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
;
230 /* Functions called to fontify regions of text. */
232 Lisp_Object Vfontification_functions
;
233 Lisp_Object Qfontification_functions
;
235 /* Non-zero means draw tool bar buttons raised when the mouse moves
238 int auto_raise_tool_bar_buttons_p
;
240 /* Margin around tool bar buttons in pixels. */
242 Lisp_Object Vtool_bar_button_margin
;
244 /* Thickness of shadow to draw around tool bar buttons. */
246 int tool_bar_button_relief
;
248 /* Non-zero means automatically resize tool-bars so that all tool-bar
249 items are visible, and no blank lines remain. */
251 int auto_resize_tool_bars_p
;
253 /* Non-nil means don't actually do any redisplay. */
255 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
257 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
259 int inhibit_eval_during_redisplay
, Qinhibit_eval_during_redisplay
;
261 /* Names of text properties relevant for redisplay. */
263 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
264 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
266 /* Symbols used in text property values. */
268 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
269 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
271 extern Lisp_Object Qheight
;
273 /* Non-nil means highlight trailing whitespace. */
275 Lisp_Object Vshow_trailing_whitespace
;
277 /* Name of the face used to highlight trailing whitespace. */
279 Lisp_Object Qtrailing_whitespace
;
281 /* The symbol `image' which is the car of the lists used to represent
286 /* Non-zero means print newline to stdout before next mini-buffer
289 int noninteractive_need_newline
;
291 /* Non-zero means print newline to message log before next message. */
293 static int message_log_need_newline
;
296 /* The buffer position of the first character appearing entirely or
297 partially on the line of the selected window which contains the
298 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
299 redisplay optimization in redisplay_internal. */
301 static struct text_pos this_line_start_pos
;
303 /* Number of characters past the end of the line above, including the
304 terminating newline. */
306 static struct text_pos this_line_end_pos
;
308 /* The vertical positions and the height of this line. */
310 static int this_line_vpos
;
311 static int this_line_y
;
312 static int this_line_pixel_height
;
314 /* X position at which this display line starts. Usually zero;
315 negative if first character is partially visible. */
317 static int this_line_start_x
;
319 /* Buffer that this_line_.* variables are referring to. */
321 static struct buffer
*this_line_buffer
;
323 /* Nonzero means truncate lines in all windows less wide than the
326 int truncate_partial_width_windows
;
328 /* A flag to control how to display unibyte 8-bit character. */
330 int unibyte_display_via_language_environment
;
332 /* Nonzero means we have more than one non-mini-buffer-only frame.
333 Not guaranteed to be accurate except while parsing
334 frame-title-format. */
338 Lisp_Object Vglobal_mode_string
;
340 /* Marker for where to display an arrow on top of the buffer text. */
342 Lisp_Object Voverlay_arrow_position
;
344 /* String to display for the arrow. Only used on terminal frames. */
346 Lisp_Object Voverlay_arrow_string
;
348 /* Values of those variables at last redisplay. However, if
349 Voverlay_arrow_position is a marker, last_arrow_position is its
350 numerical position. */
352 static Lisp_Object last_arrow_position
, last_arrow_string
;
354 /* Like mode-line-format, but for the title bar on a visible frame. */
356 Lisp_Object Vframe_title_format
;
358 /* Like mode-line-format, but for the title bar on an iconified frame. */
360 Lisp_Object Vicon_title_format
;
362 /* List of functions to call when a window's size changes. These
363 functions get one arg, a frame on which one or more windows' sizes
366 static Lisp_Object Vwindow_size_change_functions
;
368 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
370 /* Nonzero if overlay arrow has been displayed once in this window. */
372 static int overlay_arrow_seen
;
374 /* Nonzero means highlight the region even in nonselected windows. */
376 int highlight_nonselected_windows
;
378 /* If cursor motion alone moves point off frame, try scrolling this
379 many lines up or down if that will bring it back. */
381 static int scroll_step
;
383 /* Non-0 means scroll just far enough to bring point back on the
384 screen, when appropriate. */
386 static int scroll_conservatively
;
388 /* Recenter the window whenever point gets within this many lines of
389 the top or bottom of the window. This value is translated into a
390 pixel value by multiplying it with CANON_Y_UNIT, which means that
391 there is really a fixed pixel height scroll margin. */
395 /* Number of windows showing the buffer of the selected window (or
396 another buffer with the same base buffer). keyboard.c refers to
401 /* Vector containing glyphs for an ellipsis `...'. */
403 static Lisp_Object default_invis_vector
[3];
405 /* Zero means display the mode-line/header-line/menu-bar in the default face
406 (this slightly odd definition is for compatibility with previous versions
407 of emacs), non-zero means display them using their respective faces.
409 This variable is deprecated. */
411 int mode_line_inverse_video
;
413 /* Prompt to display in front of the mini-buffer contents. */
415 Lisp_Object minibuf_prompt
;
417 /* Width of current mini-buffer prompt. Only set after display_line
418 of the line that contains the prompt. */
420 int minibuf_prompt_width
;
421 int minibuf_prompt_pixel_width
;
423 /* This is the window where the echo area message was displayed. It
424 is always a mini-buffer window, but it may not be the same window
425 currently active as a mini-buffer. */
427 Lisp_Object echo_area_window
;
429 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
430 pushes the current message and the value of
431 message_enable_multibyte on the stack, the function restore_message
432 pops the stack and displays MESSAGE again. */
434 Lisp_Object Vmessage_stack
;
436 /* Nonzero means multibyte characters were enabled when the echo area
437 message was specified. */
439 int message_enable_multibyte
;
441 /* True if we should redraw the mode lines on the next redisplay. */
443 int update_mode_lines
;
445 /* Nonzero if window sizes or contents have changed since last
446 redisplay that finished */
448 int windows_or_buffers_changed
;
450 /* Nonzero after display_mode_line if %l was used and it displayed a
453 int line_number_displayed
;
455 /* Maximum buffer size for which to display line numbers. */
457 Lisp_Object Vline_number_display_limit
;
459 /* line width to consider when repostioning for line number display */
461 static int line_number_display_limit_width
;
463 /* Number of lines to keep in the message log buffer. t means
464 infinite. nil means don't log at all. */
466 Lisp_Object Vmessage_log_max
;
468 /* The name of the *Messages* buffer, a string. */
470 static Lisp_Object Vmessages_buffer_name
;
472 /* Current, index 0, and last displayed echo area message. Either
473 buffers from echo_buffers, or nil to indicate no message. */
475 Lisp_Object echo_area_buffer
[2];
477 /* The buffers referenced from echo_area_buffer. */
479 static Lisp_Object echo_buffer
[2];
481 /* A vector saved used in with_area_buffer to reduce consing. */
483 static Lisp_Object Vwith_echo_area_save_vector
;
485 /* Non-zero means display_echo_area should display the last echo area
486 message again. Set by redisplay_preserve_echo_area. */
488 static int display_last_displayed_message_p
;
490 /* Nonzero if echo area is being used by print; zero if being used by
493 int message_buf_print
;
495 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
497 Lisp_Object Qinhibit_menubar_update
;
498 int inhibit_menubar_update
;
500 /* Maximum height for resizing mini-windows. Either a float
501 specifying a fraction of the available height, or an integer
502 specifying a number of lines. */
504 Lisp_Object Vmax_mini_window_height
;
506 /* Non-zero means messages should be displayed with truncated
507 lines instead of being continued. */
509 int message_truncate_lines
;
510 Lisp_Object Qmessage_truncate_lines
;
512 /* Non-zero means we want a hollow cursor in windows that are not
513 selected. Zero means there's no cursor in such windows. */
515 int cursor_in_non_selected_windows
;
517 /* A scratch glyph row with contents used for generating truncation
518 glyphs. Also used in direct_output_for_insert. */
520 #define MAX_SCRATCH_GLYPHS 100
521 struct glyph_row scratch_glyph_row
;
522 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
524 /* Ascent and height of the last line processed by move_it_to. */
526 static int last_max_ascent
, last_height
;
528 /* Non-zero if there's a help-echo in the echo area. */
530 int help_echo_showing_p
;
532 /* If >= 0, computed, exact values of mode-line and header-line height
533 to use in the macros CURRENT_MODE_LINE_HEIGHT and
534 CURRENT_HEADER_LINE_HEIGHT. */
536 int current_mode_line_height
, current_header_line_height
;
538 /* The maximum distance to look ahead for text properties. Values
539 that are too small let us call compute_char_face and similar
540 functions too often which is expensive. Values that are too large
541 let us call compute_char_face and alike too often because we
542 might not be interested in text properties that far away. */
544 #define TEXT_PROP_DISTANCE_LIMIT 100
548 /* Non-zero means print traces of redisplay if compiled with
551 int trace_redisplay_p
;
553 #endif /* GLYPH_DEBUG */
555 #ifdef DEBUG_TRACE_MOVE
556 /* Non-zero means trace with TRACE_MOVE to stderr. */
559 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
561 #define TRACE_MOVE(x) (void) 0
564 /* Non-zero means automatically scroll windows horizontally to make
567 int automatic_hscrolling_p
;
569 /* A list of symbols, one for each supported image type. */
571 Lisp_Object Vimage_types
;
573 /* The variable `resize-mini-windows'. If nil, don't resize
574 mini-windows. If t, always resize them to fit the text they
575 display. If `grow-only', let mini-windows grow only until they
578 Lisp_Object Vresize_mini_windows
;
580 /* Value returned from text property handlers (see below). */
585 HANDLED_RECOMPUTE_PROPS
,
586 HANDLED_OVERLAY_STRING_CONSUMED
,
590 /* A description of text properties that redisplay is interested
595 /* The name of the property. */
598 /* A unique index for the property. */
601 /* A handler function called to set up iterator IT from the property
602 at IT's current position. Value is used to steer handle_stop. */
603 enum prop_handled (*handler
) P_ ((struct it
*it
));
606 static enum prop_handled handle_face_prop
P_ ((struct it
*));
607 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
608 static enum prop_handled handle_display_prop
P_ ((struct it
*));
609 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
610 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
611 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
613 /* Properties handled by iterators. */
615 static struct props it_props
[] =
617 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
618 /* Handle `face' before `display' because some sub-properties of
619 `display' need to know the face. */
620 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
621 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
622 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
623 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
627 /* Value is the position described by X. If X is a marker, value is
628 the marker_position of X. Otherwise, value is X. */
630 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
632 /* Enumeration returned by some move_it_.* functions internally. */
636 /* Not used. Undefined value. */
639 /* Move ended at the requested buffer position or ZV. */
640 MOVE_POS_MATCH_OR_ZV
,
642 /* Move ended at the requested X pixel position. */
645 /* Move within a line ended at the end of a line that must be
649 /* Move within a line ended at the end of a line that would
650 be displayed truncated. */
653 /* Move within a line ended at a line end. */
659 /* Function prototypes. */
661 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
662 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
663 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
664 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
665 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
666 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
667 static int invisible_text_between_p
P_ ((struct it
*, int, int));
668 static int next_element_from_ellipsis
P_ ((struct it
*));
669 static void pint2str
P_ ((char *, int, int));
670 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
672 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
673 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
674 static void store_frame_title_char
P_ ((char));
675 static int store_frame_title
P_ ((unsigned char *, int, int));
676 static void x_consider_frame_title
P_ ((Lisp_Object
));
677 static void handle_stop
P_ ((struct it
*));
678 static int tool_bar_lines_needed
P_ ((struct frame
*));
679 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
680 static void ensure_echo_area_buffers
P_ ((void));
681 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
683 struct glyph_row
*));
684 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
685 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
686 static int with_echo_area_buffer
P_ ((struct window
*, int,
687 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
688 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
689 static void clear_garbaged_frames
P_ ((void));
690 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
691 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
692 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
693 static int display_echo_area
P_ ((struct window
*));
694 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
695 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
696 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
697 static int string_char_and_length
P_ ((unsigned char *, int, int *));
698 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
700 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
701 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
702 static void insert_left_trunc_glyphs
P_ ((struct it
*));
703 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
704 static void extend_face_to_end_of_line
P_ ((struct it
*));
705 static int append_space
P_ ((struct it
*, int));
706 static void make_cursor_line_fully_visible
P_ ((struct window
*));
707 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
708 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
709 static int trailing_whitespace_p
P_ ((int));
710 static int message_log_check_duplicate
P_ ((int, int, int, int));
711 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
712 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
713 static void push_it
P_ ((struct it
*));
714 static void pop_it
P_ ((struct it
*));
715 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
716 static void redisplay_internal
P_ ((int));
717 static int echo_area_display
P_ ((int));
718 static void redisplay_windows
P_ ((Lisp_Object
));
719 static void redisplay_window
P_ ((Lisp_Object
, int));
720 static void update_menu_bar
P_ ((struct frame
*, int));
721 static int try_window_reusing_current_matrix
P_ ((struct window
*));
722 static int try_window_id
P_ ((struct window
*));
723 static int display_line
P_ ((struct it
*));
724 static int display_mode_lines
P_ ((struct window
*));
725 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
726 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
727 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
728 static void display_menu_bar
P_ ((struct window
*));
729 static int display_count_lines
P_ ((int, int, int, int, int *));
730 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
731 int, int, struct it
*, int, int, int, int));
732 static void compute_line_metrics
P_ ((struct it
*));
733 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
734 static int get_overlay_strings
P_ ((struct it
*));
735 static void next_overlay_string
P_ ((struct it
*));
736 static void reseat
P_ ((struct it
*, struct text_pos
, int));
737 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
738 static void back_to_previous_visible_line_start
P_ ((struct it
*));
739 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
740 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
741 static int next_element_from_display_vector
P_ ((struct it
*));
742 static int next_element_from_string
P_ ((struct it
*));
743 static int next_element_from_c_string
P_ ((struct it
*));
744 static int next_element_from_buffer
P_ ((struct it
*));
745 static int next_element_from_composition
P_ ((struct it
*));
746 static int next_element_from_image
P_ ((struct it
*));
747 static int next_element_from_stretch
P_ ((struct it
*));
748 static void load_overlay_strings
P_ ((struct it
*));
749 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
750 struct display_pos
*));
751 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
752 Lisp_Object
, int, int, int, int));
753 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
755 void move_it_vertically_backward
P_ ((struct it
*, int));
756 static void init_to_row_start
P_ ((struct it
*, struct window
*,
757 struct glyph_row
*));
758 static void init_to_row_end
P_ ((struct it
*, struct window
*,
759 struct glyph_row
*));
760 static void back_to_previous_line_start
P_ ((struct it
*));
761 static int forward_to_next_line_start
P_ ((struct it
*, int *));
762 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
764 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
765 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
766 static int number_of_chars
P_ ((unsigned char *, int));
767 static void compute_stop_pos
P_ ((struct it
*));
768 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
770 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
771 static int next_overlay_change
P_ ((int));
772 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
773 Lisp_Object
, struct text_pos
*,
775 static int underlying_face_id
P_ ((struct it
*));
776 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
779 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
780 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
782 #ifdef HAVE_WINDOW_SYSTEM
784 static void update_tool_bar
P_ ((struct frame
*, int));
785 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
786 static int redisplay_tool_bar
P_ ((struct frame
*));
787 static void display_tool_bar_line
P_ ((struct it
*));
789 #endif /* HAVE_WINDOW_SYSTEM */
792 /***********************************************************************
793 Window display dimensions
794 ***********************************************************************/
796 /* Return the window-relative maximum y + 1 for glyph rows displaying
797 text in window W. This is the height of W minus the height of a
798 mode line, if any. */
801 window_text_bottom_y (w
)
804 struct frame
*f
= XFRAME (w
->frame
);
805 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
807 if (WINDOW_WANTS_MODELINE_P (w
))
808 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
813 /* Return the pixel width of display area AREA of window W. AREA < 0
814 means return the total width of W, not including bitmap areas to
815 the left and right of the window. */
818 window_box_width (w
, area
)
822 struct frame
*f
= XFRAME (w
->frame
);
823 int width
= XFASTINT (w
->width
);
825 if (!w
->pseudo_window_p
)
827 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
829 if (area
== TEXT_AREA
)
831 if (INTEGERP (w
->left_margin_width
))
832 width
-= XFASTINT (w
->left_margin_width
);
833 if (INTEGERP (w
->right_margin_width
))
834 width
-= XFASTINT (w
->right_margin_width
);
836 else if (area
== LEFT_MARGIN_AREA
)
837 width
= (INTEGERP (w
->left_margin_width
)
838 ? XFASTINT (w
->left_margin_width
) : 0);
839 else if (area
== RIGHT_MARGIN_AREA
)
840 width
= (INTEGERP (w
->right_margin_width
)
841 ? XFASTINT (w
->right_margin_width
) : 0);
844 return width
* CANON_X_UNIT (f
);
848 /* Return the pixel height of the display area of window W, not
849 including mode lines of W, if any.. */
852 window_box_height (w
)
855 struct frame
*f
= XFRAME (w
->frame
);
856 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
858 xassert (height
>= 0);
860 /* Note: the code below that determines the mode-line/header-line
861 height is essentially the same as that contained in the macro
862 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
863 the appropriate glyph row has its `mode_line_p' flag set,
864 and if it doesn't, uses estimate_mode_line_height instead. */
866 if (WINDOW_WANTS_MODELINE_P (w
))
868 struct glyph_row
*ml_row
869 = (w
->current_matrix
&& w
->current_matrix
->rows
870 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
872 if (ml_row
&& ml_row
->mode_line_p
)
873 height
-= ml_row
->height
;
875 height
-= estimate_mode_line_height (f
, MODE_LINE_FACE_ID
);
878 if (WINDOW_WANTS_HEADER_LINE_P (w
))
880 struct glyph_row
*hl_row
881 = (w
->current_matrix
&& w
->current_matrix
->rows
882 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
884 if (hl_row
&& hl_row
->mode_line_p
)
885 height
-= hl_row
->height
;
887 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
894 /* Return the frame-relative coordinate of the left edge of display
895 area AREA of window W. AREA < 0 means return the left edge of the
896 whole window, to the right of any bitmap area at the left side of
900 window_box_left (w
, area
)
904 struct frame
*f
= XFRAME (w
->frame
);
905 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
907 if (!w
->pseudo_window_p
)
909 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
910 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
912 if (area
== TEXT_AREA
)
913 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
914 else if (area
== RIGHT_MARGIN_AREA
)
915 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
916 + window_box_width (w
, TEXT_AREA
));
923 /* Return the frame-relative coordinate of the right edge of display
924 area AREA of window W. AREA < 0 means return the left edge of the
925 whole window, to the left of any bitmap area at the right side of
929 window_box_right (w
, area
)
933 return window_box_left (w
, area
) + window_box_width (w
, area
);
937 /* Get the bounding box of the display area AREA of window W, without
938 mode lines, in frame-relative coordinates. AREA < 0 means the
939 whole window, not including bitmap areas to the left and right of
940 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
941 coordinates of the upper-left corner of the box. Return in
942 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
945 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
948 int *box_x
, *box_y
, *box_width
, *box_height
;
950 struct frame
*f
= XFRAME (w
->frame
);
952 *box_width
= window_box_width (w
, area
);
953 *box_height
= window_box_height (w
);
954 *box_x
= window_box_left (w
, area
);
955 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
956 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
957 if (WINDOW_WANTS_HEADER_LINE_P (w
))
958 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
962 /* Get the bounding box of the display area AREA of window W, without
963 mode lines. AREA < 0 means the whole window, not including bitmap
964 areas to the left and right of the window. Return in *TOP_LEFT_X
965 and TOP_LEFT_Y the frame-relative pixel coordinates of the
966 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
967 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
971 window_box_edges (w
, area
, top_left_x
, top_left_y
,
972 bottom_right_x
, bottom_right_y
)
975 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
977 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
979 *bottom_right_x
+= *top_left_x
;
980 *bottom_right_y
+= *top_left_y
;
985 /***********************************************************************
987 ***********************************************************************/
989 /* Return the bottom y-position of the line the iterator IT is in.
990 This can modify IT's settings. */
996 int line_height
= it
->max_ascent
+ it
->max_descent
;
997 int line_top_y
= it
->current_y
;
999 if (line_height
== 0)
1002 line_height
= last_height
;
1003 else if (IT_CHARPOS (*it
) < ZV
)
1005 move_it_by_lines (it
, 1, 1);
1006 line_height
= (it
->max_ascent
|| it
->max_descent
1007 ? it
->max_ascent
+ it
->max_descent
1012 struct glyph_row
*row
= it
->glyph_row
;
1014 /* Use the default character height. */
1015 it
->glyph_row
= NULL
;
1016 it
->what
= IT_CHARACTER
;
1019 PRODUCE_GLYPHS (it
);
1020 line_height
= it
->ascent
+ it
->descent
;
1021 it
->glyph_row
= row
;
1025 return line_top_y
+ line_height
;
1029 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1030 1 if POS is visible and the line containing POS is fully visible.
1031 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1032 and header-lines heights. */
1035 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1037 int charpos
, *fully
, exact_mode_line_heights_p
;
1040 struct text_pos top
;
1042 struct buffer
*old_buffer
= NULL
;
1044 if (XBUFFER (w
->buffer
) != current_buffer
)
1046 old_buffer
= current_buffer
;
1047 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1050 *fully
= visible_p
= 0;
1051 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1053 /* Compute exact mode line heights, if requested. */
1054 if (exact_mode_line_heights_p
)
1056 if (WINDOW_WANTS_MODELINE_P (w
))
1057 current_mode_line_height
1058 = display_mode_line (w
, MODE_LINE_FACE_ID
,
1059 current_buffer
->mode_line_format
);
1061 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1062 current_header_line_height
1063 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1064 current_buffer
->header_line_format
);
1067 start_display (&it
, w
, top
);
1068 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1069 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1071 /* Note that we may overshoot because of invisible text. */
1072 if (IT_CHARPOS (it
) >= charpos
)
1074 int top_y
= it
.current_y
;
1075 int bottom_y
= line_bottom_y (&it
);
1076 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1078 if (top_y
< window_top_y
)
1079 visible_p
= bottom_y
> window_top_y
;
1080 else if (top_y
< it
.last_visible_y
)
1083 *fully
= bottom_y
<= it
.last_visible_y
;
1086 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1088 move_it_by_lines (&it
, 1, 0);
1089 if (charpos
< IT_CHARPOS (it
))
1097 set_buffer_internal_1 (old_buffer
);
1099 current_header_line_height
= current_mode_line_height
= -1;
1104 /* Return the next character from STR which is MAXLEN bytes long.
1105 Return in *LEN the length of the character. This is like
1106 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1107 we find one, we return a `?', but with the length of the invalid
1111 string_char_and_length (str
, maxlen
, len
)
1117 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1118 if (!CHAR_VALID_P (c
, 1))
1119 /* We may not change the length here because other places in Emacs
1120 don't use this function, i.e. they silently accept invalid
1129 /* Given a position POS containing a valid character and byte position
1130 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1132 static struct text_pos
1133 string_pos_nchars_ahead (pos
, string
, nchars
)
1134 struct text_pos pos
;
1138 xassert (STRINGP (string
) && nchars
>= 0);
1140 if (STRING_MULTIBYTE (string
))
1142 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
1143 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
1148 string_char_and_length (p
, rest
, &len
);
1149 p
+= len
, rest
-= len
;
1150 xassert (rest
>= 0);
1152 BYTEPOS (pos
) += len
;
1156 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1162 /* Value is the text position, i.e. character and byte position,
1163 for character position CHARPOS in STRING. */
1165 static INLINE
struct text_pos
1166 string_pos (charpos
, string
)
1170 struct text_pos pos
;
1171 xassert (STRINGP (string
));
1172 xassert (charpos
>= 0);
1173 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1178 /* Value is a text position, i.e. character and byte position, for
1179 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1180 means recognize multibyte characters. */
1182 static struct text_pos
1183 c_string_pos (charpos
, s
, multibyte_p
)
1188 struct text_pos pos
;
1190 xassert (s
!= NULL
);
1191 xassert (charpos
>= 0);
1195 int rest
= strlen (s
), len
;
1197 SET_TEXT_POS (pos
, 0, 0);
1200 string_char_and_length (s
, rest
, &len
);
1201 s
+= len
, rest
-= len
;
1202 xassert (rest
>= 0);
1204 BYTEPOS (pos
) += len
;
1208 SET_TEXT_POS (pos
, charpos
, charpos
);
1214 /* Value is the number of characters in C string S. MULTIBYTE_P
1215 non-zero means recognize multibyte characters. */
1218 number_of_chars (s
, multibyte_p
)
1226 int rest
= strlen (s
), len
;
1227 unsigned char *p
= (unsigned char *) s
;
1229 for (nchars
= 0; rest
> 0; ++nchars
)
1231 string_char_and_length (p
, rest
, &len
);
1232 rest
-= len
, p
+= len
;
1236 nchars
= strlen (s
);
1242 /* Compute byte position NEWPOS->bytepos corresponding to
1243 NEWPOS->charpos. POS is a known position in string STRING.
1244 NEWPOS->charpos must be >= POS.charpos. */
1247 compute_string_pos (newpos
, pos
, string
)
1248 struct text_pos
*newpos
, pos
;
1251 xassert (STRINGP (string
));
1252 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1254 if (STRING_MULTIBYTE (string
))
1255 *newpos
= string_pos_nchars_ahead (pos
, string
,
1256 CHARPOS (*newpos
) - CHARPOS (pos
));
1258 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1263 /***********************************************************************
1264 Lisp form evaluation
1265 ***********************************************************************/
1267 /* Error handler for safe_eval and safe_call. */
1270 safe_eval_handler (arg
)
1273 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1278 /* Evaluate SEXPR and return the result, or nil if something went
1287 if (inhibit_eval_during_redisplay
)
1291 int count
= BINDING_STACK_SIZE ();
1292 struct gcpro gcpro1
;
1295 specbind (Qinhibit_redisplay
, Qt
);
1296 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
1299 val
= unbind_to (count
, val
);
1306 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1307 Return the result, or nil if something went wrong. */
1310 safe_call (nargs
, args
)
1316 if (inhibit_eval_during_redisplay
)
1320 int count
= BINDING_STACK_SIZE ();
1321 struct gcpro gcpro1
;
1324 gcpro1
.nvars
= nargs
;
1325 specbind (Qinhibit_redisplay
, Qt
);
1326 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1329 val
= unbind_to (count
, val
);
1336 /* Call function FN with one argument ARG.
1337 Return the result, or nil if something went wrong. */
1340 safe_call1 (fn
, arg
)
1341 Lisp_Object fn
, arg
;
1343 Lisp_Object args
[2];
1346 return safe_call (2, args
);
1351 /***********************************************************************
1353 ***********************************************************************/
1357 /* Define CHECK_IT to perform sanity checks on iterators.
1358 This is for debugging. It is too slow to do unconditionally. */
1364 if (it
->method
== next_element_from_string
)
1366 xassert (STRINGP (it
->string
));
1367 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1369 else if (it
->method
== next_element_from_buffer
)
1371 /* Check that character and byte positions agree. */
1372 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1376 xassert (it
->current
.dpvec_index
>= 0);
1378 xassert (it
->current
.dpvec_index
< 0);
1381 #define CHECK_IT(IT) check_it ((IT))
1385 #define CHECK_IT(IT) (void) 0
1392 /* Check that the window end of window W is what we expect it
1393 to be---the last row in the current matrix displaying text. */
1396 check_window_end (w
)
1399 if (!MINI_WINDOW_P (w
)
1400 && !NILP (w
->window_end_valid
))
1402 struct glyph_row
*row
;
1403 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1404 XFASTINT (w
->window_end_vpos
)),
1406 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1407 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1411 #define CHECK_WINDOW_END(W) check_window_end ((W))
1413 #else /* not GLYPH_DEBUG */
1415 #define CHECK_WINDOW_END(W) (void) 0
1417 #endif /* not GLYPH_DEBUG */
1421 /***********************************************************************
1422 Iterator initialization
1423 ***********************************************************************/
1425 /* Initialize IT for displaying current_buffer in window W, starting
1426 at character position CHARPOS. CHARPOS < 0 means that no buffer
1427 position is specified which is useful when the iterator is assigned
1428 a position later. BYTEPOS is the byte position corresponding to
1429 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1431 If ROW is not null, calls to produce_glyphs with IT as parameter
1432 will produce glyphs in that row.
1434 BASE_FACE_ID is the id of a base face to use. It must be one of
1435 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1436 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1437 displaying the tool-bar.
1439 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1440 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1441 corresponding mode line glyph row of the desired matrix of W. */
1444 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1447 int charpos
, bytepos
;
1448 struct glyph_row
*row
;
1449 enum face_id base_face_id
;
1451 int highlight_region_p
;
1453 /* Some precondition checks. */
1454 xassert (w
!= NULL
&& it
!= NULL
);
1455 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1457 /* If face attributes have been changed since the last redisplay,
1458 free realized faces now because they depend on face definitions
1459 that might have changed. */
1460 if (face_change_count
)
1462 face_change_count
= 0;
1463 free_all_realized_faces (Qnil
);
1466 /* Use one of the mode line rows of W's desired matrix if
1470 if (base_face_id
== MODE_LINE_FACE_ID
)
1471 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1472 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1473 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1477 bzero (it
, sizeof *it
);
1478 it
->current
.overlay_string_index
= -1;
1479 it
->current
.dpvec_index
= -1;
1480 it
->base_face_id
= base_face_id
;
1482 /* The window in which we iterate over current_buffer: */
1483 XSETWINDOW (it
->window
, w
);
1485 it
->f
= XFRAME (w
->frame
);
1487 /* Extra space between lines (on window systems only). */
1488 if (base_face_id
== DEFAULT_FACE_ID
1489 && FRAME_WINDOW_P (it
->f
))
1491 if (NATNUMP (current_buffer
->extra_line_spacing
))
1492 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1493 else if (it
->f
->extra_line_spacing
> 0)
1494 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1497 /* If realized faces have been removed, e.g. because of face
1498 attribute changes of named faces, recompute them. When running
1499 in batch mode, the face cache of Vterminal_frame is null. If
1500 we happen to get called, make a dummy face cache. */
1505 FRAME_FACE_CACHE (it
->f
) == NULL
)
1506 init_frame_faces (it
->f
);
1507 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1508 recompute_basic_faces (it
->f
);
1510 /* Current value of the `space-width', and 'height' properties. */
1511 it
->space_width
= Qnil
;
1512 it
->font_height
= Qnil
;
1514 /* Are control characters displayed as `^C'? */
1515 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1517 /* -1 means everything between a CR and the following line end
1518 is invisible. >0 means lines indented more than this value are
1520 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1521 ? XFASTINT (current_buffer
->selective_display
)
1522 : (!NILP (current_buffer
->selective_display
)
1524 it
->selective_display_ellipsis_p
1525 = !NILP (current_buffer
->selective_display_ellipses
);
1527 /* Display table to use. */
1528 it
->dp
= window_display_table (w
);
1530 /* Are multibyte characters enabled in current_buffer? */
1531 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1533 /* Non-zero if we should highlight the region. */
1535 = (!NILP (Vtransient_mark_mode
)
1536 && !NILP (current_buffer
->mark_active
)
1537 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1539 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1540 start and end of a visible region in window IT->w. Set both to
1541 -1 to indicate no region. */
1542 if (highlight_region_p
1543 /* Maybe highlight only in selected window. */
1544 && (/* Either show region everywhere. */
1545 highlight_nonselected_windows
1546 /* Or show region in the selected window. */
1547 || w
== XWINDOW (selected_window
)
1548 /* Or show the region if we are in the mini-buffer and W is
1549 the window the mini-buffer refers to. */
1550 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1551 && WINDOWP (Vminibuf_scroll_window
)
1552 && w
== XWINDOW (Vminibuf_scroll_window
))))
1554 int charpos
= marker_position (current_buffer
->mark
);
1555 it
->region_beg_charpos
= min (PT
, charpos
);
1556 it
->region_end_charpos
= max (PT
, charpos
);
1559 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1561 /* Get the position at which the redisplay_end_trigger hook should
1562 be run, if it is to be run at all. */
1563 if (MARKERP (w
->redisplay_end_trigger
)
1564 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1565 it
->redisplay_end_trigger_charpos
1566 = marker_position (w
->redisplay_end_trigger
);
1567 else if (INTEGERP (w
->redisplay_end_trigger
))
1568 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1570 /* Correct bogus values of tab_width. */
1571 it
->tab_width
= XINT (current_buffer
->tab_width
);
1572 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1575 /* Are lines in the display truncated? */
1576 it
->truncate_lines_p
1577 = (base_face_id
!= DEFAULT_FACE_ID
1578 || XINT (it
->w
->hscroll
)
1579 || (truncate_partial_width_windows
1580 && !WINDOW_FULL_WIDTH_P (it
->w
))
1581 || !NILP (current_buffer
->truncate_lines
));
1583 /* Get dimensions of truncation and continuation glyphs. These are
1584 displayed as bitmaps under X, so we don't need them for such
1586 if (!FRAME_WINDOW_P (it
->f
))
1588 if (it
->truncate_lines_p
)
1590 /* We will need the truncation glyph. */
1591 xassert (it
->glyph_row
== NULL
);
1592 produce_special_glyphs (it
, IT_TRUNCATION
);
1593 it
->truncation_pixel_width
= it
->pixel_width
;
1597 /* We will need the continuation glyph. */
1598 xassert (it
->glyph_row
== NULL
);
1599 produce_special_glyphs (it
, IT_CONTINUATION
);
1600 it
->continuation_pixel_width
= it
->pixel_width
;
1603 /* Reset these values to zero becaue the produce_special_glyphs
1604 above has changed them. */
1605 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1606 it
->phys_ascent
= it
->phys_descent
= 0;
1609 /* Set this after getting the dimensions of truncation and
1610 continuation glyphs, so that we don't produce glyphs when calling
1611 produce_special_glyphs, above. */
1612 it
->glyph_row
= row
;
1613 it
->area
= TEXT_AREA
;
1615 /* Get the dimensions of the display area. The display area
1616 consists of the visible window area plus a horizontally scrolled
1617 part to the left of the window. All x-values are relative to the
1618 start of this total display area. */
1619 if (base_face_id
!= DEFAULT_FACE_ID
)
1621 /* Mode lines, menu bar in terminal frames. */
1622 it
->first_visible_x
= 0;
1623 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1628 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1629 it
->last_visible_x
= (it
->first_visible_x
1630 + window_box_width (w
, TEXT_AREA
));
1632 /* If we truncate lines, leave room for the truncator glyph(s) at
1633 the right margin. Otherwise, leave room for the continuation
1634 glyph(s). Truncation and continuation glyphs are not inserted
1635 for window-based redisplay. */
1636 if (!FRAME_WINDOW_P (it
->f
))
1638 if (it
->truncate_lines_p
)
1639 it
->last_visible_x
-= it
->truncation_pixel_width
;
1641 it
->last_visible_x
-= it
->continuation_pixel_width
;
1644 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1645 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1648 /* Leave room for a border glyph. */
1649 if (!FRAME_WINDOW_P (it
->f
)
1650 && !WINDOW_RIGHTMOST_P (it
->w
))
1651 it
->last_visible_x
-= 1;
1653 it
->last_visible_y
= window_text_bottom_y (w
);
1655 /* For mode lines and alike, arrange for the first glyph having a
1656 left box line if the face specifies a box. */
1657 if (base_face_id
!= DEFAULT_FACE_ID
)
1661 it
->face_id
= base_face_id
;
1663 /* If we have a boxed mode line, make the first character appear
1664 with a left box line. */
1665 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1666 if (face
->box
!= FACE_NO_BOX
)
1667 it
->start_of_box_run_p
= 1;
1670 /* If a buffer position was specified, set the iterator there,
1671 getting overlays and face properties from that position. */
1674 it
->end_charpos
= ZV
;
1676 IT_CHARPOS (*it
) = charpos
;
1678 /* Compute byte position if not specified. */
1680 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1682 IT_BYTEPOS (*it
) = bytepos
;
1684 /* Compute faces etc. */
1685 reseat (it
, it
->current
.pos
, 1);
1692 /* Initialize IT for the display of window W with window start POS. */
1695 start_display (it
, w
, pos
)
1698 struct text_pos pos
;
1700 int start_at_line_beg_p
;
1701 struct glyph_row
*row
;
1702 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1705 row
= w
->desired_matrix
->rows
+ first_vpos
;
1706 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1707 first_y
= it
->current_y
;
1709 /* If window start is not at a line start, move back to the line
1710 start. This makes sure that we take continuation lines into
1712 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1713 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1714 if (!start_at_line_beg_p
)
1715 reseat_at_previous_visible_line_start (it
);
1717 /* If window start is not at a line start, skip forward to POS to
1718 get the correct continuation_lines_width and current_x. */
1719 if (!start_at_line_beg_p
)
1721 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1723 /* If lines are continued, this line may end in the middle of a
1724 multi-glyph character (e.g. a control character displayed as
1725 \003, or in the middle of an overlay string). In this case
1726 move_it_to above will not have taken us to the start of
1727 the continuation line but to the end of the continued line. */
1728 if (!it
->truncate_lines_p
)
1730 if (it
->current_x
> 0)
1732 if (it
->current
.dpvec_index
>= 0
1733 || it
->current
.overlay_string_index
>= 0)
1735 set_iterator_to_next (it
, 1);
1736 move_it_in_display_line_to (it
, -1, -1, 0);
1739 it
->continuation_lines_width
+= it
->current_x
;
1742 /* We're starting a new display line, not affected by the
1743 height of the continued line, so clear the appropriate
1744 fields in the iterator structure. */
1745 it
->max_ascent
= it
->max_descent
= 0;
1746 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1749 it
->current_y
= first_y
;
1751 it
->current_x
= it
->hpos
= 0;
1754 #if 0 /* Don't assert the following because start_display is sometimes
1755 called intentionally with a window start that is not at a
1756 line start. Please leave this code in as a comment. */
1758 /* Window start should be on a line start, now. */
1759 xassert (it
->continuation_lines_width
1760 || IT_CHARPOS (it
) == BEGV
1761 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1766 /* Return 1 if POS is a position in ellipses displayed for invisible
1767 text. W is the window we display, for text property lookup. */
1770 in_ellipses_for_invisible_text_p (pos
, w
)
1771 struct display_pos
*pos
;
1774 Lisp_Object prop
, window
;
1776 int charpos
= CHARPOS (pos
->pos
);
1778 /* If POS specifies a position in a display vector, this might
1779 be for an ellipsis displayed for invisible text. We won't
1780 get the iterator set up for delivering that ellipsis unless
1781 we make sure that it gets aware of the invisible text. */
1782 if (pos
->dpvec_index
>= 0
1783 && pos
->overlay_string_index
< 0
1784 && CHARPOS (pos
->string_pos
) < 0
1786 && (XSETWINDOW (window
, w
),
1787 prop
= Fget_char_property (make_number (charpos
),
1788 Qinvisible
, window
),
1789 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1791 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1793 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
1794 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
))
1802 /* Initialize IT for stepping through current_buffer in window W,
1803 starting at position POS that includes overlay string and display
1804 vector/ control character translation position information. */
1807 init_from_display_pos (it
, w
, pos
)
1810 struct display_pos
*pos
;
1812 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1814 /* If POS specifies a position in a display vector, this might
1815 be for an ellipsis displayed for invisible text. We won't
1816 get the iterator set up for delivering that ellipsis unless
1817 we make sure that it gets aware of the invisible text. */
1818 if (in_ellipses_for_invisible_text_p (pos
, w
))
1824 /* Keep in mind: the call to reseat in init_iterator skips invisible
1825 text, so we might end up at a position different from POS. This
1826 is only a problem when POS is a row start after a newline and an
1827 overlay starts there with an after-string, and the overlay has an
1828 invisible property. Since we don't skip invisible text in
1829 display_line and elsewhere immediately after consuming the
1830 newline before the row start, such a POS will not be in a string,
1831 but the call to init_iterator below will move us to the
1833 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1835 /* If position is within an overlay string, set up IT to
1836 the right overlay string. */
1837 if (pos
->overlay_string_index
>= 0)
1841 /* We already have the first chunk of overlay strings in
1842 IT->overlay_strings. Load more until the one for
1843 pos->overlay_string_index is in IT->overlay_strings. */
1844 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1846 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1847 it
->current
.overlay_string_index
= 0;
1850 load_overlay_strings (it
);
1851 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1855 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1856 relative_index
= (it
->current
.overlay_string_index
1857 % OVERLAY_STRING_CHUNK_SIZE
);
1858 it
->string
= it
->overlay_strings
[relative_index
];
1859 xassert (STRINGP (it
->string
));
1860 it
->current
.string_pos
= pos
->string_pos
;
1861 it
->method
= next_element_from_string
;
1863 else if (it
->current
.overlay_string_index
>= 0)
1865 /* If POS says we're already after an overlay string ending at
1866 POS, make sure to pop the iterator because it will be in
1867 front of that overlay string. When POS is ZV, we've thereby
1868 also ``processed'' overlay strings at ZV. */
1871 it
->current
.overlay_string_index
= -1;
1872 it
->method
= next_element_from_buffer
;
1873 if (CHARPOS (pos
->pos
) == ZV
)
1874 it
->overlay_strings_at_end_processed_p
= 1;
1877 if (CHARPOS (pos
->string_pos
) >= 0)
1879 /* Recorded position is not in an overlay string, but in another
1880 string. This can only be a string from a `display' property.
1881 IT should already be filled with that string. */
1882 it
->current
.string_pos
= pos
->string_pos
;
1883 xassert (STRINGP (it
->string
));
1886 /* Restore position in display vector translations, control
1887 character translations or ellipses. */
1888 if (pos
->dpvec_index
>= 0)
1890 if (it
->dpvec
== NULL
)
1891 get_next_display_element (it
);
1892 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1893 it
->current
.dpvec_index
= pos
->dpvec_index
;
1900 /* Initialize IT for stepping through current_buffer in window W
1901 starting at ROW->start. */
1904 init_to_row_start (it
, w
, row
)
1907 struct glyph_row
*row
;
1909 init_from_display_pos (it
, w
, &row
->start
);
1910 it
->continuation_lines_width
= row
->continuation_lines_width
;
1915 /* Initialize IT for stepping through current_buffer in window W
1916 starting in the line following ROW, i.e. starting at ROW->end. */
1919 init_to_row_end (it
, w
, row
)
1922 struct glyph_row
*row
;
1924 init_from_display_pos (it
, w
, &row
->end
);
1926 if (row
->continued_p
)
1927 it
->continuation_lines_width
= (row
->continuation_lines_width
1928 + row
->pixel_width
);
1935 /***********************************************************************
1937 ***********************************************************************/
1939 /* Called when IT reaches IT->stop_charpos. Handle text property and
1940 overlay changes. Set IT->stop_charpos to the next position where
1947 enum prop_handled handled
;
1948 int handle_overlay_change_p
= 1;
1952 it
->current
.dpvec_index
= -1;
1956 handled
= HANDLED_NORMALLY
;
1958 /* Call text property handlers. */
1959 for (p
= it_props
; p
->handler
; ++p
)
1961 handled
= p
->handler (it
);
1963 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1965 else if (handled
== HANDLED_RETURN
)
1967 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1968 handle_overlay_change_p
= 0;
1971 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1973 /* Don't check for overlay strings below when set to deliver
1974 characters from a display vector. */
1975 if (it
->method
== next_element_from_display_vector
)
1976 handle_overlay_change_p
= 0;
1978 /* Handle overlay changes. */
1979 if (handle_overlay_change_p
)
1980 handled
= handle_overlay_change (it
);
1982 /* Determine where to stop next. */
1983 if (handled
== HANDLED_NORMALLY
)
1984 compute_stop_pos (it
);
1987 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1991 /* Compute IT->stop_charpos from text property and overlay change
1992 information for IT's current position. */
1995 compute_stop_pos (it
)
1998 register INTERVAL iv
, next_iv
;
1999 Lisp_Object object
, limit
, position
;
2001 /* If nowhere else, stop at the end. */
2002 it
->stop_charpos
= it
->end_charpos
;
2004 if (STRINGP (it
->string
))
2006 /* Strings are usually short, so don't limit the search for
2008 object
= it
->string
;
2010 position
= make_number (IT_STRING_CHARPOS (*it
));
2016 /* If next overlay change is in front of the current stop pos
2017 (which is IT->end_charpos), stop there. Note: value of
2018 next_overlay_change is point-max if no overlay change
2020 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2021 if (charpos
< it
->stop_charpos
)
2022 it
->stop_charpos
= charpos
;
2024 /* If showing the region, we have to stop at the region
2025 start or end because the face might change there. */
2026 if (it
->region_beg_charpos
> 0)
2028 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2029 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2030 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2031 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2034 /* Set up variables for computing the stop position from text
2035 property changes. */
2036 XSETBUFFER (object
, current_buffer
);
2037 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2038 position
= make_number (IT_CHARPOS (*it
));
2042 /* Get the interval containing IT's position. Value is a null
2043 interval if there isn't such an interval. */
2044 iv
= validate_interval_range (object
, &position
, &position
, 0);
2045 if (!NULL_INTERVAL_P (iv
))
2047 Lisp_Object values_here
[LAST_PROP_IDX
];
2050 /* Get properties here. */
2051 for (p
= it_props
; p
->handler
; ++p
)
2052 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2054 /* Look for an interval following iv that has different
2056 for (next_iv
= next_interval (iv
);
2057 (!NULL_INTERVAL_P (next_iv
)
2059 || XFASTINT (limit
) > next_iv
->position
));
2060 next_iv
= next_interval (next_iv
))
2062 for (p
= it_props
; p
->handler
; ++p
)
2064 Lisp_Object new_value
;
2066 new_value
= textget (next_iv
->plist
, *p
->name
);
2067 if (!EQ (values_here
[p
->idx
], new_value
))
2075 if (!NULL_INTERVAL_P (next_iv
))
2077 if (INTEGERP (limit
)
2078 && next_iv
->position
>= XFASTINT (limit
))
2079 /* No text property change up to limit. */
2080 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2082 /* Text properties change in next_iv. */
2083 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2087 xassert (STRINGP (it
->string
)
2088 || (it
->stop_charpos
>= BEGV
2089 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2093 /* Return the position of the next overlay change after POS in
2094 current_buffer. Value is point-max if no overlay change
2095 follows. This is like `next-overlay-change' but doesn't use
2099 next_overlay_change (pos
)
2104 Lisp_Object
*overlays
;
2108 /* Get all overlays at the given position. */
2110 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2111 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2112 if (noverlays
> len
)
2115 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2116 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2119 /* If any of these overlays ends before endpos,
2120 use its ending point instead. */
2121 for (i
= 0; i
< noverlays
; ++i
)
2126 oend
= OVERLAY_END (overlays
[i
]);
2127 oendpos
= OVERLAY_POSITION (oend
);
2128 endpos
= min (endpos
, oendpos
);
2136 /***********************************************************************
2138 ***********************************************************************/
2140 /* Handle changes in the `fontified' property of the current buffer by
2141 calling hook functions from Qfontification_functions to fontify
2144 static enum prop_handled
2145 handle_fontified_prop (it
)
2148 Lisp_Object prop
, pos
;
2149 enum prop_handled handled
= HANDLED_NORMALLY
;
2151 /* Get the value of the `fontified' property at IT's current buffer
2152 position. (The `fontified' property doesn't have a special
2153 meaning in strings.) If the value is nil, call functions from
2154 Qfontification_functions. */
2155 if (!STRINGP (it
->string
)
2157 && !NILP (Vfontification_functions
)
2158 && !NILP (Vrun_hooks
)
2159 && (pos
= make_number (IT_CHARPOS (*it
)),
2160 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2163 int count
= BINDING_STACK_SIZE ();
2166 val
= Vfontification_functions
;
2167 specbind (Qfontification_functions
, Qnil
);
2168 specbind (Qafter_change_functions
, Qnil
);
2170 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2171 safe_call1 (val
, pos
);
2174 Lisp_Object globals
, fn
;
2175 struct gcpro gcpro1
, gcpro2
;
2178 GCPRO2 (val
, globals
);
2180 for (; CONSP (val
); val
= XCDR (val
))
2186 /* A value of t indicates this hook has a local
2187 binding; it means to run the global binding too.
2188 In a global value, t should not occur. If it
2189 does, we must ignore it to avoid an endless
2191 for (globals
= Fdefault_value (Qfontification_functions
);
2193 globals
= XCDR (globals
))
2195 fn
= XCAR (globals
);
2197 safe_call1 (fn
, pos
);
2201 safe_call1 (fn
, pos
);
2207 unbind_to (count
, Qnil
);
2209 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2210 something. This avoids an endless loop if they failed to
2211 fontify the text for which reason ever. */
2212 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2213 handled
= HANDLED_RECOMPUTE_PROPS
;
2221 /***********************************************************************
2223 ***********************************************************************/
2225 /* Set up iterator IT from face properties at its current position.
2226 Called from handle_stop. */
2228 static enum prop_handled
2229 handle_face_prop (it
)
2232 int new_face_id
, next_stop
;
2234 if (!STRINGP (it
->string
))
2237 = face_at_buffer_position (it
->w
,
2239 it
->region_beg_charpos
,
2240 it
->region_end_charpos
,
2243 + TEXT_PROP_DISTANCE_LIMIT
),
2246 /* Is this a start of a run of characters with box face?
2247 Caveat: this can be called for a freshly initialized
2248 iterator; face_id is -1 is this case. We know that the new
2249 face will not change until limit, i.e. if the new face has a
2250 box, all characters up to limit will have one. But, as
2251 usual, we don't know whether limit is really the end. */
2252 if (new_face_id
!= it
->face_id
)
2254 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2256 /* If new face has a box but old face has not, this is
2257 the start of a run of characters with box, i.e. it has
2258 a shadow on the left side. The value of face_id of the
2259 iterator will be -1 if this is the initial call that gets
2260 the face. In this case, we have to look in front of IT's
2261 position and see whether there is a face != new_face_id. */
2262 it
->start_of_box_run_p
2263 = (new_face
->box
!= FACE_NO_BOX
2264 && (it
->face_id
>= 0
2265 || IT_CHARPOS (*it
) == BEG
2266 || new_face_id
!= face_before_it_pos (it
)));
2267 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2272 int base_face_id
, bufpos
;
2274 if (it
->current
.overlay_string_index
>= 0)
2275 bufpos
= IT_CHARPOS (*it
);
2279 /* For strings from a buffer, i.e. overlay strings or strings
2280 from a `display' property, use the face at IT's current
2281 buffer position as the base face to merge with, so that
2282 overlay strings appear in the same face as surrounding
2283 text, unless they specify their own faces. */
2284 base_face_id
= underlying_face_id (it
);
2286 new_face_id
= face_at_string_position (it
->w
,
2288 IT_STRING_CHARPOS (*it
),
2290 it
->region_beg_charpos
,
2291 it
->region_end_charpos
,
2295 #if 0 /* This shouldn't be neccessary. Let's check it. */
2296 /* If IT is used to display a mode line we would really like to
2297 use the mode line face instead of the frame's default face. */
2298 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2299 && new_face_id
== DEFAULT_FACE_ID
)
2300 new_face_id
= MODE_LINE_FACE_ID
;
2303 /* Is this a start of a run of characters with box? Caveat:
2304 this can be called for a freshly allocated iterator; face_id
2305 is -1 is this case. We know that the new face will not
2306 change until the next check pos, i.e. if the new face has a
2307 box, all characters up to that position will have a
2308 box. But, as usual, we don't know whether that position
2309 is really the end. */
2310 if (new_face_id
!= it
->face_id
)
2312 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2313 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2315 /* If new face has a box but old face hasn't, this is the
2316 start of a run of characters with box, i.e. it has a
2317 shadow on the left side. */
2318 it
->start_of_box_run_p
2319 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2320 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2324 it
->face_id
= new_face_id
;
2325 return HANDLED_NORMALLY
;
2329 /* Return the ID of the face ``underlying'' IT's current position,
2330 which is in a string. If the iterator is associated with a
2331 buffer, return the face at IT's current buffer position.
2332 Otherwise, use the iterator's base_face_id. */
2335 underlying_face_id (it
)
2338 int face_id
= it
->base_face_id
, i
;
2340 xassert (STRINGP (it
->string
));
2342 for (i
= it
->sp
- 1; i
>= 0; --i
)
2343 if (NILP (it
->stack
[i
].string
))
2344 face_id
= it
->stack
[i
].face_id
;
2350 /* Compute the face one character before or after the current position
2351 of IT. BEFORE_P non-zero means get the face in front of IT's
2352 position. Value is the id of the face. */
2355 face_before_or_after_it_pos (it
, before_p
)
2360 int next_check_charpos
;
2361 struct text_pos pos
;
2363 xassert (it
->s
== NULL
);
2365 if (STRINGP (it
->string
))
2367 int bufpos
, base_face_id
;
2369 /* No face change past the end of the string (for the case
2370 we are padding with spaces). No face change before the
2372 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2373 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2376 /* Set pos to the position before or after IT's current position. */
2378 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2380 /* For composition, we must check the character after the
2382 pos
= (it
->what
== IT_COMPOSITION
2383 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2384 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2386 if (it
->current
.overlay_string_index
>= 0)
2387 bufpos
= IT_CHARPOS (*it
);
2391 base_face_id
= underlying_face_id (it
);
2393 /* Get the face for ASCII, or unibyte. */
2394 face_id
= face_at_string_position (it
->w
,
2398 it
->region_beg_charpos
,
2399 it
->region_end_charpos
,
2400 &next_check_charpos
,
2403 /* Correct the face for charsets different from ASCII. Do it
2404 for the multibyte case only. The face returned above is
2405 suitable for unibyte text if IT->string is unibyte. */
2406 if (STRING_MULTIBYTE (it
->string
))
2408 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2409 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2411 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2413 c
= string_char_and_length (p
, rest
, &len
);
2414 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2419 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2420 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2423 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2424 pos
= it
->current
.pos
;
2427 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2430 if (it
->what
== IT_COMPOSITION
)
2431 /* For composition, we must check the position after the
2433 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2435 INC_TEXT_POS (pos
, it
->multibyte_p
);
2438 /* Determine face for CHARSET_ASCII, or unibyte. */
2439 face_id
= face_at_buffer_position (it
->w
,
2441 it
->region_beg_charpos
,
2442 it
->region_end_charpos
,
2443 &next_check_charpos
,
2446 /* Correct the face for charsets different from ASCII. Do it
2447 for the multibyte case only. The face returned above is
2448 suitable for unibyte text if current_buffer is unibyte. */
2449 if (it
->multibyte_p
)
2451 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2452 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2453 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2462 /***********************************************************************
2464 ***********************************************************************/
2466 /* Set up iterator IT from invisible properties at its current
2467 position. Called from handle_stop. */
2469 static enum prop_handled
2470 handle_invisible_prop (it
)
2473 enum prop_handled handled
= HANDLED_NORMALLY
;
2475 if (STRINGP (it
->string
))
2477 extern Lisp_Object Qinvisible
;
2478 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2480 /* Get the value of the invisible text property at the
2481 current position. Value will be nil if there is no such
2483 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2484 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2487 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2489 handled
= HANDLED_RECOMPUTE_PROPS
;
2491 /* Get the position at which the next change of the
2492 invisible text property can be found in IT->string.
2493 Value will be nil if the property value is the same for
2494 all the rest of IT->string. */
2495 XSETINT (limit
, XSTRING (it
->string
)->size
);
2496 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2499 /* Text at current position is invisible. The next
2500 change in the property is at position end_charpos.
2501 Move IT's current position to that position. */
2502 if (INTEGERP (end_charpos
)
2503 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2505 struct text_pos old
;
2506 old
= it
->current
.string_pos
;
2507 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2508 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2512 /* The rest of the string is invisible. If this is an
2513 overlay string, proceed with the next overlay string
2514 or whatever comes and return a character from there. */
2515 if (it
->current
.overlay_string_index
>= 0)
2517 next_overlay_string (it
);
2518 /* Don't check for overlay strings when we just
2519 finished processing them. */
2520 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2524 struct Lisp_String
*s
= XSTRING (it
->string
);
2525 IT_STRING_CHARPOS (*it
) = s
->size
;
2526 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2533 int visible_p
, newpos
, next_stop
;
2534 Lisp_Object pos
, prop
;
2536 /* First of all, is there invisible text at this position? */
2537 pos
= make_number (IT_CHARPOS (*it
));
2538 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2540 /* If we are on invisible text, skip over it. */
2541 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2542 && IT_CHARPOS (*it
) < it
->end_charpos
)
2544 /* Record whether we have to display an ellipsis for the
2546 int display_ellipsis_p
2547 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2549 handled
= HANDLED_RECOMPUTE_PROPS
;
2551 /* Loop skipping over invisible text. The loop is left at
2552 ZV or with IT on the first char being visible again. */
2555 /* Try to skip some invisible text. Return value is the
2556 position reached which can be equal to IT's position
2557 if there is nothing invisible here. This skips both
2558 over invisible text properties and overlays with
2559 invisible property. */
2560 newpos
= skip_invisible (IT_CHARPOS (*it
),
2561 &next_stop
, ZV
, it
->window
);
2563 /* If we skipped nothing at all we weren't at invisible
2564 text in the first place. If everything to the end of
2565 the buffer was skipped, end the loop. */
2566 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2570 /* We skipped some characters but not necessarily
2571 all there are. Check if we ended up on visible
2572 text. Fget_char_property returns the property of
2573 the char before the given position, i.e. if we
2574 get visible_p = 1, this means that the char at
2575 newpos is visible. */
2576 pos
= make_number (newpos
);
2577 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2578 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2581 /* If we ended up on invisible text, proceed to
2582 skip starting with next_stop. */
2584 IT_CHARPOS (*it
) = next_stop
;
2588 /* The position newpos is now either ZV or on visible text. */
2589 IT_CHARPOS (*it
) = newpos
;
2590 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2592 /* Maybe return `...' next for the end of the invisible text. */
2593 if (display_ellipsis_p
)
2596 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2598 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2599 it
->dpvec
= v
->contents
;
2600 it
->dpend
= v
->contents
+ v
->size
;
2604 /* Default `...'. */
2605 it
->dpvec
= default_invis_vector
;
2606 it
->dpend
= default_invis_vector
+ 3;
2609 /* The ellipsis display does not replace the display of
2610 the character at the new position. Indicate this by
2611 setting IT->dpvec_char_len to zero. */
2612 it
->dpvec_char_len
= 0;
2614 it
->current
.dpvec_index
= 0;
2615 it
->method
= next_element_from_display_vector
;
2625 /***********************************************************************
2627 ***********************************************************************/
2629 /* Set up iterator IT from `display' property at its current position.
2630 Called from handle_stop. */
2632 static enum prop_handled
2633 handle_display_prop (it
)
2636 Lisp_Object prop
, object
;
2637 struct text_pos
*position
;
2638 int display_replaced_p
= 0;
2640 if (STRINGP (it
->string
))
2642 object
= it
->string
;
2643 position
= &it
->current
.string_pos
;
2647 object
= it
->w
->buffer
;
2648 position
= &it
->current
.pos
;
2651 /* Reset those iterator values set from display property values. */
2652 it
->font_height
= Qnil
;
2653 it
->space_width
= Qnil
;
2656 /* We don't support recursive `display' properties, i.e. string
2657 values that have a string `display' property, that have a string
2658 `display' property etc. */
2659 if (!it
->string_from_display_prop_p
)
2660 it
->area
= TEXT_AREA
;
2662 prop
= Fget_char_property (make_number (position
->charpos
),
2665 return HANDLED_NORMALLY
;
2668 && CONSP (XCAR (prop
))
2669 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2671 /* A list of sub-properties. */
2672 for (; CONSP (prop
); prop
= XCDR (prop
))
2674 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2675 position
, display_replaced_p
))
2676 display_replaced_p
= 1;
2679 else if (VECTORP (prop
))
2682 for (i
= 0; i
< ASIZE (prop
); ++i
)
2683 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2684 position
, display_replaced_p
))
2685 display_replaced_p
= 1;
2689 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2690 display_replaced_p
= 1;
2693 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2697 /* Value is the position of the end of the `display' property starting
2698 at START_POS in OBJECT. */
2700 static struct text_pos
2701 display_prop_end (it
, object
, start_pos
)
2704 struct text_pos start_pos
;
2707 struct text_pos end_pos
;
2709 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2710 Qdisplay
, object
, Qnil
);
2711 CHARPOS (end_pos
) = XFASTINT (end
);
2712 if (STRINGP (object
))
2713 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2715 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2721 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2722 is the object in which the `display' property was found. *POSITION
2723 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2724 means that we previously saw a display sub-property which already
2725 replaced text display with something else, for example an image;
2726 ignore such properties after the first one has been processed.
2728 If PROP is a `space' or `image' sub-property, set *POSITION to the
2729 end position of the `display' property.
2731 Value is non-zero something was found which replaces the display
2732 of buffer or string text. */
2735 handle_single_display_prop (it
, prop
, object
, position
,
2736 display_replaced_before_p
)
2740 struct text_pos
*position
;
2741 int display_replaced_before_p
;
2744 int replaces_text_display_p
= 0;
2747 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2748 evaluated. If the result is nil, VALUE is ignored. */
2750 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2759 if (!NILP (form
) && !EQ (form
, Qt
))
2761 struct gcpro gcpro1
;
2762 struct text_pos end_pos
, pt
;
2765 end_pos
= display_prop_end (it
, object
, *position
);
2767 /* Temporarily set point to the end position, and then evaluate
2768 the form. This makes `(eolp)' work as FORM. */
2769 if (BUFFERP (object
))
2772 BYTEPOS (pt
) = PT_BYTE
;
2773 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2776 form
= safe_eval (form
);
2778 if (BUFFERP (object
))
2779 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2787 && EQ (XCAR (prop
), Qheight
)
2788 && CONSP (XCDR (prop
)))
2790 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2793 /* `(height HEIGHT)'. */
2794 it
->font_height
= XCAR (XCDR (prop
));
2795 if (!NILP (it
->font_height
))
2797 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2798 int new_height
= -1;
2800 if (CONSP (it
->font_height
)
2801 && (EQ (XCAR (it
->font_height
), Qplus
)
2802 || EQ (XCAR (it
->font_height
), Qminus
))
2803 && CONSP (XCDR (it
->font_height
))
2804 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2806 /* `(+ N)' or `(- N)' where N is an integer. */
2807 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2808 if (EQ (XCAR (it
->font_height
), Qplus
))
2810 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2812 else if (FUNCTIONP (it
->font_height
))
2814 /* Call function with current height as argument.
2815 Value is the new height. */
2817 height
= safe_call1 (it
->font_height
,
2818 face
->lface
[LFACE_HEIGHT_INDEX
]);
2819 if (NUMBERP (height
))
2820 new_height
= XFLOATINT (height
);
2822 else if (NUMBERP (it
->font_height
))
2824 /* Value is a multiple of the canonical char height. */
2827 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2828 new_height
= (XFLOATINT (it
->font_height
)
2829 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2833 /* Evaluate IT->font_height with `height' bound to the
2834 current specified height to get the new height. */
2836 int count
= BINDING_STACK_SIZE ();
2838 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2839 value
= safe_eval (it
->font_height
);
2840 unbind_to (count
, Qnil
);
2842 if (NUMBERP (value
))
2843 new_height
= XFLOATINT (value
);
2847 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2850 else if (CONSP (prop
)
2851 && EQ (XCAR (prop
), Qspace_width
)
2852 && CONSP (XCDR (prop
)))
2854 /* `(space_width WIDTH)'. */
2855 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2858 value
= XCAR (XCDR (prop
));
2859 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2860 it
->space_width
= value
;
2862 else if (CONSP (prop
)
2863 && EQ (XCAR (prop
), Qraise
)
2864 && CONSP (XCDR (prop
)))
2866 /* `(raise FACTOR)'. */
2867 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2870 #ifdef HAVE_WINDOW_SYSTEM
2871 value
= XCAR (XCDR (prop
));
2872 if (NUMBERP (value
))
2874 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2875 it
->voffset
= - (XFLOATINT (value
)
2876 * (FONT_HEIGHT (face
->font
)));
2878 #endif /* HAVE_WINDOW_SYSTEM */
2880 else if (!it
->string_from_display_prop_p
)
2882 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2883 VALUE) or `((margin nil) VALUE)' or VALUE. */
2884 Lisp_Object location
, value
;
2885 struct text_pos start_pos
;
2888 /* Characters having this form of property are not displayed, so
2889 we have to find the end of the property. */
2890 start_pos
= *position
;
2891 *position
= display_prop_end (it
, object
, start_pos
);
2894 /* Let's stop at the new position and assume that all
2895 text properties change there. */
2896 it
->stop_charpos
= position
->charpos
;
2898 location
= Qunbound
;
2899 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2903 value
= XCDR (prop
);
2905 value
= XCAR (value
);
2908 if (EQ (XCAR (tem
), Qmargin
)
2909 && (tem
= XCDR (tem
),
2910 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2912 || EQ (tem
, Qleft_margin
)
2913 || EQ (tem
, Qright_margin
))))
2917 if (EQ (location
, Qunbound
))
2923 #ifdef HAVE_WINDOW_SYSTEM
2924 if (FRAME_TERMCAP_P (it
->f
))
2925 valid_p
= STRINGP (value
);
2927 valid_p
= (STRINGP (value
)
2928 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2929 || valid_image_p (value
));
2930 #else /* not HAVE_WINDOW_SYSTEM */
2931 valid_p
= STRINGP (value
);
2932 #endif /* not HAVE_WINDOW_SYSTEM */
2934 if ((EQ (location
, Qleft_margin
)
2935 || EQ (location
, Qright_margin
)
2938 && !display_replaced_before_p
)
2940 replaces_text_display_p
= 1;
2942 /* Save current settings of IT so that we can restore them
2943 when we are finished with the glyph property value. */
2946 if (NILP (location
))
2947 it
->area
= TEXT_AREA
;
2948 else if (EQ (location
, Qleft_margin
))
2949 it
->area
= LEFT_MARGIN_AREA
;
2951 it
->area
= RIGHT_MARGIN_AREA
;
2953 if (STRINGP (value
))
2956 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2957 it
->current
.overlay_string_index
= -1;
2958 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2959 it
->end_charpos
= it
->string_nchars
2960 = XSTRING (it
->string
)->size
;
2961 it
->method
= next_element_from_string
;
2962 it
->stop_charpos
= 0;
2963 it
->string_from_display_prop_p
= 1;
2964 /* Say that we haven't consumed the characters with
2965 `display' property yet. The call to pop_it in
2966 set_iterator_to_next will clean this up. */
2967 *position
= start_pos
;
2969 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2971 it
->method
= next_element_from_stretch
;
2973 it
->current
.pos
= it
->position
= start_pos
;
2975 #ifdef HAVE_WINDOW_SYSTEM
2978 it
->what
= IT_IMAGE
;
2979 it
->image_id
= lookup_image (it
->f
, value
);
2980 it
->position
= start_pos
;
2981 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2982 it
->method
= next_element_from_image
;
2984 /* Say that we haven't consumed the characters with
2985 `display' property yet. The call to pop_it in
2986 set_iterator_to_next will clean this up. */
2987 *position
= start_pos
;
2989 #endif /* HAVE_WINDOW_SYSTEM */
2992 /* Invalid property or property not supported. Restore
2993 the position to what it was before. */
2994 *position
= start_pos
;
2997 return replaces_text_display_p
;
3001 /* Check if PROP is a display sub-property value whose text should be
3002 treated as intangible. */
3005 single_display_prop_intangible_p (prop
)
3008 /* Skip over `when FORM'. */
3009 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3020 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3021 we don't need to treat text as intangible. */
3022 if (EQ (XCAR (prop
), Qmargin
))
3030 || EQ (XCAR (prop
), Qleft_margin
)
3031 || EQ (XCAR (prop
), Qright_margin
))
3035 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3039 /* Check if PROP is a display property value whose text should be
3040 treated as intangible. */
3043 display_prop_intangible_p (prop
)
3047 && CONSP (XCAR (prop
))
3048 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3050 /* A list of sub-properties. */
3051 while (CONSP (prop
))
3053 if (single_display_prop_intangible_p (XCAR (prop
)))
3058 else if (VECTORP (prop
))
3060 /* A vector of sub-properties. */
3062 for (i
= 0; i
< ASIZE (prop
); ++i
)
3063 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3067 return single_display_prop_intangible_p (prop
);
3073 /* Return 1 if PROP is a display sub-property value containing STRING. */
3076 single_display_prop_string_p (prop
, string
)
3077 Lisp_Object prop
, string
;
3079 extern Lisp_Object Qwhen
, Qmargin
;
3081 if (EQ (string
, prop
))
3084 /* Skip over `when FORM'. */
3085 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3094 /* Skip over `margin LOCATION'. */
3095 if (EQ (XCAR (prop
), Qmargin
))
3106 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3110 /* Return 1 if STRING appears in the `display' property PROP. */
3113 display_prop_string_p (prop
, string
)
3114 Lisp_Object prop
, string
;
3116 extern Lisp_Object Qwhen
, Qmargin
;
3119 && CONSP (XCAR (prop
))
3120 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3122 /* A list of sub-properties. */
3123 while (CONSP (prop
))
3125 if (single_display_prop_string_p (XCAR (prop
), string
))
3130 else if (VECTORP (prop
))
3132 /* A vector of sub-properties. */
3134 for (i
= 0; i
< ASIZE (prop
); ++i
)
3135 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3139 return single_display_prop_string_p (prop
, string
);
3145 /* Determine from which buffer position in W's buffer STRING comes
3146 from. AROUND_CHARPOS is an approximate position where it could
3147 be from. Value is the buffer position or 0 if it couldn't be
3150 W's buffer must be current.
3152 This function is necessary because we don't record buffer positions
3153 in glyphs generated from strings (to keep struct glyph small).
3154 This function may only use code that doesn't eval because it is
3155 called asynchronously from note_mouse_highlight. */
3158 string_buffer_position (w
, string
, around_charpos
)
3163 Lisp_Object around
= make_number (around_charpos
);
3164 Lisp_Object limit
, prop
, pos
;
3165 const int MAX_DISTANCE
= 1000;
3168 pos
= make_number (around_charpos
);
3169 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3170 while (!found
&& !EQ (pos
, limit
))
3172 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3173 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3176 pos
= Fnext_single_property_change (pos
, Qdisplay
, Qnil
, limit
);
3181 pos
= make_number (around_charpos
);
3182 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3183 while (!found
&& !EQ (pos
, limit
))
3185 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3186 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3189 pos
= Fprevious_single_property_change (pos
, Qdisplay
, Qnil
,
3194 return found
? XINT (pos
) : 0;
3199 /***********************************************************************
3200 `composition' property
3201 ***********************************************************************/
3203 /* Set up iterator IT from `composition' property at its current
3204 position. Called from handle_stop. */
3206 static enum prop_handled
3207 handle_composition_prop (it
)
3210 Lisp_Object prop
, string
;
3211 int pos
, pos_byte
, end
;
3212 enum prop_handled handled
= HANDLED_NORMALLY
;
3214 if (STRINGP (it
->string
))
3216 pos
= IT_STRING_CHARPOS (*it
);
3217 pos_byte
= IT_STRING_BYTEPOS (*it
);
3218 string
= it
->string
;
3222 pos
= IT_CHARPOS (*it
);
3223 pos_byte
= IT_BYTEPOS (*it
);
3227 /* If there's a valid composition and point is not inside of the
3228 composition (in the case that the composition is from the current
3229 buffer), draw a glyph composed from the composition components. */
3230 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3231 && COMPOSITION_VALID_P (pos
, end
, prop
)
3232 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3234 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3238 it
->method
= next_element_from_composition
;
3240 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3241 /* For a terminal, draw only the first character of the
3243 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3244 it
->len
= (STRINGP (it
->string
)
3245 ? string_char_to_byte (it
->string
, end
)
3246 : CHAR_TO_BYTE (end
)) - pos_byte
;
3247 it
->stop_charpos
= end
;
3248 handled
= HANDLED_RETURN
;
3257 /***********************************************************************
3259 ***********************************************************************/
3261 /* The following structure is used to record overlay strings for
3262 later sorting in load_overlay_strings. */
3264 struct overlay_entry
3266 Lisp_Object overlay
;
3273 /* Set up iterator IT from overlay strings at its current position.
3274 Called from handle_stop. */
3276 static enum prop_handled
3277 handle_overlay_change (it
)
3280 if (!STRINGP (it
->string
) && get_overlay_strings (it
))
3281 return HANDLED_RECOMPUTE_PROPS
;
3283 return HANDLED_NORMALLY
;
3287 /* Set up the next overlay string for delivery by IT, if there is an
3288 overlay string to deliver. Called by set_iterator_to_next when the
3289 end of the current overlay string is reached. If there are more
3290 overlay strings to display, IT->string and
3291 IT->current.overlay_string_index are set appropriately here.
3292 Otherwise IT->string is set to nil. */
3295 next_overlay_string (it
)
3298 ++it
->current
.overlay_string_index
;
3299 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3301 /* No more overlay strings. Restore IT's settings to what
3302 they were before overlay strings were processed, and
3303 continue to deliver from current_buffer. */
3305 xassert (it
->stop_charpos
>= BEGV
3306 && it
->stop_charpos
<= it
->end_charpos
);
3308 it
->current
.overlay_string_index
= -1;
3309 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3310 it
->n_overlay_strings
= 0;
3311 it
->method
= next_element_from_buffer
;
3313 /* If we're at the end of the buffer, record that we have
3314 processed the overlay strings there already, so that
3315 next_element_from_buffer doesn't try it again. */
3316 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3317 it
->overlay_strings_at_end_processed_p
= 1;
3321 /* There are more overlay strings to process. If
3322 IT->current.overlay_string_index has advanced to a position
3323 where we must load IT->overlay_strings with more strings, do
3325 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3327 if (it
->current
.overlay_string_index
&& i
== 0)
3328 load_overlay_strings (it
);
3330 /* Initialize IT to deliver display elements from the overlay
3332 it
->string
= it
->overlay_strings
[i
];
3333 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3334 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3335 it
->method
= next_element_from_string
;
3336 it
->stop_charpos
= 0;
3343 /* Compare two overlay_entry structures E1 and E2. Used as a
3344 comparison function for qsort in load_overlay_strings. Overlay
3345 strings for the same position are sorted so that
3347 1. All after-strings come in front of before-strings, except
3348 when they come from the same overlay.
3350 2. Within after-strings, strings are sorted so that overlay strings
3351 from overlays with higher priorities come first.
3353 2. Within before-strings, strings are sorted so that overlay
3354 strings from overlays with higher priorities come last.
3356 Value is analogous to strcmp. */
3360 compare_overlay_entries (e1
, e2
)
3363 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3364 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3367 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3369 /* Let after-strings appear in front of before-strings if
3370 they come from different overlays. */
3371 if (EQ (entry1
->overlay
, entry2
->overlay
))
3372 result
= entry1
->after_string_p
? 1 : -1;
3374 result
= entry1
->after_string_p
? -1 : 1;
3376 else if (entry1
->after_string_p
)
3377 /* After-strings sorted in order of decreasing priority. */
3378 result
= entry2
->priority
- entry1
->priority
;
3380 /* Before-strings sorted in order of increasing priority. */
3381 result
= entry1
->priority
- entry2
->priority
;
3387 /* Load the vector IT->overlay_strings with overlay strings from IT's
3388 current buffer position. Set IT->n_overlays to the total number of
3389 overlay strings found.
3391 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3392 a time. On entry into load_overlay_strings,
3393 IT->current.overlay_string_index gives the number of overlay
3394 strings that have already been loaded by previous calls to this
3397 IT->add_overlay_start contains an additional overlay start
3398 position to consider for taking overlay strings from, if non-zero.
3399 This position comes into play when the overlay has an `invisible'
3400 property, and both before and after-strings. When we've skipped to
3401 the end of the overlay, because of its `invisible' property, we
3402 nevertheless want its before-string to appear.
3403 IT->add_overlay_start will contain the overlay start position
3406 Overlay strings are sorted so that after-string strings come in
3407 front of before-string strings. Within before and after-strings,
3408 strings are sorted by overlay priority. See also function
3409 compare_overlay_entries. */
3412 load_overlay_strings (it
)
3415 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3416 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3419 int n
= 0, i
, j
, invis_p
;
3420 struct overlay_entry
*entries
3421 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3422 int charpos
= IT_CHARPOS (*it
);
3424 /* Append the overlay string STRING of overlay OVERLAY to vector
3425 `entries' which has size `size' and currently contains `n'
3426 elements. AFTER_P non-zero means STRING is an after-string of
3428 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3431 Lisp_Object priority; \
3435 int new_size = 2 * size; \
3436 struct overlay_entry *old = entries; \
3438 (struct overlay_entry *) alloca (new_size \
3439 * sizeof *entries); \
3440 bcopy (old, entries, size * sizeof *entries); \
3444 entries[n].string = (STRING); \
3445 entries[n].overlay = (OVERLAY); \
3446 priority = Foverlay_get ((OVERLAY), Qpriority); \
3447 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3448 entries[n].after_string_p = (AFTER_P); \
3453 /* Process overlay before the overlay center. */
3454 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3456 overlay
= XCAR (ov
);
3457 xassert (OVERLAYP (overlay
));
3458 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3459 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3464 /* Skip this overlay if it doesn't start or end at IT's current
3466 if (end
!= charpos
&& start
!= charpos
)
3469 /* Skip this overlay if it doesn't apply to IT->w. */
3470 window
= Foverlay_get (overlay
, Qwindow
);
3471 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3474 /* If the text ``under'' the overlay is invisible, both before-
3475 and after-strings from this overlay are visible; start and
3476 end position are indistinguishable. */
3477 invisible
= Foverlay_get (overlay
, Qinvisible
);
3478 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3480 /* If overlay has a non-empty before-string, record it. */
3481 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3482 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3483 && XSTRING (str
)->size
)
3484 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3486 /* If overlay has a non-empty after-string, record it. */
3487 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3488 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3489 && XSTRING (str
)->size
)
3490 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3493 /* Process overlays after the overlay center. */
3494 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3496 overlay
= XCAR (ov
);
3497 xassert (OVERLAYP (overlay
));
3498 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3499 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3501 if (start
> charpos
)
3504 /* Skip this overlay if it doesn't start or end at IT's current
3506 if (end
!= charpos
&& start
!= charpos
)
3509 /* Skip this overlay if it doesn't apply to IT->w. */
3510 window
= Foverlay_get (overlay
, Qwindow
);
3511 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3514 /* If the text ``under'' the overlay is invisible, it has a zero
3515 dimension, and both before- and after-strings apply. */
3516 invisible
= Foverlay_get (overlay
, Qinvisible
);
3517 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3519 /* If overlay has a non-empty before-string, record it. */
3520 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3521 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3522 && XSTRING (str
)->size
)
3523 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3525 /* If overlay has a non-empty after-string, record it. */
3526 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3527 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3528 && XSTRING (str
)->size
)
3529 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3532 #undef RECORD_OVERLAY_STRING
3536 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3538 /* Record the total number of strings to process. */
3539 it
->n_overlay_strings
= n
;
3541 /* IT->current.overlay_string_index is the number of overlay strings
3542 that have already been consumed by IT. Copy some of the
3543 remaining overlay strings to IT->overlay_strings. */
3545 j
= it
->current
.overlay_string_index
;
3546 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3547 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3553 /* Get the first chunk of overlay strings at IT's current buffer
3554 position. Value is non-zero if at least one overlay string was
3558 get_overlay_strings (it
)
3561 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3562 process. This fills IT->overlay_strings with strings, and sets
3563 IT->n_overlay_strings to the total number of strings to process.
3564 IT->pos.overlay_string_index has to be set temporarily to zero
3565 because load_overlay_strings needs this; it must be set to -1
3566 when no overlay strings are found because a zero value would
3567 indicate a position in the first overlay string. */
3568 it
->current
.overlay_string_index
= 0;
3569 load_overlay_strings (it
);
3571 /* If we found overlay strings, set up IT to deliver display
3572 elements from the first one. Otherwise set up IT to deliver
3573 from current_buffer. */
3574 if (it
->n_overlay_strings
)
3576 /* Make sure we know settings in current_buffer, so that we can
3577 restore meaningful values when we're done with the overlay
3579 compute_stop_pos (it
);
3580 xassert (it
->face_id
>= 0);
3582 /* Save IT's settings. They are restored after all overlay
3583 strings have been processed. */
3584 xassert (it
->sp
== 0);
3587 /* Set up IT to deliver display elements from the first overlay
3589 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3590 it
->stop_charpos
= 0;
3591 it
->string
= it
->overlay_strings
[0];
3592 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3593 xassert (STRINGP (it
->string
));
3594 it
->method
= next_element_from_string
;
3599 it
->current
.overlay_string_index
= -1;
3600 it
->method
= next_element_from_buffer
;
3605 /* Value is non-zero if we found at least one overlay string. */
3606 return STRINGP (it
->string
);
3611 /***********************************************************************
3612 Saving and restoring state
3613 ***********************************************************************/
3615 /* Save current settings of IT on IT->stack. Called, for example,
3616 before setting up IT for an overlay string, to be able to restore
3617 IT's settings to what they were after the overlay string has been
3624 struct iterator_stack_entry
*p
;
3626 xassert (it
->sp
< 2);
3627 p
= it
->stack
+ it
->sp
;
3629 p
->stop_charpos
= it
->stop_charpos
;
3630 xassert (it
->face_id
>= 0);
3631 p
->face_id
= it
->face_id
;
3632 p
->string
= it
->string
;
3633 p
->pos
= it
->current
;
3634 p
->end_charpos
= it
->end_charpos
;
3635 p
->string_nchars
= it
->string_nchars
;
3637 p
->multibyte_p
= it
->multibyte_p
;
3638 p
->space_width
= it
->space_width
;
3639 p
->font_height
= it
->font_height
;
3640 p
->voffset
= it
->voffset
;
3641 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3646 /* Restore IT's settings from IT->stack. Called, for example, when no
3647 more overlay strings must be processed, and we return to delivering
3648 display elements from a buffer, or when the end of a string from a
3649 `display' property is reached and we return to delivering display
3650 elements from an overlay string, or from a buffer. */
3656 struct iterator_stack_entry
*p
;
3658 xassert (it
->sp
> 0);
3660 p
= it
->stack
+ it
->sp
;
3661 it
->stop_charpos
= p
->stop_charpos
;
3662 it
->face_id
= p
->face_id
;
3663 it
->string
= p
->string
;
3664 it
->current
= p
->pos
;
3665 it
->end_charpos
= p
->end_charpos
;
3666 it
->string_nchars
= p
->string_nchars
;
3668 it
->multibyte_p
= p
->multibyte_p
;
3669 it
->space_width
= p
->space_width
;
3670 it
->font_height
= p
->font_height
;
3671 it
->voffset
= p
->voffset
;
3672 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3677 /***********************************************************************
3679 ***********************************************************************/
3681 /* Set IT's current position to the previous line start. */
3684 back_to_previous_line_start (it
)
3687 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3688 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3692 /* Move IT to the next line start.
3694 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3695 we skipped over part of the text (as opposed to moving the iterator
3696 continuously over the text). Otherwise, don't change the value
3699 Newlines may come from buffer text, overlay strings, or strings
3700 displayed via the `display' property. That's the reason we can't
3701 simply use find_next_newline_no_quit.
3703 Note that this function may not skip over invisible text that is so
3704 because of text properties and immediately follows a newline. If
3705 it would, function reseat_at_next_visible_line_start, when called
3706 from set_iterator_to_next, would effectively make invisible
3707 characters following a newline part of the wrong glyph row, which
3708 leads to wrong cursor motion. */
3711 forward_to_next_line_start (it
, skipped_p
)
3715 int old_selective
, newline_found_p
, n
;
3716 const int MAX_NEWLINE_DISTANCE
= 500;
3718 /* If already on a newline, just consume it to avoid unintended
3719 skipping over invisible text below. */
3720 if (it
->what
== IT_CHARACTER
3722 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3724 set_iterator_to_next (it
, 0);
3729 /* Don't handle selective display in the following. It's (a)
3730 unnecessary because it's done by the caller, and (b) leads to an
3731 infinite recursion because next_element_from_ellipsis indirectly
3732 calls this function. */
3733 old_selective
= it
->selective
;
3736 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3737 from buffer text. */
3738 for (n
= newline_found_p
= 0;
3739 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3740 n
+= STRINGP (it
->string
) ? 0 : 1)
3742 if (!get_next_display_element (it
))
3744 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3745 set_iterator_to_next (it
, 0);
3748 /* If we didn't find a newline near enough, see if we can use a
3750 if (n
== MAX_NEWLINE_DISTANCE
)
3752 int start
= IT_CHARPOS (*it
);
3753 int limit
= find_next_newline_no_quit (start
, 1);
3756 xassert (!STRINGP (it
->string
));
3758 /* If there isn't any `display' property in sight, and no
3759 overlays, we can just use the position of the newline in
3761 if (it
->stop_charpos
>= limit
3762 || ((pos
= Fnext_single_property_change (make_number (start
),
3764 Qnil
, make_number (limit
)),
3766 && next_overlay_change (start
) == ZV
))
3768 IT_CHARPOS (*it
) = limit
;
3769 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3770 *skipped_p
= newline_found_p
= 1;
3774 while (get_next_display_element (it
)
3775 && !newline_found_p
)
3777 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3778 set_iterator_to_next (it
, 0);
3783 it
->selective
= old_selective
;
3784 return newline_found_p
;
3788 /* Set IT's current position to the previous visible line start. Skip
3789 invisible text that is so either due to text properties or due to
3790 selective display. Caution: this does not change IT->current_x and
3794 back_to_previous_visible_line_start (it
)
3799 /* Go back one newline if not on BEGV already. */
3800 if (IT_CHARPOS (*it
) > BEGV
)
3801 back_to_previous_line_start (it
);
3803 /* Move over lines that are invisible because of selective display
3804 or text properties. */
3805 while (IT_CHARPOS (*it
) > BEGV
3810 /* If selective > 0, then lines indented more than that values
3812 if (it
->selective
> 0
3813 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3820 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3821 Qinvisible
, it
->window
);
3822 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3826 /* Back one more newline if the current one is invisible. */
3828 back_to_previous_line_start (it
);
3831 xassert (IT_CHARPOS (*it
) >= BEGV
);
3832 xassert (IT_CHARPOS (*it
) == BEGV
3833 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3838 /* Reseat iterator IT at the previous visible line start. Skip
3839 invisible text that is so either due to text properties or due to
3840 selective display. At the end, update IT's overlay information,
3841 face information etc. */
3844 reseat_at_previous_visible_line_start (it
)
3847 back_to_previous_visible_line_start (it
);
3848 reseat (it
, it
->current
.pos
, 1);
3853 /* Reseat iterator IT on the next visible line start in the current
3854 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3855 preceding the line start. Skip over invisible text that is so
3856 because of selective display. Compute faces, overlays etc at the
3857 new position. Note that this function does not skip over text that
3858 is invisible because of text properties. */
3861 reseat_at_next_visible_line_start (it
, on_newline_p
)
3865 int newline_found_p
, skipped_p
= 0;
3867 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3869 /* Skip over lines that are invisible because they are indented
3870 more than the value of IT->selective. */
3871 if (it
->selective
> 0)
3872 while (IT_CHARPOS (*it
) < ZV
3873 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3876 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3877 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3880 /* Position on the newline if that's what's requested. */
3881 if (on_newline_p
&& newline_found_p
)
3883 if (STRINGP (it
->string
))
3885 if (IT_STRING_CHARPOS (*it
) > 0)
3887 --IT_STRING_CHARPOS (*it
);
3888 --IT_STRING_BYTEPOS (*it
);
3891 else if (IT_CHARPOS (*it
) > BEGV
)
3895 reseat (it
, it
->current
.pos
, 0);
3899 reseat (it
, it
->current
.pos
, 0);
3906 /***********************************************************************
3907 Changing an iterator's position
3908 ***********************************************************************/
3910 /* Change IT's current position to POS in current_buffer. If FORCE_P
3911 is non-zero, always check for text properties at the new position.
3912 Otherwise, text properties are only looked up if POS >=
3913 IT->check_charpos of a property. */
3916 reseat (it
, pos
, force_p
)
3918 struct text_pos pos
;
3921 int original_pos
= IT_CHARPOS (*it
);
3923 reseat_1 (it
, pos
, 0);
3925 /* Determine where to check text properties. Avoid doing it
3926 where possible because text property lookup is very expensive. */
3928 || CHARPOS (pos
) > it
->stop_charpos
3929 || CHARPOS (pos
) < original_pos
)
3936 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3937 IT->stop_pos to POS, also. */
3940 reseat_1 (it
, pos
, set_stop_p
)
3942 struct text_pos pos
;
3945 /* Don't call this function when scanning a C string. */
3946 xassert (it
->s
== NULL
);
3948 /* POS must be a reasonable value. */
3949 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3951 it
->current
.pos
= it
->position
= pos
;
3952 XSETBUFFER (it
->object
, current_buffer
);
3953 it
->end_charpos
= ZV
;
3955 it
->current
.dpvec_index
= -1;
3956 it
->current
.overlay_string_index
= -1;
3957 IT_STRING_CHARPOS (*it
) = -1;
3958 IT_STRING_BYTEPOS (*it
) = -1;
3960 it
->method
= next_element_from_buffer
;
3962 it
->face_before_selective_p
= 0;
3965 it
->stop_charpos
= CHARPOS (pos
);
3969 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3970 If S is non-null, it is a C string to iterate over. Otherwise,
3971 STRING gives a Lisp string to iterate over.
3973 If PRECISION > 0, don't return more then PRECISION number of
3974 characters from the string.
3976 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3977 characters have been returned. FIELD_WIDTH < 0 means an infinite
3980 MULTIBYTE = 0 means disable processing of multibyte characters,
3981 MULTIBYTE > 0 means enable it,
3982 MULTIBYTE < 0 means use IT->multibyte_p.
3984 IT must be initialized via a prior call to init_iterator before
3985 calling this function. */
3988 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3993 int precision
, field_width
, multibyte
;
3995 /* No region in strings. */
3996 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3998 /* No text property checks performed by default, but see below. */
3999 it
->stop_charpos
= -1;
4001 /* Set iterator position and end position. */
4002 bzero (&it
->current
, sizeof it
->current
);
4003 it
->current
.overlay_string_index
= -1;
4004 it
->current
.dpvec_index
= -1;
4005 xassert (charpos
>= 0);
4007 /* If STRING is specified, use its multibyteness, otherwise use the
4008 setting of MULTIBYTE, if specified. */
4010 it
->multibyte_p
= multibyte
> 0;
4014 xassert (STRINGP (string
));
4015 it
->string
= string
;
4017 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
4018 it
->method
= next_element_from_string
;
4019 it
->current
.string_pos
= string_pos (charpos
, string
);
4026 /* Note that we use IT->current.pos, not it->current.string_pos,
4027 for displaying C strings. */
4028 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4029 if (it
->multibyte_p
)
4031 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4032 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4036 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4037 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4040 it
->method
= next_element_from_c_string
;
4043 /* PRECISION > 0 means don't return more than PRECISION characters
4045 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4046 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4048 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4049 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4050 FIELD_WIDTH < 0 means infinite field width. This is useful for
4051 padding with `-' at the end of a mode line. */
4052 if (field_width
< 0)
4053 field_width
= INFINITY
;
4054 if (field_width
> it
->end_charpos
- charpos
)
4055 it
->end_charpos
= charpos
+ field_width
;
4057 /* Use the standard display table for displaying strings. */
4058 if (DISP_TABLE_P (Vstandard_display_table
))
4059 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4061 it
->stop_charpos
= charpos
;
4067 /***********************************************************************
4069 ***********************************************************************/
4071 /* Load IT's display element fields with information about the next
4072 display element from the current position of IT. Value is zero if
4073 end of buffer (or C string) is reached. */
4076 get_next_display_element (it
)
4079 /* Non-zero means that we found an display element. Zero means that
4080 we hit the end of what we iterate over. Performance note: the
4081 function pointer `method' used here turns out to be faster than
4082 using a sequence of if-statements. */
4083 int success_p
= (*it
->method
) (it
);
4085 if (it
->what
== IT_CHARACTER
)
4087 /* Map via display table or translate control characters.
4088 IT->c, IT->len etc. have been set to the next character by
4089 the function call above. If we have a display table, and it
4090 contains an entry for IT->c, translate it. Don't do this if
4091 IT->c itself comes from a display table, otherwise we could
4092 end up in an infinite recursion. (An alternative could be to
4093 count the recursion depth of this function and signal an
4094 error when a certain maximum depth is reached.) Is it worth
4096 if (success_p
&& it
->dpvec
== NULL
)
4101 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4104 struct Lisp_Vector
*v
= XVECTOR (dv
);
4106 /* Return the first character from the display table
4107 entry, if not empty. If empty, don't display the
4108 current character. */
4111 it
->dpvec_char_len
= it
->len
;
4112 it
->dpvec
= v
->contents
;
4113 it
->dpend
= v
->contents
+ v
->size
;
4114 it
->current
.dpvec_index
= 0;
4115 it
->method
= next_element_from_display_vector
;
4116 success_p
= get_next_display_element (it
);
4120 set_iterator_to_next (it
, 0);
4121 success_p
= get_next_display_element (it
);
4125 /* Translate control characters into `\003' or `^C' form.
4126 Control characters coming from a display table entry are
4127 currently not translated because we use IT->dpvec to hold
4128 the translation. This could easily be changed but I
4129 don't believe that it is worth doing.
4131 Non-printable multibyte characters are also translated
4133 else if ((it
->c
< ' '
4134 && (it
->area
!= TEXT_AREA
4135 || (it
->c
!= '\n' && it
->c
!= '\t')))
4138 || !CHAR_PRINTABLE_P (it
->c
))
4140 /* IT->c is a control character which must be displayed
4141 either as '\003' or as `^C' where the '\\' and '^'
4142 can be defined in the display table. Fill
4143 IT->ctl_chars with glyphs for what we have to
4144 display. Then, set IT->dpvec to these glyphs. */
4147 if (it
->c
< 128 && it
->ctl_arrow_p
)
4149 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4151 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4152 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4153 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4155 g
= FAST_MAKE_GLYPH ('^', 0);
4156 XSETINT (it
->ctl_chars
[0], g
);
4158 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4159 XSETINT (it
->ctl_chars
[1], g
);
4161 /* Set up IT->dpvec and return first character from it. */
4162 it
->dpvec_char_len
= it
->len
;
4163 it
->dpvec
= it
->ctl_chars
;
4164 it
->dpend
= it
->dpvec
+ 2;
4165 it
->current
.dpvec_index
= 0;
4166 it
->method
= next_element_from_display_vector
;
4167 get_next_display_element (it
);
4171 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4176 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4178 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4179 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4180 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4182 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4184 if (SINGLE_BYTE_CHAR_P (it
->c
))
4185 str
[0] = it
->c
, len
= 1;
4187 len
= CHAR_STRING (it
->c
, str
);
4189 for (i
= 0; i
< len
; i
++)
4191 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4192 /* Insert three more glyphs into IT->ctl_chars for
4193 the octal display of the character. */
4194 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4195 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4196 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4197 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4198 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4199 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4202 /* Set up IT->dpvec and return the first character
4204 it
->dpvec_char_len
= it
->len
;
4205 it
->dpvec
= it
->ctl_chars
;
4206 it
->dpend
= it
->dpvec
+ len
* 4;
4207 it
->current
.dpvec_index
= 0;
4208 it
->method
= next_element_from_display_vector
;
4209 get_next_display_element (it
);
4214 /* Adjust face id for a multibyte character. There are no
4215 multibyte character in unibyte text. */
4218 && FRAME_WINDOW_P (it
->f
))
4220 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4221 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4225 /* Is this character the last one of a run of characters with
4226 box? If yes, set IT->end_of_box_run_p to 1. */
4233 it
->end_of_box_run_p
4234 = ((face_id
= face_after_it_pos (it
),
4235 face_id
!= it
->face_id
)
4236 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4237 face
->box
== FACE_NO_BOX
));
4240 /* Value is 0 if end of buffer or string reached. */
4245 /* Move IT to the next display element.
4247 RESEAT_P non-zero means if called on a newline in buffer text,
4248 skip to the next visible line start.
4250 Functions get_next_display_element and set_iterator_to_next are
4251 separate because I find this arrangement easier to handle than a
4252 get_next_display_element function that also increments IT's
4253 position. The way it is we can first look at an iterator's current
4254 display element, decide whether it fits on a line, and if it does,
4255 increment the iterator position. The other way around we probably
4256 would either need a flag indicating whether the iterator has to be
4257 incremented the next time, or we would have to implement a
4258 decrement position function which would not be easy to write. */
4261 set_iterator_to_next (it
, reseat_p
)
4265 /* Reset flags indicating start and end of a sequence of characters
4266 with box. Reset them at the start of this function because
4267 moving the iterator to a new position might set them. */
4268 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4270 if (it
->method
== next_element_from_buffer
)
4272 /* The current display element of IT is a character from
4273 current_buffer. Advance in the buffer, and maybe skip over
4274 invisible lines that are so because of selective display. */
4275 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4276 reseat_at_next_visible_line_start (it
, 0);
4279 xassert (it
->len
!= 0);
4280 IT_BYTEPOS (*it
) += it
->len
;
4281 IT_CHARPOS (*it
) += 1;
4282 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4285 else if (it
->method
== next_element_from_composition
)
4287 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4288 if (STRINGP (it
->string
))
4290 IT_STRING_BYTEPOS (*it
) += it
->len
;
4291 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4292 it
->method
= next_element_from_string
;
4293 goto consider_string_end
;
4297 IT_BYTEPOS (*it
) += it
->len
;
4298 IT_CHARPOS (*it
) += it
->cmp_len
;
4299 it
->method
= next_element_from_buffer
;
4302 else if (it
->method
== next_element_from_c_string
)
4304 /* Current display element of IT is from a C string. */
4305 IT_BYTEPOS (*it
) += it
->len
;
4306 IT_CHARPOS (*it
) += 1;
4308 else if (it
->method
== next_element_from_display_vector
)
4310 /* Current display element of IT is from a display table entry.
4311 Advance in the display table definition. Reset it to null if
4312 end reached, and continue with characters from buffers/
4314 ++it
->current
.dpvec_index
;
4316 /* Restore face of the iterator to what they were before the
4317 display vector entry (these entries may contain faces). */
4318 it
->face_id
= it
->saved_face_id
;
4320 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4323 it
->method
= next_element_from_c_string
;
4324 else if (STRINGP (it
->string
))
4325 it
->method
= next_element_from_string
;
4327 it
->method
= next_element_from_buffer
;
4330 it
->current
.dpvec_index
= -1;
4332 /* Skip over characters which were displayed via IT->dpvec. */
4333 if (it
->dpvec_char_len
< 0)
4334 reseat_at_next_visible_line_start (it
, 1);
4335 else if (it
->dpvec_char_len
> 0)
4337 it
->len
= it
->dpvec_char_len
;
4338 set_iterator_to_next (it
, reseat_p
);
4342 else if (it
->method
== next_element_from_string
)
4344 /* Current display element is a character from a Lisp string. */
4345 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4346 IT_STRING_BYTEPOS (*it
) += it
->len
;
4347 IT_STRING_CHARPOS (*it
) += 1;
4349 consider_string_end
:
4351 if (it
->current
.overlay_string_index
>= 0)
4353 /* IT->string is an overlay string. Advance to the
4354 next, if there is one. */
4355 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4356 next_overlay_string (it
);
4360 /* IT->string is not an overlay string. If we reached
4361 its end, and there is something on IT->stack, proceed
4362 with what is on the stack. This can be either another
4363 string, this time an overlay string, or a buffer. */
4364 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4368 if (!STRINGP (it
->string
))
4369 it
->method
= next_element_from_buffer
;
4373 else if (it
->method
== next_element_from_image
4374 || it
->method
== next_element_from_stretch
)
4376 /* The position etc with which we have to proceed are on
4377 the stack. The position may be at the end of a string,
4378 if the `display' property takes up the whole string. */
4381 if (STRINGP (it
->string
))
4383 it
->method
= next_element_from_string
;
4384 goto consider_string_end
;
4387 it
->method
= next_element_from_buffer
;
4390 /* There are no other methods defined, so this should be a bug. */
4393 xassert (it
->method
!= next_element_from_string
4394 || (STRINGP (it
->string
)
4395 && IT_STRING_CHARPOS (*it
) >= 0));
4399 /* Load IT's display element fields with information about the next
4400 display element which comes from a display table entry or from the
4401 result of translating a control character to one of the forms `^C'
4402 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4405 next_element_from_display_vector (it
)
4409 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4411 /* Remember the current face id in case glyphs specify faces.
4412 IT's face is restored in set_iterator_to_next. */
4413 it
->saved_face_id
= it
->face_id
;
4415 if (INTEGERP (*it
->dpvec
)
4416 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4421 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4422 it
->c
= FAST_GLYPH_CHAR (g
);
4423 it
->len
= CHAR_BYTES (it
->c
);
4425 /* The entry may contain a face id to use. Such a face id is
4426 the id of a Lisp face, not a realized face. A face id of
4427 zero means no face is specified. */
4428 lface_id
= FAST_GLYPH_FACE (g
);
4431 /* The function returns -1 if lface_id is invalid. */
4432 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4434 it
->face_id
= face_id
;
4438 /* Display table entry is invalid. Return a space. */
4439 it
->c
= ' ', it
->len
= 1;
4441 /* Don't change position and object of the iterator here. They are
4442 still the values of the character that had this display table
4443 entry or was translated, and that's what we want. */
4444 it
->what
= IT_CHARACTER
;
4449 /* Load IT with the next display element from Lisp string IT->string.
4450 IT->current.string_pos is the current position within the string.
4451 If IT->current.overlay_string_index >= 0, the Lisp string is an
4455 next_element_from_string (it
)
4458 struct text_pos position
;
4460 xassert (STRINGP (it
->string
));
4461 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4462 position
= it
->current
.string_pos
;
4464 /* Time to check for invisible text? */
4465 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4466 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4470 /* Since a handler may have changed IT->method, we must
4472 return get_next_display_element (it
);
4475 if (it
->current
.overlay_string_index
>= 0)
4477 /* Get the next character from an overlay string. In overlay
4478 strings, There is no field width or padding with spaces to
4480 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4485 else if (STRING_MULTIBYTE (it
->string
))
4487 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4488 - IT_STRING_BYTEPOS (*it
));
4489 unsigned char *s
= (XSTRING (it
->string
)->data
4490 + IT_STRING_BYTEPOS (*it
));
4491 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4495 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4501 /* Get the next character from a Lisp string that is not an
4502 overlay string. Such strings come from the mode line, for
4503 example. We may have to pad with spaces, or truncate the
4504 string. See also next_element_from_c_string. */
4505 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4510 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4512 /* Pad with spaces. */
4513 it
->c
= ' ', it
->len
= 1;
4514 CHARPOS (position
) = BYTEPOS (position
) = -1;
4516 else if (STRING_MULTIBYTE (it
->string
))
4518 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4519 - IT_STRING_BYTEPOS (*it
));
4520 unsigned char *s
= (XSTRING (it
->string
)->data
4521 + IT_STRING_BYTEPOS (*it
));
4522 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4526 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4531 /* Record what we have and where it came from. Note that we store a
4532 buffer position in IT->position although it could arguably be a
4534 it
->what
= IT_CHARACTER
;
4535 it
->object
= it
->string
;
4536 it
->position
= position
;
4541 /* Load IT with next display element from C string IT->s.
4542 IT->string_nchars is the maximum number of characters to return
4543 from the string. IT->end_charpos may be greater than
4544 IT->string_nchars when this function is called, in which case we
4545 may have to return padding spaces. Value is zero if end of string
4546 reached, including padding spaces. */
4549 next_element_from_c_string (it
)
4555 it
->what
= IT_CHARACTER
;
4556 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4559 /* IT's position can be greater IT->string_nchars in case a field
4560 width or precision has been specified when the iterator was
4562 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4564 /* End of the game. */
4568 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4570 /* Pad with spaces. */
4571 it
->c
= ' ', it
->len
= 1;
4572 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4574 else if (it
->multibyte_p
)
4576 /* Implementation note: The calls to strlen apparently aren't a
4577 performance problem because there is no noticeable performance
4578 difference between Emacs running in unibyte or multibyte mode. */
4579 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4580 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4584 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4590 /* Set up IT to return characters from an ellipsis, if appropriate.
4591 The definition of the ellipsis glyphs may come from a display table
4592 entry. This function Fills IT with the first glyph from the
4593 ellipsis if an ellipsis is to be displayed. */
4596 next_element_from_ellipsis (it
)
4599 if (it
->selective_display_ellipsis_p
)
4601 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4603 /* Use the display table definition for `...'. Invalid glyphs
4604 will be handled by the method returning elements from dpvec. */
4605 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4606 it
->dpvec_char_len
= it
->len
;
4607 it
->dpvec
= v
->contents
;
4608 it
->dpend
= v
->contents
+ v
->size
;
4609 it
->current
.dpvec_index
= 0;
4610 it
->method
= next_element_from_display_vector
;
4614 /* Use default `...' which is stored in default_invis_vector. */
4615 it
->dpvec_char_len
= it
->len
;
4616 it
->dpvec
= default_invis_vector
;
4617 it
->dpend
= default_invis_vector
+ 3;
4618 it
->current
.dpvec_index
= 0;
4619 it
->method
= next_element_from_display_vector
;
4624 /* The face at the current position may be different from the
4625 face we find after the invisible text. Remember what it
4626 was in IT->saved_face_id, and signal that it's there by
4627 setting face_before_selective_p. */
4628 it
->saved_face_id
= it
->face_id
;
4629 it
->method
= next_element_from_buffer
;
4630 reseat_at_next_visible_line_start (it
, 1);
4631 it
->face_before_selective_p
= 1;
4634 return get_next_display_element (it
);
4638 /* Deliver an image display element. The iterator IT is already
4639 filled with image information (done in handle_display_prop). Value
4644 next_element_from_image (it
)
4647 it
->what
= IT_IMAGE
;
4652 /* Fill iterator IT with next display element from a stretch glyph
4653 property. IT->object is the value of the text property. Value is
4657 next_element_from_stretch (it
)
4660 it
->what
= IT_STRETCH
;
4665 /* Load IT with the next display element from current_buffer. Value
4666 is zero if end of buffer reached. IT->stop_charpos is the next
4667 position at which to stop and check for text properties or buffer
4671 next_element_from_buffer (it
)
4676 /* Check this assumption, otherwise, we would never enter the
4677 if-statement, below. */
4678 xassert (IT_CHARPOS (*it
) >= BEGV
4679 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4681 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4683 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4685 int overlay_strings_follow_p
;
4687 /* End of the game, except when overlay strings follow that
4688 haven't been returned yet. */
4689 if (it
->overlay_strings_at_end_processed_p
)
4690 overlay_strings_follow_p
= 0;
4693 it
->overlay_strings_at_end_processed_p
= 1;
4694 overlay_strings_follow_p
= get_overlay_strings (it
);
4697 if (overlay_strings_follow_p
)
4698 success_p
= get_next_display_element (it
);
4702 it
->position
= it
->current
.pos
;
4709 return get_next_display_element (it
);
4714 /* No face changes, overlays etc. in sight, so just return a
4715 character from current_buffer. */
4718 /* Maybe run the redisplay end trigger hook. Performance note:
4719 This doesn't seem to cost measurable time. */
4720 if (it
->redisplay_end_trigger_charpos
4722 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4723 run_redisplay_end_trigger_hook (it
);
4725 /* Get the next character, maybe multibyte. */
4726 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4727 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4729 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4730 - IT_BYTEPOS (*it
));
4731 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4734 it
->c
= *p
, it
->len
= 1;
4736 /* Record what we have and where it came from. */
4737 it
->what
= IT_CHARACTER
;;
4738 it
->object
= it
->w
->buffer
;
4739 it
->position
= it
->current
.pos
;
4741 /* Normally we return the character found above, except when we
4742 really want to return an ellipsis for selective display. */
4747 /* A value of selective > 0 means hide lines indented more
4748 than that number of columns. */
4749 if (it
->selective
> 0
4750 && IT_CHARPOS (*it
) + 1 < ZV
4751 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4752 IT_BYTEPOS (*it
) + 1,
4755 success_p
= next_element_from_ellipsis (it
);
4756 it
->dpvec_char_len
= -1;
4759 else if (it
->c
== '\r' && it
->selective
== -1)
4761 /* A value of selective == -1 means that everything from the
4762 CR to the end of the line is invisible, with maybe an
4763 ellipsis displayed for it. */
4764 success_p
= next_element_from_ellipsis (it
);
4765 it
->dpvec_char_len
= -1;
4770 /* Value is zero if end of buffer reached. */
4771 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4776 /* Run the redisplay end trigger hook for IT. */
4779 run_redisplay_end_trigger_hook (it
)
4782 Lisp_Object args
[3];
4784 /* IT->glyph_row should be non-null, i.e. we should be actually
4785 displaying something, or otherwise we should not run the hook. */
4786 xassert (it
->glyph_row
);
4788 /* Set up hook arguments. */
4789 args
[0] = Qredisplay_end_trigger_functions
;
4790 args
[1] = it
->window
;
4791 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4792 it
->redisplay_end_trigger_charpos
= 0;
4794 /* Since we are *trying* to run these functions, don't try to run
4795 them again, even if they get an error. */
4796 it
->w
->redisplay_end_trigger
= Qnil
;
4797 Frun_hook_with_args (3, args
);
4799 /* Notice if it changed the face of the character we are on. */
4800 handle_face_prop (it
);
4804 /* Deliver a composition display element. The iterator IT is already
4805 filled with composition information (done in
4806 handle_composition_prop). Value is always 1. */
4809 next_element_from_composition (it
)
4812 it
->what
= IT_COMPOSITION
;
4813 it
->position
= (STRINGP (it
->string
)
4814 ? it
->current
.string_pos
4821 /***********************************************************************
4822 Moving an iterator without producing glyphs
4823 ***********************************************************************/
4825 /* Move iterator IT to a specified buffer or X position within one
4826 line on the display without producing glyphs.
4828 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4829 whichever is reached first.
4831 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4833 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4834 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4835 TO_X includes the amount by which a window is horizontally
4840 MOVE_POS_MATCH_OR_ZV
4841 - when TO_POS or ZV was reached.
4844 -when TO_X was reached before TO_POS or ZV were reached.
4847 - when we reached the end of the display area and the line must
4851 - when we reached the end of the display area and the line is
4855 - when we stopped at a line end, i.e. a newline or a CR and selective
4858 static enum move_it_result
4859 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4861 int to_charpos
, to_x
, op
;
4863 enum move_it_result result
= MOVE_UNDEFINED
;
4864 struct glyph_row
*saved_glyph_row
;
4866 /* Don't produce glyphs in produce_glyphs. */
4867 saved_glyph_row
= it
->glyph_row
;
4868 it
->glyph_row
= NULL
;
4872 int x
, i
, ascent
= 0, descent
= 0;
4874 /* Stop when ZV or TO_CHARPOS reached. */
4875 if (!get_next_display_element (it
)
4876 || ((op
& MOVE_TO_POS
) != 0
4877 && BUFFERP (it
->object
)
4878 && IT_CHARPOS (*it
) >= to_charpos
))
4880 result
= MOVE_POS_MATCH_OR_ZV
;
4884 /* The call to produce_glyphs will get the metrics of the
4885 display element IT is loaded with. We record in x the
4886 x-position before this display element in case it does not
4890 /* Remember the line height so far in case the next element doesn't
4892 if (!it
->truncate_lines_p
)
4894 ascent
= it
->max_ascent
;
4895 descent
= it
->max_descent
;
4898 PRODUCE_GLYPHS (it
);
4900 if (it
->area
!= TEXT_AREA
)
4902 set_iterator_to_next (it
, 1);
4906 /* The number of glyphs we get back in IT->nglyphs will normally
4907 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4908 character on a terminal frame, or (iii) a line end. For the
4909 second case, IT->nglyphs - 1 padding glyphs will be present
4910 (on X frames, there is only one glyph produced for a
4911 composite character.
4913 The behavior implemented below means, for continuation lines,
4914 that as many spaces of a TAB as fit on the current line are
4915 displayed there. For terminal frames, as many glyphs of a
4916 multi-glyph character are displayed in the current line, too.
4917 This is what the old redisplay code did, and we keep it that
4918 way. Under X, the whole shape of a complex character must
4919 fit on the line or it will be completely displayed in the
4922 Note that both for tabs and padding glyphs, all glyphs have
4926 /* More than one glyph or glyph doesn't fit on line. All
4927 glyphs have the same width. */
4928 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4931 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4933 new_x
= x
+ single_glyph_width
;
4935 /* We want to leave anything reaching TO_X to the caller. */
4936 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4939 result
= MOVE_X_REACHED
;
4942 else if (/* Lines are continued. */
4943 !it
->truncate_lines_p
4944 && (/* And glyph doesn't fit on the line. */
4945 new_x
> it
->last_visible_x
4946 /* Or it fits exactly and we're on a window
4948 || (new_x
== it
->last_visible_x
4949 && FRAME_WINDOW_P (it
->f
))))
4951 if (/* IT->hpos == 0 means the very first glyph
4952 doesn't fit on the line, e.g. a wide image. */
4954 || (new_x
== it
->last_visible_x
4955 && FRAME_WINDOW_P (it
->f
)))
4958 it
->current_x
= new_x
;
4959 if (i
== it
->nglyphs
- 1)
4960 set_iterator_to_next (it
, 1);
4965 it
->max_ascent
= ascent
;
4966 it
->max_descent
= descent
;
4969 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
4971 result
= MOVE_LINE_CONTINUED
;
4974 else if (new_x
> it
->first_visible_x
)
4976 /* Glyph is visible. Increment number of glyphs that
4977 would be displayed. */
4982 /* Glyph is completely off the left margin of the display
4983 area. Nothing to do. */
4987 if (result
!= MOVE_UNDEFINED
)
4990 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4992 /* Stop when TO_X specified and reached. This check is
4993 necessary here because of lines consisting of a line end,
4994 only. The line end will not produce any glyphs and we
4995 would never get MOVE_X_REACHED. */
4996 xassert (it
->nglyphs
== 0);
4997 result
= MOVE_X_REACHED
;
5001 /* Is this a line end? If yes, we're done. */
5002 if (ITERATOR_AT_END_OF_LINE_P (it
))
5004 result
= MOVE_NEWLINE_OR_CR
;
5008 /* The current display element has been consumed. Advance
5010 set_iterator_to_next (it
, 1);
5012 /* Stop if lines are truncated and IT's current x-position is
5013 past the right edge of the window now. */
5014 if (it
->truncate_lines_p
5015 && it
->current_x
>= it
->last_visible_x
)
5017 result
= MOVE_LINE_TRUNCATED
;
5022 /* Restore the iterator settings altered at the beginning of this
5024 it
->glyph_row
= saved_glyph_row
;
5029 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
5030 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
5031 the description of enum move_operation_enum.
5033 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5034 screen line, this function will set IT to the next position >
5038 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5040 int to_charpos
, to_x
, to_y
, to_vpos
;
5043 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5049 if (op
& MOVE_TO_VPOS
)
5051 /* If no TO_CHARPOS and no TO_X specified, stop at the
5052 start of the line TO_VPOS. */
5053 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5055 if (it
->vpos
== to_vpos
)
5061 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5065 /* TO_VPOS >= 0 means stop at TO_X in the line at
5066 TO_VPOS, or at TO_POS, whichever comes first. */
5067 if (it
->vpos
== to_vpos
)
5073 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5075 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5080 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5082 /* We have reached TO_X but not in the line we want. */
5083 skip
= move_it_in_display_line_to (it
, to_charpos
,
5085 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5093 else if (op
& MOVE_TO_Y
)
5095 struct it it_backup
;
5097 /* TO_Y specified means stop at TO_X in the line containing
5098 TO_Y---or at TO_CHARPOS if this is reached first. The
5099 problem is that we can't really tell whether the line
5100 contains TO_Y before we have completely scanned it, and
5101 this may skip past TO_X. What we do is to first scan to
5104 If TO_X is not specified, use a TO_X of zero. The reason
5105 is to make the outcome of this function more predictable.
5106 If we didn't use TO_X == 0, we would stop at the end of
5107 the line which is probably not what a caller would expect
5109 skip
= move_it_in_display_line_to (it
, to_charpos
,
5113 | (op
& MOVE_TO_POS
)));
5115 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5116 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5122 /* If TO_X was reached, we would like to know whether TO_Y
5123 is in the line. This can only be said if we know the
5124 total line height which requires us to scan the rest of
5126 if (skip
== MOVE_X_REACHED
)
5129 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5130 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5132 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5135 /* Now, decide whether TO_Y is in this line. */
5136 line_height
= it
->max_ascent
+ it
->max_descent
;
5137 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5139 if (to_y
>= it
->current_y
5140 && to_y
< it
->current_y
+ line_height
)
5142 if (skip
== MOVE_X_REACHED
)
5143 /* If TO_Y is in this line and TO_X was reached above,
5144 we scanned too far. We have to restore IT's settings
5145 to the ones before skipping. */
5149 else if (skip
== MOVE_X_REACHED
)
5152 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5160 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5164 case MOVE_POS_MATCH_OR_ZV
:
5168 case MOVE_NEWLINE_OR_CR
:
5169 set_iterator_to_next (it
, 1);
5170 it
->continuation_lines_width
= 0;
5173 case MOVE_LINE_TRUNCATED
:
5174 it
->continuation_lines_width
= 0;
5175 reseat_at_next_visible_line_start (it
, 0);
5176 if ((op
& MOVE_TO_POS
) != 0
5177 && IT_CHARPOS (*it
) > to_charpos
)
5184 case MOVE_LINE_CONTINUED
:
5185 it
->continuation_lines_width
+= it
->current_x
;
5192 /* Reset/increment for the next run. */
5193 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5194 it
->current_x
= it
->hpos
= 0;
5195 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5197 last_height
= it
->max_ascent
+ it
->max_descent
;
5198 last_max_ascent
= it
->max_ascent
;
5199 it
->max_ascent
= it
->max_descent
= 0;
5204 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5208 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5210 If DY > 0, move IT backward at least that many pixels. DY = 0
5211 means move IT backward to the preceding line start or BEGV. This
5212 function may move over more than DY pixels if IT->current_y - DY
5213 ends up in the middle of a line; in this case IT->current_y will be
5214 set to the top of the line moved to. */
5217 move_it_vertically_backward (it
, dy
)
5221 int nlines
, h
, line_height
;
5223 int start_pos
= IT_CHARPOS (*it
);
5227 /* Estimate how many newlines we must move back. */
5228 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5230 /* Set the iterator's position that many lines back. */
5231 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5232 back_to_previous_visible_line_start (it
);
5234 /* Reseat the iterator here. When moving backward, we don't want
5235 reseat to skip forward over invisible text, set up the iterator
5236 to deliver from overlay strings at the new position etc. So,
5237 use reseat_1 here. */
5238 reseat_1 (it
, it
->current
.pos
, 1);
5240 /* We are now surely at a line start. */
5241 it
->current_x
= it
->hpos
= 0;
5243 /* Move forward and see what y-distance we moved. First move to the
5244 start of the next line so that we get its height. We need this
5245 height to be able to tell whether we reached the specified
5248 it2
.max_ascent
= it2
.max_descent
= 0;
5249 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5250 MOVE_TO_POS
| MOVE_TO_VPOS
);
5251 xassert (IT_CHARPOS (*it
) >= BEGV
);
5252 line_height
= it2
.max_ascent
+ it2
.max_descent
;
5254 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5255 xassert (IT_CHARPOS (*it
) >= BEGV
);
5256 h
= it2
.current_y
- it
->current_y
;
5257 nlines
= it2
.vpos
- it
->vpos
;
5259 /* Correct IT's y and vpos position. */
5265 /* DY == 0 means move to the start of the screen line. The
5266 value of nlines is > 0 if continuation lines were involved. */
5268 move_it_by_lines (it
, nlines
, 1);
5269 xassert (IT_CHARPOS (*it
) <= start_pos
);
5273 /* The y-position we try to reach. Note that h has been
5274 subtracted in front of the if-statement. */
5275 int target_y
= it
->current_y
+ h
- dy
;
5277 /* If we did not reach target_y, try to move further backward if
5278 we can. If we moved too far backward, try to move forward. */
5279 if (target_y
< it
->current_y
5280 && IT_CHARPOS (*it
) > BEGV
)
5282 move_it_vertically (it
, target_y
- it
->current_y
);
5283 xassert (IT_CHARPOS (*it
) >= BEGV
);
5285 else if (target_y
>= it
->current_y
+ line_height
5286 && IT_CHARPOS (*it
) < ZV
)
5288 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5289 xassert (IT_CHARPOS (*it
) >= BEGV
);
5295 /* Move IT by a specified amount of pixel lines DY. DY negative means
5296 move backwards. DY = 0 means move to start of screen line. At the
5297 end, IT will be on the start of a screen line. */
5300 move_it_vertically (it
, dy
)
5305 move_it_vertically_backward (it
, -dy
);
5308 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5309 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5310 MOVE_TO_POS
| MOVE_TO_Y
);
5311 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5313 /* If buffer ends in ZV without a newline, move to the start of
5314 the line to satisfy the post-condition. */
5315 if (IT_CHARPOS (*it
) == ZV
5316 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5317 move_it_by_lines (it
, 0, 0);
5322 /* Move iterator IT past the end of the text line it is in. */
5325 move_it_past_eol (it
)
5328 enum move_it_result rc
;
5330 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5331 if (rc
== MOVE_NEWLINE_OR_CR
)
5332 set_iterator_to_next (it
, 0);
5336 #if 0 /* Currently not used. */
5338 /* Return non-zero if some text between buffer positions START_CHARPOS
5339 and END_CHARPOS is invisible. IT->window is the window for text
5343 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5345 int start_charpos
, end_charpos
;
5347 Lisp_Object prop
, limit
;
5348 int invisible_found_p
;
5350 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5352 /* Is text at START invisible? */
5353 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5355 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5356 invisible_found_p
= 1;
5359 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5361 make_number (end_charpos
));
5362 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5365 return invisible_found_p
;
5371 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5372 negative means move up. DVPOS == 0 means move to the start of the
5373 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5374 NEED_Y_P is zero, IT->current_y will be left unchanged.
5376 Further optimization ideas: If we would know that IT->f doesn't use
5377 a face with proportional font, we could be faster for
5378 truncate-lines nil. */
5381 move_it_by_lines (it
, dvpos
, need_y_p
)
5383 int dvpos
, need_y_p
;
5385 struct position pos
;
5387 if (!FRAME_WINDOW_P (it
->f
))
5389 struct text_pos textpos
;
5391 /* We can use vmotion on frames without proportional fonts. */
5392 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5393 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5394 reseat (it
, textpos
, 1);
5395 it
->vpos
+= pos
.vpos
;
5396 it
->current_y
+= pos
.vpos
;
5398 else if (dvpos
== 0)
5400 /* DVPOS == 0 means move to the start of the screen line. */
5401 move_it_vertically_backward (it
, 0);
5402 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5405 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5409 int start_charpos
, i
;
5411 /* Go back -DVPOS visible lines and reseat the iterator there. */
5412 start_charpos
= IT_CHARPOS (*it
);
5413 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5414 back_to_previous_visible_line_start (it
);
5415 reseat (it
, it
->current
.pos
, 1);
5416 it
->current_x
= it
->hpos
= 0;
5418 /* Above call may have moved too far if continuation lines
5419 are involved. Scan forward and see if it did. */
5421 it2
.vpos
= it2
.current_y
= 0;
5422 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5423 it
->vpos
-= it2
.vpos
;
5424 it
->current_y
-= it2
.current_y
;
5425 it
->current_x
= it
->hpos
= 0;
5427 /* If we moved too far, move IT some lines forward. */
5428 if (it2
.vpos
> -dvpos
)
5430 int delta
= it2
.vpos
+ dvpos
;
5431 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5438 /***********************************************************************
5440 ***********************************************************************/
5443 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5447 add_to_log (format
, arg1
, arg2
)
5449 Lisp_Object arg1
, arg2
;
5451 Lisp_Object args
[3];
5452 Lisp_Object msg
, fmt
;
5455 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5458 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5460 args
[0] = fmt
= build_string (format
);
5463 msg
= Fformat (3, args
);
5465 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5466 buffer
= (char *) alloca (len
);
5467 strcpy (buffer
, XSTRING (msg
)->data
);
5469 message_dolog (buffer
, len
- 1, 1, 0);
5474 /* Output a newline in the *Messages* buffer if "needs" one. */
5477 message_log_maybe_newline ()
5479 if (message_log_need_newline
)
5480 message_dolog ("", 0, 1, 0);
5484 /* Add a string M of length NBYTES to the message log, optionally
5485 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5486 nonzero, means interpret the contents of M as multibyte. This
5487 function calls low-level routines in order to bypass text property
5488 hooks, etc. which might not be safe to run. */
5491 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5493 int nbytes
, nlflag
, multibyte
;
5495 if (!NILP (Vmessage_log_max
))
5497 struct buffer
*oldbuf
;
5498 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5499 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5500 int point_at_end
= 0;
5502 Lisp_Object old_deactivate_mark
, tem
;
5503 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5505 old_deactivate_mark
= Vdeactivate_mark
;
5506 oldbuf
= current_buffer
;
5507 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5508 current_buffer
->undo_list
= Qt
;
5510 oldpoint
= Fpoint_marker ();
5511 oldbegv
= Fpoint_min_marker ();
5512 oldzv
= Fpoint_max_marker ();
5513 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5521 BEGV_BYTE
= BEG_BYTE
;
5524 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5526 /* Insert the string--maybe converting multibyte to single byte
5527 or vice versa, so that all the text fits the buffer. */
5529 && NILP (current_buffer
->enable_multibyte_characters
))
5531 int i
, c
, char_bytes
;
5532 unsigned char work
[1];
5534 /* Convert a multibyte string to single-byte
5535 for the *Message* buffer. */
5536 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5538 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5539 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5541 : multibyte_char_to_unibyte (c
, Qnil
));
5542 insert_1_both (work
, 1, 1, 1, 0, 0);
5545 else if (! multibyte
5546 && ! NILP (current_buffer
->enable_multibyte_characters
))
5548 int i
, c
, char_bytes
;
5549 unsigned char *msg
= (unsigned char *) m
;
5550 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5551 /* Convert a single-byte string to multibyte
5552 for the *Message* buffer. */
5553 for (i
= 0; i
< nbytes
; i
++)
5555 c
= unibyte_char_to_multibyte (msg
[i
]);
5556 char_bytes
= CHAR_STRING (c
, str
);
5557 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5561 insert_1 (m
, nbytes
, 1, 0, 0);
5565 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5566 insert_1 ("\n", 1, 1, 0, 0);
5568 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5570 this_bol_byte
= PT_BYTE
;
5574 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5576 prev_bol_byte
= PT_BYTE
;
5578 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5579 this_bol
, this_bol_byte
);
5582 del_range_both (prev_bol
, prev_bol_byte
,
5583 this_bol
, this_bol_byte
, 0);
5589 /* If you change this format, don't forget to also
5590 change message_log_check_duplicate. */
5591 sprintf (dupstr
, " [%d times]", dup
);
5592 duplen
= strlen (dupstr
);
5593 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5594 insert_1 (dupstr
, duplen
, 1, 0, 1);
5599 if (NATNUMP (Vmessage_log_max
))
5601 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5602 -XFASTINT (Vmessage_log_max
) - 1, 0);
5603 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5606 BEGV
= XMARKER (oldbegv
)->charpos
;
5607 BEGV_BYTE
= marker_byte_position (oldbegv
);
5616 ZV
= XMARKER (oldzv
)->charpos
;
5617 ZV_BYTE
= marker_byte_position (oldzv
);
5621 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5623 /* We can't do Fgoto_char (oldpoint) because it will run some
5625 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5626 XMARKER (oldpoint
)->bytepos
);
5629 free_marker (oldpoint
);
5630 free_marker (oldbegv
);
5631 free_marker (oldzv
);
5633 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5634 set_buffer_internal (oldbuf
);
5636 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5637 message_log_need_newline
= !nlflag
;
5638 Vdeactivate_mark
= old_deactivate_mark
;
5643 /* We are at the end of the buffer after just having inserted a newline.
5644 (Note: We depend on the fact we won't be crossing the gap.)
5645 Check to see if the most recent message looks a lot like the previous one.
5646 Return 0 if different, 1 if the new one should just replace it, or a
5647 value N > 1 if we should also append " [N times]". */
5650 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5651 int prev_bol
, this_bol
;
5652 int prev_bol_byte
, this_bol_byte
;
5655 int len
= Z_BYTE
- 1 - this_bol_byte
;
5657 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5658 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5660 for (i
= 0; i
< len
; i
++)
5662 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5670 if (*p1
++ == ' ' && *p1
++ == '[')
5673 while (*p1
>= '0' && *p1
<= '9')
5674 n
= n
* 10 + *p1
++ - '0';
5675 if (strncmp (p1
, " times]\n", 8) == 0)
5682 /* Display an echo area message M with a specified length of NBYTES
5683 bytes. The string may include null characters. If M is 0, clear
5684 out any existing message, and let the mini-buffer text show
5687 The buffer M must continue to exist until after the echo area gets
5688 cleared or some other message gets displayed there. This means do
5689 not pass text that is stored in a Lisp string; do not pass text in
5690 a buffer that was alloca'd. */
5693 message2 (m
, nbytes
, multibyte
)
5698 /* First flush out any partial line written with print. */
5699 message_log_maybe_newline ();
5701 message_dolog (m
, nbytes
, 1, multibyte
);
5702 message2_nolog (m
, nbytes
, multibyte
);
5706 /* The non-logging counterpart of message2. */
5709 message2_nolog (m
, nbytes
, multibyte
)
5713 struct frame
*sf
= SELECTED_FRAME ();
5714 message_enable_multibyte
= multibyte
;
5718 if (noninteractive_need_newline
)
5719 putc ('\n', stderr
);
5720 noninteractive_need_newline
= 0;
5722 fwrite (m
, nbytes
, 1, stderr
);
5723 if (cursor_in_echo_area
== 0)
5724 fprintf (stderr
, "\n");
5727 /* A null message buffer means that the frame hasn't really been
5728 initialized yet. Error messages get reported properly by
5729 cmd_error, so this must be just an informative message; toss it. */
5730 else if (INTERACTIVE
5731 && sf
->glyphs_initialized_p
5732 && FRAME_MESSAGE_BUF (sf
))
5734 Lisp_Object mini_window
;
5737 /* Get the frame containing the mini-buffer
5738 that the selected frame is using. */
5739 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5740 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5742 FRAME_SAMPLE_VISIBILITY (f
);
5743 if (FRAME_VISIBLE_P (sf
)
5744 && ! FRAME_VISIBLE_P (f
))
5745 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5749 set_message (m
, Qnil
, nbytes
, multibyte
);
5750 if (minibuffer_auto_raise
)
5751 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5754 clear_message (1, 1);
5756 do_pending_window_change (0);
5757 echo_area_display (1);
5758 do_pending_window_change (0);
5759 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5760 (*frame_up_to_date_hook
) (f
);
5765 /* Display an echo area message M with a specified length of NBYTES
5766 bytes. The string may include null characters. If M is not a
5767 string, clear out any existing message, and let the mini-buffer
5768 text show through. */
5771 message3 (m
, nbytes
, multibyte
)
5776 struct gcpro gcpro1
;
5780 /* First flush out any partial line written with print. */
5781 message_log_maybe_newline ();
5783 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5784 message3_nolog (m
, nbytes
, multibyte
);
5790 /* The non-logging version of message3. */
5793 message3_nolog (m
, nbytes
, multibyte
)
5795 int nbytes
, multibyte
;
5797 struct frame
*sf
= SELECTED_FRAME ();
5798 message_enable_multibyte
= multibyte
;
5802 if (noninteractive_need_newline
)
5803 putc ('\n', stderr
);
5804 noninteractive_need_newline
= 0;
5806 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5807 if (cursor_in_echo_area
== 0)
5808 fprintf (stderr
, "\n");
5811 /* A null message buffer means that the frame hasn't really been
5812 initialized yet. Error messages get reported properly by
5813 cmd_error, so this must be just an informative message; toss it. */
5814 else if (INTERACTIVE
5815 && sf
->glyphs_initialized_p
5816 && FRAME_MESSAGE_BUF (sf
))
5818 Lisp_Object mini_window
;
5822 /* Get the frame containing the mini-buffer
5823 that the selected frame is using. */
5824 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5825 frame
= XWINDOW (mini_window
)->frame
;
5828 FRAME_SAMPLE_VISIBILITY (f
);
5829 if (FRAME_VISIBLE_P (sf
)
5830 && !FRAME_VISIBLE_P (f
))
5831 Fmake_frame_visible (frame
);
5833 if (STRINGP (m
) && XSTRING (m
)->size
)
5835 set_message (NULL
, m
, nbytes
, multibyte
);
5836 if (minibuffer_auto_raise
)
5837 Fraise_frame (frame
);
5840 clear_message (1, 1);
5842 do_pending_window_change (0);
5843 echo_area_display (1);
5844 do_pending_window_change (0);
5845 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5846 (*frame_up_to_date_hook
) (f
);
5851 /* Display a null-terminated echo area message M. If M is 0, clear
5852 out any existing message, and let the mini-buffer text show through.
5854 The buffer M must continue to exist until after the echo area gets
5855 cleared or some other message gets displayed there. Do not pass
5856 text that is stored in a Lisp string. Do not pass text in a buffer
5857 that was alloca'd. */
5863 message2 (m
, (m
? strlen (m
) : 0), 0);
5867 /* The non-logging counterpart of message1. */
5873 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5876 /* Display a message M which contains a single %s
5877 which gets replaced with STRING. */
5880 message_with_string (m
, string
, log
)
5889 if (noninteractive_need_newline
)
5890 putc ('\n', stderr
);
5891 noninteractive_need_newline
= 0;
5892 fprintf (stderr
, m
, XSTRING (string
)->data
);
5893 if (cursor_in_echo_area
== 0)
5894 fprintf (stderr
, "\n");
5898 else if (INTERACTIVE
)
5900 /* The frame whose minibuffer we're going to display the message on.
5901 It may be larger than the selected frame, so we need
5902 to use its buffer, not the selected frame's buffer. */
5903 Lisp_Object mini_window
;
5904 struct frame
*f
, *sf
= SELECTED_FRAME ();
5906 /* Get the frame containing the minibuffer
5907 that the selected frame is using. */
5908 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5909 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5911 /* A null message buffer means that the frame hasn't really been
5912 initialized yet. Error messages get reported properly by
5913 cmd_error, so this must be just an informative message; toss it. */
5914 if (FRAME_MESSAGE_BUF (f
))
5918 a
[0] = (char *) XSTRING (string
)->data
;
5920 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5921 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5924 message2 (FRAME_MESSAGE_BUF (f
), len
,
5925 STRING_MULTIBYTE (string
));
5927 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5928 STRING_MULTIBYTE (string
));
5930 /* Print should start at the beginning of the message
5931 buffer next time. */
5932 message_buf_print
= 0;
5938 /* Dump an informative message to the minibuf. If M is 0, clear out
5939 any existing message, and let the mini-buffer text show through. */
5943 message (m
, a1
, a2
, a3
)
5945 EMACS_INT a1
, a2
, a3
;
5951 if (noninteractive_need_newline
)
5952 putc ('\n', stderr
);
5953 noninteractive_need_newline
= 0;
5954 fprintf (stderr
, m
, a1
, a2
, a3
);
5955 if (cursor_in_echo_area
== 0)
5956 fprintf (stderr
, "\n");
5960 else if (INTERACTIVE
)
5962 /* The frame whose mini-buffer we're going to display the message
5963 on. It may be larger than the selected frame, so we need to
5964 use its buffer, not the selected frame's buffer. */
5965 Lisp_Object mini_window
;
5966 struct frame
*f
, *sf
= SELECTED_FRAME ();
5968 /* Get the frame containing the mini-buffer
5969 that the selected frame is using. */
5970 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5971 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5973 /* A null message buffer means that the frame hasn't really been
5974 initialized yet. Error messages get reported properly by
5975 cmd_error, so this must be just an informative message; toss
5977 if (FRAME_MESSAGE_BUF (f
))
5988 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5989 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5991 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5992 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5994 #endif /* NO_ARG_ARRAY */
5996 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6001 /* Print should start at the beginning of the message
6002 buffer next time. */
6003 message_buf_print
= 0;
6009 /* The non-logging version of message. */
6012 message_nolog (m
, a1
, a2
, a3
)
6014 EMACS_INT a1
, a2
, a3
;
6016 Lisp_Object old_log_max
;
6017 old_log_max
= Vmessage_log_max
;
6018 Vmessage_log_max
= Qnil
;
6019 message (m
, a1
, a2
, a3
);
6020 Vmessage_log_max
= old_log_max
;
6024 /* Display the current message in the current mini-buffer. This is
6025 only called from error handlers in process.c, and is not time
6031 if (!NILP (echo_area_buffer
[0]))
6034 string
= Fcurrent_message ();
6035 message3 (string
, XSTRING (string
)->size
,
6036 !NILP (current_buffer
->enable_multibyte_characters
));
6041 /* Make sure echo area buffers in echo_buffers[] are life. If they
6042 aren't, make new ones. */
6045 ensure_echo_area_buffers ()
6049 for (i
= 0; i
< 2; ++i
)
6050 if (!BUFFERP (echo_buffer
[i
])
6051 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6054 Lisp_Object old_buffer
;
6057 old_buffer
= echo_buffer
[i
];
6058 sprintf (name
, " *Echo Area %d*", i
);
6059 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6060 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6062 for (j
= 0; j
< 2; ++j
)
6063 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6064 echo_area_buffer
[j
] = echo_buffer
[i
];
6069 /* Call FN with args A1..A4 with either the current or last displayed
6070 echo_area_buffer as current buffer.
6072 WHICH zero means use the current message buffer
6073 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6074 from echo_buffer[] and clear it.
6076 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6077 suitable buffer from echo_buffer[] and clear it.
6079 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6080 that the current message becomes the last displayed one, make
6081 choose a suitable buffer for echo_area_buffer[0], and clear it.
6083 Value is what FN returns. */
6086 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6089 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6095 int this_one
, the_other
, clear_buffer_p
, rc
;
6096 int count
= BINDING_STACK_SIZE ();
6098 /* If buffers aren't life, make new ones. */
6099 ensure_echo_area_buffers ();
6104 this_one
= 0, the_other
= 1;
6106 this_one
= 1, the_other
= 0;
6109 this_one
= 0, the_other
= 1;
6112 /* We need a fresh one in case the current echo buffer equals
6113 the one containing the last displayed echo area message. */
6114 if (!NILP (echo_area_buffer
[this_one
])
6115 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6116 echo_area_buffer
[this_one
] = Qnil
;
6119 /* Choose a suitable buffer from echo_buffer[] is we don't
6121 if (NILP (echo_area_buffer
[this_one
]))
6123 echo_area_buffer
[this_one
]
6124 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6125 ? echo_buffer
[the_other
]
6126 : echo_buffer
[this_one
]);
6130 buffer
= echo_area_buffer
[this_one
];
6132 record_unwind_protect (unwind_with_echo_area_buffer
,
6133 with_echo_area_buffer_unwind_data (w
));
6135 /* Make the echo area buffer current. Note that for display
6136 purposes, it is not necessary that the displayed window's buffer
6137 == current_buffer, except for text property lookup. So, let's
6138 only set that buffer temporarily here without doing a full
6139 Fset_window_buffer. We must also change w->pointm, though,
6140 because otherwise an assertions in unshow_buffer fails, and Emacs
6142 set_buffer_internal_1 (XBUFFER (buffer
));
6146 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6149 current_buffer
->undo_list
= Qt
;
6150 current_buffer
->read_only
= Qnil
;
6151 specbind (Qinhibit_read_only
, Qt
);
6153 if (clear_buffer_p
&& Z
> BEG
)
6156 xassert (BEGV
>= BEG
);
6157 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6159 rc
= fn (a1
, a2
, a3
, a4
);
6161 xassert (BEGV
>= BEG
);
6162 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6164 unbind_to (count
, Qnil
);
6169 /* Save state that should be preserved around the call to the function
6170 FN called in with_echo_area_buffer. */
6173 with_echo_area_buffer_unwind_data (w
)
6179 /* Reduce consing by keeping one vector in
6180 Vwith_echo_area_save_vector. */
6181 vector
= Vwith_echo_area_save_vector
;
6182 Vwith_echo_area_save_vector
= Qnil
;
6185 vector
= Fmake_vector (make_number (7), Qnil
);
6187 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6188 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6189 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6193 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6194 AREF (vector
, i
) = w
->buffer
; ++i
;
6195 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6196 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6201 for (; i
< end
; ++i
)
6202 AREF (vector
, i
) = Qnil
;
6205 xassert (i
== ASIZE (vector
));
6210 /* Restore global state from VECTOR which was created by
6211 with_echo_area_buffer_unwind_data. */
6214 unwind_with_echo_area_buffer (vector
)
6217 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6218 Vdeactivate_mark
= AREF (vector
, 1);
6219 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6221 if (WINDOWP (AREF (vector
, 3)))
6224 Lisp_Object buffer
, charpos
, bytepos
;
6226 w
= XWINDOW (AREF (vector
, 3));
6227 buffer
= AREF (vector
, 4);
6228 charpos
= AREF (vector
, 5);
6229 bytepos
= AREF (vector
, 6);
6232 set_marker_both (w
->pointm
, buffer
,
6233 XFASTINT (charpos
), XFASTINT (bytepos
));
6236 Vwith_echo_area_save_vector
= vector
;
6241 /* Set up the echo area for use by print functions. MULTIBYTE_P
6242 non-zero means we will print multibyte. */
6245 setup_echo_area_for_printing (multibyte_p
)
6248 ensure_echo_area_buffers ();
6250 if (!message_buf_print
)
6252 /* A message has been output since the last time we printed.
6253 Choose a fresh echo area buffer. */
6254 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6255 echo_area_buffer
[0] = echo_buffer
[1];
6257 echo_area_buffer
[0] = echo_buffer
[0];
6259 /* Switch to that buffer and clear it. */
6260 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6261 current_buffer
->truncate_lines
= Qnil
;
6265 int count
= BINDING_STACK_SIZE ();
6266 specbind (Qinhibit_read_only
, Qt
);
6268 unbind_to (count
, Qnil
);
6270 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6272 /* Set up the buffer for the multibyteness we need. */
6274 != !NILP (current_buffer
->enable_multibyte_characters
))
6275 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6277 /* Raise the frame containing the echo area. */
6278 if (minibuffer_auto_raise
)
6280 struct frame
*sf
= SELECTED_FRAME ();
6281 Lisp_Object mini_window
;
6282 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6283 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6286 message_log_maybe_newline ();
6287 message_buf_print
= 1;
6291 if (NILP (echo_area_buffer
[0]))
6293 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6294 echo_area_buffer
[0] = echo_buffer
[1];
6296 echo_area_buffer
[0] = echo_buffer
[0];
6299 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6301 /* Someone switched buffers between print requests. */
6302 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6303 current_buffer
->truncate_lines
= Qnil
;
6309 /* Display an echo area message in window W. Value is non-zero if W's
6310 height is changed. If display_last_displayed_message_p is
6311 non-zero, display the message that was last displayed, otherwise
6312 display the current message. */
6315 display_echo_area (w
)
6318 int i
, no_message_p
, window_height_changed_p
, count
;
6320 /* Temporarily disable garbage collections while displaying the echo
6321 area. This is done because a GC can print a message itself.
6322 That message would modify the echo area buffer's contents while a
6323 redisplay of the buffer is going on, and seriously confuse
6325 count
= inhibit_garbage_collection ();
6327 /* If there is no message, we must call display_echo_area_1
6328 nevertheless because it resizes the window. But we will have to
6329 reset the echo_area_buffer in question to nil at the end because
6330 with_echo_area_buffer will sets it to an empty buffer. */
6331 i
= display_last_displayed_message_p
? 1 : 0;
6332 no_message_p
= NILP (echo_area_buffer
[i
]);
6334 window_height_changed_p
6335 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6336 display_echo_area_1
,
6337 (EMACS_INT
) w
, Qnil
, 0, 0);
6340 echo_area_buffer
[i
] = Qnil
;
6342 unbind_to (count
, Qnil
);
6343 return window_height_changed_p
;
6347 /* Helper for display_echo_area. Display the current buffer which
6348 contains the current echo area message in window W, a mini-window,
6349 a pointer to which is passed in A1. A2..A4 are currently not used.
6350 Change the height of W so that all of the message is displayed.
6351 Value is non-zero if height of W was changed. */
6354 display_echo_area_1 (a1
, a2
, a3
, a4
)
6359 struct window
*w
= (struct window
*) a1
;
6361 struct text_pos start
;
6362 int window_height_changed_p
= 0;
6364 /* Do this before displaying, so that we have a large enough glyph
6365 matrix for the display. */
6366 window_height_changed_p
= resize_mini_window (w
, 0);
6369 clear_glyph_matrix (w
->desired_matrix
);
6370 XSETWINDOW (window
, w
);
6371 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6372 try_window (window
, start
);
6374 return window_height_changed_p
;
6378 /* Resize the echo area window to exactly the size needed for the
6379 currently displayed message, if there is one. */
6382 resize_echo_area_axactly ()
6384 if (BUFFERP (echo_area_buffer
[0])
6385 && WINDOWP (echo_area_window
))
6387 struct window
*w
= XWINDOW (echo_area_window
);
6390 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6391 (EMACS_INT
) w
, Qnil
, 0, 0);
6394 ++windows_or_buffers_changed
;
6395 ++update_mode_lines
;
6396 redisplay_internal (0);
6402 /* Callback function for with_echo_area_buffer, when used from
6403 resize_echo_area_axactly. A1 contains a pointer to the window to
6404 resize, A2 to A4 are not used. Value is what resize_mini_window
6408 resize_mini_window_1 (a1
, a2
, a3
, a4
)
6413 return resize_mini_window ((struct window
*) a1
, 1);
6417 /* Resize mini-window W to fit the size of its contents. EXACT:P
6418 means size the window exactly to the size needed. Otherwise, it's
6419 only enlarged until W's buffer is empty. Value is non-zero if
6420 the window height has been changed. */
6423 resize_mini_window (w
, exact_p
)
6427 struct frame
*f
= XFRAME (w
->frame
);
6428 int window_height_changed_p
= 0;
6430 xassert (MINI_WINDOW_P (w
));
6432 /* Nil means don't try to resize. */
6433 if (NILP (Vresize_mini_windows
)
6434 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6437 if (!FRAME_MINIBUF_ONLY_P (f
))
6440 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6441 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6442 int height
, max_height
;
6443 int unit
= CANON_Y_UNIT (f
);
6444 struct text_pos start
;
6445 struct buffer
*old_current_buffer
= NULL
;
6447 if (current_buffer
!= XBUFFER (w
->buffer
))
6449 old_current_buffer
= current_buffer
;
6450 set_buffer_internal (XBUFFER (w
->buffer
));
6453 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6455 /* Compute the max. number of lines specified by the user. */
6456 if (FLOATP (Vmax_mini_window_height
))
6457 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
6458 else if (INTEGERP (Vmax_mini_window_height
))
6459 max_height
= XINT (Vmax_mini_window_height
);
6461 max_height
= total_height
/ 4;
6463 /* Correct that max. height if it's bogus. */
6464 max_height
= max (1, max_height
);
6465 max_height
= min (total_height
, max_height
);
6467 /* Find out the height of the text in the window. */
6468 if (it
.truncate_lines_p
)
6473 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6474 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6475 height
= it
.current_y
+ last_height
;
6477 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6478 height
-= it
.extra_line_spacing
;
6479 height
= (height
+ unit
- 1) / unit
;
6482 /* Compute a suitable window start. */
6483 if (height
> max_height
)
6485 height
= max_height
;
6486 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6487 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6488 start
= it
.current
.pos
;
6491 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6492 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6494 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6496 /* Let it grow only, until we display an empty message, in which
6497 case the window shrinks again. */
6498 if (height
> XFASTINT (w
->height
))
6500 int old_height
= XFASTINT (w
->height
);
6501 freeze_window_starts (f
, 1);
6502 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6503 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6505 else if (height
< XFASTINT (w
->height
)
6506 && (exact_p
|| BEGV
== ZV
))
6508 int old_height
= XFASTINT (w
->height
);
6509 freeze_window_starts (f
, 0);
6510 shrink_mini_window (w
);
6511 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6516 /* Always resize to exact size needed. */
6517 if (height
> XFASTINT (w
->height
))
6519 int old_height
= XFASTINT (w
->height
);
6520 freeze_window_starts (f
, 1);
6521 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6522 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6524 else if (height
< XFASTINT (w
->height
))
6526 int old_height
= XFASTINT (w
->height
);
6527 freeze_window_starts (f
, 0);
6528 shrink_mini_window (w
);
6532 freeze_window_starts (f
, 1);
6533 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6536 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6540 if (old_current_buffer
)
6541 set_buffer_internal (old_current_buffer
);
6544 return window_height_changed_p
;
6548 /* Value is the current message, a string, or nil if there is no
6556 if (NILP (echo_area_buffer
[0]))
6560 with_echo_area_buffer (0, 0, current_message_1
,
6561 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6563 echo_area_buffer
[0] = Qnil
;
6571 current_message_1 (a1
, a2
, a3
, a4
)
6576 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6579 *msg
= make_buffer_string (BEG
, Z
, 1);
6586 /* Push the current message on Vmessage_stack for later restauration
6587 by restore_message. Value is non-zero if the current message isn't
6588 empty. This is a relatively infrequent operation, so it's not
6589 worth optimizing. */
6595 msg
= current_message ();
6596 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6597 return STRINGP (msg
);
6601 /* Handler for record_unwind_protect calling pop_message. */
6604 push_message_unwind (dummy
)
6612 /* Restore message display from the top of Vmessage_stack. */
6619 xassert (CONSP (Vmessage_stack
));
6620 msg
= XCAR (Vmessage_stack
);
6622 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6624 message3_nolog (msg
, 0, 0);
6628 /* Pop the top-most entry off Vmessage_stack. */
6633 xassert (CONSP (Vmessage_stack
));
6634 Vmessage_stack
= XCDR (Vmessage_stack
);
6638 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6639 exits. If the stack is not empty, we have a missing pop_message
6643 check_message_stack ()
6645 if (!NILP (Vmessage_stack
))
6650 /* Truncate to NCHARS what will be displayed in the echo area the next
6651 time we display it---but don't redisplay it now. */
6654 truncate_echo_area (nchars
)
6658 echo_area_buffer
[0] = Qnil
;
6659 /* A null message buffer means that the frame hasn't really been
6660 initialized yet. Error messages get reported properly by
6661 cmd_error, so this must be just an informative message; toss it. */
6662 else if (!noninteractive
6664 && !NILP (echo_area_buffer
[0]))
6666 struct frame
*sf
= SELECTED_FRAME ();
6667 if (FRAME_MESSAGE_BUF (sf
))
6668 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6673 /* Helper function for truncate_echo_area. Truncate the current
6674 message to at most NCHARS characters. */
6677 truncate_message_1 (nchars
, a2
, a3
, a4
)
6682 if (BEG
+ nchars
< Z
)
6683 del_range (BEG
+ nchars
, Z
);
6685 echo_area_buffer
[0] = Qnil
;
6690 /* Set the current message to a substring of S or STRING.
6692 If STRING is a Lisp string, set the message to the first NBYTES
6693 bytes from STRING. NBYTES zero means use the whole string. If
6694 STRING is multibyte, the message will be displayed multibyte.
6696 If S is not null, set the message to the first LEN bytes of S. LEN
6697 zero means use the whole string. MULTIBYTE_P non-zero means S is
6698 multibyte. Display the message multibyte in that case. */
6701 set_message (s
, string
, nbytes
, multibyte_p
)
6706 message_enable_multibyte
6707 = ((s
&& multibyte_p
)
6708 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6710 with_echo_area_buffer (0, -1, set_message_1
,
6711 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6712 message_buf_print
= 0;
6713 help_echo_showing_p
= 0;
6717 /* Helper function for set_message. Arguments have the same meaning
6718 as there, with A1 corresponding to S and A2 corresponding to STRING
6719 This function is called with the echo area buffer being
6723 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6726 EMACS_INT nbytes
, multibyte_p
;
6728 char *s
= (char *) a1
;
6729 Lisp_Object string
= a2
;
6733 /* Change multibyteness of the echo buffer appropriately. */
6734 if (message_enable_multibyte
6735 != !NILP (current_buffer
->enable_multibyte_characters
))
6736 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6738 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6740 /* Insert new message at BEG. */
6741 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6743 if (STRINGP (string
))
6748 nbytes
= XSTRING (string
)->size_byte
;
6749 nchars
= string_byte_to_char (string
, nbytes
);
6751 /* This function takes care of single/multibyte conversion. We
6752 just have to ensure that the echo area buffer has the right
6753 setting of enable_multibyte_characters. */
6754 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6759 nbytes
= strlen (s
);
6761 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6763 /* Convert from multi-byte to single-byte. */
6765 unsigned char work
[1];
6767 /* Convert a multibyte string to single-byte. */
6768 for (i
= 0; i
< nbytes
; i
+= n
)
6770 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6771 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6773 : multibyte_char_to_unibyte (c
, Qnil
));
6774 insert_1_both (work
, 1, 1, 1, 0, 0);
6777 else if (!multibyte_p
6778 && !NILP (current_buffer
->enable_multibyte_characters
))
6780 /* Convert from single-byte to multi-byte. */
6782 unsigned char *msg
= (unsigned char *) s
;
6783 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6785 /* Convert a single-byte string to multibyte. */
6786 for (i
= 0; i
< nbytes
; i
++)
6788 c
= unibyte_char_to_multibyte (msg
[i
]);
6789 n
= CHAR_STRING (c
, str
);
6790 insert_1_both (str
, 1, n
, 1, 0, 0);
6794 insert_1 (s
, nbytes
, 1, 0, 0);
6801 /* Clear messages. CURRENT_P non-zero means clear the current
6802 message. LAST_DISPLAYED_P non-zero means clear the message
6806 clear_message (current_p
, last_displayed_p
)
6807 int current_p
, last_displayed_p
;
6810 echo_area_buffer
[0] = Qnil
;
6812 if (last_displayed_p
)
6813 echo_area_buffer
[1] = Qnil
;
6815 message_buf_print
= 0;
6818 /* Clear garbaged frames.
6820 This function is used where the old redisplay called
6821 redraw_garbaged_frames which in turn called redraw_frame which in
6822 turn called clear_frame. The call to clear_frame was a source of
6823 flickering. I believe a clear_frame is not necessary. It should
6824 suffice in the new redisplay to invalidate all current matrices,
6825 and ensure a complete redisplay of all windows. */
6828 clear_garbaged_frames ()
6832 Lisp_Object tail
, frame
;
6834 FOR_EACH_FRAME (tail
, frame
)
6836 struct frame
*f
= XFRAME (frame
);
6838 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6840 clear_current_matrices (f
);
6846 ++windows_or_buffers_changed
;
6851 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6852 is non-zero update selected_frame. Value is non-zero if the
6853 mini-windows height has been changed. */
6856 echo_area_display (update_frame_p
)
6859 Lisp_Object mini_window
;
6862 int window_height_changed_p
= 0;
6863 struct frame
*sf
= SELECTED_FRAME ();
6865 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6866 w
= XWINDOW (mini_window
);
6867 f
= XFRAME (WINDOW_FRAME (w
));
6869 /* Don't display if frame is invisible or not yet initialized. */
6870 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6873 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
6875 #ifdef HAVE_WINDOW_SYSTEM
6876 /* When Emacs starts, selected_frame may be a visible terminal
6877 frame, even if we run under a window system. If we let this
6878 through, a message would be displayed on the terminal. */
6879 if (EQ (selected_frame
, Vterminal_frame
)
6880 && !NILP (Vwindow_system
))
6882 #endif /* HAVE_WINDOW_SYSTEM */
6885 /* Redraw garbaged frames. */
6887 clear_garbaged_frames ();
6889 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6891 echo_area_window
= mini_window
;
6892 window_height_changed_p
= display_echo_area (w
);
6893 w
->must_be_updated_p
= 1;
6895 /* Update the display, unless called from redisplay_internal.
6896 Also don't update the screen during redisplay itself. The
6897 update will happen at the end of redisplay, and an update
6898 here could cause confusion. */
6899 if (update_frame_p
&& !redisplaying_p
)
6903 /* If the display update has been interrupted by pending
6904 input, update mode lines in the frame. Due to the
6905 pending input, it might have been that redisplay hasn't
6906 been called, so that mode lines above the echo area are
6907 garbaged. This looks odd, so we prevent it here. */
6908 if (!display_completed
)
6909 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
6911 if (window_height_changed_p
6912 /* Don't do this if Emacs is shutting down. Redisplay
6913 needs to run hooks. */
6914 && !NILP (Vrun_hooks
))
6916 /* Must update other windows. Likewise as in other
6917 cases, don't let this update be interrupted by
6919 int count
= BINDING_STACK_SIZE ();
6920 specbind (Qredisplay_dont_pause
, Qt
);
6921 windows_or_buffers_changed
= 1;
6922 redisplay_internal (0);
6923 unbind_to (count
, Qnil
);
6925 else if (FRAME_WINDOW_P (f
) && n
== 0)
6927 /* Window configuration is the same as before.
6928 Can do with a display update of the echo area,
6929 unless we displayed some mode lines. */
6930 update_single_window (w
, 1);
6931 rif
->flush_display (f
);
6934 update_frame (f
, 1, 1);
6936 /* If cursor is in the echo area, make sure that the next
6937 redisplay displays the minibuffer, so that the cursor will
6938 be replaced with what the minibuffer wants. */
6939 if (cursor_in_echo_area
)
6940 ++windows_or_buffers_changed
;
6943 else if (!EQ (mini_window
, selected_window
))
6944 windows_or_buffers_changed
++;
6946 /* Last displayed message is now the current message. */
6947 echo_area_buffer
[1] = echo_area_buffer
[0];
6949 /* Prevent redisplay optimization in redisplay_internal by resetting
6950 this_line_start_pos. This is done because the mini-buffer now
6951 displays the message instead of its buffer text. */
6952 if (EQ (mini_window
, selected_window
))
6953 CHARPOS (this_line_start_pos
) = 0;
6955 return window_height_changed_p
;
6960 /***********************************************************************
6962 ***********************************************************************/
6965 #ifdef HAVE_WINDOW_SYSTEM
6967 /* A buffer for constructing frame titles in it; allocated from the
6968 heap in init_xdisp and resized as needed in store_frame_title_char. */
6970 static char *frame_title_buf
;
6972 /* The buffer's end, and a current output position in it. */
6974 static char *frame_title_buf_end
;
6975 static char *frame_title_ptr
;
6978 /* Store a single character C for the frame title in frame_title_buf.
6979 Re-allocate frame_title_buf if necessary. */
6982 store_frame_title_char (c
)
6985 /* If output position has reached the end of the allocated buffer,
6986 double the buffer's size. */
6987 if (frame_title_ptr
== frame_title_buf_end
)
6989 int len
= frame_title_ptr
- frame_title_buf
;
6990 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6991 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6992 frame_title_buf_end
= frame_title_buf
+ new_size
;
6993 frame_title_ptr
= frame_title_buf
+ len
;
6996 *frame_title_ptr
++ = c
;
7000 /* Store part of a frame title in frame_title_buf, beginning at
7001 frame_title_ptr. STR is the string to store. Do not copy
7002 characters that yield more columns than PRECISION; PRECISION <= 0
7003 means copy the whole string. Pad with spaces until FIELD_WIDTH
7004 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7005 pad. Called from display_mode_element when it is used to build a
7009 store_frame_title (str
, field_width
, precision
)
7011 int field_width
, precision
;
7014 int dummy
, nbytes
, width
;
7016 /* Copy at most PRECISION chars from STR. */
7017 nbytes
= strlen (str
);
7018 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7020 store_frame_title_char (*str
++);
7022 /* Fill up with spaces until FIELD_WIDTH reached. */
7023 while (field_width
> 0
7026 store_frame_title_char (' ');
7034 /* Set the title of FRAME, if it has changed. The title format is
7035 Vicon_title_format if FRAME is iconified, otherwise it is
7036 frame_title_format. */
7039 x_consider_frame_title (frame
)
7042 struct frame
*f
= XFRAME (frame
);
7044 if (FRAME_WINDOW_P (f
)
7045 || FRAME_MINIBUF_ONLY_P (f
)
7046 || f
->explicit_name
)
7048 /* Do we have more than one visible frame on this X display? */
7051 struct buffer
*obuf
;
7055 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7057 struct frame
*tf
= XFRAME (XCAR (tail
));
7060 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7061 && !FRAME_MINIBUF_ONLY_P (tf
)
7062 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7066 /* Set global variable indicating that multiple frames exist. */
7067 multiple_frames
= CONSP (tail
);
7069 /* Switch to the buffer of selected window of the frame. Set up
7070 frame_title_ptr so that display_mode_element will output into it;
7071 then display the title. */
7072 obuf
= current_buffer
;
7073 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
7074 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7075 frame_title_ptr
= frame_title_buf
;
7076 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7077 NULL
, DEFAULT_FACE_ID
);
7078 display_mode_element (&it
, 0, -1, -1, fmt
);
7079 len
= frame_title_ptr
- frame_title_buf
;
7080 frame_title_ptr
= NULL
;
7081 set_buffer_internal (obuf
);
7083 /* Set the title only if it's changed. This avoids consing in
7084 the common case where it hasn't. (If it turns out that we've
7085 already wasted too much time by walking through the list with
7086 display_mode_element, then we might need to optimize at a
7087 higher level than this.) */
7088 if (! STRINGP (f
->name
)
7089 || STRING_BYTES (XSTRING (f
->name
)) != len
7090 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
7091 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7095 #else /* not HAVE_WINDOW_SYSTEM */
7097 #define frame_title_ptr ((char *)0)
7098 #define store_frame_title(str, mincol, maxcol) 0
7100 #endif /* not HAVE_WINDOW_SYSTEM */
7105 /***********************************************************************
7107 ***********************************************************************/
7110 /* Prepare for redisplay by updating menu-bar item lists when
7111 appropriate. This can call eval. */
7114 prepare_menu_bars ()
7117 struct gcpro gcpro1
, gcpro2
;
7119 Lisp_Object tooltip_frame
;
7121 #ifdef HAVE_X_WINDOWS
7122 tooltip_frame
= tip_frame
;
7124 tooltip_frame
= Qnil
;
7127 /* Update all frame titles based on their buffer names, etc. We do
7128 this before the menu bars so that the buffer-menu will show the
7129 up-to-date frame titles. */
7130 #ifdef HAVE_WINDOW_SYSTEM
7131 if (windows_or_buffers_changed
|| update_mode_lines
)
7133 Lisp_Object tail
, frame
;
7135 FOR_EACH_FRAME (tail
, frame
)
7138 if (!EQ (frame
, tooltip_frame
)
7139 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7140 x_consider_frame_title (frame
);
7143 #endif /* HAVE_WINDOW_SYSTEM */
7145 /* Update the menu bar item lists, if appropriate. This has to be
7146 done before any actual redisplay or generation of display lines. */
7147 all_windows
= (update_mode_lines
7148 || buffer_shared
> 1
7149 || windows_or_buffers_changed
);
7152 Lisp_Object tail
, frame
;
7153 int count
= BINDING_STACK_SIZE ();
7155 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7157 FOR_EACH_FRAME (tail
, frame
)
7161 /* Ignore tooltip frame. */
7162 if (EQ (frame
, tooltip_frame
))
7165 /* If a window on this frame changed size, report that to
7166 the user and clear the size-change flag. */
7167 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7169 Lisp_Object functions
;
7171 /* Clear flag first in case we get an error below. */
7172 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7173 functions
= Vwindow_size_change_functions
;
7174 GCPRO2 (tail
, functions
);
7176 while (CONSP (functions
))
7178 call1 (XCAR (functions
), frame
);
7179 functions
= XCDR (functions
);
7185 update_menu_bar (f
, 0);
7186 #ifdef HAVE_WINDOW_SYSTEM
7187 update_tool_bar (f
, 0);
7192 unbind_to (count
, Qnil
);
7196 struct frame
*sf
= SELECTED_FRAME ();
7197 update_menu_bar (sf
, 1);
7198 #ifdef HAVE_WINDOW_SYSTEM
7199 update_tool_bar (sf
, 1);
7203 /* Motif needs this. See comment in xmenu.c. Turn it off when
7204 pending_menu_activation is not defined. */
7205 #ifdef USE_X_TOOLKIT
7206 pending_menu_activation
= 0;
7211 /* Update the menu bar item list for frame F. This has to be done
7212 before we start to fill in any display lines, because it can call
7215 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7218 update_menu_bar (f
, save_match_data
)
7220 int save_match_data
;
7223 register struct window
*w
;
7225 /* If called recursively during a menu update, do nothing. This can
7226 happen when, for instance, an activate-menubar-hook causes a
7228 if (inhibit_menubar_update
)
7231 window
= FRAME_SELECTED_WINDOW (f
);
7232 w
= XWINDOW (window
);
7234 if (update_mode_lines
)
7235 w
->update_mode_line
= Qt
;
7237 if (FRAME_WINDOW_P (f
)
7239 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7240 FRAME_EXTERNAL_MENU_BAR (f
)
7242 FRAME_MENU_BAR_LINES (f
) > 0
7244 : FRAME_MENU_BAR_LINES (f
) > 0)
7246 /* If the user has switched buffers or windows, we need to
7247 recompute to reflect the new bindings. But we'll
7248 recompute when update_mode_lines is set too; that means
7249 that people can use force-mode-line-update to request
7250 that the menu bar be recomputed. The adverse effect on
7251 the rest of the redisplay algorithm is about the same as
7252 windows_or_buffers_changed anyway. */
7253 if (windows_or_buffers_changed
7254 || !NILP (w
->update_mode_line
)
7255 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7256 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7257 != !NILP (w
->last_had_star
))
7258 || ((!NILP (Vtransient_mark_mode
)
7259 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7260 != !NILP (w
->region_showing
)))
7262 struct buffer
*prev
= current_buffer
;
7263 int count
= BINDING_STACK_SIZE ();
7265 specbind (Qinhibit_menubar_update
, Qt
);
7267 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7268 if (save_match_data
)
7269 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7270 if (NILP (Voverriding_local_map_menu_flag
))
7272 specbind (Qoverriding_terminal_local_map
, Qnil
);
7273 specbind (Qoverriding_local_map
, Qnil
);
7276 /* Run the Lucid hook. */
7277 safe_run_hooks (Qactivate_menubar_hook
);
7279 /* If it has changed current-menubar from previous value,
7280 really recompute the menu-bar from the value. */
7281 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7282 call0 (Qrecompute_lucid_menubar
);
7284 safe_run_hooks (Qmenu_bar_update_hook
);
7285 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7287 /* Redisplay the menu bar in case we changed it. */
7288 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7289 if (FRAME_WINDOW_P (f
)
7290 #if defined (macintosh)
7291 /* All frames on Mac OS share the same menubar. So only the
7292 selected frame should be allowed to set it. */
7293 && f
== SELECTED_FRAME ()
7296 set_frame_menubar (f
, 0, 0);
7298 /* On a terminal screen, the menu bar is an ordinary screen
7299 line, and this makes it get updated. */
7300 w
->update_mode_line
= Qt
;
7301 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7302 /* In the non-toolkit version, the menu bar is an ordinary screen
7303 line, and this makes it get updated. */
7304 w
->update_mode_line
= Qt
;
7305 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7307 unbind_to (count
, Qnil
);
7308 set_buffer_internal_1 (prev
);
7315 /***********************************************************************
7317 ***********************************************************************/
7319 #ifdef HAVE_WINDOW_SYSTEM
7321 /* Update the tool-bar item list for frame F. This has to be done
7322 before we start to fill in any display lines. Called from
7323 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7324 and restore it here. */
7327 update_tool_bar (f
, save_match_data
)
7329 int save_match_data
;
7331 if (WINDOWP (f
->tool_bar_window
)
7332 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7337 window
= FRAME_SELECTED_WINDOW (f
);
7338 w
= XWINDOW (window
);
7340 /* If the user has switched buffers or windows, we need to
7341 recompute to reflect the new bindings. But we'll
7342 recompute when update_mode_lines is set too; that means
7343 that people can use force-mode-line-update to request
7344 that the menu bar be recomputed. The adverse effect on
7345 the rest of the redisplay algorithm is about the same as
7346 windows_or_buffers_changed anyway. */
7347 if (windows_or_buffers_changed
7348 || !NILP (w
->update_mode_line
)
7349 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7350 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7351 != !NILP (w
->last_had_star
))
7352 || ((!NILP (Vtransient_mark_mode
)
7353 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7354 != !NILP (w
->region_showing
)))
7356 struct buffer
*prev
= current_buffer
;
7357 int count
= BINDING_STACK_SIZE ();
7359 /* Set current_buffer to the buffer of the selected
7360 window of the frame, so that we get the right local
7362 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7364 /* Save match data, if we must. */
7365 if (save_match_data
)
7366 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7368 /* Make sure that we don't accidentally use bogus keymaps. */
7369 if (NILP (Voverriding_local_map_menu_flag
))
7371 specbind (Qoverriding_terminal_local_map
, Qnil
);
7372 specbind (Qoverriding_local_map
, Qnil
);
7375 /* Build desired tool-bar items from keymaps. */
7377 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7379 /* Redisplay the tool-bar in case we changed it. */
7380 w
->update_mode_line
= Qt
;
7382 unbind_to (count
, Qnil
);
7383 set_buffer_internal_1 (prev
);
7389 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7390 F's desired tool-bar contents. F->tool_bar_items must have
7391 been set up previously by calling prepare_menu_bars. */
7394 build_desired_tool_bar_string (f
)
7397 int i
, size
, size_needed
;
7398 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7399 Lisp_Object image
, plist
, props
;
7401 image
= plist
= props
= Qnil
;
7402 GCPRO3 (image
, plist
, props
);
7404 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7405 Otherwise, make a new string. */
7407 /* The size of the string we might be able to reuse. */
7408 size
= (STRINGP (f
->desired_tool_bar_string
)
7409 ? XSTRING (f
->desired_tool_bar_string
)->size
7412 /* We need one space in the string for each image. */
7413 size_needed
= f
->n_tool_bar_items
;
7415 /* Reuse f->desired_tool_bar_string, if possible. */
7416 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7417 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7421 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7422 Fremove_text_properties (make_number (0), make_number (size
),
7423 props
, f
->desired_tool_bar_string
);
7426 /* Put a `display' property on the string for the images to display,
7427 put a `menu_item' property on tool-bar items with a value that
7428 is the index of the item in F's tool-bar item vector. */
7429 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7431 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7433 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7434 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7435 int hmargin
, vmargin
, relief
, idx
, end
;
7436 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7437 extern Lisp_Object Qlaplace
;
7439 /* If image is a vector, choose the image according to the
7441 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7442 if (VECTORP (image
))
7446 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7447 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7450 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7451 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7453 xassert (ASIZE (image
) >= idx
);
7454 image
= AREF (image
, idx
);
7459 /* Ignore invalid image specifications. */
7460 if (!valid_image_p (image
))
7463 /* Display the tool-bar button pressed, or depressed. */
7464 plist
= Fcopy_sequence (XCDR (image
));
7466 /* Compute margin and relief to draw. */
7467 relief
= (tool_bar_button_relief
> 0
7468 ? tool_bar_button_relief
7469 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7470 hmargin
= vmargin
= relief
;
7472 if (INTEGERP (Vtool_bar_button_margin
)
7473 && XINT (Vtool_bar_button_margin
) > 0)
7475 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7476 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7478 else if (CONSP (Vtool_bar_button_margin
))
7480 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7481 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7482 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7484 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7485 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7486 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7489 if (auto_raise_tool_bar_buttons_p
)
7491 /* Add a `:relief' property to the image spec if the item is
7495 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7502 /* If image is selected, display it pressed, i.e. with a
7503 negative relief. If it's not selected, display it with a
7505 plist
= Fplist_put (plist
, QCrelief
,
7507 ? make_number (-relief
)
7508 : make_number (relief
)));
7513 /* Put a margin around the image. */
7514 if (hmargin
|| vmargin
)
7516 if (hmargin
== vmargin
)
7517 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7519 plist
= Fplist_put (plist
, QCmargin
,
7520 Fcons (make_number (hmargin
),
7521 make_number (vmargin
)));
7524 /* If button is not enabled, and we don't have special images
7525 for the disabled state, make the image appear disabled by
7526 applying an appropriate algorithm to it. */
7527 if (!enabled_p
&& idx
< 0)
7528 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7530 /* Put a `display' text property on the string for the image to
7531 display. Put a `menu-item' property on the string that gives
7532 the start of this item's properties in the tool-bar items
7534 image
= Fcons (Qimage
, plist
);
7535 props
= list4 (Qdisplay
, image
,
7536 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7538 /* Let the last image hide all remaining spaces in the tool bar
7539 string. The string can be longer than needed when we reuse a
7541 if (i
+ 1 == f
->n_tool_bar_items
)
7542 end
= XSTRING (f
->desired_tool_bar_string
)->size
;
7545 Fadd_text_properties (make_number (i
), make_number (end
),
7546 props
, f
->desired_tool_bar_string
);
7554 /* Display one line of the tool-bar of frame IT->f. */
7557 display_tool_bar_line (it
)
7560 struct glyph_row
*row
= it
->glyph_row
;
7561 int max_x
= it
->last_visible_x
;
7564 prepare_desired_row (row
);
7565 row
->y
= it
->current_y
;
7567 /* Note that this isn't made use of if the face hasn't a box,
7568 so there's no need to check the face here. */
7569 it
->start_of_box_run_p
= 1;
7571 while (it
->current_x
< max_x
)
7573 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7575 /* Get the next display element. */
7576 if (!get_next_display_element (it
))
7579 /* Produce glyphs. */
7580 x_before
= it
->current_x
;
7581 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7582 PRODUCE_GLYPHS (it
);
7584 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7589 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7591 if (x
+ glyph
->pixel_width
> max_x
)
7593 /* Glyph doesn't fit on line. */
7594 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7600 x
+= glyph
->pixel_width
;
7604 /* Stop at line ends. */
7605 if (ITERATOR_AT_END_OF_LINE_P (it
))
7608 set_iterator_to_next (it
, 1);
7613 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7614 extend_face_to_end_of_line (it
);
7615 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7616 last
->right_box_line_p
= 1;
7617 if (last
== row
->glyphs
[TEXT_AREA
])
7618 last
->left_box_line_p
= 1;
7619 compute_line_metrics (it
);
7621 /* If line is empty, make it occupy the rest of the tool-bar. */
7622 if (!row
->displays_text_p
)
7624 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7625 row
->ascent
= row
->phys_ascent
= 0;
7628 row
->full_width_p
= 1;
7629 row
->continued_p
= 0;
7630 row
->truncated_on_left_p
= 0;
7631 row
->truncated_on_right_p
= 0;
7633 it
->current_x
= it
->hpos
= 0;
7634 it
->current_y
+= row
->height
;
7640 /* Value is the number of screen lines needed to make all tool-bar
7641 items of frame F visible. */
7644 tool_bar_lines_needed (f
)
7647 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7650 /* Initialize an iterator for iteration over
7651 F->desired_tool_bar_string in the tool-bar window of frame F. */
7652 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7653 it
.first_visible_x
= 0;
7654 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7655 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7657 while (!ITERATOR_AT_END_P (&it
))
7659 it
.glyph_row
= w
->desired_matrix
->rows
;
7660 clear_glyph_row (it
.glyph_row
);
7661 display_tool_bar_line (&it
);
7664 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7668 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7670 "Return the number of lines occupied by the tool bar of FRAME.")
7679 frame
= selected_frame
;
7681 CHECK_FRAME (frame
, 0);
7684 if (WINDOWP (f
->tool_bar_window
)
7685 || (w
= XWINDOW (f
->tool_bar_window
),
7686 XFASTINT (w
->height
) > 0))
7688 update_tool_bar (f
, 1);
7689 if (f
->n_tool_bar_items
)
7691 build_desired_tool_bar_string (f
);
7692 nlines
= tool_bar_lines_needed (f
);
7696 return make_number (nlines
);
7700 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7701 height should be changed. */
7704 redisplay_tool_bar (f
)
7709 struct glyph_row
*row
;
7710 int change_height_p
= 0;
7712 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7713 do anything. This means you must start with tool-bar-lines
7714 non-zero to get the auto-sizing effect. Or in other words, you
7715 can turn off tool-bars by specifying tool-bar-lines zero. */
7716 if (!WINDOWP (f
->tool_bar_window
)
7717 || (w
= XWINDOW (f
->tool_bar_window
),
7718 XFASTINT (w
->height
) == 0))
7721 /* Set up an iterator for the tool-bar window. */
7722 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7723 it
.first_visible_x
= 0;
7724 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7727 /* Build a string that represents the contents of the tool-bar. */
7728 build_desired_tool_bar_string (f
);
7729 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7731 /* Display as many lines as needed to display all tool-bar items. */
7732 while (it
.current_y
< it
.last_visible_y
)
7733 display_tool_bar_line (&it
);
7735 /* It doesn't make much sense to try scrolling in the tool-bar
7736 window, so don't do it. */
7737 w
->desired_matrix
->no_scrolling_p
= 1;
7738 w
->must_be_updated_p
= 1;
7740 if (auto_resize_tool_bars_p
)
7744 /* If we couldn't display everything, change the tool-bar's
7746 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7747 change_height_p
= 1;
7749 /* If there are blank lines at the end, except for a partially
7750 visible blank line at the end that is smaller than
7751 CANON_Y_UNIT, change the tool-bar's height. */
7752 row
= it
.glyph_row
- 1;
7753 if (!row
->displays_text_p
7754 && row
->height
>= CANON_Y_UNIT (f
))
7755 change_height_p
= 1;
7757 /* If row displays tool-bar items, but is partially visible,
7758 change the tool-bar's height. */
7759 if (row
->displays_text_p
7760 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7761 change_height_p
= 1;
7763 /* Resize windows as needed by changing the `tool-bar-lines'
7766 && (nlines
= tool_bar_lines_needed (f
),
7767 nlines
!= XFASTINT (w
->height
)))
7769 extern Lisp_Object Qtool_bar_lines
;
7771 int old_height
= XFASTINT (w
->height
);
7773 XSETFRAME (frame
, f
);
7774 clear_glyph_matrix (w
->desired_matrix
);
7775 Fmodify_frame_parameters (frame
,
7776 Fcons (Fcons (Qtool_bar_lines
,
7777 make_number (nlines
)),
7779 if (XFASTINT (w
->height
) != old_height
)
7780 fonts_changed_p
= 1;
7784 return change_height_p
;
7788 /* Get information about the tool-bar item which is displayed in GLYPH
7789 on frame F. Return in *PROP_IDX the index where tool-bar item
7790 properties start in F->tool_bar_items. Value is zero if
7791 GLYPH doesn't display a tool-bar item. */
7794 tool_bar_item_info (f
, glyph
, prop_idx
)
7796 struct glyph
*glyph
;
7802 /* Get the text property `menu-item' at pos. The value of that
7803 property is the start index of this item's properties in
7804 F->tool_bar_items. */
7805 prop
= Fget_text_property (make_number (glyph
->charpos
),
7806 Qmenu_item
, f
->current_tool_bar_string
);
7807 if (INTEGERP (prop
))
7809 *prop_idx
= XINT (prop
);
7818 #endif /* HAVE_WINDOW_SYSTEM */
7822 /************************************************************************
7823 Horizontal scrolling
7824 ************************************************************************/
7826 static int hscroll_window_tree
P_ ((Lisp_Object
));
7827 static int hscroll_windows
P_ ((Lisp_Object
));
7829 /* For all leaf windows in the window tree rooted at WINDOW, set their
7830 hscroll value so that PT is (i) visible in the window, and (ii) so
7831 that it is not within a certain margin at the window's left and
7832 right border. Value is non-zero if any window's hscroll has been
7836 hscroll_window_tree (window
)
7839 int hscrolled_p
= 0;
7841 while (WINDOWP (window
))
7843 struct window
*w
= XWINDOW (window
);
7845 if (WINDOWP (w
->hchild
))
7846 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7847 else if (WINDOWP (w
->vchild
))
7848 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7849 else if (w
->cursor
.vpos
>= 0)
7851 int hscroll_margin
, text_area_x
, text_area_y
;
7852 int text_area_width
, text_area_height
;
7853 struct glyph_row
*current_cursor_row
7854 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7855 struct glyph_row
*desired_cursor_row
7856 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7857 struct glyph_row
*cursor_row
7858 = (desired_cursor_row
->enabled_p
7859 ? desired_cursor_row
7860 : current_cursor_row
);
7862 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7863 &text_area_width
, &text_area_height
);
7865 /* Scroll when cursor is inside this scroll margin. */
7866 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
7868 if ((XFASTINT (w
->hscroll
)
7869 && w
->cursor
.x
< hscroll_margin
)
7870 || (cursor_row
->enabled_p
7871 && cursor_row
->truncated_on_right_p
7872 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
7876 struct buffer
*saved_current_buffer
;
7879 /* Find point in a display of infinite width. */
7880 saved_current_buffer
= current_buffer
;
7881 current_buffer
= XBUFFER (w
->buffer
);
7883 if (w
== XWINDOW (selected_window
))
7884 pt
= BUF_PT (current_buffer
);
7887 pt
= marker_position (w
->pointm
);
7888 pt
= max (BEGV
, pt
);
7892 /* Move iterator to pt starting at cursor_row->start in
7893 a line with infinite width. */
7894 init_to_row_start (&it
, w
, cursor_row
);
7895 it
.last_visible_x
= INFINITY
;
7896 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
7897 current_buffer
= saved_current_buffer
;
7899 /* Center cursor in window. */
7900 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
7901 / CANON_X_UNIT (it
.f
));
7902 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
7904 /* Don't call Fset_window_hscroll if value hasn't
7905 changed because it will prevent redisplay
7907 if (XFASTINT (w
->hscroll
) != hscroll
)
7909 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
7910 w
->hscroll
= make_number (hscroll
);
7919 /* Value is non-zero if hscroll of any leaf window has been changed. */
7924 /* Set hscroll so that cursor is visible and not inside horizontal
7925 scroll margins for all windows in the tree rooted at WINDOW. See
7926 also hscroll_window_tree above. Value is non-zero if any window's
7927 hscroll has been changed. If it has, desired matrices on the frame
7928 of WINDOW are cleared. */
7931 hscroll_windows (window
)
7936 if (automatic_hscrolling_p
)
7938 hscrolled_p
= hscroll_window_tree (window
);
7940 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
7949 /************************************************************************
7951 ************************************************************************/
7953 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
7954 to a non-zero value. This is sometimes handy to have in a debugger
7959 /* First and last unchanged row for try_window_id. */
7961 int debug_first_unchanged_at_end_vpos
;
7962 int debug_last_unchanged_at_beg_vpos
;
7964 /* Delta vpos and y. */
7966 int debug_dvpos
, debug_dy
;
7968 /* Delta in characters and bytes for try_window_id. */
7970 int debug_delta
, debug_delta_bytes
;
7972 /* Values of window_end_pos and window_end_vpos at the end of
7975 int debug_end_pos
, debug_end_vpos
;
7977 /* Append a string to W->desired_matrix->method. FMT is a printf
7978 format string. A1...A9 are a supplement for a variable-length
7979 argument list. If trace_redisplay_p is non-zero also printf the
7980 resulting string to stderr. */
7983 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
7986 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
7989 char *method
= w
->desired_matrix
->method
;
7990 int len
= strlen (method
);
7991 int size
= sizeof w
->desired_matrix
->method
;
7992 int remaining
= size
- len
- 1;
7994 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
7995 if (len
&& remaining
)
8001 strncpy (method
+ len
, buffer
, remaining
);
8003 if (trace_redisplay_p
)
8004 fprintf (stderr
, "%p (%s): %s\n",
8006 ((BUFFERP (w
->buffer
)
8007 && STRINGP (XBUFFER (w
->buffer
)->name
))
8008 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
8013 #endif /* GLYPH_DEBUG */
8016 /* This counter is used to clear the face cache every once in a while
8017 in redisplay_internal. It is incremented for each redisplay.
8018 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8021 #define CLEAR_FACE_CACHE_COUNT 10000
8022 static int clear_face_cache_count
;
8024 /* Record the previous terminal frame we displayed. */
8026 static struct frame
*previous_terminal_frame
;
8028 /* Non-zero while redisplay_internal is in progress. */
8033 /* Value is non-zero if all changes in window W, which displays
8034 current_buffer, are in the text between START and END. START is a
8035 buffer position, END is given as a distance from Z. Used in
8036 redisplay_internal for display optimization. */
8039 text_outside_line_unchanged_p (w
, start
, end
)
8043 int unchanged_p
= 1;
8045 /* If text or overlays have changed, see where. */
8046 if (XFASTINT (w
->last_modified
) < MODIFF
8047 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8049 /* Gap in the line? */
8050 if (GPT
< start
|| Z
- GPT
< end
)
8053 /* Changes start in front of the line, or end after it? */
8055 && (BEG_UNCHANGED
< start
- 1
8056 || END_UNCHANGED
< end
))
8059 /* If selective display, can't optimize if changes start at the
8060 beginning of the line. */
8062 && INTEGERP (current_buffer
->selective_display
)
8063 && XINT (current_buffer
->selective_display
) > 0
8064 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8072 /* Do a frame update, taking possible shortcuts into account. This is
8073 the main external entry point for redisplay.
8075 If the last redisplay displayed an echo area message and that message
8076 is no longer requested, we clear the echo area or bring back the
8077 mini-buffer if that is in use. */
8082 redisplay_internal (0);
8085 /* Return 1 if point moved out of or into a composition. Otherwise
8086 return 0. PREV_BUF and PREV_PT are the last point buffer and
8087 position. BUF and PT are the current point buffer and position. */
8090 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8091 struct buffer
*prev_buf
, *buf
;
8098 XSETBUFFER (buffer
, buf
);
8099 /* Check a composition at the last point if point moved within the
8101 if (prev_buf
== buf
)
8104 /* Point didn't move. */
8107 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8108 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8109 && COMPOSITION_VALID_P (start
, end
, prop
)
8110 && start
< prev_pt
&& end
> prev_pt
)
8111 /* The last point was within the composition. Return 1 iff
8112 point moved out of the composition. */
8113 return (pt
<= start
|| pt
>= end
);
8116 /* Check a composition at the current point. */
8117 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8118 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8119 && COMPOSITION_VALID_P (start
, end
, prop
)
8120 && start
< pt
&& end
> pt
);
8123 /* Reconsider the setting of B->clip_changed which is displayed
8127 reconsider_clip_changes (w
, b
)
8131 if (b
->prevent_redisplay_optimizations_p
)
8132 b
->clip_changed
= 1;
8133 else if (b
->clip_changed
8134 && !NILP (w
->window_end_valid
)
8135 && w
->current_matrix
->buffer
== b
8136 && w
->current_matrix
->zv
== BUF_ZV (b
)
8137 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8138 b
->clip_changed
= 0;
8140 /* If display wasn't paused, and W is not a tool bar window, see if
8141 point has been moved into or out of a composition. In that case,
8142 we set b->clip_changed to 1 to force updating the screen. If
8143 b->clip_changed has already been set to 1, we can skip this
8145 if (!b
->clip_changed
8146 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8150 if (w
== XWINDOW (selected_window
))
8151 pt
= BUF_PT (current_buffer
);
8153 pt
= marker_position (w
->pointm
);
8155 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8156 || pt
!= XINT (w
->last_point
))
8157 && check_point_in_composition (w
->current_matrix
->buffer
,
8158 XINT (w
->last_point
),
8159 XBUFFER (w
->buffer
), pt
))
8160 b
->clip_changed
= 1;
8165 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8166 response to any user action; therefore, we should preserve the echo
8167 area. (Actually, our caller does that job.) Perhaps in the future
8168 avoid recentering windows if it is not necessary; currently that
8169 causes some problems. */
8172 redisplay_internal (preserve_echo_area
)
8173 int preserve_echo_area
;
8175 struct window
*w
= XWINDOW (selected_window
);
8176 struct frame
*f
= XFRAME (w
->frame
);
8178 int must_finish
= 0;
8179 struct text_pos tlbufpos
, tlendpos
;
8180 int number_of_visible_frames
;
8182 struct frame
*sf
= SELECTED_FRAME ();
8184 /* Non-zero means redisplay has to consider all windows on all
8185 frames. Zero means, only selected_window is considered. */
8186 int consider_all_windows_p
;
8188 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8190 /* No redisplay if running in batch mode or frame is not yet fully
8191 initialized, or redisplay is explicitly turned off by setting
8192 Vinhibit_redisplay. */
8194 || !NILP (Vinhibit_redisplay
)
8195 || !f
->glyphs_initialized_p
)
8198 /* The flag redisplay_performed_directly_p is set by
8199 direct_output_for_insert when it already did the whole screen
8200 update necessary. */
8201 if (redisplay_performed_directly_p
)
8203 redisplay_performed_directly_p
= 0;
8204 if (!hscroll_windows (selected_window
))
8208 #ifdef USE_X_TOOLKIT
8209 if (popup_activated ())
8213 /* I don't think this happens but let's be paranoid. */
8217 /* Record a function that resets redisplaying_p to its old value
8218 when we leave this function. */
8219 count
= BINDING_STACK_SIZE ();
8220 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8225 reconsider_clip_changes (w
, current_buffer
);
8227 /* If new fonts have been loaded that make a glyph matrix adjustment
8228 necessary, do it. */
8229 if (fonts_changed_p
)
8231 adjust_glyphs (NULL
);
8232 ++windows_or_buffers_changed
;
8233 fonts_changed_p
= 0;
8236 /* If face_change_count is non-zero, init_iterator will free all
8237 realized faces, which includes the faces referenced from current
8238 matrices. So, we can't reuse current matrices in this case. */
8239 if (face_change_count
)
8240 ++windows_or_buffers_changed
;
8242 if (! FRAME_WINDOW_P (sf
)
8243 && previous_terminal_frame
!= sf
)
8245 /* Since frames on an ASCII terminal share the same display
8246 area, displaying a different frame means redisplay the whole
8248 windows_or_buffers_changed
++;
8249 SET_FRAME_GARBAGED (sf
);
8250 XSETFRAME (Vterminal_frame
, sf
);
8252 previous_terminal_frame
= sf
;
8254 /* Set the visible flags for all frames. Do this before checking
8255 for resized or garbaged frames; they want to know if their frames
8256 are visible. See the comment in frame.h for
8257 FRAME_SAMPLE_VISIBILITY. */
8259 Lisp_Object tail
, frame
;
8261 number_of_visible_frames
= 0;
8263 FOR_EACH_FRAME (tail
, frame
)
8265 struct frame
*f
= XFRAME (frame
);
8267 FRAME_SAMPLE_VISIBILITY (f
);
8268 if (FRAME_VISIBLE_P (f
))
8269 ++number_of_visible_frames
;
8270 clear_desired_matrices (f
);
8274 /* Notice any pending interrupt request to change frame size. */
8275 do_pending_window_change (1);
8277 /* Clear frames marked as garbaged. */
8279 clear_garbaged_frames ();
8281 /* Build menubar and tool-bar items. */
8282 prepare_menu_bars ();
8284 if (windows_or_buffers_changed
)
8285 update_mode_lines
++;
8287 /* Detect case that we need to write or remove a star in the mode line. */
8288 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8290 w
->update_mode_line
= Qt
;
8291 if (buffer_shared
> 1)
8292 update_mode_lines
++;
8295 /* If %c is in the mode line, update it if needed. */
8296 if (!NILP (w
->column_number_displayed
)
8297 /* This alternative quickly identifies a common case
8298 where no change is needed. */
8299 && !(PT
== XFASTINT (w
->last_point
)
8300 && XFASTINT (w
->last_modified
) >= MODIFF
8301 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8302 && XFASTINT (w
->column_number_displayed
) != current_column ())
8303 w
->update_mode_line
= Qt
;
8305 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8307 /* The variable buffer_shared is set in redisplay_window and
8308 indicates that we redisplay a buffer in different windows. See
8310 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8312 /* If specs for an arrow have changed, do thorough redisplay
8313 to ensure we remove any arrow that should no longer exist. */
8314 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8315 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8316 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8318 /* Normally the message* functions will have already displayed and
8319 updated the echo area, but the frame may have been trashed, or
8320 the update may have been preempted, so display the echo area
8321 again here. Checking both message buffers captures the case that
8322 the echo area should be cleared. */
8323 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
8325 int window_height_changed_p
= echo_area_display (0);
8328 if (fonts_changed_p
)
8330 else if (window_height_changed_p
)
8332 consider_all_windows_p
= 1;
8333 ++update_mode_lines
;
8334 ++windows_or_buffers_changed
;
8336 /* If window configuration was changed, frames may have been
8337 marked garbaged. Clear them or we will experience
8338 surprises wrt scrolling. */
8340 clear_garbaged_frames ();
8343 else if (EQ (selected_window
, minibuf_window
)
8344 && (current_buffer
->clip_changed
8345 || XFASTINT (w
->last_modified
) < MODIFF
8346 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8347 && resize_mini_window (w
, 0))
8349 /* Resized active mini-window to fit the size of what it is
8350 showing if its contents might have changed. */
8352 consider_all_windows_p
= 1;
8353 ++windows_or_buffers_changed
;
8354 ++update_mode_lines
;
8356 /* If window configuration was changed, frames may have been
8357 marked garbaged. Clear them or we will experience
8358 surprises wrt scrolling. */
8360 clear_garbaged_frames ();
8364 /* If showing the region, and mark has changed, we must redisplay
8365 the whole window. The assignment to this_line_start_pos prevents
8366 the optimization directly below this if-statement. */
8367 if (((!NILP (Vtransient_mark_mode
)
8368 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8369 != !NILP (w
->region_showing
))
8370 || (!NILP (w
->region_showing
)
8371 && !EQ (w
->region_showing
,
8372 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8373 CHARPOS (this_line_start_pos
) = 0;
8375 /* Optimize the case that only the line containing the cursor in the
8376 selected window has changed. Variables starting with this_ are
8377 set in display_line and record information about the line
8378 containing the cursor. */
8379 tlbufpos
= this_line_start_pos
;
8380 tlendpos
= this_line_end_pos
;
8381 if (!consider_all_windows_p
8382 && CHARPOS (tlbufpos
) > 0
8383 && NILP (w
->update_mode_line
)
8384 && !current_buffer
->clip_changed
8385 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8386 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8387 /* Make sure recorded data applies to current buffer, etc. */
8388 && this_line_buffer
== current_buffer
8389 && current_buffer
== XBUFFER (w
->buffer
)
8390 && NILP (w
->force_start
)
8391 /* Point must be on the line that we have info recorded about. */
8392 && PT
>= CHARPOS (tlbufpos
)
8393 && PT
<= Z
- CHARPOS (tlendpos
)
8394 /* All text outside that line, including its final newline,
8395 must be unchanged */
8396 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8397 CHARPOS (tlendpos
)))
8399 if (CHARPOS (tlbufpos
) > BEGV
8400 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8401 && (CHARPOS (tlbufpos
) == ZV
8402 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8403 /* Former continuation line has disappeared by becoming empty */
8405 else if (XFASTINT (w
->last_modified
) < MODIFF
8406 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8407 || MINI_WINDOW_P (w
))
8409 /* We have to handle the case of continuation around a
8410 wide-column character (See the comment in indent.c around
8413 For instance, in the following case:
8415 -------- Insert --------
8416 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8417 J_I_ ==> J_I_ `^^' are cursors.
8421 As we have to redraw the line above, we should goto cancel. */
8424 int line_height_before
= this_line_pixel_height
;
8426 /* Note that start_display will handle the case that the
8427 line starting at tlbufpos is a continuation lines. */
8428 start_display (&it
, w
, tlbufpos
);
8430 /* Implementation note: It this still necessary? */
8431 if (it
.current_x
!= this_line_start_x
)
8434 TRACE ((stderr
, "trying display optimization 1\n"));
8435 w
->cursor
.vpos
= -1;
8436 overlay_arrow_seen
= 0;
8437 it
.vpos
= this_line_vpos
;
8438 it
.current_y
= this_line_y
;
8439 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8442 /* If line contains point, is not continued,
8443 and ends at same distance from eob as before, we win */
8444 if (w
->cursor
.vpos
>= 0
8445 /* Line is not continued, otherwise this_line_start_pos
8446 would have been set to 0 in display_line. */
8447 && CHARPOS (this_line_start_pos
)
8448 /* Line ends as before. */
8449 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8450 /* Line has same height as before. Otherwise other lines
8451 would have to be shifted up or down. */
8452 && this_line_pixel_height
== line_height_before
)
8454 /* If this is not the window's last line, we must adjust
8455 the charstarts of the lines below. */
8456 if (it
.current_y
< it
.last_visible_y
)
8458 struct glyph_row
*row
8459 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8460 int delta
, delta_bytes
;
8462 if (Z
- CHARPOS (tlendpos
) == ZV
)
8464 /* This line ends at end of (accessible part of)
8465 buffer. There is no newline to count. */
8467 - CHARPOS (tlendpos
)
8468 - MATRIX_ROW_START_CHARPOS (row
));
8469 delta_bytes
= (Z_BYTE
8470 - BYTEPOS (tlendpos
)
8471 - MATRIX_ROW_START_BYTEPOS (row
));
8475 /* This line ends in a newline. Must take
8476 account of the newline and the rest of the
8477 text that follows. */
8479 - CHARPOS (tlendpos
)
8480 - MATRIX_ROW_START_CHARPOS (row
));
8481 delta_bytes
= (Z_BYTE
8482 - BYTEPOS (tlendpos
)
8483 - MATRIX_ROW_START_BYTEPOS (row
));
8486 increment_matrix_positions (w
->current_matrix
,
8488 w
->current_matrix
->nrows
,
8489 delta
, delta_bytes
);
8492 /* If this row displays text now but previously didn't,
8493 or vice versa, w->window_end_vpos may have to be
8495 if ((it
.glyph_row
- 1)->displays_text_p
)
8497 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8498 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8500 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8501 && this_line_vpos
> 0)
8502 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8503 w
->window_end_valid
= Qnil
;
8505 /* Update hint: No need to try to scroll in update_window. */
8506 w
->desired_matrix
->no_scrolling_p
= 1;
8509 *w
->desired_matrix
->method
= 0;
8510 debug_method_add (w
, "optimization 1");
8517 else if (/* Cursor position hasn't changed. */
8518 PT
== XFASTINT (w
->last_point
)
8519 /* Make sure the cursor was last displayed
8520 in this window. Otherwise we have to reposition it. */
8521 && 0 <= w
->cursor
.vpos
8522 && XINT (w
->height
) > w
->cursor
.vpos
)
8526 do_pending_window_change (1);
8528 /* We used to always goto end_of_redisplay here, but this
8529 isn't enough if we have a blinking cursor. */
8530 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8531 goto end_of_redisplay
;
8535 /* If highlighting the region, or if the cursor is in the echo area,
8536 then we can't just move the cursor. */
8537 else if (! (!NILP (Vtransient_mark_mode
)
8538 && !NILP (current_buffer
->mark_active
))
8539 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8540 || highlight_nonselected_windows
)
8541 && NILP (w
->region_showing
)
8542 && NILP (Vshow_trailing_whitespace
)
8543 && !cursor_in_echo_area
)
8546 struct glyph_row
*row
;
8548 /* Skip from tlbufpos to PT and see where it is. Note that
8549 PT may be in invisible text. If so, we will end at the
8550 next visible position. */
8551 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8552 NULL
, DEFAULT_FACE_ID
);
8553 it
.current_x
= this_line_start_x
;
8554 it
.current_y
= this_line_y
;
8555 it
.vpos
= this_line_vpos
;
8557 /* The call to move_it_to stops in front of PT, but
8558 moves over before-strings. */
8559 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8561 if (it
.vpos
== this_line_vpos
8562 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8565 xassert (this_line_vpos
== it
.vpos
);
8566 xassert (this_line_y
== it
.current_y
);
8567 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8569 *w
->desired_matrix
->method
= 0;
8570 debug_method_add (w
, "optimization 3");
8579 /* Text changed drastically or point moved off of line. */
8580 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8583 CHARPOS (this_line_start_pos
) = 0;
8584 consider_all_windows_p
|= buffer_shared
> 1;
8585 ++clear_face_cache_count
;
8588 /* Build desired matrices, and update the display. If
8589 consider_all_windows_p is non-zero, do it for all windows on all
8590 frames. Otherwise do it for selected_window, only. */
8592 if (consider_all_windows_p
)
8594 Lisp_Object tail
, frame
;
8595 int i
, n
= 0, size
= 50;
8596 struct frame
**updated
8597 = (struct frame
**) alloca (size
* sizeof *updated
);
8599 /* Clear the face cache eventually. */
8600 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8602 clear_face_cache (0);
8603 clear_face_cache_count
= 0;
8606 /* Recompute # windows showing selected buffer. This will be
8607 incremented each time such a window is displayed. */
8610 FOR_EACH_FRAME (tail
, frame
)
8612 struct frame
*f
= XFRAME (frame
);
8614 if (FRAME_WINDOW_P (f
) || f
== sf
)
8616 /* Mark all the scroll bars to be removed; we'll redeem
8617 the ones we want when we redisplay their windows. */
8618 if (condemn_scroll_bars_hook
)
8619 condemn_scroll_bars_hook (f
);
8621 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8622 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8624 /* Any scroll bars which redisplay_windows should have
8625 nuked should now go away. */
8626 if (judge_scroll_bars_hook
)
8627 judge_scroll_bars_hook (f
);
8629 /* If fonts changed, display again. */
8630 if (fonts_changed_p
)
8633 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8635 /* See if we have to hscroll. */
8636 if (hscroll_windows (f
->root_window
))
8639 /* Prevent various kinds of signals during display
8640 update. stdio is not robust about handling
8641 signals, which can cause an apparent I/O
8643 if (interrupt_input
)
8647 /* Update the display. */
8648 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8649 pause
|= update_frame (f
, 0, 0);
8655 int nbytes
= size
* sizeof *updated
;
8656 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8657 bcopy (updated
, p
, nbytes
);
8666 /* Do the mark_window_display_accurate after all windows have
8667 been redisplayed because this call resets flags in buffers
8668 which are needed for proper redisplay. */
8669 for (i
= 0; i
< n
; ++i
)
8671 struct frame
*f
= updated
[i
];
8672 mark_window_display_accurate (f
->root_window
, 1);
8673 if (frame_up_to_date_hook
)
8674 frame_up_to_date_hook (f
);
8677 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8679 Lisp_Object mini_window
;
8680 struct frame
*mini_frame
;
8682 redisplay_window (selected_window
, 1);
8684 /* Compare desired and current matrices, perform output. */
8687 /* If fonts changed, display again. */
8688 if (fonts_changed_p
)
8691 /* Prevent various kinds of signals during display update.
8692 stdio is not robust about handling signals,
8693 which can cause an apparent I/O error. */
8694 if (interrupt_input
)
8698 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8700 if (hscroll_windows (selected_window
))
8703 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8704 pause
= update_frame (sf
, 0, 0);
8707 /* We may have called echo_area_display at the top of this
8708 function. If the echo area is on another frame, that may
8709 have put text on a frame other than the selected one, so the
8710 above call to update_frame would not have caught it. Catch
8712 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8713 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8715 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8717 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8718 pause
|= update_frame (mini_frame
, 0, 0);
8719 if (!pause
&& hscroll_windows (mini_window
))
8724 /* If display was paused because of pending input, make sure we do a
8725 thorough update the next time. */
8728 /* Prevent the optimization at the beginning of
8729 redisplay_internal that tries a single-line update of the
8730 line containing the cursor in the selected window. */
8731 CHARPOS (this_line_start_pos
) = 0;
8733 /* Let the overlay arrow be updated the next time. */
8734 if (!NILP (last_arrow_position
))
8736 last_arrow_position
= Qt
;
8737 last_arrow_string
= Qt
;
8740 /* If we pause after scrolling, some rows in the current
8741 matrices of some windows are not valid. */
8742 if (!WINDOW_FULL_WIDTH_P (w
)
8743 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8744 update_mode_lines
= 1;
8748 if (!consider_all_windows_p
)
8750 /* This has already been done above if
8751 consider_all_windows_p is set. */
8752 mark_window_display_accurate_1 (w
, 1);
8754 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8755 last_arrow_string
= Voverlay_arrow_string
;
8757 if (frame_up_to_date_hook
!= 0)
8758 frame_up_to_date_hook (sf
);
8761 update_mode_lines
= 0;
8762 windows_or_buffers_changed
= 0;
8765 /* Start SIGIO interrupts coming again. Having them off during the
8766 code above makes it less likely one will discard output, but not
8767 impossible, since there might be stuff in the system buffer here.
8768 But it is much hairier to try to do anything about that. */
8769 if (interrupt_input
)
8773 /* If a frame has become visible which was not before, redisplay
8774 again, so that we display it. Expose events for such a frame
8775 (which it gets when becoming visible) don't call the parts of
8776 redisplay constructing glyphs, so simply exposing a frame won't
8777 display anything in this case. So, we have to display these
8778 frames here explicitly. */
8781 Lisp_Object tail
, frame
;
8784 FOR_EACH_FRAME (tail
, frame
)
8786 int this_is_visible
= 0;
8788 if (XFRAME (frame
)->visible
)
8789 this_is_visible
= 1;
8790 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8791 if (XFRAME (frame
)->visible
)
8792 this_is_visible
= 1;
8794 if (this_is_visible
)
8798 if (new_count
!= number_of_visible_frames
)
8799 windows_or_buffers_changed
++;
8802 /* Change frame size now if a change is pending. */
8803 do_pending_window_change (1);
8805 /* If we just did a pending size change, or have additional
8806 visible frames, redisplay again. */
8807 if (windows_or_buffers_changed
&& !pause
)
8812 unbind_to (count
, Qnil
);
8816 /* Redisplay, but leave alone any recent echo area message unless
8817 another message has been requested in its place.
8819 This is useful in situations where you need to redisplay but no
8820 user action has occurred, making it inappropriate for the message
8821 area to be cleared. See tracking_off and
8822 wait_reading_process_input for examples of these situations.
8824 FROM_WHERE is an integer saying from where this function was
8825 called. This is useful for debugging. */
8828 redisplay_preserve_echo_area (from_where
)
8831 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
8833 if (!NILP (echo_area_buffer
[1]))
8835 /* We have a previously displayed message, but no current
8836 message. Redisplay the previous message. */
8837 display_last_displayed_message_p
= 1;
8838 redisplay_internal (1);
8839 display_last_displayed_message_p
= 0;
8842 redisplay_internal (1);
8846 /* Function registered with record_unwind_protect in
8847 redisplay_internal. Clears the flag indicating that a redisplay is
8851 unwind_redisplay (old_redisplaying_p
)
8852 Lisp_Object old_redisplaying_p
;
8854 redisplaying_p
= XFASTINT (old_redisplaying_p
);
8859 /* Mark the display of window W as accurate or inaccurate. If
8860 ACCURATE_P is non-zero mark display of W as accurate. If
8861 ACCURATE_P is zero, arrange for W to be redisplayed the next time
8862 redisplay_internal is called. */
8865 mark_window_display_accurate_1 (w
, accurate_p
)
8869 if (BUFFERP (w
->buffer
))
8871 struct buffer
*b
= XBUFFER (w
->buffer
);
8874 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
8875 w
->last_overlay_modified
8876 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
8878 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
8882 b
->clip_changed
= 0;
8883 b
->prevent_redisplay_optimizations_p
= 0;
8885 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
8886 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
8887 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
8888 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
8890 w
->current_matrix
->buffer
= b
;
8891 w
->current_matrix
->begv
= BUF_BEGV (b
);
8892 w
->current_matrix
->zv
= BUF_ZV (b
);
8894 w
->last_cursor
= w
->cursor
;
8895 w
->last_cursor_off_p
= w
->cursor_off_p
;
8897 if (w
== XWINDOW (selected_window
))
8898 w
->last_point
= make_number (BUF_PT (b
));
8900 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
8906 w
->window_end_valid
= w
->buffer
;
8907 w
->update_mode_line
= Qnil
;
8912 /* Mark the display of windows in the window tree rooted at WINDOW as
8913 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
8914 windows as accurate. If ACCURATE_P is zero, arrange for windows to
8915 be redisplayed the next time redisplay_internal is called. */
8918 mark_window_display_accurate (window
, accurate_p
)
8924 for (; !NILP (window
); window
= w
->next
)
8926 w
= XWINDOW (window
);
8927 mark_window_display_accurate_1 (w
, accurate_p
);
8929 if (!NILP (w
->vchild
))
8930 mark_window_display_accurate (w
->vchild
, accurate_p
);
8931 if (!NILP (w
->hchild
))
8932 mark_window_display_accurate (w
->hchild
, accurate_p
);
8937 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8938 last_arrow_string
= Voverlay_arrow_string
;
8942 /* Force a thorough redisplay the next time by setting
8943 last_arrow_position and last_arrow_string to t, which is
8944 unequal to any useful value of Voverlay_arrow_... */
8945 last_arrow_position
= Qt
;
8946 last_arrow_string
= Qt
;
8951 /* Return value in display table DP (Lisp_Char_Table *) for character
8952 C. Since a display table doesn't have any parent, we don't have to
8953 follow parent. Do not call this function directly but use the
8954 macro DISP_CHAR_VECTOR. */
8957 disp_char_vector (dp
, c
)
8958 struct Lisp_Char_Table
*dp
;
8964 if (SINGLE_BYTE_CHAR_P (c
))
8965 return (dp
->contents
[c
]);
8967 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
8970 else if (code
[2] < 32)
8973 /* Here, the possible range of code[0] (== charset ID) is
8974 128..max_charset. Since the top level char table contains data
8975 for multibyte characters after 256th element, we must increment
8976 code[0] by 128 to get a correct index. */
8978 code
[3] = -1; /* anchor */
8980 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
8982 val
= dp
->contents
[code
[i
]];
8983 if (!SUB_CHAR_TABLE_P (val
))
8984 return (NILP (val
) ? dp
->defalt
: val
);
8987 /* Here, val is a sub char table. We return the default value of
8989 return (dp
->defalt
);
8994 /***********************************************************************
8996 ***********************************************************************/
8998 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9001 redisplay_windows (window
)
9004 while (!NILP (window
))
9006 struct window
*w
= XWINDOW (window
);
9008 if (!NILP (w
->hchild
))
9009 redisplay_windows (w
->hchild
);
9010 else if (!NILP (w
->vchild
))
9011 redisplay_windows (w
->vchild
);
9013 redisplay_window (window
, 0);
9020 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9021 DELTA is the number of bytes by which positions recorded in ROW
9022 differ from current buffer positions. */
9025 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9027 struct glyph_row
*row
;
9028 struct glyph_matrix
*matrix
;
9029 int delta
, delta_bytes
, dy
, dvpos
;
9031 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9032 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9034 int pt_old
= PT
- delta
;
9036 /* Skip over glyphs not having an object at the start of the row.
9037 These are special glyphs like truncation marks on terminal
9039 if (row
->displays_text_p
)
9041 && INTEGERP (glyph
->object
)
9042 && glyph
->charpos
< 0)
9044 x
+= glyph
->pixel_width
;
9049 && !INTEGERP (glyph
->object
)
9050 && (!BUFFERP (glyph
->object
)
9051 || glyph
->charpos
< pt_old
))
9053 x
+= glyph
->pixel_width
;
9057 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9059 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9060 w
->cursor
.y
= row
->y
+ dy
;
9062 if (w
== XWINDOW (selected_window
))
9064 if (!row
->continued_p
9065 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9068 this_line_buffer
= XBUFFER (w
->buffer
);
9070 CHARPOS (this_line_start_pos
)
9071 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9072 BYTEPOS (this_line_start_pos
)
9073 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9075 CHARPOS (this_line_end_pos
)
9076 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9077 BYTEPOS (this_line_end_pos
)
9078 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9080 this_line_y
= w
->cursor
.y
;
9081 this_line_pixel_height
= row
->height
;
9082 this_line_vpos
= w
->cursor
.vpos
;
9083 this_line_start_x
= row
->x
;
9086 CHARPOS (this_line_start_pos
) = 0;
9091 /* Run window scroll functions, if any, for WINDOW with new window
9092 start STARTP. Sets the window start of WINDOW to that position.
9094 We assume that the window's buffer is really current. */
9096 static INLINE
struct text_pos
9097 run_window_scroll_functions (window
, startp
)
9099 struct text_pos startp
;
9101 struct window
*w
= XWINDOW (window
);
9102 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9104 if (current_buffer
!= XBUFFER (w
->buffer
))
9107 if (!NILP (Vwindow_scroll_functions
))
9109 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9110 make_number (CHARPOS (startp
)));
9111 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9112 /* In case the hook functions switch buffers. */
9113 if (current_buffer
!= XBUFFER (w
->buffer
))
9114 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9121 /* Modify the desired matrix of window W and W->vscroll so that the
9122 line containing the cursor is fully visible. */
9125 make_cursor_line_fully_visible (w
)
9128 struct glyph_matrix
*matrix
;
9129 struct glyph_row
*row
;
9132 /* It's not always possible to find the cursor, e.g, when a window
9133 is full of overlay strings. Don't do anything in that case. */
9134 if (w
->cursor
.vpos
< 0)
9137 matrix
= w
->desired_matrix
;
9138 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9140 /* If the cursor row is not partially visible, there's nothing
9142 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9145 /* If the row the cursor is in is taller than the window's height,
9146 it's not clear what to do, so do nothing. */
9147 window_height
= window_box_height (w
);
9148 if (row
->height
>= window_height
)
9151 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9153 int dy
= row
->height
- row
->visible_height
;
9156 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9158 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9160 int dy
= - (row
->height
- row
->visible_height
);
9163 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9166 /* When we change the cursor y-position of the selected window,
9167 change this_line_y as well so that the display optimization for
9168 the cursor line of the selected window in redisplay_internal uses
9169 the correct y-position. */
9170 if (w
== XWINDOW (selected_window
))
9171 this_line_y
= w
->cursor
.y
;
9175 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9176 non-zero means only WINDOW is redisplayed in redisplay_internal.
9177 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9178 in redisplay_window to bring a partially visible line into view in
9179 the case that only the cursor has moved.
9183 1 if scrolling succeeded
9185 0 if scrolling didn't find point.
9187 -1 if new fonts have been loaded so that we must interrupt
9188 redisplay, adjust glyph matrices, and try again. */
9191 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9192 scroll_step
, temp_scroll_step
)
9194 int just_this_one_p
;
9195 int scroll_conservatively
, scroll_step
;
9196 int temp_scroll_step
;
9198 struct window
*w
= XWINDOW (window
);
9199 struct frame
*f
= XFRAME (w
->frame
);
9200 struct text_pos scroll_margin_pos
;
9201 struct text_pos pos
;
9202 struct text_pos startp
;
9204 Lisp_Object window_end
;
9205 int this_scroll_margin
;
9209 int amount_to_scroll
= 0;
9210 Lisp_Object aggressive
;
9214 debug_method_add (w
, "try_scrolling");
9217 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9219 /* Compute scroll margin height in pixels. We scroll when point is
9220 within this distance from the top or bottom of the window. */
9221 if (scroll_margin
> 0)
9223 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9224 this_scroll_margin
*= CANON_Y_UNIT (f
);
9227 this_scroll_margin
= 0;
9229 /* Compute how much we should try to scroll maximally to bring point
9231 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9232 scroll_max
= max (scroll_step
,
9233 max (scroll_conservatively
, temp_scroll_step
));
9234 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9235 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9236 /* We're trying to scroll because of aggressive scrolling
9237 but no scroll_step is set. Choose an arbitrary one. Maybe
9238 there should be a variable for this. */
9242 scroll_max
*= CANON_Y_UNIT (f
);
9244 /* Decide whether we have to scroll down. Start at the window end
9245 and move this_scroll_margin up to find the position of the scroll
9247 window_end
= Fwindow_end (window
, Qt
);
9248 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9249 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9250 if (this_scroll_margin
)
9252 start_display (&it
, w
, scroll_margin_pos
);
9253 move_it_vertically (&it
, - this_scroll_margin
);
9254 scroll_margin_pos
= it
.current
.pos
;
9257 if (PT
>= CHARPOS (scroll_margin_pos
))
9261 /* Point is in the scroll margin at the bottom of the window, or
9262 below. Compute a new window start that makes point visible. */
9264 /* Compute the distance from the scroll margin to PT.
9265 Give up if the distance is greater than scroll_max. */
9266 start_display (&it
, w
, scroll_margin_pos
);
9268 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9269 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9271 /* With a scroll_margin of 0, scroll_margin_pos is at the window
9272 end, which is one line below the window. The iterator's
9273 current_y will be same as y0 in that case, but we have to
9274 scroll a line to make PT visible. That's the reason why 1 is
9276 dy
= 1 + it
.current_y
- y0
;
9278 if (dy
> scroll_max
)
9281 /* Move the window start down. If scrolling conservatively,
9282 move it just enough down to make point visible. If
9283 scroll_step is set, move it down by scroll_step. */
9284 start_display (&it
, w
, startp
);
9286 if (scroll_conservatively
)
9288 = max (max (dy
, CANON_Y_UNIT (f
)),
9289 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9290 else if (scroll_step
|| temp_scroll_step
)
9291 amount_to_scroll
= scroll_max
;
9294 aggressive
= current_buffer
->scroll_down_aggressively
;
9295 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9296 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9297 if (NUMBERP (aggressive
))
9298 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9301 if (amount_to_scroll
<= 0)
9304 move_it_vertically (&it
, amount_to_scroll
);
9305 startp
= it
.current
.pos
;
9309 /* See if point is inside the scroll margin at the top of the
9311 scroll_margin_pos
= startp
;
9312 if (this_scroll_margin
)
9314 start_display (&it
, w
, startp
);
9315 move_it_vertically (&it
, this_scroll_margin
);
9316 scroll_margin_pos
= it
.current
.pos
;
9319 if (PT
< CHARPOS (scroll_margin_pos
))
9321 /* Point is in the scroll margin at the top of the window or
9322 above what is displayed in the window. */
9325 /* Compute the vertical distance from PT to the scroll
9326 margin position. Give up if distance is greater than
9328 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9329 start_display (&it
, w
, pos
);
9331 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9332 it
.last_visible_y
, -1,
9333 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9334 dy
= it
.current_y
- y0
;
9335 if (dy
> scroll_max
)
9338 /* Compute new window start. */
9339 start_display (&it
, w
, startp
);
9341 if (scroll_conservatively
)
9343 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9344 else if (scroll_step
|| temp_scroll_step
)
9345 amount_to_scroll
= scroll_max
;
9348 aggressive
= current_buffer
->scroll_up_aggressively
;
9349 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9350 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9351 if (NUMBERP (aggressive
))
9352 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9355 if (amount_to_scroll
<= 0)
9358 move_it_vertically (&it
, - amount_to_scroll
);
9359 startp
= it
.current
.pos
;
9363 /* Run window scroll functions. */
9364 startp
= run_window_scroll_functions (window
, startp
);
9366 /* Display the window. Give up if new fonts are loaded, or if point
9368 if (!try_window (window
, startp
))
9370 else if (w
->cursor
.vpos
< 0)
9372 clear_glyph_matrix (w
->desired_matrix
);
9377 /* Maybe forget recorded base line for line number display. */
9378 if (!just_this_one_p
9379 || current_buffer
->clip_changed
9380 || BEG_UNCHANGED
< CHARPOS (startp
))
9381 w
->base_line_number
= Qnil
;
9383 /* If cursor ends up on a partially visible line, shift display
9384 lines up or down. */
9385 make_cursor_line_fully_visible (w
);
9393 /* Compute a suitable window start for window W if display of W starts
9394 on a continuation line. Value is non-zero if a new window start
9397 The new window start will be computed, based on W's width, starting
9398 from the start of the continued line. It is the start of the
9399 screen line with the minimum distance from the old start W->start. */
9402 compute_window_start_on_continuation_line (w
)
9405 struct text_pos pos
, start_pos
;
9406 int window_start_changed_p
= 0;
9408 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9410 /* If window start is on a continuation line... Window start may be
9411 < BEGV in case there's invisible text at the start of the
9412 buffer (M-x rmail, for example). */
9413 if (CHARPOS (start_pos
) > BEGV
9414 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9417 struct glyph_row
*row
;
9419 /* Handle the case that the window start is out of range. */
9420 if (CHARPOS (start_pos
) < BEGV
)
9421 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9422 else if (CHARPOS (start_pos
) > ZV
)
9423 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9425 /* Find the start of the continued line. This should be fast
9426 because scan_buffer is fast (newline cache). */
9427 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9428 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9429 row
, DEFAULT_FACE_ID
);
9430 reseat_at_previous_visible_line_start (&it
);
9432 /* If the line start is "too far" away from the window start,
9433 say it takes too much time to compute a new window start. */
9434 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9435 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9437 int min_distance
, distance
;
9439 /* Move forward by display lines to find the new window
9440 start. If window width was enlarged, the new start can
9441 be expected to be > the old start. If window width was
9442 decreased, the new window start will be < the old start.
9443 So, we're looking for the display line start with the
9444 minimum distance from the old window start. */
9445 pos
= it
.current
.pos
;
9446 min_distance
= INFINITY
;
9447 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9448 distance
< min_distance
)
9450 min_distance
= distance
;
9451 pos
= it
.current
.pos
;
9452 move_it_by_lines (&it
, 1, 0);
9455 /* Set the window start there. */
9456 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9457 window_start_changed_p
= 1;
9461 return window_start_changed_p
;
9465 /* Try cursor movement in case text has not changes in window WINDOW,
9466 with window start STARTP. Value is
9470 0 if this method cannot be used
9472 -1 if we know we have to scroll the display. *SCROLL_STEP is
9473 set to 1, under certain circumstances, if we want to scroll as
9474 if scroll-step were set to 1. See the code. */
9477 try_cursor_movement (window
, startp
, scroll_step
)
9479 struct text_pos startp
;
9482 struct window
*w
= XWINDOW (window
);
9483 struct frame
*f
= XFRAME (w
->frame
);
9486 /* Handle case where text has not changed, only point, and it has
9487 not moved off the frame. */
9488 if (/* Point may be in this window. */
9489 PT
>= CHARPOS (startp
)
9490 /* Selective display hasn't changed. */
9491 && !current_buffer
->clip_changed
9492 /* Function force-mode-line-update is used to force a thorough
9493 redisplay. It sets either windows_or_buffers_changed or
9494 update_mode_lines. So don't take a shortcut here for these
9496 && !update_mode_lines
9497 && !windows_or_buffers_changed
9498 /* Can't use this case if highlighting a region. When a
9499 region exists, cursor movement has to do more than just
9501 && !(!NILP (Vtransient_mark_mode
)
9502 && !NILP (current_buffer
->mark_active
))
9503 && NILP (w
->region_showing
)
9504 && NILP (Vshow_trailing_whitespace
)
9505 /* Right after splitting windows, last_point may be nil. */
9506 && INTEGERP (w
->last_point
)
9507 /* This code is not used for mini-buffer for the sake of the case
9508 of redisplaying to replace an echo area message; since in
9509 that case the mini-buffer contents per se are usually
9510 unchanged. This code is of no real use in the mini-buffer
9511 since the handling of this_line_start_pos, etc., in redisplay
9512 handles the same cases. */
9513 && !EQ (window
, minibuf_window
)
9514 /* When splitting windows or for new windows, it happens that
9515 redisplay is called with a nil window_end_vpos or one being
9516 larger than the window. This should really be fixed in
9517 window.c. I don't have this on my list, now, so we do
9518 approximately the same as the old redisplay code. --gerd. */
9519 && INTEGERP (w
->window_end_vpos
)
9520 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9521 && (FRAME_WINDOW_P (f
)
9522 || !MARKERP (Voverlay_arrow_position
)
9523 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9525 int this_scroll_margin
;
9526 struct glyph_row
*row
;
9529 debug_method_add (w
, "cursor movement");
9532 /* Scroll if point within this distance from the top or bottom
9533 of the window. This is a pixel value. */
9534 this_scroll_margin
= max (0, scroll_margin
);
9535 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9536 this_scroll_margin
*= CANON_Y_UNIT (f
);
9538 /* Start with the row the cursor was displayed during the last
9539 not paused redisplay. Give up if that row is not valid. */
9540 if (w
->last_cursor
.vpos
< 0
9541 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9545 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9546 if (row
->mode_line_p
)
9548 if (!row
->enabled_p
)
9555 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9557 if (PT
> XFASTINT (w
->last_point
))
9559 /* Point has moved forward. */
9560 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9561 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9563 xassert (row
->enabled_p
);
9567 /* The end position of a row equals the start position
9568 of the next row. If PT is there, we would rather
9569 display it in the next line. */
9570 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9571 && MATRIX_ROW_END_CHARPOS (row
) == PT
9572 && !cursor_row_p (w
, row
))
9575 /* If within the scroll margin, scroll. Note that
9576 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9577 the next line would be drawn, and that
9578 this_scroll_margin can be zero. */
9579 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9580 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9581 /* Line is completely visible last line in window
9582 and PT is to be set in the next line. */
9583 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9584 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9585 && !row
->ends_at_zv_p
9586 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9589 else if (PT
< XFASTINT (w
->last_point
))
9591 /* Cursor has to be moved backward. Note that PT >=
9592 CHARPOS (startp) because of the outer
9594 while (!row
->mode_line_p
9595 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9596 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9597 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9598 && (row
->y
> this_scroll_margin
9599 || CHARPOS (startp
) == BEGV
))
9601 xassert (row
->enabled_p
);
9605 /* Consider the following case: Window starts at BEGV,
9606 there is invisible, intangible text at BEGV, so that
9607 display starts at some point START > BEGV. It can
9608 happen that we are called with PT somewhere between
9609 BEGV and START. Try to handle that case. */
9610 if (row
< w
->current_matrix
->rows
9611 || row
->mode_line_p
)
9613 row
= w
->current_matrix
->rows
;
9614 if (row
->mode_line_p
)
9618 /* Due to newlines in overlay strings, we may have to
9619 skip forward over overlay strings. */
9620 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9621 && MATRIX_ROW_END_CHARPOS (row
) == PT
9622 && !cursor_row_p (w
, row
))
9625 /* If within the scroll margin, scroll. */
9626 if (row
->y
< this_scroll_margin
9627 && CHARPOS (startp
) != BEGV
)
9631 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9632 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9634 /* if PT is not in the glyph row, give up. */
9637 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9639 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
9640 && !row
->ends_at_zv_p
9641 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
9643 else if (row
->height
> window_box_height (w
))
9645 /* If we end up in a partially visible line, let's
9646 make it fully visible, except when it's taller
9647 than the window, in which case we can't do much
9654 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9655 try_window (window
, startp
);
9656 make_cursor_line_fully_visible (w
);
9664 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9674 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9675 selected_window is redisplayed. */
9678 redisplay_window (window
, just_this_one_p
)
9680 int just_this_one_p
;
9682 struct window
*w
= XWINDOW (window
);
9683 struct frame
*f
= XFRAME (w
->frame
);
9684 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9685 struct buffer
*old
= current_buffer
;
9686 struct text_pos lpoint
, opoint
, startp
;
9687 int update_mode_line
;
9690 /* Record it now because it's overwritten. */
9691 int current_matrix_up_to_date_p
= 0;
9692 int temp_scroll_step
= 0;
9693 int count
= BINDING_STACK_SIZE ();
9696 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9699 /* W must be a leaf window here. */
9700 xassert (!NILP (w
->buffer
));
9702 *w
->desired_matrix
->method
= 0;
9705 specbind (Qinhibit_point_motion_hooks
, Qt
);
9707 reconsider_clip_changes (w
, buffer
);
9709 /* Has the mode line to be updated? */
9710 update_mode_line
= (!NILP (w
->update_mode_line
)
9711 || update_mode_lines
9712 || buffer
->clip_changed
);
9714 if (MINI_WINDOW_P (w
))
9716 if (w
== XWINDOW (echo_area_window
)
9717 && !NILP (echo_area_buffer
[0]))
9719 if (update_mode_line
)
9720 /* We may have to update a tty frame's menu bar or a
9721 tool-bar. Example `M-x C-h C-h C-g'. */
9722 goto finish_menu_bars
;
9724 /* We've already displayed the echo area glyphs in this window. */
9725 goto finish_scroll_bars
;
9727 else if (w
!= XWINDOW (minibuf_window
))
9729 /* W is a mini-buffer window, but it's not the currently
9730 active one, so clear it. */
9731 int yb
= window_text_bottom_y (w
);
9732 struct glyph_row
*row
;
9735 for (y
= 0, row
= w
->desired_matrix
->rows
;
9737 y
+= row
->height
, ++row
)
9738 blank_row (w
, row
, y
);
9739 goto finish_scroll_bars
;
9743 /* Otherwise set up data on this window; select its buffer and point
9745 /* Really select the buffer, for the sake of buffer-local
9747 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9748 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9750 current_matrix_up_to_date_p
9751 = (!NILP (w
->window_end_valid
)
9752 && !current_buffer
->clip_changed
9753 && XFASTINT (w
->last_modified
) >= MODIFF
9754 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9756 /* When windows_or_buffers_changed is non-zero, we can't rely on
9757 the window end being valid, so set it to nil there. */
9758 if (windows_or_buffers_changed
)
9760 /* If window starts on a continuation line, maybe adjust the
9761 window start in case the window's width changed. */
9762 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9763 compute_window_start_on_continuation_line (w
);
9765 w
->window_end_valid
= Qnil
;
9768 /* Some sanity checks. */
9769 CHECK_WINDOW_END (w
);
9770 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9772 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9775 /* If %c is in mode line, update it if needed. */
9776 if (!NILP (w
->column_number_displayed
)
9777 /* This alternative quickly identifies a common case
9778 where no change is needed. */
9779 && !(PT
== XFASTINT (w
->last_point
)
9780 && XFASTINT (w
->last_modified
) >= MODIFF
9781 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9782 && XFASTINT (w
->column_number_displayed
) != current_column ())
9783 update_mode_line
= 1;
9785 /* Count number of windows showing the selected buffer. An indirect
9786 buffer counts as its base buffer. */
9787 if (!just_this_one_p
)
9789 struct buffer
*current_base
, *window_base
;
9790 current_base
= current_buffer
;
9791 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9792 if (current_base
->base_buffer
)
9793 current_base
= current_base
->base_buffer
;
9794 if (window_base
->base_buffer
)
9795 window_base
= window_base
->base_buffer
;
9796 if (current_base
== window_base
)
9800 /* Point refers normally to the selected window. For any other
9801 window, set up appropriate value. */
9802 if (!EQ (window
, selected_window
))
9804 int new_pt
= XMARKER (w
->pointm
)->charpos
;
9805 int new_pt_byte
= marker_byte_position (w
->pointm
);
9809 new_pt_byte
= BEGV_BYTE
;
9810 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
9812 else if (new_pt
> (ZV
- 1))
9815 new_pt_byte
= ZV_BYTE
;
9816 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
9819 /* We don't use SET_PT so that the point-motion hooks don't run. */
9820 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
9823 /* If any of the character widths specified in the display table
9824 have changed, invalidate the width run cache. It's true that
9825 this may be a bit late to catch such changes, but the rest of
9826 redisplay goes (non-fatally) haywire when the display table is
9827 changed, so why should we worry about doing any better? */
9828 if (current_buffer
->width_run_cache
)
9830 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
9832 if (! disptab_matches_widthtab (disptab
,
9833 XVECTOR (current_buffer
->width_table
)))
9835 invalidate_region_cache (current_buffer
,
9836 current_buffer
->width_run_cache
,
9838 recompute_width_table (current_buffer
, disptab
);
9842 /* If window-start is screwed up, choose a new one. */
9843 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
9846 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9848 /* If someone specified a new starting point but did not insist,
9849 check whether it can be used. */
9850 if (!NILP (w
->optional_new_start
)
9851 && CHARPOS (startp
) >= BEGV
9852 && CHARPOS (startp
) <= ZV
)
9854 w
->optional_new_start
= Qnil
;
9855 start_display (&it
, w
, startp
);
9856 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9857 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9858 if (IT_CHARPOS (it
) == PT
)
9859 w
->force_start
= Qt
;
9862 /* Handle case where place to start displaying has been specified,
9863 unless the specified location is outside the accessible range. */
9864 if (!NILP (w
->force_start
)
9865 || w
->frozen_window_start_p
)
9867 w
->force_start
= Qnil
;
9869 w
->window_end_valid
= Qnil
;
9871 /* Forget any recorded base line for line number display. */
9872 if (!current_matrix_up_to_date_p
9873 || current_buffer
->clip_changed
)
9874 w
->base_line_number
= Qnil
;
9876 /* Redisplay the mode line. Select the buffer properly for that.
9877 Also, run the hook window-scroll-functions
9878 because we have scrolled. */
9879 /* Note, we do this after clearing force_start because
9880 if there's an error, it is better to forget about force_start
9881 than to get into an infinite loop calling the hook functions
9882 and having them get more errors. */
9883 if (!update_mode_line
9884 || ! NILP (Vwindow_scroll_functions
))
9886 update_mode_line
= 1;
9887 w
->update_mode_line
= Qt
;
9888 startp
= run_window_scroll_functions (window
, startp
);
9891 w
->last_modified
= make_number (0);
9892 w
->last_overlay_modified
= make_number (0);
9893 if (CHARPOS (startp
) < BEGV
)
9894 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
9895 else if (CHARPOS (startp
) > ZV
)
9896 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
9898 /* Redisplay, then check if cursor has been set during the
9899 redisplay. Give up if new fonts were loaded. */
9900 if (!try_window (window
, startp
))
9902 w
->force_start
= Qt
;
9903 clear_glyph_matrix (w
->desired_matrix
);
9904 goto finish_scroll_bars
;
9907 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
9909 /* If point does not appear, try to move point so it does
9910 appear. The desired matrix has been built above, so we
9913 struct glyph_row
*row
;
9915 window_height
= window_box_height (w
) / 2;
9916 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
9917 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
9920 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
9921 MATRIX_ROW_START_BYTEPOS (row
));
9923 if (w
!= XWINDOW (selected_window
))
9924 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
9925 else if (current_buffer
== old
)
9926 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9928 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
9930 /* If we are highlighting the region, then we just changed
9931 the region, so redisplay to show it. */
9932 if (!NILP (Vtransient_mark_mode
)
9933 && !NILP (current_buffer
->mark_active
))
9935 clear_glyph_matrix (w
->desired_matrix
);
9936 if (!try_window (window
, startp
))
9937 goto finish_scroll_bars
;
9941 make_cursor_line_fully_visible (w
);
9943 debug_method_add (w
, "forced window start");
9948 /* Handle case where text has not changed, only point, and it has
9949 not moved off the frame. */
9950 if (current_matrix_up_to_date_p
9951 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
9959 /* If current starting point was originally the beginning of a line
9960 but no longer is, find a new starting point. */
9961 else if (!NILP (w
->start_at_line_beg
)
9962 && !(CHARPOS (startp
) <= BEGV
9963 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
9966 debug_method_add (w
, "recenter 1");
9971 /* Try scrolling with try_window_id. */
9972 else if (/* Windows and buffers haven't changed. */
9973 !windows_or_buffers_changed
9974 /* Window must be either use window-based redisplay or
9976 && (FRAME_WINDOW_P (f
)
9977 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
9978 && !MINI_WINDOW_P (w
)
9979 /* Point is not known NOT to appear in window. */
9980 && PT
>= CHARPOS (startp
)
9981 && XFASTINT (w
->last_modified
)
9982 /* Window is not hscrolled. */
9983 && XFASTINT (w
->hscroll
) == 0
9984 /* Selective display has not changed. */
9985 && !current_buffer
->clip_changed
9986 /* Current matrix is up to date. */
9987 && !NILP (w
->window_end_valid
)
9988 /* Can't use this case if highlighting a region because
9989 a cursor movement will do more than just set the cursor. */
9990 && !(!NILP (Vtransient_mark_mode
)
9991 && !NILP (current_buffer
->mark_active
))
9992 && NILP (w
->region_showing
)
9993 && NILP (Vshow_trailing_whitespace
)
9994 /* Overlay arrow position and string not changed. */
9995 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
9996 && EQ (last_arrow_string
, Voverlay_arrow_string
)
9997 /* Value is > 0 if update has been done, it is -1 if we
9998 know that the same window start will not work. It is 0
9999 if unsuccessful for some other reason. */
10000 && (tem
= try_window_id (w
)) != 0)
10003 debug_method_add (w
, "try_window_id %d", tem
);
10006 if (fonts_changed_p
)
10007 goto finish_scroll_bars
;
10011 /* Otherwise try_window_id has returned -1 which means that we
10012 don't want the alternative below this comment to execute. */
10014 else if (CHARPOS (startp
) >= BEGV
10015 && CHARPOS (startp
) <= ZV
10016 && PT
>= CHARPOS (startp
)
10017 && (CHARPOS (startp
) < ZV
10018 /* Avoid starting at end of buffer. */
10019 || CHARPOS (startp
) == BEGV
10020 || (XFASTINT (w
->last_modified
) >= MODIFF
10021 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10024 debug_method_add (w
, "same window start");
10027 /* Try to redisplay starting at same place as before.
10028 If point has not moved off frame, accept the results. */
10029 if (!current_matrix_up_to_date_p
10030 /* Don't use try_window_reusing_current_matrix in this case
10031 because a window scroll function can have changed the
10033 || !NILP (Vwindow_scroll_functions
)
10034 || MINI_WINDOW_P (w
)
10035 || !try_window_reusing_current_matrix (w
))
10037 IF_DEBUG (debug_method_add (w
, "1"));
10038 try_window (window
, startp
);
10041 if (fonts_changed_p
)
10042 goto finish_scroll_bars
;
10044 if (w
->cursor
.vpos
>= 0)
10046 if (!just_this_one_p
10047 || current_buffer
->clip_changed
10048 || BEG_UNCHANGED
< CHARPOS (startp
))
10049 /* Forget any recorded base line for line number display. */
10050 w
->base_line_number
= Qnil
;
10052 make_cursor_line_fully_visible (w
);
10056 clear_glyph_matrix (w
->desired_matrix
);
10061 w
->last_modified
= make_number (0);
10062 w
->last_overlay_modified
= make_number (0);
10064 /* Redisplay the mode line. Select the buffer properly for that. */
10065 if (!update_mode_line
)
10067 update_mode_line
= 1;
10068 w
->update_mode_line
= Qt
;
10071 /* Try to scroll by specified few lines. */
10072 if ((scroll_conservatively
10074 || temp_scroll_step
10075 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10076 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10077 && !current_buffer
->clip_changed
10078 && CHARPOS (startp
) >= BEGV
10079 && CHARPOS (startp
) <= ZV
)
10081 /* The function returns -1 if new fonts were loaded, 1 if
10082 successful, 0 if not successful. */
10083 int rc
= try_scrolling (window
, just_this_one_p
,
10084 scroll_conservatively
,
10090 goto finish_scroll_bars
;
10093 /* Finally, just choose place to start which centers point */
10098 debug_method_add (w
, "recenter");
10101 /* w->vscroll = 0; */
10103 /* Forget any previously recorded base line for line number display. */
10104 if (!current_matrix_up_to_date_p
10105 || current_buffer
->clip_changed
)
10106 w
->base_line_number
= Qnil
;
10108 /* Move backward half the height of the window. */
10109 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10110 it
.current_y
= it
.last_visible_y
;
10111 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
10112 xassert (IT_CHARPOS (it
) >= BEGV
);
10114 /* The function move_it_vertically_backward may move over more
10115 than the specified y-distance. If it->w is small, e.g. a
10116 mini-buffer window, we may end up in front of the window's
10117 display area. Start displaying at the start of the line
10118 containing PT in this case. */
10119 if (it
.current_y
<= 0)
10121 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10122 move_it_vertically (&it
, 0);
10123 xassert (IT_CHARPOS (it
) <= PT
);
10127 it
.current_x
= it
.hpos
= 0;
10129 /* Set startp here explicitly in case that helps avoid an infinite loop
10130 in case the window-scroll-functions functions get errors. */
10131 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10133 /* Run scroll hooks. */
10134 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10136 /* Redisplay the window. */
10137 if (!current_matrix_up_to_date_p
10138 || windows_or_buffers_changed
10139 /* Don't use try_window_reusing_current_matrix in this case
10140 because it can have changed the buffer. */
10141 || !NILP (Vwindow_scroll_functions
)
10142 || !just_this_one_p
10143 || MINI_WINDOW_P (w
)
10144 || !try_window_reusing_current_matrix (w
))
10145 try_window (window
, startp
);
10147 /* If new fonts have been loaded (due to fontsets), give up. We
10148 have to start a new redisplay since we need to re-adjust glyph
10150 if (fonts_changed_p
)
10151 goto finish_scroll_bars
;
10153 /* If cursor did not appear assume that the middle of the window is
10154 in the first line of the window. Do it again with the next line.
10155 (Imagine a window of height 100, displaying two lines of height
10156 60. Moving back 50 from it->last_visible_y will end in the first
10158 if (w
->cursor
.vpos
< 0)
10160 if (!NILP (w
->window_end_valid
)
10161 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10163 clear_glyph_matrix (w
->desired_matrix
);
10164 move_it_by_lines (&it
, 1, 0);
10165 try_window (window
, it
.current
.pos
);
10167 else if (PT
< IT_CHARPOS (it
))
10169 clear_glyph_matrix (w
->desired_matrix
);
10170 move_it_by_lines (&it
, -1, 0);
10171 try_window (window
, it
.current
.pos
);
10175 /* Not much we can do about it. */
10179 /* Consider the following case: Window starts at BEGV, there is
10180 invisible, intangible text at BEGV, so that display starts at
10181 some point START > BEGV. It can happen that we are called with
10182 PT somewhere between BEGV and START. Try to handle that case. */
10183 if (w
->cursor
.vpos
< 0)
10185 struct glyph_row
*row
= w
->current_matrix
->rows
;
10186 if (row
->mode_line_p
)
10188 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10191 make_cursor_line_fully_visible (w
);
10195 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10196 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10197 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10200 /* Display the mode line, if we must. */
10201 if ((update_mode_line
10202 /* If window not full width, must redo its mode line
10203 if (a) the window to its side is being redone and
10204 (b) we do a frame-based redisplay. This is a consequence
10205 of how inverted lines are drawn in frame-based redisplay. */
10206 || (!just_this_one_p
10207 && !FRAME_WINDOW_P (f
)
10208 && !WINDOW_FULL_WIDTH_P (w
))
10209 /* Line number to display. */
10210 || INTEGERP (w
->base_line_pos
)
10211 /* Column number is displayed and different from the one displayed. */
10212 || (!NILP (w
->column_number_displayed
)
10213 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10214 /* This means that the window has a mode line. */
10215 && (WINDOW_WANTS_MODELINE_P (w
)
10216 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10218 Lisp_Object old_selected_frame
;
10220 old_selected_frame
= selected_frame
;
10222 XSETFRAME (selected_frame
, f
);
10223 display_mode_lines (w
);
10224 selected_frame
= old_selected_frame
;
10226 /* If mode line height has changed, arrange for a thorough
10227 immediate redisplay using the correct mode line height. */
10228 if (WINDOW_WANTS_MODELINE_P (w
)
10229 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10231 fonts_changed_p
= 1;
10232 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10233 = DESIRED_MODE_LINE_HEIGHT (w
);
10236 /* If top line height has changed, arrange for a thorough
10237 immediate redisplay using the correct mode line height. */
10238 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10239 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10241 fonts_changed_p
= 1;
10242 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10243 = DESIRED_HEADER_LINE_HEIGHT (w
);
10246 if (fonts_changed_p
)
10247 goto finish_scroll_bars
;
10250 if (!line_number_displayed
10251 && !BUFFERP (w
->base_line_pos
))
10253 w
->base_line_pos
= Qnil
;
10254 w
->base_line_number
= Qnil
;
10259 /* When we reach a frame's selected window, redo the frame's menu bar. */
10260 if (update_mode_line
10261 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10263 int redisplay_menu_p
= 0;
10265 if (FRAME_WINDOW_P (f
))
10267 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10268 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10270 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10274 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10276 if (redisplay_menu_p
)
10277 display_menu_bar (w
);
10279 #ifdef HAVE_WINDOW_SYSTEM
10280 if (WINDOWP (f
->tool_bar_window
)
10281 && (FRAME_TOOL_BAR_LINES (f
) > 0
10282 || auto_resize_tool_bars_p
))
10283 redisplay_tool_bar (f
);
10287 finish_scroll_bars
:
10289 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10291 int start
, end
, whole
;
10293 /* Calculate the start and end positions for the current window.
10294 At some point, it would be nice to choose between scrollbars
10295 which reflect the whole buffer size, with special markers
10296 indicating narrowing, and scrollbars which reflect only the
10299 Note that mini-buffers sometimes aren't displaying any text. */
10300 if (!MINI_WINDOW_P (w
)
10301 || (w
== XWINDOW (minibuf_window
)
10302 && NILP (echo_area_buffer
[0])))
10305 start
= marker_position (w
->start
) - BEGV
;
10306 /* I don't think this is guaranteed to be right. For the
10307 moment, we'll pretend it is. */
10308 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10312 if (whole
< (end
- start
))
10313 whole
= end
- start
;
10316 start
= end
= whole
= 0;
10318 /* Indicate what this scroll bar ought to be displaying now. */
10319 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10321 /* Note that we actually used the scroll bar attached to this
10322 window, so it shouldn't be deleted at the end of redisplay. */
10323 redeem_scroll_bar_hook (w
);
10326 /* Restore current_buffer and value of point in it. */
10327 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10328 set_buffer_internal_1 (old
);
10329 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10331 unbind_to (count
, Qnil
);
10335 /* Build the complete desired matrix of WINDOW with a window start
10336 buffer position POS. Value is non-zero if successful. It is zero
10337 if fonts were loaded during redisplay which makes re-adjusting
10338 glyph matrices necessary. */
10341 try_window (window
, pos
)
10342 Lisp_Object window
;
10343 struct text_pos pos
;
10345 struct window
*w
= XWINDOW (window
);
10347 struct glyph_row
*last_text_row
= NULL
;
10349 /* Make POS the new window start. */
10350 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10352 /* Mark cursor position as unknown. No overlay arrow seen. */
10353 w
->cursor
.vpos
= -1;
10354 overlay_arrow_seen
= 0;
10356 /* Initialize iterator and info to start at POS. */
10357 start_display (&it
, w
, pos
);
10359 /* Display all lines of W. */
10360 while (it
.current_y
< it
.last_visible_y
)
10362 if (display_line (&it
))
10363 last_text_row
= it
.glyph_row
- 1;
10364 if (fonts_changed_p
)
10368 /* If bottom moved off end of frame, change mode line percentage. */
10369 if (XFASTINT (w
->window_end_pos
) <= 0
10370 && Z
!= IT_CHARPOS (it
))
10371 w
->update_mode_line
= Qt
;
10373 /* Set window_end_pos to the offset of the last character displayed
10374 on the window from the end of current_buffer. Set
10375 window_end_vpos to its row number. */
10378 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10379 w
->window_end_bytepos
10380 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10382 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10384 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10385 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10386 ->displays_text_p
);
10390 w
->window_end_bytepos
= 0;
10391 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10394 /* But that is not valid info until redisplay finishes. */
10395 w
->window_end_valid
= Qnil
;
10401 /************************************************************************
10402 Window redisplay reusing current matrix when buffer has not changed
10403 ************************************************************************/
10405 /* Try redisplay of window W showing an unchanged buffer with a
10406 different window start than the last time it was displayed by
10407 reusing its current matrix. Value is non-zero if successful.
10408 W->start is the new window start. */
10411 try_window_reusing_current_matrix (w
)
10414 struct frame
*f
= XFRAME (w
->frame
);
10415 struct glyph_row
*row
, *bottom_row
;
10418 struct text_pos start
, new_start
;
10419 int nrows_scrolled
, i
;
10420 struct glyph_row
*last_text_row
;
10421 struct glyph_row
*last_reused_text_row
;
10422 struct glyph_row
*start_row
;
10423 int start_vpos
, min_y
, max_y
;
10425 if (/* This function doesn't handle terminal frames. */
10426 !FRAME_WINDOW_P (f
)
10427 /* Don't try to reuse the display if windows have been split
10429 || windows_or_buffers_changed
)
10432 /* Can't do this if region may have changed. */
10433 if ((!NILP (Vtransient_mark_mode
)
10434 && !NILP (current_buffer
->mark_active
))
10435 || !NILP (w
->region_showing
)
10436 || !NILP (Vshow_trailing_whitespace
))
10439 /* If top-line visibility has changed, give up. */
10440 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10441 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10444 /* Give up if old or new display is scrolled vertically. We could
10445 make this function handle this, but right now it doesn't. */
10446 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10447 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10450 /* The variable new_start now holds the new window start. The old
10451 start `start' can be determined from the current matrix. */
10452 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10453 start
= start_row
->start
.pos
;
10454 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10456 /* Clear the desired matrix for the display below. */
10457 clear_glyph_matrix (w
->desired_matrix
);
10459 if (CHARPOS (new_start
) <= CHARPOS (start
))
10463 /* Don't use this method if the display starts with an ellipsis
10464 displayed for invisible text. It's not easy to handle that case
10465 below, and it's certainly not worth the effort since this is
10466 not a frequent case. */
10467 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10470 IF_DEBUG (debug_method_add (w
, "twu1"));
10472 /* Display up to a row that can be reused. The variable
10473 last_text_row is set to the last row displayed that displays
10474 text. Note that it.vpos == 0 if or if not there is a
10475 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10476 start_display (&it
, w
, new_start
);
10477 first_row_y
= it
.current_y
;
10478 w
->cursor
.vpos
= -1;
10479 last_text_row
= last_reused_text_row
= NULL
;
10481 while (it
.current_y
< it
.last_visible_y
10482 && IT_CHARPOS (it
) < CHARPOS (start
)
10483 && !fonts_changed_p
)
10484 if (display_line (&it
))
10485 last_text_row
= it
.glyph_row
- 1;
10487 /* A value of current_y < last_visible_y means that we stopped
10488 at the previous window start, which in turn means that we
10489 have at least one reusable row. */
10490 if (it
.current_y
< it
.last_visible_y
)
10492 /* IT.vpos always starts from 0; it counts text lines. */
10493 nrows_scrolled
= it
.vpos
;
10495 /* Find PT if not already found in the lines displayed. */
10496 if (w
->cursor
.vpos
< 0)
10498 int dy
= it
.current_y
- first_row_y
;
10500 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10501 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10503 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
10504 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10506 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10507 dy
, nrows_scrolled
);
10511 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
10517 /* Give up if point was not found. This shouldn't
10518 happen often; not more often than with try_window
10520 if (w
->cursor
.vpos
< 0)
10522 clear_glyph_matrix (w
->desired_matrix
);
10527 /* Scroll the display. Do it before the current matrix is
10528 changed. The problem here is that update has not yet
10529 run, i.e. part of the current matrix is not up to date.
10530 scroll_run_hook will clear the cursor, and use the
10531 current matrix to get the height of the row the cursor is
10533 run
.current_y
= first_row_y
;
10534 run
.desired_y
= it
.current_y
;
10535 run
.height
= it
.last_visible_y
- it
.current_y
;
10537 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10540 rif
->update_window_begin_hook (w
);
10541 rif
->clear_mouse_face (w
);
10542 rif
->scroll_run_hook (w
, &run
);
10543 rif
->update_window_end_hook (w
, 0, 0);
10547 /* Shift current matrix down by nrows_scrolled lines. */
10548 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10549 rotate_matrix (w
->current_matrix
,
10551 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10554 /* Disable lines that must be updated. */
10555 for (i
= 0; i
< it
.vpos
; ++i
)
10556 (start_row
+ i
)->enabled_p
= 0;
10558 /* Re-compute Y positions. */
10559 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10560 max_y
= it
.last_visible_y
;
10561 for (row
= start_row
+ nrows_scrolled
;
10565 row
->y
= it
.current_y
;
10567 if (row
->y
< min_y
)
10568 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10569 else if (row
->y
+ row
->height
> max_y
)
10570 row
->visible_height
10571 = row
->height
- (row
->y
+ row
->height
- max_y
);
10573 row
->visible_height
= row
->height
;
10575 it
.current_y
+= row
->height
;
10577 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10578 last_reused_text_row
= row
;
10579 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10583 /* Disable lines in the current matrix which are now
10584 below the window. */
10585 for (++row
; row
< bottom_row
; ++row
)
10586 row
->enabled_p
= 0;
10589 /* Update window_end_pos etc.; last_reused_text_row is the last
10590 reused row from the current matrix containing text, if any.
10591 The value of last_text_row is the last displayed line
10592 containing text. */
10593 if (last_reused_text_row
)
10595 w
->window_end_bytepos
10596 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10598 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10600 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10601 w
->current_matrix
));
10603 else if (last_text_row
)
10605 w
->window_end_bytepos
10606 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10608 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10610 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10614 /* This window must be completely empty. */
10615 w
->window_end_bytepos
= 0;
10616 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10618 w
->window_end_valid
= Qnil
;
10620 /* Update hint: don't try scrolling again in update_window. */
10621 w
->desired_matrix
->no_scrolling_p
= 1;
10624 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10628 else if (CHARPOS (new_start
) > CHARPOS (start
))
10630 struct glyph_row
*pt_row
, *row
;
10631 struct glyph_row
*first_reusable_row
;
10632 struct glyph_row
*first_row_to_display
;
10634 int yb
= window_text_bottom_y (w
);
10636 /* Find the row starting at new_start, if there is one. Don't
10637 reuse a partially visible line at the end. */
10638 first_reusable_row
= start_row
;
10639 while (first_reusable_row
->enabled_p
10640 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10641 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10642 < CHARPOS (new_start
)))
10643 ++first_reusable_row
;
10645 /* Give up if there is no row to reuse. */
10646 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10647 || !first_reusable_row
->enabled_p
10648 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10649 != CHARPOS (new_start
)))
10652 /* We can reuse fully visible rows beginning with
10653 first_reusable_row to the end of the window. Set
10654 first_row_to_display to the first row that cannot be reused.
10655 Set pt_row to the row containing point, if there is any. */
10657 for (first_row_to_display
= first_reusable_row
;
10658 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
10659 ++first_row_to_display
)
10661 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10662 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10663 pt_row
= first_row_to_display
;
10666 /* Start displaying at the start of first_row_to_display. */
10667 xassert (first_row_to_display
->y
< yb
);
10668 init_to_row_start (&it
, w
, first_row_to_display
);
10670 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10672 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10674 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10675 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10677 /* Display lines beginning with first_row_to_display in the
10678 desired matrix. Set last_text_row to the last row displayed
10679 that displays text. */
10680 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10681 if (pt_row
== NULL
)
10682 w
->cursor
.vpos
= -1;
10683 last_text_row
= NULL
;
10684 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10685 if (display_line (&it
))
10686 last_text_row
= it
.glyph_row
- 1;
10688 /* Give up If point isn't in a row displayed or reused. */
10689 if (w
->cursor
.vpos
< 0)
10691 clear_glyph_matrix (w
->desired_matrix
);
10695 /* If point is in a reused row, adjust y and vpos of the cursor
10699 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10700 w
->current_matrix
);
10701 w
->cursor
.y
-= first_reusable_row
->y
;
10704 /* Scroll the display. */
10705 run
.current_y
= first_reusable_row
->y
;
10706 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10707 run
.height
= it
.last_visible_y
- run
.current_y
;
10708 dy
= run
.current_y
- run
.desired_y
;
10712 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10714 rif
->update_window_begin_hook (w
);
10715 rif
->clear_mouse_face (w
);
10716 rif
->scroll_run_hook (w
, &run
);
10717 rif
->update_window_end_hook (w
, 0, 0);
10721 /* Adjust Y positions of reused rows. */
10722 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10723 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10724 max_y
= it
.last_visible_y
;
10725 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10728 if (row
->y
< min_y
)
10729 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10730 else if (row
->y
+ row
->height
> max_y
)
10731 row
->visible_height
10732 = row
->height
- (row
->y
+ row
->height
- max_y
);
10734 row
->visible_height
= row
->height
;
10737 /* Scroll the current matrix. */
10738 xassert (nrows_scrolled
> 0);
10739 rotate_matrix (w
->current_matrix
,
10741 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10744 /* Disable rows not reused. */
10745 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
10746 row
->enabled_p
= 0;
10748 /* Adjust window end. A null value of last_text_row means that
10749 the window end is in reused rows which in turn means that
10750 only its vpos can have changed. */
10753 w
->window_end_bytepos
10754 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10756 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10758 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10763 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10766 w
->window_end_valid
= Qnil
;
10767 w
->desired_matrix
->no_scrolling_p
= 1;
10770 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10780 /************************************************************************
10781 Window redisplay reusing current matrix when buffer has changed
10782 ************************************************************************/
10784 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10785 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10787 static struct glyph_row
*
10788 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10789 struct glyph_row
*));
10792 /* Return the last row in MATRIX displaying text. If row START is
10793 non-null, start searching with that row. IT gives the dimensions
10794 of the display. Value is null if matrix is empty; otherwise it is
10795 a pointer to the row found. */
10797 static struct glyph_row
*
10798 find_last_row_displaying_text (matrix
, it
, start
)
10799 struct glyph_matrix
*matrix
;
10801 struct glyph_row
*start
;
10803 struct glyph_row
*row
, *row_found
;
10805 /* Set row_found to the last row in IT->w's current matrix
10806 displaying text. The loop looks funny but think of partially
10809 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
10810 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10812 xassert (row
->enabled_p
);
10814 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
10823 /* Return the last row in the current matrix of W that is not affected
10824 by changes at the start of current_buffer that occurred since the
10825 last time W was redisplayed. Value is null if no such row exists.
10827 The global variable beg_unchanged has to contain the number of
10828 bytes unchanged at the start of current_buffer. BEG +
10829 beg_unchanged is the buffer position of the first changed byte in
10830 current_buffer. Characters at positions < BEG + beg_unchanged are
10831 at the same buffer positions as they were when the current matrix
10834 static struct glyph_row
*
10835 find_last_unchanged_at_beg_row (w
)
10838 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
10839 struct glyph_row
*row
;
10840 struct glyph_row
*row_found
= NULL
;
10841 int yb
= window_text_bottom_y (w
);
10843 /* Find the last row displaying unchanged text. */
10844 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10845 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
10846 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
10848 if (/* If row ends before first_changed_pos, it is unchanged,
10849 except in some case. */
10850 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
10851 /* When row ends in ZV and we write at ZV it is not
10853 && !row
->ends_at_zv_p
10854 /* When first_changed_pos is the end of a continued line,
10855 row is not unchanged because it may be no longer
10857 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
10858 && row
->continued_p
))
10861 /* Stop if last visible row. */
10862 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
10872 /* Find the first glyph row in the current matrix of W that is not
10873 affected by changes at the end of current_buffer since the last
10874 time the window was redisplayed. Return in *DELTA the number of
10875 chars by which buffer positions in unchanged text at the end of
10876 current_buffer must be adjusted. Return in *DELTA_BYTES the
10877 corresponding number of bytes. Value is null if no such row
10878 exists, i.e. all rows are affected by changes. */
10880 static struct glyph_row
*
10881 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
10883 int *delta
, *delta_bytes
;
10885 struct glyph_row
*row
;
10886 struct glyph_row
*row_found
= NULL
;
10888 *delta
= *delta_bytes
= 0;
10890 /* Display must not have been paused, otherwise the current matrix
10891 is not up to date. */
10892 if (NILP (w
->window_end_valid
))
10895 /* A value of window_end_pos >= END_UNCHANGED means that the window
10896 end is in the range of changed text. If so, there is no
10897 unchanged row at the end of W's current matrix. */
10898 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
10901 /* Set row to the last row in W's current matrix displaying text. */
10902 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10904 /* If matrix is entirely empty, no unchanged row exists. */
10905 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10907 /* The value of row is the last glyph row in the matrix having a
10908 meaningful buffer position in it. The end position of row
10909 corresponds to window_end_pos. This allows us to translate
10910 buffer positions in the current matrix to current buffer
10911 positions for characters not in changed text. */
10912 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
10913 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
10914 int last_unchanged_pos
, last_unchanged_pos_old
;
10915 struct glyph_row
*first_text_row
10916 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10918 *delta
= Z
- Z_old
;
10919 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
10921 /* Set last_unchanged_pos to the buffer position of the last
10922 character in the buffer that has not been changed. Z is the
10923 index + 1 of the last byte in current_buffer, i.e. by
10924 subtracting end_unchanged we get the index of the last
10925 unchanged character, and we have to add BEG to get its buffer
10927 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
10928 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
10930 /* Search backward from ROW for a row displaying a line that
10931 starts at a minimum position >= last_unchanged_pos_old. */
10932 for (; row
> first_text_row
; --row
)
10934 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10937 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
10942 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
10949 /* Make sure that glyph rows in the current matrix of window W
10950 reference the same glyph memory as corresponding rows in the
10951 frame's frame matrix. This function is called after scrolling W's
10952 current matrix on a terminal frame in try_window_id and
10953 try_window_reusing_current_matrix. */
10956 sync_frame_with_window_matrix_rows (w
)
10959 struct frame
*f
= XFRAME (w
->frame
);
10960 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
10962 /* Preconditions: W must be a leaf window and full-width. Its frame
10963 must have a frame matrix. */
10964 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
10965 xassert (WINDOW_FULL_WIDTH_P (w
));
10966 xassert (!FRAME_WINDOW_P (f
));
10968 /* If W is a full-width window, glyph pointers in W's current matrix
10969 have, by definition, to be the same as glyph pointers in the
10970 corresponding frame matrix. */
10971 window_row
= w
->current_matrix
->rows
;
10972 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
10973 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
10974 while (window_row
< window_row_end
)
10978 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
10979 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
10981 /* Disable frame rows whose corresponding window rows have
10982 been disabled in try_window_id. */
10983 if (!window_row
->enabled_p
)
10984 frame_row
->enabled_p
= 0;
10986 ++window_row
, ++frame_row
;
10991 /* Find the glyph row in window W containing CHARPOS. Consider all
10992 rows between START and END (not inclusive). END null means search
10993 all rows to the end of the display area of W. Value is the row
10994 containing CHARPOS or null. */
10996 static struct glyph_row
*
10997 row_containing_pos (w
, charpos
, start
, end
)
11000 struct glyph_row
*start
, *end
;
11002 struct glyph_row
*row
= start
;
11005 /* If we happen to start on a header-line, skip that. */
11006 if (row
->mode_line_p
)
11009 if ((end
&& row
>= end
) || !row
->enabled_p
)
11012 last_y
= window_text_bottom_y (w
);
11014 while ((end
== NULL
|| row
< end
)
11015 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11016 /* The end position of a row equals the start
11017 position of the next row. If CHARPOS is there, we
11018 would rather display it in the next line, except
11019 when this line ends in ZV. */
11020 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11021 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11022 || !row
->ends_at_zv_p
)))
11023 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11026 /* Give up if CHARPOS not found. */
11027 if ((end
&& row
>= end
)
11028 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11029 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11036 /* Try to redisplay window W by reusing its existing display. W's
11037 current matrix must be up to date when this function is called,
11038 i.e. window_end_valid must not be nil.
11042 1 if display has been updated
11043 0 if otherwise unsuccessful
11044 -1 if redisplay with same window start is known not to succeed
11046 The following steps are performed:
11048 1. Find the last row in the current matrix of W that is not
11049 affected by changes at the start of current_buffer. If no such row
11052 2. Find the first row in W's current matrix that is not affected by
11053 changes at the end of current_buffer. Maybe there is no such row.
11055 3. Display lines beginning with the row + 1 found in step 1 to the
11056 row found in step 2 or, if step 2 didn't find a row, to the end of
11059 4. If cursor is not known to appear on the window, give up.
11061 5. If display stopped at the row found in step 2, scroll the
11062 display and current matrix as needed.
11064 6. Maybe display some lines at the end of W, if we must. This can
11065 happen under various circumstances, like a partially visible line
11066 becoming fully visible, or because newly displayed lines are displayed
11067 in smaller font sizes.
11069 7. Update W's window end information. */
11071 /* Check that window end is what we expect it to be. */
11077 struct frame
*f
= XFRAME (w
->frame
);
11078 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11079 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11080 struct glyph_row
*last_unchanged_at_beg_row
;
11081 struct glyph_row
*first_unchanged_at_end_row
;
11082 struct glyph_row
*row
;
11083 struct glyph_row
*bottom_row
;
11086 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11087 struct text_pos start_pos
;
11089 int first_unchanged_at_end_vpos
= 0;
11090 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11091 struct text_pos start
;
11093 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11095 /* Check pre-conditions. Window end must be valid, otherwise
11096 the current matrix would not be up to date. */
11097 xassert (!NILP (w
->window_end_valid
));
11098 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
11099 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
11101 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11102 only if buffer has really changed. The reason is that the gap is
11103 initially at Z for freshly visited files. The code below would
11104 set end_unchanged to 0 in that case. */
11105 if (MODIFF
> SAVE_MODIFF
11106 /* This seems to happen sometimes after saving a buffer. */
11107 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11109 if (GPT
- BEG
< BEG_UNCHANGED
)
11110 BEG_UNCHANGED
= GPT
- BEG
;
11111 if (Z
- GPT
< END_UNCHANGED
)
11112 END_UNCHANGED
= Z
- GPT
;
11115 /* If window starts after a line end, and the last change is in
11116 front of that newline, then changes don't affect the display.
11117 This case happens with stealth-fontification. Note that although
11118 the display is unchanged, glyph positions in the matrix have to
11119 be adjusted, of course. */
11120 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11121 if (CHARPOS (start
) > BEGV
11122 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
11123 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
11124 && PT
< MATRIX_ROW_END_CHARPOS (row
))
11126 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11127 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
11131 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11132 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
11134 increment_matrix_positions (w
->current_matrix
,
11135 MATRIX_ROW_VPOS (r0
, current_matrix
),
11136 MATRIX_ROW_VPOS (r1
, current_matrix
),
11137 delta
, delta_bytes
);
11140 #if 0 /* If changes are all in front of the window start, the
11141 distance of the last displayed glyph from Z hasn't
11144 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11145 w
->window_end_bytepos
11146 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11149 row
= row_containing_pos (w
, PT
, r0
, NULL
);
11153 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11157 /* Return quickly if changes are all below what is displayed in the
11158 window, and if PT is in the window. */
11159 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
11160 && PT
< MATRIX_ROW_END_CHARPOS (row
))
11162 /* We have to update window end positions because the buffer's
11163 size has changed. */
11165 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11166 w
->window_end_bytepos
11167 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11169 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11170 row
= row_containing_pos (w
, PT
, row
, NULL
);
11171 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11175 /* Check that window start agrees with the start of the first glyph
11176 row in its current matrix. Check this after we know the window
11177 start is not in changed text, otherwise positions would not be
11179 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11180 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11183 /* Compute the position at which we have to start displaying new
11184 lines. Some of the lines at the top of the window might be
11185 reusable because they are not displaying changed text. Find the
11186 last row in W's current matrix not affected by changes at the
11187 start of current_buffer. Value is null if changes start in the
11188 first line of window. */
11189 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11190 if (last_unchanged_at_beg_row
)
11192 /* Avoid starting to display in the moddle of a character, a TAB
11193 for instance. This is easier than to set up the iterator
11194 exactly, and it's not a frequent case, so the additional
11195 effort wouldn't really pay off. */
11196 while (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11197 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11198 --last_unchanged_at_beg_row
;
11200 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11203 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
11204 start_pos
= it
.current
.pos
;
11206 /* Start displaying new lines in the desired matrix at the same
11207 vpos we would use in the current matrix, i.e. below
11208 last_unchanged_at_beg_row. */
11209 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11211 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11212 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11214 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11218 /* There are no reusable lines at the start of the window.
11219 Start displaying in the first line. */
11220 start_display (&it
, w
, start
);
11221 start_pos
= it
.current
.pos
;
11224 /* Find the first row that is not affected by changes at the end of
11225 the buffer. Value will be null if there is no unchanged row, in
11226 which case we must redisplay to the end of the window. delta
11227 will be set to the value by which buffer positions beginning with
11228 first_unchanged_at_end_row have to be adjusted due to text
11230 first_unchanged_at_end_row
11231 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11232 IF_DEBUG (debug_delta
= delta
);
11233 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11235 /* Set stop_pos to the buffer position up to which we will have to
11236 display new lines. If first_unchanged_at_end_row != NULL, this
11237 is the buffer position of the start of the line displayed in that
11238 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11239 that we don't stop at a buffer position. */
11241 if (first_unchanged_at_end_row
)
11243 xassert (last_unchanged_at_beg_row
== NULL
11244 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11246 /* If this is a continuation line, move forward to the next one
11247 that isn't. Changes in lines above affect this line.
11248 Caution: this may move first_unchanged_at_end_row to a row
11249 not displaying text. */
11250 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11251 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11252 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11253 < it
.last_visible_y
))
11254 ++first_unchanged_at_end_row
;
11256 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11257 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11258 >= it
.last_visible_y
))
11259 first_unchanged_at_end_row
= NULL
;
11262 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11264 first_unchanged_at_end_vpos
11265 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11266 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11269 else if (last_unchanged_at_beg_row
== NULL
)
11275 /* Either there is no unchanged row at the end, or the one we have
11276 now displays text. This is a necessary condition for the window
11277 end pos calculation at the end of this function. */
11278 xassert (first_unchanged_at_end_row
== NULL
11279 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11281 debug_last_unchanged_at_beg_vpos
11282 = (last_unchanged_at_beg_row
11283 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11285 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11287 #endif /* GLYPH_DEBUG != 0 */
11290 /* Display new lines. Set last_text_row to the last new line
11291 displayed which has text on it, i.e. might end up as being the
11292 line where the window_end_vpos is. */
11293 w
->cursor
.vpos
= -1;
11294 last_text_row
= NULL
;
11295 overlay_arrow_seen
= 0;
11296 while (it
.current_y
< it
.last_visible_y
11297 && !fonts_changed_p
11298 && (first_unchanged_at_end_row
== NULL
11299 || IT_CHARPOS (it
) < stop_pos
))
11301 if (display_line (&it
))
11302 last_text_row
= it
.glyph_row
- 1;
11305 if (fonts_changed_p
)
11309 /* Compute differences in buffer positions, y-positions etc. for
11310 lines reused at the bottom of the window. Compute what we can
11312 if (first_unchanged_at_end_row
11313 /* No lines reused because we displayed everything up to the
11314 bottom of the window. */
11315 && it
.current_y
< it
.last_visible_y
)
11318 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11320 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11321 run
.current_y
= first_unchanged_at_end_row
->y
;
11322 run
.desired_y
= run
.current_y
+ dy
;
11323 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11327 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11328 first_unchanged_at_end_row
= NULL
;
11330 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11333 /* Find the cursor if not already found. We have to decide whether
11334 PT will appear on this window (it sometimes doesn't, but this is
11335 not a very frequent case.) This decision has to be made before
11336 the current matrix is altered. A value of cursor.vpos < 0 means
11337 that PT is either in one of the lines beginning at
11338 first_unchanged_at_end_row or below the window. Don't care for
11339 lines that might be displayed later at the window end; as
11340 mentioned, this is not a frequent case. */
11341 if (w
->cursor
.vpos
< 0)
11343 /* Cursor in unchanged rows at the top? */
11344 if (PT
< CHARPOS (start_pos
)
11345 && last_unchanged_at_beg_row
)
11347 row
= row_containing_pos (w
, PT
,
11348 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11349 last_unchanged_at_beg_row
+ 1);
11351 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11354 /* Start from first_unchanged_at_end_row looking for PT. */
11355 else if (first_unchanged_at_end_row
)
11357 row
= row_containing_pos (w
, PT
- delta
,
11358 first_unchanged_at_end_row
, NULL
);
11360 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11361 delta_bytes
, dy
, dvpos
);
11364 /* Give up if cursor was not found. */
11365 if (w
->cursor
.vpos
< 0)
11367 clear_glyph_matrix (w
->desired_matrix
);
11372 /* Don't let the cursor end in the scroll margins. */
11374 int this_scroll_margin
, cursor_height
;
11376 this_scroll_margin
= max (0, scroll_margin
);
11377 this_scroll_margin
= min (this_scroll_margin
,
11378 XFASTINT (w
->height
) / 4);
11379 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11380 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11382 if ((w
->cursor
.y
< this_scroll_margin
11383 && CHARPOS (start
) > BEGV
)
11384 /* Don't take scroll margin into account at the bottom because
11385 old redisplay didn't do it either. */
11386 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11388 w
->cursor
.vpos
= -1;
11389 clear_glyph_matrix (w
->desired_matrix
);
11394 /* Scroll the display. Do it before changing the current matrix so
11395 that xterm.c doesn't get confused about where the cursor glyph is
11397 if (dy
&& run
.height
)
11401 if (FRAME_WINDOW_P (f
))
11403 rif
->update_window_begin_hook (w
);
11404 rif
->clear_mouse_face (w
);
11405 rif
->scroll_run_hook (w
, &run
);
11406 rif
->update_window_end_hook (w
, 0, 0);
11410 /* Terminal frame. In this case, dvpos gives the number of
11411 lines to scroll by; dvpos < 0 means scroll up. */
11412 int first_unchanged_at_end_vpos
11413 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11414 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11415 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
11417 /* Perform the operation on the screen. */
11420 /* Scroll last_unchanged_at_beg_row to the end of the
11421 window down dvpos lines. */
11422 set_terminal_window (end
);
11424 /* On dumb terminals delete dvpos lines at the end
11425 before inserting dvpos empty lines. */
11426 if (!scroll_region_ok
)
11427 ins_del_lines (end
- dvpos
, -dvpos
);
11429 /* Insert dvpos empty lines in front of
11430 last_unchanged_at_beg_row. */
11431 ins_del_lines (from
, dvpos
);
11433 else if (dvpos
< 0)
11435 /* Scroll up last_unchanged_at_beg_vpos to the end of
11436 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11437 set_terminal_window (end
);
11439 /* Delete dvpos lines in front of
11440 last_unchanged_at_beg_vpos. ins_del_lines will set
11441 the cursor to the given vpos and emit |dvpos| delete
11443 ins_del_lines (from
+ dvpos
, dvpos
);
11445 /* On a dumb terminal insert dvpos empty lines at the
11447 if (!scroll_region_ok
)
11448 ins_del_lines (end
+ dvpos
, -dvpos
);
11451 set_terminal_window (0);
11457 /* Shift reused rows of the current matrix to the right position.
11458 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11460 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11461 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11464 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11465 bottom_vpos
, dvpos
);
11466 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11469 else if (dvpos
> 0)
11471 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11472 bottom_vpos
, dvpos
);
11473 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11474 first_unchanged_at_end_vpos
+ dvpos
, 0);
11477 /* For frame-based redisplay, make sure that current frame and window
11478 matrix are in sync with respect to glyph memory. */
11479 if (!FRAME_WINDOW_P (f
))
11480 sync_frame_with_window_matrix_rows (w
);
11482 /* Adjust buffer positions in reused rows. */
11484 increment_matrix_positions (current_matrix
,
11485 first_unchanged_at_end_vpos
+ dvpos
,
11486 bottom_vpos
, delta
, delta_bytes
);
11488 /* Adjust Y positions. */
11490 shift_glyph_matrix (w
, current_matrix
,
11491 first_unchanged_at_end_vpos
+ dvpos
,
11494 if (first_unchanged_at_end_row
)
11495 first_unchanged_at_end_row
+= dvpos
;
11497 /* If scrolling up, there may be some lines to display at the end of
11499 last_text_row_at_end
= NULL
;
11502 /* Set last_row to the glyph row in the current matrix where the
11503 window end line is found. It has been moved up or down in
11504 the matrix by dvpos. */
11505 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11506 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11508 /* If last_row is the window end line, it should display text. */
11509 xassert (last_row
->displays_text_p
);
11511 /* If window end line was partially visible before, begin
11512 displaying at that line. Otherwise begin displaying with the
11513 line following it. */
11514 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11516 init_to_row_start (&it
, w
, last_row
);
11517 it
.vpos
= last_vpos
;
11518 it
.current_y
= last_row
->y
;
11522 init_to_row_end (&it
, w
, last_row
);
11523 it
.vpos
= 1 + last_vpos
;
11524 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11528 /* We may start in a continuation line. If so, we have to get
11529 the right continuation_lines_width and current_x. */
11530 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11531 it
.hpos
= it
.current_x
= 0;
11533 /* Display the rest of the lines at the window end. */
11534 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11535 while (it
.current_y
< it
.last_visible_y
11536 && !fonts_changed_p
)
11538 /* Is it always sure that the display agrees with lines in
11539 the current matrix? I don't think so, so we mark rows
11540 displayed invalid in the current matrix by setting their
11541 enabled_p flag to zero. */
11542 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11543 if (display_line (&it
))
11544 last_text_row_at_end
= it
.glyph_row
- 1;
11548 /* Update window_end_pos and window_end_vpos. */
11549 if (first_unchanged_at_end_row
11550 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11551 && !last_text_row_at_end
)
11553 /* Window end line if one of the preserved rows from the current
11554 matrix. Set row to the last row displaying text in current
11555 matrix starting at first_unchanged_at_end_row, after
11557 xassert (first_unchanged_at_end_row
->displays_text_p
);
11558 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11559 first_unchanged_at_end_row
);
11560 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11562 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11563 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11565 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11567 else if (last_text_row_at_end
)
11570 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11571 w
->window_end_bytepos
11572 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11574 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11576 else if (last_text_row
)
11578 /* We have displayed either to the end of the window or at the
11579 end of the window, i.e. the last row with text is to be found
11580 in the desired matrix. */
11582 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11583 w
->window_end_bytepos
11584 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11586 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11588 else if (first_unchanged_at_end_row
== NULL
11589 && last_text_row
== NULL
11590 && last_text_row_at_end
== NULL
)
11592 /* Displayed to end of window, but no line containing text was
11593 displayed. Lines were deleted at the end of the window. */
11595 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11597 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
11598 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
11599 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
11600 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
11601 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
11604 w
->window_end_vpos
= make_number (vpos
);
11609 #if 0 /* This leads to problems, for instance when the cursor is
11610 at ZV, and the cursor line displays no text. */
11611 /* Disable rows below what's displayed in the window. This makes
11612 debugging easier. */
11613 enable_glyph_matrix_rows (current_matrix
,
11614 XFASTINT (w
->window_end_vpos
) + 1,
11618 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11619 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11621 /* Record that display has not been completed. */
11622 w
->window_end_valid
= Qnil
;
11623 w
->desired_matrix
->no_scrolling_p
= 1;
11629 /***********************************************************************
11630 More debugging support
11631 ***********************************************************************/
11635 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
11636 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11637 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
11640 /* Dump the contents of glyph matrix MATRIX on stderr.
11642 GLYPHS 0 means don't show glyph contents.
11643 GLYPHS 1 means show glyphs in short form
11644 GLYPHS > 1 means show glyphs in long form. */
11647 dump_glyph_matrix (matrix
, glyphs
)
11648 struct glyph_matrix
*matrix
;
11652 for (i
= 0; i
< matrix
->nrows
; ++i
)
11653 dump_glyph_row (matrix
, i
, glyphs
);
11657 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
11658 the glyph row and area where the glyph comes from. */
11661 dump_glyph (row
, glyph
, area
)
11662 struct glyph_row
*row
;
11663 struct glyph
*glyph
;
11666 if (glyph
->type
== CHAR_GLYPH
)
11669 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11670 glyph
- row
->glyphs
[TEXT_AREA
],
11673 (BUFFERP (glyph
->object
)
11675 : (STRINGP (glyph
->object
)
11678 glyph
->pixel_width
,
11680 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
11684 glyph
->left_box_line_p
,
11685 glyph
->right_box_line_p
);
11687 else if (glyph
->type
== STRETCH_GLYPH
)
11690 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11691 glyph
- row
->glyphs
[TEXT_AREA
],
11694 (BUFFERP (glyph
->object
)
11696 : (STRINGP (glyph
->object
)
11699 glyph
->pixel_width
,
11703 glyph
->left_box_line_p
,
11704 glyph
->right_box_line_p
);
11706 else if (glyph
->type
== IMAGE_GLYPH
)
11709 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11710 glyph
- row
->glyphs
[TEXT_AREA
],
11713 (BUFFERP (glyph
->object
)
11715 : (STRINGP (glyph
->object
)
11718 glyph
->pixel_width
,
11722 glyph
->left_box_line_p
,
11723 glyph
->right_box_line_p
);
11728 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
11729 GLYPHS 0 means don't show glyph contents.
11730 GLYPHS 1 means show glyphs in short form
11731 GLYPHS > 1 means show glyphs in long form. */
11734 dump_glyph_row (matrix
, vpos
, glyphs
)
11735 struct glyph_matrix
*matrix
;
11738 struct glyph_row
*row
;
11740 if (vpos
< 0 || vpos
>= matrix
->nrows
)
11743 row
= MATRIX_ROW (matrix
, vpos
);
11747 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
11748 fprintf (stderr
, "=======================================================================\n");
11750 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d\
11751 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
11752 row
- matrix
->rows
,
11753 MATRIX_ROW_START_CHARPOS (row
),
11754 MATRIX_ROW_END_CHARPOS (row
),
11755 row
->used
[TEXT_AREA
],
11756 row
->contains_overlapping_glyphs_p
,
11759 row
->truncated_on_left_p
,
11760 row
->truncated_on_right_p
,
11761 row
->overlay_arrow_p
,
11763 MATRIX_ROW_CONTINUATION_LINE_P (row
),
11764 row
->displays_text_p
,
11767 row
->ends_in_middle_of_char_p
,
11768 row
->starts_in_middle_of_char_p
,
11774 row
->visible_height
,
11777 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
11778 row
->end
.overlay_string_index
);
11779 fprintf (stderr
, "%9d %5d\n",
11780 CHARPOS (row
->start
.string_pos
),
11781 CHARPOS (row
->end
.string_pos
));
11782 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
11783 row
->end
.dpvec_index
);
11790 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11792 struct glyph
*glyph
= row
->glyphs
[area
];
11793 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
11795 /* Glyph for a line end in text. */
11796 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
11799 if (glyph
< glyph_end
)
11800 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
11802 for (; glyph
< glyph_end
; ++glyph
)
11803 dump_glyph (row
, glyph
, area
);
11806 else if (glyphs
== 1)
11810 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11812 char *s
= (char *) alloca (row
->used
[area
] + 1);
11815 for (i
= 0; i
< row
->used
[area
]; ++i
)
11817 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
11818 if (glyph
->type
== CHAR_GLYPH
11819 && glyph
->u
.ch
< 0x80
11820 && glyph
->u
.ch
>= ' ')
11821 s
[i
] = glyph
->u
.ch
;
11827 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
11833 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
11834 Sdump_glyph_matrix
, 0, 1, "p",
11835 "Dump the current matrix of the selected window to stderr.\n\
11836 Shows contents of glyph row structures. With non-nil\n\
11837 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show\n\
11838 glyphs in short form, otherwise show glyphs in long form.")
11840 Lisp_Object glyphs
;
11842 struct window
*w
= XWINDOW (selected_window
);
11843 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11845 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
11846 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
11847 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
11848 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
11849 fprintf (stderr
, "=============================================\n");
11850 dump_glyph_matrix (w
->current_matrix
,
11851 NILP (glyphs
) ? 0 : XINT (glyphs
));
11856 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
11857 "Dump glyph row ROW to stderr.\n\
11858 GLYPH 0 means don't dump glyphs.\n\
11859 GLYPH 1 means dump glyphs in short form.\n\
11860 GLYPH > 1 or omitted means dump glyphs in long form.")
11862 Lisp_Object row
, glyphs
;
11864 CHECK_NUMBER (row
, 0);
11865 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
,
11867 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
11872 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
11873 "Dump glyph row ROW of the tool-bar of the current frame to stderr.\n\
11874 GLYPH 0 means don't dump glyphs.\n\
11875 GLYPH 1 means dump glyphs in short form.\n\
11876 GLYPH > 1 or omitted means dump glyphs in long form.")
11878 Lisp_Object row
, glyphs
;
11880 struct frame
*sf
= SELECTED_FRAME ();
11881 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)->current_matrix
);
11882 dump_glyph_row (m
, XINT (row
), INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
11887 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
11888 Strace_redisplay_toggle
, 0, 0, "",
11889 "Toggle tracing of redisplay.")
11892 trace_redisplay_p
= !trace_redisplay_p
;
11897 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
11898 "Print STRING to stderr.")
11900 Lisp_Object string
;
11902 CHECK_STRING (string
, 0);
11903 fprintf (stderr
, "%s", XSTRING (string
)->data
);
11907 #endif /* GLYPH_DEBUG */
11911 /***********************************************************************
11912 Building Desired Matrix Rows
11913 ***********************************************************************/
11915 /* Return a temporary glyph row holding the glyphs of an overlay
11916 arrow. Only used for non-window-redisplay windows. */
11918 static struct glyph_row
*
11919 get_overlay_arrow_glyph_row (w
)
11922 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11923 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11924 struct buffer
*old
= current_buffer
;
11925 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
11926 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
11927 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
11931 int n_glyphs_before
;
11933 set_buffer_temp (buffer
);
11934 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
11935 it
.glyph_row
->used
[TEXT_AREA
] = 0;
11936 SET_TEXT_POS (it
.position
, 0, 0);
11938 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
11940 while (p
< arrow_end
)
11942 Lisp_Object face
, ilisp
;
11944 /* Get the next character. */
11946 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
11948 it
.c
= *p
, it
.len
= 1;
11951 /* Get its face. */
11952 ilisp
= make_number (p
- arrow_string
);
11953 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
11954 it
.face_id
= compute_char_face (f
, it
.c
, face
);
11956 /* Compute its width, get its glyphs. */
11957 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
11958 SET_TEXT_POS (it
.position
, -1, -1);
11959 PRODUCE_GLYPHS (&it
);
11961 /* If this character doesn't fit any more in the line, we have
11962 to remove some glyphs. */
11963 if (it
.current_x
> it
.last_visible_x
)
11965 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
11970 set_buffer_temp (old
);
11971 return it
.glyph_row
;
11975 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
11976 glyphs are only inserted for terminal frames since we can't really
11977 win with truncation glyphs when partially visible glyphs are
11978 involved. Which glyphs to insert is determined by
11979 produce_special_glyphs. */
11982 insert_left_trunc_glyphs (it
)
11985 struct it truncate_it
;
11986 struct glyph
*from
, *end
, *to
, *toend
;
11988 xassert (!FRAME_WINDOW_P (it
->f
));
11990 /* Get the truncation glyphs. */
11992 truncate_it
.current_x
= 0;
11993 truncate_it
.face_id
= DEFAULT_FACE_ID
;
11994 truncate_it
.glyph_row
= &scratch_glyph_row
;
11995 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
11996 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
11997 truncate_it
.object
= make_number (0);
11998 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12000 /* Overwrite glyphs from IT with truncation glyphs. */
12001 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12002 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12003 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12004 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12009 /* There may be padding glyphs left over. Overwrite them too. */
12010 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12012 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12018 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12022 /* Compute the pixel height and width of IT->glyph_row.
12024 Most of the time, ascent and height of a display line will be equal
12025 to the max_ascent and max_height values of the display iterator
12026 structure. This is not the case if
12028 1. We hit ZV without displaying anything. In this case, max_ascent
12029 and max_height will be zero.
12031 2. We have some glyphs that don't contribute to the line height.
12032 (The glyph row flag contributes_to_line_height_p is for future
12033 pixmap extensions).
12035 The first case is easily covered by using default values because in
12036 these cases, the line height does not really matter, except that it
12037 must not be zero. */
12040 compute_line_metrics (it
)
12043 struct glyph_row
*row
= it
->glyph_row
;
12046 if (FRAME_WINDOW_P (it
->f
))
12048 int i
, header_line_height
;
12050 /* The line may consist of one space only, that was added to
12051 place the cursor on it. If so, the row's height hasn't been
12053 if (row
->height
== 0)
12055 if (it
->max_ascent
+ it
->max_descent
== 0)
12056 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12057 row
->ascent
= it
->max_ascent
;
12058 row
->height
= it
->max_ascent
+ it
->max_descent
;
12059 row
->phys_ascent
= it
->max_phys_ascent
;
12060 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12063 /* Compute the width of this line. */
12064 row
->pixel_width
= row
->x
;
12065 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12066 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12068 xassert (row
->pixel_width
>= 0);
12069 xassert (row
->ascent
>= 0 && row
->height
> 0);
12071 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12072 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12074 /* If first line's physical ascent is larger than its logical
12075 ascent, use the physical ascent, and make the row taller.
12076 This makes accented characters fully visible. */
12077 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12078 && row
->phys_ascent
> row
->ascent
)
12080 row
->height
+= row
->phys_ascent
- row
->ascent
;
12081 row
->ascent
= row
->phys_ascent
;
12084 /* Compute how much of the line is visible. */
12085 row
->visible_height
= row
->height
;
12087 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12088 if (row
->y
< header_line_height
)
12089 row
->visible_height
-= header_line_height
- row
->y
;
12092 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12093 if (row
->y
+ row
->height
> max_y
)
12094 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12099 row
->pixel_width
= row
->used
[TEXT_AREA
];
12100 row
->ascent
= row
->phys_ascent
= 0;
12101 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12104 /* Compute a hash code for this row. */
12106 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12107 for (i
= 0; i
< row
->used
[area
]; ++i
)
12108 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12109 + row
->glyphs
[area
][i
].u
.val
12110 + row
->glyphs
[area
][i
].face_id
12111 + row
->glyphs
[area
][i
].padding_p
12112 + (row
->glyphs
[area
][i
].type
<< 2));
12114 it
->max_ascent
= it
->max_descent
= 0;
12115 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12119 /* Append one space to the glyph row of iterator IT if doing a
12120 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12121 space have the default face, otherwise let it have the same face as
12122 IT->face_id. Value is non-zero if a space was added.
12124 This function is called to make sure that there is always one glyph
12125 at the end of a glyph row that the cursor can be set on under
12126 window-systems. (If there weren't such a glyph we would not know
12127 how wide and tall a box cursor should be displayed).
12129 At the same time this space let's a nicely handle clearing to the
12130 end of the line if the row ends in italic text. */
12133 append_space (it
, default_face_p
)
12135 int default_face_p
;
12137 if (FRAME_WINDOW_P (it
->f
))
12139 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12141 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12142 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12144 /* Save some values that must not be changed.
12145 Must save IT->c and IT->len because otherwise
12146 ITERATOR_AT_END_P wouldn't work anymore after
12147 append_space has been called. */
12148 enum display_element_type saved_what
= it
->what
;
12149 int saved_c
= it
->c
, saved_len
= it
->len
;
12150 int saved_x
= it
->current_x
;
12151 int saved_face_id
= it
->face_id
;
12152 struct text_pos saved_pos
;
12153 Lisp_Object saved_object
;
12156 saved_object
= it
->object
;
12157 saved_pos
= it
->position
;
12159 it
->what
= IT_CHARACTER
;
12160 bzero (&it
->position
, sizeof it
->position
);
12161 it
->object
= make_number (0);
12165 if (default_face_p
)
12166 it
->face_id
= DEFAULT_FACE_ID
;
12167 else if (it
->face_before_selective_p
)
12168 it
->face_id
= it
->saved_face_id
;
12169 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12170 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12172 PRODUCE_GLYPHS (it
);
12174 it
->current_x
= saved_x
;
12175 it
->object
= saved_object
;
12176 it
->position
= saved_pos
;
12177 it
->what
= saved_what
;
12178 it
->face_id
= saved_face_id
;
12179 it
->len
= saved_len
;
12189 /* Extend the face of the last glyph in the text area of IT->glyph_row
12190 to the end of the display line. Called from display_line.
12191 If the glyph row is empty, add a space glyph to it so that we
12192 know the face to draw. Set the glyph row flag fill_line_p. */
12195 extend_face_to_end_of_line (it
)
12199 struct frame
*f
= it
->f
;
12201 /* If line is already filled, do nothing. */
12202 if (it
->current_x
>= it
->last_visible_x
)
12205 /* Face extension extends the background and box of IT->face_id
12206 to the end of the line. If the background equals the background
12207 of the frame, we don't have to do anything. */
12208 if (it
->face_before_selective_p
)
12209 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12211 face
= FACE_FROM_ID (f
, it
->face_id
);
12213 if (FRAME_WINDOW_P (f
)
12214 && face
->box
== FACE_NO_BOX
12215 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12219 /* Set the glyph row flag indicating that the face of the last glyph
12220 in the text area has to be drawn to the end of the text area. */
12221 it
->glyph_row
->fill_line_p
= 1;
12223 /* If current character of IT is not ASCII, make sure we have the
12224 ASCII face. This will be automatically undone the next time
12225 get_next_display_element returns a multibyte character. Note
12226 that the character will always be single byte in unibyte text. */
12227 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12229 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12232 if (FRAME_WINDOW_P (f
))
12234 /* If the row is empty, add a space with the current face of IT,
12235 so that we know which face to draw. */
12236 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12238 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12239 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12240 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12245 /* Save some values that must not be changed. */
12246 int saved_x
= it
->current_x
;
12247 struct text_pos saved_pos
;
12248 Lisp_Object saved_object
;
12249 enum display_element_type saved_what
= it
->what
;
12250 int saved_face_id
= it
->face_id
;
12252 saved_object
= it
->object
;
12253 saved_pos
= it
->position
;
12255 it
->what
= IT_CHARACTER
;
12256 bzero (&it
->position
, sizeof it
->position
);
12257 it
->object
= make_number (0);
12260 it
->face_id
= face
->id
;
12262 PRODUCE_GLYPHS (it
);
12264 while (it
->current_x
<= it
->last_visible_x
)
12265 PRODUCE_GLYPHS (it
);
12267 /* Don't count these blanks really. It would let us insert a left
12268 truncation glyph below and make us set the cursor on them, maybe. */
12269 it
->current_x
= saved_x
;
12270 it
->object
= saved_object
;
12271 it
->position
= saved_pos
;
12272 it
->what
= saved_what
;
12273 it
->face_id
= saved_face_id
;
12278 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12279 trailing whitespace. */
12282 trailing_whitespace_p (charpos
)
12285 int bytepos
= CHAR_TO_BYTE (charpos
);
12288 while (bytepos
< ZV_BYTE
12289 && (c
= FETCH_CHAR (bytepos
),
12290 c
== ' ' || c
== '\t'))
12293 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12295 if (bytepos
!= PT_BYTE
)
12302 /* Highlight trailing whitespace, if any, in ROW. */
12305 highlight_trailing_whitespace (f
, row
)
12307 struct glyph_row
*row
;
12309 int used
= row
->used
[TEXT_AREA
];
12313 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12314 struct glyph
*glyph
= start
+ used
- 1;
12316 /* Skip over glyphs inserted to display the cursor at the
12317 end of a line, for extending the face of the last glyph
12318 to the end of the line on terminals, and for truncation
12319 and continuation glyphs. */
12320 while (glyph
>= start
12321 && glyph
->type
== CHAR_GLYPH
12322 && INTEGERP (glyph
->object
))
12325 /* If last glyph is a space or stretch, and it's trailing
12326 whitespace, set the face of all trailing whitespace glyphs in
12327 IT->glyph_row to `trailing-whitespace'. */
12329 && BUFFERP (glyph
->object
)
12330 && (glyph
->type
== STRETCH_GLYPH
12331 || (glyph
->type
== CHAR_GLYPH
12332 && glyph
->u
.ch
== ' '))
12333 && trailing_whitespace_p (glyph
->charpos
))
12335 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12337 while (glyph
>= start
12338 && BUFFERP (glyph
->object
)
12339 && (glyph
->type
== STRETCH_GLYPH
12340 || (glyph
->type
== CHAR_GLYPH
12341 && glyph
->u
.ch
== ' ')))
12342 (glyph
--)->face_id
= face_id
;
12348 /* Value is non-zero if glyph row ROW in window W should be
12349 used to hold the cursor. */
12352 cursor_row_p (w
, row
)
12354 struct glyph_row
*row
;
12356 int cursor_row_p
= 1;
12358 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12360 /* If the row ends with a newline from a string, we don't want
12361 the cursor there (if the row is continued it doesn't end in a
12363 if (CHARPOS (row
->end
.string_pos
) >= 0
12364 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12365 cursor_row_p
= row
->continued_p
;
12367 /* If the row ends at ZV, display the cursor at the end of that
12368 row instead of at the start of the row below. */
12369 else if (row
->ends_at_zv_p
)
12375 return cursor_row_p
;
12379 /* Construct the glyph row IT->glyph_row in the desired matrix of
12380 IT->w from text at the current position of IT. See dispextern.h
12381 for an overview of struct it. Value is non-zero if
12382 IT->glyph_row displays text, as opposed to a line displaying ZV
12389 struct glyph_row
*row
= it
->glyph_row
;
12391 /* We always start displaying at hpos zero even if hscrolled. */
12392 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12394 /* We must not display in a row that's not a text row. */
12395 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12396 < it
->w
->desired_matrix
->nrows
);
12398 /* Is IT->w showing the region? */
12399 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12401 /* Clear the result glyph row and enable it. */
12402 prepare_desired_row (row
);
12404 row
->y
= it
->current_y
;
12405 row
->start
= it
->current
;
12406 row
->continuation_lines_width
= it
->continuation_lines_width
;
12407 row
->displays_text_p
= 1;
12408 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12409 it
->starts_in_middle_of_char_p
= 0;
12411 /* Arrange the overlays nicely for our purposes. Usually, we call
12412 display_line on only one line at a time, in which case this
12413 can't really hurt too much, or we call it on lines which appear
12414 one after another in the buffer, in which case all calls to
12415 recenter_overlay_lists but the first will be pretty cheap. */
12416 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12418 /* Move over display elements that are not visible because we are
12419 hscrolled. This may stop at an x-position < IT->first_visible_x
12420 if the first glyph is partially visible or if we hit a line end. */
12421 if (it
->current_x
< it
->first_visible_x
)
12422 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12423 MOVE_TO_POS
| MOVE_TO_X
);
12425 /* Get the initial row height. This is either the height of the
12426 text hscrolled, if there is any, or zero. */
12427 row
->ascent
= it
->max_ascent
;
12428 row
->height
= it
->max_ascent
+ it
->max_descent
;
12429 row
->phys_ascent
= it
->max_phys_ascent
;
12430 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12432 /* Loop generating characters. The loop is left with IT on the next
12433 character to display. */
12436 int n_glyphs_before
, hpos_before
, x_before
;
12438 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12440 /* Retrieve the next thing to display. Value is zero if end of
12442 if (!get_next_display_element (it
))
12444 /* Maybe add a space at the end of this line that is used to
12445 display the cursor there under X. Set the charpos of the
12446 first glyph of blank lines not corresponding to any text
12448 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12449 || row
->used
[TEXT_AREA
] == 0)
12451 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12452 row
->displays_text_p
= 0;
12454 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
12455 row
->indicate_empty_line_p
= 1;
12458 it
->continuation_lines_width
= 0;
12459 row
->ends_at_zv_p
= 1;
12463 /* Now, get the metrics of what we want to display. This also
12464 generates glyphs in `row' (which is IT->glyph_row). */
12465 n_glyphs_before
= row
->used
[TEXT_AREA
];
12468 /* Remember the line height so far in case the next element doesn't
12469 fit on the line. */
12470 if (!it
->truncate_lines_p
)
12472 ascent
= it
->max_ascent
;
12473 descent
= it
->max_descent
;
12474 phys_ascent
= it
->max_phys_ascent
;
12475 phys_descent
= it
->max_phys_descent
;
12478 PRODUCE_GLYPHS (it
);
12480 /* If this display element was in marginal areas, continue with
12482 if (it
->area
!= TEXT_AREA
)
12484 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12485 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12486 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12487 row
->phys_height
= max (row
->phys_height
,
12488 it
->max_phys_ascent
+ it
->max_phys_descent
);
12489 set_iterator_to_next (it
, 1);
12493 /* Does the display element fit on the line? If we truncate
12494 lines, we should draw past the right edge of the window. If
12495 we don't truncate, we want to stop so that we can display the
12496 continuation glyph before the right margin. If lines are
12497 continued, there are two possible strategies for characters
12498 resulting in more than 1 glyph (e.g. tabs): Display as many
12499 glyphs as possible in this line and leave the rest for the
12500 continuation line, or display the whole element in the next
12501 line. Original redisplay did the former, so we do it also. */
12502 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12503 hpos_before
= it
->hpos
;
12506 if (/* Not a newline. */
12508 /* Glyphs produced fit entirely in the line. */
12509 && it
->current_x
< it
->last_visible_x
)
12511 it
->hpos
+= nglyphs
;
12512 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12513 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12514 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12515 row
->phys_height
= max (row
->phys_height
,
12516 it
->max_phys_ascent
+ it
->max_phys_descent
);
12517 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
12518 row
->x
= x
- it
->first_visible_x
;
12523 struct glyph
*glyph
;
12525 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
12527 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12528 new_x
= x
+ glyph
->pixel_width
;
12530 if (/* Lines are continued. */
12531 !it
->truncate_lines_p
12532 && (/* Glyph doesn't fit on the line. */
12533 new_x
> it
->last_visible_x
12534 /* Or it fits exactly on a window system frame. */
12535 || (new_x
== it
->last_visible_x
12536 && FRAME_WINDOW_P (it
->f
))))
12538 /* End of a continued line. */
12541 || (new_x
== it
->last_visible_x
12542 && FRAME_WINDOW_P (it
->f
)))
12544 /* Current glyph is the only one on the line or
12545 fits exactly on the line. We must continue
12546 the line because we can't draw the cursor
12547 after the glyph. */
12548 row
->continued_p
= 1;
12549 it
->current_x
= new_x
;
12550 it
->continuation_lines_width
+= new_x
;
12552 if (i
== nglyphs
- 1)
12553 set_iterator_to_next (it
, 1);
12555 else if (CHAR_GLYPH_PADDING_P (*glyph
)
12556 && !FRAME_WINDOW_P (it
->f
))
12558 /* A padding glyph that doesn't fit on this line.
12559 This means the whole character doesn't fit
12561 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12563 /* Fill the rest of the row with continuation
12564 glyphs like in 20.x. */
12565 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
12566 < row
->glyphs
[1 + TEXT_AREA
])
12567 produce_special_glyphs (it
, IT_CONTINUATION
);
12569 row
->continued_p
= 1;
12570 it
->current_x
= x_before
;
12571 it
->continuation_lines_width
+= x_before
;
12573 /* Restore the height to what it was before the
12574 element not fitting on the line. */
12575 it
->max_ascent
= ascent
;
12576 it
->max_descent
= descent
;
12577 it
->max_phys_ascent
= phys_ascent
;
12578 it
->max_phys_descent
= phys_descent
;
12582 /* Display element draws past the right edge of
12583 the window. Restore positions to values
12584 before the element. The next line starts
12585 with current_x before the glyph that could
12586 not be displayed, so that TAB works right. */
12587 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12589 /* Display continuation glyphs. */
12590 if (!FRAME_WINDOW_P (it
->f
))
12591 produce_special_glyphs (it
, IT_CONTINUATION
);
12592 row
->continued_p
= 1;
12595 it
->continuation_lines_width
+= x
;
12596 if (nglyphs
> 1 && i
> 0)
12598 row
->ends_in_middle_of_char_p
= 1;
12599 it
->starts_in_middle_of_char_p
= 1;
12602 /* Restore the height to what it was before the
12603 element not fitting on the line. */
12604 it
->max_ascent
= ascent
;
12605 it
->max_descent
= descent
;
12606 it
->max_phys_ascent
= phys_ascent
;
12607 it
->max_phys_descent
= phys_descent
;
12612 else if (new_x
> it
->first_visible_x
)
12614 /* Increment number of glyphs actually displayed. */
12617 if (x
< it
->first_visible_x
)
12618 /* Glyph is partially visible, i.e. row starts at
12619 negative X position. */
12620 row
->x
= x
- it
->first_visible_x
;
12624 /* Glyph is completely off the left margin of the
12625 window. This should not happen because of the
12626 move_it_in_display_line at the start of
12632 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12633 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12634 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12635 row
->phys_height
= max (row
->phys_height
,
12636 it
->max_phys_ascent
+ it
->max_phys_descent
);
12638 /* End of this display line if row is continued. */
12639 if (row
->continued_p
)
12643 /* Is this a line end? If yes, we're also done, after making
12644 sure that a non-default face is extended up to the right
12645 margin of the window. */
12646 if (ITERATOR_AT_END_OF_LINE_P (it
))
12648 int used_before
= row
->used
[TEXT_AREA
];
12650 /* Add a space at the end of the line that is used to
12651 display the cursor there. */
12652 append_space (it
, 0);
12654 /* Extend the face to the end of the line. */
12655 extend_face_to_end_of_line (it
);
12657 /* Make sure we have the position. */
12658 if (used_before
== 0)
12659 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
12661 /* Consume the line end. This skips over invisible lines. */
12662 set_iterator_to_next (it
, 1);
12663 it
->continuation_lines_width
= 0;
12667 /* Proceed with next display element. Note that this skips
12668 over lines invisible because of selective display. */
12669 set_iterator_to_next (it
, 1);
12671 /* If we truncate lines, we are done when the last displayed
12672 glyphs reach past the right margin of the window. */
12673 if (it
->truncate_lines_p
12674 && (FRAME_WINDOW_P (it
->f
)
12675 ? (it
->current_x
>= it
->last_visible_x
)
12676 : (it
->current_x
> it
->last_visible_x
)))
12678 /* Maybe add truncation glyphs. */
12679 if (!FRAME_WINDOW_P (it
->f
))
12683 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
12684 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
12687 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
12689 row
->used
[TEXT_AREA
] = i
;
12690 produce_special_glyphs (it
, IT_TRUNCATION
);
12694 row
->truncated_on_right_p
= 1;
12695 it
->continuation_lines_width
= 0;
12696 reseat_at_next_visible_line_start (it
, 0);
12697 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
12698 it
->hpos
= hpos_before
;
12699 it
->current_x
= x_before
;
12704 /* If line is not empty and hscrolled, maybe insert truncation glyphs
12705 at the left window margin. */
12706 if (it
->first_visible_x
12707 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
12709 if (!FRAME_WINDOW_P (it
->f
))
12710 insert_left_trunc_glyphs (it
);
12711 row
->truncated_on_left_p
= 1;
12714 /* If the start of this line is the overlay arrow-position, then
12715 mark this glyph row as the one containing the overlay arrow.
12716 This is clearly a mess with variable size fonts. It would be
12717 better to let it be displayed like cursors under X. */
12718 if (MARKERP (Voverlay_arrow_position
)
12719 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
12720 && (MATRIX_ROW_START_CHARPOS (row
)
12721 == marker_position (Voverlay_arrow_position
))
12722 && STRINGP (Voverlay_arrow_string
)
12723 && ! overlay_arrow_seen
)
12725 /* Overlay arrow in window redisplay is a bitmap. */
12726 if (!FRAME_WINDOW_P (it
->f
))
12728 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
12729 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
12730 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
12731 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
12732 struct glyph
*p2
, *end
;
12734 /* Copy the arrow glyphs. */
12735 while (glyph
< arrow_end
)
12738 /* Throw away padding glyphs. */
12740 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
12741 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
12747 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
12751 overlay_arrow_seen
= 1;
12752 row
->overlay_arrow_p
= 1;
12755 /* Compute pixel dimensions of this line. */
12756 compute_line_metrics (it
);
12758 /* Remember the position at which this line ends. */
12759 row
->end
= it
->current
;
12761 /* Maybe set the cursor. */
12762 if (it
->w
->cursor
.vpos
< 0
12763 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
12764 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
12765 && cursor_row_p (it
->w
, row
))
12766 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
12768 /* Highlight trailing whitespace. */
12769 if (!NILP (Vshow_trailing_whitespace
))
12770 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
12772 /* Prepare for the next line. This line starts horizontally at (X
12773 HPOS) = (0 0). Vertical positions are incremented. As a
12774 convenience for the caller, IT->glyph_row is set to the next
12776 it
->current_x
= it
->hpos
= 0;
12777 it
->current_y
+= row
->height
;
12780 return row
->displays_text_p
;
12785 /***********************************************************************
12787 ***********************************************************************/
12789 /* Redisplay the menu bar in the frame for window W.
12791 The menu bar of X frames that don't have X toolkit support is
12792 displayed in a special window W->frame->menu_bar_window.
12794 The menu bar of terminal frames is treated specially as far as
12795 glyph matrices are concerned. Menu bar lines are not part of
12796 windows, so the update is done directly on the frame matrix rows
12797 for the menu bar. */
12800 display_menu_bar (w
)
12803 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12808 /* Don't do all this for graphical frames. */
12810 if (!NILP (Vwindow_system
))
12813 #ifdef USE_X_TOOLKIT
12818 if (FRAME_MAC_P (f
))
12822 #ifdef USE_X_TOOLKIT
12823 xassert (!FRAME_WINDOW_P (f
));
12824 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
12825 it
.first_visible_x
= 0;
12826 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12827 #else /* not USE_X_TOOLKIT */
12828 if (FRAME_WINDOW_P (f
))
12830 /* Menu bar lines are displayed in the desired matrix of the
12831 dummy window menu_bar_window. */
12832 struct window
*menu_w
;
12833 xassert (WINDOWP (f
->menu_bar_window
));
12834 menu_w
= XWINDOW (f
->menu_bar_window
);
12835 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
12837 it
.first_visible_x
= 0;
12838 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12842 /* This is a TTY frame, i.e. character hpos/vpos are used as
12844 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
12846 it
.first_visible_x
= 0;
12847 it
.last_visible_x
= FRAME_WIDTH (f
);
12849 #endif /* not USE_X_TOOLKIT */
12851 if (! mode_line_inverse_video
)
12852 /* Force the menu-bar to be displayed in the default face. */
12853 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
12855 /* Clear all rows of the menu bar. */
12856 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
12858 struct glyph_row
*row
= it
.glyph_row
+ i
;
12859 clear_glyph_row (row
);
12860 row
->enabled_p
= 1;
12861 row
->full_width_p
= 1;
12864 /* Display all items of the menu bar. */
12865 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
12866 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
12868 Lisp_Object string
;
12870 /* Stop at nil string. */
12871 string
= AREF (items
, i
+ 1);
12875 /* Remember where item was displayed. */
12876 AREF (items
, i
+ 3) = make_number (it
.hpos
);
12878 /* Display the item, pad with one space. */
12879 if (it
.current_x
< it
.last_visible_x
)
12880 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
12881 XSTRING (string
)->size
+ 1, 0, 0, -1);
12884 /* Fill out the line with spaces. */
12885 if (it
.current_x
< it
.last_visible_x
)
12886 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
12888 /* Compute the total height of the lines. */
12889 compute_line_metrics (&it
);
12894 /***********************************************************************
12896 ***********************************************************************/
12898 /* Redisplay mode lines in the window tree whose root is WINDOW. If
12899 FORCE is non-zero, redisplay mode lines unconditionally.
12900 Otherwise, redisplay only mode lines that are garbaged. Value is
12901 the number of windows whose mode lines were redisplayed. */
12904 redisplay_mode_lines (window
, force
)
12905 Lisp_Object window
;
12910 while (!NILP (window
))
12912 struct window
*w
= XWINDOW (window
);
12914 if (WINDOWP (w
->hchild
))
12915 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
12916 else if (WINDOWP (w
->vchild
))
12917 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
12919 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
12920 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
12922 Lisp_Object old_selected_frame
;
12923 struct text_pos lpoint
;
12924 struct buffer
*old
= current_buffer
;
12926 /* Set the window's buffer for the mode line display. */
12927 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12928 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12930 /* Point refers normally to the selected window. For any
12931 other window, set up appropriate value. */
12932 if (!EQ (window
, selected_window
))
12934 struct text_pos pt
;
12936 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
12937 if (CHARPOS (pt
) < BEGV
)
12938 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
12939 else if (CHARPOS (pt
) > (ZV
- 1))
12940 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
12942 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
12945 /* Temporarily set up the selected frame. */
12946 old_selected_frame
= selected_frame
;
12947 selected_frame
= w
->frame
;
12949 /* Display mode lines. */
12950 clear_glyph_matrix (w
->desired_matrix
);
12951 if (display_mode_lines (w
))
12954 w
->must_be_updated_p
= 1;
12957 /* Restore old settings. */
12958 selected_frame
= old_selected_frame
;
12959 set_buffer_internal_1 (old
);
12960 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12970 /* Display the mode and/or top line of window W. Value is the number
12971 of mode lines displayed. */
12974 display_mode_lines (w
)
12979 /* These will be set while the mode line specs are processed. */
12980 line_number_displayed
= 0;
12981 w
->column_number_displayed
= Qnil
;
12983 if (WINDOW_WANTS_MODELINE_P (w
))
12985 display_mode_line (w
, MODE_LINE_FACE_ID
,
12986 current_buffer
->mode_line_format
);
12990 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12992 display_mode_line (w
, HEADER_LINE_FACE_ID
,
12993 current_buffer
->header_line_format
);
13001 /* Display mode or top line of window W. FACE_ID specifies which line
13002 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13003 FORMAT is the mode line format to display. Value is the pixel
13004 height of the mode line displayed. */
13007 display_mode_line (w
, face_id
, format
)
13009 enum face_id face_id
;
13010 Lisp_Object format
;
13015 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13016 prepare_desired_row (it
.glyph_row
);
13018 if (! mode_line_inverse_video
)
13019 /* Force the mode-line to be displayed in the default face. */
13020 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13022 /* Temporarily make frame's keyboard the current kboard so that
13023 kboard-local variables in the mode_line_format will get the right
13025 push_frame_kboard (it
.f
);
13026 display_mode_element (&it
, 0, 0, 0, format
);
13027 pop_frame_kboard ();
13029 /* Fill up with spaces. */
13030 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13032 compute_line_metrics (&it
);
13033 it
.glyph_row
->full_width_p
= 1;
13034 it
.glyph_row
->mode_line_p
= 1;
13035 it
.glyph_row
->inverse_p
= 0;
13036 it
.glyph_row
->continued_p
= 0;
13037 it
.glyph_row
->truncated_on_left_p
= 0;
13038 it
.glyph_row
->truncated_on_right_p
= 0;
13040 /* Make a 3D mode-line have a shadow at its right end. */
13041 face
= FACE_FROM_ID (it
.f
, face_id
);
13042 extend_face_to_end_of_line (&it
);
13043 if (face
->box
!= FACE_NO_BOX
)
13045 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13046 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13047 last
->right_box_line_p
= 1;
13050 return it
.glyph_row
->height
;
13054 /* Contribute ELT to the mode line for window IT->w. How it
13055 translates into text depends on its data type.
13057 IT describes the display environment in which we display, as usual.
13059 DEPTH is the depth in recursion. It is used to prevent
13060 infinite recursion here.
13062 FIELD_WIDTH is the number of characters the display of ELT should
13063 occupy in the mode line, and PRECISION is the maximum number of
13064 characters to display from ELT's representation. See
13065 display_string for details. *
13067 Returns the hpos of the end of the text generated by ELT. */
13070 display_mode_element (it
, depth
, field_width
, precision
, elt
)
13073 int field_width
, precision
;
13076 int n
= 0, field
, prec
;
13084 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13088 /* A string: output it and check for %-constructs within it. */
13090 unsigned char *this = XSTRING (elt
)->data
;
13091 unsigned char *lisp_string
= this;
13093 while ((precision
<= 0 || n
< precision
)
13095 && (frame_title_ptr
13096 || it
->current_x
< it
->last_visible_x
))
13098 unsigned char *last
= this;
13100 /* Advance to end of string or next format specifier. */
13101 while ((c
= *this++) != '\0' && c
!= '%')
13104 if (this - 1 != last
)
13106 /* Output to end of string or up to '%'. Field width
13107 is length of string. Don't output more than
13108 PRECISION allows us. */
13110 prec
= strwidth (last
, this - last
);
13111 if (precision
> 0 && prec
> precision
- n
)
13112 prec
= precision
- n
;
13114 if (frame_title_ptr
)
13115 n
+= store_frame_title (last
, 0, prec
);
13117 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
13118 it
, 0, prec
, 0, -1);
13120 else /* c == '%' */
13122 unsigned char *percent_position
= this;
13124 /* Get the specified minimum width. Zero means
13127 while ((c
= *this++) >= '0' && c
<= '9')
13128 field
= field
* 10 + c
- '0';
13130 /* Don't pad beyond the total padding allowed. */
13131 if (field_width
- n
> 0 && field
> field_width
- n
)
13132 field
= field_width
- n
;
13134 /* Note that either PRECISION <= 0 or N < PRECISION. */
13135 prec
= precision
- n
;
13138 n
+= display_mode_element (it
, depth
, field
, prec
,
13139 Vglobal_mode_string
);
13142 unsigned char *spec
13143 = decode_mode_spec (it
->w
, c
, field
, prec
);
13145 if (frame_title_ptr
)
13146 n
+= store_frame_title (spec
, field
, prec
);
13150 = it
->glyph_row
->used
[TEXT_AREA
];
13152 = percent_position
- XSTRING (elt
)->data
;
13154 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
13155 field
, prec
, 0, -1);
13157 /* Assign to the glyphs written above the
13158 string where the `%x' came from, position
13162 struct glyph
*glyph
13163 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13167 for (i
= 0; i
< nwritten
; ++i
)
13169 glyph
[i
].object
= elt
;
13170 glyph
[i
].charpos
= charpos
;
13183 /* A symbol: process the value of the symbol recursively
13184 as if it appeared here directly. Avoid error if symbol void.
13185 Special case: if value of symbol is a string, output the string
13188 register Lisp_Object tem
;
13189 tem
= Fboundp (elt
);
13192 tem
= Fsymbol_value (elt
);
13193 /* If value is a string, output that string literally:
13194 don't check for % within it. */
13197 prec
= precision
- n
;
13198 if (frame_title_ptr
)
13199 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
13201 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
13204 else if (!EQ (tem
, elt
))
13206 /* Give up right away for nil or t. */
13216 register Lisp_Object car
, tem
;
13218 /* A cons cell: three distinct cases.
13219 If first element is a string or a cons, process all the elements
13220 and effectively concatenate them.
13221 If first element is a negative number, truncate displaying cdr to
13222 at most that many characters. If positive, pad (with spaces)
13223 to at least that many characters.
13224 If first element is a symbol, process the cadr or caddr recursively
13225 according to whether the symbol's value is non-nil or nil. */
13227 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
13229 /* An element of the form (:eval FORM) means evaluate FORM
13230 and use the result as mode line elements. */
13231 struct gcpro gcpro1
;
13234 spec
= safe_eval (XCAR (XCDR (elt
)));
13236 n
+= display_mode_element (it
, depth
, field_width
- n
,
13237 precision
- n
, spec
);
13240 else if (SYMBOLP (car
))
13242 tem
= Fboundp (car
);
13246 /* elt is now the cdr, and we know it is a cons cell.
13247 Use its car if CAR has a non-nil value. */
13250 tem
= Fsymbol_value (car
);
13257 /* Symbol's value is nil (or symbol is unbound)
13258 Get the cddr of the original list
13259 and if possible find the caddr and use that. */
13263 else if (!CONSP (elt
))
13268 else if (INTEGERP (car
))
13270 register int lim
= XINT (car
);
13274 /* Negative int means reduce maximum width. */
13275 if (precision
<= 0)
13278 precision
= min (precision
, -lim
);
13282 /* Padding specified. Don't let it be more than
13283 current maximum. */
13285 lim
= min (precision
, lim
);
13287 /* If that's more padding than already wanted, queue it.
13288 But don't reduce padding already specified even if
13289 that is beyond the current truncation point. */
13290 field_width
= max (lim
, field_width
);
13294 else if (STRINGP (car
) || CONSP (car
))
13296 register int limit
= 50;
13297 /* Limit is to protect against circular lists. */
13300 && (precision
<= 0 || n
< precision
))
13302 n
+= display_mode_element (it
, depth
, field_width
- n
,
13303 precision
- n
, XCAR (elt
));
13312 if (frame_title_ptr
)
13313 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13315 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13316 precision
- n
, 0, 0);
13320 /* Pad to FIELD_WIDTH. */
13321 if (field_width
> 0 && n
< field_width
)
13323 if (frame_title_ptr
)
13324 n
+= store_frame_title ("", field_width
- n
, 0);
13326 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13334 /* Write a null-terminated, right justified decimal representation of
13335 the positive integer D to BUF using a minimal field width WIDTH. */
13338 pint2str (buf
, width
, d
)
13339 register char *buf
;
13340 register int width
;
13343 register char *p
= buf
;
13351 *p
++ = d
% 10 + '0';
13356 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13367 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13368 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13369 type of CODING_SYSTEM. Return updated pointer into BUF. */
13371 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13374 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13375 Lisp_Object coding_system
;
13376 register char *buf
;
13380 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13381 unsigned char *eol_str
;
13383 /* The EOL conversion we are using. */
13384 Lisp_Object eoltype
;
13386 val
= Fget (coding_system
, Qcoding_system
);
13389 if (!VECTORP (val
)) /* Not yet decided. */
13394 eoltype
= eol_mnemonic_undecided
;
13395 /* Don't mention EOL conversion if it isn't decided. */
13399 Lisp_Object eolvalue
;
13401 eolvalue
= Fget (coding_system
, Qeol_type
);
13404 *buf
++ = XFASTINT (AREF (val
, 1));
13408 /* The EOL conversion that is normal on this system. */
13410 if (NILP (eolvalue
)) /* Not yet decided. */
13411 eoltype
= eol_mnemonic_undecided
;
13412 else if (VECTORP (eolvalue
)) /* Not yet decided. */
13413 eoltype
= eol_mnemonic_undecided
;
13414 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
13415 eoltype
= (XFASTINT (eolvalue
) == 0
13416 ? eol_mnemonic_unix
13417 : (XFASTINT (eolvalue
) == 1
13418 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
13424 /* Mention the EOL conversion if it is not the usual one. */
13425 if (STRINGP (eoltype
))
13427 eol_str
= XSTRING (eoltype
)->data
;
13428 eol_str_len
= XSTRING (eoltype
)->size
;
13430 else if (INTEGERP (eoltype
)
13431 && CHAR_VALID_P (XINT (eoltype
), 0))
13433 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
13434 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
13438 eol_str
= invalid_eol_type
;
13439 eol_str_len
= sizeof (invalid_eol_type
) - 1;
13441 bcopy (eol_str
, buf
, eol_str_len
);
13442 buf
+= eol_str_len
;
13448 /* Return a string for the output of a mode line %-spec for window W,
13449 generated by character C. PRECISION >= 0 means don't return a
13450 string longer than that value. FIELD_WIDTH > 0 means pad the
13451 string returned with spaces to that value. */
13453 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
13456 decode_mode_spec (w
, c
, field_width
, precision
)
13459 int field_width
, precision
;
13462 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13463 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
13464 struct buffer
*b
= XBUFFER (w
->buffer
);
13471 if (!NILP (b
->read_only
))
13473 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13478 /* This differs from %* only for a modified read-only buffer. */
13479 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13481 if (!NILP (b
->read_only
))
13486 /* This differs from %* in ignoring read-only-ness. */
13487 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13499 if (command_loop_level
> 5)
13501 p
= decode_mode_spec_buf
;
13502 for (i
= 0; i
< command_loop_level
; i
++)
13505 return decode_mode_spec_buf
;
13513 if (command_loop_level
> 5)
13515 p
= decode_mode_spec_buf
;
13516 for (i
= 0; i
< command_loop_level
; i
++)
13519 return decode_mode_spec_buf
;
13526 /* Let lots_of_dashes be a string of infinite length. */
13527 if (field_width
<= 0
13528 || field_width
> sizeof (lots_of_dashes
))
13530 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
13531 decode_mode_spec_buf
[i
] = '-';
13532 decode_mode_spec_buf
[i
] = '\0';
13533 return decode_mode_spec_buf
;
13536 return lots_of_dashes
;
13545 int col
= current_column ();
13546 w
->column_number_displayed
= make_number (col
);
13547 pint2str (decode_mode_spec_buf
, field_width
, col
);
13548 return decode_mode_spec_buf
;
13552 /* %F displays the frame name. */
13553 if (!NILP (f
->title
))
13554 return (char *) XSTRING (f
->title
)->data
;
13555 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
13556 return (char *) XSTRING (f
->name
)->data
;
13565 int startpos
= XMARKER (w
->start
)->charpos
;
13566 int startpos_byte
= marker_byte_position (w
->start
);
13567 int line
, linepos
, linepos_byte
, topline
;
13569 int height
= XFASTINT (w
->height
);
13571 /* If we decided that this buffer isn't suitable for line numbers,
13572 don't forget that too fast. */
13573 if (EQ (w
->base_line_pos
, w
->buffer
))
13575 /* But do forget it, if the window shows a different buffer now. */
13576 else if (BUFFERP (w
->base_line_pos
))
13577 w
->base_line_pos
= Qnil
;
13579 /* If the buffer is very big, don't waste time. */
13580 if (INTEGERP (Vline_number_display_limit
)
13581 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
13583 w
->base_line_pos
= Qnil
;
13584 w
->base_line_number
= Qnil
;
13588 if (!NILP (w
->base_line_number
)
13589 && !NILP (w
->base_line_pos
)
13590 && XFASTINT (w
->base_line_pos
) <= startpos
)
13592 line
= XFASTINT (w
->base_line_number
);
13593 linepos
= XFASTINT (w
->base_line_pos
);
13594 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
13599 linepos
= BUF_BEGV (b
);
13600 linepos_byte
= BUF_BEGV_BYTE (b
);
13603 /* Count lines from base line to window start position. */
13604 nlines
= display_count_lines (linepos
, linepos_byte
,
13608 topline
= nlines
+ line
;
13610 /* Determine a new base line, if the old one is too close
13611 or too far away, or if we did not have one.
13612 "Too close" means it's plausible a scroll-down would
13613 go back past it. */
13614 if (startpos
== BUF_BEGV (b
))
13616 w
->base_line_number
= make_number (topline
);
13617 w
->base_line_pos
= make_number (BUF_BEGV (b
));
13619 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
13620 || linepos
== BUF_BEGV (b
))
13622 int limit
= BUF_BEGV (b
);
13623 int limit_byte
= BUF_BEGV_BYTE (b
);
13625 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
13627 if (startpos
- distance
> limit
)
13629 limit
= startpos
- distance
;
13630 limit_byte
= CHAR_TO_BYTE (limit
);
13633 nlines
= display_count_lines (startpos
, startpos_byte
,
13635 - (height
* 2 + 30),
13637 /* If we couldn't find the lines we wanted within
13638 line_number_display_limit_width chars per line,
13639 give up on line numbers for this window. */
13640 if (position
== limit_byte
&& limit
== startpos
- distance
)
13642 w
->base_line_pos
= w
->buffer
;
13643 w
->base_line_number
= Qnil
;
13647 w
->base_line_number
= make_number (topline
- nlines
);
13648 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
13651 /* Now count lines from the start pos to point. */
13652 nlines
= display_count_lines (startpos
, startpos_byte
,
13653 PT_BYTE
, PT
, &junk
);
13655 /* Record that we did display the line number. */
13656 line_number_displayed
= 1;
13658 /* Make the string to show. */
13659 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
13660 return decode_mode_spec_buf
;
13663 char* p
= decode_mode_spec_buf
;
13664 int pad
= field_width
- 2;
13670 return decode_mode_spec_buf
;
13676 obj
= b
->mode_name
;
13680 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
13686 int pos
= marker_position (w
->start
);
13687 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13689 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
13691 if (pos
<= BUF_BEGV (b
))
13696 else if (pos
<= BUF_BEGV (b
))
13700 if (total
> 1000000)
13701 /* Do it differently for a large value, to avoid overflow. */
13702 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13704 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13705 /* We can't normally display a 3-digit number,
13706 so get us a 2-digit number that is close. */
13709 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13710 return decode_mode_spec_buf
;
13714 /* Display percentage of size above the bottom of the screen. */
13717 int toppos
= marker_position (w
->start
);
13718 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
13719 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13721 if (botpos
>= BUF_ZV (b
))
13723 if (toppos
<= BUF_BEGV (b
))
13730 if (total
> 1000000)
13731 /* Do it differently for a large value, to avoid overflow. */
13732 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13734 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13735 /* We can't normally display a 3-digit number,
13736 so get us a 2-digit number that is close. */
13739 if (toppos
<= BUF_BEGV (b
))
13740 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
13742 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13743 return decode_mode_spec_buf
;
13748 /* status of process */
13749 obj
= Fget_buffer_process (w
->buffer
);
13751 return "no process";
13752 #ifdef subprocesses
13753 obj
= Fsymbol_name (Fprocess_status (obj
));
13757 case 't': /* indicate TEXT or BINARY */
13758 #ifdef MODE_LINE_BINARY_TEXT
13759 return MODE_LINE_BINARY_TEXT (b
);
13765 /* coding-system (not including end-of-line format) */
13767 /* coding-system (including end-of-line type) */
13769 int eol_flag
= (c
== 'Z');
13770 char *p
= decode_mode_spec_buf
;
13772 if (! FRAME_WINDOW_P (f
))
13774 /* No need to mention EOL here--the terminal never needs
13775 to do EOL conversion. */
13776 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
13777 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
13779 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
13782 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
13783 #ifdef subprocesses
13784 obj
= Fget_buffer_process (Fcurrent_buffer ());
13785 if (PROCESSP (obj
))
13787 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
13789 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
13792 #endif /* subprocesses */
13795 return decode_mode_spec_buf
;
13800 return (char *) XSTRING (obj
)->data
;
13806 /* Count up to COUNT lines starting from START / START_BYTE.
13807 But don't go beyond LIMIT_BYTE.
13808 Return the number of lines thus found (always nonnegative).
13810 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
13813 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
13814 int start
, start_byte
, limit_byte
, count
;
13817 register unsigned char *cursor
;
13818 unsigned char *base
;
13820 register int ceiling
;
13821 register unsigned char *ceiling_addr
;
13822 int orig_count
= count
;
13824 /* If we are not in selective display mode,
13825 check only for newlines. */
13826 int selective_display
= (!NILP (current_buffer
->selective_display
)
13827 && !INTEGERP (current_buffer
->selective_display
));
13831 while (start_byte
< limit_byte
)
13833 ceiling
= BUFFER_CEILING_OF (start_byte
);
13834 ceiling
= min (limit_byte
- 1, ceiling
);
13835 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
13836 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
13839 if (selective_display
)
13840 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
13843 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
13846 if (cursor
!= ceiling_addr
)
13850 start_byte
+= cursor
- base
+ 1;
13851 *byte_pos_ptr
= start_byte
;
13855 if (++cursor
== ceiling_addr
)
13861 start_byte
+= cursor
- base
;
13866 while (start_byte
> limit_byte
)
13868 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
13869 ceiling
= max (limit_byte
, ceiling
);
13870 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
13871 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
13874 if (selective_display
)
13875 while (--cursor
!= ceiling_addr
13876 && *cursor
!= '\n' && *cursor
!= 015)
13879 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
13882 if (cursor
!= ceiling_addr
)
13886 start_byte
+= cursor
- base
+ 1;
13887 *byte_pos_ptr
= start_byte
;
13888 /* When scanning backwards, we should
13889 not count the newline posterior to which we stop. */
13890 return - orig_count
- 1;
13896 /* Here we add 1 to compensate for the last decrement
13897 of CURSOR, which took it past the valid range. */
13898 start_byte
+= cursor
- base
+ 1;
13902 *byte_pos_ptr
= limit_byte
;
13905 return - orig_count
+ count
;
13906 return orig_count
- count
;
13912 /***********************************************************************
13914 ***********************************************************************/
13916 /* Display a NUL-terminated string, starting with index START.
13918 If STRING is non-null, display that C string. Otherwise, the Lisp
13919 string LISP_STRING is displayed.
13921 If FACE_STRING is not nil, FACE_STRING_POS is a position in
13922 FACE_STRING. Display STRING or LISP_STRING with the face at
13923 FACE_STRING_POS in FACE_STRING:
13925 Display the string in the environment given by IT, but use the
13926 standard display table, temporarily.
13928 FIELD_WIDTH is the minimum number of output glyphs to produce.
13929 If STRING has fewer characters than FIELD_WIDTH, pad to the right
13930 with spaces. If STRING has more characters, more than FIELD_WIDTH
13931 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
13933 PRECISION is the maximum number of characters to output from
13934 STRING. PRECISION < 0 means don't truncate the string.
13936 This is roughly equivalent to printf format specifiers:
13938 FIELD_WIDTH PRECISION PRINTF
13939 ----------------------------------------
13945 MULTIBYTE zero means do not display multibyte chars, > 0 means do
13946 display them, and < 0 means obey the current buffer's value of
13947 enable_multibyte_characters.
13949 Value is the number of glyphs produced. */
13952 display_string (string
, lisp_string
, face_string
, face_string_pos
,
13953 start
, it
, field_width
, precision
, max_x
, multibyte
)
13954 unsigned char *string
;
13955 Lisp_Object lisp_string
;
13956 Lisp_Object face_string
;
13957 int face_string_pos
;
13960 int field_width
, precision
, max_x
;
13963 int hpos_at_start
= it
->hpos
;
13964 int saved_face_id
= it
->face_id
;
13965 struct glyph_row
*row
= it
->glyph_row
;
13967 /* Initialize the iterator IT for iteration over STRING beginning
13968 with index START. */
13969 reseat_to_string (it
, string
, lisp_string
, start
,
13970 precision
, field_width
, multibyte
);
13972 /* If displaying STRING, set up the face of the iterator
13973 from LISP_STRING, if that's given. */
13974 if (STRINGP (face_string
))
13980 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
13981 0, it
->region_beg_charpos
,
13982 it
->region_end_charpos
,
13983 &endptr
, it
->base_face_id
, 0);
13984 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
13985 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
13988 /* Set max_x to the maximum allowed X position. Don't let it go
13989 beyond the right edge of the window. */
13991 max_x
= it
->last_visible_x
;
13993 max_x
= min (max_x
, it
->last_visible_x
);
13995 /* Skip over display elements that are not visible. because IT->w is
13997 if (it
->current_x
< it
->first_visible_x
)
13998 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
13999 MOVE_TO_POS
| MOVE_TO_X
);
14001 row
->ascent
= it
->max_ascent
;
14002 row
->height
= it
->max_ascent
+ it
->max_descent
;
14003 row
->phys_ascent
= it
->max_phys_ascent
;
14004 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14006 /* This condition is for the case that we are called with current_x
14007 past last_visible_x. */
14008 while (it
->current_x
< max_x
)
14010 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14012 /* Get the next display element. */
14013 if (!get_next_display_element (it
))
14016 /* Produce glyphs. */
14017 x_before
= it
->current_x
;
14018 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14019 PRODUCE_GLYPHS (it
);
14021 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14024 while (i
< nglyphs
)
14026 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14028 if (!it
->truncate_lines_p
14029 && x
+ glyph
->pixel_width
> max_x
)
14031 /* End of continued line or max_x reached. */
14032 if (CHAR_GLYPH_PADDING_P (*glyph
))
14034 /* A wide character is unbreakable. */
14035 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14036 it
->current_x
= x_before
;
14040 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14045 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
14047 /* Glyph is at least partially visible. */
14049 if (x
< it
->first_visible_x
)
14050 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14054 /* Glyph is off the left margin of the display area.
14055 Should not happen. */
14059 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14060 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14061 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14062 row
->phys_height
= max (row
->phys_height
,
14063 it
->max_phys_ascent
+ it
->max_phys_descent
);
14064 x
+= glyph
->pixel_width
;
14068 /* Stop if max_x reached. */
14072 /* Stop at line ends. */
14073 if (ITERATOR_AT_END_OF_LINE_P (it
))
14075 it
->continuation_lines_width
= 0;
14079 set_iterator_to_next (it
, 1);
14081 /* Stop if truncating at the right edge. */
14082 if (it
->truncate_lines_p
14083 && it
->current_x
>= it
->last_visible_x
)
14085 /* Add truncation mark, but don't do it if the line is
14086 truncated at a padding space. */
14087 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14089 if (!FRAME_WINDOW_P (it
->f
))
14093 if (it
->current_x
> it
->last_visible_x
)
14095 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14096 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14098 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14100 row
->used
[TEXT_AREA
] = i
;
14101 produce_special_glyphs (it
, IT_TRUNCATION
);
14104 produce_special_glyphs (it
, IT_TRUNCATION
);
14106 it
->glyph_row
->truncated_on_right_p
= 1;
14112 /* Maybe insert a truncation at the left. */
14113 if (it
->first_visible_x
14114 && IT_CHARPOS (*it
) > 0)
14116 if (!FRAME_WINDOW_P (it
->f
))
14117 insert_left_trunc_glyphs (it
);
14118 it
->glyph_row
->truncated_on_left_p
= 1;
14121 it
->face_id
= saved_face_id
;
14123 /* Value is number of columns displayed. */
14124 return it
->hpos
- hpos_at_start
;
14129 /* This is like a combination of memq and assq. Return 1 if PROPVAL
14130 appears as an element of LIST or as the car of an element of LIST.
14131 If PROPVAL is a list, compare each element against LIST in that
14132 way, and return 1 if any element of PROPVAL is found in LIST.
14133 Otherwise return 0. This function cannot quit. */
14136 invisible_p (propval
, list
)
14137 register Lisp_Object propval
;
14140 register Lisp_Object tail
, proptail
;
14142 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14144 register Lisp_Object tem
;
14146 if (EQ (propval
, tem
))
14148 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14152 if (CONSP (propval
))
14154 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14156 Lisp_Object propelt
;
14157 propelt
= XCAR (proptail
);
14158 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14160 register Lisp_Object tem
;
14162 if (EQ (propelt
, tem
))
14164 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14174 /* Return 1 if PROPVAL appears as the car of an element of LIST and
14175 the cdr of that element is non-nil. If PROPVAL is a list, check
14176 each element of PROPVAL in that way, and the first time some
14177 element is found, return 1 if the cdr of that element is non-nil.
14178 Otherwise return 0. This function cannot quit. */
14181 invisible_ellipsis_p (propval
, list
)
14182 register Lisp_Object propval
;
14185 register Lisp_Object tail
, proptail
;
14187 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14189 register Lisp_Object tem
;
14191 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14192 return ! NILP (XCDR (tem
));
14195 if (CONSP (propval
))
14196 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14198 Lisp_Object propelt
;
14199 propelt
= XCAR (proptail
);
14200 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14202 register Lisp_Object tem
;
14204 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14205 return ! NILP (XCDR (tem
));
14214 /***********************************************************************
14216 ***********************************************************************/
14221 Vwith_echo_area_save_vector
= Qnil
;
14222 staticpro (&Vwith_echo_area_save_vector
);
14224 Vmessage_stack
= Qnil
;
14225 staticpro (&Vmessage_stack
);
14227 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14228 staticpro (&Qinhibit_redisplay
);
14231 defsubr (&Sdump_glyph_matrix
);
14232 defsubr (&Sdump_glyph_row
);
14233 defsubr (&Sdump_tool_bar_row
);
14234 defsubr (&Strace_redisplay_toggle
);
14235 defsubr (&Strace_to_stderr
);
14237 #ifdef HAVE_WINDOW_SYSTEM
14238 defsubr (&Stool_bar_lines_needed
);
14241 staticpro (&Qmenu_bar_update_hook
);
14242 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14244 staticpro (&Qoverriding_terminal_local_map
);
14245 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14247 staticpro (&Qoverriding_local_map
);
14248 Qoverriding_local_map
= intern ("overriding-local-map");
14250 staticpro (&Qwindow_scroll_functions
);
14251 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14253 staticpro (&Qredisplay_end_trigger_functions
);
14254 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14256 staticpro (&Qinhibit_point_motion_hooks
);
14257 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14259 QCdata
= intern (":data");
14260 staticpro (&QCdata
);
14261 Qdisplay
= intern ("display");
14262 staticpro (&Qdisplay
);
14263 Qspace_width
= intern ("space-width");
14264 staticpro (&Qspace_width
);
14265 Qraise
= intern ("raise");
14266 staticpro (&Qraise
);
14267 Qspace
= intern ("space");
14268 staticpro (&Qspace
);
14269 Qmargin
= intern ("margin");
14270 staticpro (&Qmargin
);
14271 Qleft_margin
= intern ("left-margin");
14272 staticpro (&Qleft_margin
);
14273 Qright_margin
= intern ("right-margin");
14274 staticpro (&Qright_margin
);
14275 Qalign_to
= intern ("align-to");
14276 staticpro (&Qalign_to
);
14277 QCalign_to
= intern (":align-to");
14278 staticpro (&QCalign_to
);
14279 Qrelative_width
= intern ("relative-width");
14280 staticpro (&Qrelative_width
);
14281 QCrelative_width
= intern (":relative-width");
14282 staticpro (&QCrelative_width
);
14283 QCrelative_height
= intern (":relative-height");
14284 staticpro (&QCrelative_height
);
14285 QCeval
= intern (":eval");
14286 staticpro (&QCeval
);
14287 Qwhen
= intern ("when");
14288 staticpro (&Qwhen
);
14289 QCfile
= intern (":file");
14290 staticpro (&QCfile
);
14291 Qfontified
= intern ("fontified");
14292 staticpro (&Qfontified
);
14293 Qfontification_functions
= intern ("fontification-functions");
14294 staticpro (&Qfontification_functions
);
14295 Qtrailing_whitespace
= intern ("trailing-whitespace");
14296 staticpro (&Qtrailing_whitespace
);
14297 Qimage
= intern ("image");
14298 staticpro (&Qimage
);
14299 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14300 staticpro (&Qmessage_truncate_lines
);
14301 Qgrow_only
= intern ("grow-only");
14302 staticpro (&Qgrow_only
);
14303 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14304 staticpro (&Qinhibit_menubar_update
);
14305 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
14306 staticpro (&Qinhibit_eval_during_redisplay
);
14308 last_arrow_position
= Qnil
;
14309 last_arrow_string
= Qnil
;
14310 staticpro (&last_arrow_position
);
14311 staticpro (&last_arrow_string
);
14313 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14314 staticpro (&echo_buffer
[0]);
14315 staticpro (&echo_buffer
[1]);
14317 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14318 staticpro (&echo_area_buffer
[0]);
14319 staticpro (&echo_area_buffer
[1]);
14321 Vmessages_buffer_name
= build_string ("*Messages*");
14322 staticpro (&Vmessages_buffer_name
);
14324 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14325 "Non-nil means highlight trailing whitespace.\n\
14326 The face used for trailing whitespace is `trailing-whitespace'.");
14327 Vshow_trailing_whitespace
= Qnil
;
14329 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14330 "Non-nil means don't actually do any redisplay.\n\
14331 This is used for internal purposes.");
14332 Vinhibit_redisplay
= Qnil
;
14334 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14335 "String (or mode line construct) included (normally) in `mode-line-format'.");
14336 Vglobal_mode_string
= Qnil
;
14338 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14339 "Marker for where to display an arrow on top of the buffer text.\n\
14340 This must be the beginning of a line in order to work.\n\
14341 See also `overlay-arrow-string'.");
14342 Voverlay_arrow_position
= Qnil
;
14344 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14345 "String to display as an arrow. See also `overlay-arrow-position'.");
14346 Voverlay_arrow_string
= Qnil
;
14348 DEFVAR_INT ("scroll-step", &scroll_step
,
14349 "*The number of lines to try scrolling a window by when point moves out.\n\
14350 If that fails to bring point back on frame, point is centered instead.\n\
14351 If this is zero, point is always centered after it moves off frame.\n\
14352 If you want scrolling to always be a line at a time, you should set\n\
14353 `scroll-conservatively' to a large value rather than set this to 1.");
14355 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14356 "*Scroll up to this many lines, to bring point back on screen.\n\
14357 A value of zero means to scroll the text to center point vertically\n\
14359 scroll_conservatively
= 0;
14361 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14362 "*Number of lines of margin at the top and bottom of a window.\n\
14363 Recenter the window whenever point gets within this many lines\n\
14364 of the top or bottom of the window.");
14368 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
14371 DEFVAR_BOOL ("truncate-partial-width-windows",
14372 &truncate_partial_width_windows
,
14373 "*Non-nil means truncate lines in all windows less than full frame wide.");
14374 truncate_partial_width_windows
= 1;
14376 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14377 "nil means display the mode-line/header-line/menu-bar in the default face.\n\
14378 Any other value means to use the appropriate face, `mode-line',\n\
14379 `header-line', or `menu' respectively.\n\
14381 This variable is deprecated; please change the above faces instead.");
14382 mode_line_inverse_video
= 1;
14384 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14385 "*Maximum buffer size for which line number should be displayed.\n\
14386 If the buffer is bigger than this, the line number does not appear\n\
14387 in the mode line. A value of nil means no limit.");
14388 Vline_number_display_limit
= Qnil
;
14390 DEFVAR_INT ("line-number-display-limit-width",
14391 &line_number_display_limit_width
,
14392 "*Maximum line width (in characters) for line number display.\n\
14393 If the average length of the lines near point is bigger than this, then the\n\
14394 line number may be omitted from the mode line.");
14395 line_number_display_limit_width
= 200;
14397 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14398 "*Non-nil means highlight region even in nonselected windows.");
14399 highlight_nonselected_windows
= 0;
14401 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14402 "Non-nil if more than one frame is visible on this display.\n\
14403 Minibuffer-only frames don't count, but iconified frames do.\n\
14404 This variable is not guaranteed to be accurate except while processing\n\
14405 `frame-title-format' and `icon-title-format'.");
14407 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14408 "Template for displaying the title bar of visible frames.\n\
14409 \(Assuming the window manager supports this feature.)\n\
14410 This variable has the same structure as `mode-line-format' (which see),\n\
14411 and is used only on frames for which no explicit name has been set\n\
14412 \(see `modify-frame-parameters').");
14413 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
14414 "Template for displaying the title bar of an iconified frame.\n\
14415 \(Assuming the window manager supports this feature.)\n\
14416 This variable has the same structure as `mode-line-format' (which see),\n\
14417 and is used only on frames for which no explicit name has been set\n\
14418 \(see `modify-frame-parameters').");
14420 = Vframe_title_format
14421 = Fcons (intern ("multiple-frames"),
14422 Fcons (build_string ("%b"),
14423 Fcons (Fcons (build_string (""),
14424 Fcons (intern ("invocation-name"),
14425 Fcons (build_string ("@"),
14426 Fcons (intern ("system-name"),
14430 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
14431 "Maximum number of lines to keep in the message log buffer.\n\
14432 If nil, disable message logging. If t, log messages but don't truncate\n\
14433 the buffer when it becomes large.");
14434 Vmessage_log_max
= make_number (50);
14436 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
14437 "Functions called before redisplay, if window sizes have changed.\n\
14438 The value should be a list of functions that take one argument.\n\
14439 Just before redisplay, for each frame, if any of its windows have changed\n\
14440 size since the last redisplay, or have been split or deleted,\n\
14441 all the functions in the list are called, with the frame as argument.");
14442 Vwindow_size_change_functions
= Qnil
;
14444 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
14445 "List of Functions to call before redisplaying a window with scrolling.\n\
14446 Each function is called with two arguments, the window\n\
14447 and its new display-start position. Note that the value of `window-end'\n\
14448 is not valid when these functions are called.");
14449 Vwindow_scroll_functions
= Qnil
;
14451 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
14452 "*Non-nil means automatically resize tool-bars.\n\
14453 This increases a tool-bar's height if not all tool-bar items are visible.\n\
14454 It decreases a tool-bar's height when it would display blank lines\n\
14456 auto_resize_tool_bars_p
= 1;
14458 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
14459 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
14460 auto_raise_tool_bar_buttons_p
= 1;
14462 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
14463 "*Margin around tool-bar buttons in pixels.\n\
14464 If an integer, use that for both horizontal and vertical margins.\n\
14465 Otherwise, value should be a pair of integers `(HORZ : VERT)' with\n\
14466 HORZ specifying the horizontal margin, and VERT specifying the\n\
14467 vertical margin.");
14468 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
14470 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
14471 "Relief thickness of tool-bar buttons.");
14472 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
14474 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
14475 "List of functions to call to fontify regions of text.\n\
14476 Each function is called with one argument POS. Functions must\n\
14477 fontify a region starting at POS in the current buffer, and give\n\
14478 fontified regions the property `fontified'.\n\
14479 This variable automatically becomes buffer-local when set.");
14480 Vfontification_functions
= Qnil
;
14481 Fmake_variable_buffer_local (Qfontification_functions
);
14483 DEFVAR_BOOL ("unibyte-display-via-language-environment",
14484 &unibyte_display_via_language_environment
,
14485 "*Non-nil means display unibyte text according to language environment.\n\
14486 Specifically this means that unibyte non-ASCII characters\n\
14487 are displayed by converting them to the equivalent multibyte characters\n\
14488 according to the current language environment. As a result, they are\n\
14489 displayed according to the current fontset.");
14490 unibyte_display_via_language_environment
= 0;
14492 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
14493 "*Maximum height for resizing mini-windows.\n\
14494 If a float, it specifies a fraction of the mini-window frame's height.\n\
14495 If an integer, it specifies a number of lines.");
14496 Vmax_mini_window_height
= make_float (0.25);
14498 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
14499 "*How to resize mini-windows.\n\
14500 A value of nil means don't automatically resize mini-windows.\n\
14501 A value of t means resize them to fit the text displayed in them.\n\
14502 A value of `grow-only', the default, means let mini-windows grow\n\
14503 only, until their display becomes empty, at which point the windows\n\
14504 go back to their normal size.");
14505 Vresize_mini_windows
= Qgrow_only
;
14507 DEFVAR_BOOL ("cursor-in-non-selected-windows",
14508 &cursor_in_non_selected_windows
,
14509 "*Non-nil means display a hollow cursor in non-selected windows.\n\
14510 Nil means don't display a cursor there.");
14511 cursor_in_non_selected_windows
= 1;
14513 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
14514 "*Non-nil means scroll the display automatically to make point visible.");
14515 automatic_hscrolling_p
= 1;
14517 DEFVAR_LISP ("image-types", &Vimage_types
,
14518 "List of supported image types.\n\
14519 Each element of the list is a symbol for a supported image type.");
14520 Vimage_types
= Qnil
;
14522 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
14523 "If non-nil, messages are truncated instead of resizing the echo area.\n\
14524 Bind this around calls to `message' to let it take effect.");
14525 message_truncate_lines
= 0;
14527 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
14528 "Normal hook run for clicks on menu bar, before displaying a submenu.\n\
14529 Can be used to update submenus whose contents should vary.");
14530 Vmenu_bar_update_hook
= Qnil
;
14532 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
14533 "Non-nil means don't update menu bars. Internal use only.");
14534 inhibit_menubar_update
= 0;
14536 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
14537 "Non-nil means don't eval Lisp during redisplay.");
14538 inhibit_eval_during_redisplay
= 0;
14542 /* Initialize this module when Emacs starts. */
14547 Lisp_Object root_window
;
14548 struct window
*mini_w
;
14550 current_header_line_height
= current_mode_line_height
= -1;
14552 CHARPOS (this_line_start_pos
) = 0;
14554 mini_w
= XWINDOW (minibuf_window
);
14555 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
14557 if (!noninteractive
)
14559 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
14562 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
14563 set_window_height (root_window
,
14564 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
14566 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
14567 set_window_height (minibuf_window
, 1, 0);
14569 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
14570 mini_w
->width
= make_number (FRAME_WIDTH (f
));
14572 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
14573 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
14574 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
14576 /* The default ellipsis glyphs `...'. */
14577 for (i
= 0; i
< 3; ++i
)
14578 default_invis_vector
[i
] = make_number ('.');
14581 #ifdef HAVE_WINDOW_SYSTEM
14583 /* Allocate the buffer for frame titles. */
14585 frame_title_buf
= (char *) xmalloc (size
);
14586 frame_title_buf_end
= frame_title_buf
+ size
;
14587 frame_title_ptr
= NULL
;
14589 #endif /* HAVE_WINDOW_SYSTEM */
14591 help_echo_showing_p
= 0;