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 do? 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 an 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 bottom boundary y-position for text lines in window W.
865 This is the first y position at which a line cannot start.
866 It is relative to the top of the window.
868 This is the height of W minus the height of a mode line, if any. */
871 window_text_bottom_y (w
)
874 struct frame
*f
= XFRAME (w
->frame
);
875 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
877 if (WINDOW_WANTS_MODELINE_P (w
))
878 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
883 /* Return the pixel width of display area AREA of window W. AREA < 0
884 means return the total width of W, not including fringes to
885 the left and right of the window. */
888 window_box_width (w
, area
)
892 struct frame
*f
= XFRAME (w
->frame
);
893 int width
= XFASTINT (w
->width
);
895 if (!w
->pseudo_window_p
)
897 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FRINGE_COLS (f
);
899 if (area
== TEXT_AREA
)
901 if (INTEGERP (w
->left_margin_width
))
902 width
-= XFASTINT (w
->left_margin_width
);
903 if (INTEGERP (w
->right_margin_width
))
904 width
-= XFASTINT (w
->right_margin_width
);
906 else if (area
== LEFT_MARGIN_AREA
)
907 width
= (INTEGERP (w
->left_margin_width
)
908 ? XFASTINT (w
->left_margin_width
) : 0);
909 else if (area
== RIGHT_MARGIN_AREA
)
910 width
= (INTEGERP (w
->right_margin_width
)
911 ? XFASTINT (w
->right_margin_width
) : 0);
914 return width
* CANON_X_UNIT (f
);
918 /* Return the pixel height of the display area of window W, not
919 including mode lines of W, if any. */
922 window_box_height (w
)
925 struct frame
*f
= XFRAME (w
->frame
);
926 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
928 xassert (height
>= 0);
930 /* Note: the code below that determines the mode-line/header-line
931 height is essentially the same as that contained in the macro
932 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
933 the appropriate glyph row has its `mode_line_p' flag set,
934 and if it doesn't, uses estimate_mode_line_height instead. */
936 if (WINDOW_WANTS_MODELINE_P (w
))
938 struct glyph_row
*ml_row
939 = (w
->current_matrix
&& w
->current_matrix
->rows
940 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
942 if (ml_row
&& ml_row
->mode_line_p
)
943 height
-= ml_row
->height
;
945 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
948 if (WINDOW_WANTS_HEADER_LINE_P (w
))
950 struct glyph_row
*hl_row
951 = (w
->current_matrix
&& w
->current_matrix
->rows
952 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
954 if (hl_row
&& hl_row
->mode_line_p
)
955 height
-= hl_row
->height
;
957 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
960 /* With a very small font and a mode-line that's taller than
961 default, we might end up with a negative height. */
962 return max (0, height
);
966 /* Return the frame-relative coordinate of the left edge of display
967 area AREA of window W. AREA < 0 means return the left edge of the
968 whole window, to the right of the left fringe of W. */
971 window_box_left (w
, area
)
975 struct frame
*f
= XFRAME (w
->frame
);
976 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
978 if (!w
->pseudo_window_p
)
980 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
981 + FRAME_LEFT_FRINGE_WIDTH (f
));
983 if (area
== TEXT_AREA
)
984 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
985 else if (area
== RIGHT_MARGIN_AREA
)
986 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
987 + window_box_width (w
, TEXT_AREA
));
994 /* Return the frame-relative coordinate of the right edge of display
995 area AREA of window W. AREA < 0 means return the left edge of the
996 whole window, to the left of the right fringe of W. */
999 window_box_right (w
, area
)
1003 return window_box_left (w
, area
) + window_box_width (w
, area
);
1007 /* Get the bounding box of the display area AREA of window W, without
1008 mode lines, in frame-relative coordinates. AREA < 0 means the
1009 whole window, not including the left and right fringes of
1010 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1011 coordinates of the upper-left corner of the box. Return in
1012 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1015 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1018 int *box_x
, *box_y
, *box_width
, *box_height
;
1020 struct frame
*f
= XFRAME (w
->frame
);
1022 *box_width
= window_box_width (w
, area
);
1023 *box_height
= window_box_height (w
);
1024 *box_x
= window_box_left (w
, area
);
1025 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
1026 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
1027 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1028 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1032 /* Get the bounding box of the display area AREA of window W, without
1033 mode lines. AREA < 0 means the whole window, not including the
1034 left and right fringe of the window. Return in *TOP_LEFT_X
1035 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1036 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1037 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1041 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1042 bottom_right_x
, bottom_right_y
)
1045 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1047 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1049 *bottom_right_x
+= *top_left_x
;
1050 *bottom_right_y
+= *top_left_y
;
1055 /***********************************************************************
1057 ***********************************************************************/
1059 /* Return the bottom y-position of the line the iterator IT is in.
1060 This can modify IT's settings. */
1066 int line_height
= it
->max_ascent
+ it
->max_descent
;
1067 int line_top_y
= it
->current_y
;
1069 if (line_height
== 0)
1072 line_height
= last_height
;
1073 else if (IT_CHARPOS (*it
) < ZV
)
1075 move_it_by_lines (it
, 1, 1);
1076 line_height
= (it
->max_ascent
|| it
->max_descent
1077 ? it
->max_ascent
+ it
->max_descent
1082 struct glyph_row
*row
= it
->glyph_row
;
1084 /* Use the default character height. */
1085 it
->glyph_row
= NULL
;
1086 it
->what
= IT_CHARACTER
;
1089 PRODUCE_GLYPHS (it
);
1090 line_height
= it
->ascent
+ it
->descent
;
1091 it
->glyph_row
= row
;
1095 return line_top_y
+ line_height
;
1099 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1100 1 if POS is visible and the line containing POS is fully visible.
1101 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1102 and header-lines heights. */
1105 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1107 int charpos
, *fully
, exact_mode_line_heights_p
;
1110 struct text_pos top
;
1112 struct buffer
*old_buffer
= NULL
;
1114 if (XBUFFER (w
->buffer
) != current_buffer
)
1116 old_buffer
= current_buffer
;
1117 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1120 *fully
= visible_p
= 0;
1121 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1123 /* Compute exact mode line heights, if requested. */
1124 if (exact_mode_line_heights_p
)
1126 if (WINDOW_WANTS_MODELINE_P (w
))
1127 current_mode_line_height
1128 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1129 current_buffer
->mode_line_format
);
1131 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1132 current_header_line_height
1133 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1134 current_buffer
->header_line_format
);
1137 start_display (&it
, w
, top
);
1138 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1139 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1141 /* Note that we may overshoot because of invisible text. */
1142 if (IT_CHARPOS (it
) >= charpos
)
1144 int top_y
= it
.current_y
;
1145 int bottom_y
= line_bottom_y (&it
);
1146 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1148 if (top_y
< window_top_y
)
1149 visible_p
= bottom_y
> window_top_y
;
1150 else if (top_y
< it
.last_visible_y
)
1153 *fully
= bottom_y
<= it
.last_visible_y
;
1156 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1158 move_it_by_lines (&it
, 1, 0);
1159 if (charpos
< IT_CHARPOS (it
))
1167 set_buffer_internal_1 (old_buffer
);
1169 current_header_line_height
= current_mode_line_height
= -1;
1174 /* Return the next character from STR which is MAXLEN bytes long.
1175 Return in *LEN the length of the character. This is like
1176 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1177 we find one, we return a `?', but with the length of the invalid
1181 string_char_and_length (str
, maxlen
, len
)
1182 const unsigned char *str
;
1187 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1188 if (!CHAR_VALID_P (c
, 1))
1189 /* We may not change the length here because other places in Emacs
1190 don't use this function, i.e. they silently accept invalid
1199 /* Given a position POS containing a valid character and byte position
1200 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1202 static struct text_pos
1203 string_pos_nchars_ahead (pos
, string
, nchars
)
1204 struct text_pos pos
;
1208 xassert (STRINGP (string
) && nchars
>= 0);
1210 if (STRING_MULTIBYTE (string
))
1212 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1213 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1218 string_char_and_length (p
, rest
, &len
);
1219 p
+= len
, rest
-= len
;
1220 xassert (rest
>= 0);
1222 BYTEPOS (pos
) += len
;
1226 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1232 /* Value is the text position, i.e. character and byte position,
1233 for character position CHARPOS in STRING. */
1235 static INLINE
struct text_pos
1236 string_pos (charpos
, string
)
1240 struct text_pos pos
;
1241 xassert (STRINGP (string
));
1242 xassert (charpos
>= 0);
1243 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1248 /* Value is a text position, i.e. character and byte position, for
1249 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1250 means recognize multibyte characters. */
1252 static struct text_pos
1253 c_string_pos (charpos
, s
, multibyte_p
)
1258 struct text_pos pos
;
1260 xassert (s
!= NULL
);
1261 xassert (charpos
>= 0);
1265 int rest
= strlen (s
), len
;
1267 SET_TEXT_POS (pos
, 0, 0);
1270 string_char_and_length (s
, rest
, &len
);
1271 s
+= len
, rest
-= len
;
1272 xassert (rest
>= 0);
1274 BYTEPOS (pos
) += len
;
1278 SET_TEXT_POS (pos
, charpos
, charpos
);
1284 /* Value is the number of characters in C string S. MULTIBYTE_P
1285 non-zero means recognize multibyte characters. */
1288 number_of_chars (s
, multibyte_p
)
1296 int rest
= strlen (s
), len
;
1297 unsigned char *p
= (unsigned char *) s
;
1299 for (nchars
= 0; rest
> 0; ++nchars
)
1301 string_char_and_length (p
, rest
, &len
);
1302 rest
-= len
, p
+= len
;
1306 nchars
= strlen (s
);
1312 /* Compute byte position NEWPOS->bytepos corresponding to
1313 NEWPOS->charpos. POS is a known position in string STRING.
1314 NEWPOS->charpos must be >= POS.charpos. */
1317 compute_string_pos (newpos
, pos
, string
)
1318 struct text_pos
*newpos
, pos
;
1321 xassert (STRINGP (string
));
1322 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1324 if (STRING_MULTIBYTE (string
))
1325 *newpos
= string_pos_nchars_ahead (pos
, string
,
1326 CHARPOS (*newpos
) - CHARPOS (pos
));
1328 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1333 /***********************************************************************
1334 Lisp form evaluation
1335 ***********************************************************************/
1337 /* Error handler for safe_eval and safe_call. */
1340 safe_eval_handler (arg
)
1343 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1348 /* Evaluate SEXPR and return the result, or nil if something went
1349 wrong. Prevent redisplay during the evaluation. */
1357 if (inhibit_eval_during_redisplay
)
1361 int count
= SPECPDL_INDEX ();
1362 struct gcpro gcpro1
;
1365 specbind (Qinhibit_redisplay
, Qt
);
1366 /* Use Qt to ensure debugger does not run,
1367 so there is no possibility of wanting to redisplay. */
1368 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1371 val
= unbind_to (count
, val
);
1378 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1379 Return the result, or nil if something went wrong. Prevent
1380 redisplay during the evaluation. */
1383 safe_call (nargs
, args
)
1389 if (inhibit_eval_during_redisplay
)
1393 int count
= SPECPDL_INDEX ();
1394 struct gcpro gcpro1
;
1397 gcpro1
.nvars
= nargs
;
1398 specbind (Qinhibit_redisplay
, Qt
);
1399 /* Use Qt to ensure debugger does not run,
1400 so there is no possibility of wanting to redisplay. */
1401 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1404 val
= unbind_to (count
, val
);
1411 /* Call function FN with one argument ARG.
1412 Return the result, or nil if something went wrong. */
1415 safe_call1 (fn
, arg
)
1416 Lisp_Object fn
, arg
;
1418 Lisp_Object args
[2];
1421 return safe_call (2, args
);
1426 /***********************************************************************
1428 ***********************************************************************/
1432 /* Define CHECK_IT to perform sanity checks on iterators.
1433 This is for debugging. It is too slow to do unconditionally. */
1439 if (it
->method
== next_element_from_string
)
1441 xassert (STRINGP (it
->string
));
1442 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1444 else if (it
->method
== next_element_from_buffer
)
1446 /* Check that character and byte positions agree. */
1447 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1451 xassert (it
->current
.dpvec_index
>= 0);
1453 xassert (it
->current
.dpvec_index
< 0);
1456 #define CHECK_IT(IT) check_it ((IT))
1460 #define CHECK_IT(IT) (void) 0
1467 /* Check that the window end of window W is what we expect it
1468 to be---the last row in the current matrix displaying text. */
1471 check_window_end (w
)
1474 if (!MINI_WINDOW_P (w
)
1475 && !NILP (w
->window_end_valid
))
1477 struct glyph_row
*row
;
1478 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1479 XFASTINT (w
->window_end_vpos
)),
1481 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1482 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1486 #define CHECK_WINDOW_END(W) check_window_end ((W))
1488 #else /* not GLYPH_DEBUG */
1490 #define CHECK_WINDOW_END(W) (void) 0
1492 #endif /* not GLYPH_DEBUG */
1496 /***********************************************************************
1497 Iterator initialization
1498 ***********************************************************************/
1500 /* Initialize IT for displaying current_buffer in window W, starting
1501 at character position CHARPOS. CHARPOS < 0 means that no buffer
1502 position is specified which is useful when the iterator is assigned
1503 a position later. BYTEPOS is the byte position corresponding to
1504 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1506 If ROW is not null, calls to produce_glyphs with IT as parameter
1507 will produce glyphs in that row.
1509 BASE_FACE_ID is the id of a base face to use. It must be one of
1510 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1511 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1512 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1514 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1515 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1516 will be initialized to use the corresponding mode line glyph row of
1517 the desired matrix of W. */
1520 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1523 int charpos
, bytepos
;
1524 struct glyph_row
*row
;
1525 enum face_id base_face_id
;
1527 int highlight_region_p
;
1529 /* Some precondition checks. */
1530 xassert (w
!= NULL
&& it
!= NULL
);
1531 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1534 /* If face attributes have been changed since the last redisplay,
1535 free realized faces now because they depend on face definitions
1536 that might have changed. Don't free faces while there might be
1537 desired matrices pending which reference these faces. */
1538 if (face_change_count
&& !inhibit_free_realized_faces
)
1540 face_change_count
= 0;
1541 free_all_realized_faces (Qnil
);
1544 /* Use one of the mode line rows of W's desired matrix if
1548 if (base_face_id
== MODE_LINE_FACE_ID
1549 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
1550 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1551 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1552 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1556 bzero (it
, sizeof *it
);
1557 it
->current
.overlay_string_index
= -1;
1558 it
->current
.dpvec_index
= -1;
1559 it
->base_face_id
= base_face_id
;
1561 /* The window in which we iterate over current_buffer: */
1562 XSETWINDOW (it
->window
, w
);
1564 it
->f
= XFRAME (w
->frame
);
1566 /* Extra space between lines (on window systems only). */
1567 if (base_face_id
== DEFAULT_FACE_ID
1568 && FRAME_WINDOW_P (it
->f
))
1570 if (NATNUMP (current_buffer
->extra_line_spacing
))
1571 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1572 else if (it
->f
->extra_line_spacing
> 0)
1573 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1576 /* If realized faces have been removed, e.g. because of face
1577 attribute changes of named faces, recompute them. When running
1578 in batch mode, the face cache of Vterminal_frame is null. If
1579 we happen to get called, make a dummy face cache. */
1584 FRAME_FACE_CACHE (it
->f
) == NULL
)
1585 init_frame_faces (it
->f
);
1586 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1587 recompute_basic_faces (it
->f
);
1589 /* Current value of the `space-width', and 'height' properties. */
1590 it
->space_width
= Qnil
;
1591 it
->font_height
= Qnil
;
1593 /* Are control characters displayed as `^C'? */
1594 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1596 /* -1 means everything between a CR and the following line end
1597 is invisible. >0 means lines indented more than this value are
1599 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1600 ? XFASTINT (current_buffer
->selective_display
)
1601 : (!NILP (current_buffer
->selective_display
)
1603 it
->selective_display_ellipsis_p
1604 = !NILP (current_buffer
->selective_display_ellipses
);
1606 /* Display table to use. */
1607 it
->dp
= window_display_table (w
);
1609 /* Are multibyte characters enabled in current_buffer? */
1610 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1612 /* Non-zero if we should highlight the region. */
1614 = (!NILP (Vtransient_mark_mode
)
1615 && !NILP (current_buffer
->mark_active
)
1616 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1618 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1619 start and end of a visible region in window IT->w. Set both to
1620 -1 to indicate no region. */
1621 if (highlight_region_p
1622 /* Maybe highlight only in selected window. */
1623 && (/* Either show region everywhere. */
1624 highlight_nonselected_windows
1625 /* Or show region in the selected window. */
1626 || w
== XWINDOW (selected_window
)
1627 /* Or show the region if we are in the mini-buffer and W is
1628 the window the mini-buffer refers to. */
1629 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1630 && WINDOWP (minibuf_selected_window
)
1631 && w
== XWINDOW (minibuf_selected_window
))))
1633 int charpos
= marker_position (current_buffer
->mark
);
1634 it
->region_beg_charpos
= min (PT
, charpos
);
1635 it
->region_end_charpos
= max (PT
, charpos
);
1638 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1640 /* Get the position at which the redisplay_end_trigger hook should
1641 be run, if it is to be run at all. */
1642 if (MARKERP (w
->redisplay_end_trigger
)
1643 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1644 it
->redisplay_end_trigger_charpos
1645 = marker_position (w
->redisplay_end_trigger
);
1646 else if (INTEGERP (w
->redisplay_end_trigger
))
1647 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1649 /* Correct bogus values of tab_width. */
1650 it
->tab_width
= XINT (current_buffer
->tab_width
);
1651 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1654 /* Are lines in the display truncated? */
1655 it
->truncate_lines_p
1656 = (base_face_id
!= DEFAULT_FACE_ID
1657 || XINT (it
->w
->hscroll
)
1658 || (truncate_partial_width_windows
1659 && !WINDOW_FULL_WIDTH_P (it
->w
))
1660 || !NILP (current_buffer
->truncate_lines
));
1662 /* Get dimensions of truncation and continuation glyphs. These are
1663 displayed as fringe bitmaps under X, so we don't need them for such
1665 if (!FRAME_WINDOW_P (it
->f
))
1667 if (it
->truncate_lines_p
)
1669 /* We will need the truncation glyph. */
1670 xassert (it
->glyph_row
== NULL
);
1671 produce_special_glyphs (it
, IT_TRUNCATION
);
1672 it
->truncation_pixel_width
= it
->pixel_width
;
1676 /* We will need the continuation glyph. */
1677 xassert (it
->glyph_row
== NULL
);
1678 produce_special_glyphs (it
, IT_CONTINUATION
);
1679 it
->continuation_pixel_width
= it
->pixel_width
;
1682 /* Reset these values to zero because the produce_special_glyphs
1683 above has changed them. */
1684 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1685 it
->phys_ascent
= it
->phys_descent
= 0;
1688 /* Set this after getting the dimensions of truncation and
1689 continuation glyphs, so that we don't produce glyphs when calling
1690 produce_special_glyphs, above. */
1691 it
->glyph_row
= row
;
1692 it
->area
= TEXT_AREA
;
1694 /* Get the dimensions of the display area. The display area
1695 consists of the visible window area plus a horizontally scrolled
1696 part to the left of the window. All x-values are relative to the
1697 start of this total display area. */
1698 if (base_face_id
!= DEFAULT_FACE_ID
)
1700 /* Mode lines, menu bar in terminal frames. */
1701 it
->first_visible_x
= 0;
1702 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1707 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1708 it
->last_visible_x
= (it
->first_visible_x
1709 + window_box_width (w
, TEXT_AREA
));
1711 /* If we truncate lines, leave room for the truncator glyph(s) at
1712 the right margin. Otherwise, leave room for the continuation
1713 glyph(s). Truncation and continuation glyphs are not inserted
1714 for window-based redisplay. */
1715 if (!FRAME_WINDOW_P (it
->f
))
1717 if (it
->truncate_lines_p
)
1718 it
->last_visible_x
-= it
->truncation_pixel_width
;
1720 it
->last_visible_x
-= it
->continuation_pixel_width
;
1723 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1724 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1727 /* Leave room for a border glyph. */
1728 if (!FRAME_WINDOW_P (it
->f
)
1729 && !WINDOW_RIGHTMOST_P (it
->w
))
1730 it
->last_visible_x
-= 1;
1732 it
->last_visible_y
= window_text_bottom_y (w
);
1734 /* For mode lines and alike, arrange for the first glyph having a
1735 left box line if the face specifies a box. */
1736 if (base_face_id
!= DEFAULT_FACE_ID
)
1740 it
->face_id
= base_face_id
;
1742 /* If we have a boxed mode line, make the first character appear
1743 with a left box line. */
1744 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1745 if (face
->box
!= FACE_NO_BOX
)
1746 it
->start_of_box_run_p
= 1;
1749 /* If a buffer position was specified, set the iterator there,
1750 getting overlays and face properties from that position. */
1751 if (charpos
>= BUF_BEG (current_buffer
))
1753 it
->end_charpos
= ZV
;
1755 IT_CHARPOS (*it
) = charpos
;
1757 /* Compute byte position if not specified. */
1758 if (bytepos
< charpos
)
1759 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1761 IT_BYTEPOS (*it
) = bytepos
;
1763 /* Compute faces etc. */
1764 reseat (it
, it
->current
.pos
, 1);
1771 /* Initialize IT for the display of window W with window start POS. */
1774 start_display (it
, w
, pos
)
1777 struct text_pos pos
;
1779 struct glyph_row
*row
;
1780 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1782 row
= w
->desired_matrix
->rows
+ first_vpos
;
1783 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1785 if (!it
->truncate_lines_p
)
1787 int start_at_line_beg_p
;
1788 int first_y
= it
->current_y
;
1790 /* If window start is not at a line start, skip forward to POS to
1791 get the correct continuation lines width. */
1792 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1793 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1794 if (!start_at_line_beg_p
)
1798 reseat_at_previous_visible_line_start (it
);
1799 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1801 new_x
= it
->current_x
+ it
->pixel_width
;
1803 /* If lines are continued, this line may end in the middle
1804 of a multi-glyph character (e.g. a control character
1805 displayed as \003, or in the middle of an overlay
1806 string). In this case move_it_to above will not have
1807 taken us to the start of the continuation line but to the
1808 end of the continued line. */
1809 if (it
->current_x
> 0
1810 && !it
->truncate_lines_p
/* Lines are continued. */
1811 && (/* And glyph doesn't fit on the line. */
1812 new_x
> it
->last_visible_x
1813 /* Or it fits exactly and we're on a window
1815 || (new_x
== it
->last_visible_x
1816 && FRAME_WINDOW_P (it
->f
))))
1818 if (it
->current
.dpvec_index
>= 0
1819 || it
->current
.overlay_string_index
>= 0)
1821 set_iterator_to_next (it
, 1);
1822 move_it_in_display_line_to (it
, -1, -1, 0);
1825 it
->continuation_lines_width
+= it
->current_x
;
1828 /* We're starting a new display line, not affected by the
1829 height of the continued line, so clear the appropriate
1830 fields in the iterator structure. */
1831 it
->max_ascent
= it
->max_descent
= 0;
1832 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1834 it
->current_y
= first_y
;
1836 it
->current_x
= it
->hpos
= 0;
1840 #if 0 /* Don't assert the following because start_display is sometimes
1841 called intentionally with a window start that is not at a
1842 line start. Please leave this code in as a comment. */
1844 /* Window start should be on a line start, now. */
1845 xassert (it
->continuation_lines_width
1846 || IT_CHARPOS (it
) == BEGV
1847 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1852 /* Return 1 if POS is a position in ellipses displayed for invisible
1853 text. W is the window we display, for text property lookup. */
1856 in_ellipses_for_invisible_text_p (pos
, w
)
1857 struct display_pos
*pos
;
1860 Lisp_Object prop
, window
;
1862 int charpos
= CHARPOS (pos
->pos
);
1864 /* If POS specifies a position in a display vector, this might
1865 be for an ellipsis displayed for invisible text. We won't
1866 get the iterator set up for delivering that ellipsis unless
1867 we make sure that it gets aware of the invisible text. */
1868 if (pos
->dpvec_index
>= 0
1869 && pos
->overlay_string_index
< 0
1870 && CHARPOS (pos
->string_pos
) < 0
1872 && (XSETWINDOW (window
, w
),
1873 prop
= Fget_char_property (make_number (charpos
),
1874 Qinvisible
, window
),
1875 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1877 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1879 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
1886 /* Initialize IT for stepping through current_buffer in window W,
1887 starting at position POS that includes overlay string and display
1888 vector/ control character translation position information. Value
1889 is zero if there are overlay strings with newlines at POS. */
1892 init_from_display_pos (it
, w
, pos
)
1895 struct display_pos
*pos
;
1897 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1898 int i
, overlay_strings_with_newlines
= 0;
1900 /* If POS specifies a position in a display vector, this might
1901 be for an ellipsis displayed for invisible text. We won't
1902 get the iterator set up for delivering that ellipsis unless
1903 we make sure that it gets aware of the invisible text. */
1904 if (in_ellipses_for_invisible_text_p (pos
, w
))
1910 /* Keep in mind: the call to reseat in init_iterator skips invisible
1911 text, so we might end up at a position different from POS. This
1912 is only a problem when POS is a row start after a newline and an
1913 overlay starts there with an after-string, and the overlay has an
1914 invisible property. Since we don't skip invisible text in
1915 display_line and elsewhere immediately after consuming the
1916 newline before the row start, such a POS will not be in a string,
1917 but the call to init_iterator below will move us to the
1919 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1921 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
1923 const char *s
= SDATA (it
->overlay_strings
[i
]);
1924 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
1926 while (s
< e
&& *s
!= '\n')
1931 overlay_strings_with_newlines
= 1;
1936 /* If position is within an overlay string, set up IT to the right
1938 if (pos
->overlay_string_index
>= 0)
1942 /* If the first overlay string happens to have a `display'
1943 property for an image, the iterator will be set up for that
1944 image, and we have to undo that setup first before we can
1945 correct the overlay string index. */
1946 if (it
->method
== next_element_from_image
)
1949 /* We already have the first chunk of overlay strings in
1950 IT->overlay_strings. Load more until the one for
1951 pos->overlay_string_index is in IT->overlay_strings. */
1952 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1954 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1955 it
->current
.overlay_string_index
= 0;
1958 load_overlay_strings (it
, 0);
1959 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1963 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1964 relative_index
= (it
->current
.overlay_string_index
1965 % OVERLAY_STRING_CHUNK_SIZE
);
1966 it
->string
= it
->overlay_strings
[relative_index
];
1967 xassert (STRINGP (it
->string
));
1968 it
->current
.string_pos
= pos
->string_pos
;
1969 it
->method
= next_element_from_string
;
1972 #if 0 /* This is bogus because POS not having an overlay string
1973 position does not mean it's after the string. Example: A
1974 line starting with a before-string and initialization of IT
1975 to the previous row's end position. */
1976 else if (it
->current
.overlay_string_index
>= 0)
1978 /* If POS says we're already after an overlay string ending at
1979 POS, make sure to pop the iterator because it will be in
1980 front of that overlay string. When POS is ZV, we've thereby
1981 also ``processed'' overlay strings at ZV. */
1984 it
->current
.overlay_string_index
= -1;
1985 it
->method
= next_element_from_buffer
;
1986 if (CHARPOS (pos
->pos
) == ZV
)
1987 it
->overlay_strings_at_end_processed_p
= 1;
1991 if (CHARPOS (pos
->string_pos
) >= 0)
1993 /* Recorded position is not in an overlay string, but in another
1994 string. This can only be a string from a `display' property.
1995 IT should already be filled with that string. */
1996 it
->current
.string_pos
= pos
->string_pos
;
1997 xassert (STRINGP (it
->string
));
2000 /* Restore position in display vector translations, control
2001 character translations or ellipses. */
2002 if (pos
->dpvec_index
>= 0)
2004 if (it
->dpvec
== NULL
)
2005 get_next_display_element (it
);
2006 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2007 it
->current
.dpvec_index
= pos
->dpvec_index
;
2011 return !overlay_strings_with_newlines
;
2015 /* Initialize IT for stepping through current_buffer in window W
2016 starting at ROW->start. */
2019 init_to_row_start (it
, w
, row
)
2022 struct glyph_row
*row
;
2024 init_from_display_pos (it
, w
, &row
->start
);
2025 it
->continuation_lines_width
= row
->continuation_lines_width
;
2030 /* Initialize IT for stepping through current_buffer in window W
2031 starting in the line following ROW, i.e. starting at ROW->end.
2032 Value is zero if there are overlay strings with newlines at ROW's
2036 init_to_row_end (it
, w
, row
)
2039 struct glyph_row
*row
;
2043 if (init_from_display_pos (it
, w
, &row
->end
))
2045 if (row
->continued_p
)
2046 it
->continuation_lines_width
2047 = row
->continuation_lines_width
+ row
->pixel_width
;
2058 /***********************************************************************
2060 ***********************************************************************/
2062 /* Called when IT reaches IT->stop_charpos. Handle text property and
2063 overlay changes. Set IT->stop_charpos to the next position where
2070 enum prop_handled handled
;
2071 int handle_overlay_change_p
= 1;
2075 it
->current
.dpvec_index
= -1;
2079 handled
= HANDLED_NORMALLY
;
2081 /* Call text property handlers. */
2082 for (p
= it_props
; p
->handler
; ++p
)
2084 handled
= p
->handler (it
);
2086 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2088 else if (handled
== HANDLED_RETURN
)
2090 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2091 handle_overlay_change_p
= 0;
2094 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2096 /* Don't check for overlay strings below when set to deliver
2097 characters from a display vector. */
2098 if (it
->method
== next_element_from_display_vector
)
2099 handle_overlay_change_p
= 0;
2101 /* Handle overlay changes. */
2102 if (handle_overlay_change_p
)
2103 handled
= handle_overlay_change (it
);
2105 /* Determine where to stop next. */
2106 if (handled
== HANDLED_NORMALLY
)
2107 compute_stop_pos (it
);
2110 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2114 /* Compute IT->stop_charpos from text property and overlay change
2115 information for IT's current position. */
2118 compute_stop_pos (it
)
2121 register INTERVAL iv
, next_iv
;
2122 Lisp_Object object
, limit
, position
;
2124 /* If nowhere else, stop at the end. */
2125 it
->stop_charpos
= it
->end_charpos
;
2127 if (STRINGP (it
->string
))
2129 /* Strings are usually short, so don't limit the search for
2131 object
= it
->string
;
2133 position
= make_number (IT_STRING_CHARPOS (*it
));
2139 /* If next overlay change is in front of the current stop pos
2140 (which is IT->end_charpos), stop there. Note: value of
2141 next_overlay_change is point-max if no overlay change
2143 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2144 if (charpos
< it
->stop_charpos
)
2145 it
->stop_charpos
= charpos
;
2147 /* If showing the region, we have to stop at the region
2148 start or end because the face might change there. */
2149 if (it
->region_beg_charpos
> 0)
2151 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2152 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2153 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2154 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2157 /* Set up variables for computing the stop position from text
2158 property changes. */
2159 XSETBUFFER (object
, current_buffer
);
2160 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2161 position
= make_number (IT_CHARPOS (*it
));
2165 /* Get the interval containing IT's position. Value is a null
2166 interval if there isn't such an interval. */
2167 iv
= validate_interval_range (object
, &position
, &position
, 0);
2168 if (!NULL_INTERVAL_P (iv
))
2170 Lisp_Object values_here
[LAST_PROP_IDX
];
2173 /* Get properties here. */
2174 for (p
= it_props
; p
->handler
; ++p
)
2175 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2177 /* Look for an interval following iv that has different
2179 for (next_iv
= next_interval (iv
);
2180 (!NULL_INTERVAL_P (next_iv
)
2182 || XFASTINT (limit
) > next_iv
->position
));
2183 next_iv
= next_interval (next_iv
))
2185 for (p
= it_props
; p
->handler
; ++p
)
2187 Lisp_Object new_value
;
2189 new_value
= textget (next_iv
->plist
, *p
->name
);
2190 if (!EQ (values_here
[p
->idx
], new_value
))
2198 if (!NULL_INTERVAL_P (next_iv
))
2200 if (INTEGERP (limit
)
2201 && next_iv
->position
>= XFASTINT (limit
))
2202 /* No text property change up to limit. */
2203 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2205 /* Text properties change in next_iv. */
2206 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2210 xassert (STRINGP (it
->string
)
2211 || (it
->stop_charpos
>= BEGV
2212 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2216 /* Return the position of the next overlay change after POS in
2217 current_buffer. Value is point-max if no overlay change
2218 follows. This is like `next-overlay-change' but doesn't use
2222 next_overlay_change (pos
)
2227 Lisp_Object
*overlays
;
2231 /* Get all overlays at the given position. */
2233 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2234 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2235 if (noverlays
> len
)
2238 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2239 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2242 /* If any of these overlays ends before endpos,
2243 use its ending point instead. */
2244 for (i
= 0; i
< noverlays
; ++i
)
2249 oend
= OVERLAY_END (overlays
[i
]);
2250 oendpos
= OVERLAY_POSITION (oend
);
2251 endpos
= min (endpos
, oendpos
);
2259 /***********************************************************************
2261 ***********************************************************************/
2263 /* Handle changes in the `fontified' property of the current buffer by
2264 calling hook functions from Qfontification_functions to fontify
2267 static enum prop_handled
2268 handle_fontified_prop (it
)
2271 Lisp_Object prop
, pos
;
2272 enum prop_handled handled
= HANDLED_NORMALLY
;
2274 /* Get the value of the `fontified' property at IT's current buffer
2275 position. (The `fontified' property doesn't have a special
2276 meaning in strings.) If the value is nil, call functions from
2277 Qfontification_functions. */
2278 if (!STRINGP (it
->string
)
2280 && !NILP (Vfontification_functions
)
2281 && !NILP (Vrun_hooks
)
2282 && (pos
= make_number (IT_CHARPOS (*it
)),
2283 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2286 int count
= SPECPDL_INDEX ();
2289 val
= Vfontification_functions
;
2290 specbind (Qfontification_functions
, Qnil
);
2292 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2293 safe_call1 (val
, pos
);
2296 Lisp_Object globals
, fn
;
2297 struct gcpro gcpro1
, gcpro2
;
2300 GCPRO2 (val
, globals
);
2302 for (; CONSP (val
); val
= XCDR (val
))
2308 /* A value of t indicates this hook has a local
2309 binding; it means to run the global binding too.
2310 In a global value, t should not occur. If it
2311 does, we must ignore it to avoid an endless
2313 for (globals
= Fdefault_value (Qfontification_functions
);
2315 globals
= XCDR (globals
))
2317 fn
= XCAR (globals
);
2319 safe_call1 (fn
, pos
);
2323 safe_call1 (fn
, pos
);
2329 unbind_to (count
, Qnil
);
2331 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2332 something. This avoids an endless loop if they failed to
2333 fontify the text for which reason ever. */
2334 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2335 handled
= HANDLED_RECOMPUTE_PROPS
;
2343 /***********************************************************************
2345 ***********************************************************************/
2347 /* Set up iterator IT from face properties at its current position.
2348 Called from handle_stop. */
2350 static enum prop_handled
2351 handle_face_prop (it
)
2354 int new_face_id
, next_stop
;
2356 if (!STRINGP (it
->string
))
2359 = face_at_buffer_position (it
->w
,
2361 it
->region_beg_charpos
,
2362 it
->region_end_charpos
,
2365 + TEXT_PROP_DISTANCE_LIMIT
),
2368 /* Is this a start of a run of characters with box face?
2369 Caveat: this can be called for a freshly initialized
2370 iterator; face_id is -1 in this case. We know that the new
2371 face will not change until limit, i.e. if the new face has a
2372 box, all characters up to limit will have one. But, as
2373 usual, we don't know whether limit is really the end. */
2374 if (new_face_id
!= it
->face_id
)
2376 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2378 /* If new face has a box but old face has not, this is
2379 the start of a run of characters with box, i.e. it has
2380 a shadow on the left side. The value of face_id of the
2381 iterator will be -1 if this is the initial call that gets
2382 the face. In this case, we have to look in front of IT's
2383 position and see whether there is a face != new_face_id. */
2384 it
->start_of_box_run_p
2385 = (new_face
->box
!= FACE_NO_BOX
2386 && (it
->face_id
>= 0
2387 || IT_CHARPOS (*it
) == BEG
2388 || new_face_id
!= face_before_it_pos (it
)));
2389 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2394 int base_face_id
, bufpos
;
2396 if (it
->current
.overlay_string_index
>= 0)
2397 bufpos
= IT_CHARPOS (*it
);
2401 /* For strings from a buffer, i.e. overlay strings or strings
2402 from a `display' property, use the face at IT's current
2403 buffer position as the base face to merge with, so that
2404 overlay strings appear in the same face as surrounding
2405 text, unless they specify their own faces. */
2406 base_face_id
= underlying_face_id (it
);
2408 new_face_id
= face_at_string_position (it
->w
,
2410 IT_STRING_CHARPOS (*it
),
2412 it
->region_beg_charpos
,
2413 it
->region_end_charpos
,
2417 #if 0 /* This shouldn't be neccessary. Let's check it. */
2418 /* If IT is used to display a mode line we would really like to
2419 use the mode line face instead of the frame's default face. */
2420 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2421 && new_face_id
== DEFAULT_FACE_ID
)
2422 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2425 /* Is this a start of a run of characters with box? Caveat:
2426 this can be called for a freshly allocated iterator; face_id
2427 is -1 is this case. We know that the new face will not
2428 change until the next check pos, i.e. if the new face has a
2429 box, all characters up to that position will have a
2430 box. But, as usual, we don't know whether that position
2431 is really the end. */
2432 if (new_face_id
!= it
->face_id
)
2434 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2435 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2437 /* If new face has a box but old face hasn't, this is the
2438 start of a run of characters with box, i.e. it has a
2439 shadow on the left side. */
2440 it
->start_of_box_run_p
2441 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2442 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2446 it
->face_id
= new_face_id
;
2447 return HANDLED_NORMALLY
;
2451 /* Return the ID of the face ``underlying'' IT's current position,
2452 which is in a string. If the iterator is associated with a
2453 buffer, return the face at IT's current buffer position.
2454 Otherwise, use the iterator's base_face_id. */
2457 underlying_face_id (it
)
2460 int face_id
= it
->base_face_id
, i
;
2462 xassert (STRINGP (it
->string
));
2464 for (i
= it
->sp
- 1; i
>= 0; --i
)
2465 if (NILP (it
->stack
[i
].string
))
2466 face_id
= it
->stack
[i
].face_id
;
2472 /* Compute the face one character before or after the current position
2473 of IT. BEFORE_P non-zero means get the face in front of IT's
2474 position. Value is the id of the face. */
2477 face_before_or_after_it_pos (it
, before_p
)
2482 int next_check_charpos
;
2483 struct text_pos pos
;
2485 xassert (it
->s
== NULL
);
2487 if (STRINGP (it
->string
))
2489 int bufpos
, base_face_id
;
2491 /* No face change past the end of the string (for the case
2492 we are padding with spaces). No face change before the
2494 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2495 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2498 /* Set pos to the position before or after IT's current position. */
2500 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2502 /* For composition, we must check the character after the
2504 pos
= (it
->what
== IT_COMPOSITION
2505 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2506 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2508 if (it
->current
.overlay_string_index
>= 0)
2509 bufpos
= IT_CHARPOS (*it
);
2513 base_face_id
= underlying_face_id (it
);
2515 /* Get the face for ASCII, or unibyte. */
2516 face_id
= face_at_string_position (it
->w
,
2520 it
->region_beg_charpos
,
2521 it
->region_end_charpos
,
2522 &next_check_charpos
,
2525 /* Correct the face for charsets different from ASCII. Do it
2526 for the multibyte case only. The face returned above is
2527 suitable for unibyte text if IT->string is unibyte. */
2528 if (STRING_MULTIBYTE (it
->string
))
2530 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
2531 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
2533 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2535 c
= string_char_and_length (p
, rest
, &len
);
2536 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2541 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2542 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2545 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2546 pos
= it
->current
.pos
;
2549 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2552 if (it
->what
== IT_COMPOSITION
)
2553 /* For composition, we must check the position after the
2555 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2557 INC_TEXT_POS (pos
, it
->multibyte_p
);
2560 /* Determine face for CHARSET_ASCII, or unibyte. */
2561 face_id
= face_at_buffer_position (it
->w
,
2563 it
->region_beg_charpos
,
2564 it
->region_end_charpos
,
2565 &next_check_charpos
,
2568 /* Correct the face for charsets different from ASCII. Do it
2569 for the multibyte case only. The face returned above is
2570 suitable for unibyte text if current_buffer is unibyte. */
2571 if (it
->multibyte_p
)
2573 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
2574 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2575 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2584 /***********************************************************************
2586 ***********************************************************************/
2588 /* Set up iterator IT from invisible properties at its current
2589 position. Called from handle_stop. */
2591 static enum prop_handled
2592 handle_invisible_prop (it
)
2595 enum prop_handled handled
= HANDLED_NORMALLY
;
2597 if (STRINGP (it
->string
))
2599 extern Lisp_Object Qinvisible
;
2600 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2602 /* Get the value of the invisible text property at the
2603 current position. Value will be nil if there is no such
2605 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2606 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2609 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2611 handled
= HANDLED_RECOMPUTE_PROPS
;
2613 /* Get the position at which the next change of the
2614 invisible text property can be found in IT->string.
2615 Value will be nil if the property value is the same for
2616 all the rest of IT->string. */
2617 XSETINT (limit
, SCHARS (it
->string
));
2618 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2621 /* Text at current position is invisible. The next
2622 change in the property is at position end_charpos.
2623 Move IT's current position to that position. */
2624 if (INTEGERP (end_charpos
)
2625 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2627 struct text_pos old
;
2628 old
= it
->current
.string_pos
;
2629 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2630 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2634 /* The rest of the string is invisible. If this is an
2635 overlay string, proceed with the next overlay string
2636 or whatever comes and return a character from there. */
2637 if (it
->current
.overlay_string_index
>= 0)
2639 next_overlay_string (it
);
2640 /* Don't check for overlay strings when we just
2641 finished processing them. */
2642 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2646 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
2647 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
2654 int invis_p
, newpos
, next_stop
, start_charpos
;
2655 Lisp_Object pos
, prop
, overlay
;
2657 /* First of all, is there invisible text at this position? */
2658 start_charpos
= IT_CHARPOS (*it
);
2659 pos
= make_number (IT_CHARPOS (*it
));
2660 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2662 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2664 /* If we are on invisible text, skip over it. */
2665 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
2667 /* Record whether we have to display an ellipsis for the
2669 int display_ellipsis_p
= invis_p
== 2;
2671 handled
= HANDLED_RECOMPUTE_PROPS
;
2673 /* Loop skipping over invisible text. The loop is left at
2674 ZV or with IT on the first char being visible again. */
2677 /* Try to skip some invisible text. Return value is the
2678 position reached which can be equal to IT's position
2679 if there is nothing invisible here. This skips both
2680 over invisible text properties and overlays with
2681 invisible property. */
2682 newpos
= skip_invisible (IT_CHARPOS (*it
),
2683 &next_stop
, ZV
, it
->window
);
2685 /* If we skipped nothing at all we weren't at invisible
2686 text in the first place. If everything to the end of
2687 the buffer was skipped, end the loop. */
2688 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2692 /* We skipped some characters but not necessarily
2693 all there are. Check if we ended up on visible
2694 text. Fget_char_property returns the property of
2695 the char before the given position, i.e. if we
2696 get invis_p = 0, this means that the char at
2697 newpos is visible. */
2698 pos
= make_number (newpos
);
2699 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2700 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2703 /* If we ended up on invisible text, proceed to
2704 skip starting with next_stop. */
2706 IT_CHARPOS (*it
) = next_stop
;
2710 /* The position newpos is now either ZV or on visible text. */
2711 IT_CHARPOS (*it
) = newpos
;
2712 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2714 /* If there are before-strings at the start of invisible
2715 text, and the text is invisible because of a text
2716 property, arrange to show before-strings because 20.x did
2717 it that way. (If the text is invisible because of an
2718 overlay property instead of a text property, this is
2719 already handled in the overlay code.) */
2721 && get_overlay_strings (it
, start_charpos
))
2723 handled
= HANDLED_RECOMPUTE_PROPS
;
2724 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2726 else if (display_ellipsis_p
)
2727 setup_for_ellipsis (it
);
2735 /* Make iterator IT return `...' next. */
2738 setup_for_ellipsis (it
)
2742 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2744 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2745 it
->dpvec
= v
->contents
;
2746 it
->dpend
= v
->contents
+ v
->size
;
2750 /* Default `...'. */
2751 it
->dpvec
= default_invis_vector
;
2752 it
->dpend
= default_invis_vector
+ 3;
2755 /* The ellipsis display does not replace the display of the
2756 character at the new position. Indicate this by setting
2757 IT->dpvec_char_len to zero. */
2758 it
->dpvec_char_len
= 0;
2760 it
->current
.dpvec_index
= 0;
2761 it
->method
= next_element_from_display_vector
;
2766 /***********************************************************************
2768 ***********************************************************************/
2770 /* Set up iterator IT from `display' property at its current position.
2771 Called from handle_stop. */
2773 static enum prop_handled
2774 handle_display_prop (it
)
2777 Lisp_Object prop
, object
;
2778 struct text_pos
*position
;
2779 int display_replaced_p
= 0;
2781 if (STRINGP (it
->string
))
2783 object
= it
->string
;
2784 position
= &it
->current
.string_pos
;
2788 object
= it
->w
->buffer
;
2789 position
= &it
->current
.pos
;
2792 /* Reset those iterator values set from display property values. */
2793 it
->font_height
= Qnil
;
2794 it
->space_width
= Qnil
;
2797 /* We don't support recursive `display' properties, i.e. string
2798 values that have a string `display' property, that have a string
2799 `display' property etc. */
2800 if (!it
->string_from_display_prop_p
)
2801 it
->area
= TEXT_AREA
;
2803 prop
= Fget_char_property (make_number (position
->charpos
),
2806 return HANDLED_NORMALLY
;
2809 /* Simple properties. */
2810 && !EQ (XCAR (prop
), Qimage
)
2811 && !EQ (XCAR (prop
), Qspace
)
2812 && !EQ (XCAR (prop
), Qwhen
)
2813 && !EQ (XCAR (prop
), Qspace_width
)
2814 && !EQ (XCAR (prop
), Qheight
)
2815 && !EQ (XCAR (prop
), Qraise
)
2816 /* Marginal area specifications. */
2817 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2818 && !NILP (XCAR (prop
)))
2820 for (; CONSP (prop
); prop
= XCDR (prop
))
2822 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2823 position
, display_replaced_p
))
2824 display_replaced_p
= 1;
2827 else if (VECTORP (prop
))
2830 for (i
= 0; i
< ASIZE (prop
); ++i
)
2831 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2832 position
, display_replaced_p
))
2833 display_replaced_p
= 1;
2837 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2838 display_replaced_p
= 1;
2841 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2845 /* Value is the position of the end of the `display' property starting
2846 at START_POS in OBJECT. */
2848 static struct text_pos
2849 display_prop_end (it
, object
, start_pos
)
2852 struct text_pos start_pos
;
2855 struct text_pos end_pos
;
2857 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2858 Qdisplay
, object
, Qnil
);
2859 CHARPOS (end_pos
) = XFASTINT (end
);
2860 if (STRINGP (object
))
2861 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2863 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2869 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2870 is the object in which the `display' property was found. *POSITION
2871 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2872 means that we previously saw a display sub-property which already
2873 replaced text display with something else, for example an image;
2874 ignore such properties after the first one has been processed.
2876 If PROP is a `space' or `image' sub-property, set *POSITION to the
2877 end position of the `display' property.
2879 Value is non-zero if something was found which replaces the display
2880 of buffer or string text. */
2883 handle_single_display_prop (it
, prop
, object
, position
,
2884 display_replaced_before_p
)
2888 struct text_pos
*position
;
2889 int display_replaced_before_p
;
2892 int replaces_text_display_p
= 0;
2895 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2896 evaluated. If the result is nil, VALUE is ignored. */
2898 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2907 if (!NILP (form
) && !EQ (form
, Qt
))
2909 int count
= SPECPDL_INDEX ();
2910 struct gcpro gcpro1
;
2912 /* Bind `object' to the object having the `display' property, a
2913 buffer or string. Bind `position' to the position in the
2914 object where the property was found, and `buffer-position'
2915 to the current position in the buffer. */
2916 specbind (Qobject
, object
);
2917 specbind (Qposition
, make_number (CHARPOS (*position
)));
2918 specbind (Qbuffer_position
,
2919 make_number (STRINGP (object
)
2920 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2922 form
= safe_eval (form
);
2924 unbind_to (count
, Qnil
);
2931 && EQ (XCAR (prop
), Qheight
)
2932 && CONSP (XCDR (prop
)))
2934 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2937 /* `(height HEIGHT)'. */
2938 it
->font_height
= XCAR (XCDR (prop
));
2939 if (!NILP (it
->font_height
))
2941 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2942 int new_height
= -1;
2944 if (CONSP (it
->font_height
)
2945 && (EQ (XCAR (it
->font_height
), Qplus
)
2946 || EQ (XCAR (it
->font_height
), Qminus
))
2947 && CONSP (XCDR (it
->font_height
))
2948 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2950 /* `(+ N)' or `(- N)' where N is an integer. */
2951 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2952 if (EQ (XCAR (it
->font_height
), Qplus
))
2954 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2956 else if (FUNCTIONP (it
->font_height
))
2958 /* Call function with current height as argument.
2959 Value is the new height. */
2961 height
= safe_call1 (it
->font_height
,
2962 face
->lface
[LFACE_HEIGHT_INDEX
]);
2963 if (NUMBERP (height
))
2964 new_height
= XFLOATINT (height
);
2966 else if (NUMBERP (it
->font_height
))
2968 /* Value is a multiple of the canonical char height. */
2971 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2972 new_height
= (XFLOATINT (it
->font_height
)
2973 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2977 /* Evaluate IT->font_height with `height' bound to the
2978 current specified height to get the new height. */
2980 int count
= SPECPDL_INDEX ();
2982 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2983 value
= safe_eval (it
->font_height
);
2984 unbind_to (count
, Qnil
);
2986 if (NUMBERP (value
))
2987 new_height
= XFLOATINT (value
);
2991 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2994 else if (CONSP (prop
)
2995 && EQ (XCAR (prop
), Qspace_width
)
2996 && CONSP (XCDR (prop
)))
2998 /* `(space_width WIDTH)'. */
2999 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3002 value
= XCAR (XCDR (prop
));
3003 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3004 it
->space_width
= value
;
3006 else if (CONSP (prop
)
3007 && EQ (XCAR (prop
), Qraise
)
3008 && CONSP (XCDR (prop
)))
3010 /* `(raise FACTOR)'. */
3011 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3014 #ifdef HAVE_WINDOW_SYSTEM
3015 value
= XCAR (XCDR (prop
));
3016 if (NUMBERP (value
))
3018 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3019 it
->voffset
= - (XFLOATINT (value
)
3020 * (FONT_HEIGHT (face
->font
)));
3022 #endif /* HAVE_WINDOW_SYSTEM */
3024 else if (!it
->string_from_display_prop_p
)
3026 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3027 VALUE) or `((margin nil) VALUE)' or VALUE. */
3028 Lisp_Object location
, value
;
3029 struct text_pos start_pos
;
3032 /* Characters having this form of property are not displayed, so
3033 we have to find the end of the property. */
3034 start_pos
= *position
;
3035 *position
= display_prop_end (it
, object
, start_pos
);
3038 /* Let's stop at the new position and assume that all
3039 text properties change there. */
3040 it
->stop_charpos
= position
->charpos
;
3042 location
= Qunbound
;
3043 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3047 value
= XCDR (prop
);
3049 value
= XCAR (value
);
3052 if (EQ (XCAR (tem
), Qmargin
)
3053 && (tem
= XCDR (tem
),
3054 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3056 || EQ (tem
, Qleft_margin
)
3057 || EQ (tem
, Qright_margin
))))
3061 if (EQ (location
, Qunbound
))
3067 #ifdef HAVE_WINDOW_SYSTEM
3068 if (FRAME_TERMCAP_P (it
->f
))
3069 valid_p
= STRINGP (value
);
3071 valid_p
= (STRINGP (value
)
3072 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3073 || valid_image_p (value
));
3074 #else /* not HAVE_WINDOW_SYSTEM */
3075 valid_p
= STRINGP (value
);
3076 #endif /* not HAVE_WINDOW_SYSTEM */
3078 if ((EQ (location
, Qleft_margin
)
3079 || EQ (location
, Qright_margin
)
3082 && !display_replaced_before_p
)
3084 replaces_text_display_p
= 1;
3086 /* Save current settings of IT so that we can restore them
3087 when we are finished with the glyph property value. */
3090 if (NILP (location
))
3091 it
->area
= TEXT_AREA
;
3092 else if (EQ (location
, Qleft_margin
))
3093 it
->area
= LEFT_MARGIN_AREA
;
3095 it
->area
= RIGHT_MARGIN_AREA
;
3097 if (STRINGP (value
))
3100 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3101 it
->current
.overlay_string_index
= -1;
3102 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3103 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3104 it
->method
= next_element_from_string
;
3105 it
->stop_charpos
= 0;
3106 it
->string_from_display_prop_p
= 1;
3107 /* Say that we haven't consumed the characters with
3108 `display' property yet. The call to pop_it in
3109 set_iterator_to_next will clean this up. */
3110 *position
= start_pos
;
3112 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3114 it
->method
= next_element_from_stretch
;
3116 it
->current
.pos
= it
->position
= start_pos
;
3118 #ifdef HAVE_WINDOW_SYSTEM
3121 it
->what
= IT_IMAGE
;
3122 it
->image_id
= lookup_image (it
->f
, value
);
3123 it
->position
= start_pos
;
3124 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3125 it
->method
= next_element_from_image
;
3127 /* Say that we haven't consumed the characters with
3128 `display' property yet. The call to pop_it in
3129 set_iterator_to_next will clean this up. */
3130 *position
= start_pos
;
3132 #endif /* HAVE_WINDOW_SYSTEM */
3135 /* Invalid property or property not supported. Restore
3136 the position to what it was before. */
3137 *position
= start_pos
;
3140 return replaces_text_display_p
;
3144 /* Check if PROP is a display sub-property value whose text should be
3145 treated as intangible. */
3148 single_display_prop_intangible_p (prop
)
3151 /* Skip over `when FORM'. */
3152 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3166 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3167 we don't need to treat text as intangible. */
3168 if (EQ (XCAR (prop
), Qmargin
))
3176 || EQ (XCAR (prop
), Qleft_margin
)
3177 || EQ (XCAR (prop
), Qright_margin
))
3181 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3185 /* Check if PROP is a display property value whose text should be
3186 treated as intangible. */
3189 display_prop_intangible_p (prop
)
3193 && CONSP (XCAR (prop
))
3194 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3196 /* A list of sub-properties. */
3197 while (CONSP (prop
))
3199 if (single_display_prop_intangible_p (XCAR (prop
)))
3204 else if (VECTORP (prop
))
3206 /* A vector of sub-properties. */
3208 for (i
= 0; i
< ASIZE (prop
); ++i
)
3209 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3213 return single_display_prop_intangible_p (prop
);
3219 /* Return 1 if PROP is a display sub-property value containing STRING. */
3222 single_display_prop_string_p (prop
, string
)
3223 Lisp_Object prop
, string
;
3225 if (EQ (string
, prop
))
3228 /* Skip over `when FORM'. */
3229 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3238 /* Skip over `margin LOCATION'. */
3239 if (EQ (XCAR (prop
), Qmargin
))
3250 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3254 /* Return 1 if STRING appears in the `display' property PROP. */
3257 display_prop_string_p (prop
, string
)
3258 Lisp_Object prop
, string
;
3261 && CONSP (XCAR (prop
))
3262 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3264 /* A list of sub-properties. */
3265 while (CONSP (prop
))
3267 if (single_display_prop_string_p (XCAR (prop
), string
))
3272 else if (VECTORP (prop
))
3274 /* A vector of sub-properties. */
3276 for (i
= 0; i
< ASIZE (prop
); ++i
)
3277 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3281 return single_display_prop_string_p (prop
, string
);
3287 /* Determine from which buffer position in W's buffer STRING comes
3288 from. AROUND_CHARPOS is an approximate position where it could
3289 be from. Value is the buffer position or 0 if it couldn't be
3292 W's buffer must be current.
3294 This function is necessary because we don't record buffer positions
3295 in glyphs generated from strings (to keep struct glyph small).
3296 This function may only use code that doesn't eval because it is
3297 called asynchronously from note_mouse_highlight. */
3300 string_buffer_position (w
, string
, around_charpos
)
3305 Lisp_Object limit
, prop
, pos
;
3306 const int MAX_DISTANCE
= 1000;
3309 pos
= make_number (around_charpos
);
3310 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3311 while (!found
&& !EQ (pos
, limit
))
3313 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3314 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3317 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3322 pos
= make_number (around_charpos
);
3323 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3324 while (!found
&& !EQ (pos
, limit
))
3326 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3327 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3330 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3335 return found
? XINT (pos
) : 0;
3340 /***********************************************************************
3341 `composition' property
3342 ***********************************************************************/
3344 /* Set up iterator IT from `composition' property at its current
3345 position. Called from handle_stop. */
3347 static enum prop_handled
3348 handle_composition_prop (it
)
3351 Lisp_Object prop
, string
;
3352 int pos
, pos_byte
, end
;
3353 enum prop_handled handled
= HANDLED_NORMALLY
;
3355 if (STRINGP (it
->string
))
3357 pos
= IT_STRING_CHARPOS (*it
);
3358 pos_byte
= IT_STRING_BYTEPOS (*it
);
3359 string
= it
->string
;
3363 pos
= IT_CHARPOS (*it
);
3364 pos_byte
= IT_BYTEPOS (*it
);
3368 /* If there's a valid composition and point is not inside of the
3369 composition (in the case that the composition is from the current
3370 buffer), draw a glyph composed from the composition components. */
3371 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3372 && COMPOSITION_VALID_P (pos
, end
, prop
)
3373 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3375 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3379 it
->method
= next_element_from_composition
;
3381 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3382 /* For a terminal, draw only the first character of the
3384 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3385 it
->len
= (STRINGP (it
->string
)
3386 ? string_char_to_byte (it
->string
, end
)
3387 : CHAR_TO_BYTE (end
)) - pos_byte
;
3388 it
->stop_charpos
= end
;
3389 handled
= HANDLED_RETURN
;
3398 /***********************************************************************
3400 ***********************************************************************/
3402 /* The following structure is used to record overlay strings for
3403 later sorting in load_overlay_strings. */
3405 struct overlay_entry
3407 Lisp_Object overlay
;
3414 /* Set up iterator IT from overlay strings at its current position.
3415 Called from handle_stop. */
3417 static enum prop_handled
3418 handle_overlay_change (it
)
3421 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3422 return HANDLED_RECOMPUTE_PROPS
;
3424 return HANDLED_NORMALLY
;
3428 /* Set up the next overlay string for delivery by IT, if there is an
3429 overlay string to deliver. Called by set_iterator_to_next when the
3430 end of the current overlay string is reached. If there are more
3431 overlay strings to display, IT->string and
3432 IT->current.overlay_string_index are set appropriately here.
3433 Otherwise IT->string is set to nil. */
3436 next_overlay_string (it
)
3439 ++it
->current
.overlay_string_index
;
3440 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3442 /* No more overlay strings. Restore IT's settings to what
3443 they were before overlay strings were processed, and
3444 continue to deliver from current_buffer. */
3445 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3448 xassert (it
->stop_charpos
>= BEGV
3449 && it
->stop_charpos
<= it
->end_charpos
);
3451 it
->current
.overlay_string_index
= -1;
3452 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3453 it
->n_overlay_strings
= 0;
3454 it
->method
= next_element_from_buffer
;
3456 /* If we're at the end of the buffer, record that we have
3457 processed the overlay strings there already, so that
3458 next_element_from_buffer doesn't try it again. */
3459 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3460 it
->overlay_strings_at_end_processed_p
= 1;
3462 /* If we have to display `...' for invisible text, set
3463 the iterator up for that. */
3464 if (display_ellipsis_p
)
3465 setup_for_ellipsis (it
);
3469 /* There are more overlay strings to process. If
3470 IT->current.overlay_string_index has advanced to a position
3471 where we must load IT->overlay_strings with more strings, do
3473 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3475 if (it
->current
.overlay_string_index
&& i
== 0)
3476 load_overlay_strings (it
, 0);
3478 /* Initialize IT to deliver display elements from the overlay
3480 it
->string
= it
->overlay_strings
[i
];
3481 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3482 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3483 it
->method
= next_element_from_string
;
3484 it
->stop_charpos
= 0;
3491 /* Compare two overlay_entry structures E1 and E2. Used as a
3492 comparison function for qsort in load_overlay_strings. Overlay
3493 strings for the same position are sorted so that
3495 1. All after-strings come in front of before-strings, except
3496 when they come from the same overlay.
3498 2. Within after-strings, strings are sorted so that overlay strings
3499 from overlays with higher priorities come first.
3501 2. Within before-strings, strings are sorted so that overlay
3502 strings from overlays with higher priorities come last.
3504 Value is analogous to strcmp. */
3508 compare_overlay_entries (e1
, e2
)
3511 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3512 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3515 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3517 /* Let after-strings appear in front of before-strings if
3518 they come from different overlays. */
3519 if (EQ (entry1
->overlay
, entry2
->overlay
))
3520 result
= entry1
->after_string_p
? 1 : -1;
3522 result
= entry1
->after_string_p
? -1 : 1;
3524 else if (entry1
->after_string_p
)
3525 /* After-strings sorted in order of decreasing priority. */
3526 result
= entry2
->priority
- entry1
->priority
;
3528 /* Before-strings sorted in order of increasing priority. */
3529 result
= entry1
->priority
- entry2
->priority
;
3535 /* Load the vector IT->overlay_strings with overlay strings from IT's
3536 current buffer position, or from CHARPOS if that is > 0. Set
3537 IT->n_overlays to the total number of overlay strings found.
3539 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3540 a time. On entry into load_overlay_strings,
3541 IT->current.overlay_string_index gives the number of overlay
3542 strings that have already been loaded by previous calls to this
3545 IT->add_overlay_start contains an additional overlay start
3546 position to consider for taking overlay strings from, if non-zero.
3547 This position comes into play when the overlay has an `invisible'
3548 property, and both before and after-strings. When we've skipped to
3549 the end of the overlay, because of its `invisible' property, we
3550 nevertheless want its before-string to appear.
3551 IT->add_overlay_start will contain the overlay start position
3554 Overlay strings are sorted so that after-string strings come in
3555 front of before-string strings. Within before and after-strings,
3556 strings are sorted by overlay priority. See also function
3557 compare_overlay_entries. */
3560 load_overlay_strings (it
, charpos
)
3564 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3565 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3568 int n
= 0, i
, j
, invis_p
;
3569 struct overlay_entry
*entries
3570 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3573 charpos
= IT_CHARPOS (*it
);
3575 /* Append the overlay string STRING of overlay OVERLAY to vector
3576 `entries' which has size `size' and currently contains `n'
3577 elements. AFTER_P non-zero means STRING is an after-string of
3579 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3582 Lisp_Object priority; \
3586 int new_size = 2 * size; \
3587 struct overlay_entry *old = entries; \
3589 (struct overlay_entry *) alloca (new_size \
3590 * sizeof *entries); \
3591 bcopy (old, entries, size * sizeof *entries); \
3595 entries[n].string = (STRING); \
3596 entries[n].overlay = (OVERLAY); \
3597 priority = Foverlay_get ((OVERLAY), Qpriority); \
3598 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3599 entries[n].after_string_p = (AFTER_P); \
3604 /* Process overlay before the overlay center. */
3605 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3607 overlay
= XCAR (ov
);
3608 xassert (OVERLAYP (overlay
));
3609 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3610 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3615 /* Skip this overlay if it doesn't start or end at IT's current
3617 if (end
!= charpos
&& start
!= charpos
)
3620 /* Skip this overlay if it doesn't apply to IT->w. */
3621 window
= Foverlay_get (overlay
, Qwindow
);
3622 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3625 /* If the text ``under'' the overlay is invisible, both before-
3626 and after-strings from this overlay are visible; start and
3627 end position are indistinguishable. */
3628 invisible
= Foverlay_get (overlay
, Qinvisible
);
3629 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3631 /* If overlay has a non-empty before-string, record it. */
3632 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3633 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3635 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3637 /* If overlay has a non-empty after-string, record it. */
3638 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3639 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3641 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3644 /* Process overlays after the overlay center. */
3645 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3647 overlay
= XCAR (ov
);
3648 xassert (OVERLAYP (overlay
));
3649 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3650 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3652 if (start
> charpos
)
3655 /* Skip this overlay if it doesn't start or end at IT's current
3657 if (end
!= charpos
&& start
!= charpos
)
3660 /* Skip this overlay if it doesn't apply to IT->w. */
3661 window
= Foverlay_get (overlay
, Qwindow
);
3662 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3665 /* If the text ``under'' the overlay is invisible, it has a zero
3666 dimension, and both before- and after-strings apply. */
3667 invisible
= Foverlay_get (overlay
, Qinvisible
);
3668 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3670 /* If overlay has a non-empty before-string, record it. */
3671 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3672 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3674 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3676 /* If overlay has a non-empty after-string, record it. */
3677 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3678 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3680 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3683 #undef RECORD_OVERLAY_STRING
3687 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3689 /* Record the total number of strings to process. */
3690 it
->n_overlay_strings
= n
;
3692 /* IT->current.overlay_string_index is the number of overlay strings
3693 that have already been consumed by IT. Copy some of the
3694 remaining overlay strings to IT->overlay_strings. */
3696 j
= it
->current
.overlay_string_index
;
3697 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3698 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3704 /* Get the first chunk of overlay strings at IT's current buffer
3705 position, or at CHARPOS if that is > 0. Value is non-zero if at
3706 least one overlay string was found. */
3709 get_overlay_strings (it
, charpos
)
3713 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3714 process. This fills IT->overlay_strings with strings, and sets
3715 IT->n_overlay_strings to the total number of strings to process.
3716 IT->pos.overlay_string_index has to be set temporarily to zero
3717 because load_overlay_strings needs this; it must be set to -1
3718 when no overlay strings are found because a zero value would
3719 indicate a position in the first overlay string. */
3720 it
->current
.overlay_string_index
= 0;
3721 load_overlay_strings (it
, charpos
);
3723 /* If we found overlay strings, set up IT to deliver display
3724 elements from the first one. Otherwise set up IT to deliver
3725 from current_buffer. */
3726 if (it
->n_overlay_strings
)
3728 /* Make sure we know settings in current_buffer, so that we can
3729 restore meaningful values when we're done with the overlay
3731 compute_stop_pos (it
);
3732 xassert (it
->face_id
>= 0);
3734 /* Save IT's settings. They are restored after all overlay
3735 strings have been processed. */
3736 xassert (it
->sp
== 0);
3739 /* Set up IT to deliver display elements from the first overlay
3741 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3742 it
->string
= it
->overlay_strings
[0];
3743 it
->stop_charpos
= 0;
3744 xassert (STRINGP (it
->string
));
3745 it
->end_charpos
= SCHARS (it
->string
);
3746 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3747 it
->method
= next_element_from_string
;
3752 it
->current
.overlay_string_index
= -1;
3753 it
->method
= next_element_from_buffer
;
3758 /* Value is non-zero if we found at least one overlay string. */
3759 return STRINGP (it
->string
);
3764 /***********************************************************************
3765 Saving and restoring state
3766 ***********************************************************************/
3768 /* Save current settings of IT on IT->stack. Called, for example,
3769 before setting up IT for an overlay string, to be able to restore
3770 IT's settings to what they were after the overlay string has been
3777 struct iterator_stack_entry
*p
;
3779 xassert (it
->sp
< 2);
3780 p
= it
->stack
+ it
->sp
;
3782 p
->stop_charpos
= it
->stop_charpos
;
3783 xassert (it
->face_id
>= 0);
3784 p
->face_id
= it
->face_id
;
3785 p
->string
= it
->string
;
3786 p
->pos
= it
->current
;
3787 p
->end_charpos
= it
->end_charpos
;
3788 p
->string_nchars
= it
->string_nchars
;
3790 p
->multibyte_p
= it
->multibyte_p
;
3791 p
->space_width
= it
->space_width
;
3792 p
->font_height
= it
->font_height
;
3793 p
->voffset
= it
->voffset
;
3794 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3795 p
->display_ellipsis_p
= 0;
3800 /* Restore IT's settings from IT->stack. Called, for example, when no
3801 more overlay strings must be processed, and we return to delivering
3802 display elements from a buffer, or when the end of a string from a
3803 `display' property is reached and we return to delivering display
3804 elements from an overlay string, or from a buffer. */
3810 struct iterator_stack_entry
*p
;
3812 xassert (it
->sp
> 0);
3814 p
= it
->stack
+ it
->sp
;
3815 it
->stop_charpos
= p
->stop_charpos
;
3816 it
->face_id
= p
->face_id
;
3817 it
->string
= p
->string
;
3818 it
->current
= p
->pos
;
3819 it
->end_charpos
= p
->end_charpos
;
3820 it
->string_nchars
= p
->string_nchars
;
3822 it
->multibyte_p
= p
->multibyte_p
;
3823 it
->space_width
= p
->space_width
;
3824 it
->font_height
= p
->font_height
;
3825 it
->voffset
= p
->voffset
;
3826 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3831 /***********************************************************************
3833 ***********************************************************************/
3835 /* Set IT's current position to the previous line start. */
3838 back_to_previous_line_start (it
)
3841 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3842 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3846 /* Move IT to the next line start.
3848 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3849 we skipped over part of the text (as opposed to moving the iterator
3850 continuously over the text). Otherwise, don't change the value
3853 Newlines may come from buffer text, overlay strings, or strings
3854 displayed via the `display' property. That's the reason we can't
3855 simply use find_next_newline_no_quit.
3857 Note that this function may not skip over invisible text that is so
3858 because of text properties and immediately follows a newline. If
3859 it would, function reseat_at_next_visible_line_start, when called
3860 from set_iterator_to_next, would effectively make invisible
3861 characters following a newline part of the wrong glyph row, which
3862 leads to wrong cursor motion. */
3865 forward_to_next_line_start (it
, skipped_p
)
3869 int old_selective
, newline_found_p
, n
;
3870 const int MAX_NEWLINE_DISTANCE
= 500;
3872 /* If already on a newline, just consume it to avoid unintended
3873 skipping over invisible text below. */
3874 if (it
->what
== IT_CHARACTER
3876 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3878 set_iterator_to_next (it
, 0);
3883 /* Don't handle selective display in the following. It's (a)
3884 unnecessary because it's done by the caller, and (b) leads to an
3885 infinite recursion because next_element_from_ellipsis indirectly
3886 calls this function. */
3887 old_selective
= it
->selective
;
3890 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3891 from buffer text. */
3892 for (n
= newline_found_p
= 0;
3893 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3894 n
+= STRINGP (it
->string
) ? 0 : 1)
3896 if (!get_next_display_element (it
))
3898 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3899 set_iterator_to_next (it
, 0);
3902 /* If we didn't find a newline near enough, see if we can use a
3904 if (!newline_found_p
)
3906 int start
= IT_CHARPOS (*it
);
3907 int limit
= find_next_newline_no_quit (start
, 1);
3910 xassert (!STRINGP (it
->string
));
3912 /* If there isn't any `display' property in sight, and no
3913 overlays, we can just use the position of the newline in
3915 if (it
->stop_charpos
>= limit
3916 || ((pos
= Fnext_single_property_change (make_number (start
),
3918 Qnil
, make_number (limit
)),
3920 && next_overlay_change (start
) == ZV
))
3922 IT_CHARPOS (*it
) = limit
;
3923 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3924 *skipped_p
= newline_found_p
= 1;
3928 while (get_next_display_element (it
)
3929 && !newline_found_p
)
3931 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3932 set_iterator_to_next (it
, 0);
3937 it
->selective
= old_selective
;
3938 return newline_found_p
;
3942 /* Set IT's current position to the previous visible line start. Skip
3943 invisible text that is so either due to text properties or due to
3944 selective display. Caution: this does not change IT->current_x and
3948 back_to_previous_visible_line_start (it
)
3953 /* Go back one newline if not on BEGV already. */
3954 if (IT_CHARPOS (*it
) > BEGV
)
3955 back_to_previous_line_start (it
);
3957 /* Move over lines that are invisible because of selective display
3958 or text properties. */
3959 while (IT_CHARPOS (*it
) > BEGV
3964 /* If selective > 0, then lines indented more than that values
3966 if (it
->selective
> 0
3967 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3968 (double) it
->selective
)) /* iftc */
3974 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3975 Qinvisible
, it
->window
);
3976 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3980 /* Back one more newline if the current one is invisible. */
3982 back_to_previous_line_start (it
);
3985 xassert (IT_CHARPOS (*it
) >= BEGV
);
3986 xassert (IT_CHARPOS (*it
) == BEGV
3987 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3992 /* Reseat iterator IT at the previous visible line start. Skip
3993 invisible text that is so either due to text properties or due to
3994 selective display. At the end, update IT's overlay information,
3995 face information etc. */
3998 reseat_at_previous_visible_line_start (it
)
4001 back_to_previous_visible_line_start (it
);
4002 reseat (it
, it
->current
.pos
, 1);
4007 /* Reseat iterator IT on the next visible line start in the current
4008 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4009 preceding the line start. Skip over invisible text that is so
4010 because of selective display. Compute faces, overlays etc at the
4011 new position. Note that this function does not skip over text that
4012 is invisible because of text properties. */
4015 reseat_at_next_visible_line_start (it
, on_newline_p
)
4019 int newline_found_p
, skipped_p
= 0;
4021 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4023 /* Skip over lines that are invisible because they are indented
4024 more than the value of IT->selective. */
4025 if (it
->selective
> 0)
4026 while (IT_CHARPOS (*it
) < ZV
4027 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4028 (double) it
->selective
)) /* iftc */
4030 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4031 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4034 /* Position on the newline if that's what's requested. */
4035 if (on_newline_p
&& newline_found_p
)
4037 if (STRINGP (it
->string
))
4039 if (IT_STRING_CHARPOS (*it
) > 0)
4041 --IT_STRING_CHARPOS (*it
);
4042 --IT_STRING_BYTEPOS (*it
);
4045 else if (IT_CHARPOS (*it
) > BEGV
)
4049 reseat (it
, it
->current
.pos
, 0);
4053 reseat (it
, it
->current
.pos
, 0);
4060 /***********************************************************************
4061 Changing an iterator's position
4062 ***********************************************************************/
4064 /* Change IT's current position to POS in current_buffer. If FORCE_P
4065 is non-zero, always check for text properties at the new position.
4066 Otherwise, text properties are only looked up if POS >=
4067 IT->check_charpos of a property. */
4070 reseat (it
, pos
, force_p
)
4072 struct text_pos pos
;
4075 int original_pos
= IT_CHARPOS (*it
);
4077 reseat_1 (it
, pos
, 0);
4079 /* Determine where to check text properties. Avoid doing it
4080 where possible because text property lookup is very expensive. */
4082 || CHARPOS (pos
) > it
->stop_charpos
4083 || CHARPOS (pos
) < original_pos
)
4090 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4091 IT->stop_pos to POS, also. */
4094 reseat_1 (it
, pos
, set_stop_p
)
4096 struct text_pos pos
;
4099 /* Don't call this function when scanning a C string. */
4100 xassert (it
->s
== NULL
);
4102 /* POS must be a reasonable value. */
4103 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4105 it
->current
.pos
= it
->position
= pos
;
4106 XSETBUFFER (it
->object
, current_buffer
);
4107 it
->end_charpos
= ZV
;
4109 it
->current
.dpvec_index
= -1;
4110 it
->current
.overlay_string_index
= -1;
4111 IT_STRING_CHARPOS (*it
) = -1;
4112 IT_STRING_BYTEPOS (*it
) = -1;
4114 it
->method
= next_element_from_buffer
;
4115 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4117 it
->face_before_selective_p
= 0;
4120 it
->stop_charpos
= CHARPOS (pos
);
4124 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4125 If S is non-null, it is a C string to iterate over. Otherwise,
4126 STRING gives a Lisp string to iterate over.
4128 If PRECISION > 0, don't return more then PRECISION number of
4129 characters from the string.
4131 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4132 characters have been returned. FIELD_WIDTH < 0 means an infinite
4135 MULTIBYTE = 0 means disable processing of multibyte characters,
4136 MULTIBYTE > 0 means enable it,
4137 MULTIBYTE < 0 means use IT->multibyte_p.
4139 IT must be initialized via a prior call to init_iterator before
4140 calling this function. */
4143 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4148 int precision
, field_width
, multibyte
;
4150 /* No region in strings. */
4151 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4153 /* No text property checks performed by default, but see below. */
4154 it
->stop_charpos
= -1;
4156 /* Set iterator position and end position. */
4157 bzero (&it
->current
, sizeof it
->current
);
4158 it
->current
.overlay_string_index
= -1;
4159 it
->current
.dpvec_index
= -1;
4160 xassert (charpos
>= 0);
4162 /* If STRING is specified, use its multibyteness, otherwise use the
4163 setting of MULTIBYTE, if specified. */
4165 it
->multibyte_p
= multibyte
> 0;
4169 xassert (STRINGP (string
));
4170 it
->string
= string
;
4172 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4173 it
->method
= next_element_from_string
;
4174 it
->current
.string_pos
= string_pos (charpos
, string
);
4181 /* Note that we use IT->current.pos, not it->current.string_pos,
4182 for displaying C strings. */
4183 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4184 if (it
->multibyte_p
)
4186 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4187 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4191 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4192 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4195 it
->method
= next_element_from_c_string
;
4198 /* PRECISION > 0 means don't return more than PRECISION characters
4200 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4201 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4203 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4204 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4205 FIELD_WIDTH < 0 means infinite field width. This is useful for
4206 padding with `-' at the end of a mode line. */
4207 if (field_width
< 0)
4208 field_width
= INFINITY
;
4209 if (field_width
> it
->end_charpos
- charpos
)
4210 it
->end_charpos
= charpos
+ field_width
;
4212 /* Use the standard display table for displaying strings. */
4213 if (DISP_TABLE_P (Vstandard_display_table
))
4214 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4216 it
->stop_charpos
= charpos
;
4222 /***********************************************************************
4224 ***********************************************************************/
4226 /* Load IT's display element fields with information about the next
4227 display element from the current position of IT. Value is zero if
4228 end of buffer (or C string) is reached. */
4231 get_next_display_element (it
)
4234 /* Non-zero means that we found a display element. Zero means that
4235 we hit the end of what we iterate over. Performance note: the
4236 function pointer `method' used here turns out to be faster than
4237 using a sequence of if-statements. */
4238 int success_p
= (*it
->method
) (it
);
4240 if (it
->what
== IT_CHARACTER
)
4242 /* Map via display table or translate control characters.
4243 IT->c, IT->len etc. have been set to the next character by
4244 the function call above. If we have a display table, and it
4245 contains an entry for IT->c, translate it. Don't do this if
4246 IT->c itself comes from a display table, otherwise we could
4247 end up in an infinite recursion. (An alternative could be to
4248 count the recursion depth of this function and signal an
4249 error when a certain maximum depth is reached.) Is it worth
4251 if (success_p
&& it
->dpvec
== NULL
)
4256 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4259 struct Lisp_Vector
*v
= XVECTOR (dv
);
4261 /* Return the first character from the display table
4262 entry, if not empty. If empty, don't display the
4263 current character. */
4266 it
->dpvec_char_len
= it
->len
;
4267 it
->dpvec
= v
->contents
;
4268 it
->dpend
= v
->contents
+ v
->size
;
4269 it
->current
.dpvec_index
= 0;
4270 it
->method
= next_element_from_display_vector
;
4271 success_p
= get_next_display_element (it
);
4275 set_iterator_to_next (it
, 0);
4276 success_p
= get_next_display_element (it
);
4280 /* Translate control characters into `\003' or `^C' form.
4281 Control characters coming from a display table entry are
4282 currently not translated because we use IT->dpvec to hold
4283 the translation. This could easily be changed but I
4284 don't believe that it is worth doing.
4286 If it->multibyte_p is nonzero, eight-bit characters and
4287 non-printable multibyte characters are also translated to
4290 If it->multibyte_p is zero, eight-bit characters that
4291 don't have corresponding multibyte char code are also
4292 translated to octal form. */
4293 else if ((it
->c
< ' '
4294 && (it
->area
!= TEXT_AREA
4295 || (it
->c
!= '\n' && it
->c
!= '\t')))
4299 || !CHAR_PRINTABLE_P (it
->c
))
4301 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4303 /* IT->c is a control character which must be displayed
4304 either as '\003' or as `^C' where the '\\' and '^'
4305 can be defined in the display table. Fill
4306 IT->ctl_chars with glyphs for what we have to
4307 display. Then, set IT->dpvec to these glyphs. */
4310 if (it
->c
< 128 && it
->ctl_arrow_p
)
4312 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4314 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4315 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4316 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4318 g
= FAST_MAKE_GLYPH ('^', 0);
4319 XSETINT (it
->ctl_chars
[0], g
);
4321 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4322 XSETINT (it
->ctl_chars
[1], g
);
4324 /* Set up IT->dpvec and return first character from it. */
4325 it
->dpvec_char_len
= it
->len
;
4326 it
->dpvec
= it
->ctl_chars
;
4327 it
->dpend
= it
->dpvec
+ 2;
4328 it
->current
.dpvec_index
= 0;
4329 it
->method
= next_element_from_display_vector
;
4330 get_next_display_element (it
);
4334 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4339 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4341 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4342 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4343 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4345 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4347 if (SINGLE_BYTE_CHAR_P (it
->c
))
4348 str
[0] = it
->c
, len
= 1;
4351 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4354 /* It's an invalid character, which
4355 shouldn't happen actually, but due to
4356 bugs it may happen. Let's print the char
4357 as is, there's not much meaningful we can
4360 str
[1] = it
->c
>> 8;
4361 str
[2] = it
->c
>> 16;
4362 str
[3] = it
->c
>> 24;
4367 for (i
= 0; i
< len
; i
++)
4369 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4370 /* Insert three more glyphs into IT->ctl_chars for
4371 the octal display of the character. */
4372 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4373 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4374 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4375 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4376 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4377 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4380 /* Set up IT->dpvec and return the first character
4382 it
->dpvec_char_len
= it
->len
;
4383 it
->dpvec
= it
->ctl_chars
;
4384 it
->dpend
= it
->dpvec
+ len
* 4;
4385 it
->current
.dpvec_index
= 0;
4386 it
->method
= next_element_from_display_vector
;
4387 get_next_display_element (it
);
4392 /* Adjust face id for a multibyte character. There are no
4393 multibyte character in unibyte text. */
4396 && FRAME_WINDOW_P (it
->f
))
4398 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4399 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4403 /* Is this character the last one of a run of characters with
4404 box? If yes, set IT->end_of_box_run_p to 1. */
4411 it
->end_of_box_run_p
4412 = ((face_id
= face_after_it_pos (it
),
4413 face_id
!= it
->face_id
)
4414 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4415 face
->box
== FACE_NO_BOX
));
4418 /* Value is 0 if end of buffer or string reached. */
4423 /* Move IT to the next display element.
4425 RESEAT_P non-zero means if called on a newline in buffer text,
4426 skip to the next visible line start.
4428 Functions get_next_display_element and set_iterator_to_next are
4429 separate because I find this arrangement easier to handle than a
4430 get_next_display_element function that also increments IT's
4431 position. The way it is we can first look at an iterator's current
4432 display element, decide whether it fits on a line, and if it does,
4433 increment the iterator position. The other way around we probably
4434 would either need a flag indicating whether the iterator has to be
4435 incremented the next time, or we would have to implement a
4436 decrement position function which would not be easy to write. */
4439 set_iterator_to_next (it
, reseat_p
)
4443 /* Reset flags indicating start and end of a sequence of characters
4444 with box. Reset them at the start of this function because
4445 moving the iterator to a new position might set them. */
4446 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4448 if (it
->method
== next_element_from_buffer
)
4450 /* The current display element of IT is a character from
4451 current_buffer. Advance in the buffer, and maybe skip over
4452 invisible lines that are so because of selective display. */
4453 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4454 reseat_at_next_visible_line_start (it
, 0);
4457 xassert (it
->len
!= 0);
4458 IT_BYTEPOS (*it
) += it
->len
;
4459 IT_CHARPOS (*it
) += 1;
4460 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4463 else if (it
->method
== next_element_from_composition
)
4465 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4466 if (STRINGP (it
->string
))
4468 IT_STRING_BYTEPOS (*it
) += it
->len
;
4469 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4470 it
->method
= next_element_from_string
;
4471 goto consider_string_end
;
4475 IT_BYTEPOS (*it
) += it
->len
;
4476 IT_CHARPOS (*it
) += it
->cmp_len
;
4477 it
->method
= next_element_from_buffer
;
4480 else if (it
->method
== next_element_from_c_string
)
4482 /* Current display element of IT is from a C string. */
4483 IT_BYTEPOS (*it
) += it
->len
;
4484 IT_CHARPOS (*it
) += 1;
4486 else if (it
->method
== next_element_from_display_vector
)
4488 /* Current display element of IT is from a display table entry.
4489 Advance in the display table definition. Reset it to null if
4490 end reached, and continue with characters from buffers/
4492 ++it
->current
.dpvec_index
;
4494 /* Restore face of the iterator to what they were before the
4495 display vector entry (these entries may contain faces). */
4496 it
->face_id
= it
->saved_face_id
;
4498 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4501 it
->method
= next_element_from_c_string
;
4502 else if (STRINGP (it
->string
))
4503 it
->method
= next_element_from_string
;
4505 it
->method
= next_element_from_buffer
;
4508 it
->current
.dpvec_index
= -1;
4510 /* Skip over characters which were displayed via IT->dpvec. */
4511 if (it
->dpvec_char_len
< 0)
4512 reseat_at_next_visible_line_start (it
, 1);
4513 else if (it
->dpvec_char_len
> 0)
4515 it
->len
= it
->dpvec_char_len
;
4516 set_iterator_to_next (it
, reseat_p
);
4520 else if (it
->method
== next_element_from_string
)
4522 /* Current display element is a character from a Lisp string. */
4523 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4524 IT_STRING_BYTEPOS (*it
) += it
->len
;
4525 IT_STRING_CHARPOS (*it
) += 1;
4527 consider_string_end
:
4529 if (it
->current
.overlay_string_index
>= 0)
4531 /* IT->string is an overlay string. Advance to the
4532 next, if there is one. */
4533 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4534 next_overlay_string (it
);
4538 /* IT->string is not an overlay string. If we reached
4539 its end, and there is something on IT->stack, proceed
4540 with what is on the stack. This can be either another
4541 string, this time an overlay string, or a buffer. */
4542 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
4546 if (!STRINGP (it
->string
))
4547 it
->method
= next_element_from_buffer
;
4549 goto consider_string_end
;
4553 else if (it
->method
== next_element_from_image
4554 || it
->method
== next_element_from_stretch
)
4556 /* The position etc with which we have to proceed are on
4557 the stack. The position may be at the end of a string,
4558 if the `display' property takes up the whole string. */
4561 if (STRINGP (it
->string
))
4563 it
->method
= next_element_from_string
;
4564 goto consider_string_end
;
4567 it
->method
= next_element_from_buffer
;
4570 /* There are no other methods defined, so this should be a bug. */
4573 xassert (it
->method
!= next_element_from_string
4574 || (STRINGP (it
->string
)
4575 && IT_STRING_CHARPOS (*it
) >= 0));
4579 /* Load IT's display element fields with information about the next
4580 display element which comes from a display table entry or from the
4581 result of translating a control character to one of the forms `^C'
4582 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4585 next_element_from_display_vector (it
)
4589 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4591 /* Remember the current face id in case glyphs specify faces.
4592 IT's face is restored in set_iterator_to_next. */
4593 it
->saved_face_id
= it
->face_id
;
4595 if (INTEGERP (*it
->dpvec
)
4596 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4601 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4602 it
->c
= FAST_GLYPH_CHAR (g
);
4603 it
->len
= CHAR_BYTES (it
->c
);
4605 /* The entry may contain a face id to use. Such a face id is
4606 the id of a Lisp face, not a realized face. A face id of
4607 zero means no face is specified. */
4608 lface_id
= FAST_GLYPH_FACE (g
);
4611 /* The function returns -1 if lface_id is invalid. */
4612 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4614 it
->face_id
= face_id
;
4618 /* Display table entry is invalid. Return a space. */
4619 it
->c
= ' ', it
->len
= 1;
4621 /* Don't change position and object of the iterator here. They are
4622 still the values of the character that had this display table
4623 entry or was translated, and that's what we want. */
4624 it
->what
= IT_CHARACTER
;
4629 /* Load IT with the next display element from Lisp string IT->string.
4630 IT->current.string_pos is the current position within the string.
4631 If IT->current.overlay_string_index >= 0, the Lisp string is an
4635 next_element_from_string (it
)
4638 struct text_pos position
;
4640 xassert (STRINGP (it
->string
));
4641 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4642 position
= it
->current
.string_pos
;
4644 /* Time to check for invisible text? */
4645 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4646 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4650 /* Since a handler may have changed IT->method, we must
4652 return get_next_display_element (it
);
4655 if (it
->current
.overlay_string_index
>= 0)
4657 /* Get the next character from an overlay string. In overlay
4658 strings, There is no field width or padding with spaces to
4660 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4665 else if (STRING_MULTIBYTE (it
->string
))
4667 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4668 const unsigned char *s
= (SDATA (it
->string
)
4669 + IT_STRING_BYTEPOS (*it
));
4670 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4674 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4680 /* Get the next character from a Lisp string that is not an
4681 overlay string. Such strings come from the mode line, for
4682 example. We may have to pad with spaces, or truncate the
4683 string. See also next_element_from_c_string. */
4684 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4689 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4691 /* Pad with spaces. */
4692 it
->c
= ' ', it
->len
= 1;
4693 CHARPOS (position
) = BYTEPOS (position
) = -1;
4695 else if (STRING_MULTIBYTE (it
->string
))
4697 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4698 const unsigned char *s
= (SDATA (it
->string
)
4699 + IT_STRING_BYTEPOS (*it
));
4700 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4704 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4709 /* Record what we have and where it came from. Note that we store a
4710 buffer position in IT->position although it could arguably be a
4712 it
->what
= IT_CHARACTER
;
4713 it
->object
= it
->string
;
4714 it
->position
= position
;
4719 /* Load IT with next display element from C string IT->s.
4720 IT->string_nchars is the maximum number of characters to return
4721 from the string. IT->end_charpos may be greater than
4722 IT->string_nchars when this function is called, in which case we
4723 may have to return padding spaces. Value is zero if end of string
4724 reached, including padding spaces. */
4727 next_element_from_c_string (it
)
4733 it
->what
= IT_CHARACTER
;
4734 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4737 /* IT's position can be greater IT->string_nchars in case a field
4738 width or precision has been specified when the iterator was
4740 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4742 /* End of the game. */
4746 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4748 /* Pad with spaces. */
4749 it
->c
= ' ', it
->len
= 1;
4750 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4752 else if (it
->multibyte_p
)
4754 /* Implementation note: The calls to strlen apparently aren't a
4755 performance problem because there is no noticeable performance
4756 difference between Emacs running in unibyte or multibyte mode. */
4757 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4758 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4762 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4768 /* Set up IT to return characters from an ellipsis, if appropriate.
4769 The definition of the ellipsis glyphs may come from a display table
4770 entry. This function Fills IT with the first glyph from the
4771 ellipsis if an ellipsis is to be displayed. */
4774 next_element_from_ellipsis (it
)
4777 if (it
->selective_display_ellipsis_p
)
4779 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4781 /* Use the display table definition for `...'. Invalid glyphs
4782 will be handled by the method returning elements from dpvec. */
4783 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4784 it
->dpvec_char_len
= it
->len
;
4785 it
->dpvec
= v
->contents
;
4786 it
->dpend
= v
->contents
+ v
->size
;
4787 it
->current
.dpvec_index
= 0;
4788 it
->method
= next_element_from_display_vector
;
4792 /* Use default `...' which is stored in default_invis_vector. */
4793 it
->dpvec_char_len
= it
->len
;
4794 it
->dpvec
= default_invis_vector
;
4795 it
->dpend
= default_invis_vector
+ 3;
4796 it
->current
.dpvec_index
= 0;
4797 it
->method
= next_element_from_display_vector
;
4802 /* The face at the current position may be different from the
4803 face we find after the invisible text. Remember what it
4804 was in IT->saved_face_id, and signal that it's there by
4805 setting face_before_selective_p. */
4806 it
->saved_face_id
= it
->face_id
;
4807 it
->method
= next_element_from_buffer
;
4808 reseat_at_next_visible_line_start (it
, 1);
4809 it
->face_before_selective_p
= 1;
4812 return get_next_display_element (it
);
4816 /* Deliver an image display element. The iterator IT is already
4817 filled with image information (done in handle_display_prop). Value
4822 next_element_from_image (it
)
4825 it
->what
= IT_IMAGE
;
4830 /* Fill iterator IT with next display element from a stretch glyph
4831 property. IT->object is the value of the text property. Value is
4835 next_element_from_stretch (it
)
4838 it
->what
= IT_STRETCH
;
4843 /* Load IT with the next display element from current_buffer. Value
4844 is zero if end of buffer reached. IT->stop_charpos is the next
4845 position at which to stop and check for text properties or buffer
4849 next_element_from_buffer (it
)
4854 /* Check this assumption, otherwise, we would never enter the
4855 if-statement, below. */
4856 xassert (IT_CHARPOS (*it
) >= BEGV
4857 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4859 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4861 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4863 int overlay_strings_follow_p
;
4865 /* End of the game, except when overlay strings follow that
4866 haven't been returned yet. */
4867 if (it
->overlay_strings_at_end_processed_p
)
4868 overlay_strings_follow_p
= 0;
4871 it
->overlay_strings_at_end_processed_p
= 1;
4872 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4875 if (overlay_strings_follow_p
)
4876 success_p
= get_next_display_element (it
);
4880 it
->position
= it
->current
.pos
;
4887 return get_next_display_element (it
);
4892 /* No face changes, overlays etc. in sight, so just return a
4893 character from current_buffer. */
4896 /* Maybe run the redisplay end trigger hook. Performance note:
4897 This doesn't seem to cost measurable time. */
4898 if (it
->redisplay_end_trigger_charpos
4900 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4901 run_redisplay_end_trigger_hook (it
);
4903 /* Get the next character, maybe multibyte. */
4904 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4905 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4907 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4908 - IT_BYTEPOS (*it
));
4909 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4912 it
->c
= *p
, it
->len
= 1;
4914 /* Record what we have and where it came from. */
4915 it
->what
= IT_CHARACTER
;;
4916 it
->object
= it
->w
->buffer
;
4917 it
->position
= it
->current
.pos
;
4919 /* Normally we return the character found above, except when we
4920 really want to return an ellipsis for selective display. */
4925 /* A value of selective > 0 means hide lines indented more
4926 than that number of columns. */
4927 if (it
->selective
> 0
4928 && IT_CHARPOS (*it
) + 1 < ZV
4929 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4930 IT_BYTEPOS (*it
) + 1,
4931 (double) it
->selective
)) /* iftc */
4933 success_p
= next_element_from_ellipsis (it
);
4934 it
->dpvec_char_len
= -1;
4937 else if (it
->c
== '\r' && it
->selective
== -1)
4939 /* A value of selective == -1 means that everything from the
4940 CR to the end of the line is invisible, with maybe an
4941 ellipsis displayed for it. */
4942 success_p
= next_element_from_ellipsis (it
);
4943 it
->dpvec_char_len
= -1;
4948 /* Value is zero if end of buffer reached. */
4949 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4954 /* Run the redisplay end trigger hook for IT. */
4957 run_redisplay_end_trigger_hook (it
)
4960 Lisp_Object args
[3];
4962 /* IT->glyph_row should be non-null, i.e. we should be actually
4963 displaying something, or otherwise we should not run the hook. */
4964 xassert (it
->glyph_row
);
4966 /* Set up hook arguments. */
4967 args
[0] = Qredisplay_end_trigger_functions
;
4968 args
[1] = it
->window
;
4969 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4970 it
->redisplay_end_trigger_charpos
= 0;
4972 /* Since we are *trying* to run these functions, don't try to run
4973 them again, even if they get an error. */
4974 it
->w
->redisplay_end_trigger
= Qnil
;
4975 Frun_hook_with_args (3, args
);
4977 /* Notice if it changed the face of the character we are on. */
4978 handle_face_prop (it
);
4982 /* Deliver a composition display element. The iterator IT is already
4983 filled with composition information (done in
4984 handle_composition_prop). Value is always 1. */
4987 next_element_from_composition (it
)
4990 it
->what
= IT_COMPOSITION
;
4991 it
->position
= (STRINGP (it
->string
)
4992 ? it
->current
.string_pos
4999 /***********************************************************************
5000 Moving an iterator without producing glyphs
5001 ***********************************************************************/
5003 /* Move iterator IT to a specified buffer or X position within one
5004 line on the display without producing glyphs.
5006 OP should be a bit mask including some or all of these bits:
5007 MOVE_TO_X: Stop on reaching x-position TO_X.
5008 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5009 Regardless of OP's value, stop in reaching the end of the display line.
5011 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5012 This means, in particular, that TO_X includes window's horizontal
5015 The return value has several possible values that
5016 say what condition caused the scan to stop:
5018 MOVE_POS_MATCH_OR_ZV
5019 - when TO_POS or ZV was reached.
5022 -when TO_X was reached before TO_POS or ZV were reached.
5025 - when we reached the end of the display area and the line must
5029 - when we reached the end of the display area and the line is
5033 - when we stopped at a line end, i.e. a newline or a CR and selective
5036 static enum move_it_result
5037 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5039 int to_charpos
, to_x
, op
;
5041 enum move_it_result result
= MOVE_UNDEFINED
;
5042 struct glyph_row
*saved_glyph_row
;
5044 /* Don't produce glyphs in produce_glyphs. */
5045 saved_glyph_row
= it
->glyph_row
;
5046 it
->glyph_row
= NULL
;
5050 int x
, i
, ascent
= 0, descent
= 0;
5052 /* Stop when ZV or TO_CHARPOS reached. */
5053 if (!get_next_display_element (it
)
5054 || ((op
& MOVE_TO_POS
) != 0
5055 && BUFFERP (it
->object
)
5056 && IT_CHARPOS (*it
) >= to_charpos
))
5058 result
= MOVE_POS_MATCH_OR_ZV
;
5062 /* The call to produce_glyphs will get the metrics of the
5063 display element IT is loaded with. We record in x the
5064 x-position before this display element in case it does not
5068 /* Remember the line height so far in case the next element doesn't
5070 if (!it
->truncate_lines_p
)
5072 ascent
= it
->max_ascent
;
5073 descent
= it
->max_descent
;
5076 PRODUCE_GLYPHS (it
);
5078 if (it
->area
!= TEXT_AREA
)
5080 set_iterator_to_next (it
, 1);
5084 /* The number of glyphs we get back in IT->nglyphs will normally
5085 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5086 character on a terminal frame, or (iii) a line end. For the
5087 second case, IT->nglyphs - 1 padding glyphs will be present
5088 (on X frames, there is only one glyph produced for a
5089 composite character.
5091 The behavior implemented below means, for continuation lines,
5092 that as many spaces of a TAB as fit on the current line are
5093 displayed there. For terminal frames, as many glyphs of a
5094 multi-glyph character are displayed in the current line, too.
5095 This is what the old redisplay code did, and we keep it that
5096 way. Under X, the whole shape of a complex character must
5097 fit on the line or it will be completely displayed in the
5100 Note that both for tabs and padding glyphs, all glyphs have
5104 /* More than one glyph or glyph doesn't fit on line. All
5105 glyphs have the same width. */
5106 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5109 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5111 new_x
= x
+ single_glyph_width
;
5113 /* We want to leave anything reaching TO_X to the caller. */
5114 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5117 result
= MOVE_X_REACHED
;
5120 else if (/* Lines are continued. */
5121 !it
->truncate_lines_p
5122 && (/* And glyph doesn't fit on the line. */
5123 new_x
> it
->last_visible_x
5124 /* Or it fits exactly and we're on a window
5126 || (new_x
== it
->last_visible_x
5127 && FRAME_WINDOW_P (it
->f
))))
5129 if (/* IT->hpos == 0 means the very first glyph
5130 doesn't fit on the line, e.g. a wide image. */
5132 || (new_x
== it
->last_visible_x
5133 && FRAME_WINDOW_P (it
->f
)))
5136 it
->current_x
= new_x
;
5137 if (i
== it
->nglyphs
- 1)
5138 set_iterator_to_next (it
, 1);
5143 it
->max_ascent
= ascent
;
5144 it
->max_descent
= descent
;
5147 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5149 result
= MOVE_LINE_CONTINUED
;
5152 else if (new_x
> it
->first_visible_x
)
5154 /* Glyph is visible. Increment number of glyphs that
5155 would be displayed. */
5160 /* Glyph is completely off the left margin of the display
5161 area. Nothing to do. */
5165 if (result
!= MOVE_UNDEFINED
)
5168 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5170 /* Stop when TO_X specified and reached. This check is
5171 necessary here because of lines consisting of a line end,
5172 only. The line end will not produce any glyphs and we
5173 would never get MOVE_X_REACHED. */
5174 xassert (it
->nglyphs
== 0);
5175 result
= MOVE_X_REACHED
;
5179 /* Is this a line end? If yes, we're done. */
5180 if (ITERATOR_AT_END_OF_LINE_P (it
))
5182 result
= MOVE_NEWLINE_OR_CR
;
5186 /* The current display element has been consumed. Advance
5188 set_iterator_to_next (it
, 1);
5190 /* Stop if lines are truncated and IT's current x-position is
5191 past the right edge of the window now. */
5192 if (it
->truncate_lines_p
5193 && it
->current_x
>= it
->last_visible_x
)
5195 result
= MOVE_LINE_TRUNCATED
;
5200 /* Restore the iterator settings altered at the beginning of this
5202 it
->glyph_row
= saved_glyph_row
;
5207 /* Move IT forward until it satisfies one or more of the criteria in
5208 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5210 OP is a bit-mask that specifies where to stop, and in particular,
5211 which of those four position arguments makes a difference. See the
5212 description of enum move_operation_enum.
5214 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5215 screen line, this function will set IT to the next position >
5219 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5221 int to_charpos
, to_x
, to_y
, to_vpos
;
5224 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5230 if (op
& MOVE_TO_VPOS
)
5232 /* If no TO_CHARPOS and no TO_X specified, stop at the
5233 start of the line TO_VPOS. */
5234 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5236 if (it
->vpos
== to_vpos
)
5242 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5246 /* TO_VPOS >= 0 means stop at TO_X in the line at
5247 TO_VPOS, or at TO_POS, whichever comes first. */
5248 if (it
->vpos
== to_vpos
)
5254 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5256 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5261 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5263 /* We have reached TO_X but not in the line we want. */
5264 skip
= move_it_in_display_line_to (it
, to_charpos
,
5266 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5274 else if (op
& MOVE_TO_Y
)
5276 struct it it_backup
;
5278 /* TO_Y specified means stop at TO_X in the line containing
5279 TO_Y---or at TO_CHARPOS if this is reached first. The
5280 problem is that we can't really tell whether the line
5281 contains TO_Y before we have completely scanned it, and
5282 this may skip past TO_X. What we do is to first scan to
5285 If TO_X is not specified, use a TO_X of zero. The reason
5286 is to make the outcome of this function more predictable.
5287 If we didn't use TO_X == 0, we would stop at the end of
5288 the line which is probably not what a caller would expect
5290 skip
= move_it_in_display_line_to (it
, to_charpos
,
5294 | (op
& MOVE_TO_POS
)));
5296 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5297 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5303 /* If TO_X was reached, we would like to know whether TO_Y
5304 is in the line. This can only be said if we know the
5305 total line height which requires us to scan the rest of
5307 if (skip
== MOVE_X_REACHED
)
5310 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5311 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5313 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5316 /* Now, decide whether TO_Y is in this line. */
5317 line_height
= it
->max_ascent
+ it
->max_descent
;
5318 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5320 if (to_y
>= it
->current_y
5321 && to_y
< it
->current_y
+ line_height
)
5323 if (skip
== MOVE_X_REACHED
)
5324 /* If TO_Y is in this line and TO_X was reached above,
5325 we scanned too far. We have to restore IT's settings
5326 to the ones before skipping. */
5330 else if (skip
== MOVE_X_REACHED
)
5333 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5341 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5345 case MOVE_POS_MATCH_OR_ZV
:
5349 case MOVE_NEWLINE_OR_CR
:
5350 set_iterator_to_next (it
, 1);
5351 it
->continuation_lines_width
= 0;
5354 case MOVE_LINE_TRUNCATED
:
5355 it
->continuation_lines_width
= 0;
5356 reseat_at_next_visible_line_start (it
, 0);
5357 if ((op
& MOVE_TO_POS
) != 0
5358 && IT_CHARPOS (*it
) > to_charpos
)
5365 case MOVE_LINE_CONTINUED
:
5366 it
->continuation_lines_width
+= it
->current_x
;
5373 /* Reset/increment for the next run. */
5374 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5375 it
->current_x
= it
->hpos
= 0;
5376 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5378 last_height
= it
->max_ascent
+ it
->max_descent
;
5379 last_max_ascent
= it
->max_ascent
;
5380 it
->max_ascent
= it
->max_descent
= 0;
5385 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5389 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5391 If DY > 0, move IT backward at least that many pixels. DY = 0
5392 means move IT backward to the preceding line start or BEGV. This
5393 function may move over more than DY pixels if IT->current_y - DY
5394 ends up in the middle of a line; in this case IT->current_y will be
5395 set to the top of the line moved to. */
5398 move_it_vertically_backward (it
, dy
)
5404 int start_pos
= IT_CHARPOS (*it
);
5408 /* Estimate how many newlines we must move back. */
5409 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5411 /* Set the iterator's position that many lines back. */
5412 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5413 back_to_previous_visible_line_start (it
);
5415 /* Reseat the iterator here. When moving backward, we don't want
5416 reseat to skip forward over invisible text, set up the iterator
5417 to deliver from overlay strings at the new position etc. So,
5418 use reseat_1 here. */
5419 reseat_1 (it
, it
->current
.pos
, 1);
5421 /* We are now surely at a line start. */
5422 it
->current_x
= it
->hpos
= 0;
5423 it
->continuation_lines_width
= 0;
5425 /* Move forward and see what y-distance we moved. First move to the
5426 start of the next line so that we get its height. We need this
5427 height to be able to tell whether we reached the specified
5430 it2
.max_ascent
= it2
.max_descent
= 0;
5431 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5432 MOVE_TO_POS
| MOVE_TO_VPOS
);
5433 xassert (IT_CHARPOS (*it
) >= BEGV
);
5436 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5437 xassert (IT_CHARPOS (*it
) >= BEGV
);
5438 h
= it2
.current_y
- it
->current_y
;
5439 nlines
= it2
.vpos
- it
->vpos
;
5441 /* Correct IT's y and vpos position. */
5447 /* DY == 0 means move to the start of the screen line. The
5448 value of nlines is > 0 if continuation lines were involved. */
5450 move_it_by_lines (it
, nlines
, 1);
5451 xassert (IT_CHARPOS (*it
) <= start_pos
);
5455 /* The y-position we try to reach. Note that h has been
5456 subtracted in front of the if-statement. */
5457 int target_y
= it
->current_y
+ h
- dy
;
5458 int y0
= it3
.current_y
;
5459 int y1
= line_bottom_y (&it3
);
5460 int line_height
= y1
- y0
;
5462 /* If we did not reach target_y, try to move further backward if
5463 we can. If we moved too far backward, try to move forward. */
5464 if (target_y
< it
->current_y
5465 /* This is heuristic. In a window that's 3 lines high, with
5466 a line height of 13 pixels each, recentering with point
5467 on the bottom line will try to move -39/2 = 19 pixels
5468 backward. Try to avoid moving into the first line. */
5469 && it
->current_y
- target_y
> line_height
/ 3 * 2
5470 && IT_CHARPOS (*it
) > BEGV
)
5472 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5473 target_y
- it
->current_y
));
5474 move_it_vertically (it
, target_y
- it
->current_y
);
5475 xassert (IT_CHARPOS (*it
) >= BEGV
);
5477 else if (target_y
>= it
->current_y
+ line_height
5478 && IT_CHARPOS (*it
) < ZV
)
5480 /* Should move forward by at least one line, maybe more.
5482 Note: Calling move_it_by_lines can be expensive on
5483 terminal frames, where compute_motion is used (via
5484 vmotion) to do the job, when there are very long lines
5485 and truncate-lines is nil. That's the reason for
5486 treating terminal frames specially here. */
5488 if (!FRAME_WINDOW_P (it
->f
))
5489 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5494 move_it_by_lines (it
, 1, 1);
5496 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5499 xassert (IT_CHARPOS (*it
) >= BEGV
);
5505 /* Move IT by a specified amount of pixel lines DY. DY negative means
5506 move backwards. DY = 0 means move to start of screen line. At the
5507 end, IT will be on the start of a screen line. */
5510 move_it_vertically (it
, dy
)
5515 move_it_vertically_backward (it
, -dy
);
5518 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5519 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5520 MOVE_TO_POS
| MOVE_TO_Y
);
5521 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5523 /* If buffer ends in ZV without a newline, move to the start of
5524 the line to satisfy the post-condition. */
5525 if (IT_CHARPOS (*it
) == ZV
5526 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5527 move_it_by_lines (it
, 0, 0);
5532 /* Move iterator IT past the end of the text line it is in. */
5535 move_it_past_eol (it
)
5538 enum move_it_result rc
;
5540 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5541 if (rc
== MOVE_NEWLINE_OR_CR
)
5542 set_iterator_to_next (it
, 0);
5546 #if 0 /* Currently not used. */
5548 /* Return non-zero if some text between buffer positions START_CHARPOS
5549 and END_CHARPOS is invisible. IT->window is the window for text
5553 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5555 int start_charpos
, end_charpos
;
5557 Lisp_Object prop
, limit
;
5558 int invisible_found_p
;
5560 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5562 /* Is text at START invisible? */
5563 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5565 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5566 invisible_found_p
= 1;
5569 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5571 make_number (end_charpos
));
5572 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5575 return invisible_found_p
;
5581 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5582 negative means move up. DVPOS == 0 means move to the start of the
5583 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5584 NEED_Y_P is zero, IT->current_y will be left unchanged.
5586 Further optimization ideas: If we would know that IT->f doesn't use
5587 a face with proportional font, we could be faster for
5588 truncate-lines nil. */
5591 move_it_by_lines (it
, dvpos
, need_y_p
)
5593 int dvpos
, need_y_p
;
5595 struct position pos
;
5597 if (!FRAME_WINDOW_P (it
->f
))
5599 struct text_pos textpos
;
5601 /* We can use vmotion on frames without proportional fonts. */
5602 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5603 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5604 reseat (it
, textpos
, 1);
5605 it
->vpos
+= pos
.vpos
;
5606 it
->current_y
+= pos
.vpos
;
5608 else if (dvpos
== 0)
5610 /* DVPOS == 0 means move to the start of the screen line. */
5611 move_it_vertically_backward (it
, 0);
5612 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5615 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5619 int start_charpos
, i
;
5621 /* Start at the beginning of the screen line containing IT's
5623 move_it_vertically_backward (it
, 0);
5625 /* Go back -DVPOS visible lines and reseat the iterator there. */
5626 start_charpos
= IT_CHARPOS (*it
);
5627 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5628 back_to_previous_visible_line_start (it
);
5629 reseat (it
, it
->current
.pos
, 1);
5630 it
->current_x
= it
->hpos
= 0;
5632 /* Above call may have moved too far if continuation lines
5633 are involved. Scan forward and see if it did. */
5635 it2
.vpos
= it2
.current_y
= 0;
5636 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5637 it
->vpos
-= it2
.vpos
;
5638 it
->current_y
-= it2
.current_y
;
5639 it
->current_x
= it
->hpos
= 0;
5641 /* If we moved too far, move IT some lines forward. */
5642 if (it2
.vpos
> -dvpos
)
5644 int delta
= it2
.vpos
+ dvpos
;
5645 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5652 /***********************************************************************
5654 ***********************************************************************/
5657 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5661 add_to_log (format
, arg1
, arg2
)
5663 Lisp_Object arg1
, arg2
;
5665 Lisp_Object args
[3];
5666 Lisp_Object msg
, fmt
;
5669 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5671 /* Do nothing if called asynchronously. Inserting text into
5672 a buffer may call after-change-functions and alike and
5673 that would means running Lisp asynchronously. */
5674 if (handling_signal
)
5678 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5680 args
[0] = fmt
= build_string (format
);
5683 msg
= Fformat (3, args
);
5685 len
= SBYTES (msg
) + 1;
5686 buffer
= (char *) alloca (len
);
5687 bcopy (SDATA (msg
), buffer
, len
);
5689 message_dolog (buffer
, len
- 1, 1, 0);
5694 /* Output a newline in the *Messages* buffer if "needs" one. */
5697 message_log_maybe_newline ()
5699 if (message_log_need_newline
)
5700 message_dolog ("", 0, 1, 0);
5704 /* Add a string M of length NBYTES to the message log, optionally
5705 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5706 nonzero, means interpret the contents of M as multibyte. This
5707 function calls low-level routines in order to bypass text property
5708 hooks, etc. which might not be safe to run. */
5711 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5713 int nbytes
, nlflag
, multibyte
;
5715 if (!NILP (Vmemory_full
))
5718 if (!NILP (Vmessage_log_max
))
5720 struct buffer
*oldbuf
;
5721 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5722 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5723 int point_at_end
= 0;
5725 Lisp_Object old_deactivate_mark
, tem
;
5726 struct gcpro gcpro1
;
5728 old_deactivate_mark
= Vdeactivate_mark
;
5729 oldbuf
= current_buffer
;
5730 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5731 current_buffer
->undo_list
= Qt
;
5733 oldpoint
= message_dolog_marker1
;
5734 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
5735 oldbegv
= message_dolog_marker2
;
5736 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
5737 oldzv
= message_dolog_marker3
;
5738 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
5739 GCPRO1 (old_deactivate_mark
);
5747 BEGV_BYTE
= BEG_BYTE
;
5750 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5752 /* Insert the string--maybe converting multibyte to single byte
5753 or vice versa, so that all the text fits the buffer. */
5755 && NILP (current_buffer
->enable_multibyte_characters
))
5757 int i
, c
, char_bytes
;
5758 unsigned char work
[1];
5760 /* Convert a multibyte string to single-byte
5761 for the *Message* buffer. */
5762 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5764 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5765 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5767 : multibyte_char_to_unibyte (c
, Qnil
));
5768 insert_1_both (work
, 1, 1, 1, 0, 0);
5771 else if (! multibyte
5772 && ! NILP (current_buffer
->enable_multibyte_characters
))
5774 int i
, c
, char_bytes
;
5775 unsigned char *msg
= (unsigned char *) m
;
5776 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5777 /* Convert a single-byte string to multibyte
5778 for the *Message* buffer. */
5779 for (i
= 0; i
< nbytes
; i
++)
5781 c
= unibyte_char_to_multibyte (msg
[i
]);
5782 char_bytes
= CHAR_STRING (c
, str
);
5783 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5787 insert_1 (m
, nbytes
, 1, 0, 0);
5791 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5792 insert_1 ("\n", 1, 1, 0, 0);
5794 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5796 this_bol_byte
= PT_BYTE
;
5798 /* See if this line duplicates the previous one.
5799 If so, combine duplicates. */
5802 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5804 prev_bol_byte
= PT_BYTE
;
5806 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5807 this_bol
, this_bol_byte
);
5810 del_range_both (prev_bol
, prev_bol_byte
,
5811 this_bol
, this_bol_byte
, 0);
5817 /* If you change this format, don't forget to also
5818 change message_log_check_duplicate. */
5819 sprintf (dupstr
, " [%d times]", dup
);
5820 duplen
= strlen (dupstr
);
5821 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5822 insert_1 (dupstr
, duplen
, 1, 0, 1);
5827 /* If we have more than the desired maximum number of lines
5828 in the *Messages* buffer now, delete the oldest ones.
5829 This is safe because we don't have undo in this buffer. */
5831 if (NATNUMP (Vmessage_log_max
))
5833 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5834 -XFASTINT (Vmessage_log_max
) - 1, 0);
5835 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5838 BEGV
= XMARKER (oldbegv
)->charpos
;
5839 BEGV_BYTE
= marker_byte_position (oldbegv
);
5848 ZV
= XMARKER (oldzv
)->charpos
;
5849 ZV_BYTE
= marker_byte_position (oldzv
);
5853 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5855 /* We can't do Fgoto_char (oldpoint) because it will run some
5857 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5858 XMARKER (oldpoint
)->bytepos
);
5861 unchain_marker (oldpoint
);
5862 unchain_marker (oldbegv
);
5863 unchain_marker (oldzv
);
5865 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5866 set_buffer_internal (oldbuf
);
5868 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5869 message_log_need_newline
= !nlflag
;
5870 Vdeactivate_mark
= old_deactivate_mark
;
5875 /* We are at the end of the buffer after just having inserted a newline.
5876 (Note: We depend on the fact we won't be crossing the gap.)
5877 Check to see if the most recent message looks a lot like the previous one.
5878 Return 0 if different, 1 if the new one should just replace it, or a
5879 value N > 1 if we should also append " [N times]". */
5882 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5883 int prev_bol
, this_bol
;
5884 int prev_bol_byte
, this_bol_byte
;
5887 int len
= Z_BYTE
- 1 - this_bol_byte
;
5889 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5890 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5892 for (i
= 0; i
< len
; i
++)
5894 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5902 if (*p1
++ == ' ' && *p1
++ == '[')
5905 while (*p1
>= '0' && *p1
<= '9')
5906 n
= n
* 10 + *p1
++ - '0';
5907 if (strncmp (p1
, " times]\n", 8) == 0)
5914 /* Display an echo area message M with a specified length of NBYTES
5915 bytes. The string may include null characters. If M is 0, clear
5916 out any existing message, and let the mini-buffer text show
5919 The buffer M must continue to exist until after the echo area gets
5920 cleared or some other message gets displayed there. This means do
5921 not pass text that is stored in a Lisp string; do not pass text in
5922 a buffer that was alloca'd. */
5925 message2 (m
, nbytes
, multibyte
)
5930 /* First flush out any partial line written with print. */
5931 message_log_maybe_newline ();
5933 message_dolog (m
, nbytes
, 1, multibyte
);
5934 message2_nolog (m
, nbytes
, multibyte
);
5938 /* The non-logging counterpart of message2. */
5941 message2_nolog (m
, nbytes
, multibyte
)
5943 int nbytes
, multibyte
;
5945 struct frame
*sf
= SELECTED_FRAME ();
5946 message_enable_multibyte
= multibyte
;
5950 if (noninteractive_need_newline
)
5951 putc ('\n', stderr
);
5952 noninteractive_need_newline
= 0;
5954 fwrite (m
, nbytes
, 1, stderr
);
5955 if (cursor_in_echo_area
== 0)
5956 fprintf (stderr
, "\n");
5959 /* A null message buffer means that the frame hasn't really been
5960 initialized yet. Error messages get reported properly by
5961 cmd_error, so this must be just an informative message; toss it. */
5962 else if (INTERACTIVE
5963 && sf
->glyphs_initialized_p
5964 && FRAME_MESSAGE_BUF (sf
))
5966 Lisp_Object mini_window
;
5969 /* Get the frame containing the mini-buffer
5970 that the selected frame is using. */
5971 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5972 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5974 FRAME_SAMPLE_VISIBILITY (f
);
5975 if (FRAME_VISIBLE_P (sf
)
5976 && ! FRAME_VISIBLE_P (f
))
5977 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5981 set_message (m
, Qnil
, nbytes
, multibyte
);
5982 if (minibuffer_auto_raise
)
5983 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5986 clear_message (1, 1);
5988 do_pending_window_change (0);
5989 echo_area_display (1);
5990 do_pending_window_change (0);
5991 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5992 (*frame_up_to_date_hook
) (f
);
5997 /* Display an echo area message M with a specified length of NBYTES
5998 bytes. The string may include null characters. If M is not a
5999 string, clear out any existing message, and let the mini-buffer
6000 text show through. */
6003 message3 (m
, nbytes
, multibyte
)
6008 struct gcpro gcpro1
;
6012 /* First flush out any partial line written with print. */
6013 message_log_maybe_newline ();
6015 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6016 message3_nolog (m
, nbytes
, multibyte
);
6022 /* The non-logging version of message3. */
6025 message3_nolog (m
, nbytes
, multibyte
)
6027 int nbytes
, multibyte
;
6029 struct frame
*sf
= SELECTED_FRAME ();
6030 message_enable_multibyte
= multibyte
;
6034 if (noninteractive_need_newline
)
6035 putc ('\n', stderr
);
6036 noninteractive_need_newline
= 0;
6038 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6039 if (cursor_in_echo_area
== 0)
6040 fprintf (stderr
, "\n");
6043 /* A null message buffer means that the frame hasn't really been
6044 initialized yet. Error messages get reported properly by
6045 cmd_error, so this must be just an informative message; toss it. */
6046 else if (INTERACTIVE
6047 && sf
->glyphs_initialized_p
6048 && FRAME_MESSAGE_BUF (sf
))
6050 Lisp_Object mini_window
;
6054 /* Get the frame containing the mini-buffer
6055 that the selected frame is using. */
6056 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6057 frame
= XWINDOW (mini_window
)->frame
;
6060 FRAME_SAMPLE_VISIBILITY (f
);
6061 if (FRAME_VISIBLE_P (sf
)
6062 && !FRAME_VISIBLE_P (f
))
6063 Fmake_frame_visible (frame
);
6065 if (STRINGP (m
) && SCHARS (m
) > 0)
6067 set_message (NULL
, m
, nbytes
, multibyte
);
6068 if (minibuffer_auto_raise
)
6069 Fraise_frame (frame
);
6072 clear_message (1, 1);
6074 do_pending_window_change (0);
6075 echo_area_display (1);
6076 do_pending_window_change (0);
6077 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6078 (*frame_up_to_date_hook
) (f
);
6083 /* Display a null-terminated echo area message M. If M is 0, clear
6084 out any existing message, and let the mini-buffer text show through.
6086 The buffer M must continue to exist until after the echo area gets
6087 cleared or some other message gets displayed there. Do not pass
6088 text that is stored in a Lisp string. Do not pass text in a buffer
6089 that was alloca'd. */
6095 message2 (m
, (m
? strlen (m
) : 0), 0);
6099 /* The non-logging counterpart of message1. */
6105 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6108 /* Display a message M which contains a single %s
6109 which gets replaced with STRING. */
6112 message_with_string (m
, string
, log
)
6117 CHECK_STRING (string
);
6123 if (noninteractive_need_newline
)
6124 putc ('\n', stderr
);
6125 noninteractive_need_newline
= 0;
6126 fprintf (stderr
, m
, SDATA (string
));
6127 if (cursor_in_echo_area
== 0)
6128 fprintf (stderr
, "\n");
6132 else if (INTERACTIVE
)
6134 /* The frame whose minibuffer we're going to display the message on.
6135 It may be larger than the selected frame, so we need
6136 to use its buffer, not the selected frame's buffer. */
6137 Lisp_Object mini_window
;
6138 struct frame
*f
, *sf
= SELECTED_FRAME ();
6140 /* Get the frame containing the minibuffer
6141 that the selected frame is using. */
6142 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6143 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6145 /* A null message buffer means that the frame hasn't really been
6146 initialized yet. Error messages get reported properly by
6147 cmd_error, so this must be just an informative message; toss it. */
6148 if (FRAME_MESSAGE_BUF (f
))
6150 Lisp_Object args
[2], message
;
6151 struct gcpro gcpro1
, gcpro2
;
6153 args
[0] = build_string (m
);
6154 args
[1] = message
= string
;
6155 GCPRO2 (args
[0], message
);
6158 message
= Fformat (2, args
);
6161 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6163 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6167 /* Print should start at the beginning of the message
6168 buffer next time. */
6169 message_buf_print
= 0;
6175 /* Dump an informative message to the minibuf. If M is 0, clear out
6176 any existing message, and let the mini-buffer text show through. */
6180 message (m
, a1
, a2
, a3
)
6182 EMACS_INT a1
, a2
, a3
;
6188 if (noninteractive_need_newline
)
6189 putc ('\n', stderr
);
6190 noninteractive_need_newline
= 0;
6191 fprintf (stderr
, m
, a1
, a2
, a3
);
6192 if (cursor_in_echo_area
== 0)
6193 fprintf (stderr
, "\n");
6197 else if (INTERACTIVE
)
6199 /* The frame whose mini-buffer we're going to display the message
6200 on. It may be larger than the selected frame, so we need to
6201 use its buffer, not the selected frame's buffer. */
6202 Lisp_Object mini_window
;
6203 struct frame
*f
, *sf
= SELECTED_FRAME ();
6205 /* Get the frame containing the mini-buffer
6206 that the selected frame is using. */
6207 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6208 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6210 /* A null message buffer means that the frame hasn't really been
6211 initialized yet. Error messages get reported properly by
6212 cmd_error, so this must be just an informative message; toss
6214 if (FRAME_MESSAGE_BUF (f
))
6225 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6226 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6228 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6229 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6231 #endif /* NO_ARG_ARRAY */
6233 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6238 /* Print should start at the beginning of the message
6239 buffer next time. */
6240 message_buf_print
= 0;
6246 /* The non-logging version of message. */
6249 message_nolog (m
, a1
, a2
, a3
)
6251 EMACS_INT a1
, a2
, a3
;
6253 Lisp_Object old_log_max
;
6254 old_log_max
= Vmessage_log_max
;
6255 Vmessage_log_max
= Qnil
;
6256 message (m
, a1
, a2
, a3
);
6257 Vmessage_log_max
= old_log_max
;
6261 /* Display the current message in the current mini-buffer. This is
6262 only called from error handlers in process.c, and is not time
6268 if (!NILP (echo_area_buffer
[0]))
6271 string
= Fcurrent_message ();
6272 message3 (string
, SBYTES (string
),
6273 !NILP (current_buffer
->enable_multibyte_characters
));
6278 /* Make sure echo area buffers in `echo_buffers' are live.
6279 If they aren't, make new ones. */
6282 ensure_echo_area_buffers ()
6286 for (i
= 0; i
< 2; ++i
)
6287 if (!BUFFERP (echo_buffer
[i
])
6288 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6291 Lisp_Object old_buffer
;
6294 old_buffer
= echo_buffer
[i
];
6295 sprintf (name
, " *Echo Area %d*", i
);
6296 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6297 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6299 for (j
= 0; j
< 2; ++j
)
6300 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6301 echo_area_buffer
[j
] = echo_buffer
[i
];
6306 /* Call FN with args A1..A4 with either the current or last displayed
6307 echo_area_buffer as current buffer.
6309 WHICH zero means use the current message buffer
6310 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6311 from echo_buffer[] and clear it.
6313 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6314 suitable buffer from echo_buffer[] and clear it.
6316 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6317 that the current message becomes the last displayed one, make
6318 choose a suitable buffer for echo_area_buffer[0], and clear it.
6320 Value is what FN returns. */
6323 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6326 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6332 int this_one
, the_other
, clear_buffer_p
, rc
;
6333 int count
= SPECPDL_INDEX ();
6335 /* If buffers aren't live, make new ones. */
6336 ensure_echo_area_buffers ();
6341 this_one
= 0, the_other
= 1;
6343 this_one
= 1, the_other
= 0;
6346 this_one
= 0, the_other
= 1;
6349 /* We need a fresh one in case the current echo buffer equals
6350 the one containing the last displayed echo area message. */
6351 if (!NILP (echo_area_buffer
[this_one
])
6352 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6353 echo_area_buffer
[this_one
] = Qnil
;
6356 /* Choose a suitable buffer from echo_buffer[] is we don't
6358 if (NILP (echo_area_buffer
[this_one
]))
6360 echo_area_buffer
[this_one
]
6361 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6362 ? echo_buffer
[the_other
]
6363 : echo_buffer
[this_one
]);
6367 buffer
= echo_area_buffer
[this_one
];
6369 /* Don't get confused by reusing the buffer used for echoing
6370 for a different purpose. */
6371 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6374 record_unwind_protect (unwind_with_echo_area_buffer
,
6375 with_echo_area_buffer_unwind_data (w
));
6377 /* Make the echo area buffer current. Note that for display
6378 purposes, it is not necessary that the displayed window's buffer
6379 == current_buffer, except for text property lookup. So, let's
6380 only set that buffer temporarily here without doing a full
6381 Fset_window_buffer. We must also change w->pointm, though,
6382 because otherwise an assertions in unshow_buffer fails, and Emacs
6384 set_buffer_internal_1 (XBUFFER (buffer
));
6388 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6391 current_buffer
->undo_list
= Qt
;
6392 current_buffer
->read_only
= Qnil
;
6393 specbind (Qinhibit_read_only
, Qt
);
6394 specbind (Qinhibit_modification_hooks
, Qt
);
6396 if (clear_buffer_p
&& Z
> BEG
)
6399 xassert (BEGV
>= BEG
);
6400 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6402 rc
= fn (a1
, a2
, a3
, a4
);
6404 xassert (BEGV
>= BEG
);
6405 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6407 unbind_to (count
, Qnil
);
6412 /* Save state that should be preserved around the call to the function
6413 FN called in with_echo_area_buffer. */
6416 with_echo_area_buffer_unwind_data (w
)
6422 /* Reduce consing by keeping one vector in
6423 Vwith_echo_area_save_vector. */
6424 vector
= Vwith_echo_area_save_vector
;
6425 Vwith_echo_area_save_vector
= Qnil
;
6428 vector
= Fmake_vector (make_number (7), Qnil
);
6430 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6431 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6432 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6436 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6437 AREF (vector
, i
) = w
->buffer
; ++i
;
6438 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6439 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6444 for (; i
< end
; ++i
)
6445 AREF (vector
, i
) = Qnil
;
6448 xassert (i
== ASIZE (vector
));
6453 /* Restore global state from VECTOR which was created by
6454 with_echo_area_buffer_unwind_data. */
6457 unwind_with_echo_area_buffer (vector
)
6460 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6461 Vdeactivate_mark
= AREF (vector
, 1);
6462 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6464 if (WINDOWP (AREF (vector
, 3)))
6467 Lisp_Object buffer
, charpos
, bytepos
;
6469 w
= XWINDOW (AREF (vector
, 3));
6470 buffer
= AREF (vector
, 4);
6471 charpos
= AREF (vector
, 5);
6472 bytepos
= AREF (vector
, 6);
6475 set_marker_both (w
->pointm
, buffer
,
6476 XFASTINT (charpos
), XFASTINT (bytepos
));
6479 Vwith_echo_area_save_vector
= vector
;
6484 /* Set up the echo area for use by print functions. MULTIBYTE_P
6485 non-zero means we will print multibyte. */
6488 setup_echo_area_for_printing (multibyte_p
)
6491 ensure_echo_area_buffers ();
6493 if (!message_buf_print
)
6495 /* A message has been output since the last time we printed.
6496 Choose a fresh echo area buffer. */
6497 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6498 echo_area_buffer
[0] = echo_buffer
[1];
6500 echo_area_buffer
[0] = echo_buffer
[0];
6502 /* Switch to that buffer and clear it. */
6503 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6504 current_buffer
->truncate_lines
= Qnil
;
6508 int count
= SPECPDL_INDEX ();
6509 specbind (Qinhibit_read_only
, Qt
);
6510 /* Note that undo recording is always disabled. */
6512 unbind_to (count
, Qnil
);
6514 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6516 /* Set up the buffer for the multibyteness we need. */
6518 != !NILP (current_buffer
->enable_multibyte_characters
))
6519 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6521 /* Raise the frame containing the echo area. */
6522 if (minibuffer_auto_raise
)
6524 struct frame
*sf
= SELECTED_FRAME ();
6525 Lisp_Object mini_window
;
6526 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6527 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6530 message_log_maybe_newline ();
6531 message_buf_print
= 1;
6535 if (NILP (echo_area_buffer
[0]))
6537 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6538 echo_area_buffer
[0] = echo_buffer
[1];
6540 echo_area_buffer
[0] = echo_buffer
[0];
6543 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6545 /* Someone switched buffers between print requests. */
6546 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6547 current_buffer
->truncate_lines
= Qnil
;
6553 /* Display an echo area message in window W. Value is non-zero if W's
6554 height is changed. If display_last_displayed_message_p is
6555 non-zero, display the message that was last displayed, otherwise
6556 display the current message. */
6559 display_echo_area (w
)
6562 int i
, no_message_p
, window_height_changed_p
, count
;
6564 /* Temporarily disable garbage collections while displaying the echo
6565 area. This is done because a GC can print a message itself.
6566 That message would modify the echo area buffer's contents while a
6567 redisplay of the buffer is going on, and seriously confuse
6569 count
= inhibit_garbage_collection ();
6571 /* If there is no message, we must call display_echo_area_1
6572 nevertheless because it resizes the window. But we will have to
6573 reset the echo_area_buffer in question to nil at the end because
6574 with_echo_area_buffer will sets it to an empty buffer. */
6575 i
= display_last_displayed_message_p
? 1 : 0;
6576 no_message_p
= NILP (echo_area_buffer
[i
]);
6578 window_height_changed_p
6579 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6580 display_echo_area_1
,
6581 (EMACS_INT
) w
, Qnil
, 0, 0);
6584 echo_area_buffer
[i
] = Qnil
;
6586 unbind_to (count
, Qnil
);
6587 return window_height_changed_p
;
6591 /* Helper for display_echo_area. Display the current buffer which
6592 contains the current echo area message in window W, a mini-window,
6593 a pointer to which is passed in A1. A2..A4 are currently not used.
6594 Change the height of W so that all of the message is displayed.
6595 Value is non-zero if height of W was changed. */
6598 display_echo_area_1 (a1
, a2
, a3
, a4
)
6603 struct window
*w
= (struct window
*) a1
;
6605 struct text_pos start
;
6606 int window_height_changed_p
= 0;
6608 /* Do this before displaying, so that we have a large enough glyph
6609 matrix for the display. */
6610 window_height_changed_p
= resize_mini_window (w
, 0);
6613 clear_glyph_matrix (w
->desired_matrix
);
6614 XSETWINDOW (window
, w
);
6615 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6616 try_window (window
, start
);
6618 return window_height_changed_p
;
6622 /* Resize the echo area window to exactly the size needed for the
6623 currently displayed message, if there is one. If a mini-buffer
6624 is active, don't shrink it. */
6627 resize_echo_area_exactly ()
6629 if (BUFFERP (echo_area_buffer
[0])
6630 && WINDOWP (echo_area_window
))
6632 struct window
*w
= XWINDOW (echo_area_window
);
6634 Lisp_Object resize_exactly
;
6636 if (minibuf_level
== 0)
6637 resize_exactly
= Qt
;
6639 resize_exactly
= Qnil
;
6641 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6642 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6645 ++windows_or_buffers_changed
;
6646 ++update_mode_lines
;
6647 redisplay_internal (0);
6653 /* Callback function for with_echo_area_buffer, when used from
6654 resize_echo_area_exactly. A1 contains a pointer to the window to
6655 resize, EXACTLY non-nil means resize the mini-window exactly to the
6656 size of the text displayed. A3 and A4 are not used. Value is what
6657 resize_mini_window returns. */
6660 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6662 Lisp_Object exactly
;
6665 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6669 /* Resize mini-window W to fit the size of its contents. EXACT:P
6670 means size the window exactly to the size needed. Otherwise, it's
6671 only enlarged until W's buffer is empty. Value is non-zero if
6672 the window height has been changed. */
6675 resize_mini_window (w
, exact_p
)
6679 struct frame
*f
= XFRAME (w
->frame
);
6680 int window_height_changed_p
= 0;
6682 xassert (MINI_WINDOW_P (w
));
6684 /* Don't resize windows while redisplaying a window; it would
6685 confuse redisplay functions when the size of the window they are
6686 displaying changes from under them. Such a resizing can happen,
6687 for instance, when which-func prints a long message while
6688 we are running fontification-functions. We're running these
6689 functions with safe_call which binds inhibit-redisplay to t. */
6690 if (!NILP (Vinhibit_redisplay
))
6693 /* Nil means don't try to resize. */
6694 if (NILP (Vresize_mini_windows
)
6695 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6698 if (!FRAME_MINIBUF_ONLY_P (f
))
6701 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6702 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6703 int height
, max_height
;
6704 int unit
= CANON_Y_UNIT (f
);
6705 struct text_pos start
;
6706 struct buffer
*old_current_buffer
= NULL
;
6708 if (current_buffer
!= XBUFFER (w
->buffer
))
6710 old_current_buffer
= current_buffer
;
6711 set_buffer_internal (XBUFFER (w
->buffer
));
6714 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6716 /* Compute the max. number of lines specified by the user. */
6717 if (FLOATP (Vmax_mini_window_height
))
6718 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6719 else if (INTEGERP (Vmax_mini_window_height
))
6720 max_height
= XINT (Vmax_mini_window_height
);
6722 max_height
= total_height
/ 4;
6724 /* Correct that max. height if it's bogus. */
6725 max_height
= max (1, max_height
);
6726 max_height
= min (total_height
, max_height
);
6728 /* Find out the height of the text in the window. */
6729 if (it
.truncate_lines_p
)
6734 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6735 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6736 height
= it
.current_y
+ last_height
;
6738 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6739 height
-= it
.extra_line_spacing
;
6740 height
= (height
+ unit
- 1) / unit
;
6743 /* Compute a suitable window start. */
6744 if (height
> max_height
)
6746 height
= max_height
;
6747 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6748 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6749 start
= it
.current
.pos
;
6752 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6753 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6755 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6757 /* Let it grow only, until we display an empty message, in which
6758 case the window shrinks again. */
6759 if (height
> XFASTINT (w
->height
))
6761 int old_height
= XFASTINT (w
->height
);
6762 freeze_window_starts (f
, 1);
6763 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6764 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6766 else if (height
< XFASTINT (w
->height
)
6767 && (exact_p
|| BEGV
== ZV
))
6769 int old_height
= XFASTINT (w
->height
);
6770 freeze_window_starts (f
, 0);
6771 shrink_mini_window (w
);
6772 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6777 /* Always resize to exact size needed. */
6778 if (height
> XFASTINT (w
->height
))
6780 int old_height
= XFASTINT (w
->height
);
6781 freeze_window_starts (f
, 1);
6782 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6783 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6785 else if (height
< XFASTINT (w
->height
))
6787 int old_height
= XFASTINT (w
->height
);
6788 freeze_window_starts (f
, 0);
6789 shrink_mini_window (w
);
6793 freeze_window_starts (f
, 1);
6794 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6797 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6801 if (old_current_buffer
)
6802 set_buffer_internal (old_current_buffer
);
6805 return window_height_changed_p
;
6809 /* Value is the current message, a string, or nil if there is no
6817 if (NILP (echo_area_buffer
[0]))
6821 with_echo_area_buffer (0, 0, current_message_1
,
6822 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6824 echo_area_buffer
[0] = Qnil
;
6832 current_message_1 (a1
, a2
, a3
, a4
)
6837 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6840 *msg
= make_buffer_string (BEG
, Z
, 1);
6847 /* Push the current message on Vmessage_stack for later restauration
6848 by restore_message. Value is non-zero if the current message isn't
6849 empty. This is a relatively infrequent operation, so it's not
6850 worth optimizing. */
6856 msg
= current_message ();
6857 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6858 return STRINGP (msg
);
6862 /* Restore message display from the top of Vmessage_stack. */
6869 xassert (CONSP (Vmessage_stack
));
6870 msg
= XCAR (Vmessage_stack
);
6872 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
6874 message3_nolog (msg
, 0, 0);
6878 /* Handler for record_unwind_protect calling pop_message. */
6881 pop_message_unwind (dummy
)
6888 /* Pop the top-most entry off Vmessage_stack. */
6893 xassert (CONSP (Vmessage_stack
));
6894 Vmessage_stack
= XCDR (Vmessage_stack
);
6898 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6899 exits. If the stack is not empty, we have a missing pop_message
6903 check_message_stack ()
6905 if (!NILP (Vmessage_stack
))
6910 /* Truncate to NCHARS what will be displayed in the echo area the next
6911 time we display it---but don't redisplay it now. */
6914 truncate_echo_area (nchars
)
6918 echo_area_buffer
[0] = Qnil
;
6919 /* A null message buffer means that the frame hasn't really been
6920 initialized yet. Error messages get reported properly by
6921 cmd_error, so this must be just an informative message; toss it. */
6922 else if (!noninteractive
6924 && !NILP (echo_area_buffer
[0]))
6926 struct frame
*sf
= SELECTED_FRAME ();
6927 if (FRAME_MESSAGE_BUF (sf
))
6928 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6933 /* Helper function for truncate_echo_area. Truncate the current
6934 message to at most NCHARS characters. */
6937 truncate_message_1 (nchars
, a2
, a3
, a4
)
6942 if (BEG
+ nchars
< Z
)
6943 del_range (BEG
+ nchars
, Z
);
6945 echo_area_buffer
[0] = Qnil
;
6950 /* Set the current message to a substring of S or STRING.
6952 If STRING is a Lisp string, set the message to the first NBYTES
6953 bytes from STRING. NBYTES zero means use the whole string. If
6954 STRING is multibyte, the message will be displayed multibyte.
6956 If S is not null, set the message to the first LEN bytes of S. LEN
6957 zero means use the whole string. MULTIBYTE_P non-zero means S is
6958 multibyte. Display the message multibyte in that case. */
6961 set_message (s
, string
, nbytes
, multibyte_p
)
6964 int nbytes
, multibyte_p
;
6966 message_enable_multibyte
6967 = ((s
&& multibyte_p
)
6968 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6970 with_echo_area_buffer (0, -1, set_message_1
,
6971 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6972 message_buf_print
= 0;
6973 help_echo_showing_p
= 0;
6977 /* Helper function for set_message. Arguments have the same meaning
6978 as there, with A1 corresponding to S and A2 corresponding to STRING
6979 This function is called with the echo area buffer being
6983 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6986 EMACS_INT nbytes
, multibyte_p
;
6988 const char *s
= (const char *) a1
;
6989 Lisp_Object string
= a2
;
6993 /* Change multibyteness of the echo buffer appropriately. */
6994 if (message_enable_multibyte
6995 != !NILP (current_buffer
->enable_multibyte_characters
))
6996 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6998 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7000 /* Insert new message at BEG. */
7001 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7003 if (STRINGP (string
))
7008 nbytes
= SBYTES (string
);
7009 nchars
= string_byte_to_char (string
, nbytes
);
7011 /* This function takes care of single/multibyte conversion. We
7012 just have to ensure that the echo area buffer has the right
7013 setting of enable_multibyte_characters. */
7014 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7019 nbytes
= strlen (s
);
7021 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7023 /* Convert from multi-byte to single-byte. */
7025 unsigned char work
[1];
7027 /* Convert a multibyte string to single-byte. */
7028 for (i
= 0; i
< nbytes
; i
+= n
)
7030 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7031 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7033 : multibyte_char_to_unibyte (c
, Qnil
));
7034 insert_1_both (work
, 1, 1, 1, 0, 0);
7037 else if (!multibyte_p
7038 && !NILP (current_buffer
->enable_multibyte_characters
))
7040 /* Convert from single-byte to multi-byte. */
7042 const unsigned char *msg
= (const unsigned char *) s
;
7043 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7045 /* Convert a single-byte string to multibyte. */
7046 for (i
= 0; i
< nbytes
; i
++)
7048 c
= unibyte_char_to_multibyte (msg
[i
]);
7049 n
= CHAR_STRING (c
, str
);
7050 insert_1_both (str
, 1, n
, 1, 0, 0);
7054 insert_1 (s
, nbytes
, 1, 0, 0);
7061 /* Clear messages. CURRENT_P non-zero means clear the current
7062 message. LAST_DISPLAYED_P non-zero means clear the message
7066 clear_message (current_p
, last_displayed_p
)
7067 int current_p
, last_displayed_p
;
7071 echo_area_buffer
[0] = Qnil
;
7072 message_cleared_p
= 1;
7075 if (last_displayed_p
)
7076 echo_area_buffer
[1] = Qnil
;
7078 message_buf_print
= 0;
7081 /* Clear garbaged frames.
7083 This function is used where the old redisplay called
7084 redraw_garbaged_frames which in turn called redraw_frame which in
7085 turn called clear_frame. The call to clear_frame was a source of
7086 flickering. I believe a clear_frame is not necessary. It should
7087 suffice in the new redisplay to invalidate all current matrices,
7088 and ensure a complete redisplay of all windows. */
7091 clear_garbaged_frames ()
7095 Lisp_Object tail
, frame
;
7096 int changed_count
= 0;
7098 FOR_EACH_FRAME (tail
, frame
)
7100 struct frame
*f
= XFRAME (frame
);
7102 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7105 Fredraw_frame (frame
);
7106 clear_current_matrices (f
);
7115 ++windows_or_buffers_changed
;
7120 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7121 is non-zero update selected_frame. Value is non-zero if the
7122 mini-windows height has been changed. */
7125 echo_area_display (update_frame_p
)
7128 Lisp_Object mini_window
;
7131 int window_height_changed_p
= 0;
7132 struct frame
*sf
= SELECTED_FRAME ();
7134 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7135 w
= XWINDOW (mini_window
);
7136 f
= XFRAME (WINDOW_FRAME (w
));
7138 /* Don't display if frame is invisible or not yet initialized. */
7139 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7142 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7144 #ifdef HAVE_WINDOW_SYSTEM
7145 /* When Emacs starts, selected_frame may be a visible terminal
7146 frame, even if we run under a window system. If we let this
7147 through, a message would be displayed on the terminal. */
7148 if (EQ (selected_frame
, Vterminal_frame
)
7149 && !NILP (Vwindow_system
))
7151 #endif /* HAVE_WINDOW_SYSTEM */
7154 /* Redraw garbaged frames. */
7156 clear_garbaged_frames ();
7158 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7160 echo_area_window
= mini_window
;
7161 window_height_changed_p
= display_echo_area (w
);
7162 w
->must_be_updated_p
= 1;
7164 /* Update the display, unless called from redisplay_internal.
7165 Also don't update the screen during redisplay itself. The
7166 update will happen at the end of redisplay, and an update
7167 here could cause confusion. */
7168 if (update_frame_p
&& !redisplaying_p
)
7172 /* If the display update has been interrupted by pending
7173 input, update mode lines in the frame. Due to the
7174 pending input, it might have been that redisplay hasn't
7175 been called, so that mode lines above the echo area are
7176 garbaged. This looks odd, so we prevent it here. */
7177 if (!display_completed
)
7178 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7180 if (window_height_changed_p
7181 /* Don't do this if Emacs is shutting down. Redisplay
7182 needs to run hooks. */
7183 && !NILP (Vrun_hooks
))
7185 /* Must update other windows. Likewise as in other
7186 cases, don't let this update be interrupted by
7188 int count
= SPECPDL_INDEX ();
7189 specbind (Qredisplay_dont_pause
, Qt
);
7190 windows_or_buffers_changed
= 1;
7191 redisplay_internal (0);
7192 unbind_to (count
, Qnil
);
7194 else if (FRAME_WINDOW_P (f
) && n
== 0)
7196 /* Window configuration is the same as before.
7197 Can do with a display update of the echo area,
7198 unless we displayed some mode lines. */
7199 update_single_window (w
, 1);
7200 rif
->flush_display (f
);
7203 update_frame (f
, 1, 1);
7205 /* If cursor is in the echo area, make sure that the next
7206 redisplay displays the minibuffer, so that the cursor will
7207 be replaced with what the minibuffer wants. */
7208 if (cursor_in_echo_area
)
7209 ++windows_or_buffers_changed
;
7212 else if (!EQ (mini_window
, selected_window
))
7213 windows_or_buffers_changed
++;
7215 /* Last displayed message is now the current message. */
7216 echo_area_buffer
[1] = echo_area_buffer
[0];
7218 /* Prevent redisplay optimization in redisplay_internal by resetting
7219 this_line_start_pos. This is done because the mini-buffer now
7220 displays the message instead of its buffer text. */
7221 if (EQ (mini_window
, selected_window
))
7222 CHARPOS (this_line_start_pos
) = 0;
7224 return window_height_changed_p
;
7229 /***********************************************************************
7231 ***********************************************************************/
7234 /* The frame title buffering code is also used by Fformat_mode_line.
7235 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7237 /* A buffer for constructing frame titles in it; allocated from the
7238 heap in init_xdisp and resized as needed in store_frame_title_char. */
7240 static char *frame_title_buf
;
7242 /* The buffer's end, and a current output position in it. */
7244 static char *frame_title_buf_end
;
7245 static char *frame_title_ptr
;
7248 /* Store a single character C for the frame title in frame_title_buf.
7249 Re-allocate frame_title_buf if necessary. */
7253 store_frame_title_char (char c
)
7255 store_frame_title_char (c
)
7259 /* If output position has reached the end of the allocated buffer,
7260 double the buffer's size. */
7261 if (frame_title_ptr
== frame_title_buf_end
)
7263 int len
= frame_title_ptr
- frame_title_buf
;
7264 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7265 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7266 frame_title_buf_end
= frame_title_buf
+ new_size
;
7267 frame_title_ptr
= frame_title_buf
+ len
;
7270 *frame_title_ptr
++ = c
;
7274 /* Store part of a frame title in frame_title_buf, beginning at
7275 frame_title_ptr. STR is the string to store. Do not copy
7276 characters that yield more columns than PRECISION; PRECISION <= 0
7277 means copy the whole string. Pad with spaces until FIELD_WIDTH
7278 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7279 pad. Called from display_mode_element when it is used to build a
7283 store_frame_title (str
, field_width
, precision
)
7284 const unsigned char *str
;
7285 int field_width
, precision
;
7290 /* Copy at most PRECISION chars from STR. */
7291 nbytes
= strlen (str
);
7292 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7294 store_frame_title_char (*str
++);
7296 /* Fill up with spaces until FIELD_WIDTH reached. */
7297 while (field_width
> 0
7300 store_frame_title_char (' ');
7307 #ifdef HAVE_WINDOW_SYSTEM
7309 /* Set the title of FRAME, if it has changed. The title format is
7310 Vicon_title_format if FRAME is iconified, otherwise it is
7311 frame_title_format. */
7314 x_consider_frame_title (frame
)
7317 struct frame
*f
= XFRAME (frame
);
7319 if (FRAME_WINDOW_P (f
)
7320 || FRAME_MINIBUF_ONLY_P (f
)
7321 || f
->explicit_name
)
7323 /* Do we have more than one visible frame on this X display? */
7326 struct buffer
*obuf
;
7330 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7332 Lisp_Object other_frame
= XCAR (tail
);
7333 struct frame
*tf
= XFRAME (other_frame
);
7336 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7337 && !FRAME_MINIBUF_ONLY_P (tf
)
7338 && !EQ (other_frame
, tip_frame
)
7339 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7343 /* Set global variable indicating that multiple frames exist. */
7344 multiple_frames
= CONSP (tail
);
7346 /* Switch to the buffer of selected window of the frame. Set up
7347 frame_title_ptr so that display_mode_element will output into it;
7348 then display the title. */
7349 obuf
= current_buffer
;
7350 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7351 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7352 frame_title_ptr
= frame_title_buf
;
7353 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7354 NULL
, DEFAULT_FACE_ID
);
7355 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7356 len
= frame_title_ptr
- frame_title_buf
;
7357 frame_title_ptr
= NULL
;
7358 set_buffer_internal_1 (obuf
);
7360 /* Set the title only if it's changed. This avoids consing in
7361 the common case where it hasn't. (If it turns out that we've
7362 already wasted too much time by walking through the list with
7363 display_mode_element, then we might need to optimize at a
7364 higher level than this.) */
7365 if (! STRINGP (f
->name
)
7366 || SBYTES (f
->name
) != len
7367 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7368 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7372 #endif /* not HAVE_WINDOW_SYSTEM */
7377 /***********************************************************************
7379 ***********************************************************************/
7382 /* Prepare for redisplay by updating menu-bar item lists when
7383 appropriate. This can call eval. */
7386 prepare_menu_bars ()
7389 struct gcpro gcpro1
, gcpro2
;
7391 Lisp_Object tooltip_frame
;
7393 #ifdef HAVE_WINDOW_SYSTEM
7394 tooltip_frame
= tip_frame
;
7396 tooltip_frame
= Qnil
;
7399 /* Update all frame titles based on their buffer names, etc. We do
7400 this before the menu bars so that the buffer-menu will show the
7401 up-to-date frame titles. */
7402 #ifdef HAVE_WINDOW_SYSTEM
7403 if (windows_or_buffers_changed
|| update_mode_lines
)
7405 Lisp_Object tail
, frame
;
7407 FOR_EACH_FRAME (tail
, frame
)
7410 if (!EQ (frame
, tooltip_frame
)
7411 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7412 x_consider_frame_title (frame
);
7415 #endif /* HAVE_WINDOW_SYSTEM */
7417 /* Update the menu bar item lists, if appropriate. This has to be
7418 done before any actual redisplay or generation of display lines. */
7419 all_windows
= (update_mode_lines
7420 || buffer_shared
> 1
7421 || windows_or_buffers_changed
);
7424 Lisp_Object tail
, frame
;
7425 int count
= SPECPDL_INDEX ();
7427 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7429 FOR_EACH_FRAME (tail
, frame
)
7433 /* Ignore tooltip frame. */
7434 if (EQ (frame
, tooltip_frame
))
7437 /* If a window on this frame changed size, report that to
7438 the user and clear the size-change flag. */
7439 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7441 Lisp_Object functions
;
7443 /* Clear flag first in case we get an error below. */
7444 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7445 functions
= Vwindow_size_change_functions
;
7446 GCPRO2 (tail
, functions
);
7448 while (CONSP (functions
))
7450 call1 (XCAR (functions
), frame
);
7451 functions
= XCDR (functions
);
7457 update_menu_bar (f
, 0);
7458 #ifdef HAVE_WINDOW_SYSTEM
7459 update_tool_bar (f
, 0);
7464 unbind_to (count
, Qnil
);
7468 struct frame
*sf
= SELECTED_FRAME ();
7469 update_menu_bar (sf
, 1);
7470 #ifdef HAVE_WINDOW_SYSTEM
7471 update_tool_bar (sf
, 1);
7475 /* Motif needs this. See comment in xmenu.c. Turn it off when
7476 pending_menu_activation is not defined. */
7477 #ifdef USE_X_TOOLKIT
7478 pending_menu_activation
= 0;
7483 /* Update the menu bar item list for frame F. This has to be done
7484 before we start to fill in any display lines, because it can call
7487 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7490 update_menu_bar (f
, save_match_data
)
7492 int save_match_data
;
7495 register struct window
*w
;
7497 /* If called recursively during a menu update, do nothing. This can
7498 happen when, for instance, an activate-menubar-hook causes a
7500 if (inhibit_menubar_update
)
7503 window
= FRAME_SELECTED_WINDOW (f
);
7504 w
= XWINDOW (window
);
7506 #if 0 /* The if statement below this if statement used to include the
7507 condition !NILP (w->update_mode_line), rather than using
7508 update_mode_lines directly, and this if statement may have
7509 been added to make that condition work. Now the if
7510 statement below matches its comment, this isn't needed. */
7511 if (update_mode_lines
)
7512 w
->update_mode_line
= Qt
;
7515 if (FRAME_WINDOW_P (f
)
7517 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
7518 FRAME_EXTERNAL_MENU_BAR (f
)
7520 FRAME_MENU_BAR_LINES (f
) > 0
7522 : FRAME_MENU_BAR_LINES (f
) > 0)
7524 /* If the user has switched buffers or windows, we need to
7525 recompute to reflect the new bindings. But we'll
7526 recompute when update_mode_lines is set too; that means
7527 that people can use force-mode-line-update to request
7528 that the menu bar be recomputed. The adverse effect on
7529 the rest of the redisplay algorithm is about the same as
7530 windows_or_buffers_changed anyway. */
7531 if (windows_or_buffers_changed
7532 /* This used to test w->update_mode_line, but we believe
7533 there is no need to recompute the menu in that case. */
7534 || update_mode_lines
7535 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7536 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7537 != !NILP (w
->last_had_star
))
7538 || ((!NILP (Vtransient_mark_mode
)
7539 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7540 != !NILP (w
->region_showing
)))
7542 struct buffer
*prev
= current_buffer
;
7543 int count
= SPECPDL_INDEX ();
7545 specbind (Qinhibit_menubar_update
, Qt
);
7547 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7548 if (save_match_data
)
7549 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7550 if (NILP (Voverriding_local_map_menu_flag
))
7552 specbind (Qoverriding_terminal_local_map
, Qnil
);
7553 specbind (Qoverriding_local_map
, Qnil
);
7556 /* Run the Lucid hook. */
7557 safe_run_hooks (Qactivate_menubar_hook
);
7559 /* If it has changed current-menubar from previous value,
7560 really recompute the menu-bar from the value. */
7561 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7562 call0 (Qrecompute_lucid_menubar
);
7564 safe_run_hooks (Qmenu_bar_update_hook
);
7565 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7567 /* Redisplay the menu bar in case we changed it. */
7568 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
7569 if (FRAME_WINDOW_P (f
)
7570 #if defined (MAC_OS)
7571 /* All frames on Mac OS share the same menubar. So only the
7572 selected frame should be allowed to set it. */
7573 && f
== SELECTED_FRAME ()
7576 set_frame_menubar (f
, 0, 0);
7578 /* On a terminal screen, the menu bar is an ordinary screen
7579 line, and this makes it get updated. */
7580 w
->update_mode_line
= Qt
;
7581 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7582 /* In the non-toolkit version, the menu bar is an ordinary screen
7583 line, and this makes it get updated. */
7584 w
->update_mode_line
= Qt
;
7585 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7587 unbind_to (count
, Qnil
);
7588 set_buffer_internal_1 (prev
);
7595 /***********************************************************************
7597 ***********************************************************************/
7599 #ifdef HAVE_WINDOW_SYSTEM
7601 /* Update the tool-bar item list for frame F. This has to be done
7602 before we start to fill in any display lines. Called from
7603 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7604 and restore it here. */
7607 update_tool_bar (f
, save_match_data
)
7609 int save_match_data
;
7611 if (WINDOWP (f
->tool_bar_window
)
7612 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7617 window
= FRAME_SELECTED_WINDOW (f
);
7618 w
= XWINDOW (window
);
7620 /* If the user has switched buffers or windows, we need to
7621 recompute to reflect the new bindings. But we'll
7622 recompute when update_mode_lines is set too; that means
7623 that people can use force-mode-line-update to request
7624 that the menu bar be recomputed. The adverse effect on
7625 the rest of the redisplay algorithm is about the same as
7626 windows_or_buffers_changed anyway. */
7627 if (windows_or_buffers_changed
7628 || !NILP (w
->update_mode_line
)
7629 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7630 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7631 != !NILP (w
->last_had_star
))
7632 || ((!NILP (Vtransient_mark_mode
)
7633 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7634 != !NILP (w
->region_showing
)))
7636 struct buffer
*prev
= current_buffer
;
7637 int count
= SPECPDL_INDEX ();
7639 /* Set current_buffer to the buffer of the selected
7640 window of the frame, so that we get the right local
7642 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7644 /* Save match data, if we must. */
7645 if (save_match_data
)
7646 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7648 /* Make sure that we don't accidentally use bogus keymaps. */
7649 if (NILP (Voverriding_local_map_menu_flag
))
7651 specbind (Qoverriding_terminal_local_map
, Qnil
);
7652 specbind (Qoverriding_local_map
, Qnil
);
7655 /* Build desired tool-bar items from keymaps. */
7657 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7659 /* Redisplay the tool-bar in case we changed it. */
7660 w
->update_mode_line
= Qt
;
7662 unbind_to (count
, Qnil
);
7663 set_buffer_internal_1 (prev
);
7669 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7670 F's desired tool-bar contents. F->tool_bar_items must have
7671 been set up previously by calling prepare_menu_bars. */
7674 build_desired_tool_bar_string (f
)
7677 int i
, size
, size_needed
;
7678 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7679 Lisp_Object image
, plist
, props
;
7681 image
= plist
= props
= Qnil
;
7682 GCPRO3 (image
, plist
, props
);
7684 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7685 Otherwise, make a new string. */
7687 /* The size of the string we might be able to reuse. */
7688 size
= (STRINGP (f
->desired_tool_bar_string
)
7689 ? SCHARS (f
->desired_tool_bar_string
)
7692 /* We need one space in the string for each image. */
7693 size_needed
= f
->n_tool_bar_items
;
7695 /* Reuse f->desired_tool_bar_string, if possible. */
7696 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7697 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7701 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7702 Fremove_text_properties (make_number (0), make_number (size
),
7703 props
, f
->desired_tool_bar_string
);
7706 /* Put a `display' property on the string for the images to display,
7707 put a `menu_item' property on tool-bar items with a value that
7708 is the index of the item in F's tool-bar item vector. */
7709 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7711 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7713 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7714 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7715 int hmargin
, vmargin
, relief
, idx
, end
;
7716 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7718 /* If image is a vector, choose the image according to the
7720 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7721 if (VECTORP (image
))
7725 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7726 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7729 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7730 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7732 xassert (ASIZE (image
) >= idx
);
7733 image
= AREF (image
, idx
);
7738 /* Ignore invalid image specifications. */
7739 if (!valid_image_p (image
))
7742 /* Display the tool-bar button pressed, or depressed. */
7743 plist
= Fcopy_sequence (XCDR (image
));
7745 /* Compute margin and relief to draw. */
7746 relief
= (tool_bar_button_relief
>= 0
7747 ? tool_bar_button_relief
7748 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7749 hmargin
= vmargin
= relief
;
7751 if (INTEGERP (Vtool_bar_button_margin
)
7752 && XINT (Vtool_bar_button_margin
) > 0)
7754 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7755 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7757 else if (CONSP (Vtool_bar_button_margin
))
7759 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7760 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7761 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7763 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7764 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7765 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7768 if (auto_raise_tool_bar_buttons_p
)
7770 /* Add a `:relief' property to the image spec if the item is
7774 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7781 /* If image is selected, display it pressed, i.e. with a
7782 negative relief. If it's not selected, display it with a
7784 plist
= Fplist_put (plist
, QCrelief
,
7786 ? make_number (-relief
)
7787 : make_number (relief
)));
7792 /* Put a margin around the image. */
7793 if (hmargin
|| vmargin
)
7795 if (hmargin
== vmargin
)
7796 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7798 plist
= Fplist_put (plist
, QCmargin
,
7799 Fcons (make_number (hmargin
),
7800 make_number (vmargin
)));
7803 /* If button is not enabled, and we don't have special images
7804 for the disabled state, make the image appear disabled by
7805 applying an appropriate algorithm to it. */
7806 if (!enabled_p
&& idx
< 0)
7807 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7809 /* Put a `display' text property on the string for the image to
7810 display. Put a `menu-item' property on the string that gives
7811 the start of this item's properties in the tool-bar items
7813 image
= Fcons (Qimage
, plist
);
7814 props
= list4 (Qdisplay
, image
,
7815 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7817 /* Let the last image hide all remaining spaces in the tool bar
7818 string. The string can be longer than needed when we reuse a
7820 if (i
+ 1 == f
->n_tool_bar_items
)
7821 end
= SCHARS (f
->desired_tool_bar_string
);
7824 Fadd_text_properties (make_number (i
), make_number (end
),
7825 props
, f
->desired_tool_bar_string
);
7833 /* Display one line of the tool-bar of frame IT->f. */
7836 display_tool_bar_line (it
)
7839 struct glyph_row
*row
= it
->glyph_row
;
7840 int max_x
= it
->last_visible_x
;
7843 prepare_desired_row (row
);
7844 row
->y
= it
->current_y
;
7846 /* Note that this isn't made use of if the face hasn't a box,
7847 so there's no need to check the face here. */
7848 it
->start_of_box_run_p
= 1;
7850 while (it
->current_x
< max_x
)
7852 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7854 /* Get the next display element. */
7855 if (!get_next_display_element (it
))
7858 /* Produce glyphs. */
7859 x_before
= it
->current_x
;
7860 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7861 PRODUCE_GLYPHS (it
);
7863 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7868 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7870 if (x
+ glyph
->pixel_width
> max_x
)
7872 /* Glyph doesn't fit on line. */
7873 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7879 x
+= glyph
->pixel_width
;
7883 /* Stop at line ends. */
7884 if (ITERATOR_AT_END_OF_LINE_P (it
))
7887 set_iterator_to_next (it
, 1);
7892 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7893 extend_face_to_end_of_line (it
);
7894 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7895 last
->right_box_line_p
= 1;
7896 if (last
== row
->glyphs
[TEXT_AREA
])
7897 last
->left_box_line_p
= 1;
7898 compute_line_metrics (it
);
7900 /* If line is empty, make it occupy the rest of the tool-bar. */
7901 if (!row
->displays_text_p
)
7903 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7904 row
->ascent
= row
->phys_ascent
= 0;
7907 row
->full_width_p
= 1;
7908 row
->continued_p
= 0;
7909 row
->truncated_on_left_p
= 0;
7910 row
->truncated_on_right_p
= 0;
7912 it
->current_x
= it
->hpos
= 0;
7913 it
->current_y
+= row
->height
;
7919 /* Value is the number of screen lines needed to make all tool-bar
7920 items of frame F visible. */
7923 tool_bar_lines_needed (f
)
7926 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7929 /* Initialize an iterator for iteration over
7930 F->desired_tool_bar_string in the tool-bar window of frame F. */
7931 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7932 it
.first_visible_x
= 0;
7933 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7934 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7936 while (!ITERATOR_AT_END_P (&it
))
7938 it
.glyph_row
= w
->desired_matrix
->rows
;
7939 clear_glyph_row (it
.glyph_row
);
7940 display_tool_bar_line (&it
);
7943 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7947 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7949 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
7958 frame
= selected_frame
;
7960 CHECK_FRAME (frame
);
7963 if (WINDOWP (f
->tool_bar_window
)
7964 || (w
= XWINDOW (f
->tool_bar_window
),
7965 XFASTINT (w
->height
) > 0))
7967 update_tool_bar (f
, 1);
7968 if (f
->n_tool_bar_items
)
7970 build_desired_tool_bar_string (f
);
7971 nlines
= tool_bar_lines_needed (f
);
7975 return make_number (nlines
);
7979 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7980 height should be changed. */
7983 redisplay_tool_bar (f
)
7988 struct glyph_row
*row
;
7989 int change_height_p
= 0;
7991 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7992 do anything. This means you must start with tool-bar-lines
7993 non-zero to get the auto-sizing effect. Or in other words, you
7994 can turn off tool-bars by specifying tool-bar-lines zero. */
7995 if (!WINDOWP (f
->tool_bar_window
)
7996 || (w
= XWINDOW (f
->tool_bar_window
),
7997 XFASTINT (w
->height
) == 0))
8000 /* Set up an iterator for the tool-bar window. */
8001 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8002 it
.first_visible_x
= 0;
8003 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
8006 /* Build a string that represents the contents of the tool-bar. */
8007 build_desired_tool_bar_string (f
);
8008 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8010 /* Display as many lines as needed to display all tool-bar items. */
8011 while (it
.current_y
< it
.last_visible_y
)
8012 display_tool_bar_line (&it
);
8014 /* It doesn't make much sense to try scrolling in the tool-bar
8015 window, so don't do it. */
8016 w
->desired_matrix
->no_scrolling_p
= 1;
8017 w
->must_be_updated_p
= 1;
8019 if (auto_resize_tool_bars_p
)
8023 /* If we couldn't display everything, change the tool-bar's
8025 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8026 change_height_p
= 1;
8028 /* If there are blank lines at the end, except for a partially
8029 visible blank line at the end that is smaller than
8030 CANON_Y_UNIT, change the tool-bar's height. */
8031 row
= it
.glyph_row
- 1;
8032 if (!row
->displays_text_p
8033 && row
->height
>= CANON_Y_UNIT (f
))
8034 change_height_p
= 1;
8036 /* If row displays tool-bar items, but is partially visible,
8037 change the tool-bar's height. */
8038 if (row
->displays_text_p
8039 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8040 change_height_p
= 1;
8042 /* Resize windows as needed by changing the `tool-bar-lines'
8045 && (nlines
= tool_bar_lines_needed (f
),
8046 nlines
!= XFASTINT (w
->height
)))
8048 extern Lisp_Object Qtool_bar_lines
;
8050 int old_height
= XFASTINT (w
->height
);
8052 XSETFRAME (frame
, f
);
8053 clear_glyph_matrix (w
->desired_matrix
);
8054 Fmodify_frame_parameters (frame
,
8055 Fcons (Fcons (Qtool_bar_lines
,
8056 make_number (nlines
)),
8058 if (XFASTINT (w
->height
) != old_height
)
8059 fonts_changed_p
= 1;
8063 return change_height_p
;
8067 /* Get information about the tool-bar item which is displayed in GLYPH
8068 on frame F. Return in *PROP_IDX the index where tool-bar item
8069 properties start in F->tool_bar_items. Value is zero if
8070 GLYPH doesn't display a tool-bar item. */
8073 tool_bar_item_info (f
, glyph
, prop_idx
)
8075 struct glyph
*glyph
;
8082 /* This function can be called asynchronously, which means we must
8083 exclude any possibility that Fget_text_property signals an
8085 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8086 charpos
= max (0, charpos
);
8088 /* Get the text property `menu-item' at pos. The value of that
8089 property is the start index of this item's properties in
8090 F->tool_bar_items. */
8091 prop
= Fget_text_property (make_number (charpos
),
8092 Qmenu_item
, f
->current_tool_bar_string
);
8093 if (INTEGERP (prop
))
8095 *prop_idx
= XINT (prop
);
8104 #endif /* HAVE_WINDOW_SYSTEM */
8108 /************************************************************************
8109 Horizontal scrolling
8110 ************************************************************************/
8112 static int hscroll_window_tree
P_ ((Lisp_Object
));
8113 static int hscroll_windows
P_ ((Lisp_Object
));
8115 /* For all leaf windows in the window tree rooted at WINDOW, set their
8116 hscroll value so that PT is (i) visible in the window, and (ii) so
8117 that it is not within a certain margin at the window's left and
8118 right border. Value is non-zero if any window's hscroll has been
8122 hscroll_window_tree (window
)
8125 int hscrolled_p
= 0;
8126 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
8127 int hscroll_step_abs
= 0;
8128 double hscroll_step_rel
= 0;
8130 if (hscroll_relative_p
)
8132 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
8133 if (hscroll_step_rel
< 0)
8135 hscroll_relative_p
= 0;
8136 hscroll_step_abs
= 0;
8139 else if (INTEGERP (Vhscroll_step
))
8141 hscroll_step_abs
= XINT (Vhscroll_step
);
8142 if (hscroll_step_abs
< 0)
8143 hscroll_step_abs
= 0;
8146 hscroll_step_abs
= 0;
8148 while (WINDOWP (window
))
8150 struct window
*w
= XWINDOW (window
);
8152 if (WINDOWP (w
->hchild
))
8153 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
8154 else if (WINDOWP (w
->vchild
))
8155 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
8156 else if (w
->cursor
.vpos
>= 0)
8158 int h_margin
, text_area_x
, text_area_y
;
8159 int text_area_width
, text_area_height
;
8160 struct glyph_row
*current_cursor_row
8161 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
8162 struct glyph_row
*desired_cursor_row
8163 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
8164 struct glyph_row
*cursor_row
8165 = (desired_cursor_row
->enabled_p
8166 ? desired_cursor_row
8167 : current_cursor_row
);
8169 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8170 &text_area_width
, &text_area_height
);
8172 /* Scroll when cursor is inside this scroll margin. */
8173 h_margin
= hscroll_margin
* CANON_X_UNIT (XFRAME (w
->frame
));
8175 if ((XFASTINT (w
->hscroll
)
8176 && w
->cursor
.x
<= h_margin
)
8177 || (cursor_row
->enabled_p
8178 && cursor_row
->truncated_on_right_p
8179 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
8183 struct buffer
*saved_current_buffer
;
8187 /* Find point in a display of infinite width. */
8188 saved_current_buffer
= current_buffer
;
8189 current_buffer
= XBUFFER (w
->buffer
);
8191 if (w
== XWINDOW (selected_window
))
8192 pt
= BUF_PT (current_buffer
);
8195 pt
= marker_position (w
->pointm
);
8196 pt
= max (BEGV
, pt
);
8200 /* Move iterator to pt starting at cursor_row->start in
8201 a line with infinite width. */
8202 init_to_row_start (&it
, w
, cursor_row
);
8203 it
.last_visible_x
= INFINITY
;
8204 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8205 current_buffer
= saved_current_buffer
;
8207 /* Position cursor in window. */
8208 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
8209 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
8210 / CANON_X_UNIT (it
.f
);
8211 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
8213 if (hscroll_relative_p
)
8214 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
8217 wanted_x
= text_area_width
8218 - hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8221 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8225 if (hscroll_relative_p
)
8226 wanted_x
= text_area_width
* hscroll_step_rel
8229 wanted_x
= hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8232 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8234 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8236 /* Don't call Fset_window_hscroll if value hasn't
8237 changed because it will prevent redisplay
8239 if (XFASTINT (w
->hscroll
) != hscroll
)
8241 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8242 w
->hscroll
= make_number (hscroll
);
8251 /* Value is non-zero if hscroll of any leaf window has been changed. */
8256 /* Set hscroll so that cursor is visible and not inside horizontal
8257 scroll margins for all windows in the tree rooted at WINDOW. See
8258 also hscroll_window_tree above. Value is non-zero if any window's
8259 hscroll has been changed. If it has, desired matrices on the frame
8260 of WINDOW are cleared. */
8263 hscroll_windows (window
)
8268 if (automatic_hscrolling_p
)
8270 hscrolled_p
= hscroll_window_tree (window
);
8272 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8281 /************************************************************************
8283 ************************************************************************/
8285 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8286 to a non-zero value. This is sometimes handy to have in a debugger
8291 /* First and last unchanged row for try_window_id. */
8293 int debug_first_unchanged_at_end_vpos
;
8294 int debug_last_unchanged_at_beg_vpos
;
8296 /* Delta vpos and y. */
8298 int debug_dvpos
, debug_dy
;
8300 /* Delta in characters and bytes for try_window_id. */
8302 int debug_delta
, debug_delta_bytes
;
8304 /* Values of window_end_pos and window_end_vpos at the end of
8307 EMACS_INT debug_end_pos
, debug_end_vpos
;
8309 /* Append a string to W->desired_matrix->method. FMT is a printf
8310 format string. A1...A9 are a supplement for a variable-length
8311 argument list. If trace_redisplay_p is non-zero also printf the
8312 resulting string to stderr. */
8315 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8318 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8321 char *method
= w
->desired_matrix
->method
;
8322 int len
= strlen (method
);
8323 int size
= sizeof w
->desired_matrix
->method
;
8324 int remaining
= size
- len
- 1;
8326 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8327 if (len
&& remaining
)
8333 strncpy (method
+ len
, buffer
, remaining
);
8335 if (trace_redisplay_p
)
8336 fprintf (stderr
, "%p (%s): %s\n",
8338 ((BUFFERP (w
->buffer
)
8339 && STRINGP (XBUFFER (w
->buffer
)->name
))
8340 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
8345 #endif /* GLYPH_DEBUG */
8348 /* Value is non-zero if all changes in window W, which displays
8349 current_buffer, are in the text between START and END. START is a
8350 buffer position, END is given as a distance from Z. Used in
8351 redisplay_internal for display optimization. */
8354 text_outside_line_unchanged_p (w
, start
, end
)
8358 int unchanged_p
= 1;
8360 /* If text or overlays have changed, see where. */
8361 if (XFASTINT (w
->last_modified
) < MODIFF
8362 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8364 /* Gap in the line? */
8365 if (GPT
< start
|| Z
- GPT
< end
)
8368 /* Changes start in front of the line, or end after it? */
8370 && (BEG_UNCHANGED
< start
- 1
8371 || END_UNCHANGED
< end
))
8374 /* If selective display, can't optimize if changes start at the
8375 beginning of the line. */
8377 && INTEGERP (current_buffer
->selective_display
)
8378 && XINT (current_buffer
->selective_display
) > 0
8379 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8382 /* If there are overlays at the start or end of the line, these
8383 may have overlay strings with newlines in them. A change at
8384 START, for instance, may actually concern the display of such
8385 overlay strings as well, and they are displayed on different
8386 lines. So, quickly rule out this case. (For the future, it
8387 might be desirable to implement something more telling than
8388 just BEG/END_UNCHANGED.) */
8391 if (BEG
+ BEG_UNCHANGED
== start
8392 && overlay_touches_p (start
))
8394 if (END_UNCHANGED
== end
8395 && overlay_touches_p (Z
- end
))
8404 /* Do a frame update, taking possible shortcuts into account. This is
8405 the main external entry point for redisplay.
8407 If the last redisplay displayed an echo area message and that message
8408 is no longer requested, we clear the echo area or bring back the
8409 mini-buffer if that is in use. */
8414 redisplay_internal (0);
8418 /* Return 1 if point moved out of or into a composition. Otherwise
8419 return 0. PREV_BUF and PREV_PT are the last point buffer and
8420 position. BUF and PT are the current point buffer and position. */
8423 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8424 struct buffer
*prev_buf
, *buf
;
8431 XSETBUFFER (buffer
, buf
);
8432 /* Check a composition at the last point if point moved within the
8434 if (prev_buf
== buf
)
8437 /* Point didn't move. */
8440 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8441 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8442 && COMPOSITION_VALID_P (start
, end
, prop
)
8443 && start
< prev_pt
&& end
> prev_pt
)
8444 /* The last point was within the composition. Return 1 iff
8445 point moved out of the composition. */
8446 return (pt
<= start
|| pt
>= end
);
8449 /* Check a composition at the current point. */
8450 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8451 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8452 && COMPOSITION_VALID_P (start
, end
, prop
)
8453 && start
< pt
&& end
> pt
);
8457 /* Reconsider the setting of B->clip_changed which is displayed
8461 reconsider_clip_changes (w
, b
)
8466 && !NILP (w
->window_end_valid
)
8467 && w
->current_matrix
->buffer
== b
8468 && w
->current_matrix
->zv
== BUF_ZV (b
)
8469 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8470 b
->clip_changed
= 0;
8472 /* If display wasn't paused, and W is not a tool bar window, see if
8473 point has been moved into or out of a composition. In that case,
8474 we set b->clip_changed to 1 to force updating the screen. If
8475 b->clip_changed has already been set to 1, we can skip this
8477 if (!b
->clip_changed
8478 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8482 if (w
== XWINDOW (selected_window
))
8483 pt
= BUF_PT (current_buffer
);
8485 pt
= marker_position (w
->pointm
);
8487 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8488 || pt
!= XINT (w
->last_point
))
8489 && check_point_in_composition (w
->current_matrix
->buffer
,
8490 XINT (w
->last_point
),
8491 XBUFFER (w
->buffer
), pt
))
8492 b
->clip_changed
= 1;
8496 #define STOP_POLLING \
8497 do { if (! polling_stopped_here) stop_polling (); \
8498 polling_stopped_here = 1; } while (0)
8500 #define RESUME_POLLING \
8501 do { if (polling_stopped_here) start_polling (); \
8502 polling_stopped_here = 0; } while (0)
8505 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8506 response to any user action; therefore, we should preserve the echo
8507 area. (Actually, our caller does that job.) Perhaps in the future
8508 avoid recentering windows if it is not necessary; currently that
8509 causes some problems. */
8512 redisplay_internal (preserve_echo_area
)
8513 int preserve_echo_area
;
8515 struct window
*w
= XWINDOW (selected_window
);
8516 struct frame
*f
= XFRAME (w
->frame
);
8518 int must_finish
= 0;
8519 struct text_pos tlbufpos
, tlendpos
;
8520 int number_of_visible_frames
;
8522 struct frame
*sf
= SELECTED_FRAME ();
8523 int polling_stopped_here
= 0;
8525 /* Non-zero means redisplay has to consider all windows on all
8526 frames. Zero means, only selected_window is considered. */
8527 int consider_all_windows_p
;
8529 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8531 /* No redisplay if running in batch mode or frame is not yet fully
8532 initialized, or redisplay is explicitly turned off by setting
8533 Vinhibit_redisplay. */
8535 || !NILP (Vinhibit_redisplay
)
8536 || !f
->glyphs_initialized_p
)
8539 /* The flag redisplay_performed_directly_p is set by
8540 direct_output_for_insert when it already did the whole screen
8541 update necessary. */
8542 if (redisplay_performed_directly_p
)
8544 redisplay_performed_directly_p
= 0;
8545 if (!hscroll_windows (selected_window
))
8549 #ifdef USE_X_TOOLKIT
8550 if (popup_activated ())
8554 /* I don't think this happens but let's be paranoid. */
8558 /* Record a function that resets redisplaying_p to its old value
8559 when we leave this function. */
8560 count
= SPECPDL_INDEX ();
8561 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8563 specbind (Qinhibit_free_realized_faces
, Qnil
);
8567 reconsider_clip_changes (w
, current_buffer
);
8569 /* If new fonts have been loaded that make a glyph matrix adjustment
8570 necessary, do it. */
8571 if (fonts_changed_p
)
8573 adjust_glyphs (NULL
);
8574 ++windows_or_buffers_changed
;
8575 fonts_changed_p
= 0;
8578 /* If face_change_count is non-zero, init_iterator will free all
8579 realized faces, which includes the faces referenced from current
8580 matrices. So, we can't reuse current matrices in this case. */
8581 if (face_change_count
)
8582 ++windows_or_buffers_changed
;
8584 if (! FRAME_WINDOW_P (sf
)
8585 && previous_terminal_frame
!= sf
)
8587 /* Since frames on an ASCII terminal share the same display
8588 area, displaying a different frame means redisplay the whole
8590 windows_or_buffers_changed
++;
8591 SET_FRAME_GARBAGED (sf
);
8592 XSETFRAME (Vterminal_frame
, sf
);
8594 previous_terminal_frame
= sf
;
8596 /* Set the visible flags for all frames. Do this before checking
8597 for resized or garbaged frames; they want to know if their frames
8598 are visible. See the comment in frame.h for
8599 FRAME_SAMPLE_VISIBILITY. */
8601 Lisp_Object tail
, frame
;
8603 number_of_visible_frames
= 0;
8605 FOR_EACH_FRAME (tail
, frame
)
8607 struct frame
*f
= XFRAME (frame
);
8609 FRAME_SAMPLE_VISIBILITY (f
);
8610 if (FRAME_VISIBLE_P (f
))
8611 ++number_of_visible_frames
;
8612 clear_desired_matrices (f
);
8616 /* Notice any pending interrupt request to change frame size. */
8617 do_pending_window_change (1);
8619 /* Clear frames marked as garbaged. */
8621 clear_garbaged_frames ();
8623 /* Build menubar and tool-bar items. */
8624 prepare_menu_bars ();
8626 if (windows_or_buffers_changed
)
8627 update_mode_lines
++;
8629 /* Detect case that we need to write or remove a star in the mode line. */
8630 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8632 w
->update_mode_line
= Qt
;
8633 if (buffer_shared
> 1)
8634 update_mode_lines
++;
8637 /* If %c is in the mode line, update it if needed. */
8638 if (!NILP (w
->column_number_displayed
)
8639 /* This alternative quickly identifies a common case
8640 where no change is needed. */
8641 && !(PT
== XFASTINT (w
->last_point
)
8642 && XFASTINT (w
->last_modified
) >= MODIFF
8643 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8644 && (XFASTINT (w
->column_number_displayed
)
8645 != (int) current_column ())) /* iftc */
8646 w
->update_mode_line
= Qt
;
8648 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8650 /* The variable buffer_shared is set in redisplay_window and
8651 indicates that we redisplay a buffer in different windows. See
8653 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
8654 || cursor_type_changed
);
8656 /* If specs for an arrow have changed, do thorough redisplay
8657 to ensure we remove any arrow that should no longer exist. */
8658 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8659 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8660 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8662 /* Normally the message* functions will have already displayed and
8663 updated the echo area, but the frame may have been trashed, or
8664 the update may have been preempted, so display the echo area
8665 again here. Checking message_cleared_p captures the case that
8666 the echo area should be cleared. */
8667 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8668 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8669 || (message_cleared_p
8670 && minibuf_level
== 0
8671 /* If the mini-window is currently selected, this means the
8672 echo-area doesn't show through. */
8673 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8675 int window_height_changed_p
= echo_area_display (0);
8678 /* If we don't display the current message, don't clear the
8679 message_cleared_p flag, because, if we did, we wouldn't clear
8680 the echo area in the next redisplay which doesn't preserve
8682 if (!display_last_displayed_message_p
)
8683 message_cleared_p
= 0;
8685 if (fonts_changed_p
)
8687 else if (window_height_changed_p
)
8689 consider_all_windows_p
= 1;
8690 ++update_mode_lines
;
8691 ++windows_or_buffers_changed
;
8693 /* If window configuration was changed, frames may have been
8694 marked garbaged. Clear them or we will experience
8695 surprises wrt scrolling. */
8697 clear_garbaged_frames ();
8700 else if (EQ (selected_window
, minibuf_window
)
8701 && (current_buffer
->clip_changed
8702 || XFASTINT (w
->last_modified
) < MODIFF
8703 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8704 && resize_mini_window (w
, 0))
8706 /* Resized active mini-window to fit the size of what it is
8707 showing if its contents might have changed. */
8709 consider_all_windows_p
= 1;
8710 ++windows_or_buffers_changed
;
8711 ++update_mode_lines
;
8713 /* If window configuration was changed, frames may have been
8714 marked garbaged. Clear them or we will experience
8715 surprises wrt scrolling. */
8717 clear_garbaged_frames ();
8721 /* If showing the region, and mark has changed, we must redisplay
8722 the whole window. The assignment to this_line_start_pos prevents
8723 the optimization directly below this if-statement. */
8724 if (((!NILP (Vtransient_mark_mode
)
8725 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8726 != !NILP (w
->region_showing
))
8727 || (!NILP (w
->region_showing
)
8728 && !EQ (w
->region_showing
,
8729 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8730 CHARPOS (this_line_start_pos
) = 0;
8732 /* Optimize the case that only the line containing the cursor in the
8733 selected window has changed. Variables starting with this_ are
8734 set in display_line and record information about the line
8735 containing the cursor. */
8736 tlbufpos
= this_line_start_pos
;
8737 tlendpos
= this_line_end_pos
;
8738 if (!consider_all_windows_p
8739 && CHARPOS (tlbufpos
) > 0
8740 && NILP (w
->update_mode_line
)
8741 && !current_buffer
->clip_changed
8742 && !current_buffer
->prevent_redisplay_optimizations_p
8743 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8744 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8745 /* Make sure recorded data applies to current buffer, etc. */
8746 && this_line_buffer
== current_buffer
8747 && current_buffer
== XBUFFER (w
->buffer
)
8748 && NILP (w
->force_start
)
8749 && NILP (w
->optional_new_start
)
8750 /* Point must be on the line that we have info recorded about. */
8751 && PT
>= CHARPOS (tlbufpos
)
8752 && PT
<= Z
- CHARPOS (tlendpos
)
8753 /* All text outside that line, including its final newline,
8754 must be unchanged */
8755 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8756 CHARPOS (tlendpos
)))
8758 if (CHARPOS (tlbufpos
) > BEGV
8759 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8760 && (CHARPOS (tlbufpos
) == ZV
8761 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8762 /* Former continuation line has disappeared by becoming empty */
8764 else if (XFASTINT (w
->last_modified
) < MODIFF
8765 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8766 || MINI_WINDOW_P (w
))
8768 /* We have to handle the case of continuation around a
8769 wide-column character (See the comment in indent.c around
8772 For instance, in the following case:
8774 -------- Insert --------
8775 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8776 J_I_ ==> J_I_ `^^' are cursors.
8780 As we have to redraw the line above, we should goto cancel. */
8783 int line_height_before
= this_line_pixel_height
;
8785 /* Note that start_display will handle the case that the
8786 line starting at tlbufpos is a continuation lines. */
8787 start_display (&it
, w
, tlbufpos
);
8789 /* Implementation note: It this still necessary? */
8790 if (it
.current_x
!= this_line_start_x
)
8793 TRACE ((stderr
, "trying display optimization 1\n"));
8794 w
->cursor
.vpos
= -1;
8795 overlay_arrow_seen
= 0;
8796 it
.vpos
= this_line_vpos
;
8797 it
.current_y
= this_line_y
;
8798 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8801 /* If line contains point, is not continued,
8802 and ends at same distance from eob as before, we win */
8803 if (w
->cursor
.vpos
>= 0
8804 /* Line is not continued, otherwise this_line_start_pos
8805 would have been set to 0 in display_line. */
8806 && CHARPOS (this_line_start_pos
)
8807 /* Line ends as before. */
8808 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8809 /* Line has same height as before. Otherwise other lines
8810 would have to be shifted up or down. */
8811 && this_line_pixel_height
== line_height_before
)
8813 /* If this is not the window's last line, we must adjust
8814 the charstarts of the lines below. */
8815 if (it
.current_y
< it
.last_visible_y
)
8817 struct glyph_row
*row
8818 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8819 int delta
, delta_bytes
;
8821 if (Z
- CHARPOS (tlendpos
) == ZV
)
8823 /* This line ends at end of (accessible part of)
8824 buffer. There is no newline to count. */
8826 - CHARPOS (tlendpos
)
8827 - MATRIX_ROW_START_CHARPOS (row
));
8828 delta_bytes
= (Z_BYTE
8829 - BYTEPOS (tlendpos
)
8830 - MATRIX_ROW_START_BYTEPOS (row
));
8834 /* This line ends in a newline. Must take
8835 account of the newline and the rest of the
8836 text that follows. */
8838 - CHARPOS (tlendpos
)
8839 - MATRIX_ROW_START_CHARPOS (row
));
8840 delta_bytes
= (Z_BYTE
8841 - BYTEPOS (tlendpos
)
8842 - MATRIX_ROW_START_BYTEPOS (row
));
8845 increment_matrix_positions (w
->current_matrix
,
8847 w
->current_matrix
->nrows
,
8848 delta
, delta_bytes
);
8851 /* If this row displays text now but previously didn't,
8852 or vice versa, w->window_end_vpos may have to be
8854 if ((it
.glyph_row
- 1)->displays_text_p
)
8856 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8857 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8859 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8860 && this_line_vpos
> 0)
8861 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8862 w
->window_end_valid
= Qnil
;
8864 /* Update hint: No need to try to scroll in update_window. */
8865 w
->desired_matrix
->no_scrolling_p
= 1;
8868 *w
->desired_matrix
->method
= 0;
8869 debug_method_add (w
, "optimization 1");
8876 else if (/* Cursor position hasn't changed. */
8877 PT
== XFASTINT (w
->last_point
)
8878 /* Make sure the cursor was last displayed
8879 in this window. Otherwise we have to reposition it. */
8880 && 0 <= w
->cursor
.vpos
8881 && XINT (w
->height
) > w
->cursor
.vpos
)
8885 do_pending_window_change (1);
8887 /* We used to always goto end_of_redisplay here, but this
8888 isn't enough if we have a blinking cursor. */
8889 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8890 goto end_of_redisplay
;
8894 /* If highlighting the region, or if the cursor is in the echo area,
8895 then we can't just move the cursor. */
8896 else if (! (!NILP (Vtransient_mark_mode
)
8897 && !NILP (current_buffer
->mark_active
))
8898 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8899 || highlight_nonselected_windows
)
8900 && NILP (w
->region_showing
)
8901 && NILP (Vshow_trailing_whitespace
)
8902 && !cursor_in_echo_area
)
8905 struct glyph_row
*row
;
8907 /* Skip from tlbufpos to PT and see where it is. Note that
8908 PT may be in invisible text. If so, we will end at the
8909 next visible position. */
8910 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8911 NULL
, DEFAULT_FACE_ID
);
8912 it
.current_x
= this_line_start_x
;
8913 it
.current_y
= this_line_y
;
8914 it
.vpos
= this_line_vpos
;
8916 /* The call to move_it_to stops in front of PT, but
8917 moves over before-strings. */
8918 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8920 if (it
.vpos
== this_line_vpos
8921 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8924 xassert (this_line_vpos
== it
.vpos
);
8925 xassert (this_line_y
== it
.current_y
);
8926 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8928 *w
->desired_matrix
->method
= 0;
8929 debug_method_add (w
, "optimization 3");
8938 /* Text changed drastically or point moved off of line. */
8939 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8942 CHARPOS (this_line_start_pos
) = 0;
8943 consider_all_windows_p
|= buffer_shared
> 1;
8944 ++clear_face_cache_count
;
8947 /* Build desired matrices, and update the display. If
8948 consider_all_windows_p is non-zero, do it for all windows on all
8949 frames. Otherwise do it for selected_window, only. */
8951 if (consider_all_windows_p
)
8953 Lisp_Object tail
, frame
;
8954 int i
, n
= 0, size
= 50;
8955 struct frame
**updated
8956 = (struct frame
**) alloca (size
* sizeof *updated
);
8958 /* Clear the face cache eventually. */
8959 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8961 clear_face_cache (0);
8962 clear_face_cache_count
= 0;
8965 /* Recompute # windows showing selected buffer. This will be
8966 incremented each time such a window is displayed. */
8969 FOR_EACH_FRAME (tail
, frame
)
8971 struct frame
*f
= XFRAME (frame
);
8973 if (FRAME_WINDOW_P (f
) || f
== sf
)
8975 #ifdef HAVE_WINDOW_SYSTEM
8976 if (clear_face_cache_count
% 50 == 0
8977 && FRAME_WINDOW_P (f
))
8978 clear_image_cache (f
, 0);
8979 #endif /* HAVE_WINDOW_SYSTEM */
8981 /* Mark all the scroll bars to be removed; we'll redeem
8982 the ones we want when we redisplay their windows. */
8983 if (condemn_scroll_bars_hook
)
8984 condemn_scroll_bars_hook (f
);
8986 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8987 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8989 /* Any scroll bars which redisplay_windows should have
8990 nuked should now go away. */
8991 if (judge_scroll_bars_hook
)
8992 judge_scroll_bars_hook (f
);
8994 /* If fonts changed, display again. */
8995 /* ??? rms: I suspect it is a mistake to jump all the way
8996 back to retry here. It should just retry this frame. */
8997 if (fonts_changed_p
)
9000 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
9002 /* See if we have to hscroll. */
9003 if (hscroll_windows (f
->root_window
))
9006 /* Prevent various kinds of signals during display
9007 update. stdio is not robust about handling
9008 signals, which can cause an apparent I/O
9010 if (interrupt_input
)
9014 /* Update the display. */
9015 set_window_update_flags (XWINDOW (f
->root_window
), 1);
9016 pause
|= update_frame (f
, 0, 0);
9022 int nbytes
= size
* sizeof *updated
;
9023 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
9024 bcopy (updated
, p
, nbytes
);
9033 /* Do the mark_window_display_accurate after all windows have
9034 been redisplayed because this call resets flags in buffers
9035 which are needed for proper redisplay. */
9036 for (i
= 0; i
< n
; ++i
)
9038 struct frame
*f
= updated
[i
];
9039 mark_window_display_accurate (f
->root_window
, 1);
9040 if (frame_up_to_date_hook
)
9041 frame_up_to_date_hook (f
);
9044 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9046 Lisp_Object mini_window
;
9047 struct frame
*mini_frame
;
9049 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9050 /* Use list_of_error, not Qerror, so that
9051 we catch only errors and don't run the debugger. */
9052 internal_condition_case_1 (redisplay_window_1
, selected_window
,
9054 redisplay_window_error
);
9056 /* Compare desired and current matrices, perform output. */
9059 /* If fonts changed, display again. */
9060 if (fonts_changed_p
)
9063 /* Prevent various kinds of signals during display update.
9064 stdio is not robust about handling signals,
9065 which can cause an apparent I/O error. */
9066 if (interrupt_input
)
9070 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9072 if (hscroll_windows (selected_window
))
9075 XWINDOW (selected_window
)->must_be_updated_p
= 1;
9076 pause
= update_frame (sf
, 0, 0);
9079 /* We may have called echo_area_display at the top of this
9080 function. If the echo area is on another frame, that may
9081 have put text on a frame other than the selected one, so the
9082 above call to update_frame would not have caught it. Catch
9084 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9085 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9087 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
9089 XWINDOW (mini_window
)->must_be_updated_p
= 1;
9090 pause
|= update_frame (mini_frame
, 0, 0);
9091 if (!pause
&& hscroll_windows (mini_window
))
9096 /* If display was paused because of pending input, make sure we do a
9097 thorough update the next time. */
9100 /* Prevent the optimization at the beginning of
9101 redisplay_internal that tries a single-line update of the
9102 line containing the cursor in the selected window. */
9103 CHARPOS (this_line_start_pos
) = 0;
9105 /* Let the overlay arrow be updated the next time. */
9106 if (!NILP (last_arrow_position
))
9108 last_arrow_position
= Qt
;
9109 last_arrow_string
= Qt
;
9112 /* If we pause after scrolling, some rows in the current
9113 matrices of some windows are not valid. */
9114 if (!WINDOW_FULL_WIDTH_P (w
)
9115 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
9116 update_mode_lines
= 1;
9120 if (!consider_all_windows_p
)
9122 /* This has already been done above if
9123 consider_all_windows_p is set. */
9124 mark_window_display_accurate_1 (w
, 1);
9126 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9127 last_arrow_string
= Voverlay_arrow_string
;
9129 if (frame_up_to_date_hook
!= 0)
9130 frame_up_to_date_hook (sf
);
9133 update_mode_lines
= 0;
9134 windows_or_buffers_changed
= 0;
9135 cursor_type_changed
= 0;
9138 /* Start SIGIO interrupts coming again. Having them off during the
9139 code above makes it less likely one will discard output, but not
9140 impossible, since there might be stuff in the system buffer here.
9141 But it is much hairier to try to do anything about that. */
9142 if (interrupt_input
)
9146 /* If a frame has become visible which was not before, redisplay
9147 again, so that we display it. Expose events for such a frame
9148 (which it gets when becoming visible) don't call the parts of
9149 redisplay constructing glyphs, so simply exposing a frame won't
9150 display anything in this case. So, we have to display these
9151 frames here explicitly. */
9154 Lisp_Object tail
, frame
;
9157 FOR_EACH_FRAME (tail
, frame
)
9159 int this_is_visible
= 0;
9161 if (XFRAME (frame
)->visible
)
9162 this_is_visible
= 1;
9163 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
9164 if (XFRAME (frame
)->visible
)
9165 this_is_visible
= 1;
9167 if (this_is_visible
)
9171 if (new_count
!= number_of_visible_frames
)
9172 windows_or_buffers_changed
++;
9175 /* Change frame size now if a change is pending. */
9176 do_pending_window_change (1);
9178 /* If we just did a pending size change, or have additional
9179 visible frames, redisplay again. */
9180 if (windows_or_buffers_changed
&& !pause
)
9184 unbind_to (count
, Qnil
);
9189 /* Redisplay, but leave alone any recent echo area message unless
9190 another message has been requested in its place.
9192 This is useful in situations where you need to redisplay but no
9193 user action has occurred, making it inappropriate for the message
9194 area to be cleared. See tracking_off and
9195 wait_reading_process_input for examples of these situations.
9197 FROM_WHERE is an integer saying from where this function was
9198 called. This is useful for debugging. */
9201 redisplay_preserve_echo_area (from_where
)
9204 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9206 if (!NILP (echo_area_buffer
[1]))
9208 /* We have a previously displayed message, but no current
9209 message. Redisplay the previous message. */
9210 display_last_displayed_message_p
= 1;
9211 redisplay_internal (1);
9212 display_last_displayed_message_p
= 0;
9215 redisplay_internal (1);
9219 /* Function registered with record_unwind_protect in
9220 redisplay_internal. Reset redisplaying_p to the value it had
9221 before redisplay_internal was called, and clear
9222 prevent_freeing_realized_faces_p. */
9225 unwind_redisplay (old_redisplaying_p
)
9226 Lisp_Object old_redisplaying_p
;
9228 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9233 /* Mark the display of window W as accurate or inaccurate. If
9234 ACCURATE_P is non-zero mark display of W as accurate. If
9235 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9236 redisplay_internal is called. */
9239 mark_window_display_accurate_1 (w
, accurate_p
)
9243 if (BUFFERP (w
->buffer
))
9245 struct buffer
*b
= XBUFFER (w
->buffer
);
9248 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9249 w
->last_overlay_modified
9250 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9252 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9256 b
->clip_changed
= 0;
9257 b
->prevent_redisplay_optimizations_p
= 0;
9259 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9260 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9261 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9262 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9264 w
->current_matrix
->buffer
= b
;
9265 w
->current_matrix
->begv
= BUF_BEGV (b
);
9266 w
->current_matrix
->zv
= BUF_ZV (b
);
9268 w
->last_cursor
= w
->cursor
;
9269 w
->last_cursor_off_p
= w
->cursor_off_p
;
9271 if (w
== XWINDOW (selected_window
))
9272 w
->last_point
= make_number (BUF_PT (b
));
9274 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9280 w
->window_end_valid
= w
->buffer
;
9281 #if 0 /* This is incorrect with variable-height lines. */
9282 xassert (XINT (w
->window_end_vpos
)
9284 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9286 w
->update_mode_line
= Qnil
;
9291 /* Mark the display of windows in the window tree rooted at WINDOW as
9292 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9293 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9294 be redisplayed the next time redisplay_internal is called. */
9297 mark_window_display_accurate (window
, accurate_p
)
9303 for (; !NILP (window
); window
= w
->next
)
9305 w
= XWINDOW (window
);
9306 mark_window_display_accurate_1 (w
, accurate_p
);
9308 if (!NILP (w
->vchild
))
9309 mark_window_display_accurate (w
->vchild
, accurate_p
);
9310 if (!NILP (w
->hchild
))
9311 mark_window_display_accurate (w
->hchild
, accurate_p
);
9316 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9317 last_arrow_string
= Voverlay_arrow_string
;
9321 /* Force a thorough redisplay the next time by setting
9322 last_arrow_position and last_arrow_string to t, which is
9323 unequal to any useful value of Voverlay_arrow_... */
9324 last_arrow_position
= Qt
;
9325 last_arrow_string
= Qt
;
9330 /* Return value in display table DP (Lisp_Char_Table *) for character
9331 C. Since a display table doesn't have any parent, we don't have to
9332 follow parent. Do not call this function directly but use the
9333 macro DISP_CHAR_VECTOR. */
9336 disp_char_vector (dp
, c
)
9337 struct Lisp_Char_Table
*dp
;
9343 if (SINGLE_BYTE_CHAR_P (c
))
9344 return (dp
->contents
[c
]);
9346 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9349 else if (code
[2] < 32)
9352 /* Here, the possible range of code[0] (== charset ID) is
9353 128..max_charset. Since the top level char table contains data
9354 for multibyte characters after 256th element, we must increment
9355 code[0] by 128 to get a correct index. */
9357 code
[3] = -1; /* anchor */
9359 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9361 val
= dp
->contents
[code
[i
]];
9362 if (!SUB_CHAR_TABLE_P (val
))
9363 return (NILP (val
) ? dp
->defalt
: val
);
9366 /* Here, val is a sub char table. We return the default value of
9368 return (dp
->defalt
);
9373 /***********************************************************************
9375 ***********************************************************************/
9377 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9380 redisplay_windows (window
)
9383 while (!NILP (window
))
9385 struct window
*w
= XWINDOW (window
);
9387 if (!NILP (w
->hchild
))
9388 redisplay_windows (w
->hchild
);
9389 else if (!NILP (w
->vchild
))
9390 redisplay_windows (w
->vchild
);
9393 displayed_buffer
= XBUFFER (w
->buffer
);
9394 /* Use list_of_error, not Qerror, so that
9395 we catch only errors and don't run the debugger. */
9396 internal_condition_case_1 (redisplay_window_0
, window
,
9398 redisplay_window_error
);
9406 redisplay_window_error ()
9408 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
9413 redisplay_window_0 (window
)
9416 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9417 redisplay_window (window
, 0);
9422 redisplay_window_1 (window
)
9425 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9426 redisplay_window (window
, 1);
9430 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9431 DELTA is the number of bytes by which positions recorded in ROW
9432 differ from current buffer positions. */
9435 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9437 struct glyph_row
*row
;
9438 struct glyph_matrix
*matrix
;
9439 int delta
, delta_bytes
, dy
, dvpos
;
9441 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9442 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9444 int pt_old
= PT
- delta
;
9446 /* Skip over glyphs not having an object at the start of the row.
9447 These are special glyphs like truncation marks on terminal
9449 if (row
->displays_text_p
)
9451 && INTEGERP (glyph
->object
)
9452 && glyph
->charpos
< 0)
9454 x
+= glyph
->pixel_width
;
9459 && !INTEGERP (glyph
->object
)
9460 && (!BUFFERP (glyph
->object
)
9461 || glyph
->charpos
< pt_old
))
9463 x
+= glyph
->pixel_width
;
9467 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9469 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9470 w
->cursor
.y
= row
->y
+ dy
;
9472 if (w
== XWINDOW (selected_window
))
9474 if (!row
->continued_p
9475 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9478 this_line_buffer
= XBUFFER (w
->buffer
);
9480 CHARPOS (this_line_start_pos
)
9481 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9482 BYTEPOS (this_line_start_pos
)
9483 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9485 CHARPOS (this_line_end_pos
)
9486 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9487 BYTEPOS (this_line_end_pos
)
9488 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9490 this_line_y
= w
->cursor
.y
;
9491 this_line_pixel_height
= row
->height
;
9492 this_line_vpos
= w
->cursor
.vpos
;
9493 this_line_start_x
= row
->x
;
9496 CHARPOS (this_line_start_pos
) = 0;
9501 /* Run window scroll functions, if any, for WINDOW with new window
9502 start STARTP. Sets the window start of WINDOW to that position.
9504 We assume that the window's buffer is really current. */
9506 static INLINE
struct text_pos
9507 run_window_scroll_functions (window
, startp
)
9509 struct text_pos startp
;
9511 struct window
*w
= XWINDOW (window
);
9512 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9514 if (current_buffer
!= XBUFFER (w
->buffer
))
9517 if (!NILP (Vwindow_scroll_functions
))
9519 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9520 make_number (CHARPOS (startp
)));
9521 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9522 /* In case the hook functions switch buffers. */
9523 if (current_buffer
!= XBUFFER (w
->buffer
))
9524 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9531 /* Make sure the line containing the cursor is fully visible.
9532 A value of 1 means there is nothing to be done.
9533 (Either the line is fully visible, or it cannot be made so,
9535 A value of 0 means the caller should do scrolling
9536 as if point had gone off the screen. */
9539 make_cursor_line_fully_visible (w
)
9542 struct glyph_matrix
*matrix
;
9543 struct glyph_row
*row
;
9546 /* It's not always possible to find the cursor, e.g, when a window
9547 is full of overlay strings. Don't do anything in that case. */
9548 if (w
->cursor
.vpos
< 0)
9551 matrix
= w
->desired_matrix
;
9552 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9554 /* If the cursor row is not partially visible, there's nothing to do. */
9555 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9558 /* If the row the cursor is in is taller than the window's height,
9559 it's not clear what to do, so do nothing. */
9560 window_height
= window_box_height (w
);
9561 if (row
->height
>= window_height
)
9567 /* This code used to try to scroll the window just enough to make
9568 the line visible. It returned 0 to say that the caller should
9569 allocate larger glyph matrices. */
9571 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9573 int dy
= row
->height
- row
->visible_height
;
9576 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9578 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9580 int dy
= - (row
->height
- row
->visible_height
);
9583 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9586 /* When we change the cursor y-position of the selected window,
9587 change this_line_y as well so that the display optimization for
9588 the cursor line of the selected window in redisplay_internal uses
9589 the correct y-position. */
9590 if (w
== XWINDOW (selected_window
))
9591 this_line_y
= w
->cursor
.y
;
9593 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9594 redisplay with larger matrices. */
9595 if (matrix
->nrows
< required_matrix_height (w
))
9597 fonts_changed_p
= 1;
9606 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9607 non-zero means only WINDOW is redisplayed in redisplay_internal.
9608 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9609 in redisplay_window to bring a partially visible line into view in
9610 the case that only the cursor has moved.
9614 1 if scrolling succeeded
9616 0 if scrolling didn't find point.
9618 -1 if new fonts have been loaded so that we must interrupt
9619 redisplay, adjust glyph matrices, and try again. */
9625 SCROLLING_NEED_LARGER_MATRICES
9629 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9630 scroll_step
, temp_scroll_step
)
9632 int just_this_one_p
;
9633 EMACS_INT scroll_conservatively
, scroll_step
;
9634 int temp_scroll_step
;
9636 struct window
*w
= XWINDOW (window
);
9637 struct frame
*f
= XFRAME (w
->frame
);
9638 struct text_pos scroll_margin_pos
;
9639 struct text_pos pos
;
9640 struct text_pos startp
;
9642 Lisp_Object window_end
;
9643 int this_scroll_margin
;
9647 int amount_to_scroll
= 0;
9648 Lisp_Object aggressive
;
9652 debug_method_add (w
, "try_scrolling");
9655 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9657 /* Compute scroll margin height in pixels. We scroll when point is
9658 within this distance from the top or bottom of the window. */
9659 if (scroll_margin
> 0)
9661 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9662 this_scroll_margin
*= CANON_Y_UNIT (f
);
9665 this_scroll_margin
= 0;
9667 /* Compute how much we should try to scroll maximally to bring point
9669 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9670 scroll_max
= max (scroll_step
,
9671 max (scroll_conservatively
, temp_scroll_step
));
9672 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9673 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9674 /* We're trying to scroll because of aggressive scrolling
9675 but no scroll_step is set. Choose an arbitrary one. Maybe
9676 there should be a variable for this. */
9680 scroll_max
*= CANON_Y_UNIT (f
);
9682 /* Decide whether we have to scroll down. Start at the window end
9683 and move this_scroll_margin up to find the position of the scroll
9685 window_end
= Fwindow_end (window
, Qt
);
9686 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9687 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9688 if (this_scroll_margin
)
9690 start_display (&it
, w
, scroll_margin_pos
);
9691 move_it_vertically (&it
, - this_scroll_margin
);
9692 scroll_margin_pos
= it
.current
.pos
;
9695 if (PT
>= CHARPOS (scroll_margin_pos
))
9700 /* Point is in the scroll margin at the bottom of the window, or
9701 below. Compute a new window start that makes point visible. */
9703 /* Compute the distance from the scroll margin to PT.
9704 Give up if the distance is greater than scroll_max. */
9705 start_display (&it
, w
, scroll_margin_pos
);
9707 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9708 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9710 /* To make point visible, we have to move the window start
9711 down so that the line the cursor is in is visible, which
9712 means we have to add in the height of the cursor line. */
9713 dy
= line_bottom_y (&it
) - y0
;
9715 if (dy
> scroll_max
)
9716 return SCROLLING_FAILED
;
9718 /* Move the window start down. If scrolling conservatively,
9719 move it just enough down to make point visible. If
9720 scroll_step is set, move it down by scroll_step. */
9721 start_display (&it
, w
, startp
);
9723 if (scroll_conservatively
)
9725 = max (max (dy
, CANON_Y_UNIT (f
)),
9726 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9727 else if (scroll_step
|| temp_scroll_step
)
9728 amount_to_scroll
= scroll_max
;
9731 aggressive
= current_buffer
->scroll_up_aggressively
;
9732 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9733 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9734 if (NUMBERP (aggressive
))
9735 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9738 if (amount_to_scroll
<= 0)
9739 return SCROLLING_FAILED
;
9741 move_it_vertically (&it
, amount_to_scroll
);
9742 startp
= it
.current
.pos
;
9746 /* See if point is inside the scroll margin at the top of the
9748 scroll_margin_pos
= startp
;
9749 if (this_scroll_margin
)
9751 start_display (&it
, w
, startp
);
9752 move_it_vertically (&it
, this_scroll_margin
);
9753 scroll_margin_pos
= it
.current
.pos
;
9756 if (PT
< CHARPOS (scroll_margin_pos
))
9758 /* Point is in the scroll margin at the top of the window or
9759 above what is displayed in the window. */
9762 /* Compute the vertical distance from PT to the scroll
9763 margin position. Give up if distance is greater than
9765 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9766 start_display (&it
, w
, pos
);
9768 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9769 it
.last_visible_y
, -1,
9770 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9771 dy
= it
.current_y
- y0
;
9772 if (dy
> scroll_max
)
9773 return SCROLLING_FAILED
;
9775 /* Compute new window start. */
9776 start_display (&it
, w
, startp
);
9778 if (scroll_conservatively
)
9780 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9781 else if (scroll_step
|| temp_scroll_step
)
9782 amount_to_scroll
= scroll_max
;
9785 aggressive
= current_buffer
->scroll_down_aggressively
;
9786 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9787 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9788 if (NUMBERP (aggressive
))
9789 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9792 if (amount_to_scroll
<= 0)
9793 return SCROLLING_FAILED
;
9795 move_it_vertically (&it
, - amount_to_scroll
);
9796 startp
= it
.current
.pos
;
9800 /* Run window scroll functions. */
9801 startp
= run_window_scroll_functions (window
, startp
);
9803 /* Display the window. Give up if new fonts are loaded, or if point
9805 if (!try_window (window
, startp
))
9806 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9807 else if (w
->cursor
.vpos
< 0)
9809 clear_glyph_matrix (w
->desired_matrix
);
9810 rc
= SCROLLING_FAILED
;
9814 /* Maybe forget recorded base line for line number display. */
9815 if (!just_this_one_p
9816 || current_buffer
->clip_changed
9817 || BEG_UNCHANGED
< CHARPOS (startp
))
9818 w
->base_line_number
= Qnil
;
9820 /* If cursor ends up on a partially visible line,
9821 treat that as being off the bottom of the screen. */
9822 if (! make_cursor_line_fully_visible (w
))
9824 clear_glyph_matrix (w
->desired_matrix
);
9827 rc
= SCROLLING_SUCCESS
;
9834 /* Compute a suitable window start for window W if display of W starts
9835 on a continuation line. Value is non-zero if a new window start
9838 The new window start will be computed, based on W's width, starting
9839 from the start of the continued line. It is the start of the
9840 screen line with the minimum distance from the old start W->start. */
9843 compute_window_start_on_continuation_line (w
)
9846 struct text_pos pos
, start_pos
;
9847 int window_start_changed_p
= 0;
9849 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9851 /* If window start is on a continuation line... Window start may be
9852 < BEGV in case there's invisible text at the start of the
9853 buffer (M-x rmail, for example). */
9854 if (CHARPOS (start_pos
) > BEGV
9855 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9858 struct glyph_row
*row
;
9860 /* Handle the case that the window start is out of range. */
9861 if (CHARPOS (start_pos
) < BEGV
)
9862 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9863 else if (CHARPOS (start_pos
) > ZV
)
9864 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9866 /* Find the start of the continued line. This should be fast
9867 because scan_buffer is fast (newline cache). */
9868 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9869 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9870 row
, DEFAULT_FACE_ID
);
9871 reseat_at_previous_visible_line_start (&it
);
9873 /* If the line start is "too far" away from the window start,
9874 say it takes too much time to compute a new window start. */
9875 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9876 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9878 int min_distance
, distance
;
9880 /* Move forward by display lines to find the new window
9881 start. If window width was enlarged, the new start can
9882 be expected to be > the old start. If window width was
9883 decreased, the new window start will be < the old start.
9884 So, we're looking for the display line start with the
9885 minimum distance from the old window start. */
9886 pos
= it
.current
.pos
;
9887 min_distance
= INFINITY
;
9888 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9889 distance
< min_distance
)
9891 min_distance
= distance
;
9892 pos
= it
.current
.pos
;
9893 move_it_by_lines (&it
, 1, 0);
9896 /* Set the window start there. */
9897 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9898 window_start_changed_p
= 1;
9902 return window_start_changed_p
;
9906 /* Try cursor movement in case text has not changed in window WINDOW,
9907 with window start STARTP. Value is
9909 CURSOR_MOVEMENT_SUCCESS if successful
9911 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
9913 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
9914 display. *SCROLL_STEP is set to 1, under certain circumstances, if
9915 we want to scroll as if scroll-step were set to 1. See the code.
9917 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
9918 which case we have to abort this redisplay, and adjust matrices
9923 CURSOR_MOVEMENT_SUCCESS
,
9924 CURSOR_MOVEMENT_CANNOT_BE_USED
,
9925 CURSOR_MOVEMENT_MUST_SCROLL
,
9926 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
9930 try_cursor_movement (window
, startp
, scroll_step
)
9932 struct text_pos startp
;
9935 struct window
*w
= XWINDOW (window
);
9936 struct frame
*f
= XFRAME (w
->frame
);
9937 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
9940 if (inhibit_try_cursor_movement
)
9944 /* Handle case where text has not changed, only point, and it has
9945 not moved off the frame. */
9946 if (/* Point may be in this window. */
9947 PT
>= CHARPOS (startp
)
9948 /* Selective display hasn't changed. */
9949 && !current_buffer
->clip_changed
9950 /* Function force-mode-line-update is used to force a thorough
9951 redisplay. It sets either windows_or_buffers_changed or
9952 update_mode_lines. So don't take a shortcut here for these
9954 && !update_mode_lines
9955 && !windows_or_buffers_changed
9956 && !cursor_type_changed
9957 /* Can't use this case if highlighting a region. When a
9958 region exists, cursor movement has to do more than just
9960 && !(!NILP (Vtransient_mark_mode
)
9961 && !NILP (current_buffer
->mark_active
))
9962 && NILP (w
->region_showing
)
9963 && NILP (Vshow_trailing_whitespace
)
9964 /* Right after splitting windows, last_point may be nil. */
9965 && INTEGERP (w
->last_point
)
9966 /* This code is not used for mini-buffer for the sake of the case
9967 of redisplaying to replace an echo area message; since in
9968 that case the mini-buffer contents per se are usually
9969 unchanged. This code is of no real use in the mini-buffer
9970 since the handling of this_line_start_pos, etc., in redisplay
9971 handles the same cases. */
9972 && !EQ (window
, minibuf_window
)
9973 /* When splitting windows or for new windows, it happens that
9974 redisplay is called with a nil window_end_vpos or one being
9975 larger than the window. This should really be fixed in
9976 window.c. I don't have this on my list, now, so we do
9977 approximately the same as the old redisplay code. --gerd. */
9978 && INTEGERP (w
->window_end_vpos
)
9979 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9980 && (FRAME_WINDOW_P (f
)
9981 || !MARKERP (Voverlay_arrow_position
)
9982 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9984 int this_scroll_margin
;
9985 struct glyph_row
*row
= NULL
;
9988 debug_method_add (w
, "cursor movement");
9991 /* Scroll if point within this distance from the top or bottom
9992 of the window. This is a pixel value. */
9993 this_scroll_margin
= max (0, scroll_margin
);
9994 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9995 this_scroll_margin
*= CANON_Y_UNIT (f
);
9997 /* Start with the row the cursor was displayed during the last
9998 not paused redisplay. Give up if that row is not valid. */
9999 if (w
->last_cursor
.vpos
< 0
10000 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
10001 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10004 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
10005 if (row
->mode_line_p
)
10007 if (!row
->enabled_p
)
10008 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10011 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
10014 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
10016 if (PT
> XFASTINT (w
->last_point
))
10018 /* Point has moved forward. */
10019 while (MATRIX_ROW_END_CHARPOS (row
) < PT
10020 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
10022 xassert (row
->enabled_p
);
10026 /* The end position of a row equals the start position
10027 of the next row. If PT is there, we would rather
10028 display it in the next line. */
10029 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
10030 && MATRIX_ROW_END_CHARPOS (row
) == PT
10031 && !cursor_row_p (w
, row
))
10034 /* If within the scroll margin, scroll. Note that
10035 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
10036 the next line would be drawn, and that
10037 this_scroll_margin can be zero. */
10038 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
10039 || PT
> MATRIX_ROW_END_CHARPOS (row
)
10040 /* Line is completely visible last line in window
10041 and PT is to be set in the next line. */
10042 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
10043 && PT
== MATRIX_ROW_END_CHARPOS (row
)
10044 && !row
->ends_at_zv_p
10045 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
10048 else if (PT
< XFASTINT (w
->last_point
))
10050 /* Cursor has to be moved backward. Note that PT >=
10051 CHARPOS (startp) because of the outer
10053 while (!row
->mode_line_p
10054 && (MATRIX_ROW_START_CHARPOS (row
) > PT
10055 || (MATRIX_ROW_START_CHARPOS (row
) == PT
10056 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
10057 && (row
->y
> this_scroll_margin
10058 || CHARPOS (startp
) == BEGV
))
10060 xassert (row
->enabled_p
);
10064 /* Consider the following case: Window starts at BEGV,
10065 there is invisible, intangible text at BEGV, so that
10066 display starts at some point START > BEGV. It can
10067 happen that we are called with PT somewhere between
10068 BEGV and START. Try to handle that case. */
10069 if (row
< w
->current_matrix
->rows
10070 || row
->mode_line_p
)
10072 row
= w
->current_matrix
->rows
;
10073 if (row
->mode_line_p
)
10077 /* Due to newlines in overlay strings, we may have to
10078 skip forward over overlay strings. */
10079 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
10080 && MATRIX_ROW_END_CHARPOS (row
) == PT
10081 && !cursor_row_p (w
, row
))
10084 /* If within the scroll margin, scroll. */
10085 if (row
->y
< this_scroll_margin
10086 && CHARPOS (startp
) != BEGV
)
10090 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
10091 || PT
> MATRIX_ROW_END_CHARPOS (row
))
10093 /* if PT is not in the glyph row, give up. */
10094 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10096 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10098 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
10099 && !row
->ends_at_zv_p
10100 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
10101 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10102 else if (row
->height
> window_box_height (w
))
10104 /* If we end up in a partially visible line, let's
10105 make it fully visible, except when it's taller
10106 than the window, in which case we can't do much
10109 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10113 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10114 if (!make_cursor_line_fully_visible (w
))
10115 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10117 rc
= CURSOR_MOVEMENT_SUCCESS
;
10121 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10124 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10125 rc
= CURSOR_MOVEMENT_SUCCESS
;
10134 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
10135 selected_window is redisplayed.
10137 We can return without actually redisplaying the window if
10138 fonts_changed_p is nonzero. In that case, redisplay_internal will
10142 redisplay_window (window
, just_this_one_p
)
10143 Lisp_Object window
;
10144 int just_this_one_p
;
10146 struct window
*w
= XWINDOW (window
);
10147 struct frame
*f
= XFRAME (w
->frame
);
10148 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10149 struct buffer
*old
= current_buffer
;
10150 struct text_pos lpoint
, opoint
, startp
;
10151 int update_mode_line
;
10154 /* Record it now because it's overwritten. */
10155 int current_matrix_up_to_date_p
= 0;
10156 /* This is less strict than current_matrix_up_to_date_p.
10157 It indictes that the buffer contents and narrowing are unchanged. */
10158 int buffer_unchanged_p
= 0;
10159 int temp_scroll_step
= 0;
10160 int count
= SPECPDL_INDEX ();
10162 int centering_position
;
10164 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10167 /* W must be a leaf window here. */
10168 xassert (!NILP (w
->buffer
));
10170 *w
->desired_matrix
->method
= 0;
10173 specbind (Qinhibit_point_motion_hooks
, Qt
);
10175 reconsider_clip_changes (w
, buffer
);
10177 /* Has the mode line to be updated? */
10178 update_mode_line
= (!NILP (w
->update_mode_line
)
10179 || update_mode_lines
10180 || buffer
->clip_changed
10181 || buffer
->prevent_redisplay_optimizations_p
);
10183 if (MINI_WINDOW_P (w
))
10185 if (w
== XWINDOW (echo_area_window
)
10186 && !NILP (echo_area_buffer
[0]))
10188 if (update_mode_line
)
10189 /* We may have to update a tty frame's menu bar or a
10190 tool-bar. Example `M-x C-h C-h C-g'. */
10191 goto finish_menu_bars
;
10193 /* We've already displayed the echo area glyphs in this window. */
10194 goto finish_scroll_bars
;
10196 else if (w
!= XWINDOW (minibuf_window
)
10197 || minibuf_level
== 0)
10199 /* W is a mini-buffer window, but it's not the currently
10200 active one, so clear it. */
10201 int yb
= window_text_bottom_y (w
);
10202 struct glyph_row
*row
;
10205 for (y
= 0, row
= w
->desired_matrix
->rows
;
10207 y
+= row
->height
, ++row
)
10208 blank_row (w
, row
, y
);
10209 goto finish_scroll_bars
;
10212 clear_glyph_matrix (w
->desired_matrix
);
10215 /* Otherwise set up data on this window; select its buffer and point
10217 /* Really select the buffer, for the sake of buffer-local
10219 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10220 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
10222 current_matrix_up_to_date_p
10223 = (!NILP (w
->window_end_valid
)
10224 && !current_buffer
->clip_changed
10225 && !current_buffer
->prevent_redisplay_optimizations_p
10226 && XFASTINT (w
->last_modified
) >= MODIFF
10227 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10230 = (!NILP (w
->window_end_valid
)
10231 && !current_buffer
->clip_changed
10232 && XFASTINT (w
->last_modified
) >= MODIFF
10233 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10235 /* When windows_or_buffers_changed is non-zero, we can't rely on
10236 the window end being valid, so set it to nil there. */
10237 if (windows_or_buffers_changed
)
10239 /* If window starts on a continuation line, maybe adjust the
10240 window start in case the window's width changed. */
10241 if (XMARKER (w
->start
)->buffer
== current_buffer
)
10242 compute_window_start_on_continuation_line (w
);
10244 w
->window_end_valid
= Qnil
;
10247 /* Some sanity checks. */
10248 CHECK_WINDOW_END (w
);
10249 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
10251 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
10254 /* If %c is in mode line, update it if needed. */
10255 if (!NILP (w
->column_number_displayed
)
10256 /* This alternative quickly identifies a common case
10257 where no change is needed. */
10258 && !(PT
== XFASTINT (w
->last_point
)
10259 && XFASTINT (w
->last_modified
) >= MODIFF
10260 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10261 && (XFASTINT (w
->column_number_displayed
)
10262 != (int) current_column ())) /* iftc */
10263 update_mode_line
= 1;
10265 /* Count number of windows showing the selected buffer. An indirect
10266 buffer counts as its base buffer. */
10267 if (!just_this_one_p
)
10269 struct buffer
*current_base
, *window_base
;
10270 current_base
= current_buffer
;
10271 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10272 if (current_base
->base_buffer
)
10273 current_base
= current_base
->base_buffer
;
10274 if (window_base
->base_buffer
)
10275 window_base
= window_base
->base_buffer
;
10276 if (current_base
== window_base
)
10280 /* Point refers normally to the selected window. For any other
10281 window, set up appropriate value. */
10282 if (!EQ (window
, selected_window
))
10284 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10285 int new_pt_byte
= marker_byte_position (w
->pointm
);
10289 new_pt_byte
= BEGV_BYTE
;
10290 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10292 else if (new_pt
> (ZV
- 1))
10295 new_pt_byte
= ZV_BYTE
;
10296 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10299 /* We don't use SET_PT so that the point-motion hooks don't run. */
10300 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10303 /* If any of the character widths specified in the display table
10304 have changed, invalidate the width run cache. It's true that
10305 this may be a bit late to catch such changes, but the rest of
10306 redisplay goes (non-fatally) haywire when the display table is
10307 changed, so why should we worry about doing any better? */
10308 if (current_buffer
->width_run_cache
)
10310 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10312 if (! disptab_matches_widthtab (disptab
,
10313 XVECTOR (current_buffer
->width_table
)))
10315 invalidate_region_cache (current_buffer
,
10316 current_buffer
->width_run_cache
,
10318 recompute_width_table (current_buffer
, disptab
);
10322 /* If window-start is screwed up, choose a new one. */
10323 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10326 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10328 /* If someone specified a new starting point but did not insist,
10329 check whether it can be used. */
10330 if (!NILP (w
->optional_new_start
)
10331 && CHARPOS (startp
) >= BEGV
10332 && CHARPOS (startp
) <= ZV
)
10334 w
->optional_new_start
= Qnil
;
10335 start_display (&it
, w
, startp
);
10336 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10337 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10338 if (IT_CHARPOS (it
) == PT
)
10339 w
->force_start
= Qt
;
10342 /* Handle case where place to start displaying has been specified,
10343 unless the specified location is outside the accessible range. */
10344 if (!NILP (w
->force_start
)
10345 || w
->frozen_window_start_p
)
10347 /* We set this later on if we have to adjust point. */
10350 w
->force_start
= Qnil
;
10352 w
->window_end_valid
= Qnil
;
10354 /* Forget any recorded base line for line number display. */
10355 if (!buffer_unchanged_p
)
10356 w
->base_line_number
= Qnil
;
10358 /* Redisplay the mode line. Select the buffer properly for that.
10359 Also, run the hook window-scroll-functions
10360 because we have scrolled. */
10361 /* Note, we do this after clearing force_start because
10362 if there's an error, it is better to forget about force_start
10363 than to get into an infinite loop calling the hook functions
10364 and having them get more errors. */
10365 if (!update_mode_line
10366 || ! NILP (Vwindow_scroll_functions
))
10368 update_mode_line
= 1;
10369 w
->update_mode_line
= Qt
;
10370 startp
= run_window_scroll_functions (window
, startp
);
10373 w
->last_modified
= make_number (0);
10374 w
->last_overlay_modified
= make_number (0);
10375 if (CHARPOS (startp
) < BEGV
)
10376 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10377 else if (CHARPOS (startp
) > ZV
)
10378 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10380 /* Redisplay, then check if cursor has been set during the
10381 redisplay. Give up if new fonts were loaded. */
10382 if (!try_window (window
, startp
))
10384 w
->force_start
= Qt
;
10385 clear_glyph_matrix (w
->desired_matrix
);
10386 goto need_larger_matrices
;
10389 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10391 /* If point does not appear, try to move point so it does
10392 appear. The desired matrix has been built above, so we
10393 can use it here. */
10394 new_vpos
= window_box_height (w
) / 2;
10397 if (!make_cursor_line_fully_visible (w
))
10399 /* Point does appear, but on a line partly visible at end of window.
10400 Move it back to a fully-visible line. */
10401 new_vpos
= window_box_height (w
);
10404 /* If we need to move point for either of the above reasons,
10405 now actually do it. */
10408 struct glyph_row
*row
;
10410 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10411 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
10414 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10415 MATRIX_ROW_START_BYTEPOS (row
));
10417 if (w
!= XWINDOW (selected_window
))
10418 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10419 else if (current_buffer
== old
)
10420 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10422 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10424 /* If we are highlighting the region, then we just changed
10425 the region, so redisplay to show it. */
10426 if (!NILP (Vtransient_mark_mode
)
10427 && !NILP (current_buffer
->mark_active
))
10429 clear_glyph_matrix (w
->desired_matrix
);
10430 if (!try_window (window
, startp
))
10431 goto need_larger_matrices
;
10436 debug_method_add (w
, "forced window start");
10441 /* Handle case where text has not changed, only point, and it has
10442 not moved off the frame, and we are not retrying after hscroll.
10443 (current_matrix_up_to_date_p is nonzero when retrying.) */
10444 if (current_matrix_up_to_date_p
10445 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10446 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10450 case CURSOR_MOVEMENT_SUCCESS
:
10453 #if 0 /* try_cursor_movement never returns this value. */
10454 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10455 goto need_larger_matrices
;
10458 case CURSOR_MOVEMENT_MUST_SCROLL
:
10459 goto try_to_scroll
;
10465 /* If current starting point was originally the beginning of a line
10466 but no longer is, find a new starting point. */
10467 else if (!NILP (w
->start_at_line_beg
)
10468 && !(CHARPOS (startp
) <= BEGV
10469 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10472 debug_method_add (w
, "recenter 1");
10477 /* Try scrolling with try_window_id. Value is > 0 if update has
10478 been done, it is -1 if we know that the same window start will
10479 not work. It is 0 if unsuccessful for some other reason. */
10480 else if ((tem
= try_window_id (w
)) != 0)
10483 debug_method_add (w
, "try_window_id %d", tem
);
10486 if (fonts_changed_p
)
10487 goto need_larger_matrices
;
10491 /* Otherwise try_window_id has returned -1 which means that we
10492 don't want the alternative below this comment to execute. */
10494 else if (CHARPOS (startp
) >= BEGV
10495 && CHARPOS (startp
) <= ZV
10496 && PT
>= CHARPOS (startp
)
10497 && (CHARPOS (startp
) < ZV
10498 /* Avoid starting at end of buffer. */
10499 || CHARPOS (startp
) == BEGV
10500 || (XFASTINT (w
->last_modified
) >= MODIFF
10501 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10504 debug_method_add (w
, "same window start");
10507 /* Try to redisplay starting at same place as before.
10508 If point has not moved off frame, accept the results. */
10509 if (!current_matrix_up_to_date_p
10510 /* Don't use try_window_reusing_current_matrix in this case
10511 because a window scroll function can have changed the
10513 || !NILP (Vwindow_scroll_functions
)
10514 || MINI_WINDOW_P (w
)
10515 || !try_window_reusing_current_matrix (w
))
10517 IF_DEBUG (debug_method_add (w
, "1"));
10518 try_window (window
, startp
);
10521 if (fonts_changed_p
)
10522 goto need_larger_matrices
;
10524 if (w
->cursor
.vpos
>= 0)
10526 if (!just_this_one_p
10527 || current_buffer
->clip_changed
10528 || BEG_UNCHANGED
< CHARPOS (startp
))
10529 /* Forget any recorded base line for line number display. */
10530 w
->base_line_number
= Qnil
;
10532 if (!make_cursor_line_fully_visible (w
))
10533 clear_glyph_matrix (w
->desired_matrix
);
10534 /* Drop through and scroll. */
10539 clear_glyph_matrix (w
->desired_matrix
);
10544 w
->last_modified
= make_number (0);
10545 w
->last_overlay_modified
= make_number (0);
10547 /* Redisplay the mode line. Select the buffer properly for that. */
10548 if (!update_mode_line
)
10550 update_mode_line
= 1;
10551 w
->update_mode_line
= Qt
;
10554 /* Try to scroll by specified few lines. */
10555 if ((scroll_conservatively
10557 || temp_scroll_step
10558 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10559 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10560 && !current_buffer
->clip_changed
10561 && CHARPOS (startp
) >= BEGV
10562 && CHARPOS (startp
) <= ZV
)
10564 /* The function returns -1 if new fonts were loaded, 1 if
10565 successful, 0 if not successful. */
10566 int rc
= try_scrolling (window
, just_this_one_p
,
10567 scroll_conservatively
,
10572 case SCROLLING_SUCCESS
:
10575 case SCROLLING_NEED_LARGER_MATRICES
:
10576 goto need_larger_matrices
;
10578 case SCROLLING_FAILED
:
10586 /* Finally, just choose place to start which centers point */
10589 centering_position
= window_box_height (w
) / 2;
10592 /* Jump here with centering_position already set to 0. */
10595 debug_method_add (w
, "recenter");
10598 /* w->vscroll = 0; */
10600 /* Forget any previously recorded base line for line number display. */
10601 if (!buffer_unchanged_p
)
10602 w
->base_line_number
= Qnil
;
10604 /* Move backward half the height of the window. */
10605 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10606 it
.current_y
= it
.last_visible_y
;
10607 move_it_vertically_backward (&it
, centering_position
);
10608 xassert (IT_CHARPOS (it
) >= BEGV
);
10610 /* The function move_it_vertically_backward may move over more
10611 than the specified y-distance. If it->w is small, e.g. a
10612 mini-buffer window, we may end up in front of the window's
10613 display area. Start displaying at the start of the line
10614 containing PT in this case. */
10615 if (it
.current_y
<= 0)
10617 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10618 move_it_vertically (&it
, 0);
10619 xassert (IT_CHARPOS (it
) <= PT
);
10623 it
.current_x
= it
.hpos
= 0;
10625 /* Set startp here explicitly in case that helps avoid an infinite loop
10626 in case the window-scroll-functions functions get errors. */
10627 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10629 /* Run scroll hooks. */
10630 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10632 /* Redisplay the window. */
10633 if (!current_matrix_up_to_date_p
10634 || windows_or_buffers_changed
10635 || cursor_type_changed
10636 /* Don't use try_window_reusing_current_matrix in this case
10637 because it can have changed the buffer. */
10638 || !NILP (Vwindow_scroll_functions
)
10639 || !just_this_one_p
10640 || MINI_WINDOW_P (w
)
10641 || !try_window_reusing_current_matrix (w
))
10642 try_window (window
, startp
);
10644 /* If new fonts have been loaded (due to fontsets), give up. We
10645 have to start a new redisplay since we need to re-adjust glyph
10647 if (fonts_changed_p
)
10648 goto need_larger_matrices
;
10650 /* If cursor did not appear assume that the middle of the window is
10651 in the first line of the window. Do it again with the next line.
10652 (Imagine a window of height 100, displaying two lines of height
10653 60. Moving back 50 from it->last_visible_y will end in the first
10655 if (w
->cursor
.vpos
< 0)
10657 if (!NILP (w
->window_end_valid
)
10658 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10660 clear_glyph_matrix (w
->desired_matrix
);
10661 move_it_by_lines (&it
, 1, 0);
10662 try_window (window
, it
.current
.pos
);
10664 else if (PT
< IT_CHARPOS (it
))
10666 clear_glyph_matrix (w
->desired_matrix
);
10667 move_it_by_lines (&it
, -1, 0);
10668 try_window (window
, it
.current
.pos
);
10672 /* Not much we can do about it. */
10676 /* Consider the following case: Window starts at BEGV, there is
10677 invisible, intangible text at BEGV, so that display starts at
10678 some point START > BEGV. It can happen that we are called with
10679 PT somewhere between BEGV and START. Try to handle that case. */
10680 if (w
->cursor
.vpos
< 0)
10682 struct glyph_row
*row
= w
->current_matrix
->rows
;
10683 if (row
->mode_line_p
)
10685 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10688 if (!make_cursor_line_fully_visible (w
))
10690 /* If centering point failed to make the whole line visible,
10691 put point at the top instead. That has to make the whole line
10692 visible, if it can be done. */
10693 centering_position
= 0;
10699 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10700 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10701 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10704 /* Display the mode line, if we must. */
10705 if ((update_mode_line
10706 /* If window not full width, must redo its mode line
10707 if (a) the window to its side is being redone and
10708 (b) we do a frame-based redisplay. This is a consequence
10709 of how inverted lines are drawn in frame-based redisplay. */
10710 || (!just_this_one_p
10711 && !FRAME_WINDOW_P (f
)
10712 && !WINDOW_FULL_WIDTH_P (w
))
10713 /* Line number to display. */
10714 || INTEGERP (w
->base_line_pos
)
10715 /* Column number is displayed and different from the one displayed. */
10716 || (!NILP (w
->column_number_displayed
)
10717 && (XFASTINT (w
->column_number_displayed
)
10718 != (int) current_column ()))) /* iftc */
10719 /* This means that the window has a mode line. */
10720 && (WINDOW_WANTS_MODELINE_P (w
)
10721 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10723 display_mode_lines (w
);
10725 /* If mode line height has changed, arrange for a thorough
10726 immediate redisplay using the correct mode line height. */
10727 if (WINDOW_WANTS_MODELINE_P (w
)
10728 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10730 fonts_changed_p
= 1;
10731 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10732 = DESIRED_MODE_LINE_HEIGHT (w
);
10735 /* If top line height has changed, arrange for a thorough
10736 immediate redisplay using the correct mode line height. */
10737 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10738 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10740 fonts_changed_p
= 1;
10741 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10742 = DESIRED_HEADER_LINE_HEIGHT (w
);
10745 if (fonts_changed_p
)
10746 goto need_larger_matrices
;
10749 if (!line_number_displayed
10750 && !BUFFERP (w
->base_line_pos
))
10752 w
->base_line_pos
= Qnil
;
10753 w
->base_line_number
= Qnil
;
10758 /* When we reach a frame's selected window, redo the frame's menu bar. */
10759 if (update_mode_line
10760 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10762 int redisplay_menu_p
= 0;
10764 if (FRAME_WINDOW_P (f
))
10766 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
10767 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10769 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10773 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10775 if (redisplay_menu_p
)
10776 display_menu_bar (w
);
10778 #ifdef HAVE_WINDOW_SYSTEM
10779 if (WINDOWP (f
->tool_bar_window
)
10780 && (FRAME_TOOL_BAR_LINES (f
) > 0
10781 || auto_resize_tool_bars_p
))
10782 redisplay_tool_bar (f
);
10786 /* We go to this label, with fonts_changed_p nonzero,
10787 if it is necessary to try again using larger glyph matrices.
10788 We have to redeem the scroll bar even in this case,
10789 because the loop in redisplay_internal expects that. */
10790 need_larger_matrices
:
10792 finish_scroll_bars
:
10794 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10796 int start
, end
, whole
;
10798 /* Calculate the start and end positions for the current window.
10799 At some point, it would be nice to choose between scrollbars
10800 which reflect the whole buffer size, with special markers
10801 indicating narrowing, and scrollbars which reflect only the
10804 Note that mini-buffers sometimes aren't displaying any text. */
10805 if (!MINI_WINDOW_P (w
)
10806 || (w
== XWINDOW (minibuf_window
)
10807 && NILP (echo_area_buffer
[0])))
10810 start
= marker_position (w
->start
) - BEGV
;
10811 /* I don't think this is guaranteed to be right. For the
10812 moment, we'll pretend it is. */
10813 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10817 if (whole
< (end
- start
))
10818 whole
= end
- start
;
10821 start
= end
= whole
= 0;
10823 /* Indicate what this scroll bar ought to be displaying now. */
10824 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10826 /* Note that we actually used the scroll bar attached to this
10827 window, so it shouldn't be deleted at the end of redisplay. */
10828 redeem_scroll_bar_hook (w
);
10831 /* Restore current_buffer and value of point in it. */
10832 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10833 set_buffer_internal_1 (old
);
10834 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10836 unbind_to (count
, Qnil
);
10840 /* Build the complete desired matrix of WINDOW with a window start
10841 buffer position POS. Value is non-zero if successful. It is zero
10842 if fonts were loaded during redisplay which makes re-adjusting
10843 glyph matrices necessary. */
10846 try_window (window
, pos
)
10847 Lisp_Object window
;
10848 struct text_pos pos
;
10850 struct window
*w
= XWINDOW (window
);
10852 struct glyph_row
*last_text_row
= NULL
;
10854 /* Make POS the new window start. */
10855 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10857 /* Mark cursor position as unknown. No overlay arrow seen. */
10858 w
->cursor
.vpos
= -1;
10859 overlay_arrow_seen
= 0;
10861 /* Initialize iterator and info to start at POS. */
10862 start_display (&it
, w
, pos
);
10864 /* Display all lines of W. */
10865 while (it
.current_y
< it
.last_visible_y
)
10867 if (display_line (&it
))
10868 last_text_row
= it
.glyph_row
- 1;
10869 if (fonts_changed_p
)
10873 /* If bottom moved off end of frame, change mode line percentage. */
10874 if (XFASTINT (w
->window_end_pos
) <= 0
10875 && Z
!= IT_CHARPOS (it
))
10876 w
->update_mode_line
= Qt
;
10878 /* Set window_end_pos to the offset of the last character displayed
10879 on the window from the end of current_buffer. Set
10880 window_end_vpos to its row number. */
10883 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10884 w
->window_end_bytepos
10885 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10887 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10889 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10890 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10891 ->displays_text_p
);
10895 w
->window_end_bytepos
= 0;
10896 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10899 /* But that is not valid info until redisplay finishes. */
10900 w
->window_end_valid
= Qnil
;
10906 /************************************************************************
10907 Window redisplay reusing current matrix when buffer has not changed
10908 ************************************************************************/
10910 /* Try redisplay of window W showing an unchanged buffer with a
10911 different window start than the last time it was displayed by
10912 reusing its current matrix. Value is non-zero if successful.
10913 W->start is the new window start. */
10916 try_window_reusing_current_matrix (w
)
10919 struct frame
*f
= XFRAME (w
->frame
);
10920 struct glyph_row
*row
, *bottom_row
;
10923 struct text_pos start
, new_start
;
10924 int nrows_scrolled
, i
;
10925 struct glyph_row
*last_text_row
;
10926 struct glyph_row
*last_reused_text_row
;
10927 struct glyph_row
*start_row
;
10928 int start_vpos
, min_y
, max_y
;
10931 if (inhibit_try_window_reusing
)
10935 if (/* This function doesn't handle terminal frames. */
10936 !FRAME_WINDOW_P (f
)
10937 /* Don't try to reuse the display if windows have been split
10939 || windows_or_buffers_changed
10940 || cursor_type_changed
)
10943 /* Can't do this if region may have changed. */
10944 if ((!NILP (Vtransient_mark_mode
)
10945 && !NILP (current_buffer
->mark_active
))
10946 || !NILP (w
->region_showing
)
10947 || !NILP (Vshow_trailing_whitespace
))
10950 /* If top-line visibility has changed, give up. */
10951 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10952 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10955 /* Give up if old or new display is scrolled vertically. We could
10956 make this function handle this, but right now it doesn't. */
10957 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10958 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10961 /* The variable new_start now holds the new window start. The old
10962 start `start' can be determined from the current matrix. */
10963 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10964 start
= start_row
->start
.pos
;
10965 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10967 /* Clear the desired matrix for the display below. */
10968 clear_glyph_matrix (w
->desired_matrix
);
10970 if (CHARPOS (new_start
) <= CHARPOS (start
))
10974 /* Don't use this method if the display starts with an ellipsis
10975 displayed for invisible text. It's not easy to handle that case
10976 below, and it's certainly not worth the effort since this is
10977 not a frequent case. */
10978 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10981 IF_DEBUG (debug_method_add (w
, "twu1"));
10983 /* Display up to a row that can be reused. The variable
10984 last_text_row is set to the last row displayed that displays
10985 text. Note that it.vpos == 0 if or if not there is a
10986 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10987 start_display (&it
, w
, new_start
);
10988 first_row_y
= it
.current_y
;
10989 w
->cursor
.vpos
= -1;
10990 last_text_row
= last_reused_text_row
= NULL
;
10992 while (it
.current_y
< it
.last_visible_y
10993 && IT_CHARPOS (it
) < CHARPOS (start
)
10994 && !fonts_changed_p
)
10995 if (display_line (&it
))
10996 last_text_row
= it
.glyph_row
- 1;
10998 /* A value of current_y < last_visible_y means that we stopped
10999 at the previous window start, which in turn means that we
11000 have at least one reusable row. */
11001 if (it
.current_y
< it
.last_visible_y
)
11003 /* IT.vpos always starts from 0; it counts text lines. */
11004 nrows_scrolled
= it
.vpos
;
11006 /* Find PT if not already found in the lines displayed. */
11007 if (w
->cursor
.vpos
< 0)
11009 int dy
= it
.current_y
- first_row_y
;
11011 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11012 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
11014 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
11015 dy
, nrows_scrolled
);
11018 clear_glyph_matrix (w
->desired_matrix
);
11023 /* Scroll the display. Do it before the current matrix is
11024 changed. The problem here is that update has not yet
11025 run, i.e. part of the current matrix is not up to date.
11026 scroll_run_hook will clear the cursor, and use the
11027 current matrix to get the height of the row the cursor is
11029 run
.current_y
= first_row_y
;
11030 run
.desired_y
= it
.current_y
;
11031 run
.height
= it
.last_visible_y
- it
.current_y
;
11033 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
11036 rif
->update_window_begin_hook (w
);
11037 rif
->clear_mouse_face (w
);
11038 rif
->scroll_run_hook (w
, &run
);
11039 rif
->update_window_end_hook (w
, 0, 0);
11043 /* Shift current matrix down by nrows_scrolled lines. */
11044 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11045 rotate_matrix (w
->current_matrix
,
11047 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11050 /* Disable lines that must be updated. */
11051 for (i
= 0; i
< it
.vpos
; ++i
)
11052 (start_row
+ i
)->enabled_p
= 0;
11054 /* Re-compute Y positions. */
11055 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11056 max_y
= it
.last_visible_y
;
11057 for (row
= start_row
+ nrows_scrolled
;
11061 row
->y
= it
.current_y
;
11062 row
->visible_height
= row
->height
;
11064 if (row
->y
< min_y
)
11065 row
->visible_height
-= min_y
- row
->y
;
11066 if (row
->y
+ row
->height
> max_y
)
11067 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11069 it
.current_y
+= row
->height
;
11071 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11072 last_reused_text_row
= row
;
11073 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
11077 /* Disable lines in the current matrix which are now
11078 below the window. */
11079 for (++row
; row
< bottom_row
; ++row
)
11080 row
->enabled_p
= 0;
11083 /* Update window_end_pos etc.; last_reused_text_row is the last
11084 reused row from the current matrix containing text, if any.
11085 The value of last_text_row is the last displayed line
11086 containing text. */
11087 if (last_reused_text_row
)
11089 w
->window_end_bytepos
11090 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
11092 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
11094 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
11095 w
->current_matrix
));
11097 else if (last_text_row
)
11099 w
->window_end_bytepos
11100 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11102 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11104 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11108 /* This window must be completely empty. */
11109 w
->window_end_bytepos
= 0;
11110 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
11112 w
->window_end_valid
= Qnil
;
11114 /* Update hint: don't try scrolling again in update_window. */
11115 w
->desired_matrix
->no_scrolling_p
= 1;
11118 debug_method_add (w
, "try_window_reusing_current_matrix 1");
11122 else if (CHARPOS (new_start
) > CHARPOS (start
))
11124 struct glyph_row
*pt_row
, *row
;
11125 struct glyph_row
*first_reusable_row
;
11126 struct glyph_row
*first_row_to_display
;
11128 int yb
= window_text_bottom_y (w
);
11130 /* Find the row starting at new_start, if there is one. Don't
11131 reuse a partially visible line at the end. */
11132 first_reusable_row
= start_row
;
11133 while (first_reusable_row
->enabled_p
11134 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
11135 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11136 < CHARPOS (new_start
)))
11137 ++first_reusable_row
;
11139 /* Give up if there is no row to reuse. */
11140 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
11141 || !first_reusable_row
->enabled_p
11142 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11143 != CHARPOS (new_start
)))
11146 /* We can reuse fully visible rows beginning with
11147 first_reusable_row to the end of the window. Set
11148 first_row_to_display to the first row that cannot be reused.
11149 Set pt_row to the row containing point, if there is any. */
11151 for (first_row_to_display
= first_reusable_row
;
11152 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
11153 ++first_row_to_display
)
11155 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
11156 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
11157 pt_row
= first_row_to_display
;
11160 /* Start displaying at the start of first_row_to_display. */
11161 xassert (first_row_to_display
->y
< yb
);
11162 init_to_row_start (&it
, w
, first_row_to_display
);
11164 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
11166 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
11168 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
11169 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
11171 /* Display lines beginning with first_row_to_display in the
11172 desired matrix. Set last_text_row to the last row displayed
11173 that displays text. */
11174 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
11175 if (pt_row
== NULL
)
11176 w
->cursor
.vpos
= -1;
11177 last_text_row
= NULL
;
11178 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
11179 if (display_line (&it
))
11180 last_text_row
= it
.glyph_row
- 1;
11182 /* Give up If point isn't in a row displayed or reused. */
11183 if (w
->cursor
.vpos
< 0)
11185 clear_glyph_matrix (w
->desired_matrix
);
11189 /* If point is in a reused row, adjust y and vpos of the cursor
11193 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
11194 w
->current_matrix
);
11195 w
->cursor
.y
-= first_reusable_row
->y
;
11198 /* Scroll the display. */
11199 run
.current_y
= first_reusable_row
->y
;
11200 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11201 run
.height
= it
.last_visible_y
- run
.current_y
;
11202 dy
= run
.current_y
- run
.desired_y
;
11206 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11208 rif
->update_window_begin_hook (w
);
11209 rif
->clear_mouse_face (w
);
11210 rif
->scroll_run_hook (w
, &run
);
11211 rif
->update_window_end_hook (w
, 0, 0);
11215 /* Adjust Y positions of reused rows. */
11216 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11217 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11218 max_y
= it
.last_visible_y
;
11219 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
11222 row
->visible_height
= row
->height
;
11223 if (row
->y
< min_y
)
11224 row
->visible_height
-= min_y
- row
->y
;
11225 if (row
->y
+ row
->height
> max_y
)
11226 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11229 /* Scroll the current matrix. */
11230 xassert (nrows_scrolled
> 0);
11231 rotate_matrix (w
->current_matrix
,
11233 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11236 /* Disable rows not reused. */
11237 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
11238 row
->enabled_p
= 0;
11240 /* Adjust window end. A null value of last_text_row means that
11241 the window end is in reused rows which in turn means that
11242 only its vpos can have changed. */
11245 w
->window_end_bytepos
11246 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11248 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11250 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11255 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
11258 w
->window_end_valid
= Qnil
;
11259 w
->desired_matrix
->no_scrolling_p
= 1;
11262 debug_method_add (w
, "try_window_reusing_current_matrix 2");
11272 /************************************************************************
11273 Window redisplay reusing current matrix when buffer has changed
11274 ************************************************************************/
11276 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
11277 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
11279 static struct glyph_row
*
11280 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
11281 struct glyph_row
*));
11284 /* Return the last row in MATRIX displaying text. If row START is
11285 non-null, start searching with that row. IT gives the dimensions
11286 of the display. Value is null if matrix is empty; otherwise it is
11287 a pointer to the row found. */
11289 static struct glyph_row
*
11290 find_last_row_displaying_text (matrix
, it
, start
)
11291 struct glyph_matrix
*matrix
;
11293 struct glyph_row
*start
;
11295 struct glyph_row
*row
, *row_found
;
11297 /* Set row_found to the last row in IT->w's current matrix
11298 displaying text. The loop looks funny but think of partially
11301 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11302 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11304 xassert (row
->enabled_p
);
11306 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11315 /* Return the last row in the current matrix of W that is not affected
11316 by changes at the start of current_buffer that occurred since W's
11317 current matrix was built. Value is null if no such row exists.
11319 BEG_UNCHANGED us the number of characters unchanged at the start of
11320 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11321 first changed character in current_buffer. Characters at positions <
11322 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11323 when the current matrix was built. */
11325 static struct glyph_row
*
11326 find_last_unchanged_at_beg_row (w
)
11329 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11330 struct glyph_row
*row
;
11331 struct glyph_row
*row_found
= NULL
;
11332 int yb
= window_text_bottom_y (w
);
11334 /* Find the last row displaying unchanged text. */
11335 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11336 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11337 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11339 if (/* If row ends before first_changed_pos, it is unchanged,
11340 except in some case. */
11341 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11342 /* When row ends in ZV and we write at ZV it is not
11344 && !row
->ends_at_zv_p
11345 /* When first_changed_pos is the end of a continued line,
11346 row is not unchanged because it may be no longer
11348 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11349 && row
->continued_p
))
11352 /* Stop if last visible row. */
11353 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11363 /* Find the first glyph row in the current matrix of W that is not
11364 affected by changes at the end of current_buffer since the
11365 time W's current matrix was built.
11367 Return in *DELTA the number of chars by which buffer positions in
11368 unchanged text at the end of current_buffer must be adjusted.
11370 Return in *DELTA_BYTES the corresponding number of bytes.
11372 Value is null if no such row exists, i.e. all rows are affected by
11375 static struct glyph_row
*
11376 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11378 int *delta
, *delta_bytes
;
11380 struct glyph_row
*row
;
11381 struct glyph_row
*row_found
= NULL
;
11383 *delta
= *delta_bytes
= 0;
11385 /* Display must not have been paused, otherwise the current matrix
11386 is not up to date. */
11387 if (NILP (w
->window_end_valid
))
11390 /* A value of window_end_pos >= END_UNCHANGED means that the window
11391 end is in the range of changed text. If so, there is no
11392 unchanged row at the end of W's current matrix. */
11393 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11396 /* Set row to the last row in W's current matrix displaying text. */
11397 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11399 /* If matrix is entirely empty, no unchanged row exists. */
11400 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11402 /* The value of row is the last glyph row in the matrix having a
11403 meaningful buffer position in it. The end position of row
11404 corresponds to window_end_pos. This allows us to translate
11405 buffer positions in the current matrix to current buffer
11406 positions for characters not in changed text. */
11407 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11408 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11409 int last_unchanged_pos
, last_unchanged_pos_old
;
11410 struct glyph_row
*first_text_row
11411 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11413 *delta
= Z
- Z_old
;
11414 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11416 /* Set last_unchanged_pos to the buffer position of the last
11417 character in the buffer that has not been changed. Z is the
11418 index + 1 of the last character in current_buffer, i.e. by
11419 subtracting END_UNCHANGED we get the index of the last
11420 unchanged character, and we have to add BEG to get its buffer
11422 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11423 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11425 /* Search backward from ROW for a row displaying a line that
11426 starts at a minimum position >= last_unchanged_pos_old. */
11427 for (; row
> first_text_row
; --row
)
11429 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11432 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11437 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11444 /* Make sure that glyph rows in the current matrix of window W
11445 reference the same glyph memory as corresponding rows in the
11446 frame's frame matrix. This function is called after scrolling W's
11447 current matrix on a terminal frame in try_window_id and
11448 try_window_reusing_current_matrix. */
11451 sync_frame_with_window_matrix_rows (w
)
11454 struct frame
*f
= XFRAME (w
->frame
);
11455 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11457 /* Preconditions: W must be a leaf window and full-width. Its frame
11458 must have a frame matrix. */
11459 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11460 xassert (WINDOW_FULL_WIDTH_P (w
));
11461 xassert (!FRAME_WINDOW_P (f
));
11463 /* If W is a full-width window, glyph pointers in W's current matrix
11464 have, by definition, to be the same as glyph pointers in the
11465 corresponding frame matrix. Note that frame matrices have no
11466 marginal areas (see build_frame_matrix). */
11467 window_row
= w
->current_matrix
->rows
;
11468 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11469 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11470 while (window_row
< window_row_end
)
11472 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
11473 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
11475 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
11476 frame_row
->glyphs
[TEXT_AREA
] = start
;
11477 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
11478 frame_row
->glyphs
[LAST_AREA
] = end
;
11480 /* Disable frame rows whose corresponding window rows have
11481 been disabled in try_window_id. */
11482 if (!window_row
->enabled_p
)
11483 frame_row
->enabled_p
= 0;
11485 ++window_row
, ++frame_row
;
11490 /* Find the glyph row in window W containing CHARPOS. Consider all
11491 rows between START and END (not inclusive). END null means search
11492 all rows to the end of the display area of W. Value is the row
11493 containing CHARPOS or null. */
11496 row_containing_pos (w
, charpos
, start
, end
, dy
)
11499 struct glyph_row
*start
, *end
;
11502 struct glyph_row
*row
= start
;
11505 /* If we happen to start on a header-line, skip that. */
11506 if (row
->mode_line_p
)
11509 if ((end
&& row
>= end
) || !row
->enabled_p
)
11512 last_y
= window_text_bottom_y (w
) - dy
;
11516 /* Give up if we have gone too far. */
11517 if (end
&& row
>= end
)
11519 /* This formerly returned if they were equal.
11520 I think that both quantities are of a "last plus one" type;
11521 if so, when they are equal, the row is within the screen. -- rms. */
11522 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
11525 /* If it is in this row, return this row. */
11526 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
11527 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11528 /* The end position of a row equals the start
11529 position of the next row. If CHARPOS is there, we
11530 would rather display it in the next line, except
11531 when this line ends in ZV. */
11532 && !row
->ends_at_zv_p
11533 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11534 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
11541 /* Try to redisplay window W by reusing its existing display. W's
11542 current matrix must be up to date when this function is called,
11543 i.e. window_end_valid must not be nil.
11547 1 if display has been updated
11548 0 if otherwise unsuccessful
11549 -1 if redisplay with same window start is known not to succeed
11551 The following steps are performed:
11553 1. Find the last row in the current matrix of W that is not
11554 affected by changes at the start of current_buffer. If no such row
11557 2. Find the first row in W's current matrix that is not affected by
11558 changes at the end of current_buffer. Maybe there is no such row.
11560 3. Display lines beginning with the row + 1 found in step 1 to the
11561 row found in step 2 or, if step 2 didn't find a row, to the end of
11564 4. If cursor is not known to appear on the window, give up.
11566 5. If display stopped at the row found in step 2, scroll the
11567 display and current matrix as needed.
11569 6. Maybe display some lines at the end of W, if we must. This can
11570 happen under various circumstances, like a partially visible line
11571 becoming fully visible, or because newly displayed lines are displayed
11572 in smaller font sizes.
11574 7. Update W's window end information. */
11580 struct frame
*f
= XFRAME (w
->frame
);
11581 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11582 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11583 struct glyph_row
*last_unchanged_at_beg_row
;
11584 struct glyph_row
*first_unchanged_at_end_row
;
11585 struct glyph_row
*row
;
11586 struct glyph_row
*bottom_row
;
11589 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11590 struct text_pos start_pos
;
11592 int first_unchanged_at_end_vpos
= 0;
11593 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11594 struct text_pos start
;
11595 int first_changed_charpos
, last_changed_charpos
;
11598 if (inhibit_try_window_id
)
11602 /* This is handy for debugging. */
11604 #define GIVE_UP(X) \
11606 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11610 #define GIVE_UP(X) return 0
11613 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11615 /* Don't use this for mini-windows because these can show
11616 messages and mini-buffers, and we don't handle that here. */
11617 if (MINI_WINDOW_P (w
))
11620 /* This flag is used to prevent redisplay optimizations. */
11621 if (windows_or_buffers_changed
|| cursor_type_changed
)
11624 /* Verify that narrowing has not changed.
11625 Also verify that we were not told to prevent redisplay optimizations.
11626 It would be nice to further
11627 reduce the number of cases where this prevents try_window_id. */
11628 if (current_buffer
->clip_changed
11629 || current_buffer
->prevent_redisplay_optimizations_p
)
11632 /* Window must either use window-based redisplay or be full width. */
11633 if (!FRAME_WINDOW_P (f
)
11634 && (!line_ins_del_ok
11635 || !WINDOW_FULL_WIDTH_P (w
)))
11638 /* Give up if point is not known NOT to appear in W. */
11639 if (PT
< CHARPOS (start
))
11642 /* Another way to prevent redisplay optimizations. */
11643 if (XFASTINT (w
->last_modified
) == 0)
11646 /* Verify that window is not hscrolled. */
11647 if (XFASTINT (w
->hscroll
) != 0)
11650 /* Verify that display wasn't paused. */
11651 if (NILP (w
->window_end_valid
))
11654 /* Can't use this if highlighting a region because a cursor movement
11655 will do more than just set the cursor. */
11656 if (!NILP (Vtransient_mark_mode
)
11657 && !NILP (current_buffer
->mark_active
))
11660 /* Likewise if highlighting trailing whitespace. */
11661 if (!NILP (Vshow_trailing_whitespace
))
11664 /* Likewise if showing a region. */
11665 if (!NILP (w
->region_showing
))
11668 /* Can use this if overlay arrow position and or string have changed. */
11669 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11670 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11674 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11675 only if buffer has really changed. The reason is that the gap is
11676 initially at Z for freshly visited files. The code below would
11677 set end_unchanged to 0 in that case. */
11678 if (MODIFF
> SAVE_MODIFF
11679 /* This seems to happen sometimes after saving a buffer. */
11680 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11682 if (GPT
- BEG
< BEG_UNCHANGED
)
11683 BEG_UNCHANGED
= GPT
- BEG
;
11684 if (Z
- GPT
< END_UNCHANGED
)
11685 END_UNCHANGED
= Z
- GPT
;
11688 /* The position of the first and last character that has been changed. */
11689 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11690 last_changed_charpos
= Z
- END_UNCHANGED
;
11692 /* If window starts after a line end, and the last change is in
11693 front of that newline, then changes don't affect the display.
11694 This case happens with stealth-fontification. Note that although
11695 the display is unchanged, glyph positions in the matrix have to
11696 be adjusted, of course. */
11697 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11698 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11699 && ((last_changed_charpos
< CHARPOS (start
)
11700 && CHARPOS (start
) == BEGV
)
11701 || (last_changed_charpos
< CHARPOS (start
) - 1
11702 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11704 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11705 struct glyph_row
*r0
;
11707 /* Compute how many chars/bytes have been added to or removed
11708 from the buffer. */
11709 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11710 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11712 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11714 /* Give up if PT is not in the window. Note that it already has
11715 been checked at the start of try_window_id that PT is not in
11716 front of the window start. */
11717 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11720 /* If window start is unchanged, we can reuse the whole matrix
11721 as is, after adjusting glyph positions. No need to compute
11722 the window end again, since its offset from Z hasn't changed. */
11723 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11724 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11725 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11727 /* Adjust positions in the glyph matrix. */
11728 if (delta
|| delta_bytes
)
11730 struct glyph_row
*r1
11731 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11732 increment_matrix_positions (w
->current_matrix
,
11733 MATRIX_ROW_VPOS (r0
, current_matrix
),
11734 MATRIX_ROW_VPOS (r1
, current_matrix
),
11735 delta
, delta_bytes
);
11738 /* Set the cursor. */
11739 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11741 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11748 /* Handle the case that changes are all below what is displayed in
11749 the window, and that PT is in the window. This shortcut cannot
11750 be taken if ZV is visible in the window, and text has been added
11751 there that is visible in the window. */
11752 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11753 /* ZV is not visible in the window, or there are no
11754 changes at ZV, actually. */
11755 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11756 || first_changed_charpos
== last_changed_charpos
))
11758 struct glyph_row
*r0
;
11760 /* Give up if PT is not in the window. Note that it already has
11761 been checked at the start of try_window_id that PT is not in
11762 front of the window start. */
11763 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11766 /* If window start is unchanged, we can reuse the whole matrix
11767 as is, without changing glyph positions since no text has
11768 been added/removed in front of the window end. */
11769 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11770 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11772 /* We have to compute the window end anew since text
11773 can have been added/removed after it. */
11775 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11776 w
->window_end_bytepos
11777 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11779 /* Set the cursor. */
11780 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11782 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11789 /* Give up if window start is in the changed area.
11791 The condition used to read
11793 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11795 but why that was tested escapes me at the moment. */
11796 if (CHARPOS (start
) >= first_changed_charpos
11797 && CHARPOS (start
) <= last_changed_charpos
)
11800 /* Check that window start agrees with the start of the first glyph
11801 row in its current matrix. Check this after we know the window
11802 start is not in changed text, otherwise positions would not be
11804 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11805 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11808 /* Give up if the window ends in strings. Overlay strings
11809 at the end are difficult to handle, so don't try. */
11810 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
11811 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
11814 /* Compute the position at which we have to start displaying new
11815 lines. Some of the lines at the top of the window might be
11816 reusable because they are not displaying changed text. Find the
11817 last row in W's current matrix not affected by changes at the
11818 start of current_buffer. Value is null if changes start in the
11819 first line of window. */
11820 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11821 if (last_unchanged_at_beg_row
)
11823 /* Avoid starting to display in the moddle of a character, a TAB
11824 for instance. This is easier than to set up the iterator
11825 exactly, and it's not a frequent case, so the additional
11826 effort wouldn't really pay off. */
11827 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11828 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
11829 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11830 --last_unchanged_at_beg_row
;
11832 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11835 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11837 start_pos
= it
.current
.pos
;
11839 /* Start displaying new lines in the desired matrix at the same
11840 vpos we would use in the current matrix, i.e. below
11841 last_unchanged_at_beg_row. */
11842 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11844 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11845 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11847 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11851 /* There are no reusable lines at the start of the window.
11852 Start displaying in the first line. */
11853 start_display (&it
, w
, start
);
11854 start_pos
= it
.current
.pos
;
11857 /* Find the first row that is not affected by changes at the end of
11858 the buffer. Value will be null if there is no unchanged row, in
11859 which case we must redisplay to the end of the window. delta
11860 will be set to the value by which buffer positions beginning with
11861 first_unchanged_at_end_row have to be adjusted due to text
11863 first_unchanged_at_end_row
11864 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11865 IF_DEBUG (debug_delta
= delta
);
11866 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11868 /* Set stop_pos to the buffer position up to which we will have to
11869 display new lines. If first_unchanged_at_end_row != NULL, this
11870 is the buffer position of the start of the line displayed in that
11871 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11872 that we don't stop at a buffer position. */
11874 if (first_unchanged_at_end_row
)
11876 xassert (last_unchanged_at_beg_row
== NULL
11877 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11879 /* If this is a continuation line, move forward to the next one
11880 that isn't. Changes in lines above affect this line.
11881 Caution: this may move first_unchanged_at_end_row to a row
11882 not displaying text. */
11883 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11884 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11885 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11886 < it
.last_visible_y
))
11887 ++first_unchanged_at_end_row
;
11889 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11890 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11891 >= it
.last_visible_y
))
11892 first_unchanged_at_end_row
= NULL
;
11895 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11897 first_unchanged_at_end_vpos
11898 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11899 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11902 else if (last_unchanged_at_beg_row
== NULL
)
11908 /* Either there is no unchanged row at the end, or the one we have
11909 now displays text. This is a necessary condition for the window
11910 end pos calculation at the end of this function. */
11911 xassert (first_unchanged_at_end_row
== NULL
11912 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11914 debug_last_unchanged_at_beg_vpos
11915 = (last_unchanged_at_beg_row
11916 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11918 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11920 #endif /* GLYPH_DEBUG != 0 */
11923 /* Display new lines. Set last_text_row to the last new line
11924 displayed which has text on it, i.e. might end up as being the
11925 line where the window_end_vpos is. */
11926 w
->cursor
.vpos
= -1;
11927 last_text_row
= NULL
;
11928 overlay_arrow_seen
= 0;
11929 while (it
.current_y
< it
.last_visible_y
11930 && !fonts_changed_p
11931 && (first_unchanged_at_end_row
== NULL
11932 || IT_CHARPOS (it
) < stop_pos
))
11934 if (display_line (&it
))
11935 last_text_row
= it
.glyph_row
- 1;
11938 if (fonts_changed_p
)
11942 /* Compute differences in buffer positions, y-positions etc. for
11943 lines reused at the bottom of the window. Compute what we can
11945 if (first_unchanged_at_end_row
11946 /* No lines reused because we displayed everything up to the
11947 bottom of the window. */
11948 && it
.current_y
< it
.last_visible_y
)
11951 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11953 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11954 run
.current_y
= first_unchanged_at_end_row
->y
;
11955 run
.desired_y
= run
.current_y
+ dy
;
11956 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11960 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11961 first_unchanged_at_end_row
= NULL
;
11963 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11966 /* Find the cursor if not already found. We have to decide whether
11967 PT will appear on this window (it sometimes doesn't, but this is
11968 not a very frequent case.) This decision has to be made before
11969 the current matrix is altered. A value of cursor.vpos < 0 means
11970 that PT is either in one of the lines beginning at
11971 first_unchanged_at_end_row or below the window. Don't care for
11972 lines that might be displayed later at the window end; as
11973 mentioned, this is not a frequent case. */
11974 if (w
->cursor
.vpos
< 0)
11976 /* Cursor in unchanged rows at the top? */
11977 if (PT
< CHARPOS (start_pos
)
11978 && last_unchanged_at_beg_row
)
11980 row
= row_containing_pos (w
, PT
,
11981 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11982 last_unchanged_at_beg_row
+ 1, 0);
11984 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11987 /* Start from first_unchanged_at_end_row looking for PT. */
11988 else if (first_unchanged_at_end_row
)
11990 row
= row_containing_pos (w
, PT
- delta
,
11991 first_unchanged_at_end_row
, NULL
, 0);
11993 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11994 delta_bytes
, dy
, dvpos
);
11997 /* Give up if cursor was not found. */
11998 if (w
->cursor
.vpos
< 0)
12000 clear_glyph_matrix (w
->desired_matrix
);
12005 /* Don't let the cursor end in the scroll margins. */
12007 int this_scroll_margin
, cursor_height
;
12009 this_scroll_margin
= max (0, scroll_margin
);
12010 this_scroll_margin
= min (this_scroll_margin
,
12011 XFASTINT (w
->height
) / 4);
12012 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
12013 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
12015 if ((w
->cursor
.y
< this_scroll_margin
12016 && CHARPOS (start
) > BEGV
)
12017 /* Don't take scroll margin into account at the bottom because
12018 old redisplay didn't do it either. */
12019 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
12021 w
->cursor
.vpos
= -1;
12022 clear_glyph_matrix (w
->desired_matrix
);
12027 /* Scroll the display. Do it before changing the current matrix so
12028 that xterm.c doesn't get confused about where the cursor glyph is
12030 if (dy
&& run
.height
)
12034 if (FRAME_WINDOW_P (f
))
12036 rif
->update_window_begin_hook (w
);
12037 rif
->clear_mouse_face (w
);
12038 rif
->scroll_run_hook (w
, &run
);
12039 rif
->update_window_end_hook (w
, 0, 0);
12043 /* Terminal frame. In this case, dvpos gives the number of
12044 lines to scroll by; dvpos < 0 means scroll up. */
12045 int first_unchanged_at_end_vpos
12046 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
12047 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
12048 int end
= (XFASTINT (w
->top
)
12049 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
12050 + window_internal_height (w
));
12052 /* Perform the operation on the screen. */
12055 /* Scroll last_unchanged_at_beg_row to the end of the
12056 window down dvpos lines. */
12057 set_terminal_window (end
);
12059 /* On dumb terminals delete dvpos lines at the end
12060 before inserting dvpos empty lines. */
12061 if (!scroll_region_ok
)
12062 ins_del_lines (end
- dvpos
, -dvpos
);
12064 /* Insert dvpos empty lines in front of
12065 last_unchanged_at_beg_row. */
12066 ins_del_lines (from
, dvpos
);
12068 else if (dvpos
< 0)
12070 /* Scroll up last_unchanged_at_beg_vpos to the end of
12071 the window to last_unchanged_at_beg_vpos - |dvpos|. */
12072 set_terminal_window (end
);
12074 /* Delete dvpos lines in front of
12075 last_unchanged_at_beg_vpos. ins_del_lines will set
12076 the cursor to the given vpos and emit |dvpos| delete
12078 ins_del_lines (from
+ dvpos
, dvpos
);
12080 /* On a dumb terminal insert dvpos empty lines at the
12082 if (!scroll_region_ok
)
12083 ins_del_lines (end
+ dvpos
, -dvpos
);
12086 set_terminal_window (0);
12092 /* Shift reused rows of the current matrix to the right position.
12093 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
12095 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
12096 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
12099 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
12100 bottom_vpos
, dvpos
);
12101 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
12104 else if (dvpos
> 0)
12106 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
12107 bottom_vpos
, dvpos
);
12108 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
12109 first_unchanged_at_end_vpos
+ dvpos
, 0);
12112 /* For frame-based redisplay, make sure that current frame and window
12113 matrix are in sync with respect to glyph memory. */
12114 if (!FRAME_WINDOW_P (f
))
12115 sync_frame_with_window_matrix_rows (w
);
12117 /* Adjust buffer positions in reused rows. */
12119 increment_matrix_positions (current_matrix
,
12120 first_unchanged_at_end_vpos
+ dvpos
,
12121 bottom_vpos
, delta
, delta_bytes
);
12123 /* Adjust Y positions. */
12125 shift_glyph_matrix (w
, current_matrix
,
12126 first_unchanged_at_end_vpos
+ dvpos
,
12129 if (first_unchanged_at_end_row
)
12130 first_unchanged_at_end_row
+= dvpos
;
12132 /* If scrolling up, there may be some lines to display at the end of
12134 last_text_row_at_end
= NULL
;
12137 /* Scrolling up can leave for example a partially visible line
12138 at the end of the window to be redisplayed. */
12139 /* Set last_row to the glyph row in the current matrix where the
12140 window end line is found. It has been moved up or down in
12141 the matrix by dvpos. */
12142 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
12143 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
12145 /* If last_row is the window end line, it should display text. */
12146 xassert (last_row
->displays_text_p
);
12148 /* If window end line was partially visible before, begin
12149 displaying at that line. Otherwise begin displaying with the
12150 line following it. */
12151 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
12153 init_to_row_start (&it
, w
, last_row
);
12154 it
.vpos
= last_vpos
;
12155 it
.current_y
= last_row
->y
;
12159 init_to_row_end (&it
, w
, last_row
);
12160 it
.vpos
= 1 + last_vpos
;
12161 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
12165 /* We may start in a continuation line. If so, we have to
12166 get the right continuation_lines_width and current_x. */
12167 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
12168 it
.hpos
= it
.current_x
= 0;
12170 /* Display the rest of the lines at the window end. */
12171 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
12172 while (it
.current_y
< it
.last_visible_y
12173 && !fonts_changed_p
)
12175 /* Is it always sure that the display agrees with lines in
12176 the current matrix? I don't think so, so we mark rows
12177 displayed invalid in the current matrix by setting their
12178 enabled_p flag to zero. */
12179 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
12180 if (display_line (&it
))
12181 last_text_row_at_end
= it
.glyph_row
- 1;
12185 /* Update window_end_pos and window_end_vpos. */
12186 if (first_unchanged_at_end_row
12187 && first_unchanged_at_end_row
->y
< it
.last_visible_y
12188 && !last_text_row_at_end
)
12190 /* Window end line if one of the preserved rows from the current
12191 matrix. Set row to the last row displaying text in current
12192 matrix starting at first_unchanged_at_end_row, after
12194 xassert (first_unchanged_at_end_row
->displays_text_p
);
12195 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
12196 first_unchanged_at_end_row
);
12197 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
12199 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12200 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12202 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
12203 xassert (w
->window_end_bytepos
>= 0);
12204 IF_DEBUG (debug_method_add (w
, "A"));
12206 else if (last_text_row_at_end
)
12209 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
12210 w
->window_end_bytepos
12211 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
12213 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
12214 xassert (w
->window_end_bytepos
>= 0);
12215 IF_DEBUG (debug_method_add (w
, "B"));
12217 else if (last_text_row
)
12219 /* We have displayed either to the end of the window or at the
12220 end of the window, i.e. the last row with text is to be found
12221 in the desired matrix. */
12223 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12224 w
->window_end_bytepos
12225 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12227 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
12228 xassert (w
->window_end_bytepos
>= 0);
12230 else if (first_unchanged_at_end_row
== NULL
12231 && last_text_row
== NULL
12232 && last_text_row_at_end
== NULL
)
12234 /* Displayed to end of window, but no line containing text was
12235 displayed. Lines were deleted at the end of the window. */
12236 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
12237 int vpos
= XFASTINT (w
->window_end_vpos
);
12238 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
12239 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
12242 row
== NULL
&& vpos
>= first_vpos
;
12243 --vpos
, --current_row
, --desired_row
)
12245 if (desired_row
->enabled_p
)
12247 if (desired_row
->displays_text_p
)
12250 else if (current_row
->displays_text_p
)
12254 xassert (row
!= NULL
);
12255 w
->window_end_vpos
= make_number (vpos
+ 1);
12256 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12257 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12258 xassert (w
->window_end_bytepos
>= 0);
12259 IF_DEBUG (debug_method_add (w
, "C"));
12264 #if 0 /* This leads to problems, for instance when the cursor is
12265 at ZV, and the cursor line displays no text. */
12266 /* Disable rows below what's displayed in the window. This makes
12267 debugging easier. */
12268 enable_glyph_matrix_rows (current_matrix
,
12269 XFASTINT (w
->window_end_vpos
) + 1,
12273 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
12274 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
12276 /* Record that display has not been completed. */
12277 w
->window_end_valid
= Qnil
;
12278 w
->desired_matrix
->no_scrolling_p
= 1;
12286 /***********************************************************************
12287 More debugging support
12288 ***********************************************************************/
12292 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
12293 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
12294 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
12297 /* Dump the contents of glyph matrix MATRIX on stderr.
12299 GLYPHS 0 means don't show glyph contents.
12300 GLYPHS 1 means show glyphs in short form
12301 GLYPHS > 1 means show glyphs in long form. */
12304 dump_glyph_matrix (matrix
, glyphs
)
12305 struct glyph_matrix
*matrix
;
12309 for (i
= 0; i
< matrix
->nrows
; ++i
)
12310 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12314 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12315 the glyph row and area where the glyph comes from. */
12318 dump_glyph (row
, glyph
, area
)
12319 struct glyph_row
*row
;
12320 struct glyph
*glyph
;
12323 if (glyph
->type
== CHAR_GLYPH
)
12326 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12327 glyph
- row
->glyphs
[TEXT_AREA
],
12330 (BUFFERP (glyph
->object
)
12332 : (STRINGP (glyph
->object
)
12335 glyph
->pixel_width
,
12337 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12341 glyph
->left_box_line_p
,
12342 glyph
->right_box_line_p
);
12344 else if (glyph
->type
== STRETCH_GLYPH
)
12347 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12348 glyph
- row
->glyphs
[TEXT_AREA
],
12351 (BUFFERP (glyph
->object
)
12353 : (STRINGP (glyph
->object
)
12356 glyph
->pixel_width
,
12360 glyph
->left_box_line_p
,
12361 glyph
->right_box_line_p
);
12363 else if (glyph
->type
== IMAGE_GLYPH
)
12366 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12367 glyph
- row
->glyphs
[TEXT_AREA
],
12370 (BUFFERP (glyph
->object
)
12372 : (STRINGP (glyph
->object
)
12375 glyph
->pixel_width
,
12379 glyph
->left_box_line_p
,
12380 glyph
->right_box_line_p
);
12385 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12386 GLYPHS 0 means don't show glyph contents.
12387 GLYPHS 1 means show glyphs in short form
12388 GLYPHS > 1 means show glyphs in long form. */
12391 dump_glyph_row (row
, vpos
, glyphs
)
12392 struct glyph_row
*row
;
12397 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12398 fprintf (stderr
, "=======================================================================\n");
12400 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12401 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12403 MATRIX_ROW_START_CHARPOS (row
),
12404 MATRIX_ROW_END_CHARPOS (row
),
12405 row
->used
[TEXT_AREA
],
12406 row
->contains_overlapping_glyphs_p
,
12408 row
->truncated_on_left_p
,
12409 row
->truncated_on_right_p
,
12410 row
->overlay_arrow_p
,
12412 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12413 row
->displays_text_p
,
12416 row
->ends_in_middle_of_char_p
,
12417 row
->starts_in_middle_of_char_p
,
12423 row
->visible_height
,
12426 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12427 row
->end
.overlay_string_index
,
12428 row
->continuation_lines_width
);
12429 fprintf (stderr
, "%9d %5d\n",
12430 CHARPOS (row
->start
.string_pos
),
12431 CHARPOS (row
->end
.string_pos
));
12432 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12433 row
->end
.dpvec_index
);
12440 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12442 struct glyph
*glyph
= row
->glyphs
[area
];
12443 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12445 /* Glyph for a line end in text. */
12446 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12449 if (glyph
< glyph_end
)
12450 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12452 for (; glyph
< glyph_end
; ++glyph
)
12453 dump_glyph (row
, glyph
, area
);
12456 else if (glyphs
== 1)
12460 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12462 char *s
= (char *) alloca (row
->used
[area
] + 1);
12465 for (i
= 0; i
< row
->used
[area
]; ++i
)
12467 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12468 if (glyph
->type
== CHAR_GLYPH
12469 && glyph
->u
.ch
< 0x80
12470 && glyph
->u
.ch
>= ' ')
12471 s
[i
] = glyph
->u
.ch
;
12477 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12483 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12484 Sdump_glyph_matrix
, 0, 1, "p",
12485 doc
: /* Dump the current matrix of the selected window to stderr.
12486 Shows contents of glyph row structures. With non-nil
12487 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12488 glyphs in short form, otherwise show glyphs in long form. */)
12490 Lisp_Object glyphs
;
12492 struct window
*w
= XWINDOW (selected_window
);
12493 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12495 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12496 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12497 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12498 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12499 fprintf (stderr
, "=============================================\n");
12500 dump_glyph_matrix (w
->current_matrix
,
12501 NILP (glyphs
) ? 0 : XINT (glyphs
));
12506 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
12507 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
12510 struct frame
*f
= XFRAME (selected_frame
);
12511 dump_glyph_matrix (f
->current_matrix
, 1);
12516 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12517 doc
: /* Dump glyph row ROW to stderr.
12518 GLYPH 0 means don't dump glyphs.
12519 GLYPH 1 means dump glyphs in short form.
12520 GLYPH > 1 or omitted means dump glyphs in long form. */)
12522 Lisp_Object row
, glyphs
;
12524 struct glyph_matrix
*matrix
;
12527 CHECK_NUMBER (row
);
12528 matrix
= XWINDOW (selected_window
)->current_matrix
;
12530 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12531 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12533 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12538 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12539 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12540 GLYPH 0 means don't dump glyphs.
12541 GLYPH 1 means dump glyphs in short form.
12542 GLYPH > 1 or omitted means dump glyphs in long form. */)
12544 Lisp_Object row
, glyphs
;
12546 struct frame
*sf
= SELECTED_FRAME ();
12547 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12550 CHECK_NUMBER (row
);
12552 if (vpos
>= 0 && vpos
< m
->nrows
)
12553 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12554 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12559 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12560 doc
: /* Toggle tracing of redisplay.
12561 With ARG, turn tracing on if and only if ARG is positive. */)
12566 trace_redisplay_p
= !trace_redisplay_p
;
12569 arg
= Fprefix_numeric_value (arg
);
12570 trace_redisplay_p
= XINT (arg
) > 0;
12577 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12578 doc
: /* Like `format', but print result to stderr.
12579 usage: (trace-to-stderr STRING &rest OBJECTS) */)
12584 Lisp_Object s
= Fformat (nargs
, args
);
12585 fprintf (stderr
, "%s", SDATA (s
));
12589 #endif /* GLYPH_DEBUG */
12593 /***********************************************************************
12594 Building Desired Matrix Rows
12595 ***********************************************************************/
12597 /* Return a temporary glyph row holding the glyphs of an overlay
12598 arrow. Only used for non-window-redisplay windows. */
12600 static struct glyph_row
*
12601 get_overlay_arrow_glyph_row (w
)
12604 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12605 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12606 struct buffer
*old
= current_buffer
;
12607 const unsigned char *arrow_string
= SDATA (Voverlay_arrow_string
);
12608 int arrow_len
= SCHARS (Voverlay_arrow_string
);
12609 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12610 const unsigned char *p
;
12613 int n_glyphs_before
;
12615 set_buffer_temp (buffer
);
12616 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12617 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12618 SET_TEXT_POS (it
.position
, 0, 0);
12620 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12622 while (p
< arrow_end
)
12624 Lisp_Object face
, ilisp
;
12626 /* Get the next character. */
12628 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12630 it
.c
= *p
, it
.len
= 1;
12633 /* Get its face. */
12634 ilisp
= make_number (p
- arrow_string
);
12635 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12636 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12638 /* Compute its width, get its glyphs. */
12639 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12640 SET_TEXT_POS (it
.position
, -1, -1);
12641 PRODUCE_GLYPHS (&it
);
12643 /* If this character doesn't fit any more in the line, we have
12644 to remove some glyphs. */
12645 if (it
.current_x
> it
.last_visible_x
)
12647 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12652 set_buffer_temp (old
);
12653 return it
.glyph_row
;
12657 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12658 glyphs are only inserted for terminal frames since we can't really
12659 win with truncation glyphs when partially visible glyphs are
12660 involved. Which glyphs to insert is determined by
12661 produce_special_glyphs. */
12664 insert_left_trunc_glyphs (it
)
12667 struct it truncate_it
;
12668 struct glyph
*from
, *end
, *to
, *toend
;
12670 xassert (!FRAME_WINDOW_P (it
->f
));
12672 /* Get the truncation glyphs. */
12674 truncate_it
.current_x
= 0;
12675 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12676 truncate_it
.glyph_row
= &scratch_glyph_row
;
12677 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12678 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12679 truncate_it
.object
= make_number (0);
12680 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12682 /* Overwrite glyphs from IT with truncation glyphs. */
12683 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12684 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12685 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12686 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12691 /* There may be padding glyphs left over. Overwrite them too. */
12692 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12694 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12700 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12704 /* Compute the pixel height and width of IT->glyph_row.
12706 Most of the time, ascent and height of a display line will be equal
12707 to the max_ascent and max_height values of the display iterator
12708 structure. This is not the case if
12710 1. We hit ZV without displaying anything. In this case, max_ascent
12711 and max_height will be zero.
12713 2. We have some glyphs that don't contribute to the line height.
12714 (The glyph row flag contributes_to_line_height_p is for future
12715 pixmap extensions).
12717 The first case is easily covered by using default values because in
12718 these cases, the line height does not really matter, except that it
12719 must not be zero. */
12722 compute_line_metrics (it
)
12725 struct glyph_row
*row
= it
->glyph_row
;
12728 if (FRAME_WINDOW_P (it
->f
))
12730 int i
, min_y
, max_y
;
12732 /* The line may consist of one space only, that was added to
12733 place the cursor on it. If so, the row's height hasn't been
12735 if (row
->height
== 0)
12737 if (it
->max_ascent
+ it
->max_descent
== 0)
12738 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12739 row
->ascent
= it
->max_ascent
;
12740 row
->height
= it
->max_ascent
+ it
->max_descent
;
12741 row
->phys_ascent
= it
->max_phys_ascent
;
12742 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12745 /* Compute the width of this line. */
12746 row
->pixel_width
= row
->x
;
12747 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12748 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12750 xassert (row
->pixel_width
>= 0);
12751 xassert (row
->ascent
>= 0 && row
->height
> 0);
12753 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12754 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12756 /* If first line's physical ascent is larger than its logical
12757 ascent, use the physical ascent, and make the row taller.
12758 This makes accented characters fully visible. */
12759 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12760 && row
->phys_ascent
> row
->ascent
)
12762 row
->height
+= row
->phys_ascent
- row
->ascent
;
12763 row
->ascent
= row
->phys_ascent
;
12766 /* Compute how much of the line is visible. */
12767 row
->visible_height
= row
->height
;
12769 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12770 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12772 if (row
->y
< min_y
)
12773 row
->visible_height
-= min_y
- row
->y
;
12774 if (row
->y
+ row
->height
> max_y
)
12775 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12779 row
->pixel_width
= row
->used
[TEXT_AREA
];
12780 if (row
->continued_p
)
12781 row
->pixel_width
-= it
->continuation_pixel_width
;
12782 else if (row
->truncated_on_right_p
)
12783 row
->pixel_width
-= it
->truncation_pixel_width
;
12784 row
->ascent
= row
->phys_ascent
= 0;
12785 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12788 /* Compute a hash code for this row. */
12790 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12791 for (i
= 0; i
< row
->used
[area
]; ++i
)
12792 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12793 + row
->glyphs
[area
][i
].u
.val
12794 + row
->glyphs
[area
][i
].face_id
12795 + row
->glyphs
[area
][i
].padding_p
12796 + (row
->glyphs
[area
][i
].type
<< 2));
12798 it
->max_ascent
= it
->max_descent
= 0;
12799 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12803 /* Append one space to the glyph row of iterator IT if doing a
12804 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12805 space have the default face, otherwise let it have the same face as
12806 IT->face_id. Value is non-zero if a space was added.
12808 This function is called to make sure that there is always one glyph
12809 at the end of a glyph row that the cursor can be set on under
12810 window-systems. (If there weren't such a glyph we would not know
12811 how wide and tall a box cursor should be displayed).
12813 At the same time this space let's a nicely handle clearing to the
12814 end of the line if the row ends in italic text. */
12817 append_space (it
, default_face_p
)
12819 int default_face_p
;
12821 if (FRAME_WINDOW_P (it
->f
))
12823 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12825 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12826 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12828 /* Save some values that must not be changed.
12829 Must save IT->c and IT->len because otherwise
12830 ITERATOR_AT_END_P wouldn't work anymore after
12831 append_space has been called. */
12832 enum display_element_type saved_what
= it
->what
;
12833 int saved_c
= it
->c
, saved_len
= it
->len
;
12834 int saved_x
= it
->current_x
;
12835 int saved_face_id
= it
->face_id
;
12836 struct text_pos saved_pos
;
12837 Lisp_Object saved_object
;
12840 saved_object
= it
->object
;
12841 saved_pos
= it
->position
;
12843 it
->what
= IT_CHARACTER
;
12844 bzero (&it
->position
, sizeof it
->position
);
12845 it
->object
= make_number (0);
12849 if (default_face_p
)
12850 it
->face_id
= DEFAULT_FACE_ID
;
12851 else if (it
->face_before_selective_p
)
12852 it
->face_id
= it
->saved_face_id
;
12853 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12854 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12856 PRODUCE_GLYPHS (it
);
12858 it
->current_x
= saved_x
;
12859 it
->object
= saved_object
;
12860 it
->position
= saved_pos
;
12861 it
->what
= saved_what
;
12862 it
->face_id
= saved_face_id
;
12863 it
->len
= saved_len
;
12873 /* Extend the face of the last glyph in the text area of IT->glyph_row
12874 to the end of the display line. Called from display_line.
12875 If the glyph row is empty, add a space glyph to it so that we
12876 know the face to draw. Set the glyph row flag fill_line_p. */
12879 extend_face_to_end_of_line (it
)
12883 struct frame
*f
= it
->f
;
12885 /* If line is already filled, do nothing. */
12886 if (it
->current_x
>= it
->last_visible_x
)
12889 /* Face extension extends the background and box of IT->face_id
12890 to the end of the line. If the background equals the background
12891 of the frame, we don't have to do anything. */
12892 if (it
->face_before_selective_p
)
12893 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12895 face
= FACE_FROM_ID (f
, it
->face_id
);
12897 if (FRAME_WINDOW_P (f
)
12898 && face
->box
== FACE_NO_BOX
12899 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12903 /* Set the glyph row flag indicating that the face of the last glyph
12904 in the text area has to be drawn to the end of the text area. */
12905 it
->glyph_row
->fill_line_p
= 1;
12907 /* If current character of IT is not ASCII, make sure we have the
12908 ASCII face. This will be automatically undone the next time
12909 get_next_display_element returns a multibyte character. Note
12910 that the character will always be single byte in unibyte text. */
12911 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12913 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12916 if (FRAME_WINDOW_P (f
))
12918 /* If the row is empty, add a space with the current face of IT,
12919 so that we know which face to draw. */
12920 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12922 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12923 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12924 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12929 /* Save some values that must not be changed. */
12930 int saved_x
= it
->current_x
;
12931 struct text_pos saved_pos
;
12932 Lisp_Object saved_object
;
12933 enum display_element_type saved_what
= it
->what
;
12934 int saved_face_id
= it
->face_id
;
12936 saved_object
= it
->object
;
12937 saved_pos
= it
->position
;
12939 it
->what
= IT_CHARACTER
;
12940 bzero (&it
->position
, sizeof it
->position
);
12941 it
->object
= make_number (0);
12944 it
->face_id
= face
->id
;
12946 PRODUCE_GLYPHS (it
);
12948 while (it
->current_x
<= it
->last_visible_x
)
12949 PRODUCE_GLYPHS (it
);
12951 /* Don't count these blanks really. It would let us insert a left
12952 truncation glyph below and make us set the cursor on them, maybe. */
12953 it
->current_x
= saved_x
;
12954 it
->object
= saved_object
;
12955 it
->position
= saved_pos
;
12956 it
->what
= saved_what
;
12957 it
->face_id
= saved_face_id
;
12962 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12963 trailing whitespace. */
12966 trailing_whitespace_p (charpos
)
12969 int bytepos
= CHAR_TO_BYTE (charpos
);
12972 while (bytepos
< ZV_BYTE
12973 && (c
= FETCH_CHAR (bytepos
),
12974 c
== ' ' || c
== '\t'))
12977 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12979 if (bytepos
!= PT_BYTE
)
12986 /* Highlight trailing whitespace, if any, in ROW. */
12989 highlight_trailing_whitespace (f
, row
)
12991 struct glyph_row
*row
;
12993 int used
= row
->used
[TEXT_AREA
];
12997 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12998 struct glyph
*glyph
= start
+ used
- 1;
13000 /* Skip over glyphs inserted to display the cursor at the
13001 end of a line, for extending the face of the last glyph
13002 to the end of the line on terminals, and for truncation
13003 and continuation glyphs. */
13004 while (glyph
>= start
13005 && glyph
->type
== CHAR_GLYPH
13006 && INTEGERP (glyph
->object
))
13009 /* If last glyph is a space or stretch, and it's trailing
13010 whitespace, set the face of all trailing whitespace glyphs in
13011 IT->glyph_row to `trailing-whitespace'. */
13013 && BUFFERP (glyph
->object
)
13014 && (glyph
->type
== STRETCH_GLYPH
13015 || (glyph
->type
== CHAR_GLYPH
13016 && glyph
->u
.ch
== ' '))
13017 && trailing_whitespace_p (glyph
->charpos
))
13019 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
13021 while (glyph
>= start
13022 && BUFFERP (glyph
->object
)
13023 && (glyph
->type
== STRETCH_GLYPH
13024 || (glyph
->type
== CHAR_GLYPH
13025 && glyph
->u
.ch
== ' ')))
13026 (glyph
--)->face_id
= face_id
;
13032 /* Value is non-zero if glyph row ROW in window W should be
13033 used to hold the cursor. */
13036 cursor_row_p (w
, row
)
13038 struct glyph_row
*row
;
13040 int cursor_row_p
= 1;
13042 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
13044 /* If the row ends with a newline from a string, we don't want
13045 the cursor there (if the row is continued it doesn't end in a
13047 if (CHARPOS (row
->end
.string_pos
) >= 0
13048 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13049 cursor_row_p
= row
->continued_p
;
13051 /* If the row ends at ZV, display the cursor at the end of that
13052 row instead of at the start of the row below. */
13053 else if (row
->ends_at_zv_p
)
13059 return cursor_row_p
;
13063 /* Construct the glyph row IT->glyph_row in the desired matrix of
13064 IT->w from text at the current position of IT. See dispextern.h
13065 for an overview of struct it. Value is non-zero if
13066 IT->glyph_row displays text, as opposed to a line displaying ZV
13073 struct glyph_row
*row
= it
->glyph_row
;
13075 /* We always start displaying at hpos zero even if hscrolled. */
13076 xassert (it
->hpos
== 0 && it
->current_x
== 0);
13078 /* We must not display in a row that's not a text row. */
13079 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
13080 < it
->w
->desired_matrix
->nrows
);
13082 /* Is IT->w showing the region? */
13083 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
13085 /* Clear the result glyph row and enable it. */
13086 prepare_desired_row (row
);
13088 row
->y
= it
->current_y
;
13089 row
->start
= it
->current
;
13090 row
->continuation_lines_width
= it
->continuation_lines_width
;
13091 row
->displays_text_p
= 1;
13092 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
13093 it
->starts_in_middle_of_char_p
= 0;
13095 /* Arrange the overlays nicely for our purposes. Usually, we call
13096 display_line on only one line at a time, in which case this
13097 can't really hurt too much, or we call it on lines which appear
13098 one after another in the buffer, in which case all calls to
13099 recenter_overlay_lists but the first will be pretty cheap. */
13100 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
13102 /* Move over display elements that are not visible because we are
13103 hscrolled. This may stop at an x-position < IT->first_visible_x
13104 if the first glyph is partially visible or if we hit a line end. */
13105 if (it
->current_x
< it
->first_visible_x
)
13106 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
13107 MOVE_TO_POS
| MOVE_TO_X
);
13109 /* Get the initial row height. This is either the height of the
13110 text hscrolled, if there is any, or zero. */
13111 row
->ascent
= it
->max_ascent
;
13112 row
->height
= it
->max_ascent
+ it
->max_descent
;
13113 row
->phys_ascent
= it
->max_phys_ascent
;
13114 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13116 /* Loop generating characters. The loop is left with IT on the next
13117 character to display. */
13120 int n_glyphs_before
, hpos_before
, x_before
;
13122 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
13124 /* Retrieve the next thing to display. Value is zero if end of
13126 if (!get_next_display_element (it
))
13128 /* Maybe add a space at the end of this line that is used to
13129 display the cursor there under X. Set the charpos of the
13130 first glyph of blank lines not corresponding to any text
13132 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
13133 || row
->used
[TEXT_AREA
] == 0)
13135 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
13136 row
->displays_text_p
= 0;
13138 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
13139 && (!MINI_WINDOW_P (it
->w
)
13140 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
13141 row
->indicate_empty_line_p
= 1;
13144 it
->continuation_lines_width
= 0;
13145 row
->ends_at_zv_p
= 1;
13149 /* Now, get the metrics of what we want to display. This also
13150 generates glyphs in `row' (which is IT->glyph_row). */
13151 n_glyphs_before
= row
->used
[TEXT_AREA
];
13154 /* Remember the line height so far in case the next element doesn't
13155 fit on the line. */
13156 if (!it
->truncate_lines_p
)
13158 ascent
= it
->max_ascent
;
13159 descent
= it
->max_descent
;
13160 phys_ascent
= it
->max_phys_ascent
;
13161 phys_descent
= it
->max_phys_descent
;
13164 PRODUCE_GLYPHS (it
);
13166 /* If this display element was in marginal areas, continue with
13168 if (it
->area
!= TEXT_AREA
)
13170 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13171 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13172 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13173 row
->phys_height
= max (row
->phys_height
,
13174 it
->max_phys_ascent
+ it
->max_phys_descent
);
13175 set_iterator_to_next (it
, 1);
13179 /* Does the display element fit on the line? If we truncate
13180 lines, we should draw past the right edge of the window. If
13181 we don't truncate, we want to stop so that we can display the
13182 continuation glyph before the right margin. If lines are
13183 continued, there are two possible strategies for characters
13184 resulting in more than 1 glyph (e.g. tabs): Display as many
13185 glyphs as possible in this line and leave the rest for the
13186 continuation line, or display the whole element in the next
13187 line. Original redisplay did the former, so we do it also. */
13188 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
13189 hpos_before
= it
->hpos
;
13192 if (/* Not a newline. */
13194 /* Glyphs produced fit entirely in the line. */
13195 && it
->current_x
< it
->last_visible_x
)
13197 it
->hpos
+= nglyphs
;
13198 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13199 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13200 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13201 row
->phys_height
= max (row
->phys_height
,
13202 it
->max_phys_ascent
+ it
->max_phys_descent
);
13203 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
13204 row
->x
= x
- it
->first_visible_x
;
13209 struct glyph
*glyph
;
13211 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
13213 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13214 new_x
= x
+ glyph
->pixel_width
;
13216 if (/* Lines are continued. */
13217 !it
->truncate_lines_p
13218 && (/* Glyph doesn't fit on the line. */
13219 new_x
> it
->last_visible_x
13220 /* Or it fits exactly on a window system frame. */
13221 || (new_x
== it
->last_visible_x
13222 && FRAME_WINDOW_P (it
->f
))))
13224 /* End of a continued line. */
13227 || (new_x
== it
->last_visible_x
13228 && FRAME_WINDOW_P (it
->f
)))
13230 /* Current glyph is the only one on the line or
13231 fits exactly on the line. We must continue
13232 the line because we can't draw the cursor
13233 after the glyph. */
13234 row
->continued_p
= 1;
13235 it
->current_x
= new_x
;
13236 it
->continuation_lines_width
+= new_x
;
13238 if (i
== nglyphs
- 1)
13239 set_iterator_to_next (it
, 1);
13241 else if (CHAR_GLYPH_PADDING_P (*glyph
)
13242 && !FRAME_WINDOW_P (it
->f
))
13244 /* A padding glyph that doesn't fit on this line.
13245 This means the whole character doesn't fit
13247 row
->used
[TEXT_AREA
] = n_glyphs_before
;
13249 /* Fill the rest of the row with continuation
13250 glyphs like in 20.x. */
13251 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
13252 < row
->glyphs
[1 + TEXT_AREA
])
13253 produce_special_glyphs (it
, IT_CONTINUATION
);
13255 row
->continued_p
= 1;
13256 it
->current_x
= x_before
;
13257 it
->continuation_lines_width
+= x_before
;
13259 /* Restore the height to what it was before the
13260 element not fitting on the line. */
13261 it
->max_ascent
= ascent
;
13262 it
->max_descent
= descent
;
13263 it
->max_phys_ascent
= phys_ascent
;
13264 it
->max_phys_descent
= phys_descent
;
13266 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
13268 /* A TAB that extends past the right edge of the
13269 window. This produces a single glyph on
13270 window system frames. We leave the glyph in
13271 this row and let it fill the row, but don't
13272 consume the TAB. */
13273 it
->continuation_lines_width
+= it
->last_visible_x
;
13274 row
->ends_in_middle_of_char_p
= 1;
13275 row
->continued_p
= 1;
13276 glyph
->pixel_width
= it
->last_visible_x
- x
;
13277 it
->starts_in_middle_of_char_p
= 1;
13281 /* Something other than a TAB that draws past
13282 the right edge of the window. Restore
13283 positions to values before the element. */
13284 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13286 /* Display continuation glyphs. */
13287 if (!FRAME_WINDOW_P (it
->f
))
13288 produce_special_glyphs (it
, IT_CONTINUATION
);
13289 row
->continued_p
= 1;
13291 it
->continuation_lines_width
+= x
;
13293 if (nglyphs
> 1 && i
> 0)
13295 row
->ends_in_middle_of_char_p
= 1;
13296 it
->starts_in_middle_of_char_p
= 1;
13299 /* Restore the height to what it was before the
13300 element not fitting on the line. */
13301 it
->max_ascent
= ascent
;
13302 it
->max_descent
= descent
;
13303 it
->max_phys_ascent
= phys_ascent
;
13304 it
->max_phys_descent
= phys_descent
;
13309 else if (new_x
> it
->first_visible_x
)
13311 /* Increment number of glyphs actually displayed. */
13314 if (x
< it
->first_visible_x
)
13315 /* Glyph is partially visible, i.e. row starts at
13316 negative X position. */
13317 row
->x
= x
- it
->first_visible_x
;
13321 /* Glyph is completely off the left margin of the
13322 window. This should not happen because of the
13323 move_it_in_display_line at the start of this
13324 function, unless the text display area of the
13325 window is empty. */
13326 xassert (it
->first_visible_x
<= it
->last_visible_x
);
13330 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13331 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13332 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13333 row
->phys_height
= max (row
->phys_height
,
13334 it
->max_phys_ascent
+ it
->max_phys_descent
);
13336 /* End of this display line if row is continued. */
13337 if (row
->continued_p
)
13341 /* Is this a line end? If yes, we're also done, after making
13342 sure that a non-default face is extended up to the right
13343 margin of the window. */
13344 if (ITERATOR_AT_END_OF_LINE_P (it
))
13346 int used_before
= row
->used
[TEXT_AREA
];
13348 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13350 /* Add a space at the end of the line that is used to
13351 display the cursor there. */
13352 append_space (it
, 0);
13354 /* Extend the face to the end of the line. */
13355 extend_face_to_end_of_line (it
);
13357 /* Make sure we have the position. */
13358 if (used_before
== 0)
13359 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13361 /* Consume the line end. This skips over invisible lines. */
13362 set_iterator_to_next (it
, 1);
13363 it
->continuation_lines_width
= 0;
13367 /* Proceed with next display element. Note that this skips
13368 over lines invisible because of selective display. */
13369 set_iterator_to_next (it
, 1);
13371 /* If we truncate lines, we are done when the last displayed
13372 glyphs reach past the right margin of the window. */
13373 if (it
->truncate_lines_p
13374 && (FRAME_WINDOW_P (it
->f
)
13375 ? (it
->current_x
>= it
->last_visible_x
)
13376 : (it
->current_x
> it
->last_visible_x
)))
13378 /* Maybe add truncation glyphs. */
13379 if (!FRAME_WINDOW_P (it
->f
))
13383 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13384 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13387 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13389 row
->used
[TEXT_AREA
] = i
;
13390 produce_special_glyphs (it
, IT_TRUNCATION
);
13394 row
->truncated_on_right_p
= 1;
13395 it
->continuation_lines_width
= 0;
13396 reseat_at_next_visible_line_start (it
, 0);
13397 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13398 it
->hpos
= hpos_before
;
13399 it
->current_x
= x_before
;
13404 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13405 at the left window margin. */
13406 if (it
->first_visible_x
13407 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13409 if (!FRAME_WINDOW_P (it
->f
))
13410 insert_left_trunc_glyphs (it
);
13411 row
->truncated_on_left_p
= 1;
13414 /* If the start of this line is the overlay arrow-position, then
13415 mark this glyph row as the one containing the overlay arrow.
13416 This is clearly a mess with variable size fonts. It would be
13417 better to let it be displayed like cursors under X. */
13418 if (MARKERP (Voverlay_arrow_position
)
13419 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13420 && (MATRIX_ROW_START_CHARPOS (row
)
13421 == marker_position (Voverlay_arrow_position
))
13422 && STRINGP (Voverlay_arrow_string
)
13423 && ! overlay_arrow_seen
)
13425 /* Overlay arrow in window redisplay is a fringe bitmap. */
13426 if (!FRAME_WINDOW_P (it
->f
))
13428 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13429 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13430 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13431 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13432 struct glyph
*p2
, *end
;
13434 /* Copy the arrow glyphs. */
13435 while (glyph
< arrow_end
)
13438 /* Throw away padding glyphs. */
13440 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13441 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13447 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13451 overlay_arrow_seen
= 1;
13452 row
->overlay_arrow_p
= 1;
13455 /* Compute pixel dimensions of this line. */
13456 compute_line_metrics (it
);
13458 /* Remember the position at which this line ends. */
13459 row
->end
= it
->current
;
13461 /* Maybe set the cursor. */
13462 if (it
->w
->cursor
.vpos
< 0
13463 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13464 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13465 && cursor_row_p (it
->w
, row
))
13466 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13468 /* Highlight trailing whitespace. */
13469 if (!NILP (Vshow_trailing_whitespace
))
13470 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13472 /* Prepare for the next line. This line starts horizontally at (X
13473 HPOS) = (0 0). Vertical positions are incremented. As a
13474 convenience for the caller, IT->glyph_row is set to the next
13476 it
->current_x
= it
->hpos
= 0;
13477 it
->current_y
+= row
->height
;
13480 return row
->displays_text_p
;
13485 /***********************************************************************
13487 ***********************************************************************/
13489 /* Redisplay the menu bar in the frame for window W.
13491 The menu bar of X frames that don't have X toolkit support is
13492 displayed in a special window W->frame->menu_bar_window.
13494 The menu bar of terminal frames is treated specially as far as
13495 glyph matrices are concerned. Menu bar lines are not part of
13496 windows, so the update is done directly on the frame matrix rows
13497 for the menu bar. */
13500 display_menu_bar (w
)
13503 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13508 /* Don't do all this for graphical frames. */
13510 if (!NILP (Vwindow_system
))
13513 #ifdef USE_X_TOOLKIT
13518 if (FRAME_MAC_P (f
))
13522 #ifdef USE_X_TOOLKIT
13523 xassert (!FRAME_WINDOW_P (f
));
13524 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13525 it
.first_visible_x
= 0;
13526 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13527 #else /* not USE_X_TOOLKIT */
13528 if (FRAME_WINDOW_P (f
))
13530 /* Menu bar lines are displayed in the desired matrix of the
13531 dummy window menu_bar_window. */
13532 struct window
*menu_w
;
13533 xassert (WINDOWP (f
->menu_bar_window
));
13534 menu_w
= XWINDOW (f
->menu_bar_window
);
13535 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13537 it
.first_visible_x
= 0;
13538 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13542 /* This is a TTY frame, i.e. character hpos/vpos are used as
13544 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13546 it
.first_visible_x
= 0;
13547 it
.last_visible_x
= FRAME_WIDTH (f
);
13549 #endif /* not USE_X_TOOLKIT */
13551 if (! mode_line_inverse_video
)
13552 /* Force the menu-bar to be displayed in the default face. */
13553 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13555 /* Clear all rows of the menu bar. */
13556 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13558 struct glyph_row
*row
= it
.glyph_row
+ i
;
13559 clear_glyph_row (row
);
13560 row
->enabled_p
= 1;
13561 row
->full_width_p
= 1;
13564 /* Display all items of the menu bar. */
13565 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13566 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13568 Lisp_Object string
;
13570 /* Stop at nil string. */
13571 string
= AREF (items
, i
+ 1);
13575 /* Remember where item was displayed. */
13576 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13578 /* Display the item, pad with one space. */
13579 if (it
.current_x
< it
.last_visible_x
)
13580 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13581 SCHARS (string
) + 1, 0, 0, -1);
13584 /* Fill out the line with spaces. */
13585 if (it
.current_x
< it
.last_visible_x
)
13586 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13588 /* Compute the total height of the lines. */
13589 compute_line_metrics (&it
);
13594 /***********************************************************************
13596 ***********************************************************************/
13598 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13599 FORCE is non-zero, redisplay mode lines unconditionally.
13600 Otherwise, redisplay only mode lines that are garbaged. Value is
13601 the number of windows whose mode lines were redisplayed. */
13604 redisplay_mode_lines (window
, force
)
13605 Lisp_Object window
;
13610 while (!NILP (window
))
13612 struct window
*w
= XWINDOW (window
);
13614 if (WINDOWP (w
->hchild
))
13615 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13616 else if (WINDOWP (w
->vchild
))
13617 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13619 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13620 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13622 struct text_pos lpoint
;
13623 struct buffer
*old
= current_buffer
;
13625 /* Set the window's buffer for the mode line display. */
13626 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13627 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13629 /* Point refers normally to the selected window. For any
13630 other window, set up appropriate value. */
13631 if (!EQ (window
, selected_window
))
13633 struct text_pos pt
;
13635 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13636 if (CHARPOS (pt
) < BEGV
)
13637 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13638 else if (CHARPOS (pt
) > (ZV
- 1))
13639 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13641 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13644 /* Display mode lines. */
13645 clear_glyph_matrix (w
->desired_matrix
);
13646 if (display_mode_lines (w
))
13649 w
->must_be_updated_p
= 1;
13652 /* Restore old settings. */
13653 set_buffer_internal_1 (old
);
13654 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13664 /* Display the mode and/or top line of window W. Value is the number
13665 of mode lines displayed. */
13668 display_mode_lines (w
)
13671 Lisp_Object old_selected_window
, old_selected_frame
;
13674 old_selected_frame
= selected_frame
;
13675 selected_frame
= w
->frame
;
13676 old_selected_window
= selected_window
;
13677 XSETWINDOW (selected_window
, w
);
13679 /* These will be set while the mode line specs are processed. */
13680 line_number_displayed
= 0;
13681 w
->column_number_displayed
= Qnil
;
13683 if (WINDOW_WANTS_MODELINE_P (w
))
13685 struct window
*sel_w
= XWINDOW (old_selected_window
);
13687 /* Select mode line face based on the real selected window. */
13688 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
13689 current_buffer
->mode_line_format
);
13693 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13695 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13696 current_buffer
->header_line_format
);
13700 selected_frame
= old_selected_frame
;
13701 selected_window
= old_selected_window
;
13706 /* Display mode or top line of window W. FACE_ID specifies which line
13707 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13708 FORMAT is the mode line format to display. Value is the pixel
13709 height of the mode line displayed. */
13712 display_mode_line (w
, face_id
, format
)
13714 enum face_id face_id
;
13715 Lisp_Object format
;
13720 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13721 prepare_desired_row (it
.glyph_row
);
13723 if (! mode_line_inverse_video
)
13724 /* Force the mode-line to be displayed in the default face. */
13725 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13727 /* Temporarily make frame's keyboard the current kboard so that
13728 kboard-local variables in the mode_line_format will get the right
13730 push_frame_kboard (it
.f
);
13731 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
13732 pop_frame_kboard ();
13734 /* Fill up with spaces. */
13735 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13737 compute_line_metrics (&it
);
13738 it
.glyph_row
->full_width_p
= 1;
13739 it
.glyph_row
->mode_line_p
= 1;
13740 it
.glyph_row
->continued_p
= 0;
13741 it
.glyph_row
->truncated_on_left_p
= 0;
13742 it
.glyph_row
->truncated_on_right_p
= 0;
13744 /* Make a 3D mode-line have a shadow at its right end. */
13745 face
= FACE_FROM_ID (it
.f
, face_id
);
13746 extend_face_to_end_of_line (&it
);
13747 if (face
->box
!= FACE_NO_BOX
)
13749 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13750 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13751 last
->right_box_line_p
= 1;
13754 return it
.glyph_row
->height
;
13757 /* Alist that caches the results of :propertize.
13758 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
13759 Lisp_Object mode_line_proptrans_alist
;
13761 /* List of strings making up the mode-line. */
13762 Lisp_Object mode_line_string_list
;
13764 /* Base face property when building propertized mode line string. */
13765 static Lisp_Object mode_line_string_face
;
13766 static Lisp_Object mode_line_string_face_prop
;
13769 /* Contribute ELT to the mode line for window IT->w. How it
13770 translates into text depends on its data type.
13772 IT describes the display environment in which we display, as usual.
13774 DEPTH is the depth in recursion. It is used to prevent
13775 infinite recursion here.
13777 FIELD_WIDTH is the number of characters the display of ELT should
13778 occupy in the mode line, and PRECISION is the maximum number of
13779 characters to display from ELT's representation. See
13780 display_string for details.
13782 Returns the hpos of the end of the text generated by ELT.
13784 PROPS is a property list to add to any string we encounter.
13786 If RISKY is nonzero, remove (disregard) any properties in any string
13787 we encounter, and ignore :eval and :propertize.
13789 If the global variable `frame_title_ptr' is non-NULL, then the output
13790 is passed to `store_frame_title' instead of `display_string'. */
13793 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
13796 int field_width
, precision
;
13797 Lisp_Object elt
, props
;
13800 int n
= 0, field
, prec
;
13809 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13813 /* A string: output it and check for %-constructs within it. */
13815 const unsigned char *this, *lisp_string
;
13817 if (!NILP (props
) || risky
)
13819 Lisp_Object oprops
, aelt
;
13820 oprops
= Ftext_properties_at (make_number (0), elt
);
13822 if (NILP (Fequal (props
, oprops
)) || risky
)
13824 /* If the starting string has properties,
13825 merge the specified ones onto the existing ones. */
13826 if (! NILP (oprops
) && !risky
)
13830 oprops
= Fcopy_sequence (oprops
);
13832 while (CONSP (tem
))
13834 oprops
= Fplist_put (oprops
, XCAR (tem
),
13835 XCAR (XCDR (tem
)));
13836 tem
= XCDR (XCDR (tem
));
13841 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
13842 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
13844 mode_line_proptrans_alist
13845 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
13852 elt
= Fcopy_sequence (elt
);
13853 Fset_text_properties (make_number (0), Flength (elt
),
13855 /* Add this item to mode_line_proptrans_alist. */
13856 mode_line_proptrans_alist
13857 = Fcons (Fcons (elt
, props
),
13858 mode_line_proptrans_alist
);
13859 /* Truncate mode_line_proptrans_alist
13860 to at most 50 elements. */
13861 tem
= Fnthcdr (make_number (50),
13862 mode_line_proptrans_alist
);
13864 XSETCDR (tem
, Qnil
);
13869 this = SDATA (elt
);
13870 lisp_string
= this;
13874 prec
= precision
- n
;
13875 if (frame_title_ptr
)
13876 n
+= store_frame_title (SDATA (elt
), -1, prec
);
13877 else if (!NILP (mode_line_string_list
))
13878 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
13880 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
13881 0, prec
, 0, STRING_MULTIBYTE (elt
));
13886 while ((precision
<= 0 || n
< precision
)
13888 && (frame_title_ptr
13889 || !NILP (mode_line_string_list
)
13890 || it
->current_x
< it
->last_visible_x
))
13892 const unsigned char *last
= this;
13894 /* Advance to end of string or next format specifier. */
13895 while ((c
= *this++) != '\0' && c
!= '%')
13898 if (this - 1 != last
)
13900 /* Output to end of string or up to '%'. Field width
13901 is length of string. Don't output more than
13902 PRECISION allows us. */
13905 prec
= chars_in_text (last
, this - last
);
13906 if (precision
> 0 && prec
> precision
- n
)
13907 prec
= precision
- n
;
13909 if (frame_title_ptr
)
13910 n
+= store_frame_title (last
, 0, prec
);
13911 else if (!NILP (mode_line_string_list
))
13913 int bytepos
= last
- lisp_string
;
13914 int charpos
= string_byte_to_char (elt
, bytepos
);
13915 n
+= store_mode_line_string (NULL
,
13916 Fsubstring (elt
, make_number (charpos
),
13917 make_number (charpos
+ prec
)),
13922 int bytepos
= last
- lisp_string
;
13923 int charpos
= string_byte_to_char (elt
, bytepos
);
13924 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
13926 STRING_MULTIBYTE (elt
));
13929 else /* c == '%' */
13931 const unsigned char *percent_position
= this;
13933 /* Get the specified minimum width. Zero means
13936 while ((c
= *this++) >= '0' && c
<= '9')
13937 field
= field
* 10 + c
- '0';
13939 /* Don't pad beyond the total padding allowed. */
13940 if (field_width
- n
> 0 && field
> field_width
- n
)
13941 field
= field_width
- n
;
13943 /* Note that either PRECISION <= 0 or N < PRECISION. */
13944 prec
= precision
- n
;
13947 n
+= display_mode_element (it
, depth
, field
, prec
,
13948 Vglobal_mode_string
, props
,
13953 int bytepos
, charpos
;
13954 unsigned char *spec
;
13956 bytepos
= percent_position
- lisp_string
;
13957 charpos
= (STRING_MULTIBYTE (elt
)
13958 ? string_byte_to_char (elt
, bytepos
)
13962 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
13964 if (frame_title_ptr
)
13965 n
+= store_frame_title (spec
, field
, prec
);
13966 else if (!NILP (mode_line_string_list
))
13968 int len
= strlen (spec
);
13969 Lisp_Object tem
= make_string (spec
, len
);
13970 props
= Ftext_properties_at (make_number (charpos
), elt
);
13971 /* Should only keep face property in props */
13972 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
13976 int nglyphs_before
, nwritten
;
13978 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13979 nwritten
= display_string (spec
, Qnil
, elt
,
13984 /* Assign to the glyphs written above the
13985 string where the `%x' came from, position
13989 struct glyph
*glyph
13990 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13994 for (i
= 0; i
< nwritten
; ++i
)
13996 glyph
[i
].object
= elt
;
13997 glyph
[i
].charpos
= charpos
;
14012 /* A symbol: process the value of the symbol recursively
14013 as if it appeared here directly. Avoid error if symbol void.
14014 Special case: if value of symbol is a string, output the string
14017 register Lisp_Object tem
;
14019 /* If the variable is not marked as risky to set
14020 then its contents are risky to use. */
14021 if (NILP (Fget (elt
, Qrisky_local_variable
)))
14024 tem
= Fboundp (elt
);
14027 tem
= Fsymbol_value (elt
);
14028 /* If value is a string, output that string literally:
14029 don't check for % within it. */
14033 if (!EQ (tem
, elt
))
14035 /* Give up right away for nil or t. */
14045 register Lisp_Object car
, tem
;
14047 /* A cons cell: five distinct cases.
14048 If first element is :eval or :propertize, do something special.
14049 If first element is a string or a cons, process all the elements
14050 and effectively concatenate them.
14051 If first element is a negative number, truncate displaying cdr to
14052 at most that many characters. If positive, pad (with spaces)
14053 to at least that many characters.
14054 If first element is a symbol, process the cadr or caddr recursively
14055 according to whether the symbol's value is non-nil or nil. */
14057 if (EQ (car
, QCeval
))
14059 /* An element of the form (:eval FORM) means evaluate FORM
14060 and use the result as mode line elements. */
14065 if (CONSP (XCDR (elt
)))
14068 spec
= safe_eval (XCAR (XCDR (elt
)));
14069 n
+= display_mode_element (it
, depth
, field_width
- n
,
14070 precision
- n
, spec
, props
,
14074 else if (EQ (car
, QCpropertize
))
14076 /* An element of the form (:propertize ELT PROPS...)
14077 means display ELT but applying properties PROPS. */
14082 if (CONSP (XCDR (elt
)))
14083 n
+= display_mode_element (it
, depth
, field_width
- n
,
14084 precision
- n
, XCAR (XCDR (elt
)),
14085 XCDR (XCDR (elt
)), risky
);
14087 else if (SYMBOLP (car
))
14089 tem
= Fboundp (car
);
14093 /* elt is now the cdr, and we know it is a cons cell.
14094 Use its car if CAR has a non-nil value. */
14097 tem
= Fsymbol_value (car
);
14104 /* Symbol's value is nil (or symbol is unbound)
14105 Get the cddr of the original list
14106 and if possible find the caddr and use that. */
14110 else if (!CONSP (elt
))
14115 else if (INTEGERP (car
))
14117 register int lim
= XINT (car
);
14121 /* Negative int means reduce maximum width. */
14122 if (precision
<= 0)
14125 precision
= min (precision
, -lim
);
14129 /* Padding specified. Don't let it be more than
14130 current maximum. */
14132 lim
= min (precision
, lim
);
14134 /* If that's more padding than already wanted, queue it.
14135 But don't reduce padding already specified even if
14136 that is beyond the current truncation point. */
14137 field_width
= max (lim
, field_width
);
14141 else if (STRINGP (car
) || CONSP (car
))
14143 register int limit
= 50;
14144 /* Limit is to protect against circular lists. */
14147 && (precision
<= 0 || n
< precision
))
14149 n
+= display_mode_element (it
, depth
, field_width
- n
,
14150 precision
- n
, XCAR (elt
),
14160 if (frame_title_ptr
)
14161 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
14162 else if (!NILP (mode_line_string_list
))
14163 n
+= store_mode_line_string ("*invalid*", Qnil
, 0, 0, precision
- n
, Qnil
);
14165 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
14166 precision
- n
, 0, 0);
14170 /* Pad to FIELD_WIDTH. */
14171 if (field_width
> 0 && n
< field_width
)
14173 if (frame_title_ptr
)
14174 n
+= store_frame_title ("", field_width
- n
, 0);
14175 else if (!NILP (mode_line_string_list
))
14176 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
14178 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
14185 /* Store a mode-line string element in mode_line_string_list.
14187 If STRING is non-null, display that C string. Otherwise, the Lisp
14188 string LISP_STRING is displayed.
14190 FIELD_WIDTH is the minimum number of output glyphs to produce.
14191 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14192 with spaces. FIELD_WIDTH <= 0 means don't pad.
14194 PRECISION is the maximum number of characters to output from
14195 STRING. PRECISION <= 0 means don't truncate the string.
14197 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
14198 properties to the string.
14200 PROPS are the properties to add to the string.
14201 The mode_line_string_face face property is always added to the string.
14204 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
14206 Lisp_Object lisp_string
;
14215 if (string
!= NULL
)
14217 len
= strlen (string
);
14218 if (precision
> 0 && len
> precision
)
14220 lisp_string
= make_string (string
, len
);
14222 props
= mode_line_string_face_prop
;
14223 else if (!NILP (mode_line_string_face
))
14225 Lisp_Object face
= Fplist_get (props
, Qface
);
14226 props
= Fcopy_sequence (props
);
14228 face
= mode_line_string_face
;
14230 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14231 props
= Fplist_put (props
, Qface
, face
);
14233 Fadd_text_properties (make_number (0), make_number (len
),
14234 props
, lisp_string
);
14238 len
= XFASTINT (Flength (lisp_string
));
14239 if (precision
> 0 && len
> precision
)
14242 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
14245 if (!NILP (mode_line_string_face
))
14249 props
= Ftext_properties_at (make_number (0), lisp_string
);
14250 face
= Fplist_get (props
, Qface
);
14252 face
= mode_line_string_face
;
14254 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14255 props
= Fcons (Qface
, Fcons (face
, Qnil
));
14257 lisp_string
= Fcopy_sequence (lisp_string
);
14260 Fadd_text_properties (make_number (0), make_number (len
),
14261 props
, lisp_string
);
14266 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14270 if (field_width
> len
)
14272 field_width
-= len
;
14273 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
14275 Fadd_text_properties (make_number (0), make_number (field_width
),
14276 props
, lisp_string
);
14277 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14285 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
14287 doc
: /* Return the mode-line of selected window as a string.
14288 First optional arg FORMAT specifies a different format string (see
14289 `mode-line-format' for details) to use. If FORMAT is t, return
14290 the buffer's header-line. Second optional arg WINDOW specifies a
14291 different window to use as the context for the formatting.
14292 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
14293 (format
, window
, no_props
)
14294 Lisp_Object format
, window
, no_props
;
14299 struct buffer
*old_buffer
= NULL
;
14300 enum face_id face_id
= DEFAULT_FACE_ID
;
14303 window
= selected_window
;
14304 CHECK_WINDOW (window
);
14305 w
= XWINDOW (window
);
14306 CHECK_BUFFER (w
->buffer
);
14308 if (XBUFFER (w
->buffer
) != current_buffer
)
14310 old_buffer
= current_buffer
;
14311 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14314 if (NILP (format
) || EQ (format
, Qt
))
14316 face_id
= NILP (format
)
14317 ? CURRENT_MODE_LINE_FACE_ID (w
) :
14318 HEADER_LINE_FACE_ID
;
14319 format
= NILP (format
)
14320 ? current_buffer
->mode_line_format
14321 : current_buffer
->header_line_format
;
14324 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
14326 if (NILP (no_props
))
14328 mode_line_string_face
=
14329 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
14330 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
14331 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
14333 mode_line_string_face_prop
=
14334 NILP (mode_line_string_face
) ? Qnil
:
14335 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
14337 /* We need a dummy last element in mode_line_string_list to
14338 indicate we are building the propertized mode-line string.
14339 Using mode_line_string_face_prop here GC protects it. */
14340 mode_line_string_list
=
14341 Fcons (mode_line_string_face_prop
, Qnil
);
14342 frame_title_ptr
= NULL
;
14346 mode_line_string_face_prop
= Qnil
;
14347 mode_line_string_list
= Qnil
;
14348 frame_title_ptr
= frame_title_buf
;
14351 push_frame_kboard (it
.f
);
14352 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
14353 pop_frame_kboard ();
14356 set_buffer_internal_1 (old_buffer
);
14358 if (NILP (no_props
))
14361 mode_line_string_list
= Fnreverse (mode_line_string_list
);
14362 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
14363 make_string ("", 0));
14364 mode_line_string_face_prop
= Qnil
;
14365 mode_line_string_list
= Qnil
;
14369 len
= frame_title_ptr
- frame_title_buf
;
14370 if (len
> 0 && frame_title_ptr
[-1] == '-')
14372 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
14373 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
14375 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
14376 if (len
> frame_title_ptr
- frame_title_buf
)
14377 len
= frame_title_ptr
- frame_title_buf
;
14380 frame_title_ptr
= NULL
;
14381 return make_string (frame_title_buf
, len
);
14384 /* Write a null-terminated, right justified decimal representation of
14385 the positive integer D to BUF using a minimal field width WIDTH. */
14388 pint2str (buf
, width
, d
)
14389 register char *buf
;
14390 register int width
;
14393 register char *p
= buf
;
14401 *p
++ = d
% 10 + '0';
14406 for (width
-= (int) (p
- buf
); width
> 0; --width
)
14417 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
14418 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
14419 type of CODING_SYSTEM. Return updated pointer into BUF. */
14421 static unsigned char invalid_eol_type
[] = "(*invalid*)";
14424 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
14425 Lisp_Object coding_system
;
14426 register char *buf
;
14430 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
14431 const unsigned char *eol_str
;
14433 /* The EOL conversion we are using. */
14434 Lisp_Object eoltype
;
14436 val
= Fget (coding_system
, Qcoding_system
);
14439 if (!VECTORP (val
)) /* Not yet decided. */
14444 eoltype
= eol_mnemonic_undecided
;
14445 /* Don't mention EOL conversion if it isn't decided. */
14449 Lisp_Object eolvalue
;
14451 eolvalue
= Fget (coding_system
, Qeol_type
);
14454 *buf
++ = XFASTINT (AREF (val
, 1));
14458 /* The EOL conversion that is normal on this system. */
14460 if (NILP (eolvalue
)) /* Not yet decided. */
14461 eoltype
= eol_mnemonic_undecided
;
14462 else if (VECTORP (eolvalue
)) /* Not yet decided. */
14463 eoltype
= eol_mnemonic_undecided
;
14464 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
14465 eoltype
= (XFASTINT (eolvalue
) == 0
14466 ? eol_mnemonic_unix
14467 : (XFASTINT (eolvalue
) == 1
14468 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
14474 /* Mention the EOL conversion if it is not the usual one. */
14475 if (STRINGP (eoltype
))
14477 eol_str
= SDATA (eoltype
);
14478 eol_str_len
= SBYTES (eoltype
);
14480 else if (INTEGERP (eoltype
)
14481 && CHAR_VALID_P (XINT (eoltype
), 0))
14483 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
14484 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
14489 eol_str
= invalid_eol_type
;
14490 eol_str_len
= sizeof (invalid_eol_type
) - 1;
14492 bcopy (eol_str
, buf
, eol_str_len
);
14493 buf
+= eol_str_len
;
14499 /* Return a string for the output of a mode line %-spec for window W,
14500 generated by character C. PRECISION >= 0 means don't return a
14501 string longer than that value. FIELD_WIDTH > 0 means pad the
14502 string returned with spaces to that value. Return 1 in *MULTIBYTE
14503 if the result is multibyte text. */
14505 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
14508 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
14511 int field_width
, precision
;
14515 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14516 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
14517 struct buffer
*b
= XBUFFER (w
->buffer
);
14525 if (!NILP (b
->read_only
))
14527 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14532 /* This differs from %* only for a modified read-only buffer. */
14533 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14535 if (!NILP (b
->read_only
))
14540 /* This differs from %* in ignoring read-only-ness. */
14541 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14553 if (command_loop_level
> 5)
14555 p
= decode_mode_spec_buf
;
14556 for (i
= 0; i
< command_loop_level
; i
++)
14559 return decode_mode_spec_buf
;
14567 if (command_loop_level
> 5)
14569 p
= decode_mode_spec_buf
;
14570 for (i
= 0; i
< command_loop_level
; i
++)
14573 return decode_mode_spec_buf
;
14580 /* Let lots_of_dashes be a string of infinite length. */
14581 if (!NILP (mode_line_string_list
))
14583 if (field_width
<= 0
14584 || field_width
> sizeof (lots_of_dashes
))
14586 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
14587 decode_mode_spec_buf
[i
] = '-';
14588 decode_mode_spec_buf
[i
] = '\0';
14589 return decode_mode_spec_buf
;
14592 return lots_of_dashes
;
14601 int col
= (int) current_column (); /* iftc */
14602 w
->column_number_displayed
= make_number (col
);
14603 pint2str (decode_mode_spec_buf
, field_width
, col
);
14604 return decode_mode_spec_buf
;
14608 /* %F displays the frame name. */
14609 if (!NILP (f
->title
))
14610 return (char *) SDATA (f
->title
);
14611 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
14612 return (char *) SDATA (f
->name
);
14621 int startpos
= XMARKER (w
->start
)->charpos
;
14622 int startpos_byte
= marker_byte_position (w
->start
);
14623 int line
, linepos
, linepos_byte
, topline
;
14625 int height
= XFASTINT (w
->height
);
14627 /* If we decided that this buffer isn't suitable for line numbers,
14628 don't forget that too fast. */
14629 if (EQ (w
->base_line_pos
, w
->buffer
))
14631 /* But do forget it, if the window shows a different buffer now. */
14632 else if (BUFFERP (w
->base_line_pos
))
14633 w
->base_line_pos
= Qnil
;
14635 /* If the buffer is very big, don't waste time. */
14636 if (INTEGERP (Vline_number_display_limit
)
14637 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
14639 w
->base_line_pos
= Qnil
;
14640 w
->base_line_number
= Qnil
;
14644 if (!NILP (w
->base_line_number
)
14645 && !NILP (w
->base_line_pos
)
14646 && XFASTINT (w
->base_line_pos
) <= startpos
)
14648 line
= XFASTINT (w
->base_line_number
);
14649 linepos
= XFASTINT (w
->base_line_pos
);
14650 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
14655 linepos
= BUF_BEGV (b
);
14656 linepos_byte
= BUF_BEGV_BYTE (b
);
14659 /* Count lines from base line to window start position. */
14660 nlines
= display_count_lines (linepos
, linepos_byte
,
14664 topline
= nlines
+ line
;
14666 /* Determine a new base line, if the old one is too close
14667 or too far away, or if we did not have one.
14668 "Too close" means it's plausible a scroll-down would
14669 go back past it. */
14670 if (startpos
== BUF_BEGV (b
))
14672 w
->base_line_number
= make_number (topline
);
14673 w
->base_line_pos
= make_number (BUF_BEGV (b
));
14675 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
14676 || linepos
== BUF_BEGV (b
))
14678 int limit
= BUF_BEGV (b
);
14679 int limit_byte
= BUF_BEGV_BYTE (b
);
14681 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
14683 if (startpos
- distance
> limit
)
14685 limit
= startpos
- distance
;
14686 limit_byte
= CHAR_TO_BYTE (limit
);
14689 nlines
= display_count_lines (startpos
, startpos_byte
,
14691 - (height
* 2 + 30),
14693 /* If we couldn't find the lines we wanted within
14694 line_number_display_limit_width chars per line,
14695 give up on line numbers for this window. */
14696 if (position
== limit_byte
&& limit
== startpos
- distance
)
14698 w
->base_line_pos
= w
->buffer
;
14699 w
->base_line_number
= Qnil
;
14703 w
->base_line_number
= make_number (topline
- nlines
);
14704 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
14707 /* Now count lines from the start pos to point. */
14708 nlines
= display_count_lines (startpos
, startpos_byte
,
14709 PT_BYTE
, PT
, &junk
);
14711 /* Record that we did display the line number. */
14712 line_number_displayed
= 1;
14714 /* Make the string to show. */
14715 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
14716 return decode_mode_spec_buf
;
14719 char* p
= decode_mode_spec_buf
;
14720 int pad
= field_width
- 2;
14726 return decode_mode_spec_buf
;
14732 obj
= b
->mode_name
;
14736 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
14742 int pos
= marker_position (w
->start
);
14743 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14745 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
14747 if (pos
<= BUF_BEGV (b
))
14752 else if (pos
<= BUF_BEGV (b
))
14756 if (total
> 1000000)
14757 /* Do it differently for a large value, to avoid overflow. */
14758 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14760 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14761 /* We can't normally display a 3-digit number,
14762 so get us a 2-digit number that is close. */
14765 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14766 return decode_mode_spec_buf
;
14770 /* Display percentage of size above the bottom of the screen. */
14773 int toppos
= marker_position (w
->start
);
14774 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14775 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14777 if (botpos
>= BUF_ZV (b
))
14779 if (toppos
<= BUF_BEGV (b
))
14786 if (total
> 1000000)
14787 /* Do it differently for a large value, to avoid overflow. */
14788 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14790 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14791 /* We can't normally display a 3-digit number,
14792 so get us a 2-digit number that is close. */
14795 if (toppos
<= BUF_BEGV (b
))
14796 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14798 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14799 return decode_mode_spec_buf
;
14804 /* status of process */
14805 obj
= Fget_buffer_process (w
->buffer
);
14807 return "no process";
14808 #ifdef subprocesses
14809 obj
= Fsymbol_name (Fprocess_status (obj
));
14813 case 't': /* indicate TEXT or BINARY */
14814 #ifdef MODE_LINE_BINARY_TEXT
14815 return MODE_LINE_BINARY_TEXT (b
);
14821 /* coding-system (not including end-of-line format) */
14823 /* coding-system (including end-of-line type) */
14825 int eol_flag
= (c
== 'Z');
14826 char *p
= decode_mode_spec_buf
;
14828 if (! FRAME_WINDOW_P (f
))
14830 /* No need to mention EOL here--the terminal never needs
14831 to do EOL conversion. */
14832 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14833 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14835 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14838 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14839 #ifdef subprocesses
14840 obj
= Fget_buffer_process (Fcurrent_buffer ());
14841 if (PROCESSP (obj
))
14843 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14845 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14848 #endif /* subprocesses */
14851 return decode_mode_spec_buf
;
14857 *multibyte
= STRING_MULTIBYTE (obj
);
14858 return (char *) SDATA (obj
);
14865 /* Count up to COUNT lines starting from START / START_BYTE.
14866 But don't go beyond LIMIT_BYTE.
14867 Return the number of lines thus found (always nonnegative).
14869 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14872 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14873 int start
, start_byte
, limit_byte
, count
;
14876 register unsigned char *cursor
;
14877 unsigned char *base
;
14879 register int ceiling
;
14880 register unsigned char *ceiling_addr
;
14881 int orig_count
= count
;
14883 /* If we are not in selective display mode,
14884 check only for newlines. */
14885 int selective_display
= (!NILP (current_buffer
->selective_display
)
14886 && !INTEGERP (current_buffer
->selective_display
));
14890 while (start_byte
< limit_byte
)
14892 ceiling
= BUFFER_CEILING_OF (start_byte
);
14893 ceiling
= min (limit_byte
- 1, ceiling
);
14894 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14895 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14898 if (selective_display
)
14899 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14902 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14905 if (cursor
!= ceiling_addr
)
14909 start_byte
+= cursor
- base
+ 1;
14910 *byte_pos_ptr
= start_byte
;
14914 if (++cursor
== ceiling_addr
)
14920 start_byte
+= cursor
- base
;
14925 while (start_byte
> limit_byte
)
14927 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14928 ceiling
= max (limit_byte
, ceiling
);
14929 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14930 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14933 if (selective_display
)
14934 while (--cursor
!= ceiling_addr
14935 && *cursor
!= '\n' && *cursor
!= 015)
14938 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14941 if (cursor
!= ceiling_addr
)
14945 start_byte
+= cursor
- base
+ 1;
14946 *byte_pos_ptr
= start_byte
;
14947 /* When scanning backwards, we should
14948 not count the newline posterior to which we stop. */
14949 return - orig_count
- 1;
14955 /* Here we add 1 to compensate for the last decrement
14956 of CURSOR, which took it past the valid range. */
14957 start_byte
+= cursor
- base
+ 1;
14961 *byte_pos_ptr
= limit_byte
;
14964 return - orig_count
+ count
;
14965 return orig_count
- count
;
14971 /***********************************************************************
14973 ***********************************************************************/
14975 /* Display a NUL-terminated string, starting with index START.
14977 If STRING is non-null, display that C string. Otherwise, the Lisp
14978 string LISP_STRING is displayed.
14980 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14981 FACE_STRING. Display STRING or LISP_STRING with the face at
14982 FACE_STRING_POS in FACE_STRING:
14984 Display the string in the environment given by IT, but use the
14985 standard display table, temporarily.
14987 FIELD_WIDTH is the minimum number of output glyphs to produce.
14988 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14989 with spaces. If STRING has more characters, more than FIELD_WIDTH
14990 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14992 PRECISION is the maximum number of characters to output from
14993 STRING. PRECISION < 0 means don't truncate the string.
14995 This is roughly equivalent to printf format specifiers:
14997 FIELD_WIDTH PRECISION PRINTF
14998 ----------------------------------------
15004 MULTIBYTE zero means do not display multibyte chars, > 0 means do
15005 display them, and < 0 means obey the current buffer's value of
15006 enable_multibyte_characters.
15008 Value is the number of glyphs produced. */
15011 display_string (string
, lisp_string
, face_string
, face_string_pos
,
15012 start
, it
, field_width
, precision
, max_x
, multibyte
)
15013 unsigned char *string
;
15014 Lisp_Object lisp_string
;
15015 Lisp_Object face_string
;
15016 int face_string_pos
;
15019 int field_width
, precision
, max_x
;
15022 int hpos_at_start
= it
->hpos
;
15023 int saved_face_id
= it
->face_id
;
15024 struct glyph_row
*row
= it
->glyph_row
;
15026 /* Initialize the iterator IT for iteration over STRING beginning
15027 with index START. */
15028 reseat_to_string (it
, string
, lisp_string
, start
,
15029 precision
, field_width
, multibyte
);
15031 /* If displaying STRING, set up the face of the iterator
15032 from LISP_STRING, if that's given. */
15033 if (STRINGP (face_string
))
15039 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
15040 0, it
->region_beg_charpos
,
15041 it
->region_end_charpos
,
15042 &endptr
, it
->base_face_id
, 0);
15043 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15044 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
15047 /* Set max_x to the maximum allowed X position. Don't let it go
15048 beyond the right edge of the window. */
15050 max_x
= it
->last_visible_x
;
15052 max_x
= min (max_x
, it
->last_visible_x
);
15054 /* Skip over display elements that are not visible. because IT->w is
15056 if (it
->current_x
< it
->first_visible_x
)
15057 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
15058 MOVE_TO_POS
| MOVE_TO_X
);
15060 row
->ascent
= it
->max_ascent
;
15061 row
->height
= it
->max_ascent
+ it
->max_descent
;
15062 row
->phys_ascent
= it
->max_phys_ascent
;
15063 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15065 /* This condition is for the case that we are called with current_x
15066 past last_visible_x. */
15067 while (it
->current_x
< max_x
)
15069 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
15071 /* Get the next display element. */
15072 if (!get_next_display_element (it
))
15075 /* Produce glyphs. */
15076 x_before
= it
->current_x
;
15077 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15078 PRODUCE_GLYPHS (it
);
15080 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
15083 while (i
< nglyphs
)
15085 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15087 if (!it
->truncate_lines_p
15088 && x
+ glyph
->pixel_width
> max_x
)
15090 /* End of continued line or max_x reached. */
15091 if (CHAR_GLYPH_PADDING_P (*glyph
))
15093 /* A wide character is unbreakable. */
15094 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15095 it
->current_x
= x_before
;
15099 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15104 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
15106 /* Glyph is at least partially visible. */
15108 if (x
< it
->first_visible_x
)
15109 it
->glyph_row
->x
= x
- it
->first_visible_x
;
15113 /* Glyph is off the left margin of the display area.
15114 Should not happen. */
15118 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15119 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15120 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15121 row
->phys_height
= max (row
->phys_height
,
15122 it
->max_phys_ascent
+ it
->max_phys_descent
);
15123 x
+= glyph
->pixel_width
;
15127 /* Stop if max_x reached. */
15131 /* Stop at line ends. */
15132 if (ITERATOR_AT_END_OF_LINE_P (it
))
15134 it
->continuation_lines_width
= 0;
15138 set_iterator_to_next (it
, 1);
15140 /* Stop if truncating at the right edge. */
15141 if (it
->truncate_lines_p
15142 && it
->current_x
>= it
->last_visible_x
)
15144 /* Add truncation mark, but don't do it if the line is
15145 truncated at a padding space. */
15146 if (IT_CHARPOS (*it
) < it
->string_nchars
)
15148 if (!FRAME_WINDOW_P (it
->f
))
15152 if (it
->current_x
> it
->last_visible_x
)
15154 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15155 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15157 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15159 row
->used
[TEXT_AREA
] = i
;
15160 produce_special_glyphs (it
, IT_TRUNCATION
);
15163 produce_special_glyphs (it
, IT_TRUNCATION
);
15165 it
->glyph_row
->truncated_on_right_p
= 1;
15171 /* Maybe insert a truncation at the left. */
15172 if (it
->first_visible_x
15173 && IT_CHARPOS (*it
) > 0)
15175 if (!FRAME_WINDOW_P (it
->f
))
15176 insert_left_trunc_glyphs (it
);
15177 it
->glyph_row
->truncated_on_left_p
= 1;
15180 it
->face_id
= saved_face_id
;
15182 /* Value is number of columns displayed. */
15183 return it
->hpos
- hpos_at_start
;
15188 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
15189 appears as an element of LIST or as the car of an element of LIST.
15190 If PROPVAL is a list, compare each element against LIST in that
15191 way, and return 1/2 if any element of PROPVAL is found in LIST.
15192 Otherwise return 0. This function cannot quit.
15193 The return value is 2 if the text is invisible but with an ellipsis
15194 and 1 if it's invisible and without an ellipsis. */
15197 invisible_p (propval
, list
)
15198 register Lisp_Object propval
;
15201 register Lisp_Object tail
, proptail
;
15203 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15205 register Lisp_Object tem
;
15207 if (EQ (propval
, tem
))
15209 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
15210 return NILP (XCDR (tem
)) ? 1 : 2;
15213 if (CONSP (propval
))
15215 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
15217 Lisp_Object propelt
;
15218 propelt
= XCAR (proptail
);
15219 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15221 register Lisp_Object tem
;
15223 if (EQ (propelt
, tem
))
15225 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
15226 return NILP (XCDR (tem
)) ? 1 : 2;
15235 /***********************************************************************
15237 ***********************************************************************/
15239 /* Value is the internal representation of the specified cursor type
15240 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
15241 of the bar cursor. */
15243 enum text_cursor_kinds
15244 get_specified_cursor_type (arg
, width
)
15248 enum text_cursor_kinds type
;
15253 if (EQ (arg
, Qbox
))
15254 return FILLED_BOX_CURSOR
;
15256 if (EQ (arg
, Qhollow
))
15257 return HOLLOW_BOX_CURSOR
;
15259 if (EQ (arg
, Qbar
))
15266 && EQ (XCAR (arg
), Qbar
)
15267 && INTEGERP (XCDR (arg
))
15268 && XINT (XCDR (arg
)) >= 0)
15270 *width
= XINT (XCDR (arg
));
15274 if (EQ (arg
, Qhbar
))
15277 return HBAR_CURSOR
;
15281 && EQ (XCAR (arg
), Qhbar
)
15282 && INTEGERP (XCDR (arg
))
15283 && XINT (XCDR (arg
)) >= 0)
15285 *width
= XINT (XCDR (arg
));
15286 return HBAR_CURSOR
;
15289 /* Treat anything unknown as "hollow box cursor".
15290 It was bad to signal an error; people have trouble fixing
15291 .Xdefaults with Emacs, when it has something bad in it. */
15292 type
= HOLLOW_BOX_CURSOR
;
15297 /* Set the default cursor types for specified frame. */
15299 set_frame_cursor_types (f
, arg
)
15306 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
15307 FRAME_CURSOR_WIDTH (f
) = width
;
15309 /* By default, set up the blink-off state depending on the on-state. */
15311 tem
= Fassoc (arg
, Vblink_cursor_alist
);
15314 FRAME_BLINK_OFF_CURSOR (f
)
15315 = get_specified_cursor_type (XCDR (tem
), &width
);
15316 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
15319 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
15323 /* Return the cursor we want to be displayed in window W. Return
15324 width of bar/hbar cursor through WIDTH arg. Return with
15325 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
15326 (i.e. if the `system caret' should track this cursor).
15328 In a mini-buffer window, we want the cursor only to appear if we
15329 are reading input from this window. For the selected window, we
15330 want the cursor type given by the frame parameter or buffer local
15331 setting of cursor-type. If explicitly marked off, draw no cursor.
15332 In all other cases, we want a hollow box cursor. */
15334 enum text_cursor_kinds
15335 get_window_cursor_type (w
, width
, active_cursor
)
15338 int *active_cursor
;
15340 struct frame
*f
= XFRAME (w
->frame
);
15341 struct buffer
*b
= XBUFFER (w
->buffer
);
15342 int cursor_type
= DEFAULT_CURSOR
;
15343 Lisp_Object alt_cursor
;
15344 int non_selected
= 0;
15346 *active_cursor
= 1;
15349 if (cursor_in_echo_area
15350 && FRAME_HAS_MINIBUF_P (f
)
15351 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
15353 if (w
== XWINDOW (echo_area_window
))
15355 *width
= FRAME_CURSOR_WIDTH (f
);
15356 return FRAME_DESIRED_CURSOR (f
);
15359 *active_cursor
= 0;
15363 /* Nonselected window or nonselected frame. */
15364 else if (w
!= XWINDOW (f
->selected_window
)
15365 #ifdef HAVE_WINDOW_SYSTEM
15366 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
15370 *active_cursor
= 0;
15372 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
15378 /* Never display a cursor in a window in which cursor-type is nil. */
15379 if (NILP (b
->cursor_type
))
15382 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
15385 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
15386 return get_specified_cursor_type (alt_cursor
, width
);
15389 /* Get the normal cursor type for this window. */
15390 if (EQ (b
->cursor_type
, Qt
))
15392 cursor_type
= FRAME_DESIRED_CURSOR (f
);
15393 *width
= FRAME_CURSOR_WIDTH (f
);
15396 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
15398 /* Use normal cursor if not blinked off. */
15399 if (!w
->cursor_off_p
)
15400 return cursor_type
;
15402 /* Cursor is blinked off, so determine how to "toggle" it. */
15404 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
15405 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
15406 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
15408 /* Then see if frame has specified a specific blink off cursor type. */
15409 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
15411 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
15412 return FRAME_BLINK_OFF_CURSOR (f
);
15415 /* Finally perform built-in cursor blinking:
15416 filled box <-> hollow box
15417 wide [h]bar <-> narrow [h]bar
15418 narrow [h]bar <-> no cursor
15419 other type <-> no cursor */
15421 if (cursor_type
== FILLED_BOX_CURSOR
)
15422 return HOLLOW_BOX_CURSOR
;
15424 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
15427 return cursor_type
;
15434 /***********************************************************************
15436 ***********************************************************************/
15441 Vwith_echo_area_save_vector
= Qnil
;
15442 staticpro (&Vwith_echo_area_save_vector
);
15444 Vmessage_stack
= Qnil
;
15445 staticpro (&Vmessage_stack
);
15447 Qinhibit_redisplay
= intern ("inhibit-redisplay");
15448 staticpro (&Qinhibit_redisplay
);
15450 message_dolog_marker1
= Fmake_marker ();
15451 staticpro (&message_dolog_marker1
);
15452 message_dolog_marker2
= Fmake_marker ();
15453 staticpro (&message_dolog_marker2
);
15454 message_dolog_marker3
= Fmake_marker ();
15455 staticpro (&message_dolog_marker3
);
15458 defsubr (&Sdump_frame_glyph_matrix
);
15459 defsubr (&Sdump_glyph_matrix
);
15460 defsubr (&Sdump_glyph_row
);
15461 defsubr (&Sdump_tool_bar_row
);
15462 defsubr (&Strace_redisplay
);
15463 defsubr (&Strace_to_stderr
);
15465 #ifdef HAVE_WINDOW_SYSTEM
15466 defsubr (&Stool_bar_lines_needed
);
15468 defsubr (&Sformat_mode_line
);
15470 staticpro (&Qmenu_bar_update_hook
);
15471 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
15473 staticpro (&Qoverriding_terminal_local_map
);
15474 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
15476 staticpro (&Qoverriding_local_map
);
15477 Qoverriding_local_map
= intern ("overriding-local-map");
15479 staticpro (&Qwindow_scroll_functions
);
15480 Qwindow_scroll_functions
= intern ("window-scroll-functions");
15482 staticpro (&Qredisplay_end_trigger_functions
);
15483 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
15485 staticpro (&Qinhibit_point_motion_hooks
);
15486 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
15488 QCdata
= intern (":data");
15489 staticpro (&QCdata
);
15490 Qdisplay
= intern ("display");
15491 staticpro (&Qdisplay
);
15492 Qspace_width
= intern ("space-width");
15493 staticpro (&Qspace_width
);
15494 Qraise
= intern ("raise");
15495 staticpro (&Qraise
);
15496 Qspace
= intern ("space");
15497 staticpro (&Qspace
);
15498 Qmargin
= intern ("margin");
15499 staticpro (&Qmargin
);
15500 Qleft_margin
= intern ("left-margin");
15501 staticpro (&Qleft_margin
);
15502 Qright_margin
= intern ("right-margin");
15503 staticpro (&Qright_margin
);
15504 Qalign_to
= intern ("align-to");
15505 staticpro (&Qalign_to
);
15506 QCalign_to
= intern (":align-to");
15507 staticpro (&QCalign_to
);
15508 Qrelative_width
= intern ("relative-width");
15509 staticpro (&Qrelative_width
);
15510 QCrelative_width
= intern (":relative-width");
15511 staticpro (&QCrelative_width
);
15512 QCrelative_height
= intern (":relative-height");
15513 staticpro (&QCrelative_height
);
15514 QCeval
= intern (":eval");
15515 staticpro (&QCeval
);
15516 QCpropertize
= intern (":propertize");
15517 staticpro (&QCpropertize
);
15518 Qwhen
= intern ("when");
15519 staticpro (&Qwhen
);
15520 QCfile
= intern (":file");
15521 staticpro (&QCfile
);
15522 Qfontified
= intern ("fontified");
15523 staticpro (&Qfontified
);
15524 Qfontification_functions
= intern ("fontification-functions");
15525 staticpro (&Qfontification_functions
);
15526 Qtrailing_whitespace
= intern ("trailing-whitespace");
15527 staticpro (&Qtrailing_whitespace
);
15528 Qimage
= intern ("image");
15529 staticpro (&Qimage
);
15530 Qmessage_truncate_lines
= intern ("message-truncate-lines");
15531 staticpro (&Qmessage_truncate_lines
);
15532 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
15533 staticpro (&Qcursor_in_non_selected_windows
);
15534 Qgrow_only
= intern ("grow-only");
15535 staticpro (&Qgrow_only
);
15536 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
15537 staticpro (&Qinhibit_menubar_update
);
15538 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
15539 staticpro (&Qinhibit_eval_during_redisplay
);
15540 Qposition
= intern ("position");
15541 staticpro (&Qposition
);
15542 Qbuffer_position
= intern ("buffer-position");
15543 staticpro (&Qbuffer_position
);
15544 Qobject
= intern ("object");
15545 staticpro (&Qobject
);
15546 Qbar
= intern ("bar");
15548 Qhbar
= intern ("hbar");
15549 staticpro (&Qhbar
);
15550 Qbox
= intern ("box");
15552 Qhollow
= intern ("hollow");
15553 staticpro (&Qhollow
);
15554 Qrisky_local_variable
= intern ("risky-local-variable");
15555 staticpro (&Qrisky_local_variable
);
15556 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
15557 staticpro (&Qinhibit_free_realized_faces
);
15559 list_of_error
= Fcons (intern ("error"), Qnil
);
15560 staticpro (&list_of_error
);
15562 last_arrow_position
= Qnil
;
15563 last_arrow_string
= Qnil
;
15564 staticpro (&last_arrow_position
);
15565 staticpro (&last_arrow_string
);
15567 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
15568 staticpro (&echo_buffer
[0]);
15569 staticpro (&echo_buffer
[1]);
15571 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
15572 staticpro (&echo_area_buffer
[0]);
15573 staticpro (&echo_area_buffer
[1]);
15575 Vmessages_buffer_name
= build_string ("*Messages*");
15576 staticpro (&Vmessages_buffer_name
);
15578 mode_line_proptrans_alist
= Qnil
;
15579 staticpro (&mode_line_proptrans_alist
);
15581 mode_line_string_list
= Qnil
;
15582 staticpro (&mode_line_string_list
);
15584 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
15585 doc
: /* Non-nil means highlight trailing whitespace.
15586 The face used for trailing whitespace is `trailing-whitespace'. */);
15587 Vshow_trailing_whitespace
= Qnil
;
15589 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
15590 doc
: /* Non-nil means don't actually do any redisplay.
15591 This is used for internal purposes. */);
15592 Vinhibit_redisplay
= Qnil
;
15594 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
15595 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
15596 Vglobal_mode_string
= Qnil
;
15598 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
15599 doc
: /* Marker for where to display an arrow on top of the buffer text.
15600 This must be the beginning of a line in order to work.
15601 See also `overlay-arrow-string'. */);
15602 Voverlay_arrow_position
= Qnil
;
15604 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
15605 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
15606 Voverlay_arrow_string
= Qnil
;
15608 DEFVAR_INT ("scroll-step", &scroll_step
,
15609 doc
: /* *The number of lines to try scrolling a window by when point moves out.
15610 If that fails to bring point back on frame, point is centered instead.
15611 If this is zero, point is always centered after it moves off frame.
15612 If you want scrolling to always be a line at a time, you should set
15613 `scroll-conservatively' to a large value rather than set this to 1. */);
15615 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
15616 doc
: /* *Scroll up to this many lines, to bring point back on screen.
15617 A value of zero means to scroll the text to center point vertically
15618 in the window. */);
15619 scroll_conservatively
= 0;
15621 DEFVAR_INT ("scroll-margin", &scroll_margin
,
15622 doc
: /* *Number of lines of margin at the top and bottom of a window.
15623 Recenter the window whenever point gets within this many lines
15624 of the top or bottom of the window. */);
15628 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
15631 DEFVAR_BOOL ("truncate-partial-width-windows",
15632 &truncate_partial_width_windows
,
15633 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
15634 truncate_partial_width_windows
= 1;
15636 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
15637 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
15638 Any other value means to use the appropriate face, `mode-line',
15639 `header-line', or `menu' respectively. */);
15640 mode_line_inverse_video
= 1;
15642 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
15643 doc
: /* *Maximum buffer size for which line number should be displayed.
15644 If the buffer is bigger than this, the line number does not appear
15645 in the mode line. A value of nil means no limit. */);
15646 Vline_number_display_limit
= Qnil
;
15648 DEFVAR_INT ("line-number-display-limit-width",
15649 &line_number_display_limit_width
,
15650 doc
: /* *Maximum line width (in characters) for line number display.
15651 If the average length of the lines near point is bigger than this, then the
15652 line number may be omitted from the mode line. */);
15653 line_number_display_limit_width
= 200;
15655 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
15656 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
15657 highlight_nonselected_windows
= 0;
15659 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
15660 doc
: /* Non-nil if more than one frame is visible on this display.
15661 Minibuffer-only frames don't count, but iconified frames do.
15662 This variable is not guaranteed to be accurate except while processing
15663 `frame-title-format' and `icon-title-format'. */);
15665 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
15666 doc
: /* Template for displaying the title bar of visible frames.
15667 \(Assuming the window manager supports this feature.)
15668 This variable has the same structure as `mode-line-format' (which see),
15669 and is used only on frames for which no explicit name has been set
15670 \(see `modify-frame-parameters'). */);
15671 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
15672 doc
: /* Template for displaying the title bar of an iconified frame.
15673 \(Assuming the window manager supports this feature.)
15674 This variable has the same structure as `mode-line-format' (which see),
15675 and is used only on frames for which no explicit name has been set
15676 \(see `modify-frame-parameters'). */);
15678 = Vframe_title_format
15679 = Fcons (intern ("multiple-frames"),
15680 Fcons (build_string ("%b"),
15681 Fcons (Fcons (empty_string
,
15682 Fcons (intern ("invocation-name"),
15683 Fcons (build_string ("@"),
15684 Fcons (intern ("system-name"),
15688 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
15689 doc
: /* Maximum number of lines to keep in the message log buffer.
15690 If nil, disable message logging. If t, log messages but don't truncate
15691 the buffer when it becomes large. */);
15692 Vmessage_log_max
= make_number (50);
15694 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
15695 doc
: /* Functions called before redisplay, if window sizes have changed.
15696 The value should be a list of functions that take one argument.
15697 Just before redisplay, for each frame, if any of its windows have changed
15698 size since the last redisplay, or have been split or deleted,
15699 all the functions in the list are called, with the frame as argument. */);
15700 Vwindow_size_change_functions
= Qnil
;
15702 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
15703 doc
: /* List of Functions to call before redisplaying a window with scrolling.
15704 Each function is called with two arguments, the window
15705 and its new display-start position. Note that the value of `window-end'
15706 is not valid when these functions are called. */);
15707 Vwindow_scroll_functions
= Qnil
;
15709 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
15710 doc
: /* *Non-nil means automatically resize tool-bars.
15711 This increases a tool-bar's height if not all tool-bar items are visible.
15712 It decreases a tool-bar's height when it would display blank lines
15714 auto_resize_tool_bars_p
= 1;
15716 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
15717 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
15718 auto_raise_tool_bar_buttons_p
= 1;
15720 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
15721 doc
: /* *Margin around tool-bar buttons in pixels.
15722 If an integer, use that for both horizontal and vertical margins.
15723 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
15724 HORZ specifying the horizontal margin, and VERT specifying the
15725 vertical margin. */);
15726 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
15728 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
15729 doc
: /* *Relief thickness of tool-bar buttons. */);
15730 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
15732 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
15733 doc
: /* List of functions to call to fontify regions of text.
15734 Each function is called with one argument POS. Functions must
15735 fontify a region starting at POS in the current buffer, and give
15736 fontified regions the property `fontified'. */);
15737 Vfontification_functions
= Qnil
;
15738 Fmake_variable_buffer_local (Qfontification_functions
);
15740 DEFVAR_BOOL ("unibyte-display-via-language-environment",
15741 &unibyte_display_via_language_environment
,
15742 doc
: /* *Non-nil means display unibyte text according to language environment.
15743 Specifically this means that unibyte non-ASCII characters
15744 are displayed by converting them to the equivalent multibyte characters
15745 according to the current language environment. As a result, they are
15746 displayed according to the current fontset. */);
15747 unibyte_display_via_language_environment
= 0;
15749 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
15750 doc
: /* *Maximum height for resizing mini-windows.
15751 If a float, it specifies a fraction of the mini-window frame's height.
15752 If an integer, it specifies a number of lines. */);
15753 Vmax_mini_window_height
= make_float (0.25);
15755 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
15756 doc
: /* *How to resize mini-windows.
15757 A value of nil means don't automatically resize mini-windows.
15758 A value of t means resize them to fit the text displayed in them.
15759 A value of `grow-only', the default, means let mini-windows grow
15760 only, until their display becomes empty, at which point the windows
15761 go back to their normal size. */);
15762 Vresize_mini_windows
= Qgrow_only
;
15764 DEFVAR_LISP ("cursor-in-non-selected-windows",
15765 &Vcursor_in_non_selected_windows
,
15766 doc
: /* *Cursor type to display in non-selected windows.
15767 t means to use hollow box cursor. See `cursor-type' for other values. */);
15768 Vcursor_in_non_selected_windows
= Qt
;
15770 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
15771 doc
: /* Alist specifying how to blink the cursor off.
15772 Each element has the form (ON-STATE . OFF-STATE). Whenever the
15773 `cursor-type' frame-parameter or variable equals ON-STATE,
15774 comparing using `equal', Emacs uses OFF-STATE to specify
15775 how to blink it off. */);
15776 Vblink_cursor_alist
= Qnil
;
15778 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
15779 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
15780 automatic_hscrolling_p
= 1;
15782 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
15783 doc
: /* *How many columns away from the window edge point is allowed to get
15784 before automatic hscrolling will horizontally scroll the window. */);
15785 hscroll_margin
= 5;
15787 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
15788 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
15789 When point is less than `automatic-hscroll-margin' columns from the window
15790 edge, automatic hscrolling will scroll the window by the amount of columns
15791 determined by this variable. If its value is a positive integer, scroll that
15792 many columns. If it's a positive floating-point number, it specifies the
15793 fraction of the window's width to scroll. If it's nil or zero, point will be
15794 centered horizontally after the scroll. Any other value, including negative
15795 numbers, are treated as if the value were zero.
15797 Automatic hscrolling always moves point outside the scroll margin, so if
15798 point was more than scroll step columns inside the margin, the window will
15799 scroll more than the value given by the scroll step.
15801 Note that the lower bound for automatic hscrolling specified by `scroll-left'
15802 and `scroll-right' overrides this variable's effect. */);
15803 Vhscroll_step
= make_number (0);
15805 DEFVAR_LISP ("image-types", &Vimage_types
,
15806 doc
: /* List of supported image types.
15807 Each element of the list is a symbol for a supported image type. */);
15808 Vimage_types
= Qnil
;
15810 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
15811 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
15812 Bind this around calls to `message' to let it take effect. */);
15813 message_truncate_lines
= 0;
15815 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
15816 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
15817 Can be used to update submenus whose contents should vary. */);
15818 Vmenu_bar_update_hook
= Qnil
;
15820 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
15821 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
15822 inhibit_menubar_update
= 0;
15824 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
15825 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
15826 inhibit_eval_during_redisplay
= 0;
15828 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
15829 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
15830 inhibit_free_realized_faces
= 0;
15833 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
15834 doc
: /* Inhibit try_window_id display optimization. */);
15835 inhibit_try_window_id
= 0;
15837 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
15838 doc
: /* Inhibit try_window_reusing display optimization. */);
15839 inhibit_try_window_reusing
= 0;
15841 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
15842 doc
: /* Inhibit try_cursor_movement display optimization. */);
15843 inhibit_try_cursor_movement
= 0;
15844 #endif /* GLYPH_DEBUG */
15848 /* Initialize this module when Emacs starts. */
15853 Lisp_Object root_window
;
15854 struct window
*mini_w
;
15856 current_header_line_height
= current_mode_line_height
= -1;
15858 CHARPOS (this_line_start_pos
) = 0;
15860 mini_w
= XWINDOW (minibuf_window
);
15861 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
15863 if (!noninteractive
)
15865 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
15868 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
15869 set_window_height (root_window
,
15870 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
15872 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
15873 set_window_height (minibuf_window
, 1, 0);
15875 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
15876 mini_w
->width
= make_number (FRAME_WIDTH (f
));
15878 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
15879 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
15880 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
15882 /* The default ellipsis glyphs `...'. */
15883 for (i
= 0; i
< 3; ++i
)
15884 default_invis_vector
[i
] = make_number ('.');
15888 /* Allocate the buffer for frame titles.
15889 Also used for `format-mode-line'. */
15891 frame_title_buf
= (char *) xmalloc (size
);
15892 frame_title_buf_end
= frame_title_buf
+ size
;
15893 frame_title_ptr
= NULL
;
15896 help_echo_showing_p
= 0;