1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay() +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking a iterator structure (struct it)
126 Iteration over things to be be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator
128 (or init_string_iterator for that matter). Calls to
129 get_next_display_element fill the iterator structure with relevant
130 information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
184 #include "termhooks.h"
185 #include "intervals.h"
188 #include "region-cache.h"
191 #ifdef HAVE_X_WINDOWS
201 #define min(a, b) ((a) < (b) ? (a) : (b))
202 #define max(a, b) ((a) > (b) ? (a) : (b))
204 #define INFINITY 10000000
206 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
207 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
208 extern int pending_menu_activation
;
211 extern int interrupt_input
;
212 extern int command_loop_level
;
214 extern int minibuffer_auto_raise
;
216 extern Lisp_Object Qface
;
218 extern Lisp_Object Voverriding_local_map
;
219 extern Lisp_Object Voverriding_local_map_menu_flag
;
220 extern Lisp_Object Qmenu_item
;
222 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
223 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
224 Lisp_Object Qredisplay_end_trigger_functions
;
225 Lisp_Object Qinhibit_point_motion_hooks
;
226 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
;
227 Lisp_Object Qfontified
;
228 Lisp_Object Qgrow_only
;
229 Lisp_Object Qinhibit_eval_during_redisplay
;
230 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
232 /* Functions called to fontify regions of text. */
234 Lisp_Object Vfontification_functions
;
235 Lisp_Object Qfontification_functions
;
237 /* Non-zero means draw tool bar buttons raised when the mouse moves
240 int auto_raise_tool_bar_buttons_p
;
242 /* Margin around tool bar buttons in pixels. */
244 Lisp_Object Vtool_bar_button_margin
;
246 /* Thickness of shadow to draw around tool bar buttons. */
248 int tool_bar_button_relief
;
250 /* Non-zero means automatically resize tool-bars so that all tool-bar
251 items are visible, and no blank lines remain. */
253 int auto_resize_tool_bars_p
;
255 /* Non-nil means don't actually do any redisplay. */
257 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
259 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
261 int inhibit_eval_during_redisplay
;
263 /* Names of text properties relevant for redisplay. */
265 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
266 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
268 /* Symbols used in text property values. */
270 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
271 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
273 extern Lisp_Object Qheight
;
275 /* Non-nil means highlight trailing whitespace. */
277 Lisp_Object Vshow_trailing_whitespace
;
279 /* Name of the face used to highlight trailing whitespace. */
281 Lisp_Object Qtrailing_whitespace
;
283 /* The symbol `image' which is the car of the lists used to represent
288 /* Non-zero means print newline to stdout before next mini-buffer
291 int noninteractive_need_newline
;
293 /* Non-zero means print newline to message log before next message. */
295 static int message_log_need_newline
;
298 /* The buffer position of the first character appearing entirely or
299 partially on the line of the selected window which contains the
300 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
301 redisplay optimization in redisplay_internal. */
303 static struct text_pos this_line_start_pos
;
305 /* Number of characters past the end of the line above, including the
306 terminating newline. */
308 static struct text_pos this_line_end_pos
;
310 /* The vertical positions and the height of this line. */
312 static int this_line_vpos
;
313 static int this_line_y
;
314 static int this_line_pixel_height
;
316 /* X position at which this display line starts. Usually zero;
317 negative if first character is partially visible. */
319 static int this_line_start_x
;
321 /* Buffer that this_line_.* variables are referring to. */
323 static struct buffer
*this_line_buffer
;
325 /* Nonzero means truncate lines in all windows less wide than the
328 int truncate_partial_width_windows
;
330 /* A flag to control how to display unibyte 8-bit character. */
332 int unibyte_display_via_language_environment
;
334 /* Nonzero means we have more than one non-mini-buffer-only frame.
335 Not guaranteed to be accurate except while parsing
336 frame-title-format. */
340 Lisp_Object Vglobal_mode_string
;
342 /* Marker for where to display an arrow on top of the buffer text. */
344 Lisp_Object Voverlay_arrow_position
;
346 /* String to display for the arrow. Only used on terminal frames. */
348 Lisp_Object Voverlay_arrow_string
;
350 /* Values of those variables at last redisplay. However, if
351 Voverlay_arrow_position is a marker, last_arrow_position is its
352 numerical position. */
354 static Lisp_Object last_arrow_position
, last_arrow_string
;
356 /* Like mode-line-format, but for the title bar on a visible frame. */
358 Lisp_Object Vframe_title_format
;
360 /* Like mode-line-format, but for the title bar on an iconified frame. */
362 Lisp_Object Vicon_title_format
;
364 /* List of functions to call when a window's size changes. These
365 functions get one arg, a frame on which one or more windows' sizes
368 static Lisp_Object Vwindow_size_change_functions
;
370 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
372 /* Nonzero if overlay arrow has been displayed once in this window. */
374 static int overlay_arrow_seen
;
376 /* Nonzero means highlight the region even in nonselected windows. */
378 int highlight_nonselected_windows
;
380 /* If cursor motion alone moves point off frame, try scrolling this
381 many lines up or down if that will bring it back. */
383 static int scroll_step
;
385 /* Non-0 means scroll just far enough to bring point back on the
386 screen, when appropriate. */
388 static int scroll_conservatively
;
390 /* Recenter the window whenever point gets within this many lines of
391 the top or bottom of the window. This value is translated into a
392 pixel value by multiplying it with CANON_Y_UNIT, which means that
393 there is really a fixed pixel height scroll margin. */
397 /* Number of windows showing the buffer of the selected window (or
398 another buffer with the same base buffer). keyboard.c refers to
403 /* Vector containing glyphs for an ellipsis `...'. */
405 static Lisp_Object default_invis_vector
[3];
407 /* Zero means display the mode-line/header-line/menu-bar in the default face
408 (this slightly odd definition is for compatibility with previous versions
409 of emacs), non-zero means display them using their respective faces.
411 This variable is deprecated. */
413 int mode_line_inverse_video
;
415 /* Prompt to display in front of the mini-buffer contents. */
417 Lisp_Object minibuf_prompt
;
419 /* Width of current mini-buffer prompt. Only set after display_line
420 of the line that contains the prompt. */
422 int minibuf_prompt_width
;
423 int minibuf_prompt_pixel_width
;
425 /* This is the window where the echo area message was displayed. It
426 is always a mini-buffer window, but it may not be the same window
427 currently active as a mini-buffer. */
429 Lisp_Object echo_area_window
;
431 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
432 pushes the current message and the value of
433 message_enable_multibyte on the stack, the function restore_message
434 pops the stack and displays MESSAGE again. */
436 Lisp_Object Vmessage_stack
;
438 /* Nonzero means multibyte characters were enabled when the echo area
439 message was specified. */
441 int message_enable_multibyte
;
443 /* True if we should redraw the mode lines on the next redisplay. */
445 int update_mode_lines
;
447 /* Nonzero if window sizes or contents have changed since last
448 redisplay that finished */
450 int windows_or_buffers_changed
;
452 /* Nonzero after display_mode_line if %l was used and it displayed a
455 int line_number_displayed
;
457 /* Maximum buffer size for which to display line numbers. */
459 Lisp_Object Vline_number_display_limit
;
461 /* line width to consider when repostioning for line number display */
463 static int line_number_display_limit_width
;
465 /* Number of lines to keep in the message log buffer. t means
466 infinite. nil means don't log at all. */
468 Lisp_Object Vmessage_log_max
;
470 /* The name of the *Messages* buffer, a string. */
472 static Lisp_Object Vmessages_buffer_name
;
474 /* Current, index 0, and last displayed echo area message. Either
475 buffers from echo_buffers, or nil to indicate no message. */
477 Lisp_Object echo_area_buffer
[2];
479 /* The buffers referenced from echo_area_buffer. */
481 static Lisp_Object echo_buffer
[2];
483 /* A vector saved used in with_area_buffer to reduce consing. */
485 static Lisp_Object Vwith_echo_area_save_vector
;
487 /* Non-zero means display_echo_area should display the last echo area
488 message again. Set by redisplay_preserve_echo_area. */
490 static int display_last_displayed_message_p
;
492 /* Nonzero if echo area is being used by print; zero if being used by
495 int message_buf_print
;
497 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
499 Lisp_Object Qinhibit_menubar_update
;
500 int inhibit_menubar_update
;
502 /* Maximum height for resizing mini-windows. Either a float
503 specifying a fraction of the available height, or an integer
504 specifying a number of lines. */
506 Lisp_Object Vmax_mini_window_height
;
508 /* Non-zero means messages should be displayed with truncated
509 lines instead of being continued. */
511 int message_truncate_lines
;
512 Lisp_Object Qmessage_truncate_lines
;
514 /* Set to 1 in clear_message to make redisplay_internal aware
515 of an emptied echo area. */
517 static int message_cleared_p
;
519 /* Non-zero means we want a hollow cursor in windows that are not
520 selected. Zero means there's no cursor in such windows. */
522 int cursor_in_non_selected_windows
;
524 /* A scratch glyph row with contents used for generating truncation
525 glyphs. Also used in direct_output_for_insert. */
527 #define MAX_SCRATCH_GLYPHS 100
528 struct glyph_row scratch_glyph_row
;
529 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
531 /* Ascent and height of the last line processed by move_it_to. */
533 static int last_max_ascent
, last_height
;
535 /* Non-zero if there's a help-echo in the echo area. */
537 int help_echo_showing_p
;
539 /* If >= 0, computed, exact values of mode-line and header-line height
540 to use in the macros CURRENT_MODE_LINE_HEIGHT and
541 CURRENT_HEADER_LINE_HEIGHT. */
543 int current_mode_line_height
, current_header_line_height
;
545 /* The maximum distance to look ahead for text properties. Values
546 that are too small let us call compute_char_face and similar
547 functions too often which is expensive. Values that are too large
548 let us call compute_char_face and alike too often because we
549 might not be interested in text properties that far away. */
551 #define TEXT_PROP_DISTANCE_LIMIT 100
555 /* Non-zero means print traces of redisplay if compiled with
558 int trace_redisplay_p
;
560 #endif /* GLYPH_DEBUG */
562 #ifdef DEBUG_TRACE_MOVE
563 /* Non-zero means trace with TRACE_MOVE to stderr. */
566 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
568 #define TRACE_MOVE(x) (void) 0
571 /* Non-zero means automatically scroll windows horizontally to make
574 int automatic_hscrolling_p
;
576 /* A list of symbols, one for each supported image type. */
578 Lisp_Object Vimage_types
;
580 /* The variable `resize-mini-windows'. If nil, don't resize
581 mini-windows. If t, always resize them to fit the text they
582 display. If `grow-only', let mini-windows grow only until they
585 Lisp_Object Vresize_mini_windows
;
587 /* Value returned from text property handlers (see below). */
592 HANDLED_RECOMPUTE_PROPS
,
593 HANDLED_OVERLAY_STRING_CONSUMED
,
597 /* A description of text properties that redisplay is interested
602 /* The name of the property. */
605 /* A unique index for the property. */
608 /* A handler function called to set up iterator IT from the property
609 at IT's current position. Value is used to steer handle_stop. */
610 enum prop_handled (*handler
) P_ ((struct it
*it
));
613 static enum prop_handled handle_face_prop
P_ ((struct it
*));
614 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
615 static enum prop_handled handle_display_prop
P_ ((struct it
*));
616 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
617 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
618 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
620 /* Properties handled by iterators. */
622 static struct props it_props
[] =
624 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
625 /* Handle `face' before `display' because some sub-properties of
626 `display' need to know the face. */
627 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
628 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
629 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
630 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
634 /* Value is the position described by X. If X is a marker, value is
635 the marker_position of X. Otherwise, value is X. */
637 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
639 /* Enumeration returned by some move_it_.* functions internally. */
643 /* Not used. Undefined value. */
646 /* Move ended at the requested buffer position or ZV. */
647 MOVE_POS_MATCH_OR_ZV
,
649 /* Move ended at the requested X pixel position. */
652 /* Move within a line ended at the end of a line that must be
656 /* Move within a line ended at the end of a line that would
657 be displayed truncated. */
660 /* Move within a line ended at a line end. */
666 /* Function prototypes. */
668 static void setup_for_ellipsis
P_ ((struct it
*));
669 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
670 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
671 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
672 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
673 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
674 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
675 static int invisible_text_between_p
P_ ((struct it
*, int, int));
676 static int next_element_from_ellipsis
P_ ((struct it
*));
677 static void pint2str
P_ ((char *, int, int));
678 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
680 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
681 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
682 static void store_frame_title_char
P_ ((char));
683 static int store_frame_title
P_ ((unsigned char *, int, int));
684 static void x_consider_frame_title
P_ ((Lisp_Object
));
685 static void handle_stop
P_ ((struct it
*));
686 static int tool_bar_lines_needed
P_ ((struct frame
*));
687 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
688 static void ensure_echo_area_buffers
P_ ((void));
689 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
691 struct glyph_row
*));
692 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
693 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
694 static int with_echo_area_buffer
P_ ((struct window
*, int,
695 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
696 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
697 static void clear_garbaged_frames
P_ ((void));
698 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
699 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
700 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
701 static int display_echo_area
P_ ((struct window
*));
702 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
703 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
704 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
705 static int string_char_and_length
P_ ((unsigned char *, int, int *));
706 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
708 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
709 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
710 static void insert_left_trunc_glyphs
P_ ((struct it
*));
711 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
712 static void extend_face_to_end_of_line
P_ ((struct it
*));
713 static int append_space
P_ ((struct it
*, int));
714 static void make_cursor_line_fully_visible
P_ ((struct window
*));
715 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
716 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
717 static int trailing_whitespace_p
P_ ((int));
718 static int message_log_check_duplicate
P_ ((int, int, int, int));
719 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
720 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
721 static void push_it
P_ ((struct it
*));
722 static void pop_it
P_ ((struct it
*));
723 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
724 static void redisplay_internal
P_ ((int));
725 static int echo_area_display
P_ ((int));
726 static void redisplay_windows
P_ ((Lisp_Object
));
727 static void redisplay_window
P_ ((Lisp_Object
, int));
728 static void update_menu_bar
P_ ((struct frame
*, int));
729 static int try_window_reusing_current_matrix
P_ ((struct window
*));
730 static int try_window_id
P_ ((struct window
*));
731 static int display_line
P_ ((struct it
*));
732 static int display_mode_lines
P_ ((struct window
*));
733 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
734 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
735 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
736 static void display_menu_bar
P_ ((struct window
*));
737 static int display_count_lines
P_ ((int, int, int, int, int *));
738 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
739 int, int, struct it
*, int, int, int, int));
740 static void compute_line_metrics
P_ ((struct it
*));
741 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
742 static int get_overlay_strings
P_ ((struct it
*, int));
743 static void next_overlay_string
P_ ((struct it
*));
744 static void reseat
P_ ((struct it
*, struct text_pos
, int));
745 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
746 static void back_to_previous_visible_line_start
P_ ((struct it
*));
747 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
748 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
749 static int next_element_from_display_vector
P_ ((struct it
*));
750 static int next_element_from_string
P_ ((struct it
*));
751 static int next_element_from_c_string
P_ ((struct it
*));
752 static int next_element_from_buffer
P_ ((struct it
*));
753 static int next_element_from_composition
P_ ((struct it
*));
754 static int next_element_from_image
P_ ((struct it
*));
755 static int next_element_from_stretch
P_ ((struct it
*));
756 static void load_overlay_strings
P_ ((struct it
*, int));
757 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
758 struct display_pos
*));
759 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
760 Lisp_Object
, int, int, int, int));
761 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
763 void move_it_vertically_backward
P_ ((struct it
*, int));
764 static void init_to_row_start
P_ ((struct it
*, struct window
*,
765 struct glyph_row
*));
766 static int init_to_row_end
P_ ((struct it
*, struct window
*,
767 struct glyph_row
*));
768 static void back_to_previous_line_start
P_ ((struct it
*));
769 static int forward_to_next_line_start
P_ ((struct it
*, int *));
770 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
772 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
773 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
774 static int number_of_chars
P_ ((unsigned char *, int));
775 static void compute_stop_pos
P_ ((struct it
*));
776 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
778 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
779 static int next_overlay_change
P_ ((int));
780 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
781 Lisp_Object
, struct text_pos
*,
783 static int underlying_face_id
P_ ((struct it
*));
784 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
787 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
788 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
790 #ifdef HAVE_WINDOW_SYSTEM
792 static void update_tool_bar
P_ ((struct frame
*, int));
793 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
794 static int redisplay_tool_bar
P_ ((struct frame
*));
795 static void display_tool_bar_line
P_ ((struct it
*));
797 #endif /* HAVE_WINDOW_SYSTEM */
800 /***********************************************************************
801 Window display dimensions
802 ***********************************************************************/
804 /* Return the window-relative maximum y + 1 for glyph rows displaying
805 text in window W. This is the height of W minus the height of a
806 mode line, if any. */
809 window_text_bottom_y (w
)
812 struct frame
*f
= XFRAME (w
->frame
);
813 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
815 if (WINDOW_WANTS_MODELINE_P (w
))
816 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
821 /* Return the pixel width of display area AREA of window W. AREA < 0
822 means return the total width of W, not including bitmap areas to
823 the left and right of the window. */
826 window_box_width (w
, area
)
830 struct frame
*f
= XFRAME (w
->frame
);
831 int width
= XFASTINT (w
->width
);
833 if (!w
->pseudo_window_p
)
835 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
837 if (area
== TEXT_AREA
)
839 if (INTEGERP (w
->left_margin_width
))
840 width
-= XFASTINT (w
->left_margin_width
);
841 if (INTEGERP (w
->right_margin_width
))
842 width
-= XFASTINT (w
->right_margin_width
);
844 else if (area
== LEFT_MARGIN_AREA
)
845 width
= (INTEGERP (w
->left_margin_width
)
846 ? XFASTINT (w
->left_margin_width
) : 0);
847 else if (area
== RIGHT_MARGIN_AREA
)
848 width
= (INTEGERP (w
->right_margin_width
)
849 ? XFASTINT (w
->right_margin_width
) : 0);
852 return width
* CANON_X_UNIT (f
);
856 /* Return the pixel height of the display area of window W, not
857 including mode lines of W, if any.. */
860 window_box_height (w
)
863 struct frame
*f
= XFRAME (w
->frame
);
864 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
866 xassert (height
>= 0);
868 /* Note: the code below that determines the mode-line/header-line
869 height is essentially the same as that contained in the macro
870 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
871 the appropriate glyph row has its `mode_line_p' flag set,
872 and if it doesn't, uses estimate_mode_line_height instead. */
874 if (WINDOW_WANTS_MODELINE_P (w
))
876 struct glyph_row
*ml_row
877 = (w
->current_matrix
&& w
->current_matrix
->rows
878 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
880 if (ml_row
&& ml_row
->mode_line_p
)
881 height
-= ml_row
->height
;
883 height
-= estimate_mode_line_height (f
, MODE_LINE_FACE_ID
);
886 if (WINDOW_WANTS_HEADER_LINE_P (w
))
888 struct glyph_row
*hl_row
889 = (w
->current_matrix
&& w
->current_matrix
->rows
890 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
892 if (hl_row
&& hl_row
->mode_line_p
)
893 height
-= hl_row
->height
;
895 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
902 /* Return the frame-relative coordinate of the left edge of display
903 area AREA of window W. AREA < 0 means return the left edge of the
904 whole window, to the right of any bitmap area at the left side of
908 window_box_left (w
, area
)
912 struct frame
*f
= XFRAME (w
->frame
);
913 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
915 if (!w
->pseudo_window_p
)
917 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
918 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
920 if (area
== TEXT_AREA
)
921 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
922 else if (area
== RIGHT_MARGIN_AREA
)
923 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
924 + window_box_width (w
, TEXT_AREA
));
931 /* Return the frame-relative coordinate of the right edge of display
932 area AREA of window W. AREA < 0 means return the left edge of the
933 whole window, to the left of any bitmap area at the right side of
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 bitmap areas to the left and right 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 bitmap
972 areas to the left and right 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
> 0 && charpos
<= ZV
));
1466 /* If face attributes have been changed since the last redisplay,
1467 free realized faces now because they depend on face definitions
1468 that might have changed. */
1469 if (face_change_count
)
1471 face_change_count
= 0;
1472 free_all_realized_faces (Qnil
);
1475 /* Use one of the mode line rows of W's desired matrix if
1479 if (base_face_id
== MODE_LINE_FACE_ID
)
1480 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1481 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1482 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1486 bzero (it
, sizeof *it
);
1487 it
->current
.overlay_string_index
= -1;
1488 it
->current
.dpvec_index
= -1;
1489 it
->base_face_id
= base_face_id
;
1491 /* The window in which we iterate over current_buffer: */
1492 XSETWINDOW (it
->window
, w
);
1494 it
->f
= XFRAME (w
->frame
);
1496 /* Extra space between lines (on window systems only). */
1497 if (base_face_id
== DEFAULT_FACE_ID
1498 && FRAME_WINDOW_P (it
->f
))
1500 if (NATNUMP (current_buffer
->extra_line_spacing
))
1501 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1502 else if (it
->f
->extra_line_spacing
> 0)
1503 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1506 /* If realized faces have been removed, e.g. because of face
1507 attribute changes of named faces, recompute them. When running
1508 in batch mode, the face cache of Vterminal_frame is null. If
1509 we happen to get called, make a dummy face cache. */
1514 FRAME_FACE_CACHE (it
->f
) == NULL
)
1515 init_frame_faces (it
->f
);
1516 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1517 recompute_basic_faces (it
->f
);
1519 /* Current value of the `space-width', and 'height' properties. */
1520 it
->space_width
= Qnil
;
1521 it
->font_height
= Qnil
;
1523 /* Are control characters displayed as `^C'? */
1524 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1526 /* -1 means everything between a CR and the following line end
1527 is invisible. >0 means lines indented more than this value are
1529 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1530 ? XFASTINT (current_buffer
->selective_display
)
1531 : (!NILP (current_buffer
->selective_display
)
1533 it
->selective_display_ellipsis_p
1534 = !NILP (current_buffer
->selective_display_ellipses
);
1536 /* Display table to use. */
1537 it
->dp
= window_display_table (w
);
1539 /* Are multibyte characters enabled in current_buffer? */
1540 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1542 /* Non-zero if we should highlight the region. */
1544 = (!NILP (Vtransient_mark_mode
)
1545 && !NILP (current_buffer
->mark_active
)
1546 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1548 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1549 start and end of a visible region in window IT->w. Set both to
1550 -1 to indicate no region. */
1551 if (highlight_region_p
1552 /* Maybe highlight only in selected window. */
1553 && (/* Either show region everywhere. */
1554 highlight_nonselected_windows
1555 /* Or show region in the selected window. */
1556 || w
== XWINDOW (selected_window
)
1557 /* Or show the region if we are in the mini-buffer and W is
1558 the window the mini-buffer refers to. */
1559 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1560 && WINDOWP (Vminibuf_scroll_window
)
1561 && w
== XWINDOW (Vminibuf_scroll_window
))))
1563 int charpos
= marker_position (current_buffer
->mark
);
1564 it
->region_beg_charpos
= min (PT
, charpos
);
1565 it
->region_end_charpos
= max (PT
, charpos
);
1568 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1570 /* Get the position at which the redisplay_end_trigger hook should
1571 be run, if it is to be run at all. */
1572 if (MARKERP (w
->redisplay_end_trigger
)
1573 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1574 it
->redisplay_end_trigger_charpos
1575 = marker_position (w
->redisplay_end_trigger
);
1576 else if (INTEGERP (w
->redisplay_end_trigger
))
1577 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1579 /* Correct bogus values of tab_width. */
1580 it
->tab_width
= XINT (current_buffer
->tab_width
);
1581 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1584 /* Are lines in the display truncated? */
1585 it
->truncate_lines_p
1586 = (base_face_id
!= DEFAULT_FACE_ID
1587 || XINT (it
->w
->hscroll
)
1588 || (truncate_partial_width_windows
1589 && !WINDOW_FULL_WIDTH_P (it
->w
))
1590 || !NILP (current_buffer
->truncate_lines
));
1592 /* Get dimensions of truncation and continuation glyphs. These are
1593 displayed as bitmaps under X, so we don't need them for such
1595 if (!FRAME_WINDOW_P (it
->f
))
1597 if (it
->truncate_lines_p
)
1599 /* We will need the truncation glyph. */
1600 xassert (it
->glyph_row
== NULL
);
1601 produce_special_glyphs (it
, IT_TRUNCATION
);
1602 it
->truncation_pixel_width
= it
->pixel_width
;
1606 /* We will need the continuation glyph. */
1607 xassert (it
->glyph_row
== NULL
);
1608 produce_special_glyphs (it
, IT_CONTINUATION
);
1609 it
->continuation_pixel_width
= it
->pixel_width
;
1612 /* Reset these values to zero becaue the produce_special_glyphs
1613 above has changed them. */
1614 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1615 it
->phys_ascent
= it
->phys_descent
= 0;
1618 /* Set this after getting the dimensions of truncation and
1619 continuation glyphs, so that we don't produce glyphs when calling
1620 produce_special_glyphs, above. */
1621 it
->glyph_row
= row
;
1622 it
->area
= TEXT_AREA
;
1624 /* Get the dimensions of the display area. The display area
1625 consists of the visible window area plus a horizontally scrolled
1626 part to the left of the window. All x-values are relative to the
1627 start of this total display area. */
1628 if (base_face_id
!= DEFAULT_FACE_ID
)
1630 /* Mode lines, menu bar in terminal frames. */
1631 it
->first_visible_x
= 0;
1632 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1637 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1638 it
->last_visible_x
= (it
->first_visible_x
1639 + window_box_width (w
, TEXT_AREA
));
1641 /* If we truncate lines, leave room for the truncator glyph(s) at
1642 the right margin. Otherwise, leave room for the continuation
1643 glyph(s). Truncation and continuation glyphs are not inserted
1644 for window-based redisplay. */
1645 if (!FRAME_WINDOW_P (it
->f
))
1647 if (it
->truncate_lines_p
)
1648 it
->last_visible_x
-= it
->truncation_pixel_width
;
1650 it
->last_visible_x
-= it
->continuation_pixel_width
;
1653 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1654 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1657 /* Leave room for a border glyph. */
1658 if (!FRAME_WINDOW_P (it
->f
)
1659 && !WINDOW_RIGHTMOST_P (it
->w
))
1660 it
->last_visible_x
-= 1;
1662 it
->last_visible_y
= window_text_bottom_y (w
);
1664 /* For mode lines and alike, arrange for the first glyph having a
1665 left box line if the face specifies a box. */
1666 if (base_face_id
!= DEFAULT_FACE_ID
)
1670 it
->face_id
= base_face_id
;
1672 /* If we have a boxed mode line, make the first character appear
1673 with a left box line. */
1674 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1675 if (face
->box
!= FACE_NO_BOX
)
1676 it
->start_of_box_run_p
= 1;
1679 /* If a buffer position was specified, set the iterator there,
1680 getting overlays and face properties from that position. */
1683 it
->end_charpos
= ZV
;
1685 IT_CHARPOS (*it
) = charpos
;
1687 /* Compute byte position if not specified. */
1689 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1691 IT_BYTEPOS (*it
) = bytepos
;
1693 /* Compute faces etc. */
1694 reseat (it
, it
->current
.pos
, 1);
1701 /* Initialize IT for the display of window W with window start POS. */
1704 start_display (it
, w
, pos
)
1707 struct text_pos pos
;
1709 struct glyph_row
*row
;
1710 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1712 row
= w
->desired_matrix
->rows
+ first_vpos
;
1713 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1715 if (!it
->truncate_lines_p
)
1717 int start_at_line_beg_p
;
1718 int first_y
= it
->current_y
;
1720 /* If window start is not at a line start, skip forward to POS to
1721 get the correct continuation lines width. */
1722 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1723 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1724 if (!start_at_line_beg_p
)
1726 reseat_at_previous_visible_line_start (it
);
1727 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1729 /* If lines are continued, this line may end in the middle
1730 of a multi-glyph character (e.g. a control character
1731 displayed as \003, or in the middle of an overlay
1732 string). In this case move_it_to above will not have
1733 taken us to the start of the continuation line but to the
1734 end of the continued line. */
1735 if (it
->current_x
> 0)
1737 if (it
->current
.dpvec_index
>= 0
1738 || it
->current
.overlay_string_index
>= 0)
1740 set_iterator_to_next (it
, 1);
1741 move_it_in_display_line_to (it
, -1, -1, 0);
1744 it
->continuation_lines_width
+= it
->current_x
;
1747 /* We're starting a new display line, not affected by the
1748 height of the continued line, so clear the appropriate
1749 fields in the iterator structure. */
1750 it
->max_ascent
= it
->max_descent
= 0;
1751 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1753 it
->current_y
= first_y
;
1755 it
->current_x
= it
->hpos
= 0;
1759 #if 0 /* Don't assert the following because start_display is sometimes
1760 called intentionally with a window start that is not at a
1761 line start. Please leave this code in as a comment. */
1763 /* Window start should be on a line start, now. */
1764 xassert (it
->continuation_lines_width
1765 || IT_CHARPOS (it
) == BEGV
1766 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1771 /* Return 1 if POS is a position in ellipses displayed for invisible
1772 text. W is the window we display, for text property lookup. */
1775 in_ellipses_for_invisible_text_p (pos
, w
)
1776 struct display_pos
*pos
;
1779 Lisp_Object prop
, window
;
1781 int charpos
= CHARPOS (pos
->pos
);
1783 /* If POS specifies a position in a display vector, this might
1784 be for an ellipsis displayed for invisible text. We won't
1785 get the iterator set up for delivering that ellipsis unless
1786 we make sure that it gets aware of the invisible text. */
1787 if (pos
->dpvec_index
>= 0
1788 && pos
->overlay_string_index
< 0
1789 && CHARPOS (pos
->string_pos
) < 0
1791 && (XSETWINDOW (window
, w
),
1792 prop
= Fget_char_property (make_number (charpos
),
1793 Qinvisible
, window
),
1794 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1796 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1798 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
1799 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
))
1807 /* Initialize IT for stepping through current_buffer in window W,
1808 starting at position POS that includes overlay string and display
1809 vector/ control character translation position information. Value
1810 is zero if there are overlay strings with newlines at POS. */
1813 init_from_display_pos (it
, w
, pos
)
1816 struct display_pos
*pos
;
1818 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1819 int i
, overlay_strings_with_newlines
= 0;
1821 /* If POS specifies a position in a display vector, this might
1822 be for an ellipsis displayed for invisible text. We won't
1823 get the iterator set up for delivering that ellipsis unless
1824 we make sure that it gets aware of the invisible text. */
1825 if (in_ellipses_for_invisible_text_p (pos
, w
))
1831 /* Keep in mind: the call to reseat in init_iterator skips invisible
1832 text, so we might end up at a position different from POS. This
1833 is only a problem when POS is a row start after a newline and an
1834 overlay starts there with an after-string, and the overlay has an
1835 invisible property. Since we don't skip invisible text in
1836 display_line and elsewhere immediately after consuming the
1837 newline before the row start, such a POS will not be in a string,
1838 but the call to init_iterator below will move us to the
1840 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1842 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
1844 char *s
= XSTRING (it
->overlay_strings
[i
])->data
;
1845 char *e
= s
+ STRING_BYTES (XSTRING (it
->overlay_strings
[i
]));
1847 while (s
< e
&& *s
!= '\n')
1852 overlay_strings_with_newlines
= 1;
1857 /* If position is within an overlay string, set up IT to the right
1859 if (pos
->overlay_string_index
>= 0)
1863 /* If the first overlay string happens to have a `display'
1864 property for an image, the iterator will be set up for that
1865 image, and we have to undo that setup first before we can
1866 correct the overlay string index. */
1867 if (it
->method
== next_element_from_image
)
1870 /* We already have the first chunk of overlay strings in
1871 IT->overlay_strings. Load more until the one for
1872 pos->overlay_string_index is in IT->overlay_strings. */
1873 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1875 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1876 it
->current
.overlay_string_index
= 0;
1879 load_overlay_strings (it
, 0);
1880 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1884 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1885 relative_index
= (it
->current
.overlay_string_index
1886 % OVERLAY_STRING_CHUNK_SIZE
);
1887 it
->string
= it
->overlay_strings
[relative_index
];
1888 xassert (STRINGP (it
->string
));
1889 it
->current
.string_pos
= pos
->string_pos
;
1890 it
->method
= next_element_from_string
;
1893 #if 0 /* This is bogus because POS not having an overlay string
1894 position does not mean it's after the string. Example: A
1895 line starting with a before-string and initialization of IT
1896 to the previous row's end position. */
1897 else if (it
->current
.overlay_string_index
>= 0)
1899 /* If POS says we're already after an overlay string ending at
1900 POS, make sure to pop the iterator because it will be in
1901 front of that overlay string. When POS is ZV, we've thereby
1902 also ``processed'' overlay strings at ZV. */
1905 it
->current
.overlay_string_index
= -1;
1906 it
->method
= next_element_from_buffer
;
1907 if (CHARPOS (pos
->pos
) == ZV
)
1908 it
->overlay_strings_at_end_processed_p
= 1;
1912 if (CHARPOS (pos
->string_pos
) >= 0)
1914 /* Recorded position is not in an overlay string, but in another
1915 string. This can only be a string from a `display' property.
1916 IT should already be filled with that string. */
1917 it
->current
.string_pos
= pos
->string_pos
;
1918 xassert (STRINGP (it
->string
));
1921 /* Restore position in display vector translations, control
1922 character translations or ellipses. */
1923 if (pos
->dpvec_index
>= 0)
1925 if (it
->dpvec
== NULL
)
1926 get_next_display_element (it
);
1927 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1928 it
->current
.dpvec_index
= pos
->dpvec_index
;
1932 return !overlay_strings_with_newlines
;
1936 /* Initialize IT for stepping through current_buffer in window W
1937 starting at ROW->start. */
1940 init_to_row_start (it
, w
, row
)
1943 struct glyph_row
*row
;
1945 init_from_display_pos (it
, w
, &row
->start
);
1946 it
->continuation_lines_width
= row
->continuation_lines_width
;
1951 /* Initialize IT for stepping through current_buffer in window W
1952 starting in the line following ROW, i.e. starting at ROW->end.
1953 Value is zero if there are overlay strings with newlines at ROW's
1957 init_to_row_end (it
, w
, row
)
1960 struct glyph_row
*row
;
1964 if (init_from_display_pos (it
, w
, &row
->end
))
1966 if (row
->continued_p
)
1967 it
->continuation_lines_width
1968 = row
->continuation_lines_width
+ row
->pixel_width
;
1979 /***********************************************************************
1981 ***********************************************************************/
1983 /* Called when IT reaches IT->stop_charpos. Handle text property and
1984 overlay changes. Set IT->stop_charpos to the next position where
1991 enum prop_handled handled
;
1992 int handle_overlay_change_p
= 1;
1996 it
->current
.dpvec_index
= -1;
2000 handled
= HANDLED_NORMALLY
;
2002 /* Call text property handlers. */
2003 for (p
= it_props
; p
->handler
; ++p
)
2005 handled
= p
->handler (it
);
2007 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2009 else if (handled
== HANDLED_RETURN
)
2011 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2012 handle_overlay_change_p
= 0;
2015 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2017 /* Don't check for overlay strings below when set to deliver
2018 characters from a display vector. */
2019 if (it
->method
== next_element_from_display_vector
)
2020 handle_overlay_change_p
= 0;
2022 /* Handle overlay changes. */
2023 if (handle_overlay_change_p
)
2024 handled
= handle_overlay_change (it
);
2026 /* Determine where to stop next. */
2027 if (handled
== HANDLED_NORMALLY
)
2028 compute_stop_pos (it
);
2031 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2035 /* Compute IT->stop_charpos from text property and overlay change
2036 information for IT's current position. */
2039 compute_stop_pos (it
)
2042 register INTERVAL iv
, next_iv
;
2043 Lisp_Object object
, limit
, position
;
2045 /* If nowhere else, stop at the end. */
2046 it
->stop_charpos
= it
->end_charpos
;
2048 if (STRINGP (it
->string
))
2050 /* Strings are usually short, so don't limit the search for
2052 object
= it
->string
;
2054 position
= make_number (IT_STRING_CHARPOS (*it
));
2060 /* If next overlay change is in front of the current stop pos
2061 (which is IT->end_charpos), stop there. Note: value of
2062 next_overlay_change is point-max if no overlay change
2064 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2065 if (charpos
< it
->stop_charpos
)
2066 it
->stop_charpos
= charpos
;
2068 /* If showing the region, we have to stop at the region
2069 start or end because the face might change there. */
2070 if (it
->region_beg_charpos
> 0)
2072 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2073 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2074 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2075 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2078 /* Set up variables for computing the stop position from text
2079 property changes. */
2080 XSETBUFFER (object
, current_buffer
);
2081 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2082 position
= make_number (IT_CHARPOS (*it
));
2086 /* Get the interval containing IT's position. Value is a null
2087 interval if there isn't such an interval. */
2088 iv
= validate_interval_range (object
, &position
, &position
, 0);
2089 if (!NULL_INTERVAL_P (iv
))
2091 Lisp_Object values_here
[LAST_PROP_IDX
];
2094 /* Get properties here. */
2095 for (p
= it_props
; p
->handler
; ++p
)
2096 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2098 /* Look for an interval following iv that has different
2100 for (next_iv
= next_interval (iv
);
2101 (!NULL_INTERVAL_P (next_iv
)
2103 || XFASTINT (limit
) > next_iv
->position
));
2104 next_iv
= next_interval (next_iv
))
2106 for (p
= it_props
; p
->handler
; ++p
)
2108 Lisp_Object new_value
;
2110 new_value
= textget (next_iv
->plist
, *p
->name
);
2111 if (!EQ (values_here
[p
->idx
], new_value
))
2119 if (!NULL_INTERVAL_P (next_iv
))
2121 if (INTEGERP (limit
)
2122 && next_iv
->position
>= XFASTINT (limit
))
2123 /* No text property change up to limit. */
2124 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2126 /* Text properties change in next_iv. */
2127 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2131 xassert (STRINGP (it
->string
)
2132 || (it
->stop_charpos
>= BEGV
2133 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2137 /* Return the position of the next overlay change after POS in
2138 current_buffer. Value is point-max if no overlay change
2139 follows. This is like `next-overlay-change' but doesn't use
2143 next_overlay_change (pos
)
2148 Lisp_Object
*overlays
;
2152 /* Get all overlays at the given position. */
2154 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2155 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2156 if (noverlays
> len
)
2159 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2160 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2163 /* If any of these overlays ends before endpos,
2164 use its ending point instead. */
2165 for (i
= 0; i
< noverlays
; ++i
)
2170 oend
= OVERLAY_END (overlays
[i
]);
2171 oendpos
= OVERLAY_POSITION (oend
);
2172 endpos
= min (endpos
, oendpos
);
2180 /***********************************************************************
2182 ***********************************************************************/
2184 /* Handle changes in the `fontified' property of the current buffer by
2185 calling hook functions from Qfontification_functions to fontify
2188 static enum prop_handled
2189 handle_fontified_prop (it
)
2192 Lisp_Object prop
, pos
;
2193 enum prop_handled handled
= HANDLED_NORMALLY
;
2195 /* Get the value of the `fontified' property at IT's current buffer
2196 position. (The `fontified' property doesn't have a special
2197 meaning in strings.) If the value is nil, call functions from
2198 Qfontification_functions. */
2199 if (!STRINGP (it
->string
)
2201 && !NILP (Vfontification_functions
)
2202 && !NILP (Vrun_hooks
)
2203 && (pos
= make_number (IT_CHARPOS (*it
)),
2204 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2207 int count
= BINDING_STACK_SIZE ();
2210 val
= Vfontification_functions
;
2211 specbind (Qfontification_functions
, Qnil
);
2212 specbind (Qafter_change_functions
, Qnil
);
2214 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2215 safe_call1 (val
, pos
);
2218 Lisp_Object globals
, fn
;
2219 struct gcpro gcpro1
, gcpro2
;
2222 GCPRO2 (val
, globals
);
2224 for (; CONSP (val
); val
= XCDR (val
))
2230 /* A value of t indicates this hook has a local
2231 binding; it means to run the global binding too.
2232 In a global value, t should not occur. If it
2233 does, we must ignore it to avoid an endless
2235 for (globals
= Fdefault_value (Qfontification_functions
);
2237 globals
= XCDR (globals
))
2239 fn
= XCAR (globals
);
2241 safe_call1 (fn
, pos
);
2245 safe_call1 (fn
, pos
);
2251 unbind_to (count
, Qnil
);
2253 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2254 something. This avoids an endless loop if they failed to
2255 fontify the text for which reason ever. */
2256 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2257 handled
= HANDLED_RECOMPUTE_PROPS
;
2265 /***********************************************************************
2267 ***********************************************************************/
2269 /* Set up iterator IT from face properties at its current position.
2270 Called from handle_stop. */
2272 static enum prop_handled
2273 handle_face_prop (it
)
2276 int new_face_id
, next_stop
;
2278 if (!STRINGP (it
->string
))
2281 = face_at_buffer_position (it
->w
,
2283 it
->region_beg_charpos
,
2284 it
->region_end_charpos
,
2287 + TEXT_PROP_DISTANCE_LIMIT
),
2290 /* Is this a start of a run of characters with box face?
2291 Caveat: this can be called for a freshly initialized
2292 iterator; face_id is -1 is this case. We know that the new
2293 face will not change until limit, i.e. if the new face has a
2294 box, all characters up to limit will have one. But, as
2295 usual, we don't know whether limit is really the end. */
2296 if (new_face_id
!= it
->face_id
)
2298 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2300 /* If new face has a box but old face has not, this is
2301 the start of a run of characters with box, i.e. it has
2302 a shadow on the left side. The value of face_id of the
2303 iterator will be -1 if this is the initial call that gets
2304 the face. In this case, we have to look in front of IT's
2305 position and see whether there is a face != new_face_id. */
2306 it
->start_of_box_run_p
2307 = (new_face
->box
!= FACE_NO_BOX
2308 && (it
->face_id
>= 0
2309 || IT_CHARPOS (*it
) == BEG
2310 || new_face_id
!= face_before_it_pos (it
)));
2311 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2316 int base_face_id
, bufpos
;
2318 if (it
->current
.overlay_string_index
>= 0)
2319 bufpos
= IT_CHARPOS (*it
);
2323 /* For strings from a buffer, i.e. overlay strings or strings
2324 from a `display' property, use the face at IT's current
2325 buffer position as the base face to merge with, so that
2326 overlay strings appear in the same face as surrounding
2327 text, unless they specify their own faces. */
2328 base_face_id
= underlying_face_id (it
);
2330 new_face_id
= face_at_string_position (it
->w
,
2332 IT_STRING_CHARPOS (*it
),
2334 it
->region_beg_charpos
,
2335 it
->region_end_charpos
,
2339 #if 0 /* This shouldn't be neccessary. Let's check it. */
2340 /* If IT is used to display a mode line we would really like to
2341 use the mode line face instead of the frame's default face. */
2342 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2343 && new_face_id
== DEFAULT_FACE_ID
)
2344 new_face_id
= MODE_LINE_FACE_ID
;
2347 /* Is this a start of a run of characters with box? Caveat:
2348 this can be called for a freshly allocated iterator; face_id
2349 is -1 is this case. We know that the new face will not
2350 change until the next check pos, i.e. if the new face has a
2351 box, all characters up to that position will have a
2352 box. But, as usual, we don't know whether that position
2353 is really the end. */
2354 if (new_face_id
!= it
->face_id
)
2356 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2357 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2359 /* If new face has a box but old face hasn't, this is the
2360 start of a run of characters with box, i.e. it has a
2361 shadow on the left side. */
2362 it
->start_of_box_run_p
2363 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2364 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2368 it
->face_id
= new_face_id
;
2369 return HANDLED_NORMALLY
;
2373 /* Return the ID of the face ``underlying'' IT's current position,
2374 which is in a string. If the iterator is associated with a
2375 buffer, return the face at IT's current buffer position.
2376 Otherwise, use the iterator's base_face_id. */
2379 underlying_face_id (it
)
2382 int face_id
= it
->base_face_id
, i
;
2384 xassert (STRINGP (it
->string
));
2386 for (i
= it
->sp
- 1; i
>= 0; --i
)
2387 if (NILP (it
->stack
[i
].string
))
2388 face_id
= it
->stack
[i
].face_id
;
2394 /* Compute the face one character before or after the current position
2395 of IT. BEFORE_P non-zero means get the face in front of IT's
2396 position. Value is the id of the face. */
2399 face_before_or_after_it_pos (it
, before_p
)
2404 int next_check_charpos
;
2405 struct text_pos pos
;
2407 xassert (it
->s
== NULL
);
2409 if (STRINGP (it
->string
))
2411 int bufpos
, base_face_id
;
2413 /* No face change past the end of the string (for the case
2414 we are padding with spaces). No face change before the
2416 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2417 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2420 /* Set pos to the position before or after IT's current position. */
2422 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2424 /* For composition, we must check the character after the
2426 pos
= (it
->what
== IT_COMPOSITION
2427 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2428 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2430 if (it
->current
.overlay_string_index
>= 0)
2431 bufpos
= IT_CHARPOS (*it
);
2435 base_face_id
= underlying_face_id (it
);
2437 /* Get the face for ASCII, or unibyte. */
2438 face_id
= face_at_string_position (it
->w
,
2442 it
->region_beg_charpos
,
2443 it
->region_end_charpos
,
2444 &next_check_charpos
,
2447 /* Correct the face for charsets different from ASCII. Do it
2448 for the multibyte case only. The face returned above is
2449 suitable for unibyte text if IT->string is unibyte. */
2450 if (STRING_MULTIBYTE (it
->string
))
2452 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2453 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2455 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2457 c
= string_char_and_length (p
, rest
, &len
);
2458 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2463 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2464 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2467 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2468 pos
= it
->current
.pos
;
2471 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2474 if (it
->what
== IT_COMPOSITION
)
2475 /* For composition, we must check the position after the
2477 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2479 INC_TEXT_POS (pos
, it
->multibyte_p
);
2482 /* Determine face for CHARSET_ASCII, or unibyte. */
2483 face_id
= face_at_buffer_position (it
->w
,
2485 it
->region_beg_charpos
,
2486 it
->region_end_charpos
,
2487 &next_check_charpos
,
2490 /* Correct the face for charsets different from ASCII. Do it
2491 for the multibyte case only. The face returned above is
2492 suitable for unibyte text if current_buffer is unibyte. */
2493 if (it
->multibyte_p
)
2495 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2496 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2497 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2506 /***********************************************************************
2508 ***********************************************************************/
2510 /* Set up iterator IT from invisible properties at its current
2511 position. Called from handle_stop. */
2513 static enum prop_handled
2514 handle_invisible_prop (it
)
2517 enum prop_handled handled
= HANDLED_NORMALLY
;
2519 if (STRINGP (it
->string
))
2521 extern Lisp_Object Qinvisible
;
2522 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2524 /* Get the value of the invisible text property at the
2525 current position. Value will be nil if there is no such
2527 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2528 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2531 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2533 handled
= HANDLED_RECOMPUTE_PROPS
;
2535 /* Get the position at which the next change of the
2536 invisible text property can be found in IT->string.
2537 Value will be nil if the property value is the same for
2538 all the rest of IT->string. */
2539 XSETINT (limit
, XSTRING (it
->string
)->size
);
2540 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2543 /* Text at current position is invisible. The next
2544 change in the property is at position end_charpos.
2545 Move IT's current position to that position. */
2546 if (INTEGERP (end_charpos
)
2547 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2549 struct text_pos old
;
2550 old
= it
->current
.string_pos
;
2551 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2552 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2556 /* The rest of the string is invisible. If this is an
2557 overlay string, proceed with the next overlay string
2558 or whatever comes and return a character from there. */
2559 if (it
->current
.overlay_string_index
>= 0)
2561 next_overlay_string (it
);
2562 /* Don't check for overlay strings when we just
2563 finished processing them. */
2564 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2568 struct Lisp_String
*s
= XSTRING (it
->string
);
2569 IT_STRING_CHARPOS (*it
) = s
->size
;
2570 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2577 int visible_p
, newpos
, next_stop
, start_charpos
;
2578 Lisp_Object pos
, prop
, overlay
;
2580 /* First of all, is there invisible text at this position? */
2581 start_charpos
= IT_CHARPOS (*it
);
2582 pos
= make_number (IT_CHARPOS (*it
));
2583 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2586 /* If we are on invisible text, skip over it. */
2587 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2588 && IT_CHARPOS (*it
) < it
->end_charpos
)
2590 /* Record whether we have to display an ellipsis for the
2592 int display_ellipsis_p
2593 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2595 handled
= HANDLED_RECOMPUTE_PROPS
;
2597 /* Loop skipping over invisible text. The loop is left at
2598 ZV or with IT on the first char being visible again. */
2601 /* Try to skip some invisible text. Return value is the
2602 position reached which can be equal to IT's position
2603 if there is nothing invisible here. This skips both
2604 over invisible text properties and overlays with
2605 invisible property. */
2606 newpos
= skip_invisible (IT_CHARPOS (*it
),
2607 &next_stop
, ZV
, it
->window
);
2609 /* If we skipped nothing at all we weren't at invisible
2610 text in the first place. If everything to the end of
2611 the buffer was skipped, end the loop. */
2612 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2616 /* We skipped some characters but not necessarily
2617 all there are. Check if we ended up on visible
2618 text. Fget_char_property returns the property of
2619 the char before the given position, i.e. if we
2620 get visible_p = 1, this means that the char at
2621 newpos is visible. */
2622 pos
= make_number (newpos
);
2623 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2624 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2627 /* If we ended up on invisible text, proceed to
2628 skip starting with next_stop. */
2630 IT_CHARPOS (*it
) = next_stop
;
2634 /* The position newpos is now either ZV or on visible text. */
2635 IT_CHARPOS (*it
) = newpos
;
2636 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2638 /* If there are before-strings at the start of invisible
2639 text, and the text is invisible because of a text
2640 property, arrange to show before-strings because 20.x did
2641 it that way. (If the text is invisible because of an
2642 overlay property instead of a text property, this is
2643 already handled in the overlay code.) */
2645 && get_overlay_strings (it
, start_charpos
))
2647 handled
= HANDLED_RECOMPUTE_PROPS
;
2648 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2650 else if (display_ellipsis_p
)
2651 setup_for_ellipsis (it
);
2659 /* Make iterator IT return `...' next. */
2662 setup_for_ellipsis (it
)
2666 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2668 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2669 it
->dpvec
= v
->contents
;
2670 it
->dpend
= v
->contents
+ v
->size
;
2674 /* Default `...'. */
2675 it
->dpvec
= default_invis_vector
;
2676 it
->dpend
= default_invis_vector
+ 3;
2679 /* The ellipsis display does not replace the display of the
2680 character at the new position. Indicate this by setting
2681 IT->dpvec_char_len to zero. */
2682 it
->dpvec_char_len
= 0;
2684 it
->current
.dpvec_index
= 0;
2685 it
->method
= next_element_from_display_vector
;
2690 /***********************************************************************
2692 ***********************************************************************/
2694 /* Set up iterator IT from `display' property at its current position.
2695 Called from handle_stop. */
2697 static enum prop_handled
2698 handle_display_prop (it
)
2701 Lisp_Object prop
, object
;
2702 struct text_pos
*position
;
2703 int display_replaced_p
= 0;
2705 if (STRINGP (it
->string
))
2707 object
= it
->string
;
2708 position
= &it
->current
.string_pos
;
2712 object
= it
->w
->buffer
;
2713 position
= &it
->current
.pos
;
2716 /* Reset those iterator values set from display property values. */
2717 it
->font_height
= Qnil
;
2718 it
->space_width
= Qnil
;
2721 /* We don't support recursive `display' properties, i.e. string
2722 values that have a string `display' property, that have a string
2723 `display' property etc. */
2724 if (!it
->string_from_display_prop_p
)
2725 it
->area
= TEXT_AREA
;
2727 prop
= Fget_char_property (make_number (position
->charpos
),
2730 return HANDLED_NORMALLY
;
2733 /* Simple properties. */
2734 && !EQ (XCAR (prop
), Qimage
)
2735 && !EQ (XCAR (prop
), Qspace
)
2736 && !EQ (XCAR (prop
), Qwhen
)
2737 && !EQ (XCAR (prop
), Qspace_width
)
2738 && !EQ (XCAR (prop
), Qheight
)
2739 && !EQ (XCAR (prop
), Qraise
)
2740 /* Marginal area specifications. */
2741 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2742 && !NILP (XCAR (prop
)))
2744 for (; CONSP (prop
); prop
= XCDR (prop
))
2746 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2747 position
, display_replaced_p
))
2748 display_replaced_p
= 1;
2751 else if (VECTORP (prop
))
2754 for (i
= 0; i
< ASIZE (prop
); ++i
)
2755 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2756 position
, display_replaced_p
))
2757 display_replaced_p
= 1;
2761 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2762 display_replaced_p
= 1;
2765 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2769 /* Value is the position of the end of the `display' property starting
2770 at START_POS in OBJECT. */
2772 static struct text_pos
2773 display_prop_end (it
, object
, start_pos
)
2776 struct text_pos start_pos
;
2779 struct text_pos end_pos
;
2781 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2782 Qdisplay
, object
, Qnil
);
2783 CHARPOS (end_pos
) = XFASTINT (end
);
2784 if (STRINGP (object
))
2785 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2787 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2793 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2794 is the object in which the `display' property was found. *POSITION
2795 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2796 means that we previously saw a display sub-property which already
2797 replaced text display with something else, for example an image;
2798 ignore such properties after the first one has been processed.
2800 If PROP is a `space' or `image' sub-property, set *POSITION to the
2801 end position of the `display' property.
2803 Value is non-zero something was found which replaces the display
2804 of buffer or string text. */
2807 handle_single_display_prop (it
, prop
, object
, position
,
2808 display_replaced_before_p
)
2812 struct text_pos
*position
;
2813 int display_replaced_before_p
;
2816 int replaces_text_display_p
= 0;
2819 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2820 evaluated. If the result is nil, VALUE is ignored. */
2822 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2831 if (!NILP (form
) && !EQ (form
, Qt
))
2833 int count
= BINDING_STACK_SIZE ();
2834 struct gcpro gcpro1
;
2836 /* Bind `object' to the object having the `display' property, a
2837 buffer or string. Bind `position' to the position in the
2838 object where the property was found, and `buffer-position'
2839 to the current position in the buffer. */
2840 specbind (Qobject
, object
);
2841 specbind (Qposition
, make_number (CHARPOS (*position
)));
2842 specbind (Qbuffer_position
,
2843 make_number (STRINGP (object
)
2844 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2846 form
= safe_eval (form
);
2848 unbind_to (count
, Qnil
);
2855 && EQ (XCAR (prop
), Qheight
)
2856 && CONSP (XCDR (prop
)))
2858 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2861 /* `(height HEIGHT)'. */
2862 it
->font_height
= XCAR (XCDR (prop
));
2863 if (!NILP (it
->font_height
))
2865 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2866 int new_height
= -1;
2868 if (CONSP (it
->font_height
)
2869 && (EQ (XCAR (it
->font_height
), Qplus
)
2870 || EQ (XCAR (it
->font_height
), Qminus
))
2871 && CONSP (XCDR (it
->font_height
))
2872 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2874 /* `(+ N)' or `(- N)' where N is an integer. */
2875 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2876 if (EQ (XCAR (it
->font_height
), Qplus
))
2878 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2880 else if (FUNCTIONP (it
->font_height
))
2882 /* Call function with current height as argument.
2883 Value is the new height. */
2885 height
= safe_call1 (it
->font_height
,
2886 face
->lface
[LFACE_HEIGHT_INDEX
]);
2887 if (NUMBERP (height
))
2888 new_height
= XFLOATINT (height
);
2890 else if (NUMBERP (it
->font_height
))
2892 /* Value is a multiple of the canonical char height. */
2895 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2896 new_height
= (XFLOATINT (it
->font_height
)
2897 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2901 /* Evaluate IT->font_height with `height' bound to the
2902 current specified height to get the new height. */
2904 int count
= BINDING_STACK_SIZE ();
2906 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2907 value
= safe_eval (it
->font_height
);
2908 unbind_to (count
, Qnil
);
2910 if (NUMBERP (value
))
2911 new_height
= XFLOATINT (value
);
2915 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2918 else if (CONSP (prop
)
2919 && EQ (XCAR (prop
), Qspace_width
)
2920 && CONSP (XCDR (prop
)))
2922 /* `(space_width WIDTH)'. */
2923 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2926 value
= XCAR (XCDR (prop
));
2927 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2928 it
->space_width
= value
;
2930 else if (CONSP (prop
)
2931 && EQ (XCAR (prop
), Qraise
)
2932 && CONSP (XCDR (prop
)))
2934 /* `(raise FACTOR)'. */
2935 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2938 #ifdef HAVE_WINDOW_SYSTEM
2939 value
= XCAR (XCDR (prop
));
2940 if (NUMBERP (value
))
2942 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2943 it
->voffset
= - (XFLOATINT (value
)
2944 * (FONT_HEIGHT (face
->font
)));
2946 #endif /* HAVE_WINDOW_SYSTEM */
2948 else if (!it
->string_from_display_prop_p
)
2950 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2951 VALUE) or `((margin nil) VALUE)' or VALUE. */
2952 Lisp_Object location
, value
;
2953 struct text_pos start_pos
;
2956 /* Characters having this form of property are not displayed, so
2957 we have to find the end of the property. */
2958 start_pos
= *position
;
2959 *position
= display_prop_end (it
, object
, start_pos
);
2962 /* Let's stop at the new position and assume that all
2963 text properties change there. */
2964 it
->stop_charpos
= position
->charpos
;
2966 location
= Qunbound
;
2967 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2971 value
= XCDR (prop
);
2973 value
= XCAR (value
);
2976 if (EQ (XCAR (tem
), Qmargin
)
2977 && (tem
= XCDR (tem
),
2978 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2980 || EQ (tem
, Qleft_margin
)
2981 || EQ (tem
, Qright_margin
))))
2985 if (EQ (location
, Qunbound
))
2991 #ifdef HAVE_WINDOW_SYSTEM
2992 if (FRAME_TERMCAP_P (it
->f
))
2993 valid_p
= STRINGP (value
);
2995 valid_p
= (STRINGP (value
)
2996 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2997 || valid_image_p (value
));
2998 #else /* not HAVE_WINDOW_SYSTEM */
2999 valid_p
= STRINGP (value
);
3000 #endif /* not HAVE_WINDOW_SYSTEM */
3002 if ((EQ (location
, Qleft_margin
)
3003 || EQ (location
, Qright_margin
)
3006 && !display_replaced_before_p
)
3008 replaces_text_display_p
= 1;
3010 /* Save current settings of IT so that we can restore them
3011 when we are finished with the glyph property value. */
3014 if (NILP (location
))
3015 it
->area
= TEXT_AREA
;
3016 else if (EQ (location
, Qleft_margin
))
3017 it
->area
= LEFT_MARGIN_AREA
;
3019 it
->area
= RIGHT_MARGIN_AREA
;
3021 if (STRINGP (value
))
3024 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3025 it
->current
.overlay_string_index
= -1;
3026 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3027 it
->end_charpos
= it
->string_nchars
3028 = XSTRING (it
->string
)->size
;
3029 it
->method
= next_element_from_string
;
3030 it
->stop_charpos
= 0;
3031 it
->string_from_display_prop_p
= 1;
3032 /* Say that we haven't consumed the characters with
3033 `display' property yet. The call to pop_it in
3034 set_iterator_to_next will clean this up. */
3035 *position
= start_pos
;
3037 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3039 it
->method
= next_element_from_stretch
;
3041 it
->current
.pos
= it
->position
= start_pos
;
3043 #ifdef HAVE_WINDOW_SYSTEM
3046 it
->what
= IT_IMAGE
;
3047 it
->image_id
= lookup_image (it
->f
, value
);
3048 it
->position
= start_pos
;
3049 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3050 it
->method
= next_element_from_image
;
3052 /* Say that we haven't consumed the characters with
3053 `display' property yet. The call to pop_it in
3054 set_iterator_to_next will clean this up. */
3055 *position
= start_pos
;
3057 #endif /* HAVE_WINDOW_SYSTEM */
3060 /* Invalid property or property not supported. Restore
3061 the position to what it was before. */
3062 *position
= start_pos
;
3065 return replaces_text_display_p
;
3069 /* Check if PROP is a display sub-property value whose text should be
3070 treated as intangible. */
3073 single_display_prop_intangible_p (prop
)
3076 /* Skip over `when FORM'. */
3077 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3088 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3089 we don't need to treat text as intangible. */
3090 if (EQ (XCAR (prop
), Qmargin
))
3098 || EQ (XCAR (prop
), Qleft_margin
)
3099 || EQ (XCAR (prop
), Qright_margin
))
3103 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3107 /* Check if PROP is a display property value whose text should be
3108 treated as intangible. */
3111 display_prop_intangible_p (prop
)
3115 && CONSP (XCAR (prop
))
3116 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3118 /* A list of sub-properties. */
3119 while (CONSP (prop
))
3121 if (single_display_prop_intangible_p (XCAR (prop
)))
3126 else if (VECTORP (prop
))
3128 /* A vector of sub-properties. */
3130 for (i
= 0; i
< ASIZE (prop
); ++i
)
3131 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3135 return single_display_prop_intangible_p (prop
);
3141 /* Return 1 if PROP is a display sub-property value containing STRING. */
3144 single_display_prop_string_p (prop
, string
)
3145 Lisp_Object prop
, string
;
3147 extern Lisp_Object Qwhen
, Qmargin
;
3149 if (EQ (string
, prop
))
3152 /* Skip over `when FORM'. */
3153 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3162 /* Skip over `margin LOCATION'. */
3163 if (EQ (XCAR (prop
), Qmargin
))
3174 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3178 /* Return 1 if STRING appears in the `display' property PROP. */
3181 display_prop_string_p (prop
, string
)
3182 Lisp_Object prop
, string
;
3184 extern Lisp_Object Qwhen
, Qmargin
;
3187 && CONSP (XCAR (prop
))
3188 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3190 /* A list of sub-properties. */
3191 while (CONSP (prop
))
3193 if (single_display_prop_string_p (XCAR (prop
), string
))
3198 else if (VECTORP (prop
))
3200 /* A vector of sub-properties. */
3202 for (i
= 0; i
< ASIZE (prop
); ++i
)
3203 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3207 return single_display_prop_string_p (prop
, string
);
3213 /* Determine from which buffer position in W's buffer STRING comes
3214 from. AROUND_CHARPOS is an approximate position where it could
3215 be from. Value is the buffer position or 0 if it couldn't be
3218 W's buffer must be current.
3220 This function is necessary because we don't record buffer positions
3221 in glyphs generated from strings (to keep struct glyph small).
3222 This function may only use code that doesn't eval because it is
3223 called asynchronously from note_mouse_highlight. */
3226 string_buffer_position (w
, string
, around_charpos
)
3231 Lisp_Object around
= make_number (around_charpos
);
3232 Lisp_Object limit
, prop
, pos
;
3233 const int MAX_DISTANCE
= 1000;
3236 pos
= make_number (around_charpos
);
3237 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3238 while (!found
&& !EQ (pos
, limit
))
3240 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3241 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3244 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3249 pos
= make_number (around_charpos
);
3250 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3251 while (!found
&& !EQ (pos
, limit
))
3253 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3254 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3257 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3262 return found
? XINT (pos
) : 0;
3267 /***********************************************************************
3268 `composition' property
3269 ***********************************************************************/
3271 /* Set up iterator IT from `composition' property at its current
3272 position. Called from handle_stop. */
3274 static enum prop_handled
3275 handle_composition_prop (it
)
3278 Lisp_Object prop
, string
;
3279 int pos
, pos_byte
, end
;
3280 enum prop_handled handled
= HANDLED_NORMALLY
;
3282 if (STRINGP (it
->string
))
3284 pos
= IT_STRING_CHARPOS (*it
);
3285 pos_byte
= IT_STRING_BYTEPOS (*it
);
3286 string
= it
->string
;
3290 pos
= IT_CHARPOS (*it
);
3291 pos_byte
= IT_BYTEPOS (*it
);
3295 /* If there's a valid composition and point is not inside of the
3296 composition (in the case that the composition is from the current
3297 buffer), draw a glyph composed from the composition components. */
3298 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3299 && COMPOSITION_VALID_P (pos
, end
, prop
)
3300 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3302 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3306 it
->method
= next_element_from_composition
;
3308 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3309 /* For a terminal, draw only the first character of the
3311 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3312 it
->len
= (STRINGP (it
->string
)
3313 ? string_char_to_byte (it
->string
, end
)
3314 : CHAR_TO_BYTE (end
)) - pos_byte
;
3315 it
->stop_charpos
= end
;
3316 handled
= HANDLED_RETURN
;
3325 /***********************************************************************
3327 ***********************************************************************/
3329 /* The following structure is used to record overlay strings for
3330 later sorting in load_overlay_strings. */
3332 struct overlay_entry
3334 Lisp_Object overlay
;
3341 /* Set up iterator IT from overlay strings at its current position.
3342 Called from handle_stop. */
3344 static enum prop_handled
3345 handle_overlay_change (it
)
3348 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3349 return HANDLED_RECOMPUTE_PROPS
;
3351 return HANDLED_NORMALLY
;
3355 /* Set up the next overlay string for delivery by IT, if there is an
3356 overlay string to deliver. Called by set_iterator_to_next when the
3357 end of the current overlay string is reached. If there are more
3358 overlay strings to display, IT->string and
3359 IT->current.overlay_string_index are set appropriately here.
3360 Otherwise IT->string is set to nil. */
3363 next_overlay_string (it
)
3366 ++it
->current
.overlay_string_index
;
3367 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3369 /* No more overlay strings. Restore IT's settings to what
3370 they were before overlay strings were processed, and
3371 continue to deliver from current_buffer. */
3372 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3375 xassert (it
->stop_charpos
>= BEGV
3376 && it
->stop_charpos
<= it
->end_charpos
);
3378 it
->current
.overlay_string_index
= -1;
3379 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3380 it
->n_overlay_strings
= 0;
3381 it
->method
= next_element_from_buffer
;
3383 /* If we're at the end of the buffer, record that we have
3384 processed the overlay strings there already, so that
3385 next_element_from_buffer doesn't try it again. */
3386 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3387 it
->overlay_strings_at_end_processed_p
= 1;
3389 /* If we have to display `...' for invisible text, set
3390 the iterator up for that. */
3391 if (display_ellipsis_p
)
3392 setup_for_ellipsis (it
);
3396 /* There are more overlay strings to process. If
3397 IT->current.overlay_string_index has advanced to a position
3398 where we must load IT->overlay_strings with more strings, do
3400 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3402 if (it
->current
.overlay_string_index
&& i
== 0)
3403 load_overlay_strings (it
, 0);
3405 /* Initialize IT to deliver display elements from the overlay
3407 it
->string
= it
->overlay_strings
[i
];
3408 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3409 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3410 it
->method
= next_element_from_string
;
3411 it
->stop_charpos
= 0;
3418 /* Compare two overlay_entry structures E1 and E2. Used as a
3419 comparison function for qsort in load_overlay_strings. Overlay
3420 strings for the same position are sorted so that
3422 1. All after-strings come in front of before-strings, except
3423 when they come from the same overlay.
3425 2. Within after-strings, strings are sorted so that overlay strings
3426 from overlays with higher priorities come first.
3428 2. Within before-strings, strings are sorted so that overlay
3429 strings from overlays with higher priorities come last.
3431 Value is analogous to strcmp. */
3435 compare_overlay_entries (e1
, e2
)
3438 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3439 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3442 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3444 /* Let after-strings appear in front of before-strings if
3445 they come from different overlays. */
3446 if (EQ (entry1
->overlay
, entry2
->overlay
))
3447 result
= entry1
->after_string_p
? 1 : -1;
3449 result
= entry1
->after_string_p
? -1 : 1;
3451 else if (entry1
->after_string_p
)
3452 /* After-strings sorted in order of decreasing priority. */
3453 result
= entry2
->priority
- entry1
->priority
;
3455 /* Before-strings sorted in order of increasing priority. */
3456 result
= entry1
->priority
- entry2
->priority
;
3462 /* Load the vector IT->overlay_strings with overlay strings from IT's
3463 current buffer position, or from CHARPOS if that is > 0. Set
3464 IT->n_overlays to the total number of overlay strings found.
3466 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3467 a time. On entry into load_overlay_strings,
3468 IT->current.overlay_string_index gives the number of overlay
3469 strings that have already been loaded by previous calls to this
3472 IT->add_overlay_start contains an additional overlay start
3473 position to consider for taking overlay strings from, if non-zero.
3474 This position comes into play when the overlay has an `invisible'
3475 property, and both before and after-strings. When we've skipped to
3476 the end of the overlay, because of its `invisible' property, we
3477 nevertheless want its before-string to appear.
3478 IT->add_overlay_start will contain the overlay start position
3481 Overlay strings are sorted so that after-string strings come in
3482 front of before-string strings. Within before and after-strings,
3483 strings are sorted by overlay priority. See also function
3484 compare_overlay_entries. */
3487 load_overlay_strings (it
, charpos
)
3491 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3492 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3495 int n
= 0, i
, j
, invis_p
;
3496 struct overlay_entry
*entries
3497 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3500 charpos
= IT_CHARPOS (*it
);
3502 /* Append the overlay string STRING of overlay OVERLAY to vector
3503 `entries' which has size `size' and currently contains `n'
3504 elements. AFTER_P non-zero means STRING is an after-string of
3506 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3509 Lisp_Object priority; \
3513 int new_size = 2 * size; \
3514 struct overlay_entry *old = entries; \
3516 (struct overlay_entry *) alloca (new_size \
3517 * sizeof *entries); \
3518 bcopy (old, entries, size * sizeof *entries); \
3522 entries[n].string = (STRING); \
3523 entries[n].overlay = (OVERLAY); \
3524 priority = Foverlay_get ((OVERLAY), Qpriority); \
3525 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3526 entries[n].after_string_p = (AFTER_P); \
3531 /* Process overlay before the overlay center. */
3532 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3534 overlay
= XCAR (ov
);
3535 xassert (OVERLAYP (overlay
));
3536 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3537 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3542 /* Skip this overlay if it doesn't start or end at IT's current
3544 if (end
!= charpos
&& start
!= charpos
)
3547 /* Skip this overlay if it doesn't apply to IT->w. */
3548 window
= Foverlay_get (overlay
, Qwindow
);
3549 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3552 /* If the text ``under'' the overlay is invisible, both before-
3553 and after-strings from this overlay are visible; start and
3554 end position are indistinguishable. */
3555 invisible
= Foverlay_get (overlay
, Qinvisible
);
3556 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3558 /* If overlay has a non-empty before-string, record it. */
3559 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3560 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3561 && XSTRING (str
)->size
)
3562 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3564 /* If overlay has a non-empty after-string, record it. */
3565 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3566 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3567 && XSTRING (str
)->size
)
3568 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3571 /* Process overlays after the overlay center. */
3572 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3574 overlay
= XCAR (ov
);
3575 xassert (OVERLAYP (overlay
));
3576 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3577 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3579 if (start
> charpos
)
3582 /* Skip this overlay if it doesn't start or end at IT's current
3584 if (end
!= charpos
&& start
!= charpos
)
3587 /* Skip this overlay if it doesn't apply to IT->w. */
3588 window
= Foverlay_get (overlay
, Qwindow
);
3589 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3592 /* If the text ``under'' the overlay is invisible, it has a zero
3593 dimension, and both before- and after-strings apply. */
3594 invisible
= Foverlay_get (overlay
, Qinvisible
);
3595 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3597 /* If overlay has a non-empty before-string, record it. */
3598 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3599 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3600 && XSTRING (str
)->size
)
3601 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3603 /* If overlay has a non-empty after-string, record it. */
3604 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3605 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3606 && XSTRING (str
)->size
)
3607 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3610 #undef RECORD_OVERLAY_STRING
3614 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3616 /* Record the total number of strings to process. */
3617 it
->n_overlay_strings
= n
;
3619 /* IT->current.overlay_string_index is the number of overlay strings
3620 that have already been consumed by IT. Copy some of the
3621 remaining overlay strings to IT->overlay_strings. */
3623 j
= it
->current
.overlay_string_index
;
3624 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3625 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3631 /* Get the first chunk of overlay strings at IT's current buffer
3632 position, or at CHARPOS if that is > 0. Value is non-zero if at
3633 least one overlay string was found. */
3636 get_overlay_strings (it
, charpos
)
3640 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3641 process. This fills IT->overlay_strings with strings, and sets
3642 IT->n_overlay_strings to the total number of strings to process.
3643 IT->pos.overlay_string_index has to be set temporarily to zero
3644 because load_overlay_strings needs this; it must be set to -1
3645 when no overlay strings are found because a zero value would
3646 indicate a position in the first overlay string. */
3647 it
->current
.overlay_string_index
= 0;
3648 load_overlay_strings (it
, charpos
);
3650 /* If we found overlay strings, set up IT to deliver display
3651 elements from the first one. Otherwise set up IT to deliver
3652 from current_buffer. */
3653 if (it
->n_overlay_strings
)
3655 /* Make sure we know settings in current_buffer, so that we can
3656 restore meaningful values when we're done with the overlay
3658 compute_stop_pos (it
);
3659 xassert (it
->face_id
>= 0);
3661 /* Save IT's settings. They are restored after all overlay
3662 strings have been processed. */
3663 xassert (it
->sp
== 0);
3666 /* Set up IT to deliver display elements from the first overlay
3668 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3669 it
->string
= it
->overlay_strings
[0];
3670 it
->stop_charpos
= 0;
3671 it
->end_charpos
= XSTRING (it
->string
)->size
;
3672 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3673 xassert (STRINGP (it
->string
));
3674 it
->method
= next_element_from_string
;
3679 it
->current
.overlay_string_index
= -1;
3680 it
->method
= next_element_from_buffer
;
3685 /* Value is non-zero if we found at least one overlay string. */
3686 return STRINGP (it
->string
);
3691 /***********************************************************************
3692 Saving and restoring state
3693 ***********************************************************************/
3695 /* Save current settings of IT on IT->stack. Called, for example,
3696 before setting up IT for an overlay string, to be able to restore
3697 IT's settings to what they were after the overlay string has been
3704 struct iterator_stack_entry
*p
;
3706 xassert (it
->sp
< 2);
3707 p
= it
->stack
+ it
->sp
;
3709 p
->stop_charpos
= it
->stop_charpos
;
3710 xassert (it
->face_id
>= 0);
3711 p
->face_id
= it
->face_id
;
3712 p
->string
= it
->string
;
3713 p
->pos
= it
->current
;
3714 p
->end_charpos
= it
->end_charpos
;
3715 p
->string_nchars
= it
->string_nchars
;
3717 p
->multibyte_p
= it
->multibyte_p
;
3718 p
->space_width
= it
->space_width
;
3719 p
->font_height
= it
->font_height
;
3720 p
->voffset
= it
->voffset
;
3721 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3722 p
->display_ellipsis_p
= 0;
3727 /* Restore IT's settings from IT->stack. Called, for example, when no
3728 more overlay strings must be processed, and we return to delivering
3729 display elements from a buffer, or when the end of a string from a
3730 `display' property is reached and we return to delivering display
3731 elements from an overlay string, or from a buffer. */
3737 struct iterator_stack_entry
*p
;
3739 xassert (it
->sp
> 0);
3741 p
= it
->stack
+ it
->sp
;
3742 it
->stop_charpos
= p
->stop_charpos
;
3743 it
->face_id
= p
->face_id
;
3744 it
->string
= p
->string
;
3745 it
->current
= p
->pos
;
3746 it
->end_charpos
= p
->end_charpos
;
3747 it
->string_nchars
= p
->string_nchars
;
3749 it
->multibyte_p
= p
->multibyte_p
;
3750 it
->space_width
= p
->space_width
;
3751 it
->font_height
= p
->font_height
;
3752 it
->voffset
= p
->voffset
;
3753 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3758 /***********************************************************************
3760 ***********************************************************************/
3762 /* Set IT's current position to the previous line start. */
3765 back_to_previous_line_start (it
)
3768 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3769 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3773 /* Move IT to the next line start.
3775 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3776 we skipped over part of the text (as opposed to moving the iterator
3777 continuously over the text). Otherwise, don't change the value
3780 Newlines may come from buffer text, overlay strings, or strings
3781 displayed via the `display' property. That's the reason we can't
3782 simply use find_next_newline_no_quit.
3784 Note that this function may not skip over invisible text that is so
3785 because of text properties and immediately follows a newline. If
3786 it would, function reseat_at_next_visible_line_start, when called
3787 from set_iterator_to_next, would effectively make invisible
3788 characters following a newline part of the wrong glyph row, which
3789 leads to wrong cursor motion. */
3792 forward_to_next_line_start (it
, skipped_p
)
3796 int old_selective
, newline_found_p
, n
;
3797 const int MAX_NEWLINE_DISTANCE
= 500;
3799 /* If already on a newline, just consume it to avoid unintended
3800 skipping over invisible text below. */
3801 if (it
->what
== IT_CHARACTER
3803 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3805 set_iterator_to_next (it
, 0);
3810 /* Don't handle selective display in the following. It's (a)
3811 unnecessary because it's done by the caller, and (b) leads to an
3812 infinite recursion because next_element_from_ellipsis indirectly
3813 calls this function. */
3814 old_selective
= it
->selective
;
3817 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3818 from buffer text. */
3819 for (n
= newline_found_p
= 0;
3820 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3821 n
+= STRINGP (it
->string
) ? 0 : 1)
3823 if (!get_next_display_element (it
))
3825 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3826 set_iterator_to_next (it
, 0);
3829 /* If we didn't find a newline near enough, see if we can use a
3831 if (n
== MAX_NEWLINE_DISTANCE
)
3833 int start
= IT_CHARPOS (*it
);
3834 int limit
= find_next_newline_no_quit (start
, 1);
3837 xassert (!STRINGP (it
->string
));
3839 /* If there isn't any `display' property in sight, and no
3840 overlays, we can just use the position of the newline in
3842 if (it
->stop_charpos
>= limit
3843 || ((pos
= Fnext_single_property_change (make_number (start
),
3845 Qnil
, make_number (limit
)),
3847 && next_overlay_change (start
) == ZV
))
3849 IT_CHARPOS (*it
) = limit
;
3850 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3851 *skipped_p
= newline_found_p
= 1;
3855 while (get_next_display_element (it
)
3856 && !newline_found_p
)
3858 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3859 set_iterator_to_next (it
, 0);
3864 it
->selective
= old_selective
;
3865 return newline_found_p
;
3869 /* Set IT's current position to the previous visible line start. Skip
3870 invisible text that is so either due to text properties or due to
3871 selective display. Caution: this does not change IT->current_x and
3875 back_to_previous_visible_line_start (it
)
3880 /* Go back one newline if not on BEGV already. */
3881 if (IT_CHARPOS (*it
) > BEGV
)
3882 back_to_previous_line_start (it
);
3884 /* Move over lines that are invisible because of selective display
3885 or text properties. */
3886 while (IT_CHARPOS (*it
) > BEGV
3891 /* If selective > 0, then lines indented more than that values
3893 if (it
->selective
> 0
3894 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3901 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3902 Qinvisible
, it
->window
);
3903 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3907 /* Back one more newline if the current one is invisible. */
3909 back_to_previous_line_start (it
);
3912 xassert (IT_CHARPOS (*it
) >= BEGV
);
3913 xassert (IT_CHARPOS (*it
) == BEGV
3914 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3919 /* Reseat iterator IT at the previous visible line start. Skip
3920 invisible text that is so either due to text properties or due to
3921 selective display. At the end, update IT's overlay information,
3922 face information etc. */
3925 reseat_at_previous_visible_line_start (it
)
3928 back_to_previous_visible_line_start (it
);
3929 reseat (it
, it
->current
.pos
, 1);
3934 /* Reseat iterator IT on the next visible line start in the current
3935 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3936 preceding the line start. Skip over invisible text that is so
3937 because of selective display. Compute faces, overlays etc at the
3938 new position. Note that this function does not skip over text that
3939 is invisible because of text properties. */
3942 reseat_at_next_visible_line_start (it
, on_newline_p
)
3946 int newline_found_p
, skipped_p
= 0;
3948 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3950 /* Skip over lines that are invisible because they are indented
3951 more than the value of IT->selective. */
3952 if (it
->selective
> 0)
3953 while (IT_CHARPOS (*it
) < ZV
3954 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3957 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3958 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3961 /* Position on the newline if that's what's requested. */
3962 if (on_newline_p
&& newline_found_p
)
3964 if (STRINGP (it
->string
))
3966 if (IT_STRING_CHARPOS (*it
) > 0)
3968 --IT_STRING_CHARPOS (*it
);
3969 --IT_STRING_BYTEPOS (*it
);
3972 else if (IT_CHARPOS (*it
) > BEGV
)
3976 reseat (it
, it
->current
.pos
, 0);
3980 reseat (it
, it
->current
.pos
, 0);
3987 /***********************************************************************
3988 Changing an iterator's position
3989 ***********************************************************************/
3991 /* Change IT's current position to POS in current_buffer. If FORCE_P
3992 is non-zero, always check for text properties at the new position.
3993 Otherwise, text properties are only looked up if POS >=
3994 IT->check_charpos of a property. */
3997 reseat (it
, pos
, force_p
)
3999 struct text_pos pos
;
4002 int original_pos
= IT_CHARPOS (*it
);
4004 reseat_1 (it
, pos
, 0);
4006 /* Determine where to check text properties. Avoid doing it
4007 where possible because text property lookup is very expensive. */
4009 || CHARPOS (pos
) > it
->stop_charpos
4010 || CHARPOS (pos
) < original_pos
)
4017 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4018 IT->stop_pos to POS, also. */
4021 reseat_1 (it
, pos
, set_stop_p
)
4023 struct text_pos pos
;
4026 /* Don't call this function when scanning a C string. */
4027 xassert (it
->s
== NULL
);
4029 /* POS must be a reasonable value. */
4030 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4032 it
->current
.pos
= it
->position
= pos
;
4033 XSETBUFFER (it
->object
, current_buffer
);
4034 it
->end_charpos
= ZV
;
4036 it
->current
.dpvec_index
= -1;
4037 it
->current
.overlay_string_index
= -1;
4038 IT_STRING_CHARPOS (*it
) = -1;
4039 IT_STRING_BYTEPOS (*it
) = -1;
4041 it
->method
= next_element_from_buffer
;
4043 it
->face_before_selective_p
= 0;
4046 it
->stop_charpos
= CHARPOS (pos
);
4050 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4051 If S is non-null, it is a C string to iterate over. Otherwise,
4052 STRING gives a Lisp string to iterate over.
4054 If PRECISION > 0, don't return more then PRECISION number of
4055 characters from the string.
4057 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4058 characters have been returned. FIELD_WIDTH < 0 means an infinite
4061 MULTIBYTE = 0 means disable processing of multibyte characters,
4062 MULTIBYTE > 0 means enable it,
4063 MULTIBYTE < 0 means use IT->multibyte_p.
4065 IT must be initialized via a prior call to init_iterator before
4066 calling this function. */
4069 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4074 int precision
, field_width
, multibyte
;
4076 /* No region in strings. */
4077 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4079 /* No text property checks performed by default, but see below. */
4080 it
->stop_charpos
= -1;
4082 /* Set iterator position and end position. */
4083 bzero (&it
->current
, sizeof it
->current
);
4084 it
->current
.overlay_string_index
= -1;
4085 it
->current
.dpvec_index
= -1;
4086 xassert (charpos
>= 0);
4088 /* If STRING is specified, use its multibyteness, otherwise use the
4089 setting of MULTIBYTE, if specified. */
4091 it
->multibyte_p
= multibyte
> 0;
4095 xassert (STRINGP (string
));
4096 it
->string
= string
;
4098 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
4099 it
->method
= next_element_from_string
;
4100 it
->current
.string_pos
= string_pos (charpos
, string
);
4107 /* Note that we use IT->current.pos, not it->current.string_pos,
4108 for displaying C strings. */
4109 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4110 if (it
->multibyte_p
)
4112 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4113 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4117 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4118 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4121 it
->method
= next_element_from_c_string
;
4124 /* PRECISION > 0 means don't return more than PRECISION characters
4126 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4127 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4129 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4130 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4131 FIELD_WIDTH < 0 means infinite field width. This is useful for
4132 padding with `-' at the end of a mode line. */
4133 if (field_width
< 0)
4134 field_width
= INFINITY
;
4135 if (field_width
> it
->end_charpos
- charpos
)
4136 it
->end_charpos
= charpos
+ field_width
;
4138 /* Use the standard display table for displaying strings. */
4139 if (DISP_TABLE_P (Vstandard_display_table
))
4140 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4142 it
->stop_charpos
= charpos
;
4148 /***********************************************************************
4150 ***********************************************************************/
4152 /* Load IT's display element fields with information about the next
4153 display element from the current position of IT. Value is zero if
4154 end of buffer (or C string) is reached. */
4157 get_next_display_element (it
)
4160 /* Non-zero means that we found an display element. Zero means that
4161 we hit the end of what we iterate over. Performance note: the
4162 function pointer `method' used here turns out to be faster than
4163 using a sequence of if-statements. */
4164 int success_p
= (*it
->method
) (it
);
4166 if (it
->what
== IT_CHARACTER
)
4168 /* Map via display table or translate control characters.
4169 IT->c, IT->len etc. have been set to the next character by
4170 the function call above. If we have a display table, and it
4171 contains an entry for IT->c, translate it. Don't do this if
4172 IT->c itself comes from a display table, otherwise we could
4173 end up in an infinite recursion. (An alternative could be to
4174 count the recursion depth of this function and signal an
4175 error when a certain maximum depth is reached.) Is it worth
4177 if (success_p
&& it
->dpvec
== NULL
)
4182 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4185 struct Lisp_Vector
*v
= XVECTOR (dv
);
4187 /* Return the first character from the display table
4188 entry, if not empty. If empty, don't display the
4189 current character. */
4192 it
->dpvec_char_len
= it
->len
;
4193 it
->dpvec
= v
->contents
;
4194 it
->dpend
= v
->contents
+ v
->size
;
4195 it
->current
.dpvec_index
= 0;
4196 it
->method
= next_element_from_display_vector
;
4197 success_p
= get_next_display_element (it
);
4201 set_iterator_to_next (it
, 0);
4202 success_p
= get_next_display_element (it
);
4206 /* Translate control characters into `\003' or `^C' form.
4207 Control characters coming from a display table entry are
4208 currently not translated because we use IT->dpvec to hold
4209 the translation. This could easily be changed but I
4210 don't believe that it is worth doing.
4212 Non-printable multibyte characters are also translated
4214 else if ((it
->c
< ' '
4215 && (it
->area
!= TEXT_AREA
4216 || (it
->c
!= '\n' && it
->c
!= '\t')))
4219 || !CHAR_PRINTABLE_P (it
->c
))
4221 /* IT->c is a control character which must be displayed
4222 either as '\003' or as `^C' where the '\\' and '^'
4223 can be defined in the display table. Fill
4224 IT->ctl_chars with glyphs for what we have to
4225 display. Then, set IT->dpvec to these glyphs. */
4228 if (it
->c
< 128 && it
->ctl_arrow_p
)
4230 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4232 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4233 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4234 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4236 g
= FAST_MAKE_GLYPH ('^', 0);
4237 XSETINT (it
->ctl_chars
[0], g
);
4239 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4240 XSETINT (it
->ctl_chars
[1], g
);
4242 /* Set up IT->dpvec and return first character from it. */
4243 it
->dpvec_char_len
= it
->len
;
4244 it
->dpvec
= it
->ctl_chars
;
4245 it
->dpend
= it
->dpvec
+ 2;
4246 it
->current
.dpvec_index
= 0;
4247 it
->method
= next_element_from_display_vector
;
4248 get_next_display_element (it
);
4252 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4257 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4259 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4260 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4261 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4263 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4265 if (SINGLE_BYTE_CHAR_P (it
->c
))
4266 str
[0] = it
->c
, len
= 1;
4269 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4272 /* It's an invalid character, which
4273 shouldn't happen actually, but due to
4274 bugs it may happen. Let's print the char
4275 as is, there's not much meaningful we can
4278 str
[1] = it
->c
>> 8;
4279 str
[2] = it
->c
>> 16;
4280 str
[3] = it
->c
>> 24;
4285 for (i
= 0; i
< len
; i
++)
4287 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4288 /* Insert three more glyphs into IT->ctl_chars for
4289 the octal display of the character. */
4290 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4291 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4292 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4293 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4294 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4295 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4298 /* Set up IT->dpvec and return the first character
4300 it
->dpvec_char_len
= it
->len
;
4301 it
->dpvec
= it
->ctl_chars
;
4302 it
->dpend
= it
->dpvec
+ len
* 4;
4303 it
->current
.dpvec_index
= 0;
4304 it
->method
= next_element_from_display_vector
;
4305 get_next_display_element (it
);
4310 /* Adjust face id for a multibyte character. There are no
4311 multibyte character in unibyte text. */
4314 && FRAME_WINDOW_P (it
->f
))
4316 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4317 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4321 /* Is this character the last one of a run of characters with
4322 box? If yes, set IT->end_of_box_run_p to 1. */
4329 it
->end_of_box_run_p
4330 = ((face_id
= face_after_it_pos (it
),
4331 face_id
!= it
->face_id
)
4332 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4333 face
->box
== FACE_NO_BOX
));
4336 /* Value is 0 if end of buffer or string reached. */
4341 /* Move IT to the next display element.
4343 RESEAT_P non-zero means if called on a newline in buffer text,
4344 skip to the next visible line start.
4346 Functions get_next_display_element and set_iterator_to_next are
4347 separate because I find this arrangement easier to handle than a
4348 get_next_display_element function that also increments IT's
4349 position. The way it is we can first look at an iterator's current
4350 display element, decide whether it fits on a line, and if it does,
4351 increment the iterator position. The other way around we probably
4352 would either need a flag indicating whether the iterator has to be
4353 incremented the next time, or we would have to implement a
4354 decrement position function which would not be easy to write. */
4357 set_iterator_to_next (it
, reseat_p
)
4361 /* Reset flags indicating start and end of a sequence of characters
4362 with box. Reset them at the start of this function because
4363 moving the iterator to a new position might set them. */
4364 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4366 if (it
->method
== next_element_from_buffer
)
4368 /* The current display element of IT is a character from
4369 current_buffer. Advance in the buffer, and maybe skip over
4370 invisible lines that are so because of selective display. */
4371 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4372 reseat_at_next_visible_line_start (it
, 0);
4375 xassert (it
->len
!= 0);
4376 IT_BYTEPOS (*it
) += it
->len
;
4377 IT_CHARPOS (*it
) += 1;
4378 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4381 else if (it
->method
== next_element_from_composition
)
4383 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4384 if (STRINGP (it
->string
))
4386 IT_STRING_BYTEPOS (*it
) += it
->len
;
4387 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4388 it
->method
= next_element_from_string
;
4389 goto consider_string_end
;
4393 IT_BYTEPOS (*it
) += it
->len
;
4394 IT_CHARPOS (*it
) += it
->cmp_len
;
4395 it
->method
= next_element_from_buffer
;
4398 else if (it
->method
== next_element_from_c_string
)
4400 /* Current display element of IT is from a C string. */
4401 IT_BYTEPOS (*it
) += it
->len
;
4402 IT_CHARPOS (*it
) += 1;
4404 else if (it
->method
== next_element_from_display_vector
)
4406 /* Current display element of IT is from a display table entry.
4407 Advance in the display table definition. Reset it to null if
4408 end reached, and continue with characters from buffers/
4410 ++it
->current
.dpvec_index
;
4412 /* Restore face of the iterator to what they were before the
4413 display vector entry (these entries may contain faces). */
4414 it
->face_id
= it
->saved_face_id
;
4416 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4419 it
->method
= next_element_from_c_string
;
4420 else if (STRINGP (it
->string
))
4421 it
->method
= next_element_from_string
;
4423 it
->method
= next_element_from_buffer
;
4426 it
->current
.dpvec_index
= -1;
4428 /* Skip over characters which were displayed via IT->dpvec. */
4429 if (it
->dpvec_char_len
< 0)
4430 reseat_at_next_visible_line_start (it
, 1);
4431 else if (it
->dpvec_char_len
> 0)
4433 it
->len
= it
->dpvec_char_len
;
4434 set_iterator_to_next (it
, reseat_p
);
4438 else if (it
->method
== next_element_from_string
)
4440 /* Current display element is a character from a Lisp string. */
4441 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4442 IT_STRING_BYTEPOS (*it
) += it
->len
;
4443 IT_STRING_CHARPOS (*it
) += 1;
4445 consider_string_end
:
4447 if (it
->current
.overlay_string_index
>= 0)
4449 /* IT->string is an overlay string. Advance to the
4450 next, if there is one. */
4451 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4452 next_overlay_string (it
);
4456 /* IT->string is not an overlay string. If we reached
4457 its end, and there is something on IT->stack, proceed
4458 with what is on the stack. This can be either another
4459 string, this time an overlay string, or a buffer. */
4460 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4464 if (!STRINGP (it
->string
))
4465 it
->method
= next_element_from_buffer
;
4467 goto consider_string_end
;
4471 else if (it
->method
== next_element_from_image
4472 || it
->method
== next_element_from_stretch
)
4474 /* The position etc with which we have to proceed are on
4475 the stack. The position may be at the end of a string,
4476 if the `display' property takes up the whole string. */
4479 if (STRINGP (it
->string
))
4481 it
->method
= next_element_from_string
;
4482 goto consider_string_end
;
4485 it
->method
= next_element_from_buffer
;
4488 /* There are no other methods defined, so this should be a bug. */
4491 xassert (it
->method
!= next_element_from_string
4492 || (STRINGP (it
->string
)
4493 && IT_STRING_CHARPOS (*it
) >= 0));
4497 /* Load IT's display element fields with information about the next
4498 display element which comes from a display table entry or from the
4499 result of translating a control character to one of the forms `^C'
4500 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4503 next_element_from_display_vector (it
)
4507 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4509 /* Remember the current face id in case glyphs specify faces.
4510 IT's face is restored in set_iterator_to_next. */
4511 it
->saved_face_id
= it
->face_id
;
4513 if (INTEGERP (*it
->dpvec
)
4514 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4519 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4520 it
->c
= FAST_GLYPH_CHAR (g
);
4521 it
->len
= CHAR_BYTES (it
->c
);
4523 /* The entry may contain a face id to use. Such a face id is
4524 the id of a Lisp face, not a realized face. A face id of
4525 zero means no face is specified. */
4526 lface_id
= FAST_GLYPH_FACE (g
);
4529 /* The function returns -1 if lface_id is invalid. */
4530 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4532 it
->face_id
= face_id
;
4536 /* Display table entry is invalid. Return a space. */
4537 it
->c
= ' ', it
->len
= 1;
4539 /* Don't change position and object of the iterator here. They are
4540 still the values of the character that had this display table
4541 entry or was translated, and that's what we want. */
4542 it
->what
= IT_CHARACTER
;
4547 /* Load IT with the next display element from Lisp string IT->string.
4548 IT->current.string_pos is the current position within the string.
4549 If IT->current.overlay_string_index >= 0, the Lisp string is an
4553 next_element_from_string (it
)
4556 struct text_pos position
;
4558 xassert (STRINGP (it
->string
));
4559 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4560 position
= it
->current
.string_pos
;
4562 /* Time to check for invisible text? */
4563 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4564 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4568 /* Since a handler may have changed IT->method, we must
4570 return get_next_display_element (it
);
4573 if (it
->current
.overlay_string_index
>= 0)
4575 /* Get the next character from an overlay string. In overlay
4576 strings, There is no field width or padding with spaces to
4578 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4583 else if (STRING_MULTIBYTE (it
->string
))
4585 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4586 - IT_STRING_BYTEPOS (*it
));
4587 unsigned char *s
= (XSTRING (it
->string
)->data
4588 + IT_STRING_BYTEPOS (*it
));
4589 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4593 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4599 /* Get the next character from a Lisp string that is not an
4600 overlay string. Such strings come from the mode line, for
4601 example. We may have to pad with spaces, or truncate the
4602 string. See also next_element_from_c_string. */
4603 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4608 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4610 /* Pad with spaces. */
4611 it
->c
= ' ', it
->len
= 1;
4612 CHARPOS (position
) = BYTEPOS (position
) = -1;
4614 else if (STRING_MULTIBYTE (it
->string
))
4616 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4617 - IT_STRING_BYTEPOS (*it
));
4618 unsigned char *s
= (XSTRING (it
->string
)->data
4619 + IT_STRING_BYTEPOS (*it
));
4620 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4624 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4629 /* Record what we have and where it came from. Note that we store a
4630 buffer position in IT->position although it could arguably be a
4632 it
->what
= IT_CHARACTER
;
4633 it
->object
= it
->string
;
4634 it
->position
= position
;
4639 /* Load IT with next display element from C string IT->s.
4640 IT->string_nchars is the maximum number of characters to return
4641 from the string. IT->end_charpos may be greater than
4642 IT->string_nchars when this function is called, in which case we
4643 may have to return padding spaces. Value is zero if end of string
4644 reached, including padding spaces. */
4647 next_element_from_c_string (it
)
4653 it
->what
= IT_CHARACTER
;
4654 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4657 /* IT's position can be greater IT->string_nchars in case a field
4658 width or precision has been specified when the iterator was
4660 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4662 /* End of the game. */
4666 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4668 /* Pad with spaces. */
4669 it
->c
= ' ', it
->len
= 1;
4670 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4672 else if (it
->multibyte_p
)
4674 /* Implementation note: The calls to strlen apparently aren't a
4675 performance problem because there is no noticeable performance
4676 difference between Emacs running in unibyte or multibyte mode. */
4677 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4678 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4682 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4688 /* Set up IT to return characters from an ellipsis, if appropriate.
4689 The definition of the ellipsis glyphs may come from a display table
4690 entry. This function Fills IT with the first glyph from the
4691 ellipsis if an ellipsis is to be displayed. */
4694 next_element_from_ellipsis (it
)
4697 if (it
->selective_display_ellipsis_p
)
4699 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4701 /* Use the display table definition for `...'. Invalid glyphs
4702 will be handled by the method returning elements from dpvec. */
4703 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4704 it
->dpvec_char_len
= it
->len
;
4705 it
->dpvec
= v
->contents
;
4706 it
->dpend
= v
->contents
+ v
->size
;
4707 it
->current
.dpvec_index
= 0;
4708 it
->method
= next_element_from_display_vector
;
4712 /* Use default `...' which is stored in default_invis_vector. */
4713 it
->dpvec_char_len
= it
->len
;
4714 it
->dpvec
= default_invis_vector
;
4715 it
->dpend
= default_invis_vector
+ 3;
4716 it
->current
.dpvec_index
= 0;
4717 it
->method
= next_element_from_display_vector
;
4722 /* The face at the current position may be different from the
4723 face we find after the invisible text. Remember what it
4724 was in IT->saved_face_id, and signal that it's there by
4725 setting face_before_selective_p. */
4726 it
->saved_face_id
= it
->face_id
;
4727 it
->method
= next_element_from_buffer
;
4728 reseat_at_next_visible_line_start (it
, 1);
4729 it
->face_before_selective_p
= 1;
4732 return get_next_display_element (it
);
4736 /* Deliver an image display element. The iterator IT is already
4737 filled with image information (done in handle_display_prop). Value
4742 next_element_from_image (it
)
4745 it
->what
= IT_IMAGE
;
4750 /* Fill iterator IT with next display element from a stretch glyph
4751 property. IT->object is the value of the text property. Value is
4755 next_element_from_stretch (it
)
4758 it
->what
= IT_STRETCH
;
4763 /* Load IT with the next display element from current_buffer. Value
4764 is zero if end of buffer reached. IT->stop_charpos is the next
4765 position at which to stop and check for text properties or buffer
4769 next_element_from_buffer (it
)
4774 /* Check this assumption, otherwise, we would never enter the
4775 if-statement, below. */
4776 xassert (IT_CHARPOS (*it
) >= BEGV
4777 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4779 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4781 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4783 int overlay_strings_follow_p
;
4785 /* End of the game, except when overlay strings follow that
4786 haven't been returned yet. */
4787 if (it
->overlay_strings_at_end_processed_p
)
4788 overlay_strings_follow_p
= 0;
4791 it
->overlay_strings_at_end_processed_p
= 1;
4792 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4795 if (overlay_strings_follow_p
)
4796 success_p
= get_next_display_element (it
);
4800 it
->position
= it
->current
.pos
;
4807 return get_next_display_element (it
);
4812 /* No face changes, overlays etc. in sight, so just return a
4813 character from current_buffer. */
4816 /* Maybe run the redisplay end trigger hook. Performance note:
4817 This doesn't seem to cost measurable time. */
4818 if (it
->redisplay_end_trigger_charpos
4820 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4821 run_redisplay_end_trigger_hook (it
);
4823 /* Get the next character, maybe multibyte. */
4824 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4825 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4827 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4828 - IT_BYTEPOS (*it
));
4829 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4832 it
->c
= *p
, it
->len
= 1;
4834 /* Record what we have and where it came from. */
4835 it
->what
= IT_CHARACTER
;;
4836 it
->object
= it
->w
->buffer
;
4837 it
->position
= it
->current
.pos
;
4839 /* Normally we return the character found above, except when we
4840 really want to return an ellipsis for selective display. */
4845 /* A value of selective > 0 means hide lines indented more
4846 than that number of columns. */
4847 if (it
->selective
> 0
4848 && IT_CHARPOS (*it
) + 1 < ZV
4849 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4850 IT_BYTEPOS (*it
) + 1,
4853 success_p
= next_element_from_ellipsis (it
);
4854 it
->dpvec_char_len
= -1;
4857 else if (it
->c
== '\r' && it
->selective
== -1)
4859 /* A value of selective == -1 means that everything from the
4860 CR to the end of the line is invisible, with maybe an
4861 ellipsis displayed for it. */
4862 success_p
= next_element_from_ellipsis (it
);
4863 it
->dpvec_char_len
= -1;
4868 /* Value is zero if end of buffer reached. */
4869 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4874 /* Run the redisplay end trigger hook for IT. */
4877 run_redisplay_end_trigger_hook (it
)
4880 Lisp_Object args
[3];
4882 /* IT->glyph_row should be non-null, i.e. we should be actually
4883 displaying something, or otherwise we should not run the hook. */
4884 xassert (it
->glyph_row
);
4886 /* Set up hook arguments. */
4887 args
[0] = Qredisplay_end_trigger_functions
;
4888 args
[1] = it
->window
;
4889 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4890 it
->redisplay_end_trigger_charpos
= 0;
4892 /* Since we are *trying* to run these functions, don't try to run
4893 them again, even if they get an error. */
4894 it
->w
->redisplay_end_trigger
= Qnil
;
4895 Frun_hook_with_args (3, args
);
4897 /* Notice if it changed the face of the character we are on. */
4898 handle_face_prop (it
);
4902 /* Deliver a composition display element. The iterator IT is already
4903 filled with composition information (done in
4904 handle_composition_prop). Value is always 1. */
4907 next_element_from_composition (it
)
4910 it
->what
= IT_COMPOSITION
;
4911 it
->position
= (STRINGP (it
->string
)
4912 ? it
->current
.string_pos
4919 /***********************************************************************
4920 Moving an iterator without producing glyphs
4921 ***********************************************************************/
4923 /* Move iterator IT to a specified buffer or X position within one
4924 line on the display without producing glyphs.
4926 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4927 whichever is reached first.
4929 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4931 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4932 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4933 TO_X includes the amount by which a window is horizontally
4938 MOVE_POS_MATCH_OR_ZV
4939 - when TO_POS or ZV was reached.
4942 -when TO_X was reached before TO_POS or ZV were reached.
4945 - when we reached the end of the display area and the line must
4949 - when we reached the end of the display area and the line is
4953 - when we stopped at a line end, i.e. a newline or a CR and selective
4956 static enum move_it_result
4957 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4959 int to_charpos
, to_x
, op
;
4961 enum move_it_result result
= MOVE_UNDEFINED
;
4962 struct glyph_row
*saved_glyph_row
;
4964 /* Don't produce glyphs in produce_glyphs. */
4965 saved_glyph_row
= it
->glyph_row
;
4966 it
->glyph_row
= NULL
;
4970 int x
, i
, ascent
= 0, descent
= 0;
4972 /* Stop when ZV or TO_CHARPOS reached. */
4973 if (!get_next_display_element (it
)
4974 || ((op
& MOVE_TO_POS
) != 0
4975 && BUFFERP (it
->object
)
4976 && IT_CHARPOS (*it
) >= to_charpos
))
4978 result
= MOVE_POS_MATCH_OR_ZV
;
4982 /* The call to produce_glyphs will get the metrics of the
4983 display element IT is loaded with. We record in x the
4984 x-position before this display element in case it does not
4988 /* Remember the line height so far in case the next element doesn't
4990 if (!it
->truncate_lines_p
)
4992 ascent
= it
->max_ascent
;
4993 descent
= it
->max_descent
;
4996 PRODUCE_GLYPHS (it
);
4998 if (it
->area
!= TEXT_AREA
)
5000 set_iterator_to_next (it
, 1);
5004 /* The number of glyphs we get back in IT->nglyphs will normally
5005 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5006 character on a terminal frame, or (iii) a line end. For the
5007 second case, IT->nglyphs - 1 padding glyphs will be present
5008 (on X frames, there is only one glyph produced for a
5009 composite character.
5011 The behavior implemented below means, for continuation lines,
5012 that as many spaces of a TAB as fit on the current line are
5013 displayed there. For terminal frames, as many glyphs of a
5014 multi-glyph character are displayed in the current line, too.
5015 This is what the old redisplay code did, and we keep it that
5016 way. Under X, the whole shape of a complex character must
5017 fit on the line or it will be completely displayed in the
5020 Note that both for tabs and padding glyphs, all glyphs have
5024 /* More than one glyph or glyph doesn't fit on line. All
5025 glyphs have the same width. */
5026 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5029 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5031 new_x
= x
+ single_glyph_width
;
5033 /* We want to leave anything reaching TO_X to the caller. */
5034 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5037 result
= MOVE_X_REACHED
;
5040 else if (/* Lines are continued. */
5041 !it
->truncate_lines_p
5042 && (/* And glyph doesn't fit on the line. */
5043 new_x
> it
->last_visible_x
5044 /* Or it fits exactly and we're on a window
5046 || (new_x
== it
->last_visible_x
5047 && FRAME_WINDOW_P (it
->f
))))
5049 if (/* IT->hpos == 0 means the very first glyph
5050 doesn't fit on the line, e.g. a wide image. */
5052 || (new_x
== it
->last_visible_x
5053 && FRAME_WINDOW_P (it
->f
)))
5056 it
->current_x
= new_x
;
5057 if (i
== it
->nglyphs
- 1)
5058 set_iterator_to_next (it
, 1);
5063 it
->max_ascent
= ascent
;
5064 it
->max_descent
= descent
;
5067 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5069 result
= MOVE_LINE_CONTINUED
;
5072 else if (new_x
> it
->first_visible_x
)
5074 /* Glyph is visible. Increment number of glyphs that
5075 would be displayed. */
5080 /* Glyph is completely off the left margin of the display
5081 area. Nothing to do. */
5085 if (result
!= MOVE_UNDEFINED
)
5088 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5090 /* Stop when TO_X specified and reached. This check is
5091 necessary here because of lines consisting of a line end,
5092 only. The line end will not produce any glyphs and we
5093 would never get MOVE_X_REACHED. */
5094 xassert (it
->nglyphs
== 0);
5095 result
= MOVE_X_REACHED
;
5099 /* Is this a line end? If yes, we're done. */
5100 if (ITERATOR_AT_END_OF_LINE_P (it
))
5102 result
= MOVE_NEWLINE_OR_CR
;
5106 /* The current display element has been consumed. Advance
5108 set_iterator_to_next (it
, 1);
5110 /* Stop if lines are truncated and IT's current x-position is
5111 past the right edge of the window now. */
5112 if (it
->truncate_lines_p
5113 && it
->current_x
>= it
->last_visible_x
)
5115 result
= MOVE_LINE_TRUNCATED
;
5120 /* Restore the iterator settings altered at the beginning of this
5122 it
->glyph_row
= saved_glyph_row
;
5127 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
5128 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
5129 the description of enum move_operation_enum.
5131 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5132 screen line, this function will set IT to the next position >
5136 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5138 int to_charpos
, to_x
, to_y
, to_vpos
;
5141 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5147 if (op
& MOVE_TO_VPOS
)
5149 /* If no TO_CHARPOS and no TO_X specified, stop at the
5150 start of the line TO_VPOS. */
5151 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5153 if (it
->vpos
== to_vpos
)
5159 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5163 /* TO_VPOS >= 0 means stop at TO_X in the line at
5164 TO_VPOS, or at TO_POS, whichever comes first. */
5165 if (it
->vpos
== to_vpos
)
5171 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5173 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5178 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5180 /* We have reached TO_X but not in the line we want. */
5181 skip
= move_it_in_display_line_to (it
, to_charpos
,
5183 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5191 else if (op
& MOVE_TO_Y
)
5193 struct it it_backup
;
5195 /* TO_Y specified means stop at TO_X in the line containing
5196 TO_Y---or at TO_CHARPOS if this is reached first. The
5197 problem is that we can't really tell whether the line
5198 contains TO_Y before we have completely scanned it, and
5199 this may skip past TO_X. What we do is to first scan to
5202 If TO_X is not specified, use a TO_X of zero. The reason
5203 is to make the outcome of this function more predictable.
5204 If we didn't use TO_X == 0, we would stop at the end of
5205 the line which is probably not what a caller would expect
5207 skip
= move_it_in_display_line_to (it
, to_charpos
,
5211 | (op
& MOVE_TO_POS
)));
5213 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5214 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5220 /* If TO_X was reached, we would like to know whether TO_Y
5221 is in the line. This can only be said if we know the
5222 total line height which requires us to scan the rest of
5224 if (skip
== MOVE_X_REACHED
)
5227 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5228 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5230 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5233 /* Now, decide whether TO_Y is in this line. */
5234 line_height
= it
->max_ascent
+ it
->max_descent
;
5235 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5237 if (to_y
>= it
->current_y
5238 && to_y
< it
->current_y
+ line_height
)
5240 if (skip
== MOVE_X_REACHED
)
5241 /* If TO_Y is in this line and TO_X was reached above,
5242 we scanned too far. We have to restore IT's settings
5243 to the ones before skipping. */
5247 else if (skip
== MOVE_X_REACHED
)
5250 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5258 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5262 case MOVE_POS_MATCH_OR_ZV
:
5266 case MOVE_NEWLINE_OR_CR
:
5267 set_iterator_to_next (it
, 1);
5268 it
->continuation_lines_width
= 0;
5271 case MOVE_LINE_TRUNCATED
:
5272 it
->continuation_lines_width
= 0;
5273 reseat_at_next_visible_line_start (it
, 0);
5274 if ((op
& MOVE_TO_POS
) != 0
5275 && IT_CHARPOS (*it
) > to_charpos
)
5282 case MOVE_LINE_CONTINUED
:
5283 it
->continuation_lines_width
+= it
->current_x
;
5290 /* Reset/increment for the next run. */
5291 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5292 it
->current_x
= it
->hpos
= 0;
5293 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5295 last_height
= it
->max_ascent
+ it
->max_descent
;
5296 last_max_ascent
= it
->max_ascent
;
5297 it
->max_ascent
= it
->max_descent
= 0;
5302 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5306 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5308 If DY > 0, move IT backward at least that many pixels. DY = 0
5309 means move IT backward to the preceding line start or BEGV. This
5310 function may move over more than DY pixels if IT->current_y - DY
5311 ends up in the middle of a line; in this case IT->current_y will be
5312 set to the top of the line moved to. */
5315 move_it_vertically_backward (it
, dy
)
5319 int nlines
, h
, line_height
;
5321 int start_pos
= IT_CHARPOS (*it
);
5325 /* Estimate how many newlines we must move back. */
5326 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5328 /* Set the iterator's position that many lines back. */
5329 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5330 back_to_previous_visible_line_start (it
);
5332 /* Reseat the iterator here. When moving backward, we don't want
5333 reseat to skip forward over invisible text, set up the iterator
5334 to deliver from overlay strings at the new position etc. So,
5335 use reseat_1 here. */
5336 reseat_1 (it
, it
->current
.pos
, 1);
5338 /* We are now surely at a line start. */
5339 it
->current_x
= it
->hpos
= 0;
5341 /* Move forward and see what y-distance we moved. First move to the
5342 start of the next line so that we get its height. We need this
5343 height to be able to tell whether we reached the specified
5346 it2
.max_ascent
= it2
.max_descent
= 0;
5347 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5348 MOVE_TO_POS
| MOVE_TO_VPOS
);
5349 xassert (IT_CHARPOS (*it
) >= BEGV
);
5350 line_height
= it2
.max_ascent
+ it2
.max_descent
;
5352 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5353 xassert (IT_CHARPOS (*it
) >= BEGV
);
5354 h
= it2
.current_y
- it
->current_y
;
5355 nlines
= it2
.vpos
- it
->vpos
;
5357 /* Correct IT's y and vpos position. */
5363 /* DY == 0 means move to the start of the screen line. The
5364 value of nlines is > 0 if continuation lines were involved. */
5366 move_it_by_lines (it
, nlines
, 1);
5367 xassert (IT_CHARPOS (*it
) <= start_pos
);
5371 /* The y-position we try to reach. Note that h has been
5372 subtracted in front of the if-statement. */
5373 int target_y
= it
->current_y
+ h
- dy
;
5375 /* If we did not reach target_y, try to move further backward if
5376 we can. If we moved too far backward, try to move forward. */
5377 if (target_y
< it
->current_y
5378 && IT_CHARPOS (*it
) > BEGV
)
5380 move_it_vertically (it
, target_y
- it
->current_y
);
5381 xassert (IT_CHARPOS (*it
) >= BEGV
);
5383 else if (target_y
>= it
->current_y
+ line_height
5384 && IT_CHARPOS (*it
) < ZV
)
5386 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5387 xassert (IT_CHARPOS (*it
) >= BEGV
);
5393 /* Move IT by a specified amount of pixel lines DY. DY negative means
5394 move backwards. DY = 0 means move to start of screen line. At the
5395 end, IT will be on the start of a screen line. */
5398 move_it_vertically (it
, dy
)
5403 move_it_vertically_backward (it
, -dy
);
5406 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5407 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5408 MOVE_TO_POS
| MOVE_TO_Y
);
5409 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5411 /* If buffer ends in ZV without a newline, move to the start of
5412 the line to satisfy the post-condition. */
5413 if (IT_CHARPOS (*it
) == ZV
5414 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5415 move_it_by_lines (it
, 0, 0);
5420 /* Move iterator IT past the end of the text line it is in. */
5423 move_it_past_eol (it
)
5426 enum move_it_result rc
;
5428 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5429 if (rc
== MOVE_NEWLINE_OR_CR
)
5430 set_iterator_to_next (it
, 0);
5434 #if 0 /* Currently not used. */
5436 /* Return non-zero if some text between buffer positions START_CHARPOS
5437 and END_CHARPOS is invisible. IT->window is the window for text
5441 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5443 int start_charpos
, end_charpos
;
5445 Lisp_Object prop
, limit
;
5446 int invisible_found_p
;
5448 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5450 /* Is text at START invisible? */
5451 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5453 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5454 invisible_found_p
= 1;
5457 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5459 make_number (end_charpos
));
5460 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5463 return invisible_found_p
;
5469 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5470 negative means move up. DVPOS == 0 means move to the start of the
5471 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5472 NEED_Y_P is zero, IT->current_y will be left unchanged.
5474 Further optimization ideas: If we would know that IT->f doesn't use
5475 a face with proportional font, we could be faster for
5476 truncate-lines nil. */
5479 move_it_by_lines (it
, dvpos
, need_y_p
)
5481 int dvpos
, need_y_p
;
5483 struct position pos
;
5485 if (!FRAME_WINDOW_P (it
->f
))
5487 struct text_pos textpos
;
5489 /* We can use vmotion on frames without proportional fonts. */
5490 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5491 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5492 reseat (it
, textpos
, 1);
5493 it
->vpos
+= pos
.vpos
;
5494 it
->current_y
+= pos
.vpos
;
5496 else if (dvpos
== 0)
5498 /* DVPOS == 0 means move to the start of the screen line. */
5499 move_it_vertically_backward (it
, 0);
5500 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5503 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5507 int start_charpos
, i
;
5509 /* Start at the beginning of the screen line containing IT's
5511 move_it_vertically_backward (it
, 0);
5513 /* Go back -DVPOS visible lines and reseat the iterator there. */
5514 start_charpos
= IT_CHARPOS (*it
);
5515 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5516 back_to_previous_visible_line_start (it
);
5517 reseat (it
, it
->current
.pos
, 1);
5518 it
->current_x
= it
->hpos
= 0;
5520 /* Above call may have moved too far if continuation lines
5521 are involved. Scan forward and see if it did. */
5523 it2
.vpos
= it2
.current_y
= 0;
5524 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5525 it
->vpos
-= it2
.vpos
;
5526 it
->current_y
-= it2
.current_y
;
5527 it
->current_x
= it
->hpos
= 0;
5529 /* If we moved too far, move IT some lines forward. */
5530 if (it2
.vpos
> -dvpos
)
5532 int delta
= it2
.vpos
+ dvpos
;
5533 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5540 /***********************************************************************
5542 ***********************************************************************/
5545 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5549 add_to_log (format
, arg1
, arg2
)
5551 Lisp_Object arg1
, arg2
;
5553 Lisp_Object args
[3];
5554 Lisp_Object msg
, fmt
;
5557 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5559 /* Do nothing if called asynchronously. Inserting text into
5560 a buffer may call after-change-functions and alike and
5561 that would means running Lisp asynchronously. */
5562 if (handling_signal
)
5566 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5568 args
[0] = fmt
= build_string (format
);
5571 msg
= Fformat (3, args
);
5573 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5574 buffer
= (char *) alloca (len
);
5575 bcopy (XSTRING (msg
)->data
, buffer
, len
);
5577 message_dolog (buffer
, len
- 1, 1, 0);
5582 /* Output a newline in the *Messages* buffer if "needs" one. */
5585 message_log_maybe_newline ()
5587 if (message_log_need_newline
)
5588 message_dolog ("", 0, 1, 0);
5592 /* Add a string M of length NBYTES to the message log, optionally
5593 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5594 nonzero, means interpret the contents of M as multibyte. This
5595 function calls low-level routines in order to bypass text property
5596 hooks, etc. which might not be safe to run. */
5599 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5601 int nbytes
, nlflag
, multibyte
;
5603 if (!NILP (Vmessage_log_max
))
5605 struct buffer
*oldbuf
;
5606 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5607 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5608 int point_at_end
= 0;
5610 Lisp_Object old_deactivate_mark
, tem
;
5611 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5613 old_deactivate_mark
= Vdeactivate_mark
;
5614 oldbuf
= current_buffer
;
5615 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5616 current_buffer
->undo_list
= Qt
;
5618 oldpoint
= Fpoint_marker ();
5619 oldbegv
= Fpoint_min_marker ();
5620 oldzv
= Fpoint_max_marker ();
5621 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5629 BEGV_BYTE
= BEG_BYTE
;
5632 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5634 /* Insert the string--maybe converting multibyte to single byte
5635 or vice versa, so that all the text fits the buffer. */
5637 && NILP (current_buffer
->enable_multibyte_characters
))
5639 int i
, c
, char_bytes
;
5640 unsigned char work
[1];
5642 /* Convert a multibyte string to single-byte
5643 for the *Message* buffer. */
5644 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5646 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5647 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5649 : multibyte_char_to_unibyte (c
, Qnil
));
5650 insert_1_both (work
, 1, 1, 1, 0, 0);
5653 else if (! multibyte
5654 && ! NILP (current_buffer
->enable_multibyte_characters
))
5656 int i
, c
, char_bytes
;
5657 unsigned char *msg
= (unsigned char *) m
;
5658 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5659 /* Convert a single-byte string to multibyte
5660 for the *Message* buffer. */
5661 for (i
= 0; i
< nbytes
; i
++)
5663 c
= unibyte_char_to_multibyte (msg
[i
]);
5664 char_bytes
= CHAR_STRING (c
, str
);
5665 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5669 insert_1 (m
, nbytes
, 1, 0, 0);
5673 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5674 insert_1 ("\n", 1, 1, 0, 0);
5676 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5678 this_bol_byte
= PT_BYTE
;
5682 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5684 prev_bol_byte
= PT_BYTE
;
5686 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5687 this_bol
, this_bol_byte
);
5690 del_range_both (prev_bol
, prev_bol_byte
,
5691 this_bol
, this_bol_byte
, 0);
5697 /* If you change this format, don't forget to also
5698 change message_log_check_duplicate. */
5699 sprintf (dupstr
, " [%d times]", dup
);
5700 duplen
= strlen (dupstr
);
5701 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5702 insert_1 (dupstr
, duplen
, 1, 0, 1);
5707 if (NATNUMP (Vmessage_log_max
))
5709 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5710 -XFASTINT (Vmessage_log_max
) - 1, 0);
5711 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5714 BEGV
= XMARKER (oldbegv
)->charpos
;
5715 BEGV_BYTE
= marker_byte_position (oldbegv
);
5724 ZV
= XMARKER (oldzv
)->charpos
;
5725 ZV_BYTE
= marker_byte_position (oldzv
);
5729 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5731 /* We can't do Fgoto_char (oldpoint) because it will run some
5733 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5734 XMARKER (oldpoint
)->bytepos
);
5737 free_marker (oldpoint
);
5738 free_marker (oldbegv
);
5739 free_marker (oldzv
);
5741 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5742 set_buffer_internal (oldbuf
);
5744 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5745 message_log_need_newline
= !nlflag
;
5746 Vdeactivate_mark
= old_deactivate_mark
;
5751 /* We are at the end of the buffer after just having inserted a newline.
5752 (Note: We depend on the fact we won't be crossing the gap.)
5753 Check to see if the most recent message looks a lot like the previous one.
5754 Return 0 if different, 1 if the new one should just replace it, or a
5755 value N > 1 if we should also append " [N times]". */
5758 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5759 int prev_bol
, this_bol
;
5760 int prev_bol_byte
, this_bol_byte
;
5763 int len
= Z_BYTE
- 1 - this_bol_byte
;
5765 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5766 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5768 for (i
= 0; i
< len
; i
++)
5770 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5778 if (*p1
++ == ' ' && *p1
++ == '[')
5781 while (*p1
>= '0' && *p1
<= '9')
5782 n
= n
* 10 + *p1
++ - '0';
5783 if (strncmp (p1
, " times]\n", 8) == 0)
5790 /* Display an echo area message M with a specified length of NBYTES
5791 bytes. The string may include null characters. If M is 0, clear
5792 out any existing message, and let the mini-buffer text show
5795 The buffer M must continue to exist until after the echo area gets
5796 cleared or some other message gets displayed there. This means do
5797 not pass text that is stored in a Lisp string; do not pass text in
5798 a buffer that was alloca'd. */
5801 message2 (m
, nbytes
, multibyte
)
5806 /* First flush out any partial line written with print. */
5807 message_log_maybe_newline ();
5809 message_dolog (m
, nbytes
, 1, multibyte
);
5810 message2_nolog (m
, nbytes
, multibyte
);
5814 /* The non-logging counterpart of message2. */
5817 message2_nolog (m
, nbytes
, multibyte
)
5821 struct frame
*sf
= SELECTED_FRAME ();
5822 message_enable_multibyte
= multibyte
;
5826 if (noninteractive_need_newline
)
5827 putc ('\n', stderr
);
5828 noninteractive_need_newline
= 0;
5830 fwrite (m
, nbytes
, 1, stderr
);
5831 if (cursor_in_echo_area
== 0)
5832 fprintf (stderr
, "\n");
5835 /* A null message buffer means that the frame hasn't really been
5836 initialized yet. Error messages get reported properly by
5837 cmd_error, so this must be just an informative message; toss it. */
5838 else if (INTERACTIVE
5839 && sf
->glyphs_initialized_p
5840 && FRAME_MESSAGE_BUF (sf
))
5842 Lisp_Object mini_window
;
5845 /* Get the frame containing the mini-buffer
5846 that the selected frame is using. */
5847 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5848 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5850 FRAME_SAMPLE_VISIBILITY (f
);
5851 if (FRAME_VISIBLE_P (sf
)
5852 && ! FRAME_VISIBLE_P (f
))
5853 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5857 set_message (m
, Qnil
, nbytes
, multibyte
);
5858 if (minibuffer_auto_raise
)
5859 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5862 clear_message (1, 1);
5864 do_pending_window_change (0);
5865 echo_area_display (1);
5866 do_pending_window_change (0);
5867 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5868 (*frame_up_to_date_hook
) (f
);
5873 /* Display an echo area message M with a specified length of NBYTES
5874 bytes. The string may include null characters. If M is not a
5875 string, clear out any existing message, and let the mini-buffer
5876 text show through. */
5879 message3 (m
, nbytes
, multibyte
)
5884 struct gcpro gcpro1
;
5888 /* First flush out any partial line written with print. */
5889 message_log_maybe_newline ();
5891 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5892 message3_nolog (m
, nbytes
, multibyte
);
5898 /* The non-logging version of message3. */
5901 message3_nolog (m
, nbytes
, multibyte
)
5903 int nbytes
, multibyte
;
5905 struct frame
*sf
= SELECTED_FRAME ();
5906 message_enable_multibyte
= multibyte
;
5910 if (noninteractive_need_newline
)
5911 putc ('\n', stderr
);
5912 noninteractive_need_newline
= 0;
5914 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5915 if (cursor_in_echo_area
== 0)
5916 fprintf (stderr
, "\n");
5919 /* A null message buffer means that the frame hasn't really been
5920 initialized yet. Error messages get reported properly by
5921 cmd_error, so this must be just an informative message; toss it. */
5922 else if (INTERACTIVE
5923 && sf
->glyphs_initialized_p
5924 && FRAME_MESSAGE_BUF (sf
))
5926 Lisp_Object mini_window
;
5930 /* Get the frame containing the mini-buffer
5931 that the selected frame is using. */
5932 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5933 frame
= XWINDOW (mini_window
)->frame
;
5936 FRAME_SAMPLE_VISIBILITY (f
);
5937 if (FRAME_VISIBLE_P (sf
)
5938 && !FRAME_VISIBLE_P (f
))
5939 Fmake_frame_visible (frame
);
5941 if (STRINGP (m
) && XSTRING (m
)->size
)
5943 set_message (NULL
, m
, nbytes
, multibyte
);
5944 if (minibuffer_auto_raise
)
5945 Fraise_frame (frame
);
5948 clear_message (1, 1);
5950 do_pending_window_change (0);
5951 echo_area_display (1);
5952 do_pending_window_change (0);
5953 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5954 (*frame_up_to_date_hook
) (f
);
5959 /* Display a null-terminated echo area message M. If M is 0, clear
5960 out any existing message, and let the mini-buffer text show through.
5962 The buffer M must continue to exist until after the echo area gets
5963 cleared or some other message gets displayed there. Do not pass
5964 text that is stored in a Lisp string. Do not pass text in a buffer
5965 that was alloca'd. */
5971 message2 (m
, (m
? strlen (m
) : 0), 0);
5975 /* The non-logging counterpart of message1. */
5981 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5984 /* Display a message M which contains a single %s
5985 which gets replaced with STRING. */
5988 message_with_string (m
, string
, log
)
5997 if (noninteractive_need_newline
)
5998 putc ('\n', stderr
);
5999 noninteractive_need_newline
= 0;
6000 fprintf (stderr
, m
, XSTRING (string
)->data
);
6001 if (cursor_in_echo_area
== 0)
6002 fprintf (stderr
, "\n");
6006 else if (INTERACTIVE
)
6008 /* The frame whose minibuffer we're going to display the message on.
6009 It may be larger than the selected frame, so we need
6010 to use its buffer, not the selected frame's buffer. */
6011 Lisp_Object mini_window
;
6012 struct frame
*f
, *sf
= SELECTED_FRAME ();
6014 /* Get the frame containing the minibuffer
6015 that the selected frame is using. */
6016 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6017 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6019 /* A null message buffer means that the frame hasn't really been
6020 initialized yet. Error messages get reported properly by
6021 cmd_error, so this must be just an informative message; toss it. */
6022 if (FRAME_MESSAGE_BUF (f
))
6026 a
[0] = (char *) XSTRING (string
)->data
;
6028 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6029 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6032 message2 (FRAME_MESSAGE_BUF (f
), len
,
6033 STRING_MULTIBYTE (string
));
6035 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
6036 STRING_MULTIBYTE (string
));
6038 /* Print should start at the beginning of the message
6039 buffer next time. */
6040 message_buf_print
= 0;
6046 /* Dump an informative message to the minibuf. If M is 0, clear out
6047 any existing message, and let the mini-buffer text show through. */
6051 message (m
, a1
, a2
, a3
)
6053 EMACS_INT a1
, a2
, a3
;
6059 if (noninteractive_need_newline
)
6060 putc ('\n', stderr
);
6061 noninteractive_need_newline
= 0;
6062 fprintf (stderr
, m
, a1
, a2
, a3
);
6063 if (cursor_in_echo_area
== 0)
6064 fprintf (stderr
, "\n");
6068 else if (INTERACTIVE
)
6070 /* The frame whose mini-buffer we're going to display the message
6071 on. It may be larger than the selected frame, so we need to
6072 use its buffer, not the selected frame's buffer. */
6073 Lisp_Object mini_window
;
6074 struct frame
*f
, *sf
= SELECTED_FRAME ();
6076 /* Get the frame containing the mini-buffer
6077 that the selected frame is using. */
6078 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6079 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6081 /* A null message buffer means that the frame hasn't really been
6082 initialized yet. Error messages get reported properly by
6083 cmd_error, so this must be just an informative message; toss
6085 if (FRAME_MESSAGE_BUF (f
))
6096 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6097 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6099 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6100 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6102 #endif /* NO_ARG_ARRAY */
6104 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6109 /* Print should start at the beginning of the message
6110 buffer next time. */
6111 message_buf_print
= 0;
6117 /* The non-logging version of message. */
6120 message_nolog (m
, a1
, a2
, a3
)
6122 EMACS_INT a1
, a2
, a3
;
6124 Lisp_Object old_log_max
;
6125 old_log_max
= Vmessage_log_max
;
6126 Vmessage_log_max
= Qnil
;
6127 message (m
, a1
, a2
, a3
);
6128 Vmessage_log_max
= old_log_max
;
6132 /* Display the current message in the current mini-buffer. This is
6133 only called from error handlers in process.c, and is not time
6139 if (!NILP (echo_area_buffer
[0]))
6142 string
= Fcurrent_message ();
6143 message3 (string
, XSTRING (string
)->size
,
6144 !NILP (current_buffer
->enable_multibyte_characters
));
6149 /* Make sure echo area buffers in echo_buffers[] are life. If they
6150 aren't, make new ones. */
6153 ensure_echo_area_buffers ()
6157 for (i
= 0; i
< 2; ++i
)
6158 if (!BUFFERP (echo_buffer
[i
])
6159 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6162 Lisp_Object old_buffer
;
6165 old_buffer
= echo_buffer
[i
];
6166 sprintf (name
, " *Echo Area %d*", i
);
6167 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6168 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6170 for (j
= 0; j
< 2; ++j
)
6171 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6172 echo_area_buffer
[j
] = echo_buffer
[i
];
6177 /* Call FN with args A1..A4 with either the current or last displayed
6178 echo_area_buffer as current buffer.
6180 WHICH zero means use the current message buffer
6181 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6182 from echo_buffer[] and clear it.
6184 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6185 suitable buffer from echo_buffer[] and clear it.
6187 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6188 that the current message becomes the last displayed one, make
6189 choose a suitable buffer for echo_area_buffer[0], and clear it.
6191 Value is what FN returns. */
6194 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6197 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6203 int this_one
, the_other
, clear_buffer_p
, rc
;
6204 int count
= BINDING_STACK_SIZE ();
6206 /* If buffers aren't life, make new ones. */
6207 ensure_echo_area_buffers ();
6212 this_one
= 0, the_other
= 1;
6214 this_one
= 1, the_other
= 0;
6217 this_one
= 0, the_other
= 1;
6220 /* We need a fresh one in case the current echo buffer equals
6221 the one containing the last displayed echo area message. */
6222 if (!NILP (echo_area_buffer
[this_one
])
6223 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6224 echo_area_buffer
[this_one
] = Qnil
;
6227 /* Choose a suitable buffer from echo_buffer[] is we don't
6229 if (NILP (echo_area_buffer
[this_one
]))
6231 echo_area_buffer
[this_one
]
6232 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6233 ? echo_buffer
[the_other
]
6234 : echo_buffer
[this_one
]);
6238 buffer
= echo_area_buffer
[this_one
];
6240 /* Don't get confused by reusing the buffer used for echoing
6241 for a different purpose. */
6242 if (!echoing
&& EQ (buffer
, echo_message_buffer
))
6245 record_unwind_protect (unwind_with_echo_area_buffer
,
6246 with_echo_area_buffer_unwind_data (w
));
6248 /* Make the echo area buffer current. Note that for display
6249 purposes, it is not necessary that the displayed window's buffer
6250 == current_buffer, except for text property lookup. So, let's
6251 only set that buffer temporarily here without doing a full
6252 Fset_window_buffer. We must also change w->pointm, though,
6253 because otherwise an assertions in unshow_buffer fails, and Emacs
6255 set_buffer_internal_1 (XBUFFER (buffer
));
6259 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6262 current_buffer
->undo_list
= Qt
;
6263 current_buffer
->read_only
= Qnil
;
6264 specbind (Qinhibit_read_only
, Qt
);
6266 if (clear_buffer_p
&& Z
> BEG
)
6269 xassert (BEGV
>= BEG
);
6270 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6272 rc
= fn (a1
, a2
, a3
, a4
);
6274 xassert (BEGV
>= BEG
);
6275 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6277 unbind_to (count
, Qnil
);
6282 /* Save state that should be preserved around the call to the function
6283 FN called in with_echo_area_buffer. */
6286 with_echo_area_buffer_unwind_data (w
)
6292 /* Reduce consing by keeping one vector in
6293 Vwith_echo_area_save_vector. */
6294 vector
= Vwith_echo_area_save_vector
;
6295 Vwith_echo_area_save_vector
= Qnil
;
6298 vector
= Fmake_vector (make_number (7), Qnil
);
6300 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6301 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6302 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6306 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6307 AREF (vector
, i
) = w
->buffer
; ++i
;
6308 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6309 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6314 for (; i
< end
; ++i
)
6315 AREF (vector
, i
) = Qnil
;
6318 xassert (i
== ASIZE (vector
));
6323 /* Restore global state from VECTOR which was created by
6324 with_echo_area_buffer_unwind_data. */
6327 unwind_with_echo_area_buffer (vector
)
6330 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6331 Vdeactivate_mark
= AREF (vector
, 1);
6332 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6334 if (WINDOWP (AREF (vector
, 3)))
6337 Lisp_Object buffer
, charpos
, bytepos
;
6339 w
= XWINDOW (AREF (vector
, 3));
6340 buffer
= AREF (vector
, 4);
6341 charpos
= AREF (vector
, 5);
6342 bytepos
= AREF (vector
, 6);
6345 set_marker_both (w
->pointm
, buffer
,
6346 XFASTINT (charpos
), XFASTINT (bytepos
));
6349 Vwith_echo_area_save_vector
= vector
;
6354 /* Set up the echo area for use by print functions. MULTIBYTE_P
6355 non-zero means we will print multibyte. */
6358 setup_echo_area_for_printing (multibyte_p
)
6361 ensure_echo_area_buffers ();
6363 if (!message_buf_print
)
6365 /* A message has been output since the last time we printed.
6366 Choose a fresh echo area buffer. */
6367 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6368 echo_area_buffer
[0] = echo_buffer
[1];
6370 echo_area_buffer
[0] = echo_buffer
[0];
6372 /* Switch to that buffer and clear it. */
6373 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6374 current_buffer
->truncate_lines
= Qnil
;
6378 int count
= BINDING_STACK_SIZE ();
6379 specbind (Qinhibit_read_only
, Qt
);
6381 unbind_to (count
, Qnil
);
6383 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6385 /* Set up the buffer for the multibyteness we need. */
6387 != !NILP (current_buffer
->enable_multibyte_characters
))
6388 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6390 /* Raise the frame containing the echo area. */
6391 if (minibuffer_auto_raise
)
6393 struct frame
*sf
= SELECTED_FRAME ();
6394 Lisp_Object mini_window
;
6395 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6396 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6399 message_log_maybe_newline ();
6400 message_buf_print
= 1;
6404 if (NILP (echo_area_buffer
[0]))
6406 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6407 echo_area_buffer
[0] = echo_buffer
[1];
6409 echo_area_buffer
[0] = echo_buffer
[0];
6412 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6414 /* Someone switched buffers between print requests. */
6415 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6416 current_buffer
->truncate_lines
= Qnil
;
6422 /* Display an echo area message in window W. Value is non-zero if W's
6423 height is changed. If display_last_displayed_message_p is
6424 non-zero, display the message that was last displayed, otherwise
6425 display the current message. */
6428 display_echo_area (w
)
6431 int i
, no_message_p
, window_height_changed_p
, count
;
6433 /* Temporarily disable garbage collections while displaying the echo
6434 area. This is done because a GC can print a message itself.
6435 That message would modify the echo area buffer's contents while a
6436 redisplay of the buffer is going on, and seriously confuse
6438 count
= inhibit_garbage_collection ();
6440 /* If there is no message, we must call display_echo_area_1
6441 nevertheless because it resizes the window. But we will have to
6442 reset the echo_area_buffer in question to nil at the end because
6443 with_echo_area_buffer will sets it to an empty buffer. */
6444 i
= display_last_displayed_message_p
? 1 : 0;
6445 no_message_p
= NILP (echo_area_buffer
[i
]);
6447 window_height_changed_p
6448 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6449 display_echo_area_1
,
6450 (EMACS_INT
) w
, Qnil
, 0, 0);
6453 echo_area_buffer
[i
] = Qnil
;
6455 unbind_to (count
, Qnil
);
6456 return window_height_changed_p
;
6460 /* Helper for display_echo_area. Display the current buffer which
6461 contains the current echo area message in window W, a mini-window,
6462 a pointer to which is passed in A1. A2..A4 are currently not used.
6463 Change the height of W so that all of the message is displayed.
6464 Value is non-zero if height of W was changed. */
6467 display_echo_area_1 (a1
, a2
, a3
, a4
)
6472 struct window
*w
= (struct window
*) a1
;
6474 struct text_pos start
;
6475 int window_height_changed_p
= 0;
6477 /* Do this before displaying, so that we have a large enough glyph
6478 matrix for the display. */
6479 window_height_changed_p
= resize_mini_window (w
, 0);
6482 clear_glyph_matrix (w
->desired_matrix
);
6483 XSETWINDOW (window
, w
);
6484 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6485 try_window (window
, start
);
6487 return window_height_changed_p
;
6491 /* Resize the echo area window to exactly the size needed for the
6492 currently displayed message, if there is one. If a mini-buffer
6493 is active, don't shrink it. */
6496 resize_echo_area_exactly ()
6498 if (BUFFERP (echo_area_buffer
[0])
6499 && WINDOWP (echo_area_window
))
6501 struct window
*w
= XWINDOW (echo_area_window
);
6503 Lisp_Object resize_exactly
;
6505 if (minibuf_level
== 0)
6506 resize_exactly
= Qt
;
6508 resize_exactly
= Qnil
;
6510 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6511 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6514 ++windows_or_buffers_changed
;
6515 ++update_mode_lines
;
6516 redisplay_internal (0);
6522 /* Callback function for with_echo_area_buffer, when used from
6523 resize_echo_area_exactly. A1 contains a pointer to the window to
6524 resize, EXACTLY non-nil means resize the mini-window exactly to the
6525 size of the text displayed. A3 and A4 are not used. Value is what
6526 resize_mini_window returns. */
6529 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6531 Lisp_Object exactly
;
6534 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6538 /* Resize mini-window W to fit the size of its contents. EXACT:P
6539 means size the window exactly to the size needed. Otherwise, it's
6540 only enlarged until W's buffer is empty. Value is non-zero if
6541 the window height has been changed. */
6544 resize_mini_window (w
, exact_p
)
6548 struct frame
*f
= XFRAME (w
->frame
);
6549 int window_height_changed_p
= 0;
6551 xassert (MINI_WINDOW_P (w
));
6553 /* Don't resize windows while redisplaying a window; it would
6554 confuse redisplay functions when the size of the window they are
6555 displaying changes from under them. Such a resizing can happen,
6556 for instance, when which-func prints a long message while
6557 we are running fontification-functions. We're running these
6558 functions with safe_call which binds inhibit-redisplay to t. */
6559 if (!NILP (Vinhibit_redisplay
))
6562 /* Nil means don't try to resize. */
6563 if (NILP (Vresize_mini_windows
)
6564 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6567 if (!FRAME_MINIBUF_ONLY_P (f
))
6570 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6571 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6572 int height
, max_height
;
6573 int unit
= CANON_Y_UNIT (f
);
6574 struct text_pos start
;
6575 struct buffer
*old_current_buffer
= NULL
;
6577 if (current_buffer
!= XBUFFER (w
->buffer
))
6579 old_current_buffer
= current_buffer
;
6580 set_buffer_internal (XBUFFER (w
->buffer
));
6583 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6585 /* Compute the max. number of lines specified by the user. */
6586 if (FLOATP (Vmax_mini_window_height
))
6587 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6588 else if (INTEGERP (Vmax_mini_window_height
))
6589 max_height
= XINT (Vmax_mini_window_height
);
6591 max_height
= total_height
/ 4;
6593 /* Correct that max. height if it's bogus. */
6594 max_height
= max (1, max_height
);
6595 max_height
= min (total_height
, max_height
);
6597 /* Find out the height of the text in the window. */
6598 if (it
.truncate_lines_p
)
6603 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6604 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6605 height
= it
.current_y
+ last_height
;
6607 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6608 height
-= it
.extra_line_spacing
;
6609 height
= (height
+ unit
- 1) / unit
;
6612 /* Compute a suitable window start. */
6613 if (height
> max_height
)
6615 height
= max_height
;
6616 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6617 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6618 start
= it
.current
.pos
;
6621 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6622 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6624 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6626 /* Let it grow only, until we display an empty message, in which
6627 case the window shrinks again. */
6628 if (height
> XFASTINT (w
->height
))
6630 int old_height
= XFASTINT (w
->height
);
6631 freeze_window_starts (f
, 1);
6632 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6633 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6635 else if (height
< XFASTINT (w
->height
)
6636 && (exact_p
|| BEGV
== ZV
))
6638 int old_height
= XFASTINT (w
->height
);
6639 freeze_window_starts (f
, 0);
6640 shrink_mini_window (w
);
6641 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6646 /* Always resize to exact size needed. */
6647 if (height
> XFASTINT (w
->height
))
6649 int old_height
= XFASTINT (w
->height
);
6650 freeze_window_starts (f
, 1);
6651 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6652 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6654 else if (height
< XFASTINT (w
->height
))
6656 int old_height
= XFASTINT (w
->height
);
6657 freeze_window_starts (f
, 0);
6658 shrink_mini_window (w
);
6662 freeze_window_starts (f
, 1);
6663 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6666 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6670 if (old_current_buffer
)
6671 set_buffer_internal (old_current_buffer
);
6674 return window_height_changed_p
;
6678 /* Value is the current message, a string, or nil if there is no
6686 if (NILP (echo_area_buffer
[0]))
6690 with_echo_area_buffer (0, 0, current_message_1
,
6691 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6693 echo_area_buffer
[0] = Qnil
;
6701 current_message_1 (a1
, a2
, a3
, a4
)
6706 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6709 *msg
= make_buffer_string (BEG
, Z
, 1);
6716 /* Push the current message on Vmessage_stack for later restauration
6717 by restore_message. Value is non-zero if the current message isn't
6718 empty. This is a relatively infrequent operation, so it's not
6719 worth optimizing. */
6725 msg
= current_message ();
6726 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6727 return STRINGP (msg
);
6731 /* Handler for record_unwind_protect calling pop_message. */
6734 push_message_unwind (dummy
)
6742 /* Restore message display from the top of Vmessage_stack. */
6749 xassert (CONSP (Vmessage_stack
));
6750 msg
= XCAR (Vmessage_stack
);
6752 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6754 message3_nolog (msg
, 0, 0);
6758 /* Pop the top-most entry off Vmessage_stack. */
6763 xassert (CONSP (Vmessage_stack
));
6764 Vmessage_stack
= XCDR (Vmessage_stack
);
6768 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6769 exits. If the stack is not empty, we have a missing pop_message
6773 check_message_stack ()
6775 if (!NILP (Vmessage_stack
))
6780 /* Truncate to NCHARS what will be displayed in the echo area the next
6781 time we display it---but don't redisplay it now. */
6784 truncate_echo_area (nchars
)
6788 echo_area_buffer
[0] = Qnil
;
6789 /* A null message buffer means that the frame hasn't really been
6790 initialized yet. Error messages get reported properly by
6791 cmd_error, so this must be just an informative message; toss it. */
6792 else if (!noninteractive
6794 && !NILP (echo_area_buffer
[0]))
6796 struct frame
*sf
= SELECTED_FRAME ();
6797 if (FRAME_MESSAGE_BUF (sf
))
6798 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6803 /* Helper function for truncate_echo_area. Truncate the current
6804 message to at most NCHARS characters. */
6807 truncate_message_1 (nchars
, a2
, a3
, a4
)
6812 if (BEG
+ nchars
< Z
)
6813 del_range (BEG
+ nchars
, Z
);
6815 echo_area_buffer
[0] = Qnil
;
6820 /* Set the current message to a substring of S or STRING.
6822 If STRING is a Lisp string, set the message to the first NBYTES
6823 bytes from STRING. NBYTES zero means use the whole string. If
6824 STRING is multibyte, the message will be displayed multibyte.
6826 If S is not null, set the message to the first LEN bytes of S. LEN
6827 zero means use the whole string. MULTIBYTE_P non-zero means S is
6828 multibyte. Display the message multibyte in that case. */
6831 set_message (s
, string
, nbytes
, multibyte_p
)
6836 message_enable_multibyte
6837 = ((s
&& multibyte_p
)
6838 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6840 with_echo_area_buffer (0, -1, set_message_1
,
6841 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6842 message_buf_print
= 0;
6843 help_echo_showing_p
= 0;
6847 /* Helper function for set_message. Arguments have the same meaning
6848 as there, with A1 corresponding to S and A2 corresponding to STRING
6849 This function is called with the echo area buffer being
6853 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6856 EMACS_INT nbytes
, multibyte_p
;
6858 char *s
= (char *) a1
;
6859 Lisp_Object string
= a2
;
6863 /* Change multibyteness of the echo buffer appropriately. */
6864 if (message_enable_multibyte
6865 != !NILP (current_buffer
->enable_multibyte_characters
))
6866 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6868 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6870 /* Insert new message at BEG. */
6871 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6873 if (STRINGP (string
))
6878 nbytes
= XSTRING (string
)->size_byte
;
6879 nchars
= string_byte_to_char (string
, nbytes
);
6881 /* This function takes care of single/multibyte conversion. We
6882 just have to ensure that the echo area buffer has the right
6883 setting of enable_multibyte_characters. */
6884 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6889 nbytes
= strlen (s
);
6891 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6893 /* Convert from multi-byte to single-byte. */
6895 unsigned char work
[1];
6897 /* Convert a multibyte string to single-byte. */
6898 for (i
= 0; i
< nbytes
; i
+= n
)
6900 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6901 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6903 : multibyte_char_to_unibyte (c
, Qnil
));
6904 insert_1_both (work
, 1, 1, 1, 0, 0);
6907 else if (!multibyte_p
6908 && !NILP (current_buffer
->enable_multibyte_characters
))
6910 /* Convert from single-byte to multi-byte. */
6912 unsigned char *msg
= (unsigned char *) s
;
6913 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6915 /* Convert a single-byte string to multibyte. */
6916 for (i
= 0; i
< nbytes
; i
++)
6918 c
= unibyte_char_to_multibyte (msg
[i
]);
6919 n
= CHAR_STRING (c
, str
);
6920 insert_1_both (str
, 1, n
, 1, 0, 0);
6924 insert_1 (s
, nbytes
, 1, 0, 0);
6931 /* Clear messages. CURRENT_P non-zero means clear the current
6932 message. LAST_DISPLAYED_P non-zero means clear the message
6936 clear_message (current_p
, last_displayed_p
)
6937 int current_p
, last_displayed_p
;
6941 echo_area_buffer
[0] = Qnil
;
6942 message_cleared_p
= 1;
6945 if (last_displayed_p
)
6946 echo_area_buffer
[1] = Qnil
;
6948 message_buf_print
= 0;
6951 /* Clear garbaged frames.
6953 This function is used where the old redisplay called
6954 redraw_garbaged_frames which in turn called redraw_frame which in
6955 turn called clear_frame. The call to clear_frame was a source of
6956 flickering. I believe a clear_frame is not necessary. It should
6957 suffice in the new redisplay to invalidate all current matrices,
6958 and ensure a complete redisplay of all windows. */
6961 clear_garbaged_frames ()
6965 Lisp_Object tail
, frame
;
6967 FOR_EACH_FRAME (tail
, frame
)
6969 struct frame
*f
= XFRAME (frame
);
6971 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6973 clear_current_matrices (f
);
6979 ++windows_or_buffers_changed
;
6984 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6985 is non-zero update selected_frame. Value is non-zero if the
6986 mini-windows height has been changed. */
6989 echo_area_display (update_frame_p
)
6992 Lisp_Object mini_window
;
6995 int window_height_changed_p
= 0;
6996 struct frame
*sf
= SELECTED_FRAME ();
6998 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6999 w
= XWINDOW (mini_window
);
7000 f
= XFRAME (WINDOW_FRAME (w
));
7002 /* Don't display if frame is invisible or not yet initialized. */
7003 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7006 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7008 #ifdef HAVE_WINDOW_SYSTEM
7009 /* When Emacs starts, selected_frame may be a visible terminal
7010 frame, even if we run under a window system. If we let this
7011 through, a message would be displayed on the terminal. */
7012 if (EQ (selected_frame
, Vterminal_frame
)
7013 && !NILP (Vwindow_system
))
7015 #endif /* HAVE_WINDOW_SYSTEM */
7018 /* Redraw garbaged frames. */
7020 clear_garbaged_frames ();
7022 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7024 echo_area_window
= mini_window
;
7025 window_height_changed_p
= display_echo_area (w
);
7026 w
->must_be_updated_p
= 1;
7028 /* Update the display, unless called from redisplay_internal.
7029 Also don't update the screen during redisplay itself. The
7030 update will happen at the end of redisplay, and an update
7031 here could cause confusion. */
7032 if (update_frame_p
&& !redisplaying_p
)
7036 /* If the display update has been interrupted by pending
7037 input, update mode lines in the frame. Due to the
7038 pending input, it might have been that redisplay hasn't
7039 been called, so that mode lines above the echo area are
7040 garbaged. This looks odd, so we prevent it here. */
7041 if (!display_completed
)
7042 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7044 if (window_height_changed_p
7045 /* Don't do this if Emacs is shutting down. Redisplay
7046 needs to run hooks. */
7047 && !NILP (Vrun_hooks
))
7049 /* Must update other windows. Likewise as in other
7050 cases, don't let this update be interrupted by
7052 int count
= BINDING_STACK_SIZE ();
7053 specbind (Qredisplay_dont_pause
, Qt
);
7054 windows_or_buffers_changed
= 1;
7055 redisplay_internal (0);
7056 unbind_to (count
, Qnil
);
7058 else if (FRAME_WINDOW_P (f
) && n
== 0)
7060 /* Window configuration is the same as before.
7061 Can do with a display update of the echo area,
7062 unless we displayed some mode lines. */
7063 update_single_window (w
, 1);
7064 rif
->flush_display (f
);
7067 update_frame (f
, 1, 1);
7069 /* If cursor is in the echo area, make sure that the next
7070 redisplay displays the minibuffer, so that the cursor will
7071 be replaced with what the minibuffer wants. */
7072 if (cursor_in_echo_area
)
7073 ++windows_or_buffers_changed
;
7076 else if (!EQ (mini_window
, selected_window
))
7077 windows_or_buffers_changed
++;
7079 /* Last displayed message is now the current message. */
7080 echo_area_buffer
[1] = echo_area_buffer
[0];
7082 /* Prevent redisplay optimization in redisplay_internal by resetting
7083 this_line_start_pos. This is done because the mini-buffer now
7084 displays the message instead of its buffer text. */
7085 if (EQ (mini_window
, selected_window
))
7086 CHARPOS (this_line_start_pos
) = 0;
7088 return window_height_changed_p
;
7093 /***********************************************************************
7095 ***********************************************************************/
7098 #ifdef HAVE_WINDOW_SYSTEM
7100 /* A buffer for constructing frame titles in it; allocated from the
7101 heap in init_xdisp and resized as needed in store_frame_title_char. */
7103 static char *frame_title_buf
;
7105 /* The buffer's end, and a current output position in it. */
7107 static char *frame_title_buf_end
;
7108 static char *frame_title_ptr
;
7111 /* Store a single character C for the frame title in frame_title_buf.
7112 Re-allocate frame_title_buf if necessary. */
7115 store_frame_title_char (c
)
7118 /* If output position has reached the end of the allocated buffer,
7119 double the buffer's size. */
7120 if (frame_title_ptr
== frame_title_buf_end
)
7122 int len
= frame_title_ptr
- frame_title_buf
;
7123 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7124 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7125 frame_title_buf_end
= frame_title_buf
+ new_size
;
7126 frame_title_ptr
= frame_title_buf
+ len
;
7129 *frame_title_ptr
++ = c
;
7133 /* Store part of a frame title in frame_title_buf, beginning at
7134 frame_title_ptr. STR is the string to store. Do not copy
7135 characters that yield more columns than PRECISION; PRECISION <= 0
7136 means copy the whole string. Pad with spaces until FIELD_WIDTH
7137 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7138 pad. Called from display_mode_element when it is used to build a
7142 store_frame_title (str
, field_width
, precision
)
7144 int field_width
, precision
;
7147 int dummy
, nbytes
, width
;
7149 /* Copy at most PRECISION chars from STR. */
7150 nbytes
= strlen (str
);
7151 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7153 store_frame_title_char (*str
++);
7155 /* Fill up with spaces until FIELD_WIDTH reached. */
7156 while (field_width
> 0
7159 store_frame_title_char (' ');
7167 /* Set the title of FRAME, if it has changed. The title format is
7168 Vicon_title_format if FRAME is iconified, otherwise it is
7169 frame_title_format. */
7172 x_consider_frame_title (frame
)
7175 struct frame
*f
= XFRAME (frame
);
7177 if (FRAME_WINDOW_P (f
)
7178 || FRAME_MINIBUF_ONLY_P (f
)
7179 || f
->explicit_name
)
7181 /* Do we have more than one visible frame on this X display? */
7184 struct buffer
*obuf
;
7188 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7190 struct frame
*tf
= XFRAME (XCAR (tail
));
7193 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7194 && !FRAME_MINIBUF_ONLY_P (tf
)
7195 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7199 /* Set global variable indicating that multiple frames exist. */
7200 multiple_frames
= CONSP (tail
);
7202 /* Switch to the buffer of selected window of the frame. Set up
7203 frame_title_ptr so that display_mode_element will output into it;
7204 then display the title. */
7205 obuf
= current_buffer
;
7206 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
7207 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7208 frame_title_ptr
= frame_title_buf
;
7209 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7210 NULL
, DEFAULT_FACE_ID
);
7211 display_mode_element (&it
, 0, -1, -1, fmt
);
7212 len
= frame_title_ptr
- frame_title_buf
;
7213 frame_title_ptr
= NULL
;
7214 set_buffer_internal (obuf
);
7216 /* Set the title only if it's changed. This avoids consing in
7217 the common case where it hasn't. (If it turns out that we've
7218 already wasted too much time by walking through the list with
7219 display_mode_element, then we might need to optimize at a
7220 higher level than this.) */
7221 if (! STRINGP (f
->name
)
7222 || STRING_BYTES (XSTRING (f
->name
)) != len
7223 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
7224 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7228 #else /* not HAVE_WINDOW_SYSTEM */
7230 #define frame_title_ptr ((char *)0)
7231 #define store_frame_title(str, mincol, maxcol) 0
7233 #endif /* not HAVE_WINDOW_SYSTEM */
7238 /***********************************************************************
7240 ***********************************************************************/
7243 /* Prepare for redisplay by updating menu-bar item lists when
7244 appropriate. This can call eval. */
7247 prepare_menu_bars ()
7250 struct gcpro gcpro1
, gcpro2
;
7252 Lisp_Object tooltip_frame
;
7254 #ifdef HAVE_X_WINDOWS
7255 tooltip_frame
= tip_frame
;
7257 tooltip_frame
= Qnil
;
7260 /* Update all frame titles based on their buffer names, etc. We do
7261 this before the menu bars so that the buffer-menu will show the
7262 up-to-date frame titles. */
7263 #ifdef HAVE_WINDOW_SYSTEM
7264 if (windows_or_buffers_changed
|| update_mode_lines
)
7266 Lisp_Object tail
, frame
;
7268 FOR_EACH_FRAME (tail
, frame
)
7271 if (!EQ (frame
, tooltip_frame
)
7272 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7273 x_consider_frame_title (frame
);
7276 #endif /* HAVE_WINDOW_SYSTEM */
7278 /* Update the menu bar item lists, if appropriate. This has to be
7279 done before any actual redisplay or generation of display lines. */
7280 all_windows
= (update_mode_lines
7281 || buffer_shared
> 1
7282 || windows_or_buffers_changed
);
7285 Lisp_Object tail
, frame
;
7286 int count
= BINDING_STACK_SIZE ();
7288 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7290 FOR_EACH_FRAME (tail
, frame
)
7294 /* Ignore tooltip frame. */
7295 if (EQ (frame
, tooltip_frame
))
7298 /* If a window on this frame changed size, report that to
7299 the user and clear the size-change flag. */
7300 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7302 Lisp_Object functions
;
7304 /* Clear flag first in case we get an error below. */
7305 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7306 functions
= Vwindow_size_change_functions
;
7307 GCPRO2 (tail
, functions
);
7309 while (CONSP (functions
))
7311 call1 (XCAR (functions
), frame
);
7312 functions
= XCDR (functions
);
7318 update_menu_bar (f
, 0);
7319 #ifdef HAVE_WINDOW_SYSTEM
7320 update_tool_bar (f
, 0);
7325 unbind_to (count
, Qnil
);
7329 struct frame
*sf
= SELECTED_FRAME ();
7330 update_menu_bar (sf
, 1);
7331 #ifdef HAVE_WINDOW_SYSTEM
7332 update_tool_bar (sf
, 1);
7336 /* Motif needs this. See comment in xmenu.c. Turn it off when
7337 pending_menu_activation is not defined. */
7338 #ifdef USE_X_TOOLKIT
7339 pending_menu_activation
= 0;
7344 /* Update the menu bar item list for frame F. This has to be done
7345 before we start to fill in any display lines, because it can call
7348 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7351 update_menu_bar (f
, save_match_data
)
7353 int save_match_data
;
7356 register struct window
*w
;
7358 /* If called recursively during a menu update, do nothing. This can
7359 happen when, for instance, an activate-menubar-hook causes a
7361 if (inhibit_menubar_update
)
7364 window
= FRAME_SELECTED_WINDOW (f
);
7365 w
= XWINDOW (window
);
7367 if (update_mode_lines
)
7368 w
->update_mode_line
= Qt
;
7370 if (FRAME_WINDOW_P (f
)
7372 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7373 FRAME_EXTERNAL_MENU_BAR (f
)
7375 FRAME_MENU_BAR_LINES (f
) > 0
7377 : FRAME_MENU_BAR_LINES (f
) > 0)
7379 /* If the user has switched buffers or windows, we need to
7380 recompute to reflect the new bindings. But we'll
7381 recompute when update_mode_lines is set too; that means
7382 that people can use force-mode-line-update to request
7383 that the menu bar be recomputed. The adverse effect on
7384 the rest of the redisplay algorithm is about the same as
7385 windows_or_buffers_changed anyway. */
7386 if (windows_or_buffers_changed
7387 || !NILP (w
->update_mode_line
)
7388 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7389 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7390 != !NILP (w
->last_had_star
))
7391 || ((!NILP (Vtransient_mark_mode
)
7392 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7393 != !NILP (w
->region_showing
)))
7395 struct buffer
*prev
= current_buffer
;
7396 int count
= BINDING_STACK_SIZE ();
7398 specbind (Qinhibit_menubar_update
, Qt
);
7400 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7401 if (save_match_data
)
7402 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7403 if (NILP (Voverriding_local_map_menu_flag
))
7405 specbind (Qoverriding_terminal_local_map
, Qnil
);
7406 specbind (Qoverriding_local_map
, Qnil
);
7409 /* Run the Lucid hook. */
7410 safe_run_hooks (Qactivate_menubar_hook
);
7412 /* If it has changed current-menubar from previous value,
7413 really recompute the menu-bar from the value. */
7414 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7415 call0 (Qrecompute_lucid_menubar
);
7417 safe_run_hooks (Qmenu_bar_update_hook
);
7418 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7420 /* Redisplay the menu bar in case we changed it. */
7421 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7422 if (FRAME_WINDOW_P (f
)
7423 #if defined (macintosh)
7424 /* All frames on Mac OS share the same menubar. So only the
7425 selected frame should be allowed to set it. */
7426 && f
== SELECTED_FRAME ()
7429 set_frame_menubar (f
, 0, 0);
7431 /* On a terminal screen, the menu bar is an ordinary screen
7432 line, and this makes it get updated. */
7433 w
->update_mode_line
= Qt
;
7434 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7435 /* In the non-toolkit version, the menu bar is an ordinary screen
7436 line, and this makes it get updated. */
7437 w
->update_mode_line
= Qt
;
7438 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7440 unbind_to (count
, Qnil
);
7441 set_buffer_internal_1 (prev
);
7448 /***********************************************************************
7450 ***********************************************************************/
7452 #ifdef HAVE_WINDOW_SYSTEM
7454 /* Update the tool-bar item list for frame F. This has to be done
7455 before we start to fill in any display lines. Called from
7456 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7457 and restore it here. */
7460 update_tool_bar (f
, save_match_data
)
7462 int save_match_data
;
7464 if (WINDOWP (f
->tool_bar_window
)
7465 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7470 window
= FRAME_SELECTED_WINDOW (f
);
7471 w
= XWINDOW (window
);
7473 /* If the user has switched buffers or windows, we need to
7474 recompute to reflect the new bindings. But we'll
7475 recompute when update_mode_lines is set too; that means
7476 that people can use force-mode-line-update to request
7477 that the menu bar be recomputed. The adverse effect on
7478 the rest of the redisplay algorithm is about the same as
7479 windows_or_buffers_changed anyway. */
7480 if (windows_or_buffers_changed
7481 || !NILP (w
->update_mode_line
)
7482 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7483 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7484 != !NILP (w
->last_had_star
))
7485 || ((!NILP (Vtransient_mark_mode
)
7486 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7487 != !NILP (w
->region_showing
)))
7489 struct buffer
*prev
= current_buffer
;
7490 int count
= BINDING_STACK_SIZE ();
7492 /* Set current_buffer to the buffer of the selected
7493 window of the frame, so that we get the right local
7495 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7497 /* Save match data, if we must. */
7498 if (save_match_data
)
7499 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7501 /* Make sure that we don't accidentally use bogus keymaps. */
7502 if (NILP (Voverriding_local_map_menu_flag
))
7504 specbind (Qoverriding_terminal_local_map
, Qnil
);
7505 specbind (Qoverriding_local_map
, Qnil
);
7508 /* Build desired tool-bar items from keymaps. */
7510 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7512 /* Redisplay the tool-bar in case we changed it. */
7513 w
->update_mode_line
= Qt
;
7515 unbind_to (count
, Qnil
);
7516 set_buffer_internal_1 (prev
);
7522 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7523 F's desired tool-bar contents. F->tool_bar_items must have
7524 been set up previously by calling prepare_menu_bars. */
7527 build_desired_tool_bar_string (f
)
7530 int i
, size
, size_needed
;
7531 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7532 Lisp_Object image
, plist
, props
;
7534 image
= plist
= props
= Qnil
;
7535 GCPRO3 (image
, plist
, props
);
7537 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7538 Otherwise, make a new string. */
7540 /* The size of the string we might be able to reuse. */
7541 size
= (STRINGP (f
->desired_tool_bar_string
)
7542 ? XSTRING (f
->desired_tool_bar_string
)->size
7545 /* We need one space in the string for each image. */
7546 size_needed
= f
->n_tool_bar_items
;
7548 /* Reuse f->desired_tool_bar_string, if possible. */
7549 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7550 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7554 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7555 Fremove_text_properties (make_number (0), make_number (size
),
7556 props
, f
->desired_tool_bar_string
);
7559 /* Put a `display' property on the string for the images to display,
7560 put a `menu_item' property on tool-bar items with a value that
7561 is the index of the item in F's tool-bar item vector. */
7562 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7564 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7566 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7567 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7568 int hmargin
, vmargin
, relief
, idx
, end
;
7569 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7570 extern Lisp_Object Qlaplace
;
7572 /* If image is a vector, choose the image according to the
7574 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7575 if (VECTORP (image
))
7579 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7580 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7583 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7584 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7586 xassert (ASIZE (image
) >= idx
);
7587 image
= AREF (image
, idx
);
7592 /* Ignore invalid image specifications. */
7593 if (!valid_image_p (image
))
7596 /* Display the tool-bar button pressed, or depressed. */
7597 plist
= Fcopy_sequence (XCDR (image
));
7599 /* Compute margin and relief to draw. */
7600 relief
= (tool_bar_button_relief
> 0
7601 ? tool_bar_button_relief
7602 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7603 hmargin
= vmargin
= relief
;
7605 if (INTEGERP (Vtool_bar_button_margin
)
7606 && XINT (Vtool_bar_button_margin
) > 0)
7608 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7609 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7611 else if (CONSP (Vtool_bar_button_margin
))
7613 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7614 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7615 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7617 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7618 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7619 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7622 if (auto_raise_tool_bar_buttons_p
)
7624 /* Add a `:relief' property to the image spec if the item is
7628 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7635 /* If image is selected, display it pressed, i.e. with a
7636 negative relief. If it's not selected, display it with a
7638 plist
= Fplist_put (plist
, QCrelief
,
7640 ? make_number (-relief
)
7641 : make_number (relief
)));
7646 /* Put a margin around the image. */
7647 if (hmargin
|| vmargin
)
7649 if (hmargin
== vmargin
)
7650 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7652 plist
= Fplist_put (plist
, QCmargin
,
7653 Fcons (make_number (hmargin
),
7654 make_number (vmargin
)));
7657 /* If button is not enabled, and we don't have special images
7658 for the disabled state, make the image appear disabled by
7659 applying an appropriate algorithm to it. */
7660 if (!enabled_p
&& idx
< 0)
7661 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7663 /* Put a `display' text property on the string for the image to
7664 display. Put a `menu-item' property on the string that gives
7665 the start of this item's properties in the tool-bar items
7667 image
= Fcons (Qimage
, plist
);
7668 props
= list4 (Qdisplay
, image
,
7669 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7671 /* Let the last image hide all remaining spaces in the tool bar
7672 string. The string can be longer than needed when we reuse a
7674 if (i
+ 1 == f
->n_tool_bar_items
)
7675 end
= XSTRING (f
->desired_tool_bar_string
)->size
;
7678 Fadd_text_properties (make_number (i
), make_number (end
),
7679 props
, f
->desired_tool_bar_string
);
7687 /* Display one line of the tool-bar of frame IT->f. */
7690 display_tool_bar_line (it
)
7693 struct glyph_row
*row
= it
->glyph_row
;
7694 int max_x
= it
->last_visible_x
;
7697 prepare_desired_row (row
);
7698 row
->y
= it
->current_y
;
7700 /* Note that this isn't made use of if the face hasn't a box,
7701 so there's no need to check the face here. */
7702 it
->start_of_box_run_p
= 1;
7704 while (it
->current_x
< max_x
)
7706 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7708 /* Get the next display element. */
7709 if (!get_next_display_element (it
))
7712 /* Produce glyphs. */
7713 x_before
= it
->current_x
;
7714 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7715 PRODUCE_GLYPHS (it
);
7717 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7722 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7724 if (x
+ glyph
->pixel_width
> max_x
)
7726 /* Glyph doesn't fit on line. */
7727 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7733 x
+= glyph
->pixel_width
;
7737 /* Stop at line ends. */
7738 if (ITERATOR_AT_END_OF_LINE_P (it
))
7741 set_iterator_to_next (it
, 1);
7746 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7747 extend_face_to_end_of_line (it
);
7748 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7749 last
->right_box_line_p
= 1;
7750 if (last
== row
->glyphs
[TEXT_AREA
])
7751 last
->left_box_line_p
= 1;
7752 compute_line_metrics (it
);
7754 /* If line is empty, make it occupy the rest of the tool-bar. */
7755 if (!row
->displays_text_p
)
7757 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7758 row
->ascent
= row
->phys_ascent
= 0;
7761 row
->full_width_p
= 1;
7762 row
->continued_p
= 0;
7763 row
->truncated_on_left_p
= 0;
7764 row
->truncated_on_right_p
= 0;
7766 it
->current_x
= it
->hpos
= 0;
7767 it
->current_y
+= row
->height
;
7773 /* Value is the number of screen lines needed to make all tool-bar
7774 items of frame F visible. */
7777 tool_bar_lines_needed (f
)
7780 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7783 /* Initialize an iterator for iteration over
7784 F->desired_tool_bar_string in the tool-bar window of frame F. */
7785 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7786 it
.first_visible_x
= 0;
7787 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7788 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7790 while (!ITERATOR_AT_END_P (&it
))
7792 it
.glyph_row
= w
->desired_matrix
->rows
;
7793 clear_glyph_row (it
.glyph_row
);
7794 display_tool_bar_line (&it
);
7797 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7801 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7803 "Return the number of lines occupied by the tool bar of FRAME.")
7812 frame
= selected_frame
;
7814 CHECK_FRAME (frame
, 0);
7817 if (WINDOWP (f
->tool_bar_window
)
7818 || (w
= XWINDOW (f
->tool_bar_window
),
7819 XFASTINT (w
->height
) > 0))
7821 update_tool_bar (f
, 1);
7822 if (f
->n_tool_bar_items
)
7824 build_desired_tool_bar_string (f
);
7825 nlines
= tool_bar_lines_needed (f
);
7829 return make_number (nlines
);
7833 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7834 height should be changed. */
7837 redisplay_tool_bar (f
)
7842 struct glyph_row
*row
;
7843 int change_height_p
= 0;
7845 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7846 do anything. This means you must start with tool-bar-lines
7847 non-zero to get the auto-sizing effect. Or in other words, you
7848 can turn off tool-bars by specifying tool-bar-lines zero. */
7849 if (!WINDOWP (f
->tool_bar_window
)
7850 || (w
= XWINDOW (f
->tool_bar_window
),
7851 XFASTINT (w
->height
) == 0))
7854 /* Set up an iterator for the tool-bar window. */
7855 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7856 it
.first_visible_x
= 0;
7857 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7860 /* Build a string that represents the contents of the tool-bar. */
7861 build_desired_tool_bar_string (f
);
7862 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7864 /* Display as many lines as needed to display all tool-bar items. */
7865 while (it
.current_y
< it
.last_visible_y
)
7866 display_tool_bar_line (&it
);
7868 /* It doesn't make much sense to try scrolling in the tool-bar
7869 window, so don't do it. */
7870 w
->desired_matrix
->no_scrolling_p
= 1;
7871 w
->must_be_updated_p
= 1;
7873 if (auto_resize_tool_bars_p
)
7877 /* If we couldn't display everything, change the tool-bar's
7879 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7880 change_height_p
= 1;
7882 /* If there are blank lines at the end, except for a partially
7883 visible blank line at the end that is smaller than
7884 CANON_Y_UNIT, change the tool-bar's height. */
7885 row
= it
.glyph_row
- 1;
7886 if (!row
->displays_text_p
7887 && row
->height
>= CANON_Y_UNIT (f
))
7888 change_height_p
= 1;
7890 /* If row displays tool-bar items, but is partially visible,
7891 change the tool-bar's height. */
7892 if (row
->displays_text_p
7893 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7894 change_height_p
= 1;
7896 /* Resize windows as needed by changing the `tool-bar-lines'
7899 && (nlines
= tool_bar_lines_needed (f
),
7900 nlines
!= XFASTINT (w
->height
)))
7902 extern Lisp_Object Qtool_bar_lines
;
7904 int old_height
= XFASTINT (w
->height
);
7906 XSETFRAME (frame
, f
);
7907 clear_glyph_matrix (w
->desired_matrix
);
7908 Fmodify_frame_parameters (frame
,
7909 Fcons (Fcons (Qtool_bar_lines
,
7910 make_number (nlines
)),
7912 if (XFASTINT (w
->height
) != old_height
)
7913 fonts_changed_p
= 1;
7917 return change_height_p
;
7921 /* Get information about the tool-bar item which is displayed in GLYPH
7922 on frame F. Return in *PROP_IDX the index where tool-bar item
7923 properties start in F->tool_bar_items. Value is zero if
7924 GLYPH doesn't display a tool-bar item. */
7927 tool_bar_item_info (f
, glyph
, prop_idx
)
7929 struct glyph
*glyph
;
7935 /* Get the text property `menu-item' at pos. The value of that
7936 property is the start index of this item's properties in
7937 F->tool_bar_items. */
7938 prop
= Fget_text_property (make_number (glyph
->charpos
),
7939 Qmenu_item
, f
->current_tool_bar_string
);
7940 if (INTEGERP (prop
))
7942 *prop_idx
= XINT (prop
);
7951 #endif /* HAVE_WINDOW_SYSTEM */
7955 /************************************************************************
7956 Horizontal scrolling
7957 ************************************************************************/
7959 static int hscroll_window_tree
P_ ((Lisp_Object
));
7960 static int hscroll_windows
P_ ((Lisp_Object
));
7962 /* For all leaf windows in the window tree rooted at WINDOW, set their
7963 hscroll value so that PT is (i) visible in the window, and (ii) so
7964 that it is not within a certain margin at the window's left and
7965 right border. Value is non-zero if any window's hscroll has been
7969 hscroll_window_tree (window
)
7972 int hscrolled_p
= 0;
7974 while (WINDOWP (window
))
7976 struct window
*w
= XWINDOW (window
);
7978 if (WINDOWP (w
->hchild
))
7979 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7980 else if (WINDOWP (w
->vchild
))
7981 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7982 else if (w
->cursor
.vpos
>= 0)
7984 int hscroll_margin
, text_area_x
, text_area_y
;
7985 int text_area_width
, text_area_height
;
7986 struct glyph_row
*current_cursor_row
7987 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7988 struct glyph_row
*desired_cursor_row
7989 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7990 struct glyph_row
*cursor_row
7991 = (desired_cursor_row
->enabled_p
7992 ? desired_cursor_row
7993 : current_cursor_row
);
7995 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7996 &text_area_width
, &text_area_height
);
7998 /* Scroll when cursor is inside this scroll margin. */
7999 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
8001 if ((XFASTINT (w
->hscroll
)
8002 && w
->cursor
.x
< hscroll_margin
)
8003 || (cursor_row
->enabled_p
8004 && cursor_row
->truncated_on_right_p
8005 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
8009 struct buffer
*saved_current_buffer
;
8012 /* Find point in a display of infinite width. */
8013 saved_current_buffer
= current_buffer
;
8014 current_buffer
= XBUFFER (w
->buffer
);
8016 if (w
== XWINDOW (selected_window
))
8017 pt
= BUF_PT (current_buffer
);
8020 pt
= marker_position (w
->pointm
);
8021 pt
= max (BEGV
, pt
);
8025 /* Move iterator to pt starting at cursor_row->start in
8026 a line with infinite width. */
8027 init_to_row_start (&it
, w
, cursor_row
);
8028 it
.last_visible_x
= INFINITY
;
8029 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8030 current_buffer
= saved_current_buffer
;
8032 /* Center cursor in window. */
8033 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
8034 / CANON_X_UNIT (it
.f
));
8035 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8037 /* Don't call Fset_window_hscroll if value hasn't
8038 changed because it will prevent redisplay
8040 if (XFASTINT (w
->hscroll
) != hscroll
)
8042 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8043 w
->hscroll
= make_number (hscroll
);
8052 /* Value is non-zero if hscroll of any leaf window has been changed. */
8057 /* Set hscroll so that cursor is visible and not inside horizontal
8058 scroll margins for all windows in the tree rooted at WINDOW. See
8059 also hscroll_window_tree above. Value is non-zero if any window's
8060 hscroll has been changed. If it has, desired matrices on the frame
8061 of WINDOW are cleared. */
8064 hscroll_windows (window
)
8069 if (automatic_hscrolling_p
)
8071 hscrolled_p
= hscroll_window_tree (window
);
8073 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8082 /************************************************************************
8084 ************************************************************************/
8086 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8087 to a non-zero value. This is sometimes handy to have in a debugger
8092 /* First and last unchanged row for try_window_id. */
8094 int debug_first_unchanged_at_end_vpos
;
8095 int debug_last_unchanged_at_beg_vpos
;
8097 /* Delta vpos and y. */
8099 int debug_dvpos
, debug_dy
;
8101 /* Delta in characters and bytes for try_window_id. */
8103 int debug_delta
, debug_delta_bytes
;
8105 /* Values of window_end_pos and window_end_vpos at the end of
8108 int debug_end_pos
, debug_end_vpos
;
8110 /* Append a string to W->desired_matrix->method. FMT is a printf
8111 format string. A1...A9 are a supplement for a variable-length
8112 argument list. If trace_redisplay_p is non-zero also printf the
8113 resulting string to stderr. */
8116 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8119 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8122 char *method
= w
->desired_matrix
->method
;
8123 int len
= strlen (method
);
8124 int size
= sizeof w
->desired_matrix
->method
;
8125 int remaining
= size
- len
- 1;
8127 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8128 if (len
&& remaining
)
8134 strncpy (method
+ len
, buffer
, remaining
);
8136 if (trace_redisplay_p
)
8137 fprintf (stderr
, "%p (%s): %s\n",
8139 ((BUFFERP (w
->buffer
)
8140 && STRINGP (XBUFFER (w
->buffer
)->name
))
8141 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
8146 #endif /* GLYPH_DEBUG */
8149 /* This counter is used to clear the face cache every once in a while
8150 in redisplay_internal. It is incremented for each redisplay.
8151 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8154 #define CLEAR_FACE_CACHE_COUNT 10000
8155 static int clear_face_cache_count
;
8157 /* Record the previous terminal frame we displayed. */
8159 static struct frame
*previous_terminal_frame
;
8161 /* Non-zero while redisplay_internal is in progress. */
8166 /* Value is non-zero if all changes in window W, which displays
8167 current_buffer, are in the text between START and END. START is a
8168 buffer position, END is given as a distance from Z. Used in
8169 redisplay_internal for display optimization. */
8172 text_outside_line_unchanged_p (w
, start
, end
)
8176 int unchanged_p
= 1;
8178 /* If text or overlays have changed, see where. */
8179 if (XFASTINT (w
->last_modified
) < MODIFF
8180 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8182 /* Gap in the line? */
8183 if (GPT
< start
|| Z
- GPT
< end
)
8186 /* Changes start in front of the line, or end after it? */
8188 && (BEG_UNCHANGED
< start
- 1
8189 || END_UNCHANGED
< end
))
8192 /* If selective display, can't optimize if changes start at the
8193 beginning of the line. */
8195 && INTEGERP (current_buffer
->selective_display
)
8196 && XINT (current_buffer
->selective_display
) > 0
8197 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8200 /* If there are overlays at the start or end of the line, these
8201 may have overlay strings with newlines in them. A change at
8202 START, for instance, may actually concern the display of such
8203 overlay strings as well, and they are displayed on different
8204 lines. So, quickly rule out this case. (For the future, it
8205 might be desirable to implement something more telling than
8206 just BEG/END_UNCHANGED.) */
8209 if (BEG
+ BEG_UNCHANGED
== start
8210 && overlay_touches_p (start
))
8212 if (END_UNCHANGED
== end
8213 && overlay_touches_p (Z
- end
))
8222 /* Do a frame update, taking possible shortcuts into account. This is
8223 the main external entry point for redisplay.
8225 If the last redisplay displayed an echo area message and that message
8226 is no longer requested, we clear the echo area or bring back the
8227 mini-buffer if that is in use. */
8232 redisplay_internal (0);
8236 /* Return 1 if point moved out of or into a composition. Otherwise
8237 return 0. PREV_BUF and PREV_PT are the last point buffer and
8238 position. BUF and PT are the current point buffer and position. */
8241 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8242 struct buffer
*prev_buf
, *buf
;
8249 XSETBUFFER (buffer
, buf
);
8250 /* Check a composition at the last point if point moved within the
8252 if (prev_buf
== buf
)
8255 /* Point didn't move. */
8258 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8259 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8260 && COMPOSITION_VALID_P (start
, end
, prop
)
8261 && start
< prev_pt
&& end
> prev_pt
)
8262 /* The last point was within the composition. Return 1 iff
8263 point moved out of the composition. */
8264 return (pt
<= start
|| pt
>= end
);
8267 /* Check a composition at the current point. */
8268 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8269 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8270 && COMPOSITION_VALID_P (start
, end
, prop
)
8271 && start
< pt
&& end
> pt
);
8275 /* Reconsider the setting of B->clip_changed which is displayed
8279 reconsider_clip_changes (w
, b
)
8283 if (b
->prevent_redisplay_optimizations_p
)
8284 b
->clip_changed
= 1;
8285 else if (b
->clip_changed
8286 && !NILP (w
->window_end_valid
)
8287 && w
->current_matrix
->buffer
== b
8288 && w
->current_matrix
->zv
== BUF_ZV (b
)
8289 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8290 b
->clip_changed
= 0;
8292 /* If display wasn't paused, and W is not a tool bar window, see if
8293 point has been moved into or out of a composition. In that case,
8294 we set b->clip_changed to 1 to force updating the screen. If
8295 b->clip_changed has already been set to 1, we can skip this
8297 if (!b
->clip_changed
8298 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8302 if (w
== XWINDOW (selected_window
))
8303 pt
= BUF_PT (current_buffer
);
8305 pt
= marker_position (w
->pointm
);
8307 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8308 || pt
!= XINT (w
->last_point
))
8309 && check_point_in_composition (w
->current_matrix
->buffer
,
8310 XINT (w
->last_point
),
8311 XBUFFER (w
->buffer
), pt
))
8312 b
->clip_changed
= 1;
8317 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8318 response to any user action; therefore, we should preserve the echo
8319 area. (Actually, our caller does that job.) Perhaps in the future
8320 avoid recentering windows if it is not necessary; currently that
8321 causes some problems. */
8324 redisplay_internal (preserve_echo_area
)
8325 int preserve_echo_area
;
8327 struct window
*w
= XWINDOW (selected_window
);
8328 struct frame
*f
= XFRAME (w
->frame
);
8330 int must_finish
= 0;
8331 struct text_pos tlbufpos
, tlendpos
;
8332 int number_of_visible_frames
;
8334 struct frame
*sf
= SELECTED_FRAME ();
8336 /* Non-zero means redisplay has to consider all windows on all
8337 frames. Zero means, only selected_window is considered. */
8338 int consider_all_windows_p
;
8340 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8342 /* No redisplay if running in batch mode or frame is not yet fully
8343 initialized, or redisplay is explicitly turned off by setting
8344 Vinhibit_redisplay. */
8346 || !NILP (Vinhibit_redisplay
)
8347 || !f
->glyphs_initialized_p
)
8350 /* The flag redisplay_performed_directly_p is set by
8351 direct_output_for_insert when it already did the whole screen
8352 update necessary. */
8353 if (redisplay_performed_directly_p
)
8355 redisplay_performed_directly_p
= 0;
8356 if (!hscroll_windows (selected_window
))
8360 #ifdef USE_X_TOOLKIT
8361 if (popup_activated ())
8365 /* I don't think this happens but let's be paranoid. */
8369 /* Record a function that resets redisplaying_p to its old value
8370 when we leave this function. */
8371 count
= BINDING_STACK_SIZE ();
8372 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8377 reconsider_clip_changes (w
, current_buffer
);
8379 /* If new fonts have been loaded that make a glyph matrix adjustment
8380 necessary, do it. */
8381 if (fonts_changed_p
)
8383 adjust_glyphs (NULL
);
8384 ++windows_or_buffers_changed
;
8385 fonts_changed_p
= 0;
8388 /* If face_change_count is non-zero, init_iterator will free all
8389 realized faces, which includes the faces referenced from current
8390 matrices. So, we can't reuse current matrices in this case. */
8391 if (face_change_count
)
8392 ++windows_or_buffers_changed
;
8394 if (! FRAME_WINDOW_P (sf
)
8395 && previous_terminal_frame
!= sf
)
8397 /* Since frames on an ASCII terminal share the same display
8398 area, displaying a different frame means redisplay the whole
8400 windows_or_buffers_changed
++;
8401 SET_FRAME_GARBAGED (sf
);
8402 XSETFRAME (Vterminal_frame
, sf
);
8404 previous_terminal_frame
= sf
;
8406 /* Set the visible flags for all frames. Do this before checking
8407 for resized or garbaged frames; they want to know if their frames
8408 are visible. See the comment in frame.h for
8409 FRAME_SAMPLE_VISIBILITY. */
8411 Lisp_Object tail
, frame
;
8413 number_of_visible_frames
= 0;
8415 FOR_EACH_FRAME (tail
, frame
)
8417 struct frame
*f
= XFRAME (frame
);
8419 FRAME_SAMPLE_VISIBILITY (f
);
8420 if (FRAME_VISIBLE_P (f
))
8421 ++number_of_visible_frames
;
8422 clear_desired_matrices (f
);
8426 /* Notice any pending interrupt request to change frame size. */
8427 do_pending_window_change (1);
8429 /* Clear frames marked as garbaged. */
8431 clear_garbaged_frames ();
8433 /* Build menubar and tool-bar items. */
8434 prepare_menu_bars ();
8436 if (windows_or_buffers_changed
)
8437 update_mode_lines
++;
8439 /* Detect case that we need to write or remove a star in the mode line. */
8440 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8442 w
->update_mode_line
= Qt
;
8443 if (buffer_shared
> 1)
8444 update_mode_lines
++;
8447 /* If %c is in the mode line, update it if needed. */
8448 if (!NILP (w
->column_number_displayed
)
8449 /* This alternative quickly identifies a common case
8450 where no change is needed. */
8451 && !(PT
== XFASTINT (w
->last_point
)
8452 && XFASTINT (w
->last_modified
) >= MODIFF
8453 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8454 && XFASTINT (w
->column_number_displayed
) != current_column ())
8455 w
->update_mode_line
= Qt
;
8457 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8459 /* The variable buffer_shared is set in redisplay_window and
8460 indicates that we redisplay a buffer in different windows. See
8462 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8464 /* If specs for an arrow have changed, do thorough redisplay
8465 to ensure we remove any arrow that should no longer exist. */
8466 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8467 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8468 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8470 /* Normally the message* functions will have already displayed and
8471 updated the echo area, but the frame may have been trashed, or
8472 the update may have been preempted, so display the echo area
8473 again here. Checking message_cleared_p captures the case that
8474 the echo area should be cleared. */
8475 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8476 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8477 || (message_cleared_p
&& minibuf_level
== 0))
8479 int window_height_changed_p
= echo_area_display (0);
8482 /* If we don't display the current message, don't clear the
8483 message_cleared_p flag, because, if we did, we wouldn't clear
8484 the echo area in the next redisplay which doesn't preserve
8486 if (!display_last_displayed_message_p
)
8487 message_cleared_p
= 0;
8489 if (fonts_changed_p
)
8491 else if (window_height_changed_p
)
8493 consider_all_windows_p
= 1;
8494 ++update_mode_lines
;
8495 ++windows_or_buffers_changed
;
8497 /* If window configuration was changed, frames may have been
8498 marked garbaged. Clear them or we will experience
8499 surprises wrt scrolling. */
8501 clear_garbaged_frames ();
8504 else if (EQ (selected_window
, minibuf_window
)
8505 && (current_buffer
->clip_changed
8506 || XFASTINT (w
->last_modified
) < MODIFF
8507 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8508 && resize_mini_window (w
, 0))
8510 /* Resized active mini-window to fit the size of what it is
8511 showing if its contents might have changed. */
8513 consider_all_windows_p
= 1;
8514 ++windows_or_buffers_changed
;
8515 ++update_mode_lines
;
8517 /* If window configuration was changed, frames may have been
8518 marked garbaged. Clear them or we will experience
8519 surprises wrt scrolling. */
8521 clear_garbaged_frames ();
8525 /* If showing the region, and mark has changed, we must redisplay
8526 the whole window. The assignment to this_line_start_pos prevents
8527 the optimization directly below this if-statement. */
8528 if (((!NILP (Vtransient_mark_mode
)
8529 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8530 != !NILP (w
->region_showing
))
8531 || (!NILP (w
->region_showing
)
8532 && !EQ (w
->region_showing
,
8533 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8534 CHARPOS (this_line_start_pos
) = 0;
8536 /* Optimize the case that only the line containing the cursor in the
8537 selected window has changed. Variables starting with this_ are
8538 set in display_line and record information about the line
8539 containing the cursor. */
8540 tlbufpos
= this_line_start_pos
;
8541 tlendpos
= this_line_end_pos
;
8542 if (!consider_all_windows_p
8543 && CHARPOS (tlbufpos
) > 0
8544 && NILP (w
->update_mode_line
)
8545 && !current_buffer
->clip_changed
8546 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8547 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8548 /* Make sure recorded data applies to current buffer, etc. */
8549 && this_line_buffer
== current_buffer
8550 && current_buffer
== XBUFFER (w
->buffer
)
8551 && NILP (w
->force_start
)
8552 /* Point must be on the line that we have info recorded about. */
8553 && PT
>= CHARPOS (tlbufpos
)
8554 && PT
<= Z
- CHARPOS (tlendpos
)
8555 /* All text outside that line, including its final newline,
8556 must be unchanged */
8557 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8558 CHARPOS (tlendpos
)))
8560 if (CHARPOS (tlbufpos
) > BEGV
8561 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8562 && (CHARPOS (tlbufpos
) == ZV
8563 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8564 /* Former continuation line has disappeared by becoming empty */
8566 else if (XFASTINT (w
->last_modified
) < MODIFF
8567 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8568 || MINI_WINDOW_P (w
))
8570 /* We have to handle the case of continuation around a
8571 wide-column character (See the comment in indent.c around
8574 For instance, in the following case:
8576 -------- Insert --------
8577 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8578 J_I_ ==> J_I_ `^^' are cursors.
8582 As we have to redraw the line above, we should goto cancel. */
8585 int line_height_before
= this_line_pixel_height
;
8587 /* Note that start_display will handle the case that the
8588 line starting at tlbufpos is a continuation lines. */
8589 start_display (&it
, w
, tlbufpos
);
8591 /* Implementation note: It this still necessary? */
8592 if (it
.current_x
!= this_line_start_x
)
8595 TRACE ((stderr
, "trying display optimization 1\n"));
8596 w
->cursor
.vpos
= -1;
8597 overlay_arrow_seen
= 0;
8598 it
.vpos
= this_line_vpos
;
8599 it
.current_y
= this_line_y
;
8600 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8603 /* If line contains point, is not continued,
8604 and ends at same distance from eob as before, we win */
8605 if (w
->cursor
.vpos
>= 0
8606 /* Line is not continued, otherwise this_line_start_pos
8607 would have been set to 0 in display_line. */
8608 && CHARPOS (this_line_start_pos
)
8609 /* Line ends as before. */
8610 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8611 /* Line has same height as before. Otherwise other lines
8612 would have to be shifted up or down. */
8613 && this_line_pixel_height
== line_height_before
)
8615 /* If this is not the window's last line, we must adjust
8616 the charstarts of the lines below. */
8617 if (it
.current_y
< it
.last_visible_y
)
8619 struct glyph_row
*row
8620 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8621 int delta
, delta_bytes
;
8623 if (Z
- CHARPOS (tlendpos
) == ZV
)
8625 /* This line ends at end of (accessible part of)
8626 buffer. There is no newline to count. */
8628 - CHARPOS (tlendpos
)
8629 - MATRIX_ROW_START_CHARPOS (row
));
8630 delta_bytes
= (Z_BYTE
8631 - BYTEPOS (tlendpos
)
8632 - MATRIX_ROW_START_BYTEPOS (row
));
8636 /* This line ends in a newline. Must take
8637 account of the newline and the rest of the
8638 text that follows. */
8640 - CHARPOS (tlendpos
)
8641 - MATRIX_ROW_START_CHARPOS (row
));
8642 delta_bytes
= (Z_BYTE
8643 - BYTEPOS (tlendpos
)
8644 - MATRIX_ROW_START_BYTEPOS (row
));
8647 increment_matrix_positions (w
->current_matrix
,
8649 w
->current_matrix
->nrows
,
8650 delta
, delta_bytes
);
8653 /* If this row displays text now but previously didn't,
8654 or vice versa, w->window_end_vpos may have to be
8656 if ((it
.glyph_row
- 1)->displays_text_p
)
8658 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8659 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8661 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8662 && this_line_vpos
> 0)
8663 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8664 w
->window_end_valid
= Qnil
;
8666 /* Update hint: No need to try to scroll in update_window. */
8667 w
->desired_matrix
->no_scrolling_p
= 1;
8670 *w
->desired_matrix
->method
= 0;
8671 debug_method_add (w
, "optimization 1");
8678 else if (/* Cursor position hasn't changed. */
8679 PT
== XFASTINT (w
->last_point
)
8680 /* Make sure the cursor was last displayed
8681 in this window. Otherwise we have to reposition it. */
8682 && 0 <= w
->cursor
.vpos
8683 && XINT (w
->height
) > w
->cursor
.vpos
)
8687 do_pending_window_change (1);
8689 /* We used to always goto end_of_redisplay here, but this
8690 isn't enough if we have a blinking cursor. */
8691 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8692 goto end_of_redisplay
;
8696 /* If highlighting the region, or if the cursor is in the echo area,
8697 then we can't just move the cursor. */
8698 else if (! (!NILP (Vtransient_mark_mode
)
8699 && !NILP (current_buffer
->mark_active
))
8700 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8701 || highlight_nonselected_windows
)
8702 && NILP (w
->region_showing
)
8703 && NILP (Vshow_trailing_whitespace
)
8704 && !cursor_in_echo_area
)
8707 struct glyph_row
*row
;
8709 /* Skip from tlbufpos to PT and see where it is. Note that
8710 PT may be in invisible text. If so, we will end at the
8711 next visible position. */
8712 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8713 NULL
, DEFAULT_FACE_ID
);
8714 it
.current_x
= this_line_start_x
;
8715 it
.current_y
= this_line_y
;
8716 it
.vpos
= this_line_vpos
;
8718 /* The call to move_it_to stops in front of PT, but
8719 moves over before-strings. */
8720 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8722 if (it
.vpos
== this_line_vpos
8723 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8726 xassert (this_line_vpos
== it
.vpos
);
8727 xassert (this_line_y
== it
.current_y
);
8728 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8730 *w
->desired_matrix
->method
= 0;
8731 debug_method_add (w
, "optimization 3");
8740 /* Text changed drastically or point moved off of line. */
8741 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8744 CHARPOS (this_line_start_pos
) = 0;
8745 consider_all_windows_p
|= buffer_shared
> 1;
8746 ++clear_face_cache_count
;
8749 /* Build desired matrices, and update the display. If
8750 consider_all_windows_p is non-zero, do it for all windows on all
8751 frames. Otherwise do it for selected_window, only. */
8753 if (consider_all_windows_p
)
8755 Lisp_Object tail
, frame
;
8756 int i
, n
= 0, size
= 50;
8757 struct frame
**updated
8758 = (struct frame
**) alloca (size
* sizeof *updated
);
8760 /* Clear the face cache eventually. */
8761 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8763 clear_face_cache (0);
8764 clear_face_cache_count
= 0;
8767 /* Recompute # windows showing selected buffer. This will be
8768 incremented each time such a window is displayed. */
8771 FOR_EACH_FRAME (tail
, frame
)
8773 struct frame
*f
= XFRAME (frame
);
8775 if (FRAME_WINDOW_P (f
) || f
== sf
)
8777 /* Mark all the scroll bars to be removed; we'll redeem
8778 the ones we want when we redisplay their windows. */
8779 if (condemn_scroll_bars_hook
)
8780 condemn_scroll_bars_hook (f
);
8782 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8783 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8785 /* Any scroll bars which redisplay_windows should have
8786 nuked should now go away. */
8787 if (judge_scroll_bars_hook
)
8788 judge_scroll_bars_hook (f
);
8790 /* If fonts changed, display again. */
8791 if (fonts_changed_p
)
8794 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8796 /* See if we have to hscroll. */
8797 if (hscroll_windows (f
->root_window
))
8800 /* Prevent various kinds of signals during display
8801 update. stdio is not robust about handling
8802 signals, which can cause an apparent I/O
8804 if (interrupt_input
)
8808 /* Update the display. */
8809 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8810 pause
|= update_frame (f
, 0, 0);
8816 int nbytes
= size
* sizeof *updated
;
8817 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8818 bcopy (updated
, p
, nbytes
);
8827 /* Do the mark_window_display_accurate after all windows have
8828 been redisplayed because this call resets flags in buffers
8829 which are needed for proper redisplay. */
8830 for (i
= 0; i
< n
; ++i
)
8832 struct frame
*f
= updated
[i
];
8833 mark_window_display_accurate (f
->root_window
, 1);
8834 if (frame_up_to_date_hook
)
8835 frame_up_to_date_hook (f
);
8838 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8840 Lisp_Object mini_window
;
8841 struct frame
*mini_frame
;
8843 redisplay_window (selected_window
, 1);
8845 /* Compare desired and current matrices, perform output. */
8848 /* If fonts changed, display again. */
8849 if (fonts_changed_p
)
8852 /* Prevent various kinds of signals during display update.
8853 stdio is not robust about handling signals,
8854 which can cause an apparent I/O error. */
8855 if (interrupt_input
)
8859 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8861 if (hscroll_windows (selected_window
))
8864 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8865 pause
= update_frame (sf
, 0, 0);
8868 /* We may have called echo_area_display at the top of this
8869 function. If the echo area is on another frame, that may
8870 have put text on a frame other than the selected one, so the
8871 above call to update_frame would not have caught it. Catch
8873 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8874 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8876 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8878 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8879 pause
|= update_frame (mini_frame
, 0, 0);
8880 if (!pause
&& hscroll_windows (mini_window
))
8885 /* If display was paused because of pending input, make sure we do a
8886 thorough update the next time. */
8889 /* Prevent the optimization at the beginning of
8890 redisplay_internal that tries a single-line update of the
8891 line containing the cursor in the selected window. */
8892 CHARPOS (this_line_start_pos
) = 0;
8894 /* Let the overlay arrow be updated the next time. */
8895 if (!NILP (last_arrow_position
))
8897 last_arrow_position
= Qt
;
8898 last_arrow_string
= Qt
;
8901 /* If we pause after scrolling, some rows in the current
8902 matrices of some windows are not valid. */
8903 if (!WINDOW_FULL_WIDTH_P (w
)
8904 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8905 update_mode_lines
= 1;
8909 if (!consider_all_windows_p
)
8911 /* This has already been done above if
8912 consider_all_windows_p is set. */
8913 mark_window_display_accurate_1 (w
, 1);
8915 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8916 last_arrow_string
= Voverlay_arrow_string
;
8918 if (frame_up_to_date_hook
!= 0)
8919 frame_up_to_date_hook (sf
);
8922 update_mode_lines
= 0;
8923 windows_or_buffers_changed
= 0;
8926 /* Start SIGIO interrupts coming again. Having them off during the
8927 code above makes it less likely one will discard output, but not
8928 impossible, since there might be stuff in the system buffer here.
8929 But it is much hairier to try to do anything about that. */
8930 if (interrupt_input
)
8934 /* If a frame has become visible which was not before, redisplay
8935 again, so that we display it. Expose events for such a frame
8936 (which it gets when becoming visible) don't call the parts of
8937 redisplay constructing glyphs, so simply exposing a frame won't
8938 display anything in this case. So, we have to display these
8939 frames here explicitly. */
8942 Lisp_Object tail
, frame
;
8945 FOR_EACH_FRAME (tail
, frame
)
8947 int this_is_visible
= 0;
8949 if (XFRAME (frame
)->visible
)
8950 this_is_visible
= 1;
8951 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8952 if (XFRAME (frame
)->visible
)
8953 this_is_visible
= 1;
8955 if (this_is_visible
)
8959 if (new_count
!= number_of_visible_frames
)
8960 windows_or_buffers_changed
++;
8963 /* Change frame size now if a change is pending. */
8964 do_pending_window_change (1);
8966 /* If we just did a pending size change, or have additional
8967 visible frames, redisplay again. */
8968 if (windows_or_buffers_changed
&& !pause
)
8973 unbind_to (count
, Qnil
);
8977 /* Redisplay, but leave alone any recent echo area message unless
8978 another message has been requested in its place.
8980 This is useful in situations where you need to redisplay but no
8981 user action has occurred, making it inappropriate for the message
8982 area to be cleared. See tracking_off and
8983 wait_reading_process_input for examples of these situations.
8985 FROM_WHERE is an integer saying from where this function was
8986 called. This is useful for debugging. */
8989 redisplay_preserve_echo_area (from_where
)
8992 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
8994 if (!NILP (echo_area_buffer
[1]))
8996 /* We have a previously displayed message, but no current
8997 message. Redisplay the previous message. */
8998 display_last_displayed_message_p
= 1;
8999 redisplay_internal (1);
9000 display_last_displayed_message_p
= 0;
9003 redisplay_internal (1);
9007 /* Function registered with record_unwind_protect in
9008 redisplay_internal. Clears the flag indicating that a redisplay is
9012 unwind_redisplay (old_redisplaying_p
)
9013 Lisp_Object old_redisplaying_p
;
9015 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9020 /* Mark the display of window W as accurate or inaccurate. If
9021 ACCURATE_P is non-zero mark display of W as accurate. If
9022 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9023 redisplay_internal is called. */
9026 mark_window_display_accurate_1 (w
, accurate_p
)
9030 if (BUFFERP (w
->buffer
))
9032 struct buffer
*b
= XBUFFER (w
->buffer
);
9035 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9036 w
->last_overlay_modified
9037 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9039 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9043 b
->clip_changed
= 0;
9044 b
->prevent_redisplay_optimizations_p
= 0;
9046 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9047 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9048 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9049 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9051 w
->current_matrix
->buffer
= b
;
9052 w
->current_matrix
->begv
= BUF_BEGV (b
);
9053 w
->current_matrix
->zv
= BUF_ZV (b
);
9055 w
->last_cursor
= w
->cursor
;
9056 w
->last_cursor_off_p
= w
->cursor_off_p
;
9058 if (w
== XWINDOW (selected_window
))
9059 w
->last_point
= make_number (BUF_PT (b
));
9061 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9067 w
->window_end_valid
= w
->buffer
;
9068 #if 0 /* This is incorrect with variable-height lines. */
9069 xassert (XINT (w
->window_end_vpos
)
9071 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9073 w
->update_mode_line
= Qnil
;
9078 /* Mark the display of windows in the window tree rooted at WINDOW as
9079 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9080 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9081 be redisplayed the next time redisplay_internal is called. */
9084 mark_window_display_accurate (window
, accurate_p
)
9090 for (; !NILP (window
); window
= w
->next
)
9092 w
= XWINDOW (window
);
9093 mark_window_display_accurate_1 (w
, accurate_p
);
9095 if (!NILP (w
->vchild
))
9096 mark_window_display_accurate (w
->vchild
, accurate_p
);
9097 if (!NILP (w
->hchild
))
9098 mark_window_display_accurate (w
->hchild
, accurate_p
);
9103 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9104 last_arrow_string
= Voverlay_arrow_string
;
9108 /* Force a thorough redisplay the next time by setting
9109 last_arrow_position and last_arrow_string to t, which is
9110 unequal to any useful value of Voverlay_arrow_... */
9111 last_arrow_position
= Qt
;
9112 last_arrow_string
= Qt
;
9117 /* Return value in display table DP (Lisp_Char_Table *) for character
9118 C. Since a display table doesn't have any parent, we don't have to
9119 follow parent. Do not call this function directly but use the
9120 macro DISP_CHAR_VECTOR. */
9123 disp_char_vector (dp
, c
)
9124 struct Lisp_Char_Table
*dp
;
9130 if (SINGLE_BYTE_CHAR_P (c
))
9131 return (dp
->contents
[c
]);
9133 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9136 else if (code
[2] < 32)
9139 /* Here, the possible range of code[0] (== charset ID) is
9140 128..max_charset. Since the top level char table contains data
9141 for multibyte characters after 256th element, we must increment
9142 code[0] by 128 to get a correct index. */
9144 code
[3] = -1; /* anchor */
9146 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9148 val
= dp
->contents
[code
[i
]];
9149 if (!SUB_CHAR_TABLE_P (val
))
9150 return (NILP (val
) ? dp
->defalt
: val
);
9153 /* Here, val is a sub char table. We return the default value of
9155 return (dp
->defalt
);
9160 /***********************************************************************
9162 ***********************************************************************/
9164 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9167 redisplay_windows (window
)
9170 while (!NILP (window
))
9172 struct window
*w
= XWINDOW (window
);
9174 if (!NILP (w
->hchild
))
9175 redisplay_windows (w
->hchild
);
9176 else if (!NILP (w
->vchild
))
9177 redisplay_windows (w
->vchild
);
9179 redisplay_window (window
, 0);
9186 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9187 DELTA is the number of bytes by which positions recorded in ROW
9188 differ from current buffer positions. */
9191 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9193 struct glyph_row
*row
;
9194 struct glyph_matrix
*matrix
;
9195 int delta
, delta_bytes
, dy
, dvpos
;
9197 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9198 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9200 int pt_old
= PT
- delta
;
9202 /* Skip over glyphs not having an object at the start of the row.
9203 These are special glyphs like truncation marks on terminal
9205 if (row
->displays_text_p
)
9207 && INTEGERP (glyph
->object
)
9208 && glyph
->charpos
< 0)
9210 x
+= glyph
->pixel_width
;
9215 && !INTEGERP (glyph
->object
)
9216 && (!BUFFERP (glyph
->object
)
9217 || glyph
->charpos
< pt_old
))
9219 x
+= glyph
->pixel_width
;
9223 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9225 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9226 w
->cursor
.y
= row
->y
+ dy
;
9228 if (w
== XWINDOW (selected_window
))
9230 if (!row
->continued_p
9231 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9234 this_line_buffer
= XBUFFER (w
->buffer
);
9236 CHARPOS (this_line_start_pos
)
9237 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9238 BYTEPOS (this_line_start_pos
)
9239 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9241 CHARPOS (this_line_end_pos
)
9242 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9243 BYTEPOS (this_line_end_pos
)
9244 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9246 this_line_y
= w
->cursor
.y
;
9247 this_line_pixel_height
= row
->height
;
9248 this_line_vpos
= w
->cursor
.vpos
;
9249 this_line_start_x
= row
->x
;
9252 CHARPOS (this_line_start_pos
) = 0;
9257 /* Run window scroll functions, if any, for WINDOW with new window
9258 start STARTP. Sets the window start of WINDOW to that position.
9260 We assume that the window's buffer is really current. */
9262 static INLINE
struct text_pos
9263 run_window_scroll_functions (window
, startp
)
9265 struct text_pos startp
;
9267 struct window
*w
= XWINDOW (window
);
9268 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9270 if (current_buffer
!= XBUFFER (w
->buffer
))
9273 if (!NILP (Vwindow_scroll_functions
))
9275 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9276 make_number (CHARPOS (startp
)));
9277 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9278 /* In case the hook functions switch buffers. */
9279 if (current_buffer
!= XBUFFER (w
->buffer
))
9280 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9287 /* Modify the desired matrix of window W and W->vscroll so that the
9288 line containing the cursor is fully visible. */
9291 make_cursor_line_fully_visible (w
)
9294 struct glyph_matrix
*matrix
;
9295 struct glyph_row
*row
;
9298 /* It's not always possible to find the cursor, e.g, when a window
9299 is full of overlay strings. Don't do anything in that case. */
9300 if (w
->cursor
.vpos
< 0)
9303 matrix
= w
->desired_matrix
;
9304 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9306 /* If the cursor row is not partially visible, there's nothing
9308 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9311 /* If the row the cursor is in is taller than the window's height,
9312 it's not clear what to do, so do nothing. */
9313 window_height
= window_box_height (w
);
9314 if (row
->height
>= window_height
)
9317 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9319 int dy
= row
->height
- row
->visible_height
;
9322 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9324 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9326 int dy
= - (row
->height
- row
->visible_height
);
9329 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9332 /* When we change the cursor y-position of the selected window,
9333 change this_line_y as well so that the display optimization for
9334 the cursor line of the selected window in redisplay_internal uses
9335 the correct y-position. */
9336 if (w
== XWINDOW (selected_window
))
9337 this_line_y
= w
->cursor
.y
;
9341 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9342 non-zero means only WINDOW is redisplayed in redisplay_internal.
9343 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9344 in redisplay_window to bring a partially visible line into view in
9345 the case that only the cursor has moved.
9349 1 if scrolling succeeded
9351 0 if scrolling didn't find point.
9353 -1 if new fonts have been loaded so that we must interrupt
9354 redisplay, adjust glyph matrices, and try again. */
9357 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9358 scroll_step
, temp_scroll_step
)
9360 int just_this_one_p
;
9361 int scroll_conservatively
, scroll_step
;
9362 int temp_scroll_step
;
9364 struct window
*w
= XWINDOW (window
);
9365 struct frame
*f
= XFRAME (w
->frame
);
9366 struct text_pos scroll_margin_pos
;
9367 struct text_pos pos
;
9368 struct text_pos startp
;
9370 Lisp_Object window_end
;
9371 int this_scroll_margin
;
9375 int amount_to_scroll
= 0;
9376 Lisp_Object aggressive
;
9380 debug_method_add (w
, "try_scrolling");
9383 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9385 /* Compute scroll margin height in pixels. We scroll when point is
9386 within this distance from the top or bottom of the window. */
9387 if (scroll_margin
> 0)
9389 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9390 this_scroll_margin
*= CANON_Y_UNIT (f
);
9393 this_scroll_margin
= 0;
9395 /* Compute how much we should try to scroll maximally to bring point
9397 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9398 scroll_max
= max (scroll_step
,
9399 max (scroll_conservatively
, temp_scroll_step
));
9400 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9401 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9402 /* We're trying to scroll because of aggressive scrolling
9403 but no scroll_step is set. Choose an arbitrary one. Maybe
9404 there should be a variable for this. */
9408 scroll_max
*= CANON_Y_UNIT (f
);
9410 /* Decide whether we have to scroll down. Start at the window end
9411 and move this_scroll_margin up to find the position of the scroll
9413 window_end
= Fwindow_end (window
, Qt
);
9414 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9415 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9416 if (this_scroll_margin
)
9418 start_display (&it
, w
, scroll_margin_pos
);
9419 move_it_vertically (&it
, - this_scroll_margin
);
9420 scroll_margin_pos
= it
.current
.pos
;
9423 if (PT
>= CHARPOS (scroll_margin_pos
))
9427 /* Point is in the scroll margin at the bottom of the window, or
9428 below. Compute a new window start that makes point visible. */
9430 /* Compute the distance from the scroll margin to PT.
9431 Give up if the distance is greater than scroll_max. */
9432 start_display (&it
, w
, scroll_margin_pos
);
9434 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9435 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9437 /* With a scroll_margin of 0, scroll_margin_pos is at the window
9438 end, which is one line below the window. The iterator's
9439 current_y will be same as y0 in that case, but we have to
9440 scroll a line to make PT visible. That's the reason why 1 is
9442 dy
= 1 + it
.current_y
- y0
;
9444 if (dy
> scroll_max
)
9447 /* Move the window start down. If scrolling conservatively,
9448 move it just enough down to make point visible. If
9449 scroll_step is set, move it down by scroll_step. */
9450 start_display (&it
, w
, startp
);
9452 if (scroll_conservatively
)
9454 = max (max (dy
, CANON_Y_UNIT (f
)),
9455 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9456 else if (scroll_step
|| temp_scroll_step
)
9457 amount_to_scroll
= scroll_max
;
9460 aggressive
= current_buffer
->scroll_down_aggressively
;
9461 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9462 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9463 if (NUMBERP (aggressive
))
9464 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9467 if (amount_to_scroll
<= 0)
9470 move_it_vertically (&it
, amount_to_scroll
);
9471 startp
= it
.current
.pos
;
9475 /* See if point is inside the scroll margin at the top of the
9477 scroll_margin_pos
= startp
;
9478 if (this_scroll_margin
)
9480 start_display (&it
, w
, startp
);
9481 move_it_vertically (&it
, this_scroll_margin
);
9482 scroll_margin_pos
= it
.current
.pos
;
9485 if (PT
< CHARPOS (scroll_margin_pos
))
9487 /* Point is in the scroll margin at the top of the window or
9488 above what is displayed in the window. */
9491 /* Compute the vertical distance from PT to the scroll
9492 margin position. Give up if distance is greater than
9494 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9495 start_display (&it
, w
, pos
);
9497 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9498 it
.last_visible_y
, -1,
9499 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9500 dy
= it
.current_y
- y0
;
9501 if (dy
> scroll_max
)
9504 /* Compute new window start. */
9505 start_display (&it
, w
, startp
);
9507 if (scroll_conservatively
)
9509 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9510 else if (scroll_step
|| temp_scroll_step
)
9511 amount_to_scroll
= scroll_max
;
9514 aggressive
= current_buffer
->scroll_up_aggressively
;
9515 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9516 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9517 if (NUMBERP (aggressive
))
9518 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9521 if (amount_to_scroll
<= 0)
9524 move_it_vertically (&it
, - amount_to_scroll
);
9525 startp
= it
.current
.pos
;
9529 /* Run window scroll functions. */
9530 startp
= run_window_scroll_functions (window
, startp
);
9532 /* Display the window. Give up if new fonts are loaded, or if point
9534 if (!try_window (window
, startp
))
9536 else if (w
->cursor
.vpos
< 0)
9538 clear_glyph_matrix (w
->desired_matrix
);
9543 /* Maybe forget recorded base line for line number display. */
9544 if (!just_this_one_p
9545 || current_buffer
->clip_changed
9546 || BEG_UNCHANGED
< CHARPOS (startp
))
9547 w
->base_line_number
= Qnil
;
9549 /* If cursor ends up on a partially visible line, shift display
9550 lines up or down. */
9551 make_cursor_line_fully_visible (w
);
9559 /* Compute a suitable window start for window W if display of W starts
9560 on a continuation line. Value is non-zero if a new window start
9563 The new window start will be computed, based on W's width, starting
9564 from the start of the continued line. It is the start of the
9565 screen line with the minimum distance from the old start W->start. */
9568 compute_window_start_on_continuation_line (w
)
9571 struct text_pos pos
, start_pos
;
9572 int window_start_changed_p
= 0;
9574 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9576 /* If window start is on a continuation line... Window start may be
9577 < BEGV in case there's invisible text at the start of the
9578 buffer (M-x rmail, for example). */
9579 if (CHARPOS (start_pos
) > BEGV
9580 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9583 struct glyph_row
*row
;
9585 /* Handle the case that the window start is out of range. */
9586 if (CHARPOS (start_pos
) < BEGV
)
9587 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9588 else if (CHARPOS (start_pos
) > ZV
)
9589 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9591 /* Find the start of the continued line. This should be fast
9592 because scan_buffer is fast (newline cache). */
9593 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9594 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9595 row
, DEFAULT_FACE_ID
);
9596 reseat_at_previous_visible_line_start (&it
);
9598 /* If the line start is "too far" away from the window start,
9599 say it takes too much time to compute a new window start. */
9600 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9601 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9603 int min_distance
, distance
;
9605 /* Move forward by display lines to find the new window
9606 start. If window width was enlarged, the new start can
9607 be expected to be > the old start. If window width was
9608 decreased, the new window start will be < the old start.
9609 So, we're looking for the display line start with the
9610 minimum distance from the old window start. */
9611 pos
= it
.current
.pos
;
9612 min_distance
= INFINITY
;
9613 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9614 distance
< min_distance
)
9616 min_distance
= distance
;
9617 pos
= it
.current
.pos
;
9618 move_it_by_lines (&it
, 1, 0);
9621 /* Set the window start there. */
9622 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9623 window_start_changed_p
= 1;
9627 return window_start_changed_p
;
9631 /* Try cursor movement in case text has not changes in window WINDOW,
9632 with window start STARTP. Value is
9636 0 if this method cannot be used
9638 -1 if we know we have to scroll the display. *SCROLL_STEP is
9639 set to 1, under certain circumstances, if we want to scroll as
9640 if scroll-step were set to 1. See the code. */
9643 try_cursor_movement (window
, startp
, scroll_step
)
9645 struct text_pos startp
;
9648 struct window
*w
= XWINDOW (window
);
9649 struct frame
*f
= XFRAME (w
->frame
);
9652 /* Handle case where text has not changed, only point, and it has
9653 not moved off the frame. */
9654 if (/* Point may be in this window. */
9655 PT
>= CHARPOS (startp
)
9656 /* Selective display hasn't changed. */
9657 && !current_buffer
->clip_changed
9658 /* Function force-mode-line-update is used to force a thorough
9659 redisplay. It sets either windows_or_buffers_changed or
9660 update_mode_lines. So don't take a shortcut here for these
9662 && !update_mode_lines
9663 && !windows_or_buffers_changed
9664 /* Can't use this case if highlighting a region. When a
9665 region exists, cursor movement has to do more than just
9667 && !(!NILP (Vtransient_mark_mode
)
9668 && !NILP (current_buffer
->mark_active
))
9669 && NILP (w
->region_showing
)
9670 && NILP (Vshow_trailing_whitespace
)
9671 /* Right after splitting windows, last_point may be nil. */
9672 && INTEGERP (w
->last_point
)
9673 /* This code is not used for mini-buffer for the sake of the case
9674 of redisplaying to replace an echo area message; since in
9675 that case the mini-buffer contents per se are usually
9676 unchanged. This code is of no real use in the mini-buffer
9677 since the handling of this_line_start_pos, etc., in redisplay
9678 handles the same cases. */
9679 && !EQ (window
, minibuf_window
)
9680 /* When splitting windows or for new windows, it happens that
9681 redisplay is called with a nil window_end_vpos or one being
9682 larger than the window. This should really be fixed in
9683 window.c. I don't have this on my list, now, so we do
9684 approximately the same as the old redisplay code. --gerd. */
9685 && INTEGERP (w
->window_end_vpos
)
9686 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9687 && (FRAME_WINDOW_P (f
)
9688 || !MARKERP (Voverlay_arrow_position
)
9689 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9691 int this_scroll_margin
;
9692 struct glyph_row
*row
= NULL
;
9695 debug_method_add (w
, "cursor movement");
9698 /* Scroll if point within this distance from the top or bottom
9699 of the window. This is a pixel value. */
9700 this_scroll_margin
= max (0, scroll_margin
);
9701 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9702 this_scroll_margin
*= CANON_Y_UNIT (f
);
9704 /* Start with the row the cursor was displayed during the last
9705 not paused redisplay. Give up if that row is not valid. */
9706 if (w
->last_cursor
.vpos
< 0
9707 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9711 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9712 if (row
->mode_line_p
)
9714 if (!row
->enabled_p
)
9721 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9723 if (PT
> XFASTINT (w
->last_point
))
9725 /* Point has moved forward. */
9726 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9727 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9729 xassert (row
->enabled_p
);
9733 /* The end position of a row equals the start position
9734 of the next row. If PT is there, we would rather
9735 display it in the next line. */
9736 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9737 && MATRIX_ROW_END_CHARPOS (row
) == PT
9738 && !cursor_row_p (w
, row
))
9741 /* If within the scroll margin, scroll. Note that
9742 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9743 the next line would be drawn, and that
9744 this_scroll_margin can be zero. */
9745 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9746 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9747 /* Line is completely visible last line in window
9748 and PT is to be set in the next line. */
9749 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9750 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9751 && !row
->ends_at_zv_p
9752 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9755 else if (PT
< XFASTINT (w
->last_point
))
9757 /* Cursor has to be moved backward. Note that PT >=
9758 CHARPOS (startp) because of the outer
9760 while (!row
->mode_line_p
9761 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9762 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9763 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9764 && (row
->y
> this_scroll_margin
9765 || CHARPOS (startp
) == BEGV
))
9767 xassert (row
->enabled_p
);
9771 /* Consider the following case: Window starts at BEGV,
9772 there is invisible, intangible text at BEGV, so that
9773 display starts at some point START > BEGV. It can
9774 happen that we are called with PT somewhere between
9775 BEGV and START. Try to handle that case. */
9776 if (row
< w
->current_matrix
->rows
9777 || row
->mode_line_p
)
9779 row
= w
->current_matrix
->rows
;
9780 if (row
->mode_line_p
)
9784 /* Due to newlines in overlay strings, we may have to
9785 skip forward over overlay strings. */
9786 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9787 && MATRIX_ROW_END_CHARPOS (row
) == PT
9788 && !cursor_row_p (w
, row
))
9791 /* If within the scroll margin, scroll. */
9792 if (row
->y
< this_scroll_margin
9793 && CHARPOS (startp
) != BEGV
)
9797 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9798 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9800 /* if PT is not in the glyph row, give up. */
9803 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9805 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
9806 && !row
->ends_at_zv_p
9807 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
9809 else if (row
->height
> window_box_height (w
))
9811 /* If we end up in a partially visible line, let's
9812 make it fully visible, except when it's taller
9813 than the window, in which case we can't do much
9820 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9821 try_window (window
, startp
);
9822 make_cursor_line_fully_visible (w
);
9830 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9840 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9841 selected_window is redisplayed. */
9844 redisplay_window (window
, just_this_one_p
)
9846 int just_this_one_p
;
9848 struct window
*w
= XWINDOW (window
);
9849 struct frame
*f
= XFRAME (w
->frame
);
9850 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9851 struct buffer
*old
= current_buffer
;
9852 struct text_pos lpoint
, opoint
, startp
;
9853 int update_mode_line
;
9856 /* Record it now because it's overwritten. */
9857 int current_matrix_up_to_date_p
= 0;
9858 int temp_scroll_step
= 0;
9859 int count
= BINDING_STACK_SIZE ();
9862 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9865 /* W must be a leaf window here. */
9866 xassert (!NILP (w
->buffer
));
9868 *w
->desired_matrix
->method
= 0;
9871 specbind (Qinhibit_point_motion_hooks
, Qt
);
9873 reconsider_clip_changes (w
, buffer
);
9875 /* Has the mode line to be updated? */
9876 update_mode_line
= (!NILP (w
->update_mode_line
)
9877 || update_mode_lines
9878 || buffer
->clip_changed
);
9880 if (MINI_WINDOW_P (w
))
9882 if (w
== XWINDOW (echo_area_window
)
9883 && !NILP (echo_area_buffer
[0]))
9885 if (update_mode_line
)
9886 /* We may have to update a tty frame's menu bar or a
9887 tool-bar. Example `M-x C-h C-h C-g'. */
9888 goto finish_menu_bars
;
9890 /* We've already displayed the echo area glyphs in this window. */
9891 goto finish_scroll_bars
;
9893 else if (w
!= XWINDOW (minibuf_window
))
9895 /* W is a mini-buffer window, but it's not the currently
9896 active one, so clear it. */
9897 int yb
= window_text_bottom_y (w
);
9898 struct glyph_row
*row
;
9901 for (y
= 0, row
= w
->desired_matrix
->rows
;
9903 y
+= row
->height
, ++row
)
9904 blank_row (w
, row
, y
);
9905 goto finish_scroll_bars
;
9908 clear_glyph_matrix (w
->desired_matrix
);
9911 /* Otherwise set up data on this window; select its buffer and point
9913 /* Really select the buffer, for the sake of buffer-local
9915 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9916 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9918 current_matrix_up_to_date_p
9919 = (!NILP (w
->window_end_valid
)
9920 && !current_buffer
->clip_changed
9921 && XFASTINT (w
->last_modified
) >= MODIFF
9922 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9924 /* When windows_or_buffers_changed is non-zero, we can't rely on
9925 the window end being valid, so set it to nil there. */
9926 if (windows_or_buffers_changed
)
9928 /* If window starts on a continuation line, maybe adjust the
9929 window start in case the window's width changed. */
9930 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9931 compute_window_start_on_continuation_line (w
);
9933 w
->window_end_valid
= Qnil
;
9936 /* Some sanity checks. */
9937 CHECK_WINDOW_END (w
);
9938 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9940 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9943 /* If %c is in mode line, update it if needed. */
9944 if (!NILP (w
->column_number_displayed
)
9945 /* This alternative quickly identifies a common case
9946 where no change is needed. */
9947 && !(PT
== XFASTINT (w
->last_point
)
9948 && XFASTINT (w
->last_modified
) >= MODIFF
9949 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9950 && XFASTINT (w
->column_number_displayed
) != current_column ())
9951 update_mode_line
= 1;
9953 /* Count number of windows showing the selected buffer. An indirect
9954 buffer counts as its base buffer. */
9955 if (!just_this_one_p
)
9957 struct buffer
*current_base
, *window_base
;
9958 current_base
= current_buffer
;
9959 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9960 if (current_base
->base_buffer
)
9961 current_base
= current_base
->base_buffer
;
9962 if (window_base
->base_buffer
)
9963 window_base
= window_base
->base_buffer
;
9964 if (current_base
== window_base
)
9968 /* Point refers normally to the selected window. For any other
9969 window, set up appropriate value. */
9970 if (!EQ (window
, selected_window
))
9972 int new_pt
= XMARKER (w
->pointm
)->charpos
;
9973 int new_pt_byte
= marker_byte_position (w
->pointm
);
9977 new_pt_byte
= BEGV_BYTE
;
9978 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
9980 else if (new_pt
> (ZV
- 1))
9983 new_pt_byte
= ZV_BYTE
;
9984 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
9987 /* We don't use SET_PT so that the point-motion hooks don't run. */
9988 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
9991 /* If any of the character widths specified in the display table
9992 have changed, invalidate the width run cache. It's true that
9993 this may be a bit late to catch such changes, but the rest of
9994 redisplay goes (non-fatally) haywire when the display table is
9995 changed, so why should we worry about doing any better? */
9996 if (current_buffer
->width_run_cache
)
9998 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10000 if (! disptab_matches_widthtab (disptab
,
10001 XVECTOR (current_buffer
->width_table
)))
10003 invalidate_region_cache (current_buffer
,
10004 current_buffer
->width_run_cache
,
10006 recompute_width_table (current_buffer
, disptab
);
10010 /* If window-start is screwed up, choose a new one. */
10011 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10014 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10016 /* If someone specified a new starting point but did not insist,
10017 check whether it can be used. */
10018 if (!NILP (w
->optional_new_start
)
10019 && CHARPOS (startp
) >= BEGV
10020 && CHARPOS (startp
) <= ZV
)
10022 w
->optional_new_start
= Qnil
;
10023 start_display (&it
, w
, startp
);
10024 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10025 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10026 if (IT_CHARPOS (it
) == PT
)
10027 w
->force_start
= Qt
;
10030 /* Handle case where place to start displaying has been specified,
10031 unless the specified location is outside the accessible range. */
10032 if (!NILP (w
->force_start
)
10033 || w
->frozen_window_start_p
)
10035 w
->force_start
= Qnil
;
10037 w
->window_end_valid
= Qnil
;
10039 /* Forget any recorded base line for line number display. */
10040 if (!current_matrix_up_to_date_p
10041 || current_buffer
->clip_changed
)
10042 w
->base_line_number
= Qnil
;
10044 /* Redisplay the mode line. Select the buffer properly for that.
10045 Also, run the hook window-scroll-functions
10046 because we have scrolled. */
10047 /* Note, we do this after clearing force_start because
10048 if there's an error, it is better to forget about force_start
10049 than to get into an infinite loop calling the hook functions
10050 and having them get more errors. */
10051 if (!update_mode_line
10052 || ! NILP (Vwindow_scroll_functions
))
10054 update_mode_line
= 1;
10055 w
->update_mode_line
= Qt
;
10056 startp
= run_window_scroll_functions (window
, startp
);
10059 w
->last_modified
= make_number (0);
10060 w
->last_overlay_modified
= make_number (0);
10061 if (CHARPOS (startp
) < BEGV
)
10062 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10063 else if (CHARPOS (startp
) > ZV
)
10064 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10066 /* Redisplay, then check if cursor has been set during the
10067 redisplay. Give up if new fonts were loaded. */
10068 if (!try_window (window
, startp
))
10070 w
->force_start
= Qt
;
10071 clear_glyph_matrix (w
->desired_matrix
);
10072 goto finish_scroll_bars
;
10075 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10077 /* If point does not appear, try to move point so it does
10078 appear. The desired matrix has been built above, so we
10079 can use it here. */
10081 struct glyph_row
*row
;
10083 window_height
= window_box_height (w
) / 2;
10084 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10085 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
10088 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10089 MATRIX_ROW_START_BYTEPOS (row
));
10091 if (w
!= XWINDOW (selected_window
))
10092 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10093 else if (current_buffer
== old
)
10094 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10096 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10098 /* If we are highlighting the region, then we just changed
10099 the region, so redisplay to show it. */
10100 if (!NILP (Vtransient_mark_mode
)
10101 && !NILP (current_buffer
->mark_active
))
10103 clear_glyph_matrix (w
->desired_matrix
);
10104 if (!try_window (window
, startp
))
10105 goto finish_scroll_bars
;
10109 make_cursor_line_fully_visible (w
);
10111 debug_method_add (w
, "forced window start");
10116 /* Handle case where text has not changed, only point, and it has
10117 not moved off the frame. */
10118 if (current_matrix_up_to_date_p
10119 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10123 goto try_to_scroll
;
10127 /* If current starting point was originally the beginning of a line
10128 but no longer is, find a new starting point. */
10129 else if (!NILP (w
->start_at_line_beg
)
10130 && !(CHARPOS (startp
) <= BEGV
10131 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10134 debug_method_add (w
, "recenter 1");
10139 /* Try scrolling with try_window_id. Value is > 0 if update has
10140 been done, it is -1 if we know that the same window start will
10141 not work. It is 0 if unsuccessful for some other reason. */
10142 else if ((tem
= try_window_id (w
)) != 0)
10145 debug_method_add (w
, "try_window_id %d", tem
);
10148 if (fonts_changed_p
)
10149 goto finish_scroll_bars
;
10153 /* Otherwise try_window_id has returned -1 which means that we
10154 don't want the alternative below this comment to execute. */
10156 else if (CHARPOS (startp
) >= BEGV
10157 && CHARPOS (startp
) <= ZV
10158 && PT
>= CHARPOS (startp
)
10159 && (CHARPOS (startp
) < ZV
10160 /* Avoid starting at end of buffer. */
10161 || CHARPOS (startp
) == BEGV
10162 || (XFASTINT (w
->last_modified
) >= MODIFF
10163 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10166 debug_method_add (w
, "same window start");
10169 /* Try to redisplay starting at same place as before.
10170 If point has not moved off frame, accept the results. */
10171 if (!current_matrix_up_to_date_p
10172 /* Don't use try_window_reusing_current_matrix in this case
10173 because a window scroll function can have changed the
10175 || !NILP (Vwindow_scroll_functions
)
10176 || MINI_WINDOW_P (w
)
10177 || !try_window_reusing_current_matrix (w
))
10179 IF_DEBUG (debug_method_add (w
, "1"));
10180 try_window (window
, startp
);
10183 if (fonts_changed_p
)
10184 goto finish_scroll_bars
;
10186 if (w
->cursor
.vpos
>= 0)
10188 if (!just_this_one_p
10189 || current_buffer
->clip_changed
10190 || BEG_UNCHANGED
< CHARPOS (startp
))
10191 /* Forget any recorded base line for line number display. */
10192 w
->base_line_number
= Qnil
;
10194 make_cursor_line_fully_visible (w
);
10198 clear_glyph_matrix (w
->desired_matrix
);
10203 w
->last_modified
= make_number (0);
10204 w
->last_overlay_modified
= make_number (0);
10206 /* Redisplay the mode line. Select the buffer properly for that. */
10207 if (!update_mode_line
)
10209 update_mode_line
= 1;
10210 w
->update_mode_line
= Qt
;
10213 /* Try to scroll by specified few lines. */
10214 if ((scroll_conservatively
10216 || temp_scroll_step
10217 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10218 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10219 && !current_buffer
->clip_changed
10220 && CHARPOS (startp
) >= BEGV
10221 && CHARPOS (startp
) <= ZV
)
10223 /* The function returns -1 if new fonts were loaded, 1 if
10224 successful, 0 if not successful. */
10225 int rc
= try_scrolling (window
, just_this_one_p
,
10226 scroll_conservatively
,
10232 goto finish_scroll_bars
;
10235 /* Finally, just choose place to start which centers point */
10240 debug_method_add (w
, "recenter");
10243 /* w->vscroll = 0; */
10245 /* Forget any previously recorded base line for line number display. */
10246 if (!current_matrix_up_to_date_p
10247 || current_buffer
->clip_changed
)
10248 w
->base_line_number
= Qnil
;
10250 /* Move backward half the height of the window. */
10251 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10252 it
.current_y
= it
.last_visible_y
;
10253 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
10254 xassert (IT_CHARPOS (it
) >= BEGV
);
10256 /* The function move_it_vertically_backward may move over more
10257 than the specified y-distance. If it->w is small, e.g. a
10258 mini-buffer window, we may end up in front of the window's
10259 display area. Start displaying at the start of the line
10260 containing PT in this case. */
10261 if (it
.current_y
<= 0)
10263 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10264 move_it_vertically (&it
, 0);
10265 xassert (IT_CHARPOS (it
) <= PT
);
10269 it
.current_x
= it
.hpos
= 0;
10271 /* Set startp here explicitly in case that helps avoid an infinite loop
10272 in case the window-scroll-functions functions get errors. */
10273 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10275 /* Run scroll hooks. */
10276 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10278 /* Redisplay the window. */
10279 if (!current_matrix_up_to_date_p
10280 || windows_or_buffers_changed
10281 /* Don't use try_window_reusing_current_matrix in this case
10282 because it can have changed the buffer. */
10283 || !NILP (Vwindow_scroll_functions
)
10284 || !just_this_one_p
10285 || MINI_WINDOW_P (w
)
10286 || !try_window_reusing_current_matrix (w
))
10287 try_window (window
, startp
);
10289 /* If new fonts have been loaded (due to fontsets), give up. We
10290 have to start a new redisplay since we need to re-adjust glyph
10292 if (fonts_changed_p
)
10293 goto finish_scroll_bars
;
10295 /* If cursor did not appear assume that the middle of the window is
10296 in the first line of the window. Do it again with the next line.
10297 (Imagine a window of height 100, displaying two lines of height
10298 60. Moving back 50 from it->last_visible_y will end in the first
10300 if (w
->cursor
.vpos
< 0)
10302 if (!NILP (w
->window_end_valid
)
10303 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10305 clear_glyph_matrix (w
->desired_matrix
);
10306 move_it_by_lines (&it
, 1, 0);
10307 try_window (window
, it
.current
.pos
);
10309 else if (PT
< IT_CHARPOS (it
))
10311 clear_glyph_matrix (w
->desired_matrix
);
10312 move_it_by_lines (&it
, -1, 0);
10313 try_window (window
, it
.current
.pos
);
10317 /* Not much we can do about it. */
10321 /* Consider the following case: Window starts at BEGV, there is
10322 invisible, intangible text at BEGV, so that display starts at
10323 some point START > BEGV. It can happen that we are called with
10324 PT somewhere between BEGV and START. Try to handle that case. */
10325 if (w
->cursor
.vpos
< 0)
10327 struct glyph_row
*row
= w
->current_matrix
->rows
;
10328 if (row
->mode_line_p
)
10330 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10333 make_cursor_line_fully_visible (w
);
10337 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10338 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10339 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10342 /* Display the mode line, if we must. */
10343 if ((update_mode_line
10344 /* If window not full width, must redo its mode line
10345 if (a) the window to its side is being redone and
10346 (b) we do a frame-based redisplay. This is a consequence
10347 of how inverted lines are drawn in frame-based redisplay. */
10348 || (!just_this_one_p
10349 && !FRAME_WINDOW_P (f
)
10350 && !WINDOW_FULL_WIDTH_P (w
))
10351 /* Line number to display. */
10352 || INTEGERP (w
->base_line_pos
)
10353 /* Column number is displayed and different from the one displayed. */
10354 || (!NILP (w
->column_number_displayed
)
10355 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10356 /* This means that the window has a mode line. */
10357 && (WINDOW_WANTS_MODELINE_P (w
)
10358 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10360 Lisp_Object old_selected_frame
;
10362 old_selected_frame
= selected_frame
;
10364 XSETFRAME (selected_frame
, f
);
10365 display_mode_lines (w
);
10366 selected_frame
= old_selected_frame
;
10368 /* If mode line height has changed, arrange for a thorough
10369 immediate redisplay using the correct mode line height. */
10370 if (WINDOW_WANTS_MODELINE_P (w
)
10371 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10373 fonts_changed_p
= 1;
10374 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10375 = DESIRED_MODE_LINE_HEIGHT (w
);
10378 /* If top line height has changed, arrange for a thorough
10379 immediate redisplay using the correct mode line height. */
10380 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10381 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10383 fonts_changed_p
= 1;
10384 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10385 = DESIRED_HEADER_LINE_HEIGHT (w
);
10388 if (fonts_changed_p
)
10389 goto finish_scroll_bars
;
10392 if (!line_number_displayed
10393 && !BUFFERP (w
->base_line_pos
))
10395 w
->base_line_pos
= Qnil
;
10396 w
->base_line_number
= Qnil
;
10401 /* When we reach a frame's selected window, redo the frame's menu bar. */
10402 if (update_mode_line
10403 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10405 int redisplay_menu_p
= 0;
10407 if (FRAME_WINDOW_P (f
))
10409 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10410 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10412 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10416 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10418 if (redisplay_menu_p
)
10419 display_menu_bar (w
);
10421 #ifdef HAVE_WINDOW_SYSTEM
10422 if (WINDOWP (f
->tool_bar_window
)
10423 && (FRAME_TOOL_BAR_LINES (f
) > 0
10424 || auto_resize_tool_bars_p
))
10425 redisplay_tool_bar (f
);
10429 finish_scroll_bars
:
10431 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10433 int start
, end
, whole
;
10435 /* Calculate the start and end positions for the current window.
10436 At some point, it would be nice to choose between scrollbars
10437 which reflect the whole buffer size, with special markers
10438 indicating narrowing, and scrollbars which reflect only the
10441 Note that mini-buffers sometimes aren't displaying any text. */
10442 if (!MINI_WINDOW_P (w
)
10443 || (w
== XWINDOW (minibuf_window
)
10444 && NILP (echo_area_buffer
[0])))
10447 start
= marker_position (w
->start
) - BEGV
;
10448 /* I don't think this is guaranteed to be right. For the
10449 moment, we'll pretend it is. */
10450 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10454 if (whole
< (end
- start
))
10455 whole
= end
- start
;
10458 start
= end
= whole
= 0;
10460 /* Indicate what this scroll bar ought to be displaying now. */
10461 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10463 /* Note that we actually used the scroll bar attached to this
10464 window, so it shouldn't be deleted at the end of redisplay. */
10465 redeem_scroll_bar_hook (w
);
10468 /* Restore current_buffer and value of point in it. */
10469 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10470 set_buffer_internal_1 (old
);
10471 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10473 unbind_to (count
, Qnil
);
10477 /* Build the complete desired matrix of WINDOW with a window start
10478 buffer position POS. Value is non-zero if successful. It is zero
10479 if fonts were loaded during redisplay which makes re-adjusting
10480 glyph matrices necessary. */
10483 try_window (window
, pos
)
10484 Lisp_Object window
;
10485 struct text_pos pos
;
10487 struct window
*w
= XWINDOW (window
);
10489 struct glyph_row
*last_text_row
= NULL
;
10491 /* Make POS the new window start. */
10492 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10494 /* Mark cursor position as unknown. No overlay arrow seen. */
10495 w
->cursor
.vpos
= -1;
10496 overlay_arrow_seen
= 0;
10498 /* Initialize iterator and info to start at POS. */
10499 start_display (&it
, w
, pos
);
10501 /* Display all lines of W. */
10502 while (it
.current_y
< it
.last_visible_y
)
10504 if (display_line (&it
))
10505 last_text_row
= it
.glyph_row
- 1;
10506 if (fonts_changed_p
)
10510 /* If bottom moved off end of frame, change mode line percentage. */
10511 if (XFASTINT (w
->window_end_pos
) <= 0
10512 && Z
!= IT_CHARPOS (it
))
10513 w
->update_mode_line
= Qt
;
10515 /* Set window_end_pos to the offset of the last character displayed
10516 on the window from the end of current_buffer. Set
10517 window_end_vpos to its row number. */
10520 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10521 w
->window_end_bytepos
10522 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10524 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10526 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10527 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10528 ->displays_text_p
);
10532 w
->window_end_bytepos
= 0;
10533 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10536 /* But that is not valid info until redisplay finishes. */
10537 w
->window_end_valid
= Qnil
;
10543 /************************************************************************
10544 Window redisplay reusing current matrix when buffer has not changed
10545 ************************************************************************/
10547 /* Try redisplay of window W showing an unchanged buffer with a
10548 different window start than the last time it was displayed by
10549 reusing its current matrix. Value is non-zero if successful.
10550 W->start is the new window start. */
10553 try_window_reusing_current_matrix (w
)
10556 struct frame
*f
= XFRAME (w
->frame
);
10557 struct glyph_row
*row
, *bottom_row
;
10560 struct text_pos start
, new_start
;
10561 int nrows_scrolled
, i
;
10562 struct glyph_row
*last_text_row
;
10563 struct glyph_row
*last_reused_text_row
;
10564 struct glyph_row
*start_row
;
10565 int start_vpos
, min_y
, max_y
;
10567 if (/* This function doesn't handle terminal frames. */
10568 !FRAME_WINDOW_P (f
)
10569 /* Don't try to reuse the display if windows have been split
10571 || windows_or_buffers_changed
)
10574 /* Can't do this if region may have changed. */
10575 if ((!NILP (Vtransient_mark_mode
)
10576 && !NILP (current_buffer
->mark_active
))
10577 || !NILP (w
->region_showing
)
10578 || !NILP (Vshow_trailing_whitespace
))
10581 /* If top-line visibility has changed, give up. */
10582 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10583 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10586 /* Give up if old or new display is scrolled vertically. We could
10587 make this function handle this, but right now it doesn't. */
10588 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10589 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10592 /* The variable new_start now holds the new window start. The old
10593 start `start' can be determined from the current matrix. */
10594 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10595 start
= start_row
->start
.pos
;
10596 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10598 /* Clear the desired matrix for the display below. */
10599 clear_glyph_matrix (w
->desired_matrix
);
10601 if (CHARPOS (new_start
) <= CHARPOS (start
))
10605 /* Don't use this method if the display starts with an ellipsis
10606 displayed for invisible text. It's not easy to handle that case
10607 below, and it's certainly not worth the effort since this is
10608 not a frequent case. */
10609 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10612 IF_DEBUG (debug_method_add (w
, "twu1"));
10614 /* Display up to a row that can be reused. The variable
10615 last_text_row is set to the last row displayed that displays
10616 text. Note that it.vpos == 0 if or if not there is a
10617 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10618 start_display (&it
, w
, new_start
);
10619 first_row_y
= it
.current_y
;
10620 w
->cursor
.vpos
= -1;
10621 last_text_row
= last_reused_text_row
= NULL
;
10623 while (it
.current_y
< it
.last_visible_y
10624 && IT_CHARPOS (it
) < CHARPOS (start
)
10625 && !fonts_changed_p
)
10626 if (display_line (&it
))
10627 last_text_row
= it
.glyph_row
- 1;
10629 /* A value of current_y < last_visible_y means that we stopped
10630 at the previous window start, which in turn means that we
10631 have at least one reusable row. */
10632 if (it
.current_y
< it
.last_visible_y
)
10634 /* IT.vpos always starts from 0; it counts text lines. */
10635 nrows_scrolled
= it
.vpos
;
10637 /* Find PT if not already found in the lines displayed. */
10638 if (w
->cursor
.vpos
< 0)
10640 int dy
= it
.current_y
- first_row_y
;
10642 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10643 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10645 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
10646 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10648 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10649 dy
, nrows_scrolled
);
10653 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
10659 /* Give up if point was not found. This shouldn't
10660 happen often; not more often than with try_window
10662 if (w
->cursor
.vpos
< 0)
10664 clear_glyph_matrix (w
->desired_matrix
);
10669 /* Scroll the display. Do it before the current matrix is
10670 changed. The problem here is that update has not yet
10671 run, i.e. part of the current matrix is not up to date.
10672 scroll_run_hook will clear the cursor, and use the
10673 current matrix to get the height of the row the cursor is
10675 run
.current_y
= first_row_y
;
10676 run
.desired_y
= it
.current_y
;
10677 run
.height
= it
.last_visible_y
- it
.current_y
;
10679 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10682 rif
->update_window_begin_hook (w
);
10683 rif
->clear_mouse_face (w
);
10684 rif
->scroll_run_hook (w
, &run
);
10685 rif
->update_window_end_hook (w
, 0, 0);
10689 /* Shift current matrix down by nrows_scrolled lines. */
10690 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10691 rotate_matrix (w
->current_matrix
,
10693 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10696 /* Disable lines that must be updated. */
10697 for (i
= 0; i
< it
.vpos
; ++i
)
10698 (start_row
+ i
)->enabled_p
= 0;
10700 /* Re-compute Y positions. */
10701 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10702 max_y
= it
.last_visible_y
;
10703 for (row
= start_row
+ nrows_scrolled
;
10707 row
->y
= it
.current_y
;
10708 row
->visible_height
= row
->height
;
10710 if (row
->y
< min_y
)
10711 row
->visible_height
-= min_y
- row
->y
;
10712 if (row
->y
+ row
->height
> max_y
)
10713 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10715 it
.current_y
+= row
->height
;
10717 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10718 last_reused_text_row
= row
;
10719 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10723 /* Disable lines in the current matrix which are now
10724 below the window. */
10725 for (++row
; row
< bottom_row
; ++row
)
10726 row
->enabled_p
= 0;
10729 /* Update window_end_pos etc.; last_reused_text_row is the last
10730 reused row from the current matrix containing text, if any.
10731 The value of last_text_row is the last displayed line
10732 containing text. */
10733 if (last_reused_text_row
)
10735 w
->window_end_bytepos
10736 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10738 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10740 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10741 w
->current_matrix
));
10743 else if (last_text_row
)
10745 w
->window_end_bytepos
10746 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10748 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10750 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10754 /* This window must be completely empty. */
10755 w
->window_end_bytepos
= 0;
10756 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10758 w
->window_end_valid
= Qnil
;
10760 /* Update hint: don't try scrolling again in update_window. */
10761 w
->desired_matrix
->no_scrolling_p
= 1;
10764 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10768 else if (CHARPOS (new_start
) > CHARPOS (start
))
10770 struct glyph_row
*pt_row
, *row
;
10771 struct glyph_row
*first_reusable_row
;
10772 struct glyph_row
*first_row_to_display
;
10774 int yb
= window_text_bottom_y (w
);
10776 /* Find the row starting at new_start, if there is one. Don't
10777 reuse a partially visible line at the end. */
10778 first_reusable_row
= start_row
;
10779 while (first_reusable_row
->enabled_p
10780 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10781 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10782 < CHARPOS (new_start
)))
10783 ++first_reusable_row
;
10785 /* Give up if there is no row to reuse. */
10786 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10787 || !first_reusable_row
->enabled_p
10788 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10789 != CHARPOS (new_start
)))
10792 /* We can reuse fully visible rows beginning with
10793 first_reusable_row to the end of the window. Set
10794 first_row_to_display to the first row that cannot be reused.
10795 Set pt_row to the row containing point, if there is any. */
10797 for (first_row_to_display
= first_reusable_row
;
10798 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
10799 ++first_row_to_display
)
10801 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10802 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10803 pt_row
= first_row_to_display
;
10806 /* Start displaying at the start of first_row_to_display. */
10807 xassert (first_row_to_display
->y
< yb
);
10808 init_to_row_start (&it
, w
, first_row_to_display
);
10810 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10812 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10814 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10815 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10817 /* Display lines beginning with first_row_to_display in the
10818 desired matrix. Set last_text_row to the last row displayed
10819 that displays text. */
10820 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10821 if (pt_row
== NULL
)
10822 w
->cursor
.vpos
= -1;
10823 last_text_row
= NULL
;
10824 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10825 if (display_line (&it
))
10826 last_text_row
= it
.glyph_row
- 1;
10828 /* Give up If point isn't in a row displayed or reused. */
10829 if (w
->cursor
.vpos
< 0)
10831 clear_glyph_matrix (w
->desired_matrix
);
10835 /* If point is in a reused row, adjust y and vpos of the cursor
10839 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10840 w
->current_matrix
);
10841 w
->cursor
.y
-= first_reusable_row
->y
;
10844 /* Scroll the display. */
10845 run
.current_y
= first_reusable_row
->y
;
10846 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10847 run
.height
= it
.last_visible_y
- run
.current_y
;
10848 dy
= run
.current_y
- run
.desired_y
;
10852 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10854 rif
->update_window_begin_hook (w
);
10855 rif
->clear_mouse_face (w
);
10856 rif
->scroll_run_hook (w
, &run
);
10857 rif
->update_window_end_hook (w
, 0, 0);
10861 /* Adjust Y positions of reused rows. */
10862 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10863 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10864 max_y
= it
.last_visible_y
;
10865 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10868 row
->visible_height
= row
->height
;
10869 if (row
->y
< min_y
)
10870 row
->visible_height
-= min_y
- row
->y
;
10871 if (row
->y
+ row
->height
> max_y
)
10872 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10875 /* Scroll the current matrix. */
10876 xassert (nrows_scrolled
> 0);
10877 rotate_matrix (w
->current_matrix
,
10879 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10882 /* Disable rows not reused. */
10883 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
10884 row
->enabled_p
= 0;
10886 /* Adjust window end. A null value of last_text_row means that
10887 the window end is in reused rows which in turn means that
10888 only its vpos can have changed. */
10891 w
->window_end_bytepos
10892 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10894 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10896 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10901 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10904 w
->window_end_valid
= Qnil
;
10905 w
->desired_matrix
->no_scrolling_p
= 1;
10908 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10918 /************************************************************************
10919 Window redisplay reusing current matrix when buffer has changed
10920 ************************************************************************/
10922 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10923 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10925 static struct glyph_row
*
10926 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10927 struct glyph_row
*));
10930 /* Return the last row in MATRIX displaying text. If row START is
10931 non-null, start searching with that row. IT gives the dimensions
10932 of the display. Value is null if matrix is empty; otherwise it is
10933 a pointer to the row found. */
10935 static struct glyph_row
*
10936 find_last_row_displaying_text (matrix
, it
, start
)
10937 struct glyph_matrix
*matrix
;
10939 struct glyph_row
*start
;
10941 struct glyph_row
*row
, *row_found
;
10943 /* Set row_found to the last row in IT->w's current matrix
10944 displaying text. The loop looks funny but think of partially
10947 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
10948 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10950 xassert (row
->enabled_p
);
10952 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
10961 /* Return the last row in the current matrix of W that is not affected
10962 by changes at the start of current_buffer that occurred since W's
10963 current matrix was built. Value is null if no such row exists.
10965 BEG_UNCHANGED us the number of characters unchanged at the start of
10966 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
10967 first changed character in current_buffer. Characters at positions <
10968 BEG + BEG_UNCHANGED are at the same buffer positions as they were
10969 when the current matrix was built. */
10971 static struct glyph_row
*
10972 find_last_unchanged_at_beg_row (w
)
10975 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
10976 struct glyph_row
*row
;
10977 struct glyph_row
*row_found
= NULL
;
10978 int yb
= window_text_bottom_y (w
);
10980 /* Find the last row displaying unchanged text. */
10981 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10982 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
10983 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
10985 if (/* If row ends before first_changed_pos, it is unchanged,
10986 except in some case. */
10987 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
10988 /* When row ends in ZV and we write at ZV it is not
10990 && !row
->ends_at_zv_p
10991 /* When first_changed_pos is the end of a continued line,
10992 row is not unchanged because it may be no longer
10994 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
10995 && row
->continued_p
))
10998 /* Stop if last visible row. */
10999 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11009 /* Find the first glyph row in the current matrix of W that is not
11010 affected by changes at the end of current_buffer since the
11011 time W's current matrix was built.
11013 Return in *DELTA the number of chars by which buffer positions in
11014 unchanged text at the end of current_buffer must be adjusted.
11016 Return in *DELTA_BYTES the corresponding number of bytes.
11018 Value is null if no such row exists, i.e. all rows are affected by
11021 static struct glyph_row
*
11022 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11024 int *delta
, *delta_bytes
;
11026 struct glyph_row
*row
;
11027 struct glyph_row
*row_found
= NULL
;
11029 *delta
= *delta_bytes
= 0;
11031 /* Display must not have been paused, otherwise the current matrix
11032 is not up to date. */
11033 if (NILP (w
->window_end_valid
))
11036 /* A value of window_end_pos >= END_UNCHANGED means that the window
11037 end is in the range of changed text. If so, there is no
11038 unchanged row at the end of W's current matrix. */
11039 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11042 /* Set row to the last row in W's current matrix displaying text. */
11043 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11045 /* If matrix is entirely empty, no unchanged row exists. */
11046 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11048 /* The value of row is the last glyph row in the matrix having a
11049 meaningful buffer position in it. The end position of row
11050 corresponds to window_end_pos. This allows us to translate
11051 buffer positions in the current matrix to current buffer
11052 positions for characters not in changed text. */
11053 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11054 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11055 int last_unchanged_pos
, last_unchanged_pos_old
;
11056 struct glyph_row
*first_text_row
11057 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11059 *delta
= Z
- Z_old
;
11060 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11062 /* Set last_unchanged_pos to the buffer position of the last
11063 character in the buffer that has not been changed. Z is the
11064 index + 1 of the last character in current_buffer, i.e. by
11065 subtracting END_UNCHANGED we get the index of the last
11066 unchanged character, and we have to add BEG to get its buffer
11068 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11069 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11071 /* Search backward from ROW for a row displaying a line that
11072 starts at a minimum position >= last_unchanged_pos_old. */
11073 for (; row
> first_text_row
; --row
)
11075 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11078 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11083 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11090 /* Make sure that glyph rows in the current matrix of window W
11091 reference the same glyph memory as corresponding rows in the
11092 frame's frame matrix. This function is called after scrolling W's
11093 current matrix on a terminal frame in try_window_id and
11094 try_window_reusing_current_matrix. */
11097 sync_frame_with_window_matrix_rows (w
)
11100 struct frame
*f
= XFRAME (w
->frame
);
11101 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11103 /* Preconditions: W must be a leaf window and full-width. Its frame
11104 must have a frame matrix. */
11105 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11106 xassert (WINDOW_FULL_WIDTH_P (w
));
11107 xassert (!FRAME_WINDOW_P (f
));
11109 /* If W is a full-width window, glyph pointers in W's current matrix
11110 have, by definition, to be the same as glyph pointers in the
11111 corresponding frame matrix. */
11112 window_row
= w
->current_matrix
->rows
;
11113 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11114 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11115 while (window_row
< window_row_end
)
11119 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
11120 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
11122 /* Disable frame rows whose corresponding window rows have
11123 been disabled in try_window_id. */
11124 if (!window_row
->enabled_p
)
11125 frame_row
->enabled_p
= 0;
11127 ++window_row
, ++frame_row
;
11132 /* Find the glyph row in window W containing CHARPOS. Consider all
11133 rows between START and END (not inclusive). END null means search
11134 all rows to the end of the display area of W. Value is the row
11135 containing CHARPOS or null. */
11137 static struct glyph_row
*
11138 row_containing_pos (w
, charpos
, start
, end
)
11141 struct glyph_row
*start
, *end
;
11143 struct glyph_row
*row
= start
;
11146 /* If we happen to start on a header-line, skip that. */
11147 if (row
->mode_line_p
)
11150 if ((end
&& row
>= end
) || !row
->enabled_p
)
11153 last_y
= window_text_bottom_y (w
);
11155 while ((end
== NULL
|| row
< end
)
11156 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11157 /* The end position of a row equals the start
11158 position of the next row. If CHARPOS is there, we
11159 would rather display it in the next line, except
11160 when this line ends in ZV. */
11161 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11162 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11163 || !row
->ends_at_zv_p
)))
11164 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11167 /* Give up if CHARPOS not found. */
11168 if ((end
&& row
>= end
)
11169 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11170 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11177 /* Try to redisplay window W by reusing its existing display. W's
11178 current matrix must be up to date when this function is called,
11179 i.e. window_end_valid must not be nil.
11183 1 if display has been updated
11184 0 if otherwise unsuccessful
11185 -1 if redisplay with same window start is known not to succeed
11187 The following steps are performed:
11189 1. Find the last row in the current matrix of W that is not
11190 affected by changes at the start of current_buffer. If no such row
11193 2. Find the first row in W's current matrix that is not affected by
11194 changes at the end of current_buffer. Maybe there is no such row.
11196 3. Display lines beginning with the row + 1 found in step 1 to the
11197 row found in step 2 or, if step 2 didn't find a row, to the end of
11200 4. If cursor is not known to appear on the window, give up.
11202 5. If display stopped at the row found in step 2, scroll the
11203 display and current matrix as needed.
11205 6. Maybe display some lines at the end of W, if we must. This can
11206 happen under various circumstances, like a partially visible line
11207 becoming fully visible, or because newly displayed lines are displayed
11208 in smaller font sizes.
11210 7. Update W's window end information. */
11216 struct frame
*f
= XFRAME (w
->frame
);
11217 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11218 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11219 struct glyph_row
*last_unchanged_at_beg_row
;
11220 struct glyph_row
*first_unchanged_at_end_row
;
11221 struct glyph_row
*row
;
11222 struct glyph_row
*bottom_row
;
11225 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11226 struct text_pos start_pos
;
11228 int first_unchanged_at_end_vpos
= 0;
11229 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11230 struct text_pos start
;
11231 int first_changed_charpos
, last_changed_charpos
;
11233 /* This is handy for debugging. */
11235 #define GIVE_UP(X) \
11237 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11241 #define GIVE_UP(X) return 0
11244 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11246 /* Don't use this for mini-windows because these can show
11247 messages and mini-buffers, and we don't handle that here. */
11248 if (MINI_WINDOW_P (w
))
11251 /* This flag is used to prevent redisplay optimizations. */
11252 if (windows_or_buffers_changed
)
11255 /* Verify that narrowing has not changed. This flag is also set to prevent
11256 redisplay optimizations. It would be nice to further
11257 reduce the number of cases where this prevents try_window_id. */
11258 if (current_buffer
->clip_changed
)
11261 /* Window must either use window-based redisplay or be full width. */
11262 if (!FRAME_WINDOW_P (f
)
11263 && (!line_ins_del_ok
11264 || !WINDOW_FULL_WIDTH_P (w
)))
11267 /* Give up if point is not known NOT to appear in W. */
11268 if (PT
< CHARPOS (start
))
11271 /* Another way to prevent redisplay optimizations. */
11272 if (XFASTINT (w
->last_modified
) == 0)
11275 /* Verify that window is not hscrolled. */
11276 if (XFASTINT (w
->hscroll
) != 0)
11279 /* Verify that display wasn't paused. */
11280 if (NILP (w
->window_end_valid
))
11283 /* Can't use this if highlighting a region because a cursor movement
11284 will do more than just set the cursor. */
11285 if (!NILP (Vtransient_mark_mode
)
11286 && !NILP (current_buffer
->mark_active
))
11289 /* Likewise if highlighting trailing whitespace. */
11290 if (!NILP (Vshow_trailing_whitespace
))
11293 /* Likewise if showing a region. */
11294 if (!NILP (w
->region_showing
))
11297 /* Can use this if overlay arrow position and or string have changed. */
11298 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11299 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11303 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11304 only if buffer has really changed. The reason is that the gap is
11305 initially at Z for freshly visited files. The code below would
11306 set end_unchanged to 0 in that case. */
11307 if (MODIFF
> SAVE_MODIFF
11308 /* This seems to happen sometimes after saving a buffer. */
11309 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11311 if (GPT
- BEG
< BEG_UNCHANGED
)
11312 BEG_UNCHANGED
= GPT
- BEG
;
11313 if (Z
- GPT
< END_UNCHANGED
)
11314 END_UNCHANGED
= Z
- GPT
;
11317 /* The position of the first and last character that has been changed. */
11318 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11319 last_changed_charpos
= Z
- END_UNCHANGED
;
11321 /* If window starts after a line end, and the last change is in
11322 front of that newline, then changes don't affect the display.
11323 This case happens with stealth-fontification. Note that although
11324 the display is unchanged, glyph positions in the matrix have to
11325 be adjusted, of course. */
11326 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11327 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11328 && ((last_changed_charpos
< CHARPOS (start
)
11329 && CHARPOS (start
) == BEGV
)
11330 || (last_changed_charpos
< CHARPOS (start
) - 1
11331 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11333 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11334 struct glyph_row
*r0
;
11336 /* Compute how many chars/bytes have been added to or removed
11337 from the buffer. */
11338 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11339 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11341 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11343 /* Give up if PT is not in the window. Note that it already has
11344 been checked at the start of try_window_id that PT is not in
11345 front of the window start. */
11346 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11349 /* If window start is unchanged, we can reuse the whole matrix
11350 as is, after adjusting glyph positions. No need to compute
11351 the window end again, since its offset from Z hasn't changed. */
11352 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11353 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11354 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11356 /* Adjust positions in the glyph matrix. */
11357 if (delta
|| delta_bytes
)
11359 struct glyph_row
*r1
11360 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11361 increment_matrix_positions (w
->current_matrix
,
11362 MATRIX_ROW_VPOS (r0
, current_matrix
),
11363 MATRIX_ROW_VPOS (r1
, current_matrix
),
11364 delta
, delta_bytes
);
11367 /* Set the cursor. */
11368 row
= row_containing_pos (w
, PT
, r0
, NULL
);
11369 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11374 /* Handle the case that changes are all below what is displayed in
11375 the window, and that PT is in the window. This shortcut cannot
11376 be taken if ZV is visible in the window, and text has been added
11377 there that is visible in the window. */
11378 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11379 /* ZV is not visible in the window, or there are no
11380 changes at ZV, actually. */
11381 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11382 || first_changed_charpos
== last_changed_charpos
))
11384 struct glyph_row
*r0
;
11386 /* Give up if PT is not in the window. Note that it already has
11387 been checked at the start of try_window_id that PT is not in
11388 front of the window start. */
11389 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11392 /* If window start is unchanged, we can reuse the whole matrix
11393 as is, without changing glyph positions since no text has
11394 been added/removed in front of the window end. */
11395 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11396 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11398 /* We have to compute the window end anew since text
11399 can have been added/removed after it. */
11401 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11402 w
->window_end_bytepos
11403 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11405 /* Set the cursor. */
11406 row
= row_containing_pos (w
, PT
, r0
, NULL
);
11407 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11412 /* Give up if window start is in the changed area.
11414 The condition used to read
11416 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11418 but why that was tested escapes me at the moment. */
11419 if (CHARPOS (start
) >= first_changed_charpos
11420 && CHARPOS (start
) <= last_changed_charpos
)
11423 /* Check that window start agrees with the start of the first glyph
11424 row in its current matrix. Check this after we know the window
11425 start is not in changed text, otherwise positions would not be
11427 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11428 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11431 /* Compute the position at which we have to start displaying new
11432 lines. Some of the lines at the top of the window might be
11433 reusable because they are not displaying changed text. Find the
11434 last row in W's current matrix not affected by changes at the
11435 start of current_buffer. Value is null if changes start in the
11436 first line of window. */
11437 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11438 if (last_unchanged_at_beg_row
)
11440 /* Avoid starting to display in the moddle of a character, a TAB
11441 for instance. This is easier than to set up the iterator
11442 exactly, and it's not a frequent case, so the additional
11443 effort wouldn't really pay off. */
11444 while (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11445 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11446 --last_unchanged_at_beg_row
;
11448 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11451 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11453 start_pos
= it
.current
.pos
;
11455 /* Start displaying new lines in the desired matrix at the same
11456 vpos we would use in the current matrix, i.e. below
11457 last_unchanged_at_beg_row. */
11458 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11460 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11461 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11463 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11467 /* There are no reusable lines at the start of the window.
11468 Start displaying in the first line. */
11469 start_display (&it
, w
, start
);
11470 start_pos
= it
.current
.pos
;
11473 /* Find the first row that is not affected by changes at the end of
11474 the buffer. Value will be null if there is no unchanged row, in
11475 which case we must redisplay to the end of the window. delta
11476 will be set to the value by which buffer positions beginning with
11477 first_unchanged_at_end_row have to be adjusted due to text
11479 first_unchanged_at_end_row
11480 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11481 IF_DEBUG (debug_delta
= delta
);
11482 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11484 /* Set stop_pos to the buffer position up to which we will have to
11485 display new lines. If first_unchanged_at_end_row != NULL, this
11486 is the buffer position of the start of the line displayed in that
11487 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11488 that we don't stop at a buffer position. */
11490 if (first_unchanged_at_end_row
)
11492 xassert (last_unchanged_at_beg_row
== NULL
11493 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11495 /* If this is a continuation line, move forward to the next one
11496 that isn't. Changes in lines above affect this line.
11497 Caution: this may move first_unchanged_at_end_row to a row
11498 not displaying text. */
11499 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11500 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11501 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11502 < it
.last_visible_y
))
11503 ++first_unchanged_at_end_row
;
11505 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11506 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11507 >= it
.last_visible_y
))
11508 first_unchanged_at_end_row
= NULL
;
11511 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11513 first_unchanged_at_end_vpos
11514 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11515 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11518 else if (last_unchanged_at_beg_row
== NULL
)
11524 /* Either there is no unchanged row at the end, or the one we have
11525 now displays text. This is a necessary condition for the window
11526 end pos calculation at the end of this function. */
11527 xassert (first_unchanged_at_end_row
== NULL
11528 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11530 debug_last_unchanged_at_beg_vpos
11531 = (last_unchanged_at_beg_row
11532 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11534 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11536 #endif /* GLYPH_DEBUG != 0 */
11539 /* Display new lines. Set last_text_row to the last new line
11540 displayed which has text on it, i.e. might end up as being the
11541 line where the window_end_vpos is. */
11542 w
->cursor
.vpos
= -1;
11543 last_text_row
= NULL
;
11544 overlay_arrow_seen
= 0;
11545 while (it
.current_y
< it
.last_visible_y
11546 && !fonts_changed_p
11547 && (first_unchanged_at_end_row
== NULL
11548 || IT_CHARPOS (it
) < stop_pos
))
11550 if (display_line (&it
))
11551 last_text_row
= it
.glyph_row
- 1;
11554 if (fonts_changed_p
)
11558 /* Compute differences in buffer positions, y-positions etc. for
11559 lines reused at the bottom of the window. Compute what we can
11561 if (first_unchanged_at_end_row
11562 /* No lines reused because we displayed everything up to the
11563 bottom of the window. */
11564 && it
.current_y
< it
.last_visible_y
)
11567 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11569 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11570 run
.current_y
= first_unchanged_at_end_row
->y
;
11571 run
.desired_y
= run
.current_y
+ dy
;
11572 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11576 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11577 first_unchanged_at_end_row
= NULL
;
11579 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11582 /* Find the cursor if not already found. We have to decide whether
11583 PT will appear on this window (it sometimes doesn't, but this is
11584 not a very frequent case.) This decision has to be made before
11585 the current matrix is altered. A value of cursor.vpos < 0 means
11586 that PT is either in one of the lines beginning at
11587 first_unchanged_at_end_row or below the window. Don't care for
11588 lines that might be displayed later at the window end; as
11589 mentioned, this is not a frequent case. */
11590 if (w
->cursor
.vpos
< 0)
11592 /* Cursor in unchanged rows at the top? */
11593 if (PT
< CHARPOS (start_pos
)
11594 && last_unchanged_at_beg_row
)
11596 row
= row_containing_pos (w
, PT
,
11597 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11598 last_unchanged_at_beg_row
+ 1);
11600 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11603 /* Start from first_unchanged_at_end_row looking for PT. */
11604 else if (first_unchanged_at_end_row
)
11606 row
= row_containing_pos (w
, PT
- delta
,
11607 first_unchanged_at_end_row
, NULL
);
11609 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11610 delta_bytes
, dy
, dvpos
);
11613 /* Give up if cursor was not found. */
11614 if (w
->cursor
.vpos
< 0)
11616 clear_glyph_matrix (w
->desired_matrix
);
11621 /* Don't let the cursor end in the scroll margins. */
11623 int this_scroll_margin
, cursor_height
;
11625 this_scroll_margin
= max (0, scroll_margin
);
11626 this_scroll_margin
= min (this_scroll_margin
,
11627 XFASTINT (w
->height
) / 4);
11628 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11629 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11631 if ((w
->cursor
.y
< this_scroll_margin
11632 && CHARPOS (start
) > BEGV
)
11633 /* Don't take scroll margin into account at the bottom because
11634 old redisplay didn't do it either. */
11635 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11637 w
->cursor
.vpos
= -1;
11638 clear_glyph_matrix (w
->desired_matrix
);
11643 /* Scroll the display. Do it before changing the current matrix so
11644 that xterm.c doesn't get confused about where the cursor glyph is
11646 if (dy
&& run
.height
)
11650 if (FRAME_WINDOW_P (f
))
11652 rif
->update_window_begin_hook (w
);
11653 rif
->clear_mouse_face (w
);
11654 rif
->scroll_run_hook (w
, &run
);
11655 rif
->update_window_end_hook (w
, 0, 0);
11659 /* Terminal frame. In this case, dvpos gives the number of
11660 lines to scroll by; dvpos < 0 means scroll up. */
11661 int first_unchanged_at_end_vpos
11662 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11663 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11664 int end
= (XFASTINT (w
->top
)
11665 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
11666 + window_internal_height (w
));
11668 /* Perform the operation on the screen. */
11671 /* Scroll last_unchanged_at_beg_row to the end of the
11672 window down dvpos lines. */
11673 set_terminal_window (end
);
11675 /* On dumb terminals delete dvpos lines at the end
11676 before inserting dvpos empty lines. */
11677 if (!scroll_region_ok
)
11678 ins_del_lines (end
- dvpos
, -dvpos
);
11680 /* Insert dvpos empty lines in front of
11681 last_unchanged_at_beg_row. */
11682 ins_del_lines (from
, dvpos
);
11684 else if (dvpos
< 0)
11686 /* Scroll up last_unchanged_at_beg_vpos to the end of
11687 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11688 set_terminal_window (end
);
11690 /* Delete dvpos lines in front of
11691 last_unchanged_at_beg_vpos. ins_del_lines will set
11692 the cursor to the given vpos and emit |dvpos| delete
11694 ins_del_lines (from
+ dvpos
, dvpos
);
11696 /* On a dumb terminal insert dvpos empty lines at the
11698 if (!scroll_region_ok
)
11699 ins_del_lines (end
+ dvpos
, -dvpos
);
11702 set_terminal_window (0);
11708 /* Shift reused rows of the current matrix to the right position.
11709 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11711 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11712 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11715 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11716 bottom_vpos
, dvpos
);
11717 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11720 else if (dvpos
> 0)
11722 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11723 bottom_vpos
, dvpos
);
11724 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11725 first_unchanged_at_end_vpos
+ dvpos
, 0);
11728 /* For frame-based redisplay, make sure that current frame and window
11729 matrix are in sync with respect to glyph memory. */
11730 if (!FRAME_WINDOW_P (f
))
11731 sync_frame_with_window_matrix_rows (w
);
11733 /* Adjust buffer positions in reused rows. */
11735 increment_matrix_positions (current_matrix
,
11736 first_unchanged_at_end_vpos
+ dvpos
,
11737 bottom_vpos
, delta
, delta_bytes
);
11739 /* Adjust Y positions. */
11741 shift_glyph_matrix (w
, current_matrix
,
11742 first_unchanged_at_end_vpos
+ dvpos
,
11745 if (first_unchanged_at_end_row
)
11746 first_unchanged_at_end_row
+= dvpos
;
11748 /* If scrolling up, there may be some lines to display at the end of
11750 last_text_row_at_end
= NULL
;
11753 /* Set last_row to the glyph row in the current matrix where the
11754 window end line is found. It has been moved up or down in
11755 the matrix by dvpos. */
11756 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11757 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11759 /* If last_row is the window end line, it should display text. */
11760 xassert (last_row
->displays_text_p
);
11762 /* If window end line was partially visible before, begin
11763 displaying at that line. Otherwise begin displaying with the
11764 line following it. */
11765 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11767 init_to_row_start (&it
, w
, last_row
);
11768 it
.vpos
= last_vpos
;
11769 it
.current_y
= last_row
->y
;
11773 init_to_row_end (&it
, w
, last_row
);
11774 it
.vpos
= 1 + last_vpos
;
11775 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11779 /* We may start in a continuation line. If so, we have to get
11780 the right continuation_lines_width and current_x. */
11781 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11782 it
.hpos
= it
.current_x
= 0;
11784 /* Display the rest of the lines at the window end. */
11785 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11786 while (it
.current_y
< it
.last_visible_y
11787 && !fonts_changed_p
)
11789 /* Is it always sure that the display agrees with lines in
11790 the current matrix? I don't think so, so we mark rows
11791 displayed invalid in the current matrix by setting their
11792 enabled_p flag to zero. */
11793 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11794 if (display_line (&it
))
11795 last_text_row_at_end
= it
.glyph_row
- 1;
11799 /* Update window_end_pos and window_end_vpos. */
11800 if (first_unchanged_at_end_row
11801 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11802 && !last_text_row_at_end
)
11804 /* Window end line if one of the preserved rows from the current
11805 matrix. Set row to the last row displaying text in current
11806 matrix starting at first_unchanged_at_end_row, after
11808 xassert (first_unchanged_at_end_row
->displays_text_p
);
11809 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11810 first_unchanged_at_end_row
);
11811 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11813 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11814 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11816 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11817 xassert (w
->window_end_bytepos
>= 0);
11818 IF_DEBUG (debug_method_add (w
, "A"));
11820 else if (last_text_row_at_end
)
11823 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11824 w
->window_end_bytepos
11825 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11827 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11828 xassert (w
->window_end_bytepos
>= 0);
11829 IF_DEBUG (debug_method_add (w
, "B"));
11831 else if (last_text_row
)
11833 /* We have displayed either to the end of the window or at the
11834 end of the window, i.e. the last row with text is to be found
11835 in the desired matrix. */
11837 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11838 w
->window_end_bytepos
11839 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11841 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11842 xassert (w
->window_end_bytepos
>= 0);
11844 else if (first_unchanged_at_end_row
== NULL
11845 && last_text_row
== NULL
11846 && last_text_row_at_end
== NULL
)
11848 /* Displayed to end of window, but no line containing text was
11849 displayed. Lines were deleted at the end of the window. */
11850 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11851 int vpos
= XFASTINT (w
->window_end_vpos
);
11852 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
11853 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
11856 row
== NULL
&& vpos
>= first_vpos
;
11857 --vpos
, --current_row
, --desired_row
)
11859 if (desired_row
->enabled_p
)
11861 if (desired_row
->displays_text_p
)
11864 else if (current_row
->displays_text_p
)
11868 xassert (row
!= NULL
);
11869 w
->window_end_vpos
= make_number (vpos
+ 1);
11870 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11871 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11872 xassert (w
->window_end_bytepos
>= 0);
11873 IF_DEBUG (debug_method_add (w
, "C"));
11878 #if 0 /* This leads to problems, for instance when the cursor is
11879 at ZV, and the cursor line displays no text. */
11880 /* Disable rows below what's displayed in the window. This makes
11881 debugging easier. */
11882 enable_glyph_matrix_rows (current_matrix
,
11883 XFASTINT (w
->window_end_vpos
) + 1,
11887 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11888 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11890 /* Record that display has not been completed. */
11891 w
->window_end_valid
= Qnil
;
11892 w
->desired_matrix
->no_scrolling_p
= 1;
11900 /***********************************************************************
11901 More debugging support
11902 ***********************************************************************/
11906 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
11907 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11908 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
11911 /* Dump the contents of glyph matrix MATRIX on stderr.
11913 GLYPHS 0 means don't show glyph contents.
11914 GLYPHS 1 means show glyphs in short form
11915 GLYPHS > 1 means show glyphs in long form. */
11918 dump_glyph_matrix (matrix
, glyphs
)
11919 struct glyph_matrix
*matrix
;
11923 for (i
= 0; i
< matrix
->nrows
; ++i
)
11924 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
11928 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
11929 the glyph row and area where the glyph comes from. */
11932 dump_glyph (row
, glyph
, area
)
11933 struct glyph_row
*row
;
11934 struct glyph
*glyph
;
11937 if (glyph
->type
== CHAR_GLYPH
)
11940 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11941 glyph
- row
->glyphs
[TEXT_AREA
],
11944 (BUFFERP (glyph
->object
)
11946 : (STRINGP (glyph
->object
)
11949 glyph
->pixel_width
,
11951 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
11955 glyph
->left_box_line_p
,
11956 glyph
->right_box_line_p
);
11958 else if (glyph
->type
== STRETCH_GLYPH
)
11961 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11962 glyph
- row
->glyphs
[TEXT_AREA
],
11965 (BUFFERP (glyph
->object
)
11967 : (STRINGP (glyph
->object
)
11970 glyph
->pixel_width
,
11974 glyph
->left_box_line_p
,
11975 glyph
->right_box_line_p
);
11977 else if (glyph
->type
== IMAGE_GLYPH
)
11980 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11981 glyph
- row
->glyphs
[TEXT_AREA
],
11984 (BUFFERP (glyph
->object
)
11986 : (STRINGP (glyph
->object
)
11989 glyph
->pixel_width
,
11993 glyph
->left_box_line_p
,
11994 glyph
->right_box_line_p
);
11999 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12000 GLYPHS 0 means don't show glyph contents.
12001 GLYPHS 1 means show glyphs in short form
12002 GLYPHS > 1 means show glyphs in long form. */
12005 dump_glyph_row (row
, vpos
, glyphs
)
12006 struct glyph_row
*row
;
12011 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12012 fprintf (stderr
, "=======================================================================\n");
12014 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d\
12015 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12017 MATRIX_ROW_START_CHARPOS (row
),
12018 MATRIX_ROW_END_CHARPOS (row
),
12019 row
->used
[TEXT_AREA
],
12020 row
->contains_overlapping_glyphs_p
,
12023 row
->truncated_on_left_p
,
12024 row
->truncated_on_right_p
,
12025 row
->overlay_arrow_p
,
12027 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12028 row
->displays_text_p
,
12031 row
->ends_in_middle_of_char_p
,
12032 row
->starts_in_middle_of_char_p
,
12038 row
->visible_height
,
12041 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12042 row
->end
.overlay_string_index
,
12043 row
->continuation_lines_width
);
12044 fprintf (stderr
, "%9d %5d\n",
12045 CHARPOS (row
->start
.string_pos
),
12046 CHARPOS (row
->end
.string_pos
));
12047 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12048 row
->end
.dpvec_index
);
12055 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12057 struct glyph
*glyph
= row
->glyphs
[area
];
12058 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12060 /* Glyph for a line end in text. */
12061 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12064 if (glyph
< glyph_end
)
12065 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12067 for (; glyph
< glyph_end
; ++glyph
)
12068 dump_glyph (row
, glyph
, area
);
12071 else if (glyphs
== 1)
12075 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12077 char *s
= (char *) alloca (row
->used
[area
] + 1);
12080 for (i
= 0; i
< row
->used
[area
]; ++i
)
12082 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12083 if (glyph
->type
== CHAR_GLYPH
12084 && glyph
->u
.ch
< 0x80
12085 && glyph
->u
.ch
>= ' ')
12086 s
[i
] = glyph
->u
.ch
;
12092 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12098 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12099 Sdump_glyph_matrix
, 0, 1, "p",
12100 "Dump the current matrix of the selected window to stderr.\n\
12101 Shows contents of glyph row structures. With non-nil\n\
12102 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show\n\
12103 glyphs in short form, otherwise show glyphs in long form.")
12105 Lisp_Object glyphs
;
12107 struct window
*w
= XWINDOW (selected_window
);
12108 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12110 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12111 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12112 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12113 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12114 fprintf (stderr
, "=============================================\n");
12115 dump_glyph_matrix (w
->current_matrix
,
12116 NILP (glyphs
) ? 0 : XINT (glyphs
));
12121 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12122 "Dump glyph row ROW to stderr.\n\
12123 GLYPH 0 means don't dump glyphs.\n\
12124 GLYPH 1 means dump glyphs in short form.\n\
12125 GLYPH > 1 or omitted means dump glyphs in long form.")
12127 Lisp_Object row
, glyphs
;
12129 struct glyph_matrix
*matrix
;
12132 CHECK_NUMBER (row
, 0);
12133 matrix
= XWINDOW (selected_window
)->current_matrix
;
12135 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12136 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12138 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12143 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12144 "Dump glyph row ROW of the tool-bar of the current frame to stderr.\n\
12145 GLYPH 0 means don't dump glyphs.\n\
12146 GLYPH 1 means dump glyphs in short form.\n\
12147 GLYPH > 1 or omitted means dump glyphs in long form.")
12149 Lisp_Object row
, glyphs
;
12151 struct frame
*sf
= SELECTED_FRAME ();
12152 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12155 CHECK_NUMBER (row
, 0);
12157 if (vpos
>= 0 && vpos
< m
->nrows
)
12158 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12159 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12164 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12165 "Toggle tracing of redisplay.\n\
12166 With ARG, turn tracing on if and only if ARG is positive.")
12171 trace_redisplay_p
= !trace_redisplay_p
;
12174 arg
= Fprefix_numeric_value (arg
);
12175 trace_redisplay_p
= XINT (arg
) > 0;
12182 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12183 "Like `format', but print result to stderr.")
12188 Lisp_Object s
= Fformat (nargs
, args
);
12189 fprintf (stderr
, "%s", XSTRING (s
)->data
);
12193 #endif /* GLYPH_DEBUG */
12197 /***********************************************************************
12198 Building Desired Matrix Rows
12199 ***********************************************************************/
12201 /* Return a temporary glyph row holding the glyphs of an overlay
12202 arrow. Only used for non-window-redisplay windows. */
12204 static struct glyph_row
*
12205 get_overlay_arrow_glyph_row (w
)
12208 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12209 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12210 struct buffer
*old
= current_buffer
;
12211 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
12212 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
12213 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12217 int n_glyphs_before
;
12219 set_buffer_temp (buffer
);
12220 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12221 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12222 SET_TEXT_POS (it
.position
, 0, 0);
12224 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12226 while (p
< arrow_end
)
12228 Lisp_Object face
, ilisp
;
12230 /* Get the next character. */
12232 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12234 it
.c
= *p
, it
.len
= 1;
12237 /* Get its face. */
12238 ilisp
= make_number (p
- arrow_string
);
12239 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12240 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12242 /* Compute its width, get its glyphs. */
12243 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12244 SET_TEXT_POS (it
.position
, -1, -1);
12245 PRODUCE_GLYPHS (&it
);
12247 /* If this character doesn't fit any more in the line, we have
12248 to remove some glyphs. */
12249 if (it
.current_x
> it
.last_visible_x
)
12251 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12256 set_buffer_temp (old
);
12257 return it
.glyph_row
;
12261 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12262 glyphs are only inserted for terminal frames since we can't really
12263 win with truncation glyphs when partially visible glyphs are
12264 involved. Which glyphs to insert is determined by
12265 produce_special_glyphs. */
12268 insert_left_trunc_glyphs (it
)
12271 struct it truncate_it
;
12272 struct glyph
*from
, *end
, *to
, *toend
;
12274 xassert (!FRAME_WINDOW_P (it
->f
));
12276 /* Get the truncation glyphs. */
12278 truncate_it
.current_x
= 0;
12279 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12280 truncate_it
.glyph_row
= &scratch_glyph_row
;
12281 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12282 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12283 truncate_it
.object
= make_number (0);
12284 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12286 /* Overwrite glyphs from IT with truncation glyphs. */
12287 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12288 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12289 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12290 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12295 /* There may be padding glyphs left over. Overwrite them too. */
12296 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12298 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12304 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12308 /* Compute the pixel height and width of IT->glyph_row.
12310 Most of the time, ascent and height of a display line will be equal
12311 to the max_ascent and max_height values of the display iterator
12312 structure. This is not the case if
12314 1. We hit ZV without displaying anything. In this case, max_ascent
12315 and max_height will be zero.
12317 2. We have some glyphs that don't contribute to the line height.
12318 (The glyph row flag contributes_to_line_height_p is for future
12319 pixmap extensions).
12321 The first case is easily covered by using default values because in
12322 these cases, the line height does not really matter, except that it
12323 must not be zero. */
12326 compute_line_metrics (it
)
12329 struct glyph_row
*row
= it
->glyph_row
;
12332 if (FRAME_WINDOW_P (it
->f
))
12334 int i
, min_y
, max_y
;
12336 /* The line may consist of one space only, that was added to
12337 place the cursor on it. If so, the row's height hasn't been
12339 if (row
->height
== 0)
12341 if (it
->max_ascent
+ it
->max_descent
== 0)
12342 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12343 row
->ascent
= it
->max_ascent
;
12344 row
->height
= it
->max_ascent
+ it
->max_descent
;
12345 row
->phys_ascent
= it
->max_phys_ascent
;
12346 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12349 /* Compute the width of this line. */
12350 row
->pixel_width
= row
->x
;
12351 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12352 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12354 xassert (row
->pixel_width
>= 0);
12355 xassert (row
->ascent
>= 0 && row
->height
> 0);
12357 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12358 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12360 /* If first line's physical ascent is larger than its logical
12361 ascent, use the physical ascent, and make the row taller.
12362 This makes accented characters fully visible. */
12363 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12364 && row
->phys_ascent
> row
->ascent
)
12366 row
->height
+= row
->phys_ascent
- row
->ascent
;
12367 row
->ascent
= row
->phys_ascent
;
12370 /* Compute how much of the line is visible. */
12371 row
->visible_height
= row
->height
;
12373 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12374 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12376 if (row
->y
< min_y
)
12377 row
->visible_height
-= min_y
- row
->y
;
12378 if (row
->y
+ row
->height
> max_y
)
12379 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12383 row
->pixel_width
= row
->used
[TEXT_AREA
];
12384 if (row
->continued_p
)
12385 row
->pixel_width
-= it
->continuation_pixel_width
;
12386 else if (row
->truncated_on_right_p
)
12387 row
->pixel_width
-= it
->truncation_pixel_width
;
12388 row
->ascent
= row
->phys_ascent
= 0;
12389 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12392 /* Compute a hash code for this row. */
12394 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12395 for (i
= 0; i
< row
->used
[area
]; ++i
)
12396 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12397 + row
->glyphs
[area
][i
].u
.val
12398 + row
->glyphs
[area
][i
].face_id
12399 + row
->glyphs
[area
][i
].padding_p
12400 + (row
->glyphs
[area
][i
].type
<< 2));
12402 it
->max_ascent
= it
->max_descent
= 0;
12403 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12407 /* Append one space to the glyph row of iterator IT if doing a
12408 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12409 space have the default face, otherwise let it have the same face as
12410 IT->face_id. Value is non-zero if a space was added.
12412 This function is called to make sure that there is always one glyph
12413 at the end of a glyph row that the cursor can be set on under
12414 window-systems. (If there weren't such a glyph we would not know
12415 how wide and tall a box cursor should be displayed).
12417 At the same time this space let's a nicely handle clearing to the
12418 end of the line if the row ends in italic text. */
12421 append_space (it
, default_face_p
)
12423 int default_face_p
;
12425 if (FRAME_WINDOW_P (it
->f
))
12427 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12429 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12430 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12432 /* Save some values that must not be changed.
12433 Must save IT->c and IT->len because otherwise
12434 ITERATOR_AT_END_P wouldn't work anymore after
12435 append_space has been called. */
12436 enum display_element_type saved_what
= it
->what
;
12437 int saved_c
= it
->c
, saved_len
= it
->len
;
12438 int saved_x
= it
->current_x
;
12439 int saved_face_id
= it
->face_id
;
12440 struct text_pos saved_pos
;
12441 Lisp_Object saved_object
;
12444 saved_object
= it
->object
;
12445 saved_pos
= it
->position
;
12447 it
->what
= IT_CHARACTER
;
12448 bzero (&it
->position
, sizeof it
->position
);
12449 it
->object
= make_number (0);
12453 if (default_face_p
)
12454 it
->face_id
= DEFAULT_FACE_ID
;
12455 else if (it
->face_before_selective_p
)
12456 it
->face_id
= it
->saved_face_id
;
12457 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12458 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12460 PRODUCE_GLYPHS (it
);
12462 it
->current_x
= saved_x
;
12463 it
->object
= saved_object
;
12464 it
->position
= saved_pos
;
12465 it
->what
= saved_what
;
12466 it
->face_id
= saved_face_id
;
12467 it
->len
= saved_len
;
12477 /* Extend the face of the last glyph in the text area of IT->glyph_row
12478 to the end of the display line. Called from display_line.
12479 If the glyph row is empty, add a space glyph to it so that we
12480 know the face to draw. Set the glyph row flag fill_line_p. */
12483 extend_face_to_end_of_line (it
)
12487 struct frame
*f
= it
->f
;
12489 /* If line is already filled, do nothing. */
12490 if (it
->current_x
>= it
->last_visible_x
)
12493 /* Face extension extends the background and box of IT->face_id
12494 to the end of the line. If the background equals the background
12495 of the frame, we don't have to do anything. */
12496 if (it
->face_before_selective_p
)
12497 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12499 face
= FACE_FROM_ID (f
, it
->face_id
);
12501 if (FRAME_WINDOW_P (f
)
12502 && face
->box
== FACE_NO_BOX
12503 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12507 /* Set the glyph row flag indicating that the face of the last glyph
12508 in the text area has to be drawn to the end of the text area. */
12509 it
->glyph_row
->fill_line_p
= 1;
12511 /* If current character of IT is not ASCII, make sure we have the
12512 ASCII face. This will be automatically undone the next time
12513 get_next_display_element returns a multibyte character. Note
12514 that the character will always be single byte in unibyte text. */
12515 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12517 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12520 if (FRAME_WINDOW_P (f
))
12522 /* If the row is empty, add a space with the current face of IT,
12523 so that we know which face to draw. */
12524 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12526 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12527 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12528 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12533 /* Save some values that must not be changed. */
12534 int saved_x
= it
->current_x
;
12535 struct text_pos saved_pos
;
12536 Lisp_Object saved_object
;
12537 enum display_element_type saved_what
= it
->what
;
12538 int saved_face_id
= it
->face_id
;
12540 saved_object
= it
->object
;
12541 saved_pos
= it
->position
;
12543 it
->what
= IT_CHARACTER
;
12544 bzero (&it
->position
, sizeof it
->position
);
12545 it
->object
= make_number (0);
12548 it
->face_id
= face
->id
;
12550 PRODUCE_GLYPHS (it
);
12552 while (it
->current_x
<= it
->last_visible_x
)
12553 PRODUCE_GLYPHS (it
);
12555 /* Don't count these blanks really. It would let us insert a left
12556 truncation glyph below and make us set the cursor on them, maybe. */
12557 it
->current_x
= saved_x
;
12558 it
->object
= saved_object
;
12559 it
->position
= saved_pos
;
12560 it
->what
= saved_what
;
12561 it
->face_id
= saved_face_id
;
12566 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12567 trailing whitespace. */
12570 trailing_whitespace_p (charpos
)
12573 int bytepos
= CHAR_TO_BYTE (charpos
);
12576 while (bytepos
< ZV_BYTE
12577 && (c
= FETCH_CHAR (bytepos
),
12578 c
== ' ' || c
== '\t'))
12581 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12583 if (bytepos
!= PT_BYTE
)
12590 /* Highlight trailing whitespace, if any, in ROW. */
12593 highlight_trailing_whitespace (f
, row
)
12595 struct glyph_row
*row
;
12597 int used
= row
->used
[TEXT_AREA
];
12601 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12602 struct glyph
*glyph
= start
+ used
- 1;
12604 /* Skip over glyphs inserted to display the cursor at the
12605 end of a line, for extending the face of the last glyph
12606 to the end of the line on terminals, and for truncation
12607 and continuation glyphs. */
12608 while (glyph
>= start
12609 && glyph
->type
== CHAR_GLYPH
12610 && INTEGERP (glyph
->object
))
12613 /* If last glyph is a space or stretch, and it's trailing
12614 whitespace, set the face of all trailing whitespace glyphs in
12615 IT->glyph_row to `trailing-whitespace'. */
12617 && BUFFERP (glyph
->object
)
12618 && (glyph
->type
== STRETCH_GLYPH
12619 || (glyph
->type
== CHAR_GLYPH
12620 && glyph
->u
.ch
== ' '))
12621 && trailing_whitespace_p (glyph
->charpos
))
12623 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12625 while (glyph
>= start
12626 && BUFFERP (glyph
->object
)
12627 && (glyph
->type
== STRETCH_GLYPH
12628 || (glyph
->type
== CHAR_GLYPH
12629 && glyph
->u
.ch
== ' ')))
12630 (glyph
--)->face_id
= face_id
;
12636 /* Value is non-zero if glyph row ROW in window W should be
12637 used to hold the cursor. */
12640 cursor_row_p (w
, row
)
12642 struct glyph_row
*row
;
12644 int cursor_row_p
= 1;
12646 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12648 /* If the row ends with a newline from a string, we don't want
12649 the cursor there (if the row is continued it doesn't end in a
12651 if (CHARPOS (row
->end
.string_pos
) >= 0
12652 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12653 cursor_row_p
= row
->continued_p
;
12655 /* If the row ends at ZV, display the cursor at the end of that
12656 row instead of at the start of the row below. */
12657 else if (row
->ends_at_zv_p
)
12663 return cursor_row_p
;
12667 /* Construct the glyph row IT->glyph_row in the desired matrix of
12668 IT->w from text at the current position of IT. See dispextern.h
12669 for an overview of struct it. Value is non-zero if
12670 IT->glyph_row displays text, as opposed to a line displaying ZV
12677 struct glyph_row
*row
= it
->glyph_row
;
12679 /* We always start displaying at hpos zero even if hscrolled. */
12680 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12682 /* We must not display in a row that's not a text row. */
12683 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12684 < it
->w
->desired_matrix
->nrows
);
12686 /* Is IT->w showing the region? */
12687 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12689 /* Clear the result glyph row and enable it. */
12690 prepare_desired_row (row
);
12692 row
->y
= it
->current_y
;
12693 row
->start
= it
->current
;
12694 row
->continuation_lines_width
= it
->continuation_lines_width
;
12695 row
->displays_text_p
= 1;
12696 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12697 it
->starts_in_middle_of_char_p
= 0;
12699 /* Arrange the overlays nicely for our purposes. Usually, we call
12700 display_line on only one line at a time, in which case this
12701 can't really hurt too much, or we call it on lines which appear
12702 one after another in the buffer, in which case all calls to
12703 recenter_overlay_lists but the first will be pretty cheap. */
12704 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12706 /* Move over display elements that are not visible because we are
12707 hscrolled. This may stop at an x-position < IT->first_visible_x
12708 if the first glyph is partially visible or if we hit a line end. */
12709 if (it
->current_x
< it
->first_visible_x
)
12710 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12711 MOVE_TO_POS
| MOVE_TO_X
);
12713 /* Get the initial row height. This is either the height of the
12714 text hscrolled, if there is any, or zero. */
12715 row
->ascent
= it
->max_ascent
;
12716 row
->height
= it
->max_ascent
+ it
->max_descent
;
12717 row
->phys_ascent
= it
->max_phys_ascent
;
12718 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12720 /* Loop generating characters. The loop is left with IT on the next
12721 character to display. */
12724 int n_glyphs_before
, hpos_before
, x_before
;
12726 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12728 /* Retrieve the next thing to display. Value is zero if end of
12730 if (!get_next_display_element (it
))
12732 /* Maybe add a space at the end of this line that is used to
12733 display the cursor there under X. Set the charpos of the
12734 first glyph of blank lines not corresponding to any text
12736 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12737 || row
->used
[TEXT_AREA
] == 0)
12739 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12740 row
->displays_text_p
= 0;
12742 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
12743 row
->indicate_empty_line_p
= 1;
12746 it
->continuation_lines_width
= 0;
12747 row
->ends_at_zv_p
= 1;
12751 /* Now, get the metrics of what we want to display. This also
12752 generates glyphs in `row' (which is IT->glyph_row). */
12753 n_glyphs_before
= row
->used
[TEXT_AREA
];
12756 /* Remember the line height so far in case the next element doesn't
12757 fit on the line. */
12758 if (!it
->truncate_lines_p
)
12760 ascent
= it
->max_ascent
;
12761 descent
= it
->max_descent
;
12762 phys_ascent
= it
->max_phys_ascent
;
12763 phys_descent
= it
->max_phys_descent
;
12766 PRODUCE_GLYPHS (it
);
12768 /* If this display element was in marginal areas, continue with
12770 if (it
->area
!= TEXT_AREA
)
12772 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12773 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12774 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12775 row
->phys_height
= max (row
->phys_height
,
12776 it
->max_phys_ascent
+ it
->max_phys_descent
);
12777 set_iterator_to_next (it
, 1);
12781 /* Does the display element fit on the line? If we truncate
12782 lines, we should draw past the right edge of the window. If
12783 we don't truncate, we want to stop so that we can display the
12784 continuation glyph before the right margin. If lines are
12785 continued, there are two possible strategies for characters
12786 resulting in more than 1 glyph (e.g. tabs): Display as many
12787 glyphs as possible in this line and leave the rest for the
12788 continuation line, or display the whole element in the next
12789 line. Original redisplay did the former, so we do it also. */
12790 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12791 hpos_before
= it
->hpos
;
12794 if (/* Not a newline. */
12796 /* Glyphs produced fit entirely in the line. */
12797 && it
->current_x
< it
->last_visible_x
)
12799 it
->hpos
+= nglyphs
;
12800 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12801 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12802 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12803 row
->phys_height
= max (row
->phys_height
,
12804 it
->max_phys_ascent
+ it
->max_phys_descent
);
12805 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
12806 row
->x
= x
- it
->first_visible_x
;
12811 struct glyph
*glyph
;
12813 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
12815 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12816 new_x
= x
+ glyph
->pixel_width
;
12818 if (/* Lines are continued. */
12819 !it
->truncate_lines_p
12820 && (/* Glyph doesn't fit on the line. */
12821 new_x
> it
->last_visible_x
12822 /* Or it fits exactly on a window system frame. */
12823 || (new_x
== it
->last_visible_x
12824 && FRAME_WINDOW_P (it
->f
))))
12826 /* End of a continued line. */
12829 || (new_x
== it
->last_visible_x
12830 && FRAME_WINDOW_P (it
->f
)))
12832 /* Current glyph is the only one on the line or
12833 fits exactly on the line. We must continue
12834 the line because we can't draw the cursor
12835 after the glyph. */
12836 row
->continued_p
= 1;
12837 it
->current_x
= new_x
;
12838 it
->continuation_lines_width
+= new_x
;
12840 if (i
== nglyphs
- 1)
12841 set_iterator_to_next (it
, 1);
12843 else if (CHAR_GLYPH_PADDING_P (*glyph
)
12844 && !FRAME_WINDOW_P (it
->f
))
12846 /* A padding glyph that doesn't fit on this line.
12847 This means the whole character doesn't fit
12849 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12851 /* Fill the rest of the row with continuation
12852 glyphs like in 20.x. */
12853 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
12854 < row
->glyphs
[1 + TEXT_AREA
])
12855 produce_special_glyphs (it
, IT_CONTINUATION
);
12857 row
->continued_p
= 1;
12858 it
->current_x
= x_before
;
12859 it
->continuation_lines_width
+= x_before
;
12861 /* Restore the height to what it was before the
12862 element not fitting on the line. */
12863 it
->max_ascent
= ascent
;
12864 it
->max_descent
= descent
;
12865 it
->max_phys_ascent
= phys_ascent
;
12866 it
->max_phys_descent
= phys_descent
;
12870 /* Display element draws past the right edge of
12871 the window. Restore positions to values
12872 before the element. The next line starts
12873 with current_x before the glyph that could
12874 not be displayed, so that TAB works right. */
12875 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12877 /* Display continuation glyphs. */
12878 if (!FRAME_WINDOW_P (it
->f
))
12879 produce_special_glyphs (it
, IT_CONTINUATION
);
12880 row
->continued_p
= 1;
12883 it
->continuation_lines_width
+= x
;
12884 if (nglyphs
> 1 && i
> 0)
12886 row
->ends_in_middle_of_char_p
= 1;
12887 it
->starts_in_middle_of_char_p
= 1;
12890 /* Restore the height to what it was before the
12891 element not fitting on the line. */
12892 it
->max_ascent
= ascent
;
12893 it
->max_descent
= descent
;
12894 it
->max_phys_ascent
= phys_ascent
;
12895 it
->max_phys_descent
= phys_descent
;
12900 else if (new_x
> it
->first_visible_x
)
12902 /* Increment number of glyphs actually displayed. */
12905 if (x
< it
->first_visible_x
)
12906 /* Glyph is partially visible, i.e. row starts at
12907 negative X position. */
12908 row
->x
= x
- it
->first_visible_x
;
12912 /* Glyph is completely off the left margin of the
12913 window. This should not happen because of the
12914 move_it_in_display_line at the start of
12920 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12921 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12922 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12923 row
->phys_height
= max (row
->phys_height
,
12924 it
->max_phys_ascent
+ it
->max_phys_descent
);
12926 /* End of this display line if row is continued. */
12927 if (row
->continued_p
)
12931 /* Is this a line end? If yes, we're also done, after making
12932 sure that a non-default face is extended up to the right
12933 margin of the window. */
12934 if (ITERATOR_AT_END_OF_LINE_P (it
))
12936 int used_before
= row
->used
[TEXT_AREA
];
12938 /* Add a space at the end of the line that is used to
12939 display the cursor there. */
12940 append_space (it
, 0);
12942 /* Extend the face to the end of the line. */
12943 extend_face_to_end_of_line (it
);
12945 /* Make sure we have the position. */
12946 if (used_before
== 0)
12947 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
12949 /* Consume the line end. This skips over invisible lines. */
12950 set_iterator_to_next (it
, 1);
12951 it
->continuation_lines_width
= 0;
12955 /* Proceed with next display element. Note that this skips
12956 over lines invisible because of selective display. */
12957 set_iterator_to_next (it
, 1);
12959 /* If we truncate lines, we are done when the last displayed
12960 glyphs reach past the right margin of the window. */
12961 if (it
->truncate_lines_p
12962 && (FRAME_WINDOW_P (it
->f
)
12963 ? (it
->current_x
>= it
->last_visible_x
)
12964 : (it
->current_x
> it
->last_visible_x
)))
12966 /* Maybe add truncation glyphs. */
12967 if (!FRAME_WINDOW_P (it
->f
))
12971 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
12972 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
12975 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
12977 row
->used
[TEXT_AREA
] = i
;
12978 produce_special_glyphs (it
, IT_TRUNCATION
);
12982 row
->truncated_on_right_p
= 1;
12983 it
->continuation_lines_width
= 0;
12984 reseat_at_next_visible_line_start (it
, 0);
12985 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
12986 it
->hpos
= hpos_before
;
12987 it
->current_x
= x_before
;
12992 /* If line is not empty and hscrolled, maybe insert truncation glyphs
12993 at the left window margin. */
12994 if (it
->first_visible_x
12995 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
12997 if (!FRAME_WINDOW_P (it
->f
))
12998 insert_left_trunc_glyphs (it
);
12999 row
->truncated_on_left_p
= 1;
13002 /* If the start of this line is the overlay arrow-position, then
13003 mark this glyph row as the one containing the overlay arrow.
13004 This is clearly a mess with variable size fonts. It would be
13005 better to let it be displayed like cursors under X. */
13006 if (MARKERP (Voverlay_arrow_position
)
13007 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13008 && (MATRIX_ROW_START_CHARPOS (row
)
13009 == marker_position (Voverlay_arrow_position
))
13010 && STRINGP (Voverlay_arrow_string
)
13011 && ! overlay_arrow_seen
)
13013 /* Overlay arrow in window redisplay is a bitmap. */
13014 if (!FRAME_WINDOW_P (it
->f
))
13016 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13017 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13018 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13019 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13020 struct glyph
*p2
, *end
;
13022 /* Copy the arrow glyphs. */
13023 while (glyph
< arrow_end
)
13026 /* Throw away padding glyphs. */
13028 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13029 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13035 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13039 overlay_arrow_seen
= 1;
13040 row
->overlay_arrow_p
= 1;
13043 /* Compute pixel dimensions of this line. */
13044 compute_line_metrics (it
);
13046 /* Remember the position at which this line ends. */
13047 row
->end
= it
->current
;
13049 /* Maybe set the cursor. */
13050 if (it
->w
->cursor
.vpos
< 0
13051 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13052 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13053 && cursor_row_p (it
->w
, row
))
13054 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13056 /* Highlight trailing whitespace. */
13057 if (!NILP (Vshow_trailing_whitespace
))
13058 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13060 /* Prepare for the next line. This line starts horizontally at (X
13061 HPOS) = (0 0). Vertical positions are incremented. As a
13062 convenience for the caller, IT->glyph_row is set to the next
13064 it
->current_x
= it
->hpos
= 0;
13065 it
->current_y
+= row
->height
;
13068 return row
->displays_text_p
;
13073 /***********************************************************************
13075 ***********************************************************************/
13077 /* Redisplay the menu bar in the frame for window W.
13079 The menu bar of X frames that don't have X toolkit support is
13080 displayed in a special window W->frame->menu_bar_window.
13082 The menu bar of terminal frames is treated specially as far as
13083 glyph matrices are concerned. Menu bar lines are not part of
13084 windows, so the update is done directly on the frame matrix rows
13085 for the menu bar. */
13088 display_menu_bar (w
)
13091 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13096 /* Don't do all this for graphical frames. */
13098 if (!NILP (Vwindow_system
))
13101 #ifdef USE_X_TOOLKIT
13106 if (FRAME_MAC_P (f
))
13110 #ifdef USE_X_TOOLKIT
13111 xassert (!FRAME_WINDOW_P (f
));
13112 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13113 it
.first_visible_x
= 0;
13114 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13115 #else /* not USE_X_TOOLKIT */
13116 if (FRAME_WINDOW_P (f
))
13118 /* Menu bar lines are displayed in the desired matrix of the
13119 dummy window menu_bar_window. */
13120 struct window
*menu_w
;
13121 xassert (WINDOWP (f
->menu_bar_window
));
13122 menu_w
= XWINDOW (f
->menu_bar_window
);
13123 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13125 it
.first_visible_x
= 0;
13126 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13130 /* This is a TTY frame, i.e. character hpos/vpos are used as
13132 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13134 it
.first_visible_x
= 0;
13135 it
.last_visible_x
= FRAME_WIDTH (f
);
13137 #endif /* not USE_X_TOOLKIT */
13139 if (! mode_line_inverse_video
)
13140 /* Force the menu-bar to be displayed in the default face. */
13141 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13143 /* Clear all rows of the menu bar. */
13144 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13146 struct glyph_row
*row
= it
.glyph_row
+ i
;
13147 clear_glyph_row (row
);
13148 row
->enabled_p
= 1;
13149 row
->full_width_p
= 1;
13152 /* Display all items of the menu bar. */
13153 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13154 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13156 Lisp_Object string
;
13158 /* Stop at nil string. */
13159 string
= AREF (items
, i
+ 1);
13163 /* Remember where item was displayed. */
13164 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13166 /* Display the item, pad with one space. */
13167 if (it
.current_x
< it
.last_visible_x
)
13168 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13169 XSTRING (string
)->size
+ 1, 0, 0, -1);
13172 /* Fill out the line with spaces. */
13173 if (it
.current_x
< it
.last_visible_x
)
13174 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13176 /* Compute the total height of the lines. */
13177 compute_line_metrics (&it
);
13182 /***********************************************************************
13184 ***********************************************************************/
13186 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13187 FORCE is non-zero, redisplay mode lines unconditionally.
13188 Otherwise, redisplay only mode lines that are garbaged. Value is
13189 the number of windows whose mode lines were redisplayed. */
13192 redisplay_mode_lines (window
, force
)
13193 Lisp_Object window
;
13198 while (!NILP (window
))
13200 struct window
*w
= XWINDOW (window
);
13202 if (WINDOWP (w
->hchild
))
13203 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13204 else if (WINDOWP (w
->vchild
))
13205 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13207 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13208 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13210 Lisp_Object old_selected_frame
;
13211 struct text_pos lpoint
;
13212 struct buffer
*old
= current_buffer
;
13214 /* Set the window's buffer for the mode line display. */
13215 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13216 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13218 /* Point refers normally to the selected window. For any
13219 other window, set up appropriate value. */
13220 if (!EQ (window
, selected_window
))
13222 struct text_pos pt
;
13224 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13225 if (CHARPOS (pt
) < BEGV
)
13226 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13227 else if (CHARPOS (pt
) > (ZV
- 1))
13228 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13230 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13233 /* Temporarily set up the selected frame. */
13234 old_selected_frame
= selected_frame
;
13235 selected_frame
= w
->frame
;
13237 /* Display mode lines. */
13238 clear_glyph_matrix (w
->desired_matrix
);
13239 if (display_mode_lines (w
))
13242 w
->must_be_updated_p
= 1;
13245 /* Restore old settings. */
13246 selected_frame
= old_selected_frame
;
13247 set_buffer_internal_1 (old
);
13248 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13258 /* Display the mode and/or top line of window W. Value is the number
13259 of mode lines displayed. */
13262 display_mode_lines (w
)
13267 /* These will be set while the mode line specs are processed. */
13268 line_number_displayed
= 0;
13269 w
->column_number_displayed
= Qnil
;
13271 if (WINDOW_WANTS_MODELINE_P (w
))
13273 display_mode_line (w
, MODE_LINE_FACE_ID
,
13274 current_buffer
->mode_line_format
);
13278 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13280 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13281 current_buffer
->header_line_format
);
13289 /* Display mode or top line of window W. FACE_ID specifies which line
13290 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13291 FORMAT is the mode line format to display. Value is the pixel
13292 height of the mode line displayed. */
13295 display_mode_line (w
, face_id
, format
)
13297 enum face_id face_id
;
13298 Lisp_Object format
;
13303 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13304 prepare_desired_row (it
.glyph_row
);
13306 if (! mode_line_inverse_video
)
13307 /* Force the mode-line to be displayed in the default face. */
13308 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13310 /* Temporarily make frame's keyboard the current kboard so that
13311 kboard-local variables in the mode_line_format will get the right
13313 push_frame_kboard (it
.f
);
13314 display_mode_element (&it
, 0, 0, 0, format
);
13315 pop_frame_kboard ();
13317 /* Fill up with spaces. */
13318 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13320 compute_line_metrics (&it
);
13321 it
.glyph_row
->full_width_p
= 1;
13322 it
.glyph_row
->mode_line_p
= 1;
13323 it
.glyph_row
->inverse_p
= 0;
13324 it
.glyph_row
->continued_p
= 0;
13325 it
.glyph_row
->truncated_on_left_p
= 0;
13326 it
.glyph_row
->truncated_on_right_p
= 0;
13328 /* Make a 3D mode-line have a shadow at its right end. */
13329 face
= FACE_FROM_ID (it
.f
, face_id
);
13330 extend_face_to_end_of_line (&it
);
13331 if (face
->box
!= FACE_NO_BOX
)
13333 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13334 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13335 last
->right_box_line_p
= 1;
13338 return it
.glyph_row
->height
;
13342 /* Contribute ELT to the mode line for window IT->w. How it
13343 translates into text depends on its data type.
13345 IT describes the display environment in which we display, as usual.
13347 DEPTH is the depth in recursion. It is used to prevent
13348 infinite recursion here.
13350 FIELD_WIDTH is the number of characters the display of ELT should
13351 occupy in the mode line, and PRECISION is the maximum number of
13352 characters to display from ELT's representation. See
13353 display_string for details. *
13355 Returns the hpos of the end of the text generated by ELT. */
13358 display_mode_element (it
, depth
, field_width
, precision
, elt
)
13361 int field_width
, precision
;
13364 int n
= 0, field
, prec
;
13372 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13376 /* A string: output it and check for %-constructs within it. */
13378 unsigned char *this = XSTRING (elt
)->data
;
13379 unsigned char *lisp_string
= this;
13381 while ((precision
<= 0 || n
< precision
)
13383 && (frame_title_ptr
13384 || it
->current_x
< it
->last_visible_x
))
13386 unsigned char *last
= this;
13388 /* Advance to end of string or next format specifier. */
13389 while ((c
= *this++) != '\0' && c
!= '%')
13392 if (this - 1 != last
)
13394 /* Output to end of string or up to '%'. Field width
13395 is length of string. Don't output more than
13396 PRECISION allows us. */
13399 prec
= chars_in_text (last
, this - last
);
13400 if (precision
> 0 && prec
> precision
- n
)
13401 prec
= precision
- n
;
13403 if (frame_title_ptr
)
13404 n
+= store_frame_title (last
, 0, prec
);
13407 int bytepos
= last
- lisp_string
;
13408 int charpos
= string_byte_to_char (elt
, bytepos
);
13409 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
13410 it
, 0, prec
, 0, -1);
13413 else /* c == '%' */
13415 unsigned char *percent_position
= this;
13417 /* Get the specified minimum width. Zero means
13420 while ((c
= *this++) >= '0' && c
<= '9')
13421 field
= field
* 10 + c
- '0';
13423 /* Don't pad beyond the total padding allowed. */
13424 if (field_width
- n
> 0 && field
> field_width
- n
)
13425 field
= field_width
- n
;
13427 /* Note that either PRECISION <= 0 or N < PRECISION. */
13428 prec
= precision
- n
;
13431 n
+= display_mode_element (it
, depth
, field
, prec
,
13432 Vglobal_mode_string
);
13435 unsigned char *spec
13436 = decode_mode_spec (it
->w
, c
, field
, prec
);
13438 if (frame_title_ptr
)
13439 n
+= store_frame_title (spec
, field
, prec
);
13443 = it
->glyph_row
->used
[TEXT_AREA
];
13445 = percent_position
- XSTRING (elt
)->data
;
13447 = string_byte_to_char (elt
, bytepos
);
13449 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
13450 field
, prec
, 0, -1);
13452 /* Assign to the glyphs written above the
13453 string where the `%x' came from, position
13457 struct glyph
*glyph
13458 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13462 for (i
= 0; i
< nwritten
; ++i
)
13464 glyph
[i
].object
= elt
;
13465 glyph
[i
].charpos
= charpos
;
13478 /* A symbol: process the value of the symbol recursively
13479 as if it appeared here directly. Avoid error if symbol void.
13480 Special case: if value of symbol is a string, output the string
13483 register Lisp_Object tem
;
13484 tem
= Fboundp (elt
);
13487 tem
= Fsymbol_value (elt
);
13488 /* If value is a string, output that string literally:
13489 don't check for % within it. */
13492 prec
= precision
- n
;
13493 if (frame_title_ptr
)
13494 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
13496 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
13499 else if (!EQ (tem
, elt
))
13501 /* Give up right away for nil or t. */
13511 register Lisp_Object car
, tem
;
13513 /* A cons cell: three distinct cases.
13514 If first element is a string or a cons, process all the elements
13515 and effectively concatenate them.
13516 If first element is a negative number, truncate displaying cdr to
13517 at most that many characters. If positive, pad (with spaces)
13518 to at least that many characters.
13519 If first element is a symbol, process the cadr or caddr recursively
13520 according to whether the symbol's value is non-nil or nil. */
13522 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
13524 /* An element of the form (:eval FORM) means evaluate FORM
13525 and use the result as mode line elements. */
13526 struct gcpro gcpro1
;
13529 spec
= safe_eval (XCAR (XCDR (elt
)));
13531 n
+= display_mode_element (it
, depth
, field_width
- n
,
13532 precision
- n
, spec
);
13535 else if (SYMBOLP (car
))
13537 tem
= Fboundp (car
);
13541 /* elt is now the cdr, and we know it is a cons cell.
13542 Use its car if CAR has a non-nil value. */
13545 tem
= Fsymbol_value (car
);
13552 /* Symbol's value is nil (or symbol is unbound)
13553 Get the cddr of the original list
13554 and if possible find the caddr and use that. */
13558 else if (!CONSP (elt
))
13563 else if (INTEGERP (car
))
13565 register int lim
= XINT (car
);
13569 /* Negative int means reduce maximum width. */
13570 if (precision
<= 0)
13573 precision
= min (precision
, -lim
);
13577 /* Padding specified. Don't let it be more than
13578 current maximum. */
13580 lim
= min (precision
, lim
);
13582 /* If that's more padding than already wanted, queue it.
13583 But don't reduce padding already specified even if
13584 that is beyond the current truncation point. */
13585 field_width
= max (lim
, field_width
);
13589 else if (STRINGP (car
) || CONSP (car
))
13591 register int limit
= 50;
13592 /* Limit is to protect against circular lists. */
13595 && (precision
<= 0 || n
< precision
))
13597 n
+= display_mode_element (it
, depth
, field_width
- n
,
13598 precision
- n
, XCAR (elt
));
13607 if (frame_title_ptr
)
13608 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13610 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13611 precision
- n
, 0, 0);
13615 /* Pad to FIELD_WIDTH. */
13616 if (field_width
> 0 && n
< field_width
)
13618 if (frame_title_ptr
)
13619 n
+= store_frame_title ("", field_width
- n
, 0);
13621 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13629 /* Write a null-terminated, right justified decimal representation of
13630 the positive integer D to BUF using a minimal field width WIDTH. */
13633 pint2str (buf
, width
, d
)
13634 register char *buf
;
13635 register int width
;
13638 register char *p
= buf
;
13646 *p
++ = d
% 10 + '0';
13651 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13662 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13663 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13664 type of CODING_SYSTEM. Return updated pointer into BUF. */
13666 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13669 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13670 Lisp_Object coding_system
;
13671 register char *buf
;
13675 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13676 unsigned char *eol_str
;
13678 /* The EOL conversion we are using. */
13679 Lisp_Object eoltype
;
13681 val
= Fget (coding_system
, Qcoding_system
);
13684 if (!VECTORP (val
)) /* Not yet decided. */
13689 eoltype
= eol_mnemonic_undecided
;
13690 /* Don't mention EOL conversion if it isn't decided. */
13694 Lisp_Object eolvalue
;
13696 eolvalue
= Fget (coding_system
, Qeol_type
);
13699 *buf
++ = XFASTINT (AREF (val
, 1));
13703 /* The EOL conversion that is normal on this system. */
13705 if (NILP (eolvalue
)) /* Not yet decided. */
13706 eoltype
= eol_mnemonic_undecided
;
13707 else if (VECTORP (eolvalue
)) /* Not yet decided. */
13708 eoltype
= eol_mnemonic_undecided
;
13709 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
13710 eoltype
= (XFASTINT (eolvalue
) == 0
13711 ? eol_mnemonic_unix
13712 : (XFASTINT (eolvalue
) == 1
13713 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
13719 /* Mention the EOL conversion if it is not the usual one. */
13720 if (STRINGP (eoltype
))
13722 eol_str
= XSTRING (eoltype
)->data
;
13723 eol_str_len
= XSTRING (eoltype
)->size
;
13725 else if (INTEGERP (eoltype
)
13726 && CHAR_VALID_P (XINT (eoltype
), 0))
13728 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
13729 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
13733 eol_str
= invalid_eol_type
;
13734 eol_str_len
= sizeof (invalid_eol_type
) - 1;
13736 bcopy (eol_str
, buf
, eol_str_len
);
13737 buf
+= eol_str_len
;
13743 /* Return a string for the output of a mode line %-spec for window W,
13744 generated by character C. PRECISION >= 0 means don't return a
13745 string longer than that value. FIELD_WIDTH > 0 means pad the
13746 string returned with spaces to that value. */
13748 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
13751 decode_mode_spec (w
, c
, field_width
, precision
)
13754 int field_width
, precision
;
13757 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13758 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
13759 struct buffer
*b
= XBUFFER (w
->buffer
);
13766 if (!NILP (b
->read_only
))
13768 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13773 /* This differs from %* only for a modified read-only buffer. */
13774 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13776 if (!NILP (b
->read_only
))
13781 /* This differs from %* in ignoring read-only-ness. */
13782 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13794 if (command_loop_level
> 5)
13796 p
= decode_mode_spec_buf
;
13797 for (i
= 0; i
< command_loop_level
; i
++)
13800 return decode_mode_spec_buf
;
13808 if (command_loop_level
> 5)
13810 p
= decode_mode_spec_buf
;
13811 for (i
= 0; i
< command_loop_level
; i
++)
13814 return decode_mode_spec_buf
;
13821 /* Let lots_of_dashes be a string of infinite length. */
13822 if (field_width
<= 0
13823 || field_width
> sizeof (lots_of_dashes
))
13825 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
13826 decode_mode_spec_buf
[i
] = '-';
13827 decode_mode_spec_buf
[i
] = '\0';
13828 return decode_mode_spec_buf
;
13831 return lots_of_dashes
;
13840 int col
= current_column ();
13841 w
->column_number_displayed
= make_number (col
);
13842 pint2str (decode_mode_spec_buf
, field_width
, col
);
13843 return decode_mode_spec_buf
;
13847 /* %F displays the frame name. */
13848 if (!NILP (f
->title
))
13849 return (char *) XSTRING (f
->title
)->data
;
13850 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
13851 return (char *) XSTRING (f
->name
)->data
;
13860 int startpos
= XMARKER (w
->start
)->charpos
;
13861 int startpos_byte
= marker_byte_position (w
->start
);
13862 int line
, linepos
, linepos_byte
, topline
;
13864 int height
= XFASTINT (w
->height
);
13866 /* If we decided that this buffer isn't suitable for line numbers,
13867 don't forget that too fast. */
13868 if (EQ (w
->base_line_pos
, w
->buffer
))
13870 /* But do forget it, if the window shows a different buffer now. */
13871 else if (BUFFERP (w
->base_line_pos
))
13872 w
->base_line_pos
= Qnil
;
13874 /* If the buffer is very big, don't waste time. */
13875 if (INTEGERP (Vline_number_display_limit
)
13876 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
13878 w
->base_line_pos
= Qnil
;
13879 w
->base_line_number
= Qnil
;
13883 if (!NILP (w
->base_line_number
)
13884 && !NILP (w
->base_line_pos
)
13885 && XFASTINT (w
->base_line_pos
) <= startpos
)
13887 line
= XFASTINT (w
->base_line_number
);
13888 linepos
= XFASTINT (w
->base_line_pos
);
13889 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
13894 linepos
= BUF_BEGV (b
);
13895 linepos_byte
= BUF_BEGV_BYTE (b
);
13898 /* Count lines from base line to window start position. */
13899 nlines
= display_count_lines (linepos
, linepos_byte
,
13903 topline
= nlines
+ line
;
13905 /* Determine a new base line, if the old one is too close
13906 or too far away, or if we did not have one.
13907 "Too close" means it's plausible a scroll-down would
13908 go back past it. */
13909 if (startpos
== BUF_BEGV (b
))
13911 w
->base_line_number
= make_number (topline
);
13912 w
->base_line_pos
= make_number (BUF_BEGV (b
));
13914 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
13915 || linepos
== BUF_BEGV (b
))
13917 int limit
= BUF_BEGV (b
);
13918 int limit_byte
= BUF_BEGV_BYTE (b
);
13920 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
13922 if (startpos
- distance
> limit
)
13924 limit
= startpos
- distance
;
13925 limit_byte
= CHAR_TO_BYTE (limit
);
13928 nlines
= display_count_lines (startpos
, startpos_byte
,
13930 - (height
* 2 + 30),
13932 /* If we couldn't find the lines we wanted within
13933 line_number_display_limit_width chars per line,
13934 give up on line numbers for this window. */
13935 if (position
== limit_byte
&& limit
== startpos
- distance
)
13937 w
->base_line_pos
= w
->buffer
;
13938 w
->base_line_number
= Qnil
;
13942 w
->base_line_number
= make_number (topline
- nlines
);
13943 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
13946 /* Now count lines from the start pos to point. */
13947 nlines
= display_count_lines (startpos
, startpos_byte
,
13948 PT_BYTE
, PT
, &junk
);
13950 /* Record that we did display the line number. */
13951 line_number_displayed
= 1;
13953 /* Make the string to show. */
13954 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
13955 return decode_mode_spec_buf
;
13958 char* p
= decode_mode_spec_buf
;
13959 int pad
= field_width
- 2;
13965 return decode_mode_spec_buf
;
13971 obj
= b
->mode_name
;
13975 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
13981 int pos
= marker_position (w
->start
);
13982 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13984 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
13986 if (pos
<= BUF_BEGV (b
))
13991 else if (pos
<= BUF_BEGV (b
))
13995 if (total
> 1000000)
13996 /* Do it differently for a large value, to avoid overflow. */
13997 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13999 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14000 /* We can't normally display a 3-digit number,
14001 so get us a 2-digit number that is close. */
14004 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14005 return decode_mode_spec_buf
;
14009 /* Display percentage of size above the bottom of the screen. */
14012 int toppos
= marker_position (w
->start
);
14013 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14014 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14016 if (botpos
>= BUF_ZV (b
))
14018 if (toppos
<= BUF_BEGV (b
))
14025 if (total
> 1000000)
14026 /* Do it differently for a large value, to avoid overflow. */
14027 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14029 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14030 /* We can't normally display a 3-digit number,
14031 so get us a 2-digit number that is close. */
14034 if (toppos
<= BUF_BEGV (b
))
14035 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14037 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14038 return decode_mode_spec_buf
;
14043 /* status of process */
14044 obj
= Fget_buffer_process (w
->buffer
);
14046 return "no process";
14047 #ifdef subprocesses
14048 obj
= Fsymbol_name (Fprocess_status (obj
));
14052 case 't': /* indicate TEXT or BINARY */
14053 #ifdef MODE_LINE_BINARY_TEXT
14054 return MODE_LINE_BINARY_TEXT (b
);
14060 /* coding-system (not including end-of-line format) */
14062 /* coding-system (including end-of-line type) */
14064 int eol_flag
= (c
== 'Z');
14065 char *p
= decode_mode_spec_buf
;
14067 if (! FRAME_WINDOW_P (f
))
14069 /* No need to mention EOL here--the terminal never needs
14070 to do EOL conversion. */
14071 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14072 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14074 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14077 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14078 #ifdef subprocesses
14079 obj
= Fget_buffer_process (Fcurrent_buffer ());
14080 if (PROCESSP (obj
))
14082 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14084 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14087 #endif /* subprocesses */
14090 return decode_mode_spec_buf
;
14095 return (char *) XSTRING (obj
)->data
;
14101 /* Count up to COUNT lines starting from START / START_BYTE.
14102 But don't go beyond LIMIT_BYTE.
14103 Return the number of lines thus found (always nonnegative).
14105 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14108 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14109 int start
, start_byte
, limit_byte
, count
;
14112 register unsigned char *cursor
;
14113 unsigned char *base
;
14115 register int ceiling
;
14116 register unsigned char *ceiling_addr
;
14117 int orig_count
= count
;
14119 /* If we are not in selective display mode,
14120 check only for newlines. */
14121 int selective_display
= (!NILP (current_buffer
->selective_display
)
14122 && !INTEGERP (current_buffer
->selective_display
));
14126 while (start_byte
< limit_byte
)
14128 ceiling
= BUFFER_CEILING_OF (start_byte
);
14129 ceiling
= min (limit_byte
- 1, ceiling
);
14130 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14131 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14134 if (selective_display
)
14135 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14138 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14141 if (cursor
!= ceiling_addr
)
14145 start_byte
+= cursor
- base
+ 1;
14146 *byte_pos_ptr
= start_byte
;
14150 if (++cursor
== ceiling_addr
)
14156 start_byte
+= cursor
- base
;
14161 while (start_byte
> limit_byte
)
14163 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14164 ceiling
= max (limit_byte
, ceiling
);
14165 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14166 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14169 if (selective_display
)
14170 while (--cursor
!= ceiling_addr
14171 && *cursor
!= '\n' && *cursor
!= 015)
14174 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14177 if (cursor
!= ceiling_addr
)
14181 start_byte
+= cursor
- base
+ 1;
14182 *byte_pos_ptr
= start_byte
;
14183 /* When scanning backwards, we should
14184 not count the newline posterior to which we stop. */
14185 return - orig_count
- 1;
14191 /* Here we add 1 to compensate for the last decrement
14192 of CURSOR, which took it past the valid range. */
14193 start_byte
+= cursor
- base
+ 1;
14197 *byte_pos_ptr
= limit_byte
;
14200 return - orig_count
+ count
;
14201 return orig_count
- count
;
14207 /***********************************************************************
14209 ***********************************************************************/
14211 /* Display a NUL-terminated string, starting with index START.
14213 If STRING is non-null, display that C string. Otherwise, the Lisp
14214 string LISP_STRING is displayed.
14216 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14217 FACE_STRING. Display STRING or LISP_STRING with the face at
14218 FACE_STRING_POS in FACE_STRING:
14220 Display the string in the environment given by IT, but use the
14221 standard display table, temporarily.
14223 FIELD_WIDTH is the minimum number of output glyphs to produce.
14224 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14225 with spaces. If STRING has more characters, more than FIELD_WIDTH
14226 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14228 PRECISION is the maximum number of characters to output from
14229 STRING. PRECISION < 0 means don't truncate the string.
14231 This is roughly equivalent to printf format specifiers:
14233 FIELD_WIDTH PRECISION PRINTF
14234 ----------------------------------------
14240 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14241 display them, and < 0 means obey the current buffer's value of
14242 enable_multibyte_characters.
14244 Value is the number of glyphs produced. */
14247 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14248 start
, it
, field_width
, precision
, max_x
, multibyte
)
14249 unsigned char *string
;
14250 Lisp_Object lisp_string
;
14251 Lisp_Object face_string
;
14252 int face_string_pos
;
14255 int field_width
, precision
, max_x
;
14258 int hpos_at_start
= it
->hpos
;
14259 int saved_face_id
= it
->face_id
;
14260 struct glyph_row
*row
= it
->glyph_row
;
14262 /* Initialize the iterator IT for iteration over STRING beginning
14263 with index START. */
14264 reseat_to_string (it
, string
, lisp_string
, start
,
14265 precision
, field_width
, multibyte
);
14267 /* If displaying STRING, set up the face of the iterator
14268 from LISP_STRING, if that's given. */
14269 if (STRINGP (face_string
))
14275 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
14276 0, it
->region_beg_charpos
,
14277 it
->region_end_charpos
,
14278 &endptr
, it
->base_face_id
, 0);
14279 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14280 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
14283 /* Set max_x to the maximum allowed X position. Don't let it go
14284 beyond the right edge of the window. */
14286 max_x
= it
->last_visible_x
;
14288 max_x
= min (max_x
, it
->last_visible_x
);
14290 /* Skip over display elements that are not visible. because IT->w is
14292 if (it
->current_x
< it
->first_visible_x
)
14293 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
14294 MOVE_TO_POS
| MOVE_TO_X
);
14296 row
->ascent
= it
->max_ascent
;
14297 row
->height
= it
->max_ascent
+ it
->max_descent
;
14298 row
->phys_ascent
= it
->max_phys_ascent
;
14299 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14301 /* This condition is for the case that we are called with current_x
14302 past last_visible_x. */
14303 while (it
->current_x
< max_x
)
14305 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14307 /* Get the next display element. */
14308 if (!get_next_display_element (it
))
14311 /* Produce glyphs. */
14312 x_before
= it
->current_x
;
14313 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14314 PRODUCE_GLYPHS (it
);
14316 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14319 while (i
< nglyphs
)
14321 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14323 if (!it
->truncate_lines_p
14324 && x
+ glyph
->pixel_width
> max_x
)
14326 /* End of continued line or max_x reached. */
14327 if (CHAR_GLYPH_PADDING_P (*glyph
))
14329 /* A wide character is unbreakable. */
14330 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14331 it
->current_x
= x_before
;
14335 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14340 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
14342 /* Glyph is at least partially visible. */
14344 if (x
< it
->first_visible_x
)
14345 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14349 /* Glyph is off the left margin of the display area.
14350 Should not happen. */
14354 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14355 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14356 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14357 row
->phys_height
= max (row
->phys_height
,
14358 it
->max_phys_ascent
+ it
->max_phys_descent
);
14359 x
+= glyph
->pixel_width
;
14363 /* Stop if max_x reached. */
14367 /* Stop at line ends. */
14368 if (ITERATOR_AT_END_OF_LINE_P (it
))
14370 it
->continuation_lines_width
= 0;
14374 set_iterator_to_next (it
, 1);
14376 /* Stop if truncating at the right edge. */
14377 if (it
->truncate_lines_p
14378 && it
->current_x
>= it
->last_visible_x
)
14380 /* Add truncation mark, but don't do it if the line is
14381 truncated at a padding space. */
14382 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14384 if (!FRAME_WINDOW_P (it
->f
))
14388 if (it
->current_x
> it
->last_visible_x
)
14390 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14391 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14393 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14395 row
->used
[TEXT_AREA
] = i
;
14396 produce_special_glyphs (it
, IT_TRUNCATION
);
14399 produce_special_glyphs (it
, IT_TRUNCATION
);
14401 it
->glyph_row
->truncated_on_right_p
= 1;
14407 /* Maybe insert a truncation at the left. */
14408 if (it
->first_visible_x
14409 && IT_CHARPOS (*it
) > 0)
14411 if (!FRAME_WINDOW_P (it
->f
))
14412 insert_left_trunc_glyphs (it
);
14413 it
->glyph_row
->truncated_on_left_p
= 1;
14416 it
->face_id
= saved_face_id
;
14418 /* Value is number of columns displayed. */
14419 return it
->hpos
- hpos_at_start
;
14424 /* This is like a combination of memq and assq. Return 1 if PROPVAL
14425 appears as an element of LIST or as the car of an element of LIST.
14426 If PROPVAL is a list, compare each element against LIST in that
14427 way, and return 1 if any element of PROPVAL is found in LIST.
14428 Otherwise return 0. This function cannot quit. */
14431 invisible_p (propval
, list
)
14432 register Lisp_Object propval
;
14435 register Lisp_Object tail
, proptail
;
14437 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14439 register Lisp_Object tem
;
14441 if (EQ (propval
, tem
))
14443 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14447 if (CONSP (propval
))
14449 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14451 Lisp_Object propelt
;
14452 propelt
= XCAR (proptail
);
14453 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14455 register Lisp_Object tem
;
14457 if (EQ (propelt
, tem
))
14459 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14469 /* Return 1 if PROPVAL appears as the car of an element of LIST and
14470 the cdr of that element is non-nil. If PROPVAL is a list, check
14471 each element of PROPVAL in that way, and the first time some
14472 element is found, return 1 if the cdr of that element is non-nil.
14473 Otherwise return 0. This function cannot quit. */
14476 invisible_ellipsis_p (propval
, list
)
14477 register Lisp_Object propval
;
14480 register Lisp_Object tail
, proptail
;
14482 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14484 register Lisp_Object tem
;
14486 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14487 return ! NILP (XCDR (tem
));
14490 if (CONSP (propval
))
14491 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14493 Lisp_Object propelt
;
14494 propelt
= XCAR (proptail
);
14495 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14497 register Lisp_Object tem
;
14499 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14500 return ! NILP (XCDR (tem
));
14509 /***********************************************************************
14511 ***********************************************************************/
14516 Vwith_echo_area_save_vector
= Qnil
;
14517 staticpro (&Vwith_echo_area_save_vector
);
14519 Vmessage_stack
= Qnil
;
14520 staticpro (&Vmessage_stack
);
14522 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14523 staticpro (&Qinhibit_redisplay
);
14526 defsubr (&Sdump_glyph_matrix
);
14527 defsubr (&Sdump_glyph_row
);
14528 defsubr (&Sdump_tool_bar_row
);
14529 defsubr (&Strace_redisplay
);
14530 defsubr (&Strace_to_stderr
);
14532 #ifdef HAVE_WINDOW_SYSTEM
14533 defsubr (&Stool_bar_lines_needed
);
14536 staticpro (&Qmenu_bar_update_hook
);
14537 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14539 staticpro (&Qoverriding_terminal_local_map
);
14540 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14542 staticpro (&Qoverriding_local_map
);
14543 Qoverriding_local_map
= intern ("overriding-local-map");
14545 staticpro (&Qwindow_scroll_functions
);
14546 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14548 staticpro (&Qredisplay_end_trigger_functions
);
14549 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14551 staticpro (&Qinhibit_point_motion_hooks
);
14552 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14554 QCdata
= intern (":data");
14555 staticpro (&QCdata
);
14556 Qdisplay
= intern ("display");
14557 staticpro (&Qdisplay
);
14558 Qspace_width
= intern ("space-width");
14559 staticpro (&Qspace_width
);
14560 Qraise
= intern ("raise");
14561 staticpro (&Qraise
);
14562 Qspace
= intern ("space");
14563 staticpro (&Qspace
);
14564 Qmargin
= intern ("margin");
14565 staticpro (&Qmargin
);
14566 Qleft_margin
= intern ("left-margin");
14567 staticpro (&Qleft_margin
);
14568 Qright_margin
= intern ("right-margin");
14569 staticpro (&Qright_margin
);
14570 Qalign_to
= intern ("align-to");
14571 staticpro (&Qalign_to
);
14572 QCalign_to
= intern (":align-to");
14573 staticpro (&QCalign_to
);
14574 Qrelative_width
= intern ("relative-width");
14575 staticpro (&Qrelative_width
);
14576 QCrelative_width
= intern (":relative-width");
14577 staticpro (&QCrelative_width
);
14578 QCrelative_height
= intern (":relative-height");
14579 staticpro (&QCrelative_height
);
14580 QCeval
= intern (":eval");
14581 staticpro (&QCeval
);
14582 Qwhen
= intern ("when");
14583 staticpro (&Qwhen
);
14584 QCfile
= intern (":file");
14585 staticpro (&QCfile
);
14586 Qfontified
= intern ("fontified");
14587 staticpro (&Qfontified
);
14588 Qfontification_functions
= intern ("fontification-functions");
14589 staticpro (&Qfontification_functions
);
14590 Qtrailing_whitespace
= intern ("trailing-whitespace");
14591 staticpro (&Qtrailing_whitespace
);
14592 Qimage
= intern ("image");
14593 staticpro (&Qimage
);
14594 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14595 staticpro (&Qmessage_truncate_lines
);
14596 Qgrow_only
= intern ("grow-only");
14597 staticpro (&Qgrow_only
);
14598 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14599 staticpro (&Qinhibit_menubar_update
);
14600 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
14601 staticpro (&Qinhibit_eval_during_redisplay
);
14602 Qposition
= intern ("position");
14603 staticpro (&Qposition
);
14604 Qbuffer_position
= intern ("buffer-position");
14605 staticpro (&Qbuffer_position
);
14606 Qobject
= intern ("object");
14607 staticpro (&Qobject
);
14609 last_arrow_position
= Qnil
;
14610 last_arrow_string
= Qnil
;
14611 staticpro (&last_arrow_position
);
14612 staticpro (&last_arrow_string
);
14614 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14615 staticpro (&echo_buffer
[0]);
14616 staticpro (&echo_buffer
[1]);
14618 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14619 staticpro (&echo_area_buffer
[0]);
14620 staticpro (&echo_area_buffer
[1]);
14622 Vmessages_buffer_name
= build_string ("*Messages*");
14623 staticpro (&Vmessages_buffer_name
);
14625 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14626 "Non-nil means highlight trailing whitespace.\n\
14627 The face used for trailing whitespace is `trailing-whitespace'.");
14628 Vshow_trailing_whitespace
= Qnil
;
14630 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14631 "Non-nil means don't actually do any redisplay.\n\
14632 This is used for internal purposes.");
14633 Vinhibit_redisplay
= Qnil
;
14635 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14636 "String (or mode line construct) included (normally) in `mode-line-format'.");
14637 Vglobal_mode_string
= Qnil
;
14639 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14640 "Marker for where to display an arrow on top of the buffer text.\n\
14641 This must be the beginning of a line in order to work.\n\
14642 See also `overlay-arrow-string'.");
14643 Voverlay_arrow_position
= Qnil
;
14645 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14646 "String to display as an arrow. See also `overlay-arrow-position'.");
14647 Voverlay_arrow_string
= Qnil
;
14649 DEFVAR_INT ("scroll-step", &scroll_step
,
14650 "*The number of lines to try scrolling a window by when point moves out.\n\
14651 If that fails to bring point back on frame, point is centered instead.\n\
14652 If this is zero, point is always centered after it moves off frame.\n\
14653 If you want scrolling to always be a line at a time, you should set\n\
14654 `scroll-conservatively' to a large value rather than set this to 1.");
14656 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14657 "*Scroll up to this many lines, to bring point back on screen.\n\
14658 A value of zero means to scroll the text to center point vertically\n\
14660 scroll_conservatively
= 0;
14662 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14663 "*Number of lines of margin at the top and bottom of a window.\n\
14664 Recenter the window whenever point gets within this many lines\n\
14665 of the top or bottom of the window.");
14669 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
14672 DEFVAR_BOOL ("truncate-partial-width-windows",
14673 &truncate_partial_width_windows
,
14674 "*Non-nil means truncate lines in all windows less than full frame wide.");
14675 truncate_partial_width_windows
= 1;
14677 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14678 "nil means display the mode-line/header-line/menu-bar in the default face.\n\
14679 Any other value means to use the appropriate face, `mode-line',\n\
14680 `header-line', or `menu' respectively.\n\
14682 This variable is deprecated; please change the above faces instead.");
14683 mode_line_inverse_video
= 1;
14685 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14686 "*Maximum buffer size for which line number should be displayed.\n\
14687 If the buffer is bigger than this, the line number does not appear\n\
14688 in the mode line. A value of nil means no limit.");
14689 Vline_number_display_limit
= Qnil
;
14691 DEFVAR_INT ("line-number-display-limit-width",
14692 &line_number_display_limit_width
,
14693 "*Maximum line width (in characters) for line number display.\n\
14694 If the average length of the lines near point is bigger than this, then the\n\
14695 line number may be omitted from the mode line.");
14696 line_number_display_limit_width
= 200;
14698 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14699 "*Non-nil means highlight region even in nonselected windows.");
14700 highlight_nonselected_windows
= 0;
14702 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14703 "Non-nil if more than one frame is visible on this display.\n\
14704 Minibuffer-only frames don't count, but iconified frames do.\n\
14705 This variable is not guaranteed to be accurate except while processing\n\
14706 `frame-title-format' and `icon-title-format'.");
14708 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14709 "Template for displaying the title bar of visible frames.\n\
14710 \(Assuming the window manager supports this feature.)\n\
14711 This variable has the same structure as `mode-line-format' (which see),\n\
14712 and is used only on frames for which no explicit name has been set\n\
14713 \(see `modify-frame-parameters').");
14714 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
14715 "Template for displaying the title bar of an iconified frame.\n\
14716 \(Assuming the window manager supports this feature.)\n\
14717 This variable has the same structure as `mode-line-format' (which see),\n\
14718 and is used only on frames for which no explicit name has been set\n\
14719 \(see `modify-frame-parameters').");
14721 = Vframe_title_format
14722 = Fcons (intern ("multiple-frames"),
14723 Fcons (build_string ("%b"),
14724 Fcons (Fcons (build_string (""),
14725 Fcons (intern ("invocation-name"),
14726 Fcons (build_string ("@"),
14727 Fcons (intern ("system-name"),
14731 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
14732 "Maximum number of lines to keep in the message log buffer.\n\
14733 If nil, disable message logging. If t, log messages but don't truncate\n\
14734 the buffer when it becomes large.");
14735 Vmessage_log_max
= make_number (50);
14737 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
14738 "Functions called before redisplay, if window sizes have changed.\n\
14739 The value should be a list of functions that take one argument.\n\
14740 Just before redisplay, for each frame, if any of its windows have changed\n\
14741 size since the last redisplay, or have been split or deleted,\n\
14742 all the functions in the list are called, with the frame as argument.");
14743 Vwindow_size_change_functions
= Qnil
;
14745 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
14746 "List of Functions to call before redisplaying a window with scrolling.\n\
14747 Each function is called with two arguments, the window\n\
14748 and its new display-start position. Note that the value of `window-end'\n\
14749 is not valid when these functions are called.");
14750 Vwindow_scroll_functions
= Qnil
;
14752 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
14753 "*Non-nil means automatically resize tool-bars.\n\
14754 This increases a tool-bar's height if not all tool-bar items are visible.\n\
14755 It decreases a tool-bar's height when it would display blank lines\n\
14757 auto_resize_tool_bars_p
= 1;
14759 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
14760 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
14761 auto_raise_tool_bar_buttons_p
= 1;
14763 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
14764 "*Margin around tool-bar buttons in pixels.\n\
14765 If an integer, use that for both horizontal and vertical margins.\n\
14766 Otherwise, value should be a pair of integers `(HORZ : VERT)' with\n\
14767 HORZ specifying the horizontal margin, and VERT specifying the\n\
14768 vertical margin.");
14769 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
14771 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
14772 "Relief thickness of tool-bar buttons.");
14773 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
14775 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
14776 "List of functions to call to fontify regions of text.\n\
14777 Each function is called with one argument POS. Functions must\n\
14778 fontify a region starting at POS in the current buffer, and give\n\
14779 fontified regions the property `fontified'.\n\
14780 This variable automatically becomes buffer-local when set.");
14781 Vfontification_functions
= Qnil
;
14782 Fmake_variable_buffer_local (Qfontification_functions
);
14784 DEFVAR_BOOL ("unibyte-display-via-language-environment",
14785 &unibyte_display_via_language_environment
,
14786 "*Non-nil means display unibyte text according to language environment.\n\
14787 Specifically this means that unibyte non-ASCII characters\n\
14788 are displayed by converting them to the equivalent multibyte characters\n\
14789 according to the current language environment. As a result, they are\n\
14790 displayed according to the current fontset.");
14791 unibyte_display_via_language_environment
= 0;
14793 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
14794 "*Maximum height for resizing mini-windows.\n\
14795 If a float, it specifies a fraction of the mini-window frame's height.\n\
14796 If an integer, it specifies a number of lines.");
14797 Vmax_mini_window_height
= make_float (0.25);
14799 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
14800 "*How to resize mini-windows.\n\
14801 A value of nil means don't automatically resize mini-windows.\n\
14802 A value of t means resize them to fit the text displayed in them.\n\
14803 A value of `grow-only', the default, means let mini-windows grow\n\
14804 only, until their display becomes empty, at which point the windows\n\
14805 go back to their normal size.");
14806 Vresize_mini_windows
= Qgrow_only
;
14808 DEFVAR_BOOL ("cursor-in-non-selected-windows",
14809 &cursor_in_non_selected_windows
,
14810 "*Non-nil means display a hollow cursor in non-selected windows.\n\
14811 Nil means don't display a cursor there.");
14812 cursor_in_non_selected_windows
= 1;
14814 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
14815 "*Non-nil means scroll the display automatically to make point visible.");
14816 automatic_hscrolling_p
= 1;
14818 DEFVAR_LISP ("image-types", &Vimage_types
,
14819 "List of supported image types.\n\
14820 Each element of the list is a symbol for a supported image type.");
14821 Vimage_types
= Qnil
;
14823 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
14824 "If non-nil, messages are truncated instead of resizing the echo area.\n\
14825 Bind this around calls to `message' to let it take effect.");
14826 message_truncate_lines
= 0;
14828 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
14829 "Normal hook run for clicks on menu bar, before displaying a submenu.\n\
14830 Can be used to update submenus whose contents should vary.");
14831 Vmenu_bar_update_hook
= Qnil
;
14833 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
14834 "Non-nil means don't update menu bars. Internal use only.");
14835 inhibit_menubar_update
= 0;
14837 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
14838 "Non-nil means don't eval Lisp during redisplay.");
14839 inhibit_eval_during_redisplay
= 0;
14843 /* Initialize this module when Emacs starts. */
14848 Lisp_Object root_window
;
14849 struct window
*mini_w
;
14851 current_header_line_height
= current_mode_line_height
= -1;
14853 CHARPOS (this_line_start_pos
) = 0;
14855 mini_w
= XWINDOW (minibuf_window
);
14856 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
14858 if (!noninteractive
)
14860 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
14863 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
14864 set_window_height (root_window
,
14865 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
14867 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
14868 set_window_height (minibuf_window
, 1, 0);
14870 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
14871 mini_w
->width
= make_number (FRAME_WIDTH (f
));
14873 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
14874 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
14875 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
14877 /* The default ellipsis glyphs `...'. */
14878 for (i
= 0; i
< 3; ++i
)
14879 default_invis_vector
[i
] = make_number ('.');
14882 #ifdef HAVE_WINDOW_SYSTEM
14884 /* Allocate the buffer for frame titles. */
14886 frame_title_buf
= (char *) xmalloc (size
);
14887 frame_title_buf_end
= frame_title_buf
+ size
;
14888 frame_title_ptr
= NULL
;
14890 #endif /* HAVE_WINDOW_SYSTEM */
14892 help_echo_showing_p
= 0;