1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking a iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
184 #include "termhooks.h"
185 #include "intervals.h"
188 #include "region-cache.h"
191 #ifdef HAVE_X_WINDOWS
201 #define INFINITY 10000000
203 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
204 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
205 extern int pending_menu_activation
;
208 extern int interrupt_input
;
209 extern int command_loop_level
;
211 extern int minibuffer_auto_raise
;
213 extern Lisp_Object Qface
;
214 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
216 extern Lisp_Object Voverriding_local_map
;
217 extern Lisp_Object Voverriding_local_map_menu_flag
;
218 extern Lisp_Object Qmenu_item
;
220 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
221 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
222 Lisp_Object Qredisplay_end_trigger_functions
;
223 Lisp_Object Qinhibit_point_motion_hooks
;
224 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
, QCpropertize
;
225 Lisp_Object Qfontified
;
226 Lisp_Object Qgrow_only
;
227 Lisp_Object Qinhibit_eval_during_redisplay
;
228 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
231 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
233 Lisp_Object Qrisky_local_variable
;
235 /* Holds the list (error). */
236 Lisp_Object list_of_error
;
238 /* Functions called to fontify regions of text. */
240 Lisp_Object Vfontification_functions
;
241 Lisp_Object Qfontification_functions
;
243 /* Non-zero means draw tool bar buttons raised when the mouse moves
246 int auto_raise_tool_bar_buttons_p
;
248 /* Margin around tool bar buttons in pixels. */
250 Lisp_Object Vtool_bar_button_margin
;
252 /* Thickness of shadow to draw around tool bar buttons. */
254 EMACS_INT tool_bar_button_relief
;
256 /* Non-zero means automatically resize tool-bars so that all tool-bar
257 items are visible, and no blank lines remain. */
259 int auto_resize_tool_bars_p
;
261 /* Non-nil means don't actually do any redisplay. */
263 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
265 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
267 int inhibit_eval_during_redisplay
;
269 /* Names of text properties relevant for redisplay. */
271 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
272 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
274 /* Symbols used in text property values. */
276 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
277 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
279 extern Lisp_Object Qheight
;
281 /* Non-nil means highlight trailing whitespace. */
283 Lisp_Object Vshow_trailing_whitespace
;
285 /* Name of the face used to highlight trailing whitespace. */
287 Lisp_Object Qtrailing_whitespace
;
289 /* The symbol `image' which is the car of the lists used to represent
294 /* Non-zero means print newline to stdout before next mini-buffer
297 int noninteractive_need_newline
;
299 /* Non-zero means print newline to message log before next message. */
301 static int message_log_need_newline
;
303 /* Three markers that message_dolog uses.
304 It could allocate them itself, but that causes trouble
305 in handling memory-full errors. */
306 static Lisp_Object message_dolog_marker1
;
307 static Lisp_Object message_dolog_marker2
;
308 static Lisp_Object message_dolog_marker3
;
310 /* The buffer position of the first character appearing entirely or
311 partially on the line of the selected window which contains the
312 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
313 redisplay optimization in redisplay_internal. */
315 static struct text_pos this_line_start_pos
;
317 /* Number of characters past the end of the line above, including the
318 terminating newline. */
320 static struct text_pos this_line_end_pos
;
322 /* The vertical positions and the height of this line. */
324 static int this_line_vpos
;
325 static int this_line_y
;
326 static int this_line_pixel_height
;
328 /* X position at which this display line starts. Usually zero;
329 negative if first character is partially visible. */
331 static int this_line_start_x
;
333 /* Buffer that this_line_.* variables are referring to. */
335 static struct buffer
*this_line_buffer
;
337 /* Nonzero means truncate lines in all windows less wide than the
340 int truncate_partial_width_windows
;
342 /* A flag to control how to display unibyte 8-bit character. */
344 int unibyte_display_via_language_environment
;
346 /* Nonzero means we have more than one non-mini-buffer-only frame.
347 Not guaranteed to be accurate except while parsing
348 frame-title-format. */
352 Lisp_Object Vglobal_mode_string
;
354 /* Marker for where to display an arrow on top of the buffer text. */
356 Lisp_Object Voverlay_arrow_position
;
358 /* String to display for the arrow. Only used on terminal frames. */
360 Lisp_Object Voverlay_arrow_string
;
362 /* Values of those variables at last redisplay. However, if
363 Voverlay_arrow_position is a marker, last_arrow_position is its
364 numerical position. */
366 static Lisp_Object last_arrow_position
, last_arrow_string
;
368 /* Like mode-line-format, but for the title bar on a visible frame. */
370 Lisp_Object Vframe_title_format
;
372 /* Like mode-line-format, but for the title bar on an iconified frame. */
374 Lisp_Object Vicon_title_format
;
376 /* List of functions to call when a window's size changes. These
377 functions get one arg, a frame on which one or more windows' sizes
380 static Lisp_Object Vwindow_size_change_functions
;
382 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
384 /* Nonzero if overlay arrow has been displayed once in this window. */
386 static int overlay_arrow_seen
;
388 /* Nonzero means highlight the region even in nonselected windows. */
390 int highlight_nonselected_windows
;
392 /* If cursor motion alone moves point off frame, try scrolling this
393 many lines up or down if that will bring it back. */
395 static EMACS_INT scroll_step
;
397 /* Nonzero means scroll just far enough to bring point back on the
398 screen, when appropriate. */
400 static EMACS_INT scroll_conservatively
;
402 /* Recenter the window whenever point gets within this many lines of
403 the top or bottom of the window. This value is translated into a
404 pixel value by multiplying it with CANON_Y_UNIT, which means that
405 there is really a fixed pixel height scroll margin. */
407 EMACS_INT scroll_margin
;
409 /* Number of windows showing the buffer of the selected window (or
410 another buffer with the same base buffer). keyboard.c refers to
415 /* Vector containing glyphs for an ellipsis `...'. */
417 static Lisp_Object default_invis_vector
[3];
419 /* Zero means display the mode-line/header-line/menu-bar in the default face
420 (this slightly odd definition is for compatibility with previous versions
421 of emacs), non-zero means display them using their respective faces.
423 This variable is deprecated. */
425 int mode_line_inverse_video
;
427 /* Prompt to display in front of the mini-buffer contents. */
429 Lisp_Object minibuf_prompt
;
431 /* Width of current mini-buffer prompt. Only set after display_line
432 of the line that contains the prompt. */
434 int minibuf_prompt_width
;
436 /* This is the window where the echo area message was displayed. It
437 is always a mini-buffer window, but it may not be the same window
438 currently active as a mini-buffer. */
440 Lisp_Object echo_area_window
;
442 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
443 pushes the current message and the value of
444 message_enable_multibyte on the stack, the function restore_message
445 pops the stack and displays MESSAGE again. */
447 Lisp_Object Vmessage_stack
;
449 /* Nonzero means multibyte characters were enabled when the echo area
450 message was specified. */
452 int message_enable_multibyte
;
454 /* Nonzero if we should redraw the mode lines on the next redisplay. */
456 int update_mode_lines
;
458 /* Nonzero if window sizes or contents have changed since last
459 redisplay that finished. */
461 int windows_or_buffers_changed
;
463 /* Nonzero means a frame's cursor type has been changed. */
465 int cursor_type_changed
;
467 /* Nonzero after display_mode_line if %l was used and it displayed a
470 int line_number_displayed
;
472 /* Maximum buffer size for which to display line numbers. */
474 Lisp_Object Vline_number_display_limit
;
476 /* Line width to consider when repositioning for line number display. */
478 static EMACS_INT line_number_display_limit_width
;
480 /* Number of lines to keep in the message log buffer. t means
481 infinite. nil means don't log at all. */
483 Lisp_Object Vmessage_log_max
;
485 /* The name of the *Messages* buffer, a string. */
487 static Lisp_Object Vmessages_buffer_name
;
489 /* Current, index 0, and last displayed echo area message. Either
490 buffers from echo_buffers, or nil to indicate no message. */
492 Lisp_Object echo_area_buffer
[2];
494 /* The buffers referenced from echo_area_buffer. */
496 static Lisp_Object echo_buffer
[2];
498 /* A vector saved used in with_area_buffer to reduce consing. */
500 static Lisp_Object Vwith_echo_area_save_vector
;
502 /* Non-zero means display_echo_area should display the last echo area
503 message again. Set by redisplay_preserve_echo_area. */
505 static int display_last_displayed_message_p
;
507 /* Nonzero if echo area is being used by print; zero if being used by
510 int message_buf_print
;
512 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
514 Lisp_Object Qinhibit_menubar_update
;
515 int inhibit_menubar_update
;
517 /* Maximum height for resizing mini-windows. Either a float
518 specifying a fraction of the available height, or an integer
519 specifying a number of lines. */
521 Lisp_Object Vmax_mini_window_height
;
523 /* Non-zero means messages should be displayed with truncated
524 lines instead of being continued. */
526 int message_truncate_lines
;
527 Lisp_Object Qmessage_truncate_lines
;
529 /* Set to 1 in clear_message to make redisplay_internal aware
530 of an emptied echo area. */
532 static int message_cleared_p
;
534 /* Non-zero means we want a hollow cursor in windows that are not
535 selected. Zero means there's no cursor in such windows. */
537 Lisp_Object Vcursor_in_non_selected_windows
;
538 Lisp_Object Qcursor_in_non_selected_windows
;
540 /* How to blink the default frame cursor off. */
541 Lisp_Object Vblink_cursor_alist
;
543 /* A scratch glyph row with contents used for generating truncation
544 glyphs. Also used in direct_output_for_insert. */
546 #define MAX_SCRATCH_GLYPHS 100
547 struct glyph_row scratch_glyph_row
;
548 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
550 /* Ascent and height of the last line processed by move_it_to. */
552 static int last_max_ascent
, last_height
;
554 /* Non-zero if there's a help-echo in the echo area. */
556 int help_echo_showing_p
;
558 /* If >= 0, computed, exact values of mode-line and header-line height
559 to use in the macros CURRENT_MODE_LINE_HEIGHT and
560 CURRENT_HEADER_LINE_HEIGHT. */
562 int current_mode_line_height
, current_header_line_height
;
564 /* The maximum distance to look ahead for text properties. Values
565 that are too small let us call compute_char_face and similar
566 functions too often which is expensive. Values that are too large
567 let us call compute_char_face and alike too often because we
568 might not be interested in text properties that far away. */
570 #define TEXT_PROP_DISTANCE_LIMIT 100
574 /* Variables to turn off display optimizations from Lisp. */
576 int inhibit_try_window_id
, inhibit_try_window_reusing
;
577 int inhibit_try_cursor_movement
;
579 /* Non-zero means print traces of redisplay if compiled with
582 int trace_redisplay_p
;
584 #endif /* GLYPH_DEBUG */
586 #ifdef DEBUG_TRACE_MOVE
587 /* Non-zero means trace with TRACE_MOVE to stderr. */
590 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
592 #define TRACE_MOVE(x) (void) 0
595 /* Non-zero means automatically scroll windows horizontally to make
598 int automatic_hscrolling_p
;
600 /* How close to the margin can point get before the window is scrolled
602 EMACS_INT hscroll_margin
;
604 /* How much to scroll horizontally when point is inside the above margin. */
605 Lisp_Object Vhscroll_step
;
607 /* A list of symbols, one for each supported image type. */
609 Lisp_Object Vimage_types
;
611 /* The variable `resize-mini-windows'. If nil, don't resize
612 mini-windows. If t, always resize them to fit the text they
613 display. If `grow-only', let mini-windows grow only until they
616 Lisp_Object Vresize_mini_windows
;
618 /* Buffer being redisplayed -- for redisplay_window_error. */
620 struct buffer
*displayed_buffer
;
622 /* Value returned from text property handlers (see below). */
627 HANDLED_RECOMPUTE_PROPS
,
628 HANDLED_OVERLAY_STRING_CONSUMED
,
632 /* A description of text properties that redisplay is interested
637 /* The name of the property. */
640 /* A unique index for the property. */
643 /* A handler function called to set up iterator IT from the property
644 at IT's current position. Value is used to steer handle_stop. */
645 enum prop_handled (*handler
) P_ ((struct it
*it
));
648 static enum prop_handled handle_face_prop
P_ ((struct it
*));
649 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
650 static enum prop_handled handle_display_prop
P_ ((struct it
*));
651 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
652 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
653 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
655 /* Properties handled by iterators. */
657 static struct props it_props
[] =
659 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
660 /* Handle `face' before `display' because some sub-properties of
661 `display' need to know the face. */
662 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
663 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
664 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
665 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
669 /* Value is the position described by X. If X is a marker, value is
670 the marker_position of X. Otherwise, value is X. */
672 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
674 /* Enumeration returned by some move_it_.* functions internally. */
678 /* Not used. Undefined value. */
681 /* Move ended at the requested buffer position or ZV. */
682 MOVE_POS_MATCH_OR_ZV
,
684 /* Move ended at the requested X pixel position. */
687 /* Move within a line ended at the end of a line that must be
691 /* Move within a line ended at the end of a line that would
692 be displayed truncated. */
695 /* Move within a line ended at a line end. */
699 /* This counter is used to clear the face cache every once in a while
700 in redisplay_internal. It is incremented for each redisplay.
701 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
704 #define CLEAR_FACE_CACHE_COUNT 500
705 static int clear_face_cache_count
;
707 /* Record the previous terminal frame we displayed. */
709 static struct frame
*previous_terminal_frame
;
711 /* Non-zero while redisplay_internal is in progress. */
715 /* Non-zero means don't free realized faces. Bound while freeing
716 realized faces is dangerous because glyph matrices might still
719 int inhibit_free_realized_faces
;
720 Lisp_Object Qinhibit_free_realized_faces
;
723 /* Function prototypes. */
725 static void setup_for_ellipsis
P_ ((struct it
*));
726 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
727 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
728 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
729 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
730 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
731 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
734 static int invisible_text_between_p
P_ ((struct it
*, int, int));
737 static int next_element_from_ellipsis
P_ ((struct it
*));
738 static void pint2str
P_ ((char *, int, int));
739 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
741 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
742 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
743 static void store_frame_title_char
P_ ((char));
744 static int store_frame_title
P_ ((const unsigned char *, int, int));
745 static void x_consider_frame_title
P_ ((Lisp_Object
));
746 static void handle_stop
P_ ((struct it
*));
747 static int tool_bar_lines_needed
P_ ((struct frame
*));
748 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
749 static void ensure_echo_area_buffers
P_ ((void));
750 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
751 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
752 static int with_echo_area_buffer
P_ ((struct window
*, int,
753 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
754 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
755 static void clear_garbaged_frames
P_ ((void));
756 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
757 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
758 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
759 static int display_echo_area
P_ ((struct window
*));
760 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
761 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
762 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
763 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
764 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
766 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
767 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
768 static void insert_left_trunc_glyphs
P_ ((struct it
*));
769 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
770 static void extend_face_to_end_of_line
P_ ((struct it
*));
771 static int append_space
P_ ((struct it
*, int));
772 static int make_cursor_line_fully_visible
P_ ((struct window
*));
773 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int));
774 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
775 static int trailing_whitespace_p
P_ ((int));
776 static int message_log_check_duplicate
P_ ((int, int, int, int));
777 static void push_it
P_ ((struct it
*));
778 static void pop_it
P_ ((struct it
*));
779 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
780 static void redisplay_internal
P_ ((int));
781 static int echo_area_display
P_ ((int));
782 static void redisplay_windows
P_ ((Lisp_Object
));
783 static void redisplay_window
P_ ((Lisp_Object
, int));
784 static Lisp_Object
redisplay_window_error ();
785 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
786 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
787 static void update_menu_bar
P_ ((struct frame
*, int));
788 static int try_window_reusing_current_matrix
P_ ((struct window
*));
789 static int try_window_id
P_ ((struct window
*));
790 static int display_line
P_ ((struct it
*));
791 static int display_mode_lines
P_ ((struct window
*));
792 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
793 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
794 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
795 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
796 static void display_menu_bar
P_ ((struct window
*));
797 static int display_count_lines
P_ ((int, int, int, int, int *));
798 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
799 int, int, struct it
*, int, int, int, int));
800 static void compute_line_metrics
P_ ((struct it
*));
801 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
802 static int get_overlay_strings
P_ ((struct it
*, int));
803 static void next_overlay_string
P_ ((struct it
*));
804 static void reseat
P_ ((struct it
*, struct text_pos
, int));
805 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
806 static void back_to_previous_visible_line_start
P_ ((struct it
*));
807 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
808 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
809 static int next_element_from_display_vector
P_ ((struct it
*));
810 static int next_element_from_string
P_ ((struct it
*));
811 static int next_element_from_c_string
P_ ((struct it
*));
812 static int next_element_from_buffer
P_ ((struct it
*));
813 static int next_element_from_composition
P_ ((struct it
*));
814 static int next_element_from_image
P_ ((struct it
*));
815 static int next_element_from_stretch
P_ ((struct it
*));
816 static void load_overlay_strings
P_ ((struct it
*, int));
817 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
818 struct display_pos
*));
819 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
820 Lisp_Object
, int, int, int, int));
821 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
823 void move_it_vertically_backward
P_ ((struct it
*, int));
824 static void init_to_row_start
P_ ((struct it
*, struct window
*,
825 struct glyph_row
*));
826 static int init_to_row_end
P_ ((struct it
*, struct window
*,
827 struct glyph_row
*));
828 static void back_to_previous_line_start
P_ ((struct it
*));
829 static int forward_to_next_line_start
P_ ((struct it
*, int *));
830 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
832 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
833 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
834 static int number_of_chars
P_ ((unsigned char *, int));
835 static void compute_stop_pos
P_ ((struct it
*));
836 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
838 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
839 static int next_overlay_change
P_ ((int));
840 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
841 Lisp_Object
, struct text_pos
*,
843 static int underlying_face_id
P_ ((struct it
*));
844 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
847 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
848 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
850 #ifdef HAVE_WINDOW_SYSTEM
852 static void update_tool_bar
P_ ((struct frame
*, int));
853 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
854 static int redisplay_tool_bar
P_ ((struct frame
*));
855 static void display_tool_bar_line
P_ ((struct it
*));
857 #endif /* HAVE_WINDOW_SYSTEM */
860 /***********************************************************************
861 Window display dimensions
862 ***********************************************************************/
864 /* Return the window-relative maximum y + 1 for glyph rows displaying
865 text in window W. This is the height of W minus the height of a
866 mode line, if any. */
869 window_text_bottom_y (w
)
872 struct frame
*f
= XFRAME (w
->frame
);
873 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
875 if (WINDOW_WANTS_MODELINE_P (w
))
876 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
881 /* Return the pixel width of display area AREA of window W. AREA < 0
882 means return the total width of W, not including fringes to
883 the left and right of the window. */
886 window_box_width (w
, area
)
890 struct frame
*f
= XFRAME (w
->frame
);
891 int width
= XFASTINT (w
->width
);
893 if (!w
->pseudo_window_p
)
895 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FRINGE_COLS (f
);
897 if (area
== TEXT_AREA
)
899 if (INTEGERP (w
->left_margin_width
))
900 width
-= XFASTINT (w
->left_margin_width
);
901 if (INTEGERP (w
->right_margin_width
))
902 width
-= XFASTINT (w
->right_margin_width
);
904 else if (area
== LEFT_MARGIN_AREA
)
905 width
= (INTEGERP (w
->left_margin_width
)
906 ? XFASTINT (w
->left_margin_width
) : 0);
907 else if (area
== RIGHT_MARGIN_AREA
)
908 width
= (INTEGERP (w
->right_margin_width
)
909 ? XFASTINT (w
->right_margin_width
) : 0);
912 return width
* CANON_X_UNIT (f
);
916 /* Return the pixel height of the display area of window W, not
917 including mode lines of W, if any. */
920 window_box_height (w
)
923 struct frame
*f
= XFRAME (w
->frame
);
924 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
926 xassert (height
>= 0);
928 /* Note: the code below that determines the mode-line/header-line
929 height is essentially the same as that contained in the macro
930 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
931 the appropriate glyph row has its `mode_line_p' flag set,
932 and if it doesn't, uses estimate_mode_line_height instead. */
934 if (WINDOW_WANTS_MODELINE_P (w
))
936 struct glyph_row
*ml_row
937 = (w
->current_matrix
&& w
->current_matrix
->rows
938 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
940 if (ml_row
&& ml_row
->mode_line_p
)
941 height
-= ml_row
->height
;
943 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
946 if (WINDOW_WANTS_HEADER_LINE_P (w
))
948 struct glyph_row
*hl_row
949 = (w
->current_matrix
&& w
->current_matrix
->rows
950 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
952 if (hl_row
&& hl_row
->mode_line_p
)
953 height
-= hl_row
->height
;
955 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
958 /* With a very small font and a mode-line that's taller than
959 default, we might end up with a negative height. */
960 return max (0, height
);
964 /* Return the frame-relative coordinate of the left edge of display
965 area AREA of window W. AREA < 0 means return the left edge of the
966 whole window, to the right of the left fringe of W. */
969 window_box_left (w
, area
)
973 struct frame
*f
= XFRAME (w
->frame
);
974 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
976 if (!w
->pseudo_window_p
)
978 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
979 + FRAME_LEFT_FRINGE_WIDTH (f
));
981 if (area
== TEXT_AREA
)
982 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
983 else if (area
== RIGHT_MARGIN_AREA
)
984 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
985 + window_box_width (w
, TEXT_AREA
));
992 /* Return the frame-relative coordinate of the right edge of display
993 area AREA of window W. AREA < 0 means return the left edge of the
994 whole window, to the left of the right fringe of W. */
997 window_box_right (w
, area
)
1001 return window_box_left (w
, area
) + window_box_width (w
, area
);
1005 /* Get the bounding box of the display area AREA of window W, without
1006 mode lines, in frame-relative coordinates. AREA < 0 means the
1007 whole window, not including the left and right fringes of
1008 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1009 coordinates of the upper-left corner of the box. Return in
1010 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1013 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1016 int *box_x
, *box_y
, *box_width
, *box_height
;
1018 struct frame
*f
= XFRAME (w
->frame
);
1020 *box_width
= window_box_width (w
, area
);
1021 *box_height
= window_box_height (w
);
1022 *box_x
= window_box_left (w
, area
);
1023 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
1024 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
1025 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1026 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1030 /* Get the bounding box of the display area AREA of window W, without
1031 mode lines. AREA < 0 means the whole window, not including the
1032 left and right fringe of the window. Return in *TOP_LEFT_X
1033 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1034 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1035 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1039 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1040 bottom_right_x
, bottom_right_y
)
1043 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1045 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1047 *bottom_right_x
+= *top_left_x
;
1048 *bottom_right_y
+= *top_left_y
;
1053 /***********************************************************************
1055 ***********************************************************************/
1057 /* Return the bottom y-position of the line the iterator IT is in.
1058 This can modify IT's settings. */
1064 int line_height
= it
->max_ascent
+ it
->max_descent
;
1065 int line_top_y
= it
->current_y
;
1067 if (line_height
== 0)
1070 line_height
= last_height
;
1071 else if (IT_CHARPOS (*it
) < ZV
)
1073 move_it_by_lines (it
, 1, 1);
1074 line_height
= (it
->max_ascent
|| it
->max_descent
1075 ? it
->max_ascent
+ it
->max_descent
1080 struct glyph_row
*row
= it
->glyph_row
;
1082 /* Use the default character height. */
1083 it
->glyph_row
= NULL
;
1084 it
->what
= IT_CHARACTER
;
1087 PRODUCE_GLYPHS (it
);
1088 line_height
= it
->ascent
+ it
->descent
;
1089 it
->glyph_row
= row
;
1093 return line_top_y
+ line_height
;
1097 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1098 1 if POS is visible and the line containing POS is fully visible.
1099 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1100 and header-lines heights. */
1103 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1105 int charpos
, *fully
, exact_mode_line_heights_p
;
1108 struct text_pos top
;
1110 struct buffer
*old_buffer
= NULL
;
1112 if (XBUFFER (w
->buffer
) != current_buffer
)
1114 old_buffer
= current_buffer
;
1115 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1118 *fully
= visible_p
= 0;
1119 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1121 /* Compute exact mode line heights, if requested. */
1122 if (exact_mode_line_heights_p
)
1124 if (WINDOW_WANTS_MODELINE_P (w
))
1125 current_mode_line_height
1126 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1127 current_buffer
->mode_line_format
);
1129 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1130 current_header_line_height
1131 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1132 current_buffer
->header_line_format
);
1135 start_display (&it
, w
, top
);
1136 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1137 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1139 /* Note that we may overshoot because of invisible text. */
1140 if (IT_CHARPOS (it
) >= charpos
)
1142 int top_y
= it
.current_y
;
1143 int bottom_y
= line_bottom_y (&it
);
1144 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1146 if (top_y
< window_top_y
)
1147 visible_p
= bottom_y
> window_top_y
;
1148 else if (top_y
< it
.last_visible_y
)
1151 *fully
= bottom_y
<= it
.last_visible_y
;
1154 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1156 move_it_by_lines (&it
, 1, 0);
1157 if (charpos
< IT_CHARPOS (it
))
1165 set_buffer_internal_1 (old_buffer
);
1167 current_header_line_height
= current_mode_line_height
= -1;
1172 /* Return the next character from STR which is MAXLEN bytes long.
1173 Return in *LEN the length of the character. This is like
1174 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1175 we find one, we return a `?', but with the length of the invalid
1179 string_char_and_length (str
, maxlen
, len
)
1180 const unsigned char *str
;
1185 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1186 if (!CHAR_VALID_P (c
, 1))
1187 /* We may not change the length here because other places in Emacs
1188 don't use this function, i.e. they silently accept invalid
1197 /* Given a position POS containing a valid character and byte position
1198 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1200 static struct text_pos
1201 string_pos_nchars_ahead (pos
, string
, nchars
)
1202 struct text_pos pos
;
1206 xassert (STRINGP (string
) && nchars
>= 0);
1208 if (STRING_MULTIBYTE (string
))
1210 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1211 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1216 string_char_and_length (p
, rest
, &len
);
1217 p
+= len
, rest
-= len
;
1218 xassert (rest
>= 0);
1220 BYTEPOS (pos
) += len
;
1224 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1230 /* Value is the text position, i.e. character and byte position,
1231 for character position CHARPOS in STRING. */
1233 static INLINE
struct text_pos
1234 string_pos (charpos
, string
)
1238 struct text_pos pos
;
1239 xassert (STRINGP (string
));
1240 xassert (charpos
>= 0);
1241 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1246 /* Value is a text position, i.e. character and byte position, for
1247 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1248 means recognize multibyte characters. */
1250 static struct text_pos
1251 c_string_pos (charpos
, s
, multibyte_p
)
1256 struct text_pos pos
;
1258 xassert (s
!= NULL
);
1259 xassert (charpos
>= 0);
1263 int rest
= strlen (s
), len
;
1265 SET_TEXT_POS (pos
, 0, 0);
1268 string_char_and_length (s
, rest
, &len
);
1269 s
+= len
, rest
-= len
;
1270 xassert (rest
>= 0);
1272 BYTEPOS (pos
) += len
;
1276 SET_TEXT_POS (pos
, charpos
, charpos
);
1282 /* Value is the number of characters in C string S. MULTIBYTE_P
1283 non-zero means recognize multibyte characters. */
1286 number_of_chars (s
, multibyte_p
)
1294 int rest
= strlen (s
), len
;
1295 unsigned char *p
= (unsigned char *) s
;
1297 for (nchars
= 0; rest
> 0; ++nchars
)
1299 string_char_and_length (p
, rest
, &len
);
1300 rest
-= len
, p
+= len
;
1304 nchars
= strlen (s
);
1310 /* Compute byte position NEWPOS->bytepos corresponding to
1311 NEWPOS->charpos. POS is a known position in string STRING.
1312 NEWPOS->charpos must be >= POS.charpos. */
1315 compute_string_pos (newpos
, pos
, string
)
1316 struct text_pos
*newpos
, pos
;
1319 xassert (STRINGP (string
));
1320 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1322 if (STRING_MULTIBYTE (string
))
1323 *newpos
= string_pos_nchars_ahead (pos
, string
,
1324 CHARPOS (*newpos
) - CHARPOS (pos
));
1326 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1331 /***********************************************************************
1332 Lisp form evaluation
1333 ***********************************************************************/
1335 /* Error handler for safe_eval and safe_call. */
1338 safe_eval_handler (arg
)
1341 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1346 /* Evaluate SEXPR and return the result, or nil if something went
1347 wrong. Prevent redisplay during the evaluation. */
1355 if (inhibit_eval_during_redisplay
)
1359 int count
= SPECPDL_INDEX ();
1360 struct gcpro gcpro1
;
1363 specbind (Qinhibit_redisplay
, Qt
);
1364 /* Use Qt to ensure debugger does not run,
1365 so there is no possibility of wanting to redisplay. */
1366 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1369 val
= unbind_to (count
, val
);
1376 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1377 Return the result, or nil if something went wrong. Prevent
1378 redisplay during the evaluation. */
1381 safe_call (nargs
, args
)
1387 if (inhibit_eval_during_redisplay
)
1391 int count
= SPECPDL_INDEX ();
1392 struct gcpro gcpro1
;
1395 gcpro1
.nvars
= nargs
;
1396 specbind (Qinhibit_redisplay
, Qt
);
1397 /* Use Qt to ensure debugger does not run,
1398 so there is no possibility of wanting to redisplay. */
1399 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1402 val
= unbind_to (count
, val
);
1409 /* Call function FN with one argument ARG.
1410 Return the result, or nil if something went wrong. */
1413 safe_call1 (fn
, arg
)
1414 Lisp_Object fn
, arg
;
1416 Lisp_Object args
[2];
1419 return safe_call (2, args
);
1424 /***********************************************************************
1426 ***********************************************************************/
1430 /* Define CHECK_IT to perform sanity checks on iterators.
1431 This is for debugging. It is too slow to do unconditionally. */
1437 if (it
->method
== next_element_from_string
)
1439 xassert (STRINGP (it
->string
));
1440 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1442 else if (it
->method
== next_element_from_buffer
)
1444 /* Check that character and byte positions agree. */
1445 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1449 xassert (it
->current
.dpvec_index
>= 0);
1451 xassert (it
->current
.dpvec_index
< 0);
1454 #define CHECK_IT(IT) check_it ((IT))
1458 #define CHECK_IT(IT) (void) 0
1465 /* Check that the window end of window W is what we expect it
1466 to be---the last row in the current matrix displaying text. */
1469 check_window_end (w
)
1472 if (!MINI_WINDOW_P (w
)
1473 && !NILP (w
->window_end_valid
))
1475 struct glyph_row
*row
;
1476 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1477 XFASTINT (w
->window_end_vpos
)),
1479 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1480 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1484 #define CHECK_WINDOW_END(W) check_window_end ((W))
1486 #else /* not GLYPH_DEBUG */
1488 #define CHECK_WINDOW_END(W) (void) 0
1490 #endif /* not GLYPH_DEBUG */
1494 /***********************************************************************
1495 Iterator initialization
1496 ***********************************************************************/
1498 /* Initialize IT for displaying current_buffer in window W, starting
1499 at character position CHARPOS. CHARPOS < 0 means that no buffer
1500 position is specified which is useful when the iterator is assigned
1501 a position later. BYTEPOS is the byte position corresponding to
1502 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1504 If ROW is not null, calls to produce_glyphs with IT as parameter
1505 will produce glyphs in that row.
1507 BASE_FACE_ID is the id of a base face to use. It must be one of
1508 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1509 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1510 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1512 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1513 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1514 will be initialized to use the corresponding mode line glyph row of
1515 the desired matrix of W. */
1518 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1521 int charpos
, bytepos
;
1522 struct glyph_row
*row
;
1523 enum face_id base_face_id
;
1525 int highlight_region_p
;
1527 /* Some precondition checks. */
1528 xassert (w
!= NULL
&& it
!= NULL
);
1529 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1532 /* If face attributes have been changed since the last redisplay,
1533 free realized faces now because they depend on face definitions
1534 that might have changed. Don't free faces while there might be
1535 desired matrices pending which reference these faces. */
1536 if (face_change_count
&& !inhibit_free_realized_faces
)
1538 face_change_count
= 0;
1539 free_all_realized_faces (Qnil
);
1542 /* Use one of the mode line rows of W's desired matrix if
1546 if (base_face_id
== MODE_LINE_FACE_ID
1547 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
1548 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1549 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1550 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1554 bzero (it
, sizeof *it
);
1555 it
->current
.overlay_string_index
= -1;
1556 it
->current
.dpvec_index
= -1;
1557 it
->base_face_id
= base_face_id
;
1559 /* The window in which we iterate over current_buffer: */
1560 XSETWINDOW (it
->window
, w
);
1562 it
->f
= XFRAME (w
->frame
);
1564 /* Extra space between lines (on window systems only). */
1565 if (base_face_id
== DEFAULT_FACE_ID
1566 && FRAME_WINDOW_P (it
->f
))
1568 if (NATNUMP (current_buffer
->extra_line_spacing
))
1569 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1570 else if (it
->f
->extra_line_spacing
> 0)
1571 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1574 /* If realized faces have been removed, e.g. because of face
1575 attribute changes of named faces, recompute them. When running
1576 in batch mode, the face cache of Vterminal_frame is null. If
1577 we happen to get called, make a dummy face cache. */
1582 FRAME_FACE_CACHE (it
->f
) == NULL
)
1583 init_frame_faces (it
->f
);
1584 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1585 recompute_basic_faces (it
->f
);
1587 /* Current value of the `space-width', and 'height' properties. */
1588 it
->space_width
= Qnil
;
1589 it
->font_height
= Qnil
;
1591 /* Are control characters displayed as `^C'? */
1592 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1594 /* -1 means everything between a CR and the following line end
1595 is invisible. >0 means lines indented more than this value are
1597 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1598 ? XFASTINT (current_buffer
->selective_display
)
1599 : (!NILP (current_buffer
->selective_display
)
1601 it
->selective_display_ellipsis_p
1602 = !NILP (current_buffer
->selective_display_ellipses
);
1604 /* Display table to use. */
1605 it
->dp
= window_display_table (w
);
1607 /* Are multibyte characters enabled in current_buffer? */
1608 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1610 /* Non-zero if we should highlight the region. */
1612 = (!NILP (Vtransient_mark_mode
)
1613 && !NILP (current_buffer
->mark_active
)
1614 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1616 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1617 start and end of a visible region in window IT->w. Set both to
1618 -1 to indicate no region. */
1619 if (highlight_region_p
1620 /* Maybe highlight only in selected window. */
1621 && (/* Either show region everywhere. */
1622 highlight_nonselected_windows
1623 /* Or show region in the selected window. */
1624 || w
== XWINDOW (selected_window
)
1625 /* Or show the region if we are in the mini-buffer and W is
1626 the window the mini-buffer refers to. */
1627 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1628 && WINDOWP (minibuf_selected_window
)
1629 && w
== XWINDOW (minibuf_selected_window
))))
1631 int charpos
= marker_position (current_buffer
->mark
);
1632 it
->region_beg_charpos
= min (PT
, charpos
);
1633 it
->region_end_charpos
= max (PT
, charpos
);
1636 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1638 /* Get the position at which the redisplay_end_trigger hook should
1639 be run, if it is to be run at all. */
1640 if (MARKERP (w
->redisplay_end_trigger
)
1641 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1642 it
->redisplay_end_trigger_charpos
1643 = marker_position (w
->redisplay_end_trigger
);
1644 else if (INTEGERP (w
->redisplay_end_trigger
))
1645 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1647 /* Correct bogus values of tab_width. */
1648 it
->tab_width
= XINT (current_buffer
->tab_width
);
1649 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1652 /* Are lines in the display truncated? */
1653 it
->truncate_lines_p
1654 = (base_face_id
!= DEFAULT_FACE_ID
1655 || XINT (it
->w
->hscroll
)
1656 || (truncate_partial_width_windows
1657 && !WINDOW_FULL_WIDTH_P (it
->w
))
1658 || !NILP (current_buffer
->truncate_lines
));
1660 /* Get dimensions of truncation and continuation glyphs. These are
1661 displayed as fringe bitmaps under X, so we don't need them for such
1663 if (!FRAME_WINDOW_P (it
->f
))
1665 if (it
->truncate_lines_p
)
1667 /* We will need the truncation glyph. */
1668 xassert (it
->glyph_row
== NULL
);
1669 produce_special_glyphs (it
, IT_TRUNCATION
);
1670 it
->truncation_pixel_width
= it
->pixel_width
;
1674 /* We will need the continuation glyph. */
1675 xassert (it
->glyph_row
== NULL
);
1676 produce_special_glyphs (it
, IT_CONTINUATION
);
1677 it
->continuation_pixel_width
= it
->pixel_width
;
1680 /* Reset these values to zero because the produce_special_glyphs
1681 above has changed them. */
1682 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1683 it
->phys_ascent
= it
->phys_descent
= 0;
1686 /* Set this after getting the dimensions of truncation and
1687 continuation glyphs, so that we don't produce glyphs when calling
1688 produce_special_glyphs, above. */
1689 it
->glyph_row
= row
;
1690 it
->area
= TEXT_AREA
;
1692 /* Get the dimensions of the display area. The display area
1693 consists of the visible window area plus a horizontally scrolled
1694 part to the left of the window. All x-values are relative to the
1695 start of this total display area. */
1696 if (base_face_id
!= DEFAULT_FACE_ID
)
1698 /* Mode lines, menu bar in terminal frames. */
1699 it
->first_visible_x
= 0;
1700 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1705 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1706 it
->last_visible_x
= (it
->first_visible_x
1707 + window_box_width (w
, TEXT_AREA
));
1709 /* If we truncate lines, leave room for the truncator glyph(s) at
1710 the right margin. Otherwise, leave room for the continuation
1711 glyph(s). Truncation and continuation glyphs are not inserted
1712 for window-based redisplay. */
1713 if (!FRAME_WINDOW_P (it
->f
))
1715 if (it
->truncate_lines_p
)
1716 it
->last_visible_x
-= it
->truncation_pixel_width
;
1718 it
->last_visible_x
-= it
->continuation_pixel_width
;
1721 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1722 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1725 /* Leave room for a border glyph. */
1726 if (!FRAME_WINDOW_P (it
->f
)
1727 && !WINDOW_RIGHTMOST_P (it
->w
))
1728 it
->last_visible_x
-= 1;
1730 it
->last_visible_y
= window_text_bottom_y (w
);
1732 /* For mode lines and alike, arrange for the first glyph having a
1733 left box line if the face specifies a box. */
1734 if (base_face_id
!= DEFAULT_FACE_ID
)
1738 it
->face_id
= base_face_id
;
1740 /* If we have a boxed mode line, make the first character appear
1741 with a left box line. */
1742 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1743 if (face
->box
!= FACE_NO_BOX
)
1744 it
->start_of_box_run_p
= 1;
1747 /* If a buffer position was specified, set the iterator there,
1748 getting overlays and face properties from that position. */
1749 if (charpos
>= BUF_BEG (current_buffer
))
1751 it
->end_charpos
= ZV
;
1753 IT_CHARPOS (*it
) = charpos
;
1755 /* Compute byte position if not specified. */
1756 if (bytepos
< charpos
)
1757 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1759 IT_BYTEPOS (*it
) = bytepos
;
1761 /* Compute faces etc. */
1762 reseat (it
, it
->current
.pos
, 1);
1769 /* Initialize IT for the display of window W with window start POS. */
1772 start_display (it
, w
, pos
)
1775 struct text_pos pos
;
1777 struct glyph_row
*row
;
1778 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1780 row
= w
->desired_matrix
->rows
+ first_vpos
;
1781 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1783 if (!it
->truncate_lines_p
)
1785 int start_at_line_beg_p
;
1786 int first_y
= it
->current_y
;
1788 /* If window start is not at a line start, skip forward to POS to
1789 get the correct continuation lines width. */
1790 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1791 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1792 if (!start_at_line_beg_p
)
1794 reseat_at_previous_visible_line_start (it
);
1795 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1797 /* If lines are continued, this line may end in the middle
1798 of a multi-glyph character (e.g. a control character
1799 displayed as \003, or in the middle of an overlay
1800 string). In this case move_it_to above will not have
1801 taken us to the start of the continuation line but to the
1802 end of the continued line. */
1803 if (it
->current_x
> 0)
1805 if (it
->current
.dpvec_index
>= 0
1806 || it
->current
.overlay_string_index
>= 0)
1808 set_iterator_to_next (it
, 1);
1809 move_it_in_display_line_to (it
, -1, -1, 0);
1812 it
->continuation_lines_width
+= it
->current_x
;
1815 /* We're starting a new display line, not affected by the
1816 height of the continued line, so clear the appropriate
1817 fields in the iterator structure. */
1818 it
->max_ascent
= it
->max_descent
= 0;
1819 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1821 it
->current_y
= first_y
;
1823 it
->current_x
= it
->hpos
= 0;
1827 #if 0 /* Don't assert the following because start_display is sometimes
1828 called intentionally with a window start that is not at a
1829 line start. Please leave this code in as a comment. */
1831 /* Window start should be on a line start, now. */
1832 xassert (it
->continuation_lines_width
1833 || IT_CHARPOS (it
) == BEGV
1834 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1839 /* Return 1 if POS is a position in ellipses displayed for invisible
1840 text. W is the window we display, for text property lookup. */
1843 in_ellipses_for_invisible_text_p (pos
, w
)
1844 struct display_pos
*pos
;
1847 Lisp_Object prop
, window
;
1849 int charpos
= CHARPOS (pos
->pos
);
1851 /* If POS specifies a position in a display vector, this might
1852 be for an ellipsis displayed for invisible text. We won't
1853 get the iterator set up for delivering that ellipsis unless
1854 we make sure that it gets aware of the invisible text. */
1855 if (pos
->dpvec_index
>= 0
1856 && pos
->overlay_string_index
< 0
1857 && CHARPOS (pos
->string_pos
) < 0
1859 && (XSETWINDOW (window
, w
),
1860 prop
= Fget_char_property (make_number (charpos
),
1861 Qinvisible
, window
),
1862 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1864 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1866 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
1873 /* Initialize IT for stepping through current_buffer in window W,
1874 starting at position POS that includes overlay string and display
1875 vector/ control character translation position information. Value
1876 is zero if there are overlay strings with newlines at POS. */
1879 init_from_display_pos (it
, w
, pos
)
1882 struct display_pos
*pos
;
1884 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1885 int i
, overlay_strings_with_newlines
= 0;
1887 /* If POS specifies a position in a display vector, this might
1888 be for an ellipsis displayed for invisible text. We won't
1889 get the iterator set up for delivering that ellipsis unless
1890 we make sure that it gets aware of the invisible text. */
1891 if (in_ellipses_for_invisible_text_p (pos
, w
))
1897 /* Keep in mind: the call to reseat in init_iterator skips invisible
1898 text, so we might end up at a position different from POS. This
1899 is only a problem when POS is a row start after a newline and an
1900 overlay starts there with an after-string, and the overlay has an
1901 invisible property. Since we don't skip invisible text in
1902 display_line and elsewhere immediately after consuming the
1903 newline before the row start, such a POS will not be in a string,
1904 but the call to init_iterator below will move us to the
1906 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1908 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
1910 const char *s
= SDATA (it
->overlay_strings
[i
]);
1911 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
1913 while (s
< e
&& *s
!= '\n')
1918 overlay_strings_with_newlines
= 1;
1923 /* If position is within an overlay string, set up IT to the right
1925 if (pos
->overlay_string_index
>= 0)
1929 /* If the first overlay string happens to have a `display'
1930 property for an image, the iterator will be set up for that
1931 image, and we have to undo that setup first before we can
1932 correct the overlay string index. */
1933 if (it
->method
== next_element_from_image
)
1936 /* We already have the first chunk of overlay strings in
1937 IT->overlay_strings. Load more until the one for
1938 pos->overlay_string_index is in IT->overlay_strings. */
1939 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1941 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1942 it
->current
.overlay_string_index
= 0;
1945 load_overlay_strings (it
, 0);
1946 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1950 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1951 relative_index
= (it
->current
.overlay_string_index
1952 % OVERLAY_STRING_CHUNK_SIZE
);
1953 it
->string
= it
->overlay_strings
[relative_index
];
1954 xassert (STRINGP (it
->string
));
1955 it
->current
.string_pos
= pos
->string_pos
;
1956 it
->method
= next_element_from_string
;
1959 #if 0 /* This is bogus because POS not having an overlay string
1960 position does not mean it's after the string. Example: A
1961 line starting with a before-string and initialization of IT
1962 to the previous row's end position. */
1963 else if (it
->current
.overlay_string_index
>= 0)
1965 /* If POS says we're already after an overlay string ending at
1966 POS, make sure to pop the iterator because it will be in
1967 front of that overlay string. When POS is ZV, we've thereby
1968 also ``processed'' overlay strings at ZV. */
1971 it
->current
.overlay_string_index
= -1;
1972 it
->method
= next_element_from_buffer
;
1973 if (CHARPOS (pos
->pos
) == ZV
)
1974 it
->overlay_strings_at_end_processed_p
= 1;
1978 if (CHARPOS (pos
->string_pos
) >= 0)
1980 /* Recorded position is not in an overlay string, but in another
1981 string. This can only be a string from a `display' property.
1982 IT should already be filled with that string. */
1983 it
->current
.string_pos
= pos
->string_pos
;
1984 xassert (STRINGP (it
->string
));
1987 /* Restore position in display vector translations, control
1988 character translations or ellipses. */
1989 if (pos
->dpvec_index
>= 0)
1991 if (it
->dpvec
== NULL
)
1992 get_next_display_element (it
);
1993 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1994 it
->current
.dpvec_index
= pos
->dpvec_index
;
1998 return !overlay_strings_with_newlines
;
2002 /* Initialize IT for stepping through current_buffer in window W
2003 starting at ROW->start. */
2006 init_to_row_start (it
, w
, row
)
2009 struct glyph_row
*row
;
2011 init_from_display_pos (it
, w
, &row
->start
);
2012 it
->continuation_lines_width
= row
->continuation_lines_width
;
2017 /* Initialize IT for stepping through current_buffer in window W
2018 starting in the line following ROW, i.e. starting at ROW->end.
2019 Value is zero if there are overlay strings with newlines at ROW's
2023 init_to_row_end (it
, w
, row
)
2026 struct glyph_row
*row
;
2030 if (init_from_display_pos (it
, w
, &row
->end
))
2032 if (row
->continued_p
)
2033 it
->continuation_lines_width
2034 = row
->continuation_lines_width
+ row
->pixel_width
;
2045 /***********************************************************************
2047 ***********************************************************************/
2049 /* Called when IT reaches IT->stop_charpos. Handle text property and
2050 overlay changes. Set IT->stop_charpos to the next position where
2057 enum prop_handled handled
;
2058 int handle_overlay_change_p
= 1;
2062 it
->current
.dpvec_index
= -1;
2066 handled
= HANDLED_NORMALLY
;
2068 /* Call text property handlers. */
2069 for (p
= it_props
; p
->handler
; ++p
)
2071 handled
= p
->handler (it
);
2073 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2075 else if (handled
== HANDLED_RETURN
)
2077 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2078 handle_overlay_change_p
= 0;
2081 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2083 /* Don't check for overlay strings below when set to deliver
2084 characters from a display vector. */
2085 if (it
->method
== next_element_from_display_vector
)
2086 handle_overlay_change_p
= 0;
2088 /* Handle overlay changes. */
2089 if (handle_overlay_change_p
)
2090 handled
= handle_overlay_change (it
);
2092 /* Determine where to stop next. */
2093 if (handled
== HANDLED_NORMALLY
)
2094 compute_stop_pos (it
);
2097 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2101 /* Compute IT->stop_charpos from text property and overlay change
2102 information for IT's current position. */
2105 compute_stop_pos (it
)
2108 register INTERVAL iv
, next_iv
;
2109 Lisp_Object object
, limit
, position
;
2111 /* If nowhere else, stop at the end. */
2112 it
->stop_charpos
= it
->end_charpos
;
2114 if (STRINGP (it
->string
))
2116 /* Strings are usually short, so don't limit the search for
2118 object
= it
->string
;
2120 position
= make_number (IT_STRING_CHARPOS (*it
));
2126 /* If next overlay change is in front of the current stop pos
2127 (which is IT->end_charpos), stop there. Note: value of
2128 next_overlay_change is point-max if no overlay change
2130 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2131 if (charpos
< it
->stop_charpos
)
2132 it
->stop_charpos
= charpos
;
2134 /* If showing the region, we have to stop at the region
2135 start or end because the face might change there. */
2136 if (it
->region_beg_charpos
> 0)
2138 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2139 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2140 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2141 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2144 /* Set up variables for computing the stop position from text
2145 property changes. */
2146 XSETBUFFER (object
, current_buffer
);
2147 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2148 position
= make_number (IT_CHARPOS (*it
));
2152 /* Get the interval containing IT's position. Value is a null
2153 interval if there isn't such an interval. */
2154 iv
= validate_interval_range (object
, &position
, &position
, 0);
2155 if (!NULL_INTERVAL_P (iv
))
2157 Lisp_Object values_here
[LAST_PROP_IDX
];
2160 /* Get properties here. */
2161 for (p
= it_props
; p
->handler
; ++p
)
2162 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2164 /* Look for an interval following iv that has different
2166 for (next_iv
= next_interval (iv
);
2167 (!NULL_INTERVAL_P (next_iv
)
2169 || XFASTINT (limit
) > next_iv
->position
));
2170 next_iv
= next_interval (next_iv
))
2172 for (p
= it_props
; p
->handler
; ++p
)
2174 Lisp_Object new_value
;
2176 new_value
= textget (next_iv
->plist
, *p
->name
);
2177 if (!EQ (values_here
[p
->idx
], new_value
))
2185 if (!NULL_INTERVAL_P (next_iv
))
2187 if (INTEGERP (limit
)
2188 && next_iv
->position
>= XFASTINT (limit
))
2189 /* No text property change up to limit. */
2190 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2192 /* Text properties change in next_iv. */
2193 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2197 xassert (STRINGP (it
->string
)
2198 || (it
->stop_charpos
>= BEGV
2199 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2203 /* Return the position of the next overlay change after POS in
2204 current_buffer. Value is point-max if no overlay change
2205 follows. This is like `next-overlay-change' but doesn't use
2209 next_overlay_change (pos
)
2214 Lisp_Object
*overlays
;
2218 /* Get all overlays at the given position. */
2220 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2221 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2222 if (noverlays
> len
)
2225 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2226 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2229 /* If any of these overlays ends before endpos,
2230 use its ending point instead. */
2231 for (i
= 0; i
< noverlays
; ++i
)
2236 oend
= OVERLAY_END (overlays
[i
]);
2237 oendpos
= OVERLAY_POSITION (oend
);
2238 endpos
= min (endpos
, oendpos
);
2246 /***********************************************************************
2248 ***********************************************************************/
2250 /* Handle changes in the `fontified' property of the current buffer by
2251 calling hook functions from Qfontification_functions to fontify
2254 static enum prop_handled
2255 handle_fontified_prop (it
)
2258 Lisp_Object prop
, pos
;
2259 enum prop_handled handled
= HANDLED_NORMALLY
;
2261 /* Get the value of the `fontified' property at IT's current buffer
2262 position. (The `fontified' property doesn't have a special
2263 meaning in strings.) If the value is nil, call functions from
2264 Qfontification_functions. */
2265 if (!STRINGP (it
->string
)
2267 && !NILP (Vfontification_functions
)
2268 && !NILP (Vrun_hooks
)
2269 && (pos
= make_number (IT_CHARPOS (*it
)),
2270 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2273 int count
= SPECPDL_INDEX ();
2276 val
= Vfontification_functions
;
2277 specbind (Qfontification_functions
, Qnil
);
2279 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2280 safe_call1 (val
, pos
);
2283 Lisp_Object globals
, fn
;
2284 struct gcpro gcpro1
, gcpro2
;
2287 GCPRO2 (val
, globals
);
2289 for (; CONSP (val
); val
= XCDR (val
))
2295 /* A value of t indicates this hook has a local
2296 binding; it means to run the global binding too.
2297 In a global value, t should not occur. If it
2298 does, we must ignore it to avoid an endless
2300 for (globals
= Fdefault_value (Qfontification_functions
);
2302 globals
= XCDR (globals
))
2304 fn
= XCAR (globals
);
2306 safe_call1 (fn
, pos
);
2310 safe_call1 (fn
, pos
);
2316 unbind_to (count
, Qnil
);
2318 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2319 something. This avoids an endless loop if they failed to
2320 fontify the text for which reason ever. */
2321 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2322 handled
= HANDLED_RECOMPUTE_PROPS
;
2330 /***********************************************************************
2332 ***********************************************************************/
2334 /* Set up iterator IT from face properties at its current position.
2335 Called from handle_stop. */
2337 static enum prop_handled
2338 handle_face_prop (it
)
2341 int new_face_id
, next_stop
;
2343 if (!STRINGP (it
->string
))
2346 = face_at_buffer_position (it
->w
,
2348 it
->region_beg_charpos
,
2349 it
->region_end_charpos
,
2352 + TEXT_PROP_DISTANCE_LIMIT
),
2355 /* Is this a start of a run of characters with box face?
2356 Caveat: this can be called for a freshly initialized
2357 iterator; face_id is -1 in this case. We know that the new
2358 face will not change until limit, i.e. if the new face has a
2359 box, all characters up to limit will have one. But, as
2360 usual, we don't know whether limit is really the end. */
2361 if (new_face_id
!= it
->face_id
)
2363 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2365 /* If new face has a box but old face has not, this is
2366 the start of a run of characters with box, i.e. it has
2367 a shadow on the left side. The value of face_id of the
2368 iterator will be -1 if this is the initial call that gets
2369 the face. In this case, we have to look in front of IT's
2370 position and see whether there is a face != new_face_id. */
2371 it
->start_of_box_run_p
2372 = (new_face
->box
!= FACE_NO_BOX
2373 && (it
->face_id
>= 0
2374 || IT_CHARPOS (*it
) == BEG
2375 || new_face_id
!= face_before_it_pos (it
)));
2376 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2381 int base_face_id
, bufpos
;
2383 if (it
->current
.overlay_string_index
>= 0)
2384 bufpos
= IT_CHARPOS (*it
);
2388 /* For strings from a buffer, i.e. overlay strings or strings
2389 from a `display' property, use the face at IT's current
2390 buffer position as the base face to merge with, so that
2391 overlay strings appear in the same face as surrounding
2392 text, unless they specify their own faces. */
2393 base_face_id
= underlying_face_id (it
);
2395 new_face_id
= face_at_string_position (it
->w
,
2397 IT_STRING_CHARPOS (*it
),
2399 it
->region_beg_charpos
,
2400 it
->region_end_charpos
,
2404 #if 0 /* This shouldn't be neccessary. Let's check it. */
2405 /* If IT is used to display a mode line we would really like to
2406 use the mode line face instead of the frame's default face. */
2407 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2408 && new_face_id
== DEFAULT_FACE_ID
)
2409 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2412 /* Is this a start of a run of characters with box? Caveat:
2413 this can be called for a freshly allocated iterator; face_id
2414 is -1 is this case. We know that the new face will not
2415 change until the next check pos, i.e. if the new face has a
2416 box, all characters up to that position will have a
2417 box. But, as usual, we don't know whether that position
2418 is really the end. */
2419 if (new_face_id
!= it
->face_id
)
2421 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2422 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2424 /* If new face has a box but old face hasn't, this is the
2425 start of a run of characters with box, i.e. it has a
2426 shadow on the left side. */
2427 it
->start_of_box_run_p
2428 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2429 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2433 it
->face_id
= new_face_id
;
2434 return HANDLED_NORMALLY
;
2438 /* Return the ID of the face ``underlying'' IT's current position,
2439 which is in a string. If the iterator is associated with a
2440 buffer, return the face at IT's current buffer position.
2441 Otherwise, use the iterator's base_face_id. */
2444 underlying_face_id (it
)
2447 int face_id
= it
->base_face_id
, i
;
2449 xassert (STRINGP (it
->string
));
2451 for (i
= it
->sp
- 1; i
>= 0; --i
)
2452 if (NILP (it
->stack
[i
].string
))
2453 face_id
= it
->stack
[i
].face_id
;
2459 /* Compute the face one character before or after the current position
2460 of IT. BEFORE_P non-zero means get the face in front of IT's
2461 position. Value is the id of the face. */
2464 face_before_or_after_it_pos (it
, before_p
)
2469 int next_check_charpos
;
2470 struct text_pos pos
;
2472 xassert (it
->s
== NULL
);
2474 if (STRINGP (it
->string
))
2476 int bufpos
, base_face_id
;
2478 /* No face change past the end of the string (for the case
2479 we are padding with spaces). No face change before the
2481 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2482 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2485 /* Set pos to the position before or after IT's current position. */
2487 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2489 /* For composition, we must check the character after the
2491 pos
= (it
->what
== IT_COMPOSITION
2492 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2493 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2495 if (it
->current
.overlay_string_index
>= 0)
2496 bufpos
= IT_CHARPOS (*it
);
2500 base_face_id
= underlying_face_id (it
);
2502 /* Get the face for ASCII, or unibyte. */
2503 face_id
= face_at_string_position (it
->w
,
2507 it
->region_beg_charpos
,
2508 it
->region_end_charpos
,
2509 &next_check_charpos
,
2512 /* Correct the face for charsets different from ASCII. Do it
2513 for the multibyte case only. The face returned above is
2514 suitable for unibyte text if IT->string is unibyte. */
2515 if (STRING_MULTIBYTE (it
->string
))
2517 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
2518 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
2520 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2522 c
= string_char_and_length (p
, rest
, &len
);
2523 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2528 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2529 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2532 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2533 pos
= it
->current
.pos
;
2536 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2539 if (it
->what
== IT_COMPOSITION
)
2540 /* For composition, we must check the position after the
2542 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2544 INC_TEXT_POS (pos
, it
->multibyte_p
);
2547 /* Determine face for CHARSET_ASCII, or unibyte. */
2548 face_id
= face_at_buffer_position (it
->w
,
2550 it
->region_beg_charpos
,
2551 it
->region_end_charpos
,
2552 &next_check_charpos
,
2555 /* Correct the face for charsets different from ASCII. Do it
2556 for the multibyte case only. The face returned above is
2557 suitable for unibyte text if current_buffer is unibyte. */
2558 if (it
->multibyte_p
)
2560 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
2561 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2562 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2571 /***********************************************************************
2573 ***********************************************************************/
2575 /* Set up iterator IT from invisible properties at its current
2576 position. Called from handle_stop. */
2578 static enum prop_handled
2579 handle_invisible_prop (it
)
2582 enum prop_handled handled
= HANDLED_NORMALLY
;
2584 if (STRINGP (it
->string
))
2586 extern Lisp_Object Qinvisible
;
2587 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2589 /* Get the value of the invisible text property at the
2590 current position. Value will be nil if there is no such
2592 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2593 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2596 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2598 handled
= HANDLED_RECOMPUTE_PROPS
;
2600 /* Get the position at which the next change of the
2601 invisible text property can be found in IT->string.
2602 Value will be nil if the property value is the same for
2603 all the rest of IT->string. */
2604 XSETINT (limit
, SCHARS (it
->string
));
2605 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2608 /* Text at current position is invisible. The next
2609 change in the property is at position end_charpos.
2610 Move IT's current position to that position. */
2611 if (INTEGERP (end_charpos
)
2612 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2614 struct text_pos old
;
2615 old
= it
->current
.string_pos
;
2616 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2617 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2621 /* The rest of the string is invisible. If this is an
2622 overlay string, proceed with the next overlay string
2623 or whatever comes and return a character from there. */
2624 if (it
->current
.overlay_string_index
>= 0)
2626 next_overlay_string (it
);
2627 /* Don't check for overlay strings when we just
2628 finished processing them. */
2629 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2633 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
2634 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
2641 int invis_p
, newpos
, next_stop
, start_charpos
;
2642 Lisp_Object pos
, prop
, overlay
;
2644 /* First of all, is there invisible text at this position? */
2645 start_charpos
= IT_CHARPOS (*it
);
2646 pos
= make_number (IT_CHARPOS (*it
));
2647 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2649 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2651 /* If we are on invisible text, skip over it. */
2652 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
2654 /* Record whether we have to display an ellipsis for the
2656 int display_ellipsis_p
= invis_p
== 2;
2658 handled
= HANDLED_RECOMPUTE_PROPS
;
2660 /* Loop skipping over invisible text. The loop is left at
2661 ZV or with IT on the first char being visible again. */
2664 /* Try to skip some invisible text. Return value is the
2665 position reached which can be equal to IT's position
2666 if there is nothing invisible here. This skips both
2667 over invisible text properties and overlays with
2668 invisible property. */
2669 newpos
= skip_invisible (IT_CHARPOS (*it
),
2670 &next_stop
, ZV
, it
->window
);
2672 /* If we skipped nothing at all we weren't at invisible
2673 text in the first place. If everything to the end of
2674 the buffer was skipped, end the loop. */
2675 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2679 /* We skipped some characters but not necessarily
2680 all there are. Check if we ended up on visible
2681 text. Fget_char_property returns the property of
2682 the char before the given position, i.e. if we
2683 get invis_p = 0, this means that the char at
2684 newpos is visible. */
2685 pos
= make_number (newpos
);
2686 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2687 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2690 /* If we ended up on invisible text, proceed to
2691 skip starting with next_stop. */
2693 IT_CHARPOS (*it
) = next_stop
;
2697 /* The position newpos is now either ZV or on visible text. */
2698 IT_CHARPOS (*it
) = newpos
;
2699 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2701 /* If there are before-strings at the start of invisible
2702 text, and the text is invisible because of a text
2703 property, arrange to show before-strings because 20.x did
2704 it that way. (If the text is invisible because of an
2705 overlay property instead of a text property, this is
2706 already handled in the overlay code.) */
2708 && get_overlay_strings (it
, start_charpos
))
2710 handled
= HANDLED_RECOMPUTE_PROPS
;
2711 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2713 else if (display_ellipsis_p
)
2714 setup_for_ellipsis (it
);
2722 /* Make iterator IT return `...' next. */
2725 setup_for_ellipsis (it
)
2729 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2731 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2732 it
->dpvec
= v
->contents
;
2733 it
->dpend
= v
->contents
+ v
->size
;
2737 /* Default `...'. */
2738 it
->dpvec
= default_invis_vector
;
2739 it
->dpend
= default_invis_vector
+ 3;
2742 /* The ellipsis display does not replace the display of the
2743 character at the new position. Indicate this by setting
2744 IT->dpvec_char_len to zero. */
2745 it
->dpvec_char_len
= 0;
2747 it
->current
.dpvec_index
= 0;
2748 it
->method
= next_element_from_display_vector
;
2753 /***********************************************************************
2755 ***********************************************************************/
2757 /* Set up iterator IT from `display' property at its current position.
2758 Called from handle_stop. */
2760 static enum prop_handled
2761 handle_display_prop (it
)
2764 Lisp_Object prop
, object
;
2765 struct text_pos
*position
;
2766 int display_replaced_p
= 0;
2768 if (STRINGP (it
->string
))
2770 object
= it
->string
;
2771 position
= &it
->current
.string_pos
;
2775 object
= it
->w
->buffer
;
2776 position
= &it
->current
.pos
;
2779 /* Reset those iterator values set from display property values. */
2780 it
->font_height
= Qnil
;
2781 it
->space_width
= Qnil
;
2784 /* We don't support recursive `display' properties, i.e. string
2785 values that have a string `display' property, that have a string
2786 `display' property etc. */
2787 if (!it
->string_from_display_prop_p
)
2788 it
->area
= TEXT_AREA
;
2790 prop
= Fget_char_property (make_number (position
->charpos
),
2793 return HANDLED_NORMALLY
;
2796 /* Simple properties. */
2797 && !EQ (XCAR (prop
), Qimage
)
2798 && !EQ (XCAR (prop
), Qspace
)
2799 && !EQ (XCAR (prop
), Qwhen
)
2800 && !EQ (XCAR (prop
), Qspace_width
)
2801 && !EQ (XCAR (prop
), Qheight
)
2802 && !EQ (XCAR (prop
), Qraise
)
2803 /* Marginal area specifications. */
2804 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2805 && !NILP (XCAR (prop
)))
2807 for (; CONSP (prop
); prop
= XCDR (prop
))
2809 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2810 position
, display_replaced_p
))
2811 display_replaced_p
= 1;
2814 else if (VECTORP (prop
))
2817 for (i
= 0; i
< ASIZE (prop
); ++i
)
2818 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2819 position
, display_replaced_p
))
2820 display_replaced_p
= 1;
2824 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2825 display_replaced_p
= 1;
2828 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2832 /* Value is the position of the end of the `display' property starting
2833 at START_POS in OBJECT. */
2835 static struct text_pos
2836 display_prop_end (it
, object
, start_pos
)
2839 struct text_pos start_pos
;
2842 struct text_pos end_pos
;
2844 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2845 Qdisplay
, object
, Qnil
);
2846 CHARPOS (end_pos
) = XFASTINT (end
);
2847 if (STRINGP (object
))
2848 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2850 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2856 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2857 is the object in which the `display' property was found. *POSITION
2858 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2859 means that we previously saw a display sub-property which already
2860 replaced text display with something else, for example an image;
2861 ignore such properties after the first one has been processed.
2863 If PROP is a `space' or `image' sub-property, set *POSITION to the
2864 end position of the `display' property.
2866 Value is non-zero if something was found which replaces the display
2867 of buffer or string text. */
2870 handle_single_display_prop (it
, prop
, object
, position
,
2871 display_replaced_before_p
)
2875 struct text_pos
*position
;
2876 int display_replaced_before_p
;
2879 int replaces_text_display_p
= 0;
2882 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2883 evaluated. If the result is nil, VALUE is ignored. */
2885 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2894 if (!NILP (form
) && !EQ (form
, Qt
))
2896 int count
= SPECPDL_INDEX ();
2897 struct gcpro gcpro1
;
2899 /* Bind `object' to the object having the `display' property, a
2900 buffer or string. Bind `position' to the position in the
2901 object where the property was found, and `buffer-position'
2902 to the current position in the buffer. */
2903 specbind (Qobject
, object
);
2904 specbind (Qposition
, make_number (CHARPOS (*position
)));
2905 specbind (Qbuffer_position
,
2906 make_number (STRINGP (object
)
2907 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2909 form
= safe_eval (form
);
2911 unbind_to (count
, Qnil
);
2918 && EQ (XCAR (prop
), Qheight
)
2919 && CONSP (XCDR (prop
)))
2921 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2924 /* `(height HEIGHT)'. */
2925 it
->font_height
= XCAR (XCDR (prop
));
2926 if (!NILP (it
->font_height
))
2928 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2929 int new_height
= -1;
2931 if (CONSP (it
->font_height
)
2932 && (EQ (XCAR (it
->font_height
), Qplus
)
2933 || EQ (XCAR (it
->font_height
), Qminus
))
2934 && CONSP (XCDR (it
->font_height
))
2935 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2937 /* `(+ N)' or `(- N)' where N is an integer. */
2938 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2939 if (EQ (XCAR (it
->font_height
), Qplus
))
2941 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2943 else if (FUNCTIONP (it
->font_height
))
2945 /* Call function with current height as argument.
2946 Value is the new height. */
2948 height
= safe_call1 (it
->font_height
,
2949 face
->lface
[LFACE_HEIGHT_INDEX
]);
2950 if (NUMBERP (height
))
2951 new_height
= XFLOATINT (height
);
2953 else if (NUMBERP (it
->font_height
))
2955 /* Value is a multiple of the canonical char height. */
2958 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2959 new_height
= (XFLOATINT (it
->font_height
)
2960 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2964 /* Evaluate IT->font_height with `height' bound to the
2965 current specified height to get the new height. */
2967 int count
= SPECPDL_INDEX ();
2969 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2970 value
= safe_eval (it
->font_height
);
2971 unbind_to (count
, Qnil
);
2973 if (NUMBERP (value
))
2974 new_height
= XFLOATINT (value
);
2978 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2981 else if (CONSP (prop
)
2982 && EQ (XCAR (prop
), Qspace_width
)
2983 && CONSP (XCDR (prop
)))
2985 /* `(space_width WIDTH)'. */
2986 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2989 value
= XCAR (XCDR (prop
));
2990 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2991 it
->space_width
= value
;
2993 else if (CONSP (prop
)
2994 && EQ (XCAR (prop
), Qraise
)
2995 && CONSP (XCDR (prop
)))
2997 /* `(raise FACTOR)'. */
2998 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3001 #ifdef HAVE_WINDOW_SYSTEM
3002 value
= XCAR (XCDR (prop
));
3003 if (NUMBERP (value
))
3005 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3006 it
->voffset
= - (XFLOATINT (value
)
3007 * (FONT_HEIGHT (face
->font
)));
3009 #endif /* HAVE_WINDOW_SYSTEM */
3011 else if (!it
->string_from_display_prop_p
)
3013 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3014 VALUE) or `((margin nil) VALUE)' or VALUE. */
3015 Lisp_Object location
, value
;
3016 struct text_pos start_pos
;
3019 /* Characters having this form of property are not displayed, so
3020 we have to find the end of the property. */
3021 start_pos
= *position
;
3022 *position
= display_prop_end (it
, object
, start_pos
);
3025 /* Let's stop at the new position and assume that all
3026 text properties change there. */
3027 it
->stop_charpos
= position
->charpos
;
3029 location
= Qunbound
;
3030 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3034 value
= XCDR (prop
);
3036 value
= XCAR (value
);
3039 if (EQ (XCAR (tem
), Qmargin
)
3040 && (tem
= XCDR (tem
),
3041 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3043 || EQ (tem
, Qleft_margin
)
3044 || EQ (tem
, Qright_margin
))))
3048 if (EQ (location
, Qunbound
))
3054 #ifdef HAVE_WINDOW_SYSTEM
3055 if (FRAME_TERMCAP_P (it
->f
))
3056 valid_p
= STRINGP (value
);
3058 valid_p
= (STRINGP (value
)
3059 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3060 || valid_image_p (value
));
3061 #else /* not HAVE_WINDOW_SYSTEM */
3062 valid_p
= STRINGP (value
);
3063 #endif /* not HAVE_WINDOW_SYSTEM */
3065 if ((EQ (location
, Qleft_margin
)
3066 || EQ (location
, Qright_margin
)
3069 && !display_replaced_before_p
)
3071 replaces_text_display_p
= 1;
3073 /* Save current settings of IT so that we can restore them
3074 when we are finished with the glyph property value. */
3077 if (NILP (location
))
3078 it
->area
= TEXT_AREA
;
3079 else if (EQ (location
, Qleft_margin
))
3080 it
->area
= LEFT_MARGIN_AREA
;
3082 it
->area
= RIGHT_MARGIN_AREA
;
3084 if (STRINGP (value
))
3087 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3088 it
->current
.overlay_string_index
= -1;
3089 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3090 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3091 it
->method
= next_element_from_string
;
3092 it
->stop_charpos
= 0;
3093 it
->string_from_display_prop_p
= 1;
3094 /* Say that we haven't consumed the characters with
3095 `display' property yet. The call to pop_it in
3096 set_iterator_to_next will clean this up. */
3097 *position
= start_pos
;
3099 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3101 it
->method
= next_element_from_stretch
;
3103 it
->current
.pos
= it
->position
= start_pos
;
3105 #ifdef HAVE_WINDOW_SYSTEM
3108 it
->what
= IT_IMAGE
;
3109 it
->image_id
= lookup_image (it
->f
, value
);
3110 it
->position
= start_pos
;
3111 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3112 it
->method
= next_element_from_image
;
3114 /* Say that we haven't consumed the characters with
3115 `display' property yet. The call to pop_it in
3116 set_iterator_to_next will clean this up. */
3117 *position
= start_pos
;
3119 #endif /* HAVE_WINDOW_SYSTEM */
3122 /* Invalid property or property not supported. Restore
3123 the position to what it was before. */
3124 *position
= start_pos
;
3127 return replaces_text_display_p
;
3131 /* Check if PROP is a display sub-property value whose text should be
3132 treated as intangible. */
3135 single_display_prop_intangible_p (prop
)
3138 /* Skip over `when FORM'. */
3139 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3150 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3151 we don't need to treat text as intangible. */
3152 if (EQ (XCAR (prop
), Qmargin
))
3160 || EQ (XCAR (prop
), Qleft_margin
)
3161 || EQ (XCAR (prop
), Qright_margin
))
3165 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3169 /* Check if PROP is a display property value whose text should be
3170 treated as intangible. */
3173 display_prop_intangible_p (prop
)
3177 && CONSP (XCAR (prop
))
3178 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3180 /* A list of sub-properties. */
3181 while (CONSP (prop
))
3183 if (single_display_prop_intangible_p (XCAR (prop
)))
3188 else if (VECTORP (prop
))
3190 /* A vector of sub-properties. */
3192 for (i
= 0; i
< ASIZE (prop
); ++i
)
3193 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3197 return single_display_prop_intangible_p (prop
);
3203 /* Return 1 if PROP is a display sub-property value containing STRING. */
3206 single_display_prop_string_p (prop
, string
)
3207 Lisp_Object prop
, string
;
3209 if (EQ (string
, prop
))
3212 /* Skip over `when FORM'. */
3213 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3222 /* Skip over `margin LOCATION'. */
3223 if (EQ (XCAR (prop
), Qmargin
))
3234 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3238 /* Return 1 if STRING appears in the `display' property PROP. */
3241 display_prop_string_p (prop
, string
)
3242 Lisp_Object prop
, string
;
3245 && CONSP (XCAR (prop
))
3246 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3248 /* A list of sub-properties. */
3249 while (CONSP (prop
))
3251 if (single_display_prop_string_p (XCAR (prop
), string
))
3256 else if (VECTORP (prop
))
3258 /* A vector of sub-properties. */
3260 for (i
= 0; i
< ASIZE (prop
); ++i
)
3261 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3265 return single_display_prop_string_p (prop
, string
);
3271 /* Determine from which buffer position in W's buffer STRING comes
3272 from. AROUND_CHARPOS is an approximate position where it could
3273 be from. Value is the buffer position or 0 if it couldn't be
3276 W's buffer must be current.
3278 This function is necessary because we don't record buffer positions
3279 in glyphs generated from strings (to keep struct glyph small).
3280 This function may only use code that doesn't eval because it is
3281 called asynchronously from note_mouse_highlight. */
3284 string_buffer_position (w
, string
, around_charpos
)
3289 Lisp_Object limit
, prop
, pos
;
3290 const int MAX_DISTANCE
= 1000;
3293 pos
= make_number (around_charpos
);
3294 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3295 while (!found
&& !EQ (pos
, limit
))
3297 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3298 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3301 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3306 pos
= make_number (around_charpos
);
3307 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3308 while (!found
&& !EQ (pos
, limit
))
3310 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3311 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3314 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3319 return found
? XINT (pos
) : 0;
3324 /***********************************************************************
3325 `composition' property
3326 ***********************************************************************/
3328 /* Set up iterator IT from `composition' property at its current
3329 position. Called from handle_stop. */
3331 static enum prop_handled
3332 handle_composition_prop (it
)
3335 Lisp_Object prop
, string
;
3336 int pos
, pos_byte
, end
;
3337 enum prop_handled handled
= HANDLED_NORMALLY
;
3339 if (STRINGP (it
->string
))
3341 pos
= IT_STRING_CHARPOS (*it
);
3342 pos_byte
= IT_STRING_BYTEPOS (*it
);
3343 string
= it
->string
;
3347 pos
= IT_CHARPOS (*it
);
3348 pos_byte
= IT_BYTEPOS (*it
);
3352 /* If there's a valid composition and point is not inside of the
3353 composition (in the case that the composition is from the current
3354 buffer), draw a glyph composed from the composition components. */
3355 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3356 && COMPOSITION_VALID_P (pos
, end
, prop
)
3357 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3359 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3363 it
->method
= next_element_from_composition
;
3365 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3366 /* For a terminal, draw only the first character of the
3368 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3369 it
->len
= (STRINGP (it
->string
)
3370 ? string_char_to_byte (it
->string
, end
)
3371 : CHAR_TO_BYTE (end
)) - pos_byte
;
3372 it
->stop_charpos
= end
;
3373 handled
= HANDLED_RETURN
;
3382 /***********************************************************************
3384 ***********************************************************************/
3386 /* The following structure is used to record overlay strings for
3387 later sorting in load_overlay_strings. */
3389 struct overlay_entry
3391 Lisp_Object overlay
;
3398 /* Set up iterator IT from overlay strings at its current position.
3399 Called from handle_stop. */
3401 static enum prop_handled
3402 handle_overlay_change (it
)
3405 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3406 return HANDLED_RECOMPUTE_PROPS
;
3408 return HANDLED_NORMALLY
;
3412 /* Set up the next overlay string for delivery by IT, if there is an
3413 overlay string to deliver. Called by set_iterator_to_next when the
3414 end of the current overlay string is reached. If there are more
3415 overlay strings to display, IT->string and
3416 IT->current.overlay_string_index are set appropriately here.
3417 Otherwise IT->string is set to nil. */
3420 next_overlay_string (it
)
3423 ++it
->current
.overlay_string_index
;
3424 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3426 /* No more overlay strings. Restore IT's settings to what
3427 they were before overlay strings were processed, and
3428 continue to deliver from current_buffer. */
3429 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3432 xassert (it
->stop_charpos
>= BEGV
3433 && it
->stop_charpos
<= it
->end_charpos
);
3435 it
->current
.overlay_string_index
= -1;
3436 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3437 it
->n_overlay_strings
= 0;
3438 it
->method
= next_element_from_buffer
;
3440 /* If we're at the end of the buffer, record that we have
3441 processed the overlay strings there already, so that
3442 next_element_from_buffer doesn't try it again. */
3443 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3444 it
->overlay_strings_at_end_processed_p
= 1;
3446 /* If we have to display `...' for invisible text, set
3447 the iterator up for that. */
3448 if (display_ellipsis_p
)
3449 setup_for_ellipsis (it
);
3453 /* There are more overlay strings to process. If
3454 IT->current.overlay_string_index has advanced to a position
3455 where we must load IT->overlay_strings with more strings, do
3457 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3459 if (it
->current
.overlay_string_index
&& i
== 0)
3460 load_overlay_strings (it
, 0);
3462 /* Initialize IT to deliver display elements from the overlay
3464 it
->string
= it
->overlay_strings
[i
];
3465 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3466 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3467 it
->method
= next_element_from_string
;
3468 it
->stop_charpos
= 0;
3475 /* Compare two overlay_entry structures E1 and E2. Used as a
3476 comparison function for qsort in load_overlay_strings. Overlay
3477 strings for the same position are sorted so that
3479 1. All after-strings come in front of before-strings, except
3480 when they come from the same overlay.
3482 2. Within after-strings, strings are sorted so that overlay strings
3483 from overlays with higher priorities come first.
3485 2. Within before-strings, strings are sorted so that overlay
3486 strings from overlays with higher priorities come last.
3488 Value is analogous to strcmp. */
3492 compare_overlay_entries (e1
, e2
)
3495 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3496 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3499 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3501 /* Let after-strings appear in front of before-strings if
3502 they come from different overlays. */
3503 if (EQ (entry1
->overlay
, entry2
->overlay
))
3504 result
= entry1
->after_string_p
? 1 : -1;
3506 result
= entry1
->after_string_p
? -1 : 1;
3508 else if (entry1
->after_string_p
)
3509 /* After-strings sorted in order of decreasing priority. */
3510 result
= entry2
->priority
- entry1
->priority
;
3512 /* Before-strings sorted in order of increasing priority. */
3513 result
= entry1
->priority
- entry2
->priority
;
3519 /* Load the vector IT->overlay_strings with overlay strings from IT's
3520 current buffer position, or from CHARPOS if that is > 0. Set
3521 IT->n_overlays to the total number of overlay strings found.
3523 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3524 a time. On entry into load_overlay_strings,
3525 IT->current.overlay_string_index gives the number of overlay
3526 strings that have already been loaded by previous calls to this
3529 IT->add_overlay_start contains an additional overlay start
3530 position to consider for taking overlay strings from, if non-zero.
3531 This position comes into play when the overlay has an `invisible'
3532 property, and both before and after-strings. When we've skipped to
3533 the end of the overlay, because of its `invisible' property, we
3534 nevertheless want its before-string to appear.
3535 IT->add_overlay_start will contain the overlay start position
3538 Overlay strings are sorted so that after-string strings come in
3539 front of before-string strings. Within before and after-strings,
3540 strings are sorted by overlay priority. See also function
3541 compare_overlay_entries. */
3544 load_overlay_strings (it
, charpos
)
3548 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3549 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3552 int n
= 0, i
, j
, invis_p
;
3553 struct overlay_entry
*entries
3554 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3557 charpos
= IT_CHARPOS (*it
);
3559 /* Append the overlay string STRING of overlay OVERLAY to vector
3560 `entries' which has size `size' and currently contains `n'
3561 elements. AFTER_P non-zero means STRING is an after-string of
3563 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3566 Lisp_Object priority; \
3570 int new_size = 2 * size; \
3571 struct overlay_entry *old = entries; \
3573 (struct overlay_entry *) alloca (new_size \
3574 * sizeof *entries); \
3575 bcopy (old, entries, size * sizeof *entries); \
3579 entries[n].string = (STRING); \
3580 entries[n].overlay = (OVERLAY); \
3581 priority = Foverlay_get ((OVERLAY), Qpriority); \
3582 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3583 entries[n].after_string_p = (AFTER_P); \
3588 /* Process overlay before the overlay center. */
3589 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3591 overlay
= XCAR (ov
);
3592 xassert (OVERLAYP (overlay
));
3593 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3594 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3599 /* Skip this overlay if it doesn't start or end at IT's current
3601 if (end
!= charpos
&& start
!= charpos
)
3604 /* Skip this overlay if it doesn't apply to IT->w. */
3605 window
= Foverlay_get (overlay
, Qwindow
);
3606 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3609 /* If the text ``under'' the overlay is invisible, both before-
3610 and after-strings from this overlay are visible; start and
3611 end position are indistinguishable. */
3612 invisible
= Foverlay_get (overlay
, Qinvisible
);
3613 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3615 /* If overlay has a non-empty before-string, record it. */
3616 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3617 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3619 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3621 /* If overlay has a non-empty after-string, record it. */
3622 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3623 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3625 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3628 /* Process overlays after the overlay center. */
3629 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3631 overlay
= XCAR (ov
);
3632 xassert (OVERLAYP (overlay
));
3633 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3634 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3636 if (start
> charpos
)
3639 /* Skip this overlay if it doesn't start or end at IT's current
3641 if (end
!= charpos
&& start
!= charpos
)
3644 /* Skip this overlay if it doesn't apply to IT->w. */
3645 window
= Foverlay_get (overlay
, Qwindow
);
3646 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3649 /* If the text ``under'' the overlay is invisible, it has a zero
3650 dimension, and both before- and after-strings apply. */
3651 invisible
= Foverlay_get (overlay
, Qinvisible
);
3652 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3654 /* If overlay has a non-empty before-string, record it. */
3655 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3656 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3658 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3660 /* If overlay has a non-empty after-string, record it. */
3661 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3662 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3664 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3667 #undef RECORD_OVERLAY_STRING
3671 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3673 /* Record the total number of strings to process. */
3674 it
->n_overlay_strings
= n
;
3676 /* IT->current.overlay_string_index is the number of overlay strings
3677 that have already been consumed by IT. Copy some of the
3678 remaining overlay strings to IT->overlay_strings. */
3680 j
= it
->current
.overlay_string_index
;
3681 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3682 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3688 /* Get the first chunk of overlay strings at IT's current buffer
3689 position, or at CHARPOS if that is > 0. Value is non-zero if at
3690 least one overlay string was found. */
3693 get_overlay_strings (it
, charpos
)
3697 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3698 process. This fills IT->overlay_strings with strings, and sets
3699 IT->n_overlay_strings to the total number of strings to process.
3700 IT->pos.overlay_string_index has to be set temporarily to zero
3701 because load_overlay_strings needs this; it must be set to -1
3702 when no overlay strings are found because a zero value would
3703 indicate a position in the first overlay string. */
3704 it
->current
.overlay_string_index
= 0;
3705 load_overlay_strings (it
, charpos
);
3707 /* If we found overlay strings, set up IT to deliver display
3708 elements from the first one. Otherwise set up IT to deliver
3709 from current_buffer. */
3710 if (it
->n_overlay_strings
)
3712 /* Make sure we know settings in current_buffer, so that we can
3713 restore meaningful values when we're done with the overlay
3715 compute_stop_pos (it
);
3716 xassert (it
->face_id
>= 0);
3718 /* Save IT's settings. They are restored after all overlay
3719 strings have been processed. */
3720 xassert (it
->sp
== 0);
3723 /* Set up IT to deliver display elements from the first overlay
3725 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3726 it
->string
= it
->overlay_strings
[0];
3727 it
->stop_charpos
= 0;
3728 xassert (STRINGP (it
->string
));
3729 it
->end_charpos
= SCHARS (it
->string
);
3730 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3731 it
->method
= next_element_from_string
;
3736 it
->current
.overlay_string_index
= -1;
3737 it
->method
= next_element_from_buffer
;
3742 /* Value is non-zero if we found at least one overlay string. */
3743 return STRINGP (it
->string
);
3748 /***********************************************************************
3749 Saving and restoring state
3750 ***********************************************************************/
3752 /* Save current settings of IT on IT->stack. Called, for example,
3753 before setting up IT for an overlay string, to be able to restore
3754 IT's settings to what they were after the overlay string has been
3761 struct iterator_stack_entry
*p
;
3763 xassert (it
->sp
< 2);
3764 p
= it
->stack
+ it
->sp
;
3766 p
->stop_charpos
= it
->stop_charpos
;
3767 xassert (it
->face_id
>= 0);
3768 p
->face_id
= it
->face_id
;
3769 p
->string
= it
->string
;
3770 p
->pos
= it
->current
;
3771 p
->end_charpos
= it
->end_charpos
;
3772 p
->string_nchars
= it
->string_nchars
;
3774 p
->multibyte_p
= it
->multibyte_p
;
3775 p
->space_width
= it
->space_width
;
3776 p
->font_height
= it
->font_height
;
3777 p
->voffset
= it
->voffset
;
3778 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3779 p
->display_ellipsis_p
= 0;
3784 /* Restore IT's settings from IT->stack. Called, for example, when no
3785 more overlay strings must be processed, and we return to delivering
3786 display elements from a buffer, or when the end of a string from a
3787 `display' property is reached and we return to delivering display
3788 elements from an overlay string, or from a buffer. */
3794 struct iterator_stack_entry
*p
;
3796 xassert (it
->sp
> 0);
3798 p
= it
->stack
+ it
->sp
;
3799 it
->stop_charpos
= p
->stop_charpos
;
3800 it
->face_id
= p
->face_id
;
3801 it
->string
= p
->string
;
3802 it
->current
= p
->pos
;
3803 it
->end_charpos
= p
->end_charpos
;
3804 it
->string_nchars
= p
->string_nchars
;
3806 it
->multibyte_p
= p
->multibyte_p
;
3807 it
->space_width
= p
->space_width
;
3808 it
->font_height
= p
->font_height
;
3809 it
->voffset
= p
->voffset
;
3810 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3815 /***********************************************************************
3817 ***********************************************************************/
3819 /* Set IT's current position to the previous line start. */
3822 back_to_previous_line_start (it
)
3825 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3826 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3830 /* Move IT to the next line start.
3832 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3833 we skipped over part of the text (as opposed to moving the iterator
3834 continuously over the text). Otherwise, don't change the value
3837 Newlines may come from buffer text, overlay strings, or strings
3838 displayed via the `display' property. That's the reason we can't
3839 simply use find_next_newline_no_quit.
3841 Note that this function may not skip over invisible text that is so
3842 because of text properties and immediately follows a newline. If
3843 it would, function reseat_at_next_visible_line_start, when called
3844 from set_iterator_to_next, would effectively make invisible
3845 characters following a newline part of the wrong glyph row, which
3846 leads to wrong cursor motion. */
3849 forward_to_next_line_start (it
, skipped_p
)
3853 int old_selective
, newline_found_p
, n
;
3854 const int MAX_NEWLINE_DISTANCE
= 500;
3856 /* If already on a newline, just consume it to avoid unintended
3857 skipping over invisible text below. */
3858 if (it
->what
== IT_CHARACTER
3860 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3862 set_iterator_to_next (it
, 0);
3867 /* Don't handle selective display in the following. It's (a)
3868 unnecessary because it's done by the caller, and (b) leads to an
3869 infinite recursion because next_element_from_ellipsis indirectly
3870 calls this function. */
3871 old_selective
= it
->selective
;
3874 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3875 from buffer text. */
3876 for (n
= newline_found_p
= 0;
3877 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3878 n
+= STRINGP (it
->string
) ? 0 : 1)
3880 if (!get_next_display_element (it
))
3882 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3883 set_iterator_to_next (it
, 0);
3886 /* If we didn't find a newline near enough, see if we can use a
3888 if (!newline_found_p
)
3890 int start
= IT_CHARPOS (*it
);
3891 int limit
= find_next_newline_no_quit (start
, 1);
3894 xassert (!STRINGP (it
->string
));
3896 /* If there isn't any `display' property in sight, and no
3897 overlays, we can just use the position of the newline in
3899 if (it
->stop_charpos
>= limit
3900 || ((pos
= Fnext_single_property_change (make_number (start
),
3902 Qnil
, make_number (limit
)),
3904 && next_overlay_change (start
) == ZV
))
3906 IT_CHARPOS (*it
) = limit
;
3907 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3908 *skipped_p
= newline_found_p
= 1;
3912 while (get_next_display_element (it
)
3913 && !newline_found_p
)
3915 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3916 set_iterator_to_next (it
, 0);
3921 it
->selective
= old_selective
;
3922 return newline_found_p
;
3926 /* Set IT's current position to the previous visible line start. Skip
3927 invisible text that is so either due to text properties or due to
3928 selective display. Caution: this does not change IT->current_x and
3932 back_to_previous_visible_line_start (it
)
3937 /* Go back one newline if not on BEGV already. */
3938 if (IT_CHARPOS (*it
) > BEGV
)
3939 back_to_previous_line_start (it
);
3941 /* Move over lines that are invisible because of selective display
3942 or text properties. */
3943 while (IT_CHARPOS (*it
) > BEGV
3948 /* If selective > 0, then lines indented more than that values
3950 if (it
->selective
> 0
3951 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3952 (double) it
->selective
)) /* iftc */
3958 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3959 Qinvisible
, it
->window
);
3960 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3964 /* Back one more newline if the current one is invisible. */
3966 back_to_previous_line_start (it
);
3969 xassert (IT_CHARPOS (*it
) >= BEGV
);
3970 xassert (IT_CHARPOS (*it
) == BEGV
3971 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3976 /* Reseat iterator IT at the previous visible line start. Skip
3977 invisible text that is so either due to text properties or due to
3978 selective display. At the end, update IT's overlay information,
3979 face information etc. */
3982 reseat_at_previous_visible_line_start (it
)
3985 back_to_previous_visible_line_start (it
);
3986 reseat (it
, it
->current
.pos
, 1);
3991 /* Reseat iterator IT on the next visible line start in the current
3992 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3993 preceding the line start. Skip over invisible text that is so
3994 because of selective display. Compute faces, overlays etc at the
3995 new position. Note that this function does not skip over text that
3996 is invisible because of text properties. */
3999 reseat_at_next_visible_line_start (it
, on_newline_p
)
4003 int newline_found_p
, skipped_p
= 0;
4005 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4007 /* Skip over lines that are invisible because they are indented
4008 more than the value of IT->selective. */
4009 if (it
->selective
> 0)
4010 while (IT_CHARPOS (*it
) < ZV
4011 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4012 (double) it
->selective
)) /* iftc */
4014 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4015 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4018 /* Position on the newline if that's what's requested. */
4019 if (on_newline_p
&& newline_found_p
)
4021 if (STRINGP (it
->string
))
4023 if (IT_STRING_CHARPOS (*it
) > 0)
4025 --IT_STRING_CHARPOS (*it
);
4026 --IT_STRING_BYTEPOS (*it
);
4029 else if (IT_CHARPOS (*it
) > BEGV
)
4033 reseat (it
, it
->current
.pos
, 0);
4037 reseat (it
, it
->current
.pos
, 0);
4044 /***********************************************************************
4045 Changing an iterator's position
4046 ***********************************************************************/
4048 /* Change IT's current position to POS in current_buffer. If FORCE_P
4049 is non-zero, always check for text properties at the new position.
4050 Otherwise, text properties are only looked up if POS >=
4051 IT->check_charpos of a property. */
4054 reseat (it
, pos
, force_p
)
4056 struct text_pos pos
;
4059 int original_pos
= IT_CHARPOS (*it
);
4061 reseat_1 (it
, pos
, 0);
4063 /* Determine where to check text properties. Avoid doing it
4064 where possible because text property lookup is very expensive. */
4066 || CHARPOS (pos
) > it
->stop_charpos
4067 || CHARPOS (pos
) < original_pos
)
4074 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4075 IT->stop_pos to POS, also. */
4078 reseat_1 (it
, pos
, set_stop_p
)
4080 struct text_pos pos
;
4083 /* Don't call this function when scanning a C string. */
4084 xassert (it
->s
== NULL
);
4086 /* POS must be a reasonable value. */
4087 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4089 it
->current
.pos
= it
->position
= pos
;
4090 XSETBUFFER (it
->object
, current_buffer
);
4091 it
->end_charpos
= ZV
;
4093 it
->current
.dpvec_index
= -1;
4094 it
->current
.overlay_string_index
= -1;
4095 IT_STRING_CHARPOS (*it
) = -1;
4096 IT_STRING_BYTEPOS (*it
) = -1;
4098 it
->method
= next_element_from_buffer
;
4099 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4101 it
->face_before_selective_p
= 0;
4104 it
->stop_charpos
= CHARPOS (pos
);
4108 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4109 If S is non-null, it is a C string to iterate over. Otherwise,
4110 STRING gives a Lisp string to iterate over.
4112 If PRECISION > 0, don't return more then PRECISION number of
4113 characters from the string.
4115 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4116 characters have been returned. FIELD_WIDTH < 0 means an infinite
4119 MULTIBYTE = 0 means disable processing of multibyte characters,
4120 MULTIBYTE > 0 means enable it,
4121 MULTIBYTE < 0 means use IT->multibyte_p.
4123 IT must be initialized via a prior call to init_iterator before
4124 calling this function. */
4127 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4132 int precision
, field_width
, multibyte
;
4134 /* No region in strings. */
4135 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4137 /* No text property checks performed by default, but see below. */
4138 it
->stop_charpos
= -1;
4140 /* Set iterator position and end position. */
4141 bzero (&it
->current
, sizeof it
->current
);
4142 it
->current
.overlay_string_index
= -1;
4143 it
->current
.dpvec_index
= -1;
4144 xassert (charpos
>= 0);
4146 /* If STRING is specified, use its multibyteness, otherwise use the
4147 setting of MULTIBYTE, if specified. */
4149 it
->multibyte_p
= multibyte
> 0;
4153 xassert (STRINGP (string
));
4154 it
->string
= string
;
4156 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4157 it
->method
= next_element_from_string
;
4158 it
->current
.string_pos
= string_pos (charpos
, string
);
4165 /* Note that we use IT->current.pos, not it->current.string_pos,
4166 for displaying C strings. */
4167 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4168 if (it
->multibyte_p
)
4170 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4171 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4175 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4176 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4179 it
->method
= next_element_from_c_string
;
4182 /* PRECISION > 0 means don't return more than PRECISION characters
4184 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4185 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4187 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4188 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4189 FIELD_WIDTH < 0 means infinite field width. This is useful for
4190 padding with `-' at the end of a mode line. */
4191 if (field_width
< 0)
4192 field_width
= INFINITY
;
4193 if (field_width
> it
->end_charpos
- charpos
)
4194 it
->end_charpos
= charpos
+ field_width
;
4196 /* Use the standard display table for displaying strings. */
4197 if (DISP_TABLE_P (Vstandard_display_table
))
4198 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4200 it
->stop_charpos
= charpos
;
4206 /***********************************************************************
4208 ***********************************************************************/
4210 /* Load IT's display element fields with information about the next
4211 display element from the current position of IT. Value is zero if
4212 end of buffer (or C string) is reached. */
4215 get_next_display_element (it
)
4218 /* Non-zero means that we found an display element. Zero means that
4219 we hit the end of what we iterate over. Performance note: the
4220 function pointer `method' used here turns out to be faster than
4221 using a sequence of if-statements. */
4222 int success_p
= (*it
->method
) (it
);
4224 if (it
->what
== IT_CHARACTER
)
4226 /* Map via display table or translate control characters.
4227 IT->c, IT->len etc. have been set to the next character by
4228 the function call above. If we have a display table, and it
4229 contains an entry for IT->c, translate it. Don't do this if
4230 IT->c itself comes from a display table, otherwise we could
4231 end up in an infinite recursion. (An alternative could be to
4232 count the recursion depth of this function and signal an
4233 error when a certain maximum depth is reached.) Is it worth
4235 if (success_p
&& it
->dpvec
== NULL
)
4240 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4243 struct Lisp_Vector
*v
= XVECTOR (dv
);
4245 /* Return the first character from the display table
4246 entry, if not empty. If empty, don't display the
4247 current character. */
4250 it
->dpvec_char_len
= it
->len
;
4251 it
->dpvec
= v
->contents
;
4252 it
->dpend
= v
->contents
+ v
->size
;
4253 it
->current
.dpvec_index
= 0;
4254 it
->method
= next_element_from_display_vector
;
4255 success_p
= get_next_display_element (it
);
4259 set_iterator_to_next (it
, 0);
4260 success_p
= get_next_display_element (it
);
4264 /* Translate control characters into `\003' or `^C' form.
4265 Control characters coming from a display table entry are
4266 currently not translated because we use IT->dpvec to hold
4267 the translation. This could easily be changed but I
4268 don't believe that it is worth doing.
4270 If it->multibyte_p is nonzero, eight-bit characters and
4271 non-printable multibyte characters are also translated to
4274 If it->multibyte_p is zero, eight-bit characters that
4275 don't have corresponding multibyte char code are also
4276 translated to octal form. */
4277 else if ((it
->c
< ' '
4278 && (it
->area
!= TEXT_AREA
4279 || (it
->c
!= '\n' && it
->c
!= '\t')))
4283 || !CHAR_PRINTABLE_P (it
->c
))
4285 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4287 /* IT->c is a control character which must be displayed
4288 either as '\003' or as `^C' where the '\\' and '^'
4289 can be defined in the display table. Fill
4290 IT->ctl_chars with glyphs for what we have to
4291 display. Then, set IT->dpvec to these glyphs. */
4294 if (it
->c
< 128 && it
->ctl_arrow_p
)
4296 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4298 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4299 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4300 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4302 g
= FAST_MAKE_GLYPH ('^', 0);
4303 XSETINT (it
->ctl_chars
[0], g
);
4305 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4306 XSETINT (it
->ctl_chars
[1], g
);
4308 /* Set up IT->dpvec and return first character from it. */
4309 it
->dpvec_char_len
= it
->len
;
4310 it
->dpvec
= it
->ctl_chars
;
4311 it
->dpend
= it
->dpvec
+ 2;
4312 it
->current
.dpvec_index
= 0;
4313 it
->method
= next_element_from_display_vector
;
4314 get_next_display_element (it
);
4318 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4323 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4325 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4326 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4327 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4329 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4331 if (SINGLE_BYTE_CHAR_P (it
->c
))
4332 str
[0] = it
->c
, len
= 1;
4335 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4338 /* It's an invalid character, which
4339 shouldn't happen actually, but due to
4340 bugs it may happen. Let's print the char
4341 as is, there's not much meaningful we can
4344 str
[1] = it
->c
>> 8;
4345 str
[2] = it
->c
>> 16;
4346 str
[3] = it
->c
>> 24;
4351 for (i
= 0; i
< len
; i
++)
4353 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4354 /* Insert three more glyphs into IT->ctl_chars for
4355 the octal display of the character. */
4356 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4357 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4358 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4359 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4360 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4361 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4364 /* Set up IT->dpvec and return the first character
4366 it
->dpvec_char_len
= it
->len
;
4367 it
->dpvec
= it
->ctl_chars
;
4368 it
->dpend
= it
->dpvec
+ len
* 4;
4369 it
->current
.dpvec_index
= 0;
4370 it
->method
= next_element_from_display_vector
;
4371 get_next_display_element (it
);
4376 /* Adjust face id for a multibyte character. There are no
4377 multibyte character in unibyte text. */
4380 && FRAME_WINDOW_P (it
->f
))
4382 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4383 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4387 /* Is this character the last one of a run of characters with
4388 box? If yes, set IT->end_of_box_run_p to 1. */
4395 it
->end_of_box_run_p
4396 = ((face_id
= face_after_it_pos (it
),
4397 face_id
!= it
->face_id
)
4398 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4399 face
->box
== FACE_NO_BOX
));
4402 /* Value is 0 if end of buffer or string reached. */
4407 /* Move IT to the next display element.
4409 RESEAT_P non-zero means if called on a newline in buffer text,
4410 skip to the next visible line start.
4412 Functions get_next_display_element and set_iterator_to_next are
4413 separate because I find this arrangement easier to handle than a
4414 get_next_display_element function that also increments IT's
4415 position. The way it is we can first look at an iterator's current
4416 display element, decide whether it fits on a line, and if it does,
4417 increment the iterator position. The other way around we probably
4418 would either need a flag indicating whether the iterator has to be
4419 incremented the next time, or we would have to implement a
4420 decrement position function which would not be easy to write. */
4423 set_iterator_to_next (it
, reseat_p
)
4427 /* Reset flags indicating start and end of a sequence of characters
4428 with box. Reset them at the start of this function because
4429 moving the iterator to a new position might set them. */
4430 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4432 if (it
->method
== next_element_from_buffer
)
4434 /* The current display element of IT is a character from
4435 current_buffer. Advance in the buffer, and maybe skip over
4436 invisible lines that are so because of selective display. */
4437 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4438 reseat_at_next_visible_line_start (it
, 0);
4441 xassert (it
->len
!= 0);
4442 IT_BYTEPOS (*it
) += it
->len
;
4443 IT_CHARPOS (*it
) += 1;
4444 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4447 else if (it
->method
== next_element_from_composition
)
4449 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4450 if (STRINGP (it
->string
))
4452 IT_STRING_BYTEPOS (*it
) += it
->len
;
4453 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4454 it
->method
= next_element_from_string
;
4455 goto consider_string_end
;
4459 IT_BYTEPOS (*it
) += it
->len
;
4460 IT_CHARPOS (*it
) += it
->cmp_len
;
4461 it
->method
= next_element_from_buffer
;
4464 else if (it
->method
== next_element_from_c_string
)
4466 /* Current display element of IT is from a C string. */
4467 IT_BYTEPOS (*it
) += it
->len
;
4468 IT_CHARPOS (*it
) += 1;
4470 else if (it
->method
== next_element_from_display_vector
)
4472 /* Current display element of IT is from a display table entry.
4473 Advance in the display table definition. Reset it to null if
4474 end reached, and continue with characters from buffers/
4476 ++it
->current
.dpvec_index
;
4478 /* Restore face of the iterator to what they were before the
4479 display vector entry (these entries may contain faces). */
4480 it
->face_id
= it
->saved_face_id
;
4482 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4485 it
->method
= next_element_from_c_string
;
4486 else if (STRINGP (it
->string
))
4487 it
->method
= next_element_from_string
;
4489 it
->method
= next_element_from_buffer
;
4492 it
->current
.dpvec_index
= -1;
4494 /* Skip over characters which were displayed via IT->dpvec. */
4495 if (it
->dpvec_char_len
< 0)
4496 reseat_at_next_visible_line_start (it
, 1);
4497 else if (it
->dpvec_char_len
> 0)
4499 it
->len
= it
->dpvec_char_len
;
4500 set_iterator_to_next (it
, reseat_p
);
4504 else if (it
->method
== next_element_from_string
)
4506 /* Current display element is a character from a Lisp string. */
4507 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4508 IT_STRING_BYTEPOS (*it
) += it
->len
;
4509 IT_STRING_CHARPOS (*it
) += 1;
4511 consider_string_end
:
4513 if (it
->current
.overlay_string_index
>= 0)
4515 /* IT->string is an overlay string. Advance to the
4516 next, if there is one. */
4517 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4518 next_overlay_string (it
);
4522 /* IT->string is not an overlay string. If we reached
4523 its end, and there is something on IT->stack, proceed
4524 with what is on the stack. This can be either another
4525 string, this time an overlay string, or a buffer. */
4526 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
4530 if (!STRINGP (it
->string
))
4531 it
->method
= next_element_from_buffer
;
4533 goto consider_string_end
;
4537 else if (it
->method
== next_element_from_image
4538 || it
->method
== next_element_from_stretch
)
4540 /* The position etc with which we have to proceed are on
4541 the stack. The position may be at the end of a string,
4542 if the `display' property takes up the whole string. */
4545 if (STRINGP (it
->string
))
4547 it
->method
= next_element_from_string
;
4548 goto consider_string_end
;
4551 it
->method
= next_element_from_buffer
;
4554 /* There are no other methods defined, so this should be a bug. */
4557 xassert (it
->method
!= next_element_from_string
4558 || (STRINGP (it
->string
)
4559 && IT_STRING_CHARPOS (*it
) >= 0));
4563 /* Load IT's display element fields with information about the next
4564 display element which comes from a display table entry or from the
4565 result of translating a control character to one of the forms `^C'
4566 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4569 next_element_from_display_vector (it
)
4573 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4575 /* Remember the current face id in case glyphs specify faces.
4576 IT's face is restored in set_iterator_to_next. */
4577 it
->saved_face_id
= it
->face_id
;
4579 if (INTEGERP (*it
->dpvec
)
4580 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4585 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4586 it
->c
= FAST_GLYPH_CHAR (g
);
4587 it
->len
= CHAR_BYTES (it
->c
);
4589 /* The entry may contain a face id to use. Such a face id is
4590 the id of a Lisp face, not a realized face. A face id of
4591 zero means no face is specified. */
4592 lface_id
= FAST_GLYPH_FACE (g
);
4595 /* The function returns -1 if lface_id is invalid. */
4596 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4598 it
->face_id
= face_id
;
4602 /* Display table entry is invalid. Return a space. */
4603 it
->c
= ' ', it
->len
= 1;
4605 /* Don't change position and object of the iterator here. They are
4606 still the values of the character that had this display table
4607 entry or was translated, and that's what we want. */
4608 it
->what
= IT_CHARACTER
;
4613 /* Load IT with the next display element from Lisp string IT->string.
4614 IT->current.string_pos is the current position within the string.
4615 If IT->current.overlay_string_index >= 0, the Lisp string is an
4619 next_element_from_string (it
)
4622 struct text_pos position
;
4624 xassert (STRINGP (it
->string
));
4625 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4626 position
= it
->current
.string_pos
;
4628 /* Time to check for invisible text? */
4629 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4630 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4634 /* Since a handler may have changed IT->method, we must
4636 return get_next_display_element (it
);
4639 if (it
->current
.overlay_string_index
>= 0)
4641 /* Get the next character from an overlay string. In overlay
4642 strings, There is no field width or padding with spaces to
4644 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4649 else if (STRING_MULTIBYTE (it
->string
))
4651 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4652 const unsigned char *s
= (SDATA (it
->string
)
4653 + IT_STRING_BYTEPOS (*it
));
4654 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4658 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4664 /* Get the next character from a Lisp string that is not an
4665 overlay string. Such strings come from the mode line, for
4666 example. We may have to pad with spaces, or truncate the
4667 string. See also next_element_from_c_string. */
4668 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4673 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4675 /* Pad with spaces. */
4676 it
->c
= ' ', it
->len
= 1;
4677 CHARPOS (position
) = BYTEPOS (position
) = -1;
4679 else if (STRING_MULTIBYTE (it
->string
))
4681 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4682 const unsigned char *s
= (SDATA (it
->string
)
4683 + IT_STRING_BYTEPOS (*it
));
4684 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4688 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4693 /* Record what we have and where it came from. Note that we store a
4694 buffer position in IT->position although it could arguably be a
4696 it
->what
= IT_CHARACTER
;
4697 it
->object
= it
->string
;
4698 it
->position
= position
;
4703 /* Load IT with next display element from C string IT->s.
4704 IT->string_nchars is the maximum number of characters to return
4705 from the string. IT->end_charpos may be greater than
4706 IT->string_nchars when this function is called, in which case we
4707 may have to return padding spaces. Value is zero if end of string
4708 reached, including padding spaces. */
4711 next_element_from_c_string (it
)
4717 it
->what
= IT_CHARACTER
;
4718 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4721 /* IT's position can be greater IT->string_nchars in case a field
4722 width or precision has been specified when the iterator was
4724 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4726 /* End of the game. */
4730 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4732 /* Pad with spaces. */
4733 it
->c
= ' ', it
->len
= 1;
4734 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4736 else if (it
->multibyte_p
)
4738 /* Implementation note: The calls to strlen apparently aren't a
4739 performance problem because there is no noticeable performance
4740 difference between Emacs running in unibyte or multibyte mode. */
4741 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4742 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4746 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4752 /* Set up IT to return characters from an ellipsis, if appropriate.
4753 The definition of the ellipsis glyphs may come from a display table
4754 entry. This function Fills IT with the first glyph from the
4755 ellipsis if an ellipsis is to be displayed. */
4758 next_element_from_ellipsis (it
)
4761 if (it
->selective_display_ellipsis_p
)
4763 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4765 /* Use the display table definition for `...'. Invalid glyphs
4766 will be handled by the method returning elements from dpvec. */
4767 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4768 it
->dpvec_char_len
= it
->len
;
4769 it
->dpvec
= v
->contents
;
4770 it
->dpend
= v
->contents
+ v
->size
;
4771 it
->current
.dpvec_index
= 0;
4772 it
->method
= next_element_from_display_vector
;
4776 /* Use default `...' which is stored in default_invis_vector. */
4777 it
->dpvec_char_len
= it
->len
;
4778 it
->dpvec
= default_invis_vector
;
4779 it
->dpend
= default_invis_vector
+ 3;
4780 it
->current
.dpvec_index
= 0;
4781 it
->method
= next_element_from_display_vector
;
4786 /* The face at the current position may be different from the
4787 face we find after the invisible text. Remember what it
4788 was in IT->saved_face_id, and signal that it's there by
4789 setting face_before_selective_p. */
4790 it
->saved_face_id
= it
->face_id
;
4791 it
->method
= next_element_from_buffer
;
4792 reseat_at_next_visible_line_start (it
, 1);
4793 it
->face_before_selective_p
= 1;
4796 return get_next_display_element (it
);
4800 /* Deliver an image display element. The iterator IT is already
4801 filled with image information (done in handle_display_prop). Value
4806 next_element_from_image (it
)
4809 it
->what
= IT_IMAGE
;
4814 /* Fill iterator IT with next display element from a stretch glyph
4815 property. IT->object is the value of the text property. Value is
4819 next_element_from_stretch (it
)
4822 it
->what
= IT_STRETCH
;
4827 /* Load IT with the next display element from current_buffer. Value
4828 is zero if end of buffer reached. IT->stop_charpos is the next
4829 position at which to stop and check for text properties or buffer
4833 next_element_from_buffer (it
)
4838 /* Check this assumption, otherwise, we would never enter the
4839 if-statement, below. */
4840 xassert (IT_CHARPOS (*it
) >= BEGV
4841 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4843 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4845 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4847 int overlay_strings_follow_p
;
4849 /* End of the game, except when overlay strings follow that
4850 haven't been returned yet. */
4851 if (it
->overlay_strings_at_end_processed_p
)
4852 overlay_strings_follow_p
= 0;
4855 it
->overlay_strings_at_end_processed_p
= 1;
4856 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4859 if (overlay_strings_follow_p
)
4860 success_p
= get_next_display_element (it
);
4864 it
->position
= it
->current
.pos
;
4871 return get_next_display_element (it
);
4876 /* No face changes, overlays etc. in sight, so just return a
4877 character from current_buffer. */
4880 /* Maybe run the redisplay end trigger hook. Performance note:
4881 This doesn't seem to cost measurable time. */
4882 if (it
->redisplay_end_trigger_charpos
4884 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4885 run_redisplay_end_trigger_hook (it
);
4887 /* Get the next character, maybe multibyte. */
4888 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4889 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4891 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4892 - IT_BYTEPOS (*it
));
4893 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4896 it
->c
= *p
, it
->len
= 1;
4898 /* Record what we have and where it came from. */
4899 it
->what
= IT_CHARACTER
;;
4900 it
->object
= it
->w
->buffer
;
4901 it
->position
= it
->current
.pos
;
4903 /* Normally we return the character found above, except when we
4904 really want to return an ellipsis for selective display. */
4909 /* A value of selective > 0 means hide lines indented more
4910 than that number of columns. */
4911 if (it
->selective
> 0
4912 && IT_CHARPOS (*it
) + 1 < ZV
4913 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4914 IT_BYTEPOS (*it
) + 1,
4915 (double) it
->selective
)) /* iftc */
4917 success_p
= next_element_from_ellipsis (it
);
4918 it
->dpvec_char_len
= -1;
4921 else if (it
->c
== '\r' && it
->selective
== -1)
4923 /* A value of selective == -1 means that everything from the
4924 CR to the end of the line is invisible, with maybe an
4925 ellipsis displayed for it. */
4926 success_p
= next_element_from_ellipsis (it
);
4927 it
->dpvec_char_len
= -1;
4932 /* Value is zero if end of buffer reached. */
4933 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4938 /* Run the redisplay end trigger hook for IT. */
4941 run_redisplay_end_trigger_hook (it
)
4944 Lisp_Object args
[3];
4946 /* IT->glyph_row should be non-null, i.e. we should be actually
4947 displaying something, or otherwise we should not run the hook. */
4948 xassert (it
->glyph_row
);
4950 /* Set up hook arguments. */
4951 args
[0] = Qredisplay_end_trigger_functions
;
4952 args
[1] = it
->window
;
4953 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4954 it
->redisplay_end_trigger_charpos
= 0;
4956 /* Since we are *trying* to run these functions, don't try to run
4957 them again, even if they get an error. */
4958 it
->w
->redisplay_end_trigger
= Qnil
;
4959 Frun_hook_with_args (3, args
);
4961 /* Notice if it changed the face of the character we are on. */
4962 handle_face_prop (it
);
4966 /* Deliver a composition display element. The iterator IT is already
4967 filled with composition information (done in
4968 handle_composition_prop). Value is always 1. */
4971 next_element_from_composition (it
)
4974 it
->what
= IT_COMPOSITION
;
4975 it
->position
= (STRINGP (it
->string
)
4976 ? it
->current
.string_pos
4983 /***********************************************************************
4984 Moving an iterator without producing glyphs
4985 ***********************************************************************/
4987 /* Move iterator IT to a specified buffer or X position within one
4988 line on the display without producing glyphs.
4990 OP should be a bit mask including some or all of these bits:
4991 MOVE_TO_X: Stop on reaching x-position TO_X.
4992 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
4993 Regardless of OP's value, stop in reaching the end of the display line.
4995 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
4996 This means, in particular, that TO_X includes window's horizontal
4999 The return value has several possible values that
5000 say what condition caused the scan to stop:
5002 MOVE_POS_MATCH_OR_ZV
5003 - when TO_POS or ZV was reached.
5006 -when TO_X was reached before TO_POS or ZV were reached.
5009 - when we reached the end of the display area and the line must
5013 - when we reached the end of the display area and the line is
5017 - when we stopped at a line end, i.e. a newline or a CR and selective
5020 static enum move_it_result
5021 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5023 int to_charpos
, to_x
, op
;
5025 enum move_it_result result
= MOVE_UNDEFINED
;
5026 struct glyph_row
*saved_glyph_row
;
5028 /* Don't produce glyphs in produce_glyphs. */
5029 saved_glyph_row
= it
->glyph_row
;
5030 it
->glyph_row
= NULL
;
5034 int x
, i
, ascent
= 0, descent
= 0;
5036 /* Stop when ZV or TO_CHARPOS reached. */
5037 if (!get_next_display_element (it
)
5038 || ((op
& MOVE_TO_POS
) != 0
5039 && BUFFERP (it
->object
)
5040 && IT_CHARPOS (*it
) >= to_charpos
))
5042 result
= MOVE_POS_MATCH_OR_ZV
;
5046 /* The call to produce_glyphs will get the metrics of the
5047 display element IT is loaded with. We record in x the
5048 x-position before this display element in case it does not
5052 /* Remember the line height so far in case the next element doesn't
5054 if (!it
->truncate_lines_p
)
5056 ascent
= it
->max_ascent
;
5057 descent
= it
->max_descent
;
5060 PRODUCE_GLYPHS (it
);
5062 if (it
->area
!= TEXT_AREA
)
5064 set_iterator_to_next (it
, 1);
5068 /* The number of glyphs we get back in IT->nglyphs will normally
5069 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5070 character on a terminal frame, or (iii) a line end. For the
5071 second case, IT->nglyphs - 1 padding glyphs will be present
5072 (on X frames, there is only one glyph produced for a
5073 composite character.
5075 The behavior implemented below means, for continuation lines,
5076 that as many spaces of a TAB as fit on the current line are
5077 displayed there. For terminal frames, as many glyphs of a
5078 multi-glyph character are displayed in the current line, too.
5079 This is what the old redisplay code did, and we keep it that
5080 way. Under X, the whole shape of a complex character must
5081 fit on the line or it will be completely displayed in the
5084 Note that both for tabs and padding glyphs, all glyphs have
5088 /* More than one glyph or glyph doesn't fit on line. All
5089 glyphs have the same width. */
5090 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5093 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5095 new_x
= x
+ single_glyph_width
;
5097 /* We want to leave anything reaching TO_X to the caller. */
5098 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5101 result
= MOVE_X_REACHED
;
5104 else if (/* Lines are continued. */
5105 !it
->truncate_lines_p
5106 && (/* And glyph doesn't fit on the line. */
5107 new_x
> it
->last_visible_x
5108 /* Or it fits exactly and we're on a window
5110 || (new_x
== it
->last_visible_x
5111 && FRAME_WINDOW_P (it
->f
))))
5113 if (/* IT->hpos == 0 means the very first glyph
5114 doesn't fit on the line, e.g. a wide image. */
5116 || (new_x
== it
->last_visible_x
5117 && FRAME_WINDOW_P (it
->f
)))
5120 it
->current_x
= new_x
;
5121 if (i
== it
->nglyphs
- 1)
5122 set_iterator_to_next (it
, 1);
5127 it
->max_ascent
= ascent
;
5128 it
->max_descent
= descent
;
5131 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5133 result
= MOVE_LINE_CONTINUED
;
5136 else if (new_x
> it
->first_visible_x
)
5138 /* Glyph is visible. Increment number of glyphs that
5139 would be displayed. */
5144 /* Glyph is completely off the left margin of the display
5145 area. Nothing to do. */
5149 if (result
!= MOVE_UNDEFINED
)
5152 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5154 /* Stop when TO_X specified and reached. This check is
5155 necessary here because of lines consisting of a line end,
5156 only. The line end will not produce any glyphs and we
5157 would never get MOVE_X_REACHED. */
5158 xassert (it
->nglyphs
== 0);
5159 result
= MOVE_X_REACHED
;
5163 /* Is this a line end? If yes, we're done. */
5164 if (ITERATOR_AT_END_OF_LINE_P (it
))
5166 result
= MOVE_NEWLINE_OR_CR
;
5170 /* The current display element has been consumed. Advance
5172 set_iterator_to_next (it
, 1);
5174 /* Stop if lines are truncated and IT's current x-position is
5175 past the right edge of the window now. */
5176 if (it
->truncate_lines_p
5177 && it
->current_x
>= it
->last_visible_x
)
5179 result
= MOVE_LINE_TRUNCATED
;
5184 /* Restore the iterator settings altered at the beginning of this
5186 it
->glyph_row
= saved_glyph_row
;
5191 /* Move IT forward until it satisfies one or more of the criteria in
5192 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5194 OP is a bit-mask that specifies where to stop, and in particular,
5195 which of those four position arguments makes a difference. See the
5196 description of enum move_operation_enum.
5198 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5199 screen line, this function will set IT to the next position >
5203 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5205 int to_charpos
, to_x
, to_y
, to_vpos
;
5208 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5214 if (op
& MOVE_TO_VPOS
)
5216 /* If no TO_CHARPOS and no TO_X specified, stop at the
5217 start of the line TO_VPOS. */
5218 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5220 if (it
->vpos
== to_vpos
)
5226 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5230 /* TO_VPOS >= 0 means stop at TO_X in the line at
5231 TO_VPOS, or at TO_POS, whichever comes first. */
5232 if (it
->vpos
== to_vpos
)
5238 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5240 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5245 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5247 /* We have reached TO_X but not in the line we want. */
5248 skip
= move_it_in_display_line_to (it
, to_charpos
,
5250 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5258 else if (op
& MOVE_TO_Y
)
5260 struct it it_backup
;
5262 /* TO_Y specified means stop at TO_X in the line containing
5263 TO_Y---or at TO_CHARPOS if this is reached first. The
5264 problem is that we can't really tell whether the line
5265 contains TO_Y before we have completely scanned it, and
5266 this may skip past TO_X. What we do is to first scan to
5269 If TO_X is not specified, use a TO_X of zero. The reason
5270 is to make the outcome of this function more predictable.
5271 If we didn't use TO_X == 0, we would stop at the end of
5272 the line which is probably not what a caller would expect
5274 skip
= move_it_in_display_line_to (it
, to_charpos
,
5278 | (op
& MOVE_TO_POS
)));
5280 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5281 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5287 /* If TO_X was reached, we would like to know whether TO_Y
5288 is in the line. This can only be said if we know the
5289 total line height which requires us to scan the rest of
5291 if (skip
== MOVE_X_REACHED
)
5294 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5295 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5297 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5300 /* Now, decide whether TO_Y is in this line. */
5301 line_height
= it
->max_ascent
+ it
->max_descent
;
5302 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5304 if (to_y
>= it
->current_y
5305 && to_y
< it
->current_y
+ line_height
)
5307 if (skip
== MOVE_X_REACHED
)
5308 /* If TO_Y is in this line and TO_X was reached above,
5309 we scanned too far. We have to restore IT's settings
5310 to the ones before skipping. */
5314 else if (skip
== MOVE_X_REACHED
)
5317 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5325 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5329 case MOVE_POS_MATCH_OR_ZV
:
5333 case MOVE_NEWLINE_OR_CR
:
5334 set_iterator_to_next (it
, 1);
5335 it
->continuation_lines_width
= 0;
5338 case MOVE_LINE_TRUNCATED
:
5339 it
->continuation_lines_width
= 0;
5340 reseat_at_next_visible_line_start (it
, 0);
5341 if ((op
& MOVE_TO_POS
) != 0
5342 && IT_CHARPOS (*it
) > to_charpos
)
5349 case MOVE_LINE_CONTINUED
:
5350 it
->continuation_lines_width
+= it
->current_x
;
5357 /* Reset/increment for the next run. */
5358 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5359 it
->current_x
= it
->hpos
= 0;
5360 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5362 last_height
= it
->max_ascent
+ it
->max_descent
;
5363 last_max_ascent
= it
->max_ascent
;
5364 it
->max_ascent
= it
->max_descent
= 0;
5369 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5373 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5375 If DY > 0, move IT backward at least that many pixels. DY = 0
5376 means move IT backward to the preceding line start or BEGV. This
5377 function may move over more than DY pixels if IT->current_y - DY
5378 ends up in the middle of a line; in this case IT->current_y will be
5379 set to the top of the line moved to. */
5382 move_it_vertically_backward (it
, dy
)
5388 int start_pos
= IT_CHARPOS (*it
);
5392 /* Estimate how many newlines we must move back. */
5393 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5395 /* Set the iterator's position that many lines back. */
5396 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5397 back_to_previous_visible_line_start (it
);
5399 /* Reseat the iterator here. When moving backward, we don't want
5400 reseat to skip forward over invisible text, set up the iterator
5401 to deliver from overlay strings at the new position etc. So,
5402 use reseat_1 here. */
5403 reseat_1 (it
, it
->current
.pos
, 1);
5405 /* We are now surely at a line start. */
5406 it
->current_x
= it
->hpos
= 0;
5408 /* Move forward and see what y-distance we moved. First move to the
5409 start of the next line so that we get its height. We need this
5410 height to be able to tell whether we reached the specified
5413 it2
.max_ascent
= it2
.max_descent
= 0;
5414 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5415 MOVE_TO_POS
| MOVE_TO_VPOS
);
5416 xassert (IT_CHARPOS (*it
) >= BEGV
);
5419 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5420 xassert (IT_CHARPOS (*it
) >= BEGV
);
5421 h
= it2
.current_y
- it
->current_y
;
5422 nlines
= it2
.vpos
- it
->vpos
;
5424 /* Correct IT's y and vpos position. */
5430 /* DY == 0 means move to the start of the screen line. The
5431 value of nlines is > 0 if continuation lines were involved. */
5433 move_it_by_lines (it
, nlines
, 1);
5434 xassert (IT_CHARPOS (*it
) <= start_pos
);
5438 /* The y-position we try to reach. Note that h has been
5439 subtracted in front of the if-statement. */
5440 int target_y
= it
->current_y
+ h
- dy
;
5441 int y0
= it3
.current_y
;
5442 int y1
= line_bottom_y (&it3
);
5443 int line_height
= y1
- y0
;
5445 /* If we did not reach target_y, try to move further backward if
5446 we can. If we moved too far backward, try to move forward. */
5447 if (target_y
< it
->current_y
5448 /* This is heuristic. In a window that's 3 lines high, with
5449 a line height of 13 pixels each, recentering with point
5450 on the bottom line will try to move -39/2 = 19 pixels
5451 backward. Try to avoid moving into the first line. */
5452 && it
->current_y
- target_y
> line_height
/ 3 * 2
5453 && IT_CHARPOS (*it
) > BEGV
)
5455 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5456 target_y
- it
->current_y
));
5457 move_it_vertically (it
, target_y
- it
->current_y
);
5458 xassert (IT_CHARPOS (*it
) >= BEGV
);
5460 else if (target_y
>= it
->current_y
+ line_height
5461 && IT_CHARPOS (*it
) < ZV
)
5463 /* Should move forward by at least one line, maybe more.
5465 Note: Calling move_it_by_lines can be expensive on
5466 terminal frames, where compute_motion is used (via
5467 vmotion) to do the job, when there are very long lines
5468 and truncate-lines is nil. That's the reason for
5469 treating terminal frames specially here. */
5471 if (!FRAME_WINDOW_P (it
->f
))
5472 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5477 move_it_by_lines (it
, 1, 1);
5479 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5482 xassert (IT_CHARPOS (*it
) >= BEGV
);
5488 /* Move IT by a specified amount of pixel lines DY. DY negative means
5489 move backwards. DY = 0 means move to start of screen line. At the
5490 end, IT will be on the start of a screen line. */
5493 move_it_vertically (it
, dy
)
5498 move_it_vertically_backward (it
, -dy
);
5501 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5502 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5503 MOVE_TO_POS
| MOVE_TO_Y
);
5504 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5506 /* If buffer ends in ZV without a newline, move to the start of
5507 the line to satisfy the post-condition. */
5508 if (IT_CHARPOS (*it
) == ZV
5509 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5510 move_it_by_lines (it
, 0, 0);
5515 /* Move iterator IT past the end of the text line it is in. */
5518 move_it_past_eol (it
)
5521 enum move_it_result rc
;
5523 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5524 if (rc
== MOVE_NEWLINE_OR_CR
)
5525 set_iterator_to_next (it
, 0);
5529 #if 0 /* Currently not used. */
5531 /* Return non-zero if some text between buffer positions START_CHARPOS
5532 and END_CHARPOS is invisible. IT->window is the window for text
5536 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5538 int start_charpos
, end_charpos
;
5540 Lisp_Object prop
, limit
;
5541 int invisible_found_p
;
5543 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5545 /* Is text at START invisible? */
5546 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5548 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5549 invisible_found_p
= 1;
5552 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5554 make_number (end_charpos
));
5555 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5558 return invisible_found_p
;
5564 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5565 negative means move up. DVPOS == 0 means move to the start of the
5566 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5567 NEED_Y_P is zero, IT->current_y will be left unchanged.
5569 Further optimization ideas: If we would know that IT->f doesn't use
5570 a face with proportional font, we could be faster for
5571 truncate-lines nil. */
5574 move_it_by_lines (it
, dvpos
, need_y_p
)
5576 int dvpos
, need_y_p
;
5578 struct position pos
;
5580 if (!FRAME_WINDOW_P (it
->f
))
5582 struct text_pos textpos
;
5584 /* We can use vmotion on frames without proportional fonts. */
5585 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5586 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5587 reseat (it
, textpos
, 1);
5588 it
->vpos
+= pos
.vpos
;
5589 it
->current_y
+= pos
.vpos
;
5591 else if (dvpos
== 0)
5593 /* DVPOS == 0 means move to the start of the screen line. */
5594 move_it_vertically_backward (it
, 0);
5595 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5598 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5602 int start_charpos
, i
;
5604 /* Start at the beginning of the screen line containing IT's
5606 move_it_vertically_backward (it
, 0);
5608 /* Go back -DVPOS visible lines and reseat the iterator there. */
5609 start_charpos
= IT_CHARPOS (*it
);
5610 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5611 back_to_previous_visible_line_start (it
);
5612 reseat (it
, it
->current
.pos
, 1);
5613 it
->current_x
= it
->hpos
= 0;
5615 /* Above call may have moved too far if continuation lines
5616 are involved. Scan forward and see if it did. */
5618 it2
.vpos
= it2
.current_y
= 0;
5619 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5620 it
->vpos
-= it2
.vpos
;
5621 it
->current_y
-= it2
.current_y
;
5622 it
->current_x
= it
->hpos
= 0;
5624 /* If we moved too far, move IT some lines forward. */
5625 if (it2
.vpos
> -dvpos
)
5627 int delta
= it2
.vpos
+ dvpos
;
5628 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5635 /***********************************************************************
5637 ***********************************************************************/
5640 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5644 add_to_log (format
, arg1
, arg2
)
5646 Lisp_Object arg1
, arg2
;
5648 Lisp_Object args
[3];
5649 Lisp_Object msg
, fmt
;
5652 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5654 /* Do nothing if called asynchronously. Inserting text into
5655 a buffer may call after-change-functions and alike and
5656 that would means running Lisp asynchronously. */
5657 if (handling_signal
)
5661 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5663 args
[0] = fmt
= build_string (format
);
5666 msg
= Fformat (3, args
);
5668 len
= SBYTES (msg
) + 1;
5669 buffer
= (char *) alloca (len
);
5670 bcopy (SDATA (msg
), buffer
, len
);
5672 message_dolog (buffer
, len
- 1, 1, 0);
5677 /* Output a newline in the *Messages* buffer if "needs" one. */
5680 message_log_maybe_newline ()
5682 if (message_log_need_newline
)
5683 message_dolog ("", 0, 1, 0);
5687 /* Add a string M of length NBYTES to the message log, optionally
5688 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5689 nonzero, means interpret the contents of M as multibyte. This
5690 function calls low-level routines in order to bypass text property
5691 hooks, etc. which might not be safe to run. */
5694 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5696 int nbytes
, nlflag
, multibyte
;
5698 if (!NILP (Vmemory_full
))
5701 if (!NILP (Vmessage_log_max
))
5703 struct buffer
*oldbuf
;
5704 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5705 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5706 int point_at_end
= 0;
5708 Lisp_Object old_deactivate_mark
, tem
;
5709 struct gcpro gcpro1
;
5711 old_deactivate_mark
= Vdeactivate_mark
;
5712 oldbuf
= current_buffer
;
5713 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5714 current_buffer
->undo_list
= Qt
;
5716 oldpoint
= message_dolog_marker1
;
5717 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
5718 oldbegv
= message_dolog_marker2
;
5719 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
5720 oldzv
= message_dolog_marker3
;
5721 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
5722 GCPRO1 (old_deactivate_mark
);
5730 BEGV_BYTE
= BEG_BYTE
;
5733 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5735 /* Insert the string--maybe converting multibyte to single byte
5736 or vice versa, so that all the text fits the buffer. */
5738 && NILP (current_buffer
->enable_multibyte_characters
))
5740 int i
, c
, char_bytes
;
5741 unsigned char work
[1];
5743 /* Convert a multibyte string to single-byte
5744 for the *Message* buffer. */
5745 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5747 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5748 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5750 : multibyte_char_to_unibyte (c
, Qnil
));
5751 insert_1_both (work
, 1, 1, 1, 0, 0);
5754 else if (! multibyte
5755 && ! NILP (current_buffer
->enable_multibyte_characters
))
5757 int i
, c
, char_bytes
;
5758 unsigned char *msg
= (unsigned char *) m
;
5759 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5760 /* Convert a single-byte string to multibyte
5761 for the *Message* buffer. */
5762 for (i
= 0; i
< nbytes
; i
++)
5764 c
= unibyte_char_to_multibyte (msg
[i
]);
5765 char_bytes
= CHAR_STRING (c
, str
);
5766 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5770 insert_1 (m
, nbytes
, 1, 0, 0);
5774 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5775 insert_1 ("\n", 1, 1, 0, 0);
5777 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5779 this_bol_byte
= PT_BYTE
;
5781 /* See if this line duplicates the previous one.
5782 If so, combine duplicates. */
5785 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5787 prev_bol_byte
= PT_BYTE
;
5789 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5790 this_bol
, this_bol_byte
);
5793 del_range_both (prev_bol
, prev_bol_byte
,
5794 this_bol
, this_bol_byte
, 0);
5800 /* If you change this format, don't forget to also
5801 change message_log_check_duplicate. */
5802 sprintf (dupstr
, " [%d times]", dup
);
5803 duplen
= strlen (dupstr
);
5804 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5805 insert_1 (dupstr
, duplen
, 1, 0, 1);
5810 /* If we have more than the desired maximum number of lines
5811 in the *Messages* buffer now, delete the oldest ones.
5812 This is safe because we don't have undo in this buffer. */
5814 if (NATNUMP (Vmessage_log_max
))
5816 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5817 -XFASTINT (Vmessage_log_max
) - 1, 0);
5818 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5821 BEGV
= XMARKER (oldbegv
)->charpos
;
5822 BEGV_BYTE
= marker_byte_position (oldbegv
);
5831 ZV
= XMARKER (oldzv
)->charpos
;
5832 ZV_BYTE
= marker_byte_position (oldzv
);
5836 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5838 /* We can't do Fgoto_char (oldpoint) because it will run some
5840 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5841 XMARKER (oldpoint
)->bytepos
);
5844 unchain_marker (oldpoint
);
5845 unchain_marker (oldbegv
);
5846 unchain_marker (oldzv
);
5848 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5849 set_buffer_internal (oldbuf
);
5851 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5852 message_log_need_newline
= !nlflag
;
5853 Vdeactivate_mark
= old_deactivate_mark
;
5858 /* We are at the end of the buffer after just having inserted a newline.
5859 (Note: We depend on the fact we won't be crossing the gap.)
5860 Check to see if the most recent message looks a lot like the previous one.
5861 Return 0 if different, 1 if the new one should just replace it, or a
5862 value N > 1 if we should also append " [N times]". */
5865 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5866 int prev_bol
, this_bol
;
5867 int prev_bol_byte
, this_bol_byte
;
5870 int len
= Z_BYTE
- 1 - this_bol_byte
;
5872 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5873 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5875 for (i
= 0; i
< len
; i
++)
5877 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5885 if (*p1
++ == ' ' && *p1
++ == '[')
5888 while (*p1
>= '0' && *p1
<= '9')
5889 n
= n
* 10 + *p1
++ - '0';
5890 if (strncmp (p1
, " times]\n", 8) == 0)
5897 /* Display an echo area message M with a specified length of NBYTES
5898 bytes. The string may include null characters. If M is 0, clear
5899 out any existing message, and let the mini-buffer text show
5902 The buffer M must continue to exist until after the echo area gets
5903 cleared or some other message gets displayed there. This means do
5904 not pass text that is stored in a Lisp string; do not pass text in
5905 a buffer that was alloca'd. */
5908 message2 (m
, nbytes
, multibyte
)
5913 /* First flush out any partial line written with print. */
5914 message_log_maybe_newline ();
5916 message_dolog (m
, nbytes
, 1, multibyte
);
5917 message2_nolog (m
, nbytes
, multibyte
);
5921 /* The non-logging counterpart of message2. */
5924 message2_nolog (m
, nbytes
, multibyte
)
5928 struct frame
*sf
= SELECTED_FRAME ();
5929 message_enable_multibyte
= multibyte
;
5933 if (noninteractive_need_newline
)
5934 putc ('\n', stderr
);
5935 noninteractive_need_newline
= 0;
5937 fwrite (m
, nbytes
, 1, stderr
);
5938 if (cursor_in_echo_area
== 0)
5939 fprintf (stderr
, "\n");
5942 /* A null message buffer means that the frame hasn't really been
5943 initialized yet. Error messages get reported properly by
5944 cmd_error, so this must be just an informative message; toss it. */
5945 else if (INTERACTIVE
5946 && sf
->glyphs_initialized_p
5947 && FRAME_MESSAGE_BUF (sf
))
5949 Lisp_Object mini_window
;
5952 /* Get the frame containing the mini-buffer
5953 that the selected frame is using. */
5954 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5955 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5957 FRAME_SAMPLE_VISIBILITY (f
);
5958 if (FRAME_VISIBLE_P (sf
)
5959 && ! FRAME_VISIBLE_P (f
))
5960 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5964 set_message (m
, Qnil
, nbytes
, multibyte
);
5965 if (minibuffer_auto_raise
)
5966 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5969 clear_message (1, 1);
5971 do_pending_window_change (0);
5972 echo_area_display (1);
5973 do_pending_window_change (0);
5974 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5975 (*frame_up_to_date_hook
) (f
);
5980 /* Display an echo area message M with a specified length of NBYTES
5981 bytes. The string may include null characters. If M is not a
5982 string, clear out any existing message, and let the mini-buffer
5983 text show through. */
5986 message3 (m
, nbytes
, multibyte
)
5991 struct gcpro gcpro1
;
5995 /* First flush out any partial line written with print. */
5996 message_log_maybe_newline ();
5998 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
5999 message3_nolog (m
, nbytes
, multibyte
);
6005 /* The non-logging version of message3. */
6008 message3_nolog (m
, nbytes
, multibyte
)
6010 int nbytes
, multibyte
;
6012 struct frame
*sf
= SELECTED_FRAME ();
6013 message_enable_multibyte
= multibyte
;
6017 if (noninteractive_need_newline
)
6018 putc ('\n', stderr
);
6019 noninteractive_need_newline
= 0;
6021 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6022 if (cursor_in_echo_area
== 0)
6023 fprintf (stderr
, "\n");
6026 /* A null message buffer means that the frame hasn't really been
6027 initialized yet. Error messages get reported properly by
6028 cmd_error, so this must be just an informative message; toss it. */
6029 else if (INTERACTIVE
6030 && sf
->glyphs_initialized_p
6031 && FRAME_MESSAGE_BUF (sf
))
6033 Lisp_Object mini_window
;
6037 /* Get the frame containing the mini-buffer
6038 that the selected frame is using. */
6039 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6040 frame
= XWINDOW (mini_window
)->frame
;
6043 FRAME_SAMPLE_VISIBILITY (f
);
6044 if (FRAME_VISIBLE_P (sf
)
6045 && !FRAME_VISIBLE_P (f
))
6046 Fmake_frame_visible (frame
);
6048 if (STRINGP (m
) && SCHARS (m
) > 0)
6050 set_message (NULL
, m
, nbytes
, multibyte
);
6051 if (minibuffer_auto_raise
)
6052 Fraise_frame (frame
);
6055 clear_message (1, 1);
6057 do_pending_window_change (0);
6058 echo_area_display (1);
6059 do_pending_window_change (0);
6060 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6061 (*frame_up_to_date_hook
) (f
);
6066 /* Display a null-terminated echo area message M. If M is 0, clear
6067 out any existing message, and let the mini-buffer text show through.
6069 The buffer M must continue to exist until after the echo area gets
6070 cleared or some other message gets displayed there. Do not pass
6071 text that is stored in a Lisp string. Do not pass text in a buffer
6072 that was alloca'd. */
6078 message2 (m
, (m
? strlen (m
) : 0), 0);
6082 /* The non-logging counterpart of message1. */
6088 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6091 /* Display a message M which contains a single %s
6092 which gets replaced with STRING. */
6095 message_with_string (m
, string
, log
)
6100 CHECK_STRING (string
);
6106 if (noninteractive_need_newline
)
6107 putc ('\n', stderr
);
6108 noninteractive_need_newline
= 0;
6109 fprintf (stderr
, m
, SDATA (string
));
6110 if (cursor_in_echo_area
== 0)
6111 fprintf (stderr
, "\n");
6115 else if (INTERACTIVE
)
6117 /* The frame whose minibuffer we're going to display the message on.
6118 It may be larger than the selected frame, so we need
6119 to use its buffer, not the selected frame's buffer. */
6120 Lisp_Object mini_window
;
6121 struct frame
*f
, *sf
= SELECTED_FRAME ();
6123 /* Get the frame containing the minibuffer
6124 that the selected frame is using. */
6125 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6126 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6128 /* A null message buffer means that the frame hasn't really been
6129 initialized yet. Error messages get reported properly by
6130 cmd_error, so this must be just an informative message; toss it. */
6131 if (FRAME_MESSAGE_BUF (f
))
6133 Lisp_Object args
[2], message
;
6134 struct gcpro gcpro1
, gcpro2
;
6136 args
[0] = build_string (m
);
6137 args
[1] = message
= string
;
6138 GCPRO2 (args
[0], message
);
6141 message
= Fformat (2, args
);
6144 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6146 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6150 /* Print should start at the beginning of the message
6151 buffer next time. */
6152 message_buf_print
= 0;
6158 /* Dump an informative message to the minibuf. If M is 0, clear out
6159 any existing message, and let the mini-buffer text show through. */
6163 message (m
, a1
, a2
, a3
)
6165 EMACS_INT a1
, a2
, a3
;
6171 if (noninteractive_need_newline
)
6172 putc ('\n', stderr
);
6173 noninteractive_need_newline
= 0;
6174 fprintf (stderr
, m
, a1
, a2
, a3
);
6175 if (cursor_in_echo_area
== 0)
6176 fprintf (stderr
, "\n");
6180 else if (INTERACTIVE
)
6182 /* The frame whose mini-buffer we're going to display the message
6183 on. It may be larger than the selected frame, so we need to
6184 use its buffer, not the selected frame's buffer. */
6185 Lisp_Object mini_window
;
6186 struct frame
*f
, *sf
= SELECTED_FRAME ();
6188 /* Get the frame containing the mini-buffer
6189 that the selected frame is using. */
6190 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6191 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6193 /* A null message buffer means that the frame hasn't really been
6194 initialized yet. Error messages get reported properly by
6195 cmd_error, so this must be just an informative message; toss
6197 if (FRAME_MESSAGE_BUF (f
))
6208 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6209 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6211 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6212 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6214 #endif /* NO_ARG_ARRAY */
6216 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6221 /* Print should start at the beginning of the message
6222 buffer next time. */
6223 message_buf_print
= 0;
6229 /* The non-logging version of message. */
6232 message_nolog (m
, a1
, a2
, a3
)
6234 EMACS_INT a1
, a2
, a3
;
6236 Lisp_Object old_log_max
;
6237 old_log_max
= Vmessage_log_max
;
6238 Vmessage_log_max
= Qnil
;
6239 message (m
, a1
, a2
, a3
);
6240 Vmessage_log_max
= old_log_max
;
6244 /* Display the current message in the current mini-buffer. This is
6245 only called from error handlers in process.c, and is not time
6251 if (!NILP (echo_area_buffer
[0]))
6254 string
= Fcurrent_message ();
6255 message3 (string
, SBYTES (string
),
6256 !NILP (current_buffer
->enable_multibyte_characters
));
6261 /* Make sure echo area buffers in `echo_buffers' are live.
6262 If they aren't, make new ones. */
6265 ensure_echo_area_buffers ()
6269 for (i
= 0; i
< 2; ++i
)
6270 if (!BUFFERP (echo_buffer
[i
])
6271 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6274 Lisp_Object old_buffer
;
6277 old_buffer
= echo_buffer
[i
];
6278 sprintf (name
, " *Echo Area %d*", i
);
6279 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6280 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6282 for (j
= 0; j
< 2; ++j
)
6283 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6284 echo_area_buffer
[j
] = echo_buffer
[i
];
6289 /* Call FN with args A1..A4 with either the current or last displayed
6290 echo_area_buffer as current buffer.
6292 WHICH zero means use the current message buffer
6293 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6294 from echo_buffer[] and clear it.
6296 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6297 suitable buffer from echo_buffer[] and clear it.
6299 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6300 that the current message becomes the last displayed one, make
6301 choose a suitable buffer for echo_area_buffer[0], and clear it.
6303 Value is what FN returns. */
6306 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6309 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6315 int this_one
, the_other
, clear_buffer_p
, rc
;
6316 int count
= SPECPDL_INDEX ();
6318 /* If buffers aren't live, make new ones. */
6319 ensure_echo_area_buffers ();
6324 this_one
= 0, the_other
= 1;
6326 this_one
= 1, the_other
= 0;
6329 this_one
= 0, the_other
= 1;
6332 /* We need a fresh one in case the current echo buffer equals
6333 the one containing the last displayed echo area message. */
6334 if (!NILP (echo_area_buffer
[this_one
])
6335 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6336 echo_area_buffer
[this_one
] = Qnil
;
6339 /* Choose a suitable buffer from echo_buffer[] is we don't
6341 if (NILP (echo_area_buffer
[this_one
]))
6343 echo_area_buffer
[this_one
]
6344 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6345 ? echo_buffer
[the_other
]
6346 : echo_buffer
[this_one
]);
6350 buffer
= echo_area_buffer
[this_one
];
6352 /* Don't get confused by reusing the buffer used for echoing
6353 for a different purpose. */
6354 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6357 record_unwind_protect (unwind_with_echo_area_buffer
,
6358 with_echo_area_buffer_unwind_data (w
));
6360 /* Make the echo area buffer current. Note that for display
6361 purposes, it is not necessary that the displayed window's buffer
6362 == current_buffer, except for text property lookup. So, let's
6363 only set that buffer temporarily here without doing a full
6364 Fset_window_buffer. We must also change w->pointm, though,
6365 because otherwise an assertions in unshow_buffer fails, and Emacs
6367 set_buffer_internal_1 (XBUFFER (buffer
));
6371 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6374 current_buffer
->undo_list
= Qt
;
6375 current_buffer
->read_only
= Qnil
;
6376 specbind (Qinhibit_read_only
, Qt
);
6377 specbind (Qinhibit_modification_hooks
, Qt
);
6379 if (clear_buffer_p
&& Z
> BEG
)
6382 xassert (BEGV
>= BEG
);
6383 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6385 rc
= fn (a1
, a2
, a3
, a4
);
6387 xassert (BEGV
>= BEG
);
6388 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6390 unbind_to (count
, Qnil
);
6395 /* Save state that should be preserved around the call to the function
6396 FN called in with_echo_area_buffer. */
6399 with_echo_area_buffer_unwind_data (w
)
6405 /* Reduce consing by keeping one vector in
6406 Vwith_echo_area_save_vector. */
6407 vector
= Vwith_echo_area_save_vector
;
6408 Vwith_echo_area_save_vector
= Qnil
;
6411 vector
= Fmake_vector (make_number (7), Qnil
);
6413 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6414 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6415 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6419 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6420 AREF (vector
, i
) = w
->buffer
; ++i
;
6421 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6422 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6427 for (; i
< end
; ++i
)
6428 AREF (vector
, i
) = Qnil
;
6431 xassert (i
== ASIZE (vector
));
6436 /* Restore global state from VECTOR which was created by
6437 with_echo_area_buffer_unwind_data. */
6440 unwind_with_echo_area_buffer (vector
)
6443 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6444 Vdeactivate_mark
= AREF (vector
, 1);
6445 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6447 if (WINDOWP (AREF (vector
, 3)))
6450 Lisp_Object buffer
, charpos
, bytepos
;
6452 w
= XWINDOW (AREF (vector
, 3));
6453 buffer
= AREF (vector
, 4);
6454 charpos
= AREF (vector
, 5);
6455 bytepos
= AREF (vector
, 6);
6458 set_marker_both (w
->pointm
, buffer
,
6459 XFASTINT (charpos
), XFASTINT (bytepos
));
6462 Vwith_echo_area_save_vector
= vector
;
6467 /* Set up the echo area for use by print functions. MULTIBYTE_P
6468 non-zero means we will print multibyte. */
6471 setup_echo_area_for_printing (multibyte_p
)
6474 ensure_echo_area_buffers ();
6476 if (!message_buf_print
)
6478 /* A message has been output since the last time we printed.
6479 Choose a fresh echo area buffer. */
6480 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6481 echo_area_buffer
[0] = echo_buffer
[1];
6483 echo_area_buffer
[0] = echo_buffer
[0];
6485 /* Switch to that buffer and clear it. */
6486 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6487 current_buffer
->truncate_lines
= Qnil
;
6491 int count
= SPECPDL_INDEX ();
6492 specbind (Qinhibit_read_only
, Qt
);
6493 /* Note that undo recording is always disabled. */
6495 unbind_to (count
, Qnil
);
6497 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6499 /* Set up the buffer for the multibyteness we need. */
6501 != !NILP (current_buffer
->enable_multibyte_characters
))
6502 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6504 /* Raise the frame containing the echo area. */
6505 if (minibuffer_auto_raise
)
6507 struct frame
*sf
= SELECTED_FRAME ();
6508 Lisp_Object mini_window
;
6509 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6510 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6513 message_log_maybe_newline ();
6514 message_buf_print
= 1;
6518 if (NILP (echo_area_buffer
[0]))
6520 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6521 echo_area_buffer
[0] = echo_buffer
[1];
6523 echo_area_buffer
[0] = echo_buffer
[0];
6526 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6528 /* Someone switched buffers between print requests. */
6529 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6530 current_buffer
->truncate_lines
= Qnil
;
6536 /* Display an echo area message in window W. Value is non-zero if W's
6537 height is changed. If display_last_displayed_message_p is
6538 non-zero, display the message that was last displayed, otherwise
6539 display the current message. */
6542 display_echo_area (w
)
6545 int i
, no_message_p
, window_height_changed_p
, count
;
6547 /* Temporarily disable garbage collections while displaying the echo
6548 area. This is done because a GC can print a message itself.
6549 That message would modify the echo area buffer's contents while a
6550 redisplay of the buffer is going on, and seriously confuse
6552 count
= inhibit_garbage_collection ();
6554 /* If there is no message, we must call display_echo_area_1
6555 nevertheless because it resizes the window. But we will have to
6556 reset the echo_area_buffer in question to nil at the end because
6557 with_echo_area_buffer will sets it to an empty buffer. */
6558 i
= display_last_displayed_message_p
? 1 : 0;
6559 no_message_p
= NILP (echo_area_buffer
[i
]);
6561 window_height_changed_p
6562 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6563 display_echo_area_1
,
6564 (EMACS_INT
) w
, Qnil
, 0, 0);
6567 echo_area_buffer
[i
] = Qnil
;
6569 unbind_to (count
, Qnil
);
6570 return window_height_changed_p
;
6574 /* Helper for display_echo_area. Display the current buffer which
6575 contains the current echo area message in window W, a mini-window,
6576 a pointer to which is passed in A1. A2..A4 are currently not used.
6577 Change the height of W so that all of the message is displayed.
6578 Value is non-zero if height of W was changed. */
6581 display_echo_area_1 (a1
, a2
, a3
, a4
)
6586 struct window
*w
= (struct window
*) a1
;
6588 struct text_pos start
;
6589 int window_height_changed_p
= 0;
6591 /* Do this before displaying, so that we have a large enough glyph
6592 matrix for the display. */
6593 window_height_changed_p
= resize_mini_window (w
, 0);
6596 clear_glyph_matrix (w
->desired_matrix
);
6597 XSETWINDOW (window
, w
);
6598 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6599 try_window (window
, start
);
6601 return window_height_changed_p
;
6605 /* Resize the echo area window to exactly the size needed for the
6606 currently displayed message, if there is one. If a mini-buffer
6607 is active, don't shrink it. */
6610 resize_echo_area_exactly ()
6612 if (BUFFERP (echo_area_buffer
[0])
6613 && WINDOWP (echo_area_window
))
6615 struct window
*w
= XWINDOW (echo_area_window
);
6617 Lisp_Object resize_exactly
;
6619 if (minibuf_level
== 0)
6620 resize_exactly
= Qt
;
6622 resize_exactly
= Qnil
;
6624 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6625 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6628 ++windows_or_buffers_changed
;
6629 ++update_mode_lines
;
6630 redisplay_internal (0);
6636 /* Callback function for with_echo_area_buffer, when used from
6637 resize_echo_area_exactly. A1 contains a pointer to the window to
6638 resize, EXACTLY non-nil means resize the mini-window exactly to the
6639 size of the text displayed. A3 and A4 are not used. Value is what
6640 resize_mini_window returns. */
6643 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6645 Lisp_Object exactly
;
6648 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6652 /* Resize mini-window W to fit the size of its contents. EXACT:P
6653 means size the window exactly to the size needed. Otherwise, it's
6654 only enlarged until W's buffer is empty. Value is non-zero if
6655 the window height has been changed. */
6658 resize_mini_window (w
, exact_p
)
6662 struct frame
*f
= XFRAME (w
->frame
);
6663 int window_height_changed_p
= 0;
6665 xassert (MINI_WINDOW_P (w
));
6667 /* Don't resize windows while redisplaying a window; it would
6668 confuse redisplay functions when the size of the window they are
6669 displaying changes from under them. Such a resizing can happen,
6670 for instance, when which-func prints a long message while
6671 we are running fontification-functions. We're running these
6672 functions with safe_call which binds inhibit-redisplay to t. */
6673 if (!NILP (Vinhibit_redisplay
))
6676 /* Nil means don't try to resize. */
6677 if (NILP (Vresize_mini_windows
)
6678 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6681 if (!FRAME_MINIBUF_ONLY_P (f
))
6684 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6685 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6686 int height
, max_height
;
6687 int unit
= CANON_Y_UNIT (f
);
6688 struct text_pos start
;
6689 struct buffer
*old_current_buffer
= NULL
;
6691 if (current_buffer
!= XBUFFER (w
->buffer
))
6693 old_current_buffer
= current_buffer
;
6694 set_buffer_internal (XBUFFER (w
->buffer
));
6697 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6699 /* Compute the max. number of lines specified by the user. */
6700 if (FLOATP (Vmax_mini_window_height
))
6701 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6702 else if (INTEGERP (Vmax_mini_window_height
))
6703 max_height
= XINT (Vmax_mini_window_height
);
6705 max_height
= total_height
/ 4;
6707 /* Correct that max. height if it's bogus. */
6708 max_height
= max (1, max_height
);
6709 max_height
= min (total_height
, max_height
);
6711 /* Find out the height of the text in the window. */
6712 if (it
.truncate_lines_p
)
6717 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6718 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6719 height
= it
.current_y
+ last_height
;
6721 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6722 height
-= it
.extra_line_spacing
;
6723 height
= (height
+ unit
- 1) / unit
;
6726 /* Compute a suitable window start. */
6727 if (height
> max_height
)
6729 height
= max_height
;
6730 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6731 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6732 start
= it
.current
.pos
;
6735 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6736 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6738 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6740 /* Let it grow only, until we display an empty message, in which
6741 case the window shrinks again. */
6742 if (height
> XFASTINT (w
->height
))
6744 int old_height
= XFASTINT (w
->height
);
6745 freeze_window_starts (f
, 1);
6746 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6747 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6749 else if (height
< XFASTINT (w
->height
)
6750 && (exact_p
|| BEGV
== ZV
))
6752 int old_height
= XFASTINT (w
->height
);
6753 freeze_window_starts (f
, 0);
6754 shrink_mini_window (w
);
6755 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6760 /* Always resize to exact size needed. */
6761 if (height
> XFASTINT (w
->height
))
6763 int old_height
= XFASTINT (w
->height
);
6764 freeze_window_starts (f
, 1);
6765 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6766 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6768 else if (height
< XFASTINT (w
->height
))
6770 int old_height
= XFASTINT (w
->height
);
6771 freeze_window_starts (f
, 0);
6772 shrink_mini_window (w
);
6776 freeze_window_starts (f
, 1);
6777 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6780 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6784 if (old_current_buffer
)
6785 set_buffer_internal (old_current_buffer
);
6788 return window_height_changed_p
;
6792 /* Value is the current message, a string, or nil if there is no
6800 if (NILP (echo_area_buffer
[0]))
6804 with_echo_area_buffer (0, 0, current_message_1
,
6805 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6807 echo_area_buffer
[0] = Qnil
;
6815 current_message_1 (a1
, a2
, a3
, a4
)
6820 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6823 *msg
= make_buffer_string (BEG
, Z
, 1);
6830 /* Push the current message on Vmessage_stack for later restauration
6831 by restore_message. Value is non-zero if the current message isn't
6832 empty. This is a relatively infrequent operation, so it's not
6833 worth optimizing. */
6839 msg
= current_message ();
6840 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6841 return STRINGP (msg
);
6845 /* Restore message display from the top of Vmessage_stack. */
6852 xassert (CONSP (Vmessage_stack
));
6853 msg
= XCAR (Vmessage_stack
);
6855 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
6857 message3_nolog (msg
, 0, 0);
6861 /* Handler for record_unwind_protect calling pop_message. */
6864 pop_message_unwind (dummy
)
6871 /* Pop the top-most entry off Vmessage_stack. */
6876 xassert (CONSP (Vmessage_stack
));
6877 Vmessage_stack
= XCDR (Vmessage_stack
);
6881 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6882 exits. If the stack is not empty, we have a missing pop_message
6886 check_message_stack ()
6888 if (!NILP (Vmessage_stack
))
6893 /* Truncate to NCHARS what will be displayed in the echo area the next
6894 time we display it---but don't redisplay it now. */
6897 truncate_echo_area (nchars
)
6901 echo_area_buffer
[0] = Qnil
;
6902 /* A null message buffer means that the frame hasn't really been
6903 initialized yet. Error messages get reported properly by
6904 cmd_error, so this must be just an informative message; toss it. */
6905 else if (!noninteractive
6907 && !NILP (echo_area_buffer
[0]))
6909 struct frame
*sf
= SELECTED_FRAME ();
6910 if (FRAME_MESSAGE_BUF (sf
))
6911 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6916 /* Helper function for truncate_echo_area. Truncate the current
6917 message to at most NCHARS characters. */
6920 truncate_message_1 (nchars
, a2
, a3
, a4
)
6925 if (BEG
+ nchars
< Z
)
6926 del_range (BEG
+ nchars
, Z
);
6928 echo_area_buffer
[0] = Qnil
;
6933 /* Set the current message to a substring of S or STRING.
6935 If STRING is a Lisp string, set the message to the first NBYTES
6936 bytes from STRING. NBYTES zero means use the whole string. If
6937 STRING is multibyte, the message will be displayed multibyte.
6939 If S is not null, set the message to the first LEN bytes of S. LEN
6940 zero means use the whole string. MULTIBYTE_P non-zero means S is
6941 multibyte. Display the message multibyte in that case. */
6944 set_message (s
, string
, nbytes
, multibyte_p
)
6949 message_enable_multibyte
6950 = ((s
&& multibyte_p
)
6951 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6953 with_echo_area_buffer (0, -1, set_message_1
,
6954 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6955 message_buf_print
= 0;
6956 help_echo_showing_p
= 0;
6960 /* Helper function for set_message. Arguments have the same meaning
6961 as there, with A1 corresponding to S and A2 corresponding to STRING
6962 This function is called with the echo area buffer being
6966 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6969 EMACS_INT nbytes
, multibyte_p
;
6971 const char *s
= (const char *) a1
;
6972 Lisp_Object string
= a2
;
6976 /* Change multibyteness of the echo buffer appropriately. */
6977 if (message_enable_multibyte
6978 != !NILP (current_buffer
->enable_multibyte_characters
))
6979 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6981 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6983 /* Insert new message at BEG. */
6984 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6986 if (STRINGP (string
))
6991 nbytes
= SBYTES (string
);
6992 nchars
= string_byte_to_char (string
, nbytes
);
6994 /* This function takes care of single/multibyte conversion. We
6995 just have to ensure that the echo area buffer has the right
6996 setting of enable_multibyte_characters. */
6997 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7002 nbytes
= strlen (s
);
7004 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7006 /* Convert from multi-byte to single-byte. */
7008 unsigned char work
[1];
7010 /* Convert a multibyte string to single-byte. */
7011 for (i
= 0; i
< nbytes
; i
+= n
)
7013 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7014 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7016 : multibyte_char_to_unibyte (c
, Qnil
));
7017 insert_1_both (work
, 1, 1, 1, 0, 0);
7020 else if (!multibyte_p
7021 && !NILP (current_buffer
->enable_multibyte_characters
))
7023 /* Convert from single-byte to multi-byte. */
7025 const unsigned char *msg
= (const unsigned char *) s
;
7026 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7028 /* Convert a single-byte string to multibyte. */
7029 for (i
= 0; i
< nbytes
; i
++)
7031 c
= unibyte_char_to_multibyte (msg
[i
]);
7032 n
= CHAR_STRING (c
, str
);
7033 insert_1_both (str
, 1, n
, 1, 0, 0);
7037 insert_1 (s
, nbytes
, 1, 0, 0);
7044 /* Clear messages. CURRENT_P non-zero means clear the current
7045 message. LAST_DISPLAYED_P non-zero means clear the message
7049 clear_message (current_p
, last_displayed_p
)
7050 int current_p
, last_displayed_p
;
7054 echo_area_buffer
[0] = Qnil
;
7055 message_cleared_p
= 1;
7058 if (last_displayed_p
)
7059 echo_area_buffer
[1] = Qnil
;
7061 message_buf_print
= 0;
7064 /* Clear garbaged frames.
7066 This function is used where the old redisplay called
7067 redraw_garbaged_frames which in turn called redraw_frame which in
7068 turn called clear_frame. The call to clear_frame was a source of
7069 flickering. I believe a clear_frame is not necessary. It should
7070 suffice in the new redisplay to invalidate all current matrices,
7071 and ensure a complete redisplay of all windows. */
7074 clear_garbaged_frames ()
7078 Lisp_Object tail
, frame
;
7079 int changed_count
= 0;
7081 FOR_EACH_FRAME (tail
, frame
)
7083 struct frame
*f
= XFRAME (frame
);
7085 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7088 Fredraw_frame (frame
);
7089 clear_current_matrices (f
);
7098 ++windows_or_buffers_changed
;
7103 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7104 is non-zero update selected_frame. Value is non-zero if the
7105 mini-windows height has been changed. */
7108 echo_area_display (update_frame_p
)
7111 Lisp_Object mini_window
;
7114 int window_height_changed_p
= 0;
7115 struct frame
*sf
= SELECTED_FRAME ();
7117 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7118 w
= XWINDOW (mini_window
);
7119 f
= XFRAME (WINDOW_FRAME (w
));
7121 /* Don't display if frame is invisible or not yet initialized. */
7122 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7125 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7127 #ifdef HAVE_WINDOW_SYSTEM
7128 /* When Emacs starts, selected_frame may be a visible terminal
7129 frame, even if we run under a window system. If we let this
7130 through, a message would be displayed on the terminal. */
7131 if (EQ (selected_frame
, Vterminal_frame
)
7132 && !NILP (Vwindow_system
))
7134 #endif /* HAVE_WINDOW_SYSTEM */
7137 /* Redraw garbaged frames. */
7139 clear_garbaged_frames ();
7141 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7143 echo_area_window
= mini_window
;
7144 window_height_changed_p
= display_echo_area (w
);
7145 w
->must_be_updated_p
= 1;
7147 /* Update the display, unless called from redisplay_internal.
7148 Also don't update the screen during redisplay itself. The
7149 update will happen at the end of redisplay, and an update
7150 here could cause confusion. */
7151 if (update_frame_p
&& !redisplaying_p
)
7155 /* If the display update has been interrupted by pending
7156 input, update mode lines in the frame. Due to the
7157 pending input, it might have been that redisplay hasn't
7158 been called, so that mode lines above the echo area are
7159 garbaged. This looks odd, so we prevent it here. */
7160 if (!display_completed
)
7161 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7163 if (window_height_changed_p
7164 /* Don't do this if Emacs is shutting down. Redisplay
7165 needs to run hooks. */
7166 && !NILP (Vrun_hooks
))
7168 /* Must update other windows. Likewise as in other
7169 cases, don't let this update be interrupted by
7171 int count
= SPECPDL_INDEX ();
7172 specbind (Qredisplay_dont_pause
, Qt
);
7173 windows_or_buffers_changed
= 1;
7174 redisplay_internal (0);
7175 unbind_to (count
, Qnil
);
7177 else if (FRAME_WINDOW_P (f
) && n
== 0)
7179 /* Window configuration is the same as before.
7180 Can do with a display update of the echo area,
7181 unless we displayed some mode lines. */
7182 update_single_window (w
, 1);
7183 rif
->flush_display (f
);
7186 update_frame (f
, 1, 1);
7188 /* If cursor is in the echo area, make sure that the next
7189 redisplay displays the minibuffer, so that the cursor will
7190 be replaced with what the minibuffer wants. */
7191 if (cursor_in_echo_area
)
7192 ++windows_or_buffers_changed
;
7195 else if (!EQ (mini_window
, selected_window
))
7196 windows_or_buffers_changed
++;
7198 /* Last displayed message is now the current message. */
7199 echo_area_buffer
[1] = echo_area_buffer
[0];
7201 /* Prevent redisplay optimization in redisplay_internal by resetting
7202 this_line_start_pos. This is done because the mini-buffer now
7203 displays the message instead of its buffer text. */
7204 if (EQ (mini_window
, selected_window
))
7205 CHARPOS (this_line_start_pos
) = 0;
7207 return window_height_changed_p
;
7212 /***********************************************************************
7214 ***********************************************************************/
7217 /* The frame title buffering code is also used by Fformat_mode_line.
7218 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7220 /* A buffer for constructing frame titles in it; allocated from the
7221 heap in init_xdisp and resized as needed in store_frame_title_char. */
7223 static char *frame_title_buf
;
7225 /* The buffer's end, and a current output position in it. */
7227 static char *frame_title_buf_end
;
7228 static char *frame_title_ptr
;
7231 /* Store a single character C for the frame title in frame_title_buf.
7232 Re-allocate frame_title_buf if necessary. */
7235 store_frame_title_char (c
)
7238 /* If output position has reached the end of the allocated buffer,
7239 double the buffer's size. */
7240 if (frame_title_ptr
== frame_title_buf_end
)
7242 int len
= frame_title_ptr
- frame_title_buf
;
7243 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7244 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7245 frame_title_buf_end
= frame_title_buf
+ new_size
;
7246 frame_title_ptr
= frame_title_buf
+ len
;
7249 *frame_title_ptr
++ = c
;
7253 /* Store part of a frame title in frame_title_buf, beginning at
7254 frame_title_ptr. STR is the string to store. Do not copy
7255 characters that yield more columns than PRECISION; PRECISION <= 0
7256 means copy the whole string. Pad with spaces until FIELD_WIDTH
7257 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7258 pad. Called from display_mode_element when it is used to build a
7262 store_frame_title (str
, field_width
, precision
)
7263 const unsigned char *str
;
7264 int field_width
, precision
;
7269 /* Copy at most PRECISION chars from STR. */
7270 nbytes
= strlen (str
);
7271 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7273 store_frame_title_char (*str
++);
7275 /* Fill up with spaces until FIELD_WIDTH reached. */
7276 while (field_width
> 0
7279 store_frame_title_char (' ');
7286 #ifdef HAVE_WINDOW_SYSTEM
7288 /* Set the title of FRAME, if it has changed. The title format is
7289 Vicon_title_format if FRAME is iconified, otherwise it is
7290 frame_title_format. */
7293 x_consider_frame_title (frame
)
7296 struct frame
*f
= XFRAME (frame
);
7298 if (FRAME_WINDOW_P (f
)
7299 || FRAME_MINIBUF_ONLY_P (f
)
7300 || f
->explicit_name
)
7302 /* Do we have more than one visible frame on this X display? */
7305 struct buffer
*obuf
;
7309 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7311 Lisp_Object other_frame
= XCAR (tail
);
7312 struct frame
*tf
= XFRAME (other_frame
);
7315 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7316 && !FRAME_MINIBUF_ONLY_P (tf
)
7317 && !EQ (other_frame
, tip_frame
)
7318 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7322 /* Set global variable indicating that multiple frames exist. */
7323 multiple_frames
= CONSP (tail
);
7325 /* Switch to the buffer of selected window of the frame. Set up
7326 frame_title_ptr so that display_mode_element will output into it;
7327 then display the title. */
7328 obuf
= current_buffer
;
7329 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7330 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7331 frame_title_ptr
= frame_title_buf
;
7332 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7333 NULL
, DEFAULT_FACE_ID
);
7334 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7335 len
= frame_title_ptr
- frame_title_buf
;
7336 frame_title_ptr
= NULL
;
7337 set_buffer_internal_1 (obuf
);
7339 /* Set the title only if it's changed. This avoids consing in
7340 the common case where it hasn't. (If it turns out that we've
7341 already wasted too much time by walking through the list with
7342 display_mode_element, then we might need to optimize at a
7343 higher level than this.) */
7344 if (! STRINGP (f
->name
)
7345 || SBYTES (f
->name
) != len
7346 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7347 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7351 #endif /* not HAVE_WINDOW_SYSTEM */
7356 /***********************************************************************
7358 ***********************************************************************/
7361 /* Prepare for redisplay by updating menu-bar item lists when
7362 appropriate. This can call eval. */
7365 prepare_menu_bars ()
7368 struct gcpro gcpro1
, gcpro2
;
7370 Lisp_Object tooltip_frame
;
7372 #ifdef HAVE_WINDOW_SYSTEM
7373 tooltip_frame
= tip_frame
;
7375 tooltip_frame
= Qnil
;
7378 /* Update all frame titles based on their buffer names, etc. We do
7379 this before the menu bars so that the buffer-menu will show the
7380 up-to-date frame titles. */
7381 #ifdef HAVE_WINDOW_SYSTEM
7382 if (windows_or_buffers_changed
|| update_mode_lines
)
7384 Lisp_Object tail
, frame
;
7386 FOR_EACH_FRAME (tail
, frame
)
7389 if (!EQ (frame
, tooltip_frame
)
7390 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7391 x_consider_frame_title (frame
);
7394 #endif /* HAVE_WINDOW_SYSTEM */
7396 /* Update the menu bar item lists, if appropriate. This has to be
7397 done before any actual redisplay or generation of display lines. */
7398 all_windows
= (update_mode_lines
7399 || buffer_shared
> 1
7400 || windows_or_buffers_changed
);
7403 Lisp_Object tail
, frame
;
7404 int count
= SPECPDL_INDEX ();
7406 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7408 FOR_EACH_FRAME (tail
, frame
)
7412 /* Ignore tooltip frame. */
7413 if (EQ (frame
, tooltip_frame
))
7416 /* If a window on this frame changed size, report that to
7417 the user and clear the size-change flag. */
7418 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7420 Lisp_Object functions
;
7422 /* Clear flag first in case we get an error below. */
7423 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7424 functions
= Vwindow_size_change_functions
;
7425 GCPRO2 (tail
, functions
);
7427 while (CONSP (functions
))
7429 call1 (XCAR (functions
), frame
);
7430 functions
= XCDR (functions
);
7436 update_menu_bar (f
, 0);
7437 #ifdef HAVE_WINDOW_SYSTEM
7438 update_tool_bar (f
, 0);
7443 unbind_to (count
, Qnil
);
7447 struct frame
*sf
= SELECTED_FRAME ();
7448 update_menu_bar (sf
, 1);
7449 #ifdef HAVE_WINDOW_SYSTEM
7450 update_tool_bar (sf
, 1);
7454 /* Motif needs this. See comment in xmenu.c. Turn it off when
7455 pending_menu_activation is not defined. */
7456 #ifdef USE_X_TOOLKIT
7457 pending_menu_activation
= 0;
7462 /* Update the menu bar item list for frame F. This has to be done
7463 before we start to fill in any display lines, because it can call
7466 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7469 update_menu_bar (f
, save_match_data
)
7471 int save_match_data
;
7474 register struct window
*w
;
7476 /* If called recursively during a menu update, do nothing. This can
7477 happen when, for instance, an activate-menubar-hook causes a
7479 if (inhibit_menubar_update
)
7482 window
= FRAME_SELECTED_WINDOW (f
);
7483 w
= XWINDOW (window
);
7485 #if 0 /* The if statement below this if statement used to include the
7486 condition !NILP (w->update_mode_line), rather than using
7487 update_mode_lines directly, and this if statement may have
7488 been added to make that condition work. Now the if
7489 statement below matches its comment, this isn't needed. */
7490 if (update_mode_lines
)
7491 w
->update_mode_line
= Qt
;
7494 if (FRAME_WINDOW_P (f
)
7496 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
7497 FRAME_EXTERNAL_MENU_BAR (f
)
7499 FRAME_MENU_BAR_LINES (f
) > 0
7501 : FRAME_MENU_BAR_LINES (f
) > 0)
7503 /* If the user has switched buffers or windows, we need to
7504 recompute to reflect the new bindings. But we'll
7505 recompute when update_mode_lines is set too; that means
7506 that people can use force-mode-line-update to request
7507 that the menu bar be recomputed. The adverse effect on
7508 the rest of the redisplay algorithm is about the same as
7509 windows_or_buffers_changed anyway. */
7510 if (windows_or_buffers_changed
7511 /* This used to test w->update_mode_line, but we believe
7512 there is no need to recompute the menu in that case. */
7513 || update_mode_lines
7514 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7515 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7516 != !NILP (w
->last_had_star
))
7517 || ((!NILP (Vtransient_mark_mode
)
7518 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7519 != !NILP (w
->region_showing
)))
7521 struct buffer
*prev
= current_buffer
;
7522 int count
= SPECPDL_INDEX ();
7524 specbind (Qinhibit_menubar_update
, Qt
);
7526 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7527 if (save_match_data
)
7528 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7529 if (NILP (Voverriding_local_map_menu_flag
))
7531 specbind (Qoverriding_terminal_local_map
, Qnil
);
7532 specbind (Qoverriding_local_map
, Qnil
);
7535 /* Run the Lucid hook. */
7536 safe_run_hooks (Qactivate_menubar_hook
);
7538 /* If it has changed current-menubar from previous value,
7539 really recompute the menu-bar from the value. */
7540 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7541 call0 (Qrecompute_lucid_menubar
);
7543 safe_run_hooks (Qmenu_bar_update_hook
);
7544 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7546 /* Redisplay the menu bar in case we changed it. */
7547 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
7548 if (FRAME_WINDOW_P (f
)
7549 #if defined (MAC_OS)
7550 /* All frames on Mac OS share the same menubar. So only the
7551 selected frame should be allowed to set it. */
7552 && f
== SELECTED_FRAME ()
7555 set_frame_menubar (f
, 0, 0);
7557 /* On a terminal screen, the menu bar is an ordinary screen
7558 line, and this makes it get updated. */
7559 w
->update_mode_line
= Qt
;
7560 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7561 /* In the non-toolkit version, the menu bar is an ordinary screen
7562 line, and this makes it get updated. */
7563 w
->update_mode_line
= Qt
;
7564 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7566 unbind_to (count
, Qnil
);
7567 set_buffer_internal_1 (prev
);
7574 /***********************************************************************
7576 ***********************************************************************/
7578 #ifdef HAVE_WINDOW_SYSTEM
7580 /* Update the tool-bar item list for frame F. This has to be done
7581 before we start to fill in any display lines. Called from
7582 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7583 and restore it here. */
7586 update_tool_bar (f
, save_match_data
)
7588 int save_match_data
;
7590 if (WINDOWP (f
->tool_bar_window
)
7591 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7596 window
= FRAME_SELECTED_WINDOW (f
);
7597 w
= XWINDOW (window
);
7599 /* If the user has switched buffers or windows, we need to
7600 recompute to reflect the new bindings. But we'll
7601 recompute when update_mode_lines is set too; that means
7602 that people can use force-mode-line-update to request
7603 that the menu bar be recomputed. The adverse effect on
7604 the rest of the redisplay algorithm is about the same as
7605 windows_or_buffers_changed anyway. */
7606 if (windows_or_buffers_changed
7607 || !NILP (w
->update_mode_line
)
7608 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7609 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7610 != !NILP (w
->last_had_star
))
7611 || ((!NILP (Vtransient_mark_mode
)
7612 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7613 != !NILP (w
->region_showing
)))
7615 struct buffer
*prev
= current_buffer
;
7616 int count
= SPECPDL_INDEX ();
7618 /* Set current_buffer to the buffer of the selected
7619 window of the frame, so that we get the right local
7621 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7623 /* Save match data, if we must. */
7624 if (save_match_data
)
7625 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7627 /* Make sure that we don't accidentally use bogus keymaps. */
7628 if (NILP (Voverriding_local_map_menu_flag
))
7630 specbind (Qoverriding_terminal_local_map
, Qnil
);
7631 specbind (Qoverriding_local_map
, Qnil
);
7634 /* Build desired tool-bar items from keymaps. */
7636 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7638 /* Redisplay the tool-bar in case we changed it. */
7639 w
->update_mode_line
= Qt
;
7641 unbind_to (count
, Qnil
);
7642 set_buffer_internal_1 (prev
);
7648 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7649 F's desired tool-bar contents. F->tool_bar_items must have
7650 been set up previously by calling prepare_menu_bars. */
7653 build_desired_tool_bar_string (f
)
7656 int i
, size
, size_needed
;
7657 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7658 Lisp_Object image
, plist
, props
;
7660 image
= plist
= props
= Qnil
;
7661 GCPRO3 (image
, plist
, props
);
7663 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7664 Otherwise, make a new string. */
7666 /* The size of the string we might be able to reuse. */
7667 size
= (STRINGP (f
->desired_tool_bar_string
)
7668 ? SCHARS (f
->desired_tool_bar_string
)
7671 /* We need one space in the string for each image. */
7672 size_needed
= f
->n_tool_bar_items
;
7674 /* Reuse f->desired_tool_bar_string, if possible. */
7675 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7676 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7680 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7681 Fremove_text_properties (make_number (0), make_number (size
),
7682 props
, f
->desired_tool_bar_string
);
7685 /* Put a `display' property on the string for the images to display,
7686 put a `menu_item' property on tool-bar items with a value that
7687 is the index of the item in F's tool-bar item vector. */
7688 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7690 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7692 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7693 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7694 int hmargin
, vmargin
, relief
, idx
, end
;
7695 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7697 /* If image is a vector, choose the image according to the
7699 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7700 if (VECTORP (image
))
7704 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7705 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7708 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7709 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7711 xassert (ASIZE (image
) >= idx
);
7712 image
= AREF (image
, idx
);
7717 /* Ignore invalid image specifications. */
7718 if (!valid_image_p (image
))
7721 /* Display the tool-bar button pressed, or depressed. */
7722 plist
= Fcopy_sequence (XCDR (image
));
7724 /* Compute margin and relief to draw. */
7725 relief
= (tool_bar_button_relief
>= 0
7726 ? tool_bar_button_relief
7727 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7728 hmargin
= vmargin
= relief
;
7730 if (INTEGERP (Vtool_bar_button_margin
)
7731 && XINT (Vtool_bar_button_margin
) > 0)
7733 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7734 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7736 else if (CONSP (Vtool_bar_button_margin
))
7738 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7739 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7740 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7742 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7743 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7744 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7747 if (auto_raise_tool_bar_buttons_p
)
7749 /* Add a `:relief' property to the image spec if the item is
7753 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7760 /* If image is selected, display it pressed, i.e. with a
7761 negative relief. If it's not selected, display it with a
7763 plist
= Fplist_put (plist
, QCrelief
,
7765 ? make_number (-relief
)
7766 : make_number (relief
)));
7771 /* Put a margin around the image. */
7772 if (hmargin
|| vmargin
)
7774 if (hmargin
== vmargin
)
7775 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7777 plist
= Fplist_put (plist
, QCmargin
,
7778 Fcons (make_number (hmargin
),
7779 make_number (vmargin
)));
7782 /* If button is not enabled, and we don't have special images
7783 for the disabled state, make the image appear disabled by
7784 applying an appropriate algorithm to it. */
7785 if (!enabled_p
&& idx
< 0)
7786 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7788 /* Put a `display' text property on the string for the image to
7789 display. Put a `menu-item' property on the string that gives
7790 the start of this item's properties in the tool-bar items
7792 image
= Fcons (Qimage
, plist
);
7793 props
= list4 (Qdisplay
, image
,
7794 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7796 /* Let the last image hide all remaining spaces in the tool bar
7797 string. The string can be longer than needed when we reuse a
7799 if (i
+ 1 == f
->n_tool_bar_items
)
7800 end
= SCHARS (f
->desired_tool_bar_string
);
7803 Fadd_text_properties (make_number (i
), make_number (end
),
7804 props
, f
->desired_tool_bar_string
);
7812 /* Display one line of the tool-bar of frame IT->f. */
7815 display_tool_bar_line (it
)
7818 struct glyph_row
*row
= it
->glyph_row
;
7819 int max_x
= it
->last_visible_x
;
7822 prepare_desired_row (row
);
7823 row
->y
= it
->current_y
;
7825 /* Note that this isn't made use of if the face hasn't a box,
7826 so there's no need to check the face here. */
7827 it
->start_of_box_run_p
= 1;
7829 while (it
->current_x
< max_x
)
7831 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7833 /* Get the next display element. */
7834 if (!get_next_display_element (it
))
7837 /* Produce glyphs. */
7838 x_before
= it
->current_x
;
7839 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7840 PRODUCE_GLYPHS (it
);
7842 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7847 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7849 if (x
+ glyph
->pixel_width
> max_x
)
7851 /* Glyph doesn't fit on line. */
7852 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7858 x
+= glyph
->pixel_width
;
7862 /* Stop at line ends. */
7863 if (ITERATOR_AT_END_OF_LINE_P (it
))
7866 set_iterator_to_next (it
, 1);
7871 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7872 extend_face_to_end_of_line (it
);
7873 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7874 last
->right_box_line_p
= 1;
7875 if (last
== row
->glyphs
[TEXT_AREA
])
7876 last
->left_box_line_p
= 1;
7877 compute_line_metrics (it
);
7879 /* If line is empty, make it occupy the rest of the tool-bar. */
7880 if (!row
->displays_text_p
)
7882 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7883 row
->ascent
= row
->phys_ascent
= 0;
7886 row
->full_width_p
= 1;
7887 row
->continued_p
= 0;
7888 row
->truncated_on_left_p
= 0;
7889 row
->truncated_on_right_p
= 0;
7891 it
->current_x
= it
->hpos
= 0;
7892 it
->current_y
+= row
->height
;
7898 /* Value is the number of screen lines needed to make all tool-bar
7899 items of frame F visible. */
7902 tool_bar_lines_needed (f
)
7905 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7908 /* Initialize an iterator for iteration over
7909 F->desired_tool_bar_string in the tool-bar window of frame F. */
7910 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7911 it
.first_visible_x
= 0;
7912 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7913 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7915 while (!ITERATOR_AT_END_P (&it
))
7917 it
.glyph_row
= w
->desired_matrix
->rows
;
7918 clear_glyph_row (it
.glyph_row
);
7919 display_tool_bar_line (&it
);
7922 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7926 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7928 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
7937 frame
= selected_frame
;
7939 CHECK_FRAME (frame
);
7942 if (WINDOWP (f
->tool_bar_window
)
7943 || (w
= XWINDOW (f
->tool_bar_window
),
7944 XFASTINT (w
->height
) > 0))
7946 update_tool_bar (f
, 1);
7947 if (f
->n_tool_bar_items
)
7949 build_desired_tool_bar_string (f
);
7950 nlines
= tool_bar_lines_needed (f
);
7954 return make_number (nlines
);
7958 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7959 height should be changed. */
7962 redisplay_tool_bar (f
)
7967 struct glyph_row
*row
;
7968 int change_height_p
= 0;
7970 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7971 do anything. This means you must start with tool-bar-lines
7972 non-zero to get the auto-sizing effect. Or in other words, you
7973 can turn off tool-bars by specifying tool-bar-lines zero. */
7974 if (!WINDOWP (f
->tool_bar_window
)
7975 || (w
= XWINDOW (f
->tool_bar_window
),
7976 XFASTINT (w
->height
) == 0))
7979 /* Set up an iterator for the tool-bar window. */
7980 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7981 it
.first_visible_x
= 0;
7982 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7985 /* Build a string that represents the contents of the tool-bar. */
7986 build_desired_tool_bar_string (f
);
7987 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7989 /* Display as many lines as needed to display all tool-bar items. */
7990 while (it
.current_y
< it
.last_visible_y
)
7991 display_tool_bar_line (&it
);
7993 /* It doesn't make much sense to try scrolling in the tool-bar
7994 window, so don't do it. */
7995 w
->desired_matrix
->no_scrolling_p
= 1;
7996 w
->must_be_updated_p
= 1;
7998 if (auto_resize_tool_bars_p
)
8002 /* If we couldn't display everything, change the tool-bar's
8004 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8005 change_height_p
= 1;
8007 /* If there are blank lines at the end, except for a partially
8008 visible blank line at the end that is smaller than
8009 CANON_Y_UNIT, change the tool-bar's height. */
8010 row
= it
.glyph_row
- 1;
8011 if (!row
->displays_text_p
8012 && row
->height
>= CANON_Y_UNIT (f
))
8013 change_height_p
= 1;
8015 /* If row displays tool-bar items, but is partially visible,
8016 change the tool-bar's height. */
8017 if (row
->displays_text_p
8018 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8019 change_height_p
= 1;
8021 /* Resize windows as needed by changing the `tool-bar-lines'
8024 && (nlines
= tool_bar_lines_needed (f
),
8025 nlines
!= XFASTINT (w
->height
)))
8027 extern Lisp_Object Qtool_bar_lines
;
8029 int old_height
= XFASTINT (w
->height
);
8031 XSETFRAME (frame
, f
);
8032 clear_glyph_matrix (w
->desired_matrix
);
8033 Fmodify_frame_parameters (frame
,
8034 Fcons (Fcons (Qtool_bar_lines
,
8035 make_number (nlines
)),
8037 if (XFASTINT (w
->height
) != old_height
)
8038 fonts_changed_p
= 1;
8042 return change_height_p
;
8046 /* Get information about the tool-bar item which is displayed in GLYPH
8047 on frame F. Return in *PROP_IDX the index where tool-bar item
8048 properties start in F->tool_bar_items. Value is zero if
8049 GLYPH doesn't display a tool-bar item. */
8052 tool_bar_item_info (f
, glyph
, prop_idx
)
8054 struct glyph
*glyph
;
8061 /* This function can be called asynchronously, which means we must
8062 exclude any possibility that Fget_text_property signals an
8064 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8065 charpos
= max (0, charpos
);
8067 /* Get the text property `menu-item' at pos. The value of that
8068 property is the start index of this item's properties in
8069 F->tool_bar_items. */
8070 prop
= Fget_text_property (make_number (charpos
),
8071 Qmenu_item
, f
->current_tool_bar_string
);
8072 if (INTEGERP (prop
))
8074 *prop_idx
= XINT (prop
);
8083 #endif /* HAVE_WINDOW_SYSTEM */
8087 /************************************************************************
8088 Horizontal scrolling
8089 ************************************************************************/
8091 static int hscroll_window_tree
P_ ((Lisp_Object
));
8092 static int hscroll_windows
P_ ((Lisp_Object
));
8094 /* For all leaf windows in the window tree rooted at WINDOW, set their
8095 hscroll value so that PT is (i) visible in the window, and (ii) so
8096 that it is not within a certain margin at the window's left and
8097 right border. Value is non-zero if any window's hscroll has been
8101 hscroll_window_tree (window
)
8104 int hscrolled_p
= 0;
8105 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
8106 int hscroll_step_abs
= 0;
8107 double hscroll_step_rel
= 0;
8109 if (hscroll_relative_p
)
8111 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
8112 if (hscroll_step_rel
< 0)
8114 hscroll_relative_p
= 0;
8115 hscroll_step_abs
= 0;
8118 else if (INTEGERP (Vhscroll_step
))
8120 hscroll_step_abs
= XINT (Vhscroll_step
);
8121 if (hscroll_step_abs
< 0)
8122 hscroll_step_abs
= 0;
8125 hscroll_step_abs
= 0;
8127 while (WINDOWP (window
))
8129 struct window
*w
= XWINDOW (window
);
8131 if (WINDOWP (w
->hchild
))
8132 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
8133 else if (WINDOWP (w
->vchild
))
8134 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
8135 else if (w
->cursor
.vpos
>= 0)
8137 int h_margin
, text_area_x
, text_area_y
;
8138 int text_area_width
, text_area_height
;
8139 struct glyph_row
*current_cursor_row
8140 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
8141 struct glyph_row
*desired_cursor_row
8142 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
8143 struct glyph_row
*cursor_row
8144 = (desired_cursor_row
->enabled_p
8145 ? desired_cursor_row
8146 : current_cursor_row
);
8148 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8149 &text_area_width
, &text_area_height
);
8151 /* Scroll when cursor is inside this scroll margin. */
8152 h_margin
= hscroll_margin
* CANON_X_UNIT (XFRAME (w
->frame
));
8154 if ((XFASTINT (w
->hscroll
)
8155 && w
->cursor
.x
<= h_margin
)
8156 || (cursor_row
->enabled_p
8157 && cursor_row
->truncated_on_right_p
8158 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
8162 struct buffer
*saved_current_buffer
;
8166 /* Find point in a display of infinite width. */
8167 saved_current_buffer
= current_buffer
;
8168 current_buffer
= XBUFFER (w
->buffer
);
8170 if (w
== XWINDOW (selected_window
))
8171 pt
= BUF_PT (current_buffer
);
8174 pt
= marker_position (w
->pointm
);
8175 pt
= max (BEGV
, pt
);
8179 /* Move iterator to pt starting at cursor_row->start in
8180 a line with infinite width. */
8181 init_to_row_start (&it
, w
, cursor_row
);
8182 it
.last_visible_x
= INFINITY
;
8183 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8184 current_buffer
= saved_current_buffer
;
8186 /* Position cursor in window. */
8187 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
8188 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
8189 / CANON_X_UNIT (it
.f
);
8190 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
8192 if (hscroll_relative_p
)
8193 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
8196 wanted_x
= text_area_width
8197 - hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8200 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8204 if (hscroll_relative_p
)
8205 wanted_x
= text_area_width
* hscroll_step_rel
8208 wanted_x
= hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8211 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8213 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8215 /* Don't call Fset_window_hscroll if value hasn't
8216 changed because it will prevent redisplay
8218 if (XFASTINT (w
->hscroll
) != hscroll
)
8220 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8221 w
->hscroll
= make_number (hscroll
);
8230 /* Value is non-zero if hscroll of any leaf window has been changed. */
8235 /* Set hscroll so that cursor is visible and not inside horizontal
8236 scroll margins for all windows in the tree rooted at WINDOW. See
8237 also hscroll_window_tree above. Value is non-zero if any window's
8238 hscroll has been changed. If it has, desired matrices on the frame
8239 of WINDOW are cleared. */
8242 hscroll_windows (window
)
8247 if (automatic_hscrolling_p
)
8249 hscrolled_p
= hscroll_window_tree (window
);
8251 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8260 /************************************************************************
8262 ************************************************************************/
8264 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8265 to a non-zero value. This is sometimes handy to have in a debugger
8270 /* First and last unchanged row for try_window_id. */
8272 int debug_first_unchanged_at_end_vpos
;
8273 int debug_last_unchanged_at_beg_vpos
;
8275 /* Delta vpos and y. */
8277 int debug_dvpos
, debug_dy
;
8279 /* Delta in characters and bytes for try_window_id. */
8281 int debug_delta
, debug_delta_bytes
;
8283 /* Values of window_end_pos and window_end_vpos at the end of
8286 EMACS_INT debug_end_pos
, debug_end_vpos
;
8288 /* Append a string to W->desired_matrix->method. FMT is a printf
8289 format string. A1...A9 are a supplement for a variable-length
8290 argument list. If trace_redisplay_p is non-zero also printf the
8291 resulting string to stderr. */
8294 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8297 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8300 char *method
= w
->desired_matrix
->method
;
8301 int len
= strlen (method
);
8302 int size
= sizeof w
->desired_matrix
->method
;
8303 int remaining
= size
- len
- 1;
8305 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8306 if (len
&& remaining
)
8312 strncpy (method
+ len
, buffer
, remaining
);
8314 if (trace_redisplay_p
)
8315 fprintf (stderr
, "%p (%s): %s\n",
8317 ((BUFFERP (w
->buffer
)
8318 && STRINGP (XBUFFER (w
->buffer
)->name
))
8319 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
8324 #endif /* GLYPH_DEBUG */
8327 /* Value is non-zero if all changes in window W, which displays
8328 current_buffer, are in the text between START and END. START is a
8329 buffer position, END is given as a distance from Z. Used in
8330 redisplay_internal for display optimization. */
8333 text_outside_line_unchanged_p (w
, start
, end
)
8337 int unchanged_p
= 1;
8339 /* If text or overlays have changed, see where. */
8340 if (XFASTINT (w
->last_modified
) < MODIFF
8341 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8343 /* Gap in the line? */
8344 if (GPT
< start
|| Z
- GPT
< end
)
8347 /* Changes start in front of the line, or end after it? */
8349 && (BEG_UNCHANGED
< start
- 1
8350 || END_UNCHANGED
< end
))
8353 /* If selective display, can't optimize if changes start at the
8354 beginning of the line. */
8356 && INTEGERP (current_buffer
->selective_display
)
8357 && XINT (current_buffer
->selective_display
) > 0
8358 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8361 /* If there are overlays at the start or end of the line, these
8362 may have overlay strings with newlines in them. A change at
8363 START, for instance, may actually concern the display of such
8364 overlay strings as well, and they are displayed on different
8365 lines. So, quickly rule out this case. (For the future, it
8366 might be desirable to implement something more telling than
8367 just BEG/END_UNCHANGED.) */
8370 if (BEG
+ BEG_UNCHANGED
== start
8371 && overlay_touches_p (start
))
8373 if (END_UNCHANGED
== end
8374 && overlay_touches_p (Z
- end
))
8383 /* Do a frame update, taking possible shortcuts into account. This is
8384 the main external entry point for redisplay.
8386 If the last redisplay displayed an echo area message and that message
8387 is no longer requested, we clear the echo area or bring back the
8388 mini-buffer if that is in use. */
8393 redisplay_internal (0);
8397 /* Return 1 if point moved out of or into a composition. Otherwise
8398 return 0. PREV_BUF and PREV_PT are the last point buffer and
8399 position. BUF and PT are the current point buffer and position. */
8402 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8403 struct buffer
*prev_buf
, *buf
;
8410 XSETBUFFER (buffer
, buf
);
8411 /* Check a composition at the last point if point moved within the
8413 if (prev_buf
== buf
)
8416 /* Point didn't move. */
8419 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8420 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8421 && COMPOSITION_VALID_P (start
, end
, prop
)
8422 && start
< prev_pt
&& end
> prev_pt
)
8423 /* The last point was within the composition. Return 1 iff
8424 point moved out of the composition. */
8425 return (pt
<= start
|| pt
>= end
);
8428 /* Check a composition at the current point. */
8429 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8430 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8431 && COMPOSITION_VALID_P (start
, end
, prop
)
8432 && start
< pt
&& end
> pt
);
8436 /* Reconsider the setting of B->clip_changed which is displayed
8440 reconsider_clip_changes (w
, b
)
8445 && !NILP (w
->window_end_valid
)
8446 && w
->current_matrix
->buffer
== b
8447 && w
->current_matrix
->zv
== BUF_ZV (b
)
8448 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8449 b
->clip_changed
= 0;
8451 /* If display wasn't paused, and W is not a tool bar window, see if
8452 point has been moved into or out of a composition. In that case,
8453 we set b->clip_changed to 1 to force updating the screen. If
8454 b->clip_changed has already been set to 1, we can skip this
8456 if (!b
->clip_changed
8457 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8461 if (w
== XWINDOW (selected_window
))
8462 pt
= BUF_PT (current_buffer
);
8464 pt
= marker_position (w
->pointm
);
8466 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8467 || pt
!= XINT (w
->last_point
))
8468 && check_point_in_composition (w
->current_matrix
->buffer
,
8469 XINT (w
->last_point
),
8470 XBUFFER (w
->buffer
), pt
))
8471 b
->clip_changed
= 1;
8476 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8477 response to any user action; therefore, we should preserve the echo
8478 area. (Actually, our caller does that job.) Perhaps in the future
8479 avoid recentering windows if it is not necessary; currently that
8480 causes some problems. */
8483 redisplay_internal (preserve_echo_area
)
8484 int preserve_echo_area
;
8486 struct window
*w
= XWINDOW (selected_window
);
8487 struct frame
*f
= XFRAME (w
->frame
);
8489 int must_finish
= 0;
8490 struct text_pos tlbufpos
, tlendpos
;
8491 int number_of_visible_frames
;
8493 struct frame
*sf
= SELECTED_FRAME ();
8495 /* Non-zero means redisplay has to consider all windows on all
8496 frames. Zero means, only selected_window is considered. */
8497 int consider_all_windows_p
;
8499 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8501 /* No redisplay if running in batch mode or frame is not yet fully
8502 initialized, or redisplay is explicitly turned off by setting
8503 Vinhibit_redisplay. */
8505 || !NILP (Vinhibit_redisplay
)
8506 || !f
->glyphs_initialized_p
)
8509 /* The flag redisplay_performed_directly_p is set by
8510 direct_output_for_insert when it already did the whole screen
8511 update necessary. */
8512 if (redisplay_performed_directly_p
)
8514 redisplay_performed_directly_p
= 0;
8515 if (!hscroll_windows (selected_window
))
8519 #ifdef USE_X_TOOLKIT
8520 if (popup_activated ())
8524 /* I don't think this happens but let's be paranoid. */
8528 /* Record a function that resets redisplaying_p to its old value
8529 when we leave this function. */
8530 count
= SPECPDL_INDEX ();
8531 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8533 specbind (Qinhibit_free_realized_faces
, Qnil
);
8537 reconsider_clip_changes (w
, current_buffer
);
8539 /* If new fonts have been loaded that make a glyph matrix adjustment
8540 necessary, do it. */
8541 if (fonts_changed_p
)
8543 adjust_glyphs (NULL
);
8544 ++windows_or_buffers_changed
;
8545 fonts_changed_p
= 0;
8548 /* If face_change_count is non-zero, init_iterator will free all
8549 realized faces, which includes the faces referenced from current
8550 matrices. So, we can't reuse current matrices in this case. */
8551 if (face_change_count
)
8552 ++windows_or_buffers_changed
;
8554 if (! FRAME_WINDOW_P (sf
)
8555 && previous_terminal_frame
!= sf
)
8557 /* Since frames on an ASCII terminal share the same display
8558 area, displaying a different frame means redisplay the whole
8560 windows_or_buffers_changed
++;
8561 SET_FRAME_GARBAGED (sf
);
8562 XSETFRAME (Vterminal_frame
, sf
);
8564 previous_terminal_frame
= sf
;
8566 /* Set the visible flags for all frames. Do this before checking
8567 for resized or garbaged frames; they want to know if their frames
8568 are visible. See the comment in frame.h for
8569 FRAME_SAMPLE_VISIBILITY. */
8571 Lisp_Object tail
, frame
;
8573 number_of_visible_frames
= 0;
8575 FOR_EACH_FRAME (tail
, frame
)
8577 struct frame
*f
= XFRAME (frame
);
8579 FRAME_SAMPLE_VISIBILITY (f
);
8580 if (FRAME_VISIBLE_P (f
))
8581 ++number_of_visible_frames
;
8582 clear_desired_matrices (f
);
8586 /* Notice any pending interrupt request to change frame size. */
8587 do_pending_window_change (1);
8589 /* Clear frames marked as garbaged. */
8591 clear_garbaged_frames ();
8593 /* Build menubar and tool-bar items. */
8594 prepare_menu_bars ();
8596 if (windows_or_buffers_changed
)
8597 update_mode_lines
++;
8599 /* Detect case that we need to write or remove a star in the mode line. */
8600 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8602 w
->update_mode_line
= Qt
;
8603 if (buffer_shared
> 1)
8604 update_mode_lines
++;
8607 /* If %c is in the mode line, update it if needed. */
8608 if (!NILP (w
->column_number_displayed
)
8609 /* This alternative quickly identifies a common case
8610 where no change is needed. */
8611 && !(PT
== XFASTINT (w
->last_point
)
8612 && XFASTINT (w
->last_modified
) >= MODIFF
8613 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8614 && (XFASTINT (w
->column_number_displayed
)
8615 != (int) current_column ())) /* iftc */
8616 w
->update_mode_line
= Qt
;
8618 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8620 /* The variable buffer_shared is set in redisplay_window and
8621 indicates that we redisplay a buffer in different windows. See
8623 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
8624 || cursor_type_changed
);
8626 /* If specs for an arrow have changed, do thorough redisplay
8627 to ensure we remove any arrow that should no longer exist. */
8628 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8629 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8630 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8632 /* Normally the message* functions will have already displayed and
8633 updated the echo area, but the frame may have been trashed, or
8634 the update may have been preempted, so display the echo area
8635 again here. Checking message_cleared_p captures the case that
8636 the echo area should be cleared. */
8637 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8638 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8639 || (message_cleared_p
8640 && minibuf_level
== 0
8641 /* If the mini-window is currently selected, this means the
8642 echo-area doesn't show through. */
8643 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8645 int window_height_changed_p
= echo_area_display (0);
8648 /* If we don't display the current message, don't clear the
8649 message_cleared_p flag, because, if we did, we wouldn't clear
8650 the echo area in the next redisplay which doesn't preserve
8652 if (!display_last_displayed_message_p
)
8653 message_cleared_p
= 0;
8655 if (fonts_changed_p
)
8657 else if (window_height_changed_p
)
8659 consider_all_windows_p
= 1;
8660 ++update_mode_lines
;
8661 ++windows_or_buffers_changed
;
8663 /* If window configuration was changed, frames may have been
8664 marked garbaged. Clear them or we will experience
8665 surprises wrt scrolling. */
8667 clear_garbaged_frames ();
8670 else if (EQ (selected_window
, minibuf_window
)
8671 && (current_buffer
->clip_changed
8672 || XFASTINT (w
->last_modified
) < MODIFF
8673 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8674 && resize_mini_window (w
, 0))
8676 /* Resized active mini-window to fit the size of what it is
8677 showing if its contents might have changed. */
8679 consider_all_windows_p
= 1;
8680 ++windows_or_buffers_changed
;
8681 ++update_mode_lines
;
8683 /* If window configuration was changed, frames may have been
8684 marked garbaged. Clear them or we will experience
8685 surprises wrt scrolling. */
8687 clear_garbaged_frames ();
8691 /* If showing the region, and mark has changed, we must redisplay
8692 the whole window. The assignment to this_line_start_pos prevents
8693 the optimization directly below this if-statement. */
8694 if (((!NILP (Vtransient_mark_mode
)
8695 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8696 != !NILP (w
->region_showing
))
8697 || (!NILP (w
->region_showing
)
8698 && !EQ (w
->region_showing
,
8699 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8700 CHARPOS (this_line_start_pos
) = 0;
8702 /* Optimize the case that only the line containing the cursor in the
8703 selected window has changed. Variables starting with this_ are
8704 set in display_line and record information about the line
8705 containing the cursor. */
8706 tlbufpos
= this_line_start_pos
;
8707 tlendpos
= this_line_end_pos
;
8708 if (!consider_all_windows_p
8709 && CHARPOS (tlbufpos
) > 0
8710 && NILP (w
->update_mode_line
)
8711 && !current_buffer
->clip_changed
8712 && !current_buffer
->prevent_redisplay_optimizations_p
8713 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8714 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8715 /* Make sure recorded data applies to current buffer, etc. */
8716 && this_line_buffer
== current_buffer
8717 && current_buffer
== XBUFFER (w
->buffer
)
8718 && NILP (w
->force_start
)
8719 && NILP (w
->optional_new_start
)
8720 /* Point must be on the line that we have info recorded about. */
8721 && PT
>= CHARPOS (tlbufpos
)
8722 && PT
<= Z
- CHARPOS (tlendpos
)
8723 /* All text outside that line, including its final newline,
8724 must be unchanged */
8725 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8726 CHARPOS (tlendpos
)))
8728 if (CHARPOS (tlbufpos
) > BEGV
8729 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8730 && (CHARPOS (tlbufpos
) == ZV
8731 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8732 /* Former continuation line has disappeared by becoming empty */
8734 else if (XFASTINT (w
->last_modified
) < MODIFF
8735 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8736 || MINI_WINDOW_P (w
))
8738 /* We have to handle the case of continuation around a
8739 wide-column character (See the comment in indent.c around
8742 For instance, in the following case:
8744 -------- Insert --------
8745 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8746 J_I_ ==> J_I_ `^^' are cursors.
8750 As we have to redraw the line above, we should goto cancel. */
8753 int line_height_before
= this_line_pixel_height
;
8755 /* Note that start_display will handle the case that the
8756 line starting at tlbufpos is a continuation lines. */
8757 start_display (&it
, w
, tlbufpos
);
8759 /* Implementation note: It this still necessary? */
8760 if (it
.current_x
!= this_line_start_x
)
8763 TRACE ((stderr
, "trying display optimization 1\n"));
8764 w
->cursor
.vpos
= -1;
8765 overlay_arrow_seen
= 0;
8766 it
.vpos
= this_line_vpos
;
8767 it
.current_y
= this_line_y
;
8768 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8771 /* If line contains point, is not continued,
8772 and ends at same distance from eob as before, we win */
8773 if (w
->cursor
.vpos
>= 0
8774 /* Line is not continued, otherwise this_line_start_pos
8775 would have been set to 0 in display_line. */
8776 && CHARPOS (this_line_start_pos
)
8777 /* Line ends as before. */
8778 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8779 /* Line has same height as before. Otherwise other lines
8780 would have to be shifted up or down. */
8781 && this_line_pixel_height
== line_height_before
)
8783 /* If this is not the window's last line, we must adjust
8784 the charstarts of the lines below. */
8785 if (it
.current_y
< it
.last_visible_y
)
8787 struct glyph_row
*row
8788 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8789 int delta
, delta_bytes
;
8791 if (Z
- CHARPOS (tlendpos
) == ZV
)
8793 /* This line ends at end of (accessible part of)
8794 buffer. There is no newline to count. */
8796 - CHARPOS (tlendpos
)
8797 - MATRIX_ROW_START_CHARPOS (row
));
8798 delta_bytes
= (Z_BYTE
8799 - BYTEPOS (tlendpos
)
8800 - MATRIX_ROW_START_BYTEPOS (row
));
8804 /* This line ends in a newline. Must take
8805 account of the newline and the rest of the
8806 text that follows. */
8808 - CHARPOS (tlendpos
)
8809 - MATRIX_ROW_START_CHARPOS (row
));
8810 delta_bytes
= (Z_BYTE
8811 - BYTEPOS (tlendpos
)
8812 - MATRIX_ROW_START_BYTEPOS (row
));
8815 increment_matrix_positions (w
->current_matrix
,
8817 w
->current_matrix
->nrows
,
8818 delta
, delta_bytes
);
8821 /* If this row displays text now but previously didn't,
8822 or vice versa, w->window_end_vpos may have to be
8824 if ((it
.glyph_row
- 1)->displays_text_p
)
8826 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8827 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8829 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8830 && this_line_vpos
> 0)
8831 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8832 w
->window_end_valid
= Qnil
;
8834 /* Update hint: No need to try to scroll in update_window. */
8835 w
->desired_matrix
->no_scrolling_p
= 1;
8838 *w
->desired_matrix
->method
= 0;
8839 debug_method_add (w
, "optimization 1");
8846 else if (/* Cursor position hasn't changed. */
8847 PT
== XFASTINT (w
->last_point
)
8848 /* Make sure the cursor was last displayed
8849 in this window. Otherwise we have to reposition it. */
8850 && 0 <= w
->cursor
.vpos
8851 && XINT (w
->height
) > w
->cursor
.vpos
)
8855 do_pending_window_change (1);
8857 /* We used to always goto end_of_redisplay here, but this
8858 isn't enough if we have a blinking cursor. */
8859 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8860 goto end_of_redisplay
;
8864 /* If highlighting the region, or if the cursor is in the echo area,
8865 then we can't just move the cursor. */
8866 else if (! (!NILP (Vtransient_mark_mode
)
8867 && !NILP (current_buffer
->mark_active
))
8868 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8869 || highlight_nonselected_windows
)
8870 && NILP (w
->region_showing
)
8871 && NILP (Vshow_trailing_whitespace
)
8872 && !cursor_in_echo_area
)
8875 struct glyph_row
*row
;
8877 /* Skip from tlbufpos to PT and see where it is. Note that
8878 PT may be in invisible text. If so, we will end at the
8879 next visible position. */
8880 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8881 NULL
, DEFAULT_FACE_ID
);
8882 it
.current_x
= this_line_start_x
;
8883 it
.current_y
= this_line_y
;
8884 it
.vpos
= this_line_vpos
;
8886 /* The call to move_it_to stops in front of PT, but
8887 moves over before-strings. */
8888 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8890 if (it
.vpos
== this_line_vpos
8891 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8894 xassert (this_line_vpos
== it
.vpos
);
8895 xassert (this_line_y
== it
.current_y
);
8896 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8898 *w
->desired_matrix
->method
= 0;
8899 debug_method_add (w
, "optimization 3");
8908 /* Text changed drastically or point moved off of line. */
8909 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8912 CHARPOS (this_line_start_pos
) = 0;
8913 consider_all_windows_p
|= buffer_shared
> 1;
8914 ++clear_face_cache_count
;
8917 /* Build desired matrices, and update the display. If
8918 consider_all_windows_p is non-zero, do it for all windows on all
8919 frames. Otherwise do it for selected_window, only. */
8921 if (consider_all_windows_p
)
8923 Lisp_Object tail
, frame
;
8924 int i
, n
= 0, size
= 50;
8925 struct frame
**updated
8926 = (struct frame
**) alloca (size
* sizeof *updated
);
8928 /* Clear the face cache eventually. */
8929 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8931 clear_face_cache (0);
8932 clear_face_cache_count
= 0;
8935 /* Recompute # windows showing selected buffer. This will be
8936 incremented each time such a window is displayed. */
8939 FOR_EACH_FRAME (tail
, frame
)
8941 struct frame
*f
= XFRAME (frame
);
8943 if (FRAME_WINDOW_P (f
) || f
== sf
)
8945 #ifdef HAVE_WINDOW_SYSTEM
8946 if (clear_face_cache_count
% 50 == 0
8947 && FRAME_WINDOW_P (f
))
8948 clear_image_cache (f
, 0);
8949 #endif /* HAVE_WINDOW_SYSTEM */
8951 /* Mark all the scroll bars to be removed; we'll redeem
8952 the ones we want when we redisplay their windows. */
8953 if (condemn_scroll_bars_hook
)
8954 condemn_scroll_bars_hook (f
);
8956 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8957 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8959 /* Any scroll bars which redisplay_windows should have
8960 nuked should now go away. */
8961 if (judge_scroll_bars_hook
)
8962 judge_scroll_bars_hook (f
);
8964 /* If fonts changed, display again. */
8965 /* ??? rms: I suspect it is a mistake to jump all the way
8966 back to retry here. It should just retry this frame. */
8967 if (fonts_changed_p
)
8970 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8972 /* See if we have to hscroll. */
8973 if (hscroll_windows (f
->root_window
))
8976 /* Prevent various kinds of signals during display
8977 update. stdio is not robust about handling
8978 signals, which can cause an apparent I/O
8980 if (interrupt_input
)
8984 /* Update the display. */
8985 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8986 pause
|= update_frame (f
, 0, 0);
8992 int nbytes
= size
* sizeof *updated
;
8993 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8994 bcopy (updated
, p
, nbytes
);
9003 /* Do the mark_window_display_accurate after all windows have
9004 been redisplayed because this call resets flags in buffers
9005 which are needed for proper redisplay. */
9006 for (i
= 0; i
< n
; ++i
)
9008 struct frame
*f
= updated
[i
];
9009 mark_window_display_accurate (f
->root_window
, 1);
9010 if (frame_up_to_date_hook
)
9011 frame_up_to_date_hook (f
);
9014 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9016 Lisp_Object mini_window
;
9017 struct frame
*mini_frame
;
9019 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9020 /* Use list_of_error, not Qerror, so that
9021 we catch only errors and don't run the debugger. */
9022 internal_condition_case_1 (redisplay_window_1
, selected_window
,
9024 redisplay_window_error
);
9026 /* Compare desired and current matrices, perform output. */
9029 /* If fonts changed, display again. */
9030 if (fonts_changed_p
)
9033 /* Prevent various kinds of signals during display update.
9034 stdio is not robust about handling signals,
9035 which can cause an apparent I/O error. */
9036 if (interrupt_input
)
9040 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9042 if (hscroll_windows (selected_window
))
9045 XWINDOW (selected_window
)->must_be_updated_p
= 1;
9046 pause
= update_frame (sf
, 0, 0);
9049 /* We may have called echo_area_display at the top of this
9050 function. If the echo area is on another frame, that may
9051 have put text on a frame other than the selected one, so the
9052 above call to update_frame would not have caught it. Catch
9054 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9055 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9057 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
9059 XWINDOW (mini_window
)->must_be_updated_p
= 1;
9060 pause
|= update_frame (mini_frame
, 0, 0);
9061 if (!pause
&& hscroll_windows (mini_window
))
9066 /* If display was paused because of pending input, make sure we do a
9067 thorough update the next time. */
9070 /* Prevent the optimization at the beginning of
9071 redisplay_internal that tries a single-line update of the
9072 line containing the cursor in the selected window. */
9073 CHARPOS (this_line_start_pos
) = 0;
9075 /* Let the overlay arrow be updated the next time. */
9076 if (!NILP (last_arrow_position
))
9078 last_arrow_position
= Qt
;
9079 last_arrow_string
= Qt
;
9082 /* If we pause after scrolling, some rows in the current
9083 matrices of some windows are not valid. */
9084 if (!WINDOW_FULL_WIDTH_P (w
)
9085 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
9086 update_mode_lines
= 1;
9090 if (!consider_all_windows_p
)
9092 /* This has already been done above if
9093 consider_all_windows_p is set. */
9094 mark_window_display_accurate_1 (w
, 1);
9096 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9097 last_arrow_string
= Voverlay_arrow_string
;
9099 if (frame_up_to_date_hook
!= 0)
9100 frame_up_to_date_hook (sf
);
9103 update_mode_lines
= 0;
9104 windows_or_buffers_changed
= 0;
9105 cursor_type_changed
= 0;
9108 /* Start SIGIO interrupts coming again. Having them off during the
9109 code above makes it less likely one will discard output, but not
9110 impossible, since there might be stuff in the system buffer here.
9111 But it is much hairier to try to do anything about that. */
9112 if (interrupt_input
)
9116 /* If a frame has become visible which was not before, redisplay
9117 again, so that we display it. Expose events for such a frame
9118 (which it gets when becoming visible) don't call the parts of
9119 redisplay constructing glyphs, so simply exposing a frame won't
9120 display anything in this case. So, we have to display these
9121 frames here explicitly. */
9124 Lisp_Object tail
, frame
;
9127 FOR_EACH_FRAME (tail
, frame
)
9129 int this_is_visible
= 0;
9131 if (XFRAME (frame
)->visible
)
9132 this_is_visible
= 1;
9133 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
9134 if (XFRAME (frame
)->visible
)
9135 this_is_visible
= 1;
9137 if (this_is_visible
)
9141 if (new_count
!= number_of_visible_frames
)
9142 windows_or_buffers_changed
++;
9145 /* Change frame size now if a change is pending. */
9146 do_pending_window_change (1);
9148 /* If we just did a pending size change, or have additional
9149 visible frames, redisplay again. */
9150 if (windows_or_buffers_changed
&& !pause
)
9154 unbind_to (count
, Qnil
);
9158 /* Redisplay, but leave alone any recent echo area message unless
9159 another message has been requested in its place.
9161 This is useful in situations where you need to redisplay but no
9162 user action has occurred, making it inappropriate for the message
9163 area to be cleared. See tracking_off and
9164 wait_reading_process_input for examples of these situations.
9166 FROM_WHERE is an integer saying from where this function was
9167 called. This is useful for debugging. */
9170 redisplay_preserve_echo_area (from_where
)
9173 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9175 if (!NILP (echo_area_buffer
[1]))
9177 /* We have a previously displayed message, but no current
9178 message. Redisplay the previous message. */
9179 display_last_displayed_message_p
= 1;
9180 redisplay_internal (1);
9181 display_last_displayed_message_p
= 0;
9184 redisplay_internal (1);
9188 /* Function registered with record_unwind_protect in
9189 redisplay_internal. Reset redisplaying_p to the value it had
9190 before redisplay_internal was called, and clear
9191 prevent_freeing_realized_faces_p. */
9194 unwind_redisplay (old_redisplaying_p
)
9195 Lisp_Object old_redisplaying_p
;
9197 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9202 /* Mark the display of window W as accurate or inaccurate. If
9203 ACCURATE_P is non-zero mark display of W as accurate. If
9204 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9205 redisplay_internal is called. */
9208 mark_window_display_accurate_1 (w
, accurate_p
)
9212 if (BUFFERP (w
->buffer
))
9214 struct buffer
*b
= XBUFFER (w
->buffer
);
9217 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9218 w
->last_overlay_modified
9219 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9221 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9225 b
->clip_changed
= 0;
9226 b
->prevent_redisplay_optimizations_p
= 0;
9228 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9229 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9230 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9231 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9233 w
->current_matrix
->buffer
= b
;
9234 w
->current_matrix
->begv
= BUF_BEGV (b
);
9235 w
->current_matrix
->zv
= BUF_ZV (b
);
9237 w
->last_cursor
= w
->cursor
;
9238 w
->last_cursor_off_p
= w
->cursor_off_p
;
9240 if (w
== XWINDOW (selected_window
))
9241 w
->last_point
= make_number (BUF_PT (b
));
9243 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9249 w
->window_end_valid
= w
->buffer
;
9250 #if 0 /* This is incorrect with variable-height lines. */
9251 xassert (XINT (w
->window_end_vpos
)
9253 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9255 w
->update_mode_line
= Qnil
;
9260 /* Mark the display of windows in the window tree rooted at WINDOW as
9261 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9262 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9263 be redisplayed the next time redisplay_internal is called. */
9266 mark_window_display_accurate (window
, accurate_p
)
9272 for (; !NILP (window
); window
= w
->next
)
9274 w
= XWINDOW (window
);
9275 mark_window_display_accurate_1 (w
, accurate_p
);
9277 if (!NILP (w
->vchild
))
9278 mark_window_display_accurate (w
->vchild
, accurate_p
);
9279 if (!NILP (w
->hchild
))
9280 mark_window_display_accurate (w
->hchild
, accurate_p
);
9285 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9286 last_arrow_string
= Voverlay_arrow_string
;
9290 /* Force a thorough redisplay the next time by setting
9291 last_arrow_position and last_arrow_string to t, which is
9292 unequal to any useful value of Voverlay_arrow_... */
9293 last_arrow_position
= Qt
;
9294 last_arrow_string
= Qt
;
9299 /* Return value in display table DP (Lisp_Char_Table *) for character
9300 C. Since a display table doesn't have any parent, we don't have to
9301 follow parent. Do not call this function directly but use the
9302 macro DISP_CHAR_VECTOR. */
9305 disp_char_vector (dp
, c
)
9306 struct Lisp_Char_Table
*dp
;
9312 if (SINGLE_BYTE_CHAR_P (c
))
9313 return (dp
->contents
[c
]);
9315 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9318 else if (code
[2] < 32)
9321 /* Here, the possible range of code[0] (== charset ID) is
9322 128..max_charset. Since the top level char table contains data
9323 for multibyte characters after 256th element, we must increment
9324 code[0] by 128 to get a correct index. */
9326 code
[3] = -1; /* anchor */
9328 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9330 val
= dp
->contents
[code
[i
]];
9331 if (!SUB_CHAR_TABLE_P (val
))
9332 return (NILP (val
) ? dp
->defalt
: val
);
9335 /* Here, val is a sub char table. We return the default value of
9337 return (dp
->defalt
);
9342 /***********************************************************************
9344 ***********************************************************************/
9346 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9349 redisplay_windows (window
)
9352 while (!NILP (window
))
9354 struct window
*w
= XWINDOW (window
);
9356 if (!NILP (w
->hchild
))
9357 redisplay_windows (w
->hchild
);
9358 else if (!NILP (w
->vchild
))
9359 redisplay_windows (w
->vchild
);
9362 displayed_buffer
= XBUFFER (w
->buffer
);
9363 /* Use list_of_error, not Qerror, so that
9364 we catch only errors and don't run the debugger. */
9365 internal_condition_case_1 (redisplay_window_0
, window
,
9367 redisplay_window_error
);
9375 redisplay_window_error ()
9377 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
9382 redisplay_window_0 (window
)
9385 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9386 redisplay_window (window
, 0);
9391 redisplay_window_1 (window
)
9394 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9395 redisplay_window (window
, 1);
9399 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9400 DELTA is the number of bytes by which positions recorded in ROW
9401 differ from current buffer positions. */
9404 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9406 struct glyph_row
*row
;
9407 struct glyph_matrix
*matrix
;
9408 int delta
, delta_bytes
, dy
, dvpos
;
9410 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9411 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9413 int pt_old
= PT
- delta
;
9415 /* Skip over glyphs not having an object at the start of the row.
9416 These are special glyphs like truncation marks on terminal
9418 if (row
->displays_text_p
)
9420 && INTEGERP (glyph
->object
)
9421 && glyph
->charpos
< 0)
9423 x
+= glyph
->pixel_width
;
9428 && !INTEGERP (glyph
->object
)
9429 && (!BUFFERP (glyph
->object
)
9430 || glyph
->charpos
< pt_old
))
9432 x
+= glyph
->pixel_width
;
9436 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9438 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9439 w
->cursor
.y
= row
->y
+ dy
;
9441 if (w
== XWINDOW (selected_window
))
9443 if (!row
->continued_p
9444 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9447 this_line_buffer
= XBUFFER (w
->buffer
);
9449 CHARPOS (this_line_start_pos
)
9450 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9451 BYTEPOS (this_line_start_pos
)
9452 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9454 CHARPOS (this_line_end_pos
)
9455 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9456 BYTEPOS (this_line_end_pos
)
9457 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9459 this_line_y
= w
->cursor
.y
;
9460 this_line_pixel_height
= row
->height
;
9461 this_line_vpos
= w
->cursor
.vpos
;
9462 this_line_start_x
= row
->x
;
9465 CHARPOS (this_line_start_pos
) = 0;
9470 /* Run window scroll functions, if any, for WINDOW with new window
9471 start STARTP. Sets the window start of WINDOW to that position.
9473 We assume that the window's buffer is really current. */
9475 static INLINE
struct text_pos
9476 run_window_scroll_functions (window
, startp
)
9478 struct text_pos startp
;
9480 struct window
*w
= XWINDOW (window
);
9481 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9483 if (current_buffer
!= XBUFFER (w
->buffer
))
9486 if (!NILP (Vwindow_scroll_functions
))
9488 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9489 make_number (CHARPOS (startp
)));
9490 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9491 /* In case the hook functions switch buffers. */
9492 if (current_buffer
!= XBUFFER (w
->buffer
))
9493 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9500 /* Make sure the line containing the cursor is fully visible.
9501 A value of 1 means there is nothing to be done.
9502 (Either the line is fully visible, or it cannot be made so,
9504 A value of 0 means the caller should do scrolling
9505 as if point had gone off the screen. */
9508 make_cursor_line_fully_visible (w
)
9511 struct glyph_matrix
*matrix
;
9512 struct glyph_row
*row
;
9515 /* It's not always possible to find the cursor, e.g, when a window
9516 is full of overlay strings. Don't do anything in that case. */
9517 if (w
->cursor
.vpos
< 0)
9520 matrix
= w
->desired_matrix
;
9521 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9523 /* If the cursor row is not partially visible, there's nothing to do. */
9524 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9527 /* If the row the cursor is in is taller than the window's height,
9528 it's not clear what to do, so do nothing. */
9529 window_height
= window_box_height (w
);
9530 if (row
->height
>= window_height
)
9536 /* This code used to try to scroll the window just enough to make
9537 the line visible. It returned 0 to say that the caller should
9538 allocate larger glyph matrices. */
9540 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9542 int dy
= row
->height
- row
->visible_height
;
9545 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9547 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9549 int dy
= - (row
->height
- row
->visible_height
);
9552 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9555 /* When we change the cursor y-position of the selected window,
9556 change this_line_y as well so that the display optimization for
9557 the cursor line of the selected window in redisplay_internal uses
9558 the correct y-position. */
9559 if (w
== XWINDOW (selected_window
))
9560 this_line_y
= w
->cursor
.y
;
9562 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9563 redisplay with larger matrices. */
9564 if (matrix
->nrows
< required_matrix_height (w
))
9566 fonts_changed_p
= 1;
9575 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9576 non-zero means only WINDOW is redisplayed in redisplay_internal.
9577 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9578 in redisplay_window to bring a partially visible line into view in
9579 the case that only the cursor has moved.
9583 1 if scrolling succeeded
9585 0 if scrolling didn't find point.
9587 -1 if new fonts have been loaded so that we must interrupt
9588 redisplay, adjust glyph matrices, and try again. */
9594 SCROLLING_NEED_LARGER_MATRICES
9598 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9599 scroll_step
, temp_scroll_step
)
9601 int just_this_one_p
;
9602 EMACS_INT scroll_conservatively
, scroll_step
;
9603 int temp_scroll_step
;
9605 struct window
*w
= XWINDOW (window
);
9606 struct frame
*f
= XFRAME (w
->frame
);
9607 struct text_pos scroll_margin_pos
;
9608 struct text_pos pos
;
9609 struct text_pos startp
;
9611 Lisp_Object window_end
;
9612 int this_scroll_margin
;
9616 int amount_to_scroll
= 0;
9617 Lisp_Object aggressive
;
9621 debug_method_add (w
, "try_scrolling");
9624 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9626 /* Compute scroll margin height in pixels. We scroll when point is
9627 within this distance from the top or bottom of the window. */
9628 if (scroll_margin
> 0)
9630 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9631 this_scroll_margin
*= CANON_Y_UNIT (f
);
9634 this_scroll_margin
= 0;
9636 /* Compute how much we should try to scroll maximally to bring point
9638 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9639 scroll_max
= max (scroll_step
,
9640 max (scroll_conservatively
, temp_scroll_step
));
9641 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9642 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9643 /* We're trying to scroll because of aggressive scrolling
9644 but no scroll_step is set. Choose an arbitrary one. Maybe
9645 there should be a variable for this. */
9649 scroll_max
*= CANON_Y_UNIT (f
);
9651 /* Decide whether we have to scroll down. Start at the window end
9652 and move this_scroll_margin up to find the position of the scroll
9654 window_end
= Fwindow_end (window
, Qt
);
9655 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9656 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9657 if (this_scroll_margin
)
9659 start_display (&it
, w
, scroll_margin_pos
);
9660 move_it_vertically (&it
, - this_scroll_margin
);
9661 scroll_margin_pos
= it
.current
.pos
;
9664 if (PT
>= CHARPOS (scroll_margin_pos
))
9669 /* Point is in the scroll margin at the bottom of the window, or
9670 below. Compute a new window start that makes point visible. */
9672 /* Compute the distance from the scroll margin to PT.
9673 Give up if the distance is greater than scroll_max. */
9674 start_display (&it
, w
, scroll_margin_pos
);
9676 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9677 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9679 /* To make point visible, we have to move the window start
9680 down so that the line the cursor is in is visible, which
9681 means we have to add in the height of the cursor line. */
9682 dy
= line_bottom_y (&it
) - y0
;
9684 if (dy
> scroll_max
)
9685 return SCROLLING_FAILED
;
9687 /* Move the window start down. If scrolling conservatively,
9688 move it just enough down to make point visible. If
9689 scroll_step is set, move it down by scroll_step. */
9690 start_display (&it
, w
, startp
);
9692 if (scroll_conservatively
)
9694 = max (max (dy
, CANON_Y_UNIT (f
)),
9695 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9696 else if (scroll_step
|| temp_scroll_step
)
9697 amount_to_scroll
= scroll_max
;
9700 aggressive
= current_buffer
->scroll_up_aggressively
;
9701 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9702 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9703 if (NUMBERP (aggressive
))
9704 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9707 if (amount_to_scroll
<= 0)
9708 return SCROLLING_FAILED
;
9710 move_it_vertically (&it
, amount_to_scroll
);
9711 startp
= it
.current
.pos
;
9715 /* See if point is inside the scroll margin at the top of the
9717 scroll_margin_pos
= startp
;
9718 if (this_scroll_margin
)
9720 start_display (&it
, w
, startp
);
9721 move_it_vertically (&it
, this_scroll_margin
);
9722 scroll_margin_pos
= it
.current
.pos
;
9725 if (PT
< CHARPOS (scroll_margin_pos
))
9727 /* Point is in the scroll margin at the top of the window or
9728 above what is displayed in the window. */
9731 /* Compute the vertical distance from PT to the scroll
9732 margin position. Give up if distance is greater than
9734 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9735 start_display (&it
, w
, pos
);
9737 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9738 it
.last_visible_y
, -1,
9739 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9740 dy
= it
.current_y
- y0
;
9741 if (dy
> scroll_max
)
9742 return SCROLLING_FAILED
;
9744 /* Compute new window start. */
9745 start_display (&it
, w
, startp
);
9747 if (scroll_conservatively
)
9749 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9750 else if (scroll_step
|| temp_scroll_step
)
9751 amount_to_scroll
= scroll_max
;
9754 aggressive
= current_buffer
->scroll_down_aggressively
;
9755 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9756 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9757 if (NUMBERP (aggressive
))
9758 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9761 if (amount_to_scroll
<= 0)
9762 return SCROLLING_FAILED
;
9764 move_it_vertically (&it
, - amount_to_scroll
);
9765 startp
= it
.current
.pos
;
9769 /* Run window scroll functions. */
9770 startp
= run_window_scroll_functions (window
, startp
);
9772 /* Display the window. Give up if new fonts are loaded, or if point
9774 if (!try_window (window
, startp
))
9775 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9776 else if (w
->cursor
.vpos
< 0)
9778 clear_glyph_matrix (w
->desired_matrix
);
9779 rc
= SCROLLING_FAILED
;
9783 /* Maybe forget recorded base line for line number display. */
9784 if (!just_this_one_p
9785 || current_buffer
->clip_changed
9786 || BEG_UNCHANGED
< CHARPOS (startp
))
9787 w
->base_line_number
= Qnil
;
9789 /* If cursor ends up on a partially visible line,
9790 treat that as being off the bottom of the screen. */
9791 if (! make_cursor_line_fully_visible (w
))
9793 clear_glyph_matrix (w
->desired_matrix
);
9796 rc
= SCROLLING_SUCCESS
;
9803 /* Compute a suitable window start for window W if display of W starts
9804 on a continuation line. Value is non-zero if a new window start
9807 The new window start will be computed, based on W's width, starting
9808 from the start of the continued line. It is the start of the
9809 screen line with the minimum distance from the old start W->start. */
9812 compute_window_start_on_continuation_line (w
)
9815 struct text_pos pos
, start_pos
;
9816 int window_start_changed_p
= 0;
9818 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9820 /* If window start is on a continuation line... Window start may be
9821 < BEGV in case there's invisible text at the start of the
9822 buffer (M-x rmail, for example). */
9823 if (CHARPOS (start_pos
) > BEGV
9824 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9827 struct glyph_row
*row
;
9829 /* Handle the case that the window start is out of range. */
9830 if (CHARPOS (start_pos
) < BEGV
)
9831 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9832 else if (CHARPOS (start_pos
) > ZV
)
9833 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9835 /* Find the start of the continued line. This should be fast
9836 because scan_buffer is fast (newline cache). */
9837 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9838 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9839 row
, DEFAULT_FACE_ID
);
9840 reseat_at_previous_visible_line_start (&it
);
9842 /* If the line start is "too far" away from the window start,
9843 say it takes too much time to compute a new window start. */
9844 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9845 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9847 int min_distance
, distance
;
9849 /* Move forward by display lines to find the new window
9850 start. If window width was enlarged, the new start can
9851 be expected to be > the old start. If window width was
9852 decreased, the new window start will be < the old start.
9853 So, we're looking for the display line start with the
9854 minimum distance from the old window start. */
9855 pos
= it
.current
.pos
;
9856 min_distance
= INFINITY
;
9857 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9858 distance
< min_distance
)
9860 min_distance
= distance
;
9861 pos
= it
.current
.pos
;
9862 move_it_by_lines (&it
, 1, 0);
9865 /* Set the window start there. */
9866 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9867 window_start_changed_p
= 1;
9871 return window_start_changed_p
;
9875 /* Try cursor movement in case text has not changed in window WINDOW,
9876 with window start STARTP. Value is
9878 CURSOR_MOVEMENT_SUCCESS if successful
9880 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
9882 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
9883 display. *SCROLL_STEP is set to 1, under certain circumstances, if
9884 we want to scroll as if scroll-step were set to 1. See the code.
9886 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
9887 which case we have to abort this redisplay, and adjust matrices
9892 CURSOR_MOVEMENT_SUCCESS
,
9893 CURSOR_MOVEMENT_CANNOT_BE_USED
,
9894 CURSOR_MOVEMENT_MUST_SCROLL
,
9895 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
9899 try_cursor_movement (window
, startp
, scroll_step
)
9901 struct text_pos startp
;
9904 struct window
*w
= XWINDOW (window
);
9905 struct frame
*f
= XFRAME (w
->frame
);
9906 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
9909 if (inhibit_try_cursor_movement
)
9913 /* Handle case where text has not changed, only point, and it has
9914 not moved off the frame. */
9915 if (/* Point may be in this window. */
9916 PT
>= CHARPOS (startp
)
9917 /* Selective display hasn't changed. */
9918 && !current_buffer
->clip_changed
9919 /* Function force-mode-line-update is used to force a thorough
9920 redisplay. It sets either windows_or_buffers_changed or
9921 update_mode_lines. So don't take a shortcut here for these
9923 && !update_mode_lines
9924 && !windows_or_buffers_changed
9925 && !cursor_type_changed
9926 /* Can't use this case if highlighting a region. When a
9927 region exists, cursor movement has to do more than just
9929 && !(!NILP (Vtransient_mark_mode
)
9930 && !NILP (current_buffer
->mark_active
))
9931 && NILP (w
->region_showing
)
9932 && NILP (Vshow_trailing_whitespace
)
9933 /* Right after splitting windows, last_point may be nil. */
9934 && INTEGERP (w
->last_point
)
9935 /* This code is not used for mini-buffer for the sake of the case
9936 of redisplaying to replace an echo area message; since in
9937 that case the mini-buffer contents per se are usually
9938 unchanged. This code is of no real use in the mini-buffer
9939 since the handling of this_line_start_pos, etc., in redisplay
9940 handles the same cases. */
9941 && !EQ (window
, minibuf_window
)
9942 /* When splitting windows or for new windows, it happens that
9943 redisplay is called with a nil window_end_vpos or one being
9944 larger than the window. This should really be fixed in
9945 window.c. I don't have this on my list, now, so we do
9946 approximately the same as the old redisplay code. --gerd. */
9947 && INTEGERP (w
->window_end_vpos
)
9948 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9949 && (FRAME_WINDOW_P (f
)
9950 || !MARKERP (Voverlay_arrow_position
)
9951 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9953 int this_scroll_margin
;
9954 struct glyph_row
*row
= NULL
;
9957 debug_method_add (w
, "cursor movement");
9960 /* Scroll if point within this distance from the top or bottom
9961 of the window. This is a pixel value. */
9962 this_scroll_margin
= max (0, scroll_margin
);
9963 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9964 this_scroll_margin
*= CANON_Y_UNIT (f
);
9966 /* Start with the row the cursor was displayed during the last
9967 not paused redisplay. Give up if that row is not valid. */
9968 if (w
->last_cursor
.vpos
< 0
9969 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9970 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9973 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9974 if (row
->mode_line_p
)
9976 if (!row
->enabled_p
)
9977 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9980 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
9983 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9985 if (PT
> XFASTINT (w
->last_point
))
9987 /* Point has moved forward. */
9988 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9989 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9991 xassert (row
->enabled_p
);
9995 /* The end position of a row equals the start position
9996 of the next row. If PT is there, we would rather
9997 display it in the next line. */
9998 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9999 && MATRIX_ROW_END_CHARPOS (row
) == PT
10000 && !cursor_row_p (w
, row
))
10003 /* If within the scroll margin, scroll. Note that
10004 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
10005 the next line would be drawn, and that
10006 this_scroll_margin can be zero. */
10007 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
10008 || PT
> MATRIX_ROW_END_CHARPOS (row
)
10009 /* Line is completely visible last line in window
10010 and PT is to be set in the next line. */
10011 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
10012 && PT
== MATRIX_ROW_END_CHARPOS (row
)
10013 && !row
->ends_at_zv_p
10014 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
10017 else if (PT
< XFASTINT (w
->last_point
))
10019 /* Cursor has to be moved backward. Note that PT >=
10020 CHARPOS (startp) because of the outer
10022 while (!row
->mode_line_p
10023 && (MATRIX_ROW_START_CHARPOS (row
) > PT
10024 || (MATRIX_ROW_START_CHARPOS (row
) == PT
10025 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
10026 && (row
->y
> this_scroll_margin
10027 || CHARPOS (startp
) == BEGV
))
10029 xassert (row
->enabled_p
);
10033 /* Consider the following case: Window starts at BEGV,
10034 there is invisible, intangible text at BEGV, so that
10035 display starts at some point START > BEGV. It can
10036 happen that we are called with PT somewhere between
10037 BEGV and START. Try to handle that case. */
10038 if (row
< w
->current_matrix
->rows
10039 || row
->mode_line_p
)
10041 row
= w
->current_matrix
->rows
;
10042 if (row
->mode_line_p
)
10046 /* Due to newlines in overlay strings, we may have to
10047 skip forward over overlay strings. */
10048 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
10049 && MATRIX_ROW_END_CHARPOS (row
) == PT
10050 && !cursor_row_p (w
, row
))
10053 /* If within the scroll margin, scroll. */
10054 if (row
->y
< this_scroll_margin
10055 && CHARPOS (startp
) != BEGV
)
10059 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
10060 || PT
> MATRIX_ROW_END_CHARPOS (row
))
10062 /* if PT is not in the glyph row, give up. */
10063 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10065 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10067 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
10068 && !row
->ends_at_zv_p
10069 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
10070 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10071 else if (row
->height
> window_box_height (w
))
10073 /* If we end up in a partially visible line, let's
10074 make it fully visible, except when it's taller
10075 than the window, in which case we can't do much
10078 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10082 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10083 try_window (window
, startp
);
10084 if (!make_cursor_line_fully_visible (w
))
10085 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10087 rc
= CURSOR_MOVEMENT_SUCCESS
;
10091 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10094 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10095 rc
= CURSOR_MOVEMENT_SUCCESS
;
10104 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
10105 selected_window is redisplayed.
10107 We can return without actually redisplaying the window if
10108 fonts_changed_p is nonzero. In that case, redisplay_internal will
10112 redisplay_window (window
, just_this_one_p
)
10113 Lisp_Object window
;
10114 int just_this_one_p
;
10116 struct window
*w
= XWINDOW (window
);
10117 struct frame
*f
= XFRAME (w
->frame
);
10118 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10119 struct buffer
*old
= current_buffer
;
10120 struct text_pos lpoint
, opoint
, startp
;
10121 int update_mode_line
;
10124 /* Record it now because it's overwritten. */
10125 int current_matrix_up_to_date_p
= 0;
10126 /* This is less strict than current_matrix_up_to_date_p.
10127 It indictes that the buffer contents and narrowing are unchanged. */
10128 int buffer_unchanged_p
= 0;
10129 int temp_scroll_step
= 0;
10130 int count
= SPECPDL_INDEX ();
10132 int centering_position
;
10134 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10137 /* W must be a leaf window here. */
10138 xassert (!NILP (w
->buffer
));
10140 *w
->desired_matrix
->method
= 0;
10143 specbind (Qinhibit_point_motion_hooks
, Qt
);
10145 reconsider_clip_changes (w
, buffer
);
10147 /* Has the mode line to be updated? */
10148 update_mode_line
= (!NILP (w
->update_mode_line
)
10149 || update_mode_lines
10150 || buffer
->clip_changed
10151 || buffer
->prevent_redisplay_optimizations_p
);
10153 if (MINI_WINDOW_P (w
))
10155 if (w
== XWINDOW (echo_area_window
)
10156 && !NILP (echo_area_buffer
[0]))
10158 if (update_mode_line
)
10159 /* We may have to update a tty frame's menu bar or a
10160 tool-bar. Example `M-x C-h C-h C-g'. */
10161 goto finish_menu_bars
;
10163 /* We've already displayed the echo area glyphs in this window. */
10164 goto finish_scroll_bars
;
10166 else if (w
!= XWINDOW (minibuf_window
))
10168 /* W is a mini-buffer window, but it's not the currently
10169 active one, so clear it. */
10170 int yb
= window_text_bottom_y (w
);
10171 struct glyph_row
*row
;
10174 for (y
= 0, row
= w
->desired_matrix
->rows
;
10176 y
+= row
->height
, ++row
)
10177 blank_row (w
, row
, y
);
10178 goto finish_scroll_bars
;
10181 clear_glyph_matrix (w
->desired_matrix
);
10184 /* Otherwise set up data on this window; select its buffer and point
10186 /* Really select the buffer, for the sake of buffer-local
10188 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10189 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
10191 current_matrix_up_to_date_p
10192 = (!NILP (w
->window_end_valid
)
10193 && !current_buffer
->clip_changed
10194 && !current_buffer
->prevent_redisplay_optimizations_p
10195 && XFASTINT (w
->last_modified
) >= MODIFF
10196 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10199 = (!NILP (w
->window_end_valid
)
10200 && !current_buffer
->clip_changed
10201 && XFASTINT (w
->last_modified
) >= MODIFF
10202 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10204 /* When windows_or_buffers_changed is non-zero, we can't rely on
10205 the window end being valid, so set it to nil there. */
10206 if (windows_or_buffers_changed
)
10208 /* If window starts on a continuation line, maybe adjust the
10209 window start in case the window's width changed. */
10210 if (XMARKER (w
->start
)->buffer
== current_buffer
)
10211 compute_window_start_on_continuation_line (w
);
10213 w
->window_end_valid
= Qnil
;
10216 /* Some sanity checks. */
10217 CHECK_WINDOW_END (w
);
10218 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
10220 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
10223 /* If %c is in mode line, update it if needed. */
10224 if (!NILP (w
->column_number_displayed
)
10225 /* This alternative quickly identifies a common case
10226 where no change is needed. */
10227 && !(PT
== XFASTINT (w
->last_point
)
10228 && XFASTINT (w
->last_modified
) >= MODIFF
10229 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10230 && (XFASTINT (w
->column_number_displayed
)
10231 != (int) current_column ())) /* iftc */
10232 update_mode_line
= 1;
10234 /* Count number of windows showing the selected buffer. An indirect
10235 buffer counts as its base buffer. */
10236 if (!just_this_one_p
)
10238 struct buffer
*current_base
, *window_base
;
10239 current_base
= current_buffer
;
10240 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10241 if (current_base
->base_buffer
)
10242 current_base
= current_base
->base_buffer
;
10243 if (window_base
->base_buffer
)
10244 window_base
= window_base
->base_buffer
;
10245 if (current_base
== window_base
)
10249 /* Point refers normally to the selected window. For any other
10250 window, set up appropriate value. */
10251 if (!EQ (window
, selected_window
))
10253 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10254 int new_pt_byte
= marker_byte_position (w
->pointm
);
10258 new_pt_byte
= BEGV_BYTE
;
10259 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10261 else if (new_pt
> (ZV
- 1))
10264 new_pt_byte
= ZV_BYTE
;
10265 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10268 /* We don't use SET_PT so that the point-motion hooks don't run. */
10269 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10272 /* If any of the character widths specified in the display table
10273 have changed, invalidate the width run cache. It's true that
10274 this may be a bit late to catch such changes, but the rest of
10275 redisplay goes (non-fatally) haywire when the display table is
10276 changed, so why should we worry about doing any better? */
10277 if (current_buffer
->width_run_cache
)
10279 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10281 if (! disptab_matches_widthtab (disptab
,
10282 XVECTOR (current_buffer
->width_table
)))
10284 invalidate_region_cache (current_buffer
,
10285 current_buffer
->width_run_cache
,
10287 recompute_width_table (current_buffer
, disptab
);
10291 /* If window-start is screwed up, choose a new one. */
10292 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10295 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10297 /* If someone specified a new starting point but did not insist,
10298 check whether it can be used. */
10299 if (!NILP (w
->optional_new_start
)
10300 && CHARPOS (startp
) >= BEGV
10301 && CHARPOS (startp
) <= ZV
)
10303 w
->optional_new_start
= Qnil
;
10304 start_display (&it
, w
, startp
);
10305 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10306 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10307 if (IT_CHARPOS (it
) == PT
)
10308 w
->force_start
= Qt
;
10311 /* Handle case where place to start displaying has been specified,
10312 unless the specified location is outside the accessible range. */
10313 if (!NILP (w
->force_start
)
10314 || w
->frozen_window_start_p
)
10316 /* We set this later on if we have to adjust point. */
10319 w
->force_start
= Qnil
;
10321 w
->window_end_valid
= Qnil
;
10323 /* Forget any recorded base line for line number display. */
10324 if (!buffer_unchanged_p
)
10325 w
->base_line_number
= Qnil
;
10327 /* Redisplay the mode line. Select the buffer properly for that.
10328 Also, run the hook window-scroll-functions
10329 because we have scrolled. */
10330 /* Note, we do this after clearing force_start because
10331 if there's an error, it is better to forget about force_start
10332 than to get into an infinite loop calling the hook functions
10333 and having them get more errors. */
10334 if (!update_mode_line
10335 || ! NILP (Vwindow_scroll_functions
))
10337 update_mode_line
= 1;
10338 w
->update_mode_line
= Qt
;
10339 startp
= run_window_scroll_functions (window
, startp
);
10342 w
->last_modified
= make_number (0);
10343 w
->last_overlay_modified
= make_number (0);
10344 if (CHARPOS (startp
) < BEGV
)
10345 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10346 else if (CHARPOS (startp
) > ZV
)
10347 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10349 /* Redisplay, then check if cursor has been set during the
10350 redisplay. Give up if new fonts were loaded. */
10351 if (!try_window (window
, startp
))
10353 w
->force_start
= Qt
;
10354 clear_glyph_matrix (w
->desired_matrix
);
10355 goto need_larger_matrices
;
10358 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10360 /* If point does not appear, try to move point so it does
10361 appear. The desired matrix has been built above, so we
10362 can use it here. */
10363 new_vpos
= window_box_height (w
) / 2;
10366 if (!make_cursor_line_fully_visible (w
))
10368 /* Point does appear, but on a line partly visible at end of window.
10369 Move it back to a fully-visible line. */
10370 new_vpos
= window_box_height (w
);
10373 /* If we need to move point for either of the above reasons,
10374 now actually do it. */
10377 struct glyph_row
*row
;
10379 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10380 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
10383 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10384 MATRIX_ROW_START_BYTEPOS (row
));
10386 if (w
!= XWINDOW (selected_window
))
10387 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10388 else if (current_buffer
== old
)
10389 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10391 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10393 /* If we are highlighting the region, then we just changed
10394 the region, so redisplay to show it. */
10395 if (!NILP (Vtransient_mark_mode
)
10396 && !NILP (current_buffer
->mark_active
))
10398 clear_glyph_matrix (w
->desired_matrix
);
10399 if (!try_window (window
, startp
))
10400 goto need_larger_matrices
;
10405 debug_method_add (w
, "forced window start");
10410 /* Handle case where text has not changed, only point, and it has
10411 not moved off the frame, and we are not retrying after hscroll.
10412 (current_matrix_up_to_date_p is nonzero when retrying.) */
10413 if (current_matrix_up_to_date_p
10414 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10415 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10419 case CURSOR_MOVEMENT_SUCCESS
:
10422 #if 0 /* try_cursor_movement never returns this value. */
10423 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10424 goto need_larger_matrices
;
10427 case CURSOR_MOVEMENT_MUST_SCROLL
:
10428 goto try_to_scroll
;
10434 /* If current starting point was originally the beginning of a line
10435 but no longer is, find a new starting point. */
10436 else if (!NILP (w
->start_at_line_beg
)
10437 && !(CHARPOS (startp
) <= BEGV
10438 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10441 debug_method_add (w
, "recenter 1");
10446 /* Try scrolling with try_window_id. Value is > 0 if update has
10447 been done, it is -1 if we know that the same window start will
10448 not work. It is 0 if unsuccessful for some other reason. */
10449 else if ((tem
= try_window_id (w
)) != 0)
10452 debug_method_add (w
, "try_window_id %d", tem
);
10455 if (fonts_changed_p
)
10456 goto need_larger_matrices
;
10460 /* Otherwise try_window_id has returned -1 which means that we
10461 don't want the alternative below this comment to execute. */
10463 else if (CHARPOS (startp
) >= BEGV
10464 && CHARPOS (startp
) <= ZV
10465 && PT
>= CHARPOS (startp
)
10466 && (CHARPOS (startp
) < ZV
10467 /* Avoid starting at end of buffer. */
10468 || CHARPOS (startp
) == BEGV
10469 || (XFASTINT (w
->last_modified
) >= MODIFF
10470 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10473 debug_method_add (w
, "same window start");
10476 /* Try to redisplay starting at same place as before.
10477 If point has not moved off frame, accept the results. */
10478 if (!current_matrix_up_to_date_p
10479 /* Don't use try_window_reusing_current_matrix in this case
10480 because a window scroll function can have changed the
10482 || !NILP (Vwindow_scroll_functions
)
10483 || MINI_WINDOW_P (w
)
10484 || !try_window_reusing_current_matrix (w
))
10486 IF_DEBUG (debug_method_add (w
, "1"));
10487 try_window (window
, startp
);
10490 if (fonts_changed_p
)
10491 goto need_larger_matrices
;
10493 if (w
->cursor
.vpos
>= 0)
10495 if (!just_this_one_p
10496 || current_buffer
->clip_changed
10497 || BEG_UNCHANGED
< CHARPOS (startp
))
10498 /* Forget any recorded base line for line number display. */
10499 w
->base_line_number
= Qnil
;
10501 if (!make_cursor_line_fully_visible (w
))
10502 clear_glyph_matrix (w
->desired_matrix
);
10503 /* Drop through and scroll. */
10508 clear_glyph_matrix (w
->desired_matrix
);
10513 w
->last_modified
= make_number (0);
10514 w
->last_overlay_modified
= make_number (0);
10516 /* Redisplay the mode line. Select the buffer properly for that. */
10517 if (!update_mode_line
)
10519 update_mode_line
= 1;
10520 w
->update_mode_line
= Qt
;
10523 /* Try to scroll by specified few lines. */
10524 if ((scroll_conservatively
10526 || temp_scroll_step
10527 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10528 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10529 && !current_buffer
->clip_changed
10530 && CHARPOS (startp
) >= BEGV
10531 && CHARPOS (startp
) <= ZV
)
10533 /* The function returns -1 if new fonts were loaded, 1 if
10534 successful, 0 if not successful. */
10535 int rc
= try_scrolling (window
, just_this_one_p
,
10536 scroll_conservatively
,
10541 case SCROLLING_SUCCESS
:
10544 case SCROLLING_NEED_LARGER_MATRICES
:
10545 goto need_larger_matrices
;
10547 case SCROLLING_FAILED
:
10555 /* Finally, just choose place to start which centers point */
10558 centering_position
= window_box_height (w
) / 2;
10561 /* Jump here with centering_position already set to 0. */
10564 debug_method_add (w
, "recenter");
10567 /* w->vscroll = 0; */
10569 /* Forget any previously recorded base line for line number display. */
10570 if (!buffer_unchanged_p
)
10571 w
->base_line_number
= Qnil
;
10573 /* Move backward half the height of the window. */
10574 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10575 it
.current_y
= it
.last_visible_y
;
10576 move_it_vertically_backward (&it
, centering_position
);
10577 xassert (IT_CHARPOS (it
) >= BEGV
);
10579 /* The function move_it_vertically_backward may move over more
10580 than the specified y-distance. If it->w is small, e.g. a
10581 mini-buffer window, we may end up in front of the window's
10582 display area. Start displaying at the start of the line
10583 containing PT in this case. */
10584 if (it
.current_y
<= 0)
10586 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10587 move_it_vertically (&it
, 0);
10588 xassert (IT_CHARPOS (it
) <= PT
);
10592 it
.current_x
= it
.hpos
= 0;
10594 /* Set startp here explicitly in case that helps avoid an infinite loop
10595 in case the window-scroll-functions functions get errors. */
10596 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10598 /* Run scroll hooks. */
10599 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10601 /* Redisplay the window. */
10602 if (!current_matrix_up_to_date_p
10603 || windows_or_buffers_changed
10604 || cursor_type_changed
10605 /* Don't use try_window_reusing_current_matrix in this case
10606 because it can have changed the buffer. */
10607 || !NILP (Vwindow_scroll_functions
)
10608 || !just_this_one_p
10609 || MINI_WINDOW_P (w
)
10610 || !try_window_reusing_current_matrix (w
))
10611 try_window (window
, startp
);
10613 /* If new fonts have been loaded (due to fontsets), give up. We
10614 have to start a new redisplay since we need to re-adjust glyph
10616 if (fonts_changed_p
)
10617 goto need_larger_matrices
;
10619 /* If cursor did not appear assume that the middle of the window is
10620 in the first line of the window. Do it again with the next line.
10621 (Imagine a window of height 100, displaying two lines of height
10622 60. Moving back 50 from it->last_visible_y will end in the first
10624 if (w
->cursor
.vpos
< 0)
10626 if (!NILP (w
->window_end_valid
)
10627 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10629 clear_glyph_matrix (w
->desired_matrix
);
10630 move_it_by_lines (&it
, 1, 0);
10631 try_window (window
, it
.current
.pos
);
10633 else if (PT
< IT_CHARPOS (it
))
10635 clear_glyph_matrix (w
->desired_matrix
);
10636 move_it_by_lines (&it
, -1, 0);
10637 try_window (window
, it
.current
.pos
);
10641 /* Not much we can do about it. */
10645 /* Consider the following case: Window starts at BEGV, there is
10646 invisible, intangible text at BEGV, so that display starts at
10647 some point START > BEGV. It can happen that we are called with
10648 PT somewhere between BEGV and START. Try to handle that case. */
10649 if (w
->cursor
.vpos
< 0)
10651 struct glyph_row
*row
= w
->current_matrix
->rows
;
10652 if (row
->mode_line_p
)
10654 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10657 if (!make_cursor_line_fully_visible (w
))
10659 /* If centering point failed to make the whole line visible,
10660 put point at the top instead. That has to make the whole line
10661 visible, if it can be done. */
10662 centering_position
= 0;
10668 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10669 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10670 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10673 /* Display the mode line, if we must. */
10674 if ((update_mode_line
10675 /* If window not full width, must redo its mode line
10676 if (a) the window to its side is being redone and
10677 (b) we do a frame-based redisplay. This is a consequence
10678 of how inverted lines are drawn in frame-based redisplay. */
10679 || (!just_this_one_p
10680 && !FRAME_WINDOW_P (f
)
10681 && !WINDOW_FULL_WIDTH_P (w
))
10682 /* Line number to display. */
10683 || INTEGERP (w
->base_line_pos
)
10684 /* Column number is displayed and different from the one displayed. */
10685 || (!NILP (w
->column_number_displayed
)
10686 && (XFASTINT (w
->column_number_displayed
)
10687 != (int) current_column ()))) /* iftc */
10688 /* This means that the window has a mode line. */
10689 && (WINDOW_WANTS_MODELINE_P (w
)
10690 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10692 display_mode_lines (w
);
10694 /* If mode line height has changed, arrange for a thorough
10695 immediate redisplay using the correct mode line height. */
10696 if (WINDOW_WANTS_MODELINE_P (w
)
10697 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10699 fonts_changed_p
= 1;
10700 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10701 = DESIRED_MODE_LINE_HEIGHT (w
);
10704 /* If top line height has changed, arrange for a thorough
10705 immediate redisplay using the correct mode line height. */
10706 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10707 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10709 fonts_changed_p
= 1;
10710 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10711 = DESIRED_HEADER_LINE_HEIGHT (w
);
10714 if (fonts_changed_p
)
10715 goto need_larger_matrices
;
10718 if (!line_number_displayed
10719 && !BUFFERP (w
->base_line_pos
))
10721 w
->base_line_pos
= Qnil
;
10722 w
->base_line_number
= Qnil
;
10727 /* When we reach a frame's selected window, redo the frame's menu bar. */
10728 if (update_mode_line
10729 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10731 int redisplay_menu_p
= 0;
10733 if (FRAME_WINDOW_P (f
))
10735 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
10736 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10738 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10742 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10744 if (redisplay_menu_p
)
10745 display_menu_bar (w
);
10747 #ifdef HAVE_WINDOW_SYSTEM
10748 if (WINDOWP (f
->tool_bar_window
)
10749 && (FRAME_TOOL_BAR_LINES (f
) > 0
10750 || auto_resize_tool_bars_p
))
10751 redisplay_tool_bar (f
);
10755 /* We go to this label, with fonts_changed_p nonzero,
10756 if it is necessary to try again using larger glyph matrices.
10757 We have to redeem the scroll bar even in this case,
10758 because the loop in redisplay_internal expects that. */
10759 need_larger_matrices
:
10761 finish_scroll_bars
:
10763 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10765 int start
, end
, whole
;
10767 /* Calculate the start and end positions for the current window.
10768 At some point, it would be nice to choose between scrollbars
10769 which reflect the whole buffer size, with special markers
10770 indicating narrowing, and scrollbars which reflect only the
10773 Note that mini-buffers sometimes aren't displaying any text. */
10774 if (!MINI_WINDOW_P (w
)
10775 || (w
== XWINDOW (minibuf_window
)
10776 && NILP (echo_area_buffer
[0])))
10779 start
= marker_position (w
->start
) - BEGV
;
10780 /* I don't think this is guaranteed to be right. For the
10781 moment, we'll pretend it is. */
10782 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10786 if (whole
< (end
- start
))
10787 whole
= end
- start
;
10790 start
= end
= whole
= 0;
10792 /* Indicate what this scroll bar ought to be displaying now. */
10793 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10795 /* Note that we actually used the scroll bar attached to this
10796 window, so it shouldn't be deleted at the end of redisplay. */
10797 redeem_scroll_bar_hook (w
);
10800 /* Restore current_buffer and value of point in it. */
10801 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10802 set_buffer_internal_1 (old
);
10803 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10805 unbind_to (count
, Qnil
);
10809 /* Build the complete desired matrix of WINDOW with a window start
10810 buffer position POS. Value is non-zero if successful. It is zero
10811 if fonts were loaded during redisplay which makes re-adjusting
10812 glyph matrices necessary. */
10815 try_window (window
, pos
)
10816 Lisp_Object window
;
10817 struct text_pos pos
;
10819 struct window
*w
= XWINDOW (window
);
10821 struct glyph_row
*last_text_row
= NULL
;
10823 /* Make POS the new window start. */
10824 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10826 /* Mark cursor position as unknown. No overlay arrow seen. */
10827 w
->cursor
.vpos
= -1;
10828 overlay_arrow_seen
= 0;
10830 /* Initialize iterator and info to start at POS. */
10831 start_display (&it
, w
, pos
);
10833 /* Display all lines of W. */
10834 while (it
.current_y
< it
.last_visible_y
)
10836 if (display_line (&it
))
10837 last_text_row
= it
.glyph_row
- 1;
10838 if (fonts_changed_p
)
10842 /* If bottom moved off end of frame, change mode line percentage. */
10843 if (XFASTINT (w
->window_end_pos
) <= 0
10844 && Z
!= IT_CHARPOS (it
))
10845 w
->update_mode_line
= Qt
;
10847 /* Set window_end_pos to the offset of the last character displayed
10848 on the window from the end of current_buffer. Set
10849 window_end_vpos to its row number. */
10852 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10853 w
->window_end_bytepos
10854 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10856 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10858 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10859 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10860 ->displays_text_p
);
10864 w
->window_end_bytepos
= 0;
10865 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10868 /* But that is not valid info until redisplay finishes. */
10869 w
->window_end_valid
= Qnil
;
10875 /************************************************************************
10876 Window redisplay reusing current matrix when buffer has not changed
10877 ************************************************************************/
10879 /* Try redisplay of window W showing an unchanged buffer with a
10880 different window start than the last time it was displayed by
10881 reusing its current matrix. Value is non-zero if successful.
10882 W->start is the new window start. */
10885 try_window_reusing_current_matrix (w
)
10888 struct frame
*f
= XFRAME (w
->frame
);
10889 struct glyph_row
*row
, *bottom_row
;
10892 struct text_pos start
, new_start
;
10893 int nrows_scrolled
, i
;
10894 struct glyph_row
*last_text_row
;
10895 struct glyph_row
*last_reused_text_row
;
10896 struct glyph_row
*start_row
;
10897 int start_vpos
, min_y
, max_y
;
10900 if (inhibit_try_window_reusing
)
10904 if (/* This function doesn't handle terminal frames. */
10905 !FRAME_WINDOW_P (f
)
10906 /* Don't try to reuse the display if windows have been split
10908 || windows_or_buffers_changed
10909 || cursor_type_changed
)
10912 /* Can't do this if region may have changed. */
10913 if ((!NILP (Vtransient_mark_mode
)
10914 && !NILP (current_buffer
->mark_active
))
10915 || !NILP (w
->region_showing
)
10916 || !NILP (Vshow_trailing_whitespace
))
10919 /* If top-line visibility has changed, give up. */
10920 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10921 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10924 /* Give up if old or new display is scrolled vertically. We could
10925 make this function handle this, but right now it doesn't. */
10926 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10927 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10930 /* The variable new_start now holds the new window start. The old
10931 start `start' can be determined from the current matrix. */
10932 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10933 start
= start_row
->start
.pos
;
10934 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10936 /* Clear the desired matrix for the display below. */
10937 clear_glyph_matrix (w
->desired_matrix
);
10939 if (CHARPOS (new_start
) <= CHARPOS (start
))
10943 /* Don't use this method if the display starts with an ellipsis
10944 displayed for invisible text. It's not easy to handle that case
10945 below, and it's certainly not worth the effort since this is
10946 not a frequent case. */
10947 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10950 IF_DEBUG (debug_method_add (w
, "twu1"));
10952 /* Display up to a row that can be reused. The variable
10953 last_text_row is set to the last row displayed that displays
10954 text. Note that it.vpos == 0 if or if not there is a
10955 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10956 start_display (&it
, w
, new_start
);
10957 first_row_y
= it
.current_y
;
10958 w
->cursor
.vpos
= -1;
10959 last_text_row
= last_reused_text_row
= NULL
;
10961 while (it
.current_y
< it
.last_visible_y
10962 && IT_CHARPOS (it
) < CHARPOS (start
)
10963 && !fonts_changed_p
)
10964 if (display_line (&it
))
10965 last_text_row
= it
.glyph_row
- 1;
10967 /* A value of current_y < last_visible_y means that we stopped
10968 at the previous window start, which in turn means that we
10969 have at least one reusable row. */
10970 if (it
.current_y
< it
.last_visible_y
)
10972 /* IT.vpos always starts from 0; it counts text lines. */
10973 nrows_scrolled
= it
.vpos
;
10975 /* Find PT if not already found in the lines displayed. */
10976 if (w
->cursor
.vpos
< 0)
10978 int dy
= it
.current_y
- first_row_y
;
10980 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10981 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
10983 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10984 dy
, nrows_scrolled
);
10987 clear_glyph_matrix (w
->desired_matrix
);
10992 /* Scroll the display. Do it before the current matrix is
10993 changed. The problem here is that update has not yet
10994 run, i.e. part of the current matrix is not up to date.
10995 scroll_run_hook will clear the cursor, and use the
10996 current matrix to get the height of the row the cursor is
10998 run
.current_y
= first_row_y
;
10999 run
.desired_y
= it
.current_y
;
11000 run
.height
= it
.last_visible_y
- it
.current_y
;
11002 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
11005 rif
->update_window_begin_hook (w
);
11006 rif
->clear_mouse_face (w
);
11007 rif
->scroll_run_hook (w
, &run
);
11008 rif
->update_window_end_hook (w
, 0, 0);
11012 /* Shift current matrix down by nrows_scrolled lines. */
11013 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11014 rotate_matrix (w
->current_matrix
,
11016 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11019 /* Disable lines that must be updated. */
11020 for (i
= 0; i
< it
.vpos
; ++i
)
11021 (start_row
+ i
)->enabled_p
= 0;
11023 /* Re-compute Y positions. */
11024 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11025 max_y
= it
.last_visible_y
;
11026 for (row
= start_row
+ nrows_scrolled
;
11030 row
->y
= it
.current_y
;
11031 row
->visible_height
= row
->height
;
11033 if (row
->y
< min_y
)
11034 row
->visible_height
-= min_y
- row
->y
;
11035 if (row
->y
+ row
->height
> max_y
)
11036 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11038 it
.current_y
+= row
->height
;
11040 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11041 last_reused_text_row
= row
;
11042 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
11046 /* Disable lines in the current matrix which are now
11047 below the window. */
11048 for (++row
; row
< bottom_row
; ++row
)
11049 row
->enabled_p
= 0;
11052 /* Update window_end_pos etc.; last_reused_text_row is the last
11053 reused row from the current matrix containing text, if any.
11054 The value of last_text_row is the last displayed line
11055 containing text. */
11056 if (last_reused_text_row
)
11058 w
->window_end_bytepos
11059 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
11061 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
11063 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
11064 w
->current_matrix
));
11066 else if (last_text_row
)
11068 w
->window_end_bytepos
11069 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11071 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11073 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11077 /* This window must be completely empty. */
11078 w
->window_end_bytepos
= 0;
11079 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
11081 w
->window_end_valid
= Qnil
;
11083 /* Update hint: don't try scrolling again in update_window. */
11084 w
->desired_matrix
->no_scrolling_p
= 1;
11087 debug_method_add (w
, "try_window_reusing_current_matrix 1");
11091 else if (CHARPOS (new_start
) > CHARPOS (start
))
11093 struct glyph_row
*pt_row
, *row
;
11094 struct glyph_row
*first_reusable_row
;
11095 struct glyph_row
*first_row_to_display
;
11097 int yb
= window_text_bottom_y (w
);
11099 /* Find the row starting at new_start, if there is one. Don't
11100 reuse a partially visible line at the end. */
11101 first_reusable_row
= start_row
;
11102 while (first_reusable_row
->enabled_p
11103 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
11104 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11105 < CHARPOS (new_start
)))
11106 ++first_reusable_row
;
11108 /* Give up if there is no row to reuse. */
11109 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
11110 || !first_reusable_row
->enabled_p
11111 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11112 != CHARPOS (new_start
)))
11115 /* We can reuse fully visible rows beginning with
11116 first_reusable_row to the end of the window. Set
11117 first_row_to_display to the first row that cannot be reused.
11118 Set pt_row to the row containing point, if there is any. */
11120 for (first_row_to_display
= first_reusable_row
;
11121 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
11122 ++first_row_to_display
)
11124 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
11125 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
11126 pt_row
= first_row_to_display
;
11129 /* Start displaying at the start of first_row_to_display. */
11130 xassert (first_row_to_display
->y
< yb
);
11131 init_to_row_start (&it
, w
, first_row_to_display
);
11133 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
11135 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
11137 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
11138 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
11140 /* Display lines beginning with first_row_to_display in the
11141 desired matrix. Set last_text_row to the last row displayed
11142 that displays text. */
11143 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
11144 if (pt_row
== NULL
)
11145 w
->cursor
.vpos
= -1;
11146 last_text_row
= NULL
;
11147 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
11148 if (display_line (&it
))
11149 last_text_row
= it
.glyph_row
- 1;
11151 /* Give up If point isn't in a row displayed or reused. */
11152 if (w
->cursor
.vpos
< 0)
11154 clear_glyph_matrix (w
->desired_matrix
);
11158 /* If point is in a reused row, adjust y and vpos of the cursor
11162 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
11163 w
->current_matrix
);
11164 w
->cursor
.y
-= first_reusable_row
->y
;
11167 /* Scroll the display. */
11168 run
.current_y
= first_reusable_row
->y
;
11169 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11170 run
.height
= it
.last_visible_y
- run
.current_y
;
11171 dy
= run
.current_y
- run
.desired_y
;
11175 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11177 rif
->update_window_begin_hook (w
);
11178 rif
->clear_mouse_face (w
);
11179 rif
->scroll_run_hook (w
, &run
);
11180 rif
->update_window_end_hook (w
, 0, 0);
11184 /* Adjust Y positions of reused rows. */
11185 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11186 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11187 max_y
= it
.last_visible_y
;
11188 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
11191 row
->visible_height
= row
->height
;
11192 if (row
->y
< min_y
)
11193 row
->visible_height
-= min_y
- row
->y
;
11194 if (row
->y
+ row
->height
> max_y
)
11195 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11198 /* Scroll the current matrix. */
11199 xassert (nrows_scrolled
> 0);
11200 rotate_matrix (w
->current_matrix
,
11202 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11205 /* Disable rows not reused. */
11206 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
11207 row
->enabled_p
= 0;
11209 /* Adjust window end. A null value of last_text_row means that
11210 the window end is in reused rows which in turn means that
11211 only its vpos can have changed. */
11214 w
->window_end_bytepos
11215 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11217 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11219 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11224 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
11227 w
->window_end_valid
= Qnil
;
11228 w
->desired_matrix
->no_scrolling_p
= 1;
11231 debug_method_add (w
, "try_window_reusing_current_matrix 2");
11241 /************************************************************************
11242 Window redisplay reusing current matrix when buffer has changed
11243 ************************************************************************/
11245 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
11246 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
11248 static struct glyph_row
*
11249 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
11250 struct glyph_row
*));
11253 /* Return the last row in MATRIX displaying text. If row START is
11254 non-null, start searching with that row. IT gives the dimensions
11255 of the display. Value is null if matrix is empty; otherwise it is
11256 a pointer to the row found. */
11258 static struct glyph_row
*
11259 find_last_row_displaying_text (matrix
, it
, start
)
11260 struct glyph_matrix
*matrix
;
11262 struct glyph_row
*start
;
11264 struct glyph_row
*row
, *row_found
;
11266 /* Set row_found to the last row in IT->w's current matrix
11267 displaying text. The loop looks funny but think of partially
11270 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11271 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11273 xassert (row
->enabled_p
);
11275 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11284 /* Return the last row in the current matrix of W that is not affected
11285 by changes at the start of current_buffer that occurred since W's
11286 current matrix was built. Value is null if no such row exists.
11288 BEG_UNCHANGED us the number of characters unchanged at the start of
11289 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11290 first changed character in current_buffer. Characters at positions <
11291 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11292 when the current matrix was built. */
11294 static struct glyph_row
*
11295 find_last_unchanged_at_beg_row (w
)
11298 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11299 struct glyph_row
*row
;
11300 struct glyph_row
*row_found
= NULL
;
11301 int yb
= window_text_bottom_y (w
);
11303 /* Find the last row displaying unchanged text. */
11304 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11305 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11306 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11308 if (/* If row ends before first_changed_pos, it is unchanged,
11309 except in some case. */
11310 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11311 /* When row ends in ZV and we write at ZV it is not
11313 && !row
->ends_at_zv_p
11314 /* When first_changed_pos is the end of a continued line,
11315 row is not unchanged because it may be no longer
11317 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11318 && row
->continued_p
))
11321 /* Stop if last visible row. */
11322 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11332 /* Find the first glyph row in the current matrix of W that is not
11333 affected by changes at the end of current_buffer since the
11334 time W's current matrix was built.
11336 Return in *DELTA the number of chars by which buffer positions in
11337 unchanged text at the end of current_buffer must be adjusted.
11339 Return in *DELTA_BYTES the corresponding number of bytes.
11341 Value is null if no such row exists, i.e. all rows are affected by
11344 static struct glyph_row
*
11345 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11347 int *delta
, *delta_bytes
;
11349 struct glyph_row
*row
;
11350 struct glyph_row
*row_found
= NULL
;
11352 *delta
= *delta_bytes
= 0;
11354 /* Display must not have been paused, otherwise the current matrix
11355 is not up to date. */
11356 if (NILP (w
->window_end_valid
))
11359 /* A value of window_end_pos >= END_UNCHANGED means that the window
11360 end is in the range of changed text. If so, there is no
11361 unchanged row at the end of W's current matrix. */
11362 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11365 /* Set row to the last row in W's current matrix displaying text. */
11366 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11368 /* If matrix is entirely empty, no unchanged row exists. */
11369 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11371 /* The value of row is the last glyph row in the matrix having a
11372 meaningful buffer position in it. The end position of row
11373 corresponds to window_end_pos. This allows us to translate
11374 buffer positions in the current matrix to current buffer
11375 positions for characters not in changed text. */
11376 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11377 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11378 int last_unchanged_pos
, last_unchanged_pos_old
;
11379 struct glyph_row
*first_text_row
11380 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11382 *delta
= Z
- Z_old
;
11383 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11385 /* Set last_unchanged_pos to the buffer position of the last
11386 character in the buffer that has not been changed. Z is the
11387 index + 1 of the last character in current_buffer, i.e. by
11388 subtracting END_UNCHANGED we get the index of the last
11389 unchanged character, and we have to add BEG to get its buffer
11391 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11392 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11394 /* Search backward from ROW for a row displaying a line that
11395 starts at a minimum position >= last_unchanged_pos_old. */
11396 for (; row
> first_text_row
; --row
)
11398 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11401 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11406 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11413 /* Make sure that glyph rows in the current matrix of window W
11414 reference the same glyph memory as corresponding rows in the
11415 frame's frame matrix. This function is called after scrolling W's
11416 current matrix on a terminal frame in try_window_id and
11417 try_window_reusing_current_matrix. */
11420 sync_frame_with_window_matrix_rows (w
)
11423 struct frame
*f
= XFRAME (w
->frame
);
11424 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11426 /* Preconditions: W must be a leaf window and full-width. Its frame
11427 must have a frame matrix. */
11428 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11429 xassert (WINDOW_FULL_WIDTH_P (w
));
11430 xassert (!FRAME_WINDOW_P (f
));
11432 /* If W is a full-width window, glyph pointers in W's current matrix
11433 have, by definition, to be the same as glyph pointers in the
11434 corresponding frame matrix. Note that frame matrices have no
11435 marginal areas (see build_frame_matrix). */
11436 window_row
= w
->current_matrix
->rows
;
11437 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11438 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11439 while (window_row
< window_row_end
)
11441 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
11442 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
11444 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
11445 frame_row
->glyphs
[TEXT_AREA
] = start
;
11446 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
11447 frame_row
->glyphs
[LAST_AREA
] = end
;
11449 /* Disable frame rows whose corresponding window rows have
11450 been disabled in try_window_id. */
11451 if (!window_row
->enabled_p
)
11452 frame_row
->enabled_p
= 0;
11454 ++window_row
, ++frame_row
;
11459 /* Find the glyph row in window W containing CHARPOS. Consider all
11460 rows between START and END (not inclusive). END null means search
11461 all rows to the end of the display area of W. Value is the row
11462 containing CHARPOS or null. */
11465 row_containing_pos (w
, charpos
, start
, end
, dy
)
11468 struct glyph_row
*start
, *end
;
11471 struct glyph_row
*row
= start
;
11474 /* If we happen to start on a header-line, skip that. */
11475 if (row
->mode_line_p
)
11478 if ((end
&& row
>= end
) || !row
->enabled_p
)
11481 last_y
= window_text_bottom_y (w
) - dy
;
11483 while ((end
== NULL
|| row
< end
)
11484 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
11485 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11486 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11487 /* The end position of a row equals the start
11488 position of the next row. If CHARPOS is there, we
11489 would rather display it in the next line, except
11490 when this line ends in ZV. */
11491 && !row
->ends_at_zv_p
11492 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))
11495 /* Give up if CHARPOS not found. */
11496 if ((end
&& row
>= end
)
11497 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11498 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11505 /* Try to redisplay window W by reusing its existing display. W's
11506 current matrix must be up to date when this function is called,
11507 i.e. window_end_valid must not be nil.
11511 1 if display has been updated
11512 0 if otherwise unsuccessful
11513 -1 if redisplay with same window start is known not to succeed
11515 The following steps are performed:
11517 1. Find the last row in the current matrix of W that is not
11518 affected by changes at the start of current_buffer. If no such row
11521 2. Find the first row in W's current matrix that is not affected by
11522 changes at the end of current_buffer. Maybe there is no such row.
11524 3. Display lines beginning with the row + 1 found in step 1 to the
11525 row found in step 2 or, if step 2 didn't find a row, to the end of
11528 4. If cursor is not known to appear on the window, give up.
11530 5. If display stopped at the row found in step 2, scroll the
11531 display and current matrix as needed.
11533 6. Maybe display some lines at the end of W, if we must. This can
11534 happen under various circumstances, like a partially visible line
11535 becoming fully visible, or because newly displayed lines are displayed
11536 in smaller font sizes.
11538 7. Update W's window end information. */
11544 struct frame
*f
= XFRAME (w
->frame
);
11545 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11546 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11547 struct glyph_row
*last_unchanged_at_beg_row
;
11548 struct glyph_row
*first_unchanged_at_end_row
;
11549 struct glyph_row
*row
;
11550 struct glyph_row
*bottom_row
;
11553 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11554 struct text_pos start_pos
;
11556 int first_unchanged_at_end_vpos
= 0;
11557 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11558 struct text_pos start
;
11559 int first_changed_charpos
, last_changed_charpos
;
11562 if (inhibit_try_window_id
)
11566 /* This is handy for debugging. */
11568 #define GIVE_UP(X) \
11570 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11574 #define GIVE_UP(X) return 0
11577 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11579 /* Don't use this for mini-windows because these can show
11580 messages and mini-buffers, and we don't handle that here. */
11581 if (MINI_WINDOW_P (w
))
11584 /* This flag is used to prevent redisplay optimizations. */
11585 if (windows_or_buffers_changed
|| cursor_type_changed
)
11588 /* Verify that narrowing has not changed.
11589 Also verify that we were not told to prevent redisplay optimizations.
11590 It would be nice to further
11591 reduce the number of cases where this prevents try_window_id. */
11592 if (current_buffer
->clip_changed
11593 || current_buffer
->prevent_redisplay_optimizations_p
)
11596 /* Window must either use window-based redisplay or be full width. */
11597 if (!FRAME_WINDOW_P (f
)
11598 && (!line_ins_del_ok
11599 || !WINDOW_FULL_WIDTH_P (w
)))
11602 /* Give up if point is not known NOT to appear in W. */
11603 if (PT
< CHARPOS (start
))
11606 /* Another way to prevent redisplay optimizations. */
11607 if (XFASTINT (w
->last_modified
) == 0)
11610 /* Verify that window is not hscrolled. */
11611 if (XFASTINT (w
->hscroll
) != 0)
11614 /* Verify that display wasn't paused. */
11615 if (NILP (w
->window_end_valid
))
11618 /* Can't use this if highlighting a region because a cursor movement
11619 will do more than just set the cursor. */
11620 if (!NILP (Vtransient_mark_mode
)
11621 && !NILP (current_buffer
->mark_active
))
11624 /* Likewise if highlighting trailing whitespace. */
11625 if (!NILP (Vshow_trailing_whitespace
))
11628 /* Likewise if showing a region. */
11629 if (!NILP (w
->region_showing
))
11632 /* Can use this if overlay arrow position and or string have changed. */
11633 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11634 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11638 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11639 only if buffer has really changed. The reason is that the gap is
11640 initially at Z for freshly visited files. The code below would
11641 set end_unchanged to 0 in that case. */
11642 if (MODIFF
> SAVE_MODIFF
11643 /* This seems to happen sometimes after saving a buffer. */
11644 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11646 if (GPT
- BEG
< BEG_UNCHANGED
)
11647 BEG_UNCHANGED
= GPT
- BEG
;
11648 if (Z
- GPT
< END_UNCHANGED
)
11649 END_UNCHANGED
= Z
- GPT
;
11652 /* The position of the first and last character that has been changed. */
11653 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11654 last_changed_charpos
= Z
- END_UNCHANGED
;
11656 /* If window starts after a line end, and the last change is in
11657 front of that newline, then changes don't affect the display.
11658 This case happens with stealth-fontification. Note that although
11659 the display is unchanged, glyph positions in the matrix have to
11660 be adjusted, of course. */
11661 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11662 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11663 && ((last_changed_charpos
< CHARPOS (start
)
11664 && CHARPOS (start
) == BEGV
)
11665 || (last_changed_charpos
< CHARPOS (start
) - 1
11666 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11668 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11669 struct glyph_row
*r0
;
11671 /* Compute how many chars/bytes have been added to or removed
11672 from the buffer. */
11673 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11674 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11676 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11678 /* Give up if PT is not in the window. Note that it already has
11679 been checked at the start of try_window_id that PT is not in
11680 front of the window start. */
11681 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11684 /* If window start is unchanged, we can reuse the whole matrix
11685 as is, after adjusting glyph positions. No need to compute
11686 the window end again, since its offset from Z hasn't changed. */
11687 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11688 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11689 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11691 /* Adjust positions in the glyph matrix. */
11692 if (delta
|| delta_bytes
)
11694 struct glyph_row
*r1
11695 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11696 increment_matrix_positions (w
->current_matrix
,
11697 MATRIX_ROW_VPOS (r0
, current_matrix
),
11698 MATRIX_ROW_VPOS (r1
, current_matrix
),
11699 delta
, delta_bytes
);
11702 /* Set the cursor. */
11703 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11704 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11709 /* Handle the case that changes are all below what is displayed in
11710 the window, and that PT is in the window. This shortcut cannot
11711 be taken if ZV is visible in the window, and text has been added
11712 there that is visible in the window. */
11713 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11714 /* ZV is not visible in the window, or there are no
11715 changes at ZV, actually. */
11716 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11717 || first_changed_charpos
== last_changed_charpos
))
11719 struct glyph_row
*r0
;
11721 /* Give up if PT is not in the window. Note that it already has
11722 been checked at the start of try_window_id that PT is not in
11723 front of the window start. */
11724 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11727 /* If window start is unchanged, we can reuse the whole matrix
11728 as is, without changing glyph positions since no text has
11729 been added/removed in front of the window end. */
11730 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11731 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11733 /* We have to compute the window end anew since text
11734 can have been added/removed after it. */
11736 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11737 w
->window_end_bytepos
11738 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11740 /* Set the cursor. */
11741 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11742 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11747 /* Give up if window start is in the changed area.
11749 The condition used to read
11751 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11753 but why that was tested escapes me at the moment. */
11754 if (CHARPOS (start
) >= first_changed_charpos
11755 && CHARPOS (start
) <= last_changed_charpos
)
11758 /* Check that window start agrees with the start of the first glyph
11759 row in its current matrix. Check this after we know the window
11760 start is not in changed text, otherwise positions would not be
11762 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11763 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11766 /* Give up if the window ends in strings. Overlay strings
11767 at the end are difficult to handle, so don't try. */
11768 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
11769 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
11772 /* Compute the position at which we have to start displaying new
11773 lines. Some of the lines at the top of the window might be
11774 reusable because they are not displaying changed text. Find the
11775 last row in W's current matrix not affected by changes at the
11776 start of current_buffer. Value is null if changes start in the
11777 first line of window. */
11778 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11779 if (last_unchanged_at_beg_row
)
11781 /* Avoid starting to display in the moddle of a character, a TAB
11782 for instance. This is easier than to set up the iterator
11783 exactly, and it's not a frequent case, so the additional
11784 effort wouldn't really pay off. */
11785 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11786 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
11787 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11788 --last_unchanged_at_beg_row
;
11790 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11793 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11795 start_pos
= it
.current
.pos
;
11797 /* Start displaying new lines in the desired matrix at the same
11798 vpos we would use in the current matrix, i.e. below
11799 last_unchanged_at_beg_row. */
11800 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11802 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11803 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11805 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11809 /* There are no reusable lines at the start of the window.
11810 Start displaying in the first line. */
11811 start_display (&it
, w
, start
);
11812 start_pos
= it
.current
.pos
;
11815 /* Find the first row that is not affected by changes at the end of
11816 the buffer. Value will be null if there is no unchanged row, in
11817 which case we must redisplay to the end of the window. delta
11818 will be set to the value by which buffer positions beginning with
11819 first_unchanged_at_end_row have to be adjusted due to text
11821 first_unchanged_at_end_row
11822 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11823 IF_DEBUG (debug_delta
= delta
);
11824 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11826 /* Set stop_pos to the buffer position up to which we will have to
11827 display new lines. If first_unchanged_at_end_row != NULL, this
11828 is the buffer position of the start of the line displayed in that
11829 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11830 that we don't stop at a buffer position. */
11832 if (first_unchanged_at_end_row
)
11834 xassert (last_unchanged_at_beg_row
== NULL
11835 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11837 /* If this is a continuation line, move forward to the next one
11838 that isn't. Changes in lines above affect this line.
11839 Caution: this may move first_unchanged_at_end_row to a row
11840 not displaying text. */
11841 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11842 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11843 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11844 < it
.last_visible_y
))
11845 ++first_unchanged_at_end_row
;
11847 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11848 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11849 >= it
.last_visible_y
))
11850 first_unchanged_at_end_row
= NULL
;
11853 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11855 first_unchanged_at_end_vpos
11856 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11857 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11860 else if (last_unchanged_at_beg_row
== NULL
)
11866 /* Either there is no unchanged row at the end, or the one we have
11867 now displays text. This is a necessary condition for the window
11868 end pos calculation at the end of this function. */
11869 xassert (first_unchanged_at_end_row
== NULL
11870 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11872 debug_last_unchanged_at_beg_vpos
11873 = (last_unchanged_at_beg_row
11874 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11876 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11878 #endif /* GLYPH_DEBUG != 0 */
11881 /* Display new lines. Set last_text_row to the last new line
11882 displayed which has text on it, i.e. might end up as being the
11883 line where the window_end_vpos is. */
11884 w
->cursor
.vpos
= -1;
11885 last_text_row
= NULL
;
11886 overlay_arrow_seen
= 0;
11887 while (it
.current_y
< it
.last_visible_y
11888 && !fonts_changed_p
11889 && (first_unchanged_at_end_row
== NULL
11890 || IT_CHARPOS (it
) < stop_pos
))
11892 if (display_line (&it
))
11893 last_text_row
= it
.glyph_row
- 1;
11896 if (fonts_changed_p
)
11900 /* Compute differences in buffer positions, y-positions etc. for
11901 lines reused at the bottom of the window. Compute what we can
11903 if (first_unchanged_at_end_row
11904 /* No lines reused because we displayed everything up to the
11905 bottom of the window. */
11906 && it
.current_y
< it
.last_visible_y
)
11909 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11911 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11912 run
.current_y
= first_unchanged_at_end_row
->y
;
11913 run
.desired_y
= run
.current_y
+ dy
;
11914 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11918 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11919 first_unchanged_at_end_row
= NULL
;
11921 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11924 /* Find the cursor if not already found. We have to decide whether
11925 PT will appear on this window (it sometimes doesn't, but this is
11926 not a very frequent case.) This decision has to be made before
11927 the current matrix is altered. A value of cursor.vpos < 0 means
11928 that PT is either in one of the lines beginning at
11929 first_unchanged_at_end_row or below the window. Don't care for
11930 lines that might be displayed later at the window end; as
11931 mentioned, this is not a frequent case. */
11932 if (w
->cursor
.vpos
< 0)
11934 /* Cursor in unchanged rows at the top? */
11935 if (PT
< CHARPOS (start_pos
)
11936 && last_unchanged_at_beg_row
)
11938 row
= row_containing_pos (w
, PT
,
11939 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11940 last_unchanged_at_beg_row
+ 1, 0);
11942 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11945 /* Start from first_unchanged_at_end_row looking for PT. */
11946 else if (first_unchanged_at_end_row
)
11948 row
= row_containing_pos (w
, PT
- delta
,
11949 first_unchanged_at_end_row
, NULL
, 0);
11951 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11952 delta_bytes
, dy
, dvpos
);
11955 /* Give up if cursor was not found. */
11956 if (w
->cursor
.vpos
< 0)
11958 clear_glyph_matrix (w
->desired_matrix
);
11963 /* Don't let the cursor end in the scroll margins. */
11965 int this_scroll_margin
, cursor_height
;
11967 this_scroll_margin
= max (0, scroll_margin
);
11968 this_scroll_margin
= min (this_scroll_margin
,
11969 XFASTINT (w
->height
) / 4);
11970 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11971 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11973 if ((w
->cursor
.y
< this_scroll_margin
11974 && CHARPOS (start
) > BEGV
)
11975 /* Don't take scroll margin into account at the bottom because
11976 old redisplay didn't do it either. */
11977 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11979 w
->cursor
.vpos
= -1;
11980 clear_glyph_matrix (w
->desired_matrix
);
11985 /* Scroll the display. Do it before changing the current matrix so
11986 that xterm.c doesn't get confused about where the cursor glyph is
11988 if (dy
&& run
.height
)
11992 if (FRAME_WINDOW_P (f
))
11994 rif
->update_window_begin_hook (w
);
11995 rif
->clear_mouse_face (w
);
11996 rif
->scroll_run_hook (w
, &run
);
11997 rif
->update_window_end_hook (w
, 0, 0);
12001 /* Terminal frame. In this case, dvpos gives the number of
12002 lines to scroll by; dvpos < 0 means scroll up. */
12003 int first_unchanged_at_end_vpos
12004 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
12005 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
12006 int end
= (XFASTINT (w
->top
)
12007 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
12008 + window_internal_height (w
));
12010 /* Perform the operation on the screen. */
12013 /* Scroll last_unchanged_at_beg_row to the end of the
12014 window down dvpos lines. */
12015 set_terminal_window (end
);
12017 /* On dumb terminals delete dvpos lines at the end
12018 before inserting dvpos empty lines. */
12019 if (!scroll_region_ok
)
12020 ins_del_lines (end
- dvpos
, -dvpos
);
12022 /* Insert dvpos empty lines in front of
12023 last_unchanged_at_beg_row. */
12024 ins_del_lines (from
, dvpos
);
12026 else if (dvpos
< 0)
12028 /* Scroll up last_unchanged_at_beg_vpos to the end of
12029 the window to last_unchanged_at_beg_vpos - |dvpos|. */
12030 set_terminal_window (end
);
12032 /* Delete dvpos lines in front of
12033 last_unchanged_at_beg_vpos. ins_del_lines will set
12034 the cursor to the given vpos and emit |dvpos| delete
12036 ins_del_lines (from
+ dvpos
, dvpos
);
12038 /* On a dumb terminal insert dvpos empty lines at the
12040 if (!scroll_region_ok
)
12041 ins_del_lines (end
+ dvpos
, -dvpos
);
12044 set_terminal_window (0);
12050 /* Shift reused rows of the current matrix to the right position.
12051 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
12053 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
12054 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
12057 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
12058 bottom_vpos
, dvpos
);
12059 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
12062 else if (dvpos
> 0)
12064 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
12065 bottom_vpos
, dvpos
);
12066 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
12067 first_unchanged_at_end_vpos
+ dvpos
, 0);
12070 /* For frame-based redisplay, make sure that current frame and window
12071 matrix are in sync with respect to glyph memory. */
12072 if (!FRAME_WINDOW_P (f
))
12073 sync_frame_with_window_matrix_rows (w
);
12075 /* Adjust buffer positions in reused rows. */
12077 increment_matrix_positions (current_matrix
,
12078 first_unchanged_at_end_vpos
+ dvpos
,
12079 bottom_vpos
, delta
, delta_bytes
);
12081 /* Adjust Y positions. */
12083 shift_glyph_matrix (w
, current_matrix
,
12084 first_unchanged_at_end_vpos
+ dvpos
,
12087 if (first_unchanged_at_end_row
)
12088 first_unchanged_at_end_row
+= dvpos
;
12090 /* If scrolling up, there may be some lines to display at the end of
12092 last_text_row_at_end
= NULL
;
12095 /* Scrolling up can leave for example a partially visible line
12096 at the end of the window to be redisplayed. */
12097 /* Set last_row to the glyph row in the current matrix where the
12098 window end line is found. It has been moved up or down in
12099 the matrix by dvpos. */
12100 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
12101 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
12103 /* If last_row is the window end line, it should display text. */
12104 xassert (last_row
->displays_text_p
);
12106 /* If window end line was partially visible before, begin
12107 displaying at that line. Otherwise begin displaying with the
12108 line following it. */
12109 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
12111 init_to_row_start (&it
, w
, last_row
);
12112 it
.vpos
= last_vpos
;
12113 it
.current_y
= last_row
->y
;
12117 init_to_row_end (&it
, w
, last_row
);
12118 it
.vpos
= 1 + last_vpos
;
12119 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
12123 /* We may start in a continuation line. If so, we have to
12124 get the right continuation_lines_width and current_x. */
12125 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
12126 it
.hpos
= it
.current_x
= 0;
12128 /* Display the rest of the lines at the window end. */
12129 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
12130 while (it
.current_y
< it
.last_visible_y
12131 && !fonts_changed_p
)
12133 /* Is it always sure that the display agrees with lines in
12134 the current matrix? I don't think so, so we mark rows
12135 displayed invalid in the current matrix by setting their
12136 enabled_p flag to zero. */
12137 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
12138 if (display_line (&it
))
12139 last_text_row_at_end
= it
.glyph_row
- 1;
12143 /* Update window_end_pos and window_end_vpos. */
12144 if (first_unchanged_at_end_row
12145 && first_unchanged_at_end_row
->y
< it
.last_visible_y
12146 && !last_text_row_at_end
)
12148 /* Window end line if one of the preserved rows from the current
12149 matrix. Set row to the last row displaying text in current
12150 matrix starting at first_unchanged_at_end_row, after
12152 xassert (first_unchanged_at_end_row
->displays_text_p
);
12153 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
12154 first_unchanged_at_end_row
);
12155 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
12157 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12158 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12160 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
12161 xassert (w
->window_end_bytepos
>= 0);
12162 IF_DEBUG (debug_method_add (w
, "A"));
12164 else if (last_text_row_at_end
)
12167 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
12168 w
->window_end_bytepos
12169 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
12171 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
12172 xassert (w
->window_end_bytepos
>= 0);
12173 IF_DEBUG (debug_method_add (w
, "B"));
12175 else if (last_text_row
)
12177 /* We have displayed either to the end of the window or at the
12178 end of the window, i.e. the last row with text is to be found
12179 in the desired matrix. */
12181 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12182 w
->window_end_bytepos
12183 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12185 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
12186 xassert (w
->window_end_bytepos
>= 0);
12188 else if (first_unchanged_at_end_row
== NULL
12189 && last_text_row
== NULL
12190 && last_text_row_at_end
== NULL
)
12192 /* Displayed to end of window, but no line containing text was
12193 displayed. Lines were deleted at the end of the window. */
12194 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
12195 int vpos
= XFASTINT (w
->window_end_vpos
);
12196 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
12197 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
12200 row
== NULL
&& vpos
>= first_vpos
;
12201 --vpos
, --current_row
, --desired_row
)
12203 if (desired_row
->enabled_p
)
12205 if (desired_row
->displays_text_p
)
12208 else if (current_row
->displays_text_p
)
12212 xassert (row
!= NULL
);
12213 w
->window_end_vpos
= make_number (vpos
+ 1);
12214 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12215 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12216 xassert (w
->window_end_bytepos
>= 0);
12217 IF_DEBUG (debug_method_add (w
, "C"));
12222 #if 0 /* This leads to problems, for instance when the cursor is
12223 at ZV, and the cursor line displays no text. */
12224 /* Disable rows below what's displayed in the window. This makes
12225 debugging easier. */
12226 enable_glyph_matrix_rows (current_matrix
,
12227 XFASTINT (w
->window_end_vpos
) + 1,
12231 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
12232 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
12234 /* Record that display has not been completed. */
12235 w
->window_end_valid
= Qnil
;
12236 w
->desired_matrix
->no_scrolling_p
= 1;
12244 /***********************************************************************
12245 More debugging support
12246 ***********************************************************************/
12250 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
12251 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
12252 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
12255 /* Dump the contents of glyph matrix MATRIX on stderr.
12257 GLYPHS 0 means don't show glyph contents.
12258 GLYPHS 1 means show glyphs in short form
12259 GLYPHS > 1 means show glyphs in long form. */
12262 dump_glyph_matrix (matrix
, glyphs
)
12263 struct glyph_matrix
*matrix
;
12267 for (i
= 0; i
< matrix
->nrows
; ++i
)
12268 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12272 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12273 the glyph row and area where the glyph comes from. */
12276 dump_glyph (row
, glyph
, area
)
12277 struct glyph_row
*row
;
12278 struct glyph
*glyph
;
12281 if (glyph
->type
== CHAR_GLYPH
)
12284 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12285 glyph
- row
->glyphs
[TEXT_AREA
],
12288 (BUFFERP (glyph
->object
)
12290 : (STRINGP (glyph
->object
)
12293 glyph
->pixel_width
,
12295 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12299 glyph
->left_box_line_p
,
12300 glyph
->right_box_line_p
);
12302 else if (glyph
->type
== STRETCH_GLYPH
)
12305 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12306 glyph
- row
->glyphs
[TEXT_AREA
],
12309 (BUFFERP (glyph
->object
)
12311 : (STRINGP (glyph
->object
)
12314 glyph
->pixel_width
,
12318 glyph
->left_box_line_p
,
12319 glyph
->right_box_line_p
);
12321 else if (glyph
->type
== IMAGE_GLYPH
)
12324 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12325 glyph
- row
->glyphs
[TEXT_AREA
],
12328 (BUFFERP (glyph
->object
)
12330 : (STRINGP (glyph
->object
)
12333 glyph
->pixel_width
,
12337 glyph
->left_box_line_p
,
12338 glyph
->right_box_line_p
);
12343 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12344 GLYPHS 0 means don't show glyph contents.
12345 GLYPHS 1 means show glyphs in short form
12346 GLYPHS > 1 means show glyphs in long form. */
12349 dump_glyph_row (row
, vpos
, glyphs
)
12350 struct glyph_row
*row
;
12355 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12356 fprintf (stderr
, "=======================================================================\n");
12358 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12359 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12361 MATRIX_ROW_START_CHARPOS (row
),
12362 MATRIX_ROW_END_CHARPOS (row
),
12363 row
->used
[TEXT_AREA
],
12364 row
->contains_overlapping_glyphs_p
,
12366 row
->truncated_on_left_p
,
12367 row
->truncated_on_right_p
,
12368 row
->overlay_arrow_p
,
12370 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12371 row
->displays_text_p
,
12374 row
->ends_in_middle_of_char_p
,
12375 row
->starts_in_middle_of_char_p
,
12381 row
->visible_height
,
12384 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12385 row
->end
.overlay_string_index
,
12386 row
->continuation_lines_width
);
12387 fprintf (stderr
, "%9d %5d\n",
12388 CHARPOS (row
->start
.string_pos
),
12389 CHARPOS (row
->end
.string_pos
));
12390 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12391 row
->end
.dpvec_index
);
12398 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12400 struct glyph
*glyph
= row
->glyphs
[area
];
12401 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12403 /* Glyph for a line end in text. */
12404 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12407 if (glyph
< glyph_end
)
12408 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12410 for (; glyph
< glyph_end
; ++glyph
)
12411 dump_glyph (row
, glyph
, area
);
12414 else if (glyphs
== 1)
12418 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12420 char *s
= (char *) alloca (row
->used
[area
] + 1);
12423 for (i
= 0; i
< row
->used
[area
]; ++i
)
12425 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12426 if (glyph
->type
== CHAR_GLYPH
12427 && glyph
->u
.ch
< 0x80
12428 && glyph
->u
.ch
>= ' ')
12429 s
[i
] = glyph
->u
.ch
;
12435 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12441 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12442 Sdump_glyph_matrix
, 0, 1, "p",
12443 doc
: /* Dump the current matrix of the selected window to stderr.
12444 Shows contents of glyph row structures. With non-nil
12445 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12446 glyphs in short form, otherwise show glyphs in long form. */)
12448 Lisp_Object glyphs
;
12450 struct window
*w
= XWINDOW (selected_window
);
12451 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12453 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12454 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12455 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12456 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12457 fprintf (stderr
, "=============================================\n");
12458 dump_glyph_matrix (w
->current_matrix
,
12459 NILP (glyphs
) ? 0 : XINT (glyphs
));
12464 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
12465 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
12468 struct frame
*f
= XFRAME (selected_frame
);
12469 dump_glyph_matrix (f
->current_matrix
, 1);
12474 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12475 doc
: /* Dump glyph row ROW to stderr.
12476 GLYPH 0 means don't dump glyphs.
12477 GLYPH 1 means dump glyphs in short form.
12478 GLYPH > 1 or omitted means dump glyphs in long form. */)
12480 Lisp_Object row
, glyphs
;
12482 struct glyph_matrix
*matrix
;
12485 CHECK_NUMBER (row
);
12486 matrix
= XWINDOW (selected_window
)->current_matrix
;
12488 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12489 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12491 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12496 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12497 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12498 GLYPH 0 means don't dump glyphs.
12499 GLYPH 1 means dump glyphs in short form.
12500 GLYPH > 1 or omitted means dump glyphs in long form. */)
12502 Lisp_Object row
, glyphs
;
12504 struct frame
*sf
= SELECTED_FRAME ();
12505 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12508 CHECK_NUMBER (row
);
12510 if (vpos
>= 0 && vpos
< m
->nrows
)
12511 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12512 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12517 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12518 doc
: /* Toggle tracing of redisplay.
12519 With ARG, turn tracing on if and only if ARG is positive. */)
12524 trace_redisplay_p
= !trace_redisplay_p
;
12527 arg
= Fprefix_numeric_value (arg
);
12528 trace_redisplay_p
= XINT (arg
) > 0;
12535 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12536 doc
: /* Like `format', but print result to stderr.
12537 usage: (trace-to-stderr STRING &rest OBJECTS) */)
12542 Lisp_Object s
= Fformat (nargs
, args
);
12543 fprintf (stderr
, "%s", SDATA (s
));
12547 #endif /* GLYPH_DEBUG */
12551 /***********************************************************************
12552 Building Desired Matrix Rows
12553 ***********************************************************************/
12555 /* Return a temporary glyph row holding the glyphs of an overlay
12556 arrow. Only used for non-window-redisplay windows. */
12558 static struct glyph_row
*
12559 get_overlay_arrow_glyph_row (w
)
12562 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12563 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12564 struct buffer
*old
= current_buffer
;
12565 const unsigned char *arrow_string
= SDATA (Voverlay_arrow_string
);
12566 int arrow_len
= SCHARS (Voverlay_arrow_string
);
12567 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12568 const unsigned char *p
;
12571 int n_glyphs_before
;
12573 set_buffer_temp (buffer
);
12574 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12575 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12576 SET_TEXT_POS (it
.position
, 0, 0);
12578 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12580 while (p
< arrow_end
)
12582 Lisp_Object face
, ilisp
;
12584 /* Get the next character. */
12586 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12588 it
.c
= *p
, it
.len
= 1;
12591 /* Get its face. */
12592 ilisp
= make_number (p
- arrow_string
);
12593 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12594 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12596 /* Compute its width, get its glyphs. */
12597 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12598 SET_TEXT_POS (it
.position
, -1, -1);
12599 PRODUCE_GLYPHS (&it
);
12601 /* If this character doesn't fit any more in the line, we have
12602 to remove some glyphs. */
12603 if (it
.current_x
> it
.last_visible_x
)
12605 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12610 set_buffer_temp (old
);
12611 return it
.glyph_row
;
12615 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12616 glyphs are only inserted for terminal frames since we can't really
12617 win with truncation glyphs when partially visible glyphs are
12618 involved. Which glyphs to insert is determined by
12619 produce_special_glyphs. */
12622 insert_left_trunc_glyphs (it
)
12625 struct it truncate_it
;
12626 struct glyph
*from
, *end
, *to
, *toend
;
12628 xassert (!FRAME_WINDOW_P (it
->f
));
12630 /* Get the truncation glyphs. */
12632 truncate_it
.current_x
= 0;
12633 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12634 truncate_it
.glyph_row
= &scratch_glyph_row
;
12635 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12636 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12637 truncate_it
.object
= make_number (0);
12638 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12640 /* Overwrite glyphs from IT with truncation glyphs. */
12641 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12642 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12643 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12644 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12649 /* There may be padding glyphs left over. Overwrite them too. */
12650 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12652 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12658 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12662 /* Compute the pixel height and width of IT->glyph_row.
12664 Most of the time, ascent and height of a display line will be equal
12665 to the max_ascent and max_height values of the display iterator
12666 structure. This is not the case if
12668 1. We hit ZV without displaying anything. In this case, max_ascent
12669 and max_height will be zero.
12671 2. We have some glyphs that don't contribute to the line height.
12672 (The glyph row flag contributes_to_line_height_p is for future
12673 pixmap extensions).
12675 The first case is easily covered by using default values because in
12676 these cases, the line height does not really matter, except that it
12677 must not be zero. */
12680 compute_line_metrics (it
)
12683 struct glyph_row
*row
= it
->glyph_row
;
12686 if (FRAME_WINDOW_P (it
->f
))
12688 int i
, min_y
, max_y
;
12690 /* The line may consist of one space only, that was added to
12691 place the cursor on it. If so, the row's height hasn't been
12693 if (row
->height
== 0)
12695 if (it
->max_ascent
+ it
->max_descent
== 0)
12696 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12697 row
->ascent
= it
->max_ascent
;
12698 row
->height
= it
->max_ascent
+ it
->max_descent
;
12699 row
->phys_ascent
= it
->max_phys_ascent
;
12700 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12703 /* Compute the width of this line. */
12704 row
->pixel_width
= row
->x
;
12705 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12706 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12708 xassert (row
->pixel_width
>= 0);
12709 xassert (row
->ascent
>= 0 && row
->height
> 0);
12711 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12712 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12714 /* If first line's physical ascent is larger than its logical
12715 ascent, use the physical ascent, and make the row taller.
12716 This makes accented characters fully visible. */
12717 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12718 && row
->phys_ascent
> row
->ascent
)
12720 row
->height
+= row
->phys_ascent
- row
->ascent
;
12721 row
->ascent
= row
->phys_ascent
;
12724 /* Compute how much of the line is visible. */
12725 row
->visible_height
= row
->height
;
12727 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12728 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12730 if (row
->y
< min_y
)
12731 row
->visible_height
-= min_y
- row
->y
;
12732 if (row
->y
+ row
->height
> max_y
)
12733 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12737 row
->pixel_width
= row
->used
[TEXT_AREA
];
12738 if (row
->continued_p
)
12739 row
->pixel_width
-= it
->continuation_pixel_width
;
12740 else if (row
->truncated_on_right_p
)
12741 row
->pixel_width
-= it
->truncation_pixel_width
;
12742 row
->ascent
= row
->phys_ascent
= 0;
12743 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12746 /* Compute a hash code for this row. */
12748 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12749 for (i
= 0; i
< row
->used
[area
]; ++i
)
12750 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12751 + row
->glyphs
[area
][i
].u
.val
12752 + row
->glyphs
[area
][i
].face_id
12753 + row
->glyphs
[area
][i
].padding_p
12754 + (row
->glyphs
[area
][i
].type
<< 2));
12756 it
->max_ascent
= it
->max_descent
= 0;
12757 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12761 /* Append one space to the glyph row of iterator IT if doing a
12762 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12763 space have the default face, otherwise let it have the same face as
12764 IT->face_id. Value is non-zero if a space was added.
12766 This function is called to make sure that there is always one glyph
12767 at the end of a glyph row that the cursor can be set on under
12768 window-systems. (If there weren't such a glyph we would not know
12769 how wide and tall a box cursor should be displayed).
12771 At the same time this space let's a nicely handle clearing to the
12772 end of the line if the row ends in italic text. */
12775 append_space (it
, default_face_p
)
12777 int default_face_p
;
12779 if (FRAME_WINDOW_P (it
->f
))
12781 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12783 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12784 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12786 /* Save some values that must not be changed.
12787 Must save IT->c and IT->len because otherwise
12788 ITERATOR_AT_END_P wouldn't work anymore after
12789 append_space has been called. */
12790 enum display_element_type saved_what
= it
->what
;
12791 int saved_c
= it
->c
, saved_len
= it
->len
;
12792 int saved_x
= it
->current_x
;
12793 int saved_face_id
= it
->face_id
;
12794 struct text_pos saved_pos
;
12795 Lisp_Object saved_object
;
12798 saved_object
= it
->object
;
12799 saved_pos
= it
->position
;
12801 it
->what
= IT_CHARACTER
;
12802 bzero (&it
->position
, sizeof it
->position
);
12803 it
->object
= make_number (0);
12807 if (default_face_p
)
12808 it
->face_id
= DEFAULT_FACE_ID
;
12809 else if (it
->face_before_selective_p
)
12810 it
->face_id
= it
->saved_face_id
;
12811 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12812 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12814 PRODUCE_GLYPHS (it
);
12816 it
->current_x
= saved_x
;
12817 it
->object
= saved_object
;
12818 it
->position
= saved_pos
;
12819 it
->what
= saved_what
;
12820 it
->face_id
= saved_face_id
;
12821 it
->len
= saved_len
;
12831 /* Extend the face of the last glyph in the text area of IT->glyph_row
12832 to the end of the display line. Called from display_line.
12833 If the glyph row is empty, add a space glyph to it so that we
12834 know the face to draw. Set the glyph row flag fill_line_p. */
12837 extend_face_to_end_of_line (it
)
12841 struct frame
*f
= it
->f
;
12843 /* If line is already filled, do nothing. */
12844 if (it
->current_x
>= it
->last_visible_x
)
12847 /* Face extension extends the background and box of IT->face_id
12848 to the end of the line. If the background equals the background
12849 of the frame, we don't have to do anything. */
12850 if (it
->face_before_selective_p
)
12851 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12853 face
= FACE_FROM_ID (f
, it
->face_id
);
12855 if (FRAME_WINDOW_P (f
)
12856 && face
->box
== FACE_NO_BOX
12857 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12861 /* Set the glyph row flag indicating that the face of the last glyph
12862 in the text area has to be drawn to the end of the text area. */
12863 it
->glyph_row
->fill_line_p
= 1;
12865 /* If current character of IT is not ASCII, make sure we have the
12866 ASCII face. This will be automatically undone the next time
12867 get_next_display_element returns a multibyte character. Note
12868 that the character will always be single byte in unibyte text. */
12869 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12871 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12874 if (FRAME_WINDOW_P (f
))
12876 /* If the row is empty, add a space with the current face of IT,
12877 so that we know which face to draw. */
12878 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12880 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12881 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12882 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12887 /* Save some values that must not be changed. */
12888 int saved_x
= it
->current_x
;
12889 struct text_pos saved_pos
;
12890 Lisp_Object saved_object
;
12891 enum display_element_type saved_what
= it
->what
;
12892 int saved_face_id
= it
->face_id
;
12894 saved_object
= it
->object
;
12895 saved_pos
= it
->position
;
12897 it
->what
= IT_CHARACTER
;
12898 bzero (&it
->position
, sizeof it
->position
);
12899 it
->object
= make_number (0);
12902 it
->face_id
= face
->id
;
12904 PRODUCE_GLYPHS (it
);
12906 while (it
->current_x
<= it
->last_visible_x
)
12907 PRODUCE_GLYPHS (it
);
12909 /* Don't count these blanks really. It would let us insert a left
12910 truncation glyph below and make us set the cursor on them, maybe. */
12911 it
->current_x
= saved_x
;
12912 it
->object
= saved_object
;
12913 it
->position
= saved_pos
;
12914 it
->what
= saved_what
;
12915 it
->face_id
= saved_face_id
;
12920 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12921 trailing whitespace. */
12924 trailing_whitespace_p (charpos
)
12927 int bytepos
= CHAR_TO_BYTE (charpos
);
12930 while (bytepos
< ZV_BYTE
12931 && (c
= FETCH_CHAR (bytepos
),
12932 c
== ' ' || c
== '\t'))
12935 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12937 if (bytepos
!= PT_BYTE
)
12944 /* Highlight trailing whitespace, if any, in ROW. */
12947 highlight_trailing_whitespace (f
, row
)
12949 struct glyph_row
*row
;
12951 int used
= row
->used
[TEXT_AREA
];
12955 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12956 struct glyph
*glyph
= start
+ used
- 1;
12958 /* Skip over glyphs inserted to display the cursor at the
12959 end of a line, for extending the face of the last glyph
12960 to the end of the line on terminals, and for truncation
12961 and continuation glyphs. */
12962 while (glyph
>= start
12963 && glyph
->type
== CHAR_GLYPH
12964 && INTEGERP (glyph
->object
))
12967 /* If last glyph is a space or stretch, and it's trailing
12968 whitespace, set the face of all trailing whitespace glyphs in
12969 IT->glyph_row to `trailing-whitespace'. */
12971 && BUFFERP (glyph
->object
)
12972 && (glyph
->type
== STRETCH_GLYPH
12973 || (glyph
->type
== CHAR_GLYPH
12974 && glyph
->u
.ch
== ' '))
12975 && trailing_whitespace_p (glyph
->charpos
))
12977 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12979 while (glyph
>= start
12980 && BUFFERP (glyph
->object
)
12981 && (glyph
->type
== STRETCH_GLYPH
12982 || (glyph
->type
== CHAR_GLYPH
12983 && glyph
->u
.ch
== ' ')))
12984 (glyph
--)->face_id
= face_id
;
12990 /* Value is non-zero if glyph row ROW in window W should be
12991 used to hold the cursor. */
12994 cursor_row_p (w
, row
)
12996 struct glyph_row
*row
;
12998 int cursor_row_p
= 1;
13000 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
13002 /* If the row ends with a newline from a string, we don't want
13003 the cursor there (if the row is continued it doesn't end in a
13005 if (CHARPOS (row
->end
.string_pos
) >= 0
13006 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13007 cursor_row_p
= row
->continued_p
;
13009 /* If the row ends at ZV, display the cursor at the end of that
13010 row instead of at the start of the row below. */
13011 else if (row
->ends_at_zv_p
)
13017 return cursor_row_p
;
13021 /* Construct the glyph row IT->glyph_row in the desired matrix of
13022 IT->w from text at the current position of IT. See dispextern.h
13023 for an overview of struct it. Value is non-zero if
13024 IT->glyph_row displays text, as opposed to a line displaying ZV
13031 struct glyph_row
*row
= it
->glyph_row
;
13033 /* We always start displaying at hpos zero even if hscrolled. */
13034 xassert (it
->hpos
== 0 && it
->current_x
== 0);
13036 /* We must not display in a row that's not a text row. */
13037 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
13038 < it
->w
->desired_matrix
->nrows
);
13040 /* Is IT->w showing the region? */
13041 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
13043 /* Clear the result glyph row and enable it. */
13044 prepare_desired_row (row
);
13046 row
->y
= it
->current_y
;
13047 row
->start
= it
->current
;
13048 row
->continuation_lines_width
= it
->continuation_lines_width
;
13049 row
->displays_text_p
= 1;
13050 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
13051 it
->starts_in_middle_of_char_p
= 0;
13053 /* Arrange the overlays nicely for our purposes. Usually, we call
13054 display_line on only one line at a time, in which case this
13055 can't really hurt too much, or we call it on lines which appear
13056 one after another in the buffer, in which case all calls to
13057 recenter_overlay_lists but the first will be pretty cheap. */
13058 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
13060 /* Move over display elements that are not visible because we are
13061 hscrolled. This may stop at an x-position < IT->first_visible_x
13062 if the first glyph is partially visible or if we hit a line end. */
13063 if (it
->current_x
< it
->first_visible_x
)
13064 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
13065 MOVE_TO_POS
| MOVE_TO_X
);
13067 /* Get the initial row height. This is either the height of the
13068 text hscrolled, if there is any, or zero. */
13069 row
->ascent
= it
->max_ascent
;
13070 row
->height
= it
->max_ascent
+ it
->max_descent
;
13071 row
->phys_ascent
= it
->max_phys_ascent
;
13072 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13074 /* Loop generating characters. The loop is left with IT on the next
13075 character to display. */
13078 int n_glyphs_before
, hpos_before
, x_before
;
13080 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
13082 /* Retrieve the next thing to display. Value is zero if end of
13084 if (!get_next_display_element (it
))
13086 /* Maybe add a space at the end of this line that is used to
13087 display the cursor there under X. Set the charpos of the
13088 first glyph of blank lines not corresponding to any text
13090 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
13091 || row
->used
[TEXT_AREA
] == 0)
13093 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
13094 row
->displays_text_p
= 0;
13096 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
13097 && (!MINI_WINDOW_P (it
->w
)
13098 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
13099 row
->indicate_empty_line_p
= 1;
13102 it
->continuation_lines_width
= 0;
13103 row
->ends_at_zv_p
= 1;
13107 /* Now, get the metrics of what we want to display. This also
13108 generates glyphs in `row' (which is IT->glyph_row). */
13109 n_glyphs_before
= row
->used
[TEXT_AREA
];
13112 /* Remember the line height so far in case the next element doesn't
13113 fit on the line. */
13114 if (!it
->truncate_lines_p
)
13116 ascent
= it
->max_ascent
;
13117 descent
= it
->max_descent
;
13118 phys_ascent
= it
->max_phys_ascent
;
13119 phys_descent
= it
->max_phys_descent
;
13122 PRODUCE_GLYPHS (it
);
13124 /* If this display element was in marginal areas, continue with
13126 if (it
->area
!= TEXT_AREA
)
13128 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13129 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13130 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13131 row
->phys_height
= max (row
->phys_height
,
13132 it
->max_phys_ascent
+ it
->max_phys_descent
);
13133 set_iterator_to_next (it
, 1);
13137 /* Does the display element fit on the line? If we truncate
13138 lines, we should draw past the right edge of the window. If
13139 we don't truncate, we want to stop so that we can display the
13140 continuation glyph before the right margin. If lines are
13141 continued, there are two possible strategies for characters
13142 resulting in more than 1 glyph (e.g. tabs): Display as many
13143 glyphs as possible in this line and leave the rest for the
13144 continuation line, or display the whole element in the next
13145 line. Original redisplay did the former, so we do it also. */
13146 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
13147 hpos_before
= it
->hpos
;
13150 if (/* Not a newline. */
13152 /* Glyphs produced fit entirely in the line. */
13153 && it
->current_x
< it
->last_visible_x
)
13155 it
->hpos
+= nglyphs
;
13156 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13157 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13158 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13159 row
->phys_height
= max (row
->phys_height
,
13160 it
->max_phys_ascent
+ it
->max_phys_descent
);
13161 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
13162 row
->x
= x
- it
->first_visible_x
;
13167 struct glyph
*glyph
;
13169 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
13171 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13172 new_x
= x
+ glyph
->pixel_width
;
13174 if (/* Lines are continued. */
13175 !it
->truncate_lines_p
13176 && (/* Glyph doesn't fit on the line. */
13177 new_x
> it
->last_visible_x
13178 /* Or it fits exactly on a window system frame. */
13179 || (new_x
== it
->last_visible_x
13180 && FRAME_WINDOW_P (it
->f
))))
13182 /* End of a continued line. */
13185 || (new_x
== it
->last_visible_x
13186 && FRAME_WINDOW_P (it
->f
)))
13188 /* Current glyph is the only one on the line or
13189 fits exactly on the line. We must continue
13190 the line because we can't draw the cursor
13191 after the glyph. */
13192 row
->continued_p
= 1;
13193 it
->current_x
= new_x
;
13194 it
->continuation_lines_width
+= new_x
;
13196 if (i
== nglyphs
- 1)
13197 set_iterator_to_next (it
, 1);
13199 else if (CHAR_GLYPH_PADDING_P (*glyph
)
13200 && !FRAME_WINDOW_P (it
->f
))
13202 /* A padding glyph that doesn't fit on this line.
13203 This means the whole character doesn't fit
13205 row
->used
[TEXT_AREA
] = n_glyphs_before
;
13207 /* Fill the rest of the row with continuation
13208 glyphs like in 20.x. */
13209 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
13210 < row
->glyphs
[1 + TEXT_AREA
])
13211 produce_special_glyphs (it
, IT_CONTINUATION
);
13213 row
->continued_p
= 1;
13214 it
->current_x
= x_before
;
13215 it
->continuation_lines_width
+= x_before
;
13217 /* Restore the height to what it was before the
13218 element not fitting on the line. */
13219 it
->max_ascent
= ascent
;
13220 it
->max_descent
= descent
;
13221 it
->max_phys_ascent
= phys_ascent
;
13222 it
->max_phys_descent
= phys_descent
;
13224 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
13226 /* A TAB that extends past the right edge of the
13227 window. This produces a single glyph on
13228 window system frames. We leave the glyph in
13229 this row and let it fill the row, but don't
13230 consume the TAB. */
13231 it
->continuation_lines_width
+= it
->last_visible_x
;
13232 row
->ends_in_middle_of_char_p
= 1;
13233 row
->continued_p
= 1;
13234 glyph
->pixel_width
= it
->last_visible_x
- x
;
13235 it
->starts_in_middle_of_char_p
= 1;
13239 /* Something other than a TAB that draws past
13240 the right edge of the window. Restore
13241 positions to values before the element. */
13242 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13244 /* Display continuation glyphs. */
13245 if (!FRAME_WINDOW_P (it
->f
))
13246 produce_special_glyphs (it
, IT_CONTINUATION
);
13247 row
->continued_p
= 1;
13249 it
->continuation_lines_width
+= x
;
13251 if (nglyphs
> 1 && i
> 0)
13253 row
->ends_in_middle_of_char_p
= 1;
13254 it
->starts_in_middle_of_char_p
= 1;
13257 /* Restore the height to what it was before the
13258 element not fitting on the line. */
13259 it
->max_ascent
= ascent
;
13260 it
->max_descent
= descent
;
13261 it
->max_phys_ascent
= phys_ascent
;
13262 it
->max_phys_descent
= phys_descent
;
13267 else if (new_x
> it
->first_visible_x
)
13269 /* Increment number of glyphs actually displayed. */
13272 if (x
< it
->first_visible_x
)
13273 /* Glyph is partially visible, i.e. row starts at
13274 negative X position. */
13275 row
->x
= x
- it
->first_visible_x
;
13279 /* Glyph is completely off the left margin of the
13280 window. This should not happen because of the
13281 move_it_in_display_line at the start of this
13282 function, unless the text display area of the
13283 window is empty. */
13284 xassert (it
->first_visible_x
<= it
->last_visible_x
);
13288 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13289 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13290 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13291 row
->phys_height
= max (row
->phys_height
,
13292 it
->max_phys_ascent
+ it
->max_phys_descent
);
13294 /* End of this display line if row is continued. */
13295 if (row
->continued_p
)
13299 /* Is this a line end? If yes, we're also done, after making
13300 sure that a non-default face is extended up to the right
13301 margin of the window. */
13302 if (ITERATOR_AT_END_OF_LINE_P (it
))
13304 int used_before
= row
->used
[TEXT_AREA
];
13306 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13308 /* Add a space at the end of the line that is used to
13309 display the cursor there. */
13310 append_space (it
, 0);
13312 /* Extend the face to the end of the line. */
13313 extend_face_to_end_of_line (it
);
13315 /* Make sure we have the position. */
13316 if (used_before
== 0)
13317 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13319 /* Consume the line end. This skips over invisible lines. */
13320 set_iterator_to_next (it
, 1);
13321 it
->continuation_lines_width
= 0;
13325 /* Proceed with next display element. Note that this skips
13326 over lines invisible because of selective display. */
13327 set_iterator_to_next (it
, 1);
13329 /* If we truncate lines, we are done when the last displayed
13330 glyphs reach past the right margin of the window. */
13331 if (it
->truncate_lines_p
13332 && (FRAME_WINDOW_P (it
->f
)
13333 ? (it
->current_x
>= it
->last_visible_x
)
13334 : (it
->current_x
> it
->last_visible_x
)))
13336 /* Maybe add truncation glyphs. */
13337 if (!FRAME_WINDOW_P (it
->f
))
13341 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13342 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13345 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13347 row
->used
[TEXT_AREA
] = i
;
13348 produce_special_glyphs (it
, IT_TRUNCATION
);
13352 row
->truncated_on_right_p
= 1;
13353 it
->continuation_lines_width
= 0;
13354 reseat_at_next_visible_line_start (it
, 0);
13355 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13356 it
->hpos
= hpos_before
;
13357 it
->current_x
= x_before
;
13362 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13363 at the left window margin. */
13364 if (it
->first_visible_x
13365 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13367 if (!FRAME_WINDOW_P (it
->f
))
13368 insert_left_trunc_glyphs (it
);
13369 row
->truncated_on_left_p
= 1;
13372 /* If the start of this line is the overlay arrow-position, then
13373 mark this glyph row as the one containing the overlay arrow.
13374 This is clearly a mess with variable size fonts. It would be
13375 better to let it be displayed like cursors under X. */
13376 if (MARKERP (Voverlay_arrow_position
)
13377 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13378 && (MATRIX_ROW_START_CHARPOS (row
)
13379 == marker_position (Voverlay_arrow_position
))
13380 && STRINGP (Voverlay_arrow_string
)
13381 && ! overlay_arrow_seen
)
13383 /* Overlay arrow in window redisplay is a fringe bitmap. */
13384 if (!FRAME_WINDOW_P (it
->f
))
13386 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13387 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13388 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13389 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13390 struct glyph
*p2
, *end
;
13392 /* Copy the arrow glyphs. */
13393 while (glyph
< arrow_end
)
13396 /* Throw away padding glyphs. */
13398 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13399 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13405 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13409 overlay_arrow_seen
= 1;
13410 row
->overlay_arrow_p
= 1;
13413 /* Compute pixel dimensions of this line. */
13414 compute_line_metrics (it
);
13416 /* Remember the position at which this line ends. */
13417 row
->end
= it
->current
;
13419 /* Maybe set the cursor. */
13420 if (it
->w
->cursor
.vpos
< 0
13421 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13422 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13423 && cursor_row_p (it
->w
, row
))
13424 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13426 /* Highlight trailing whitespace. */
13427 if (!NILP (Vshow_trailing_whitespace
))
13428 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13430 /* Prepare for the next line. This line starts horizontally at (X
13431 HPOS) = (0 0). Vertical positions are incremented. As a
13432 convenience for the caller, IT->glyph_row is set to the next
13434 it
->current_x
= it
->hpos
= 0;
13435 it
->current_y
+= row
->height
;
13438 return row
->displays_text_p
;
13443 /***********************************************************************
13445 ***********************************************************************/
13447 /* Redisplay the menu bar in the frame for window W.
13449 The menu bar of X frames that don't have X toolkit support is
13450 displayed in a special window W->frame->menu_bar_window.
13452 The menu bar of terminal frames is treated specially as far as
13453 glyph matrices are concerned. Menu bar lines are not part of
13454 windows, so the update is done directly on the frame matrix rows
13455 for the menu bar. */
13458 display_menu_bar (w
)
13461 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13466 /* Don't do all this for graphical frames. */
13468 if (!NILP (Vwindow_system
))
13471 #ifdef USE_X_TOOLKIT
13476 if (FRAME_MAC_P (f
))
13480 #ifdef USE_X_TOOLKIT
13481 xassert (!FRAME_WINDOW_P (f
));
13482 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13483 it
.first_visible_x
= 0;
13484 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13485 #else /* not USE_X_TOOLKIT */
13486 if (FRAME_WINDOW_P (f
))
13488 /* Menu bar lines are displayed in the desired matrix of the
13489 dummy window menu_bar_window. */
13490 struct window
*menu_w
;
13491 xassert (WINDOWP (f
->menu_bar_window
));
13492 menu_w
= XWINDOW (f
->menu_bar_window
);
13493 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13495 it
.first_visible_x
= 0;
13496 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13500 /* This is a TTY frame, i.e. character hpos/vpos are used as
13502 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13504 it
.first_visible_x
= 0;
13505 it
.last_visible_x
= FRAME_WIDTH (f
);
13507 #endif /* not USE_X_TOOLKIT */
13509 if (! mode_line_inverse_video
)
13510 /* Force the menu-bar to be displayed in the default face. */
13511 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13513 /* Clear all rows of the menu bar. */
13514 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13516 struct glyph_row
*row
= it
.glyph_row
+ i
;
13517 clear_glyph_row (row
);
13518 row
->enabled_p
= 1;
13519 row
->full_width_p
= 1;
13522 /* Display all items of the menu bar. */
13523 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13524 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13526 Lisp_Object string
;
13528 /* Stop at nil string. */
13529 string
= AREF (items
, i
+ 1);
13533 /* Remember where item was displayed. */
13534 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13536 /* Display the item, pad with one space. */
13537 if (it
.current_x
< it
.last_visible_x
)
13538 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13539 SCHARS (string
) + 1, 0, 0, -1);
13542 /* Fill out the line with spaces. */
13543 if (it
.current_x
< it
.last_visible_x
)
13544 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13546 /* Compute the total height of the lines. */
13547 compute_line_metrics (&it
);
13552 /***********************************************************************
13554 ***********************************************************************/
13556 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13557 FORCE is non-zero, redisplay mode lines unconditionally.
13558 Otherwise, redisplay only mode lines that are garbaged. Value is
13559 the number of windows whose mode lines were redisplayed. */
13562 redisplay_mode_lines (window
, force
)
13563 Lisp_Object window
;
13568 while (!NILP (window
))
13570 struct window
*w
= XWINDOW (window
);
13572 if (WINDOWP (w
->hchild
))
13573 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13574 else if (WINDOWP (w
->vchild
))
13575 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13577 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13578 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13580 struct text_pos lpoint
;
13581 struct buffer
*old
= current_buffer
;
13583 /* Set the window's buffer for the mode line display. */
13584 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13585 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13587 /* Point refers normally to the selected window. For any
13588 other window, set up appropriate value. */
13589 if (!EQ (window
, selected_window
))
13591 struct text_pos pt
;
13593 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13594 if (CHARPOS (pt
) < BEGV
)
13595 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13596 else if (CHARPOS (pt
) > (ZV
- 1))
13597 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13599 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13602 /* Display mode lines. */
13603 clear_glyph_matrix (w
->desired_matrix
);
13604 if (display_mode_lines (w
))
13607 w
->must_be_updated_p
= 1;
13610 /* Restore old settings. */
13611 set_buffer_internal_1 (old
);
13612 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13622 /* Display the mode and/or top line of window W. Value is the number
13623 of mode lines displayed. */
13626 display_mode_lines (w
)
13629 Lisp_Object old_selected_window
, old_selected_frame
;
13632 old_selected_frame
= selected_frame
;
13633 selected_frame
= w
->frame
;
13634 old_selected_window
= selected_window
;
13635 XSETWINDOW (selected_window
, w
);
13637 /* These will be set while the mode line specs are processed. */
13638 line_number_displayed
= 0;
13639 w
->column_number_displayed
= Qnil
;
13641 if (WINDOW_WANTS_MODELINE_P (w
))
13643 struct window
*sel_w
= XWINDOW (old_selected_window
);
13645 /* Select mode line face based on the real selected window. */
13646 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
13647 current_buffer
->mode_line_format
);
13651 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13653 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13654 current_buffer
->header_line_format
);
13658 selected_frame
= old_selected_frame
;
13659 selected_window
= old_selected_window
;
13664 /* Display mode or top line of window W. FACE_ID specifies which line
13665 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13666 FORMAT is the mode line format to display. Value is the pixel
13667 height of the mode line displayed. */
13670 display_mode_line (w
, face_id
, format
)
13672 enum face_id face_id
;
13673 Lisp_Object format
;
13678 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13679 prepare_desired_row (it
.glyph_row
);
13681 if (! mode_line_inverse_video
)
13682 /* Force the mode-line to be displayed in the default face. */
13683 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13685 /* Temporarily make frame's keyboard the current kboard so that
13686 kboard-local variables in the mode_line_format will get the right
13688 push_frame_kboard (it
.f
);
13689 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
13690 pop_frame_kboard ();
13692 /* Fill up with spaces. */
13693 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13695 compute_line_metrics (&it
);
13696 it
.glyph_row
->full_width_p
= 1;
13697 it
.glyph_row
->mode_line_p
= 1;
13698 it
.glyph_row
->continued_p
= 0;
13699 it
.glyph_row
->truncated_on_left_p
= 0;
13700 it
.glyph_row
->truncated_on_right_p
= 0;
13702 /* Make a 3D mode-line have a shadow at its right end. */
13703 face
= FACE_FROM_ID (it
.f
, face_id
);
13704 extend_face_to_end_of_line (&it
);
13705 if (face
->box
!= FACE_NO_BOX
)
13707 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13708 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13709 last
->right_box_line_p
= 1;
13712 return it
.glyph_row
->height
;
13715 /* Alist that caches the results of :propertize.
13716 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
13717 Lisp_Object mode_line_proptrans_alist
;
13719 /* List of strings making up the mode-line. */
13720 Lisp_Object mode_line_string_list
;
13722 /* Base face property when building propertized mode line string. */
13723 static Lisp_Object mode_line_string_face
;
13724 static Lisp_Object mode_line_string_face_prop
;
13727 /* Contribute ELT to the mode line for window IT->w. How it
13728 translates into text depends on its data type.
13730 IT describes the display environment in which we display, as usual.
13732 DEPTH is the depth in recursion. It is used to prevent
13733 infinite recursion here.
13735 FIELD_WIDTH is the number of characters the display of ELT should
13736 occupy in the mode line, and PRECISION is the maximum number of
13737 characters to display from ELT's representation. See
13738 display_string for details.
13740 Returns the hpos of the end of the text generated by ELT.
13742 PROPS is a property list to add to any string we encounter.
13744 If RISKY is nonzero, remove (disregard) any properties in any string
13745 we encounter, and ignore :eval and :propertize.
13747 If the global variable `frame_title_ptr' is non-NULL, then the output
13748 is passed to `store_frame_title' instead of `display_string'. */
13751 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
13754 int field_width
, precision
;
13755 Lisp_Object elt
, props
;
13758 int n
= 0, field
, prec
;
13767 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13771 /* A string: output it and check for %-constructs within it. */
13773 const unsigned char *this, *lisp_string
;
13775 if (!NILP (props
) || risky
)
13777 Lisp_Object oprops
, aelt
;
13778 oprops
= Ftext_properties_at (make_number (0), elt
);
13780 if (NILP (Fequal (props
, oprops
)) || risky
)
13782 /* If the starting string has properties,
13783 merge the specified ones onto the existing ones. */
13784 if (! NILP (oprops
) && !risky
)
13788 oprops
= Fcopy_sequence (oprops
);
13790 while (CONSP (tem
))
13792 oprops
= Fplist_put (oprops
, XCAR (tem
),
13793 XCAR (XCDR (tem
)));
13794 tem
= XCDR (XCDR (tem
));
13799 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
13800 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
13802 mode_line_proptrans_alist
13803 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
13810 elt
= Fcopy_sequence (elt
);
13811 Fset_text_properties (make_number (0), Flength (elt
),
13813 /* Add this item to mode_line_proptrans_alist. */
13814 mode_line_proptrans_alist
13815 = Fcons (Fcons (elt
, props
),
13816 mode_line_proptrans_alist
);
13817 /* Truncate mode_line_proptrans_alist
13818 to at most 50 elements. */
13819 tem
= Fnthcdr (make_number (50),
13820 mode_line_proptrans_alist
);
13822 XSETCDR (tem
, Qnil
);
13827 this = SDATA (elt
);
13828 lisp_string
= this;
13832 prec
= precision
- n
;
13833 if (frame_title_ptr
)
13834 n
+= store_frame_title (SDATA (elt
), -1, prec
);
13835 else if (!NILP (mode_line_string_list
))
13836 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
13838 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
13839 0, prec
, 0, STRING_MULTIBYTE (elt
));
13844 while ((precision
<= 0 || n
< precision
)
13846 && (frame_title_ptr
13847 || !NILP (mode_line_string_list
)
13848 || it
->current_x
< it
->last_visible_x
))
13850 const unsigned char *last
= this;
13852 /* Advance to end of string or next format specifier. */
13853 while ((c
= *this++) != '\0' && c
!= '%')
13856 if (this - 1 != last
)
13858 /* Output to end of string or up to '%'. Field width
13859 is length of string. Don't output more than
13860 PRECISION allows us. */
13863 prec
= chars_in_text (last
, this - last
);
13864 if (precision
> 0 && prec
> precision
- n
)
13865 prec
= precision
- n
;
13867 if (frame_title_ptr
)
13868 n
+= store_frame_title (last
, 0, prec
);
13869 else if (!NILP (mode_line_string_list
))
13871 int bytepos
= last
- lisp_string
;
13872 int charpos
= string_byte_to_char (elt
, bytepos
);
13873 n
+= store_mode_line_string (NULL
,
13874 Fsubstring (elt
, make_number (charpos
),
13875 make_number (charpos
+ prec
)),
13880 int bytepos
= last
- lisp_string
;
13881 int charpos
= string_byte_to_char (elt
, bytepos
);
13882 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
13884 STRING_MULTIBYTE (elt
));
13887 else /* c == '%' */
13889 const unsigned char *percent_position
= this;
13891 /* Get the specified minimum width. Zero means
13894 while ((c
= *this++) >= '0' && c
<= '9')
13895 field
= field
* 10 + c
- '0';
13897 /* Don't pad beyond the total padding allowed. */
13898 if (field_width
- n
> 0 && field
> field_width
- n
)
13899 field
= field_width
- n
;
13901 /* Note that either PRECISION <= 0 or N < PRECISION. */
13902 prec
= precision
- n
;
13905 n
+= display_mode_element (it
, depth
, field
, prec
,
13906 Vglobal_mode_string
, props
,
13911 int bytepos
, charpos
;
13912 unsigned char *spec
;
13914 bytepos
= percent_position
- lisp_string
;
13915 charpos
= (STRING_MULTIBYTE (elt
)
13916 ? string_byte_to_char (elt
, bytepos
)
13920 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
13922 if (frame_title_ptr
)
13923 n
+= store_frame_title (spec
, field
, prec
);
13924 else if (!NILP (mode_line_string_list
))
13926 int len
= strlen (spec
);
13927 Lisp_Object tem
= make_string (spec
, len
);
13928 props
= Ftext_properties_at (make_number (charpos
), elt
);
13929 /* Should only keep face property in props */
13930 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
13934 int nglyphs_before
, nwritten
;
13936 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13937 nwritten
= display_string (spec
, Qnil
, elt
,
13942 /* Assign to the glyphs written above the
13943 string where the `%x' came from, position
13947 struct glyph
*glyph
13948 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13952 for (i
= 0; i
< nwritten
; ++i
)
13954 glyph
[i
].object
= elt
;
13955 glyph
[i
].charpos
= charpos
;
13970 /* A symbol: process the value of the symbol recursively
13971 as if it appeared here directly. Avoid error if symbol void.
13972 Special case: if value of symbol is a string, output the string
13975 register Lisp_Object tem
;
13977 /* If the variable is not marked as risky to set
13978 then its contents are risky to use. */
13979 if (NILP (Fget (elt
, Qrisky_local_variable
)))
13982 tem
= Fboundp (elt
);
13985 tem
= Fsymbol_value (elt
);
13986 /* If value is a string, output that string literally:
13987 don't check for % within it. */
13991 if (!EQ (tem
, elt
))
13993 /* Give up right away for nil or t. */
14003 register Lisp_Object car
, tem
;
14005 /* A cons cell: five distinct cases.
14006 If first element is :eval or :propertize, do something special.
14007 If first element is a string or a cons, process all the elements
14008 and effectively concatenate them.
14009 If first element is a negative number, truncate displaying cdr to
14010 at most that many characters. If positive, pad (with spaces)
14011 to at least that many characters.
14012 If first element is a symbol, process the cadr or caddr recursively
14013 according to whether the symbol's value is non-nil or nil. */
14015 if (EQ (car
, QCeval
))
14017 /* An element of the form (:eval FORM) means evaluate FORM
14018 and use the result as mode line elements. */
14023 if (CONSP (XCDR (elt
)))
14026 spec
= safe_eval (XCAR (XCDR (elt
)));
14027 n
+= display_mode_element (it
, depth
, field_width
- n
,
14028 precision
- n
, spec
, props
,
14032 else if (EQ (car
, QCpropertize
))
14034 /* An element of the form (:propertize ELT PROPS...)
14035 means display ELT but applying properties PROPS. */
14040 if (CONSP (XCDR (elt
)))
14041 n
+= display_mode_element (it
, depth
, field_width
- n
,
14042 precision
- n
, XCAR (XCDR (elt
)),
14043 XCDR (XCDR (elt
)), risky
);
14045 else if (SYMBOLP (car
))
14047 tem
= Fboundp (car
);
14051 /* elt is now the cdr, and we know it is a cons cell.
14052 Use its car if CAR has a non-nil value. */
14055 tem
= Fsymbol_value (car
);
14062 /* Symbol's value is nil (or symbol is unbound)
14063 Get the cddr of the original list
14064 and if possible find the caddr and use that. */
14068 else if (!CONSP (elt
))
14073 else if (INTEGERP (car
))
14075 register int lim
= XINT (car
);
14079 /* Negative int means reduce maximum width. */
14080 if (precision
<= 0)
14083 precision
= min (precision
, -lim
);
14087 /* Padding specified. Don't let it be more than
14088 current maximum. */
14090 lim
= min (precision
, lim
);
14092 /* If that's more padding than already wanted, queue it.
14093 But don't reduce padding already specified even if
14094 that is beyond the current truncation point. */
14095 field_width
= max (lim
, field_width
);
14099 else if (STRINGP (car
) || CONSP (car
))
14101 register int limit
= 50;
14102 /* Limit is to protect against circular lists. */
14105 && (precision
<= 0 || n
< precision
))
14107 n
+= display_mode_element (it
, depth
, field_width
- n
,
14108 precision
- n
, XCAR (elt
),
14118 if (frame_title_ptr
)
14119 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
14120 else if (!NILP (mode_line_string_list
))
14121 n
+= store_mode_line_string ("*invalid*", Qnil
, 0, 0, precision
- n
, Qnil
);
14123 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
14124 precision
- n
, 0, 0);
14128 /* Pad to FIELD_WIDTH. */
14129 if (field_width
> 0 && n
< field_width
)
14131 if (frame_title_ptr
)
14132 n
+= store_frame_title ("", field_width
- n
, 0);
14133 else if (!NILP (mode_line_string_list
))
14134 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
14136 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
14143 /* Store a mode-line string element in mode_line_string_list.
14145 If STRING is non-null, display that C string. Otherwise, the Lisp
14146 string LISP_STRING is displayed.
14148 FIELD_WIDTH is the minimum number of output glyphs to produce.
14149 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14150 with spaces. FIELD_WIDTH <= 0 means don't pad.
14152 PRECISION is the maximum number of characters to output from
14153 STRING. PRECISION <= 0 means don't truncate the string.
14155 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
14156 properties to the string.
14158 PROPS are the properties to add to the string.
14159 The mode_line_string_face face property is always added to the string.
14162 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
14164 Lisp_Object lisp_string
;
14173 if (string
!= NULL
)
14175 len
= strlen (string
);
14176 if (precision
> 0 && len
> precision
)
14178 lisp_string
= make_string (string
, len
);
14180 props
= mode_line_string_face_prop
;
14181 else if (!NILP (mode_line_string_face
))
14183 Lisp_Object face
= Fplist_get (props
, Qface
);
14184 props
= Fcopy_sequence (props
);
14186 face
= mode_line_string_face
;
14188 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14189 props
= Fplist_put (props
, Qface
, face
);
14191 Fadd_text_properties (make_number (0), make_number (len
),
14192 props
, lisp_string
);
14196 len
= XFASTINT (Flength (lisp_string
));
14197 if (precision
> 0 && len
> precision
)
14200 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
14203 if (!NILP (mode_line_string_face
))
14207 props
= Ftext_properties_at (make_number (0), lisp_string
);
14208 face
= Fplist_get (props
, Qface
);
14210 face
= mode_line_string_face
;
14212 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14213 props
= Fcons (Qface
, Fcons (face
, Qnil
));
14215 lisp_string
= Fcopy_sequence (lisp_string
);
14218 Fadd_text_properties (make_number (0), make_number (len
),
14219 props
, lisp_string
);
14224 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14228 if (field_width
> len
)
14230 field_width
-= len
;
14231 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
14233 Fadd_text_properties (make_number (0), make_number (field_width
),
14234 props
, lisp_string
);
14235 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14243 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
14245 doc
: /* Return the mode-line of selected window as a string.
14246 First optional arg FORMAT specifies a different format string (see
14247 `mode-line-format' for details) to use. If FORMAT is t, return
14248 the buffer's header-line. Second optional arg WINDOW specifies a
14249 different window to use as the context for the formatting.
14250 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
14251 (format
, window
, no_props
)
14252 Lisp_Object format
, window
, no_props
;
14257 struct buffer
*old_buffer
= NULL
;
14258 enum face_id face_id
= DEFAULT_FACE_ID
;
14261 window
= selected_window
;
14262 CHECK_WINDOW (window
);
14263 w
= XWINDOW (window
);
14264 CHECK_BUFFER (w
->buffer
);
14266 if (XBUFFER (w
->buffer
) != current_buffer
)
14268 old_buffer
= current_buffer
;
14269 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14272 if (NILP (format
) || EQ (format
, Qt
))
14274 face_id
= NILP (format
)
14275 ? CURRENT_MODE_LINE_FACE_ID (w
) :
14276 HEADER_LINE_FACE_ID
;
14277 format
= NILP (format
)
14278 ? current_buffer
->mode_line_format
14279 : current_buffer
->header_line_format
;
14282 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
14284 if (NILP (no_props
))
14286 mode_line_string_face
=
14287 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
14288 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
14289 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
14291 mode_line_string_face_prop
=
14292 NILP (mode_line_string_face
) ? Qnil
:
14293 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
14295 /* We need a dummy last element in mode_line_string_list to
14296 indicate we are building the propertized mode-line string.
14297 Using mode_line_string_face_prop here GC protects it. */
14298 mode_line_string_list
=
14299 Fcons (mode_line_string_face_prop
, Qnil
);
14300 frame_title_ptr
= NULL
;
14304 mode_line_string_face_prop
= Qnil
;
14305 mode_line_string_list
= Qnil
;
14306 frame_title_ptr
= frame_title_buf
;
14309 push_frame_kboard (it
.f
);
14310 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
14311 pop_frame_kboard ();
14314 set_buffer_internal_1 (old_buffer
);
14316 if (NILP (no_props
))
14319 mode_line_string_list
= Fnreverse (mode_line_string_list
);
14320 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
14321 make_string ("", 0));
14322 mode_line_string_face_prop
= Qnil
;
14323 mode_line_string_list
= Qnil
;
14327 len
= frame_title_ptr
- frame_title_buf
;
14328 if (len
> 0 && frame_title_ptr
[-1] == '-')
14330 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
14331 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
14333 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
14334 if (len
> frame_title_ptr
- frame_title_buf
)
14335 len
= frame_title_ptr
- frame_title_buf
;
14338 frame_title_ptr
= NULL
;
14339 return make_string (frame_title_buf
, len
);
14342 /* Write a null-terminated, right justified decimal representation of
14343 the positive integer D to BUF using a minimal field width WIDTH. */
14346 pint2str (buf
, width
, d
)
14347 register char *buf
;
14348 register int width
;
14351 register char *p
= buf
;
14359 *p
++ = d
% 10 + '0';
14364 for (width
-= (int) (p
- buf
); width
> 0; --width
)
14375 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
14376 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
14377 type of CODING_SYSTEM. Return updated pointer into BUF. */
14379 static unsigned char invalid_eol_type
[] = "(*invalid*)";
14382 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
14383 Lisp_Object coding_system
;
14384 register char *buf
;
14388 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
14389 const unsigned char *eol_str
;
14391 /* The EOL conversion we are using. */
14392 Lisp_Object eoltype
;
14394 val
= Fget (coding_system
, Qcoding_system
);
14397 if (!VECTORP (val
)) /* Not yet decided. */
14402 eoltype
= eol_mnemonic_undecided
;
14403 /* Don't mention EOL conversion if it isn't decided. */
14407 Lisp_Object eolvalue
;
14409 eolvalue
= Fget (coding_system
, Qeol_type
);
14412 *buf
++ = XFASTINT (AREF (val
, 1));
14416 /* The EOL conversion that is normal on this system. */
14418 if (NILP (eolvalue
)) /* Not yet decided. */
14419 eoltype
= eol_mnemonic_undecided
;
14420 else if (VECTORP (eolvalue
)) /* Not yet decided. */
14421 eoltype
= eol_mnemonic_undecided
;
14422 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
14423 eoltype
= (XFASTINT (eolvalue
) == 0
14424 ? eol_mnemonic_unix
14425 : (XFASTINT (eolvalue
) == 1
14426 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
14432 /* Mention the EOL conversion if it is not the usual one. */
14433 if (STRINGP (eoltype
))
14435 eol_str
= SDATA (eoltype
);
14436 eol_str_len
= SBYTES (eoltype
);
14438 else if (INTEGERP (eoltype
)
14439 && CHAR_VALID_P (XINT (eoltype
), 0))
14441 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
14442 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
14447 eol_str
= invalid_eol_type
;
14448 eol_str_len
= sizeof (invalid_eol_type
) - 1;
14450 bcopy (eol_str
, buf
, eol_str_len
);
14451 buf
+= eol_str_len
;
14457 /* Return a string for the output of a mode line %-spec for window W,
14458 generated by character C. PRECISION >= 0 means don't return a
14459 string longer than that value. FIELD_WIDTH > 0 means pad the
14460 string returned with spaces to that value. Return 1 in *MULTIBYTE
14461 if the result is multibyte text. */
14463 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
14466 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
14469 int field_width
, precision
;
14473 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14474 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
14475 struct buffer
*b
= XBUFFER (w
->buffer
);
14483 if (!NILP (b
->read_only
))
14485 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14490 /* This differs from %* only for a modified read-only buffer. */
14491 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14493 if (!NILP (b
->read_only
))
14498 /* This differs from %* in ignoring read-only-ness. */
14499 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14511 if (command_loop_level
> 5)
14513 p
= decode_mode_spec_buf
;
14514 for (i
= 0; i
< command_loop_level
; i
++)
14517 return decode_mode_spec_buf
;
14525 if (command_loop_level
> 5)
14527 p
= decode_mode_spec_buf
;
14528 for (i
= 0; i
< command_loop_level
; i
++)
14531 return decode_mode_spec_buf
;
14538 /* Let lots_of_dashes be a string of infinite length. */
14539 if (!NILP (mode_line_string_list
))
14541 if (field_width
<= 0
14542 || field_width
> sizeof (lots_of_dashes
))
14544 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
14545 decode_mode_spec_buf
[i
] = '-';
14546 decode_mode_spec_buf
[i
] = '\0';
14547 return decode_mode_spec_buf
;
14550 return lots_of_dashes
;
14559 int col
= (int) current_column (); /* iftc */
14560 w
->column_number_displayed
= make_number (col
);
14561 pint2str (decode_mode_spec_buf
, field_width
, col
);
14562 return decode_mode_spec_buf
;
14566 /* %F displays the frame name. */
14567 if (!NILP (f
->title
))
14568 return (char *) SDATA (f
->title
);
14569 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
14570 return (char *) SDATA (f
->name
);
14579 int startpos
= XMARKER (w
->start
)->charpos
;
14580 int startpos_byte
= marker_byte_position (w
->start
);
14581 int line
, linepos
, linepos_byte
, topline
;
14583 int height
= XFASTINT (w
->height
);
14585 /* If we decided that this buffer isn't suitable for line numbers,
14586 don't forget that too fast. */
14587 if (EQ (w
->base_line_pos
, w
->buffer
))
14589 /* But do forget it, if the window shows a different buffer now. */
14590 else if (BUFFERP (w
->base_line_pos
))
14591 w
->base_line_pos
= Qnil
;
14593 /* If the buffer is very big, don't waste time. */
14594 if (INTEGERP (Vline_number_display_limit
)
14595 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
14597 w
->base_line_pos
= Qnil
;
14598 w
->base_line_number
= Qnil
;
14602 if (!NILP (w
->base_line_number
)
14603 && !NILP (w
->base_line_pos
)
14604 && XFASTINT (w
->base_line_pos
) <= startpos
)
14606 line
= XFASTINT (w
->base_line_number
);
14607 linepos
= XFASTINT (w
->base_line_pos
);
14608 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
14613 linepos
= BUF_BEGV (b
);
14614 linepos_byte
= BUF_BEGV_BYTE (b
);
14617 /* Count lines from base line to window start position. */
14618 nlines
= display_count_lines (linepos
, linepos_byte
,
14622 topline
= nlines
+ line
;
14624 /* Determine a new base line, if the old one is too close
14625 or too far away, or if we did not have one.
14626 "Too close" means it's plausible a scroll-down would
14627 go back past it. */
14628 if (startpos
== BUF_BEGV (b
))
14630 w
->base_line_number
= make_number (topline
);
14631 w
->base_line_pos
= make_number (BUF_BEGV (b
));
14633 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
14634 || linepos
== BUF_BEGV (b
))
14636 int limit
= BUF_BEGV (b
);
14637 int limit_byte
= BUF_BEGV_BYTE (b
);
14639 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
14641 if (startpos
- distance
> limit
)
14643 limit
= startpos
- distance
;
14644 limit_byte
= CHAR_TO_BYTE (limit
);
14647 nlines
= display_count_lines (startpos
, startpos_byte
,
14649 - (height
* 2 + 30),
14651 /* If we couldn't find the lines we wanted within
14652 line_number_display_limit_width chars per line,
14653 give up on line numbers for this window. */
14654 if (position
== limit_byte
&& limit
== startpos
- distance
)
14656 w
->base_line_pos
= w
->buffer
;
14657 w
->base_line_number
= Qnil
;
14661 w
->base_line_number
= make_number (topline
- nlines
);
14662 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
14665 /* Now count lines from the start pos to point. */
14666 nlines
= display_count_lines (startpos
, startpos_byte
,
14667 PT_BYTE
, PT
, &junk
);
14669 /* Record that we did display the line number. */
14670 line_number_displayed
= 1;
14672 /* Make the string to show. */
14673 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
14674 return decode_mode_spec_buf
;
14677 char* p
= decode_mode_spec_buf
;
14678 int pad
= field_width
- 2;
14684 return decode_mode_spec_buf
;
14690 obj
= b
->mode_name
;
14694 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
14700 int pos
= marker_position (w
->start
);
14701 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14703 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
14705 if (pos
<= BUF_BEGV (b
))
14710 else if (pos
<= BUF_BEGV (b
))
14714 if (total
> 1000000)
14715 /* Do it differently for a large value, to avoid overflow. */
14716 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14718 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14719 /* We can't normally display a 3-digit number,
14720 so get us a 2-digit number that is close. */
14723 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14724 return decode_mode_spec_buf
;
14728 /* Display percentage of size above the bottom of the screen. */
14731 int toppos
= marker_position (w
->start
);
14732 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14733 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14735 if (botpos
>= BUF_ZV (b
))
14737 if (toppos
<= BUF_BEGV (b
))
14744 if (total
> 1000000)
14745 /* Do it differently for a large value, to avoid overflow. */
14746 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14748 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14749 /* We can't normally display a 3-digit number,
14750 so get us a 2-digit number that is close. */
14753 if (toppos
<= BUF_BEGV (b
))
14754 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14756 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14757 return decode_mode_spec_buf
;
14762 /* status of process */
14763 obj
= Fget_buffer_process (w
->buffer
);
14765 return "no process";
14766 #ifdef subprocesses
14767 obj
= Fsymbol_name (Fprocess_status (obj
));
14771 case 't': /* indicate TEXT or BINARY */
14772 #ifdef MODE_LINE_BINARY_TEXT
14773 return MODE_LINE_BINARY_TEXT (b
);
14779 /* coding-system (not including end-of-line format) */
14781 /* coding-system (including end-of-line type) */
14783 int eol_flag
= (c
== 'Z');
14784 char *p
= decode_mode_spec_buf
;
14786 if (! FRAME_WINDOW_P (f
))
14788 /* No need to mention EOL here--the terminal never needs
14789 to do EOL conversion. */
14790 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14791 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14793 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14796 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14797 #ifdef subprocesses
14798 obj
= Fget_buffer_process (Fcurrent_buffer ());
14799 if (PROCESSP (obj
))
14801 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14803 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14806 #endif /* subprocesses */
14809 return decode_mode_spec_buf
;
14815 *multibyte
= STRING_MULTIBYTE (obj
);
14816 return (char *) SDATA (obj
);
14823 /* Count up to COUNT lines starting from START / START_BYTE.
14824 But don't go beyond LIMIT_BYTE.
14825 Return the number of lines thus found (always nonnegative).
14827 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14830 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14831 int start
, start_byte
, limit_byte
, count
;
14834 register unsigned char *cursor
;
14835 unsigned char *base
;
14837 register int ceiling
;
14838 register unsigned char *ceiling_addr
;
14839 int orig_count
= count
;
14841 /* If we are not in selective display mode,
14842 check only for newlines. */
14843 int selective_display
= (!NILP (current_buffer
->selective_display
)
14844 && !INTEGERP (current_buffer
->selective_display
));
14848 while (start_byte
< limit_byte
)
14850 ceiling
= BUFFER_CEILING_OF (start_byte
);
14851 ceiling
= min (limit_byte
- 1, ceiling
);
14852 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14853 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14856 if (selective_display
)
14857 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14860 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14863 if (cursor
!= ceiling_addr
)
14867 start_byte
+= cursor
- base
+ 1;
14868 *byte_pos_ptr
= start_byte
;
14872 if (++cursor
== ceiling_addr
)
14878 start_byte
+= cursor
- base
;
14883 while (start_byte
> limit_byte
)
14885 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14886 ceiling
= max (limit_byte
, ceiling
);
14887 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14888 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14891 if (selective_display
)
14892 while (--cursor
!= ceiling_addr
14893 && *cursor
!= '\n' && *cursor
!= 015)
14896 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14899 if (cursor
!= ceiling_addr
)
14903 start_byte
+= cursor
- base
+ 1;
14904 *byte_pos_ptr
= start_byte
;
14905 /* When scanning backwards, we should
14906 not count the newline posterior to which we stop. */
14907 return - orig_count
- 1;
14913 /* Here we add 1 to compensate for the last decrement
14914 of CURSOR, which took it past the valid range. */
14915 start_byte
+= cursor
- base
+ 1;
14919 *byte_pos_ptr
= limit_byte
;
14922 return - orig_count
+ count
;
14923 return orig_count
- count
;
14929 /***********************************************************************
14931 ***********************************************************************/
14933 /* Display a NUL-terminated string, starting with index START.
14935 If STRING is non-null, display that C string. Otherwise, the Lisp
14936 string LISP_STRING is displayed.
14938 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14939 FACE_STRING. Display STRING or LISP_STRING with the face at
14940 FACE_STRING_POS in FACE_STRING:
14942 Display the string in the environment given by IT, but use the
14943 standard display table, temporarily.
14945 FIELD_WIDTH is the minimum number of output glyphs to produce.
14946 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14947 with spaces. If STRING has more characters, more than FIELD_WIDTH
14948 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14950 PRECISION is the maximum number of characters to output from
14951 STRING. PRECISION < 0 means don't truncate the string.
14953 This is roughly equivalent to printf format specifiers:
14955 FIELD_WIDTH PRECISION PRINTF
14956 ----------------------------------------
14962 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14963 display them, and < 0 means obey the current buffer's value of
14964 enable_multibyte_characters.
14966 Value is the number of glyphs produced. */
14969 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14970 start
, it
, field_width
, precision
, max_x
, multibyte
)
14971 unsigned char *string
;
14972 Lisp_Object lisp_string
;
14973 Lisp_Object face_string
;
14974 int face_string_pos
;
14977 int field_width
, precision
, max_x
;
14980 int hpos_at_start
= it
->hpos
;
14981 int saved_face_id
= it
->face_id
;
14982 struct glyph_row
*row
= it
->glyph_row
;
14984 /* Initialize the iterator IT for iteration over STRING beginning
14985 with index START. */
14986 reseat_to_string (it
, string
, lisp_string
, start
,
14987 precision
, field_width
, multibyte
);
14989 /* If displaying STRING, set up the face of the iterator
14990 from LISP_STRING, if that's given. */
14991 if (STRINGP (face_string
))
14997 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
14998 0, it
->region_beg_charpos
,
14999 it
->region_end_charpos
,
15000 &endptr
, it
->base_face_id
, 0);
15001 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15002 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
15005 /* Set max_x to the maximum allowed X position. Don't let it go
15006 beyond the right edge of the window. */
15008 max_x
= it
->last_visible_x
;
15010 max_x
= min (max_x
, it
->last_visible_x
);
15012 /* Skip over display elements that are not visible. because IT->w is
15014 if (it
->current_x
< it
->first_visible_x
)
15015 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
15016 MOVE_TO_POS
| MOVE_TO_X
);
15018 row
->ascent
= it
->max_ascent
;
15019 row
->height
= it
->max_ascent
+ it
->max_descent
;
15020 row
->phys_ascent
= it
->max_phys_ascent
;
15021 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15023 /* This condition is for the case that we are called with current_x
15024 past last_visible_x. */
15025 while (it
->current_x
< max_x
)
15027 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
15029 /* Get the next display element. */
15030 if (!get_next_display_element (it
))
15033 /* Produce glyphs. */
15034 x_before
= it
->current_x
;
15035 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15036 PRODUCE_GLYPHS (it
);
15038 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
15041 while (i
< nglyphs
)
15043 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15045 if (!it
->truncate_lines_p
15046 && x
+ glyph
->pixel_width
> max_x
)
15048 /* End of continued line or max_x reached. */
15049 if (CHAR_GLYPH_PADDING_P (*glyph
))
15051 /* A wide character is unbreakable. */
15052 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15053 it
->current_x
= x_before
;
15057 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15062 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
15064 /* Glyph is at least partially visible. */
15066 if (x
< it
->first_visible_x
)
15067 it
->glyph_row
->x
= x
- it
->first_visible_x
;
15071 /* Glyph is off the left margin of the display area.
15072 Should not happen. */
15076 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15077 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15078 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15079 row
->phys_height
= max (row
->phys_height
,
15080 it
->max_phys_ascent
+ it
->max_phys_descent
);
15081 x
+= glyph
->pixel_width
;
15085 /* Stop if max_x reached. */
15089 /* Stop at line ends. */
15090 if (ITERATOR_AT_END_OF_LINE_P (it
))
15092 it
->continuation_lines_width
= 0;
15096 set_iterator_to_next (it
, 1);
15098 /* Stop if truncating at the right edge. */
15099 if (it
->truncate_lines_p
15100 && it
->current_x
>= it
->last_visible_x
)
15102 /* Add truncation mark, but don't do it if the line is
15103 truncated at a padding space. */
15104 if (IT_CHARPOS (*it
) < it
->string_nchars
)
15106 if (!FRAME_WINDOW_P (it
->f
))
15110 if (it
->current_x
> it
->last_visible_x
)
15112 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15113 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15115 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15117 row
->used
[TEXT_AREA
] = i
;
15118 produce_special_glyphs (it
, IT_TRUNCATION
);
15121 produce_special_glyphs (it
, IT_TRUNCATION
);
15123 it
->glyph_row
->truncated_on_right_p
= 1;
15129 /* Maybe insert a truncation at the left. */
15130 if (it
->first_visible_x
15131 && IT_CHARPOS (*it
) > 0)
15133 if (!FRAME_WINDOW_P (it
->f
))
15134 insert_left_trunc_glyphs (it
);
15135 it
->glyph_row
->truncated_on_left_p
= 1;
15138 it
->face_id
= saved_face_id
;
15140 /* Value is number of columns displayed. */
15141 return it
->hpos
- hpos_at_start
;
15146 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
15147 appears as an element of LIST or as the car of an element of LIST.
15148 If PROPVAL is a list, compare each element against LIST in that
15149 way, and return 1/2 if any element of PROPVAL is found in LIST.
15150 Otherwise return 0. This function cannot quit.
15151 The return value is 2 if the text is invisible but with an ellipsis
15152 and 1 if it's invisible and without an ellipsis. */
15155 invisible_p (propval
, list
)
15156 register Lisp_Object propval
;
15159 register Lisp_Object tail
, proptail
;
15161 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15163 register Lisp_Object tem
;
15165 if (EQ (propval
, tem
))
15167 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
15168 return NILP (XCDR (tem
)) ? 1 : 2;
15171 if (CONSP (propval
))
15173 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
15175 Lisp_Object propelt
;
15176 propelt
= XCAR (proptail
);
15177 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15179 register Lisp_Object tem
;
15181 if (EQ (propelt
, tem
))
15183 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
15184 return NILP (XCDR (tem
)) ? 1 : 2;
15193 /***********************************************************************
15195 ***********************************************************************/
15197 /* Value is the internal representation of the specified cursor type
15198 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
15199 of the bar cursor. */
15201 enum text_cursor_kinds
15202 get_specified_cursor_type (arg
, width
)
15206 enum text_cursor_kinds type
;
15211 if (EQ (arg
, Qbox
))
15212 return FILLED_BOX_CURSOR
;
15214 if (EQ (arg
, Qhollow
))
15215 return HOLLOW_BOX_CURSOR
;
15217 if (EQ (arg
, Qbar
))
15224 && EQ (XCAR (arg
), Qbar
)
15225 && INTEGERP (XCDR (arg
))
15226 && XINT (XCDR (arg
)) >= 0)
15228 *width
= XINT (XCDR (arg
));
15232 if (EQ (arg
, Qhbar
))
15235 return HBAR_CURSOR
;
15239 && EQ (XCAR (arg
), Qhbar
)
15240 && INTEGERP (XCDR (arg
))
15241 && XINT (XCDR (arg
)) >= 0)
15243 *width
= XINT (XCDR (arg
));
15244 return HBAR_CURSOR
;
15247 /* Treat anything unknown as "hollow box cursor".
15248 It was bad to signal an error; people have trouble fixing
15249 .Xdefaults with Emacs, when it has something bad in it. */
15250 type
= HOLLOW_BOX_CURSOR
;
15255 /* Set the default cursor types for specified frame. */
15257 set_frame_cursor_types (f
, arg
)
15264 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
15265 FRAME_CURSOR_WIDTH (f
) = width
;
15267 /* By default, set up the blink-off state depending on the on-state. */
15269 tem
= Fassoc (arg
, Vblink_cursor_alist
);
15272 FRAME_BLINK_OFF_CURSOR (f
)
15273 = get_specified_cursor_type (XCDR (tem
), &width
);
15274 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
15277 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
15281 /* Return the cursor we want to be displayed. In a mini-buffer
15282 window, we want the cursor only to appear if we are reading input
15283 from this window. For the selected window, we want the cursor type
15284 given by the frame parameter or buffer local setting of
15285 cursor-type. If explicitly marked off, draw no cursor. In all
15286 other cases, we want a hollow box cursor. */
15288 enum text_cursor_kinds
15289 get_window_cursor_type (w
, width
)
15293 struct frame
*f
= XFRAME (w
->frame
);
15294 struct buffer
*b
= XBUFFER (w
->buffer
);
15295 int cursor_type
= DEFAULT_CURSOR
;
15296 Lisp_Object alt_cursor
;
15297 int non_selected
= 0;
15300 if (cursor_in_echo_area
15301 && FRAME_HAS_MINIBUF_P (f
)
15302 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
15304 if (w
== XWINDOW (echo_area_window
))
15306 *width
= FRAME_CURSOR_WIDTH (f
);
15307 return FRAME_DESIRED_CURSOR (f
);
15313 /* Nonselected window or nonselected frame. */
15314 else if (w
!= XWINDOW (f
->selected_window
)
15315 #ifdef HAVE_WINDOW_SYSTEM
15316 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
15320 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
15326 /* Never display a cursor in a window in which cursor-type is nil. */
15327 if (NILP (b
->cursor_type
))
15330 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
15333 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
15334 return get_specified_cursor_type (alt_cursor
, width
);
15337 /* Get the normal cursor type for this window. */
15338 if (EQ (b
->cursor_type
, Qt
))
15340 cursor_type
= FRAME_DESIRED_CURSOR (f
);
15341 *width
= FRAME_CURSOR_WIDTH (f
);
15344 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
15346 /* Use normal cursor if not blinked off. */
15347 if (!w
->cursor_off_p
)
15348 return cursor_type
;
15350 /* Cursor is blinked off, so determine how to "toggle" it. */
15352 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
15353 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
15354 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
15356 /* Then see if frame has specified a specific blink off cursor type. */
15357 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
15359 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
15360 return FRAME_BLINK_OFF_CURSOR (f
);
15363 /* Finally perform built-in cursor blinking:
15364 filled box <-> hollow box
15365 wide [h]bar <-> narrow [h]bar
15366 narrow [h]bar <-> no cursor
15367 other type <-> no cursor */
15369 if (cursor_type
== FILLED_BOX_CURSOR
)
15370 return HOLLOW_BOX_CURSOR
;
15372 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
15375 return cursor_type
;
15382 /***********************************************************************
15384 ***********************************************************************/
15389 Vwith_echo_area_save_vector
= Qnil
;
15390 staticpro (&Vwith_echo_area_save_vector
);
15392 Vmessage_stack
= Qnil
;
15393 staticpro (&Vmessage_stack
);
15395 Qinhibit_redisplay
= intern ("inhibit-redisplay");
15396 staticpro (&Qinhibit_redisplay
);
15398 message_dolog_marker1
= Fmake_marker ();
15399 staticpro (&message_dolog_marker1
);
15400 message_dolog_marker2
= Fmake_marker ();
15401 staticpro (&message_dolog_marker2
);
15402 message_dolog_marker3
= Fmake_marker ();
15403 staticpro (&message_dolog_marker3
);
15406 defsubr (&Sdump_frame_glyph_matrix
);
15407 defsubr (&Sdump_glyph_matrix
);
15408 defsubr (&Sdump_glyph_row
);
15409 defsubr (&Sdump_tool_bar_row
);
15410 defsubr (&Strace_redisplay
);
15411 defsubr (&Strace_to_stderr
);
15413 #ifdef HAVE_WINDOW_SYSTEM
15414 defsubr (&Stool_bar_lines_needed
);
15416 defsubr (&Sformat_mode_line
);
15418 staticpro (&Qmenu_bar_update_hook
);
15419 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
15421 staticpro (&Qoverriding_terminal_local_map
);
15422 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
15424 staticpro (&Qoverriding_local_map
);
15425 Qoverriding_local_map
= intern ("overriding-local-map");
15427 staticpro (&Qwindow_scroll_functions
);
15428 Qwindow_scroll_functions
= intern ("window-scroll-functions");
15430 staticpro (&Qredisplay_end_trigger_functions
);
15431 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
15433 staticpro (&Qinhibit_point_motion_hooks
);
15434 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
15436 QCdata
= intern (":data");
15437 staticpro (&QCdata
);
15438 Qdisplay
= intern ("display");
15439 staticpro (&Qdisplay
);
15440 Qspace_width
= intern ("space-width");
15441 staticpro (&Qspace_width
);
15442 Qraise
= intern ("raise");
15443 staticpro (&Qraise
);
15444 Qspace
= intern ("space");
15445 staticpro (&Qspace
);
15446 Qmargin
= intern ("margin");
15447 staticpro (&Qmargin
);
15448 Qleft_margin
= intern ("left-margin");
15449 staticpro (&Qleft_margin
);
15450 Qright_margin
= intern ("right-margin");
15451 staticpro (&Qright_margin
);
15452 Qalign_to
= intern ("align-to");
15453 staticpro (&Qalign_to
);
15454 QCalign_to
= intern (":align-to");
15455 staticpro (&QCalign_to
);
15456 Qrelative_width
= intern ("relative-width");
15457 staticpro (&Qrelative_width
);
15458 QCrelative_width
= intern (":relative-width");
15459 staticpro (&QCrelative_width
);
15460 QCrelative_height
= intern (":relative-height");
15461 staticpro (&QCrelative_height
);
15462 QCeval
= intern (":eval");
15463 staticpro (&QCeval
);
15464 QCpropertize
= intern (":propertize");
15465 staticpro (&QCpropertize
);
15466 Qwhen
= intern ("when");
15467 staticpro (&Qwhen
);
15468 QCfile
= intern (":file");
15469 staticpro (&QCfile
);
15470 Qfontified
= intern ("fontified");
15471 staticpro (&Qfontified
);
15472 Qfontification_functions
= intern ("fontification-functions");
15473 staticpro (&Qfontification_functions
);
15474 Qtrailing_whitespace
= intern ("trailing-whitespace");
15475 staticpro (&Qtrailing_whitespace
);
15476 Qimage
= intern ("image");
15477 staticpro (&Qimage
);
15478 Qmessage_truncate_lines
= intern ("message-truncate-lines");
15479 staticpro (&Qmessage_truncate_lines
);
15480 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
15481 staticpro (&Qcursor_in_non_selected_windows
);
15482 Qgrow_only
= intern ("grow-only");
15483 staticpro (&Qgrow_only
);
15484 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
15485 staticpro (&Qinhibit_menubar_update
);
15486 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
15487 staticpro (&Qinhibit_eval_during_redisplay
);
15488 Qposition
= intern ("position");
15489 staticpro (&Qposition
);
15490 Qbuffer_position
= intern ("buffer-position");
15491 staticpro (&Qbuffer_position
);
15492 Qobject
= intern ("object");
15493 staticpro (&Qobject
);
15494 Qbar
= intern ("bar");
15496 Qhbar
= intern ("hbar");
15497 staticpro (&Qhbar
);
15498 Qbox
= intern ("box");
15500 Qhollow
= intern ("hollow");
15501 staticpro (&Qhollow
);
15502 Qrisky_local_variable
= intern ("risky-local-variable");
15503 staticpro (&Qrisky_local_variable
);
15504 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
15505 staticpro (&Qinhibit_free_realized_faces
);
15507 list_of_error
= Fcons (intern ("error"), Qnil
);
15508 staticpro (&list_of_error
);
15510 last_arrow_position
= Qnil
;
15511 last_arrow_string
= Qnil
;
15512 staticpro (&last_arrow_position
);
15513 staticpro (&last_arrow_string
);
15515 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
15516 staticpro (&echo_buffer
[0]);
15517 staticpro (&echo_buffer
[1]);
15519 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
15520 staticpro (&echo_area_buffer
[0]);
15521 staticpro (&echo_area_buffer
[1]);
15523 Vmessages_buffer_name
= build_string ("*Messages*");
15524 staticpro (&Vmessages_buffer_name
);
15526 mode_line_proptrans_alist
= Qnil
;
15527 staticpro (&mode_line_proptrans_alist
);
15529 mode_line_string_list
= Qnil
;
15530 staticpro (&mode_line_string_list
);
15532 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
15533 doc
: /* Non-nil means highlight trailing whitespace.
15534 The face used for trailing whitespace is `trailing-whitespace'. */);
15535 Vshow_trailing_whitespace
= Qnil
;
15537 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
15538 doc
: /* Non-nil means don't actually do any redisplay.
15539 This is used for internal purposes. */);
15540 Vinhibit_redisplay
= Qnil
;
15542 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
15543 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
15544 Vglobal_mode_string
= Qnil
;
15546 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
15547 doc
: /* Marker for where to display an arrow on top of the buffer text.
15548 This must be the beginning of a line in order to work.
15549 See also `overlay-arrow-string'. */);
15550 Voverlay_arrow_position
= Qnil
;
15552 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
15553 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
15554 Voverlay_arrow_string
= Qnil
;
15556 DEFVAR_INT ("scroll-step", &scroll_step
,
15557 doc
: /* *The number of lines to try scrolling a window by when point moves out.
15558 If that fails to bring point back on frame, point is centered instead.
15559 If this is zero, point is always centered after it moves off frame.
15560 If you want scrolling to always be a line at a time, you should set
15561 `scroll-conservatively' to a large value rather than set this to 1. */);
15563 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
15564 doc
: /* *Scroll up to this many lines, to bring point back on screen.
15565 A value of zero means to scroll the text to center point vertically
15566 in the window. */);
15567 scroll_conservatively
= 0;
15569 DEFVAR_INT ("scroll-margin", &scroll_margin
,
15570 doc
: /* *Number of lines of margin at the top and bottom of a window.
15571 Recenter the window whenever point gets within this many lines
15572 of the top or bottom of the window. */);
15576 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
15579 DEFVAR_BOOL ("truncate-partial-width-windows",
15580 &truncate_partial_width_windows
,
15581 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
15582 truncate_partial_width_windows
= 1;
15584 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
15585 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
15586 Any other value means to use the appropriate face, `mode-line',
15587 `header-line', or `menu' respectively. */);
15588 mode_line_inverse_video
= 1;
15590 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
15591 doc
: /* *Maximum buffer size for which line number should be displayed.
15592 If the buffer is bigger than this, the line number does not appear
15593 in the mode line. A value of nil means no limit. */);
15594 Vline_number_display_limit
= Qnil
;
15596 DEFVAR_INT ("line-number-display-limit-width",
15597 &line_number_display_limit_width
,
15598 doc
: /* *Maximum line width (in characters) for line number display.
15599 If the average length of the lines near point is bigger than this, then the
15600 line number may be omitted from the mode line. */);
15601 line_number_display_limit_width
= 200;
15603 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
15604 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
15605 highlight_nonselected_windows
= 0;
15607 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
15608 doc
: /* Non-nil if more than one frame is visible on this display.
15609 Minibuffer-only frames don't count, but iconified frames do.
15610 This variable is not guaranteed to be accurate except while processing
15611 `frame-title-format' and `icon-title-format'. */);
15613 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
15614 doc
: /* Template for displaying the title bar of visible frames.
15615 \(Assuming the window manager supports this feature.)
15616 This variable has the same structure as `mode-line-format' (which see),
15617 and is used only on frames for which no explicit name has been set
15618 \(see `modify-frame-parameters'). */);
15619 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
15620 doc
: /* Template for displaying the title bar of an iconified frame.
15621 \(Assuming the window manager supports this feature.)
15622 This variable has the same structure as `mode-line-format' (which see),
15623 and is used only on frames for which no explicit name has been set
15624 \(see `modify-frame-parameters'). */);
15626 = Vframe_title_format
15627 = Fcons (intern ("multiple-frames"),
15628 Fcons (build_string ("%b"),
15629 Fcons (Fcons (empty_string
,
15630 Fcons (intern ("invocation-name"),
15631 Fcons (build_string ("@"),
15632 Fcons (intern ("system-name"),
15636 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
15637 doc
: /* Maximum number of lines to keep in the message log buffer.
15638 If nil, disable message logging. If t, log messages but don't truncate
15639 the buffer when it becomes large. */);
15640 Vmessage_log_max
= make_number (50);
15642 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
15643 doc
: /* Functions called before redisplay, if window sizes have changed.
15644 The value should be a list of functions that take one argument.
15645 Just before redisplay, for each frame, if any of its windows have changed
15646 size since the last redisplay, or have been split or deleted,
15647 all the functions in the list are called, with the frame as argument. */);
15648 Vwindow_size_change_functions
= Qnil
;
15650 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
15651 doc
: /* List of Functions to call before redisplaying a window with scrolling.
15652 Each function is called with two arguments, the window
15653 and its new display-start position. Note that the value of `window-end'
15654 is not valid when these functions are called. */);
15655 Vwindow_scroll_functions
= Qnil
;
15657 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
15658 doc
: /* *Non-nil means automatically resize tool-bars.
15659 This increases a tool-bar's height if not all tool-bar items are visible.
15660 It decreases a tool-bar's height when it would display blank lines
15662 auto_resize_tool_bars_p
= 1;
15664 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
15665 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
15666 auto_raise_tool_bar_buttons_p
= 1;
15668 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
15669 doc
: /* *Margin around tool-bar buttons in pixels.
15670 If an integer, use that for both horizontal and vertical margins.
15671 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
15672 HORZ specifying the horizontal margin, and VERT specifying the
15673 vertical margin. */);
15674 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
15676 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
15677 doc
: /* *Relief thickness of tool-bar buttons. */);
15678 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
15680 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
15681 doc
: /* List of functions to call to fontify regions of text.
15682 Each function is called with one argument POS. Functions must
15683 fontify a region starting at POS in the current buffer, and give
15684 fontified regions the property `fontified'. */);
15685 Vfontification_functions
= Qnil
;
15686 Fmake_variable_buffer_local (Qfontification_functions
);
15688 DEFVAR_BOOL ("unibyte-display-via-language-environment",
15689 &unibyte_display_via_language_environment
,
15690 doc
: /* *Non-nil means display unibyte text according to language environment.
15691 Specifically this means that unibyte non-ASCII characters
15692 are displayed by converting them to the equivalent multibyte characters
15693 according to the current language environment. As a result, they are
15694 displayed according to the current fontset. */);
15695 unibyte_display_via_language_environment
= 0;
15697 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
15698 doc
: /* *Maximum height for resizing mini-windows.
15699 If a float, it specifies a fraction of the mini-window frame's height.
15700 If an integer, it specifies a number of lines. */);
15701 Vmax_mini_window_height
= make_float (0.25);
15703 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
15704 doc
: /* *How to resize mini-windows.
15705 A value of nil means don't automatically resize mini-windows.
15706 A value of t means resize them to fit the text displayed in them.
15707 A value of `grow-only', the default, means let mini-windows grow
15708 only, until their display becomes empty, at which point the windows
15709 go back to their normal size. */);
15710 Vresize_mini_windows
= Qgrow_only
;
15712 DEFVAR_LISP ("cursor-in-non-selected-windows",
15713 &Vcursor_in_non_selected_windows
,
15714 doc
: /* *Cursor type to display in non-selected windows.
15715 t means to use hollow box cursor. See `cursor-type' for other values. */);
15716 Vcursor_in_non_selected_windows
= Qt
;
15718 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
15719 doc
: /* Alist specifying how to blink the cursor off.
15720 Each element has the form (ON-STATE . OFF-STATE). Whenever the
15721 `cursor-type' frame-parameter or variable equals ON-STATE,
15722 comparing using `equal', Emacs uses OFF-STATE to specify
15723 how to blink it off. */);
15724 Vblink_cursor_alist
= Qnil
;
15726 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
15727 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
15728 automatic_hscrolling_p
= 1;
15730 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
15731 doc
: /* *How many columns away from the window edge point is allowed to get
15732 before automatic hscrolling will horizontally scroll the window. */);
15733 hscroll_margin
= 5;
15735 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
15736 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
15737 When point is less than `automatic-hscroll-margin' columns from the window
15738 edge, automatic hscrolling will scroll the window by the amount of columns
15739 determined by this variable. If its value is a positive integer, scroll that
15740 many columns. If it's a positive floating-point number, it specifies the
15741 fraction of the window's width to scroll. If it's nil or zero, point will be
15742 centered horizontally after the scroll. Any other value, including negative
15743 numbers, are treated as if the value were zero.
15745 Automatic hscrolling always moves point outside the scroll margin, so if
15746 point was more than scroll step columns inside the margin, the window will
15747 scroll more than the value given by the scroll step.
15749 Note that the lower bound for automatic hscrolling specified by `scroll-left'
15750 and `scroll-right' overrides this variable's effect. */);
15751 Vhscroll_step
= make_number (0);
15753 DEFVAR_LISP ("image-types", &Vimage_types
,
15754 doc
: /* List of supported image types.
15755 Each element of the list is a symbol for a supported image type. */);
15756 Vimage_types
= Qnil
;
15758 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
15759 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
15760 Bind this around calls to `message' to let it take effect. */);
15761 message_truncate_lines
= 0;
15763 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
15764 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
15765 Can be used to update submenus whose contents should vary. */);
15766 Vmenu_bar_update_hook
= Qnil
;
15768 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
15769 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
15770 inhibit_menubar_update
= 0;
15772 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
15773 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
15774 inhibit_eval_during_redisplay
= 0;
15776 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
15777 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
15778 inhibit_free_realized_faces
= 0;
15781 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
15782 doc
: /* Inhibit try_window_id display optimization. */);
15783 inhibit_try_window_id
= 0;
15785 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
15786 doc
: /* Inhibit try_window_reusing display optimization. */);
15787 inhibit_try_window_reusing
= 0;
15789 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
15790 doc
: /* Inhibit try_cursor_movement display optimization. */);
15791 inhibit_try_cursor_movement
= 0;
15792 #endif /* GLYPH_DEBUG */
15796 /* Initialize this module when Emacs starts. */
15801 Lisp_Object root_window
;
15802 struct window
*mini_w
;
15804 current_header_line_height
= current_mode_line_height
= -1;
15806 CHARPOS (this_line_start_pos
) = 0;
15808 mini_w
= XWINDOW (minibuf_window
);
15809 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
15811 if (!noninteractive
)
15813 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
15816 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
15817 set_window_height (root_window
,
15818 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
15820 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
15821 set_window_height (minibuf_window
, 1, 0);
15823 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
15824 mini_w
->width
= make_number (FRAME_WIDTH (f
));
15826 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
15827 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
15828 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
15830 /* The default ellipsis glyphs `...'. */
15831 for (i
= 0; i
< 3; ++i
)
15832 default_invis_vector
[i
] = make_number ('.');
15836 /* Allocate the buffer for frame titles.
15837 Also used for `format-mode-line'. */
15839 frame_title_buf
= (char *) xmalloc (size
);
15840 frame_title_buf_end
= frame_title_buf
+ size
;
15841 frame_title_ptr
= NULL
;
15844 help_echo_showing_p
= 0;