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
;
7939 /* Get the text property `menu-item' at pos. The value of that
7940 property is the start index of this item's properties in
7941 F->tool_bar_items. */
7942 prop
= Fget_text_property (make_number (glyph
->charpos
),
7943 Qmenu_item
, f
->current_tool_bar_string
);
7944 if (INTEGERP (prop
))
7946 *prop_idx
= XINT (prop
);
7955 #endif /* HAVE_WINDOW_SYSTEM */
7959 /************************************************************************
7960 Horizontal scrolling
7961 ************************************************************************/
7963 static int hscroll_window_tree
P_ ((Lisp_Object
));
7964 static int hscroll_windows
P_ ((Lisp_Object
));
7966 /* For all leaf windows in the window tree rooted at WINDOW, set their
7967 hscroll value so that PT is (i) visible in the window, and (ii) so
7968 that it is not within a certain margin at the window's left and
7969 right border. Value is non-zero if any window's hscroll has been
7973 hscroll_window_tree (window
)
7976 int hscrolled_p
= 0;
7978 while (WINDOWP (window
))
7980 struct window
*w
= XWINDOW (window
);
7982 if (WINDOWP (w
->hchild
))
7983 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7984 else if (WINDOWP (w
->vchild
))
7985 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7986 else if (w
->cursor
.vpos
>= 0)
7988 int hscroll_margin
, text_area_x
, text_area_y
;
7989 int text_area_width
, text_area_height
;
7990 struct glyph_row
*current_cursor_row
7991 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7992 struct glyph_row
*desired_cursor_row
7993 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7994 struct glyph_row
*cursor_row
7995 = (desired_cursor_row
->enabled_p
7996 ? desired_cursor_row
7997 : current_cursor_row
);
7999 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8000 &text_area_width
, &text_area_height
);
8002 /* Scroll when cursor is inside this scroll margin. */
8003 /* Shouldn't we export this `5' for customization ? -stef */
8004 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
8006 if ((XFASTINT (w
->hscroll
)
8007 && w
->cursor
.x
< hscroll_margin
)
8008 || (cursor_row
->enabled_p
8009 && cursor_row
->truncated_on_right_p
8010 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
8014 struct buffer
*saved_current_buffer
;
8017 /* Find point in a display of infinite width. */
8018 saved_current_buffer
= current_buffer
;
8019 current_buffer
= XBUFFER (w
->buffer
);
8021 if (w
== XWINDOW (selected_window
))
8022 pt
= BUF_PT (current_buffer
);
8025 pt
= marker_position (w
->pointm
);
8026 pt
= max (BEGV
, pt
);
8030 /* Move iterator to pt starting at cursor_row->start in
8031 a line with infinite width. */
8032 init_to_row_start (&it
, w
, cursor_row
);
8033 it
.last_visible_x
= INFINITY
;
8034 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8035 current_buffer
= saved_current_buffer
;
8037 /* Center cursor in window. */
8038 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
8039 / CANON_X_UNIT (it
.f
));
8040 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8042 /* Don't call Fset_window_hscroll if value hasn't
8043 changed because it will prevent redisplay
8045 if (XFASTINT (w
->hscroll
) != hscroll
)
8047 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8048 w
->hscroll
= make_number (hscroll
);
8057 /* Value is non-zero if hscroll of any leaf window has been changed. */
8062 /* Set hscroll so that cursor is visible and not inside horizontal
8063 scroll margins for all windows in the tree rooted at WINDOW. See
8064 also hscroll_window_tree above. Value is non-zero if any window's
8065 hscroll has been changed. If it has, desired matrices on the frame
8066 of WINDOW are cleared. */
8069 hscroll_windows (window
)
8074 if (automatic_hscrolling_p
)
8076 hscrolled_p
= hscroll_window_tree (window
);
8078 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8087 /************************************************************************
8089 ************************************************************************/
8091 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8092 to a non-zero value. This is sometimes handy to have in a debugger
8097 /* First and last unchanged row for try_window_id. */
8099 int debug_first_unchanged_at_end_vpos
;
8100 int debug_last_unchanged_at_beg_vpos
;
8102 /* Delta vpos and y. */
8104 int debug_dvpos
, debug_dy
;
8106 /* Delta in characters and bytes for try_window_id. */
8108 int debug_delta
, debug_delta_bytes
;
8110 /* Values of window_end_pos and window_end_vpos at the end of
8113 int debug_end_pos
, debug_end_vpos
;
8115 /* Append a string to W->desired_matrix->method. FMT is a printf
8116 format string. A1...A9 are a supplement for a variable-length
8117 argument list. If trace_redisplay_p is non-zero also printf the
8118 resulting string to stderr. */
8121 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8124 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8127 char *method
= w
->desired_matrix
->method
;
8128 int len
= strlen (method
);
8129 int size
= sizeof w
->desired_matrix
->method
;
8130 int remaining
= size
- len
- 1;
8132 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8133 if (len
&& remaining
)
8139 strncpy (method
+ len
, buffer
, remaining
);
8141 if (trace_redisplay_p
)
8142 fprintf (stderr
, "%p (%s): %s\n",
8144 ((BUFFERP (w
->buffer
)
8145 && STRINGP (XBUFFER (w
->buffer
)->name
))
8146 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
8151 #endif /* GLYPH_DEBUG */
8154 /* This counter is used to clear the face cache every once in a while
8155 in redisplay_internal. It is incremented for each redisplay.
8156 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8159 #define CLEAR_FACE_CACHE_COUNT 10000
8160 static int clear_face_cache_count
;
8162 /* Record the previous terminal frame we displayed. */
8164 static struct frame
*previous_terminal_frame
;
8166 /* Non-zero while redisplay_internal is in progress. */
8171 /* Value is non-zero if all changes in window W, which displays
8172 current_buffer, are in the text between START and END. START is a
8173 buffer position, END is given as a distance from Z. Used in
8174 redisplay_internal for display optimization. */
8177 text_outside_line_unchanged_p (w
, start
, end
)
8181 int unchanged_p
= 1;
8183 /* If text or overlays have changed, see where. */
8184 if (XFASTINT (w
->last_modified
) < MODIFF
8185 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8187 /* Gap in the line? */
8188 if (GPT
< start
|| Z
- GPT
< end
)
8191 /* Changes start in front of the line, or end after it? */
8193 && (BEG_UNCHANGED
< start
- 1
8194 || END_UNCHANGED
< end
))
8197 /* If selective display, can't optimize if changes start at the
8198 beginning of the line. */
8200 && INTEGERP (current_buffer
->selective_display
)
8201 && XINT (current_buffer
->selective_display
) > 0
8202 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8205 /* If there are overlays at the start or end of the line, these
8206 may have overlay strings with newlines in them. A change at
8207 START, for instance, may actually concern the display of such
8208 overlay strings as well, and they are displayed on different
8209 lines. So, quickly rule out this case. (For the future, it
8210 might be desirable to implement something more telling than
8211 just BEG/END_UNCHANGED.) */
8214 if (BEG
+ BEG_UNCHANGED
== start
8215 && overlay_touches_p (start
))
8217 if (END_UNCHANGED
== end
8218 && overlay_touches_p (Z
- end
))
8227 /* Do a frame update, taking possible shortcuts into account. This is
8228 the main external entry point for redisplay.
8230 If the last redisplay displayed an echo area message and that message
8231 is no longer requested, we clear the echo area or bring back the
8232 mini-buffer if that is in use. */
8237 redisplay_internal (0);
8241 /* Return 1 if point moved out of or into a composition. Otherwise
8242 return 0. PREV_BUF and PREV_PT are the last point buffer and
8243 position. BUF and PT are the current point buffer and position. */
8246 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8247 struct buffer
*prev_buf
, *buf
;
8254 XSETBUFFER (buffer
, buf
);
8255 /* Check a composition at the last point if point moved within the
8257 if (prev_buf
== buf
)
8260 /* Point didn't move. */
8263 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8264 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8265 && COMPOSITION_VALID_P (start
, end
, prop
)
8266 && start
< prev_pt
&& end
> prev_pt
)
8267 /* The last point was within the composition. Return 1 iff
8268 point moved out of the composition. */
8269 return (pt
<= start
|| pt
>= end
);
8272 /* Check a composition at the current point. */
8273 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8274 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8275 && COMPOSITION_VALID_P (start
, end
, prop
)
8276 && start
< pt
&& end
> pt
);
8280 /* Reconsider the setting of B->clip_changed which is displayed
8284 reconsider_clip_changes (w
, b
)
8288 if (b
->prevent_redisplay_optimizations_p
)
8289 b
->clip_changed
= 1;
8290 else if (b
->clip_changed
8291 && !NILP (w
->window_end_valid
)
8292 && w
->current_matrix
->buffer
== b
8293 && w
->current_matrix
->zv
== BUF_ZV (b
)
8294 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8295 b
->clip_changed
= 0;
8297 /* If display wasn't paused, and W is not a tool bar window, see if
8298 point has been moved into or out of a composition. In that case,
8299 we set b->clip_changed to 1 to force updating the screen. If
8300 b->clip_changed has already been set to 1, we can skip this
8302 if (!b
->clip_changed
8303 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8307 if (w
== XWINDOW (selected_window
))
8308 pt
= BUF_PT (current_buffer
);
8310 pt
= marker_position (w
->pointm
);
8312 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8313 || pt
!= XINT (w
->last_point
))
8314 && check_point_in_composition (w
->current_matrix
->buffer
,
8315 XINT (w
->last_point
),
8316 XBUFFER (w
->buffer
), pt
))
8317 b
->clip_changed
= 1;
8322 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8323 response to any user action; therefore, we should preserve the echo
8324 area. (Actually, our caller does that job.) Perhaps in the future
8325 avoid recentering windows if it is not necessary; currently that
8326 causes some problems. */
8329 redisplay_internal (preserve_echo_area
)
8330 int preserve_echo_area
;
8332 struct window
*w
= XWINDOW (selected_window
);
8333 struct frame
*f
= XFRAME (w
->frame
);
8335 int must_finish
= 0;
8336 struct text_pos tlbufpos
, tlendpos
;
8337 int number_of_visible_frames
;
8339 struct frame
*sf
= SELECTED_FRAME ();
8341 /* Non-zero means redisplay has to consider all windows on all
8342 frames. Zero means, only selected_window is considered. */
8343 int consider_all_windows_p
;
8345 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8347 /* No redisplay if running in batch mode or frame is not yet fully
8348 initialized, or redisplay is explicitly turned off by setting
8349 Vinhibit_redisplay. */
8351 || !NILP (Vinhibit_redisplay
)
8352 || !f
->glyphs_initialized_p
)
8355 /* The flag redisplay_performed_directly_p is set by
8356 direct_output_for_insert when it already did the whole screen
8357 update necessary. */
8358 if (redisplay_performed_directly_p
)
8360 redisplay_performed_directly_p
= 0;
8361 if (!hscroll_windows (selected_window
))
8365 #ifdef USE_X_TOOLKIT
8366 if (popup_activated ())
8370 /* I don't think this happens but let's be paranoid. */
8374 /* Record a function that resets redisplaying_p to its old value
8375 when we leave this function. */
8376 count
= BINDING_STACK_SIZE ();
8377 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8382 reconsider_clip_changes (w
, current_buffer
);
8384 /* If new fonts have been loaded that make a glyph matrix adjustment
8385 necessary, do it. */
8386 if (fonts_changed_p
)
8388 adjust_glyphs (NULL
);
8389 ++windows_or_buffers_changed
;
8390 fonts_changed_p
= 0;
8393 /* If face_change_count is non-zero, init_iterator will free all
8394 realized faces, which includes the faces referenced from current
8395 matrices. So, we can't reuse current matrices in this case. */
8396 if (face_change_count
)
8397 ++windows_or_buffers_changed
;
8399 if (! FRAME_WINDOW_P (sf
)
8400 && previous_terminal_frame
!= sf
)
8402 /* Since frames on an ASCII terminal share the same display
8403 area, displaying a different frame means redisplay the whole
8405 windows_or_buffers_changed
++;
8406 SET_FRAME_GARBAGED (sf
);
8407 XSETFRAME (Vterminal_frame
, sf
);
8409 previous_terminal_frame
= sf
;
8411 /* Set the visible flags for all frames. Do this before checking
8412 for resized or garbaged frames; they want to know if their frames
8413 are visible. See the comment in frame.h for
8414 FRAME_SAMPLE_VISIBILITY. */
8416 Lisp_Object tail
, frame
;
8418 number_of_visible_frames
= 0;
8420 FOR_EACH_FRAME (tail
, frame
)
8422 struct frame
*f
= XFRAME (frame
);
8424 FRAME_SAMPLE_VISIBILITY (f
);
8425 if (FRAME_VISIBLE_P (f
))
8426 ++number_of_visible_frames
;
8427 clear_desired_matrices (f
);
8431 /* Notice any pending interrupt request to change frame size. */
8432 do_pending_window_change (1);
8434 /* Clear frames marked as garbaged. */
8436 clear_garbaged_frames ();
8438 /* Build menubar and tool-bar items. */
8439 prepare_menu_bars ();
8441 if (windows_or_buffers_changed
)
8442 update_mode_lines
++;
8444 /* Detect case that we need to write or remove a star in the mode line. */
8445 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8447 w
->update_mode_line
= Qt
;
8448 if (buffer_shared
> 1)
8449 update_mode_lines
++;
8452 /* If %c is in the mode line, update it if needed. */
8453 if (!NILP (w
->column_number_displayed
)
8454 /* This alternative quickly identifies a common case
8455 where no change is needed. */
8456 && !(PT
== XFASTINT (w
->last_point
)
8457 && XFASTINT (w
->last_modified
) >= MODIFF
8458 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8459 && XFASTINT (w
->column_number_displayed
) != current_column ())
8460 w
->update_mode_line
= Qt
;
8462 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8464 /* The variable buffer_shared is set in redisplay_window and
8465 indicates that we redisplay a buffer in different windows. See
8467 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8469 /* If specs for an arrow have changed, do thorough redisplay
8470 to ensure we remove any arrow that should no longer exist. */
8471 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8472 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8473 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8475 /* Normally the message* functions will have already displayed and
8476 updated the echo area, but the frame may have been trashed, or
8477 the update may have been preempted, so display the echo area
8478 again here. Checking message_cleared_p captures the case that
8479 the echo area should be cleared. */
8480 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8481 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8482 || (message_cleared_p
8483 && minibuf_level
== 0
8484 /* If the mini-window is currently selected, this means the
8485 echo-area doesn't show through. */
8486 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8488 int window_height_changed_p
= echo_area_display (0);
8491 /* If we don't display the current message, don't clear the
8492 message_cleared_p flag, because, if we did, we wouldn't clear
8493 the echo area in the next redisplay which doesn't preserve
8495 if (!display_last_displayed_message_p
)
8496 message_cleared_p
= 0;
8498 if (fonts_changed_p
)
8500 else if (window_height_changed_p
)
8502 consider_all_windows_p
= 1;
8503 ++update_mode_lines
;
8504 ++windows_or_buffers_changed
;
8506 /* If window configuration was changed, frames may have been
8507 marked garbaged. Clear them or we will experience
8508 surprises wrt scrolling. */
8510 clear_garbaged_frames ();
8513 else if (EQ (selected_window
, minibuf_window
)
8514 && (current_buffer
->clip_changed
8515 || XFASTINT (w
->last_modified
) < MODIFF
8516 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8517 && resize_mini_window (w
, 0))
8519 /* Resized active mini-window to fit the size of what it is
8520 showing if its contents might have changed. */
8522 consider_all_windows_p
= 1;
8523 ++windows_or_buffers_changed
;
8524 ++update_mode_lines
;
8526 /* If window configuration was changed, frames may have been
8527 marked garbaged. Clear them or we will experience
8528 surprises wrt scrolling. */
8530 clear_garbaged_frames ();
8534 /* If showing the region, and mark has changed, we must redisplay
8535 the whole window. The assignment to this_line_start_pos prevents
8536 the optimization directly below this if-statement. */
8537 if (((!NILP (Vtransient_mark_mode
)
8538 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8539 != !NILP (w
->region_showing
))
8540 || (!NILP (w
->region_showing
)
8541 && !EQ (w
->region_showing
,
8542 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8543 CHARPOS (this_line_start_pos
) = 0;
8545 /* Optimize the case that only the line containing the cursor in the
8546 selected window has changed. Variables starting with this_ are
8547 set in display_line and record information about the line
8548 containing the cursor. */
8549 tlbufpos
= this_line_start_pos
;
8550 tlendpos
= this_line_end_pos
;
8551 if (!consider_all_windows_p
8552 && CHARPOS (tlbufpos
) > 0
8553 && NILP (w
->update_mode_line
)
8554 && !current_buffer
->clip_changed
8555 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8556 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8557 /* Make sure recorded data applies to current buffer, etc. */
8558 && this_line_buffer
== current_buffer
8559 && current_buffer
== XBUFFER (w
->buffer
)
8560 && NILP (w
->force_start
)
8561 /* Point must be on the line that we have info recorded about. */
8562 && PT
>= CHARPOS (tlbufpos
)
8563 && PT
<= Z
- CHARPOS (tlendpos
)
8564 /* All text outside that line, including its final newline,
8565 must be unchanged */
8566 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8567 CHARPOS (tlendpos
)))
8569 if (CHARPOS (tlbufpos
) > BEGV
8570 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8571 && (CHARPOS (tlbufpos
) == ZV
8572 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8573 /* Former continuation line has disappeared by becoming empty */
8575 else if (XFASTINT (w
->last_modified
) < MODIFF
8576 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8577 || MINI_WINDOW_P (w
))
8579 /* We have to handle the case of continuation around a
8580 wide-column character (See the comment in indent.c around
8583 For instance, in the following case:
8585 -------- Insert --------
8586 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8587 J_I_ ==> J_I_ `^^' are cursors.
8591 As we have to redraw the line above, we should goto cancel. */
8594 int line_height_before
= this_line_pixel_height
;
8596 /* Note that start_display will handle the case that the
8597 line starting at tlbufpos is a continuation lines. */
8598 start_display (&it
, w
, tlbufpos
);
8600 /* Implementation note: It this still necessary? */
8601 if (it
.current_x
!= this_line_start_x
)
8604 TRACE ((stderr
, "trying display optimization 1\n"));
8605 w
->cursor
.vpos
= -1;
8606 overlay_arrow_seen
= 0;
8607 it
.vpos
= this_line_vpos
;
8608 it
.current_y
= this_line_y
;
8609 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8612 /* If line contains point, is not continued,
8613 and ends at same distance from eob as before, we win */
8614 if (w
->cursor
.vpos
>= 0
8615 /* Line is not continued, otherwise this_line_start_pos
8616 would have been set to 0 in display_line. */
8617 && CHARPOS (this_line_start_pos
)
8618 /* Line ends as before. */
8619 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8620 /* Line has same height as before. Otherwise other lines
8621 would have to be shifted up or down. */
8622 && this_line_pixel_height
== line_height_before
)
8624 /* If this is not the window's last line, we must adjust
8625 the charstarts of the lines below. */
8626 if (it
.current_y
< it
.last_visible_y
)
8628 struct glyph_row
*row
8629 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8630 int delta
, delta_bytes
;
8632 if (Z
- CHARPOS (tlendpos
) == ZV
)
8634 /* This line ends at end of (accessible part of)
8635 buffer. There is no newline to count. */
8637 - CHARPOS (tlendpos
)
8638 - MATRIX_ROW_START_CHARPOS (row
));
8639 delta_bytes
= (Z_BYTE
8640 - BYTEPOS (tlendpos
)
8641 - MATRIX_ROW_START_BYTEPOS (row
));
8645 /* This line ends in a newline. Must take
8646 account of the newline and the rest of the
8647 text that follows. */
8649 - CHARPOS (tlendpos
)
8650 - MATRIX_ROW_START_CHARPOS (row
));
8651 delta_bytes
= (Z_BYTE
8652 - BYTEPOS (tlendpos
)
8653 - MATRIX_ROW_START_BYTEPOS (row
));
8656 increment_matrix_positions (w
->current_matrix
,
8658 w
->current_matrix
->nrows
,
8659 delta
, delta_bytes
);
8662 /* If this row displays text now but previously didn't,
8663 or vice versa, w->window_end_vpos may have to be
8665 if ((it
.glyph_row
- 1)->displays_text_p
)
8667 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8668 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8670 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8671 && this_line_vpos
> 0)
8672 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8673 w
->window_end_valid
= Qnil
;
8675 /* Update hint: No need to try to scroll in update_window. */
8676 w
->desired_matrix
->no_scrolling_p
= 1;
8679 *w
->desired_matrix
->method
= 0;
8680 debug_method_add (w
, "optimization 1");
8687 else if (/* Cursor position hasn't changed. */
8688 PT
== XFASTINT (w
->last_point
)
8689 /* Make sure the cursor was last displayed
8690 in this window. Otherwise we have to reposition it. */
8691 && 0 <= w
->cursor
.vpos
8692 && XINT (w
->height
) > w
->cursor
.vpos
)
8696 do_pending_window_change (1);
8698 /* We used to always goto end_of_redisplay here, but this
8699 isn't enough if we have a blinking cursor. */
8700 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8701 goto end_of_redisplay
;
8705 /* If highlighting the region, or if the cursor is in the echo area,
8706 then we can't just move the cursor. */
8707 else if (! (!NILP (Vtransient_mark_mode
)
8708 && !NILP (current_buffer
->mark_active
))
8709 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8710 || highlight_nonselected_windows
)
8711 && NILP (w
->region_showing
)
8712 && NILP (Vshow_trailing_whitespace
)
8713 && !cursor_in_echo_area
)
8716 struct glyph_row
*row
;
8718 /* Skip from tlbufpos to PT and see where it is. Note that
8719 PT may be in invisible text. If so, we will end at the
8720 next visible position. */
8721 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8722 NULL
, DEFAULT_FACE_ID
);
8723 it
.current_x
= this_line_start_x
;
8724 it
.current_y
= this_line_y
;
8725 it
.vpos
= this_line_vpos
;
8727 /* The call to move_it_to stops in front of PT, but
8728 moves over before-strings. */
8729 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8731 if (it
.vpos
== this_line_vpos
8732 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8735 xassert (this_line_vpos
== it
.vpos
);
8736 xassert (this_line_y
== it
.current_y
);
8737 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8739 *w
->desired_matrix
->method
= 0;
8740 debug_method_add (w
, "optimization 3");
8749 /* Text changed drastically or point moved off of line. */
8750 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8753 CHARPOS (this_line_start_pos
) = 0;
8754 consider_all_windows_p
|= buffer_shared
> 1;
8755 ++clear_face_cache_count
;
8758 /* Build desired matrices, and update the display. If
8759 consider_all_windows_p is non-zero, do it for all windows on all
8760 frames. Otherwise do it for selected_window, only. */
8762 if (consider_all_windows_p
)
8764 Lisp_Object tail
, frame
;
8765 int i
, n
= 0, size
= 50;
8766 struct frame
**updated
8767 = (struct frame
**) alloca (size
* sizeof *updated
);
8769 /* Clear the face cache eventually. */
8770 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8772 clear_face_cache (0);
8773 clear_face_cache_count
= 0;
8776 /* Recompute # windows showing selected buffer. This will be
8777 incremented each time such a window is displayed. */
8780 FOR_EACH_FRAME (tail
, frame
)
8782 struct frame
*f
= XFRAME (frame
);
8784 if (FRAME_WINDOW_P (f
) || f
== sf
)
8786 /* Mark all the scroll bars to be removed; we'll redeem
8787 the ones we want when we redisplay their windows. */
8788 if (condemn_scroll_bars_hook
)
8789 condemn_scroll_bars_hook (f
);
8791 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8792 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8794 /* Any scroll bars which redisplay_windows should have
8795 nuked should now go away. */
8796 if (judge_scroll_bars_hook
)
8797 judge_scroll_bars_hook (f
);
8799 /* If fonts changed, display again. */
8800 if (fonts_changed_p
)
8803 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8805 /* See if we have to hscroll. */
8806 if (hscroll_windows (f
->root_window
))
8809 /* Prevent various kinds of signals during display
8810 update. stdio is not robust about handling
8811 signals, which can cause an apparent I/O
8813 if (interrupt_input
)
8817 /* Update the display. */
8818 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8819 pause
|= update_frame (f
, 0, 0);
8825 int nbytes
= size
* sizeof *updated
;
8826 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8827 bcopy (updated
, p
, nbytes
);
8836 /* Do the mark_window_display_accurate after all windows have
8837 been redisplayed because this call resets flags in buffers
8838 which are needed for proper redisplay. */
8839 for (i
= 0; i
< n
; ++i
)
8841 struct frame
*f
= updated
[i
];
8842 mark_window_display_accurate (f
->root_window
, 1);
8843 if (frame_up_to_date_hook
)
8844 frame_up_to_date_hook (f
);
8847 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8849 Lisp_Object mini_window
;
8850 struct frame
*mini_frame
;
8852 redisplay_window (selected_window
, 1);
8854 /* Compare desired and current matrices, perform output. */
8857 /* If fonts changed, display again. */
8858 if (fonts_changed_p
)
8861 /* Prevent various kinds of signals during display update.
8862 stdio is not robust about handling signals,
8863 which can cause an apparent I/O error. */
8864 if (interrupt_input
)
8868 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8870 if (hscroll_windows (selected_window
))
8873 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8874 pause
= update_frame (sf
, 0, 0);
8877 /* We may have called echo_area_display at the top of this
8878 function. If the echo area is on another frame, that may
8879 have put text on a frame other than the selected one, so the
8880 above call to update_frame would not have caught it. Catch
8882 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8883 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8885 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8887 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8888 pause
|= update_frame (mini_frame
, 0, 0);
8889 if (!pause
&& hscroll_windows (mini_window
))
8894 /* If display was paused because of pending input, make sure we do a
8895 thorough update the next time. */
8898 /* Prevent the optimization at the beginning of
8899 redisplay_internal that tries a single-line update of the
8900 line containing the cursor in the selected window. */
8901 CHARPOS (this_line_start_pos
) = 0;
8903 /* Let the overlay arrow be updated the next time. */
8904 if (!NILP (last_arrow_position
))
8906 last_arrow_position
= Qt
;
8907 last_arrow_string
= Qt
;
8910 /* If we pause after scrolling, some rows in the current
8911 matrices of some windows are not valid. */
8912 if (!WINDOW_FULL_WIDTH_P (w
)
8913 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8914 update_mode_lines
= 1;
8918 if (!consider_all_windows_p
)
8920 /* This has already been done above if
8921 consider_all_windows_p is set. */
8922 mark_window_display_accurate_1 (w
, 1);
8924 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8925 last_arrow_string
= Voverlay_arrow_string
;
8927 if (frame_up_to_date_hook
!= 0)
8928 frame_up_to_date_hook (sf
);
8931 update_mode_lines
= 0;
8932 windows_or_buffers_changed
= 0;
8935 /* Start SIGIO interrupts coming again. Having them off during the
8936 code above makes it less likely one will discard output, but not
8937 impossible, since there might be stuff in the system buffer here.
8938 But it is much hairier to try to do anything about that. */
8939 if (interrupt_input
)
8943 /* If a frame has become visible which was not before, redisplay
8944 again, so that we display it. Expose events for such a frame
8945 (which it gets when becoming visible) don't call the parts of
8946 redisplay constructing glyphs, so simply exposing a frame won't
8947 display anything in this case. So, we have to display these
8948 frames here explicitly. */
8951 Lisp_Object tail
, frame
;
8954 FOR_EACH_FRAME (tail
, frame
)
8956 int this_is_visible
= 0;
8958 if (XFRAME (frame
)->visible
)
8959 this_is_visible
= 1;
8960 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8961 if (XFRAME (frame
)->visible
)
8962 this_is_visible
= 1;
8964 if (this_is_visible
)
8968 if (new_count
!= number_of_visible_frames
)
8969 windows_or_buffers_changed
++;
8972 /* Change frame size now if a change is pending. */
8973 do_pending_window_change (1);
8975 /* If we just did a pending size change, or have additional
8976 visible frames, redisplay again. */
8977 if (windows_or_buffers_changed
&& !pause
)
8982 unbind_to (count
, Qnil
);
8986 /* Redisplay, but leave alone any recent echo area message unless
8987 another message has been requested in its place.
8989 This is useful in situations where you need to redisplay but no
8990 user action has occurred, making it inappropriate for the message
8991 area to be cleared. See tracking_off and
8992 wait_reading_process_input for examples of these situations.
8994 FROM_WHERE is an integer saying from where this function was
8995 called. This is useful for debugging. */
8998 redisplay_preserve_echo_area (from_where
)
9001 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9003 if (!NILP (echo_area_buffer
[1]))
9005 /* We have a previously displayed message, but no current
9006 message. Redisplay the previous message. */
9007 display_last_displayed_message_p
= 1;
9008 redisplay_internal (1);
9009 display_last_displayed_message_p
= 0;
9012 redisplay_internal (1);
9016 /* Function registered with record_unwind_protect in
9017 redisplay_internal. Clears the flag indicating that a redisplay is
9021 unwind_redisplay (old_redisplaying_p
)
9022 Lisp_Object old_redisplaying_p
;
9024 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9029 /* Mark the display of window W as accurate or inaccurate. If
9030 ACCURATE_P is non-zero mark display of W as accurate. If
9031 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9032 redisplay_internal is called. */
9035 mark_window_display_accurate_1 (w
, accurate_p
)
9039 if (BUFFERP (w
->buffer
))
9041 struct buffer
*b
= XBUFFER (w
->buffer
);
9044 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9045 w
->last_overlay_modified
9046 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9048 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9052 b
->clip_changed
= 0;
9053 b
->prevent_redisplay_optimizations_p
= 0;
9055 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9056 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9057 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9058 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9060 w
->current_matrix
->buffer
= b
;
9061 w
->current_matrix
->begv
= BUF_BEGV (b
);
9062 w
->current_matrix
->zv
= BUF_ZV (b
);
9064 w
->last_cursor
= w
->cursor
;
9065 w
->last_cursor_off_p
= w
->cursor_off_p
;
9067 if (w
== XWINDOW (selected_window
))
9068 w
->last_point
= make_number (BUF_PT (b
));
9070 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9076 w
->window_end_valid
= w
->buffer
;
9077 #if 0 /* This is incorrect with variable-height lines. */
9078 xassert (XINT (w
->window_end_vpos
)
9080 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9082 w
->update_mode_line
= Qnil
;
9087 /* Mark the display of windows in the window tree rooted at WINDOW as
9088 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9089 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9090 be redisplayed the next time redisplay_internal is called. */
9093 mark_window_display_accurate (window
, accurate_p
)
9099 for (; !NILP (window
); window
= w
->next
)
9101 w
= XWINDOW (window
);
9102 mark_window_display_accurate_1 (w
, accurate_p
);
9104 if (!NILP (w
->vchild
))
9105 mark_window_display_accurate (w
->vchild
, accurate_p
);
9106 if (!NILP (w
->hchild
))
9107 mark_window_display_accurate (w
->hchild
, accurate_p
);
9112 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9113 last_arrow_string
= Voverlay_arrow_string
;
9117 /* Force a thorough redisplay the next time by setting
9118 last_arrow_position and last_arrow_string to t, which is
9119 unequal to any useful value of Voverlay_arrow_... */
9120 last_arrow_position
= Qt
;
9121 last_arrow_string
= Qt
;
9126 /* Return value in display table DP (Lisp_Char_Table *) for character
9127 C. Since a display table doesn't have any parent, we don't have to
9128 follow parent. Do not call this function directly but use the
9129 macro DISP_CHAR_VECTOR. */
9132 disp_char_vector (dp
, c
)
9133 struct Lisp_Char_Table
*dp
;
9139 if (SINGLE_BYTE_CHAR_P (c
))
9140 return (dp
->contents
[c
]);
9142 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9145 else if (code
[2] < 32)
9148 /* Here, the possible range of code[0] (== charset ID) is
9149 128..max_charset. Since the top level char table contains data
9150 for multibyte characters after 256th element, we must increment
9151 code[0] by 128 to get a correct index. */
9153 code
[3] = -1; /* anchor */
9155 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9157 val
= dp
->contents
[code
[i
]];
9158 if (!SUB_CHAR_TABLE_P (val
))
9159 return (NILP (val
) ? dp
->defalt
: val
);
9162 /* Here, val is a sub char table. We return the default value of
9164 return (dp
->defalt
);
9169 /***********************************************************************
9171 ***********************************************************************/
9173 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9176 redisplay_windows (window
)
9179 while (!NILP (window
))
9181 struct window
*w
= XWINDOW (window
);
9183 if (!NILP (w
->hchild
))
9184 redisplay_windows (w
->hchild
);
9185 else if (!NILP (w
->vchild
))
9186 redisplay_windows (w
->vchild
);
9188 redisplay_window (window
, 0);
9195 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9196 DELTA is the number of bytes by which positions recorded in ROW
9197 differ from current buffer positions. */
9200 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9202 struct glyph_row
*row
;
9203 struct glyph_matrix
*matrix
;
9204 int delta
, delta_bytes
, dy
, dvpos
;
9206 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9207 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9209 int pt_old
= PT
- delta
;
9211 /* Skip over glyphs not having an object at the start of the row.
9212 These are special glyphs like truncation marks on terminal
9214 if (row
->displays_text_p
)
9216 && INTEGERP (glyph
->object
)
9217 && glyph
->charpos
< 0)
9219 x
+= glyph
->pixel_width
;
9224 && !INTEGERP (glyph
->object
)
9225 && (!BUFFERP (glyph
->object
)
9226 || glyph
->charpos
< pt_old
))
9228 x
+= glyph
->pixel_width
;
9232 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9234 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9235 w
->cursor
.y
= row
->y
+ dy
;
9237 if (w
== XWINDOW (selected_window
))
9239 if (!row
->continued_p
9240 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9243 this_line_buffer
= XBUFFER (w
->buffer
);
9245 CHARPOS (this_line_start_pos
)
9246 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9247 BYTEPOS (this_line_start_pos
)
9248 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9250 CHARPOS (this_line_end_pos
)
9251 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9252 BYTEPOS (this_line_end_pos
)
9253 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9255 this_line_y
= w
->cursor
.y
;
9256 this_line_pixel_height
= row
->height
;
9257 this_line_vpos
= w
->cursor
.vpos
;
9258 this_line_start_x
= row
->x
;
9261 CHARPOS (this_line_start_pos
) = 0;
9266 /* Run window scroll functions, if any, for WINDOW with new window
9267 start STARTP. Sets the window start of WINDOW to that position.
9269 We assume that the window's buffer is really current. */
9271 static INLINE
struct text_pos
9272 run_window_scroll_functions (window
, startp
)
9274 struct text_pos startp
;
9276 struct window
*w
= XWINDOW (window
);
9277 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9279 if (current_buffer
!= XBUFFER (w
->buffer
))
9282 if (!NILP (Vwindow_scroll_functions
))
9284 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9285 make_number (CHARPOS (startp
)));
9286 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9287 /* In case the hook functions switch buffers. */
9288 if (current_buffer
!= XBUFFER (w
->buffer
))
9289 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9296 /* Modify the desired matrix of window W and W->vscroll so that the
9297 line containing the cursor is fully visible. If this requires
9298 larger matrices than are allocated, set fonts_changed_p and return
9302 make_cursor_line_fully_visible (w
)
9305 struct glyph_matrix
*matrix
;
9306 struct glyph_row
*row
;
9309 /* It's not always possible to find the cursor, e.g, when a window
9310 is full of overlay strings. Don't do anything in that case. */
9311 if (w
->cursor
.vpos
< 0)
9314 matrix
= w
->desired_matrix
;
9315 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9317 /* If the cursor row is not partially visible, there's nothing
9319 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9322 /* If the row the cursor is in is taller than the window's height,
9323 it's not clear what to do, so do nothing. */
9324 window_height
= window_box_height (w
);
9325 if (row
->height
>= window_height
)
9328 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9330 int dy
= row
->height
- row
->visible_height
;
9333 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9335 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9337 int dy
= - (row
->height
- row
->visible_height
);
9340 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9343 /* When we change the cursor y-position of the selected window,
9344 change this_line_y as well so that the display optimization for
9345 the cursor line of the selected window in redisplay_internal uses
9346 the correct y-position. */
9347 if (w
== XWINDOW (selected_window
))
9348 this_line_y
= w
->cursor
.y
;
9350 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9351 redisplay with larger matrices. */
9352 if (matrix
->nrows
< required_matrix_height (w
))
9354 fonts_changed_p
= 1;
9362 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9363 non-zero means only WINDOW is redisplayed in redisplay_internal.
9364 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9365 in redisplay_window to bring a partially visible line into view in
9366 the case that only the cursor has moved.
9370 1 if scrolling succeeded
9372 0 if scrolling didn't find point.
9374 -1 if new fonts have been loaded so that we must interrupt
9375 redisplay, adjust glyph matrices, and try again. */
9381 SCROLLING_NEED_LARGER_MATRICES
9385 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9386 scroll_step
, temp_scroll_step
)
9388 int just_this_one_p
;
9389 int scroll_conservatively
, scroll_step
;
9390 int temp_scroll_step
;
9392 struct window
*w
= XWINDOW (window
);
9393 struct frame
*f
= XFRAME (w
->frame
);
9394 struct text_pos scroll_margin_pos
;
9395 struct text_pos pos
;
9396 struct text_pos startp
;
9398 Lisp_Object window_end
;
9399 int this_scroll_margin
;
9403 int amount_to_scroll
= 0;
9404 Lisp_Object aggressive
;
9408 debug_method_add (w
, "try_scrolling");
9411 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9413 /* Compute scroll margin height in pixels. We scroll when point is
9414 within this distance from the top or bottom of the window. */
9415 if (scroll_margin
> 0)
9417 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9418 this_scroll_margin
*= CANON_Y_UNIT (f
);
9421 this_scroll_margin
= 0;
9423 /* Compute how much we should try to scroll maximally to bring point
9425 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9426 scroll_max
= max (scroll_step
,
9427 max (scroll_conservatively
, temp_scroll_step
));
9428 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9429 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9430 /* We're trying to scroll because of aggressive scrolling
9431 but no scroll_step is set. Choose an arbitrary one. Maybe
9432 there should be a variable for this. */
9436 scroll_max
*= CANON_Y_UNIT (f
);
9438 /* Decide whether we have to scroll down. Start at the window end
9439 and move this_scroll_margin up to find the position of the scroll
9441 window_end
= Fwindow_end (window
, Qt
);
9442 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9443 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9444 if (this_scroll_margin
)
9446 start_display (&it
, w
, scroll_margin_pos
);
9447 move_it_vertically (&it
, - this_scroll_margin
);
9448 scroll_margin_pos
= it
.current
.pos
;
9451 if (PT
>= CHARPOS (scroll_margin_pos
))
9455 /* Point is in the scroll margin at the bottom of the window, or
9456 below. Compute a new window start that makes point visible. */
9458 /* Compute the distance from the scroll margin to PT.
9459 Give up if the distance is greater than scroll_max. */
9460 start_display (&it
, w
, scroll_margin_pos
);
9462 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9463 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9465 /* With a scroll_margin of 0, scroll_margin_pos is at the window
9466 end, which is one line below the window. The iterator's
9467 current_y will be same as y0 in that case, but we have to
9468 scroll a line to make PT visible. That's the reason why 1 is
9470 dy
= 1 + it
.current_y
- y0
;
9472 if (dy
> scroll_max
)
9473 return SCROLLING_FAILED
;
9475 /* Move the window start down. If scrolling conservatively,
9476 move it just enough down to make point visible. If
9477 scroll_step is set, move it down by scroll_step. */
9478 start_display (&it
, w
, startp
);
9480 if (scroll_conservatively
)
9482 = max (max (dy
, CANON_Y_UNIT (f
)),
9483 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9484 else if (scroll_step
|| temp_scroll_step
)
9485 amount_to_scroll
= scroll_max
;
9488 aggressive
= current_buffer
->scroll_down_aggressively
;
9489 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9490 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9491 if (NUMBERP (aggressive
))
9492 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9495 if (amount_to_scroll
<= 0)
9496 return SCROLLING_FAILED
;
9498 move_it_vertically (&it
, amount_to_scroll
);
9499 startp
= it
.current
.pos
;
9503 /* See if point is inside the scroll margin at the top of the
9505 scroll_margin_pos
= startp
;
9506 if (this_scroll_margin
)
9508 start_display (&it
, w
, startp
);
9509 move_it_vertically (&it
, this_scroll_margin
);
9510 scroll_margin_pos
= it
.current
.pos
;
9513 if (PT
< CHARPOS (scroll_margin_pos
))
9515 /* Point is in the scroll margin at the top of the window or
9516 above what is displayed in the window. */
9519 /* Compute the vertical distance from PT to the scroll
9520 margin position. Give up if distance is greater than
9522 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9523 start_display (&it
, w
, pos
);
9525 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9526 it
.last_visible_y
, -1,
9527 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9528 dy
= it
.current_y
- y0
;
9529 if (dy
> scroll_max
)
9530 return SCROLLING_FAILED
;
9532 /* Compute new window start. */
9533 start_display (&it
, w
, startp
);
9535 if (scroll_conservatively
)
9537 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9538 else if (scroll_step
|| temp_scroll_step
)
9539 amount_to_scroll
= scroll_max
;
9542 aggressive
= current_buffer
->scroll_up_aggressively
;
9543 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9544 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9545 if (NUMBERP (aggressive
))
9546 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9549 if (amount_to_scroll
<= 0)
9550 return SCROLLING_FAILED
;
9552 move_it_vertically (&it
, - amount_to_scroll
);
9553 startp
= it
.current
.pos
;
9557 /* Run window scroll functions. */
9558 startp
= run_window_scroll_functions (window
, startp
);
9560 /* Display the window. Give up if new fonts are loaded, or if point
9562 if (!try_window (window
, startp
))
9563 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9564 else if (w
->cursor
.vpos
< 0)
9566 clear_glyph_matrix (w
->desired_matrix
);
9567 rc
= SCROLLING_FAILED
;
9571 /* Maybe forget recorded base line for line number display. */
9572 if (!just_this_one_p
9573 || current_buffer
->clip_changed
9574 || BEG_UNCHANGED
< CHARPOS (startp
))
9575 w
->base_line_number
= Qnil
;
9577 /* If cursor ends up on a partially visible line, shift display
9578 lines up or down. If that fails because we need larger
9579 matrices, give up. */
9580 if (!make_cursor_line_fully_visible (w
))
9581 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9583 rc
= SCROLLING_SUCCESS
;
9590 /* Compute a suitable window start for window W if display of W starts
9591 on a continuation line. Value is non-zero if a new window start
9594 The new window start will be computed, based on W's width, starting
9595 from the start of the continued line. It is the start of the
9596 screen line with the minimum distance from the old start W->start. */
9599 compute_window_start_on_continuation_line (w
)
9602 struct text_pos pos
, start_pos
;
9603 int window_start_changed_p
= 0;
9605 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9607 /* If window start is on a continuation line... Window start may be
9608 < BEGV in case there's invisible text at the start of the
9609 buffer (M-x rmail, for example). */
9610 if (CHARPOS (start_pos
) > BEGV
9611 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9614 struct glyph_row
*row
;
9616 /* Handle the case that the window start is out of range. */
9617 if (CHARPOS (start_pos
) < BEGV
)
9618 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9619 else if (CHARPOS (start_pos
) > ZV
)
9620 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9622 /* Find the start of the continued line. This should be fast
9623 because scan_buffer is fast (newline cache). */
9624 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9625 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9626 row
, DEFAULT_FACE_ID
);
9627 reseat_at_previous_visible_line_start (&it
);
9629 /* If the line start is "too far" away from the window start,
9630 say it takes too much time to compute a new window start. */
9631 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9632 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9634 int min_distance
, distance
;
9636 /* Move forward by display lines to find the new window
9637 start. If window width was enlarged, the new start can
9638 be expected to be > the old start. If window width was
9639 decreased, the new window start will be < the old start.
9640 So, we're looking for the display line start with the
9641 minimum distance from the old window start. */
9642 pos
= it
.current
.pos
;
9643 min_distance
= INFINITY
;
9644 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9645 distance
< min_distance
)
9647 min_distance
= distance
;
9648 pos
= it
.current
.pos
;
9649 move_it_by_lines (&it
, 1, 0);
9652 /* Set the window start there. */
9653 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9654 window_start_changed_p
= 1;
9658 return window_start_changed_p
;
9662 /* Try cursor movement in case text has not changes in window WINDOW,
9663 with window start STARTP. Value is
9665 CURSOR_MOVEMENT_SUCCESS if successful
9667 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
9669 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
9670 display. *SCROLL_STEP is set to 1, under certain circumstances, if
9671 we want to scroll as if scroll-step were set to 1. See the code.
9673 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
9674 which case we have to abort this redisplay, and adjust matrices
9679 CURSOR_MOVEMENT_SUCCESS
,
9680 CURSOR_MOVEMENT_CANNOT_BE_USED
,
9681 CURSOR_MOVEMENT_MUST_SCROLL
,
9682 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
9686 try_cursor_movement (window
, startp
, scroll_step
)
9688 struct text_pos startp
;
9691 struct window
*w
= XWINDOW (window
);
9692 struct frame
*f
= XFRAME (w
->frame
);
9693 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
9696 if (inhibit_try_cursor_movement
)
9700 /* Handle case where text has not changed, only point, and it has
9701 not moved off the frame. */
9702 if (/* Point may be in this window. */
9703 PT
>= CHARPOS (startp
)
9704 /* Selective display hasn't changed. */
9705 && !current_buffer
->clip_changed
9706 /* Function force-mode-line-update is used to force a thorough
9707 redisplay. It sets either windows_or_buffers_changed or
9708 update_mode_lines. So don't take a shortcut here for these
9710 && !update_mode_lines
9711 && !windows_or_buffers_changed
9712 /* Can't use this case if highlighting a region. When a
9713 region exists, cursor movement has to do more than just
9715 && !(!NILP (Vtransient_mark_mode
)
9716 && !NILP (current_buffer
->mark_active
))
9717 && NILP (w
->region_showing
)
9718 && NILP (Vshow_trailing_whitespace
)
9719 /* Right after splitting windows, last_point may be nil. */
9720 && INTEGERP (w
->last_point
)
9721 /* This code is not used for mini-buffer for the sake of the case
9722 of redisplaying to replace an echo area message; since in
9723 that case the mini-buffer contents per se are usually
9724 unchanged. This code is of no real use in the mini-buffer
9725 since the handling of this_line_start_pos, etc., in redisplay
9726 handles the same cases. */
9727 && !EQ (window
, minibuf_window
)
9728 /* When splitting windows or for new windows, it happens that
9729 redisplay is called with a nil window_end_vpos or one being
9730 larger than the window. This should really be fixed in
9731 window.c. I don't have this on my list, now, so we do
9732 approximately the same as the old redisplay code. --gerd. */
9733 && INTEGERP (w
->window_end_vpos
)
9734 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9735 && (FRAME_WINDOW_P (f
)
9736 || !MARKERP (Voverlay_arrow_position
)
9737 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9739 int this_scroll_margin
;
9740 struct glyph_row
*row
= NULL
;
9743 debug_method_add (w
, "cursor movement");
9746 /* Scroll if point within this distance from the top or bottom
9747 of the window. This is a pixel value. */
9748 this_scroll_margin
= max (0, scroll_margin
);
9749 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9750 this_scroll_margin
*= CANON_Y_UNIT (f
);
9752 /* Start with the row the cursor was displayed during the last
9753 not paused redisplay. Give up if that row is not valid. */
9754 if (w
->last_cursor
.vpos
< 0
9755 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9756 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9759 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9760 if (row
->mode_line_p
)
9762 if (!row
->enabled_p
)
9763 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9766 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
9769 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9771 if (PT
> XFASTINT (w
->last_point
))
9773 /* Point has moved forward. */
9774 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9775 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9777 xassert (row
->enabled_p
);
9781 /* The end position of a row equals the start position
9782 of the next row. If PT is there, we would rather
9783 display it in the next line. */
9784 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9785 && MATRIX_ROW_END_CHARPOS (row
) == PT
9786 && !cursor_row_p (w
, row
))
9789 /* If within the scroll margin, scroll. Note that
9790 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9791 the next line would be drawn, and that
9792 this_scroll_margin can be zero. */
9793 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9794 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9795 /* Line is completely visible last line in window
9796 and PT is to be set in the next line. */
9797 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9798 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9799 && !row
->ends_at_zv_p
9800 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9803 else if (PT
< XFASTINT (w
->last_point
))
9805 /* Cursor has to be moved backward. Note that PT >=
9806 CHARPOS (startp) because of the outer
9808 while (!row
->mode_line_p
9809 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9810 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9811 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9812 && (row
->y
> this_scroll_margin
9813 || CHARPOS (startp
) == BEGV
))
9815 xassert (row
->enabled_p
);
9819 /* Consider the following case: Window starts at BEGV,
9820 there is invisible, intangible text at BEGV, so that
9821 display starts at some point START > BEGV. It can
9822 happen that we are called with PT somewhere between
9823 BEGV and START. Try to handle that case. */
9824 if (row
< w
->current_matrix
->rows
9825 || row
->mode_line_p
)
9827 row
= w
->current_matrix
->rows
;
9828 if (row
->mode_line_p
)
9832 /* Due to newlines in overlay strings, we may have to
9833 skip forward over overlay strings. */
9834 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9835 && MATRIX_ROW_END_CHARPOS (row
) == PT
9836 && !cursor_row_p (w
, row
))
9839 /* If within the scroll margin, scroll. */
9840 if (row
->y
< this_scroll_margin
9841 && CHARPOS (startp
) != BEGV
)
9845 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9846 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9848 /* if PT is not in the glyph row, give up. */
9849 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9851 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9853 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
9854 && !row
->ends_at_zv_p
9855 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
9856 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9857 else if (row
->height
> window_box_height (w
))
9859 /* If we end up in a partially visible line, let's
9860 make it fully visible, except when it's taller
9861 than the window, in which case we can't do much
9864 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9868 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9869 try_window (window
, startp
);
9870 if (!make_cursor_line_fully_visible (w
))
9871 rc
= CURSOR_MOVEMENT_NEED_LARGER_MATRICES
;
9873 rc
= CURSOR_MOVEMENT_SUCCESS
;
9877 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9880 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9881 rc
= CURSOR_MOVEMENT_SUCCESS
;
9890 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9891 selected_window is redisplayed. */
9894 redisplay_window (window
, just_this_one_p
)
9896 int just_this_one_p
;
9898 struct window
*w
= XWINDOW (window
);
9899 struct frame
*f
= XFRAME (w
->frame
);
9900 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9901 struct buffer
*old
= current_buffer
;
9902 struct text_pos lpoint
, opoint
, startp
;
9903 int update_mode_line
;
9906 /* Record it now because it's overwritten. */
9907 int current_matrix_up_to_date_p
= 0;
9908 int temp_scroll_step
= 0;
9909 int count
= BINDING_STACK_SIZE ();
9912 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9915 /* W must be a leaf window here. */
9916 xassert (!NILP (w
->buffer
));
9918 *w
->desired_matrix
->method
= 0;
9921 specbind (Qinhibit_point_motion_hooks
, Qt
);
9923 reconsider_clip_changes (w
, buffer
);
9925 /* Has the mode line to be updated? */
9926 update_mode_line
= (!NILP (w
->update_mode_line
)
9927 || update_mode_lines
9928 || buffer
->clip_changed
);
9930 if (MINI_WINDOW_P (w
))
9932 if (w
== XWINDOW (echo_area_window
)
9933 && !NILP (echo_area_buffer
[0]))
9935 if (update_mode_line
)
9936 /* We may have to update a tty frame's menu bar or a
9937 tool-bar. Example `M-x C-h C-h C-g'. */
9938 goto finish_menu_bars
;
9940 /* We've already displayed the echo area glyphs in this window. */
9941 goto finish_scroll_bars
;
9943 else if (w
!= XWINDOW (minibuf_window
))
9945 /* W is a mini-buffer window, but it's not the currently
9946 active one, so clear it. */
9947 int yb
= window_text_bottom_y (w
);
9948 struct glyph_row
*row
;
9951 for (y
= 0, row
= w
->desired_matrix
->rows
;
9953 y
+= row
->height
, ++row
)
9954 blank_row (w
, row
, y
);
9955 goto finish_scroll_bars
;
9958 clear_glyph_matrix (w
->desired_matrix
);
9961 /* Otherwise set up data on this window; select its buffer and point
9963 /* Really select the buffer, for the sake of buffer-local
9965 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9966 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9968 current_matrix_up_to_date_p
9969 = (!NILP (w
->window_end_valid
)
9970 && !current_buffer
->clip_changed
9971 && XFASTINT (w
->last_modified
) >= MODIFF
9972 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9974 /* When windows_or_buffers_changed is non-zero, we can't rely on
9975 the window end being valid, so set it to nil there. */
9976 if (windows_or_buffers_changed
)
9978 /* If window starts on a continuation line, maybe adjust the
9979 window start in case the window's width changed. */
9980 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9981 compute_window_start_on_continuation_line (w
);
9983 w
->window_end_valid
= Qnil
;
9986 /* Some sanity checks. */
9987 CHECK_WINDOW_END (w
);
9988 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9990 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9993 /* If %c is in mode line, update it if needed. */
9994 if (!NILP (w
->column_number_displayed
)
9995 /* This alternative quickly identifies a common case
9996 where no change is needed. */
9997 && !(PT
== XFASTINT (w
->last_point
)
9998 && XFASTINT (w
->last_modified
) >= MODIFF
9999 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10000 && XFASTINT (w
->column_number_displayed
) != current_column ())
10001 update_mode_line
= 1;
10003 /* Count number of windows showing the selected buffer. An indirect
10004 buffer counts as its base buffer. */
10005 if (!just_this_one_p
)
10007 struct buffer
*current_base
, *window_base
;
10008 current_base
= current_buffer
;
10009 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10010 if (current_base
->base_buffer
)
10011 current_base
= current_base
->base_buffer
;
10012 if (window_base
->base_buffer
)
10013 window_base
= window_base
->base_buffer
;
10014 if (current_base
== window_base
)
10018 /* Point refers normally to the selected window. For any other
10019 window, set up appropriate value. */
10020 if (!EQ (window
, selected_window
))
10022 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10023 int new_pt_byte
= marker_byte_position (w
->pointm
);
10027 new_pt_byte
= BEGV_BYTE
;
10028 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10030 else if (new_pt
> (ZV
- 1))
10033 new_pt_byte
= ZV_BYTE
;
10034 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10037 /* We don't use SET_PT so that the point-motion hooks don't run. */
10038 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10041 /* If any of the character widths specified in the display table
10042 have changed, invalidate the width run cache. It's true that
10043 this may be a bit late to catch such changes, but the rest of
10044 redisplay goes (non-fatally) haywire when the display table is
10045 changed, so why should we worry about doing any better? */
10046 if (current_buffer
->width_run_cache
)
10048 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10050 if (! disptab_matches_widthtab (disptab
,
10051 XVECTOR (current_buffer
->width_table
)))
10053 invalidate_region_cache (current_buffer
,
10054 current_buffer
->width_run_cache
,
10056 recompute_width_table (current_buffer
, disptab
);
10060 /* If window-start is screwed up, choose a new one. */
10061 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10064 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10066 /* If someone specified a new starting point but did not insist,
10067 check whether it can be used. */
10068 if (!NILP (w
->optional_new_start
)
10069 && CHARPOS (startp
) >= BEGV
10070 && CHARPOS (startp
) <= ZV
)
10072 w
->optional_new_start
= Qnil
;
10073 start_display (&it
, w
, startp
);
10074 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10075 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10076 if (IT_CHARPOS (it
) == PT
)
10077 w
->force_start
= Qt
;
10080 /* Handle case where place to start displaying has been specified,
10081 unless the specified location is outside the accessible range. */
10082 if (!NILP (w
->force_start
)
10083 || w
->frozen_window_start_p
)
10085 w
->force_start
= Qnil
;
10087 w
->window_end_valid
= Qnil
;
10089 /* Forget any recorded base line for line number display. */
10090 if (!current_matrix_up_to_date_p
10091 || current_buffer
->clip_changed
)
10092 w
->base_line_number
= Qnil
;
10094 /* Redisplay the mode line. Select the buffer properly for that.
10095 Also, run the hook window-scroll-functions
10096 because we have scrolled. */
10097 /* Note, we do this after clearing force_start because
10098 if there's an error, it is better to forget about force_start
10099 than to get into an infinite loop calling the hook functions
10100 and having them get more errors. */
10101 if (!update_mode_line
10102 || ! NILP (Vwindow_scroll_functions
))
10104 update_mode_line
= 1;
10105 w
->update_mode_line
= Qt
;
10106 startp
= run_window_scroll_functions (window
, startp
);
10109 w
->last_modified
= make_number (0);
10110 w
->last_overlay_modified
= make_number (0);
10111 if (CHARPOS (startp
) < BEGV
)
10112 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10113 else if (CHARPOS (startp
) > ZV
)
10114 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10116 /* Redisplay, then check if cursor has been set during the
10117 redisplay. Give up if new fonts were loaded. */
10118 if (!try_window (window
, startp
))
10120 w
->force_start
= Qt
;
10121 clear_glyph_matrix (w
->desired_matrix
);
10122 goto finish_scroll_bars
;
10125 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10127 /* If point does not appear, try to move point so it does
10128 appear. The desired matrix has been built above, so we
10129 can use it here. */
10131 struct glyph_row
*row
;
10133 window_height
= window_box_height (w
) / 2;
10134 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10135 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
10138 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10139 MATRIX_ROW_START_BYTEPOS (row
));
10141 if (w
!= XWINDOW (selected_window
))
10142 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10143 else if (current_buffer
== old
)
10144 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10146 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10148 /* If we are highlighting the region, then we just changed
10149 the region, so redisplay to show it. */
10150 if (!NILP (Vtransient_mark_mode
)
10151 && !NILP (current_buffer
->mark_active
))
10153 clear_glyph_matrix (w
->desired_matrix
);
10154 if (!try_window (window
, startp
))
10155 goto need_larger_matrices
;
10159 if (!make_cursor_line_fully_visible (w
))
10160 goto need_larger_matrices
;
10162 debug_method_add (w
, "forced window start");
10167 /* Handle case where text has not changed, only point, and it has
10168 not moved off the frame. */
10169 if (current_matrix_up_to_date_p
10170 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10171 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10175 case CURSOR_MOVEMENT_SUCCESS
:
10178 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10179 goto need_larger_matrices
;
10181 case CURSOR_MOVEMENT_MUST_SCROLL
:
10182 goto try_to_scroll
;
10188 /* If current starting point was originally the beginning of a line
10189 but no longer is, find a new starting point. */
10190 else if (!NILP (w
->start_at_line_beg
)
10191 && !(CHARPOS (startp
) <= BEGV
10192 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10195 debug_method_add (w
, "recenter 1");
10200 /* Try scrolling with try_window_id. Value is > 0 if update has
10201 been done, it is -1 if we know that the same window start will
10202 not work. It is 0 if unsuccessful for some other reason. */
10203 else if ((tem
= try_window_id (w
)) != 0)
10206 debug_method_add (w
, "try_window_id %d", tem
);
10209 if (fonts_changed_p
)
10210 goto need_larger_matrices
;
10214 /* Otherwise try_window_id has returned -1 which means that we
10215 don't want the alternative below this comment to execute. */
10217 else if (CHARPOS (startp
) >= BEGV
10218 && CHARPOS (startp
) <= ZV
10219 && PT
>= CHARPOS (startp
)
10220 && (CHARPOS (startp
) < ZV
10221 /* Avoid starting at end of buffer. */
10222 || CHARPOS (startp
) == BEGV
10223 || (XFASTINT (w
->last_modified
) >= MODIFF
10224 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10227 debug_method_add (w
, "same window start");
10230 /* Try to redisplay starting at same place as before.
10231 If point has not moved off frame, accept the results. */
10232 if (!current_matrix_up_to_date_p
10233 /* Don't use try_window_reusing_current_matrix in this case
10234 because a window scroll function can have changed the
10236 || !NILP (Vwindow_scroll_functions
)
10237 || MINI_WINDOW_P (w
)
10238 || !try_window_reusing_current_matrix (w
))
10240 IF_DEBUG (debug_method_add (w
, "1"));
10241 try_window (window
, startp
);
10244 if (fonts_changed_p
)
10245 goto need_larger_matrices
;
10247 if (w
->cursor
.vpos
>= 0)
10249 if (!just_this_one_p
10250 || current_buffer
->clip_changed
10251 || BEG_UNCHANGED
< CHARPOS (startp
))
10252 /* Forget any recorded base line for line number display. */
10253 w
->base_line_number
= Qnil
;
10255 if (!make_cursor_line_fully_visible (w
))
10256 goto need_larger_matrices
;
10260 clear_glyph_matrix (w
->desired_matrix
);
10265 w
->last_modified
= make_number (0);
10266 w
->last_overlay_modified
= make_number (0);
10268 /* Redisplay the mode line. Select the buffer properly for that. */
10269 if (!update_mode_line
)
10271 update_mode_line
= 1;
10272 w
->update_mode_line
= Qt
;
10275 /* Try to scroll by specified few lines. */
10276 if ((scroll_conservatively
10278 || temp_scroll_step
10279 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10280 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10281 && !current_buffer
->clip_changed
10282 && CHARPOS (startp
) >= BEGV
10283 && CHARPOS (startp
) <= ZV
)
10285 /* The function returns -1 if new fonts were loaded, 1 if
10286 successful, 0 if not successful. */
10287 int rc
= try_scrolling (window
, just_this_one_p
,
10288 scroll_conservatively
,
10293 case SCROLLING_SUCCESS
:
10296 case SCROLLING_NEED_LARGER_MATRICES
:
10297 goto need_larger_matrices
;
10299 case SCROLLING_FAILED
:
10307 /* Finally, just choose place to start which centers point */
10312 debug_method_add (w
, "recenter");
10315 /* w->vscroll = 0; */
10317 /* Forget any previously recorded base line for line number display. */
10318 if (!current_matrix_up_to_date_p
10319 || current_buffer
->clip_changed
)
10320 w
->base_line_number
= Qnil
;
10322 /* Move backward half the height of the window. */
10323 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10324 it
.current_y
= it
.last_visible_y
;
10325 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
10326 xassert (IT_CHARPOS (it
) >= BEGV
);
10328 /* The function move_it_vertically_backward may move over more
10329 than the specified y-distance. If it->w is small, e.g. a
10330 mini-buffer window, we may end up in front of the window's
10331 display area. Start displaying at the start of the line
10332 containing PT in this case. */
10333 if (it
.current_y
<= 0)
10335 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10336 move_it_vertically (&it
, 0);
10337 xassert (IT_CHARPOS (it
) <= PT
);
10341 it
.current_x
= it
.hpos
= 0;
10343 /* Set startp here explicitly in case that helps avoid an infinite loop
10344 in case the window-scroll-functions functions get errors. */
10345 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10347 /* Run scroll hooks. */
10348 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10350 /* Redisplay the window. */
10351 if (!current_matrix_up_to_date_p
10352 || windows_or_buffers_changed
10353 /* Don't use try_window_reusing_current_matrix in this case
10354 because it can have changed the buffer. */
10355 || !NILP (Vwindow_scroll_functions
)
10356 || !just_this_one_p
10357 || MINI_WINDOW_P (w
)
10358 || !try_window_reusing_current_matrix (w
))
10359 try_window (window
, startp
);
10361 /* If new fonts have been loaded (due to fontsets), give up. We
10362 have to start a new redisplay since we need to re-adjust glyph
10364 if (fonts_changed_p
)
10365 goto need_larger_matrices
;
10367 /* If cursor did not appear assume that the middle of the window is
10368 in the first line of the window. Do it again with the next line.
10369 (Imagine a window of height 100, displaying two lines of height
10370 60. Moving back 50 from it->last_visible_y will end in the first
10372 if (w
->cursor
.vpos
< 0)
10374 if (!NILP (w
->window_end_valid
)
10375 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10377 clear_glyph_matrix (w
->desired_matrix
);
10378 move_it_by_lines (&it
, 1, 0);
10379 try_window (window
, it
.current
.pos
);
10381 else if (PT
< IT_CHARPOS (it
))
10383 clear_glyph_matrix (w
->desired_matrix
);
10384 move_it_by_lines (&it
, -1, 0);
10385 try_window (window
, it
.current
.pos
);
10389 /* Not much we can do about it. */
10393 /* Consider the following case: Window starts at BEGV, there is
10394 invisible, intangible text at BEGV, so that display starts at
10395 some point START > BEGV. It can happen that we are called with
10396 PT somewhere between BEGV and START. Try to handle that case. */
10397 if (w
->cursor
.vpos
< 0)
10399 struct glyph_row
*row
= w
->current_matrix
->rows
;
10400 if (row
->mode_line_p
)
10402 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10405 if (!make_cursor_line_fully_visible (w
))
10406 goto need_larger_matrices
;
10410 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10411 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10412 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10415 /* Display the mode line, if we must. */
10416 if ((update_mode_line
10417 /* If window not full width, must redo its mode line
10418 if (a) the window to its side is being redone and
10419 (b) we do a frame-based redisplay. This is a consequence
10420 of how inverted lines are drawn in frame-based redisplay. */
10421 || (!just_this_one_p
10422 && !FRAME_WINDOW_P (f
)
10423 && !WINDOW_FULL_WIDTH_P (w
))
10424 /* Line number to display. */
10425 || INTEGERP (w
->base_line_pos
)
10426 /* Column number is displayed and different from the one displayed. */
10427 || (!NILP (w
->column_number_displayed
)
10428 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10429 /* This means that the window has a mode line. */
10430 && (WINDOW_WANTS_MODELINE_P (w
)
10431 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10433 display_mode_lines (w
);
10435 /* If mode line height has changed, arrange for a thorough
10436 immediate redisplay using the correct mode line height. */
10437 if (WINDOW_WANTS_MODELINE_P (w
)
10438 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10440 fonts_changed_p
= 1;
10441 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10442 = DESIRED_MODE_LINE_HEIGHT (w
);
10445 /* If top line height has changed, arrange for a thorough
10446 immediate redisplay using the correct mode line height. */
10447 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10448 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10450 fonts_changed_p
= 1;
10451 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10452 = DESIRED_HEADER_LINE_HEIGHT (w
);
10455 if (fonts_changed_p
)
10456 goto need_larger_matrices
;
10459 if (!line_number_displayed
10460 && !BUFFERP (w
->base_line_pos
))
10462 w
->base_line_pos
= Qnil
;
10463 w
->base_line_number
= Qnil
;
10468 /* When we reach a frame's selected window, redo the frame's menu bar. */
10469 if (update_mode_line
10470 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10472 int redisplay_menu_p
= 0;
10474 if (FRAME_WINDOW_P (f
))
10476 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10477 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10479 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10483 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10485 if (redisplay_menu_p
)
10486 display_menu_bar (w
);
10488 #ifdef HAVE_WINDOW_SYSTEM
10489 if (WINDOWP (f
->tool_bar_window
)
10490 && (FRAME_TOOL_BAR_LINES (f
) > 0
10491 || auto_resize_tool_bars_p
))
10492 redisplay_tool_bar (f
);
10496 need_larger_matrices
:
10498 finish_scroll_bars
:
10500 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10502 int start
, end
, whole
;
10504 /* Calculate the start and end positions for the current window.
10505 At some point, it would be nice to choose between scrollbars
10506 which reflect the whole buffer size, with special markers
10507 indicating narrowing, and scrollbars which reflect only the
10510 Note that mini-buffers sometimes aren't displaying any text. */
10511 if (!MINI_WINDOW_P (w
)
10512 || (w
== XWINDOW (minibuf_window
)
10513 && NILP (echo_area_buffer
[0])))
10516 start
= marker_position (w
->start
) - BEGV
;
10517 /* I don't think this is guaranteed to be right. For the
10518 moment, we'll pretend it is. */
10519 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10523 if (whole
< (end
- start
))
10524 whole
= end
- start
;
10527 start
= end
= whole
= 0;
10529 /* Indicate what this scroll bar ought to be displaying now. */
10530 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10532 /* Note that we actually used the scroll bar attached to this
10533 window, so it shouldn't be deleted at the end of redisplay. */
10534 redeem_scroll_bar_hook (w
);
10537 /* Restore current_buffer and value of point in it. */
10538 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10539 set_buffer_internal_1 (old
);
10540 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10542 unbind_to (count
, Qnil
);
10546 /* Build the complete desired matrix of WINDOW with a window start
10547 buffer position POS. Value is non-zero if successful. It is zero
10548 if fonts were loaded during redisplay which makes re-adjusting
10549 glyph matrices necessary. */
10552 try_window (window
, pos
)
10553 Lisp_Object window
;
10554 struct text_pos pos
;
10556 struct window
*w
= XWINDOW (window
);
10558 struct glyph_row
*last_text_row
= NULL
;
10560 /* Make POS the new window start. */
10561 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10563 /* Mark cursor position as unknown. No overlay arrow seen. */
10564 w
->cursor
.vpos
= -1;
10565 overlay_arrow_seen
= 0;
10567 /* Initialize iterator and info to start at POS. */
10568 start_display (&it
, w
, pos
);
10570 /* Display all lines of W. */
10571 while (it
.current_y
< it
.last_visible_y
)
10573 if (display_line (&it
))
10574 last_text_row
= it
.glyph_row
- 1;
10575 if (fonts_changed_p
)
10579 /* If bottom moved off end of frame, change mode line percentage. */
10580 if (XFASTINT (w
->window_end_pos
) <= 0
10581 && Z
!= IT_CHARPOS (it
))
10582 w
->update_mode_line
= Qt
;
10584 /* Set window_end_pos to the offset of the last character displayed
10585 on the window from the end of current_buffer. Set
10586 window_end_vpos to its row number. */
10589 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10590 w
->window_end_bytepos
10591 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10593 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10595 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10596 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10597 ->displays_text_p
);
10601 w
->window_end_bytepos
= 0;
10602 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10605 /* But that is not valid info until redisplay finishes. */
10606 w
->window_end_valid
= Qnil
;
10612 /************************************************************************
10613 Window redisplay reusing current matrix when buffer has not changed
10614 ************************************************************************/
10616 /* Try redisplay of window W showing an unchanged buffer with a
10617 different window start than the last time it was displayed by
10618 reusing its current matrix. Value is non-zero if successful.
10619 W->start is the new window start. */
10622 try_window_reusing_current_matrix (w
)
10625 struct frame
*f
= XFRAME (w
->frame
);
10626 struct glyph_row
*row
, *bottom_row
;
10629 struct text_pos start
, new_start
;
10630 int nrows_scrolled
, i
;
10631 struct glyph_row
*last_text_row
;
10632 struct glyph_row
*last_reused_text_row
;
10633 struct glyph_row
*start_row
;
10634 int start_vpos
, min_y
, max_y
;
10637 if (inhibit_try_window_reusing
)
10641 if (/* This function doesn't handle terminal frames. */
10642 !FRAME_WINDOW_P (f
)
10643 /* Don't try to reuse the display if windows have been split
10645 || windows_or_buffers_changed
)
10648 /* Can't do this if region may have changed. */
10649 if ((!NILP (Vtransient_mark_mode
)
10650 && !NILP (current_buffer
->mark_active
))
10651 || !NILP (w
->region_showing
)
10652 || !NILP (Vshow_trailing_whitespace
))
10655 /* If top-line visibility has changed, give up. */
10656 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10657 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10660 /* Give up if old or new display is scrolled vertically. We could
10661 make this function handle this, but right now it doesn't. */
10662 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10663 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10666 /* The variable new_start now holds the new window start. The old
10667 start `start' can be determined from the current matrix. */
10668 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10669 start
= start_row
->start
.pos
;
10670 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10672 /* Clear the desired matrix for the display below. */
10673 clear_glyph_matrix (w
->desired_matrix
);
10675 if (CHARPOS (new_start
) <= CHARPOS (start
))
10679 /* Don't use this method if the display starts with an ellipsis
10680 displayed for invisible text. It's not easy to handle that case
10681 below, and it's certainly not worth the effort since this is
10682 not a frequent case. */
10683 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10686 IF_DEBUG (debug_method_add (w
, "twu1"));
10688 /* Display up to a row that can be reused. The variable
10689 last_text_row is set to the last row displayed that displays
10690 text. Note that it.vpos == 0 if or if not there is a
10691 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10692 start_display (&it
, w
, new_start
);
10693 first_row_y
= it
.current_y
;
10694 w
->cursor
.vpos
= -1;
10695 last_text_row
= last_reused_text_row
= NULL
;
10697 while (it
.current_y
< it
.last_visible_y
10698 && IT_CHARPOS (it
) < CHARPOS (start
)
10699 && !fonts_changed_p
)
10700 if (display_line (&it
))
10701 last_text_row
= it
.glyph_row
- 1;
10703 /* A value of current_y < last_visible_y means that we stopped
10704 at the previous window start, which in turn means that we
10705 have at least one reusable row. */
10706 if (it
.current_y
< it
.last_visible_y
)
10708 /* IT.vpos always starts from 0; it counts text lines. */
10709 nrows_scrolled
= it
.vpos
;
10711 /* Find PT if not already found in the lines displayed. */
10712 if (w
->cursor
.vpos
< 0)
10714 int dy
= it
.current_y
- first_row_y
;
10716 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10717 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
10719 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10720 dy
, nrows_scrolled
);
10723 clear_glyph_matrix (w
->desired_matrix
);
10728 /* Scroll the display. Do it before the current matrix is
10729 changed. The problem here is that update has not yet
10730 run, i.e. part of the current matrix is not up to date.
10731 scroll_run_hook will clear the cursor, and use the
10732 current matrix to get the height of the row the cursor is
10734 run
.current_y
= first_row_y
;
10735 run
.desired_y
= it
.current_y
;
10736 run
.height
= it
.last_visible_y
- it
.current_y
;
10738 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10741 rif
->update_window_begin_hook (w
);
10742 rif
->clear_mouse_face (w
);
10743 rif
->scroll_run_hook (w
, &run
);
10744 rif
->update_window_end_hook (w
, 0, 0);
10748 /* Shift current matrix down by nrows_scrolled lines. */
10749 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10750 rotate_matrix (w
->current_matrix
,
10752 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10755 /* Disable lines that must be updated. */
10756 for (i
= 0; i
< it
.vpos
; ++i
)
10757 (start_row
+ i
)->enabled_p
= 0;
10759 /* Re-compute Y positions. */
10760 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10761 max_y
= it
.last_visible_y
;
10762 for (row
= start_row
+ nrows_scrolled
;
10766 row
->y
= it
.current_y
;
10767 row
->visible_height
= row
->height
;
10769 if (row
->y
< min_y
)
10770 row
->visible_height
-= min_y
- row
->y
;
10771 if (row
->y
+ row
->height
> max_y
)
10772 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10774 it
.current_y
+= row
->height
;
10776 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10777 last_reused_text_row
= row
;
10778 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10782 /* Disable lines in the current matrix which are now
10783 below the window. */
10784 for (++row
; row
< bottom_row
; ++row
)
10785 row
->enabled_p
= 0;
10788 /* Update window_end_pos etc.; last_reused_text_row is the last
10789 reused row from the current matrix containing text, if any.
10790 The value of last_text_row is the last displayed line
10791 containing text. */
10792 if (last_reused_text_row
)
10794 w
->window_end_bytepos
10795 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10797 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10799 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10800 w
->current_matrix
));
10802 else if (last_text_row
)
10804 w
->window_end_bytepos
10805 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10807 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10809 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10813 /* This window must be completely empty. */
10814 w
->window_end_bytepos
= 0;
10815 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10817 w
->window_end_valid
= Qnil
;
10819 /* Update hint: don't try scrolling again in update_window. */
10820 w
->desired_matrix
->no_scrolling_p
= 1;
10823 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10827 else if (CHARPOS (new_start
) > CHARPOS (start
))
10829 struct glyph_row
*pt_row
, *row
;
10830 struct glyph_row
*first_reusable_row
;
10831 struct glyph_row
*first_row_to_display
;
10833 int yb
= window_text_bottom_y (w
);
10835 /* Find the row starting at new_start, if there is one. Don't
10836 reuse a partially visible line at the end. */
10837 first_reusable_row
= start_row
;
10838 while (first_reusable_row
->enabled_p
10839 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10840 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10841 < CHARPOS (new_start
)))
10842 ++first_reusable_row
;
10844 /* Give up if there is no row to reuse. */
10845 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10846 || !first_reusable_row
->enabled_p
10847 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10848 != CHARPOS (new_start
)))
10851 /* We can reuse fully visible rows beginning with
10852 first_reusable_row to the end of the window. Set
10853 first_row_to_display to the first row that cannot be reused.
10854 Set pt_row to the row containing point, if there is any. */
10856 for (first_row_to_display
= first_reusable_row
;
10857 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
10858 ++first_row_to_display
)
10860 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10861 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10862 pt_row
= first_row_to_display
;
10865 /* Start displaying at the start of first_row_to_display. */
10866 xassert (first_row_to_display
->y
< yb
);
10867 init_to_row_start (&it
, w
, first_row_to_display
);
10869 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10871 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10873 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10874 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10876 /* Display lines beginning with first_row_to_display in the
10877 desired matrix. Set last_text_row to the last row displayed
10878 that displays text. */
10879 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10880 if (pt_row
== NULL
)
10881 w
->cursor
.vpos
= -1;
10882 last_text_row
= NULL
;
10883 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10884 if (display_line (&it
))
10885 last_text_row
= it
.glyph_row
- 1;
10887 /* Give up If point isn't in a row displayed or reused. */
10888 if (w
->cursor
.vpos
< 0)
10890 clear_glyph_matrix (w
->desired_matrix
);
10894 /* If point is in a reused row, adjust y and vpos of the cursor
10898 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10899 w
->current_matrix
);
10900 w
->cursor
.y
-= first_reusable_row
->y
;
10903 /* Scroll the display. */
10904 run
.current_y
= first_reusable_row
->y
;
10905 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10906 run
.height
= it
.last_visible_y
- run
.current_y
;
10907 dy
= run
.current_y
- run
.desired_y
;
10911 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10913 rif
->update_window_begin_hook (w
);
10914 rif
->clear_mouse_face (w
);
10915 rif
->scroll_run_hook (w
, &run
);
10916 rif
->update_window_end_hook (w
, 0, 0);
10920 /* Adjust Y positions of reused rows. */
10921 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10922 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10923 max_y
= it
.last_visible_y
;
10924 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10927 row
->visible_height
= row
->height
;
10928 if (row
->y
< min_y
)
10929 row
->visible_height
-= min_y
- row
->y
;
10930 if (row
->y
+ row
->height
> max_y
)
10931 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10934 /* Scroll the current matrix. */
10935 xassert (nrows_scrolled
> 0);
10936 rotate_matrix (w
->current_matrix
,
10938 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10941 /* Disable rows not reused. */
10942 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
10943 row
->enabled_p
= 0;
10945 /* Adjust window end. A null value of last_text_row means that
10946 the window end is in reused rows which in turn means that
10947 only its vpos can have changed. */
10950 w
->window_end_bytepos
10951 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10953 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10955 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10960 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10963 w
->window_end_valid
= Qnil
;
10964 w
->desired_matrix
->no_scrolling_p
= 1;
10967 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10977 /************************************************************************
10978 Window redisplay reusing current matrix when buffer has changed
10979 ************************************************************************/
10981 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10982 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10984 static struct glyph_row
*
10985 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10986 struct glyph_row
*));
10989 /* Return the last row in MATRIX displaying text. If row START is
10990 non-null, start searching with that row. IT gives the dimensions
10991 of the display. Value is null if matrix is empty; otherwise it is
10992 a pointer to the row found. */
10994 static struct glyph_row
*
10995 find_last_row_displaying_text (matrix
, it
, start
)
10996 struct glyph_matrix
*matrix
;
10998 struct glyph_row
*start
;
11000 struct glyph_row
*row
, *row_found
;
11002 /* Set row_found to the last row in IT->w's current matrix
11003 displaying text. The loop looks funny but think of partially
11006 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11007 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11009 xassert (row
->enabled_p
);
11011 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11020 /* Return the last row in the current matrix of W that is not affected
11021 by changes at the start of current_buffer that occurred since W's
11022 current matrix was built. Value is null if no such row exists.
11024 BEG_UNCHANGED us the number of characters unchanged at the start of
11025 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11026 first changed character in current_buffer. Characters at positions <
11027 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11028 when the current matrix was built. */
11030 static struct glyph_row
*
11031 find_last_unchanged_at_beg_row (w
)
11034 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11035 struct glyph_row
*row
;
11036 struct glyph_row
*row_found
= NULL
;
11037 int yb
= window_text_bottom_y (w
);
11039 /* Find the last row displaying unchanged text. */
11040 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11041 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11042 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11044 if (/* If row ends before first_changed_pos, it is unchanged,
11045 except in some case. */
11046 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11047 /* When row ends in ZV and we write at ZV it is not
11049 && !row
->ends_at_zv_p
11050 /* When first_changed_pos is the end of a continued line,
11051 row is not unchanged because it may be no longer
11053 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11054 && row
->continued_p
))
11057 /* Stop if last visible row. */
11058 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11068 /* Find the first glyph row in the current matrix of W that is not
11069 affected by changes at the end of current_buffer since the
11070 time W's current matrix was built.
11072 Return in *DELTA the number of chars by which buffer positions in
11073 unchanged text at the end of current_buffer must be adjusted.
11075 Return in *DELTA_BYTES the corresponding number of bytes.
11077 Value is null if no such row exists, i.e. all rows are affected by
11080 static struct glyph_row
*
11081 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11083 int *delta
, *delta_bytes
;
11085 struct glyph_row
*row
;
11086 struct glyph_row
*row_found
= NULL
;
11088 *delta
= *delta_bytes
= 0;
11090 /* Display must not have been paused, otherwise the current matrix
11091 is not up to date. */
11092 if (NILP (w
->window_end_valid
))
11095 /* A value of window_end_pos >= END_UNCHANGED means that the window
11096 end is in the range of changed text. If so, there is no
11097 unchanged row at the end of W's current matrix. */
11098 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11101 /* Set row to the last row in W's current matrix displaying text. */
11102 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11104 /* If matrix is entirely empty, no unchanged row exists. */
11105 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11107 /* The value of row is the last glyph row in the matrix having a
11108 meaningful buffer position in it. The end position of row
11109 corresponds to window_end_pos. This allows us to translate
11110 buffer positions in the current matrix to current buffer
11111 positions for characters not in changed text. */
11112 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11113 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11114 int last_unchanged_pos
, last_unchanged_pos_old
;
11115 struct glyph_row
*first_text_row
11116 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11118 *delta
= Z
- Z_old
;
11119 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11121 /* Set last_unchanged_pos to the buffer position of the last
11122 character in the buffer that has not been changed. Z is the
11123 index + 1 of the last character in current_buffer, i.e. by
11124 subtracting END_UNCHANGED we get the index of the last
11125 unchanged character, and we have to add BEG to get its buffer
11127 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11128 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11130 /* Search backward from ROW for a row displaying a line that
11131 starts at a minimum position >= last_unchanged_pos_old. */
11132 for (; row
> first_text_row
; --row
)
11134 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11137 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11142 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11149 /* Make sure that glyph rows in the current matrix of window W
11150 reference the same glyph memory as corresponding rows in the
11151 frame's frame matrix. This function is called after scrolling W's
11152 current matrix on a terminal frame in try_window_id and
11153 try_window_reusing_current_matrix. */
11156 sync_frame_with_window_matrix_rows (w
)
11159 struct frame
*f
= XFRAME (w
->frame
);
11160 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11162 /* Preconditions: W must be a leaf window and full-width. Its frame
11163 must have a frame matrix. */
11164 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11165 xassert (WINDOW_FULL_WIDTH_P (w
));
11166 xassert (!FRAME_WINDOW_P (f
));
11168 /* If W is a full-width window, glyph pointers in W's current matrix
11169 have, by definition, to be the same as glyph pointers in the
11170 corresponding frame matrix. */
11171 window_row
= w
->current_matrix
->rows
;
11172 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11173 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11174 while (window_row
< window_row_end
)
11178 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
11179 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
11181 /* Disable frame rows whose corresponding window rows have
11182 been disabled in try_window_id. */
11183 if (!window_row
->enabled_p
)
11184 frame_row
->enabled_p
= 0;
11186 ++window_row
, ++frame_row
;
11191 /* Find the glyph row in window W containing CHARPOS. Consider all
11192 rows between START and END (not inclusive). END null means search
11193 all rows to the end of the display area of W. Value is the row
11194 containing CHARPOS or null. */
11197 row_containing_pos (w
, charpos
, start
, end
, dy
)
11200 struct glyph_row
*start
, *end
;
11203 struct glyph_row
*row
= start
;
11206 /* If we happen to start on a header-line, skip that. */
11207 if (row
->mode_line_p
)
11210 if ((end
&& row
>= end
) || !row
->enabled_p
)
11213 last_y
= window_text_bottom_y (w
) - dy
;
11215 while ((end
== NULL
|| row
< end
)
11216 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
11217 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11218 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11219 /* The end position of a row equals the start
11220 position of the next row. If CHARPOS is there, we
11221 would rather display it in the next line, except
11222 when this line ends in ZV. */
11223 && !row
->ends_at_zv_p
11224 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))
11227 /* Give up if CHARPOS not found. */
11228 if ((end
&& row
>= end
)
11229 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11230 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11237 /* Try to redisplay window W by reusing its existing display. W's
11238 current matrix must be up to date when this function is called,
11239 i.e. window_end_valid must not be nil.
11243 1 if display has been updated
11244 0 if otherwise unsuccessful
11245 -1 if redisplay with same window start is known not to succeed
11247 The following steps are performed:
11249 1. Find the last row in the current matrix of W that is not
11250 affected by changes at the start of current_buffer. If no such row
11253 2. Find the first row in W's current matrix that is not affected by
11254 changes at the end of current_buffer. Maybe there is no such row.
11256 3. Display lines beginning with the row + 1 found in step 1 to the
11257 row found in step 2 or, if step 2 didn't find a row, to the end of
11260 4. If cursor is not known to appear on the window, give up.
11262 5. If display stopped at the row found in step 2, scroll the
11263 display and current matrix as needed.
11265 6. Maybe display some lines at the end of W, if we must. This can
11266 happen under various circumstances, like a partially visible line
11267 becoming fully visible, or because newly displayed lines are displayed
11268 in smaller font sizes.
11270 7. Update W's window end information. */
11276 struct frame
*f
= XFRAME (w
->frame
);
11277 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11278 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11279 struct glyph_row
*last_unchanged_at_beg_row
;
11280 struct glyph_row
*first_unchanged_at_end_row
;
11281 struct glyph_row
*row
;
11282 struct glyph_row
*bottom_row
;
11285 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11286 struct text_pos start_pos
;
11288 int first_unchanged_at_end_vpos
= 0;
11289 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11290 struct text_pos start
;
11291 int first_changed_charpos
, last_changed_charpos
;
11294 if (inhibit_try_window_id
)
11298 /* This is handy for debugging. */
11300 #define GIVE_UP(X) \
11302 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11306 #define GIVE_UP(X) return 0
11309 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11311 /* Don't use this for mini-windows because these can show
11312 messages and mini-buffers, and we don't handle that here. */
11313 if (MINI_WINDOW_P (w
))
11316 /* This flag is used to prevent redisplay optimizations. */
11317 if (windows_or_buffers_changed
)
11320 /* Verify that narrowing has not changed. This flag is also set to prevent
11321 redisplay optimizations. It would be nice to further
11322 reduce the number of cases where this prevents try_window_id. */
11323 if (current_buffer
->clip_changed
)
11326 /* Window must either use window-based redisplay or be full width. */
11327 if (!FRAME_WINDOW_P (f
)
11328 && (!line_ins_del_ok
11329 || !WINDOW_FULL_WIDTH_P (w
)))
11332 /* Give up if point is not known NOT to appear in W. */
11333 if (PT
< CHARPOS (start
))
11336 /* Another way to prevent redisplay optimizations. */
11337 if (XFASTINT (w
->last_modified
) == 0)
11340 /* Verify that window is not hscrolled. */
11341 if (XFASTINT (w
->hscroll
) != 0)
11344 /* Verify that display wasn't paused. */
11345 if (NILP (w
->window_end_valid
))
11348 /* Can't use this if highlighting a region because a cursor movement
11349 will do more than just set the cursor. */
11350 if (!NILP (Vtransient_mark_mode
)
11351 && !NILP (current_buffer
->mark_active
))
11354 /* Likewise if highlighting trailing whitespace. */
11355 if (!NILP (Vshow_trailing_whitespace
))
11358 /* Likewise if showing a region. */
11359 if (!NILP (w
->region_showing
))
11362 /* Can use this if overlay arrow position and or string have changed. */
11363 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11364 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11368 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11369 only if buffer has really changed. The reason is that the gap is
11370 initially at Z for freshly visited files. The code below would
11371 set end_unchanged to 0 in that case. */
11372 if (MODIFF
> SAVE_MODIFF
11373 /* This seems to happen sometimes after saving a buffer. */
11374 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11376 if (GPT
- BEG
< BEG_UNCHANGED
)
11377 BEG_UNCHANGED
= GPT
- BEG
;
11378 if (Z
- GPT
< END_UNCHANGED
)
11379 END_UNCHANGED
= Z
- GPT
;
11382 /* The position of the first and last character that has been changed. */
11383 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11384 last_changed_charpos
= Z
- END_UNCHANGED
;
11386 /* If window starts after a line end, and the last change is in
11387 front of that newline, then changes don't affect the display.
11388 This case happens with stealth-fontification. Note that although
11389 the display is unchanged, glyph positions in the matrix have to
11390 be adjusted, of course. */
11391 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11392 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11393 && ((last_changed_charpos
< CHARPOS (start
)
11394 && CHARPOS (start
) == BEGV
)
11395 || (last_changed_charpos
< CHARPOS (start
) - 1
11396 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11398 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11399 struct glyph_row
*r0
;
11401 /* Compute how many chars/bytes have been added to or removed
11402 from the buffer. */
11403 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11404 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11406 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11408 /* Give up if PT is not in the window. Note that it already has
11409 been checked at the start of try_window_id that PT is not in
11410 front of the window start. */
11411 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11414 /* If window start is unchanged, we can reuse the whole matrix
11415 as is, after adjusting glyph positions. No need to compute
11416 the window end again, since its offset from Z hasn't changed. */
11417 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11418 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11419 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11421 /* Adjust positions in the glyph matrix. */
11422 if (delta
|| delta_bytes
)
11424 struct glyph_row
*r1
11425 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11426 increment_matrix_positions (w
->current_matrix
,
11427 MATRIX_ROW_VPOS (r0
, current_matrix
),
11428 MATRIX_ROW_VPOS (r1
, current_matrix
),
11429 delta
, delta_bytes
);
11432 /* Set the cursor. */
11433 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11434 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11439 /* Handle the case that changes are all below what is displayed in
11440 the window, and that PT is in the window. This shortcut cannot
11441 be taken if ZV is visible in the window, and text has been added
11442 there that is visible in the window. */
11443 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11444 /* ZV is not visible in the window, or there are no
11445 changes at ZV, actually. */
11446 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11447 || first_changed_charpos
== last_changed_charpos
))
11449 struct glyph_row
*r0
;
11451 /* Give up if PT is not in the window. Note that it already has
11452 been checked at the start of try_window_id that PT is not in
11453 front of the window start. */
11454 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11457 /* If window start is unchanged, we can reuse the whole matrix
11458 as is, without changing glyph positions since no text has
11459 been added/removed in front of the window end. */
11460 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11461 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11463 /* We have to compute the window end anew since text
11464 can have been added/removed after it. */
11466 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11467 w
->window_end_bytepos
11468 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11470 /* Set the cursor. */
11471 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11472 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11477 /* Give up if window start is in the changed area.
11479 The condition used to read
11481 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11483 but why that was tested escapes me at the moment. */
11484 if (CHARPOS (start
) >= first_changed_charpos
11485 && CHARPOS (start
) <= last_changed_charpos
)
11488 /* Check that window start agrees with the start of the first glyph
11489 row in its current matrix. Check this after we know the window
11490 start is not in changed text, otherwise positions would not be
11492 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11493 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11496 /* Give up if the window ends in strings. Overlay strings
11497 at the end are difficult to handle, so don't try. */
11498 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
11499 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
11502 /* Compute the position at which we have to start displaying new
11503 lines. Some of the lines at the top of the window might be
11504 reusable because they are not displaying changed text. Find the
11505 last row in W's current matrix not affected by changes at the
11506 start of current_buffer. Value is null if changes start in the
11507 first line of window. */
11508 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11509 if (last_unchanged_at_beg_row
)
11511 /* Avoid starting to display in the moddle of a character, a TAB
11512 for instance. This is easier than to set up the iterator
11513 exactly, and it's not a frequent case, so the additional
11514 effort wouldn't really pay off. */
11515 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11516 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
11517 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11518 --last_unchanged_at_beg_row
;
11520 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11523 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11525 start_pos
= it
.current
.pos
;
11527 /* Start displaying new lines in the desired matrix at the same
11528 vpos we would use in the current matrix, i.e. below
11529 last_unchanged_at_beg_row. */
11530 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11532 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11533 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11535 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11539 /* There are no reusable lines at the start of the window.
11540 Start displaying in the first line. */
11541 start_display (&it
, w
, start
);
11542 start_pos
= it
.current
.pos
;
11545 /* Find the first row that is not affected by changes at the end of
11546 the buffer. Value will be null if there is no unchanged row, in
11547 which case we must redisplay to the end of the window. delta
11548 will be set to the value by which buffer positions beginning with
11549 first_unchanged_at_end_row have to be adjusted due to text
11551 first_unchanged_at_end_row
11552 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11553 IF_DEBUG (debug_delta
= delta
);
11554 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11556 /* Set stop_pos to the buffer position up to which we will have to
11557 display new lines. If first_unchanged_at_end_row != NULL, this
11558 is the buffer position of the start of the line displayed in that
11559 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11560 that we don't stop at a buffer position. */
11562 if (first_unchanged_at_end_row
)
11564 xassert (last_unchanged_at_beg_row
== NULL
11565 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11567 /* If this is a continuation line, move forward to the next one
11568 that isn't. Changes in lines above affect this line.
11569 Caution: this may move first_unchanged_at_end_row to a row
11570 not displaying text. */
11571 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11572 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11573 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11574 < it
.last_visible_y
))
11575 ++first_unchanged_at_end_row
;
11577 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11578 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11579 >= it
.last_visible_y
))
11580 first_unchanged_at_end_row
= NULL
;
11583 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11585 first_unchanged_at_end_vpos
11586 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11587 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11590 else if (last_unchanged_at_beg_row
== NULL
)
11596 /* Either there is no unchanged row at the end, or the one we have
11597 now displays text. This is a necessary condition for the window
11598 end pos calculation at the end of this function. */
11599 xassert (first_unchanged_at_end_row
== NULL
11600 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11602 debug_last_unchanged_at_beg_vpos
11603 = (last_unchanged_at_beg_row
11604 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11606 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11608 #endif /* GLYPH_DEBUG != 0 */
11611 /* Display new lines. Set last_text_row to the last new line
11612 displayed which has text on it, i.e. might end up as being the
11613 line where the window_end_vpos is. */
11614 w
->cursor
.vpos
= -1;
11615 last_text_row
= NULL
;
11616 overlay_arrow_seen
= 0;
11617 while (it
.current_y
< it
.last_visible_y
11618 && !fonts_changed_p
11619 && (first_unchanged_at_end_row
== NULL
11620 || IT_CHARPOS (it
) < stop_pos
))
11622 if (display_line (&it
))
11623 last_text_row
= it
.glyph_row
- 1;
11626 if (fonts_changed_p
)
11630 /* Compute differences in buffer positions, y-positions etc. for
11631 lines reused at the bottom of the window. Compute what we can
11633 if (first_unchanged_at_end_row
11634 /* No lines reused because we displayed everything up to the
11635 bottom of the window. */
11636 && it
.current_y
< it
.last_visible_y
)
11639 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11641 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11642 run
.current_y
= first_unchanged_at_end_row
->y
;
11643 run
.desired_y
= run
.current_y
+ dy
;
11644 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11648 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11649 first_unchanged_at_end_row
= NULL
;
11651 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11654 /* Find the cursor if not already found. We have to decide whether
11655 PT will appear on this window (it sometimes doesn't, but this is
11656 not a very frequent case.) This decision has to be made before
11657 the current matrix is altered. A value of cursor.vpos < 0 means
11658 that PT is either in one of the lines beginning at
11659 first_unchanged_at_end_row or below the window. Don't care for
11660 lines that might be displayed later at the window end; as
11661 mentioned, this is not a frequent case. */
11662 if (w
->cursor
.vpos
< 0)
11664 /* Cursor in unchanged rows at the top? */
11665 if (PT
< CHARPOS (start_pos
)
11666 && last_unchanged_at_beg_row
)
11668 row
= row_containing_pos (w
, PT
,
11669 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11670 last_unchanged_at_beg_row
+ 1, 0);
11672 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11675 /* Start from first_unchanged_at_end_row looking for PT. */
11676 else if (first_unchanged_at_end_row
)
11678 row
= row_containing_pos (w
, PT
- delta
,
11679 first_unchanged_at_end_row
, NULL
, 0);
11681 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11682 delta_bytes
, dy
, dvpos
);
11685 /* Give up if cursor was not found. */
11686 if (w
->cursor
.vpos
< 0)
11688 clear_glyph_matrix (w
->desired_matrix
);
11693 /* Don't let the cursor end in the scroll margins. */
11695 int this_scroll_margin
, cursor_height
;
11697 this_scroll_margin
= max (0, scroll_margin
);
11698 this_scroll_margin
= min (this_scroll_margin
,
11699 XFASTINT (w
->height
) / 4);
11700 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11701 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11703 if ((w
->cursor
.y
< this_scroll_margin
11704 && CHARPOS (start
) > BEGV
)
11705 /* Don't take scroll margin into account at the bottom because
11706 old redisplay didn't do it either. */
11707 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11709 w
->cursor
.vpos
= -1;
11710 clear_glyph_matrix (w
->desired_matrix
);
11715 /* Scroll the display. Do it before changing the current matrix so
11716 that xterm.c doesn't get confused about where the cursor glyph is
11718 if (dy
&& run
.height
)
11722 if (FRAME_WINDOW_P (f
))
11724 rif
->update_window_begin_hook (w
);
11725 rif
->clear_mouse_face (w
);
11726 rif
->scroll_run_hook (w
, &run
);
11727 rif
->update_window_end_hook (w
, 0, 0);
11731 /* Terminal frame. In this case, dvpos gives the number of
11732 lines to scroll by; dvpos < 0 means scroll up. */
11733 int first_unchanged_at_end_vpos
11734 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11735 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11736 int end
= (XFASTINT (w
->top
)
11737 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
11738 + window_internal_height (w
));
11740 /* Perform the operation on the screen. */
11743 /* Scroll last_unchanged_at_beg_row to the end of the
11744 window down dvpos lines. */
11745 set_terminal_window (end
);
11747 /* On dumb terminals delete dvpos lines at the end
11748 before inserting dvpos empty lines. */
11749 if (!scroll_region_ok
)
11750 ins_del_lines (end
- dvpos
, -dvpos
);
11752 /* Insert dvpos empty lines in front of
11753 last_unchanged_at_beg_row. */
11754 ins_del_lines (from
, dvpos
);
11756 else if (dvpos
< 0)
11758 /* Scroll up last_unchanged_at_beg_vpos to the end of
11759 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11760 set_terminal_window (end
);
11762 /* Delete dvpos lines in front of
11763 last_unchanged_at_beg_vpos. ins_del_lines will set
11764 the cursor to the given vpos and emit |dvpos| delete
11766 ins_del_lines (from
+ dvpos
, dvpos
);
11768 /* On a dumb terminal insert dvpos empty lines at the
11770 if (!scroll_region_ok
)
11771 ins_del_lines (end
+ dvpos
, -dvpos
);
11774 set_terminal_window (0);
11780 /* Shift reused rows of the current matrix to the right position.
11781 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11783 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11784 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11787 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11788 bottom_vpos
, dvpos
);
11789 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11792 else if (dvpos
> 0)
11794 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11795 bottom_vpos
, dvpos
);
11796 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11797 first_unchanged_at_end_vpos
+ dvpos
, 0);
11800 /* For frame-based redisplay, make sure that current frame and window
11801 matrix are in sync with respect to glyph memory. */
11802 if (!FRAME_WINDOW_P (f
))
11803 sync_frame_with_window_matrix_rows (w
);
11805 /* Adjust buffer positions in reused rows. */
11807 increment_matrix_positions (current_matrix
,
11808 first_unchanged_at_end_vpos
+ dvpos
,
11809 bottom_vpos
, delta
, delta_bytes
);
11811 /* Adjust Y positions. */
11813 shift_glyph_matrix (w
, current_matrix
,
11814 first_unchanged_at_end_vpos
+ dvpos
,
11817 if (first_unchanged_at_end_row
)
11818 first_unchanged_at_end_row
+= dvpos
;
11820 /* If scrolling up, there may be some lines to display at the end of
11822 last_text_row_at_end
= NULL
;
11825 /* Scrolling up can leave for example a partially visible line
11826 at the end of the window to be redisplayed. */
11827 /* Set last_row to the glyph row in the current matrix where the
11828 window end line is found. It has been moved up or down in
11829 the matrix by dvpos. */
11830 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11831 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11833 /* If last_row is the window end line, it should display text. */
11834 xassert (last_row
->displays_text_p
);
11836 /* If window end line was partially visible before, begin
11837 displaying at that line. Otherwise begin displaying with the
11838 line following it. */
11839 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11841 init_to_row_start (&it
, w
, last_row
);
11842 it
.vpos
= last_vpos
;
11843 it
.current_y
= last_row
->y
;
11847 init_to_row_end (&it
, w
, last_row
);
11848 it
.vpos
= 1 + last_vpos
;
11849 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11853 /* We may start in a continuation line. If so, we have to
11854 get the right continuation_lines_width and current_x. */
11855 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11856 it
.hpos
= it
.current_x
= 0;
11858 /* Display the rest of the lines at the window end. */
11859 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11860 while (it
.current_y
< it
.last_visible_y
11861 && !fonts_changed_p
)
11863 /* Is it always sure that the display agrees with lines in
11864 the current matrix? I don't think so, so we mark rows
11865 displayed invalid in the current matrix by setting their
11866 enabled_p flag to zero. */
11867 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11868 if (display_line (&it
))
11869 last_text_row_at_end
= it
.glyph_row
- 1;
11873 /* Update window_end_pos and window_end_vpos. */
11874 if (first_unchanged_at_end_row
11875 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11876 && !last_text_row_at_end
)
11878 /* Window end line if one of the preserved rows from the current
11879 matrix. Set row to the last row displaying text in current
11880 matrix starting at first_unchanged_at_end_row, after
11882 xassert (first_unchanged_at_end_row
->displays_text_p
);
11883 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11884 first_unchanged_at_end_row
);
11885 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11887 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11888 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11890 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11891 xassert (w
->window_end_bytepos
>= 0);
11892 IF_DEBUG (debug_method_add (w
, "A"));
11894 else if (last_text_row_at_end
)
11897 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11898 w
->window_end_bytepos
11899 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11901 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11902 xassert (w
->window_end_bytepos
>= 0);
11903 IF_DEBUG (debug_method_add (w
, "B"));
11905 else if (last_text_row
)
11907 /* We have displayed either to the end of the window or at the
11908 end of the window, i.e. the last row with text is to be found
11909 in the desired matrix. */
11911 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11912 w
->window_end_bytepos
11913 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11915 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11916 xassert (w
->window_end_bytepos
>= 0);
11918 else if (first_unchanged_at_end_row
== NULL
11919 && last_text_row
== NULL
11920 && last_text_row_at_end
== NULL
)
11922 /* Displayed to end of window, but no line containing text was
11923 displayed. Lines were deleted at the end of the window. */
11924 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11925 int vpos
= XFASTINT (w
->window_end_vpos
);
11926 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
11927 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
11930 row
== NULL
&& vpos
>= first_vpos
;
11931 --vpos
, --current_row
, --desired_row
)
11933 if (desired_row
->enabled_p
)
11935 if (desired_row
->displays_text_p
)
11938 else if (current_row
->displays_text_p
)
11942 xassert (row
!= NULL
);
11943 w
->window_end_vpos
= make_number (vpos
+ 1);
11944 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11945 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11946 xassert (w
->window_end_bytepos
>= 0);
11947 IF_DEBUG (debug_method_add (w
, "C"));
11952 #if 0 /* This leads to problems, for instance when the cursor is
11953 at ZV, and the cursor line displays no text. */
11954 /* Disable rows below what's displayed in the window. This makes
11955 debugging easier. */
11956 enable_glyph_matrix_rows (current_matrix
,
11957 XFASTINT (w
->window_end_vpos
) + 1,
11961 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11962 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11964 /* Record that display has not been completed. */
11965 w
->window_end_valid
= Qnil
;
11966 w
->desired_matrix
->no_scrolling_p
= 1;
11974 /***********************************************************************
11975 More debugging support
11976 ***********************************************************************/
11980 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
11981 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11982 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
11985 /* Dump the contents of glyph matrix MATRIX on stderr.
11987 GLYPHS 0 means don't show glyph contents.
11988 GLYPHS 1 means show glyphs in short form
11989 GLYPHS > 1 means show glyphs in long form. */
11992 dump_glyph_matrix (matrix
, glyphs
)
11993 struct glyph_matrix
*matrix
;
11997 for (i
= 0; i
< matrix
->nrows
; ++i
)
11998 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12002 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12003 the glyph row and area where the glyph comes from. */
12006 dump_glyph (row
, glyph
, area
)
12007 struct glyph_row
*row
;
12008 struct glyph
*glyph
;
12011 if (glyph
->type
== CHAR_GLYPH
)
12014 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12015 glyph
- row
->glyphs
[TEXT_AREA
],
12018 (BUFFERP (glyph
->object
)
12020 : (STRINGP (glyph
->object
)
12023 glyph
->pixel_width
,
12025 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12029 glyph
->left_box_line_p
,
12030 glyph
->right_box_line_p
);
12032 else if (glyph
->type
== STRETCH_GLYPH
)
12035 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12036 glyph
- row
->glyphs
[TEXT_AREA
],
12039 (BUFFERP (glyph
->object
)
12041 : (STRINGP (glyph
->object
)
12044 glyph
->pixel_width
,
12048 glyph
->left_box_line_p
,
12049 glyph
->right_box_line_p
);
12051 else if (glyph
->type
== IMAGE_GLYPH
)
12054 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12055 glyph
- row
->glyphs
[TEXT_AREA
],
12058 (BUFFERP (glyph
->object
)
12060 : (STRINGP (glyph
->object
)
12063 glyph
->pixel_width
,
12067 glyph
->left_box_line_p
,
12068 glyph
->right_box_line_p
);
12073 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12074 GLYPHS 0 means don't show glyph contents.
12075 GLYPHS 1 means show glyphs in short form
12076 GLYPHS > 1 means show glyphs in long form. */
12079 dump_glyph_row (row
, vpos
, glyphs
)
12080 struct glyph_row
*row
;
12085 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12086 fprintf (stderr
, "=======================================================================\n");
12088 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12089 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12091 MATRIX_ROW_START_CHARPOS (row
),
12092 MATRIX_ROW_END_CHARPOS (row
),
12093 row
->used
[TEXT_AREA
],
12094 row
->contains_overlapping_glyphs_p
,
12096 row
->truncated_on_left_p
,
12097 row
->truncated_on_right_p
,
12098 row
->overlay_arrow_p
,
12100 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12101 row
->displays_text_p
,
12104 row
->ends_in_middle_of_char_p
,
12105 row
->starts_in_middle_of_char_p
,
12111 row
->visible_height
,
12114 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12115 row
->end
.overlay_string_index
,
12116 row
->continuation_lines_width
);
12117 fprintf (stderr
, "%9d %5d\n",
12118 CHARPOS (row
->start
.string_pos
),
12119 CHARPOS (row
->end
.string_pos
));
12120 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12121 row
->end
.dpvec_index
);
12128 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12130 struct glyph
*glyph
= row
->glyphs
[area
];
12131 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12133 /* Glyph for a line end in text. */
12134 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12137 if (glyph
< glyph_end
)
12138 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12140 for (; glyph
< glyph_end
; ++glyph
)
12141 dump_glyph (row
, glyph
, area
);
12144 else if (glyphs
== 1)
12148 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12150 char *s
= (char *) alloca (row
->used
[area
] + 1);
12153 for (i
= 0; i
< row
->used
[area
]; ++i
)
12155 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12156 if (glyph
->type
== CHAR_GLYPH
12157 && glyph
->u
.ch
< 0x80
12158 && glyph
->u
.ch
>= ' ')
12159 s
[i
] = glyph
->u
.ch
;
12165 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12171 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12172 Sdump_glyph_matrix
, 0, 1, "p",
12173 doc
: /* Dump the current matrix of the selected window to stderr.
12174 Shows contents of glyph row structures. With non-nil
12175 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12176 glyphs in short form, otherwise show glyphs in long form. */)
12178 Lisp_Object glyphs
;
12180 struct window
*w
= XWINDOW (selected_window
);
12181 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12183 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12184 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12185 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12186 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12187 fprintf (stderr
, "=============================================\n");
12188 dump_glyph_matrix (w
->current_matrix
,
12189 NILP (glyphs
) ? 0 : XINT (glyphs
));
12194 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12195 doc
: /* Dump glyph row ROW to stderr.
12196 GLYPH 0 means don't dump glyphs.
12197 GLYPH 1 means dump glyphs in short form.
12198 GLYPH > 1 or omitted means dump glyphs in long form. */)
12200 Lisp_Object row
, glyphs
;
12202 struct glyph_matrix
*matrix
;
12205 CHECK_NUMBER (row
);
12206 matrix
= XWINDOW (selected_window
)->current_matrix
;
12208 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12209 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12211 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12216 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12217 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12218 GLYPH 0 means don't dump glyphs.
12219 GLYPH 1 means dump glyphs in short form.
12220 GLYPH > 1 or omitted means dump glyphs in long form. */)
12222 Lisp_Object row
, glyphs
;
12224 struct frame
*sf
= SELECTED_FRAME ();
12225 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12228 CHECK_NUMBER (row
);
12230 if (vpos
>= 0 && vpos
< m
->nrows
)
12231 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12232 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12237 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12238 doc
: /* Toggle tracing of redisplay.
12239 With ARG, turn tracing on if and only if ARG is positive. */)
12244 trace_redisplay_p
= !trace_redisplay_p
;
12247 arg
= Fprefix_numeric_value (arg
);
12248 trace_redisplay_p
= XINT (arg
) > 0;
12255 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12256 doc
: /* Like `format', but print result to stderr. */)
12261 Lisp_Object s
= Fformat (nargs
, args
);
12262 fprintf (stderr
, "%s", XSTRING (s
)->data
);
12266 #endif /* GLYPH_DEBUG */
12270 /***********************************************************************
12271 Building Desired Matrix Rows
12272 ***********************************************************************/
12274 /* Return a temporary glyph row holding the glyphs of an overlay
12275 arrow. Only used for non-window-redisplay windows. */
12277 static struct glyph_row
*
12278 get_overlay_arrow_glyph_row (w
)
12281 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12282 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12283 struct buffer
*old
= current_buffer
;
12284 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
12285 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
12286 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12290 int n_glyphs_before
;
12292 set_buffer_temp (buffer
);
12293 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12294 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12295 SET_TEXT_POS (it
.position
, 0, 0);
12297 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12299 while (p
< arrow_end
)
12301 Lisp_Object face
, ilisp
;
12303 /* Get the next character. */
12305 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12307 it
.c
= *p
, it
.len
= 1;
12310 /* Get its face. */
12311 ilisp
= make_number (p
- arrow_string
);
12312 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12313 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12315 /* Compute its width, get its glyphs. */
12316 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12317 SET_TEXT_POS (it
.position
, -1, -1);
12318 PRODUCE_GLYPHS (&it
);
12320 /* If this character doesn't fit any more in the line, we have
12321 to remove some glyphs. */
12322 if (it
.current_x
> it
.last_visible_x
)
12324 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12329 set_buffer_temp (old
);
12330 return it
.glyph_row
;
12334 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12335 glyphs are only inserted for terminal frames since we can't really
12336 win with truncation glyphs when partially visible glyphs are
12337 involved. Which glyphs to insert is determined by
12338 produce_special_glyphs. */
12341 insert_left_trunc_glyphs (it
)
12344 struct it truncate_it
;
12345 struct glyph
*from
, *end
, *to
, *toend
;
12347 xassert (!FRAME_WINDOW_P (it
->f
));
12349 /* Get the truncation glyphs. */
12351 truncate_it
.current_x
= 0;
12352 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12353 truncate_it
.glyph_row
= &scratch_glyph_row
;
12354 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12355 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12356 truncate_it
.object
= make_number (0);
12357 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12359 /* Overwrite glyphs from IT with truncation glyphs. */
12360 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12361 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12362 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12363 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12368 /* There may be padding glyphs left over. Overwrite them too. */
12369 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12371 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12377 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12381 /* Compute the pixel height and width of IT->glyph_row.
12383 Most of the time, ascent and height of a display line will be equal
12384 to the max_ascent and max_height values of the display iterator
12385 structure. This is not the case if
12387 1. We hit ZV without displaying anything. In this case, max_ascent
12388 and max_height will be zero.
12390 2. We have some glyphs that don't contribute to the line height.
12391 (The glyph row flag contributes_to_line_height_p is for future
12392 pixmap extensions).
12394 The first case is easily covered by using default values because in
12395 these cases, the line height does not really matter, except that it
12396 must not be zero. */
12399 compute_line_metrics (it
)
12402 struct glyph_row
*row
= it
->glyph_row
;
12405 if (FRAME_WINDOW_P (it
->f
))
12407 int i
, min_y
, max_y
;
12409 /* The line may consist of one space only, that was added to
12410 place the cursor on it. If so, the row's height hasn't been
12412 if (row
->height
== 0)
12414 if (it
->max_ascent
+ it
->max_descent
== 0)
12415 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12416 row
->ascent
= it
->max_ascent
;
12417 row
->height
= it
->max_ascent
+ it
->max_descent
;
12418 row
->phys_ascent
= it
->max_phys_ascent
;
12419 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12422 /* Compute the width of this line. */
12423 row
->pixel_width
= row
->x
;
12424 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12425 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12427 xassert (row
->pixel_width
>= 0);
12428 xassert (row
->ascent
>= 0 && row
->height
> 0);
12430 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12431 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12433 /* If first line's physical ascent is larger than its logical
12434 ascent, use the physical ascent, and make the row taller.
12435 This makes accented characters fully visible. */
12436 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12437 && row
->phys_ascent
> row
->ascent
)
12439 row
->height
+= row
->phys_ascent
- row
->ascent
;
12440 row
->ascent
= row
->phys_ascent
;
12443 /* Compute how much of the line is visible. */
12444 row
->visible_height
= row
->height
;
12446 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12447 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12449 if (row
->y
< min_y
)
12450 row
->visible_height
-= min_y
- row
->y
;
12451 if (row
->y
+ row
->height
> max_y
)
12452 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12456 row
->pixel_width
= row
->used
[TEXT_AREA
];
12457 if (row
->continued_p
)
12458 row
->pixel_width
-= it
->continuation_pixel_width
;
12459 else if (row
->truncated_on_right_p
)
12460 row
->pixel_width
-= it
->truncation_pixel_width
;
12461 row
->ascent
= row
->phys_ascent
= 0;
12462 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12465 /* Compute a hash code for this row. */
12467 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12468 for (i
= 0; i
< row
->used
[area
]; ++i
)
12469 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12470 + row
->glyphs
[area
][i
].u
.val
12471 + row
->glyphs
[area
][i
].face_id
12472 + row
->glyphs
[area
][i
].padding_p
12473 + (row
->glyphs
[area
][i
].type
<< 2));
12475 it
->max_ascent
= it
->max_descent
= 0;
12476 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12480 /* Append one space to the glyph row of iterator IT if doing a
12481 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12482 space have the default face, otherwise let it have the same face as
12483 IT->face_id. Value is non-zero if a space was added.
12485 This function is called to make sure that there is always one glyph
12486 at the end of a glyph row that the cursor can be set on under
12487 window-systems. (If there weren't such a glyph we would not know
12488 how wide and tall a box cursor should be displayed).
12490 At the same time this space let's a nicely handle clearing to the
12491 end of the line if the row ends in italic text. */
12494 append_space (it
, default_face_p
)
12496 int default_face_p
;
12498 if (FRAME_WINDOW_P (it
->f
))
12500 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12502 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12503 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12505 /* Save some values that must not be changed.
12506 Must save IT->c and IT->len because otherwise
12507 ITERATOR_AT_END_P wouldn't work anymore after
12508 append_space has been called. */
12509 enum display_element_type saved_what
= it
->what
;
12510 int saved_c
= it
->c
, saved_len
= it
->len
;
12511 int saved_x
= it
->current_x
;
12512 int saved_face_id
= it
->face_id
;
12513 struct text_pos saved_pos
;
12514 Lisp_Object saved_object
;
12517 saved_object
= it
->object
;
12518 saved_pos
= it
->position
;
12520 it
->what
= IT_CHARACTER
;
12521 bzero (&it
->position
, sizeof it
->position
);
12522 it
->object
= make_number (0);
12526 if (default_face_p
)
12527 it
->face_id
= DEFAULT_FACE_ID
;
12528 else if (it
->face_before_selective_p
)
12529 it
->face_id
= it
->saved_face_id
;
12530 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12531 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12533 PRODUCE_GLYPHS (it
);
12535 it
->current_x
= saved_x
;
12536 it
->object
= saved_object
;
12537 it
->position
= saved_pos
;
12538 it
->what
= saved_what
;
12539 it
->face_id
= saved_face_id
;
12540 it
->len
= saved_len
;
12550 /* Extend the face of the last glyph in the text area of IT->glyph_row
12551 to the end of the display line. Called from display_line.
12552 If the glyph row is empty, add a space glyph to it so that we
12553 know the face to draw. Set the glyph row flag fill_line_p. */
12556 extend_face_to_end_of_line (it
)
12560 struct frame
*f
= it
->f
;
12562 /* If line is already filled, do nothing. */
12563 if (it
->current_x
>= it
->last_visible_x
)
12566 /* Face extension extends the background and box of IT->face_id
12567 to the end of the line. If the background equals the background
12568 of the frame, we don't have to do anything. */
12569 if (it
->face_before_selective_p
)
12570 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12572 face
= FACE_FROM_ID (f
, it
->face_id
);
12574 if (FRAME_WINDOW_P (f
)
12575 && face
->box
== FACE_NO_BOX
12576 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12580 /* Set the glyph row flag indicating that the face of the last glyph
12581 in the text area has to be drawn to the end of the text area. */
12582 it
->glyph_row
->fill_line_p
= 1;
12584 /* If current character of IT is not ASCII, make sure we have the
12585 ASCII face. This will be automatically undone the next time
12586 get_next_display_element returns a multibyte character. Note
12587 that the character will always be single byte in unibyte text. */
12588 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12590 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12593 if (FRAME_WINDOW_P (f
))
12595 /* If the row is empty, add a space with the current face of IT,
12596 so that we know which face to draw. */
12597 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12599 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12600 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12601 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12606 /* Save some values that must not be changed. */
12607 int saved_x
= it
->current_x
;
12608 struct text_pos saved_pos
;
12609 Lisp_Object saved_object
;
12610 enum display_element_type saved_what
= it
->what
;
12611 int saved_face_id
= it
->face_id
;
12613 saved_object
= it
->object
;
12614 saved_pos
= it
->position
;
12616 it
->what
= IT_CHARACTER
;
12617 bzero (&it
->position
, sizeof it
->position
);
12618 it
->object
= make_number (0);
12621 it
->face_id
= face
->id
;
12623 PRODUCE_GLYPHS (it
);
12625 while (it
->current_x
<= it
->last_visible_x
)
12626 PRODUCE_GLYPHS (it
);
12628 /* Don't count these blanks really. It would let us insert a left
12629 truncation glyph below and make us set the cursor on them, maybe. */
12630 it
->current_x
= saved_x
;
12631 it
->object
= saved_object
;
12632 it
->position
= saved_pos
;
12633 it
->what
= saved_what
;
12634 it
->face_id
= saved_face_id
;
12639 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12640 trailing whitespace. */
12643 trailing_whitespace_p (charpos
)
12646 int bytepos
= CHAR_TO_BYTE (charpos
);
12649 while (bytepos
< ZV_BYTE
12650 && (c
= FETCH_CHAR (bytepos
),
12651 c
== ' ' || c
== '\t'))
12654 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12656 if (bytepos
!= PT_BYTE
)
12663 /* Highlight trailing whitespace, if any, in ROW. */
12666 highlight_trailing_whitespace (f
, row
)
12668 struct glyph_row
*row
;
12670 int used
= row
->used
[TEXT_AREA
];
12674 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12675 struct glyph
*glyph
= start
+ used
- 1;
12677 /* Skip over glyphs inserted to display the cursor at the
12678 end of a line, for extending the face of the last glyph
12679 to the end of the line on terminals, and for truncation
12680 and continuation glyphs. */
12681 while (glyph
>= start
12682 && glyph
->type
== CHAR_GLYPH
12683 && INTEGERP (glyph
->object
))
12686 /* If last glyph is a space or stretch, and it's trailing
12687 whitespace, set the face of all trailing whitespace glyphs in
12688 IT->glyph_row to `trailing-whitespace'. */
12690 && BUFFERP (glyph
->object
)
12691 && (glyph
->type
== STRETCH_GLYPH
12692 || (glyph
->type
== CHAR_GLYPH
12693 && glyph
->u
.ch
== ' '))
12694 && trailing_whitespace_p (glyph
->charpos
))
12696 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12698 while (glyph
>= start
12699 && BUFFERP (glyph
->object
)
12700 && (glyph
->type
== STRETCH_GLYPH
12701 || (glyph
->type
== CHAR_GLYPH
12702 && glyph
->u
.ch
== ' ')))
12703 (glyph
--)->face_id
= face_id
;
12709 /* Value is non-zero if glyph row ROW in window W should be
12710 used to hold the cursor. */
12713 cursor_row_p (w
, row
)
12715 struct glyph_row
*row
;
12717 int cursor_row_p
= 1;
12719 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12721 /* If the row ends with a newline from a string, we don't want
12722 the cursor there (if the row is continued it doesn't end in a
12724 if (CHARPOS (row
->end
.string_pos
) >= 0
12725 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12726 cursor_row_p
= row
->continued_p
;
12728 /* If the row ends at ZV, display the cursor at the end of that
12729 row instead of at the start of the row below. */
12730 else if (row
->ends_at_zv_p
)
12736 return cursor_row_p
;
12740 /* Construct the glyph row IT->glyph_row in the desired matrix of
12741 IT->w from text at the current position of IT. See dispextern.h
12742 for an overview of struct it. Value is non-zero if
12743 IT->glyph_row displays text, as opposed to a line displaying ZV
12750 struct glyph_row
*row
= it
->glyph_row
;
12752 /* We always start displaying at hpos zero even if hscrolled. */
12753 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12755 /* We must not display in a row that's not a text row. */
12756 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12757 < it
->w
->desired_matrix
->nrows
);
12759 /* Is IT->w showing the region? */
12760 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12762 /* Clear the result glyph row and enable it. */
12763 prepare_desired_row (row
);
12765 row
->y
= it
->current_y
;
12766 row
->start
= it
->current
;
12767 row
->continuation_lines_width
= it
->continuation_lines_width
;
12768 row
->displays_text_p
= 1;
12769 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12770 it
->starts_in_middle_of_char_p
= 0;
12772 /* Arrange the overlays nicely for our purposes. Usually, we call
12773 display_line on only one line at a time, in which case this
12774 can't really hurt too much, or we call it on lines which appear
12775 one after another in the buffer, in which case all calls to
12776 recenter_overlay_lists but the first will be pretty cheap. */
12777 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12779 /* Move over display elements that are not visible because we are
12780 hscrolled. This may stop at an x-position < IT->first_visible_x
12781 if the first glyph is partially visible or if we hit a line end. */
12782 if (it
->current_x
< it
->first_visible_x
)
12783 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12784 MOVE_TO_POS
| MOVE_TO_X
);
12786 /* Get the initial row height. This is either the height of the
12787 text hscrolled, if there is any, or zero. */
12788 row
->ascent
= it
->max_ascent
;
12789 row
->height
= it
->max_ascent
+ it
->max_descent
;
12790 row
->phys_ascent
= it
->max_phys_ascent
;
12791 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12793 /* Loop generating characters. The loop is left with IT on the next
12794 character to display. */
12797 int n_glyphs_before
, hpos_before
, x_before
;
12799 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12801 /* Retrieve the next thing to display. Value is zero if end of
12803 if (!get_next_display_element (it
))
12805 /* Maybe add a space at the end of this line that is used to
12806 display the cursor there under X. Set the charpos of the
12807 first glyph of blank lines not corresponding to any text
12809 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12810 || row
->used
[TEXT_AREA
] == 0)
12812 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12813 row
->displays_text_p
= 0;
12815 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
12816 && (!MINI_WINDOW_P (it
->w
)
12817 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
12818 row
->indicate_empty_line_p
= 1;
12821 it
->continuation_lines_width
= 0;
12822 row
->ends_at_zv_p
= 1;
12826 /* Now, get the metrics of what we want to display. This also
12827 generates glyphs in `row' (which is IT->glyph_row). */
12828 n_glyphs_before
= row
->used
[TEXT_AREA
];
12831 /* Remember the line height so far in case the next element doesn't
12832 fit on the line. */
12833 if (!it
->truncate_lines_p
)
12835 ascent
= it
->max_ascent
;
12836 descent
= it
->max_descent
;
12837 phys_ascent
= it
->max_phys_ascent
;
12838 phys_descent
= it
->max_phys_descent
;
12841 PRODUCE_GLYPHS (it
);
12843 /* If this display element was in marginal areas, continue with
12845 if (it
->area
!= TEXT_AREA
)
12847 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12848 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12849 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12850 row
->phys_height
= max (row
->phys_height
,
12851 it
->max_phys_ascent
+ it
->max_phys_descent
);
12852 set_iterator_to_next (it
, 1);
12856 /* Does the display element fit on the line? If we truncate
12857 lines, we should draw past the right edge of the window. If
12858 we don't truncate, we want to stop so that we can display the
12859 continuation glyph before the right margin. If lines are
12860 continued, there are two possible strategies for characters
12861 resulting in more than 1 glyph (e.g. tabs): Display as many
12862 glyphs as possible in this line and leave the rest for the
12863 continuation line, or display the whole element in the next
12864 line. Original redisplay did the former, so we do it also. */
12865 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12866 hpos_before
= it
->hpos
;
12869 if (/* Not a newline. */
12871 /* Glyphs produced fit entirely in the line. */
12872 && it
->current_x
< it
->last_visible_x
)
12874 it
->hpos
+= nglyphs
;
12875 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12876 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12877 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12878 row
->phys_height
= max (row
->phys_height
,
12879 it
->max_phys_ascent
+ it
->max_phys_descent
);
12880 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
12881 row
->x
= x
- it
->first_visible_x
;
12886 struct glyph
*glyph
;
12888 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
12890 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12891 new_x
= x
+ glyph
->pixel_width
;
12893 if (/* Lines are continued. */
12894 !it
->truncate_lines_p
12895 && (/* Glyph doesn't fit on the line. */
12896 new_x
> it
->last_visible_x
12897 /* Or it fits exactly on a window system frame. */
12898 || (new_x
== it
->last_visible_x
12899 && FRAME_WINDOW_P (it
->f
))))
12901 /* End of a continued line. */
12904 || (new_x
== it
->last_visible_x
12905 && FRAME_WINDOW_P (it
->f
)))
12907 /* Current glyph is the only one on the line or
12908 fits exactly on the line. We must continue
12909 the line because we can't draw the cursor
12910 after the glyph. */
12911 row
->continued_p
= 1;
12912 it
->current_x
= new_x
;
12913 it
->continuation_lines_width
+= new_x
;
12915 if (i
== nglyphs
- 1)
12916 set_iterator_to_next (it
, 1);
12918 else if (CHAR_GLYPH_PADDING_P (*glyph
)
12919 && !FRAME_WINDOW_P (it
->f
))
12921 /* A padding glyph that doesn't fit on this line.
12922 This means the whole character doesn't fit
12924 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12926 /* Fill the rest of the row with continuation
12927 glyphs like in 20.x. */
12928 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
12929 < row
->glyphs
[1 + TEXT_AREA
])
12930 produce_special_glyphs (it
, IT_CONTINUATION
);
12932 row
->continued_p
= 1;
12933 it
->current_x
= x_before
;
12934 it
->continuation_lines_width
+= x_before
;
12936 /* Restore the height to what it was before the
12937 element not fitting on the line. */
12938 it
->max_ascent
= ascent
;
12939 it
->max_descent
= descent
;
12940 it
->max_phys_ascent
= phys_ascent
;
12941 it
->max_phys_descent
= phys_descent
;
12943 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
12945 /* A TAB that extends past the right edge of the
12946 window. This produces a single glyph on
12947 window system frames. We leave the glyph in
12948 this row and let it fill the row, but don't
12949 consume the TAB. */
12950 it
->continuation_lines_width
+= it
->last_visible_x
;
12951 row
->ends_in_middle_of_char_p
= 1;
12952 row
->continued_p
= 1;
12953 glyph
->pixel_width
= it
->last_visible_x
- x
;
12954 it
->starts_in_middle_of_char_p
= 1;
12958 /* Something other than a TAB that draws past
12959 the right edge of the window. Restore
12960 positions to values before the element. */
12961 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12963 /* Display continuation glyphs. */
12964 if (!FRAME_WINDOW_P (it
->f
))
12965 produce_special_glyphs (it
, IT_CONTINUATION
);
12966 row
->continued_p
= 1;
12968 it
->continuation_lines_width
+= x
;
12970 if (nglyphs
> 1 && i
> 0)
12972 row
->ends_in_middle_of_char_p
= 1;
12973 it
->starts_in_middle_of_char_p
= 1;
12976 /* Restore the height to what it was before the
12977 element not fitting on the line. */
12978 it
->max_ascent
= ascent
;
12979 it
->max_descent
= descent
;
12980 it
->max_phys_ascent
= phys_ascent
;
12981 it
->max_phys_descent
= phys_descent
;
12986 else if (new_x
> it
->first_visible_x
)
12988 /* Increment number of glyphs actually displayed. */
12991 if (x
< it
->first_visible_x
)
12992 /* Glyph is partially visible, i.e. row starts at
12993 negative X position. */
12994 row
->x
= x
- it
->first_visible_x
;
12998 /* Glyph is completely off the left margin of the
12999 window. This should not happen because of the
13000 move_it_in_display_line at the start of
13006 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13007 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13008 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13009 row
->phys_height
= max (row
->phys_height
,
13010 it
->max_phys_ascent
+ it
->max_phys_descent
);
13012 /* End of this display line if row is continued. */
13013 if (row
->continued_p
)
13017 /* Is this a line end? If yes, we're also done, after making
13018 sure that a non-default face is extended up to the right
13019 margin of the window. */
13020 if (ITERATOR_AT_END_OF_LINE_P (it
))
13022 int used_before
= row
->used
[TEXT_AREA
];
13024 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13026 /* Add a space at the end of the line that is used to
13027 display the cursor there. */
13028 append_space (it
, 0);
13030 /* Extend the face to the end of the line. */
13031 extend_face_to_end_of_line (it
);
13033 /* Make sure we have the position. */
13034 if (used_before
== 0)
13035 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13037 /* Consume the line end. This skips over invisible lines. */
13038 set_iterator_to_next (it
, 1);
13039 it
->continuation_lines_width
= 0;
13043 /* Proceed with next display element. Note that this skips
13044 over lines invisible because of selective display. */
13045 set_iterator_to_next (it
, 1);
13047 /* If we truncate lines, we are done when the last displayed
13048 glyphs reach past the right margin of the window. */
13049 if (it
->truncate_lines_p
13050 && (FRAME_WINDOW_P (it
->f
)
13051 ? (it
->current_x
>= it
->last_visible_x
)
13052 : (it
->current_x
> it
->last_visible_x
)))
13054 /* Maybe add truncation glyphs. */
13055 if (!FRAME_WINDOW_P (it
->f
))
13059 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13060 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13063 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13065 row
->used
[TEXT_AREA
] = i
;
13066 produce_special_glyphs (it
, IT_TRUNCATION
);
13070 row
->truncated_on_right_p
= 1;
13071 it
->continuation_lines_width
= 0;
13072 reseat_at_next_visible_line_start (it
, 0);
13073 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13074 it
->hpos
= hpos_before
;
13075 it
->current_x
= x_before
;
13080 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13081 at the left window margin. */
13082 if (it
->first_visible_x
13083 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13085 if (!FRAME_WINDOW_P (it
->f
))
13086 insert_left_trunc_glyphs (it
);
13087 row
->truncated_on_left_p
= 1;
13090 /* If the start of this line is the overlay arrow-position, then
13091 mark this glyph row as the one containing the overlay arrow.
13092 This is clearly a mess with variable size fonts. It would be
13093 better to let it be displayed like cursors under X. */
13094 if (MARKERP (Voverlay_arrow_position
)
13095 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13096 && (MATRIX_ROW_START_CHARPOS (row
)
13097 == marker_position (Voverlay_arrow_position
))
13098 && STRINGP (Voverlay_arrow_string
)
13099 && ! overlay_arrow_seen
)
13101 /* Overlay arrow in window redisplay is a fringe bitmap. */
13102 if (!FRAME_WINDOW_P (it
->f
))
13104 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13105 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13106 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13107 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13108 struct glyph
*p2
, *end
;
13110 /* Copy the arrow glyphs. */
13111 while (glyph
< arrow_end
)
13114 /* Throw away padding glyphs. */
13116 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13117 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13123 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13127 overlay_arrow_seen
= 1;
13128 row
->overlay_arrow_p
= 1;
13131 /* Compute pixel dimensions of this line. */
13132 compute_line_metrics (it
);
13134 /* Remember the position at which this line ends. */
13135 row
->end
= it
->current
;
13137 /* Maybe set the cursor. */
13138 if (it
->w
->cursor
.vpos
< 0
13139 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13140 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13141 && cursor_row_p (it
->w
, row
))
13142 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13144 /* Highlight trailing whitespace. */
13145 if (!NILP (Vshow_trailing_whitespace
))
13146 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13148 /* Prepare for the next line. This line starts horizontally at (X
13149 HPOS) = (0 0). Vertical positions are incremented. As a
13150 convenience for the caller, IT->glyph_row is set to the next
13152 it
->current_x
= it
->hpos
= 0;
13153 it
->current_y
+= row
->height
;
13156 return row
->displays_text_p
;
13161 /***********************************************************************
13163 ***********************************************************************/
13165 /* Redisplay the menu bar in the frame for window W.
13167 The menu bar of X frames that don't have X toolkit support is
13168 displayed in a special window W->frame->menu_bar_window.
13170 The menu bar of terminal frames is treated specially as far as
13171 glyph matrices are concerned. Menu bar lines are not part of
13172 windows, so the update is done directly on the frame matrix rows
13173 for the menu bar. */
13176 display_menu_bar (w
)
13179 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13184 /* Don't do all this for graphical frames. */
13186 if (!NILP (Vwindow_system
))
13189 #ifdef USE_X_TOOLKIT
13194 if (FRAME_MAC_P (f
))
13198 #ifdef USE_X_TOOLKIT
13199 xassert (!FRAME_WINDOW_P (f
));
13200 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13201 it
.first_visible_x
= 0;
13202 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13203 #else /* not USE_X_TOOLKIT */
13204 if (FRAME_WINDOW_P (f
))
13206 /* Menu bar lines are displayed in the desired matrix of the
13207 dummy window menu_bar_window. */
13208 struct window
*menu_w
;
13209 xassert (WINDOWP (f
->menu_bar_window
));
13210 menu_w
= XWINDOW (f
->menu_bar_window
);
13211 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13213 it
.first_visible_x
= 0;
13214 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13218 /* This is a TTY frame, i.e. character hpos/vpos are used as
13220 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13222 it
.first_visible_x
= 0;
13223 it
.last_visible_x
= FRAME_WIDTH (f
);
13225 #endif /* not USE_X_TOOLKIT */
13227 if (! mode_line_inverse_video
)
13228 /* Force the menu-bar to be displayed in the default face. */
13229 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13231 /* Clear all rows of the menu bar. */
13232 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13234 struct glyph_row
*row
= it
.glyph_row
+ i
;
13235 clear_glyph_row (row
);
13236 row
->enabled_p
= 1;
13237 row
->full_width_p
= 1;
13240 /* Display all items of the menu bar. */
13241 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13242 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13244 Lisp_Object string
;
13246 /* Stop at nil string. */
13247 string
= AREF (items
, i
+ 1);
13251 /* Remember where item was displayed. */
13252 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13254 /* Display the item, pad with one space. */
13255 if (it
.current_x
< it
.last_visible_x
)
13256 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13257 XSTRING (string
)->size
+ 1, 0, 0, -1);
13260 /* Fill out the line with spaces. */
13261 if (it
.current_x
< it
.last_visible_x
)
13262 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13264 /* Compute the total height of the lines. */
13265 compute_line_metrics (&it
);
13270 /***********************************************************************
13272 ***********************************************************************/
13274 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13275 FORCE is non-zero, redisplay mode lines unconditionally.
13276 Otherwise, redisplay only mode lines that are garbaged. Value is
13277 the number of windows whose mode lines were redisplayed. */
13280 redisplay_mode_lines (window
, force
)
13281 Lisp_Object window
;
13286 while (!NILP (window
))
13288 struct window
*w
= XWINDOW (window
);
13290 if (WINDOWP (w
->hchild
))
13291 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13292 else if (WINDOWP (w
->vchild
))
13293 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13295 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13296 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13298 struct text_pos lpoint
;
13299 struct buffer
*old
= current_buffer
;
13301 /* Set the window's buffer for the mode line display. */
13302 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13303 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13305 /* Point refers normally to the selected window. For any
13306 other window, set up appropriate value. */
13307 if (!EQ (window
, selected_window
))
13309 struct text_pos pt
;
13311 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13312 if (CHARPOS (pt
) < BEGV
)
13313 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13314 else if (CHARPOS (pt
) > (ZV
- 1))
13315 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13317 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13320 /* Display mode lines. */
13321 clear_glyph_matrix (w
->desired_matrix
);
13322 if (display_mode_lines (w
))
13325 w
->must_be_updated_p
= 1;
13328 /* Restore old settings. */
13329 set_buffer_internal_1 (old
);
13330 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13340 /* Display the mode and/or top line of window W. Value is the number
13341 of mode lines displayed. */
13344 display_mode_lines (w
)
13347 Lisp_Object old_selected_window
, old_selected_frame
;
13350 old_selected_frame
= selected_frame
;
13351 selected_frame
= w
->frame
;
13352 old_selected_window
= selected_window
;
13353 XSETWINDOW (selected_window
, w
);
13355 /* These will be set while the mode line specs are processed. */
13356 line_number_displayed
= 0;
13357 w
->column_number_displayed
= Qnil
;
13359 if (WINDOW_WANTS_MODELINE_P (w
))
13361 display_mode_line (w
, MODE_LINE_FACE_ID
,
13362 current_buffer
->mode_line_format
);
13366 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13368 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13369 current_buffer
->header_line_format
);
13373 selected_frame
= old_selected_frame
;
13374 selected_window
= old_selected_window
;
13379 /* Display mode or top line of window W. FACE_ID specifies which line
13380 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13381 FORMAT is the mode line format to display. Value is the pixel
13382 height of the mode line displayed. */
13385 display_mode_line (w
, face_id
, format
)
13387 enum face_id face_id
;
13388 Lisp_Object format
;
13393 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13394 prepare_desired_row (it
.glyph_row
);
13396 if (! mode_line_inverse_video
)
13397 /* Force the mode-line to be displayed in the default face. */
13398 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13400 /* Temporarily make frame's keyboard the current kboard so that
13401 kboard-local variables in the mode_line_format will get the right
13403 push_frame_kboard (it
.f
);
13404 display_mode_element (&it
, 0, 0, 0, format
);
13405 pop_frame_kboard ();
13407 /* Fill up with spaces. */
13408 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13410 compute_line_metrics (&it
);
13411 it
.glyph_row
->full_width_p
= 1;
13412 it
.glyph_row
->mode_line_p
= 1;
13413 it
.glyph_row
->continued_p
= 0;
13414 it
.glyph_row
->truncated_on_left_p
= 0;
13415 it
.glyph_row
->truncated_on_right_p
= 0;
13417 /* Make a 3D mode-line have a shadow at its right end. */
13418 face
= FACE_FROM_ID (it
.f
, face_id
);
13419 extend_face_to_end_of_line (&it
);
13420 if (face
->box
!= FACE_NO_BOX
)
13422 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13423 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13424 last
->right_box_line_p
= 1;
13427 return it
.glyph_row
->height
;
13431 /* Contribute ELT to the mode line for window IT->w. How it
13432 translates into text depends on its data type.
13434 IT describes the display environment in which we display, as usual.
13436 DEPTH is the depth in recursion. It is used to prevent
13437 infinite recursion here.
13439 FIELD_WIDTH is the number of characters the display of ELT should
13440 occupy in the mode line, and PRECISION is the maximum number of
13441 characters to display from ELT's representation. See
13442 display_string for details. *
13444 Returns the hpos of the end of the text generated by ELT. */
13447 display_mode_element (it
, depth
, field_width
, precision
, elt
)
13450 int field_width
, precision
;
13453 int n
= 0, field
, prec
;
13461 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13465 /* A string: output it and check for %-constructs within it. */
13467 unsigned char *this = XSTRING (elt
)->data
;
13468 unsigned char *lisp_string
= this;
13470 while ((precision
<= 0 || n
< precision
)
13472 && (frame_title_ptr
13473 || it
->current_x
< it
->last_visible_x
))
13475 unsigned char *last
= this;
13477 /* Advance to end of string or next format specifier. */
13478 while ((c
= *this++) != '\0' && c
!= '%')
13481 if (this - 1 != last
)
13483 /* Output to end of string or up to '%'. Field width
13484 is length of string. Don't output more than
13485 PRECISION allows us. */
13488 prec
= chars_in_text (last
, this - last
);
13489 if (precision
> 0 && prec
> precision
- n
)
13490 prec
= precision
- n
;
13492 if (frame_title_ptr
)
13493 n
+= store_frame_title (last
, 0, prec
);
13496 int bytepos
= last
- lisp_string
;
13497 int charpos
= string_byte_to_char (elt
, bytepos
);
13498 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
13500 STRING_MULTIBYTE (elt
));
13503 else /* c == '%' */
13505 unsigned char *percent_position
= this;
13507 /* Get the specified minimum width. Zero means
13510 while ((c
= *this++) >= '0' && c
<= '9')
13511 field
= field
* 10 + c
- '0';
13513 /* Don't pad beyond the total padding allowed. */
13514 if (field_width
- n
> 0 && field
> field_width
- n
)
13515 field
= field_width
- n
;
13517 /* Note that either PRECISION <= 0 or N < PRECISION. */
13518 prec
= precision
- n
;
13521 n
+= display_mode_element (it
, depth
, field
, prec
,
13522 Vglobal_mode_string
);
13526 unsigned char *spec
13527 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
13529 if (frame_title_ptr
)
13530 n
+= store_frame_title (spec
, field
, prec
);
13533 int nglyphs_before
, bytepos
, charpos
, nwritten
;
13535 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13536 bytepos
= percent_position
- XSTRING (elt
)->data
;
13537 charpos
= (multibyte
13538 ? string_byte_to_char (elt
, bytepos
)
13540 nwritten
= display_string (spec
, Qnil
, elt
,
13545 /* Assign to the glyphs written above the
13546 string where the `%x' came from, position
13550 struct glyph
*glyph
13551 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13555 for (i
= 0; i
< nwritten
; ++i
)
13557 glyph
[i
].object
= elt
;
13558 glyph
[i
].charpos
= charpos
;
13571 /* A symbol: process the value of the symbol recursively
13572 as if it appeared here directly. Avoid error if symbol void.
13573 Special case: if value of symbol is a string, output the string
13576 register Lisp_Object tem
;
13577 tem
= Fboundp (elt
);
13580 tem
= Fsymbol_value (elt
);
13581 /* If value is a string, output that string literally:
13582 don't check for % within it. */
13585 prec
= precision
- n
;
13586 if (frame_title_ptr
)
13587 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
13589 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
13590 0, prec
, 0, STRING_MULTIBYTE (tem
));
13592 else if (!EQ (tem
, elt
))
13594 /* Give up right away for nil or t. */
13604 register Lisp_Object car
, tem
;
13606 /* A cons cell: three distinct cases.
13607 If first element is a string or a cons, process all the elements
13608 and effectively concatenate them.
13609 If first element is a negative number, truncate displaying cdr to
13610 at most that many characters. If positive, pad (with spaces)
13611 to at least that many characters.
13612 If first element is a symbol, process the cadr or caddr recursively
13613 according to whether the symbol's value is non-nil or nil. */
13615 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
13617 /* An element of the form (:eval FORM) means evaluate FORM
13618 and use the result as mode line elements. */
13619 struct gcpro gcpro1
;
13622 spec
= safe_eval (XCAR (XCDR (elt
)));
13624 n
+= display_mode_element (it
, depth
, field_width
- n
,
13625 precision
- n
, spec
);
13628 else if (SYMBOLP (car
))
13630 tem
= Fboundp (car
);
13634 /* elt is now the cdr, and we know it is a cons cell.
13635 Use its car if CAR has a non-nil value. */
13638 tem
= Fsymbol_value (car
);
13645 /* Symbol's value is nil (or symbol is unbound)
13646 Get the cddr of the original list
13647 and if possible find the caddr and use that. */
13651 else if (!CONSP (elt
))
13656 else if (INTEGERP (car
))
13658 register int lim
= XINT (car
);
13662 /* Negative int means reduce maximum width. */
13663 if (precision
<= 0)
13666 precision
= min (precision
, -lim
);
13670 /* Padding specified. Don't let it be more than
13671 current maximum. */
13673 lim
= min (precision
, lim
);
13675 /* If that's more padding than already wanted, queue it.
13676 But don't reduce padding already specified even if
13677 that is beyond the current truncation point. */
13678 field_width
= max (lim
, field_width
);
13682 else if (STRINGP (car
) || CONSP (car
))
13684 register int limit
= 50;
13685 /* Limit is to protect against circular lists. */
13688 && (precision
<= 0 || n
< precision
))
13690 n
+= display_mode_element (it
, depth
, field_width
- n
,
13691 precision
- n
, XCAR (elt
));
13700 if (frame_title_ptr
)
13701 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13703 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13704 precision
- n
, 0, 0);
13708 /* Pad to FIELD_WIDTH. */
13709 if (field_width
> 0 && n
< field_width
)
13711 if (frame_title_ptr
)
13712 n
+= store_frame_title ("", field_width
- n
, 0);
13714 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13722 /* Write a null-terminated, right justified decimal representation of
13723 the positive integer D to BUF using a minimal field width WIDTH. */
13726 pint2str (buf
, width
, d
)
13727 register char *buf
;
13728 register int width
;
13731 register char *p
= buf
;
13739 *p
++ = d
% 10 + '0';
13744 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13755 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13756 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13757 type of CODING_SYSTEM. Return updated pointer into BUF. */
13759 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13762 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13763 Lisp_Object coding_system
;
13764 register char *buf
;
13768 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13769 unsigned char *eol_str
;
13771 /* The EOL conversion we are using. */
13772 Lisp_Object eoltype
;
13774 val
= Fget (coding_system
, Qcoding_system
);
13777 if (!VECTORP (val
)) /* Not yet decided. */
13782 eoltype
= eol_mnemonic_undecided
;
13783 /* Don't mention EOL conversion if it isn't decided. */
13787 Lisp_Object eolvalue
;
13789 eolvalue
= Fget (coding_system
, Qeol_type
);
13792 *buf
++ = XFASTINT (AREF (val
, 1));
13796 /* The EOL conversion that is normal on this system. */
13798 if (NILP (eolvalue
)) /* Not yet decided. */
13799 eoltype
= eol_mnemonic_undecided
;
13800 else if (VECTORP (eolvalue
)) /* Not yet decided. */
13801 eoltype
= eol_mnemonic_undecided
;
13802 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
13803 eoltype
= (XFASTINT (eolvalue
) == 0
13804 ? eol_mnemonic_unix
13805 : (XFASTINT (eolvalue
) == 1
13806 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
13812 /* Mention the EOL conversion if it is not the usual one. */
13813 if (STRINGP (eoltype
))
13815 eol_str
= XSTRING (eoltype
)->data
;
13816 eol_str_len
= XSTRING (eoltype
)->size
;
13818 else if (INTEGERP (eoltype
)
13819 && CHAR_VALID_P (XINT (eoltype
), 0))
13821 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
13822 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
13826 eol_str
= invalid_eol_type
;
13827 eol_str_len
= sizeof (invalid_eol_type
) - 1;
13829 bcopy (eol_str
, buf
, eol_str_len
);
13830 buf
+= eol_str_len
;
13836 /* Return a string for the output of a mode line %-spec for window W,
13837 generated by character C. PRECISION >= 0 means don't return a
13838 string longer than that value. FIELD_WIDTH > 0 means pad the
13839 string returned with spaces to that value. Return 1 in *MULTIBYTE
13840 if the result is multibyte text. */
13842 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
13845 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
13848 int field_width
, precision
;
13852 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13853 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
13854 struct buffer
*b
= XBUFFER (w
->buffer
);
13862 if (!NILP (b
->read_only
))
13864 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13869 /* This differs from %* only for a modified read-only buffer. */
13870 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13872 if (!NILP (b
->read_only
))
13877 /* This differs from %* in ignoring read-only-ness. */
13878 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13890 if (command_loop_level
> 5)
13892 p
= decode_mode_spec_buf
;
13893 for (i
= 0; i
< command_loop_level
; i
++)
13896 return decode_mode_spec_buf
;
13904 if (command_loop_level
> 5)
13906 p
= decode_mode_spec_buf
;
13907 for (i
= 0; i
< command_loop_level
; i
++)
13910 return decode_mode_spec_buf
;
13917 /* Let lots_of_dashes be a string of infinite length. */
13918 if (field_width
<= 0
13919 || field_width
> sizeof (lots_of_dashes
))
13921 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
13922 decode_mode_spec_buf
[i
] = '-';
13923 decode_mode_spec_buf
[i
] = '\0';
13924 return decode_mode_spec_buf
;
13927 return lots_of_dashes
;
13936 int col
= current_column ();
13937 w
->column_number_displayed
= make_number (col
);
13938 pint2str (decode_mode_spec_buf
, field_width
, col
);
13939 return decode_mode_spec_buf
;
13943 /* %F displays the frame name. */
13944 if (!NILP (f
->title
))
13945 return (char *) XSTRING (f
->title
)->data
;
13946 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
13947 return (char *) XSTRING (f
->name
)->data
;
13956 int startpos
= XMARKER (w
->start
)->charpos
;
13957 int startpos_byte
= marker_byte_position (w
->start
);
13958 int line
, linepos
, linepos_byte
, topline
;
13960 int height
= XFASTINT (w
->height
);
13962 /* If we decided that this buffer isn't suitable for line numbers,
13963 don't forget that too fast. */
13964 if (EQ (w
->base_line_pos
, w
->buffer
))
13966 /* But do forget it, if the window shows a different buffer now. */
13967 else if (BUFFERP (w
->base_line_pos
))
13968 w
->base_line_pos
= Qnil
;
13970 /* If the buffer is very big, don't waste time. */
13971 if (INTEGERP (Vline_number_display_limit
)
13972 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
13974 w
->base_line_pos
= Qnil
;
13975 w
->base_line_number
= Qnil
;
13979 if (!NILP (w
->base_line_number
)
13980 && !NILP (w
->base_line_pos
)
13981 && XFASTINT (w
->base_line_pos
) <= startpos
)
13983 line
= XFASTINT (w
->base_line_number
);
13984 linepos
= XFASTINT (w
->base_line_pos
);
13985 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
13990 linepos
= BUF_BEGV (b
);
13991 linepos_byte
= BUF_BEGV_BYTE (b
);
13994 /* Count lines from base line to window start position. */
13995 nlines
= display_count_lines (linepos
, linepos_byte
,
13999 topline
= nlines
+ line
;
14001 /* Determine a new base line, if the old one is too close
14002 or too far away, or if we did not have one.
14003 "Too close" means it's plausible a scroll-down would
14004 go back past it. */
14005 if (startpos
== BUF_BEGV (b
))
14007 w
->base_line_number
= make_number (topline
);
14008 w
->base_line_pos
= make_number (BUF_BEGV (b
));
14010 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
14011 || linepos
== BUF_BEGV (b
))
14013 int limit
= BUF_BEGV (b
);
14014 int limit_byte
= BUF_BEGV_BYTE (b
);
14016 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
14018 if (startpos
- distance
> limit
)
14020 limit
= startpos
- distance
;
14021 limit_byte
= CHAR_TO_BYTE (limit
);
14024 nlines
= display_count_lines (startpos
, startpos_byte
,
14026 - (height
* 2 + 30),
14028 /* If we couldn't find the lines we wanted within
14029 line_number_display_limit_width chars per line,
14030 give up on line numbers for this window. */
14031 if (position
== limit_byte
&& limit
== startpos
- distance
)
14033 w
->base_line_pos
= w
->buffer
;
14034 w
->base_line_number
= Qnil
;
14038 w
->base_line_number
= make_number (topline
- nlines
);
14039 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
14042 /* Now count lines from the start pos to point. */
14043 nlines
= display_count_lines (startpos
, startpos_byte
,
14044 PT_BYTE
, PT
, &junk
);
14046 /* Record that we did display the line number. */
14047 line_number_displayed
= 1;
14049 /* Make the string to show. */
14050 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
14051 return decode_mode_spec_buf
;
14054 char* p
= decode_mode_spec_buf
;
14055 int pad
= field_width
- 2;
14061 return decode_mode_spec_buf
;
14067 obj
= b
->mode_name
;
14071 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
14077 int pos
= marker_position (w
->start
);
14078 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14080 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
14082 if (pos
<= BUF_BEGV (b
))
14087 else if (pos
<= BUF_BEGV (b
))
14091 if (total
> 1000000)
14092 /* Do it differently for a large value, to avoid overflow. */
14093 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14095 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14096 /* We can't normally display a 3-digit number,
14097 so get us a 2-digit number that is close. */
14100 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14101 return decode_mode_spec_buf
;
14105 /* Display percentage of size above the bottom of the screen. */
14108 int toppos
= marker_position (w
->start
);
14109 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14110 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14112 if (botpos
>= BUF_ZV (b
))
14114 if (toppos
<= BUF_BEGV (b
))
14121 if (total
> 1000000)
14122 /* Do it differently for a large value, to avoid overflow. */
14123 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14125 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14126 /* We can't normally display a 3-digit number,
14127 so get us a 2-digit number that is close. */
14130 if (toppos
<= BUF_BEGV (b
))
14131 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14133 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14134 return decode_mode_spec_buf
;
14139 /* status of process */
14140 obj
= Fget_buffer_process (w
->buffer
);
14142 return "no process";
14143 #ifdef subprocesses
14144 obj
= Fsymbol_name (Fprocess_status (obj
));
14148 case 't': /* indicate TEXT or BINARY */
14149 #ifdef MODE_LINE_BINARY_TEXT
14150 return MODE_LINE_BINARY_TEXT (b
);
14156 /* coding-system (not including end-of-line format) */
14158 /* coding-system (including end-of-line type) */
14160 int eol_flag
= (c
== 'Z');
14161 char *p
= decode_mode_spec_buf
;
14163 if (! FRAME_WINDOW_P (f
))
14165 /* No need to mention EOL here--the terminal never needs
14166 to do EOL conversion. */
14167 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14168 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14170 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14173 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14174 #ifdef subprocesses
14175 obj
= Fget_buffer_process (Fcurrent_buffer ());
14176 if (PROCESSP (obj
))
14178 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14180 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14183 #endif /* subprocesses */
14186 return decode_mode_spec_buf
;
14192 *multibyte
= STRING_MULTIBYTE (obj
);
14193 return (char *) XSTRING (obj
)->data
;
14200 /* Count up to COUNT lines starting from START / START_BYTE.
14201 But don't go beyond LIMIT_BYTE.
14202 Return the number of lines thus found (always nonnegative).
14204 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14207 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14208 int start
, start_byte
, limit_byte
, count
;
14211 register unsigned char *cursor
;
14212 unsigned char *base
;
14214 register int ceiling
;
14215 register unsigned char *ceiling_addr
;
14216 int orig_count
= count
;
14218 /* If we are not in selective display mode,
14219 check only for newlines. */
14220 int selective_display
= (!NILP (current_buffer
->selective_display
)
14221 && !INTEGERP (current_buffer
->selective_display
));
14225 while (start_byte
< limit_byte
)
14227 ceiling
= BUFFER_CEILING_OF (start_byte
);
14228 ceiling
= min (limit_byte
- 1, ceiling
);
14229 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14230 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14233 if (selective_display
)
14234 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14237 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14240 if (cursor
!= ceiling_addr
)
14244 start_byte
+= cursor
- base
+ 1;
14245 *byte_pos_ptr
= start_byte
;
14249 if (++cursor
== ceiling_addr
)
14255 start_byte
+= cursor
- base
;
14260 while (start_byte
> limit_byte
)
14262 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14263 ceiling
= max (limit_byte
, ceiling
);
14264 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14265 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14268 if (selective_display
)
14269 while (--cursor
!= ceiling_addr
14270 && *cursor
!= '\n' && *cursor
!= 015)
14273 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14276 if (cursor
!= ceiling_addr
)
14280 start_byte
+= cursor
- base
+ 1;
14281 *byte_pos_ptr
= start_byte
;
14282 /* When scanning backwards, we should
14283 not count the newline posterior to which we stop. */
14284 return - orig_count
- 1;
14290 /* Here we add 1 to compensate for the last decrement
14291 of CURSOR, which took it past the valid range. */
14292 start_byte
+= cursor
- base
+ 1;
14296 *byte_pos_ptr
= limit_byte
;
14299 return - orig_count
+ count
;
14300 return orig_count
- count
;
14306 /***********************************************************************
14308 ***********************************************************************/
14310 /* Display a NUL-terminated string, starting with index START.
14312 If STRING is non-null, display that C string. Otherwise, the Lisp
14313 string LISP_STRING is displayed.
14315 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14316 FACE_STRING. Display STRING or LISP_STRING with the face at
14317 FACE_STRING_POS in FACE_STRING:
14319 Display the string in the environment given by IT, but use the
14320 standard display table, temporarily.
14322 FIELD_WIDTH is the minimum number of output glyphs to produce.
14323 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14324 with spaces. If STRING has more characters, more than FIELD_WIDTH
14325 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14327 PRECISION is the maximum number of characters to output from
14328 STRING. PRECISION < 0 means don't truncate the string.
14330 This is roughly equivalent to printf format specifiers:
14332 FIELD_WIDTH PRECISION PRINTF
14333 ----------------------------------------
14339 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14340 display them, and < 0 means obey the current buffer's value of
14341 enable_multibyte_characters.
14343 Value is the number of glyphs produced. */
14346 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14347 start
, it
, field_width
, precision
, max_x
, multibyte
)
14348 unsigned char *string
;
14349 Lisp_Object lisp_string
;
14350 Lisp_Object face_string
;
14351 int face_string_pos
;
14354 int field_width
, precision
, max_x
;
14357 int hpos_at_start
= it
->hpos
;
14358 int saved_face_id
= it
->face_id
;
14359 struct glyph_row
*row
= it
->glyph_row
;
14361 /* Initialize the iterator IT for iteration over STRING beginning
14362 with index START. */
14363 reseat_to_string (it
, string
, lisp_string
, start
,
14364 precision
, field_width
, multibyte
);
14366 /* If displaying STRING, set up the face of the iterator
14367 from LISP_STRING, if that's given. */
14368 if (STRINGP (face_string
))
14374 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
14375 0, it
->region_beg_charpos
,
14376 it
->region_end_charpos
,
14377 &endptr
, it
->base_face_id
, 0);
14378 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14379 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
14382 /* Set max_x to the maximum allowed X position. Don't let it go
14383 beyond the right edge of the window. */
14385 max_x
= it
->last_visible_x
;
14387 max_x
= min (max_x
, it
->last_visible_x
);
14389 /* Skip over display elements that are not visible. because IT->w is
14391 if (it
->current_x
< it
->first_visible_x
)
14392 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
14393 MOVE_TO_POS
| MOVE_TO_X
);
14395 row
->ascent
= it
->max_ascent
;
14396 row
->height
= it
->max_ascent
+ it
->max_descent
;
14397 row
->phys_ascent
= it
->max_phys_ascent
;
14398 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14400 /* This condition is for the case that we are called with current_x
14401 past last_visible_x. */
14402 while (it
->current_x
< max_x
)
14404 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14406 /* Get the next display element. */
14407 if (!get_next_display_element (it
))
14410 /* Produce glyphs. */
14411 x_before
= it
->current_x
;
14412 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14413 PRODUCE_GLYPHS (it
);
14415 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14418 while (i
< nglyphs
)
14420 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14422 if (!it
->truncate_lines_p
14423 && x
+ glyph
->pixel_width
> max_x
)
14425 /* End of continued line or max_x reached. */
14426 if (CHAR_GLYPH_PADDING_P (*glyph
))
14428 /* A wide character is unbreakable. */
14429 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14430 it
->current_x
= x_before
;
14434 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14439 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
14441 /* Glyph is at least partially visible. */
14443 if (x
< it
->first_visible_x
)
14444 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14448 /* Glyph is off the left margin of the display area.
14449 Should not happen. */
14453 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14454 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14455 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14456 row
->phys_height
= max (row
->phys_height
,
14457 it
->max_phys_ascent
+ it
->max_phys_descent
);
14458 x
+= glyph
->pixel_width
;
14462 /* Stop if max_x reached. */
14466 /* Stop at line ends. */
14467 if (ITERATOR_AT_END_OF_LINE_P (it
))
14469 it
->continuation_lines_width
= 0;
14473 set_iterator_to_next (it
, 1);
14475 /* Stop if truncating at the right edge. */
14476 if (it
->truncate_lines_p
14477 && it
->current_x
>= it
->last_visible_x
)
14479 /* Add truncation mark, but don't do it if the line is
14480 truncated at a padding space. */
14481 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14483 if (!FRAME_WINDOW_P (it
->f
))
14487 if (it
->current_x
> it
->last_visible_x
)
14489 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14490 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14492 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14494 row
->used
[TEXT_AREA
] = i
;
14495 produce_special_glyphs (it
, IT_TRUNCATION
);
14498 produce_special_glyphs (it
, IT_TRUNCATION
);
14500 it
->glyph_row
->truncated_on_right_p
= 1;
14506 /* Maybe insert a truncation at the left. */
14507 if (it
->first_visible_x
14508 && IT_CHARPOS (*it
) > 0)
14510 if (!FRAME_WINDOW_P (it
->f
))
14511 insert_left_trunc_glyphs (it
);
14512 it
->glyph_row
->truncated_on_left_p
= 1;
14515 it
->face_id
= saved_face_id
;
14517 /* Value is number of columns displayed. */
14518 return it
->hpos
- hpos_at_start
;
14523 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
14524 appears as an element of LIST or as the car of an element of LIST.
14525 If PROPVAL is a list, compare each element against LIST in that
14526 way, and return 1/2 if any element of PROPVAL is found in LIST.
14527 Otherwise return 0. This function cannot quit.
14528 The return value is 2 if the text is invisible but with an ellipsis
14529 and 1 if it's invisible and without an ellipsis. */
14532 invisible_p (propval
, list
)
14533 register Lisp_Object propval
;
14536 register Lisp_Object tail
, proptail
;
14538 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14540 register Lisp_Object tem
;
14542 if (EQ (propval
, tem
))
14544 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14545 return NILP (XCDR (tem
)) ? 1 : 2;
14548 if (CONSP (propval
))
14550 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14552 Lisp_Object propelt
;
14553 propelt
= XCAR (proptail
);
14554 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14556 register Lisp_Object tem
;
14558 if (EQ (propelt
, tem
))
14560 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14561 return NILP (XCDR (tem
)) ? 1 : 2;
14570 /***********************************************************************
14572 ***********************************************************************/
14577 Vwith_echo_area_save_vector
= Qnil
;
14578 staticpro (&Vwith_echo_area_save_vector
);
14580 Vmessage_stack
= Qnil
;
14581 staticpro (&Vmessage_stack
);
14583 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14584 staticpro (&Qinhibit_redisplay
);
14587 defsubr (&Sdump_glyph_matrix
);
14588 defsubr (&Sdump_glyph_row
);
14589 defsubr (&Sdump_tool_bar_row
);
14590 defsubr (&Strace_redisplay
);
14591 defsubr (&Strace_to_stderr
);
14593 #ifdef HAVE_WINDOW_SYSTEM
14594 defsubr (&Stool_bar_lines_needed
);
14597 staticpro (&Qmenu_bar_update_hook
);
14598 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14600 staticpro (&Qoverriding_terminal_local_map
);
14601 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14603 staticpro (&Qoverriding_local_map
);
14604 Qoverriding_local_map
= intern ("overriding-local-map");
14606 staticpro (&Qwindow_scroll_functions
);
14607 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14609 staticpro (&Qredisplay_end_trigger_functions
);
14610 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14612 staticpro (&Qinhibit_point_motion_hooks
);
14613 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14615 QCdata
= intern (":data");
14616 staticpro (&QCdata
);
14617 Qdisplay
= intern ("display");
14618 staticpro (&Qdisplay
);
14619 Qspace_width
= intern ("space-width");
14620 staticpro (&Qspace_width
);
14621 Qraise
= intern ("raise");
14622 staticpro (&Qraise
);
14623 Qspace
= intern ("space");
14624 staticpro (&Qspace
);
14625 Qmargin
= intern ("margin");
14626 staticpro (&Qmargin
);
14627 Qleft_margin
= intern ("left-margin");
14628 staticpro (&Qleft_margin
);
14629 Qright_margin
= intern ("right-margin");
14630 staticpro (&Qright_margin
);
14631 Qalign_to
= intern ("align-to");
14632 staticpro (&Qalign_to
);
14633 QCalign_to
= intern (":align-to");
14634 staticpro (&QCalign_to
);
14635 Qrelative_width
= intern ("relative-width");
14636 staticpro (&Qrelative_width
);
14637 QCrelative_width
= intern (":relative-width");
14638 staticpro (&QCrelative_width
);
14639 QCrelative_height
= intern (":relative-height");
14640 staticpro (&QCrelative_height
);
14641 QCeval
= intern (":eval");
14642 staticpro (&QCeval
);
14643 Qwhen
= intern ("when");
14644 staticpro (&Qwhen
);
14645 QCfile
= intern (":file");
14646 staticpro (&QCfile
);
14647 Qfontified
= intern ("fontified");
14648 staticpro (&Qfontified
);
14649 Qfontification_functions
= intern ("fontification-functions");
14650 staticpro (&Qfontification_functions
);
14651 Qtrailing_whitespace
= intern ("trailing-whitespace");
14652 staticpro (&Qtrailing_whitespace
);
14653 Qimage
= intern ("image");
14654 staticpro (&Qimage
);
14655 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14656 staticpro (&Qmessage_truncate_lines
);
14657 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
14658 staticpro (&Qcursor_in_non_selected_windows
);
14659 Qgrow_only
= intern ("grow-only");
14660 staticpro (&Qgrow_only
);
14661 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14662 staticpro (&Qinhibit_menubar_update
);
14663 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
14664 staticpro (&Qinhibit_eval_during_redisplay
);
14665 Qposition
= intern ("position");
14666 staticpro (&Qposition
);
14667 Qbuffer_position
= intern ("buffer-position");
14668 staticpro (&Qbuffer_position
);
14669 Qobject
= intern ("object");
14670 staticpro (&Qobject
);
14672 last_arrow_position
= Qnil
;
14673 last_arrow_string
= Qnil
;
14674 staticpro (&last_arrow_position
);
14675 staticpro (&last_arrow_string
);
14677 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14678 staticpro (&echo_buffer
[0]);
14679 staticpro (&echo_buffer
[1]);
14681 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14682 staticpro (&echo_area_buffer
[0]);
14683 staticpro (&echo_area_buffer
[1]);
14685 Vmessages_buffer_name
= build_string ("*Messages*");
14686 staticpro (&Vmessages_buffer_name
);
14688 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14689 doc
: /* Non-nil means highlight trailing whitespace.
14690 The face used for trailing whitespace is `trailing-whitespace'. */);
14691 Vshow_trailing_whitespace
= Qnil
;
14693 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14694 doc
: /* Non-nil means don't actually do any redisplay.
14695 This is used for internal purposes. */);
14696 Vinhibit_redisplay
= Qnil
;
14698 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14699 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
14700 Vglobal_mode_string
= Qnil
;
14702 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14703 doc
: /* Marker for where to display an arrow on top of the buffer text.
14704 This must be the beginning of a line in order to work.
14705 See also `overlay-arrow-string'. */);
14706 Voverlay_arrow_position
= Qnil
;
14708 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14709 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
14710 Voverlay_arrow_string
= Qnil
;
14712 DEFVAR_INT ("scroll-step", &scroll_step
,
14713 doc
: /* *The number of lines to try scrolling a window by when point moves out.
14714 If that fails to bring point back on frame, point is centered instead.
14715 If this is zero, point is always centered after it moves off frame.
14716 If you want scrolling to always be a line at a time, you should set
14717 `scroll-conservatively' to a large value rather than set this to 1. */);
14719 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14720 doc
: /* *Scroll up to this many lines, to bring point back on screen.
14721 A value of zero means to scroll the text to center point vertically
14722 in the window. */);
14723 scroll_conservatively
= 0;
14725 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14726 doc
: /* *Number of lines of margin at the top and bottom of a window.
14727 Recenter the window whenever point gets within this many lines
14728 of the top or bottom of the window. */);
14732 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
14735 DEFVAR_BOOL ("truncate-partial-width-windows",
14736 &truncate_partial_width_windows
,
14737 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
14738 truncate_partial_width_windows
= 1;
14740 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14741 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
14742 Any other value means to use the appropriate face, `mode-line',
14743 `header-line', or `menu' respectively.
14745 This variable is deprecated; please change the above faces instead. */);
14746 mode_line_inverse_video
= 1;
14748 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14749 doc
: /* *Maximum buffer size for which line number should be displayed.
14750 If the buffer is bigger than this, the line number does not appear
14751 in the mode line. A value of nil means no limit. */);
14752 Vline_number_display_limit
= Qnil
;
14754 DEFVAR_INT ("line-number-display-limit-width",
14755 &line_number_display_limit_width
,
14756 doc
: /* *Maximum line width (in characters) for line number display.
14757 If the average length of the lines near point is bigger than this, then the
14758 line number may be omitted from the mode line. */);
14759 line_number_display_limit_width
= 200;
14761 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14762 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
14763 highlight_nonselected_windows
= 0;
14765 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14766 doc
: /* Non-nil if more than one frame is visible on this display.
14767 Minibuffer-only frames don't count, but iconified frames do.
14768 This variable is not guaranteed to be accurate except while processing
14769 `frame-title-format' and `icon-title-format'. */);
14771 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14772 doc
: /* Template for displaying the title bar of visible frames.
14773 \(Assuming the window manager supports this feature.)
14774 This variable has the same structure as `mode-line-format' (which see),
14775 and is used only on frames for which no explicit name has been set
14776 \(see `modify-frame-parameters'). */);
14777 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
14778 doc
: /* Template for displaying the title bar of an iconified frame.
14779 \(Assuming the window manager supports this feature.)
14780 This variable has the same structure as `mode-line-format' (which see),
14781 and is used only on frames for which no explicit name has been set
14782 \(see `modify-frame-parameters'). */);
14784 = Vframe_title_format
14785 = Fcons (intern ("multiple-frames"),
14786 Fcons (build_string ("%b"),
14787 Fcons (Fcons (empty_string
,
14788 Fcons (intern ("invocation-name"),
14789 Fcons (build_string ("@"),
14790 Fcons (intern ("system-name"),
14794 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
14795 doc
: /* Maximum number of lines to keep in the message log buffer.
14796 If nil, disable message logging. If t, log messages but don't truncate
14797 the buffer when it becomes large. */);
14798 Vmessage_log_max
= make_number (50);
14800 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
14801 doc
: /* Functions called before redisplay, if window sizes have changed.
14802 The value should be a list of functions that take one argument.
14803 Just before redisplay, for each frame, if any of its windows have changed
14804 size since the last redisplay, or have been split or deleted,
14805 all the functions in the list are called, with the frame as argument. */);
14806 Vwindow_size_change_functions
= Qnil
;
14808 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
14809 doc
: /* List of Functions to call before redisplaying a window with scrolling.
14810 Each function is called with two arguments, the window
14811 and its new display-start position. Note that the value of `window-end'
14812 is not valid when these functions are called. */);
14813 Vwindow_scroll_functions
= Qnil
;
14815 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
14816 doc
: /* *Non-nil means automatically resize tool-bars.
14817 This increases a tool-bar's height if not all tool-bar items are visible.
14818 It decreases a tool-bar's height when it would display blank lines
14820 auto_resize_tool_bars_p
= 1;
14822 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
14823 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
14824 auto_raise_tool_bar_buttons_p
= 1;
14826 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
14827 doc
: /* *Margin around tool-bar buttons in pixels.
14828 If an integer, use that for both horizontal and vertical margins.
14829 Otherwise, value should be a pair of integers `(HORZ : VERT)' with
14830 HORZ specifying the horizontal margin, and VERT specifying the
14831 vertical margin. */);
14832 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
14834 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
14835 doc
: /* Relief thickness of tool-bar buttons. */);
14836 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
14838 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
14839 doc
: /* List of functions to call to fontify regions of text.
14840 Each function is called with one argument POS. Functions must
14841 fontify a region starting at POS in the current buffer, and give
14842 fontified regions the property `fontified'. */);
14843 Vfontification_functions
= Qnil
;
14844 Fmake_variable_buffer_local (Qfontification_functions
);
14846 DEFVAR_BOOL ("unibyte-display-via-language-environment",
14847 &unibyte_display_via_language_environment
,
14848 doc
: /* *Non-nil means display unibyte text according to language environment.
14849 Specifically this means that unibyte non-ASCII characters
14850 are displayed by converting them to the equivalent multibyte characters
14851 according to the current language environment. As a result, they are
14852 displayed according to the current fontset. */);
14853 unibyte_display_via_language_environment
= 0;
14855 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
14856 doc
: /* *Maximum height for resizing mini-windows.
14857 If a float, it specifies a fraction of the mini-window frame's height.
14858 If an integer, it specifies a number of lines. */);
14859 Vmax_mini_window_height
= make_float (0.25);
14861 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
14862 doc
: /* *How to resize mini-windows.
14863 A value of nil means don't automatically resize mini-windows.
14864 A value of t means resize them to fit the text displayed in them.
14865 A value of `grow-only', the default, means let mini-windows grow
14866 only, until their display becomes empty, at which point the windows
14867 go back to their normal size. */);
14868 Vresize_mini_windows
= Qgrow_only
;
14870 DEFVAR_BOOL ("cursor-in-non-selected-windows",
14871 &cursor_in_non_selected_windows
,
14872 doc
: /* *Non-nil means display a hollow cursor in non-selected windows.
14873 Nil means don't display a cursor there. */);
14874 cursor_in_non_selected_windows
= 1;
14876 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
14877 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
14878 automatic_hscrolling_p
= 1;
14880 DEFVAR_LISP ("image-types", &Vimage_types
,
14881 doc
: /* List of supported image types.
14882 Each element of the list is a symbol for a supported image type. */);
14883 Vimage_types
= Qnil
;
14885 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
14886 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
14887 Bind this around calls to `message' to let it take effect. */);
14888 message_truncate_lines
= 0;
14890 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
14891 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
14892 Can be used to update submenus whose contents should vary. */);
14893 Vmenu_bar_update_hook
= Qnil
;
14895 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
14896 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
14897 inhibit_menubar_update
= 0;
14899 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
14900 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
14901 inhibit_eval_during_redisplay
= 0;
14904 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
14905 doc
: /* Inhibit try_window_id display optimization. */);
14906 inhibit_try_window_id
= 0;
14908 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
14909 doc
: /* Inhibit try_window_reusing display optimization. */);
14910 inhibit_try_window_reusing
= 0;
14912 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
14913 doc
: /* Inhibit try_cursor_movement display optimization. */);
14914 inhibit_try_cursor_movement
= 0;
14915 #endif /* GLYPH_DEBUG */
14919 /* Initialize this module when Emacs starts. */
14924 Lisp_Object root_window
;
14925 struct window
*mini_w
;
14927 current_header_line_height
= current_mode_line_height
= -1;
14929 CHARPOS (this_line_start_pos
) = 0;
14931 mini_w
= XWINDOW (minibuf_window
);
14932 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
14934 if (!noninteractive
)
14936 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
14939 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
14940 set_window_height (root_window
,
14941 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
14943 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
14944 set_window_height (minibuf_window
, 1, 0);
14946 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
14947 mini_w
->width
= make_number (FRAME_WIDTH (f
));
14949 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
14950 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
14951 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
14953 /* The default ellipsis glyphs `...'. */
14954 for (i
= 0; i
< 3; ++i
)
14955 default_invis_vector
[i
] = make_number ('.');
14958 #ifdef HAVE_WINDOW_SYSTEM
14960 /* Allocate the buffer for frame titles. */
14962 frame_title_buf
= (char *) xmalloc (size
);
14963 frame_title_buf_end
= frame_title_buf
+ size
;
14964 frame_title_ptr
= NULL
;
14966 #endif /* HAVE_WINDOW_SYSTEM */
14968 help_echo_showing_p
= 0;