1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay() +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking a iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
184 #include "termhooks.h"
185 #include "intervals.h"
188 #include "region-cache.h"
191 #ifdef HAVE_X_WINDOWS
201 #define INFINITY 10000000
203 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
204 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
205 extern int pending_menu_activation
;
208 extern int interrupt_input
;
209 extern int command_loop_level
;
211 extern int minibuffer_auto_raise
;
213 extern Lisp_Object Qface
;
215 extern Lisp_Object Voverriding_local_map
;
216 extern Lisp_Object Voverriding_local_map_menu_flag
;
217 extern Lisp_Object Qmenu_item
;
219 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
220 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
221 Lisp_Object Qredisplay_end_trigger_functions
;
222 Lisp_Object Qinhibit_point_motion_hooks
;
223 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
;
224 Lisp_Object Qfontified
;
225 Lisp_Object Qgrow_only
;
226 Lisp_Object Qinhibit_eval_during_redisplay
;
227 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
229 /* Functions called to fontify regions of text. */
231 Lisp_Object Vfontification_functions
;
232 Lisp_Object Qfontification_functions
;
234 /* Non-zero means draw tool bar buttons raised when the mouse moves
237 int auto_raise_tool_bar_buttons_p
;
239 /* Margin around tool bar buttons in pixels. */
241 Lisp_Object Vtool_bar_button_margin
;
243 /* Thickness of shadow to draw around tool bar buttons. */
245 int tool_bar_button_relief
;
247 /* Non-zero means automatically resize tool-bars so that all tool-bar
248 items are visible, and no blank lines remain. */
250 int auto_resize_tool_bars_p
;
252 /* Non-nil means don't actually do any redisplay. */
254 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
256 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
258 int inhibit_eval_during_redisplay
;
260 /* Names of text properties relevant for redisplay. */
262 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
263 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
265 /* Symbols used in text property values. */
267 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
268 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
270 extern Lisp_Object Qheight
;
272 /* Non-nil means highlight trailing whitespace. */
274 Lisp_Object Vshow_trailing_whitespace
;
276 /* Name of the face used to highlight trailing whitespace. */
278 Lisp_Object Qtrailing_whitespace
;
280 /* The symbol `image' which is the car of the lists used to represent
285 /* Non-zero means print newline to stdout before next mini-buffer
288 int noninteractive_need_newline
;
290 /* Non-zero means print newline to message log before next message. */
292 static int message_log_need_newline
;
295 /* The buffer position of the first character appearing entirely or
296 partially on the line of the selected window which contains the
297 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
298 redisplay optimization in redisplay_internal. */
300 static struct text_pos this_line_start_pos
;
302 /* Number of characters past the end of the line above, including the
303 terminating newline. */
305 static struct text_pos this_line_end_pos
;
307 /* The vertical positions and the height of this line. */
309 static int this_line_vpos
;
310 static int this_line_y
;
311 static int this_line_pixel_height
;
313 /* X position at which this display line starts. Usually zero;
314 negative if first character is partially visible. */
316 static int this_line_start_x
;
318 /* Buffer that this_line_.* variables are referring to. */
320 static struct buffer
*this_line_buffer
;
322 /* Nonzero means truncate lines in all windows less wide than the
325 int truncate_partial_width_windows
;
327 /* A flag to control how to display unibyte 8-bit character. */
329 int unibyte_display_via_language_environment
;
331 /* Nonzero means we have more than one non-mini-buffer-only frame.
332 Not guaranteed to be accurate except while parsing
333 frame-title-format. */
337 Lisp_Object Vglobal_mode_string
;
339 /* Marker for where to display an arrow on top of the buffer text. */
341 Lisp_Object Voverlay_arrow_position
;
343 /* String to display for the arrow. Only used on terminal frames. */
345 Lisp_Object Voverlay_arrow_string
;
347 /* Values of those variables at last redisplay. However, if
348 Voverlay_arrow_position is a marker, last_arrow_position is its
349 numerical position. */
351 static Lisp_Object last_arrow_position
, last_arrow_string
;
353 /* Like mode-line-format, but for the title bar on a visible frame. */
355 Lisp_Object Vframe_title_format
;
357 /* Like mode-line-format, but for the title bar on an iconified frame. */
359 Lisp_Object Vicon_title_format
;
361 /* List of functions to call when a window's size changes. These
362 functions get one arg, a frame on which one or more windows' sizes
365 static Lisp_Object Vwindow_size_change_functions
;
367 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
369 /* Nonzero if overlay arrow has been displayed once in this window. */
371 static int overlay_arrow_seen
;
373 /* Nonzero means highlight the region even in nonselected windows. */
375 int highlight_nonselected_windows
;
377 /* If cursor motion alone moves point off frame, try scrolling this
378 many lines up or down if that will bring it back. */
380 static int scroll_step
;
382 /* Non-0 means scroll just far enough to bring point back on the
383 screen, when appropriate. */
385 static int scroll_conservatively
;
387 /* Recenter the window whenever point gets within this many lines of
388 the top or bottom of the window. This value is translated into a
389 pixel value by multiplying it with CANON_Y_UNIT, which means that
390 there is really a fixed pixel height scroll margin. */
394 /* Number of windows showing the buffer of the selected window (or
395 another buffer with the same base buffer). keyboard.c refers to
400 /* Vector containing glyphs for an ellipsis `...'. */
402 static Lisp_Object default_invis_vector
[3];
404 /* Zero means display the mode-line/header-line/menu-bar in the default face
405 (this slightly odd definition is for compatibility with previous versions
406 of emacs), non-zero means display them using their respective faces.
408 This variable is deprecated. */
410 int mode_line_inverse_video
;
412 /* Prompt to display in front of the mini-buffer contents. */
414 Lisp_Object minibuf_prompt
;
416 /* Width of current mini-buffer prompt. Only set after display_line
417 of the line that contains the prompt. */
419 int minibuf_prompt_width
;
420 int minibuf_prompt_pixel_width
;
422 /* This is the window where the echo area message was displayed. It
423 is always a mini-buffer window, but it may not be the same window
424 currently active as a mini-buffer. */
426 Lisp_Object echo_area_window
;
428 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
429 pushes the current message and the value of
430 message_enable_multibyte on the stack, the function restore_message
431 pops the stack and displays MESSAGE again. */
433 Lisp_Object Vmessage_stack
;
435 /* Nonzero means multibyte characters were enabled when the echo area
436 message was specified. */
438 int message_enable_multibyte
;
440 /* True if we should redraw the mode lines on the next redisplay. */
442 int update_mode_lines
;
444 /* Nonzero if window sizes or contents have changed since last
445 redisplay that finished */
447 int windows_or_buffers_changed
;
449 /* Nonzero after display_mode_line if %l was used and it displayed a
452 int line_number_displayed
;
454 /* Maximum buffer size for which to display line numbers. */
456 Lisp_Object Vline_number_display_limit
;
458 /* line width to consider when repostioning for line number display */
460 static int line_number_display_limit_width
;
462 /* Number of lines to keep in the message log buffer. t means
463 infinite. nil means don't log at all. */
465 Lisp_Object Vmessage_log_max
;
467 /* The name of the *Messages* buffer, a string. */
469 static Lisp_Object Vmessages_buffer_name
;
471 /* Current, index 0, and last displayed echo area message. Either
472 buffers from echo_buffers, or nil to indicate no message. */
474 Lisp_Object echo_area_buffer
[2];
476 /* The buffers referenced from echo_area_buffer. */
478 static Lisp_Object echo_buffer
[2];
480 /* A vector saved used in with_area_buffer to reduce consing. */
482 static Lisp_Object Vwith_echo_area_save_vector
;
484 /* Non-zero means display_echo_area should display the last echo area
485 message again. Set by redisplay_preserve_echo_area. */
487 static int display_last_displayed_message_p
;
489 /* Nonzero if echo area is being used by print; zero if being used by
492 int message_buf_print
;
494 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
496 Lisp_Object Qinhibit_menubar_update
;
497 int inhibit_menubar_update
;
499 /* Maximum height for resizing mini-windows. Either a float
500 specifying a fraction of the available height, or an integer
501 specifying a number of lines. */
503 Lisp_Object Vmax_mini_window_height
;
505 /* Non-zero means messages should be displayed with truncated
506 lines instead of being continued. */
508 int message_truncate_lines
;
509 Lisp_Object Qmessage_truncate_lines
;
511 /* Set to 1 in clear_message to make redisplay_internal aware
512 of an emptied echo area. */
514 static int message_cleared_p
;
516 /* Non-zero means we want a hollow cursor in windows that are not
517 selected. Zero means there's no cursor in such windows. */
519 int cursor_in_non_selected_windows
;
520 Lisp_Object Qcursor_in_non_selected_windows
;
522 /* A scratch glyph row with contents used for generating truncation
523 glyphs. Also used in direct_output_for_insert. */
525 #define MAX_SCRATCH_GLYPHS 100
526 struct glyph_row scratch_glyph_row
;
527 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
529 /* Ascent and height of the last line processed by move_it_to. */
531 static int last_max_ascent
, last_height
;
533 /* Non-zero if there's a help-echo in the echo area. */
535 int help_echo_showing_p
;
537 /* If >= 0, computed, exact values of mode-line and header-line height
538 to use in the macros CURRENT_MODE_LINE_HEIGHT and
539 CURRENT_HEADER_LINE_HEIGHT. */
541 int current_mode_line_height
, current_header_line_height
;
543 /* The maximum distance to look ahead for text properties. Values
544 that are too small let us call compute_char_face and similar
545 functions too often which is expensive. Values that are too large
546 let us call compute_char_face and alike too often because we
547 might not be interested in text properties that far away. */
549 #define TEXT_PROP_DISTANCE_LIMIT 100
553 /* Variables to turn off display optimizations from Lisp. */
555 int inhibit_try_window_id
, inhibit_try_window_reusing
;
556 int inhibit_try_cursor_movement
;
558 /* Non-zero means print traces of redisplay if compiled with
561 int trace_redisplay_p
;
563 #endif /* GLYPH_DEBUG */
565 #ifdef DEBUG_TRACE_MOVE
566 /* Non-zero means trace with TRACE_MOVE to stderr. */
569 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
571 #define TRACE_MOVE(x) (void) 0
574 /* Non-zero means automatically scroll windows horizontally to make
577 int automatic_hscrolling_p
;
579 /* A list of symbols, one for each supported image type. */
581 Lisp_Object Vimage_types
;
583 /* The variable `resize-mini-windows'. If nil, don't resize
584 mini-windows. If t, always resize them to fit the text they
585 display. If `grow-only', let mini-windows grow only until they
588 Lisp_Object Vresize_mini_windows
;
590 /* Value returned from text property handlers (see below). */
595 HANDLED_RECOMPUTE_PROPS
,
596 HANDLED_OVERLAY_STRING_CONSUMED
,
600 /* A description of text properties that redisplay is interested
605 /* The name of the property. */
608 /* A unique index for the property. */
611 /* A handler function called to set up iterator IT from the property
612 at IT's current position. Value is used to steer handle_stop. */
613 enum prop_handled (*handler
) P_ ((struct it
*it
));
616 static enum prop_handled handle_face_prop
P_ ((struct it
*));
617 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
618 static enum prop_handled handle_display_prop
P_ ((struct it
*));
619 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
620 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
621 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
623 /* Properties handled by iterators. */
625 static struct props it_props
[] =
627 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
628 /* Handle `face' before `display' because some sub-properties of
629 `display' need to know the face. */
630 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
631 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
632 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
633 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
637 /* Value is the position described by X. If X is a marker, value is
638 the marker_position of X. Otherwise, value is X. */
640 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
642 /* Enumeration returned by some move_it_.* functions internally. */
646 /* Not used. Undefined value. */
649 /* Move ended at the requested buffer position or ZV. */
650 MOVE_POS_MATCH_OR_ZV
,
652 /* Move ended at the requested X pixel position. */
655 /* Move within a line ended at the end of a line that must be
659 /* Move within a line ended at the end of a line that would
660 be displayed truncated. */
663 /* Move within a line ended at a line end. */
669 /* Function prototypes. */
671 static void setup_for_ellipsis
P_ ((struct it
*));
672 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
673 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
674 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
675 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
676 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
677 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
680 static int invisible_text_between_p
P_ ((struct it
*, int, int));
683 static int next_element_from_ellipsis
P_ ((struct it
*));
684 static void pint2str
P_ ((char *, int, int));
685 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
687 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
688 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
689 static void store_frame_title_char
P_ ((char));
690 static int store_frame_title
P_ ((unsigned char *, int, int));
691 static void x_consider_frame_title
P_ ((Lisp_Object
));
692 static void handle_stop
P_ ((struct it
*));
693 static int tool_bar_lines_needed
P_ ((struct frame
*));
694 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
695 static void ensure_echo_area_buffers
P_ ((void));
696 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
697 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
698 static int with_echo_area_buffer
P_ ((struct window
*, int,
699 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
700 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
701 static void clear_garbaged_frames
P_ ((void));
702 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
703 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
704 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
705 static int display_echo_area
P_ ((struct window
*));
706 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
707 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
708 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
709 static int string_char_and_length
P_ ((unsigned char *, int, int *));
710 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
712 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
713 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
714 static void insert_left_trunc_glyphs
P_ ((struct it
*));
715 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
716 static void extend_face_to_end_of_line
P_ ((struct it
*));
717 static int append_space
P_ ((struct it
*, int));
718 static int make_cursor_line_fully_visible
P_ ((struct window
*));
719 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
720 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
721 static int trailing_whitespace_p
P_ ((int));
722 static int message_log_check_duplicate
P_ ((int, int, int, int));
723 static void push_it
P_ ((struct it
*));
724 static void pop_it
P_ ((struct it
*));
725 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
726 static void redisplay_internal
P_ ((int));
727 static int echo_area_display
P_ ((int));
728 static void redisplay_windows
P_ ((Lisp_Object
));
729 static void redisplay_window
P_ ((Lisp_Object
, int));
730 static void update_menu_bar
P_ ((struct frame
*, int));
731 static int try_window_reusing_current_matrix
P_ ((struct window
*));
732 static int try_window_id
P_ ((struct window
*));
733 static int display_line
P_ ((struct it
*));
734 static int display_mode_lines
P_ ((struct window
*));
735 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
736 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
737 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
738 static void display_menu_bar
P_ ((struct window
*));
739 static int display_count_lines
P_ ((int, int, int, int, int *));
740 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
741 int, int, struct it
*, int, int, int, int));
742 static void compute_line_metrics
P_ ((struct it
*));
743 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
744 static int get_overlay_strings
P_ ((struct it
*, int));
745 static void next_overlay_string
P_ ((struct it
*));
746 static void reseat
P_ ((struct it
*, struct text_pos
, int));
747 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
748 static void back_to_previous_visible_line_start
P_ ((struct it
*));
749 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
750 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
751 static int next_element_from_display_vector
P_ ((struct it
*));
752 static int next_element_from_string
P_ ((struct it
*));
753 static int next_element_from_c_string
P_ ((struct it
*));
754 static int next_element_from_buffer
P_ ((struct it
*));
755 static int next_element_from_composition
P_ ((struct it
*));
756 static int next_element_from_image
P_ ((struct it
*));
757 static int next_element_from_stretch
P_ ((struct it
*));
758 static void load_overlay_strings
P_ ((struct it
*, int));
759 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
760 struct display_pos
*));
761 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
762 Lisp_Object
, int, int, int, int));
763 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
765 void move_it_vertically_backward
P_ ((struct it
*, int));
766 static void init_to_row_start
P_ ((struct it
*, struct window
*,
767 struct glyph_row
*));
768 static int init_to_row_end
P_ ((struct it
*, struct window
*,
769 struct glyph_row
*));
770 static void back_to_previous_line_start
P_ ((struct it
*));
771 static int forward_to_next_line_start
P_ ((struct it
*, int *));
772 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
774 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
775 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
776 static int number_of_chars
P_ ((unsigned char *, int));
777 static void compute_stop_pos
P_ ((struct it
*));
778 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
780 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
781 static int next_overlay_change
P_ ((int));
782 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
783 Lisp_Object
, struct text_pos
*,
785 static int underlying_face_id
P_ ((struct it
*));
786 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
789 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
790 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
792 #ifdef HAVE_WINDOW_SYSTEM
794 static void update_tool_bar
P_ ((struct frame
*, int));
795 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
796 static int redisplay_tool_bar
P_ ((struct frame
*));
797 static void display_tool_bar_line
P_ ((struct it
*));
799 #endif /* HAVE_WINDOW_SYSTEM */
802 /***********************************************************************
803 Window display dimensions
804 ***********************************************************************/
806 /* Return the window-relative maximum y + 1 for glyph rows displaying
807 text in window W. This is the height of W minus the height of a
808 mode line, if any. */
811 window_text_bottom_y (w
)
814 struct frame
*f
= XFRAME (w
->frame
);
815 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
817 if (WINDOW_WANTS_MODELINE_P (w
))
818 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
823 /* Return the pixel width of display area AREA of window W. AREA < 0
824 means return the total width of W, not including fringes to
825 the left and right of the window. */
828 window_box_width (w
, area
)
832 struct frame
*f
= XFRAME (w
->frame
);
833 int width
= XFASTINT (w
->width
);
835 if (!w
->pseudo_window_p
)
837 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FRINGE_COLS (f
);
839 if (area
== TEXT_AREA
)
841 if (INTEGERP (w
->left_margin_width
))
842 width
-= XFASTINT (w
->left_margin_width
);
843 if (INTEGERP (w
->right_margin_width
))
844 width
-= XFASTINT (w
->right_margin_width
);
846 else if (area
== LEFT_MARGIN_AREA
)
847 width
= (INTEGERP (w
->left_margin_width
)
848 ? XFASTINT (w
->left_margin_width
) : 0);
849 else if (area
== RIGHT_MARGIN_AREA
)
850 width
= (INTEGERP (w
->right_margin_width
)
851 ? XFASTINT (w
->right_margin_width
) : 0);
854 return width
* CANON_X_UNIT (f
);
858 /* Return the pixel height of the display area of window W, not
859 including mode lines of W, if any.. */
862 window_box_height (w
)
865 struct frame
*f
= XFRAME (w
->frame
);
866 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
868 xassert (height
>= 0);
870 /* Note: the code below that determines the mode-line/header-line
871 height is essentially the same as that contained in the macro
872 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
873 the appropriate glyph row has its `mode_line_p' flag set,
874 and if it doesn't, uses estimate_mode_line_height instead. */
876 if (WINDOW_WANTS_MODELINE_P (w
))
878 struct glyph_row
*ml_row
879 = (w
->current_matrix
&& w
->current_matrix
->rows
880 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
882 if (ml_row
&& ml_row
->mode_line_p
)
883 height
-= ml_row
->height
;
885 height
-= estimate_mode_line_height (f
, MODE_LINE_FACE_ID
);
888 if (WINDOW_WANTS_HEADER_LINE_P (w
))
890 struct glyph_row
*hl_row
891 = (w
->current_matrix
&& w
->current_matrix
->rows
892 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
894 if (hl_row
&& hl_row
->mode_line_p
)
895 height
-= hl_row
->height
;
897 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
904 /* Return the frame-relative coordinate of the left edge of display
905 area AREA of window W. AREA < 0 means return the left edge of the
906 whole window, to the right of the left fringe of W. */
909 window_box_left (w
, area
)
913 struct frame
*f
= XFRAME (w
->frame
);
914 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
916 if (!w
->pseudo_window_p
)
918 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
919 + FRAME_LEFT_FRINGE_WIDTH (f
));
921 if (area
== TEXT_AREA
)
922 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
923 else if (area
== RIGHT_MARGIN_AREA
)
924 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
925 + window_box_width (w
, TEXT_AREA
));
932 /* Return the frame-relative coordinate of the right edge of display
933 area AREA of window W. AREA < 0 means return the left edge of the
934 whole window, to the left of the right fringe of W. */
937 window_box_right (w
, area
)
941 return window_box_left (w
, area
) + window_box_width (w
, area
);
945 /* Get the bounding box of the display area AREA of window W, without
946 mode lines, in frame-relative coordinates. AREA < 0 means the
947 whole window, not including the left and right fringes of
948 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
949 coordinates of the upper-left corner of the box. Return in
950 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
953 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
956 int *box_x
, *box_y
, *box_width
, *box_height
;
958 struct frame
*f
= XFRAME (w
->frame
);
960 *box_width
= window_box_width (w
, area
);
961 *box_height
= window_box_height (w
);
962 *box_x
= window_box_left (w
, area
);
963 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
964 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
965 if (WINDOW_WANTS_HEADER_LINE_P (w
))
966 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
970 /* Get the bounding box of the display area AREA of window W, without
971 mode lines. AREA < 0 means the whole window, not including the
972 left and right fringe of the window. Return in *TOP_LEFT_X
973 and TOP_LEFT_Y the frame-relative pixel coordinates of the
974 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
975 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
979 window_box_edges (w
, area
, top_left_x
, top_left_y
,
980 bottom_right_x
, bottom_right_y
)
983 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
985 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
987 *bottom_right_x
+= *top_left_x
;
988 *bottom_right_y
+= *top_left_y
;
993 /***********************************************************************
995 ***********************************************************************/
997 /* Return the bottom y-position of the line the iterator IT is in.
998 This can modify IT's settings. */
1004 int line_height
= it
->max_ascent
+ it
->max_descent
;
1005 int line_top_y
= it
->current_y
;
1007 if (line_height
== 0)
1010 line_height
= last_height
;
1011 else if (IT_CHARPOS (*it
) < ZV
)
1013 move_it_by_lines (it
, 1, 1);
1014 line_height
= (it
->max_ascent
|| it
->max_descent
1015 ? it
->max_ascent
+ it
->max_descent
1020 struct glyph_row
*row
= it
->glyph_row
;
1022 /* Use the default character height. */
1023 it
->glyph_row
= NULL
;
1024 it
->what
= IT_CHARACTER
;
1027 PRODUCE_GLYPHS (it
);
1028 line_height
= it
->ascent
+ it
->descent
;
1029 it
->glyph_row
= row
;
1033 return line_top_y
+ line_height
;
1037 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1038 1 if POS is visible and the line containing POS is fully visible.
1039 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1040 and header-lines heights. */
1043 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1045 int charpos
, *fully
, exact_mode_line_heights_p
;
1048 struct text_pos top
;
1050 struct buffer
*old_buffer
= NULL
;
1052 if (XBUFFER (w
->buffer
) != current_buffer
)
1054 old_buffer
= current_buffer
;
1055 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1058 *fully
= visible_p
= 0;
1059 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1061 /* Compute exact mode line heights, if requested. */
1062 if (exact_mode_line_heights_p
)
1064 if (WINDOW_WANTS_MODELINE_P (w
))
1065 current_mode_line_height
1066 = display_mode_line (w
, MODE_LINE_FACE_ID
,
1067 current_buffer
->mode_line_format
);
1069 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1070 current_header_line_height
1071 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1072 current_buffer
->header_line_format
);
1075 start_display (&it
, w
, top
);
1076 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1077 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1079 /* Note that we may overshoot because of invisible text. */
1080 if (IT_CHARPOS (it
) >= charpos
)
1082 int top_y
= it
.current_y
;
1083 int bottom_y
= line_bottom_y (&it
);
1084 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1086 if (top_y
< window_top_y
)
1087 visible_p
= bottom_y
> window_top_y
;
1088 else if (top_y
< it
.last_visible_y
)
1091 *fully
= bottom_y
<= it
.last_visible_y
;
1094 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1096 move_it_by_lines (&it
, 1, 0);
1097 if (charpos
< IT_CHARPOS (it
))
1105 set_buffer_internal_1 (old_buffer
);
1107 current_header_line_height
= current_mode_line_height
= -1;
1112 /* Return the next character from STR which is MAXLEN bytes long.
1113 Return in *LEN the length of the character. This is like
1114 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1115 we find one, we return a `?', but with the length of the invalid
1119 string_char_and_length (str
, maxlen
, len
)
1125 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1126 if (!CHAR_VALID_P (c
, 1))
1127 /* We may not change the length here because other places in Emacs
1128 don't use this function, i.e. they silently accept invalid
1137 /* Given a position POS containing a valid character and byte position
1138 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1140 static struct text_pos
1141 string_pos_nchars_ahead (pos
, string
, nchars
)
1142 struct text_pos pos
;
1146 xassert (STRINGP (string
) && nchars
>= 0);
1148 if (STRING_MULTIBYTE (string
))
1150 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
1151 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
1156 string_char_and_length (p
, rest
, &len
);
1157 p
+= len
, rest
-= len
;
1158 xassert (rest
>= 0);
1160 BYTEPOS (pos
) += len
;
1164 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1170 /* Value is the text position, i.e. character and byte position,
1171 for character position CHARPOS in STRING. */
1173 static INLINE
struct text_pos
1174 string_pos (charpos
, string
)
1178 struct text_pos pos
;
1179 xassert (STRINGP (string
));
1180 xassert (charpos
>= 0);
1181 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1186 /* Value is a text position, i.e. character and byte position, for
1187 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1188 means recognize multibyte characters. */
1190 static struct text_pos
1191 c_string_pos (charpos
, s
, multibyte_p
)
1196 struct text_pos pos
;
1198 xassert (s
!= NULL
);
1199 xassert (charpos
>= 0);
1203 int rest
= strlen (s
), len
;
1205 SET_TEXT_POS (pos
, 0, 0);
1208 string_char_and_length (s
, rest
, &len
);
1209 s
+= len
, rest
-= len
;
1210 xassert (rest
>= 0);
1212 BYTEPOS (pos
) += len
;
1216 SET_TEXT_POS (pos
, charpos
, charpos
);
1222 /* Value is the number of characters in C string S. MULTIBYTE_P
1223 non-zero means recognize multibyte characters. */
1226 number_of_chars (s
, multibyte_p
)
1234 int rest
= strlen (s
), len
;
1235 unsigned char *p
= (unsigned char *) s
;
1237 for (nchars
= 0; rest
> 0; ++nchars
)
1239 string_char_and_length (p
, rest
, &len
);
1240 rest
-= len
, p
+= len
;
1244 nchars
= strlen (s
);
1250 /* Compute byte position NEWPOS->bytepos corresponding to
1251 NEWPOS->charpos. POS is a known position in string STRING.
1252 NEWPOS->charpos must be >= POS.charpos. */
1255 compute_string_pos (newpos
, pos
, string
)
1256 struct text_pos
*newpos
, pos
;
1259 xassert (STRINGP (string
));
1260 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1262 if (STRING_MULTIBYTE (string
))
1263 *newpos
= string_pos_nchars_ahead (pos
, string
,
1264 CHARPOS (*newpos
) - CHARPOS (pos
));
1266 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1271 /***********************************************************************
1272 Lisp form evaluation
1273 ***********************************************************************/
1275 /* Error handler for safe_eval and safe_call. */
1278 safe_eval_handler (arg
)
1281 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1286 /* Evaluate SEXPR and return the result, or nil if something went
1287 wrong. Prevent redisplay during the evaluation. */
1295 if (inhibit_eval_during_redisplay
)
1299 int count
= BINDING_STACK_SIZE ();
1300 struct gcpro gcpro1
;
1303 specbind (Qinhibit_redisplay
, Qt
);
1304 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
1307 val
= unbind_to (count
, val
);
1314 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1315 Return the result, or nil if something went wrong. Prevent
1316 redisplay during the evaluation. */
1319 safe_call (nargs
, args
)
1325 if (inhibit_eval_during_redisplay
)
1329 int count
= BINDING_STACK_SIZE ();
1330 struct gcpro gcpro1
;
1333 gcpro1
.nvars
= nargs
;
1334 specbind (Qinhibit_redisplay
, Qt
);
1335 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1338 val
= unbind_to (count
, val
);
1345 /* Call function FN with one argument ARG.
1346 Return the result, or nil if something went wrong. */
1349 safe_call1 (fn
, arg
)
1350 Lisp_Object fn
, arg
;
1352 Lisp_Object args
[2];
1355 return safe_call (2, args
);
1360 /***********************************************************************
1362 ***********************************************************************/
1366 /* Define CHECK_IT to perform sanity checks on iterators.
1367 This is for debugging. It is too slow to do unconditionally. */
1373 if (it
->method
== next_element_from_string
)
1375 xassert (STRINGP (it
->string
));
1376 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1378 else if (it
->method
== next_element_from_buffer
)
1380 /* Check that character and byte positions agree. */
1381 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1385 xassert (it
->current
.dpvec_index
>= 0);
1387 xassert (it
->current
.dpvec_index
< 0);
1390 #define CHECK_IT(IT) check_it ((IT))
1394 #define CHECK_IT(IT) (void) 0
1401 /* Check that the window end of window W is what we expect it
1402 to be---the last row in the current matrix displaying text. */
1405 check_window_end (w
)
1408 if (!MINI_WINDOW_P (w
)
1409 && !NILP (w
->window_end_valid
))
1411 struct glyph_row
*row
;
1412 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1413 XFASTINT (w
->window_end_vpos
)),
1415 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1416 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1420 #define CHECK_WINDOW_END(W) check_window_end ((W))
1422 #else /* not GLYPH_DEBUG */
1424 #define CHECK_WINDOW_END(W) (void) 0
1426 #endif /* not GLYPH_DEBUG */
1430 /***********************************************************************
1431 Iterator initialization
1432 ***********************************************************************/
1434 /* Initialize IT for displaying current_buffer in window W, starting
1435 at character position CHARPOS. CHARPOS < 0 means that no buffer
1436 position is specified which is useful when the iterator is assigned
1437 a position later. BYTEPOS is the byte position corresponding to
1438 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1440 If ROW is not null, calls to produce_glyphs with IT as parameter
1441 will produce glyphs in that row.
1443 BASE_FACE_ID is the id of a base face to use. It must be one of
1444 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1445 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1446 displaying the tool-bar.
1448 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1449 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1450 corresponding mode line glyph row of the desired matrix of W. */
1453 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1456 int charpos
, bytepos
;
1457 struct glyph_row
*row
;
1458 enum face_id base_face_id
;
1460 int highlight_region_p
;
1462 /* Some precondition checks. */
1463 xassert (w
!= NULL
&& it
!= NULL
);
1464 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1467 /* If face attributes have been changed since the last redisplay,
1468 free realized faces now because they depend on face definitions
1469 that might have changed. */
1470 if (face_change_count
)
1472 face_change_count
= 0;
1473 free_all_realized_faces (Qnil
);
1476 /* Use one of the mode line rows of W's desired matrix if
1480 if (base_face_id
== MODE_LINE_FACE_ID
)
1481 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1482 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1483 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1487 bzero (it
, sizeof *it
);
1488 it
->current
.overlay_string_index
= -1;
1489 it
->current
.dpvec_index
= -1;
1490 it
->base_face_id
= base_face_id
;
1492 /* The window in which we iterate over current_buffer: */
1493 XSETWINDOW (it
->window
, w
);
1495 it
->f
= XFRAME (w
->frame
);
1497 /* Extra space between lines (on window systems only). */
1498 if (base_face_id
== DEFAULT_FACE_ID
1499 && FRAME_WINDOW_P (it
->f
))
1501 if (NATNUMP (current_buffer
->extra_line_spacing
))
1502 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1503 else if (it
->f
->extra_line_spacing
> 0)
1504 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1507 /* If realized faces have been removed, e.g. because of face
1508 attribute changes of named faces, recompute them. When running
1509 in batch mode, the face cache of Vterminal_frame is null. If
1510 we happen to get called, make a dummy face cache. */
1515 FRAME_FACE_CACHE (it
->f
) == NULL
)
1516 init_frame_faces (it
->f
);
1517 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1518 recompute_basic_faces (it
->f
);
1520 /* Current value of the `space-width', and 'height' properties. */
1521 it
->space_width
= Qnil
;
1522 it
->font_height
= Qnil
;
1524 /* Are control characters displayed as `^C'? */
1525 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1527 /* -1 means everything between a CR and the following line end
1528 is invisible. >0 means lines indented more than this value are
1530 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1531 ? XFASTINT (current_buffer
->selective_display
)
1532 : (!NILP (current_buffer
->selective_display
)
1534 it
->selective_display_ellipsis_p
1535 = !NILP (current_buffer
->selective_display_ellipses
);
1537 /* Display table to use. */
1538 it
->dp
= window_display_table (w
);
1540 /* Are multibyte characters enabled in current_buffer? */
1541 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1543 /* Non-zero if we should highlight the region. */
1545 = (!NILP (Vtransient_mark_mode
)
1546 && !NILP (current_buffer
->mark_active
)
1547 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1549 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1550 start and end of a visible region in window IT->w. Set both to
1551 -1 to indicate no region. */
1552 if (highlight_region_p
1553 /* Maybe highlight only in selected window. */
1554 && (/* Either show region everywhere. */
1555 highlight_nonselected_windows
1556 /* Or show region in the selected window. */
1557 || w
== XWINDOW (selected_window
)
1558 /* Or show the region if we are in the mini-buffer and W is
1559 the window the mini-buffer refers to. */
1560 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1561 && WINDOWP (Vminibuf_scroll_window
)
1562 && w
== XWINDOW (Vminibuf_scroll_window
))))
1564 int charpos
= marker_position (current_buffer
->mark
);
1565 it
->region_beg_charpos
= min (PT
, charpos
);
1566 it
->region_end_charpos
= max (PT
, charpos
);
1569 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1571 /* Get the position at which the redisplay_end_trigger hook should
1572 be run, if it is to be run at all. */
1573 if (MARKERP (w
->redisplay_end_trigger
)
1574 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1575 it
->redisplay_end_trigger_charpos
1576 = marker_position (w
->redisplay_end_trigger
);
1577 else if (INTEGERP (w
->redisplay_end_trigger
))
1578 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1580 /* Correct bogus values of tab_width. */
1581 it
->tab_width
= XINT (current_buffer
->tab_width
);
1582 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1585 /* Are lines in the display truncated? */
1586 it
->truncate_lines_p
1587 = (base_face_id
!= DEFAULT_FACE_ID
1588 || XINT (it
->w
->hscroll
)
1589 || (truncate_partial_width_windows
1590 && !WINDOW_FULL_WIDTH_P (it
->w
))
1591 || !NILP (current_buffer
->truncate_lines
));
1593 /* Get dimensions of truncation and continuation glyphs. These are
1594 displayed as fringe bitmaps under X, so we don't need them for such
1596 if (!FRAME_WINDOW_P (it
->f
))
1598 if (it
->truncate_lines_p
)
1600 /* We will need the truncation glyph. */
1601 xassert (it
->glyph_row
== NULL
);
1602 produce_special_glyphs (it
, IT_TRUNCATION
);
1603 it
->truncation_pixel_width
= it
->pixel_width
;
1607 /* We will need the continuation glyph. */
1608 xassert (it
->glyph_row
== NULL
);
1609 produce_special_glyphs (it
, IT_CONTINUATION
);
1610 it
->continuation_pixel_width
= it
->pixel_width
;
1613 /* Reset these values to zero becaue the produce_special_glyphs
1614 above has changed them. */
1615 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1616 it
->phys_ascent
= it
->phys_descent
= 0;
1619 /* Set this after getting the dimensions of truncation and
1620 continuation glyphs, so that we don't produce glyphs when calling
1621 produce_special_glyphs, above. */
1622 it
->glyph_row
= row
;
1623 it
->area
= TEXT_AREA
;
1625 /* Get the dimensions of the display area. The display area
1626 consists of the visible window area plus a horizontally scrolled
1627 part to the left of the window. All x-values are relative to the
1628 start of this total display area. */
1629 if (base_face_id
!= DEFAULT_FACE_ID
)
1631 /* Mode lines, menu bar in terminal frames. */
1632 it
->first_visible_x
= 0;
1633 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1638 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1639 it
->last_visible_x
= (it
->first_visible_x
1640 + window_box_width (w
, TEXT_AREA
));
1642 /* If we truncate lines, leave room for the truncator glyph(s) at
1643 the right margin. Otherwise, leave room for the continuation
1644 glyph(s). Truncation and continuation glyphs are not inserted
1645 for window-based redisplay. */
1646 if (!FRAME_WINDOW_P (it
->f
))
1648 if (it
->truncate_lines_p
)
1649 it
->last_visible_x
-= it
->truncation_pixel_width
;
1651 it
->last_visible_x
-= it
->continuation_pixel_width
;
1654 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1655 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1658 /* Leave room for a border glyph. */
1659 if (!FRAME_WINDOW_P (it
->f
)
1660 && !WINDOW_RIGHTMOST_P (it
->w
))
1661 it
->last_visible_x
-= 1;
1663 it
->last_visible_y
= window_text_bottom_y (w
);
1665 /* For mode lines and alike, arrange for the first glyph having a
1666 left box line if the face specifies a box. */
1667 if (base_face_id
!= DEFAULT_FACE_ID
)
1671 it
->face_id
= base_face_id
;
1673 /* If we have a boxed mode line, make the first character appear
1674 with a left box line. */
1675 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1676 if (face
->box
!= FACE_NO_BOX
)
1677 it
->start_of_box_run_p
= 1;
1680 /* If a buffer position was specified, set the iterator there,
1681 getting overlays and face properties from that position. */
1682 if (charpos
>= BUF_BEG (current_buffer
))
1684 it
->end_charpos
= ZV
;
1686 IT_CHARPOS (*it
) = charpos
;
1688 /* Compute byte position if not specified. */
1689 if (bytepos
< charpos
)
1690 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1692 IT_BYTEPOS (*it
) = bytepos
;
1694 /* Compute faces etc. */
1695 reseat (it
, it
->current
.pos
, 1);
1702 /* Initialize IT for the display of window W with window start POS. */
1705 start_display (it
, w
, pos
)
1708 struct text_pos pos
;
1710 struct glyph_row
*row
;
1711 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1713 row
= w
->desired_matrix
->rows
+ first_vpos
;
1714 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1716 if (!it
->truncate_lines_p
)
1718 int start_at_line_beg_p
;
1719 int first_y
= it
->current_y
;
1721 /* If window start is not at a line start, skip forward to POS to
1722 get the correct continuation lines width. */
1723 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1724 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1725 if (!start_at_line_beg_p
)
1727 reseat_at_previous_visible_line_start (it
);
1728 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1730 /* If lines are continued, this line may end in the middle
1731 of a multi-glyph character (e.g. a control character
1732 displayed as \003, or in the middle of an overlay
1733 string). In this case move_it_to above will not have
1734 taken us to the start of the continuation line but to the
1735 end of the continued line. */
1736 if (it
->current_x
> 0)
1738 if (it
->current
.dpvec_index
>= 0
1739 || it
->current
.overlay_string_index
>= 0)
1741 set_iterator_to_next (it
, 1);
1742 move_it_in_display_line_to (it
, -1, -1, 0);
1745 it
->continuation_lines_width
+= it
->current_x
;
1748 /* We're starting a new display line, not affected by the
1749 height of the continued line, so clear the appropriate
1750 fields in the iterator structure. */
1751 it
->max_ascent
= it
->max_descent
= 0;
1752 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1754 it
->current_y
= first_y
;
1756 it
->current_x
= it
->hpos
= 0;
1760 #if 0 /* Don't assert the following because start_display is sometimes
1761 called intentionally with a window start that is not at a
1762 line start. Please leave this code in as a comment. */
1764 /* Window start should be on a line start, now. */
1765 xassert (it
->continuation_lines_width
1766 || IT_CHARPOS (it
) == BEGV
1767 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1772 /* Return 1 if POS is a position in ellipses displayed for invisible
1773 text. W is the window we display, for text property lookup. */
1776 in_ellipses_for_invisible_text_p (pos
, w
)
1777 struct display_pos
*pos
;
1780 Lisp_Object prop
, window
;
1782 int charpos
= CHARPOS (pos
->pos
);
1784 /* If POS specifies a position in a display vector, this might
1785 be for an ellipsis displayed for invisible text. We won't
1786 get the iterator set up for delivering that ellipsis unless
1787 we make sure that it gets aware of the invisible text. */
1788 if (pos
->dpvec_index
>= 0
1789 && pos
->overlay_string_index
< 0
1790 && CHARPOS (pos
->string_pos
) < 0
1792 && (XSETWINDOW (window
, w
),
1793 prop
= Fget_char_property (make_number (charpos
),
1794 Qinvisible
, window
),
1795 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1797 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1799 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
1806 /* Initialize IT for stepping through current_buffer in window W,
1807 starting at position POS that includes overlay string and display
1808 vector/ control character translation position information. Value
1809 is zero if there are overlay strings with newlines at POS. */
1812 init_from_display_pos (it
, w
, pos
)
1815 struct display_pos
*pos
;
1817 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1818 int i
, overlay_strings_with_newlines
= 0;
1820 /* If POS specifies a position in a display vector, this might
1821 be for an ellipsis displayed for invisible text. We won't
1822 get the iterator set up for delivering that ellipsis unless
1823 we make sure that it gets aware of the invisible text. */
1824 if (in_ellipses_for_invisible_text_p (pos
, w
))
1830 /* Keep in mind: the call to reseat in init_iterator skips invisible
1831 text, so we might end up at a position different from POS. This
1832 is only a problem when POS is a row start after a newline and an
1833 overlay starts there with an after-string, and the overlay has an
1834 invisible property. Since we don't skip invisible text in
1835 display_line and elsewhere immediately after consuming the
1836 newline before the row start, such a POS will not be in a string,
1837 but the call to init_iterator below will move us to the
1839 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1841 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
1843 char *s
= XSTRING (it
->overlay_strings
[i
])->data
;
1844 char *e
= s
+ STRING_BYTES (XSTRING (it
->overlay_strings
[i
]));
1846 while (s
< e
&& *s
!= '\n')
1851 overlay_strings_with_newlines
= 1;
1856 /* If position is within an overlay string, set up IT to the right
1858 if (pos
->overlay_string_index
>= 0)
1862 /* If the first overlay string happens to have a `display'
1863 property for an image, the iterator will be set up for that
1864 image, and we have to undo that setup first before we can
1865 correct the overlay string index. */
1866 if (it
->method
== next_element_from_image
)
1869 /* We already have the first chunk of overlay strings in
1870 IT->overlay_strings. Load more until the one for
1871 pos->overlay_string_index is in IT->overlay_strings. */
1872 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1874 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1875 it
->current
.overlay_string_index
= 0;
1878 load_overlay_strings (it
, 0);
1879 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1883 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1884 relative_index
= (it
->current
.overlay_string_index
1885 % OVERLAY_STRING_CHUNK_SIZE
);
1886 it
->string
= it
->overlay_strings
[relative_index
];
1887 xassert (STRINGP (it
->string
));
1888 it
->current
.string_pos
= pos
->string_pos
;
1889 it
->method
= next_element_from_string
;
1892 #if 0 /* This is bogus because POS not having an overlay string
1893 position does not mean it's after the string. Example: A
1894 line starting with a before-string and initialization of IT
1895 to the previous row's end position. */
1896 else if (it
->current
.overlay_string_index
>= 0)
1898 /* If POS says we're already after an overlay string ending at
1899 POS, make sure to pop the iterator because it will be in
1900 front of that overlay string. When POS is ZV, we've thereby
1901 also ``processed'' overlay strings at ZV. */
1904 it
->current
.overlay_string_index
= -1;
1905 it
->method
= next_element_from_buffer
;
1906 if (CHARPOS (pos
->pos
) == ZV
)
1907 it
->overlay_strings_at_end_processed_p
= 1;
1911 if (CHARPOS (pos
->string_pos
) >= 0)
1913 /* Recorded position is not in an overlay string, but in another
1914 string. This can only be a string from a `display' property.
1915 IT should already be filled with that string. */
1916 it
->current
.string_pos
= pos
->string_pos
;
1917 xassert (STRINGP (it
->string
));
1920 /* Restore position in display vector translations, control
1921 character translations or ellipses. */
1922 if (pos
->dpvec_index
>= 0)
1924 if (it
->dpvec
== NULL
)
1925 get_next_display_element (it
);
1926 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1927 it
->current
.dpvec_index
= pos
->dpvec_index
;
1931 return !overlay_strings_with_newlines
;
1935 /* Initialize IT for stepping through current_buffer in window W
1936 starting at ROW->start. */
1939 init_to_row_start (it
, w
, row
)
1942 struct glyph_row
*row
;
1944 init_from_display_pos (it
, w
, &row
->start
);
1945 it
->continuation_lines_width
= row
->continuation_lines_width
;
1950 /* Initialize IT for stepping through current_buffer in window W
1951 starting in the line following ROW, i.e. starting at ROW->end.
1952 Value is zero if there are overlay strings with newlines at ROW's
1956 init_to_row_end (it
, w
, row
)
1959 struct glyph_row
*row
;
1963 if (init_from_display_pos (it
, w
, &row
->end
))
1965 if (row
->continued_p
)
1966 it
->continuation_lines_width
1967 = row
->continuation_lines_width
+ row
->pixel_width
;
1978 /***********************************************************************
1980 ***********************************************************************/
1982 /* Called when IT reaches IT->stop_charpos. Handle text property and
1983 overlay changes. Set IT->stop_charpos to the next position where
1990 enum prop_handled handled
;
1991 int handle_overlay_change_p
= 1;
1995 it
->current
.dpvec_index
= -1;
1999 handled
= HANDLED_NORMALLY
;
2001 /* Call text property handlers. */
2002 for (p
= it_props
; p
->handler
; ++p
)
2004 handled
= p
->handler (it
);
2006 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2008 else if (handled
== HANDLED_RETURN
)
2010 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2011 handle_overlay_change_p
= 0;
2014 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2016 /* Don't check for overlay strings below when set to deliver
2017 characters from a display vector. */
2018 if (it
->method
== next_element_from_display_vector
)
2019 handle_overlay_change_p
= 0;
2021 /* Handle overlay changes. */
2022 if (handle_overlay_change_p
)
2023 handled
= handle_overlay_change (it
);
2025 /* Determine where to stop next. */
2026 if (handled
== HANDLED_NORMALLY
)
2027 compute_stop_pos (it
);
2030 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2034 /* Compute IT->stop_charpos from text property and overlay change
2035 information for IT's current position. */
2038 compute_stop_pos (it
)
2041 register INTERVAL iv
, next_iv
;
2042 Lisp_Object object
, limit
, position
;
2044 /* If nowhere else, stop at the end. */
2045 it
->stop_charpos
= it
->end_charpos
;
2047 if (STRINGP (it
->string
))
2049 /* Strings are usually short, so don't limit the search for
2051 object
= it
->string
;
2053 position
= make_number (IT_STRING_CHARPOS (*it
));
2059 /* If next overlay change is in front of the current stop pos
2060 (which is IT->end_charpos), stop there. Note: value of
2061 next_overlay_change is point-max if no overlay change
2063 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2064 if (charpos
< it
->stop_charpos
)
2065 it
->stop_charpos
= charpos
;
2067 /* If showing the region, we have to stop at the region
2068 start or end because the face might change there. */
2069 if (it
->region_beg_charpos
> 0)
2071 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2072 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2073 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2074 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2077 /* Set up variables for computing the stop position from text
2078 property changes. */
2079 XSETBUFFER (object
, current_buffer
);
2080 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2081 position
= make_number (IT_CHARPOS (*it
));
2085 /* Get the interval containing IT's position. Value is a null
2086 interval if there isn't such an interval. */
2087 iv
= validate_interval_range (object
, &position
, &position
, 0);
2088 if (!NULL_INTERVAL_P (iv
))
2090 Lisp_Object values_here
[LAST_PROP_IDX
];
2093 /* Get properties here. */
2094 for (p
= it_props
; p
->handler
; ++p
)
2095 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2097 /* Look for an interval following iv that has different
2099 for (next_iv
= next_interval (iv
);
2100 (!NULL_INTERVAL_P (next_iv
)
2102 || XFASTINT (limit
) > next_iv
->position
));
2103 next_iv
= next_interval (next_iv
))
2105 for (p
= it_props
; p
->handler
; ++p
)
2107 Lisp_Object new_value
;
2109 new_value
= textget (next_iv
->plist
, *p
->name
);
2110 if (!EQ (values_here
[p
->idx
], new_value
))
2118 if (!NULL_INTERVAL_P (next_iv
))
2120 if (INTEGERP (limit
)
2121 && next_iv
->position
>= XFASTINT (limit
))
2122 /* No text property change up to limit. */
2123 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2125 /* Text properties change in next_iv. */
2126 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2130 xassert (STRINGP (it
->string
)
2131 || (it
->stop_charpos
>= BEGV
2132 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2136 /* Return the position of the next overlay change after POS in
2137 current_buffer. Value is point-max if no overlay change
2138 follows. This is like `next-overlay-change' but doesn't use
2142 next_overlay_change (pos
)
2147 Lisp_Object
*overlays
;
2151 /* Get all overlays at the given position. */
2153 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2154 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2155 if (noverlays
> len
)
2158 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2159 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2162 /* If any of these overlays ends before endpos,
2163 use its ending point instead. */
2164 for (i
= 0; i
< noverlays
; ++i
)
2169 oend
= OVERLAY_END (overlays
[i
]);
2170 oendpos
= OVERLAY_POSITION (oend
);
2171 endpos
= min (endpos
, oendpos
);
2179 /***********************************************************************
2181 ***********************************************************************/
2183 /* Handle changes in the `fontified' property of the current buffer by
2184 calling hook functions from Qfontification_functions to fontify
2187 static enum prop_handled
2188 handle_fontified_prop (it
)
2191 Lisp_Object prop
, pos
;
2192 enum prop_handled handled
= HANDLED_NORMALLY
;
2194 /* Get the value of the `fontified' property at IT's current buffer
2195 position. (The `fontified' property doesn't have a special
2196 meaning in strings.) If the value is nil, call functions from
2197 Qfontification_functions. */
2198 if (!STRINGP (it
->string
)
2200 && !NILP (Vfontification_functions
)
2201 && !NILP (Vrun_hooks
)
2202 && (pos
= make_number (IT_CHARPOS (*it
)),
2203 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2206 int count
= BINDING_STACK_SIZE ();
2209 val
= Vfontification_functions
;
2210 specbind (Qfontification_functions
, Qnil
);
2212 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2213 safe_call1 (val
, pos
);
2216 Lisp_Object globals
, fn
;
2217 struct gcpro gcpro1
, gcpro2
;
2220 GCPRO2 (val
, globals
);
2222 for (; CONSP (val
); val
= XCDR (val
))
2228 /* A value of t indicates this hook has a local
2229 binding; it means to run the global binding too.
2230 In a global value, t should not occur. If it
2231 does, we must ignore it to avoid an endless
2233 for (globals
= Fdefault_value (Qfontification_functions
);
2235 globals
= XCDR (globals
))
2237 fn
= XCAR (globals
);
2239 safe_call1 (fn
, pos
);
2243 safe_call1 (fn
, pos
);
2249 unbind_to (count
, Qnil
);
2251 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2252 something. This avoids an endless loop if they failed to
2253 fontify the text for which reason ever. */
2254 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2255 handled
= HANDLED_RECOMPUTE_PROPS
;
2263 /***********************************************************************
2265 ***********************************************************************/
2267 /* Set up iterator IT from face properties at its current position.
2268 Called from handle_stop. */
2270 static enum prop_handled
2271 handle_face_prop (it
)
2274 int new_face_id
, next_stop
;
2276 if (!STRINGP (it
->string
))
2279 = face_at_buffer_position (it
->w
,
2281 it
->region_beg_charpos
,
2282 it
->region_end_charpos
,
2285 + TEXT_PROP_DISTANCE_LIMIT
),
2288 /* Is this a start of a run of characters with box face?
2289 Caveat: this can be called for a freshly initialized
2290 iterator; face_id is -1 is this case. We know that the new
2291 face will not change until limit, i.e. if the new face has a
2292 box, all characters up to limit will have one. But, as
2293 usual, we don't know whether limit is really the end. */
2294 if (new_face_id
!= it
->face_id
)
2296 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2298 /* If new face has a box but old face has not, this is
2299 the start of a run of characters with box, i.e. it has
2300 a shadow on the left side. The value of face_id of the
2301 iterator will be -1 if this is the initial call that gets
2302 the face. In this case, we have to look in front of IT's
2303 position and see whether there is a face != new_face_id. */
2304 it
->start_of_box_run_p
2305 = (new_face
->box
!= FACE_NO_BOX
2306 && (it
->face_id
>= 0
2307 || IT_CHARPOS (*it
) == BEG
2308 || new_face_id
!= face_before_it_pos (it
)));
2309 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2314 int base_face_id
, bufpos
;
2316 if (it
->current
.overlay_string_index
>= 0)
2317 bufpos
= IT_CHARPOS (*it
);
2321 /* For strings from a buffer, i.e. overlay strings or strings
2322 from a `display' property, use the face at IT's current
2323 buffer position as the base face to merge with, so that
2324 overlay strings appear in the same face as surrounding
2325 text, unless they specify their own faces. */
2326 base_face_id
= underlying_face_id (it
);
2328 new_face_id
= face_at_string_position (it
->w
,
2330 IT_STRING_CHARPOS (*it
),
2332 it
->region_beg_charpos
,
2333 it
->region_end_charpos
,
2337 #if 0 /* This shouldn't be neccessary. Let's check it. */
2338 /* If IT is used to display a mode line we would really like to
2339 use the mode line face instead of the frame's default face. */
2340 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2341 && new_face_id
== DEFAULT_FACE_ID
)
2342 new_face_id
= MODE_LINE_FACE_ID
;
2345 /* Is this a start of a run of characters with box? Caveat:
2346 this can be called for a freshly allocated iterator; face_id
2347 is -1 is this case. We know that the new face will not
2348 change until the next check pos, i.e. if the new face has a
2349 box, all characters up to that position will have a
2350 box. But, as usual, we don't know whether that position
2351 is really the end. */
2352 if (new_face_id
!= it
->face_id
)
2354 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2355 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2357 /* If new face has a box but old face hasn't, this is the
2358 start of a run of characters with box, i.e. it has a
2359 shadow on the left side. */
2360 it
->start_of_box_run_p
2361 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2362 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2366 it
->face_id
= new_face_id
;
2367 return HANDLED_NORMALLY
;
2371 /* Return the ID of the face ``underlying'' IT's current position,
2372 which is in a string. If the iterator is associated with a
2373 buffer, return the face at IT's current buffer position.
2374 Otherwise, use the iterator's base_face_id. */
2377 underlying_face_id (it
)
2380 int face_id
= it
->base_face_id
, i
;
2382 xassert (STRINGP (it
->string
));
2384 for (i
= it
->sp
- 1; i
>= 0; --i
)
2385 if (NILP (it
->stack
[i
].string
))
2386 face_id
= it
->stack
[i
].face_id
;
2392 /* Compute the face one character before or after the current position
2393 of IT. BEFORE_P non-zero means get the face in front of IT's
2394 position. Value is the id of the face. */
2397 face_before_or_after_it_pos (it
, before_p
)
2402 int next_check_charpos
;
2403 struct text_pos pos
;
2405 xassert (it
->s
== NULL
);
2407 if (STRINGP (it
->string
))
2409 int bufpos
, base_face_id
;
2411 /* No face change past the end of the string (for the case
2412 we are padding with spaces). No face change before the
2414 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2415 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2418 /* Set pos to the position before or after IT's current position. */
2420 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2422 /* For composition, we must check the character after the
2424 pos
= (it
->what
== IT_COMPOSITION
2425 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2426 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2428 if (it
->current
.overlay_string_index
>= 0)
2429 bufpos
= IT_CHARPOS (*it
);
2433 base_face_id
= underlying_face_id (it
);
2435 /* Get the face for ASCII, or unibyte. */
2436 face_id
= face_at_string_position (it
->w
,
2440 it
->region_beg_charpos
,
2441 it
->region_end_charpos
,
2442 &next_check_charpos
,
2445 /* Correct the face for charsets different from ASCII. Do it
2446 for the multibyte case only. The face returned above is
2447 suitable for unibyte text if IT->string is unibyte. */
2448 if (STRING_MULTIBYTE (it
->string
))
2450 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2451 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2453 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2455 c
= string_char_and_length (p
, rest
, &len
);
2456 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2461 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2462 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2465 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2466 pos
= it
->current
.pos
;
2469 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2472 if (it
->what
== IT_COMPOSITION
)
2473 /* For composition, we must check the position after the
2475 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2477 INC_TEXT_POS (pos
, it
->multibyte_p
);
2480 /* Determine face for CHARSET_ASCII, or unibyte. */
2481 face_id
= face_at_buffer_position (it
->w
,
2483 it
->region_beg_charpos
,
2484 it
->region_end_charpos
,
2485 &next_check_charpos
,
2488 /* Correct the face for charsets different from ASCII. Do it
2489 for the multibyte case only. The face returned above is
2490 suitable for unibyte text if current_buffer is unibyte. */
2491 if (it
->multibyte_p
)
2493 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2494 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2495 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2504 /***********************************************************************
2506 ***********************************************************************/
2508 /* Set up iterator IT from invisible properties at its current
2509 position. Called from handle_stop. */
2511 static enum prop_handled
2512 handle_invisible_prop (it
)
2515 enum prop_handled handled
= HANDLED_NORMALLY
;
2517 if (STRINGP (it
->string
))
2519 extern Lisp_Object Qinvisible
;
2520 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2522 /* Get the value of the invisible text property at the
2523 current position. Value will be nil if there is no such
2525 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2526 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2529 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2531 handled
= HANDLED_RECOMPUTE_PROPS
;
2533 /* Get the position at which the next change of the
2534 invisible text property can be found in IT->string.
2535 Value will be nil if the property value is the same for
2536 all the rest of IT->string. */
2537 XSETINT (limit
, XSTRING (it
->string
)->size
);
2538 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2541 /* Text at current position is invisible. The next
2542 change in the property is at position end_charpos.
2543 Move IT's current position to that position. */
2544 if (INTEGERP (end_charpos
)
2545 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2547 struct text_pos old
;
2548 old
= it
->current
.string_pos
;
2549 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2550 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2554 /* The rest of the string is invisible. If this is an
2555 overlay string, proceed with the next overlay string
2556 or whatever comes and return a character from there. */
2557 if (it
->current
.overlay_string_index
>= 0)
2559 next_overlay_string (it
);
2560 /* Don't check for overlay strings when we just
2561 finished processing them. */
2562 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2566 struct Lisp_String
*s
= XSTRING (it
->string
);
2567 IT_STRING_CHARPOS (*it
) = s
->size
;
2568 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2575 int invis_p
, newpos
, next_stop
, start_charpos
;
2576 Lisp_Object pos
, prop
, overlay
;
2578 /* First of all, is there invisible text at this position? */
2579 start_charpos
= IT_CHARPOS (*it
);
2580 pos
= make_number (IT_CHARPOS (*it
));
2581 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2583 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2585 /* If we are on invisible text, skip over it. */
2586 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
2588 /* Record whether we have to display an ellipsis for the
2590 int display_ellipsis_p
= invis_p
== 2;
2592 handled
= HANDLED_RECOMPUTE_PROPS
;
2594 /* Loop skipping over invisible text. The loop is left at
2595 ZV or with IT on the first char being visible again. */
2598 /* Try to skip some invisible text. Return value is the
2599 position reached which can be equal to IT's position
2600 if there is nothing invisible here. This skips both
2601 over invisible text properties and overlays with
2602 invisible property. */
2603 newpos
= skip_invisible (IT_CHARPOS (*it
),
2604 &next_stop
, ZV
, it
->window
);
2606 /* If we skipped nothing at all we weren't at invisible
2607 text in the first place. If everything to the end of
2608 the buffer was skipped, end the loop. */
2609 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2613 /* We skipped some characters but not necessarily
2614 all there are. Check if we ended up on visible
2615 text. Fget_char_property returns the property of
2616 the char before the given position, i.e. if we
2617 get invis_p = 0, this means that the char at
2618 newpos is visible. */
2619 pos
= make_number (newpos
);
2620 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2621 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2624 /* If we ended up on invisible text, proceed to
2625 skip starting with next_stop. */
2627 IT_CHARPOS (*it
) = next_stop
;
2631 /* The position newpos is now either ZV or on visible text. */
2632 IT_CHARPOS (*it
) = newpos
;
2633 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2635 /* If there are before-strings at the start of invisible
2636 text, and the text is invisible because of a text
2637 property, arrange to show before-strings because 20.x did
2638 it that way. (If the text is invisible because of an
2639 overlay property instead of a text property, this is
2640 already handled in the overlay code.) */
2642 && get_overlay_strings (it
, start_charpos
))
2644 handled
= HANDLED_RECOMPUTE_PROPS
;
2645 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2647 else if (display_ellipsis_p
)
2648 setup_for_ellipsis (it
);
2656 /* Make iterator IT return `...' next. */
2659 setup_for_ellipsis (it
)
2663 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2665 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2666 it
->dpvec
= v
->contents
;
2667 it
->dpend
= v
->contents
+ v
->size
;
2671 /* Default `...'. */
2672 it
->dpvec
= default_invis_vector
;
2673 it
->dpend
= default_invis_vector
+ 3;
2676 /* The ellipsis display does not replace the display of the
2677 character at the new position. Indicate this by setting
2678 IT->dpvec_char_len to zero. */
2679 it
->dpvec_char_len
= 0;
2681 it
->current
.dpvec_index
= 0;
2682 it
->method
= next_element_from_display_vector
;
2687 /***********************************************************************
2689 ***********************************************************************/
2691 /* Set up iterator IT from `display' property at its current position.
2692 Called from handle_stop. */
2694 static enum prop_handled
2695 handle_display_prop (it
)
2698 Lisp_Object prop
, object
;
2699 struct text_pos
*position
;
2700 int display_replaced_p
= 0;
2702 if (STRINGP (it
->string
))
2704 object
= it
->string
;
2705 position
= &it
->current
.string_pos
;
2709 object
= it
->w
->buffer
;
2710 position
= &it
->current
.pos
;
2713 /* Reset those iterator values set from display property values. */
2714 it
->font_height
= Qnil
;
2715 it
->space_width
= Qnil
;
2718 /* We don't support recursive `display' properties, i.e. string
2719 values that have a string `display' property, that have a string
2720 `display' property etc. */
2721 if (!it
->string_from_display_prop_p
)
2722 it
->area
= TEXT_AREA
;
2724 prop
= Fget_char_property (make_number (position
->charpos
),
2727 return HANDLED_NORMALLY
;
2730 /* Simple properties. */
2731 && !EQ (XCAR (prop
), Qimage
)
2732 && !EQ (XCAR (prop
), Qspace
)
2733 && !EQ (XCAR (prop
), Qwhen
)
2734 && !EQ (XCAR (prop
), Qspace_width
)
2735 && !EQ (XCAR (prop
), Qheight
)
2736 && !EQ (XCAR (prop
), Qraise
)
2737 /* Marginal area specifications. */
2738 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2739 && !NILP (XCAR (prop
)))
2741 for (; CONSP (prop
); prop
= XCDR (prop
))
2743 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2744 position
, display_replaced_p
))
2745 display_replaced_p
= 1;
2748 else if (VECTORP (prop
))
2751 for (i
= 0; i
< ASIZE (prop
); ++i
)
2752 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2753 position
, display_replaced_p
))
2754 display_replaced_p
= 1;
2758 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2759 display_replaced_p
= 1;
2762 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2766 /* Value is the position of the end of the `display' property starting
2767 at START_POS in OBJECT. */
2769 static struct text_pos
2770 display_prop_end (it
, object
, start_pos
)
2773 struct text_pos start_pos
;
2776 struct text_pos end_pos
;
2778 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2779 Qdisplay
, object
, Qnil
);
2780 CHARPOS (end_pos
) = XFASTINT (end
);
2781 if (STRINGP (object
))
2782 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2784 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2790 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2791 is the object in which the `display' property was found. *POSITION
2792 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2793 means that we previously saw a display sub-property which already
2794 replaced text display with something else, for example an image;
2795 ignore such properties after the first one has been processed.
2797 If PROP is a `space' or `image' sub-property, set *POSITION to the
2798 end position of the `display' property.
2800 Value is non-zero something was found which replaces the display
2801 of buffer or string text. */
2804 handle_single_display_prop (it
, prop
, object
, position
,
2805 display_replaced_before_p
)
2809 struct text_pos
*position
;
2810 int display_replaced_before_p
;
2813 int replaces_text_display_p
= 0;
2816 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2817 evaluated. If the result is nil, VALUE is ignored. */
2819 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2828 if (!NILP (form
) && !EQ (form
, Qt
))
2830 int count
= BINDING_STACK_SIZE ();
2831 struct gcpro gcpro1
;
2833 /* Bind `object' to the object having the `display' property, a
2834 buffer or string. Bind `position' to the position in the
2835 object where the property was found, and `buffer-position'
2836 to the current position in the buffer. */
2837 specbind (Qobject
, object
);
2838 specbind (Qposition
, make_number (CHARPOS (*position
)));
2839 specbind (Qbuffer_position
,
2840 make_number (STRINGP (object
)
2841 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2843 form
= safe_eval (form
);
2845 unbind_to (count
, Qnil
);
2852 && EQ (XCAR (prop
), Qheight
)
2853 && CONSP (XCDR (prop
)))
2855 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2858 /* `(height HEIGHT)'. */
2859 it
->font_height
= XCAR (XCDR (prop
));
2860 if (!NILP (it
->font_height
))
2862 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2863 int new_height
= -1;
2865 if (CONSP (it
->font_height
)
2866 && (EQ (XCAR (it
->font_height
), Qplus
)
2867 || EQ (XCAR (it
->font_height
), Qminus
))
2868 && CONSP (XCDR (it
->font_height
))
2869 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2871 /* `(+ N)' or `(- N)' where N is an integer. */
2872 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2873 if (EQ (XCAR (it
->font_height
), Qplus
))
2875 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2877 else if (FUNCTIONP (it
->font_height
))
2879 /* Call function with current height as argument.
2880 Value is the new height. */
2882 height
= safe_call1 (it
->font_height
,
2883 face
->lface
[LFACE_HEIGHT_INDEX
]);
2884 if (NUMBERP (height
))
2885 new_height
= XFLOATINT (height
);
2887 else if (NUMBERP (it
->font_height
))
2889 /* Value is a multiple of the canonical char height. */
2892 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2893 new_height
= (XFLOATINT (it
->font_height
)
2894 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2898 /* Evaluate IT->font_height with `height' bound to the
2899 current specified height to get the new height. */
2901 int count
= BINDING_STACK_SIZE ();
2903 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2904 value
= safe_eval (it
->font_height
);
2905 unbind_to (count
, Qnil
);
2907 if (NUMBERP (value
))
2908 new_height
= XFLOATINT (value
);
2912 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2915 else if (CONSP (prop
)
2916 && EQ (XCAR (prop
), Qspace_width
)
2917 && CONSP (XCDR (prop
)))
2919 /* `(space_width WIDTH)'. */
2920 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2923 value
= XCAR (XCDR (prop
));
2924 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2925 it
->space_width
= value
;
2927 else if (CONSP (prop
)
2928 && EQ (XCAR (prop
), Qraise
)
2929 && CONSP (XCDR (prop
)))
2931 /* `(raise FACTOR)'. */
2932 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2935 #ifdef HAVE_WINDOW_SYSTEM
2936 value
= XCAR (XCDR (prop
));
2937 if (NUMBERP (value
))
2939 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2940 it
->voffset
= - (XFLOATINT (value
)
2941 * (FONT_HEIGHT (face
->font
)));
2943 #endif /* HAVE_WINDOW_SYSTEM */
2945 else if (!it
->string_from_display_prop_p
)
2947 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2948 VALUE) or `((margin nil) VALUE)' or VALUE. */
2949 Lisp_Object location
, value
;
2950 struct text_pos start_pos
;
2953 /* Characters having this form of property are not displayed, so
2954 we have to find the end of the property. */
2955 start_pos
= *position
;
2956 *position
= display_prop_end (it
, object
, start_pos
);
2959 /* Let's stop at the new position and assume that all
2960 text properties change there. */
2961 it
->stop_charpos
= position
->charpos
;
2963 location
= Qunbound
;
2964 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2968 value
= XCDR (prop
);
2970 value
= XCAR (value
);
2973 if (EQ (XCAR (tem
), Qmargin
)
2974 && (tem
= XCDR (tem
),
2975 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2977 || EQ (tem
, Qleft_margin
)
2978 || EQ (tem
, Qright_margin
))))
2982 if (EQ (location
, Qunbound
))
2988 #ifdef HAVE_WINDOW_SYSTEM
2989 if (FRAME_TERMCAP_P (it
->f
))
2990 valid_p
= STRINGP (value
);
2992 valid_p
= (STRINGP (value
)
2993 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2994 || valid_image_p (value
));
2995 #else /* not HAVE_WINDOW_SYSTEM */
2996 valid_p
= STRINGP (value
);
2997 #endif /* not HAVE_WINDOW_SYSTEM */
2999 if ((EQ (location
, Qleft_margin
)
3000 || EQ (location
, Qright_margin
)
3003 && !display_replaced_before_p
)
3005 replaces_text_display_p
= 1;
3007 /* Save current settings of IT so that we can restore them
3008 when we are finished with the glyph property value. */
3011 if (NILP (location
))
3012 it
->area
= TEXT_AREA
;
3013 else if (EQ (location
, Qleft_margin
))
3014 it
->area
= LEFT_MARGIN_AREA
;
3016 it
->area
= RIGHT_MARGIN_AREA
;
3018 if (STRINGP (value
))
3021 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3022 it
->current
.overlay_string_index
= -1;
3023 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3024 it
->end_charpos
= it
->string_nchars
3025 = XSTRING (it
->string
)->size
;
3026 it
->method
= next_element_from_string
;
3027 it
->stop_charpos
= 0;
3028 it
->string_from_display_prop_p
= 1;
3029 /* Say that we haven't consumed the characters with
3030 `display' property yet. The call to pop_it in
3031 set_iterator_to_next will clean this up. */
3032 *position
= start_pos
;
3034 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3036 it
->method
= next_element_from_stretch
;
3038 it
->current
.pos
= it
->position
= start_pos
;
3040 #ifdef HAVE_WINDOW_SYSTEM
3043 it
->what
= IT_IMAGE
;
3044 it
->image_id
= lookup_image (it
->f
, value
);
3045 it
->position
= start_pos
;
3046 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3047 it
->method
= next_element_from_image
;
3049 /* Say that we haven't consumed the characters with
3050 `display' property yet. The call to pop_it in
3051 set_iterator_to_next will clean this up. */
3052 *position
= start_pos
;
3054 #endif /* HAVE_WINDOW_SYSTEM */
3057 /* Invalid property or property not supported. Restore
3058 the position to what it was before. */
3059 *position
= start_pos
;
3062 return replaces_text_display_p
;
3066 /* Check if PROP is a display sub-property value whose text should be
3067 treated as intangible. */
3070 single_display_prop_intangible_p (prop
)
3073 /* Skip over `when FORM'. */
3074 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3085 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3086 we don't need to treat text as intangible. */
3087 if (EQ (XCAR (prop
), Qmargin
))
3095 || EQ (XCAR (prop
), Qleft_margin
)
3096 || EQ (XCAR (prop
), Qright_margin
))
3100 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3104 /* Check if PROP is a display property value whose text should be
3105 treated as intangible. */
3108 display_prop_intangible_p (prop
)
3112 && CONSP (XCAR (prop
))
3113 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3115 /* A list of sub-properties. */
3116 while (CONSP (prop
))
3118 if (single_display_prop_intangible_p (XCAR (prop
)))
3123 else if (VECTORP (prop
))
3125 /* A vector of sub-properties. */
3127 for (i
= 0; i
< ASIZE (prop
); ++i
)
3128 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3132 return single_display_prop_intangible_p (prop
);
3138 /* Return 1 if PROP is a display sub-property value containing STRING. */
3141 single_display_prop_string_p (prop
, string
)
3142 Lisp_Object prop
, string
;
3144 if (EQ (string
, prop
))
3147 /* Skip over `when FORM'. */
3148 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3157 /* Skip over `margin LOCATION'. */
3158 if (EQ (XCAR (prop
), Qmargin
))
3169 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3173 /* Return 1 if STRING appears in the `display' property PROP. */
3176 display_prop_string_p (prop
, string
)
3177 Lisp_Object prop
, string
;
3180 && CONSP (XCAR (prop
))
3181 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3183 /* A list of sub-properties. */
3184 while (CONSP (prop
))
3186 if (single_display_prop_string_p (XCAR (prop
), string
))
3191 else if (VECTORP (prop
))
3193 /* A vector of sub-properties. */
3195 for (i
= 0; i
< ASIZE (prop
); ++i
)
3196 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3200 return single_display_prop_string_p (prop
, string
);
3206 /* Determine from which buffer position in W's buffer STRING comes
3207 from. AROUND_CHARPOS is an approximate position where it could
3208 be from. Value is the buffer position or 0 if it couldn't be
3211 W's buffer must be current.
3213 This function is necessary because we don't record buffer positions
3214 in glyphs generated from strings (to keep struct glyph small).
3215 This function may only use code that doesn't eval because it is
3216 called asynchronously from note_mouse_highlight. */
3219 string_buffer_position (w
, string
, around_charpos
)
3224 Lisp_Object limit
, prop
, pos
;
3225 const int MAX_DISTANCE
= 1000;
3228 pos
= make_number (around_charpos
);
3229 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3230 while (!found
&& !EQ (pos
, limit
))
3232 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3233 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3236 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3241 pos
= make_number (around_charpos
);
3242 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3243 while (!found
&& !EQ (pos
, limit
))
3245 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3246 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3249 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3254 return found
? XINT (pos
) : 0;
3259 /***********************************************************************
3260 `composition' property
3261 ***********************************************************************/
3263 /* Set up iterator IT from `composition' property at its current
3264 position. Called from handle_stop. */
3266 static enum prop_handled
3267 handle_composition_prop (it
)
3270 Lisp_Object prop
, string
;
3271 int pos
, pos_byte
, end
;
3272 enum prop_handled handled
= HANDLED_NORMALLY
;
3274 if (STRINGP (it
->string
))
3276 pos
= IT_STRING_CHARPOS (*it
);
3277 pos_byte
= IT_STRING_BYTEPOS (*it
);
3278 string
= it
->string
;
3282 pos
= IT_CHARPOS (*it
);
3283 pos_byte
= IT_BYTEPOS (*it
);
3287 /* If there's a valid composition and point is not inside of the
3288 composition (in the case that the composition is from the current
3289 buffer), draw a glyph composed from the composition components. */
3290 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3291 && COMPOSITION_VALID_P (pos
, end
, prop
)
3292 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3294 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3298 it
->method
= next_element_from_composition
;
3300 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3301 /* For a terminal, draw only the first character of the
3303 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3304 it
->len
= (STRINGP (it
->string
)
3305 ? string_char_to_byte (it
->string
, end
)
3306 : CHAR_TO_BYTE (end
)) - pos_byte
;
3307 it
->stop_charpos
= end
;
3308 handled
= HANDLED_RETURN
;
3317 /***********************************************************************
3319 ***********************************************************************/
3321 /* The following structure is used to record overlay strings for
3322 later sorting in load_overlay_strings. */
3324 struct overlay_entry
3326 Lisp_Object overlay
;
3333 /* Set up iterator IT from overlay strings at its current position.
3334 Called from handle_stop. */
3336 static enum prop_handled
3337 handle_overlay_change (it
)
3340 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3341 return HANDLED_RECOMPUTE_PROPS
;
3343 return HANDLED_NORMALLY
;
3347 /* Set up the next overlay string for delivery by IT, if there is an
3348 overlay string to deliver. Called by set_iterator_to_next when the
3349 end of the current overlay string is reached. If there are more
3350 overlay strings to display, IT->string and
3351 IT->current.overlay_string_index are set appropriately here.
3352 Otherwise IT->string is set to nil. */
3355 next_overlay_string (it
)
3358 ++it
->current
.overlay_string_index
;
3359 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3361 /* No more overlay strings. Restore IT's settings to what
3362 they were before overlay strings were processed, and
3363 continue to deliver from current_buffer. */
3364 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3367 xassert (it
->stop_charpos
>= BEGV
3368 && it
->stop_charpos
<= it
->end_charpos
);
3370 it
->current
.overlay_string_index
= -1;
3371 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3372 it
->n_overlay_strings
= 0;
3373 it
->method
= next_element_from_buffer
;
3375 /* If we're at the end of the buffer, record that we have
3376 processed the overlay strings there already, so that
3377 next_element_from_buffer doesn't try it again. */
3378 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3379 it
->overlay_strings_at_end_processed_p
= 1;
3381 /* If we have to display `...' for invisible text, set
3382 the iterator up for that. */
3383 if (display_ellipsis_p
)
3384 setup_for_ellipsis (it
);
3388 /* There are more overlay strings to process. If
3389 IT->current.overlay_string_index has advanced to a position
3390 where we must load IT->overlay_strings with more strings, do
3392 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3394 if (it
->current
.overlay_string_index
&& i
== 0)
3395 load_overlay_strings (it
, 0);
3397 /* Initialize IT to deliver display elements from the overlay
3399 it
->string
= it
->overlay_strings
[i
];
3400 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3401 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3402 it
->method
= next_element_from_string
;
3403 it
->stop_charpos
= 0;
3410 /* Compare two overlay_entry structures E1 and E2. Used as a
3411 comparison function for qsort in load_overlay_strings. Overlay
3412 strings for the same position are sorted so that
3414 1. All after-strings come in front of before-strings, except
3415 when they come from the same overlay.
3417 2. Within after-strings, strings are sorted so that overlay strings
3418 from overlays with higher priorities come first.
3420 2. Within before-strings, strings are sorted so that overlay
3421 strings from overlays with higher priorities come last.
3423 Value is analogous to strcmp. */
3427 compare_overlay_entries (e1
, e2
)
3430 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3431 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3434 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3436 /* Let after-strings appear in front of before-strings if
3437 they come from different overlays. */
3438 if (EQ (entry1
->overlay
, entry2
->overlay
))
3439 result
= entry1
->after_string_p
? 1 : -1;
3441 result
= entry1
->after_string_p
? -1 : 1;
3443 else if (entry1
->after_string_p
)
3444 /* After-strings sorted in order of decreasing priority. */
3445 result
= entry2
->priority
- entry1
->priority
;
3447 /* Before-strings sorted in order of increasing priority. */
3448 result
= entry1
->priority
- entry2
->priority
;
3454 /* Load the vector IT->overlay_strings with overlay strings from IT's
3455 current buffer position, or from CHARPOS if that is > 0. Set
3456 IT->n_overlays to the total number of overlay strings found.
3458 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3459 a time. On entry into load_overlay_strings,
3460 IT->current.overlay_string_index gives the number of overlay
3461 strings that have already been loaded by previous calls to this
3464 IT->add_overlay_start contains an additional overlay start
3465 position to consider for taking overlay strings from, if non-zero.
3466 This position comes into play when the overlay has an `invisible'
3467 property, and both before and after-strings. When we've skipped to
3468 the end of the overlay, because of its `invisible' property, we
3469 nevertheless want its before-string to appear.
3470 IT->add_overlay_start will contain the overlay start position
3473 Overlay strings are sorted so that after-string strings come in
3474 front of before-string strings. Within before and after-strings,
3475 strings are sorted by overlay priority. See also function
3476 compare_overlay_entries. */
3479 load_overlay_strings (it
, charpos
)
3483 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3484 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3487 int n
= 0, i
, j
, invis_p
;
3488 struct overlay_entry
*entries
3489 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3492 charpos
= IT_CHARPOS (*it
);
3494 /* Append the overlay string STRING of overlay OVERLAY to vector
3495 `entries' which has size `size' and currently contains `n'
3496 elements. AFTER_P non-zero means STRING is an after-string of
3498 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3501 Lisp_Object priority; \
3505 int new_size = 2 * size; \
3506 struct overlay_entry *old = entries; \
3508 (struct overlay_entry *) alloca (new_size \
3509 * sizeof *entries); \
3510 bcopy (old, entries, size * sizeof *entries); \
3514 entries[n].string = (STRING); \
3515 entries[n].overlay = (OVERLAY); \
3516 priority = Foverlay_get ((OVERLAY), Qpriority); \
3517 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3518 entries[n].after_string_p = (AFTER_P); \
3523 /* Process overlay before the overlay center. */
3524 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3526 overlay
= XCAR (ov
);
3527 xassert (OVERLAYP (overlay
));
3528 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3529 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3534 /* Skip this overlay if it doesn't start or end at IT's current
3536 if (end
!= charpos
&& start
!= charpos
)
3539 /* Skip this overlay if it doesn't apply to IT->w. */
3540 window
= Foverlay_get (overlay
, Qwindow
);
3541 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3544 /* If the text ``under'' the overlay is invisible, both before-
3545 and after-strings from this overlay are visible; start and
3546 end position are indistinguishable. */
3547 invisible
= Foverlay_get (overlay
, Qinvisible
);
3548 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3550 /* If overlay has a non-empty before-string, record it. */
3551 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3552 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3553 && XSTRING (str
)->size
)
3554 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3556 /* If overlay has a non-empty after-string, record it. */
3557 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3558 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3559 && XSTRING (str
)->size
)
3560 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3563 /* Process overlays after the overlay center. */
3564 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3566 overlay
= XCAR (ov
);
3567 xassert (OVERLAYP (overlay
));
3568 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3569 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3571 if (start
> charpos
)
3574 /* Skip this overlay if it doesn't start or end at IT's current
3576 if (end
!= charpos
&& start
!= charpos
)
3579 /* Skip this overlay if it doesn't apply to IT->w. */
3580 window
= Foverlay_get (overlay
, Qwindow
);
3581 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3584 /* If the text ``under'' the overlay is invisible, it has a zero
3585 dimension, and both before- and after-strings apply. */
3586 invisible
= Foverlay_get (overlay
, Qinvisible
);
3587 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3589 /* If overlay has a non-empty before-string, record it. */
3590 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3591 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3592 && XSTRING (str
)->size
)
3593 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3595 /* If overlay has a non-empty after-string, record it. */
3596 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3597 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3598 && XSTRING (str
)->size
)
3599 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3602 #undef RECORD_OVERLAY_STRING
3606 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3608 /* Record the total number of strings to process. */
3609 it
->n_overlay_strings
= n
;
3611 /* IT->current.overlay_string_index is the number of overlay strings
3612 that have already been consumed by IT. Copy some of the
3613 remaining overlay strings to IT->overlay_strings. */
3615 j
= it
->current
.overlay_string_index
;
3616 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3617 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3623 /* Get the first chunk of overlay strings at IT's current buffer
3624 position, or at CHARPOS if that is > 0. Value is non-zero if at
3625 least one overlay string was found. */
3628 get_overlay_strings (it
, charpos
)
3632 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3633 process. This fills IT->overlay_strings with strings, and sets
3634 IT->n_overlay_strings to the total number of strings to process.
3635 IT->pos.overlay_string_index has to be set temporarily to zero
3636 because load_overlay_strings needs this; it must be set to -1
3637 when no overlay strings are found because a zero value would
3638 indicate a position in the first overlay string. */
3639 it
->current
.overlay_string_index
= 0;
3640 load_overlay_strings (it
, charpos
);
3642 /* If we found overlay strings, set up IT to deliver display
3643 elements from the first one. Otherwise set up IT to deliver
3644 from current_buffer. */
3645 if (it
->n_overlay_strings
)
3647 /* Make sure we know settings in current_buffer, so that we can
3648 restore meaningful values when we're done with the overlay
3650 compute_stop_pos (it
);
3651 xassert (it
->face_id
>= 0);
3653 /* Save IT's settings. They are restored after all overlay
3654 strings have been processed. */
3655 xassert (it
->sp
== 0);
3658 /* Set up IT to deliver display elements from the first overlay
3660 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3661 it
->string
= it
->overlay_strings
[0];
3662 it
->stop_charpos
= 0;
3663 it
->end_charpos
= XSTRING (it
->string
)->size
;
3664 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3665 xassert (STRINGP (it
->string
));
3666 it
->method
= next_element_from_string
;
3671 it
->current
.overlay_string_index
= -1;
3672 it
->method
= next_element_from_buffer
;
3677 /* Value is non-zero if we found at least one overlay string. */
3678 return STRINGP (it
->string
);
3683 /***********************************************************************
3684 Saving and restoring state
3685 ***********************************************************************/
3687 /* Save current settings of IT on IT->stack. Called, for example,
3688 before setting up IT for an overlay string, to be able to restore
3689 IT's settings to what they were after the overlay string has been
3696 struct iterator_stack_entry
*p
;
3698 xassert (it
->sp
< 2);
3699 p
= it
->stack
+ it
->sp
;
3701 p
->stop_charpos
= it
->stop_charpos
;
3702 xassert (it
->face_id
>= 0);
3703 p
->face_id
= it
->face_id
;
3704 p
->string
= it
->string
;
3705 p
->pos
= it
->current
;
3706 p
->end_charpos
= it
->end_charpos
;
3707 p
->string_nchars
= it
->string_nchars
;
3709 p
->multibyte_p
= it
->multibyte_p
;
3710 p
->space_width
= it
->space_width
;
3711 p
->font_height
= it
->font_height
;
3712 p
->voffset
= it
->voffset
;
3713 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3714 p
->display_ellipsis_p
= 0;
3719 /* Restore IT's settings from IT->stack. Called, for example, when no
3720 more overlay strings must be processed, and we return to delivering
3721 display elements from a buffer, or when the end of a string from a
3722 `display' property is reached and we return to delivering display
3723 elements from an overlay string, or from a buffer. */
3729 struct iterator_stack_entry
*p
;
3731 xassert (it
->sp
> 0);
3733 p
= it
->stack
+ it
->sp
;
3734 it
->stop_charpos
= p
->stop_charpos
;
3735 it
->face_id
= p
->face_id
;
3736 it
->string
= p
->string
;
3737 it
->current
= p
->pos
;
3738 it
->end_charpos
= p
->end_charpos
;
3739 it
->string_nchars
= p
->string_nchars
;
3741 it
->multibyte_p
= p
->multibyte_p
;
3742 it
->space_width
= p
->space_width
;
3743 it
->font_height
= p
->font_height
;
3744 it
->voffset
= p
->voffset
;
3745 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3750 /***********************************************************************
3752 ***********************************************************************/
3754 /* Set IT's current position to the previous line start. */
3757 back_to_previous_line_start (it
)
3760 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3761 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3765 /* Move IT to the next line start.
3767 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3768 we skipped over part of the text (as opposed to moving the iterator
3769 continuously over the text). Otherwise, don't change the value
3772 Newlines may come from buffer text, overlay strings, or strings
3773 displayed via the `display' property. That's the reason we can't
3774 simply use find_next_newline_no_quit.
3776 Note that this function may not skip over invisible text that is so
3777 because of text properties and immediately follows a newline. If
3778 it would, function reseat_at_next_visible_line_start, when called
3779 from set_iterator_to_next, would effectively make invisible
3780 characters following a newline part of the wrong glyph row, which
3781 leads to wrong cursor motion. */
3784 forward_to_next_line_start (it
, skipped_p
)
3788 int old_selective
, newline_found_p
, n
;
3789 const int MAX_NEWLINE_DISTANCE
= 500;
3791 /* If already on a newline, just consume it to avoid unintended
3792 skipping over invisible text below. */
3793 if (it
->what
== IT_CHARACTER
3795 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3797 set_iterator_to_next (it
, 0);
3802 /* Don't handle selective display in the following. It's (a)
3803 unnecessary because it's done by the caller, and (b) leads to an
3804 infinite recursion because next_element_from_ellipsis indirectly
3805 calls this function. */
3806 old_selective
= it
->selective
;
3809 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3810 from buffer text. */
3811 for (n
= newline_found_p
= 0;
3812 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3813 n
+= STRINGP (it
->string
) ? 0 : 1)
3815 if (!get_next_display_element (it
))
3817 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3818 set_iterator_to_next (it
, 0);
3821 /* If we didn't find a newline near enough, see if we can use a
3823 if (n
== MAX_NEWLINE_DISTANCE
)
3825 int start
= IT_CHARPOS (*it
);
3826 int limit
= find_next_newline_no_quit (start
, 1);
3829 xassert (!STRINGP (it
->string
));
3831 /* If there isn't any `display' property in sight, and no
3832 overlays, we can just use the position of the newline in
3834 if (it
->stop_charpos
>= limit
3835 || ((pos
= Fnext_single_property_change (make_number (start
),
3837 Qnil
, make_number (limit
)),
3839 && next_overlay_change (start
) == ZV
))
3841 IT_CHARPOS (*it
) = limit
;
3842 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3843 *skipped_p
= newline_found_p
= 1;
3847 while (get_next_display_element (it
)
3848 && !newline_found_p
)
3850 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3851 set_iterator_to_next (it
, 0);
3856 it
->selective
= old_selective
;
3857 return newline_found_p
;
3861 /* Set IT's current position to the previous visible line start. Skip
3862 invisible text that is so either due to text properties or due to
3863 selective display. Caution: this does not change IT->current_x and
3867 back_to_previous_visible_line_start (it
)
3872 /* Go back one newline if not on BEGV already. */
3873 if (IT_CHARPOS (*it
) > BEGV
)
3874 back_to_previous_line_start (it
);
3876 /* Move over lines that are invisible because of selective display
3877 or text properties. */
3878 while (IT_CHARPOS (*it
) > BEGV
3883 /* If selective > 0, then lines indented more than that values
3885 if (it
->selective
> 0
3886 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3893 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3894 Qinvisible
, it
->window
);
3895 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3899 /* Back one more newline if the current one is invisible. */
3901 back_to_previous_line_start (it
);
3904 xassert (IT_CHARPOS (*it
) >= BEGV
);
3905 xassert (IT_CHARPOS (*it
) == BEGV
3906 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3911 /* Reseat iterator IT at the previous visible line start. Skip
3912 invisible text that is so either due to text properties or due to
3913 selective display. At the end, update IT's overlay information,
3914 face information etc. */
3917 reseat_at_previous_visible_line_start (it
)
3920 back_to_previous_visible_line_start (it
);
3921 reseat (it
, it
->current
.pos
, 1);
3926 /* Reseat iterator IT on the next visible line start in the current
3927 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3928 preceding the line start. Skip over invisible text that is so
3929 because of selective display. Compute faces, overlays etc at the
3930 new position. Note that this function does not skip over text that
3931 is invisible because of text properties. */
3934 reseat_at_next_visible_line_start (it
, on_newline_p
)
3938 int newline_found_p
, skipped_p
= 0;
3940 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3942 /* Skip over lines that are invisible because they are indented
3943 more than the value of IT->selective. */
3944 if (it
->selective
> 0)
3945 while (IT_CHARPOS (*it
) < ZV
3946 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3949 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3950 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3953 /* Position on the newline if that's what's requested. */
3954 if (on_newline_p
&& newline_found_p
)
3956 if (STRINGP (it
->string
))
3958 if (IT_STRING_CHARPOS (*it
) > 0)
3960 --IT_STRING_CHARPOS (*it
);
3961 --IT_STRING_BYTEPOS (*it
);
3964 else if (IT_CHARPOS (*it
) > BEGV
)
3968 reseat (it
, it
->current
.pos
, 0);
3972 reseat (it
, it
->current
.pos
, 0);
3979 /***********************************************************************
3980 Changing an iterator's position
3981 ***********************************************************************/
3983 /* Change IT's current position to POS in current_buffer. If FORCE_P
3984 is non-zero, always check for text properties at the new position.
3985 Otherwise, text properties are only looked up if POS >=
3986 IT->check_charpos of a property. */
3989 reseat (it
, pos
, force_p
)
3991 struct text_pos pos
;
3994 int original_pos
= IT_CHARPOS (*it
);
3996 reseat_1 (it
, pos
, 0);
3998 /* Determine where to check text properties. Avoid doing it
3999 where possible because text property lookup is very expensive. */
4001 || CHARPOS (pos
) > it
->stop_charpos
4002 || CHARPOS (pos
) < original_pos
)
4009 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4010 IT->stop_pos to POS, also. */
4013 reseat_1 (it
, pos
, set_stop_p
)
4015 struct text_pos pos
;
4018 /* Don't call this function when scanning a C string. */
4019 xassert (it
->s
== NULL
);
4021 /* POS must be a reasonable value. */
4022 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4024 it
->current
.pos
= it
->position
= pos
;
4025 XSETBUFFER (it
->object
, current_buffer
);
4026 it
->end_charpos
= ZV
;
4028 it
->current
.dpvec_index
= -1;
4029 it
->current
.overlay_string_index
= -1;
4030 IT_STRING_CHARPOS (*it
) = -1;
4031 IT_STRING_BYTEPOS (*it
) = -1;
4033 it
->method
= next_element_from_buffer
;
4034 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4036 it
->face_before_selective_p
= 0;
4039 it
->stop_charpos
= CHARPOS (pos
);
4043 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4044 If S is non-null, it is a C string to iterate over. Otherwise,
4045 STRING gives a Lisp string to iterate over.
4047 If PRECISION > 0, don't return more then PRECISION number of
4048 characters from the string.
4050 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4051 characters have been returned. FIELD_WIDTH < 0 means an infinite
4054 MULTIBYTE = 0 means disable processing of multibyte characters,
4055 MULTIBYTE > 0 means enable it,
4056 MULTIBYTE < 0 means use IT->multibyte_p.
4058 IT must be initialized via a prior call to init_iterator before
4059 calling this function. */
4062 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4067 int precision
, field_width
, multibyte
;
4069 /* No region in strings. */
4070 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4072 /* No text property checks performed by default, but see below. */
4073 it
->stop_charpos
= -1;
4075 /* Set iterator position and end position. */
4076 bzero (&it
->current
, sizeof it
->current
);
4077 it
->current
.overlay_string_index
= -1;
4078 it
->current
.dpvec_index
= -1;
4079 xassert (charpos
>= 0);
4081 /* If STRING is specified, use its multibyteness, otherwise use the
4082 setting of MULTIBYTE, if specified. */
4084 it
->multibyte_p
= multibyte
> 0;
4088 xassert (STRINGP (string
));
4089 it
->string
= string
;
4091 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
4092 it
->method
= next_element_from_string
;
4093 it
->current
.string_pos
= string_pos (charpos
, string
);
4100 /* Note that we use IT->current.pos, not it->current.string_pos,
4101 for displaying C strings. */
4102 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4103 if (it
->multibyte_p
)
4105 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4106 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4110 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4111 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4114 it
->method
= next_element_from_c_string
;
4117 /* PRECISION > 0 means don't return more than PRECISION characters
4119 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4120 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4122 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4123 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4124 FIELD_WIDTH < 0 means infinite field width. This is useful for
4125 padding with `-' at the end of a mode line. */
4126 if (field_width
< 0)
4127 field_width
= INFINITY
;
4128 if (field_width
> it
->end_charpos
- charpos
)
4129 it
->end_charpos
= charpos
+ field_width
;
4131 /* Use the standard display table for displaying strings. */
4132 if (DISP_TABLE_P (Vstandard_display_table
))
4133 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4135 it
->stop_charpos
= charpos
;
4141 /***********************************************************************
4143 ***********************************************************************/
4145 /* Load IT's display element fields with information about the next
4146 display element from the current position of IT. Value is zero if
4147 end of buffer (or C string) is reached. */
4150 get_next_display_element (it
)
4153 /* Non-zero means that we found an display element. Zero means that
4154 we hit the end of what we iterate over. Performance note: the
4155 function pointer `method' used here turns out to be faster than
4156 using a sequence of if-statements. */
4157 int success_p
= (*it
->method
) (it
);
4159 if (it
->what
== IT_CHARACTER
)
4161 /* Map via display table or translate control characters.
4162 IT->c, IT->len etc. have been set to the next character by
4163 the function call above. If we have a display table, and it
4164 contains an entry for IT->c, translate it. Don't do this if
4165 IT->c itself comes from a display table, otherwise we could
4166 end up in an infinite recursion. (An alternative could be to
4167 count the recursion depth of this function and signal an
4168 error when a certain maximum depth is reached.) Is it worth
4170 if (success_p
&& it
->dpvec
== NULL
)
4175 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4178 struct Lisp_Vector
*v
= XVECTOR (dv
);
4180 /* Return the first character from the display table
4181 entry, if not empty. If empty, don't display the
4182 current character. */
4185 it
->dpvec_char_len
= it
->len
;
4186 it
->dpvec
= v
->contents
;
4187 it
->dpend
= v
->contents
+ v
->size
;
4188 it
->current
.dpvec_index
= 0;
4189 it
->method
= next_element_from_display_vector
;
4190 success_p
= get_next_display_element (it
);
4194 set_iterator_to_next (it
, 0);
4195 success_p
= get_next_display_element (it
);
4199 /* Translate control characters into `\003' or `^C' form.
4200 Control characters coming from a display table entry are
4201 currently not translated because we use IT->dpvec to hold
4202 the translation. This could easily be changed but I
4203 don't believe that it is worth doing.
4205 Non-printable multibyte characters are also translated
4207 else if ((it
->c
< ' '
4208 && (it
->area
!= TEXT_AREA
4209 || (it
->c
!= '\n' && it
->c
!= '\t')))
4212 || !CHAR_PRINTABLE_P (it
->c
))
4214 /* IT->c is a control character which must be displayed
4215 either as '\003' or as `^C' where the '\\' and '^'
4216 can be defined in the display table. Fill
4217 IT->ctl_chars with glyphs for what we have to
4218 display. Then, set IT->dpvec to these glyphs. */
4221 if (it
->c
< 128 && it
->ctl_arrow_p
)
4223 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4225 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4226 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4227 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4229 g
= FAST_MAKE_GLYPH ('^', 0);
4230 XSETINT (it
->ctl_chars
[0], g
);
4232 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4233 XSETINT (it
->ctl_chars
[1], g
);
4235 /* Set up IT->dpvec and return first character from it. */
4236 it
->dpvec_char_len
= it
->len
;
4237 it
->dpvec
= it
->ctl_chars
;
4238 it
->dpend
= it
->dpvec
+ 2;
4239 it
->current
.dpvec_index
= 0;
4240 it
->method
= next_element_from_display_vector
;
4241 get_next_display_element (it
);
4245 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4250 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4252 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4253 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4254 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4256 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4258 if (SINGLE_BYTE_CHAR_P (it
->c
))
4259 str
[0] = it
->c
, len
= 1;
4262 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4265 /* It's an invalid character, which
4266 shouldn't happen actually, but due to
4267 bugs it may happen. Let's print the char
4268 as is, there's not much meaningful we can
4271 str
[1] = it
->c
>> 8;
4272 str
[2] = it
->c
>> 16;
4273 str
[3] = it
->c
>> 24;
4278 for (i
= 0; i
< len
; i
++)
4280 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4281 /* Insert three more glyphs into IT->ctl_chars for
4282 the octal display of the character. */
4283 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4284 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4285 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4286 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4287 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4288 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4291 /* Set up IT->dpvec and return the first character
4293 it
->dpvec_char_len
= it
->len
;
4294 it
->dpvec
= it
->ctl_chars
;
4295 it
->dpend
= it
->dpvec
+ len
* 4;
4296 it
->current
.dpvec_index
= 0;
4297 it
->method
= next_element_from_display_vector
;
4298 get_next_display_element (it
);
4303 /* Adjust face id for a multibyte character. There are no
4304 multibyte character in unibyte text. */
4307 && FRAME_WINDOW_P (it
->f
))
4309 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4310 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4314 /* Is this character the last one of a run of characters with
4315 box? If yes, set IT->end_of_box_run_p to 1. */
4322 it
->end_of_box_run_p
4323 = ((face_id
= face_after_it_pos (it
),
4324 face_id
!= it
->face_id
)
4325 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4326 face
->box
== FACE_NO_BOX
));
4329 /* Value is 0 if end of buffer or string reached. */
4334 /* Move IT to the next display element.
4336 RESEAT_P non-zero means if called on a newline in buffer text,
4337 skip to the next visible line start.
4339 Functions get_next_display_element and set_iterator_to_next are
4340 separate because I find this arrangement easier to handle than a
4341 get_next_display_element function that also increments IT's
4342 position. The way it is we can first look at an iterator's current
4343 display element, decide whether it fits on a line, and if it does,
4344 increment the iterator position. The other way around we probably
4345 would either need a flag indicating whether the iterator has to be
4346 incremented the next time, or we would have to implement a
4347 decrement position function which would not be easy to write. */
4350 set_iterator_to_next (it
, reseat_p
)
4354 /* Reset flags indicating start and end of a sequence of characters
4355 with box. Reset them at the start of this function because
4356 moving the iterator to a new position might set them. */
4357 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4359 if (it
->method
== next_element_from_buffer
)
4361 /* The current display element of IT is a character from
4362 current_buffer. Advance in the buffer, and maybe skip over
4363 invisible lines that are so because of selective display. */
4364 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4365 reseat_at_next_visible_line_start (it
, 0);
4368 xassert (it
->len
!= 0);
4369 IT_BYTEPOS (*it
) += it
->len
;
4370 IT_CHARPOS (*it
) += 1;
4371 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4374 else if (it
->method
== next_element_from_composition
)
4376 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4377 if (STRINGP (it
->string
))
4379 IT_STRING_BYTEPOS (*it
) += it
->len
;
4380 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4381 it
->method
= next_element_from_string
;
4382 goto consider_string_end
;
4386 IT_BYTEPOS (*it
) += it
->len
;
4387 IT_CHARPOS (*it
) += it
->cmp_len
;
4388 it
->method
= next_element_from_buffer
;
4391 else if (it
->method
== next_element_from_c_string
)
4393 /* Current display element of IT is from a C string. */
4394 IT_BYTEPOS (*it
) += it
->len
;
4395 IT_CHARPOS (*it
) += 1;
4397 else if (it
->method
== next_element_from_display_vector
)
4399 /* Current display element of IT is from a display table entry.
4400 Advance in the display table definition. Reset it to null if
4401 end reached, and continue with characters from buffers/
4403 ++it
->current
.dpvec_index
;
4405 /* Restore face of the iterator to what they were before the
4406 display vector entry (these entries may contain faces). */
4407 it
->face_id
= it
->saved_face_id
;
4409 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4412 it
->method
= next_element_from_c_string
;
4413 else if (STRINGP (it
->string
))
4414 it
->method
= next_element_from_string
;
4416 it
->method
= next_element_from_buffer
;
4419 it
->current
.dpvec_index
= -1;
4421 /* Skip over characters which were displayed via IT->dpvec. */
4422 if (it
->dpvec_char_len
< 0)
4423 reseat_at_next_visible_line_start (it
, 1);
4424 else if (it
->dpvec_char_len
> 0)
4426 it
->len
= it
->dpvec_char_len
;
4427 set_iterator_to_next (it
, reseat_p
);
4431 else if (it
->method
== next_element_from_string
)
4433 /* Current display element is a character from a Lisp string. */
4434 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4435 IT_STRING_BYTEPOS (*it
) += it
->len
;
4436 IT_STRING_CHARPOS (*it
) += 1;
4438 consider_string_end
:
4440 if (it
->current
.overlay_string_index
>= 0)
4442 /* IT->string is an overlay string. Advance to the
4443 next, if there is one. */
4444 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4445 next_overlay_string (it
);
4449 /* IT->string is not an overlay string. If we reached
4450 its end, and there is something on IT->stack, proceed
4451 with what is on the stack. This can be either another
4452 string, this time an overlay string, or a buffer. */
4453 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4457 if (!STRINGP (it
->string
))
4458 it
->method
= next_element_from_buffer
;
4460 goto consider_string_end
;
4464 else if (it
->method
== next_element_from_image
4465 || it
->method
== next_element_from_stretch
)
4467 /* The position etc with which we have to proceed are on
4468 the stack. The position may be at the end of a string,
4469 if the `display' property takes up the whole string. */
4472 if (STRINGP (it
->string
))
4474 it
->method
= next_element_from_string
;
4475 goto consider_string_end
;
4478 it
->method
= next_element_from_buffer
;
4481 /* There are no other methods defined, so this should be a bug. */
4484 xassert (it
->method
!= next_element_from_string
4485 || (STRINGP (it
->string
)
4486 && IT_STRING_CHARPOS (*it
) >= 0));
4490 /* Load IT's display element fields with information about the next
4491 display element which comes from a display table entry or from the
4492 result of translating a control character to one of the forms `^C'
4493 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4496 next_element_from_display_vector (it
)
4500 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4502 /* Remember the current face id in case glyphs specify faces.
4503 IT's face is restored in set_iterator_to_next. */
4504 it
->saved_face_id
= it
->face_id
;
4506 if (INTEGERP (*it
->dpvec
)
4507 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4512 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4513 it
->c
= FAST_GLYPH_CHAR (g
);
4514 it
->len
= CHAR_BYTES (it
->c
);
4516 /* The entry may contain a face id to use. Such a face id is
4517 the id of a Lisp face, not a realized face. A face id of
4518 zero means no face is specified. */
4519 lface_id
= FAST_GLYPH_FACE (g
);
4522 /* The function returns -1 if lface_id is invalid. */
4523 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4525 it
->face_id
= face_id
;
4529 /* Display table entry is invalid. Return a space. */
4530 it
->c
= ' ', it
->len
= 1;
4532 /* Don't change position and object of the iterator here. They are
4533 still the values of the character that had this display table
4534 entry or was translated, and that's what we want. */
4535 it
->what
= IT_CHARACTER
;
4540 /* Load IT with the next display element from Lisp string IT->string.
4541 IT->current.string_pos is the current position within the string.
4542 If IT->current.overlay_string_index >= 0, the Lisp string is an
4546 next_element_from_string (it
)
4549 struct text_pos position
;
4551 xassert (STRINGP (it
->string
));
4552 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4553 position
= it
->current
.string_pos
;
4555 /* Time to check for invisible text? */
4556 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4557 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4561 /* Since a handler may have changed IT->method, we must
4563 return get_next_display_element (it
);
4566 if (it
->current
.overlay_string_index
>= 0)
4568 /* Get the next character from an overlay string. In overlay
4569 strings, There is no field width or padding with spaces to
4571 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4576 else if (STRING_MULTIBYTE (it
->string
))
4578 int remaining
= (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
, remaining
, &it
->len
);
4586 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4592 /* Get the next character from a Lisp string that is not an
4593 overlay string. Such strings come from the mode line, for
4594 example. We may have to pad with spaces, or truncate the
4595 string. See also next_element_from_c_string. */
4596 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4601 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4603 /* Pad with spaces. */
4604 it
->c
= ' ', it
->len
= 1;
4605 CHARPOS (position
) = BYTEPOS (position
) = -1;
4607 else if (STRING_MULTIBYTE (it
->string
))
4609 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4610 - IT_STRING_BYTEPOS (*it
));
4611 unsigned char *s
= (XSTRING (it
->string
)->data
4612 + IT_STRING_BYTEPOS (*it
));
4613 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4617 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4622 /* Record what we have and where it came from. Note that we store a
4623 buffer position in IT->position although it could arguably be a
4625 it
->what
= IT_CHARACTER
;
4626 it
->object
= it
->string
;
4627 it
->position
= position
;
4632 /* Load IT with next display element from C string IT->s.
4633 IT->string_nchars is the maximum number of characters to return
4634 from the string. IT->end_charpos may be greater than
4635 IT->string_nchars when this function is called, in which case we
4636 may have to return padding spaces. Value is zero if end of string
4637 reached, including padding spaces. */
4640 next_element_from_c_string (it
)
4646 it
->what
= IT_CHARACTER
;
4647 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4650 /* IT's position can be greater IT->string_nchars in case a field
4651 width or precision has been specified when the iterator was
4653 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4655 /* End of the game. */
4659 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4661 /* Pad with spaces. */
4662 it
->c
= ' ', it
->len
= 1;
4663 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4665 else if (it
->multibyte_p
)
4667 /* Implementation note: The calls to strlen apparently aren't a
4668 performance problem because there is no noticeable performance
4669 difference between Emacs running in unibyte or multibyte mode. */
4670 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4671 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4675 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4681 /* Set up IT to return characters from an ellipsis, if appropriate.
4682 The definition of the ellipsis glyphs may come from a display table
4683 entry. This function Fills IT with the first glyph from the
4684 ellipsis if an ellipsis is to be displayed. */
4687 next_element_from_ellipsis (it
)
4690 if (it
->selective_display_ellipsis_p
)
4692 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4694 /* Use the display table definition for `...'. Invalid glyphs
4695 will be handled by the method returning elements from dpvec. */
4696 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4697 it
->dpvec_char_len
= it
->len
;
4698 it
->dpvec
= v
->contents
;
4699 it
->dpend
= v
->contents
+ v
->size
;
4700 it
->current
.dpvec_index
= 0;
4701 it
->method
= next_element_from_display_vector
;
4705 /* Use default `...' which is stored in default_invis_vector. */
4706 it
->dpvec_char_len
= it
->len
;
4707 it
->dpvec
= default_invis_vector
;
4708 it
->dpend
= default_invis_vector
+ 3;
4709 it
->current
.dpvec_index
= 0;
4710 it
->method
= next_element_from_display_vector
;
4715 /* The face at the current position may be different from the
4716 face we find after the invisible text. Remember what it
4717 was in IT->saved_face_id, and signal that it's there by
4718 setting face_before_selective_p. */
4719 it
->saved_face_id
= it
->face_id
;
4720 it
->method
= next_element_from_buffer
;
4721 reseat_at_next_visible_line_start (it
, 1);
4722 it
->face_before_selective_p
= 1;
4725 return get_next_display_element (it
);
4729 /* Deliver an image display element. The iterator IT is already
4730 filled with image information (done in handle_display_prop). Value
4735 next_element_from_image (it
)
4738 it
->what
= IT_IMAGE
;
4743 /* Fill iterator IT with next display element from a stretch glyph
4744 property. IT->object is the value of the text property. Value is
4748 next_element_from_stretch (it
)
4751 it
->what
= IT_STRETCH
;
4756 /* Load IT with the next display element from current_buffer. Value
4757 is zero if end of buffer reached. IT->stop_charpos is the next
4758 position at which to stop and check for text properties or buffer
4762 next_element_from_buffer (it
)
4767 /* Check this assumption, otherwise, we would never enter the
4768 if-statement, below. */
4769 xassert (IT_CHARPOS (*it
) >= BEGV
4770 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4772 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4774 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4776 int overlay_strings_follow_p
;
4778 /* End of the game, except when overlay strings follow that
4779 haven't been returned yet. */
4780 if (it
->overlay_strings_at_end_processed_p
)
4781 overlay_strings_follow_p
= 0;
4784 it
->overlay_strings_at_end_processed_p
= 1;
4785 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4788 if (overlay_strings_follow_p
)
4789 success_p
= get_next_display_element (it
);
4793 it
->position
= it
->current
.pos
;
4800 return get_next_display_element (it
);
4805 /* No face changes, overlays etc. in sight, so just return a
4806 character from current_buffer. */
4809 /* Maybe run the redisplay end trigger hook. Performance note:
4810 This doesn't seem to cost measurable time. */
4811 if (it
->redisplay_end_trigger_charpos
4813 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4814 run_redisplay_end_trigger_hook (it
);
4816 /* Get the next character, maybe multibyte. */
4817 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4818 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4820 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4821 - IT_BYTEPOS (*it
));
4822 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4825 it
->c
= *p
, it
->len
= 1;
4827 /* Record what we have and where it came from. */
4828 it
->what
= IT_CHARACTER
;;
4829 it
->object
= it
->w
->buffer
;
4830 it
->position
= it
->current
.pos
;
4832 /* Normally we return the character found above, except when we
4833 really want to return an ellipsis for selective display. */
4838 /* A value of selective > 0 means hide lines indented more
4839 than that number of columns. */
4840 if (it
->selective
> 0
4841 && IT_CHARPOS (*it
) + 1 < ZV
4842 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4843 IT_BYTEPOS (*it
) + 1,
4846 success_p
= next_element_from_ellipsis (it
);
4847 it
->dpvec_char_len
= -1;
4850 else if (it
->c
== '\r' && it
->selective
== -1)
4852 /* A value of selective == -1 means that everything from the
4853 CR to the end of the line is invisible, with maybe an
4854 ellipsis displayed for it. */
4855 success_p
= next_element_from_ellipsis (it
);
4856 it
->dpvec_char_len
= -1;
4861 /* Value is zero if end of buffer reached. */
4862 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4867 /* Run the redisplay end trigger hook for IT. */
4870 run_redisplay_end_trigger_hook (it
)
4873 Lisp_Object args
[3];
4875 /* IT->glyph_row should be non-null, i.e. we should be actually
4876 displaying something, or otherwise we should not run the hook. */
4877 xassert (it
->glyph_row
);
4879 /* Set up hook arguments. */
4880 args
[0] = Qredisplay_end_trigger_functions
;
4881 args
[1] = it
->window
;
4882 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4883 it
->redisplay_end_trigger_charpos
= 0;
4885 /* Since we are *trying* to run these functions, don't try to run
4886 them again, even if they get an error. */
4887 it
->w
->redisplay_end_trigger
= Qnil
;
4888 Frun_hook_with_args (3, args
);
4890 /* Notice if it changed the face of the character we are on. */
4891 handle_face_prop (it
);
4895 /* Deliver a composition display element. The iterator IT is already
4896 filled with composition information (done in
4897 handle_composition_prop). Value is always 1. */
4900 next_element_from_composition (it
)
4903 it
->what
= IT_COMPOSITION
;
4904 it
->position
= (STRINGP (it
->string
)
4905 ? it
->current
.string_pos
4912 /***********************************************************************
4913 Moving an iterator without producing glyphs
4914 ***********************************************************************/
4916 /* Move iterator IT to a specified buffer or X position within one
4917 line on the display without producing glyphs.
4919 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4920 whichever is reached first.
4922 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4924 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4925 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4926 TO_X includes the amount by which a window is horizontally
4931 MOVE_POS_MATCH_OR_ZV
4932 - when TO_POS or ZV was reached.
4935 -when TO_X was reached before TO_POS or ZV were reached.
4938 - when we reached the end of the display area and the line must
4942 - when we reached the end of the display area and the line is
4946 - when we stopped at a line end, i.e. a newline or a CR and selective
4949 static enum move_it_result
4950 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4952 int to_charpos
, to_x
, op
;
4954 enum move_it_result result
= MOVE_UNDEFINED
;
4955 struct glyph_row
*saved_glyph_row
;
4957 /* Don't produce glyphs in produce_glyphs. */
4958 saved_glyph_row
= it
->glyph_row
;
4959 it
->glyph_row
= NULL
;
4963 int x
, i
, ascent
= 0, descent
= 0;
4965 /* Stop when ZV or TO_CHARPOS reached. */
4966 if (!get_next_display_element (it
)
4967 || ((op
& MOVE_TO_POS
) != 0
4968 && BUFFERP (it
->object
)
4969 && IT_CHARPOS (*it
) >= to_charpos
))
4971 result
= MOVE_POS_MATCH_OR_ZV
;
4975 /* The call to produce_glyphs will get the metrics of the
4976 display element IT is loaded with. We record in x the
4977 x-position before this display element in case it does not
4981 /* Remember the line height so far in case the next element doesn't
4983 if (!it
->truncate_lines_p
)
4985 ascent
= it
->max_ascent
;
4986 descent
= it
->max_descent
;
4989 PRODUCE_GLYPHS (it
);
4991 if (it
->area
!= TEXT_AREA
)
4993 set_iterator_to_next (it
, 1);
4997 /* The number of glyphs we get back in IT->nglyphs will normally
4998 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4999 character on a terminal frame, or (iii) a line end. For the
5000 second case, IT->nglyphs - 1 padding glyphs will be present
5001 (on X frames, there is only one glyph produced for a
5002 composite character.
5004 The behavior implemented below means, for continuation lines,
5005 that as many spaces of a TAB as fit on the current line are
5006 displayed there. For terminal frames, as many glyphs of a
5007 multi-glyph character are displayed in the current line, too.
5008 This is what the old redisplay code did, and we keep it that
5009 way. Under X, the whole shape of a complex character must
5010 fit on the line or it will be completely displayed in the
5013 Note that both for tabs and padding glyphs, all glyphs have
5017 /* More than one glyph or glyph doesn't fit on line. All
5018 glyphs have the same width. */
5019 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5022 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5024 new_x
= x
+ single_glyph_width
;
5026 /* We want to leave anything reaching TO_X to the caller. */
5027 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5030 result
= MOVE_X_REACHED
;
5033 else if (/* Lines are continued. */
5034 !it
->truncate_lines_p
5035 && (/* And glyph doesn't fit on the line. */
5036 new_x
> it
->last_visible_x
5037 /* Or it fits exactly and we're on a window
5039 || (new_x
== it
->last_visible_x
5040 && FRAME_WINDOW_P (it
->f
))))
5042 if (/* IT->hpos == 0 means the very first glyph
5043 doesn't fit on the line, e.g. a wide image. */
5045 || (new_x
== it
->last_visible_x
5046 && FRAME_WINDOW_P (it
->f
)))
5049 it
->current_x
= new_x
;
5050 if (i
== it
->nglyphs
- 1)
5051 set_iterator_to_next (it
, 1);
5056 it
->max_ascent
= ascent
;
5057 it
->max_descent
= descent
;
5060 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5062 result
= MOVE_LINE_CONTINUED
;
5065 else if (new_x
> it
->first_visible_x
)
5067 /* Glyph is visible. Increment number of glyphs that
5068 would be displayed. */
5073 /* Glyph is completely off the left margin of the display
5074 area. Nothing to do. */
5078 if (result
!= MOVE_UNDEFINED
)
5081 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5083 /* Stop when TO_X specified and reached. This check is
5084 necessary here because of lines consisting of a line end,
5085 only. The line end will not produce any glyphs and we
5086 would never get MOVE_X_REACHED. */
5087 xassert (it
->nglyphs
== 0);
5088 result
= MOVE_X_REACHED
;
5092 /* Is this a line end? If yes, we're done. */
5093 if (ITERATOR_AT_END_OF_LINE_P (it
))
5095 result
= MOVE_NEWLINE_OR_CR
;
5099 /* The current display element has been consumed. Advance
5101 set_iterator_to_next (it
, 1);
5103 /* Stop if lines are truncated and IT's current x-position is
5104 past the right edge of the window now. */
5105 if (it
->truncate_lines_p
5106 && it
->current_x
>= it
->last_visible_x
)
5108 result
= MOVE_LINE_TRUNCATED
;
5113 /* Restore the iterator settings altered at the beginning of this
5115 it
->glyph_row
= saved_glyph_row
;
5120 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
5121 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
5122 the description of enum move_operation_enum.
5124 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5125 screen line, this function will set IT to the next position >
5129 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5131 int to_charpos
, to_x
, to_y
, to_vpos
;
5134 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5140 if (op
& MOVE_TO_VPOS
)
5142 /* If no TO_CHARPOS and no TO_X specified, stop at the
5143 start of the line TO_VPOS. */
5144 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5146 if (it
->vpos
== to_vpos
)
5152 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5156 /* TO_VPOS >= 0 means stop at TO_X in the line at
5157 TO_VPOS, or at TO_POS, whichever comes first. */
5158 if (it
->vpos
== to_vpos
)
5164 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5166 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5171 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5173 /* We have reached TO_X but not in the line we want. */
5174 skip
= move_it_in_display_line_to (it
, to_charpos
,
5176 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5184 else if (op
& MOVE_TO_Y
)
5186 struct it it_backup
;
5188 /* TO_Y specified means stop at TO_X in the line containing
5189 TO_Y---or at TO_CHARPOS if this is reached first. The
5190 problem is that we can't really tell whether the line
5191 contains TO_Y before we have completely scanned it, and
5192 this may skip past TO_X. What we do is to first scan to
5195 If TO_X is not specified, use a TO_X of zero. The reason
5196 is to make the outcome of this function more predictable.
5197 If we didn't use TO_X == 0, we would stop at the end of
5198 the line which is probably not what a caller would expect
5200 skip
= move_it_in_display_line_to (it
, to_charpos
,
5204 | (op
& MOVE_TO_POS
)));
5206 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5207 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5213 /* If TO_X was reached, we would like to know whether TO_Y
5214 is in the line. This can only be said if we know the
5215 total line height which requires us to scan the rest of
5217 if (skip
== MOVE_X_REACHED
)
5220 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5221 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5223 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5226 /* Now, decide whether TO_Y is in this line. */
5227 line_height
= it
->max_ascent
+ it
->max_descent
;
5228 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5230 if (to_y
>= it
->current_y
5231 && to_y
< it
->current_y
+ line_height
)
5233 if (skip
== MOVE_X_REACHED
)
5234 /* If TO_Y is in this line and TO_X was reached above,
5235 we scanned too far. We have to restore IT's settings
5236 to the ones before skipping. */
5240 else if (skip
== MOVE_X_REACHED
)
5243 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5251 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5255 case MOVE_POS_MATCH_OR_ZV
:
5259 case MOVE_NEWLINE_OR_CR
:
5260 set_iterator_to_next (it
, 1);
5261 it
->continuation_lines_width
= 0;
5264 case MOVE_LINE_TRUNCATED
:
5265 it
->continuation_lines_width
= 0;
5266 reseat_at_next_visible_line_start (it
, 0);
5267 if ((op
& MOVE_TO_POS
) != 0
5268 && IT_CHARPOS (*it
) > to_charpos
)
5275 case MOVE_LINE_CONTINUED
:
5276 it
->continuation_lines_width
+= it
->current_x
;
5283 /* Reset/increment for the next run. */
5284 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5285 it
->current_x
= it
->hpos
= 0;
5286 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5288 last_height
= it
->max_ascent
+ it
->max_descent
;
5289 last_max_ascent
= it
->max_ascent
;
5290 it
->max_ascent
= it
->max_descent
= 0;
5295 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5299 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5301 If DY > 0, move IT backward at least that many pixels. DY = 0
5302 means move IT backward to the preceding line start or BEGV. This
5303 function may move over more than DY pixels if IT->current_y - DY
5304 ends up in the middle of a line; in this case IT->current_y will be
5305 set to the top of the line moved to. */
5308 move_it_vertically_backward (it
, dy
)
5314 int start_pos
= IT_CHARPOS (*it
);
5318 /* Estimate how many newlines we must move back. */
5319 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5321 /* Set the iterator's position that many lines back. */
5322 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5323 back_to_previous_visible_line_start (it
);
5325 /* Reseat the iterator here. When moving backward, we don't want
5326 reseat to skip forward over invisible text, set up the iterator
5327 to deliver from overlay strings at the new position etc. So,
5328 use reseat_1 here. */
5329 reseat_1 (it
, it
->current
.pos
, 1);
5331 /* We are now surely at a line start. */
5332 it
->current_x
= it
->hpos
= 0;
5334 /* Move forward and see what y-distance we moved. First move to the
5335 start of the next line so that we get its height. We need this
5336 height to be able to tell whether we reached the specified
5339 it2
.max_ascent
= it2
.max_descent
= 0;
5340 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5341 MOVE_TO_POS
| MOVE_TO_VPOS
);
5342 xassert (IT_CHARPOS (*it
) >= BEGV
);
5345 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5346 xassert (IT_CHARPOS (*it
) >= BEGV
);
5347 h
= it2
.current_y
- it
->current_y
;
5348 nlines
= it2
.vpos
- it
->vpos
;
5350 /* Correct IT's y and vpos position. */
5356 /* DY == 0 means move to the start of the screen line. The
5357 value of nlines is > 0 if continuation lines were involved. */
5359 move_it_by_lines (it
, nlines
, 1);
5360 xassert (IT_CHARPOS (*it
) <= start_pos
);
5364 /* The y-position we try to reach. Note that h has been
5365 subtracted in front of the if-statement. */
5366 int target_y
= it
->current_y
+ h
- dy
;
5367 int y0
= it3
.current_y
;
5368 int y1
= line_bottom_y (&it3
);
5369 int line_height
= y1
- y0
;
5371 /* If we did not reach target_y, try to move further backward if
5372 we can. If we moved too far backward, try to move forward. */
5373 if (target_y
< it
->current_y
5374 /* This is heuristic. In a window that's 3 lines high, with
5375 a line height of 13 pixels each, recentering with point
5376 on the bottom line will try to move -39/2 = 19 pixels
5377 backward. Try to avoid moving into the first line. */
5378 && it
->current_y
- target_y
> line_height
/ 3 * 2
5379 && IT_CHARPOS (*it
) > BEGV
)
5381 move_it_vertically (it
, target_y
- it
->current_y
);
5382 xassert (IT_CHARPOS (*it
) >= BEGV
);
5384 else if (target_y
>= it
->current_y
+ line_height
5385 && IT_CHARPOS (*it
) < ZV
)
5387 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5388 xassert (IT_CHARPOS (*it
) >= BEGV
);
5394 /* Move IT by a specified amount of pixel lines DY. DY negative means
5395 move backwards. DY = 0 means move to start of screen line. At the
5396 end, IT will be on the start of a screen line. */
5399 move_it_vertically (it
, dy
)
5404 move_it_vertically_backward (it
, -dy
);
5407 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5408 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5409 MOVE_TO_POS
| MOVE_TO_Y
);
5410 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5412 /* If buffer ends in ZV without a newline, move to the start of
5413 the line to satisfy the post-condition. */
5414 if (IT_CHARPOS (*it
) == ZV
5415 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5416 move_it_by_lines (it
, 0, 0);
5421 /* Move iterator IT past the end of the text line it is in. */
5424 move_it_past_eol (it
)
5427 enum move_it_result rc
;
5429 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5430 if (rc
== MOVE_NEWLINE_OR_CR
)
5431 set_iterator_to_next (it
, 0);
5435 #if 0 /* Currently not used. */
5437 /* Return non-zero if some text between buffer positions START_CHARPOS
5438 and END_CHARPOS is invisible. IT->window is the window for text
5442 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5444 int start_charpos
, end_charpos
;
5446 Lisp_Object prop
, limit
;
5447 int invisible_found_p
;
5449 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5451 /* Is text at START invisible? */
5452 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5454 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5455 invisible_found_p
= 1;
5458 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5460 make_number (end_charpos
));
5461 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5464 return invisible_found_p
;
5470 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5471 negative means move up. DVPOS == 0 means move to the start of the
5472 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5473 NEED_Y_P is zero, IT->current_y will be left unchanged.
5475 Further optimization ideas: If we would know that IT->f doesn't use
5476 a face with proportional font, we could be faster for
5477 truncate-lines nil. */
5480 move_it_by_lines (it
, dvpos
, need_y_p
)
5482 int dvpos
, need_y_p
;
5484 struct position pos
;
5486 if (!FRAME_WINDOW_P (it
->f
))
5488 struct text_pos textpos
;
5490 /* We can use vmotion on frames without proportional fonts. */
5491 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5492 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5493 reseat (it
, textpos
, 1);
5494 it
->vpos
+= pos
.vpos
;
5495 it
->current_y
+= pos
.vpos
;
5497 else if (dvpos
== 0)
5499 /* DVPOS == 0 means move to the start of the screen line. */
5500 move_it_vertically_backward (it
, 0);
5501 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5504 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5508 int start_charpos
, i
;
5510 /* Start at the beginning of the screen line containing IT's
5512 move_it_vertically_backward (it
, 0);
5514 /* Go back -DVPOS visible lines and reseat the iterator there. */
5515 start_charpos
= IT_CHARPOS (*it
);
5516 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5517 back_to_previous_visible_line_start (it
);
5518 reseat (it
, it
->current
.pos
, 1);
5519 it
->current_x
= it
->hpos
= 0;
5521 /* Above call may have moved too far if continuation lines
5522 are involved. Scan forward and see if it did. */
5524 it2
.vpos
= it2
.current_y
= 0;
5525 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5526 it
->vpos
-= it2
.vpos
;
5527 it
->current_y
-= it2
.current_y
;
5528 it
->current_x
= it
->hpos
= 0;
5530 /* If we moved too far, move IT some lines forward. */
5531 if (it2
.vpos
> -dvpos
)
5533 int delta
= it2
.vpos
+ dvpos
;
5534 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5541 /***********************************************************************
5543 ***********************************************************************/
5546 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5550 add_to_log (format
, arg1
, arg2
)
5552 Lisp_Object arg1
, arg2
;
5554 Lisp_Object args
[3];
5555 Lisp_Object msg
, fmt
;
5558 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5560 /* Do nothing if called asynchronously. Inserting text into
5561 a buffer may call after-change-functions and alike and
5562 that would means running Lisp asynchronously. */
5563 if (handling_signal
)
5567 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5569 args
[0] = fmt
= build_string (format
);
5572 msg
= Fformat (3, args
);
5574 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5575 buffer
= (char *) alloca (len
);
5576 bcopy (XSTRING (msg
)->data
, buffer
, len
);
5578 message_dolog (buffer
, len
- 1, 1, 0);
5583 /* Output a newline in the *Messages* buffer if "needs" one. */
5586 message_log_maybe_newline ()
5588 if (message_log_need_newline
)
5589 message_dolog ("", 0, 1, 0);
5593 /* Add a string M of length NBYTES to the message log, optionally
5594 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5595 nonzero, means interpret the contents of M as multibyte. This
5596 function calls low-level routines in order to bypass text property
5597 hooks, etc. which might not be safe to run. */
5600 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5602 int nbytes
, nlflag
, multibyte
;
5604 if (!NILP (Vmessage_log_max
))
5606 struct buffer
*oldbuf
;
5607 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5608 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5609 int point_at_end
= 0;
5611 Lisp_Object old_deactivate_mark
, tem
;
5612 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5614 old_deactivate_mark
= Vdeactivate_mark
;
5615 oldbuf
= current_buffer
;
5616 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5617 current_buffer
->undo_list
= Qt
;
5619 oldpoint
= Fpoint_marker ();
5620 oldbegv
= Fpoint_min_marker ();
5621 oldzv
= Fpoint_max_marker ();
5622 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5630 BEGV_BYTE
= BEG_BYTE
;
5633 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5635 /* Insert the string--maybe converting multibyte to single byte
5636 or vice versa, so that all the text fits the buffer. */
5638 && NILP (current_buffer
->enable_multibyte_characters
))
5640 int i
, c
, char_bytes
;
5641 unsigned char work
[1];
5643 /* Convert a multibyte string to single-byte
5644 for the *Message* buffer. */
5645 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5647 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5648 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5650 : multibyte_char_to_unibyte (c
, Qnil
));
5651 insert_1_both (work
, 1, 1, 1, 0, 0);
5654 else if (! multibyte
5655 && ! NILP (current_buffer
->enable_multibyte_characters
))
5657 int i
, c
, char_bytes
;
5658 unsigned char *msg
= (unsigned char *) m
;
5659 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5660 /* Convert a single-byte string to multibyte
5661 for the *Message* buffer. */
5662 for (i
= 0; i
< nbytes
; i
++)
5664 c
= unibyte_char_to_multibyte (msg
[i
]);
5665 char_bytes
= CHAR_STRING (c
, str
);
5666 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5670 insert_1 (m
, nbytes
, 1, 0, 0);
5674 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5675 insert_1 ("\n", 1, 1, 0, 0);
5677 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5679 this_bol_byte
= PT_BYTE
;
5683 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5685 prev_bol_byte
= PT_BYTE
;
5687 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5688 this_bol
, this_bol_byte
);
5691 del_range_both (prev_bol
, prev_bol_byte
,
5692 this_bol
, this_bol_byte
, 0);
5698 /* If you change this format, don't forget to also
5699 change message_log_check_duplicate. */
5700 sprintf (dupstr
, " [%d times]", dup
);
5701 duplen
= strlen (dupstr
);
5702 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5703 insert_1 (dupstr
, duplen
, 1, 0, 1);
5708 if (NATNUMP (Vmessage_log_max
))
5710 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5711 -XFASTINT (Vmessage_log_max
) - 1, 0);
5712 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5715 BEGV
= XMARKER (oldbegv
)->charpos
;
5716 BEGV_BYTE
= marker_byte_position (oldbegv
);
5725 ZV
= XMARKER (oldzv
)->charpos
;
5726 ZV_BYTE
= marker_byte_position (oldzv
);
5730 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5732 /* We can't do Fgoto_char (oldpoint) because it will run some
5734 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5735 XMARKER (oldpoint
)->bytepos
);
5738 free_marker (oldpoint
);
5739 free_marker (oldbegv
);
5740 free_marker (oldzv
);
5742 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5743 set_buffer_internal (oldbuf
);
5745 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5746 message_log_need_newline
= !nlflag
;
5747 Vdeactivate_mark
= old_deactivate_mark
;
5752 /* We are at the end of the buffer after just having inserted a newline.
5753 (Note: We depend on the fact we won't be crossing the gap.)
5754 Check to see if the most recent message looks a lot like the previous one.
5755 Return 0 if different, 1 if the new one should just replace it, or a
5756 value N > 1 if we should also append " [N times]". */
5759 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5760 int prev_bol
, this_bol
;
5761 int prev_bol_byte
, this_bol_byte
;
5764 int len
= Z_BYTE
- 1 - this_bol_byte
;
5766 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5767 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5769 for (i
= 0; i
< len
; i
++)
5771 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5779 if (*p1
++ == ' ' && *p1
++ == '[')
5782 while (*p1
>= '0' && *p1
<= '9')
5783 n
= n
* 10 + *p1
++ - '0';
5784 if (strncmp (p1
, " times]\n", 8) == 0)
5791 /* Display an echo area message M with a specified length of NBYTES
5792 bytes. The string may include null characters. If M is 0, clear
5793 out any existing message, and let the mini-buffer text show
5796 The buffer M must continue to exist until after the echo area gets
5797 cleared or some other message gets displayed there. This means do
5798 not pass text that is stored in a Lisp string; do not pass text in
5799 a buffer that was alloca'd. */
5802 message2 (m
, nbytes
, multibyte
)
5807 /* First flush out any partial line written with print. */
5808 message_log_maybe_newline ();
5810 message_dolog (m
, nbytes
, 1, multibyte
);
5811 message2_nolog (m
, nbytes
, multibyte
);
5815 /* The non-logging counterpart of message2. */
5818 message2_nolog (m
, nbytes
, multibyte
)
5822 struct frame
*sf
= SELECTED_FRAME ();
5823 message_enable_multibyte
= multibyte
;
5827 if (noninteractive_need_newline
)
5828 putc ('\n', stderr
);
5829 noninteractive_need_newline
= 0;
5831 fwrite (m
, nbytes
, 1, stderr
);
5832 if (cursor_in_echo_area
== 0)
5833 fprintf (stderr
, "\n");
5836 /* A null message buffer means that the frame hasn't really been
5837 initialized yet. Error messages get reported properly by
5838 cmd_error, so this must be just an informative message; toss it. */
5839 else if (INTERACTIVE
5840 && sf
->glyphs_initialized_p
5841 && FRAME_MESSAGE_BUF (sf
))
5843 Lisp_Object mini_window
;
5846 /* Get the frame containing the mini-buffer
5847 that the selected frame is using. */
5848 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5849 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5851 FRAME_SAMPLE_VISIBILITY (f
);
5852 if (FRAME_VISIBLE_P (sf
)
5853 && ! FRAME_VISIBLE_P (f
))
5854 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5858 set_message (m
, Qnil
, nbytes
, multibyte
);
5859 if (minibuffer_auto_raise
)
5860 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5863 clear_message (1, 1);
5865 do_pending_window_change (0);
5866 echo_area_display (1);
5867 do_pending_window_change (0);
5868 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5869 (*frame_up_to_date_hook
) (f
);
5874 /* Display an echo area message M with a specified length of NBYTES
5875 bytes. The string may include null characters. If M is not a
5876 string, clear out any existing message, and let the mini-buffer
5877 text show through. */
5880 message3 (m
, nbytes
, multibyte
)
5885 struct gcpro gcpro1
;
5889 /* First flush out any partial line written with print. */
5890 message_log_maybe_newline ();
5892 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5893 message3_nolog (m
, nbytes
, multibyte
);
5899 /* The non-logging version of message3. */
5902 message3_nolog (m
, nbytes
, multibyte
)
5904 int nbytes
, multibyte
;
5906 struct frame
*sf
= SELECTED_FRAME ();
5907 message_enable_multibyte
= multibyte
;
5911 if (noninteractive_need_newline
)
5912 putc ('\n', stderr
);
5913 noninteractive_need_newline
= 0;
5915 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5916 if (cursor_in_echo_area
== 0)
5917 fprintf (stderr
, "\n");
5920 /* A null message buffer means that the frame hasn't really been
5921 initialized yet. Error messages get reported properly by
5922 cmd_error, so this must be just an informative message; toss it. */
5923 else if (INTERACTIVE
5924 && sf
->glyphs_initialized_p
5925 && FRAME_MESSAGE_BUF (sf
))
5927 Lisp_Object mini_window
;
5931 /* Get the frame containing the mini-buffer
5932 that the selected frame is using. */
5933 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5934 frame
= XWINDOW (mini_window
)->frame
;
5937 FRAME_SAMPLE_VISIBILITY (f
);
5938 if (FRAME_VISIBLE_P (sf
)
5939 && !FRAME_VISIBLE_P (f
))
5940 Fmake_frame_visible (frame
);
5942 if (STRINGP (m
) && XSTRING (m
)->size
)
5944 set_message (NULL
, m
, nbytes
, multibyte
);
5945 if (minibuffer_auto_raise
)
5946 Fraise_frame (frame
);
5949 clear_message (1, 1);
5951 do_pending_window_change (0);
5952 echo_area_display (1);
5953 do_pending_window_change (0);
5954 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5955 (*frame_up_to_date_hook
) (f
);
5960 /* Display a null-terminated echo area message M. If M is 0, clear
5961 out any existing message, and let the mini-buffer text show through.
5963 The buffer M must continue to exist until after the echo area gets
5964 cleared or some other message gets displayed there. Do not pass
5965 text that is stored in a Lisp string. Do not pass text in a buffer
5966 that was alloca'd. */
5972 message2 (m
, (m
? strlen (m
) : 0), 0);
5976 /* The non-logging counterpart of message1. */
5982 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5985 /* Display a message M which contains a single %s
5986 which gets replaced with STRING. */
5989 message_with_string (m
, string
, log
)
5998 if (noninteractive_need_newline
)
5999 putc ('\n', stderr
);
6000 noninteractive_need_newline
= 0;
6001 fprintf (stderr
, m
, XSTRING (string
)->data
);
6002 if (cursor_in_echo_area
== 0)
6003 fprintf (stderr
, "\n");
6007 else if (INTERACTIVE
)
6009 /* The frame whose minibuffer we're going to display the message on.
6010 It may be larger than the selected frame, so we need
6011 to use its buffer, not the selected frame's buffer. */
6012 Lisp_Object mini_window
;
6013 struct frame
*f
, *sf
= SELECTED_FRAME ();
6015 /* Get the frame containing the minibuffer
6016 that the selected frame is using. */
6017 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6018 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6020 /* A null message buffer means that the frame hasn't really been
6021 initialized yet. Error messages get reported properly by
6022 cmd_error, so this must be just an informative message; toss it. */
6023 if (FRAME_MESSAGE_BUF (f
))
6027 a
[0] = (char *) XSTRING (string
)->data
;
6029 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6030 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6033 message2 (FRAME_MESSAGE_BUF (f
), len
,
6034 STRING_MULTIBYTE (string
));
6036 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
6037 STRING_MULTIBYTE (string
));
6039 /* Print should start at the beginning of the message
6040 buffer next time. */
6041 message_buf_print
= 0;
6047 /* Dump an informative message to the minibuf. If M is 0, clear out
6048 any existing message, and let the mini-buffer text show through. */
6052 message (m
, a1
, a2
, a3
)
6054 EMACS_INT a1
, a2
, a3
;
6060 if (noninteractive_need_newline
)
6061 putc ('\n', stderr
);
6062 noninteractive_need_newline
= 0;
6063 fprintf (stderr
, m
, a1
, a2
, a3
);
6064 if (cursor_in_echo_area
== 0)
6065 fprintf (stderr
, "\n");
6069 else if (INTERACTIVE
)
6071 /* The frame whose mini-buffer we're going to display the message
6072 on. It may be larger than the selected frame, so we need to
6073 use its buffer, not the selected frame's buffer. */
6074 Lisp_Object mini_window
;
6075 struct frame
*f
, *sf
= SELECTED_FRAME ();
6077 /* Get the frame containing the mini-buffer
6078 that the selected frame is using. */
6079 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6080 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6082 /* A null message buffer means that the frame hasn't really been
6083 initialized yet. Error messages get reported properly by
6084 cmd_error, so this must be just an informative message; toss
6086 if (FRAME_MESSAGE_BUF (f
))
6097 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6098 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6100 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6101 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6103 #endif /* NO_ARG_ARRAY */
6105 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6110 /* Print should start at the beginning of the message
6111 buffer next time. */
6112 message_buf_print
= 0;
6118 /* The non-logging version of message. */
6121 message_nolog (m
, a1
, a2
, a3
)
6123 EMACS_INT a1
, a2
, a3
;
6125 Lisp_Object old_log_max
;
6126 old_log_max
= Vmessage_log_max
;
6127 Vmessage_log_max
= Qnil
;
6128 message (m
, a1
, a2
, a3
);
6129 Vmessage_log_max
= old_log_max
;
6133 /* Display the current message in the current mini-buffer. This is
6134 only called from error handlers in process.c, and is not time
6140 if (!NILP (echo_area_buffer
[0]))
6143 string
= Fcurrent_message ();
6144 message3 (string
, XSTRING (string
)->size
,
6145 !NILP (current_buffer
->enable_multibyte_characters
));
6150 /* Make sure echo area buffers in echo_buffers[] are life. If they
6151 aren't, make new ones. */
6154 ensure_echo_area_buffers ()
6158 for (i
= 0; i
< 2; ++i
)
6159 if (!BUFFERP (echo_buffer
[i
])
6160 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6163 Lisp_Object old_buffer
;
6166 old_buffer
= echo_buffer
[i
];
6167 sprintf (name
, " *Echo Area %d*", i
);
6168 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6169 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6171 for (j
= 0; j
< 2; ++j
)
6172 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6173 echo_area_buffer
[j
] = echo_buffer
[i
];
6178 /* Call FN with args A1..A4 with either the current or last displayed
6179 echo_area_buffer as current buffer.
6181 WHICH zero means use the current message buffer
6182 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6183 from echo_buffer[] and clear it.
6185 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6186 suitable buffer from echo_buffer[] and clear it.
6188 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6189 that the current message becomes the last displayed one, make
6190 choose a suitable buffer for echo_area_buffer[0], and clear it.
6192 Value is what FN returns. */
6195 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6198 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6204 int this_one
, the_other
, clear_buffer_p
, rc
;
6205 int count
= BINDING_STACK_SIZE ();
6207 /* If buffers aren't life, make new ones. */
6208 ensure_echo_area_buffers ();
6213 this_one
= 0, the_other
= 1;
6215 this_one
= 1, the_other
= 0;
6218 this_one
= 0, the_other
= 1;
6221 /* We need a fresh one in case the current echo buffer equals
6222 the one containing the last displayed echo area message. */
6223 if (!NILP (echo_area_buffer
[this_one
])
6224 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6225 echo_area_buffer
[this_one
] = Qnil
;
6228 /* Choose a suitable buffer from echo_buffer[] is we don't
6230 if (NILP (echo_area_buffer
[this_one
]))
6232 echo_area_buffer
[this_one
]
6233 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6234 ? echo_buffer
[the_other
]
6235 : echo_buffer
[this_one
]);
6239 buffer
= echo_area_buffer
[this_one
];
6241 /* Don't get confused by reusing the buffer used for echoing
6242 for a different purpose. */
6243 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6246 record_unwind_protect (unwind_with_echo_area_buffer
,
6247 with_echo_area_buffer_unwind_data (w
));
6249 /* Make the echo area buffer current. Note that for display
6250 purposes, it is not necessary that the displayed window's buffer
6251 == current_buffer, except for text property lookup. So, let's
6252 only set that buffer temporarily here without doing a full
6253 Fset_window_buffer. We must also change w->pointm, though,
6254 because otherwise an assertions in unshow_buffer fails, and Emacs
6256 set_buffer_internal_1 (XBUFFER (buffer
));
6260 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6263 current_buffer
->undo_list
= Qt
;
6264 current_buffer
->read_only
= Qnil
;
6265 specbind (Qinhibit_read_only
, Qt
);
6266 specbind (Qinhibit_modification_hooks
, Qt
);
6268 if (clear_buffer_p
&& Z
> BEG
)
6271 xassert (BEGV
>= BEG
);
6272 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6274 rc
= fn (a1
, a2
, a3
, a4
);
6276 xassert (BEGV
>= BEG
);
6277 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6279 unbind_to (count
, Qnil
);
6284 /* Save state that should be preserved around the call to the function
6285 FN called in with_echo_area_buffer. */
6288 with_echo_area_buffer_unwind_data (w
)
6294 /* Reduce consing by keeping one vector in
6295 Vwith_echo_area_save_vector. */
6296 vector
= Vwith_echo_area_save_vector
;
6297 Vwith_echo_area_save_vector
= Qnil
;
6300 vector
= Fmake_vector (make_number (7), Qnil
);
6302 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6303 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6304 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6308 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6309 AREF (vector
, i
) = w
->buffer
; ++i
;
6310 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6311 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6316 for (; i
< end
; ++i
)
6317 AREF (vector
, i
) = Qnil
;
6320 xassert (i
== ASIZE (vector
));
6325 /* Restore global state from VECTOR which was created by
6326 with_echo_area_buffer_unwind_data. */
6329 unwind_with_echo_area_buffer (vector
)
6332 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6333 Vdeactivate_mark
= AREF (vector
, 1);
6334 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6336 if (WINDOWP (AREF (vector
, 3)))
6339 Lisp_Object buffer
, charpos
, bytepos
;
6341 w
= XWINDOW (AREF (vector
, 3));
6342 buffer
= AREF (vector
, 4);
6343 charpos
= AREF (vector
, 5);
6344 bytepos
= AREF (vector
, 6);
6347 set_marker_both (w
->pointm
, buffer
,
6348 XFASTINT (charpos
), XFASTINT (bytepos
));
6351 Vwith_echo_area_save_vector
= vector
;
6356 /* Set up the echo area for use by print functions. MULTIBYTE_P
6357 non-zero means we will print multibyte. */
6360 setup_echo_area_for_printing (multibyte_p
)
6363 ensure_echo_area_buffers ();
6365 if (!message_buf_print
)
6367 /* A message has been output since the last time we printed.
6368 Choose a fresh echo area buffer. */
6369 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6370 echo_area_buffer
[0] = echo_buffer
[1];
6372 echo_area_buffer
[0] = echo_buffer
[0];
6374 /* Switch to that buffer and clear it. */
6375 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6376 current_buffer
->truncate_lines
= Qnil
;
6380 int count
= BINDING_STACK_SIZE ();
6381 specbind (Qinhibit_read_only
, Qt
);
6383 unbind_to (count
, Qnil
);
6385 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6387 /* Set up the buffer for the multibyteness we need. */
6389 != !NILP (current_buffer
->enable_multibyte_characters
))
6390 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6392 /* Raise the frame containing the echo area. */
6393 if (minibuffer_auto_raise
)
6395 struct frame
*sf
= SELECTED_FRAME ();
6396 Lisp_Object mini_window
;
6397 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6398 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6401 message_log_maybe_newline ();
6402 message_buf_print
= 1;
6406 if (NILP (echo_area_buffer
[0]))
6408 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6409 echo_area_buffer
[0] = echo_buffer
[1];
6411 echo_area_buffer
[0] = echo_buffer
[0];
6414 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6416 /* Someone switched buffers between print requests. */
6417 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6418 current_buffer
->truncate_lines
= Qnil
;
6424 /* Display an echo area message in window W. Value is non-zero if W's
6425 height is changed. If display_last_displayed_message_p is
6426 non-zero, display the message that was last displayed, otherwise
6427 display the current message. */
6430 display_echo_area (w
)
6433 int i
, no_message_p
, window_height_changed_p
, count
;
6435 /* Temporarily disable garbage collections while displaying the echo
6436 area. This is done because a GC can print a message itself.
6437 That message would modify the echo area buffer's contents while a
6438 redisplay of the buffer is going on, and seriously confuse
6440 count
= inhibit_garbage_collection ();
6442 /* If there is no message, we must call display_echo_area_1
6443 nevertheless because it resizes the window. But we will have to
6444 reset the echo_area_buffer in question to nil at the end because
6445 with_echo_area_buffer will sets it to an empty buffer. */
6446 i
= display_last_displayed_message_p
? 1 : 0;
6447 no_message_p
= NILP (echo_area_buffer
[i
]);
6449 window_height_changed_p
6450 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6451 display_echo_area_1
,
6452 (EMACS_INT
) w
, Qnil
, 0, 0);
6455 echo_area_buffer
[i
] = Qnil
;
6457 unbind_to (count
, Qnil
);
6458 return window_height_changed_p
;
6462 /* Helper for display_echo_area. Display the current buffer which
6463 contains the current echo area message in window W, a mini-window,
6464 a pointer to which is passed in A1. A2..A4 are currently not used.
6465 Change the height of W so that all of the message is displayed.
6466 Value is non-zero if height of W was changed. */
6469 display_echo_area_1 (a1
, a2
, a3
, a4
)
6474 struct window
*w
= (struct window
*) a1
;
6476 struct text_pos start
;
6477 int window_height_changed_p
= 0;
6479 /* Do this before displaying, so that we have a large enough glyph
6480 matrix for the display. */
6481 window_height_changed_p
= resize_mini_window (w
, 0);
6484 clear_glyph_matrix (w
->desired_matrix
);
6485 XSETWINDOW (window
, w
);
6486 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6487 try_window (window
, start
);
6489 return window_height_changed_p
;
6493 /* Resize the echo area window to exactly the size needed for the
6494 currently displayed message, if there is one. If a mini-buffer
6495 is active, don't shrink it. */
6498 resize_echo_area_exactly ()
6500 if (BUFFERP (echo_area_buffer
[0])
6501 && WINDOWP (echo_area_window
))
6503 struct window
*w
= XWINDOW (echo_area_window
);
6505 Lisp_Object resize_exactly
;
6507 if (minibuf_level
== 0)
6508 resize_exactly
= Qt
;
6510 resize_exactly
= Qnil
;
6512 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6513 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6516 ++windows_or_buffers_changed
;
6517 ++update_mode_lines
;
6518 redisplay_internal (0);
6524 /* Callback function for with_echo_area_buffer, when used from
6525 resize_echo_area_exactly. A1 contains a pointer to the window to
6526 resize, EXACTLY non-nil means resize the mini-window exactly to the
6527 size of the text displayed. A3 and A4 are not used. Value is what
6528 resize_mini_window returns. */
6531 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6533 Lisp_Object exactly
;
6536 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6540 /* Resize mini-window W to fit the size of its contents. EXACT:P
6541 means size the window exactly to the size needed. Otherwise, it's
6542 only enlarged until W's buffer is empty. Value is non-zero if
6543 the window height has been changed. */
6546 resize_mini_window (w
, exact_p
)
6550 struct frame
*f
= XFRAME (w
->frame
);
6551 int window_height_changed_p
= 0;
6553 xassert (MINI_WINDOW_P (w
));
6555 /* Don't resize windows while redisplaying a window; it would
6556 confuse redisplay functions when the size of the window they are
6557 displaying changes from under them. Such a resizing can happen,
6558 for instance, when which-func prints a long message while
6559 we are running fontification-functions. We're running these
6560 functions with safe_call which binds inhibit-redisplay to t. */
6561 if (!NILP (Vinhibit_redisplay
))
6564 /* Nil means don't try to resize. */
6565 if (NILP (Vresize_mini_windows
)
6566 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6569 if (!FRAME_MINIBUF_ONLY_P (f
))
6572 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6573 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6574 int height
, max_height
;
6575 int unit
= CANON_Y_UNIT (f
);
6576 struct text_pos start
;
6577 struct buffer
*old_current_buffer
= NULL
;
6579 if (current_buffer
!= XBUFFER (w
->buffer
))
6581 old_current_buffer
= current_buffer
;
6582 set_buffer_internal (XBUFFER (w
->buffer
));
6585 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6587 /* Compute the max. number of lines specified by the user. */
6588 if (FLOATP (Vmax_mini_window_height
))
6589 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6590 else if (INTEGERP (Vmax_mini_window_height
))
6591 max_height
= XINT (Vmax_mini_window_height
);
6593 max_height
= total_height
/ 4;
6595 /* Correct that max. height if it's bogus. */
6596 max_height
= max (1, max_height
);
6597 max_height
= min (total_height
, max_height
);
6599 /* Find out the height of the text in the window. */
6600 if (it
.truncate_lines_p
)
6605 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6606 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6607 height
= it
.current_y
+ last_height
;
6609 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6610 height
-= it
.extra_line_spacing
;
6611 height
= (height
+ unit
- 1) / unit
;
6614 /* Compute a suitable window start. */
6615 if (height
> max_height
)
6617 height
= max_height
;
6618 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6619 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6620 start
= it
.current
.pos
;
6623 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6624 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6626 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6628 /* Let it grow only, until we display an empty message, in which
6629 case the window shrinks again. */
6630 if (height
> XFASTINT (w
->height
))
6632 int old_height
= XFASTINT (w
->height
);
6633 freeze_window_starts (f
, 1);
6634 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6635 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6637 else if (height
< XFASTINT (w
->height
)
6638 && (exact_p
|| BEGV
== ZV
))
6640 int old_height
= XFASTINT (w
->height
);
6641 freeze_window_starts (f
, 0);
6642 shrink_mini_window (w
);
6643 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6648 /* Always resize to exact size needed. */
6649 if (height
> XFASTINT (w
->height
))
6651 int old_height
= XFASTINT (w
->height
);
6652 freeze_window_starts (f
, 1);
6653 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6654 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6656 else if (height
< XFASTINT (w
->height
))
6658 int old_height
= XFASTINT (w
->height
);
6659 freeze_window_starts (f
, 0);
6660 shrink_mini_window (w
);
6664 freeze_window_starts (f
, 1);
6665 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6668 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6672 if (old_current_buffer
)
6673 set_buffer_internal (old_current_buffer
);
6676 return window_height_changed_p
;
6680 /* Value is the current message, a string, or nil if there is no
6688 if (NILP (echo_area_buffer
[0]))
6692 with_echo_area_buffer (0, 0, current_message_1
,
6693 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6695 echo_area_buffer
[0] = Qnil
;
6703 current_message_1 (a1
, a2
, a3
, a4
)
6708 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6711 *msg
= make_buffer_string (BEG
, Z
, 1);
6718 /* Push the current message on Vmessage_stack for later restauration
6719 by restore_message. Value is non-zero if the current message isn't
6720 empty. This is a relatively infrequent operation, so it's not
6721 worth optimizing. */
6727 msg
= current_message ();
6728 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6729 return STRINGP (msg
);
6733 /* Handler for record_unwind_protect calling pop_message. */
6736 push_message_unwind (dummy
)
6744 /* Restore message display from the top of Vmessage_stack. */
6751 xassert (CONSP (Vmessage_stack
));
6752 msg
= XCAR (Vmessage_stack
);
6754 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6756 message3_nolog (msg
, 0, 0);
6760 /* Pop the top-most entry off Vmessage_stack. */
6765 xassert (CONSP (Vmessage_stack
));
6766 Vmessage_stack
= XCDR (Vmessage_stack
);
6770 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6771 exits. If the stack is not empty, we have a missing pop_message
6775 check_message_stack ()
6777 if (!NILP (Vmessage_stack
))
6782 /* Truncate to NCHARS what will be displayed in the echo area the next
6783 time we display it---but don't redisplay it now. */
6786 truncate_echo_area (nchars
)
6790 echo_area_buffer
[0] = Qnil
;
6791 /* A null message buffer means that the frame hasn't really been
6792 initialized yet. Error messages get reported properly by
6793 cmd_error, so this must be just an informative message; toss it. */
6794 else if (!noninteractive
6796 && !NILP (echo_area_buffer
[0]))
6798 struct frame
*sf
= SELECTED_FRAME ();
6799 if (FRAME_MESSAGE_BUF (sf
))
6800 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6805 /* Helper function for truncate_echo_area. Truncate the current
6806 message to at most NCHARS characters. */
6809 truncate_message_1 (nchars
, a2
, a3
, a4
)
6814 if (BEG
+ nchars
< Z
)
6815 del_range (BEG
+ nchars
, Z
);
6817 echo_area_buffer
[0] = Qnil
;
6822 /* Set the current message to a substring of S or STRING.
6824 If STRING is a Lisp string, set the message to the first NBYTES
6825 bytes from STRING. NBYTES zero means use the whole string. If
6826 STRING is multibyte, the message will be displayed multibyte.
6828 If S is not null, set the message to the first LEN bytes of S. LEN
6829 zero means use the whole string. MULTIBYTE_P non-zero means S is
6830 multibyte. Display the message multibyte in that case. */
6833 set_message (s
, string
, nbytes
, multibyte_p
)
6838 message_enable_multibyte
6839 = ((s
&& multibyte_p
)
6840 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6842 with_echo_area_buffer (0, -1, set_message_1
,
6843 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6844 message_buf_print
= 0;
6845 help_echo_showing_p
= 0;
6849 /* Helper function for set_message. Arguments have the same meaning
6850 as there, with A1 corresponding to S and A2 corresponding to STRING
6851 This function is called with the echo area buffer being
6855 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6858 EMACS_INT nbytes
, multibyte_p
;
6860 char *s
= (char *) a1
;
6861 Lisp_Object string
= a2
;
6865 /* Change multibyteness of the echo buffer appropriately. */
6866 if (message_enable_multibyte
6867 != !NILP (current_buffer
->enable_multibyte_characters
))
6868 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6870 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6872 /* Insert new message at BEG. */
6873 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6875 if (STRINGP (string
))
6880 nbytes
= XSTRING (string
)->size_byte
;
6881 nchars
= string_byte_to_char (string
, nbytes
);
6883 /* This function takes care of single/multibyte conversion. We
6884 just have to ensure that the echo area buffer has the right
6885 setting of enable_multibyte_characters. */
6886 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6891 nbytes
= strlen (s
);
6893 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6895 /* Convert from multi-byte to single-byte. */
6897 unsigned char work
[1];
6899 /* Convert a multibyte string to single-byte. */
6900 for (i
= 0; i
< nbytes
; i
+= n
)
6902 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6903 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6905 : multibyte_char_to_unibyte (c
, Qnil
));
6906 insert_1_both (work
, 1, 1, 1, 0, 0);
6909 else if (!multibyte_p
6910 && !NILP (current_buffer
->enable_multibyte_characters
))
6912 /* Convert from single-byte to multi-byte. */
6914 unsigned char *msg
= (unsigned char *) s
;
6915 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6917 /* Convert a single-byte string to multibyte. */
6918 for (i
= 0; i
< nbytes
; i
++)
6920 c
= unibyte_char_to_multibyte (msg
[i
]);
6921 n
= CHAR_STRING (c
, str
);
6922 insert_1_both (str
, 1, n
, 1, 0, 0);
6926 insert_1 (s
, nbytes
, 1, 0, 0);
6933 /* Clear messages. CURRENT_P non-zero means clear the current
6934 message. LAST_DISPLAYED_P non-zero means clear the message
6938 clear_message (current_p
, last_displayed_p
)
6939 int current_p
, last_displayed_p
;
6943 echo_area_buffer
[0] = Qnil
;
6944 message_cleared_p
= 1;
6947 if (last_displayed_p
)
6948 echo_area_buffer
[1] = Qnil
;
6950 message_buf_print
= 0;
6953 /* Clear garbaged frames.
6955 This function is used where the old redisplay called
6956 redraw_garbaged_frames which in turn called redraw_frame which in
6957 turn called clear_frame. The call to clear_frame was a source of
6958 flickering. I believe a clear_frame is not necessary. It should
6959 suffice in the new redisplay to invalidate all current matrices,
6960 and ensure a complete redisplay of all windows. */
6963 clear_garbaged_frames ()
6967 Lisp_Object tail
, frame
;
6969 FOR_EACH_FRAME (tail
, frame
)
6971 struct frame
*f
= XFRAME (frame
);
6973 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6976 Fredraw_frame (frame
);
6977 clear_current_matrices (f
);
6984 ++windows_or_buffers_changed
;
6989 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6990 is non-zero update selected_frame. Value is non-zero if the
6991 mini-windows height has been changed. */
6994 echo_area_display (update_frame_p
)
6997 Lisp_Object mini_window
;
7000 int window_height_changed_p
= 0;
7001 struct frame
*sf
= SELECTED_FRAME ();
7003 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7004 w
= XWINDOW (mini_window
);
7005 f
= XFRAME (WINDOW_FRAME (w
));
7007 /* Don't display if frame is invisible or not yet initialized. */
7008 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7011 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7013 #ifdef HAVE_WINDOW_SYSTEM
7014 /* When Emacs starts, selected_frame may be a visible terminal
7015 frame, even if we run under a window system. If we let this
7016 through, a message would be displayed on the terminal. */
7017 if (EQ (selected_frame
, Vterminal_frame
)
7018 && !NILP (Vwindow_system
))
7020 #endif /* HAVE_WINDOW_SYSTEM */
7023 /* Redraw garbaged frames. */
7025 clear_garbaged_frames ();
7027 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7029 echo_area_window
= mini_window
;
7030 window_height_changed_p
= display_echo_area (w
);
7031 w
->must_be_updated_p
= 1;
7033 /* Update the display, unless called from redisplay_internal.
7034 Also don't update the screen during redisplay itself. The
7035 update will happen at the end of redisplay, and an update
7036 here could cause confusion. */
7037 if (update_frame_p
&& !redisplaying_p
)
7041 /* If the display update has been interrupted by pending
7042 input, update mode lines in the frame. Due to the
7043 pending input, it might have been that redisplay hasn't
7044 been called, so that mode lines above the echo area are
7045 garbaged. This looks odd, so we prevent it here. */
7046 if (!display_completed
)
7047 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7049 if (window_height_changed_p
7050 /* Don't do this if Emacs is shutting down. Redisplay
7051 needs to run hooks. */
7052 && !NILP (Vrun_hooks
))
7054 /* Must update other windows. Likewise as in other
7055 cases, don't let this update be interrupted by
7057 int count
= BINDING_STACK_SIZE ();
7058 specbind (Qredisplay_dont_pause
, Qt
);
7059 windows_or_buffers_changed
= 1;
7060 redisplay_internal (0);
7061 unbind_to (count
, Qnil
);
7063 else if (FRAME_WINDOW_P (f
) && n
== 0)
7065 /* Window configuration is the same as before.
7066 Can do with a display update of the echo area,
7067 unless we displayed some mode lines. */
7068 update_single_window (w
, 1);
7069 rif
->flush_display (f
);
7072 update_frame (f
, 1, 1);
7074 /* If cursor is in the echo area, make sure that the next
7075 redisplay displays the minibuffer, so that the cursor will
7076 be replaced with what the minibuffer wants. */
7077 if (cursor_in_echo_area
)
7078 ++windows_or_buffers_changed
;
7081 else if (!EQ (mini_window
, selected_window
))
7082 windows_or_buffers_changed
++;
7084 /* Last displayed message is now the current message. */
7085 echo_area_buffer
[1] = echo_area_buffer
[0];
7087 /* Prevent redisplay optimization in redisplay_internal by resetting
7088 this_line_start_pos. This is done because the mini-buffer now
7089 displays the message instead of its buffer text. */
7090 if (EQ (mini_window
, selected_window
))
7091 CHARPOS (this_line_start_pos
) = 0;
7093 return window_height_changed_p
;
7098 /***********************************************************************
7100 ***********************************************************************/
7103 #ifdef HAVE_WINDOW_SYSTEM
7105 /* A buffer for constructing frame titles in it; allocated from the
7106 heap in init_xdisp and resized as needed in store_frame_title_char. */
7108 static char *frame_title_buf
;
7110 /* The buffer's end, and a current output position in it. */
7112 static char *frame_title_buf_end
;
7113 static char *frame_title_ptr
;
7116 /* Store a single character C for the frame title in frame_title_buf.
7117 Re-allocate frame_title_buf if necessary. */
7120 store_frame_title_char (c
)
7123 /* If output position has reached the end of the allocated buffer,
7124 double the buffer's size. */
7125 if (frame_title_ptr
== frame_title_buf_end
)
7127 int len
= frame_title_ptr
- frame_title_buf
;
7128 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7129 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7130 frame_title_buf_end
= frame_title_buf
+ new_size
;
7131 frame_title_ptr
= frame_title_buf
+ len
;
7134 *frame_title_ptr
++ = c
;
7138 /* Store part of a frame title in frame_title_buf, beginning at
7139 frame_title_ptr. STR is the string to store. Do not copy
7140 characters that yield more columns than PRECISION; PRECISION <= 0
7141 means copy the whole string. Pad with spaces until FIELD_WIDTH
7142 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7143 pad. Called from display_mode_element when it is used to build a
7147 store_frame_title (str
, field_width
, precision
)
7149 int field_width
, precision
;
7154 /* Copy at most PRECISION chars from STR. */
7155 nbytes
= strlen (str
);
7156 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7158 store_frame_title_char (*str
++);
7160 /* Fill up with spaces until FIELD_WIDTH reached. */
7161 while (field_width
> 0
7164 store_frame_title_char (' ');
7172 /* Set the title of FRAME, if it has changed. The title format is
7173 Vicon_title_format if FRAME is iconified, otherwise it is
7174 frame_title_format. */
7177 x_consider_frame_title (frame
)
7180 struct frame
*f
= XFRAME (frame
);
7182 if (FRAME_WINDOW_P (f
)
7183 || FRAME_MINIBUF_ONLY_P (f
)
7184 || f
->explicit_name
)
7186 /* Do we have more than one visible frame on this X display? */
7189 struct buffer
*obuf
;
7193 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7195 struct frame
*tf
= XFRAME (XCAR (tail
));
7198 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7199 && !FRAME_MINIBUF_ONLY_P (tf
)
7200 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7204 /* Set global variable indicating that multiple frames exist. */
7205 multiple_frames
= CONSP (tail
);
7207 /* Switch to the buffer of selected window of the frame. Set up
7208 frame_title_ptr so that display_mode_element will output into it;
7209 then display the title. */
7210 obuf
= current_buffer
;
7211 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
7212 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7213 frame_title_ptr
= frame_title_buf
;
7214 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7215 NULL
, DEFAULT_FACE_ID
);
7216 display_mode_element (&it
, 0, -1, -1, fmt
);
7217 len
= frame_title_ptr
- frame_title_buf
;
7218 frame_title_ptr
= NULL
;
7219 set_buffer_internal (obuf
);
7221 /* Set the title only if it's changed. This avoids consing in
7222 the common case where it hasn't. (If it turns out that we've
7223 already wasted too much time by walking through the list with
7224 display_mode_element, then we might need to optimize at a
7225 higher level than this.) */
7226 if (! STRINGP (f
->name
)
7227 || STRING_BYTES (XSTRING (f
->name
)) != len
7228 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
7229 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7233 #else /* not HAVE_WINDOW_SYSTEM */
7235 #define frame_title_ptr ((char *)0)
7236 #define store_frame_title(str, mincol, maxcol) 0
7238 #endif /* not HAVE_WINDOW_SYSTEM */
7243 /***********************************************************************
7245 ***********************************************************************/
7248 /* Prepare for redisplay by updating menu-bar item lists when
7249 appropriate. This can call eval. */
7252 prepare_menu_bars ()
7255 struct gcpro gcpro1
, gcpro2
;
7257 Lisp_Object tooltip_frame
;
7259 #ifdef HAVE_X_WINDOWS
7260 tooltip_frame
= tip_frame
;
7262 tooltip_frame
= Qnil
;
7265 /* Update all frame titles based on their buffer names, etc. We do
7266 this before the menu bars so that the buffer-menu will show the
7267 up-to-date frame titles. */
7268 #ifdef HAVE_WINDOW_SYSTEM
7269 if (windows_or_buffers_changed
|| update_mode_lines
)
7271 Lisp_Object tail
, frame
;
7273 FOR_EACH_FRAME (tail
, frame
)
7276 if (!EQ (frame
, tooltip_frame
)
7277 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7278 x_consider_frame_title (frame
);
7281 #endif /* HAVE_WINDOW_SYSTEM */
7283 /* Update the menu bar item lists, if appropriate. This has to be
7284 done before any actual redisplay or generation of display lines. */
7285 all_windows
= (update_mode_lines
7286 || buffer_shared
> 1
7287 || windows_or_buffers_changed
);
7290 Lisp_Object tail
, frame
;
7291 int count
= BINDING_STACK_SIZE ();
7293 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7295 FOR_EACH_FRAME (tail
, frame
)
7299 /* Ignore tooltip frame. */
7300 if (EQ (frame
, tooltip_frame
))
7303 /* If a window on this frame changed size, report that to
7304 the user and clear the size-change flag. */
7305 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7307 Lisp_Object functions
;
7309 /* Clear flag first in case we get an error below. */
7310 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7311 functions
= Vwindow_size_change_functions
;
7312 GCPRO2 (tail
, functions
);
7314 while (CONSP (functions
))
7316 call1 (XCAR (functions
), frame
);
7317 functions
= XCDR (functions
);
7323 update_menu_bar (f
, 0);
7324 #ifdef HAVE_WINDOW_SYSTEM
7325 update_tool_bar (f
, 0);
7330 unbind_to (count
, Qnil
);
7334 struct frame
*sf
= SELECTED_FRAME ();
7335 update_menu_bar (sf
, 1);
7336 #ifdef HAVE_WINDOW_SYSTEM
7337 update_tool_bar (sf
, 1);
7341 /* Motif needs this. See comment in xmenu.c. Turn it off when
7342 pending_menu_activation is not defined. */
7343 #ifdef USE_X_TOOLKIT
7344 pending_menu_activation
= 0;
7349 /* Update the menu bar item list for frame F. This has to be done
7350 before we start to fill in any display lines, because it can call
7353 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7356 update_menu_bar (f
, save_match_data
)
7358 int save_match_data
;
7361 register struct window
*w
;
7363 /* If called recursively during a menu update, do nothing. This can
7364 happen when, for instance, an activate-menubar-hook causes a
7366 if (inhibit_menubar_update
)
7369 window
= FRAME_SELECTED_WINDOW (f
);
7370 w
= XWINDOW (window
);
7372 if (update_mode_lines
)
7373 w
->update_mode_line
= Qt
;
7375 if (FRAME_WINDOW_P (f
)
7377 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7378 FRAME_EXTERNAL_MENU_BAR (f
)
7380 FRAME_MENU_BAR_LINES (f
) > 0
7382 : FRAME_MENU_BAR_LINES (f
) > 0)
7384 /* If the user has switched buffers or windows, we need to
7385 recompute to reflect the new bindings. But we'll
7386 recompute when update_mode_lines is set too; that means
7387 that people can use force-mode-line-update to request
7388 that the menu bar be recomputed. The adverse effect on
7389 the rest of the redisplay algorithm is about the same as
7390 windows_or_buffers_changed anyway. */
7391 if (windows_or_buffers_changed
7392 || !NILP (w
->update_mode_line
)
7393 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7394 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7395 != !NILP (w
->last_had_star
))
7396 || ((!NILP (Vtransient_mark_mode
)
7397 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7398 != !NILP (w
->region_showing
)))
7400 struct buffer
*prev
= current_buffer
;
7401 int count
= BINDING_STACK_SIZE ();
7403 specbind (Qinhibit_menubar_update
, Qt
);
7405 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7406 if (save_match_data
)
7407 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7408 if (NILP (Voverriding_local_map_menu_flag
))
7410 specbind (Qoverriding_terminal_local_map
, Qnil
);
7411 specbind (Qoverriding_local_map
, Qnil
);
7414 /* Run the Lucid hook. */
7415 safe_run_hooks (Qactivate_menubar_hook
);
7417 /* If it has changed current-menubar from previous value,
7418 really recompute the menu-bar from the value. */
7419 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7420 call0 (Qrecompute_lucid_menubar
);
7422 safe_run_hooks (Qmenu_bar_update_hook
);
7423 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7425 /* Redisplay the menu bar in case we changed it. */
7426 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7427 if (FRAME_WINDOW_P (f
)
7428 #if defined (macintosh)
7429 /* All frames on Mac OS share the same menubar. So only the
7430 selected frame should be allowed to set it. */
7431 && f
== SELECTED_FRAME ()
7434 set_frame_menubar (f
, 0, 0);
7436 /* On a terminal screen, the menu bar is an ordinary screen
7437 line, and this makes it get updated. */
7438 w
->update_mode_line
= Qt
;
7439 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7440 /* In the non-toolkit version, the menu bar is an ordinary screen
7441 line, and this makes it get updated. */
7442 w
->update_mode_line
= Qt
;
7443 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7445 unbind_to (count
, Qnil
);
7446 set_buffer_internal_1 (prev
);
7453 /***********************************************************************
7455 ***********************************************************************/
7457 #ifdef HAVE_WINDOW_SYSTEM
7459 /* Update the tool-bar item list for frame F. This has to be done
7460 before we start to fill in any display lines. Called from
7461 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7462 and restore it here. */
7465 update_tool_bar (f
, save_match_data
)
7467 int save_match_data
;
7469 if (WINDOWP (f
->tool_bar_window
)
7470 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7475 window
= FRAME_SELECTED_WINDOW (f
);
7476 w
= XWINDOW (window
);
7478 /* If the user has switched buffers or windows, we need to
7479 recompute to reflect the new bindings. But we'll
7480 recompute when update_mode_lines is set too; that means
7481 that people can use force-mode-line-update to request
7482 that the menu bar be recomputed. The adverse effect on
7483 the rest of the redisplay algorithm is about the same as
7484 windows_or_buffers_changed anyway. */
7485 if (windows_or_buffers_changed
7486 || !NILP (w
->update_mode_line
)
7487 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7488 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7489 != !NILP (w
->last_had_star
))
7490 || ((!NILP (Vtransient_mark_mode
)
7491 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7492 != !NILP (w
->region_showing
)))
7494 struct buffer
*prev
= current_buffer
;
7495 int count
= BINDING_STACK_SIZE ();
7497 /* Set current_buffer to the buffer of the selected
7498 window of the frame, so that we get the right local
7500 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7502 /* Save match data, if we must. */
7503 if (save_match_data
)
7504 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7506 /* Make sure that we don't accidentally use bogus keymaps. */
7507 if (NILP (Voverriding_local_map_menu_flag
))
7509 specbind (Qoverriding_terminal_local_map
, Qnil
);
7510 specbind (Qoverriding_local_map
, Qnil
);
7513 /* Build desired tool-bar items from keymaps. */
7515 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7517 /* Redisplay the tool-bar in case we changed it. */
7518 w
->update_mode_line
= Qt
;
7520 unbind_to (count
, Qnil
);
7521 set_buffer_internal_1 (prev
);
7527 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7528 F's desired tool-bar contents. F->tool_bar_items must have
7529 been set up previously by calling prepare_menu_bars. */
7532 build_desired_tool_bar_string (f
)
7535 int i
, size
, size_needed
;
7536 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7537 Lisp_Object image
, plist
, props
;
7539 image
= plist
= props
= Qnil
;
7540 GCPRO3 (image
, plist
, props
);
7542 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7543 Otherwise, make a new string. */
7545 /* The size of the string we might be able to reuse. */
7546 size
= (STRINGP (f
->desired_tool_bar_string
)
7547 ? XSTRING (f
->desired_tool_bar_string
)->size
7550 /* We need one space in the string for each image. */
7551 size_needed
= f
->n_tool_bar_items
;
7553 /* Reuse f->desired_tool_bar_string, if possible. */
7554 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7555 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7559 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7560 Fremove_text_properties (make_number (0), make_number (size
),
7561 props
, f
->desired_tool_bar_string
);
7564 /* Put a `display' property on the string for the images to display,
7565 put a `menu_item' property on tool-bar items with a value that
7566 is the index of the item in F's tool-bar item vector. */
7567 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7569 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7571 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7572 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7573 int hmargin
, vmargin
, relief
, idx
, end
;
7574 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7576 /* If image is a vector, choose the image according to the
7578 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7579 if (VECTORP (image
))
7583 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7584 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7587 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7588 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7590 xassert (ASIZE (image
) >= idx
);
7591 image
= AREF (image
, idx
);
7596 /* Ignore invalid image specifications. */
7597 if (!valid_image_p (image
))
7600 /* Display the tool-bar button pressed, or depressed. */
7601 plist
= Fcopy_sequence (XCDR (image
));
7603 /* Compute margin and relief to draw. */
7604 relief
= (tool_bar_button_relief
>= 0
7605 ? tool_bar_button_relief
7606 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7607 hmargin
= vmargin
= relief
;
7609 if (INTEGERP (Vtool_bar_button_margin
)
7610 && XINT (Vtool_bar_button_margin
) > 0)
7612 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7613 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7615 else if (CONSP (Vtool_bar_button_margin
))
7617 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7618 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7619 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7621 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7622 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7623 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7626 if (auto_raise_tool_bar_buttons_p
)
7628 /* Add a `:relief' property to the image spec if the item is
7632 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7639 /* If image is selected, display it pressed, i.e. with a
7640 negative relief. If it's not selected, display it with a
7642 plist
= Fplist_put (plist
, QCrelief
,
7644 ? make_number (-relief
)
7645 : make_number (relief
)));
7650 /* Put a margin around the image. */
7651 if (hmargin
|| vmargin
)
7653 if (hmargin
== vmargin
)
7654 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7656 plist
= Fplist_put (plist
, QCmargin
,
7657 Fcons (make_number (hmargin
),
7658 make_number (vmargin
)));
7661 /* If button is not enabled, and we don't have special images
7662 for the disabled state, make the image appear disabled by
7663 applying an appropriate algorithm to it. */
7664 if (!enabled_p
&& idx
< 0)
7665 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7667 /* Put a `display' text property on the string for the image to
7668 display. Put a `menu-item' property on the string that gives
7669 the start of this item's properties in the tool-bar items
7671 image
= Fcons (Qimage
, plist
);
7672 props
= list4 (Qdisplay
, image
,
7673 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7675 /* Let the last image hide all remaining spaces in the tool bar
7676 string. The string can be longer than needed when we reuse a
7678 if (i
+ 1 == f
->n_tool_bar_items
)
7679 end
= XSTRING (f
->desired_tool_bar_string
)->size
;
7682 Fadd_text_properties (make_number (i
), make_number (end
),
7683 props
, f
->desired_tool_bar_string
);
7691 /* Display one line of the tool-bar of frame IT->f. */
7694 display_tool_bar_line (it
)
7697 struct glyph_row
*row
= it
->glyph_row
;
7698 int max_x
= it
->last_visible_x
;
7701 prepare_desired_row (row
);
7702 row
->y
= it
->current_y
;
7704 /* Note that this isn't made use of if the face hasn't a box,
7705 so there's no need to check the face here. */
7706 it
->start_of_box_run_p
= 1;
7708 while (it
->current_x
< max_x
)
7710 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7712 /* Get the next display element. */
7713 if (!get_next_display_element (it
))
7716 /* Produce glyphs. */
7717 x_before
= it
->current_x
;
7718 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7719 PRODUCE_GLYPHS (it
);
7721 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7726 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7728 if (x
+ glyph
->pixel_width
> max_x
)
7730 /* Glyph doesn't fit on line. */
7731 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7737 x
+= glyph
->pixel_width
;
7741 /* Stop at line ends. */
7742 if (ITERATOR_AT_END_OF_LINE_P (it
))
7745 set_iterator_to_next (it
, 1);
7750 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7751 extend_face_to_end_of_line (it
);
7752 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7753 last
->right_box_line_p
= 1;
7754 if (last
== row
->glyphs
[TEXT_AREA
])
7755 last
->left_box_line_p
= 1;
7756 compute_line_metrics (it
);
7758 /* If line is empty, make it occupy the rest of the tool-bar. */
7759 if (!row
->displays_text_p
)
7761 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7762 row
->ascent
= row
->phys_ascent
= 0;
7765 row
->full_width_p
= 1;
7766 row
->continued_p
= 0;
7767 row
->truncated_on_left_p
= 0;
7768 row
->truncated_on_right_p
= 0;
7770 it
->current_x
= it
->hpos
= 0;
7771 it
->current_y
+= row
->height
;
7777 /* Value is the number of screen lines needed to make all tool-bar
7778 items of frame F visible. */
7781 tool_bar_lines_needed (f
)
7784 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7787 /* Initialize an iterator for iteration over
7788 F->desired_tool_bar_string in the tool-bar window of frame F. */
7789 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7790 it
.first_visible_x
= 0;
7791 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7792 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7794 while (!ITERATOR_AT_END_P (&it
))
7796 it
.glyph_row
= w
->desired_matrix
->rows
;
7797 clear_glyph_row (it
.glyph_row
);
7798 display_tool_bar_line (&it
);
7801 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7805 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7807 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
7816 frame
= selected_frame
;
7818 CHECK_FRAME (frame
);
7821 if (WINDOWP (f
->tool_bar_window
)
7822 || (w
= XWINDOW (f
->tool_bar_window
),
7823 XFASTINT (w
->height
) > 0))
7825 update_tool_bar (f
, 1);
7826 if (f
->n_tool_bar_items
)
7828 build_desired_tool_bar_string (f
);
7829 nlines
= tool_bar_lines_needed (f
);
7833 return make_number (nlines
);
7837 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7838 height should be changed. */
7841 redisplay_tool_bar (f
)
7846 struct glyph_row
*row
;
7847 int change_height_p
= 0;
7849 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7850 do anything. This means you must start with tool-bar-lines
7851 non-zero to get the auto-sizing effect. Or in other words, you
7852 can turn off tool-bars by specifying tool-bar-lines zero. */
7853 if (!WINDOWP (f
->tool_bar_window
)
7854 || (w
= XWINDOW (f
->tool_bar_window
),
7855 XFASTINT (w
->height
) == 0))
7858 /* Set up an iterator for the tool-bar window. */
7859 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7860 it
.first_visible_x
= 0;
7861 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7864 /* Build a string that represents the contents of the tool-bar. */
7865 build_desired_tool_bar_string (f
);
7866 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7868 /* Display as many lines as needed to display all tool-bar items. */
7869 while (it
.current_y
< it
.last_visible_y
)
7870 display_tool_bar_line (&it
);
7872 /* It doesn't make much sense to try scrolling in the tool-bar
7873 window, so don't do it. */
7874 w
->desired_matrix
->no_scrolling_p
= 1;
7875 w
->must_be_updated_p
= 1;
7877 if (auto_resize_tool_bars_p
)
7881 /* If we couldn't display everything, change the tool-bar's
7883 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7884 change_height_p
= 1;
7886 /* If there are blank lines at the end, except for a partially
7887 visible blank line at the end that is smaller than
7888 CANON_Y_UNIT, change the tool-bar's height. */
7889 row
= it
.glyph_row
- 1;
7890 if (!row
->displays_text_p
7891 && row
->height
>= CANON_Y_UNIT (f
))
7892 change_height_p
= 1;
7894 /* If row displays tool-bar items, but is partially visible,
7895 change the tool-bar's height. */
7896 if (row
->displays_text_p
7897 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7898 change_height_p
= 1;
7900 /* Resize windows as needed by changing the `tool-bar-lines'
7903 && (nlines
= tool_bar_lines_needed (f
),
7904 nlines
!= XFASTINT (w
->height
)))
7906 extern Lisp_Object Qtool_bar_lines
;
7908 int old_height
= XFASTINT (w
->height
);
7910 XSETFRAME (frame
, f
);
7911 clear_glyph_matrix (w
->desired_matrix
);
7912 Fmodify_frame_parameters (frame
,
7913 Fcons (Fcons (Qtool_bar_lines
,
7914 make_number (nlines
)),
7916 if (XFASTINT (w
->height
) != old_height
)
7917 fonts_changed_p
= 1;
7921 return change_height_p
;
7925 /* Get information about the tool-bar item which is displayed in GLYPH
7926 on frame F. Return in *PROP_IDX the index where tool-bar item
7927 properties start in F->tool_bar_items. Value is zero if
7928 GLYPH doesn't display a tool-bar item. */
7931 tool_bar_item_info (f
, glyph
, prop_idx
)
7933 struct glyph
*glyph
;
7940 /* This function can be called asynchronously, which means we must
7941 exclude any possibility that Fget_text_property signals an
7943 charpos
= min (XSTRING (f
->current_tool_bar_string
)->size
, glyph
->charpos
);
7944 charpos
= max (0, charpos
);
7946 /* Get the text property `menu-item' at pos. The value of that
7947 property is the start index of this item's properties in
7948 F->tool_bar_items. */
7949 prop
= Fget_text_property (make_number (charpos
),
7950 Qmenu_item
, f
->current_tool_bar_string
);
7951 if (INTEGERP (prop
))
7953 *prop_idx
= XINT (prop
);
7962 #endif /* HAVE_WINDOW_SYSTEM */
7966 /************************************************************************
7967 Horizontal scrolling
7968 ************************************************************************/
7970 static int hscroll_window_tree
P_ ((Lisp_Object
));
7971 static int hscroll_windows
P_ ((Lisp_Object
));
7973 /* For all leaf windows in the window tree rooted at WINDOW, set their
7974 hscroll value so that PT is (i) visible in the window, and (ii) so
7975 that it is not within a certain margin at the window's left and
7976 right border. Value is non-zero if any window's hscroll has been
7980 hscroll_window_tree (window
)
7983 int hscrolled_p
= 0;
7985 while (WINDOWP (window
))
7987 struct window
*w
= XWINDOW (window
);
7989 if (WINDOWP (w
->hchild
))
7990 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7991 else if (WINDOWP (w
->vchild
))
7992 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7993 else if (w
->cursor
.vpos
>= 0)
7995 int hscroll_margin
, text_area_x
, text_area_y
;
7996 int text_area_width
, text_area_height
;
7997 struct glyph_row
*current_cursor_row
7998 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7999 struct glyph_row
*desired_cursor_row
8000 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
8001 struct glyph_row
*cursor_row
8002 = (desired_cursor_row
->enabled_p
8003 ? desired_cursor_row
8004 : current_cursor_row
);
8006 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8007 &text_area_width
, &text_area_height
);
8009 /* Scroll when cursor is inside this scroll margin. */
8010 /* Shouldn't we export this `5' for customization ? -stef */
8011 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
8013 if ((XFASTINT (w
->hscroll
)
8014 && w
->cursor
.x
< hscroll_margin
)
8015 || (cursor_row
->enabled_p
8016 && cursor_row
->truncated_on_right_p
8017 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
8021 struct buffer
*saved_current_buffer
;
8024 /* Find point in a display of infinite width. */
8025 saved_current_buffer
= current_buffer
;
8026 current_buffer
= XBUFFER (w
->buffer
);
8028 if (w
== XWINDOW (selected_window
))
8029 pt
= BUF_PT (current_buffer
);
8032 pt
= marker_position (w
->pointm
);
8033 pt
= max (BEGV
, pt
);
8037 /* Move iterator to pt starting at cursor_row->start in
8038 a line with infinite width. */
8039 init_to_row_start (&it
, w
, cursor_row
);
8040 it
.last_visible_x
= INFINITY
;
8041 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8042 current_buffer
= saved_current_buffer
;
8044 /* Center cursor in window. */
8045 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
8046 / CANON_X_UNIT (it
.f
));
8047 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8049 /* Don't call Fset_window_hscroll if value hasn't
8050 changed because it will prevent redisplay
8052 if (XFASTINT (w
->hscroll
) != hscroll
)
8054 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8055 w
->hscroll
= make_number (hscroll
);
8064 /* Value is non-zero if hscroll of any leaf window has been changed. */
8069 /* Set hscroll so that cursor is visible and not inside horizontal
8070 scroll margins for all windows in the tree rooted at WINDOW. See
8071 also hscroll_window_tree above. Value is non-zero if any window's
8072 hscroll has been changed. If it has, desired matrices on the frame
8073 of WINDOW are cleared. */
8076 hscroll_windows (window
)
8081 if (automatic_hscrolling_p
)
8083 hscrolled_p
= hscroll_window_tree (window
);
8085 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8094 /************************************************************************
8096 ************************************************************************/
8098 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8099 to a non-zero value. This is sometimes handy to have in a debugger
8104 /* First and last unchanged row for try_window_id. */
8106 int debug_first_unchanged_at_end_vpos
;
8107 int debug_last_unchanged_at_beg_vpos
;
8109 /* Delta vpos and y. */
8111 int debug_dvpos
, debug_dy
;
8113 /* Delta in characters and bytes for try_window_id. */
8115 int debug_delta
, debug_delta_bytes
;
8117 /* Values of window_end_pos and window_end_vpos at the end of
8120 int debug_end_pos
, debug_end_vpos
;
8122 /* Append a string to W->desired_matrix->method. FMT is a printf
8123 format string. A1...A9 are a supplement for a variable-length
8124 argument list. If trace_redisplay_p is non-zero also printf the
8125 resulting string to stderr. */
8128 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8131 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8134 char *method
= w
->desired_matrix
->method
;
8135 int len
= strlen (method
);
8136 int size
= sizeof w
->desired_matrix
->method
;
8137 int remaining
= size
- len
- 1;
8139 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8140 if (len
&& remaining
)
8146 strncpy (method
+ len
, buffer
, remaining
);
8148 if (trace_redisplay_p
)
8149 fprintf (stderr
, "%p (%s): %s\n",
8151 ((BUFFERP (w
->buffer
)
8152 && STRINGP (XBUFFER (w
->buffer
)->name
))
8153 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
8158 #endif /* GLYPH_DEBUG */
8161 /* This counter is used to clear the face cache every once in a while
8162 in redisplay_internal. It is incremented for each redisplay.
8163 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8166 #define CLEAR_FACE_CACHE_COUNT 10000
8167 static int clear_face_cache_count
;
8169 /* Record the previous terminal frame we displayed. */
8171 static struct frame
*previous_terminal_frame
;
8173 /* Non-zero while redisplay_internal is in progress. */
8178 /* Value is non-zero if all changes in window W, which displays
8179 current_buffer, are in the text between START and END. START is a
8180 buffer position, END is given as a distance from Z. Used in
8181 redisplay_internal for display optimization. */
8184 text_outside_line_unchanged_p (w
, start
, end
)
8188 int unchanged_p
= 1;
8190 /* If text or overlays have changed, see where. */
8191 if (XFASTINT (w
->last_modified
) < MODIFF
8192 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8194 /* Gap in the line? */
8195 if (GPT
< start
|| Z
- GPT
< end
)
8198 /* Changes start in front of the line, or end after it? */
8200 && (BEG_UNCHANGED
< start
- 1
8201 || END_UNCHANGED
< end
))
8204 /* If selective display, can't optimize if changes start at the
8205 beginning of the line. */
8207 && INTEGERP (current_buffer
->selective_display
)
8208 && XINT (current_buffer
->selective_display
) > 0
8209 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8212 /* If there are overlays at the start or end of the line, these
8213 may have overlay strings with newlines in them. A change at
8214 START, for instance, may actually concern the display of such
8215 overlay strings as well, and they are displayed on different
8216 lines. So, quickly rule out this case. (For the future, it
8217 might be desirable to implement something more telling than
8218 just BEG/END_UNCHANGED.) */
8221 if (BEG
+ BEG_UNCHANGED
== start
8222 && overlay_touches_p (start
))
8224 if (END_UNCHANGED
== end
8225 && overlay_touches_p (Z
- end
))
8234 /* Do a frame update, taking possible shortcuts into account. This is
8235 the main external entry point for redisplay.
8237 If the last redisplay displayed an echo area message and that message
8238 is no longer requested, we clear the echo area or bring back the
8239 mini-buffer if that is in use. */
8244 redisplay_internal (0);
8248 /* Return 1 if point moved out of or into a composition. Otherwise
8249 return 0. PREV_BUF and PREV_PT are the last point buffer and
8250 position. BUF and PT are the current point buffer and position. */
8253 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8254 struct buffer
*prev_buf
, *buf
;
8261 XSETBUFFER (buffer
, buf
);
8262 /* Check a composition at the last point if point moved within the
8264 if (prev_buf
== buf
)
8267 /* Point didn't move. */
8270 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8271 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8272 && COMPOSITION_VALID_P (start
, end
, prop
)
8273 && start
< prev_pt
&& end
> prev_pt
)
8274 /* The last point was within the composition. Return 1 iff
8275 point moved out of the composition. */
8276 return (pt
<= start
|| pt
>= end
);
8279 /* Check a composition at the current point. */
8280 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8281 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8282 && COMPOSITION_VALID_P (start
, end
, prop
)
8283 && start
< pt
&& end
> pt
);
8287 /* Reconsider the setting of B->clip_changed which is displayed
8291 reconsider_clip_changes (w
, b
)
8295 if (b
->prevent_redisplay_optimizations_p
)
8296 b
->clip_changed
= 1;
8297 else if (b
->clip_changed
8298 && !NILP (w
->window_end_valid
)
8299 && w
->current_matrix
->buffer
== b
8300 && w
->current_matrix
->zv
== BUF_ZV (b
)
8301 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8302 b
->clip_changed
= 0;
8304 /* If display wasn't paused, and W is not a tool bar window, see if
8305 point has been moved into or out of a composition. In that case,
8306 we set b->clip_changed to 1 to force updating the screen. If
8307 b->clip_changed has already been set to 1, we can skip this
8309 if (!b
->clip_changed
8310 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8314 if (w
== XWINDOW (selected_window
))
8315 pt
= BUF_PT (current_buffer
);
8317 pt
= marker_position (w
->pointm
);
8319 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8320 || pt
!= XINT (w
->last_point
))
8321 && check_point_in_composition (w
->current_matrix
->buffer
,
8322 XINT (w
->last_point
),
8323 XBUFFER (w
->buffer
), pt
))
8324 b
->clip_changed
= 1;
8329 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8330 response to any user action; therefore, we should preserve the echo
8331 area. (Actually, our caller does that job.) Perhaps in the future
8332 avoid recentering windows if it is not necessary; currently that
8333 causes some problems. */
8336 redisplay_internal (preserve_echo_area
)
8337 int preserve_echo_area
;
8339 struct window
*w
= XWINDOW (selected_window
);
8340 struct frame
*f
= XFRAME (w
->frame
);
8342 int must_finish
= 0;
8343 struct text_pos tlbufpos
, tlendpos
;
8344 int number_of_visible_frames
;
8346 struct frame
*sf
= SELECTED_FRAME ();
8348 /* Non-zero means redisplay has to consider all windows on all
8349 frames. Zero means, only selected_window is considered. */
8350 int consider_all_windows_p
;
8352 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8354 /* No redisplay if running in batch mode or frame is not yet fully
8355 initialized, or redisplay is explicitly turned off by setting
8356 Vinhibit_redisplay. */
8358 || !NILP (Vinhibit_redisplay
)
8359 || !f
->glyphs_initialized_p
)
8362 /* The flag redisplay_performed_directly_p is set by
8363 direct_output_for_insert when it already did the whole screen
8364 update necessary. */
8365 if (redisplay_performed_directly_p
)
8367 redisplay_performed_directly_p
= 0;
8368 if (!hscroll_windows (selected_window
))
8372 #ifdef USE_X_TOOLKIT
8373 if (popup_activated ())
8377 /* I don't think this happens but let's be paranoid. */
8381 /* Record a function that resets redisplaying_p to its old value
8382 when we leave this function. */
8383 count
= BINDING_STACK_SIZE ();
8384 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8389 reconsider_clip_changes (w
, current_buffer
);
8391 /* If new fonts have been loaded that make a glyph matrix adjustment
8392 necessary, do it. */
8393 if (fonts_changed_p
)
8395 adjust_glyphs (NULL
);
8396 ++windows_or_buffers_changed
;
8397 fonts_changed_p
= 0;
8400 /* If face_change_count is non-zero, init_iterator will free all
8401 realized faces, which includes the faces referenced from current
8402 matrices. So, we can't reuse current matrices in this case. */
8403 if (face_change_count
)
8404 ++windows_or_buffers_changed
;
8406 if (! FRAME_WINDOW_P (sf
)
8407 && previous_terminal_frame
!= sf
)
8409 /* Since frames on an ASCII terminal share the same display
8410 area, displaying a different frame means redisplay the whole
8412 windows_or_buffers_changed
++;
8413 SET_FRAME_GARBAGED (sf
);
8414 XSETFRAME (Vterminal_frame
, sf
);
8416 previous_terminal_frame
= sf
;
8418 /* Set the visible flags for all frames. Do this before checking
8419 for resized or garbaged frames; they want to know if their frames
8420 are visible. See the comment in frame.h for
8421 FRAME_SAMPLE_VISIBILITY. */
8423 Lisp_Object tail
, frame
;
8425 number_of_visible_frames
= 0;
8427 FOR_EACH_FRAME (tail
, frame
)
8429 struct frame
*f
= XFRAME (frame
);
8431 FRAME_SAMPLE_VISIBILITY (f
);
8432 if (FRAME_VISIBLE_P (f
))
8433 ++number_of_visible_frames
;
8434 clear_desired_matrices (f
);
8438 /* Notice any pending interrupt request to change frame size. */
8439 do_pending_window_change (1);
8441 /* Clear frames marked as garbaged. */
8443 clear_garbaged_frames ();
8445 /* Build menubar and tool-bar items. */
8446 prepare_menu_bars ();
8448 if (windows_or_buffers_changed
)
8449 update_mode_lines
++;
8451 /* Detect case that we need to write or remove a star in the mode line. */
8452 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8454 w
->update_mode_line
= Qt
;
8455 if (buffer_shared
> 1)
8456 update_mode_lines
++;
8459 /* If %c is in the mode line, update it if needed. */
8460 if (!NILP (w
->column_number_displayed
)
8461 /* This alternative quickly identifies a common case
8462 where no change is needed. */
8463 && !(PT
== XFASTINT (w
->last_point
)
8464 && XFASTINT (w
->last_modified
) >= MODIFF
8465 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8466 && XFASTINT (w
->column_number_displayed
) != current_column ())
8467 w
->update_mode_line
= Qt
;
8469 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8471 /* The variable buffer_shared is set in redisplay_window and
8472 indicates that we redisplay a buffer in different windows. See
8474 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8476 /* If specs for an arrow have changed, do thorough redisplay
8477 to ensure we remove any arrow that should no longer exist. */
8478 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8479 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8480 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8482 /* Normally the message* functions will have already displayed and
8483 updated the echo area, but the frame may have been trashed, or
8484 the update may have been preempted, so display the echo area
8485 again here. Checking message_cleared_p captures the case that
8486 the echo area should be cleared. */
8487 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8488 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8489 || (message_cleared_p
8490 && minibuf_level
== 0
8491 /* If the mini-window is currently selected, this means the
8492 echo-area doesn't show through. */
8493 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8495 int window_height_changed_p
= echo_area_display (0);
8498 /* If we don't display the current message, don't clear the
8499 message_cleared_p flag, because, if we did, we wouldn't clear
8500 the echo area in the next redisplay which doesn't preserve
8502 if (!display_last_displayed_message_p
)
8503 message_cleared_p
= 0;
8505 if (fonts_changed_p
)
8507 else if (window_height_changed_p
)
8509 consider_all_windows_p
= 1;
8510 ++update_mode_lines
;
8511 ++windows_or_buffers_changed
;
8513 /* If window configuration was changed, frames may have been
8514 marked garbaged. Clear them or we will experience
8515 surprises wrt scrolling. */
8517 clear_garbaged_frames ();
8520 else if (EQ (selected_window
, minibuf_window
)
8521 && (current_buffer
->clip_changed
8522 || XFASTINT (w
->last_modified
) < MODIFF
8523 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8524 && resize_mini_window (w
, 0))
8526 /* Resized active mini-window to fit the size of what it is
8527 showing if its contents might have changed. */
8529 consider_all_windows_p
= 1;
8530 ++windows_or_buffers_changed
;
8531 ++update_mode_lines
;
8533 /* If window configuration was changed, frames may have been
8534 marked garbaged. Clear them or we will experience
8535 surprises wrt scrolling. */
8537 clear_garbaged_frames ();
8541 /* If showing the region, and mark has changed, we must redisplay
8542 the whole window. The assignment to this_line_start_pos prevents
8543 the optimization directly below this if-statement. */
8544 if (((!NILP (Vtransient_mark_mode
)
8545 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8546 != !NILP (w
->region_showing
))
8547 || (!NILP (w
->region_showing
)
8548 && !EQ (w
->region_showing
,
8549 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8550 CHARPOS (this_line_start_pos
) = 0;
8552 /* Optimize the case that only the line containing the cursor in the
8553 selected window has changed. Variables starting with this_ are
8554 set in display_line and record information about the line
8555 containing the cursor. */
8556 tlbufpos
= this_line_start_pos
;
8557 tlendpos
= this_line_end_pos
;
8558 if (!consider_all_windows_p
8559 && CHARPOS (tlbufpos
) > 0
8560 && NILP (w
->update_mode_line
)
8561 && !current_buffer
->clip_changed
8562 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8563 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8564 /* Make sure recorded data applies to current buffer, etc. */
8565 && this_line_buffer
== current_buffer
8566 && current_buffer
== XBUFFER (w
->buffer
)
8567 && NILP (w
->force_start
)
8568 /* Point must be on the line that we have info recorded about. */
8569 && PT
>= CHARPOS (tlbufpos
)
8570 && PT
<= Z
- CHARPOS (tlendpos
)
8571 /* All text outside that line, including its final newline,
8572 must be unchanged */
8573 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8574 CHARPOS (tlendpos
)))
8576 if (CHARPOS (tlbufpos
) > BEGV
8577 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8578 && (CHARPOS (tlbufpos
) == ZV
8579 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8580 /* Former continuation line has disappeared by becoming empty */
8582 else if (XFASTINT (w
->last_modified
) < MODIFF
8583 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8584 || MINI_WINDOW_P (w
))
8586 /* We have to handle the case of continuation around a
8587 wide-column character (See the comment in indent.c around
8590 For instance, in the following case:
8592 -------- Insert --------
8593 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8594 J_I_ ==> J_I_ `^^' are cursors.
8598 As we have to redraw the line above, we should goto cancel. */
8601 int line_height_before
= this_line_pixel_height
;
8603 /* Note that start_display will handle the case that the
8604 line starting at tlbufpos is a continuation lines. */
8605 start_display (&it
, w
, tlbufpos
);
8607 /* Implementation note: It this still necessary? */
8608 if (it
.current_x
!= this_line_start_x
)
8611 TRACE ((stderr
, "trying display optimization 1\n"));
8612 w
->cursor
.vpos
= -1;
8613 overlay_arrow_seen
= 0;
8614 it
.vpos
= this_line_vpos
;
8615 it
.current_y
= this_line_y
;
8616 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8619 /* If line contains point, is not continued,
8620 and ends at same distance from eob as before, we win */
8621 if (w
->cursor
.vpos
>= 0
8622 /* Line is not continued, otherwise this_line_start_pos
8623 would have been set to 0 in display_line. */
8624 && CHARPOS (this_line_start_pos
)
8625 /* Line ends as before. */
8626 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8627 /* Line has same height as before. Otherwise other lines
8628 would have to be shifted up or down. */
8629 && this_line_pixel_height
== line_height_before
)
8631 /* If this is not the window's last line, we must adjust
8632 the charstarts of the lines below. */
8633 if (it
.current_y
< it
.last_visible_y
)
8635 struct glyph_row
*row
8636 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8637 int delta
, delta_bytes
;
8639 if (Z
- CHARPOS (tlendpos
) == ZV
)
8641 /* This line ends at end of (accessible part of)
8642 buffer. There is no newline to count. */
8644 - CHARPOS (tlendpos
)
8645 - MATRIX_ROW_START_CHARPOS (row
));
8646 delta_bytes
= (Z_BYTE
8647 - BYTEPOS (tlendpos
)
8648 - MATRIX_ROW_START_BYTEPOS (row
));
8652 /* This line ends in a newline. Must take
8653 account of the newline and the rest of the
8654 text that follows. */
8656 - CHARPOS (tlendpos
)
8657 - MATRIX_ROW_START_CHARPOS (row
));
8658 delta_bytes
= (Z_BYTE
8659 - BYTEPOS (tlendpos
)
8660 - MATRIX_ROW_START_BYTEPOS (row
));
8663 increment_matrix_positions (w
->current_matrix
,
8665 w
->current_matrix
->nrows
,
8666 delta
, delta_bytes
);
8669 /* If this row displays text now but previously didn't,
8670 or vice versa, w->window_end_vpos may have to be
8672 if ((it
.glyph_row
- 1)->displays_text_p
)
8674 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8675 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8677 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8678 && this_line_vpos
> 0)
8679 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8680 w
->window_end_valid
= Qnil
;
8682 /* Update hint: No need to try to scroll in update_window. */
8683 w
->desired_matrix
->no_scrolling_p
= 1;
8686 *w
->desired_matrix
->method
= 0;
8687 debug_method_add (w
, "optimization 1");
8694 else if (/* Cursor position hasn't changed. */
8695 PT
== XFASTINT (w
->last_point
)
8696 /* Make sure the cursor was last displayed
8697 in this window. Otherwise we have to reposition it. */
8698 && 0 <= w
->cursor
.vpos
8699 && XINT (w
->height
) > w
->cursor
.vpos
)
8703 do_pending_window_change (1);
8705 /* We used to always goto end_of_redisplay here, but this
8706 isn't enough if we have a blinking cursor. */
8707 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8708 goto end_of_redisplay
;
8712 /* If highlighting the region, or if the cursor is in the echo area,
8713 then we can't just move the cursor. */
8714 else if (! (!NILP (Vtransient_mark_mode
)
8715 && !NILP (current_buffer
->mark_active
))
8716 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8717 || highlight_nonselected_windows
)
8718 && NILP (w
->region_showing
)
8719 && NILP (Vshow_trailing_whitespace
)
8720 && !cursor_in_echo_area
)
8723 struct glyph_row
*row
;
8725 /* Skip from tlbufpos to PT and see where it is. Note that
8726 PT may be in invisible text. If so, we will end at the
8727 next visible position. */
8728 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8729 NULL
, DEFAULT_FACE_ID
);
8730 it
.current_x
= this_line_start_x
;
8731 it
.current_y
= this_line_y
;
8732 it
.vpos
= this_line_vpos
;
8734 /* The call to move_it_to stops in front of PT, but
8735 moves over before-strings. */
8736 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8738 if (it
.vpos
== this_line_vpos
8739 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8742 xassert (this_line_vpos
== it
.vpos
);
8743 xassert (this_line_y
== it
.current_y
);
8744 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8746 *w
->desired_matrix
->method
= 0;
8747 debug_method_add (w
, "optimization 3");
8756 /* Text changed drastically or point moved off of line. */
8757 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8760 CHARPOS (this_line_start_pos
) = 0;
8761 consider_all_windows_p
|= buffer_shared
> 1;
8762 ++clear_face_cache_count
;
8765 /* Build desired matrices, and update the display. If
8766 consider_all_windows_p is non-zero, do it for all windows on all
8767 frames. Otherwise do it for selected_window, only. */
8769 if (consider_all_windows_p
)
8771 Lisp_Object tail
, frame
;
8772 int i
, n
= 0, size
= 50;
8773 struct frame
**updated
8774 = (struct frame
**) alloca (size
* sizeof *updated
);
8776 /* Clear the face cache eventually. */
8777 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8779 clear_face_cache (0);
8780 clear_face_cache_count
= 0;
8783 /* Recompute # windows showing selected buffer. This will be
8784 incremented each time such a window is displayed. */
8787 FOR_EACH_FRAME (tail
, frame
)
8789 struct frame
*f
= XFRAME (frame
);
8791 if (FRAME_WINDOW_P (f
) || f
== sf
)
8793 /* Mark all the scroll bars to be removed; we'll redeem
8794 the ones we want when we redisplay their windows. */
8795 if (condemn_scroll_bars_hook
)
8796 condemn_scroll_bars_hook (f
);
8798 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8799 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8801 /* Any scroll bars which redisplay_windows should have
8802 nuked should now go away. */
8803 if (judge_scroll_bars_hook
)
8804 judge_scroll_bars_hook (f
);
8806 /* If fonts changed, display again. */
8807 if (fonts_changed_p
)
8810 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8812 /* See if we have to hscroll. */
8813 if (hscroll_windows (f
->root_window
))
8816 /* Prevent various kinds of signals during display
8817 update. stdio is not robust about handling
8818 signals, which can cause an apparent I/O
8820 if (interrupt_input
)
8824 /* Update the display. */
8825 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8826 pause
|= update_frame (f
, 0, 0);
8832 int nbytes
= size
* sizeof *updated
;
8833 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8834 bcopy (updated
, p
, nbytes
);
8843 /* Do the mark_window_display_accurate after all windows have
8844 been redisplayed because this call resets flags in buffers
8845 which are needed for proper redisplay. */
8846 for (i
= 0; i
< n
; ++i
)
8848 struct frame
*f
= updated
[i
];
8849 mark_window_display_accurate (f
->root_window
, 1);
8850 if (frame_up_to_date_hook
)
8851 frame_up_to_date_hook (f
);
8854 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8856 Lisp_Object mini_window
;
8857 struct frame
*mini_frame
;
8859 redisplay_window (selected_window
, 1);
8861 /* Compare desired and current matrices, perform output. */
8864 /* If fonts changed, display again. */
8865 if (fonts_changed_p
)
8868 /* Prevent various kinds of signals during display update.
8869 stdio is not robust about handling signals,
8870 which can cause an apparent I/O error. */
8871 if (interrupt_input
)
8875 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8877 if (hscroll_windows (selected_window
))
8880 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8881 pause
= update_frame (sf
, 0, 0);
8884 /* We may have called echo_area_display at the top of this
8885 function. If the echo area is on another frame, that may
8886 have put text on a frame other than the selected one, so the
8887 above call to update_frame would not have caught it. Catch
8889 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8890 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8892 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8894 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8895 pause
|= update_frame (mini_frame
, 0, 0);
8896 if (!pause
&& hscroll_windows (mini_window
))
8901 /* If display was paused because of pending input, make sure we do a
8902 thorough update the next time. */
8905 /* Prevent the optimization at the beginning of
8906 redisplay_internal that tries a single-line update of the
8907 line containing the cursor in the selected window. */
8908 CHARPOS (this_line_start_pos
) = 0;
8910 /* Let the overlay arrow be updated the next time. */
8911 if (!NILP (last_arrow_position
))
8913 last_arrow_position
= Qt
;
8914 last_arrow_string
= Qt
;
8917 /* If we pause after scrolling, some rows in the current
8918 matrices of some windows are not valid. */
8919 if (!WINDOW_FULL_WIDTH_P (w
)
8920 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8921 update_mode_lines
= 1;
8925 if (!consider_all_windows_p
)
8927 /* This has already been done above if
8928 consider_all_windows_p is set. */
8929 mark_window_display_accurate_1 (w
, 1);
8931 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8932 last_arrow_string
= Voverlay_arrow_string
;
8934 if (frame_up_to_date_hook
!= 0)
8935 frame_up_to_date_hook (sf
);
8938 update_mode_lines
= 0;
8939 windows_or_buffers_changed
= 0;
8942 /* Start SIGIO interrupts coming again. Having them off during the
8943 code above makes it less likely one will discard output, but not
8944 impossible, since there might be stuff in the system buffer here.
8945 But it is much hairier to try to do anything about that. */
8946 if (interrupt_input
)
8950 /* If a frame has become visible which was not before, redisplay
8951 again, so that we display it. Expose events for such a frame
8952 (which it gets when becoming visible) don't call the parts of
8953 redisplay constructing glyphs, so simply exposing a frame won't
8954 display anything in this case. So, we have to display these
8955 frames here explicitly. */
8958 Lisp_Object tail
, frame
;
8961 FOR_EACH_FRAME (tail
, frame
)
8963 int this_is_visible
= 0;
8965 if (XFRAME (frame
)->visible
)
8966 this_is_visible
= 1;
8967 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8968 if (XFRAME (frame
)->visible
)
8969 this_is_visible
= 1;
8971 if (this_is_visible
)
8975 if (new_count
!= number_of_visible_frames
)
8976 windows_or_buffers_changed
++;
8979 /* Change frame size now if a change is pending. */
8980 do_pending_window_change (1);
8982 /* If we just did a pending size change, or have additional
8983 visible frames, redisplay again. */
8984 if (windows_or_buffers_changed
&& !pause
)
8989 unbind_to (count
, Qnil
);
8993 /* Redisplay, but leave alone any recent echo area message unless
8994 another message has been requested in its place.
8996 This is useful in situations where you need to redisplay but no
8997 user action has occurred, making it inappropriate for the message
8998 area to be cleared. See tracking_off and
8999 wait_reading_process_input for examples of these situations.
9001 FROM_WHERE is an integer saying from where this function was
9002 called. This is useful for debugging. */
9005 redisplay_preserve_echo_area (from_where
)
9008 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9010 if (!NILP (echo_area_buffer
[1]))
9012 /* We have a previously displayed message, but no current
9013 message. Redisplay the previous message. */
9014 display_last_displayed_message_p
= 1;
9015 redisplay_internal (1);
9016 display_last_displayed_message_p
= 0;
9019 redisplay_internal (1);
9023 /* Function registered with record_unwind_protect in
9024 redisplay_internal. Clears the flag indicating that a redisplay is
9028 unwind_redisplay (old_redisplaying_p
)
9029 Lisp_Object old_redisplaying_p
;
9031 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9036 /* Mark the display of window W as accurate or inaccurate. If
9037 ACCURATE_P is non-zero mark display of W as accurate. If
9038 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9039 redisplay_internal is called. */
9042 mark_window_display_accurate_1 (w
, accurate_p
)
9046 if (BUFFERP (w
->buffer
))
9048 struct buffer
*b
= XBUFFER (w
->buffer
);
9051 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9052 w
->last_overlay_modified
9053 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9055 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9059 b
->clip_changed
= 0;
9060 b
->prevent_redisplay_optimizations_p
= 0;
9062 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9063 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9064 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9065 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9067 w
->current_matrix
->buffer
= b
;
9068 w
->current_matrix
->begv
= BUF_BEGV (b
);
9069 w
->current_matrix
->zv
= BUF_ZV (b
);
9071 w
->last_cursor
= w
->cursor
;
9072 w
->last_cursor_off_p
= w
->cursor_off_p
;
9074 if (w
== XWINDOW (selected_window
))
9075 w
->last_point
= make_number (BUF_PT (b
));
9077 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9083 w
->window_end_valid
= w
->buffer
;
9084 #if 0 /* This is incorrect with variable-height lines. */
9085 xassert (XINT (w
->window_end_vpos
)
9087 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9089 w
->update_mode_line
= Qnil
;
9094 /* Mark the display of windows in the window tree rooted at WINDOW as
9095 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9096 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9097 be redisplayed the next time redisplay_internal is called. */
9100 mark_window_display_accurate (window
, accurate_p
)
9106 for (; !NILP (window
); window
= w
->next
)
9108 w
= XWINDOW (window
);
9109 mark_window_display_accurate_1 (w
, accurate_p
);
9111 if (!NILP (w
->vchild
))
9112 mark_window_display_accurate (w
->vchild
, accurate_p
);
9113 if (!NILP (w
->hchild
))
9114 mark_window_display_accurate (w
->hchild
, accurate_p
);
9119 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9120 last_arrow_string
= Voverlay_arrow_string
;
9124 /* Force a thorough redisplay the next time by setting
9125 last_arrow_position and last_arrow_string to t, which is
9126 unequal to any useful value of Voverlay_arrow_... */
9127 last_arrow_position
= Qt
;
9128 last_arrow_string
= Qt
;
9133 /* Return value in display table DP (Lisp_Char_Table *) for character
9134 C. Since a display table doesn't have any parent, we don't have to
9135 follow parent. Do not call this function directly but use the
9136 macro DISP_CHAR_VECTOR. */
9139 disp_char_vector (dp
, c
)
9140 struct Lisp_Char_Table
*dp
;
9146 if (SINGLE_BYTE_CHAR_P (c
))
9147 return (dp
->contents
[c
]);
9149 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9152 else if (code
[2] < 32)
9155 /* Here, the possible range of code[0] (== charset ID) is
9156 128..max_charset. Since the top level char table contains data
9157 for multibyte characters after 256th element, we must increment
9158 code[0] by 128 to get a correct index. */
9160 code
[3] = -1; /* anchor */
9162 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9164 val
= dp
->contents
[code
[i
]];
9165 if (!SUB_CHAR_TABLE_P (val
))
9166 return (NILP (val
) ? dp
->defalt
: val
);
9169 /* Here, val is a sub char table. We return the default value of
9171 return (dp
->defalt
);
9176 /***********************************************************************
9178 ***********************************************************************/
9180 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9183 redisplay_windows (window
)
9186 while (!NILP (window
))
9188 struct window
*w
= XWINDOW (window
);
9190 if (!NILP (w
->hchild
))
9191 redisplay_windows (w
->hchild
);
9192 else if (!NILP (w
->vchild
))
9193 redisplay_windows (w
->vchild
);
9195 redisplay_window (window
, 0);
9202 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9203 DELTA is the number of bytes by which positions recorded in ROW
9204 differ from current buffer positions. */
9207 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9209 struct glyph_row
*row
;
9210 struct glyph_matrix
*matrix
;
9211 int delta
, delta_bytes
, dy
, dvpos
;
9213 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9214 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9216 int pt_old
= PT
- delta
;
9218 /* Skip over glyphs not having an object at the start of the row.
9219 These are special glyphs like truncation marks on terminal
9221 if (row
->displays_text_p
)
9223 && INTEGERP (glyph
->object
)
9224 && glyph
->charpos
< 0)
9226 x
+= glyph
->pixel_width
;
9231 && !INTEGERP (glyph
->object
)
9232 && (!BUFFERP (glyph
->object
)
9233 || glyph
->charpos
< pt_old
))
9235 x
+= glyph
->pixel_width
;
9239 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9241 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9242 w
->cursor
.y
= row
->y
+ dy
;
9244 if (w
== XWINDOW (selected_window
))
9246 if (!row
->continued_p
9247 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9250 this_line_buffer
= XBUFFER (w
->buffer
);
9252 CHARPOS (this_line_start_pos
)
9253 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9254 BYTEPOS (this_line_start_pos
)
9255 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9257 CHARPOS (this_line_end_pos
)
9258 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9259 BYTEPOS (this_line_end_pos
)
9260 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9262 this_line_y
= w
->cursor
.y
;
9263 this_line_pixel_height
= row
->height
;
9264 this_line_vpos
= w
->cursor
.vpos
;
9265 this_line_start_x
= row
->x
;
9268 CHARPOS (this_line_start_pos
) = 0;
9273 /* Run window scroll functions, if any, for WINDOW with new window
9274 start STARTP. Sets the window start of WINDOW to that position.
9276 We assume that the window's buffer is really current. */
9278 static INLINE
struct text_pos
9279 run_window_scroll_functions (window
, startp
)
9281 struct text_pos startp
;
9283 struct window
*w
= XWINDOW (window
);
9284 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9286 if (current_buffer
!= XBUFFER (w
->buffer
))
9289 if (!NILP (Vwindow_scroll_functions
))
9291 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9292 make_number (CHARPOS (startp
)));
9293 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9294 /* In case the hook functions switch buffers. */
9295 if (current_buffer
!= XBUFFER (w
->buffer
))
9296 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9303 /* Modify the desired matrix of window W and W->vscroll so that the
9304 line containing the cursor is fully visible. If this requires
9305 larger matrices than are allocated, set fonts_changed_p and return
9309 make_cursor_line_fully_visible (w
)
9312 struct glyph_matrix
*matrix
;
9313 struct glyph_row
*row
;
9316 /* It's not always possible to find the cursor, e.g, when a window
9317 is full of overlay strings. Don't do anything in that case. */
9318 if (w
->cursor
.vpos
< 0)
9321 matrix
= w
->desired_matrix
;
9322 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9324 /* If the cursor row is not partially visible, there's nothing
9326 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9329 /* If the row the cursor is in is taller than the window's height,
9330 it's not clear what to do, so do nothing. */
9331 window_height
= window_box_height (w
);
9332 if (row
->height
>= window_height
)
9335 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9337 int dy
= row
->height
- row
->visible_height
;
9340 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9342 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9344 int dy
= - (row
->height
- row
->visible_height
);
9347 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9350 /* When we change the cursor y-position of the selected window,
9351 change this_line_y as well so that the display optimization for
9352 the cursor line of the selected window in redisplay_internal uses
9353 the correct y-position. */
9354 if (w
== XWINDOW (selected_window
))
9355 this_line_y
= w
->cursor
.y
;
9357 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9358 redisplay with larger matrices. */
9359 if (matrix
->nrows
< required_matrix_height (w
))
9361 fonts_changed_p
= 1;
9369 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9370 non-zero means only WINDOW is redisplayed in redisplay_internal.
9371 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9372 in redisplay_window to bring a partially visible line into view in
9373 the case that only the cursor has moved.
9377 1 if scrolling succeeded
9379 0 if scrolling didn't find point.
9381 -1 if new fonts have been loaded so that we must interrupt
9382 redisplay, adjust glyph matrices, and try again. */
9388 SCROLLING_NEED_LARGER_MATRICES
9392 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9393 scroll_step
, temp_scroll_step
)
9395 int just_this_one_p
;
9396 int scroll_conservatively
, scroll_step
;
9397 int temp_scroll_step
;
9399 struct window
*w
= XWINDOW (window
);
9400 struct frame
*f
= XFRAME (w
->frame
);
9401 struct text_pos scroll_margin_pos
;
9402 struct text_pos pos
;
9403 struct text_pos startp
;
9405 Lisp_Object window_end
;
9406 int this_scroll_margin
;
9410 int amount_to_scroll
= 0;
9411 Lisp_Object aggressive
;
9415 debug_method_add (w
, "try_scrolling");
9418 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9420 /* Compute scroll margin height in pixels. We scroll when point is
9421 within this distance from the top or bottom of the window. */
9422 if (scroll_margin
> 0)
9424 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9425 this_scroll_margin
*= CANON_Y_UNIT (f
);
9428 this_scroll_margin
= 0;
9430 /* Compute how much we should try to scroll maximally to bring point
9432 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9433 scroll_max
= max (scroll_step
,
9434 max (scroll_conservatively
, temp_scroll_step
));
9435 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9436 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9437 /* We're trying to scroll because of aggressive scrolling
9438 but no scroll_step is set. Choose an arbitrary one. Maybe
9439 there should be a variable for this. */
9443 scroll_max
*= CANON_Y_UNIT (f
);
9445 /* Decide whether we have to scroll down. Start at the window end
9446 and move this_scroll_margin up to find the position of the scroll
9448 window_end
= Fwindow_end (window
, Qt
);
9449 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9450 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9451 if (this_scroll_margin
)
9453 start_display (&it
, w
, scroll_margin_pos
);
9454 move_it_vertically (&it
, - this_scroll_margin
);
9455 scroll_margin_pos
= it
.current
.pos
;
9458 if (PT
>= CHARPOS (scroll_margin_pos
))
9462 /* Point is in the scroll margin at the bottom of the window, or
9463 below. Compute a new window start that makes point visible. */
9465 /* Compute the distance from the scroll margin to PT.
9466 Give up if the distance is greater than scroll_max. */
9467 start_display (&it
, w
, scroll_margin_pos
);
9469 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9470 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9472 /* With a scroll_margin of 0, scroll_margin_pos is at the window
9473 end, which is one line below the window. The iterator's
9474 current_y will be same as y0 in that case, but we have to
9475 scroll a line to make PT visible. That's the reason why 1 is
9477 dy
= 1 + it
.current_y
- y0
;
9479 if (dy
> scroll_max
)
9480 return SCROLLING_FAILED
;
9482 /* Move the window start down. If scrolling conservatively,
9483 move it just enough down to make point visible. If
9484 scroll_step is set, move it down by scroll_step. */
9485 start_display (&it
, w
, startp
);
9487 if (scroll_conservatively
)
9489 = max (max (dy
, CANON_Y_UNIT (f
)),
9490 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9491 else if (scroll_step
|| temp_scroll_step
)
9492 amount_to_scroll
= scroll_max
;
9495 aggressive
= current_buffer
->scroll_down_aggressively
;
9496 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9497 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9498 if (NUMBERP (aggressive
))
9499 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9502 if (amount_to_scroll
<= 0)
9503 return SCROLLING_FAILED
;
9505 move_it_vertically (&it
, amount_to_scroll
);
9506 startp
= it
.current
.pos
;
9510 /* See if point is inside the scroll margin at the top of the
9512 scroll_margin_pos
= startp
;
9513 if (this_scroll_margin
)
9515 start_display (&it
, w
, startp
);
9516 move_it_vertically (&it
, this_scroll_margin
);
9517 scroll_margin_pos
= it
.current
.pos
;
9520 if (PT
< CHARPOS (scroll_margin_pos
))
9522 /* Point is in the scroll margin at the top of the window or
9523 above what is displayed in the window. */
9526 /* Compute the vertical distance from PT to the scroll
9527 margin position. Give up if distance is greater than
9529 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9530 start_display (&it
, w
, pos
);
9532 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9533 it
.last_visible_y
, -1,
9534 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9535 dy
= it
.current_y
- y0
;
9536 if (dy
> scroll_max
)
9537 return SCROLLING_FAILED
;
9539 /* Compute new window start. */
9540 start_display (&it
, w
, startp
);
9542 if (scroll_conservatively
)
9544 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9545 else if (scroll_step
|| temp_scroll_step
)
9546 amount_to_scroll
= scroll_max
;
9549 aggressive
= current_buffer
->scroll_up_aggressively
;
9550 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9551 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9552 if (NUMBERP (aggressive
))
9553 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9556 if (amount_to_scroll
<= 0)
9557 return SCROLLING_FAILED
;
9559 move_it_vertically (&it
, - amount_to_scroll
);
9560 startp
= it
.current
.pos
;
9564 /* Run window scroll functions. */
9565 startp
= run_window_scroll_functions (window
, startp
);
9567 /* Display the window. Give up if new fonts are loaded, or if point
9569 if (!try_window (window
, startp
))
9570 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9571 else if (w
->cursor
.vpos
< 0)
9573 clear_glyph_matrix (w
->desired_matrix
);
9574 rc
= SCROLLING_FAILED
;
9578 /* Maybe forget recorded base line for line number display. */
9579 if (!just_this_one_p
9580 || current_buffer
->clip_changed
9581 || BEG_UNCHANGED
< CHARPOS (startp
))
9582 w
->base_line_number
= Qnil
;
9584 /* If cursor ends up on a partially visible line, shift display
9585 lines up or down. If that fails because we need larger
9586 matrices, give up. */
9587 if (!make_cursor_line_fully_visible (w
))
9588 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9590 rc
= SCROLLING_SUCCESS
;
9597 /* Compute a suitable window start for window W if display of W starts
9598 on a continuation line. Value is non-zero if a new window start
9601 The new window start will be computed, based on W's width, starting
9602 from the start of the continued line. It is the start of the
9603 screen line with the minimum distance from the old start W->start. */
9606 compute_window_start_on_continuation_line (w
)
9609 struct text_pos pos
, start_pos
;
9610 int window_start_changed_p
= 0;
9612 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9614 /* If window start is on a continuation line... Window start may be
9615 < BEGV in case there's invisible text at the start of the
9616 buffer (M-x rmail, for example). */
9617 if (CHARPOS (start_pos
) > BEGV
9618 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9621 struct glyph_row
*row
;
9623 /* Handle the case that the window start is out of range. */
9624 if (CHARPOS (start_pos
) < BEGV
)
9625 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9626 else if (CHARPOS (start_pos
) > ZV
)
9627 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9629 /* Find the start of the continued line. This should be fast
9630 because scan_buffer is fast (newline cache). */
9631 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9632 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9633 row
, DEFAULT_FACE_ID
);
9634 reseat_at_previous_visible_line_start (&it
);
9636 /* If the line start is "too far" away from the window start,
9637 say it takes too much time to compute a new window start. */
9638 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9639 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9641 int min_distance
, distance
;
9643 /* Move forward by display lines to find the new window
9644 start. If window width was enlarged, the new start can
9645 be expected to be > the old start. If window width was
9646 decreased, the new window start will be < the old start.
9647 So, we're looking for the display line start with the
9648 minimum distance from the old window start. */
9649 pos
= it
.current
.pos
;
9650 min_distance
= INFINITY
;
9651 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9652 distance
< min_distance
)
9654 min_distance
= distance
;
9655 pos
= it
.current
.pos
;
9656 move_it_by_lines (&it
, 1, 0);
9659 /* Set the window start there. */
9660 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9661 window_start_changed_p
= 1;
9665 return window_start_changed_p
;
9669 /* Try cursor movement in case text has not changes in window WINDOW,
9670 with window start STARTP. Value is
9672 CURSOR_MOVEMENT_SUCCESS if successful
9674 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
9676 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
9677 display. *SCROLL_STEP is set to 1, under certain circumstances, if
9678 we want to scroll as if scroll-step were set to 1. See the code.
9680 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
9681 which case we have to abort this redisplay, and adjust matrices
9686 CURSOR_MOVEMENT_SUCCESS
,
9687 CURSOR_MOVEMENT_CANNOT_BE_USED
,
9688 CURSOR_MOVEMENT_MUST_SCROLL
,
9689 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
9693 try_cursor_movement (window
, startp
, scroll_step
)
9695 struct text_pos startp
;
9698 struct window
*w
= XWINDOW (window
);
9699 struct frame
*f
= XFRAME (w
->frame
);
9700 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
9703 if (inhibit_try_cursor_movement
)
9707 /* Handle case where text has not changed, only point, and it has
9708 not moved off the frame. */
9709 if (/* Point may be in this window. */
9710 PT
>= CHARPOS (startp
)
9711 /* Selective display hasn't changed. */
9712 && !current_buffer
->clip_changed
9713 /* Function force-mode-line-update is used to force a thorough
9714 redisplay. It sets either windows_or_buffers_changed or
9715 update_mode_lines. So don't take a shortcut here for these
9717 && !update_mode_lines
9718 && !windows_or_buffers_changed
9719 /* Can't use this case if highlighting a region. When a
9720 region exists, cursor movement has to do more than just
9722 && !(!NILP (Vtransient_mark_mode
)
9723 && !NILP (current_buffer
->mark_active
))
9724 && NILP (w
->region_showing
)
9725 && NILP (Vshow_trailing_whitespace
)
9726 /* Right after splitting windows, last_point may be nil. */
9727 && INTEGERP (w
->last_point
)
9728 /* This code is not used for mini-buffer for the sake of the case
9729 of redisplaying to replace an echo area message; since in
9730 that case the mini-buffer contents per se are usually
9731 unchanged. This code is of no real use in the mini-buffer
9732 since the handling of this_line_start_pos, etc., in redisplay
9733 handles the same cases. */
9734 && !EQ (window
, minibuf_window
)
9735 /* When splitting windows or for new windows, it happens that
9736 redisplay is called with a nil window_end_vpos or one being
9737 larger than the window. This should really be fixed in
9738 window.c. I don't have this on my list, now, so we do
9739 approximately the same as the old redisplay code. --gerd. */
9740 && INTEGERP (w
->window_end_vpos
)
9741 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9742 && (FRAME_WINDOW_P (f
)
9743 || !MARKERP (Voverlay_arrow_position
)
9744 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9746 int this_scroll_margin
;
9747 struct glyph_row
*row
= NULL
;
9750 debug_method_add (w
, "cursor movement");
9753 /* Scroll if point within this distance from the top or bottom
9754 of the window. This is a pixel value. */
9755 this_scroll_margin
= max (0, scroll_margin
);
9756 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9757 this_scroll_margin
*= CANON_Y_UNIT (f
);
9759 /* Start with the row the cursor was displayed during the last
9760 not paused redisplay. Give up if that row is not valid. */
9761 if (w
->last_cursor
.vpos
< 0
9762 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9763 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9766 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9767 if (row
->mode_line_p
)
9769 if (!row
->enabled_p
)
9770 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9773 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
9776 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9778 if (PT
> XFASTINT (w
->last_point
))
9780 /* Point has moved forward. */
9781 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9782 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9784 xassert (row
->enabled_p
);
9788 /* The end position of a row equals the start position
9789 of the next row. If PT is there, we would rather
9790 display it in the next line. */
9791 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9792 && MATRIX_ROW_END_CHARPOS (row
) == PT
9793 && !cursor_row_p (w
, row
))
9796 /* If within the scroll margin, scroll. Note that
9797 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9798 the next line would be drawn, and that
9799 this_scroll_margin can be zero. */
9800 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9801 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9802 /* Line is completely visible last line in window
9803 and PT is to be set in the next line. */
9804 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9805 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9806 && !row
->ends_at_zv_p
9807 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9810 else if (PT
< XFASTINT (w
->last_point
))
9812 /* Cursor has to be moved backward. Note that PT >=
9813 CHARPOS (startp) because of the outer
9815 while (!row
->mode_line_p
9816 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9817 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9818 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9819 && (row
->y
> this_scroll_margin
9820 || CHARPOS (startp
) == BEGV
))
9822 xassert (row
->enabled_p
);
9826 /* Consider the following case: Window starts at BEGV,
9827 there is invisible, intangible text at BEGV, so that
9828 display starts at some point START > BEGV. It can
9829 happen that we are called with PT somewhere between
9830 BEGV and START. Try to handle that case. */
9831 if (row
< w
->current_matrix
->rows
9832 || row
->mode_line_p
)
9834 row
= w
->current_matrix
->rows
;
9835 if (row
->mode_line_p
)
9839 /* Due to newlines in overlay strings, we may have to
9840 skip forward over overlay strings. */
9841 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9842 && MATRIX_ROW_END_CHARPOS (row
) == PT
9843 && !cursor_row_p (w
, row
))
9846 /* If within the scroll margin, scroll. */
9847 if (row
->y
< this_scroll_margin
9848 && CHARPOS (startp
) != BEGV
)
9852 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9853 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9855 /* if PT is not in the glyph row, give up. */
9856 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9858 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9860 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
9861 && !row
->ends_at_zv_p
9862 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
9863 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9864 else if (row
->height
> window_box_height (w
))
9866 /* If we end up in a partially visible line, let's
9867 make it fully visible, except when it's taller
9868 than the window, in which case we can't do much
9871 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9875 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9876 try_window (window
, startp
);
9877 if (!make_cursor_line_fully_visible (w
))
9878 rc
= CURSOR_MOVEMENT_NEED_LARGER_MATRICES
;
9880 rc
= CURSOR_MOVEMENT_SUCCESS
;
9884 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9887 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9888 rc
= CURSOR_MOVEMENT_SUCCESS
;
9897 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9898 selected_window is redisplayed. */
9901 redisplay_window (window
, just_this_one_p
)
9903 int just_this_one_p
;
9905 struct window
*w
= XWINDOW (window
);
9906 struct frame
*f
= XFRAME (w
->frame
);
9907 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9908 struct buffer
*old
= current_buffer
;
9909 struct text_pos lpoint
, opoint
, startp
;
9910 int update_mode_line
;
9913 /* Record it now because it's overwritten. */
9914 int current_matrix_up_to_date_p
= 0;
9915 int temp_scroll_step
= 0;
9916 int count
= BINDING_STACK_SIZE ();
9919 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9922 /* W must be a leaf window here. */
9923 xassert (!NILP (w
->buffer
));
9925 *w
->desired_matrix
->method
= 0;
9928 specbind (Qinhibit_point_motion_hooks
, Qt
);
9930 reconsider_clip_changes (w
, buffer
);
9932 /* Has the mode line to be updated? */
9933 update_mode_line
= (!NILP (w
->update_mode_line
)
9934 || update_mode_lines
9935 || buffer
->clip_changed
);
9937 if (MINI_WINDOW_P (w
))
9939 if (w
== XWINDOW (echo_area_window
)
9940 && !NILP (echo_area_buffer
[0]))
9942 if (update_mode_line
)
9943 /* We may have to update a tty frame's menu bar or a
9944 tool-bar. Example `M-x C-h C-h C-g'. */
9945 goto finish_menu_bars
;
9947 /* We've already displayed the echo area glyphs in this window. */
9948 goto finish_scroll_bars
;
9950 else if (w
!= XWINDOW (minibuf_window
))
9952 /* W is a mini-buffer window, but it's not the currently
9953 active one, so clear it. */
9954 int yb
= window_text_bottom_y (w
);
9955 struct glyph_row
*row
;
9958 for (y
= 0, row
= w
->desired_matrix
->rows
;
9960 y
+= row
->height
, ++row
)
9961 blank_row (w
, row
, y
);
9962 goto finish_scroll_bars
;
9965 clear_glyph_matrix (w
->desired_matrix
);
9968 /* Otherwise set up data on this window; select its buffer and point
9970 /* Really select the buffer, for the sake of buffer-local
9972 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9973 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9975 current_matrix_up_to_date_p
9976 = (!NILP (w
->window_end_valid
)
9977 && !current_buffer
->clip_changed
9978 && XFASTINT (w
->last_modified
) >= MODIFF
9979 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9981 /* When windows_or_buffers_changed is non-zero, we can't rely on
9982 the window end being valid, so set it to nil there. */
9983 if (windows_or_buffers_changed
)
9985 /* If window starts on a continuation line, maybe adjust the
9986 window start in case the window's width changed. */
9987 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9988 compute_window_start_on_continuation_line (w
);
9990 w
->window_end_valid
= Qnil
;
9993 /* Some sanity checks. */
9994 CHECK_WINDOW_END (w
);
9995 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9997 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
10000 /* If %c is in mode line, update it if needed. */
10001 if (!NILP (w
->column_number_displayed
)
10002 /* This alternative quickly identifies a common case
10003 where no change is needed. */
10004 && !(PT
== XFASTINT (w
->last_point
)
10005 && XFASTINT (w
->last_modified
) >= MODIFF
10006 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10007 && XFASTINT (w
->column_number_displayed
) != current_column ())
10008 update_mode_line
= 1;
10010 /* Count number of windows showing the selected buffer. An indirect
10011 buffer counts as its base buffer. */
10012 if (!just_this_one_p
)
10014 struct buffer
*current_base
, *window_base
;
10015 current_base
= current_buffer
;
10016 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10017 if (current_base
->base_buffer
)
10018 current_base
= current_base
->base_buffer
;
10019 if (window_base
->base_buffer
)
10020 window_base
= window_base
->base_buffer
;
10021 if (current_base
== window_base
)
10025 /* Point refers normally to the selected window. For any other
10026 window, set up appropriate value. */
10027 if (!EQ (window
, selected_window
))
10029 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10030 int new_pt_byte
= marker_byte_position (w
->pointm
);
10034 new_pt_byte
= BEGV_BYTE
;
10035 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10037 else if (new_pt
> (ZV
- 1))
10040 new_pt_byte
= ZV_BYTE
;
10041 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10044 /* We don't use SET_PT so that the point-motion hooks don't run. */
10045 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10048 /* If any of the character widths specified in the display table
10049 have changed, invalidate the width run cache. It's true that
10050 this may be a bit late to catch such changes, but the rest of
10051 redisplay goes (non-fatally) haywire when the display table is
10052 changed, so why should we worry about doing any better? */
10053 if (current_buffer
->width_run_cache
)
10055 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10057 if (! disptab_matches_widthtab (disptab
,
10058 XVECTOR (current_buffer
->width_table
)))
10060 invalidate_region_cache (current_buffer
,
10061 current_buffer
->width_run_cache
,
10063 recompute_width_table (current_buffer
, disptab
);
10067 /* If window-start is screwed up, choose a new one. */
10068 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10071 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10073 /* If someone specified a new starting point but did not insist,
10074 check whether it can be used. */
10075 if (!NILP (w
->optional_new_start
)
10076 && CHARPOS (startp
) >= BEGV
10077 && CHARPOS (startp
) <= ZV
)
10079 w
->optional_new_start
= Qnil
;
10080 start_display (&it
, w
, startp
);
10081 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10082 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10083 if (IT_CHARPOS (it
) == PT
)
10084 w
->force_start
= Qt
;
10087 /* Handle case where place to start displaying has been specified,
10088 unless the specified location is outside the accessible range. */
10089 if (!NILP (w
->force_start
)
10090 || w
->frozen_window_start_p
)
10092 w
->force_start
= Qnil
;
10094 w
->window_end_valid
= Qnil
;
10096 /* Forget any recorded base line for line number display. */
10097 if (!current_matrix_up_to_date_p
10098 || current_buffer
->clip_changed
)
10099 w
->base_line_number
= Qnil
;
10101 /* Redisplay the mode line. Select the buffer properly for that.
10102 Also, run the hook window-scroll-functions
10103 because we have scrolled. */
10104 /* Note, we do this after clearing force_start because
10105 if there's an error, it is better to forget about force_start
10106 than to get into an infinite loop calling the hook functions
10107 and having them get more errors. */
10108 if (!update_mode_line
10109 || ! NILP (Vwindow_scroll_functions
))
10111 update_mode_line
= 1;
10112 w
->update_mode_line
= Qt
;
10113 startp
= run_window_scroll_functions (window
, startp
);
10116 w
->last_modified
= make_number (0);
10117 w
->last_overlay_modified
= make_number (0);
10118 if (CHARPOS (startp
) < BEGV
)
10119 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10120 else if (CHARPOS (startp
) > ZV
)
10121 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10123 /* Redisplay, then check if cursor has been set during the
10124 redisplay. Give up if new fonts were loaded. */
10125 if (!try_window (window
, startp
))
10127 w
->force_start
= Qt
;
10128 clear_glyph_matrix (w
->desired_matrix
);
10129 goto finish_scroll_bars
;
10132 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10134 /* If point does not appear, try to move point so it does
10135 appear. The desired matrix has been built above, so we
10136 can use it here. */
10138 struct glyph_row
*row
;
10140 window_height
= window_box_height (w
) / 2;
10141 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10142 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
10145 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10146 MATRIX_ROW_START_BYTEPOS (row
));
10148 if (w
!= XWINDOW (selected_window
))
10149 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10150 else if (current_buffer
== old
)
10151 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10153 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10155 /* If we are highlighting the region, then we just changed
10156 the region, so redisplay to show it. */
10157 if (!NILP (Vtransient_mark_mode
)
10158 && !NILP (current_buffer
->mark_active
))
10160 clear_glyph_matrix (w
->desired_matrix
);
10161 if (!try_window (window
, startp
))
10162 goto need_larger_matrices
;
10166 if (!make_cursor_line_fully_visible (w
))
10167 goto need_larger_matrices
;
10169 debug_method_add (w
, "forced window start");
10174 /* Handle case where text has not changed, only point, and it has
10175 not moved off the frame. */
10176 if (current_matrix_up_to_date_p
10177 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10178 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10182 case CURSOR_MOVEMENT_SUCCESS
:
10185 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10186 goto need_larger_matrices
;
10188 case CURSOR_MOVEMENT_MUST_SCROLL
:
10189 goto try_to_scroll
;
10195 /* If current starting point was originally the beginning of a line
10196 but no longer is, find a new starting point. */
10197 else if (!NILP (w
->start_at_line_beg
)
10198 && !(CHARPOS (startp
) <= BEGV
10199 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10202 debug_method_add (w
, "recenter 1");
10207 /* Try scrolling with try_window_id. Value is > 0 if update has
10208 been done, it is -1 if we know that the same window start will
10209 not work. It is 0 if unsuccessful for some other reason. */
10210 else if ((tem
= try_window_id (w
)) != 0)
10213 debug_method_add (w
, "try_window_id %d", tem
);
10216 if (fonts_changed_p
)
10217 goto need_larger_matrices
;
10221 /* Otherwise try_window_id has returned -1 which means that we
10222 don't want the alternative below this comment to execute. */
10224 else if (CHARPOS (startp
) >= BEGV
10225 && CHARPOS (startp
) <= ZV
10226 && PT
>= CHARPOS (startp
)
10227 && (CHARPOS (startp
) < ZV
10228 /* Avoid starting at end of buffer. */
10229 || CHARPOS (startp
) == BEGV
10230 || (XFASTINT (w
->last_modified
) >= MODIFF
10231 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10234 debug_method_add (w
, "same window start");
10237 /* Try to redisplay starting at same place as before.
10238 If point has not moved off frame, accept the results. */
10239 if (!current_matrix_up_to_date_p
10240 /* Don't use try_window_reusing_current_matrix in this case
10241 because a window scroll function can have changed the
10243 || !NILP (Vwindow_scroll_functions
)
10244 || MINI_WINDOW_P (w
)
10245 || !try_window_reusing_current_matrix (w
))
10247 IF_DEBUG (debug_method_add (w
, "1"));
10248 try_window (window
, startp
);
10251 if (fonts_changed_p
)
10252 goto need_larger_matrices
;
10254 if (w
->cursor
.vpos
>= 0)
10256 if (!just_this_one_p
10257 || current_buffer
->clip_changed
10258 || BEG_UNCHANGED
< CHARPOS (startp
))
10259 /* Forget any recorded base line for line number display. */
10260 w
->base_line_number
= Qnil
;
10262 if (!make_cursor_line_fully_visible (w
))
10263 goto need_larger_matrices
;
10267 clear_glyph_matrix (w
->desired_matrix
);
10272 w
->last_modified
= make_number (0);
10273 w
->last_overlay_modified
= make_number (0);
10275 /* Redisplay the mode line. Select the buffer properly for that. */
10276 if (!update_mode_line
)
10278 update_mode_line
= 1;
10279 w
->update_mode_line
= Qt
;
10282 /* Try to scroll by specified few lines. */
10283 if ((scroll_conservatively
10285 || temp_scroll_step
10286 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10287 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10288 && !current_buffer
->clip_changed
10289 && CHARPOS (startp
) >= BEGV
10290 && CHARPOS (startp
) <= ZV
)
10292 /* The function returns -1 if new fonts were loaded, 1 if
10293 successful, 0 if not successful. */
10294 int rc
= try_scrolling (window
, just_this_one_p
,
10295 scroll_conservatively
,
10300 case SCROLLING_SUCCESS
:
10303 case SCROLLING_NEED_LARGER_MATRICES
:
10304 goto need_larger_matrices
;
10306 case SCROLLING_FAILED
:
10314 /* Finally, just choose place to start which centers point */
10319 debug_method_add (w
, "recenter");
10322 /* w->vscroll = 0; */
10324 /* Forget any previously recorded base line for line number display. */
10325 if (!current_matrix_up_to_date_p
10326 || current_buffer
->clip_changed
)
10327 w
->base_line_number
= Qnil
;
10329 /* Move backward half the height of the window. */
10330 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10331 it
.current_y
= it
.last_visible_y
;
10332 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
10333 xassert (IT_CHARPOS (it
) >= BEGV
);
10335 /* The function move_it_vertically_backward may move over more
10336 than the specified y-distance. If it->w is small, e.g. a
10337 mini-buffer window, we may end up in front of the window's
10338 display area. Start displaying at the start of the line
10339 containing PT in this case. */
10340 if (it
.current_y
<= 0)
10342 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10343 move_it_vertically (&it
, 0);
10344 xassert (IT_CHARPOS (it
) <= PT
);
10348 it
.current_x
= it
.hpos
= 0;
10350 /* Set startp here explicitly in case that helps avoid an infinite loop
10351 in case the window-scroll-functions functions get errors. */
10352 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10354 /* Run scroll hooks. */
10355 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10357 /* Redisplay the window. */
10358 if (!current_matrix_up_to_date_p
10359 || windows_or_buffers_changed
10360 /* Don't use try_window_reusing_current_matrix in this case
10361 because it can have changed the buffer. */
10362 || !NILP (Vwindow_scroll_functions
)
10363 || !just_this_one_p
10364 || MINI_WINDOW_P (w
)
10365 || !try_window_reusing_current_matrix (w
))
10366 try_window (window
, startp
);
10368 /* If new fonts have been loaded (due to fontsets), give up. We
10369 have to start a new redisplay since we need to re-adjust glyph
10371 if (fonts_changed_p
)
10372 goto need_larger_matrices
;
10374 /* If cursor did not appear assume that the middle of the window is
10375 in the first line of the window. Do it again with the next line.
10376 (Imagine a window of height 100, displaying two lines of height
10377 60. Moving back 50 from it->last_visible_y will end in the first
10379 if (w
->cursor
.vpos
< 0)
10381 if (!NILP (w
->window_end_valid
)
10382 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10384 clear_glyph_matrix (w
->desired_matrix
);
10385 move_it_by_lines (&it
, 1, 0);
10386 try_window (window
, it
.current
.pos
);
10388 else if (PT
< IT_CHARPOS (it
))
10390 clear_glyph_matrix (w
->desired_matrix
);
10391 move_it_by_lines (&it
, -1, 0);
10392 try_window (window
, it
.current
.pos
);
10396 /* Not much we can do about it. */
10400 /* Consider the following case: Window starts at BEGV, there is
10401 invisible, intangible text at BEGV, so that display starts at
10402 some point START > BEGV. It can happen that we are called with
10403 PT somewhere between BEGV and START. Try to handle that case. */
10404 if (w
->cursor
.vpos
< 0)
10406 struct glyph_row
*row
= w
->current_matrix
->rows
;
10407 if (row
->mode_line_p
)
10409 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10412 if (!make_cursor_line_fully_visible (w
))
10413 goto need_larger_matrices
;
10417 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10418 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10419 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10422 /* Display the mode line, if we must. */
10423 if ((update_mode_line
10424 /* If window not full width, must redo its mode line
10425 if (a) the window to its side is being redone and
10426 (b) we do a frame-based redisplay. This is a consequence
10427 of how inverted lines are drawn in frame-based redisplay. */
10428 || (!just_this_one_p
10429 && !FRAME_WINDOW_P (f
)
10430 && !WINDOW_FULL_WIDTH_P (w
))
10431 /* Line number to display. */
10432 || INTEGERP (w
->base_line_pos
)
10433 /* Column number is displayed and different from the one displayed. */
10434 || (!NILP (w
->column_number_displayed
)
10435 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10436 /* This means that the window has a mode line. */
10437 && (WINDOW_WANTS_MODELINE_P (w
)
10438 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10440 display_mode_lines (w
);
10442 /* If mode line height has changed, arrange for a thorough
10443 immediate redisplay using the correct mode line height. */
10444 if (WINDOW_WANTS_MODELINE_P (w
)
10445 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10447 fonts_changed_p
= 1;
10448 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10449 = DESIRED_MODE_LINE_HEIGHT (w
);
10452 /* If top line height has changed, arrange for a thorough
10453 immediate redisplay using the correct mode line height. */
10454 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10455 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10457 fonts_changed_p
= 1;
10458 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10459 = DESIRED_HEADER_LINE_HEIGHT (w
);
10462 if (fonts_changed_p
)
10463 goto need_larger_matrices
;
10466 if (!line_number_displayed
10467 && !BUFFERP (w
->base_line_pos
))
10469 w
->base_line_pos
= Qnil
;
10470 w
->base_line_number
= Qnil
;
10475 /* When we reach a frame's selected window, redo the frame's menu bar. */
10476 if (update_mode_line
10477 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10479 int redisplay_menu_p
= 0;
10481 if (FRAME_WINDOW_P (f
))
10483 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10484 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10486 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10490 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10492 if (redisplay_menu_p
)
10493 display_menu_bar (w
);
10495 #ifdef HAVE_WINDOW_SYSTEM
10496 if (WINDOWP (f
->tool_bar_window
)
10497 && (FRAME_TOOL_BAR_LINES (f
) > 0
10498 || auto_resize_tool_bars_p
))
10499 redisplay_tool_bar (f
);
10503 need_larger_matrices
:
10505 finish_scroll_bars
:
10507 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10509 int start
, end
, whole
;
10511 /* Calculate the start and end positions for the current window.
10512 At some point, it would be nice to choose between scrollbars
10513 which reflect the whole buffer size, with special markers
10514 indicating narrowing, and scrollbars which reflect only the
10517 Note that mini-buffers sometimes aren't displaying any text. */
10518 if (!MINI_WINDOW_P (w
)
10519 || (w
== XWINDOW (minibuf_window
)
10520 && NILP (echo_area_buffer
[0])))
10523 start
= marker_position (w
->start
) - BEGV
;
10524 /* I don't think this is guaranteed to be right. For the
10525 moment, we'll pretend it is. */
10526 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10530 if (whole
< (end
- start
))
10531 whole
= end
- start
;
10534 start
= end
= whole
= 0;
10536 /* Indicate what this scroll bar ought to be displaying now. */
10537 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10539 /* Note that we actually used the scroll bar attached to this
10540 window, so it shouldn't be deleted at the end of redisplay. */
10541 redeem_scroll_bar_hook (w
);
10544 /* Restore current_buffer and value of point in it. */
10545 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10546 set_buffer_internal_1 (old
);
10547 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10549 unbind_to (count
, Qnil
);
10553 /* Build the complete desired matrix of WINDOW with a window start
10554 buffer position POS. Value is non-zero if successful. It is zero
10555 if fonts were loaded during redisplay which makes re-adjusting
10556 glyph matrices necessary. */
10559 try_window (window
, pos
)
10560 Lisp_Object window
;
10561 struct text_pos pos
;
10563 struct window
*w
= XWINDOW (window
);
10565 struct glyph_row
*last_text_row
= NULL
;
10567 /* Make POS the new window start. */
10568 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10570 /* Mark cursor position as unknown. No overlay arrow seen. */
10571 w
->cursor
.vpos
= -1;
10572 overlay_arrow_seen
= 0;
10574 /* Initialize iterator and info to start at POS. */
10575 start_display (&it
, w
, pos
);
10577 /* Display all lines of W. */
10578 while (it
.current_y
< it
.last_visible_y
)
10580 if (display_line (&it
))
10581 last_text_row
= it
.glyph_row
- 1;
10582 if (fonts_changed_p
)
10586 /* If bottom moved off end of frame, change mode line percentage. */
10587 if (XFASTINT (w
->window_end_pos
) <= 0
10588 && Z
!= IT_CHARPOS (it
))
10589 w
->update_mode_line
= Qt
;
10591 /* Set window_end_pos to the offset of the last character displayed
10592 on the window from the end of current_buffer. Set
10593 window_end_vpos to its row number. */
10596 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10597 w
->window_end_bytepos
10598 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10600 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10602 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10603 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10604 ->displays_text_p
);
10608 w
->window_end_bytepos
= 0;
10609 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10612 /* But that is not valid info until redisplay finishes. */
10613 w
->window_end_valid
= Qnil
;
10619 /************************************************************************
10620 Window redisplay reusing current matrix when buffer has not changed
10621 ************************************************************************/
10623 /* Try redisplay of window W showing an unchanged buffer with a
10624 different window start than the last time it was displayed by
10625 reusing its current matrix. Value is non-zero if successful.
10626 W->start is the new window start. */
10629 try_window_reusing_current_matrix (w
)
10632 struct frame
*f
= XFRAME (w
->frame
);
10633 struct glyph_row
*row
, *bottom_row
;
10636 struct text_pos start
, new_start
;
10637 int nrows_scrolled
, i
;
10638 struct glyph_row
*last_text_row
;
10639 struct glyph_row
*last_reused_text_row
;
10640 struct glyph_row
*start_row
;
10641 int start_vpos
, min_y
, max_y
;
10644 if (inhibit_try_window_reusing
)
10648 if (/* This function doesn't handle terminal frames. */
10649 !FRAME_WINDOW_P (f
)
10650 /* Don't try to reuse the display if windows have been split
10652 || windows_or_buffers_changed
)
10655 /* Can't do this if region may have changed. */
10656 if ((!NILP (Vtransient_mark_mode
)
10657 && !NILP (current_buffer
->mark_active
))
10658 || !NILP (w
->region_showing
)
10659 || !NILP (Vshow_trailing_whitespace
))
10662 /* If top-line visibility has changed, give up. */
10663 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10664 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10667 /* Give up if old or new display is scrolled vertically. We could
10668 make this function handle this, but right now it doesn't. */
10669 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10670 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10673 /* The variable new_start now holds the new window start. The old
10674 start `start' can be determined from the current matrix. */
10675 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10676 start
= start_row
->start
.pos
;
10677 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10679 /* Clear the desired matrix for the display below. */
10680 clear_glyph_matrix (w
->desired_matrix
);
10682 if (CHARPOS (new_start
) <= CHARPOS (start
))
10686 /* Don't use this method if the display starts with an ellipsis
10687 displayed for invisible text. It's not easy to handle that case
10688 below, and it's certainly not worth the effort since this is
10689 not a frequent case. */
10690 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10693 IF_DEBUG (debug_method_add (w
, "twu1"));
10695 /* Display up to a row that can be reused. The variable
10696 last_text_row is set to the last row displayed that displays
10697 text. Note that it.vpos == 0 if or if not there is a
10698 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10699 start_display (&it
, w
, new_start
);
10700 first_row_y
= it
.current_y
;
10701 w
->cursor
.vpos
= -1;
10702 last_text_row
= last_reused_text_row
= NULL
;
10704 while (it
.current_y
< it
.last_visible_y
10705 && IT_CHARPOS (it
) < CHARPOS (start
)
10706 && !fonts_changed_p
)
10707 if (display_line (&it
))
10708 last_text_row
= it
.glyph_row
- 1;
10710 /* A value of current_y < last_visible_y means that we stopped
10711 at the previous window start, which in turn means that we
10712 have at least one reusable row. */
10713 if (it
.current_y
< it
.last_visible_y
)
10715 /* IT.vpos always starts from 0; it counts text lines. */
10716 nrows_scrolled
= it
.vpos
;
10718 /* Find PT if not already found in the lines displayed. */
10719 if (w
->cursor
.vpos
< 0)
10721 int dy
= it
.current_y
- first_row_y
;
10723 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10724 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
10726 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10727 dy
, nrows_scrolled
);
10730 clear_glyph_matrix (w
->desired_matrix
);
10735 /* Scroll the display. Do it before the current matrix is
10736 changed. The problem here is that update has not yet
10737 run, i.e. part of the current matrix is not up to date.
10738 scroll_run_hook will clear the cursor, and use the
10739 current matrix to get the height of the row the cursor is
10741 run
.current_y
= first_row_y
;
10742 run
.desired_y
= it
.current_y
;
10743 run
.height
= it
.last_visible_y
- it
.current_y
;
10745 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10748 rif
->update_window_begin_hook (w
);
10749 rif
->clear_mouse_face (w
);
10750 rif
->scroll_run_hook (w
, &run
);
10751 rif
->update_window_end_hook (w
, 0, 0);
10755 /* Shift current matrix down by nrows_scrolled lines. */
10756 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10757 rotate_matrix (w
->current_matrix
,
10759 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10762 /* Disable lines that must be updated. */
10763 for (i
= 0; i
< it
.vpos
; ++i
)
10764 (start_row
+ i
)->enabled_p
= 0;
10766 /* Re-compute Y positions. */
10767 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10768 max_y
= it
.last_visible_y
;
10769 for (row
= start_row
+ nrows_scrolled
;
10773 row
->y
= it
.current_y
;
10774 row
->visible_height
= row
->height
;
10776 if (row
->y
< min_y
)
10777 row
->visible_height
-= min_y
- row
->y
;
10778 if (row
->y
+ row
->height
> max_y
)
10779 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10781 it
.current_y
+= row
->height
;
10783 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10784 last_reused_text_row
= row
;
10785 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10789 /* Disable lines in the current matrix which are now
10790 below the window. */
10791 for (++row
; row
< bottom_row
; ++row
)
10792 row
->enabled_p
= 0;
10795 /* Update window_end_pos etc.; last_reused_text_row is the last
10796 reused row from the current matrix containing text, if any.
10797 The value of last_text_row is the last displayed line
10798 containing text. */
10799 if (last_reused_text_row
)
10801 w
->window_end_bytepos
10802 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10804 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10806 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10807 w
->current_matrix
));
10809 else if (last_text_row
)
10811 w
->window_end_bytepos
10812 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10814 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10816 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10820 /* This window must be completely empty. */
10821 w
->window_end_bytepos
= 0;
10822 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10824 w
->window_end_valid
= Qnil
;
10826 /* Update hint: don't try scrolling again in update_window. */
10827 w
->desired_matrix
->no_scrolling_p
= 1;
10830 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10834 else if (CHARPOS (new_start
) > CHARPOS (start
))
10836 struct glyph_row
*pt_row
, *row
;
10837 struct glyph_row
*first_reusable_row
;
10838 struct glyph_row
*first_row_to_display
;
10840 int yb
= window_text_bottom_y (w
);
10842 /* Find the row starting at new_start, if there is one. Don't
10843 reuse a partially visible line at the end. */
10844 first_reusable_row
= start_row
;
10845 while (first_reusable_row
->enabled_p
10846 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10847 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10848 < CHARPOS (new_start
)))
10849 ++first_reusable_row
;
10851 /* Give up if there is no row to reuse. */
10852 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10853 || !first_reusable_row
->enabled_p
10854 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10855 != CHARPOS (new_start
)))
10858 /* We can reuse fully visible rows beginning with
10859 first_reusable_row to the end of the window. Set
10860 first_row_to_display to the first row that cannot be reused.
10861 Set pt_row to the row containing point, if there is any. */
10863 for (first_row_to_display
= first_reusable_row
;
10864 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
10865 ++first_row_to_display
)
10867 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10868 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10869 pt_row
= first_row_to_display
;
10872 /* Start displaying at the start of first_row_to_display. */
10873 xassert (first_row_to_display
->y
< yb
);
10874 init_to_row_start (&it
, w
, first_row_to_display
);
10876 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10878 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10880 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10881 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10883 /* Display lines beginning with first_row_to_display in the
10884 desired matrix. Set last_text_row to the last row displayed
10885 that displays text. */
10886 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10887 if (pt_row
== NULL
)
10888 w
->cursor
.vpos
= -1;
10889 last_text_row
= NULL
;
10890 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10891 if (display_line (&it
))
10892 last_text_row
= it
.glyph_row
- 1;
10894 /* Give up If point isn't in a row displayed or reused. */
10895 if (w
->cursor
.vpos
< 0)
10897 clear_glyph_matrix (w
->desired_matrix
);
10901 /* If point is in a reused row, adjust y and vpos of the cursor
10905 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10906 w
->current_matrix
);
10907 w
->cursor
.y
-= first_reusable_row
->y
;
10910 /* Scroll the display. */
10911 run
.current_y
= first_reusable_row
->y
;
10912 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10913 run
.height
= it
.last_visible_y
- run
.current_y
;
10914 dy
= run
.current_y
- run
.desired_y
;
10918 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10920 rif
->update_window_begin_hook (w
);
10921 rif
->clear_mouse_face (w
);
10922 rif
->scroll_run_hook (w
, &run
);
10923 rif
->update_window_end_hook (w
, 0, 0);
10927 /* Adjust Y positions of reused rows. */
10928 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10929 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10930 max_y
= it
.last_visible_y
;
10931 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10934 row
->visible_height
= row
->height
;
10935 if (row
->y
< min_y
)
10936 row
->visible_height
-= min_y
- row
->y
;
10937 if (row
->y
+ row
->height
> max_y
)
10938 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10941 /* Scroll the current matrix. */
10942 xassert (nrows_scrolled
> 0);
10943 rotate_matrix (w
->current_matrix
,
10945 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10948 /* Disable rows not reused. */
10949 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
10950 row
->enabled_p
= 0;
10952 /* Adjust window end. A null value of last_text_row means that
10953 the window end is in reused rows which in turn means that
10954 only its vpos can have changed. */
10957 w
->window_end_bytepos
10958 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10960 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10962 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10967 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10970 w
->window_end_valid
= Qnil
;
10971 w
->desired_matrix
->no_scrolling_p
= 1;
10974 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10984 /************************************************************************
10985 Window redisplay reusing current matrix when buffer has changed
10986 ************************************************************************/
10988 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10989 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10991 static struct glyph_row
*
10992 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10993 struct glyph_row
*));
10996 /* Return the last row in MATRIX displaying text. If row START is
10997 non-null, start searching with that row. IT gives the dimensions
10998 of the display. Value is null if matrix is empty; otherwise it is
10999 a pointer to the row found. */
11001 static struct glyph_row
*
11002 find_last_row_displaying_text (matrix
, it
, start
)
11003 struct glyph_matrix
*matrix
;
11005 struct glyph_row
*start
;
11007 struct glyph_row
*row
, *row_found
;
11009 /* Set row_found to the last row in IT->w's current matrix
11010 displaying text. The loop looks funny but think of partially
11013 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11014 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11016 xassert (row
->enabled_p
);
11018 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11027 /* Return the last row in the current matrix of W that is not affected
11028 by changes at the start of current_buffer that occurred since W's
11029 current matrix was built. Value is null if no such row exists.
11031 BEG_UNCHANGED us the number of characters unchanged at the start of
11032 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11033 first changed character in current_buffer. Characters at positions <
11034 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11035 when the current matrix was built. */
11037 static struct glyph_row
*
11038 find_last_unchanged_at_beg_row (w
)
11041 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11042 struct glyph_row
*row
;
11043 struct glyph_row
*row_found
= NULL
;
11044 int yb
= window_text_bottom_y (w
);
11046 /* Find the last row displaying unchanged text. */
11047 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11048 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11049 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11051 if (/* If row ends before first_changed_pos, it is unchanged,
11052 except in some case. */
11053 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11054 /* When row ends in ZV and we write at ZV it is not
11056 && !row
->ends_at_zv_p
11057 /* When first_changed_pos is the end of a continued line,
11058 row is not unchanged because it may be no longer
11060 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11061 && row
->continued_p
))
11064 /* Stop if last visible row. */
11065 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11075 /* Find the first glyph row in the current matrix of W that is not
11076 affected by changes at the end of current_buffer since the
11077 time W's current matrix was built.
11079 Return in *DELTA the number of chars by which buffer positions in
11080 unchanged text at the end of current_buffer must be adjusted.
11082 Return in *DELTA_BYTES the corresponding number of bytes.
11084 Value is null if no such row exists, i.e. all rows are affected by
11087 static struct glyph_row
*
11088 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11090 int *delta
, *delta_bytes
;
11092 struct glyph_row
*row
;
11093 struct glyph_row
*row_found
= NULL
;
11095 *delta
= *delta_bytes
= 0;
11097 /* Display must not have been paused, otherwise the current matrix
11098 is not up to date. */
11099 if (NILP (w
->window_end_valid
))
11102 /* A value of window_end_pos >= END_UNCHANGED means that the window
11103 end is in the range of changed text. If so, there is no
11104 unchanged row at the end of W's current matrix. */
11105 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11108 /* Set row to the last row in W's current matrix displaying text. */
11109 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11111 /* If matrix is entirely empty, no unchanged row exists. */
11112 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11114 /* The value of row is the last glyph row in the matrix having a
11115 meaningful buffer position in it. The end position of row
11116 corresponds to window_end_pos. This allows us to translate
11117 buffer positions in the current matrix to current buffer
11118 positions for characters not in changed text. */
11119 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11120 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11121 int last_unchanged_pos
, last_unchanged_pos_old
;
11122 struct glyph_row
*first_text_row
11123 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11125 *delta
= Z
- Z_old
;
11126 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11128 /* Set last_unchanged_pos to the buffer position of the last
11129 character in the buffer that has not been changed. Z is the
11130 index + 1 of the last character in current_buffer, i.e. by
11131 subtracting END_UNCHANGED we get the index of the last
11132 unchanged character, and we have to add BEG to get its buffer
11134 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11135 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11137 /* Search backward from ROW for a row displaying a line that
11138 starts at a minimum position >= last_unchanged_pos_old. */
11139 for (; row
> first_text_row
; --row
)
11141 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11144 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11149 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11156 /* Make sure that glyph rows in the current matrix of window W
11157 reference the same glyph memory as corresponding rows in the
11158 frame's frame matrix. This function is called after scrolling W's
11159 current matrix on a terminal frame in try_window_id and
11160 try_window_reusing_current_matrix. */
11163 sync_frame_with_window_matrix_rows (w
)
11166 struct frame
*f
= XFRAME (w
->frame
);
11167 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11169 /* Preconditions: W must be a leaf window and full-width. Its frame
11170 must have a frame matrix. */
11171 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11172 xassert (WINDOW_FULL_WIDTH_P (w
));
11173 xassert (!FRAME_WINDOW_P (f
));
11175 /* If W is a full-width window, glyph pointers in W's current matrix
11176 have, by definition, to be the same as glyph pointers in the
11177 corresponding frame matrix. */
11178 window_row
= w
->current_matrix
->rows
;
11179 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11180 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11181 while (window_row
< window_row_end
)
11185 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
11186 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
11188 /* Disable frame rows whose corresponding window rows have
11189 been disabled in try_window_id. */
11190 if (!window_row
->enabled_p
)
11191 frame_row
->enabled_p
= 0;
11193 ++window_row
, ++frame_row
;
11198 /* Find the glyph row in window W containing CHARPOS. Consider all
11199 rows between START and END (not inclusive). END null means search
11200 all rows to the end of the display area of W. Value is the row
11201 containing CHARPOS or null. */
11204 row_containing_pos (w
, charpos
, start
, end
, dy
)
11207 struct glyph_row
*start
, *end
;
11210 struct glyph_row
*row
= start
;
11213 /* If we happen to start on a header-line, skip that. */
11214 if (row
->mode_line_p
)
11217 if ((end
&& row
>= end
) || !row
->enabled_p
)
11220 last_y
= window_text_bottom_y (w
) - dy
;
11222 while ((end
== NULL
|| row
< end
)
11223 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
11224 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11225 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11226 /* The end position of a row equals the start
11227 position of the next row. If CHARPOS is there, we
11228 would rather display it in the next line, except
11229 when this line ends in ZV. */
11230 && !row
->ends_at_zv_p
11231 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))
11234 /* Give up if CHARPOS not found. */
11235 if ((end
&& row
>= end
)
11236 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11237 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11244 /* Try to redisplay window W by reusing its existing display. W's
11245 current matrix must be up to date when this function is called,
11246 i.e. window_end_valid must not be nil.
11250 1 if display has been updated
11251 0 if otherwise unsuccessful
11252 -1 if redisplay with same window start is known not to succeed
11254 The following steps are performed:
11256 1. Find the last row in the current matrix of W that is not
11257 affected by changes at the start of current_buffer. If no such row
11260 2. Find the first row in W's current matrix that is not affected by
11261 changes at the end of current_buffer. Maybe there is no such row.
11263 3. Display lines beginning with the row + 1 found in step 1 to the
11264 row found in step 2 or, if step 2 didn't find a row, to the end of
11267 4. If cursor is not known to appear on the window, give up.
11269 5. If display stopped at the row found in step 2, scroll the
11270 display and current matrix as needed.
11272 6. Maybe display some lines at the end of W, if we must. This can
11273 happen under various circumstances, like a partially visible line
11274 becoming fully visible, or because newly displayed lines are displayed
11275 in smaller font sizes.
11277 7. Update W's window end information. */
11283 struct frame
*f
= XFRAME (w
->frame
);
11284 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11285 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11286 struct glyph_row
*last_unchanged_at_beg_row
;
11287 struct glyph_row
*first_unchanged_at_end_row
;
11288 struct glyph_row
*row
;
11289 struct glyph_row
*bottom_row
;
11292 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11293 struct text_pos start_pos
;
11295 int first_unchanged_at_end_vpos
= 0;
11296 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11297 struct text_pos start
;
11298 int first_changed_charpos
, last_changed_charpos
;
11301 if (inhibit_try_window_id
)
11305 /* This is handy for debugging. */
11307 #define GIVE_UP(X) \
11309 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11313 #define GIVE_UP(X) return 0
11316 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11318 /* Don't use this for mini-windows because these can show
11319 messages and mini-buffers, and we don't handle that here. */
11320 if (MINI_WINDOW_P (w
))
11323 /* This flag is used to prevent redisplay optimizations. */
11324 if (windows_or_buffers_changed
)
11327 /* Verify that narrowing has not changed. This flag is also set to prevent
11328 redisplay optimizations. It would be nice to further
11329 reduce the number of cases where this prevents try_window_id. */
11330 if (current_buffer
->clip_changed
)
11333 /* Window must either use window-based redisplay or be full width. */
11334 if (!FRAME_WINDOW_P (f
)
11335 && (!line_ins_del_ok
11336 || !WINDOW_FULL_WIDTH_P (w
)))
11339 /* Give up if point is not known NOT to appear in W. */
11340 if (PT
< CHARPOS (start
))
11343 /* Another way to prevent redisplay optimizations. */
11344 if (XFASTINT (w
->last_modified
) == 0)
11347 /* Verify that window is not hscrolled. */
11348 if (XFASTINT (w
->hscroll
) != 0)
11351 /* Verify that display wasn't paused. */
11352 if (NILP (w
->window_end_valid
))
11355 /* Can't use this if highlighting a region because a cursor movement
11356 will do more than just set the cursor. */
11357 if (!NILP (Vtransient_mark_mode
)
11358 && !NILP (current_buffer
->mark_active
))
11361 /* Likewise if highlighting trailing whitespace. */
11362 if (!NILP (Vshow_trailing_whitespace
))
11365 /* Likewise if showing a region. */
11366 if (!NILP (w
->region_showing
))
11369 /* Can use this if overlay arrow position and or string have changed. */
11370 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11371 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11375 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11376 only if buffer has really changed. The reason is that the gap is
11377 initially at Z for freshly visited files. The code below would
11378 set end_unchanged to 0 in that case. */
11379 if (MODIFF
> SAVE_MODIFF
11380 /* This seems to happen sometimes after saving a buffer. */
11381 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11383 if (GPT
- BEG
< BEG_UNCHANGED
)
11384 BEG_UNCHANGED
= GPT
- BEG
;
11385 if (Z
- GPT
< END_UNCHANGED
)
11386 END_UNCHANGED
= Z
- GPT
;
11389 /* The position of the first and last character that has been changed. */
11390 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11391 last_changed_charpos
= Z
- END_UNCHANGED
;
11393 /* If window starts after a line end, and the last change is in
11394 front of that newline, then changes don't affect the display.
11395 This case happens with stealth-fontification. Note that although
11396 the display is unchanged, glyph positions in the matrix have to
11397 be adjusted, of course. */
11398 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11399 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11400 && ((last_changed_charpos
< CHARPOS (start
)
11401 && CHARPOS (start
) == BEGV
)
11402 || (last_changed_charpos
< CHARPOS (start
) - 1
11403 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11405 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11406 struct glyph_row
*r0
;
11408 /* Compute how many chars/bytes have been added to or removed
11409 from the buffer. */
11410 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11411 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11413 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11415 /* Give up if PT is not in the window. Note that it already has
11416 been checked at the start of try_window_id that PT is not in
11417 front of the window start. */
11418 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11421 /* If window start is unchanged, we can reuse the whole matrix
11422 as is, after adjusting glyph positions. No need to compute
11423 the window end again, since its offset from Z hasn't changed. */
11424 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11425 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11426 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11428 /* Adjust positions in the glyph matrix. */
11429 if (delta
|| delta_bytes
)
11431 struct glyph_row
*r1
11432 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11433 increment_matrix_positions (w
->current_matrix
,
11434 MATRIX_ROW_VPOS (r0
, current_matrix
),
11435 MATRIX_ROW_VPOS (r1
, current_matrix
),
11436 delta
, delta_bytes
);
11439 /* Set the cursor. */
11440 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11441 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11446 /* Handle the case that changes are all below what is displayed in
11447 the window, and that PT is in the window. This shortcut cannot
11448 be taken if ZV is visible in the window, and text has been added
11449 there that is visible in the window. */
11450 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11451 /* ZV is not visible in the window, or there are no
11452 changes at ZV, actually. */
11453 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11454 || first_changed_charpos
== last_changed_charpos
))
11456 struct glyph_row
*r0
;
11458 /* Give up if PT is not in the window. Note that it already has
11459 been checked at the start of try_window_id that PT is not in
11460 front of the window start. */
11461 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11464 /* If window start is unchanged, we can reuse the whole matrix
11465 as is, without changing glyph positions since no text has
11466 been added/removed in front of the window end. */
11467 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11468 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11470 /* We have to compute the window end anew since text
11471 can have been added/removed after it. */
11473 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11474 w
->window_end_bytepos
11475 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11477 /* Set the cursor. */
11478 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11479 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11484 /* Give up if window start is in the changed area.
11486 The condition used to read
11488 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11490 but why that was tested escapes me at the moment. */
11491 if (CHARPOS (start
) >= first_changed_charpos
11492 && CHARPOS (start
) <= last_changed_charpos
)
11495 /* Check that window start agrees with the start of the first glyph
11496 row in its current matrix. Check this after we know the window
11497 start is not in changed text, otherwise positions would not be
11499 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11500 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11503 /* Give up if the window ends in strings. Overlay strings
11504 at the end are difficult to handle, so don't try. */
11505 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
11506 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
11509 /* Compute the position at which we have to start displaying new
11510 lines. Some of the lines at the top of the window might be
11511 reusable because they are not displaying changed text. Find the
11512 last row in W's current matrix not affected by changes at the
11513 start of current_buffer. Value is null if changes start in the
11514 first line of window. */
11515 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11516 if (last_unchanged_at_beg_row
)
11518 /* Avoid starting to display in the moddle of a character, a TAB
11519 for instance. This is easier than to set up the iterator
11520 exactly, and it's not a frequent case, so the additional
11521 effort wouldn't really pay off. */
11522 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11523 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
11524 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11525 --last_unchanged_at_beg_row
;
11527 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11530 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11532 start_pos
= it
.current
.pos
;
11534 /* Start displaying new lines in the desired matrix at the same
11535 vpos we would use in the current matrix, i.e. below
11536 last_unchanged_at_beg_row. */
11537 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11539 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11540 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11542 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11546 /* There are no reusable lines at the start of the window.
11547 Start displaying in the first line. */
11548 start_display (&it
, w
, start
);
11549 start_pos
= it
.current
.pos
;
11552 /* Find the first row that is not affected by changes at the end of
11553 the buffer. Value will be null if there is no unchanged row, in
11554 which case we must redisplay to the end of the window. delta
11555 will be set to the value by which buffer positions beginning with
11556 first_unchanged_at_end_row have to be adjusted due to text
11558 first_unchanged_at_end_row
11559 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11560 IF_DEBUG (debug_delta
= delta
);
11561 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11563 /* Set stop_pos to the buffer position up to which we will have to
11564 display new lines. If first_unchanged_at_end_row != NULL, this
11565 is the buffer position of the start of the line displayed in that
11566 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11567 that we don't stop at a buffer position. */
11569 if (first_unchanged_at_end_row
)
11571 xassert (last_unchanged_at_beg_row
== NULL
11572 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11574 /* If this is a continuation line, move forward to the next one
11575 that isn't. Changes in lines above affect this line.
11576 Caution: this may move first_unchanged_at_end_row to a row
11577 not displaying text. */
11578 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11579 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11580 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11581 < it
.last_visible_y
))
11582 ++first_unchanged_at_end_row
;
11584 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11585 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11586 >= it
.last_visible_y
))
11587 first_unchanged_at_end_row
= NULL
;
11590 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11592 first_unchanged_at_end_vpos
11593 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11594 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11597 else if (last_unchanged_at_beg_row
== NULL
)
11603 /* Either there is no unchanged row at the end, or the one we have
11604 now displays text. This is a necessary condition for the window
11605 end pos calculation at the end of this function. */
11606 xassert (first_unchanged_at_end_row
== NULL
11607 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11609 debug_last_unchanged_at_beg_vpos
11610 = (last_unchanged_at_beg_row
11611 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11613 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11615 #endif /* GLYPH_DEBUG != 0 */
11618 /* Display new lines. Set last_text_row to the last new line
11619 displayed which has text on it, i.e. might end up as being the
11620 line where the window_end_vpos is. */
11621 w
->cursor
.vpos
= -1;
11622 last_text_row
= NULL
;
11623 overlay_arrow_seen
= 0;
11624 while (it
.current_y
< it
.last_visible_y
11625 && !fonts_changed_p
11626 && (first_unchanged_at_end_row
== NULL
11627 || IT_CHARPOS (it
) < stop_pos
))
11629 if (display_line (&it
))
11630 last_text_row
= it
.glyph_row
- 1;
11633 if (fonts_changed_p
)
11637 /* Compute differences in buffer positions, y-positions etc. for
11638 lines reused at the bottom of the window. Compute what we can
11640 if (first_unchanged_at_end_row
11641 /* No lines reused because we displayed everything up to the
11642 bottom of the window. */
11643 && it
.current_y
< it
.last_visible_y
)
11646 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11648 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11649 run
.current_y
= first_unchanged_at_end_row
->y
;
11650 run
.desired_y
= run
.current_y
+ dy
;
11651 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11655 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11656 first_unchanged_at_end_row
= NULL
;
11658 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11661 /* Find the cursor if not already found. We have to decide whether
11662 PT will appear on this window (it sometimes doesn't, but this is
11663 not a very frequent case.) This decision has to be made before
11664 the current matrix is altered. A value of cursor.vpos < 0 means
11665 that PT is either in one of the lines beginning at
11666 first_unchanged_at_end_row or below the window. Don't care for
11667 lines that might be displayed later at the window end; as
11668 mentioned, this is not a frequent case. */
11669 if (w
->cursor
.vpos
< 0)
11671 /* Cursor in unchanged rows at the top? */
11672 if (PT
< CHARPOS (start_pos
)
11673 && last_unchanged_at_beg_row
)
11675 row
= row_containing_pos (w
, PT
,
11676 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11677 last_unchanged_at_beg_row
+ 1, 0);
11679 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11682 /* Start from first_unchanged_at_end_row looking for PT. */
11683 else if (first_unchanged_at_end_row
)
11685 row
= row_containing_pos (w
, PT
- delta
,
11686 first_unchanged_at_end_row
, NULL
, 0);
11688 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11689 delta_bytes
, dy
, dvpos
);
11692 /* Give up if cursor was not found. */
11693 if (w
->cursor
.vpos
< 0)
11695 clear_glyph_matrix (w
->desired_matrix
);
11700 /* Don't let the cursor end in the scroll margins. */
11702 int this_scroll_margin
, cursor_height
;
11704 this_scroll_margin
= max (0, scroll_margin
);
11705 this_scroll_margin
= min (this_scroll_margin
,
11706 XFASTINT (w
->height
) / 4);
11707 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11708 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11710 if ((w
->cursor
.y
< this_scroll_margin
11711 && CHARPOS (start
) > BEGV
)
11712 /* Don't take scroll margin into account at the bottom because
11713 old redisplay didn't do it either. */
11714 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11716 w
->cursor
.vpos
= -1;
11717 clear_glyph_matrix (w
->desired_matrix
);
11722 /* Scroll the display. Do it before changing the current matrix so
11723 that xterm.c doesn't get confused about where the cursor glyph is
11725 if (dy
&& run
.height
)
11729 if (FRAME_WINDOW_P (f
))
11731 rif
->update_window_begin_hook (w
);
11732 rif
->clear_mouse_face (w
);
11733 rif
->scroll_run_hook (w
, &run
);
11734 rif
->update_window_end_hook (w
, 0, 0);
11738 /* Terminal frame. In this case, dvpos gives the number of
11739 lines to scroll by; dvpos < 0 means scroll up. */
11740 int first_unchanged_at_end_vpos
11741 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11742 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11743 int end
= (XFASTINT (w
->top
)
11744 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
11745 + window_internal_height (w
));
11747 /* Perform the operation on the screen. */
11750 /* Scroll last_unchanged_at_beg_row to the end of the
11751 window down dvpos lines. */
11752 set_terminal_window (end
);
11754 /* On dumb terminals delete dvpos lines at the end
11755 before inserting dvpos empty lines. */
11756 if (!scroll_region_ok
)
11757 ins_del_lines (end
- dvpos
, -dvpos
);
11759 /* Insert dvpos empty lines in front of
11760 last_unchanged_at_beg_row. */
11761 ins_del_lines (from
, dvpos
);
11763 else if (dvpos
< 0)
11765 /* Scroll up last_unchanged_at_beg_vpos to the end of
11766 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11767 set_terminal_window (end
);
11769 /* Delete dvpos lines in front of
11770 last_unchanged_at_beg_vpos. ins_del_lines will set
11771 the cursor to the given vpos and emit |dvpos| delete
11773 ins_del_lines (from
+ dvpos
, dvpos
);
11775 /* On a dumb terminal insert dvpos empty lines at the
11777 if (!scroll_region_ok
)
11778 ins_del_lines (end
+ dvpos
, -dvpos
);
11781 set_terminal_window (0);
11787 /* Shift reused rows of the current matrix to the right position.
11788 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11790 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11791 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11794 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11795 bottom_vpos
, dvpos
);
11796 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11799 else if (dvpos
> 0)
11801 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11802 bottom_vpos
, dvpos
);
11803 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11804 first_unchanged_at_end_vpos
+ dvpos
, 0);
11807 /* For frame-based redisplay, make sure that current frame and window
11808 matrix are in sync with respect to glyph memory. */
11809 if (!FRAME_WINDOW_P (f
))
11810 sync_frame_with_window_matrix_rows (w
);
11812 /* Adjust buffer positions in reused rows. */
11814 increment_matrix_positions (current_matrix
,
11815 first_unchanged_at_end_vpos
+ dvpos
,
11816 bottom_vpos
, delta
, delta_bytes
);
11818 /* Adjust Y positions. */
11820 shift_glyph_matrix (w
, current_matrix
,
11821 first_unchanged_at_end_vpos
+ dvpos
,
11824 if (first_unchanged_at_end_row
)
11825 first_unchanged_at_end_row
+= dvpos
;
11827 /* If scrolling up, there may be some lines to display at the end of
11829 last_text_row_at_end
= NULL
;
11832 /* Scrolling up can leave for example a partially visible line
11833 at the end of the window to be redisplayed. */
11834 /* Set last_row to the glyph row in the current matrix where the
11835 window end line is found. It has been moved up or down in
11836 the matrix by dvpos. */
11837 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11838 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11840 /* If last_row is the window end line, it should display text. */
11841 xassert (last_row
->displays_text_p
);
11843 /* If window end line was partially visible before, begin
11844 displaying at that line. Otherwise begin displaying with the
11845 line following it. */
11846 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11848 init_to_row_start (&it
, w
, last_row
);
11849 it
.vpos
= last_vpos
;
11850 it
.current_y
= last_row
->y
;
11854 init_to_row_end (&it
, w
, last_row
);
11855 it
.vpos
= 1 + last_vpos
;
11856 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11860 /* We may start in a continuation line. If so, we have to
11861 get the right continuation_lines_width and current_x. */
11862 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11863 it
.hpos
= it
.current_x
= 0;
11865 /* Display the rest of the lines at the window end. */
11866 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11867 while (it
.current_y
< it
.last_visible_y
11868 && !fonts_changed_p
)
11870 /* Is it always sure that the display agrees with lines in
11871 the current matrix? I don't think so, so we mark rows
11872 displayed invalid in the current matrix by setting their
11873 enabled_p flag to zero. */
11874 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11875 if (display_line (&it
))
11876 last_text_row_at_end
= it
.glyph_row
- 1;
11880 /* Update window_end_pos and window_end_vpos. */
11881 if (first_unchanged_at_end_row
11882 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11883 && !last_text_row_at_end
)
11885 /* Window end line if one of the preserved rows from the current
11886 matrix. Set row to the last row displaying text in current
11887 matrix starting at first_unchanged_at_end_row, after
11889 xassert (first_unchanged_at_end_row
->displays_text_p
);
11890 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11891 first_unchanged_at_end_row
);
11892 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11894 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11895 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11897 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11898 xassert (w
->window_end_bytepos
>= 0);
11899 IF_DEBUG (debug_method_add (w
, "A"));
11901 else if (last_text_row_at_end
)
11904 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11905 w
->window_end_bytepos
11906 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11908 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11909 xassert (w
->window_end_bytepos
>= 0);
11910 IF_DEBUG (debug_method_add (w
, "B"));
11912 else if (last_text_row
)
11914 /* We have displayed either to the end of the window or at the
11915 end of the window, i.e. the last row with text is to be found
11916 in the desired matrix. */
11918 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11919 w
->window_end_bytepos
11920 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11922 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11923 xassert (w
->window_end_bytepos
>= 0);
11925 else if (first_unchanged_at_end_row
== NULL
11926 && last_text_row
== NULL
11927 && last_text_row_at_end
== NULL
)
11929 /* Displayed to end of window, but no line containing text was
11930 displayed. Lines were deleted at the end of the window. */
11931 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11932 int vpos
= XFASTINT (w
->window_end_vpos
);
11933 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
11934 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
11937 row
== NULL
&& vpos
>= first_vpos
;
11938 --vpos
, --current_row
, --desired_row
)
11940 if (desired_row
->enabled_p
)
11942 if (desired_row
->displays_text_p
)
11945 else if (current_row
->displays_text_p
)
11949 xassert (row
!= NULL
);
11950 w
->window_end_vpos
= make_number (vpos
+ 1);
11951 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11952 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11953 xassert (w
->window_end_bytepos
>= 0);
11954 IF_DEBUG (debug_method_add (w
, "C"));
11959 #if 0 /* This leads to problems, for instance when the cursor is
11960 at ZV, and the cursor line displays no text. */
11961 /* Disable rows below what's displayed in the window. This makes
11962 debugging easier. */
11963 enable_glyph_matrix_rows (current_matrix
,
11964 XFASTINT (w
->window_end_vpos
) + 1,
11968 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11969 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11971 /* Record that display has not been completed. */
11972 w
->window_end_valid
= Qnil
;
11973 w
->desired_matrix
->no_scrolling_p
= 1;
11981 /***********************************************************************
11982 More debugging support
11983 ***********************************************************************/
11987 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
11988 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11989 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
11992 /* Dump the contents of glyph matrix MATRIX on stderr.
11994 GLYPHS 0 means don't show glyph contents.
11995 GLYPHS 1 means show glyphs in short form
11996 GLYPHS > 1 means show glyphs in long form. */
11999 dump_glyph_matrix (matrix
, glyphs
)
12000 struct glyph_matrix
*matrix
;
12004 for (i
= 0; i
< matrix
->nrows
; ++i
)
12005 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12009 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12010 the glyph row and area where the glyph comes from. */
12013 dump_glyph (row
, glyph
, area
)
12014 struct glyph_row
*row
;
12015 struct glyph
*glyph
;
12018 if (glyph
->type
== CHAR_GLYPH
)
12021 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12022 glyph
- row
->glyphs
[TEXT_AREA
],
12025 (BUFFERP (glyph
->object
)
12027 : (STRINGP (glyph
->object
)
12030 glyph
->pixel_width
,
12032 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12036 glyph
->left_box_line_p
,
12037 glyph
->right_box_line_p
);
12039 else if (glyph
->type
== STRETCH_GLYPH
)
12042 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12043 glyph
- row
->glyphs
[TEXT_AREA
],
12046 (BUFFERP (glyph
->object
)
12048 : (STRINGP (glyph
->object
)
12051 glyph
->pixel_width
,
12055 glyph
->left_box_line_p
,
12056 glyph
->right_box_line_p
);
12058 else if (glyph
->type
== IMAGE_GLYPH
)
12061 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12062 glyph
- row
->glyphs
[TEXT_AREA
],
12065 (BUFFERP (glyph
->object
)
12067 : (STRINGP (glyph
->object
)
12070 glyph
->pixel_width
,
12074 glyph
->left_box_line_p
,
12075 glyph
->right_box_line_p
);
12080 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12081 GLYPHS 0 means don't show glyph contents.
12082 GLYPHS 1 means show glyphs in short form
12083 GLYPHS > 1 means show glyphs in long form. */
12086 dump_glyph_row (row
, vpos
, glyphs
)
12087 struct glyph_row
*row
;
12092 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12093 fprintf (stderr
, "=======================================================================\n");
12095 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12096 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12098 MATRIX_ROW_START_CHARPOS (row
),
12099 MATRIX_ROW_END_CHARPOS (row
),
12100 row
->used
[TEXT_AREA
],
12101 row
->contains_overlapping_glyphs_p
,
12103 row
->truncated_on_left_p
,
12104 row
->truncated_on_right_p
,
12105 row
->overlay_arrow_p
,
12107 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12108 row
->displays_text_p
,
12111 row
->ends_in_middle_of_char_p
,
12112 row
->starts_in_middle_of_char_p
,
12118 row
->visible_height
,
12121 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12122 row
->end
.overlay_string_index
,
12123 row
->continuation_lines_width
);
12124 fprintf (stderr
, "%9d %5d\n",
12125 CHARPOS (row
->start
.string_pos
),
12126 CHARPOS (row
->end
.string_pos
));
12127 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12128 row
->end
.dpvec_index
);
12135 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12137 struct glyph
*glyph
= row
->glyphs
[area
];
12138 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12140 /* Glyph for a line end in text. */
12141 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12144 if (glyph
< glyph_end
)
12145 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12147 for (; glyph
< glyph_end
; ++glyph
)
12148 dump_glyph (row
, glyph
, area
);
12151 else if (glyphs
== 1)
12155 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12157 char *s
= (char *) alloca (row
->used
[area
] + 1);
12160 for (i
= 0; i
< row
->used
[area
]; ++i
)
12162 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12163 if (glyph
->type
== CHAR_GLYPH
12164 && glyph
->u
.ch
< 0x80
12165 && glyph
->u
.ch
>= ' ')
12166 s
[i
] = glyph
->u
.ch
;
12172 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12178 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12179 Sdump_glyph_matrix
, 0, 1, "p",
12180 doc
: /* Dump the current matrix of the selected window to stderr.
12181 Shows contents of glyph row structures. With non-nil
12182 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12183 glyphs in short form, otherwise show glyphs in long form. */)
12185 Lisp_Object glyphs
;
12187 struct window
*w
= XWINDOW (selected_window
);
12188 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12190 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12191 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12192 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12193 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12194 fprintf (stderr
, "=============================================\n");
12195 dump_glyph_matrix (w
->current_matrix
,
12196 NILP (glyphs
) ? 0 : XINT (glyphs
));
12201 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12202 doc
: /* Dump glyph row ROW to stderr.
12203 GLYPH 0 means don't dump glyphs.
12204 GLYPH 1 means dump glyphs in short form.
12205 GLYPH > 1 or omitted means dump glyphs in long form. */)
12207 Lisp_Object row
, glyphs
;
12209 struct glyph_matrix
*matrix
;
12212 CHECK_NUMBER (row
);
12213 matrix
= XWINDOW (selected_window
)->current_matrix
;
12215 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12216 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12218 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12223 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12224 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12225 GLYPH 0 means don't dump glyphs.
12226 GLYPH 1 means dump glyphs in short form.
12227 GLYPH > 1 or omitted means dump glyphs in long form. */)
12229 Lisp_Object row
, glyphs
;
12231 struct frame
*sf
= SELECTED_FRAME ();
12232 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12235 CHECK_NUMBER (row
);
12237 if (vpos
>= 0 && vpos
< m
->nrows
)
12238 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12239 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12244 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12245 doc
: /* Toggle tracing of redisplay.
12246 With ARG, turn tracing on if and only if ARG is positive. */)
12251 trace_redisplay_p
= !trace_redisplay_p
;
12254 arg
= Fprefix_numeric_value (arg
);
12255 trace_redisplay_p
= XINT (arg
) > 0;
12262 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12263 doc
: /* Like `format', but print result to stderr. */)
12268 Lisp_Object s
= Fformat (nargs
, args
);
12269 fprintf (stderr
, "%s", XSTRING (s
)->data
);
12273 #endif /* GLYPH_DEBUG */
12277 /***********************************************************************
12278 Building Desired Matrix Rows
12279 ***********************************************************************/
12281 /* Return a temporary glyph row holding the glyphs of an overlay
12282 arrow. Only used for non-window-redisplay windows. */
12284 static struct glyph_row
*
12285 get_overlay_arrow_glyph_row (w
)
12288 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12289 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12290 struct buffer
*old
= current_buffer
;
12291 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
12292 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
12293 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12297 int n_glyphs_before
;
12299 set_buffer_temp (buffer
);
12300 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12301 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12302 SET_TEXT_POS (it
.position
, 0, 0);
12304 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12306 while (p
< arrow_end
)
12308 Lisp_Object face
, ilisp
;
12310 /* Get the next character. */
12312 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12314 it
.c
= *p
, it
.len
= 1;
12317 /* Get its face. */
12318 ilisp
= make_number (p
- arrow_string
);
12319 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12320 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12322 /* Compute its width, get its glyphs. */
12323 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12324 SET_TEXT_POS (it
.position
, -1, -1);
12325 PRODUCE_GLYPHS (&it
);
12327 /* If this character doesn't fit any more in the line, we have
12328 to remove some glyphs. */
12329 if (it
.current_x
> it
.last_visible_x
)
12331 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12336 set_buffer_temp (old
);
12337 return it
.glyph_row
;
12341 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12342 glyphs are only inserted for terminal frames since we can't really
12343 win with truncation glyphs when partially visible glyphs are
12344 involved. Which glyphs to insert is determined by
12345 produce_special_glyphs. */
12348 insert_left_trunc_glyphs (it
)
12351 struct it truncate_it
;
12352 struct glyph
*from
, *end
, *to
, *toend
;
12354 xassert (!FRAME_WINDOW_P (it
->f
));
12356 /* Get the truncation glyphs. */
12358 truncate_it
.current_x
= 0;
12359 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12360 truncate_it
.glyph_row
= &scratch_glyph_row
;
12361 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12362 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12363 truncate_it
.object
= make_number (0);
12364 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12366 /* Overwrite glyphs from IT with truncation glyphs. */
12367 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12368 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12369 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12370 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12375 /* There may be padding glyphs left over. Overwrite them too. */
12376 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12378 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12384 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12388 /* Compute the pixel height and width of IT->glyph_row.
12390 Most of the time, ascent and height of a display line will be equal
12391 to the max_ascent and max_height values of the display iterator
12392 structure. This is not the case if
12394 1. We hit ZV without displaying anything. In this case, max_ascent
12395 and max_height will be zero.
12397 2. We have some glyphs that don't contribute to the line height.
12398 (The glyph row flag contributes_to_line_height_p is for future
12399 pixmap extensions).
12401 The first case is easily covered by using default values because in
12402 these cases, the line height does not really matter, except that it
12403 must not be zero. */
12406 compute_line_metrics (it
)
12409 struct glyph_row
*row
= it
->glyph_row
;
12412 if (FRAME_WINDOW_P (it
->f
))
12414 int i
, min_y
, max_y
;
12416 /* The line may consist of one space only, that was added to
12417 place the cursor on it. If so, the row's height hasn't been
12419 if (row
->height
== 0)
12421 if (it
->max_ascent
+ it
->max_descent
== 0)
12422 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12423 row
->ascent
= it
->max_ascent
;
12424 row
->height
= it
->max_ascent
+ it
->max_descent
;
12425 row
->phys_ascent
= it
->max_phys_ascent
;
12426 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12429 /* Compute the width of this line. */
12430 row
->pixel_width
= row
->x
;
12431 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12432 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12434 xassert (row
->pixel_width
>= 0);
12435 xassert (row
->ascent
>= 0 && row
->height
> 0);
12437 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12438 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12440 /* If first line's physical ascent is larger than its logical
12441 ascent, use the physical ascent, and make the row taller.
12442 This makes accented characters fully visible. */
12443 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12444 && row
->phys_ascent
> row
->ascent
)
12446 row
->height
+= row
->phys_ascent
- row
->ascent
;
12447 row
->ascent
= row
->phys_ascent
;
12450 /* Compute how much of the line is visible. */
12451 row
->visible_height
= row
->height
;
12453 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12454 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12456 if (row
->y
< min_y
)
12457 row
->visible_height
-= min_y
- row
->y
;
12458 if (row
->y
+ row
->height
> max_y
)
12459 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12463 row
->pixel_width
= row
->used
[TEXT_AREA
];
12464 if (row
->continued_p
)
12465 row
->pixel_width
-= it
->continuation_pixel_width
;
12466 else if (row
->truncated_on_right_p
)
12467 row
->pixel_width
-= it
->truncation_pixel_width
;
12468 row
->ascent
= row
->phys_ascent
= 0;
12469 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12472 /* Compute a hash code for this row. */
12474 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12475 for (i
= 0; i
< row
->used
[area
]; ++i
)
12476 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12477 + row
->glyphs
[area
][i
].u
.val
12478 + row
->glyphs
[area
][i
].face_id
12479 + row
->glyphs
[area
][i
].padding_p
12480 + (row
->glyphs
[area
][i
].type
<< 2));
12482 it
->max_ascent
= it
->max_descent
= 0;
12483 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12487 /* Append one space to the glyph row of iterator IT if doing a
12488 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12489 space have the default face, otherwise let it have the same face as
12490 IT->face_id. Value is non-zero if a space was added.
12492 This function is called to make sure that there is always one glyph
12493 at the end of a glyph row that the cursor can be set on under
12494 window-systems. (If there weren't such a glyph we would not know
12495 how wide and tall a box cursor should be displayed).
12497 At the same time this space let's a nicely handle clearing to the
12498 end of the line if the row ends in italic text. */
12501 append_space (it
, default_face_p
)
12503 int default_face_p
;
12505 if (FRAME_WINDOW_P (it
->f
))
12507 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12509 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12510 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12512 /* Save some values that must not be changed.
12513 Must save IT->c and IT->len because otherwise
12514 ITERATOR_AT_END_P wouldn't work anymore after
12515 append_space has been called. */
12516 enum display_element_type saved_what
= it
->what
;
12517 int saved_c
= it
->c
, saved_len
= it
->len
;
12518 int saved_x
= it
->current_x
;
12519 int saved_face_id
= it
->face_id
;
12520 struct text_pos saved_pos
;
12521 Lisp_Object saved_object
;
12524 saved_object
= it
->object
;
12525 saved_pos
= it
->position
;
12527 it
->what
= IT_CHARACTER
;
12528 bzero (&it
->position
, sizeof it
->position
);
12529 it
->object
= make_number (0);
12533 if (default_face_p
)
12534 it
->face_id
= DEFAULT_FACE_ID
;
12535 else if (it
->face_before_selective_p
)
12536 it
->face_id
= it
->saved_face_id
;
12537 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12538 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12540 PRODUCE_GLYPHS (it
);
12542 it
->current_x
= saved_x
;
12543 it
->object
= saved_object
;
12544 it
->position
= saved_pos
;
12545 it
->what
= saved_what
;
12546 it
->face_id
= saved_face_id
;
12547 it
->len
= saved_len
;
12557 /* Extend the face of the last glyph in the text area of IT->glyph_row
12558 to the end of the display line. Called from display_line.
12559 If the glyph row is empty, add a space glyph to it so that we
12560 know the face to draw. Set the glyph row flag fill_line_p. */
12563 extend_face_to_end_of_line (it
)
12567 struct frame
*f
= it
->f
;
12569 /* If line is already filled, do nothing. */
12570 if (it
->current_x
>= it
->last_visible_x
)
12573 /* Face extension extends the background and box of IT->face_id
12574 to the end of the line. If the background equals the background
12575 of the frame, we don't have to do anything. */
12576 if (it
->face_before_selective_p
)
12577 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12579 face
= FACE_FROM_ID (f
, it
->face_id
);
12581 if (FRAME_WINDOW_P (f
)
12582 && face
->box
== FACE_NO_BOX
12583 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12587 /* Set the glyph row flag indicating that the face of the last glyph
12588 in the text area has to be drawn to the end of the text area. */
12589 it
->glyph_row
->fill_line_p
= 1;
12591 /* If current character of IT is not ASCII, make sure we have the
12592 ASCII face. This will be automatically undone the next time
12593 get_next_display_element returns a multibyte character. Note
12594 that the character will always be single byte in unibyte text. */
12595 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12597 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12600 if (FRAME_WINDOW_P (f
))
12602 /* If the row is empty, add a space with the current face of IT,
12603 so that we know which face to draw. */
12604 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12606 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12607 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12608 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12613 /* Save some values that must not be changed. */
12614 int saved_x
= it
->current_x
;
12615 struct text_pos saved_pos
;
12616 Lisp_Object saved_object
;
12617 enum display_element_type saved_what
= it
->what
;
12618 int saved_face_id
= it
->face_id
;
12620 saved_object
= it
->object
;
12621 saved_pos
= it
->position
;
12623 it
->what
= IT_CHARACTER
;
12624 bzero (&it
->position
, sizeof it
->position
);
12625 it
->object
= make_number (0);
12628 it
->face_id
= face
->id
;
12630 PRODUCE_GLYPHS (it
);
12632 while (it
->current_x
<= it
->last_visible_x
)
12633 PRODUCE_GLYPHS (it
);
12635 /* Don't count these blanks really. It would let us insert a left
12636 truncation glyph below and make us set the cursor on them, maybe. */
12637 it
->current_x
= saved_x
;
12638 it
->object
= saved_object
;
12639 it
->position
= saved_pos
;
12640 it
->what
= saved_what
;
12641 it
->face_id
= saved_face_id
;
12646 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12647 trailing whitespace. */
12650 trailing_whitespace_p (charpos
)
12653 int bytepos
= CHAR_TO_BYTE (charpos
);
12656 while (bytepos
< ZV_BYTE
12657 && (c
= FETCH_CHAR (bytepos
),
12658 c
== ' ' || c
== '\t'))
12661 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12663 if (bytepos
!= PT_BYTE
)
12670 /* Highlight trailing whitespace, if any, in ROW. */
12673 highlight_trailing_whitespace (f
, row
)
12675 struct glyph_row
*row
;
12677 int used
= row
->used
[TEXT_AREA
];
12681 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12682 struct glyph
*glyph
= start
+ used
- 1;
12684 /* Skip over glyphs inserted to display the cursor at the
12685 end of a line, for extending the face of the last glyph
12686 to the end of the line on terminals, and for truncation
12687 and continuation glyphs. */
12688 while (glyph
>= start
12689 && glyph
->type
== CHAR_GLYPH
12690 && INTEGERP (glyph
->object
))
12693 /* If last glyph is a space or stretch, and it's trailing
12694 whitespace, set the face of all trailing whitespace glyphs in
12695 IT->glyph_row to `trailing-whitespace'. */
12697 && BUFFERP (glyph
->object
)
12698 && (glyph
->type
== STRETCH_GLYPH
12699 || (glyph
->type
== CHAR_GLYPH
12700 && glyph
->u
.ch
== ' '))
12701 && trailing_whitespace_p (glyph
->charpos
))
12703 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12705 while (glyph
>= start
12706 && BUFFERP (glyph
->object
)
12707 && (glyph
->type
== STRETCH_GLYPH
12708 || (glyph
->type
== CHAR_GLYPH
12709 && glyph
->u
.ch
== ' ')))
12710 (glyph
--)->face_id
= face_id
;
12716 /* Value is non-zero if glyph row ROW in window W should be
12717 used to hold the cursor. */
12720 cursor_row_p (w
, row
)
12722 struct glyph_row
*row
;
12724 int cursor_row_p
= 1;
12726 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12728 /* If the row ends with a newline from a string, we don't want
12729 the cursor there (if the row is continued it doesn't end in a
12731 if (CHARPOS (row
->end
.string_pos
) >= 0
12732 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12733 cursor_row_p
= row
->continued_p
;
12735 /* If the row ends at ZV, display the cursor at the end of that
12736 row instead of at the start of the row below. */
12737 else if (row
->ends_at_zv_p
)
12743 return cursor_row_p
;
12747 /* Construct the glyph row IT->glyph_row in the desired matrix of
12748 IT->w from text at the current position of IT. See dispextern.h
12749 for an overview of struct it. Value is non-zero if
12750 IT->glyph_row displays text, as opposed to a line displaying ZV
12757 struct glyph_row
*row
= it
->glyph_row
;
12759 /* We always start displaying at hpos zero even if hscrolled. */
12760 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12762 /* We must not display in a row that's not a text row. */
12763 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12764 < it
->w
->desired_matrix
->nrows
);
12766 /* Is IT->w showing the region? */
12767 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12769 /* Clear the result glyph row and enable it. */
12770 prepare_desired_row (row
);
12772 row
->y
= it
->current_y
;
12773 row
->start
= it
->current
;
12774 row
->continuation_lines_width
= it
->continuation_lines_width
;
12775 row
->displays_text_p
= 1;
12776 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12777 it
->starts_in_middle_of_char_p
= 0;
12779 /* Arrange the overlays nicely for our purposes. Usually, we call
12780 display_line on only one line at a time, in which case this
12781 can't really hurt too much, or we call it on lines which appear
12782 one after another in the buffer, in which case all calls to
12783 recenter_overlay_lists but the first will be pretty cheap. */
12784 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12786 /* Move over display elements that are not visible because we are
12787 hscrolled. This may stop at an x-position < IT->first_visible_x
12788 if the first glyph is partially visible or if we hit a line end. */
12789 if (it
->current_x
< it
->first_visible_x
)
12790 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12791 MOVE_TO_POS
| MOVE_TO_X
);
12793 /* Get the initial row height. This is either the height of the
12794 text hscrolled, if there is any, or zero. */
12795 row
->ascent
= it
->max_ascent
;
12796 row
->height
= it
->max_ascent
+ it
->max_descent
;
12797 row
->phys_ascent
= it
->max_phys_ascent
;
12798 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12800 /* Loop generating characters. The loop is left with IT on the next
12801 character to display. */
12804 int n_glyphs_before
, hpos_before
, x_before
;
12806 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12808 /* Retrieve the next thing to display. Value is zero if end of
12810 if (!get_next_display_element (it
))
12812 /* Maybe add a space at the end of this line that is used to
12813 display the cursor there under X. Set the charpos of the
12814 first glyph of blank lines not corresponding to any text
12816 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12817 || row
->used
[TEXT_AREA
] == 0)
12819 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12820 row
->displays_text_p
= 0;
12822 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
12823 && (!MINI_WINDOW_P (it
->w
)
12824 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
12825 row
->indicate_empty_line_p
= 1;
12828 it
->continuation_lines_width
= 0;
12829 row
->ends_at_zv_p
= 1;
12833 /* Now, get the metrics of what we want to display. This also
12834 generates glyphs in `row' (which is IT->glyph_row). */
12835 n_glyphs_before
= row
->used
[TEXT_AREA
];
12838 /* Remember the line height so far in case the next element doesn't
12839 fit on the line. */
12840 if (!it
->truncate_lines_p
)
12842 ascent
= it
->max_ascent
;
12843 descent
= it
->max_descent
;
12844 phys_ascent
= it
->max_phys_ascent
;
12845 phys_descent
= it
->max_phys_descent
;
12848 PRODUCE_GLYPHS (it
);
12850 /* If this display element was in marginal areas, continue with
12852 if (it
->area
!= TEXT_AREA
)
12854 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12855 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12856 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12857 row
->phys_height
= max (row
->phys_height
,
12858 it
->max_phys_ascent
+ it
->max_phys_descent
);
12859 set_iterator_to_next (it
, 1);
12863 /* Does the display element fit on the line? If we truncate
12864 lines, we should draw past the right edge of the window. If
12865 we don't truncate, we want to stop so that we can display the
12866 continuation glyph before the right margin. If lines are
12867 continued, there are two possible strategies for characters
12868 resulting in more than 1 glyph (e.g. tabs): Display as many
12869 glyphs as possible in this line and leave the rest for the
12870 continuation line, or display the whole element in the next
12871 line. Original redisplay did the former, so we do it also. */
12872 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12873 hpos_before
= it
->hpos
;
12876 if (/* Not a newline. */
12878 /* Glyphs produced fit entirely in the line. */
12879 && it
->current_x
< it
->last_visible_x
)
12881 it
->hpos
+= nglyphs
;
12882 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12883 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12884 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12885 row
->phys_height
= max (row
->phys_height
,
12886 it
->max_phys_ascent
+ it
->max_phys_descent
);
12887 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
12888 row
->x
= x
- it
->first_visible_x
;
12893 struct glyph
*glyph
;
12895 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
12897 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12898 new_x
= x
+ glyph
->pixel_width
;
12900 if (/* Lines are continued. */
12901 !it
->truncate_lines_p
12902 && (/* Glyph doesn't fit on the line. */
12903 new_x
> it
->last_visible_x
12904 /* Or it fits exactly on a window system frame. */
12905 || (new_x
== it
->last_visible_x
12906 && FRAME_WINDOW_P (it
->f
))))
12908 /* End of a continued line. */
12911 || (new_x
== it
->last_visible_x
12912 && FRAME_WINDOW_P (it
->f
)))
12914 /* Current glyph is the only one on the line or
12915 fits exactly on the line. We must continue
12916 the line because we can't draw the cursor
12917 after the glyph. */
12918 row
->continued_p
= 1;
12919 it
->current_x
= new_x
;
12920 it
->continuation_lines_width
+= new_x
;
12922 if (i
== nglyphs
- 1)
12923 set_iterator_to_next (it
, 1);
12925 else if (CHAR_GLYPH_PADDING_P (*glyph
)
12926 && !FRAME_WINDOW_P (it
->f
))
12928 /* A padding glyph that doesn't fit on this line.
12929 This means the whole character doesn't fit
12931 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12933 /* Fill the rest of the row with continuation
12934 glyphs like in 20.x. */
12935 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
12936 < row
->glyphs
[1 + TEXT_AREA
])
12937 produce_special_glyphs (it
, IT_CONTINUATION
);
12939 row
->continued_p
= 1;
12940 it
->current_x
= x_before
;
12941 it
->continuation_lines_width
+= x_before
;
12943 /* Restore the height to what it was before the
12944 element not fitting on the line. */
12945 it
->max_ascent
= ascent
;
12946 it
->max_descent
= descent
;
12947 it
->max_phys_ascent
= phys_ascent
;
12948 it
->max_phys_descent
= phys_descent
;
12950 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
12952 /* A TAB that extends past the right edge of the
12953 window. This produces a single glyph on
12954 window system frames. We leave the glyph in
12955 this row and let it fill the row, but don't
12956 consume the TAB. */
12957 it
->continuation_lines_width
+= it
->last_visible_x
;
12958 row
->ends_in_middle_of_char_p
= 1;
12959 row
->continued_p
= 1;
12960 glyph
->pixel_width
= it
->last_visible_x
- x
;
12961 it
->starts_in_middle_of_char_p
= 1;
12965 /* Something other than a TAB that draws past
12966 the right edge of the window. Restore
12967 positions to values before the element. */
12968 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12970 /* Display continuation glyphs. */
12971 if (!FRAME_WINDOW_P (it
->f
))
12972 produce_special_glyphs (it
, IT_CONTINUATION
);
12973 row
->continued_p
= 1;
12975 it
->continuation_lines_width
+= x
;
12977 if (nglyphs
> 1 && i
> 0)
12979 row
->ends_in_middle_of_char_p
= 1;
12980 it
->starts_in_middle_of_char_p
= 1;
12983 /* Restore the height to what it was before the
12984 element not fitting on the line. */
12985 it
->max_ascent
= ascent
;
12986 it
->max_descent
= descent
;
12987 it
->max_phys_ascent
= phys_ascent
;
12988 it
->max_phys_descent
= phys_descent
;
12993 else if (new_x
> it
->first_visible_x
)
12995 /* Increment number of glyphs actually displayed. */
12998 if (x
< it
->first_visible_x
)
12999 /* Glyph is partially visible, i.e. row starts at
13000 negative X position. */
13001 row
->x
= x
- it
->first_visible_x
;
13005 /* Glyph is completely off the left margin of the
13006 window. This should not happen because of the
13007 move_it_in_display_line at the start of
13013 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13014 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13015 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13016 row
->phys_height
= max (row
->phys_height
,
13017 it
->max_phys_ascent
+ it
->max_phys_descent
);
13019 /* End of this display line if row is continued. */
13020 if (row
->continued_p
)
13024 /* Is this a line end? If yes, we're also done, after making
13025 sure that a non-default face is extended up to the right
13026 margin of the window. */
13027 if (ITERATOR_AT_END_OF_LINE_P (it
))
13029 int used_before
= row
->used
[TEXT_AREA
];
13031 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13033 /* Add a space at the end of the line that is used to
13034 display the cursor there. */
13035 append_space (it
, 0);
13037 /* Extend the face to the end of the line. */
13038 extend_face_to_end_of_line (it
);
13040 /* Make sure we have the position. */
13041 if (used_before
== 0)
13042 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13044 /* Consume the line end. This skips over invisible lines. */
13045 set_iterator_to_next (it
, 1);
13046 it
->continuation_lines_width
= 0;
13050 /* Proceed with next display element. Note that this skips
13051 over lines invisible because of selective display. */
13052 set_iterator_to_next (it
, 1);
13054 /* If we truncate lines, we are done when the last displayed
13055 glyphs reach past the right margin of the window. */
13056 if (it
->truncate_lines_p
13057 && (FRAME_WINDOW_P (it
->f
)
13058 ? (it
->current_x
>= it
->last_visible_x
)
13059 : (it
->current_x
> it
->last_visible_x
)))
13061 /* Maybe add truncation glyphs. */
13062 if (!FRAME_WINDOW_P (it
->f
))
13066 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13067 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13070 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13072 row
->used
[TEXT_AREA
] = i
;
13073 produce_special_glyphs (it
, IT_TRUNCATION
);
13077 row
->truncated_on_right_p
= 1;
13078 it
->continuation_lines_width
= 0;
13079 reseat_at_next_visible_line_start (it
, 0);
13080 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13081 it
->hpos
= hpos_before
;
13082 it
->current_x
= x_before
;
13087 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13088 at the left window margin. */
13089 if (it
->first_visible_x
13090 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13092 if (!FRAME_WINDOW_P (it
->f
))
13093 insert_left_trunc_glyphs (it
);
13094 row
->truncated_on_left_p
= 1;
13097 /* If the start of this line is the overlay arrow-position, then
13098 mark this glyph row as the one containing the overlay arrow.
13099 This is clearly a mess with variable size fonts. It would be
13100 better to let it be displayed like cursors under X. */
13101 if (MARKERP (Voverlay_arrow_position
)
13102 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13103 && (MATRIX_ROW_START_CHARPOS (row
)
13104 == marker_position (Voverlay_arrow_position
))
13105 && STRINGP (Voverlay_arrow_string
)
13106 && ! overlay_arrow_seen
)
13108 /* Overlay arrow in window redisplay is a fringe bitmap. */
13109 if (!FRAME_WINDOW_P (it
->f
))
13111 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13112 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13113 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13114 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13115 struct glyph
*p2
, *end
;
13117 /* Copy the arrow glyphs. */
13118 while (glyph
< arrow_end
)
13121 /* Throw away padding glyphs. */
13123 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13124 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13130 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13134 overlay_arrow_seen
= 1;
13135 row
->overlay_arrow_p
= 1;
13138 /* Compute pixel dimensions of this line. */
13139 compute_line_metrics (it
);
13141 /* Remember the position at which this line ends. */
13142 row
->end
= it
->current
;
13144 /* Maybe set the cursor. */
13145 if (it
->w
->cursor
.vpos
< 0
13146 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13147 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13148 && cursor_row_p (it
->w
, row
))
13149 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13151 /* Highlight trailing whitespace. */
13152 if (!NILP (Vshow_trailing_whitespace
))
13153 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13155 /* Prepare for the next line. This line starts horizontally at (X
13156 HPOS) = (0 0). Vertical positions are incremented. As a
13157 convenience for the caller, IT->glyph_row is set to the next
13159 it
->current_x
= it
->hpos
= 0;
13160 it
->current_y
+= row
->height
;
13163 return row
->displays_text_p
;
13168 /***********************************************************************
13170 ***********************************************************************/
13172 /* Redisplay the menu bar in the frame for window W.
13174 The menu bar of X frames that don't have X toolkit support is
13175 displayed in a special window W->frame->menu_bar_window.
13177 The menu bar of terminal frames is treated specially as far as
13178 glyph matrices are concerned. Menu bar lines are not part of
13179 windows, so the update is done directly on the frame matrix rows
13180 for the menu bar. */
13183 display_menu_bar (w
)
13186 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13191 /* Don't do all this for graphical frames. */
13193 if (!NILP (Vwindow_system
))
13196 #ifdef USE_X_TOOLKIT
13201 if (FRAME_MAC_P (f
))
13205 #ifdef USE_X_TOOLKIT
13206 xassert (!FRAME_WINDOW_P (f
));
13207 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13208 it
.first_visible_x
= 0;
13209 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13210 #else /* not USE_X_TOOLKIT */
13211 if (FRAME_WINDOW_P (f
))
13213 /* Menu bar lines are displayed in the desired matrix of the
13214 dummy window menu_bar_window. */
13215 struct window
*menu_w
;
13216 xassert (WINDOWP (f
->menu_bar_window
));
13217 menu_w
= XWINDOW (f
->menu_bar_window
);
13218 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13220 it
.first_visible_x
= 0;
13221 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13225 /* This is a TTY frame, i.e. character hpos/vpos are used as
13227 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13229 it
.first_visible_x
= 0;
13230 it
.last_visible_x
= FRAME_WIDTH (f
);
13232 #endif /* not USE_X_TOOLKIT */
13234 if (! mode_line_inverse_video
)
13235 /* Force the menu-bar to be displayed in the default face. */
13236 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13238 /* Clear all rows of the menu bar. */
13239 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13241 struct glyph_row
*row
= it
.glyph_row
+ i
;
13242 clear_glyph_row (row
);
13243 row
->enabled_p
= 1;
13244 row
->full_width_p
= 1;
13247 /* Display all items of the menu bar. */
13248 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13249 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13251 Lisp_Object string
;
13253 /* Stop at nil string. */
13254 string
= AREF (items
, i
+ 1);
13258 /* Remember where item was displayed. */
13259 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13261 /* Display the item, pad with one space. */
13262 if (it
.current_x
< it
.last_visible_x
)
13263 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13264 XSTRING (string
)->size
+ 1, 0, 0, -1);
13267 /* Fill out the line with spaces. */
13268 if (it
.current_x
< it
.last_visible_x
)
13269 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13271 /* Compute the total height of the lines. */
13272 compute_line_metrics (&it
);
13277 /***********************************************************************
13279 ***********************************************************************/
13281 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13282 FORCE is non-zero, redisplay mode lines unconditionally.
13283 Otherwise, redisplay only mode lines that are garbaged. Value is
13284 the number of windows whose mode lines were redisplayed. */
13287 redisplay_mode_lines (window
, force
)
13288 Lisp_Object window
;
13293 while (!NILP (window
))
13295 struct window
*w
= XWINDOW (window
);
13297 if (WINDOWP (w
->hchild
))
13298 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13299 else if (WINDOWP (w
->vchild
))
13300 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13302 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13303 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13305 struct text_pos lpoint
;
13306 struct buffer
*old
= current_buffer
;
13308 /* Set the window's buffer for the mode line display. */
13309 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13310 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13312 /* Point refers normally to the selected window. For any
13313 other window, set up appropriate value. */
13314 if (!EQ (window
, selected_window
))
13316 struct text_pos pt
;
13318 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13319 if (CHARPOS (pt
) < BEGV
)
13320 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13321 else if (CHARPOS (pt
) > (ZV
- 1))
13322 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13324 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13327 /* Display mode lines. */
13328 clear_glyph_matrix (w
->desired_matrix
);
13329 if (display_mode_lines (w
))
13332 w
->must_be_updated_p
= 1;
13335 /* Restore old settings. */
13336 set_buffer_internal_1 (old
);
13337 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13347 /* Display the mode and/or top line of window W. Value is the number
13348 of mode lines displayed. */
13351 display_mode_lines (w
)
13354 Lisp_Object old_selected_window
, old_selected_frame
;
13357 old_selected_frame
= selected_frame
;
13358 selected_frame
= w
->frame
;
13359 old_selected_window
= selected_window
;
13360 XSETWINDOW (selected_window
, w
);
13362 /* These will be set while the mode line specs are processed. */
13363 line_number_displayed
= 0;
13364 w
->column_number_displayed
= Qnil
;
13366 if (WINDOW_WANTS_MODELINE_P (w
))
13368 display_mode_line (w
, MODE_LINE_FACE_ID
,
13369 current_buffer
->mode_line_format
);
13373 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13375 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13376 current_buffer
->header_line_format
);
13380 selected_frame
= old_selected_frame
;
13381 selected_window
= old_selected_window
;
13386 /* Display mode or top line of window W. FACE_ID specifies which line
13387 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13388 FORMAT is the mode line format to display. Value is the pixel
13389 height of the mode line displayed. */
13392 display_mode_line (w
, face_id
, format
)
13394 enum face_id face_id
;
13395 Lisp_Object format
;
13400 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13401 prepare_desired_row (it
.glyph_row
);
13403 if (! mode_line_inverse_video
)
13404 /* Force the mode-line to be displayed in the default face. */
13405 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13407 /* Temporarily make frame's keyboard the current kboard so that
13408 kboard-local variables in the mode_line_format will get the right
13410 push_frame_kboard (it
.f
);
13411 display_mode_element (&it
, 0, 0, 0, format
);
13412 pop_frame_kboard ();
13414 /* Fill up with spaces. */
13415 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13417 compute_line_metrics (&it
);
13418 it
.glyph_row
->full_width_p
= 1;
13419 it
.glyph_row
->mode_line_p
= 1;
13420 it
.glyph_row
->continued_p
= 0;
13421 it
.glyph_row
->truncated_on_left_p
= 0;
13422 it
.glyph_row
->truncated_on_right_p
= 0;
13424 /* Make a 3D mode-line have a shadow at its right end. */
13425 face
= FACE_FROM_ID (it
.f
, face_id
);
13426 extend_face_to_end_of_line (&it
);
13427 if (face
->box
!= FACE_NO_BOX
)
13429 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13430 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13431 last
->right_box_line_p
= 1;
13434 return it
.glyph_row
->height
;
13438 /* Contribute ELT to the mode line for window IT->w. How it
13439 translates into text depends on its data type.
13441 IT describes the display environment in which we display, as usual.
13443 DEPTH is the depth in recursion. It is used to prevent
13444 infinite recursion here.
13446 FIELD_WIDTH is the number of characters the display of ELT should
13447 occupy in the mode line, and PRECISION is the maximum number of
13448 characters to display from ELT's representation. See
13449 display_string for details. *
13451 Returns the hpos of the end of the text generated by ELT. */
13454 display_mode_element (it
, depth
, field_width
, precision
, elt
)
13457 int field_width
, precision
;
13460 int n
= 0, field
, prec
;
13468 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13472 /* A string: output it and check for %-constructs within it. */
13474 unsigned char *this = XSTRING (elt
)->data
;
13475 unsigned char *lisp_string
= this;
13477 while ((precision
<= 0 || n
< precision
)
13479 && (frame_title_ptr
13480 || it
->current_x
< it
->last_visible_x
))
13482 unsigned char *last
= this;
13484 /* Advance to end of string or next format specifier. */
13485 while ((c
= *this++) != '\0' && c
!= '%')
13488 if (this - 1 != last
)
13490 /* Output to end of string or up to '%'. Field width
13491 is length of string. Don't output more than
13492 PRECISION allows us. */
13495 prec
= chars_in_text (last
, this - last
);
13496 if (precision
> 0 && prec
> precision
- n
)
13497 prec
= precision
- n
;
13499 if (frame_title_ptr
)
13500 n
+= store_frame_title (last
, 0, prec
);
13503 int bytepos
= last
- lisp_string
;
13504 int charpos
= string_byte_to_char (elt
, bytepos
);
13505 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
13507 STRING_MULTIBYTE (elt
));
13510 else /* c == '%' */
13512 unsigned char *percent_position
= this;
13514 /* Get the specified minimum width. Zero means
13517 while ((c
= *this++) >= '0' && c
<= '9')
13518 field
= field
* 10 + c
- '0';
13520 /* Don't pad beyond the total padding allowed. */
13521 if (field_width
- n
> 0 && field
> field_width
- n
)
13522 field
= field_width
- n
;
13524 /* Note that either PRECISION <= 0 or N < PRECISION. */
13525 prec
= precision
- n
;
13528 n
+= display_mode_element (it
, depth
, field
, prec
,
13529 Vglobal_mode_string
);
13533 unsigned char *spec
13534 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
13536 if (frame_title_ptr
)
13537 n
+= store_frame_title (spec
, field
, prec
);
13540 int nglyphs_before
, bytepos
, charpos
, nwritten
;
13542 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13543 bytepos
= percent_position
- XSTRING (elt
)->data
;
13544 charpos
= (multibyte
13545 ? string_byte_to_char (elt
, bytepos
)
13547 nwritten
= display_string (spec
, Qnil
, elt
,
13552 /* Assign to the glyphs written above the
13553 string where the `%x' came from, position
13557 struct glyph
*glyph
13558 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13562 for (i
= 0; i
< nwritten
; ++i
)
13564 glyph
[i
].object
= elt
;
13565 glyph
[i
].charpos
= charpos
;
13578 /* A symbol: process the value of the symbol recursively
13579 as if it appeared here directly. Avoid error if symbol void.
13580 Special case: if value of symbol is a string, output the string
13583 register Lisp_Object tem
;
13584 tem
= Fboundp (elt
);
13587 tem
= Fsymbol_value (elt
);
13588 /* If value is a string, output that string literally:
13589 don't check for % within it. */
13592 prec
= precision
- n
;
13593 if (frame_title_ptr
)
13594 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
13596 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
13597 0, prec
, 0, STRING_MULTIBYTE (tem
));
13599 else if (!EQ (tem
, elt
))
13601 /* Give up right away for nil or t. */
13611 register Lisp_Object car
, tem
;
13613 /* A cons cell: three distinct cases.
13614 If first element is a string or a cons, process all the elements
13615 and effectively concatenate them.
13616 If first element is a negative number, truncate displaying cdr to
13617 at most that many characters. If positive, pad (with spaces)
13618 to at least that many characters.
13619 If first element is a symbol, process the cadr or caddr recursively
13620 according to whether the symbol's value is non-nil or nil. */
13622 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
13624 /* An element of the form (:eval FORM) means evaluate FORM
13625 and use the result as mode line elements. */
13626 struct gcpro gcpro1
;
13629 spec
= safe_eval (XCAR (XCDR (elt
)));
13631 n
+= display_mode_element (it
, depth
, field_width
- n
,
13632 precision
- n
, spec
);
13635 else if (SYMBOLP (car
))
13637 tem
= Fboundp (car
);
13641 /* elt is now the cdr, and we know it is a cons cell.
13642 Use its car if CAR has a non-nil value. */
13645 tem
= Fsymbol_value (car
);
13652 /* Symbol's value is nil (or symbol is unbound)
13653 Get the cddr of the original list
13654 and if possible find the caddr and use that. */
13658 else if (!CONSP (elt
))
13663 else if (INTEGERP (car
))
13665 register int lim
= XINT (car
);
13669 /* Negative int means reduce maximum width. */
13670 if (precision
<= 0)
13673 precision
= min (precision
, -lim
);
13677 /* Padding specified. Don't let it be more than
13678 current maximum. */
13680 lim
= min (precision
, lim
);
13682 /* If that's more padding than already wanted, queue it.
13683 But don't reduce padding already specified even if
13684 that is beyond the current truncation point. */
13685 field_width
= max (lim
, field_width
);
13689 else if (STRINGP (car
) || CONSP (car
))
13691 register int limit
= 50;
13692 /* Limit is to protect against circular lists. */
13695 && (precision
<= 0 || n
< precision
))
13697 n
+= display_mode_element (it
, depth
, field_width
- n
,
13698 precision
- n
, XCAR (elt
));
13707 if (frame_title_ptr
)
13708 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13710 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13711 precision
- n
, 0, 0);
13715 /* Pad to FIELD_WIDTH. */
13716 if (field_width
> 0 && n
< field_width
)
13718 if (frame_title_ptr
)
13719 n
+= store_frame_title ("", field_width
- n
, 0);
13721 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13729 /* Write a null-terminated, right justified decimal representation of
13730 the positive integer D to BUF using a minimal field width WIDTH. */
13733 pint2str (buf
, width
, d
)
13734 register char *buf
;
13735 register int width
;
13738 register char *p
= buf
;
13746 *p
++ = d
% 10 + '0';
13751 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13762 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13763 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13764 type of CODING_SYSTEM. Return updated pointer into BUF. */
13766 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13769 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13770 Lisp_Object coding_system
;
13771 register char *buf
;
13775 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13776 unsigned char *eol_str
;
13778 /* The EOL conversion we are using. */
13779 Lisp_Object eoltype
;
13781 val
= Fget (coding_system
, Qcoding_system
);
13784 if (!VECTORP (val
)) /* Not yet decided. */
13789 eoltype
= eol_mnemonic_undecided
;
13790 /* Don't mention EOL conversion if it isn't decided. */
13794 Lisp_Object eolvalue
;
13796 eolvalue
= Fget (coding_system
, Qeol_type
);
13799 *buf
++ = XFASTINT (AREF (val
, 1));
13803 /* The EOL conversion that is normal on this system. */
13805 if (NILP (eolvalue
)) /* Not yet decided. */
13806 eoltype
= eol_mnemonic_undecided
;
13807 else if (VECTORP (eolvalue
)) /* Not yet decided. */
13808 eoltype
= eol_mnemonic_undecided
;
13809 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
13810 eoltype
= (XFASTINT (eolvalue
) == 0
13811 ? eol_mnemonic_unix
13812 : (XFASTINT (eolvalue
) == 1
13813 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
13819 /* Mention the EOL conversion if it is not the usual one. */
13820 if (STRINGP (eoltype
))
13822 eol_str
= XSTRING (eoltype
)->data
;
13823 eol_str_len
= XSTRING (eoltype
)->size
;
13825 else if (INTEGERP (eoltype
)
13826 && CHAR_VALID_P (XINT (eoltype
), 0))
13828 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
13829 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
13833 eol_str
= invalid_eol_type
;
13834 eol_str_len
= sizeof (invalid_eol_type
) - 1;
13836 bcopy (eol_str
, buf
, eol_str_len
);
13837 buf
+= eol_str_len
;
13843 /* Return a string for the output of a mode line %-spec for window W,
13844 generated by character C. PRECISION >= 0 means don't return a
13845 string longer than that value. FIELD_WIDTH > 0 means pad the
13846 string returned with spaces to that value. Return 1 in *MULTIBYTE
13847 if the result is multibyte text. */
13849 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
13852 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
13855 int field_width
, precision
;
13859 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13860 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
13861 struct buffer
*b
= XBUFFER (w
->buffer
);
13869 if (!NILP (b
->read_only
))
13871 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13876 /* This differs from %* only for a modified read-only buffer. */
13877 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13879 if (!NILP (b
->read_only
))
13884 /* This differs from %* in ignoring read-only-ness. */
13885 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13897 if (command_loop_level
> 5)
13899 p
= decode_mode_spec_buf
;
13900 for (i
= 0; i
< command_loop_level
; i
++)
13903 return decode_mode_spec_buf
;
13911 if (command_loop_level
> 5)
13913 p
= decode_mode_spec_buf
;
13914 for (i
= 0; i
< command_loop_level
; i
++)
13917 return decode_mode_spec_buf
;
13924 /* Let lots_of_dashes be a string of infinite length. */
13925 if (field_width
<= 0
13926 || field_width
> sizeof (lots_of_dashes
))
13928 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
13929 decode_mode_spec_buf
[i
] = '-';
13930 decode_mode_spec_buf
[i
] = '\0';
13931 return decode_mode_spec_buf
;
13934 return lots_of_dashes
;
13943 int col
= current_column ();
13944 w
->column_number_displayed
= make_number (col
);
13945 pint2str (decode_mode_spec_buf
, field_width
, col
);
13946 return decode_mode_spec_buf
;
13950 /* %F displays the frame name. */
13951 if (!NILP (f
->title
))
13952 return (char *) XSTRING (f
->title
)->data
;
13953 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
13954 return (char *) XSTRING (f
->name
)->data
;
13963 int startpos
= XMARKER (w
->start
)->charpos
;
13964 int startpos_byte
= marker_byte_position (w
->start
);
13965 int line
, linepos
, linepos_byte
, topline
;
13967 int height
= XFASTINT (w
->height
);
13969 /* If we decided that this buffer isn't suitable for line numbers,
13970 don't forget that too fast. */
13971 if (EQ (w
->base_line_pos
, w
->buffer
))
13973 /* But do forget it, if the window shows a different buffer now. */
13974 else if (BUFFERP (w
->base_line_pos
))
13975 w
->base_line_pos
= Qnil
;
13977 /* If the buffer is very big, don't waste time. */
13978 if (INTEGERP (Vline_number_display_limit
)
13979 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
13981 w
->base_line_pos
= Qnil
;
13982 w
->base_line_number
= Qnil
;
13986 if (!NILP (w
->base_line_number
)
13987 && !NILP (w
->base_line_pos
)
13988 && XFASTINT (w
->base_line_pos
) <= startpos
)
13990 line
= XFASTINT (w
->base_line_number
);
13991 linepos
= XFASTINT (w
->base_line_pos
);
13992 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
13997 linepos
= BUF_BEGV (b
);
13998 linepos_byte
= BUF_BEGV_BYTE (b
);
14001 /* Count lines from base line to window start position. */
14002 nlines
= display_count_lines (linepos
, linepos_byte
,
14006 topline
= nlines
+ line
;
14008 /* Determine a new base line, if the old one is too close
14009 or too far away, or if we did not have one.
14010 "Too close" means it's plausible a scroll-down would
14011 go back past it. */
14012 if (startpos
== BUF_BEGV (b
))
14014 w
->base_line_number
= make_number (topline
);
14015 w
->base_line_pos
= make_number (BUF_BEGV (b
));
14017 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
14018 || linepos
== BUF_BEGV (b
))
14020 int limit
= BUF_BEGV (b
);
14021 int limit_byte
= BUF_BEGV_BYTE (b
);
14023 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
14025 if (startpos
- distance
> limit
)
14027 limit
= startpos
- distance
;
14028 limit_byte
= CHAR_TO_BYTE (limit
);
14031 nlines
= display_count_lines (startpos
, startpos_byte
,
14033 - (height
* 2 + 30),
14035 /* If we couldn't find the lines we wanted within
14036 line_number_display_limit_width chars per line,
14037 give up on line numbers for this window. */
14038 if (position
== limit_byte
&& limit
== startpos
- distance
)
14040 w
->base_line_pos
= w
->buffer
;
14041 w
->base_line_number
= Qnil
;
14045 w
->base_line_number
= make_number (topline
- nlines
);
14046 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
14049 /* Now count lines from the start pos to point. */
14050 nlines
= display_count_lines (startpos
, startpos_byte
,
14051 PT_BYTE
, PT
, &junk
);
14053 /* Record that we did display the line number. */
14054 line_number_displayed
= 1;
14056 /* Make the string to show. */
14057 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
14058 return decode_mode_spec_buf
;
14061 char* p
= decode_mode_spec_buf
;
14062 int pad
= field_width
- 2;
14068 return decode_mode_spec_buf
;
14074 obj
= b
->mode_name
;
14078 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
14084 int pos
= marker_position (w
->start
);
14085 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14087 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
14089 if (pos
<= BUF_BEGV (b
))
14094 else if (pos
<= BUF_BEGV (b
))
14098 if (total
> 1000000)
14099 /* Do it differently for a large value, to avoid overflow. */
14100 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14102 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14103 /* We can't normally display a 3-digit number,
14104 so get us a 2-digit number that is close. */
14107 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14108 return decode_mode_spec_buf
;
14112 /* Display percentage of size above the bottom of the screen. */
14115 int toppos
= marker_position (w
->start
);
14116 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14117 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14119 if (botpos
>= BUF_ZV (b
))
14121 if (toppos
<= BUF_BEGV (b
))
14128 if (total
> 1000000)
14129 /* Do it differently for a large value, to avoid overflow. */
14130 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14132 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14133 /* We can't normally display a 3-digit number,
14134 so get us a 2-digit number that is close. */
14137 if (toppos
<= BUF_BEGV (b
))
14138 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14140 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14141 return decode_mode_spec_buf
;
14146 /* status of process */
14147 obj
= Fget_buffer_process (w
->buffer
);
14149 return "no process";
14150 #ifdef subprocesses
14151 obj
= Fsymbol_name (Fprocess_status (obj
));
14155 case 't': /* indicate TEXT or BINARY */
14156 #ifdef MODE_LINE_BINARY_TEXT
14157 return MODE_LINE_BINARY_TEXT (b
);
14163 /* coding-system (not including end-of-line format) */
14165 /* coding-system (including end-of-line type) */
14167 int eol_flag
= (c
== 'Z');
14168 char *p
= decode_mode_spec_buf
;
14170 if (! FRAME_WINDOW_P (f
))
14172 /* No need to mention EOL here--the terminal never needs
14173 to do EOL conversion. */
14174 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14175 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14177 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14180 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14181 #ifdef subprocesses
14182 obj
= Fget_buffer_process (Fcurrent_buffer ());
14183 if (PROCESSP (obj
))
14185 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14187 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14190 #endif /* subprocesses */
14193 return decode_mode_spec_buf
;
14199 *multibyte
= STRING_MULTIBYTE (obj
);
14200 return (char *) XSTRING (obj
)->data
;
14207 /* Count up to COUNT lines starting from START / START_BYTE.
14208 But don't go beyond LIMIT_BYTE.
14209 Return the number of lines thus found (always nonnegative).
14211 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14214 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14215 int start
, start_byte
, limit_byte
, count
;
14218 register unsigned char *cursor
;
14219 unsigned char *base
;
14221 register int ceiling
;
14222 register unsigned char *ceiling_addr
;
14223 int orig_count
= count
;
14225 /* If we are not in selective display mode,
14226 check only for newlines. */
14227 int selective_display
= (!NILP (current_buffer
->selective_display
)
14228 && !INTEGERP (current_buffer
->selective_display
));
14232 while (start_byte
< limit_byte
)
14234 ceiling
= BUFFER_CEILING_OF (start_byte
);
14235 ceiling
= min (limit_byte
- 1, ceiling
);
14236 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14237 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14240 if (selective_display
)
14241 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14244 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14247 if (cursor
!= ceiling_addr
)
14251 start_byte
+= cursor
- base
+ 1;
14252 *byte_pos_ptr
= start_byte
;
14256 if (++cursor
== ceiling_addr
)
14262 start_byte
+= cursor
- base
;
14267 while (start_byte
> limit_byte
)
14269 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14270 ceiling
= max (limit_byte
, ceiling
);
14271 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14272 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14275 if (selective_display
)
14276 while (--cursor
!= ceiling_addr
14277 && *cursor
!= '\n' && *cursor
!= 015)
14280 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14283 if (cursor
!= ceiling_addr
)
14287 start_byte
+= cursor
- base
+ 1;
14288 *byte_pos_ptr
= start_byte
;
14289 /* When scanning backwards, we should
14290 not count the newline posterior to which we stop. */
14291 return - orig_count
- 1;
14297 /* Here we add 1 to compensate for the last decrement
14298 of CURSOR, which took it past the valid range. */
14299 start_byte
+= cursor
- base
+ 1;
14303 *byte_pos_ptr
= limit_byte
;
14306 return - orig_count
+ count
;
14307 return orig_count
- count
;
14313 /***********************************************************************
14315 ***********************************************************************/
14317 /* Display a NUL-terminated string, starting with index START.
14319 If STRING is non-null, display that C string. Otherwise, the Lisp
14320 string LISP_STRING is displayed.
14322 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14323 FACE_STRING. Display STRING or LISP_STRING with the face at
14324 FACE_STRING_POS in FACE_STRING:
14326 Display the string in the environment given by IT, but use the
14327 standard display table, temporarily.
14329 FIELD_WIDTH is the minimum number of output glyphs to produce.
14330 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14331 with spaces. If STRING has more characters, more than FIELD_WIDTH
14332 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14334 PRECISION is the maximum number of characters to output from
14335 STRING. PRECISION < 0 means don't truncate the string.
14337 This is roughly equivalent to printf format specifiers:
14339 FIELD_WIDTH PRECISION PRINTF
14340 ----------------------------------------
14346 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14347 display them, and < 0 means obey the current buffer's value of
14348 enable_multibyte_characters.
14350 Value is the number of glyphs produced. */
14353 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14354 start
, it
, field_width
, precision
, max_x
, multibyte
)
14355 unsigned char *string
;
14356 Lisp_Object lisp_string
;
14357 Lisp_Object face_string
;
14358 int face_string_pos
;
14361 int field_width
, precision
, max_x
;
14364 int hpos_at_start
= it
->hpos
;
14365 int saved_face_id
= it
->face_id
;
14366 struct glyph_row
*row
= it
->glyph_row
;
14368 /* Initialize the iterator IT for iteration over STRING beginning
14369 with index START. */
14370 reseat_to_string (it
, string
, lisp_string
, start
,
14371 precision
, field_width
, multibyte
);
14373 /* If displaying STRING, set up the face of the iterator
14374 from LISP_STRING, if that's given. */
14375 if (STRINGP (face_string
))
14381 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
14382 0, it
->region_beg_charpos
,
14383 it
->region_end_charpos
,
14384 &endptr
, it
->base_face_id
, 0);
14385 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14386 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
14389 /* Set max_x to the maximum allowed X position. Don't let it go
14390 beyond the right edge of the window. */
14392 max_x
= it
->last_visible_x
;
14394 max_x
= min (max_x
, it
->last_visible_x
);
14396 /* Skip over display elements that are not visible. because IT->w is
14398 if (it
->current_x
< it
->first_visible_x
)
14399 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
14400 MOVE_TO_POS
| MOVE_TO_X
);
14402 row
->ascent
= it
->max_ascent
;
14403 row
->height
= it
->max_ascent
+ it
->max_descent
;
14404 row
->phys_ascent
= it
->max_phys_ascent
;
14405 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14407 /* This condition is for the case that we are called with current_x
14408 past last_visible_x. */
14409 while (it
->current_x
< max_x
)
14411 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14413 /* Get the next display element. */
14414 if (!get_next_display_element (it
))
14417 /* Produce glyphs. */
14418 x_before
= it
->current_x
;
14419 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14420 PRODUCE_GLYPHS (it
);
14422 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14425 while (i
< nglyphs
)
14427 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14429 if (!it
->truncate_lines_p
14430 && x
+ glyph
->pixel_width
> max_x
)
14432 /* End of continued line or max_x reached. */
14433 if (CHAR_GLYPH_PADDING_P (*glyph
))
14435 /* A wide character is unbreakable. */
14436 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14437 it
->current_x
= x_before
;
14441 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14446 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
14448 /* Glyph is at least partially visible. */
14450 if (x
< it
->first_visible_x
)
14451 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14455 /* Glyph is off the left margin of the display area.
14456 Should not happen. */
14460 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14461 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14462 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14463 row
->phys_height
= max (row
->phys_height
,
14464 it
->max_phys_ascent
+ it
->max_phys_descent
);
14465 x
+= glyph
->pixel_width
;
14469 /* Stop if max_x reached. */
14473 /* Stop at line ends. */
14474 if (ITERATOR_AT_END_OF_LINE_P (it
))
14476 it
->continuation_lines_width
= 0;
14480 set_iterator_to_next (it
, 1);
14482 /* Stop if truncating at the right edge. */
14483 if (it
->truncate_lines_p
14484 && it
->current_x
>= it
->last_visible_x
)
14486 /* Add truncation mark, but don't do it if the line is
14487 truncated at a padding space. */
14488 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14490 if (!FRAME_WINDOW_P (it
->f
))
14494 if (it
->current_x
> it
->last_visible_x
)
14496 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14497 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14499 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14501 row
->used
[TEXT_AREA
] = i
;
14502 produce_special_glyphs (it
, IT_TRUNCATION
);
14505 produce_special_glyphs (it
, IT_TRUNCATION
);
14507 it
->glyph_row
->truncated_on_right_p
= 1;
14513 /* Maybe insert a truncation at the left. */
14514 if (it
->first_visible_x
14515 && IT_CHARPOS (*it
) > 0)
14517 if (!FRAME_WINDOW_P (it
->f
))
14518 insert_left_trunc_glyphs (it
);
14519 it
->glyph_row
->truncated_on_left_p
= 1;
14522 it
->face_id
= saved_face_id
;
14524 /* Value is number of columns displayed. */
14525 return it
->hpos
- hpos_at_start
;
14530 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
14531 appears as an element of LIST or as the car of an element of LIST.
14532 If PROPVAL is a list, compare each element against LIST in that
14533 way, and return 1/2 if any element of PROPVAL is found in LIST.
14534 Otherwise return 0. This function cannot quit.
14535 The return value is 2 if the text is invisible but with an ellipsis
14536 and 1 if it's invisible and without an ellipsis. */
14539 invisible_p (propval
, list
)
14540 register Lisp_Object propval
;
14543 register Lisp_Object tail
, proptail
;
14545 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14547 register Lisp_Object tem
;
14549 if (EQ (propval
, tem
))
14551 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14552 return NILP (XCDR (tem
)) ? 1 : 2;
14555 if (CONSP (propval
))
14557 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14559 Lisp_Object propelt
;
14560 propelt
= XCAR (proptail
);
14561 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14563 register Lisp_Object tem
;
14565 if (EQ (propelt
, tem
))
14567 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14568 return NILP (XCDR (tem
)) ? 1 : 2;
14577 /***********************************************************************
14579 ***********************************************************************/
14584 Vwith_echo_area_save_vector
= Qnil
;
14585 staticpro (&Vwith_echo_area_save_vector
);
14587 Vmessage_stack
= Qnil
;
14588 staticpro (&Vmessage_stack
);
14590 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14591 staticpro (&Qinhibit_redisplay
);
14594 defsubr (&Sdump_glyph_matrix
);
14595 defsubr (&Sdump_glyph_row
);
14596 defsubr (&Sdump_tool_bar_row
);
14597 defsubr (&Strace_redisplay
);
14598 defsubr (&Strace_to_stderr
);
14600 #ifdef HAVE_WINDOW_SYSTEM
14601 defsubr (&Stool_bar_lines_needed
);
14604 staticpro (&Qmenu_bar_update_hook
);
14605 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14607 staticpro (&Qoverriding_terminal_local_map
);
14608 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14610 staticpro (&Qoverriding_local_map
);
14611 Qoverriding_local_map
= intern ("overriding-local-map");
14613 staticpro (&Qwindow_scroll_functions
);
14614 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14616 staticpro (&Qredisplay_end_trigger_functions
);
14617 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14619 staticpro (&Qinhibit_point_motion_hooks
);
14620 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14622 QCdata
= intern (":data");
14623 staticpro (&QCdata
);
14624 Qdisplay
= intern ("display");
14625 staticpro (&Qdisplay
);
14626 Qspace_width
= intern ("space-width");
14627 staticpro (&Qspace_width
);
14628 Qraise
= intern ("raise");
14629 staticpro (&Qraise
);
14630 Qspace
= intern ("space");
14631 staticpro (&Qspace
);
14632 Qmargin
= intern ("margin");
14633 staticpro (&Qmargin
);
14634 Qleft_margin
= intern ("left-margin");
14635 staticpro (&Qleft_margin
);
14636 Qright_margin
= intern ("right-margin");
14637 staticpro (&Qright_margin
);
14638 Qalign_to
= intern ("align-to");
14639 staticpro (&Qalign_to
);
14640 QCalign_to
= intern (":align-to");
14641 staticpro (&QCalign_to
);
14642 Qrelative_width
= intern ("relative-width");
14643 staticpro (&Qrelative_width
);
14644 QCrelative_width
= intern (":relative-width");
14645 staticpro (&QCrelative_width
);
14646 QCrelative_height
= intern (":relative-height");
14647 staticpro (&QCrelative_height
);
14648 QCeval
= intern (":eval");
14649 staticpro (&QCeval
);
14650 Qwhen
= intern ("when");
14651 staticpro (&Qwhen
);
14652 QCfile
= intern (":file");
14653 staticpro (&QCfile
);
14654 Qfontified
= intern ("fontified");
14655 staticpro (&Qfontified
);
14656 Qfontification_functions
= intern ("fontification-functions");
14657 staticpro (&Qfontification_functions
);
14658 Qtrailing_whitespace
= intern ("trailing-whitespace");
14659 staticpro (&Qtrailing_whitespace
);
14660 Qimage
= intern ("image");
14661 staticpro (&Qimage
);
14662 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14663 staticpro (&Qmessage_truncate_lines
);
14664 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
14665 staticpro (&Qcursor_in_non_selected_windows
);
14666 Qgrow_only
= intern ("grow-only");
14667 staticpro (&Qgrow_only
);
14668 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14669 staticpro (&Qinhibit_menubar_update
);
14670 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
14671 staticpro (&Qinhibit_eval_during_redisplay
);
14672 Qposition
= intern ("position");
14673 staticpro (&Qposition
);
14674 Qbuffer_position
= intern ("buffer-position");
14675 staticpro (&Qbuffer_position
);
14676 Qobject
= intern ("object");
14677 staticpro (&Qobject
);
14679 last_arrow_position
= Qnil
;
14680 last_arrow_string
= Qnil
;
14681 staticpro (&last_arrow_position
);
14682 staticpro (&last_arrow_string
);
14684 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14685 staticpro (&echo_buffer
[0]);
14686 staticpro (&echo_buffer
[1]);
14688 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14689 staticpro (&echo_area_buffer
[0]);
14690 staticpro (&echo_area_buffer
[1]);
14692 Vmessages_buffer_name
= build_string ("*Messages*");
14693 staticpro (&Vmessages_buffer_name
);
14695 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14696 doc
: /* Non-nil means highlight trailing whitespace.
14697 The face used for trailing whitespace is `trailing-whitespace'. */);
14698 Vshow_trailing_whitespace
= Qnil
;
14700 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14701 doc
: /* Non-nil means don't actually do any redisplay.
14702 This is used for internal purposes. */);
14703 Vinhibit_redisplay
= Qnil
;
14705 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14706 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
14707 Vglobal_mode_string
= Qnil
;
14709 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14710 doc
: /* Marker for where to display an arrow on top of the buffer text.
14711 This must be the beginning of a line in order to work.
14712 See also `overlay-arrow-string'. */);
14713 Voverlay_arrow_position
= Qnil
;
14715 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14716 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
14717 Voverlay_arrow_string
= Qnil
;
14719 DEFVAR_INT ("scroll-step", &scroll_step
,
14720 doc
: /* *The number of lines to try scrolling a window by when point moves out.
14721 If that fails to bring point back on frame, point is centered instead.
14722 If this is zero, point is always centered after it moves off frame.
14723 If you want scrolling to always be a line at a time, you should set
14724 `scroll-conservatively' to a large value rather than set this to 1. */);
14726 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14727 doc
: /* *Scroll up to this many lines, to bring point back on screen.
14728 A value of zero means to scroll the text to center point vertically
14729 in the window. */);
14730 scroll_conservatively
= 0;
14732 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14733 doc
: /* *Number of lines of margin at the top and bottom of a window.
14734 Recenter the window whenever point gets within this many lines
14735 of the top or bottom of the window. */);
14739 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
14742 DEFVAR_BOOL ("truncate-partial-width-windows",
14743 &truncate_partial_width_windows
,
14744 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
14745 truncate_partial_width_windows
= 1;
14747 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14748 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
14749 Any other value means to use the appropriate face, `mode-line',
14750 `header-line', or `menu' respectively.
14752 This variable is deprecated; please change the above faces instead. */);
14753 mode_line_inverse_video
= 1;
14755 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14756 doc
: /* *Maximum buffer size for which line number should be displayed.
14757 If the buffer is bigger than this, the line number does not appear
14758 in the mode line. A value of nil means no limit. */);
14759 Vline_number_display_limit
= Qnil
;
14761 DEFVAR_INT ("line-number-display-limit-width",
14762 &line_number_display_limit_width
,
14763 doc
: /* *Maximum line width (in characters) for line number display.
14764 If the average length of the lines near point is bigger than this, then the
14765 line number may be omitted from the mode line. */);
14766 line_number_display_limit_width
= 200;
14768 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14769 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
14770 highlight_nonselected_windows
= 0;
14772 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14773 doc
: /* Non-nil if more than one frame is visible on this display.
14774 Minibuffer-only frames don't count, but iconified frames do.
14775 This variable is not guaranteed to be accurate except while processing
14776 `frame-title-format' and `icon-title-format'. */);
14778 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14779 doc
: /* Template for displaying the title bar of visible frames.
14780 \(Assuming the window manager supports this feature.)
14781 This variable has the same structure as `mode-line-format' (which see),
14782 and is used only on frames for which no explicit name has been set
14783 \(see `modify-frame-parameters'). */);
14784 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
14785 doc
: /* Template for displaying the title bar of an iconified frame.
14786 \(Assuming the window manager supports this feature.)
14787 This variable has the same structure as `mode-line-format' (which see),
14788 and is used only on frames for which no explicit name has been set
14789 \(see `modify-frame-parameters'). */);
14791 = Vframe_title_format
14792 = Fcons (intern ("multiple-frames"),
14793 Fcons (build_string ("%b"),
14794 Fcons (Fcons (empty_string
,
14795 Fcons (intern ("invocation-name"),
14796 Fcons (build_string ("@"),
14797 Fcons (intern ("system-name"),
14801 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
14802 doc
: /* Maximum number of lines to keep in the message log buffer.
14803 If nil, disable message logging. If t, log messages but don't truncate
14804 the buffer when it becomes large. */);
14805 Vmessage_log_max
= make_number (50);
14807 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
14808 doc
: /* Functions called before redisplay, if window sizes have changed.
14809 The value should be a list of functions that take one argument.
14810 Just before redisplay, for each frame, if any of its windows have changed
14811 size since the last redisplay, or have been split or deleted,
14812 all the functions in the list are called, with the frame as argument. */);
14813 Vwindow_size_change_functions
= Qnil
;
14815 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
14816 doc
: /* List of Functions to call before redisplaying a window with scrolling.
14817 Each function is called with two arguments, the window
14818 and its new display-start position. Note that the value of `window-end'
14819 is not valid when these functions are called. */);
14820 Vwindow_scroll_functions
= Qnil
;
14822 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
14823 doc
: /* *Non-nil means automatically resize tool-bars.
14824 This increases a tool-bar's height if not all tool-bar items are visible.
14825 It decreases a tool-bar's height when it would display blank lines
14827 auto_resize_tool_bars_p
= 1;
14829 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
14830 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
14831 auto_raise_tool_bar_buttons_p
= 1;
14833 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
14834 doc
: /* *Margin around tool-bar buttons in pixels.
14835 If an integer, use that for both horizontal and vertical margins.
14836 Otherwise, value should be a pair of integers `(HORZ : VERT)' with
14837 HORZ specifying the horizontal margin, and VERT specifying the
14838 vertical margin. */);
14839 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
14841 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
14842 doc
: /* Relief thickness of tool-bar buttons. */);
14843 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
14845 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
14846 doc
: /* List of functions to call to fontify regions of text.
14847 Each function is called with one argument POS. Functions must
14848 fontify a region starting at POS in the current buffer, and give
14849 fontified regions the property `fontified'. */);
14850 Vfontification_functions
= Qnil
;
14851 Fmake_variable_buffer_local (Qfontification_functions
);
14853 DEFVAR_BOOL ("unibyte-display-via-language-environment",
14854 &unibyte_display_via_language_environment
,
14855 doc
: /* *Non-nil means display unibyte text according to language environment.
14856 Specifically this means that unibyte non-ASCII characters
14857 are displayed by converting them to the equivalent multibyte characters
14858 according to the current language environment. As a result, they are
14859 displayed according to the current fontset. */);
14860 unibyte_display_via_language_environment
= 0;
14862 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
14863 doc
: /* *Maximum height for resizing mini-windows.
14864 If a float, it specifies a fraction of the mini-window frame's height.
14865 If an integer, it specifies a number of lines. */);
14866 Vmax_mini_window_height
= make_float (0.25);
14868 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
14869 doc
: /* *How to resize mini-windows.
14870 A value of nil means don't automatically resize mini-windows.
14871 A value of t means resize them to fit the text displayed in them.
14872 A value of `grow-only', the default, means let mini-windows grow
14873 only, until their display becomes empty, at which point the windows
14874 go back to their normal size. */);
14875 Vresize_mini_windows
= Qgrow_only
;
14877 DEFVAR_BOOL ("cursor-in-non-selected-windows",
14878 &cursor_in_non_selected_windows
,
14879 doc
: /* *Non-nil means display a hollow cursor in non-selected windows.
14880 Nil means don't display a cursor there. */);
14881 cursor_in_non_selected_windows
= 1;
14883 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
14884 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
14885 automatic_hscrolling_p
= 1;
14887 DEFVAR_LISP ("image-types", &Vimage_types
,
14888 doc
: /* List of supported image types.
14889 Each element of the list is a symbol for a supported image type. */);
14890 Vimage_types
= Qnil
;
14892 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
14893 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
14894 Bind this around calls to `message' to let it take effect. */);
14895 message_truncate_lines
= 0;
14897 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
14898 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
14899 Can be used to update submenus whose contents should vary. */);
14900 Vmenu_bar_update_hook
= Qnil
;
14902 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
14903 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
14904 inhibit_menubar_update
= 0;
14906 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
14907 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
14908 inhibit_eval_during_redisplay
= 0;
14911 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
14912 doc
: /* Inhibit try_window_id display optimization. */);
14913 inhibit_try_window_id
= 0;
14915 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
14916 doc
: /* Inhibit try_window_reusing display optimization. */);
14917 inhibit_try_window_reusing
= 0;
14919 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
14920 doc
: /* Inhibit try_cursor_movement display optimization. */);
14921 inhibit_try_cursor_movement
= 0;
14922 #endif /* GLYPH_DEBUG */
14926 /* Initialize this module when Emacs starts. */
14931 Lisp_Object root_window
;
14932 struct window
*mini_w
;
14934 current_header_line_height
= current_mode_line_height
= -1;
14936 CHARPOS (this_line_start_pos
) = 0;
14938 mini_w
= XWINDOW (minibuf_window
);
14939 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
14941 if (!noninteractive
)
14943 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
14946 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
14947 set_window_height (root_window
,
14948 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
14950 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
14951 set_window_height (minibuf_window
, 1, 0);
14953 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
14954 mini_w
->width
= make_number (FRAME_WIDTH (f
));
14956 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
14957 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
14958 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
14960 /* The default ellipsis glyphs `...'. */
14961 for (i
= 0; i
< 3; ++i
)
14962 default_invis_vector
[i
] = make_number ('.');
14965 #ifdef HAVE_WINDOW_SYSTEM
14967 /* Allocate the buffer for frame titles. */
14969 frame_title_buf
= (char *) xmalloc (size
);
14970 frame_title_buf_end
= frame_title_buf
+ size
;
14971 frame_title_ptr
= NULL
;
14973 #endif /* HAVE_WINDOW_SYSTEM */
14975 help_echo_showing_p
= 0;