1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking a iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
184 #include "termhooks.h"
185 #include "intervals.h"
188 #include "region-cache.h"
191 #ifdef HAVE_X_WINDOWS
201 #define INFINITY 10000000
203 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
204 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
205 extern int pending_menu_activation
;
208 extern int interrupt_input
;
209 extern int command_loop_level
;
211 extern int minibuffer_auto_raise
;
213 extern Lisp_Object Qface
;
214 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
216 extern Lisp_Object Voverriding_local_map
;
217 extern Lisp_Object Voverriding_local_map_menu_flag
;
218 extern Lisp_Object Qmenu_item
;
220 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
221 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
222 Lisp_Object Qredisplay_end_trigger_functions
;
223 Lisp_Object Qinhibit_point_motion_hooks
;
224 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
, QCpropertize
;
225 Lisp_Object Qfontified
;
226 Lisp_Object Qgrow_only
;
227 Lisp_Object Qinhibit_eval_during_redisplay
;
228 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
231 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
233 Lisp_Object Qrisky_local_variable
;
235 /* Holds the list (error). */
236 Lisp_Object list_of_error
;
238 /* Functions called to fontify regions of text. */
240 Lisp_Object Vfontification_functions
;
241 Lisp_Object Qfontification_functions
;
243 /* Non-zero means draw tool bar buttons raised when the mouse moves
246 int auto_raise_tool_bar_buttons_p
;
248 /* Margin around tool bar buttons in pixels. */
250 Lisp_Object Vtool_bar_button_margin
;
252 /* Thickness of shadow to draw around tool bar buttons. */
254 EMACS_INT tool_bar_button_relief
;
256 /* Non-zero means automatically resize tool-bars so that all tool-bar
257 items are visible, and no blank lines remain. */
259 int auto_resize_tool_bars_p
;
261 /* Non-nil means don't actually do any redisplay. */
263 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
265 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
267 int inhibit_eval_during_redisplay
;
269 /* Names of text properties relevant for redisplay. */
271 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
272 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
274 /* Symbols used in text property values. */
276 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
277 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
279 extern Lisp_Object Qheight
;
281 /* Non-nil means highlight trailing whitespace. */
283 Lisp_Object Vshow_trailing_whitespace
;
285 /* Name of the face used to highlight trailing whitespace. */
287 Lisp_Object Qtrailing_whitespace
;
289 /* The symbol `image' which is the car of the lists used to represent
294 /* Non-zero means print newline to stdout before next mini-buffer
297 int noninteractive_need_newline
;
299 /* Non-zero means print newline to message log before next message. */
301 static int message_log_need_newline
;
303 /* Three markers that message_dolog uses.
304 It could allocate them itself, but that causes trouble
305 in handling memory-full errors. */
306 static Lisp_Object message_dolog_marker1
;
307 static Lisp_Object message_dolog_marker2
;
308 static Lisp_Object message_dolog_marker3
;
310 /* The buffer position of the first character appearing entirely or
311 partially on the line of the selected window which contains the
312 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
313 redisplay optimization in redisplay_internal. */
315 static struct text_pos this_line_start_pos
;
317 /* Number of characters past the end of the line above, including the
318 terminating newline. */
320 static struct text_pos this_line_end_pos
;
322 /* The vertical positions and the height of this line. */
324 static int this_line_vpos
;
325 static int this_line_y
;
326 static int this_line_pixel_height
;
328 /* X position at which this display line starts. Usually zero;
329 negative if first character is partially visible. */
331 static int this_line_start_x
;
333 /* Buffer that this_line_.* variables are referring to. */
335 static struct buffer
*this_line_buffer
;
337 /* Nonzero means truncate lines in all windows less wide than the
340 int truncate_partial_width_windows
;
342 /* A flag to control how to display unibyte 8-bit character. */
344 int unibyte_display_via_language_environment
;
346 /* Nonzero means we have more than one non-mini-buffer-only frame.
347 Not guaranteed to be accurate except while parsing
348 frame-title-format. */
352 Lisp_Object Vglobal_mode_string
;
354 /* Marker for where to display an arrow on top of the buffer text. */
356 Lisp_Object Voverlay_arrow_position
;
358 /* String to display for the arrow. Only used on terminal frames. */
360 Lisp_Object Voverlay_arrow_string
;
362 /* Values of those variables at last redisplay. However, if
363 Voverlay_arrow_position is a marker, last_arrow_position is its
364 numerical position. */
366 static Lisp_Object last_arrow_position
, last_arrow_string
;
368 /* Like mode-line-format, but for the title bar on a visible frame. */
370 Lisp_Object Vframe_title_format
;
372 /* Like mode-line-format, but for the title bar on an iconified frame. */
374 Lisp_Object Vicon_title_format
;
376 /* List of functions to call when a window's size changes. These
377 functions get one arg, a frame on which one or more windows' sizes
380 static Lisp_Object Vwindow_size_change_functions
;
382 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
384 /* Nonzero if overlay arrow has been displayed once in this window. */
386 static int overlay_arrow_seen
;
388 /* Nonzero means highlight the region even in nonselected windows. */
390 int highlight_nonselected_windows
;
392 /* If cursor motion alone moves point off frame, try scrolling this
393 many lines up or down if that will bring it back. */
395 static EMACS_INT scroll_step
;
397 /* Nonzero means scroll just far enough to bring point back on the
398 screen, when appropriate. */
400 static EMACS_INT scroll_conservatively
;
402 /* Recenter the window whenever point gets within this many lines of
403 the top or bottom of the window. This value is translated into a
404 pixel value by multiplying it with CANON_Y_UNIT, which means that
405 there is really a fixed pixel height scroll margin. */
407 EMACS_INT scroll_margin
;
409 /* Number of windows showing the buffer of the selected window (or
410 another buffer with the same base buffer). keyboard.c refers to
415 /* Vector containing glyphs for an ellipsis `...'. */
417 static Lisp_Object default_invis_vector
[3];
419 /* Zero means display the mode-line/header-line/menu-bar in the default face
420 (this slightly odd definition is for compatibility with previous versions
421 of emacs), non-zero means display them using their respective faces.
423 This variable is deprecated. */
425 int mode_line_inverse_video
;
427 /* Prompt to display in front of the mini-buffer contents. */
429 Lisp_Object minibuf_prompt
;
431 /* Width of current mini-buffer prompt. Only set after display_line
432 of the line that contains the prompt. */
434 int minibuf_prompt_width
;
436 /* This is the window where the echo area message was displayed. It
437 is always a mini-buffer window, but it may not be the same window
438 currently active as a mini-buffer. */
440 Lisp_Object echo_area_window
;
442 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
443 pushes the current message and the value of
444 message_enable_multibyte on the stack, the function restore_message
445 pops the stack and displays MESSAGE again. */
447 Lisp_Object Vmessage_stack
;
449 /* Nonzero means multibyte characters were enabled when the echo area
450 message was specified. */
452 int message_enable_multibyte
;
454 /* Nonzero if we should redraw the mode lines on the next redisplay. */
456 int update_mode_lines
;
458 /* Nonzero if window sizes or contents have changed since last
459 redisplay that finished. */
461 int windows_or_buffers_changed
;
463 /* Nonzero means a frame's cursor type has been changed. */
465 int cursor_type_changed
;
467 /* Nonzero after display_mode_line if %l was used and it displayed a
470 int line_number_displayed
;
472 /* Maximum buffer size for which to display line numbers. */
474 Lisp_Object Vline_number_display_limit
;
476 /* Line width to consider when repositioning for line number display. */
478 static EMACS_INT line_number_display_limit_width
;
480 /* Number of lines to keep in the message log buffer. t means
481 infinite. nil means don't log at all. */
483 Lisp_Object Vmessage_log_max
;
485 /* The name of the *Messages* buffer, a string. */
487 static Lisp_Object Vmessages_buffer_name
;
489 /* Current, index 0, and last displayed echo area message. Either
490 buffers from echo_buffers, or nil to indicate no message. */
492 Lisp_Object echo_area_buffer
[2];
494 /* The buffers referenced from echo_area_buffer. */
496 static Lisp_Object echo_buffer
[2];
498 /* A vector saved used in with_area_buffer to reduce consing. */
500 static Lisp_Object Vwith_echo_area_save_vector
;
502 /* Non-zero means display_echo_area should display the last echo area
503 message again. Set by redisplay_preserve_echo_area. */
505 static int display_last_displayed_message_p
;
507 /* Nonzero if echo area is being used by print; zero if being used by
510 int message_buf_print
;
512 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
514 Lisp_Object Qinhibit_menubar_update
;
515 int inhibit_menubar_update
;
517 /* Maximum height for resizing mini-windows. Either a float
518 specifying a fraction of the available height, or an integer
519 specifying a number of lines. */
521 Lisp_Object Vmax_mini_window_height
;
523 /* Non-zero means messages should be displayed with truncated
524 lines instead of being continued. */
526 int message_truncate_lines
;
527 Lisp_Object Qmessage_truncate_lines
;
529 /* Set to 1 in clear_message to make redisplay_internal aware
530 of an emptied echo area. */
532 static int message_cleared_p
;
534 /* Non-zero means we want a hollow cursor in windows that are not
535 selected. Zero means there's no cursor in such windows. */
537 Lisp_Object Vcursor_in_non_selected_windows
;
538 Lisp_Object Qcursor_in_non_selected_windows
;
540 /* Specifies the desired cursor-type to use to show the blinking
541 cursor off state and cursor shown in non-selected windows.
542 t means to use the default. */
544 Lisp_Object Valternate_cursor_type
;
545 Lisp_Object Qalternate_cursor_type
;
547 /* How to blink the default frame cursor off. */
548 Lisp_Object Vblink_cursor_alist
;
550 /* A scratch glyph row with contents used for generating truncation
551 glyphs. Also used in direct_output_for_insert. */
553 #define MAX_SCRATCH_GLYPHS 100
554 struct glyph_row scratch_glyph_row
;
555 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
557 /* Ascent and height of the last line processed by move_it_to. */
559 static int last_max_ascent
, last_height
;
561 /* Non-zero if there's a help-echo in the echo area. */
563 int help_echo_showing_p
;
565 /* If >= 0, computed, exact values of mode-line and header-line height
566 to use in the macros CURRENT_MODE_LINE_HEIGHT and
567 CURRENT_HEADER_LINE_HEIGHT. */
569 int current_mode_line_height
, current_header_line_height
;
571 /* The maximum distance to look ahead for text properties. Values
572 that are too small let us call compute_char_face and similar
573 functions too often which is expensive. Values that are too large
574 let us call compute_char_face and alike too often because we
575 might not be interested in text properties that far away. */
577 #define TEXT_PROP_DISTANCE_LIMIT 100
581 /* Variables to turn off display optimizations from Lisp. */
583 int inhibit_try_window_id
, inhibit_try_window_reusing
;
584 int inhibit_try_cursor_movement
;
586 /* Non-zero means print traces of redisplay if compiled with
589 int trace_redisplay_p
;
591 #endif /* GLYPH_DEBUG */
593 #ifdef DEBUG_TRACE_MOVE
594 /* Non-zero means trace with TRACE_MOVE to stderr. */
597 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
599 #define TRACE_MOVE(x) (void) 0
602 /* Non-zero means automatically scroll windows horizontally to make
605 int automatic_hscrolling_p
;
607 /* How close to the margin can point get before the window is scrolled
609 EMACS_INT hscroll_margin
;
611 /* How much to scroll horizontally when point is inside the above margin. */
612 Lisp_Object Vhscroll_step
;
614 /* A list of symbols, one for each supported image type. */
616 Lisp_Object Vimage_types
;
618 /* The variable `resize-mini-windows'. If nil, don't resize
619 mini-windows. If t, always resize them to fit the text they
620 display. If `grow-only', let mini-windows grow only until they
623 Lisp_Object Vresize_mini_windows
;
625 /* Buffer being redisplayed -- for redisplay_window_error. */
627 struct buffer
*displayed_buffer
;
629 /* Value returned from text property handlers (see below). */
634 HANDLED_RECOMPUTE_PROPS
,
635 HANDLED_OVERLAY_STRING_CONSUMED
,
639 /* A description of text properties that redisplay is interested
644 /* The name of the property. */
647 /* A unique index for the property. */
650 /* A handler function called to set up iterator IT from the property
651 at IT's current position. Value is used to steer handle_stop. */
652 enum prop_handled (*handler
) P_ ((struct it
*it
));
655 static enum prop_handled handle_face_prop
P_ ((struct it
*));
656 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
657 static enum prop_handled handle_display_prop
P_ ((struct it
*));
658 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
659 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
660 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
662 /* Properties handled by iterators. */
664 static struct props it_props
[] =
666 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
667 /* Handle `face' before `display' because some sub-properties of
668 `display' need to know the face. */
669 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
670 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
671 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
672 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
676 /* Value is the position described by X. If X is a marker, value is
677 the marker_position of X. Otherwise, value is X. */
679 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
681 /* Enumeration returned by some move_it_.* functions internally. */
685 /* Not used. Undefined value. */
688 /* Move ended at the requested buffer position or ZV. */
689 MOVE_POS_MATCH_OR_ZV
,
691 /* Move ended at the requested X pixel position. */
694 /* Move within a line ended at the end of a line that must be
698 /* Move within a line ended at the end of a line that would
699 be displayed truncated. */
702 /* Move within a line ended at a line end. */
706 /* This counter is used to clear the face cache every once in a while
707 in redisplay_internal. It is incremented for each redisplay.
708 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
711 #define CLEAR_FACE_CACHE_COUNT 500
712 static int clear_face_cache_count
;
714 /* Record the previous terminal frame we displayed. */
716 static struct frame
*previous_terminal_frame
;
718 /* Non-zero while redisplay_internal is in progress. */
722 /* Non-zero means don't free realized faces. Bound while freeing
723 realized faces is dangerous because glyph matrices might still
726 int inhibit_free_realized_faces
;
727 Lisp_Object Qinhibit_free_realized_faces
;
730 /* Function prototypes. */
732 static void setup_for_ellipsis
P_ ((struct it
*));
733 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
734 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
735 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
736 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
737 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
738 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
741 static int invisible_text_between_p
P_ ((struct it
*, int, int));
744 static int next_element_from_ellipsis
P_ ((struct it
*));
745 static void pint2str
P_ ((char *, int, int));
746 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
748 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
749 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
750 static void store_frame_title_char
P_ ((char));
751 static int store_frame_title
P_ ((const unsigned char *, int, int));
752 static void x_consider_frame_title
P_ ((Lisp_Object
));
753 static void handle_stop
P_ ((struct it
*));
754 static int tool_bar_lines_needed
P_ ((struct frame
*));
755 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
756 static void ensure_echo_area_buffers
P_ ((void));
757 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
758 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
759 static int with_echo_area_buffer
P_ ((struct window
*, int,
760 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
761 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
762 static void clear_garbaged_frames
P_ ((void));
763 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
764 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
765 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
766 static int display_echo_area
P_ ((struct window
*));
767 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
768 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
769 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
770 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
771 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
773 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
774 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
775 static void insert_left_trunc_glyphs
P_ ((struct it
*));
776 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
777 static void extend_face_to_end_of_line
P_ ((struct it
*));
778 static int append_space
P_ ((struct it
*, int));
779 static int make_cursor_line_fully_visible
P_ ((struct window
*));
780 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int));
781 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
782 static int trailing_whitespace_p
P_ ((int));
783 static int message_log_check_duplicate
P_ ((int, int, int, int));
784 static void push_it
P_ ((struct it
*));
785 static void pop_it
P_ ((struct it
*));
786 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
787 static void redisplay_internal
P_ ((int));
788 static int echo_area_display
P_ ((int));
789 static void redisplay_windows
P_ ((Lisp_Object
));
790 static void redisplay_window
P_ ((Lisp_Object
, int));
791 static Lisp_Object
redisplay_window_error ();
792 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
793 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
794 static void update_menu_bar
P_ ((struct frame
*, int));
795 static int try_window_reusing_current_matrix
P_ ((struct window
*));
796 static int try_window_id
P_ ((struct window
*));
797 static int display_line
P_ ((struct it
*));
798 static int display_mode_lines
P_ ((struct window
*));
799 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
800 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
801 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
802 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
803 static void display_menu_bar
P_ ((struct window
*));
804 static int display_count_lines
P_ ((int, int, int, int, int *));
805 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
806 int, int, struct it
*, int, int, int, int));
807 static void compute_line_metrics
P_ ((struct it
*));
808 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
809 static int get_overlay_strings
P_ ((struct it
*, int));
810 static void next_overlay_string
P_ ((struct it
*));
811 static void reseat
P_ ((struct it
*, struct text_pos
, int));
812 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
813 static void back_to_previous_visible_line_start
P_ ((struct it
*));
814 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
815 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
816 static int next_element_from_display_vector
P_ ((struct it
*));
817 static int next_element_from_string
P_ ((struct it
*));
818 static int next_element_from_c_string
P_ ((struct it
*));
819 static int next_element_from_buffer
P_ ((struct it
*));
820 static int next_element_from_composition
P_ ((struct it
*));
821 static int next_element_from_image
P_ ((struct it
*));
822 static int next_element_from_stretch
P_ ((struct it
*));
823 static void load_overlay_strings
P_ ((struct it
*, int));
824 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
825 struct display_pos
*));
826 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
827 Lisp_Object
, int, int, int, int));
828 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
830 void move_it_vertically_backward
P_ ((struct it
*, int));
831 static void init_to_row_start
P_ ((struct it
*, struct window
*,
832 struct glyph_row
*));
833 static int init_to_row_end
P_ ((struct it
*, struct window
*,
834 struct glyph_row
*));
835 static void back_to_previous_line_start
P_ ((struct it
*));
836 static int forward_to_next_line_start
P_ ((struct it
*, int *));
837 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
839 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
840 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
841 static int number_of_chars
P_ ((unsigned char *, int));
842 static void compute_stop_pos
P_ ((struct it
*));
843 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
845 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
846 static int next_overlay_change
P_ ((int));
847 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
848 Lisp_Object
, struct text_pos
*,
850 static int underlying_face_id
P_ ((struct it
*));
851 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
854 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
855 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
857 #ifdef HAVE_WINDOW_SYSTEM
859 static void update_tool_bar
P_ ((struct frame
*, int));
860 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
861 static int redisplay_tool_bar
P_ ((struct frame
*));
862 static void display_tool_bar_line
P_ ((struct it
*));
864 #endif /* HAVE_WINDOW_SYSTEM */
867 /***********************************************************************
868 Window display dimensions
869 ***********************************************************************/
871 /* Return the window-relative maximum y + 1 for glyph rows displaying
872 text in window W. This is the height of W minus the height of a
873 mode line, if any. */
876 window_text_bottom_y (w
)
879 struct frame
*f
= XFRAME (w
->frame
);
880 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
882 if (WINDOW_WANTS_MODELINE_P (w
))
883 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
888 /* Return the pixel width of display area AREA of window W. AREA < 0
889 means return the total width of W, not including fringes to
890 the left and right of the window. */
893 window_box_width (w
, area
)
897 struct frame
*f
= XFRAME (w
->frame
);
898 int width
= XFASTINT (w
->width
);
900 if (!w
->pseudo_window_p
)
902 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FRINGE_COLS (f
);
904 if (area
== TEXT_AREA
)
906 if (INTEGERP (w
->left_margin_width
))
907 width
-= XFASTINT (w
->left_margin_width
);
908 if (INTEGERP (w
->right_margin_width
))
909 width
-= XFASTINT (w
->right_margin_width
);
911 else if (area
== LEFT_MARGIN_AREA
)
912 width
= (INTEGERP (w
->left_margin_width
)
913 ? XFASTINT (w
->left_margin_width
) : 0);
914 else if (area
== RIGHT_MARGIN_AREA
)
915 width
= (INTEGERP (w
->right_margin_width
)
916 ? XFASTINT (w
->right_margin_width
) : 0);
919 return width
* CANON_X_UNIT (f
);
923 /* Return the pixel height of the display area of window W, not
924 including mode lines of W, if any. */
927 window_box_height (w
)
930 struct frame
*f
= XFRAME (w
->frame
);
931 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
933 xassert (height
>= 0);
935 /* Note: the code below that determines the mode-line/header-line
936 height is essentially the same as that contained in the macro
937 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
938 the appropriate glyph row has its `mode_line_p' flag set,
939 and if it doesn't, uses estimate_mode_line_height instead. */
941 if (WINDOW_WANTS_MODELINE_P (w
))
943 struct glyph_row
*ml_row
944 = (w
->current_matrix
&& w
->current_matrix
->rows
945 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
947 if (ml_row
&& ml_row
->mode_line_p
)
948 height
-= ml_row
->height
;
950 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
953 if (WINDOW_WANTS_HEADER_LINE_P (w
))
955 struct glyph_row
*hl_row
956 = (w
->current_matrix
&& w
->current_matrix
->rows
957 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
959 if (hl_row
&& hl_row
->mode_line_p
)
960 height
-= hl_row
->height
;
962 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
965 /* With a very small font and a mode-line that's taller than
966 default, we might end up with a negative height. */
967 return max (0, height
);
971 /* Return the frame-relative coordinate of the left edge of display
972 area AREA of window W. AREA < 0 means return the left edge of the
973 whole window, to the right of the left fringe of W. */
976 window_box_left (w
, area
)
980 struct frame
*f
= XFRAME (w
->frame
);
981 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
983 if (!w
->pseudo_window_p
)
985 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
986 + FRAME_LEFT_FRINGE_WIDTH (f
));
988 if (area
== TEXT_AREA
)
989 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
990 else if (area
== RIGHT_MARGIN_AREA
)
991 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
992 + window_box_width (w
, TEXT_AREA
));
999 /* Return the frame-relative coordinate of the right edge of display
1000 area AREA of window W. AREA < 0 means return the left edge of the
1001 whole window, to the left of the right fringe of W. */
1004 window_box_right (w
, area
)
1008 return window_box_left (w
, area
) + window_box_width (w
, area
);
1012 /* Get the bounding box of the display area AREA of window W, without
1013 mode lines, in frame-relative coordinates. AREA < 0 means the
1014 whole window, not including the left and right fringes of
1015 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1016 coordinates of the upper-left corner of the box. Return in
1017 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1020 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1023 int *box_x
, *box_y
, *box_width
, *box_height
;
1025 struct frame
*f
= XFRAME (w
->frame
);
1027 *box_width
= window_box_width (w
, area
);
1028 *box_height
= window_box_height (w
);
1029 *box_x
= window_box_left (w
, area
);
1030 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
1031 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
1032 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1033 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1037 /* Get the bounding box of the display area AREA of window W, without
1038 mode lines. AREA < 0 means the whole window, not including the
1039 left and right fringe of the window. Return in *TOP_LEFT_X
1040 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1041 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1042 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1046 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1047 bottom_right_x
, bottom_right_y
)
1050 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1052 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1054 *bottom_right_x
+= *top_left_x
;
1055 *bottom_right_y
+= *top_left_y
;
1060 /***********************************************************************
1062 ***********************************************************************/
1064 /* Return the bottom y-position of the line the iterator IT is in.
1065 This can modify IT's settings. */
1071 int line_height
= it
->max_ascent
+ it
->max_descent
;
1072 int line_top_y
= it
->current_y
;
1074 if (line_height
== 0)
1077 line_height
= last_height
;
1078 else if (IT_CHARPOS (*it
) < ZV
)
1080 move_it_by_lines (it
, 1, 1);
1081 line_height
= (it
->max_ascent
|| it
->max_descent
1082 ? it
->max_ascent
+ it
->max_descent
1087 struct glyph_row
*row
= it
->glyph_row
;
1089 /* Use the default character height. */
1090 it
->glyph_row
= NULL
;
1091 it
->what
= IT_CHARACTER
;
1094 PRODUCE_GLYPHS (it
);
1095 line_height
= it
->ascent
+ it
->descent
;
1096 it
->glyph_row
= row
;
1100 return line_top_y
+ line_height
;
1104 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1105 1 if POS is visible and the line containing POS is fully visible.
1106 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1107 and header-lines heights. */
1110 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1112 int charpos
, *fully
, exact_mode_line_heights_p
;
1115 struct text_pos top
;
1117 struct buffer
*old_buffer
= NULL
;
1119 if (XBUFFER (w
->buffer
) != current_buffer
)
1121 old_buffer
= current_buffer
;
1122 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1125 *fully
= visible_p
= 0;
1126 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1128 /* Compute exact mode line heights, if requested. */
1129 if (exact_mode_line_heights_p
)
1131 if (WINDOW_WANTS_MODELINE_P (w
))
1132 current_mode_line_height
1133 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1134 current_buffer
->mode_line_format
);
1136 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1137 current_header_line_height
1138 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1139 current_buffer
->header_line_format
);
1142 start_display (&it
, w
, top
);
1143 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1144 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1146 /* Note that we may overshoot because of invisible text. */
1147 if (IT_CHARPOS (it
) >= charpos
)
1149 int top_y
= it
.current_y
;
1150 int bottom_y
= line_bottom_y (&it
);
1151 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1153 if (top_y
< window_top_y
)
1154 visible_p
= bottom_y
> window_top_y
;
1155 else if (top_y
< it
.last_visible_y
)
1158 *fully
= bottom_y
<= it
.last_visible_y
;
1161 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1163 move_it_by_lines (&it
, 1, 0);
1164 if (charpos
< IT_CHARPOS (it
))
1172 set_buffer_internal_1 (old_buffer
);
1174 current_header_line_height
= current_mode_line_height
= -1;
1179 /* Return the next character from STR which is MAXLEN bytes long.
1180 Return in *LEN the length of the character. This is like
1181 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1182 we find one, we return a `?', but with the length of the invalid
1186 string_char_and_length (str
, maxlen
, len
)
1187 const unsigned char *str
;
1192 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1193 if (!CHAR_VALID_P (c
, 1))
1194 /* We may not change the length here because other places in Emacs
1195 don't use this function, i.e. they silently accept invalid
1204 /* Given a position POS containing a valid character and byte position
1205 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1207 static struct text_pos
1208 string_pos_nchars_ahead (pos
, string
, nchars
)
1209 struct text_pos pos
;
1213 xassert (STRINGP (string
) && nchars
>= 0);
1215 if (STRING_MULTIBYTE (string
))
1217 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1218 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1223 string_char_and_length (p
, rest
, &len
);
1224 p
+= len
, rest
-= len
;
1225 xassert (rest
>= 0);
1227 BYTEPOS (pos
) += len
;
1231 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1237 /* Value is the text position, i.e. character and byte position,
1238 for character position CHARPOS in STRING. */
1240 static INLINE
struct text_pos
1241 string_pos (charpos
, string
)
1245 struct text_pos pos
;
1246 xassert (STRINGP (string
));
1247 xassert (charpos
>= 0);
1248 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1253 /* Value is a text position, i.e. character and byte position, for
1254 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1255 means recognize multibyte characters. */
1257 static struct text_pos
1258 c_string_pos (charpos
, s
, multibyte_p
)
1263 struct text_pos pos
;
1265 xassert (s
!= NULL
);
1266 xassert (charpos
>= 0);
1270 int rest
= strlen (s
), len
;
1272 SET_TEXT_POS (pos
, 0, 0);
1275 string_char_and_length (s
, rest
, &len
);
1276 s
+= len
, rest
-= len
;
1277 xassert (rest
>= 0);
1279 BYTEPOS (pos
) += len
;
1283 SET_TEXT_POS (pos
, charpos
, charpos
);
1289 /* Value is the number of characters in C string S. MULTIBYTE_P
1290 non-zero means recognize multibyte characters. */
1293 number_of_chars (s
, multibyte_p
)
1301 int rest
= strlen (s
), len
;
1302 unsigned char *p
= (unsigned char *) s
;
1304 for (nchars
= 0; rest
> 0; ++nchars
)
1306 string_char_and_length (p
, rest
, &len
);
1307 rest
-= len
, p
+= len
;
1311 nchars
= strlen (s
);
1317 /* Compute byte position NEWPOS->bytepos corresponding to
1318 NEWPOS->charpos. POS is a known position in string STRING.
1319 NEWPOS->charpos must be >= POS.charpos. */
1322 compute_string_pos (newpos
, pos
, string
)
1323 struct text_pos
*newpos
, pos
;
1326 xassert (STRINGP (string
));
1327 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1329 if (STRING_MULTIBYTE (string
))
1330 *newpos
= string_pos_nchars_ahead (pos
, string
,
1331 CHARPOS (*newpos
) - CHARPOS (pos
));
1333 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1338 /***********************************************************************
1339 Lisp form evaluation
1340 ***********************************************************************/
1342 /* Error handler for safe_eval and safe_call. */
1345 safe_eval_handler (arg
)
1348 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1353 /* Evaluate SEXPR and return the result, or nil if something went
1354 wrong. Prevent redisplay during the evaluation. */
1362 if (inhibit_eval_during_redisplay
)
1366 int count
= SPECPDL_INDEX ();
1367 struct gcpro gcpro1
;
1370 specbind (Qinhibit_redisplay
, Qt
);
1371 /* Use Qt to ensure debugger does not run,
1372 so there is no possibility of wanting to redisplay. */
1373 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1376 val
= unbind_to (count
, val
);
1383 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1384 Return the result, or nil if something went wrong. Prevent
1385 redisplay during the evaluation. */
1388 safe_call (nargs
, args
)
1394 if (inhibit_eval_during_redisplay
)
1398 int count
= SPECPDL_INDEX ();
1399 struct gcpro gcpro1
;
1402 gcpro1
.nvars
= nargs
;
1403 specbind (Qinhibit_redisplay
, Qt
);
1404 /* Use Qt to ensure debugger does not run,
1405 so there is no possibility of wanting to redisplay. */
1406 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1409 val
= unbind_to (count
, val
);
1416 /* Call function FN with one argument ARG.
1417 Return the result, or nil if something went wrong. */
1420 safe_call1 (fn
, arg
)
1421 Lisp_Object fn
, arg
;
1423 Lisp_Object args
[2];
1426 return safe_call (2, args
);
1431 /***********************************************************************
1433 ***********************************************************************/
1437 /* Define CHECK_IT to perform sanity checks on iterators.
1438 This is for debugging. It is too slow to do unconditionally. */
1444 if (it
->method
== next_element_from_string
)
1446 xassert (STRINGP (it
->string
));
1447 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1449 else if (it
->method
== next_element_from_buffer
)
1451 /* Check that character and byte positions agree. */
1452 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1456 xassert (it
->current
.dpvec_index
>= 0);
1458 xassert (it
->current
.dpvec_index
< 0);
1461 #define CHECK_IT(IT) check_it ((IT))
1465 #define CHECK_IT(IT) (void) 0
1472 /* Check that the window end of window W is what we expect it
1473 to be---the last row in the current matrix displaying text. */
1476 check_window_end (w
)
1479 if (!MINI_WINDOW_P (w
)
1480 && !NILP (w
->window_end_valid
))
1482 struct glyph_row
*row
;
1483 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1484 XFASTINT (w
->window_end_vpos
)),
1486 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1487 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1491 #define CHECK_WINDOW_END(W) check_window_end ((W))
1493 #else /* not GLYPH_DEBUG */
1495 #define CHECK_WINDOW_END(W) (void) 0
1497 #endif /* not GLYPH_DEBUG */
1501 /***********************************************************************
1502 Iterator initialization
1503 ***********************************************************************/
1505 /* Initialize IT for displaying current_buffer in window W, starting
1506 at character position CHARPOS. CHARPOS < 0 means that no buffer
1507 position is specified which is useful when the iterator is assigned
1508 a position later. BYTEPOS is the byte position corresponding to
1509 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1511 If ROW is not null, calls to produce_glyphs with IT as parameter
1512 will produce glyphs in that row.
1514 BASE_FACE_ID is the id of a base face to use. It must be one of
1515 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1516 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1517 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1519 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1520 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1521 will be initialized to use the corresponding mode line glyph row of
1522 the desired matrix of W. */
1525 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1528 int charpos
, bytepos
;
1529 struct glyph_row
*row
;
1530 enum face_id base_face_id
;
1532 int highlight_region_p
;
1534 /* Some precondition checks. */
1535 xassert (w
!= NULL
&& it
!= NULL
);
1536 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1539 /* If face attributes have been changed since the last redisplay,
1540 free realized faces now because they depend on face definitions
1541 that might have changed. Don't free faces while there might be
1542 desired matrices pending which reference these faces. */
1543 if (face_change_count
&& !inhibit_free_realized_faces
)
1545 face_change_count
= 0;
1546 free_all_realized_faces (Qnil
);
1549 /* Use one of the mode line rows of W's desired matrix if
1553 if (base_face_id
== MODE_LINE_FACE_ID
1554 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
1555 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1556 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1557 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1561 bzero (it
, sizeof *it
);
1562 it
->current
.overlay_string_index
= -1;
1563 it
->current
.dpvec_index
= -1;
1564 it
->base_face_id
= base_face_id
;
1566 /* The window in which we iterate over current_buffer: */
1567 XSETWINDOW (it
->window
, w
);
1569 it
->f
= XFRAME (w
->frame
);
1571 /* Extra space between lines (on window systems only). */
1572 if (base_face_id
== DEFAULT_FACE_ID
1573 && FRAME_WINDOW_P (it
->f
))
1575 if (NATNUMP (current_buffer
->extra_line_spacing
))
1576 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1577 else if (it
->f
->extra_line_spacing
> 0)
1578 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1581 /* If realized faces have been removed, e.g. because of face
1582 attribute changes of named faces, recompute them. When running
1583 in batch mode, the face cache of Vterminal_frame is null. If
1584 we happen to get called, make a dummy face cache. */
1589 FRAME_FACE_CACHE (it
->f
) == NULL
)
1590 init_frame_faces (it
->f
);
1591 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1592 recompute_basic_faces (it
->f
);
1594 /* Current value of the `space-width', and 'height' properties. */
1595 it
->space_width
= Qnil
;
1596 it
->font_height
= Qnil
;
1598 /* Are control characters displayed as `^C'? */
1599 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1601 /* -1 means everything between a CR and the following line end
1602 is invisible. >0 means lines indented more than this value are
1604 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1605 ? XFASTINT (current_buffer
->selective_display
)
1606 : (!NILP (current_buffer
->selective_display
)
1608 it
->selective_display_ellipsis_p
1609 = !NILP (current_buffer
->selective_display_ellipses
);
1611 /* Display table to use. */
1612 it
->dp
= window_display_table (w
);
1614 /* Are multibyte characters enabled in current_buffer? */
1615 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1617 /* Non-zero if we should highlight the region. */
1619 = (!NILP (Vtransient_mark_mode
)
1620 && !NILP (current_buffer
->mark_active
)
1621 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1623 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1624 start and end of a visible region in window IT->w. Set both to
1625 -1 to indicate no region. */
1626 if (highlight_region_p
1627 /* Maybe highlight only in selected window. */
1628 && (/* Either show region everywhere. */
1629 highlight_nonselected_windows
1630 /* Or show region in the selected window. */
1631 || w
== XWINDOW (selected_window
)
1632 /* Or show the region if we are in the mini-buffer and W is
1633 the window the mini-buffer refers to. */
1634 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1635 && WINDOWP (minibuf_selected_window
)
1636 && w
== XWINDOW (minibuf_selected_window
))))
1638 int charpos
= marker_position (current_buffer
->mark
);
1639 it
->region_beg_charpos
= min (PT
, charpos
);
1640 it
->region_end_charpos
= max (PT
, charpos
);
1643 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1645 /* Get the position at which the redisplay_end_trigger hook should
1646 be run, if it is to be run at all. */
1647 if (MARKERP (w
->redisplay_end_trigger
)
1648 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1649 it
->redisplay_end_trigger_charpos
1650 = marker_position (w
->redisplay_end_trigger
);
1651 else if (INTEGERP (w
->redisplay_end_trigger
))
1652 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1654 /* Correct bogus values of tab_width. */
1655 it
->tab_width
= XINT (current_buffer
->tab_width
);
1656 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1659 /* Are lines in the display truncated? */
1660 it
->truncate_lines_p
1661 = (base_face_id
!= DEFAULT_FACE_ID
1662 || XINT (it
->w
->hscroll
)
1663 || (truncate_partial_width_windows
1664 && !WINDOW_FULL_WIDTH_P (it
->w
))
1665 || !NILP (current_buffer
->truncate_lines
));
1667 /* Get dimensions of truncation and continuation glyphs. These are
1668 displayed as fringe bitmaps under X, so we don't need them for such
1670 if (!FRAME_WINDOW_P (it
->f
))
1672 if (it
->truncate_lines_p
)
1674 /* We will need the truncation glyph. */
1675 xassert (it
->glyph_row
== NULL
);
1676 produce_special_glyphs (it
, IT_TRUNCATION
);
1677 it
->truncation_pixel_width
= it
->pixel_width
;
1681 /* We will need the continuation glyph. */
1682 xassert (it
->glyph_row
== NULL
);
1683 produce_special_glyphs (it
, IT_CONTINUATION
);
1684 it
->continuation_pixel_width
= it
->pixel_width
;
1687 /* Reset these values to zero because the produce_special_glyphs
1688 above has changed them. */
1689 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1690 it
->phys_ascent
= it
->phys_descent
= 0;
1693 /* Set this after getting the dimensions of truncation and
1694 continuation glyphs, so that we don't produce glyphs when calling
1695 produce_special_glyphs, above. */
1696 it
->glyph_row
= row
;
1697 it
->area
= TEXT_AREA
;
1699 /* Get the dimensions of the display area. The display area
1700 consists of the visible window area plus a horizontally scrolled
1701 part to the left of the window. All x-values are relative to the
1702 start of this total display area. */
1703 if (base_face_id
!= DEFAULT_FACE_ID
)
1705 /* Mode lines, menu bar in terminal frames. */
1706 it
->first_visible_x
= 0;
1707 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1712 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1713 it
->last_visible_x
= (it
->first_visible_x
1714 + window_box_width (w
, TEXT_AREA
));
1716 /* If we truncate lines, leave room for the truncator glyph(s) at
1717 the right margin. Otherwise, leave room for the continuation
1718 glyph(s). Truncation and continuation glyphs are not inserted
1719 for window-based redisplay. */
1720 if (!FRAME_WINDOW_P (it
->f
))
1722 if (it
->truncate_lines_p
)
1723 it
->last_visible_x
-= it
->truncation_pixel_width
;
1725 it
->last_visible_x
-= it
->continuation_pixel_width
;
1728 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1729 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1732 /* Leave room for a border glyph. */
1733 if (!FRAME_WINDOW_P (it
->f
)
1734 && !WINDOW_RIGHTMOST_P (it
->w
))
1735 it
->last_visible_x
-= 1;
1737 it
->last_visible_y
= window_text_bottom_y (w
);
1739 /* For mode lines and alike, arrange for the first glyph having a
1740 left box line if the face specifies a box. */
1741 if (base_face_id
!= DEFAULT_FACE_ID
)
1745 it
->face_id
= base_face_id
;
1747 /* If we have a boxed mode line, make the first character appear
1748 with a left box line. */
1749 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1750 if (face
->box
!= FACE_NO_BOX
)
1751 it
->start_of_box_run_p
= 1;
1754 /* If a buffer position was specified, set the iterator there,
1755 getting overlays and face properties from that position. */
1756 if (charpos
>= BUF_BEG (current_buffer
))
1758 it
->end_charpos
= ZV
;
1760 IT_CHARPOS (*it
) = charpos
;
1762 /* Compute byte position if not specified. */
1763 if (bytepos
< charpos
)
1764 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1766 IT_BYTEPOS (*it
) = bytepos
;
1768 /* Compute faces etc. */
1769 reseat (it
, it
->current
.pos
, 1);
1776 /* Initialize IT for the display of window W with window start POS. */
1779 start_display (it
, w
, pos
)
1782 struct text_pos pos
;
1784 struct glyph_row
*row
;
1785 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1787 row
= w
->desired_matrix
->rows
+ first_vpos
;
1788 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1790 if (!it
->truncate_lines_p
)
1792 int start_at_line_beg_p
;
1793 int first_y
= it
->current_y
;
1795 /* If window start is not at a line start, skip forward to POS to
1796 get the correct continuation lines width. */
1797 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1798 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1799 if (!start_at_line_beg_p
)
1801 reseat_at_previous_visible_line_start (it
);
1802 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1804 /* If lines are continued, this line may end in the middle
1805 of a multi-glyph character (e.g. a control character
1806 displayed as \003, or in the middle of an overlay
1807 string). In this case move_it_to above will not have
1808 taken us to the start of the continuation line but to the
1809 end of the continued line. */
1810 if (it
->current_x
> 0)
1812 if (it
->current
.dpvec_index
>= 0
1813 || it
->current
.overlay_string_index
>= 0)
1815 set_iterator_to_next (it
, 1);
1816 move_it_in_display_line_to (it
, -1, -1, 0);
1819 it
->continuation_lines_width
+= it
->current_x
;
1822 /* We're starting a new display line, not affected by the
1823 height of the continued line, so clear the appropriate
1824 fields in the iterator structure. */
1825 it
->max_ascent
= it
->max_descent
= 0;
1826 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1828 it
->current_y
= first_y
;
1830 it
->current_x
= it
->hpos
= 0;
1834 #if 0 /* Don't assert the following because start_display is sometimes
1835 called intentionally with a window start that is not at a
1836 line start. Please leave this code in as a comment. */
1838 /* Window start should be on a line start, now. */
1839 xassert (it
->continuation_lines_width
1840 || IT_CHARPOS (it
) == BEGV
1841 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1846 /* Return 1 if POS is a position in ellipses displayed for invisible
1847 text. W is the window we display, for text property lookup. */
1850 in_ellipses_for_invisible_text_p (pos
, w
)
1851 struct display_pos
*pos
;
1854 Lisp_Object prop
, window
;
1856 int charpos
= CHARPOS (pos
->pos
);
1858 /* If POS specifies a position in a display vector, this might
1859 be for an ellipsis displayed for invisible text. We won't
1860 get the iterator set up for delivering that ellipsis unless
1861 we make sure that it gets aware of the invisible text. */
1862 if (pos
->dpvec_index
>= 0
1863 && pos
->overlay_string_index
< 0
1864 && CHARPOS (pos
->string_pos
) < 0
1866 && (XSETWINDOW (window
, w
),
1867 prop
= Fget_char_property (make_number (charpos
),
1868 Qinvisible
, window
),
1869 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1871 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1873 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
1880 /* Initialize IT for stepping through current_buffer in window W,
1881 starting at position POS that includes overlay string and display
1882 vector/ control character translation position information. Value
1883 is zero if there are overlay strings with newlines at POS. */
1886 init_from_display_pos (it
, w
, pos
)
1889 struct display_pos
*pos
;
1891 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1892 int i
, overlay_strings_with_newlines
= 0;
1894 /* If POS specifies a position in a display vector, this might
1895 be for an ellipsis displayed for invisible text. We won't
1896 get the iterator set up for delivering that ellipsis unless
1897 we make sure that it gets aware of the invisible text. */
1898 if (in_ellipses_for_invisible_text_p (pos
, w
))
1904 /* Keep in mind: the call to reseat in init_iterator skips invisible
1905 text, so we might end up at a position different from POS. This
1906 is only a problem when POS is a row start after a newline and an
1907 overlay starts there with an after-string, and the overlay has an
1908 invisible property. Since we don't skip invisible text in
1909 display_line and elsewhere immediately after consuming the
1910 newline before the row start, such a POS will not be in a string,
1911 but the call to init_iterator below will move us to the
1913 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1915 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
1917 const char *s
= SDATA (it
->overlay_strings
[i
]);
1918 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
1920 while (s
< e
&& *s
!= '\n')
1925 overlay_strings_with_newlines
= 1;
1930 /* If position is within an overlay string, set up IT to the right
1932 if (pos
->overlay_string_index
>= 0)
1936 /* If the first overlay string happens to have a `display'
1937 property for an image, the iterator will be set up for that
1938 image, and we have to undo that setup first before we can
1939 correct the overlay string index. */
1940 if (it
->method
== next_element_from_image
)
1943 /* We already have the first chunk of overlay strings in
1944 IT->overlay_strings. Load more until the one for
1945 pos->overlay_string_index is in IT->overlay_strings. */
1946 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1948 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1949 it
->current
.overlay_string_index
= 0;
1952 load_overlay_strings (it
, 0);
1953 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1957 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1958 relative_index
= (it
->current
.overlay_string_index
1959 % OVERLAY_STRING_CHUNK_SIZE
);
1960 it
->string
= it
->overlay_strings
[relative_index
];
1961 xassert (STRINGP (it
->string
));
1962 it
->current
.string_pos
= pos
->string_pos
;
1963 it
->method
= next_element_from_string
;
1966 #if 0 /* This is bogus because POS not having an overlay string
1967 position does not mean it's after the string. Example: A
1968 line starting with a before-string and initialization of IT
1969 to the previous row's end position. */
1970 else if (it
->current
.overlay_string_index
>= 0)
1972 /* If POS says we're already after an overlay string ending at
1973 POS, make sure to pop the iterator because it will be in
1974 front of that overlay string. When POS is ZV, we've thereby
1975 also ``processed'' overlay strings at ZV. */
1978 it
->current
.overlay_string_index
= -1;
1979 it
->method
= next_element_from_buffer
;
1980 if (CHARPOS (pos
->pos
) == ZV
)
1981 it
->overlay_strings_at_end_processed_p
= 1;
1985 if (CHARPOS (pos
->string_pos
) >= 0)
1987 /* Recorded position is not in an overlay string, but in another
1988 string. This can only be a string from a `display' property.
1989 IT should already be filled with that string. */
1990 it
->current
.string_pos
= pos
->string_pos
;
1991 xassert (STRINGP (it
->string
));
1994 /* Restore position in display vector translations, control
1995 character translations or ellipses. */
1996 if (pos
->dpvec_index
>= 0)
1998 if (it
->dpvec
== NULL
)
1999 get_next_display_element (it
);
2000 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2001 it
->current
.dpvec_index
= pos
->dpvec_index
;
2005 return !overlay_strings_with_newlines
;
2009 /* Initialize IT for stepping through current_buffer in window W
2010 starting at ROW->start. */
2013 init_to_row_start (it
, w
, row
)
2016 struct glyph_row
*row
;
2018 init_from_display_pos (it
, w
, &row
->start
);
2019 it
->continuation_lines_width
= row
->continuation_lines_width
;
2024 /* Initialize IT for stepping through current_buffer in window W
2025 starting in the line following ROW, i.e. starting at ROW->end.
2026 Value is zero if there are overlay strings with newlines at ROW's
2030 init_to_row_end (it
, w
, row
)
2033 struct glyph_row
*row
;
2037 if (init_from_display_pos (it
, w
, &row
->end
))
2039 if (row
->continued_p
)
2040 it
->continuation_lines_width
2041 = row
->continuation_lines_width
+ row
->pixel_width
;
2052 /***********************************************************************
2054 ***********************************************************************/
2056 /* Called when IT reaches IT->stop_charpos. Handle text property and
2057 overlay changes. Set IT->stop_charpos to the next position where
2064 enum prop_handled handled
;
2065 int handle_overlay_change_p
= 1;
2069 it
->current
.dpvec_index
= -1;
2073 handled
= HANDLED_NORMALLY
;
2075 /* Call text property handlers. */
2076 for (p
= it_props
; p
->handler
; ++p
)
2078 handled
= p
->handler (it
);
2080 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2082 else if (handled
== HANDLED_RETURN
)
2084 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2085 handle_overlay_change_p
= 0;
2088 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2090 /* Don't check for overlay strings below when set to deliver
2091 characters from a display vector. */
2092 if (it
->method
== next_element_from_display_vector
)
2093 handle_overlay_change_p
= 0;
2095 /* Handle overlay changes. */
2096 if (handle_overlay_change_p
)
2097 handled
= handle_overlay_change (it
);
2099 /* Determine where to stop next. */
2100 if (handled
== HANDLED_NORMALLY
)
2101 compute_stop_pos (it
);
2104 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2108 /* Compute IT->stop_charpos from text property and overlay change
2109 information for IT's current position. */
2112 compute_stop_pos (it
)
2115 register INTERVAL iv
, next_iv
;
2116 Lisp_Object object
, limit
, position
;
2118 /* If nowhere else, stop at the end. */
2119 it
->stop_charpos
= it
->end_charpos
;
2121 if (STRINGP (it
->string
))
2123 /* Strings are usually short, so don't limit the search for
2125 object
= it
->string
;
2127 position
= make_number (IT_STRING_CHARPOS (*it
));
2133 /* If next overlay change is in front of the current stop pos
2134 (which is IT->end_charpos), stop there. Note: value of
2135 next_overlay_change is point-max if no overlay change
2137 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2138 if (charpos
< it
->stop_charpos
)
2139 it
->stop_charpos
= charpos
;
2141 /* If showing the region, we have to stop at the region
2142 start or end because the face might change there. */
2143 if (it
->region_beg_charpos
> 0)
2145 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2146 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2147 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2148 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2151 /* Set up variables for computing the stop position from text
2152 property changes. */
2153 XSETBUFFER (object
, current_buffer
);
2154 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2155 position
= make_number (IT_CHARPOS (*it
));
2159 /* Get the interval containing IT's position. Value is a null
2160 interval if there isn't such an interval. */
2161 iv
= validate_interval_range (object
, &position
, &position
, 0);
2162 if (!NULL_INTERVAL_P (iv
))
2164 Lisp_Object values_here
[LAST_PROP_IDX
];
2167 /* Get properties here. */
2168 for (p
= it_props
; p
->handler
; ++p
)
2169 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2171 /* Look for an interval following iv that has different
2173 for (next_iv
= next_interval (iv
);
2174 (!NULL_INTERVAL_P (next_iv
)
2176 || XFASTINT (limit
) > next_iv
->position
));
2177 next_iv
= next_interval (next_iv
))
2179 for (p
= it_props
; p
->handler
; ++p
)
2181 Lisp_Object new_value
;
2183 new_value
= textget (next_iv
->plist
, *p
->name
);
2184 if (!EQ (values_here
[p
->idx
], new_value
))
2192 if (!NULL_INTERVAL_P (next_iv
))
2194 if (INTEGERP (limit
)
2195 && next_iv
->position
>= XFASTINT (limit
))
2196 /* No text property change up to limit. */
2197 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2199 /* Text properties change in next_iv. */
2200 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2204 xassert (STRINGP (it
->string
)
2205 || (it
->stop_charpos
>= BEGV
2206 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2210 /* Return the position of the next overlay change after POS in
2211 current_buffer. Value is point-max if no overlay change
2212 follows. This is like `next-overlay-change' but doesn't use
2216 next_overlay_change (pos
)
2221 Lisp_Object
*overlays
;
2225 /* Get all overlays at the given position. */
2227 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2228 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2229 if (noverlays
> len
)
2232 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2233 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2236 /* If any of these overlays ends before endpos,
2237 use its ending point instead. */
2238 for (i
= 0; i
< noverlays
; ++i
)
2243 oend
= OVERLAY_END (overlays
[i
]);
2244 oendpos
= OVERLAY_POSITION (oend
);
2245 endpos
= min (endpos
, oendpos
);
2253 /***********************************************************************
2255 ***********************************************************************/
2257 /* Handle changes in the `fontified' property of the current buffer by
2258 calling hook functions from Qfontification_functions to fontify
2261 static enum prop_handled
2262 handle_fontified_prop (it
)
2265 Lisp_Object prop
, pos
;
2266 enum prop_handled handled
= HANDLED_NORMALLY
;
2268 /* Get the value of the `fontified' property at IT's current buffer
2269 position. (The `fontified' property doesn't have a special
2270 meaning in strings.) If the value is nil, call functions from
2271 Qfontification_functions. */
2272 if (!STRINGP (it
->string
)
2274 && !NILP (Vfontification_functions
)
2275 && !NILP (Vrun_hooks
)
2276 && (pos
= make_number (IT_CHARPOS (*it
)),
2277 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2280 int count
= SPECPDL_INDEX ();
2283 val
= Vfontification_functions
;
2284 specbind (Qfontification_functions
, Qnil
);
2286 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2287 safe_call1 (val
, pos
);
2290 Lisp_Object globals
, fn
;
2291 struct gcpro gcpro1
, gcpro2
;
2294 GCPRO2 (val
, globals
);
2296 for (; CONSP (val
); val
= XCDR (val
))
2302 /* A value of t indicates this hook has a local
2303 binding; it means to run the global binding too.
2304 In a global value, t should not occur. If it
2305 does, we must ignore it to avoid an endless
2307 for (globals
= Fdefault_value (Qfontification_functions
);
2309 globals
= XCDR (globals
))
2311 fn
= XCAR (globals
);
2313 safe_call1 (fn
, pos
);
2317 safe_call1 (fn
, pos
);
2323 unbind_to (count
, Qnil
);
2325 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2326 something. This avoids an endless loop if they failed to
2327 fontify the text for which reason ever. */
2328 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2329 handled
= HANDLED_RECOMPUTE_PROPS
;
2337 /***********************************************************************
2339 ***********************************************************************/
2341 /* Set up iterator IT from face properties at its current position.
2342 Called from handle_stop. */
2344 static enum prop_handled
2345 handle_face_prop (it
)
2348 int new_face_id
, next_stop
;
2350 if (!STRINGP (it
->string
))
2353 = face_at_buffer_position (it
->w
,
2355 it
->region_beg_charpos
,
2356 it
->region_end_charpos
,
2359 + TEXT_PROP_DISTANCE_LIMIT
),
2362 /* Is this a start of a run of characters with box face?
2363 Caveat: this can be called for a freshly initialized
2364 iterator; face_id is -1 in this case. We know that the new
2365 face will not change until limit, i.e. if the new face has a
2366 box, all characters up to limit will have one. But, as
2367 usual, we don't know whether limit is really the end. */
2368 if (new_face_id
!= it
->face_id
)
2370 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2372 /* If new face has a box but old face has not, this is
2373 the start of a run of characters with box, i.e. it has
2374 a shadow on the left side. The value of face_id of the
2375 iterator will be -1 if this is the initial call that gets
2376 the face. In this case, we have to look in front of IT's
2377 position and see whether there is a face != new_face_id. */
2378 it
->start_of_box_run_p
2379 = (new_face
->box
!= FACE_NO_BOX
2380 && (it
->face_id
>= 0
2381 || IT_CHARPOS (*it
) == BEG
2382 || new_face_id
!= face_before_it_pos (it
)));
2383 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2388 int base_face_id
, bufpos
;
2390 if (it
->current
.overlay_string_index
>= 0)
2391 bufpos
= IT_CHARPOS (*it
);
2395 /* For strings from a buffer, i.e. overlay strings or strings
2396 from a `display' property, use the face at IT's current
2397 buffer position as the base face to merge with, so that
2398 overlay strings appear in the same face as surrounding
2399 text, unless they specify their own faces. */
2400 base_face_id
= underlying_face_id (it
);
2402 new_face_id
= face_at_string_position (it
->w
,
2404 IT_STRING_CHARPOS (*it
),
2406 it
->region_beg_charpos
,
2407 it
->region_end_charpos
,
2411 #if 0 /* This shouldn't be neccessary. Let's check it. */
2412 /* If IT is used to display a mode line we would really like to
2413 use the mode line face instead of the frame's default face. */
2414 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2415 && new_face_id
== DEFAULT_FACE_ID
)
2416 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2419 /* Is this a start of a run of characters with box? Caveat:
2420 this can be called for a freshly allocated iterator; face_id
2421 is -1 is this case. We know that the new face will not
2422 change until the next check pos, i.e. if the new face has a
2423 box, all characters up to that position will have a
2424 box. But, as usual, we don't know whether that position
2425 is really the end. */
2426 if (new_face_id
!= it
->face_id
)
2428 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2429 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2431 /* If new face has a box but old face hasn't, this is the
2432 start of a run of characters with box, i.e. it has a
2433 shadow on the left side. */
2434 it
->start_of_box_run_p
2435 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2436 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2440 it
->face_id
= new_face_id
;
2441 return HANDLED_NORMALLY
;
2445 /* Return the ID of the face ``underlying'' IT's current position,
2446 which is in a string. If the iterator is associated with a
2447 buffer, return the face at IT's current buffer position.
2448 Otherwise, use the iterator's base_face_id. */
2451 underlying_face_id (it
)
2454 int face_id
= it
->base_face_id
, i
;
2456 xassert (STRINGP (it
->string
));
2458 for (i
= it
->sp
- 1; i
>= 0; --i
)
2459 if (NILP (it
->stack
[i
].string
))
2460 face_id
= it
->stack
[i
].face_id
;
2466 /* Compute the face one character before or after the current position
2467 of IT. BEFORE_P non-zero means get the face in front of IT's
2468 position. Value is the id of the face. */
2471 face_before_or_after_it_pos (it
, before_p
)
2476 int next_check_charpos
;
2477 struct text_pos pos
;
2479 xassert (it
->s
== NULL
);
2481 if (STRINGP (it
->string
))
2483 int bufpos
, base_face_id
;
2485 /* No face change past the end of the string (for the case
2486 we are padding with spaces). No face change before the
2488 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2489 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2492 /* Set pos to the position before or after IT's current position. */
2494 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2496 /* For composition, we must check the character after the
2498 pos
= (it
->what
== IT_COMPOSITION
2499 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2500 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2502 if (it
->current
.overlay_string_index
>= 0)
2503 bufpos
= IT_CHARPOS (*it
);
2507 base_face_id
= underlying_face_id (it
);
2509 /* Get the face for ASCII, or unibyte. */
2510 face_id
= face_at_string_position (it
->w
,
2514 it
->region_beg_charpos
,
2515 it
->region_end_charpos
,
2516 &next_check_charpos
,
2519 /* Correct the face for charsets different from ASCII. Do it
2520 for the multibyte case only. The face returned above is
2521 suitable for unibyte text if IT->string is unibyte. */
2522 if (STRING_MULTIBYTE (it
->string
))
2524 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
2525 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
2527 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2529 c
= string_char_and_length (p
, rest
, &len
);
2530 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2535 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2536 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2539 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2540 pos
= it
->current
.pos
;
2543 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2546 if (it
->what
== IT_COMPOSITION
)
2547 /* For composition, we must check the position after the
2549 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2551 INC_TEXT_POS (pos
, it
->multibyte_p
);
2554 /* Determine face for CHARSET_ASCII, or unibyte. */
2555 face_id
= face_at_buffer_position (it
->w
,
2557 it
->region_beg_charpos
,
2558 it
->region_end_charpos
,
2559 &next_check_charpos
,
2562 /* Correct the face for charsets different from ASCII. Do it
2563 for the multibyte case only. The face returned above is
2564 suitable for unibyte text if current_buffer is unibyte. */
2565 if (it
->multibyte_p
)
2567 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
2568 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2569 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2578 /***********************************************************************
2580 ***********************************************************************/
2582 /* Set up iterator IT from invisible properties at its current
2583 position. Called from handle_stop. */
2585 static enum prop_handled
2586 handle_invisible_prop (it
)
2589 enum prop_handled handled
= HANDLED_NORMALLY
;
2591 if (STRINGP (it
->string
))
2593 extern Lisp_Object Qinvisible
;
2594 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2596 /* Get the value of the invisible text property at the
2597 current position. Value will be nil if there is no such
2599 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2600 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2603 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2605 handled
= HANDLED_RECOMPUTE_PROPS
;
2607 /* Get the position at which the next change of the
2608 invisible text property can be found in IT->string.
2609 Value will be nil if the property value is the same for
2610 all the rest of IT->string. */
2611 XSETINT (limit
, SCHARS (it
->string
));
2612 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2615 /* Text at current position is invisible. The next
2616 change in the property is at position end_charpos.
2617 Move IT's current position to that position. */
2618 if (INTEGERP (end_charpos
)
2619 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2621 struct text_pos old
;
2622 old
= it
->current
.string_pos
;
2623 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2624 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2628 /* The rest of the string is invisible. If this is an
2629 overlay string, proceed with the next overlay string
2630 or whatever comes and return a character from there. */
2631 if (it
->current
.overlay_string_index
>= 0)
2633 next_overlay_string (it
);
2634 /* Don't check for overlay strings when we just
2635 finished processing them. */
2636 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2640 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
2641 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
2648 int invis_p
, newpos
, next_stop
, start_charpos
;
2649 Lisp_Object pos
, prop
, overlay
;
2651 /* First of all, is there invisible text at this position? */
2652 start_charpos
= IT_CHARPOS (*it
);
2653 pos
= make_number (IT_CHARPOS (*it
));
2654 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2656 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2658 /* If we are on invisible text, skip over it. */
2659 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
2661 /* Record whether we have to display an ellipsis for the
2663 int display_ellipsis_p
= invis_p
== 2;
2665 handled
= HANDLED_RECOMPUTE_PROPS
;
2667 /* Loop skipping over invisible text. The loop is left at
2668 ZV or with IT on the first char being visible again. */
2671 /* Try to skip some invisible text. Return value is the
2672 position reached which can be equal to IT's position
2673 if there is nothing invisible here. This skips both
2674 over invisible text properties and overlays with
2675 invisible property. */
2676 newpos
= skip_invisible (IT_CHARPOS (*it
),
2677 &next_stop
, ZV
, it
->window
);
2679 /* If we skipped nothing at all we weren't at invisible
2680 text in the first place. If everything to the end of
2681 the buffer was skipped, end the loop. */
2682 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2686 /* We skipped some characters but not necessarily
2687 all there are. Check if we ended up on visible
2688 text. Fget_char_property returns the property of
2689 the char before the given position, i.e. if we
2690 get invis_p = 0, this means that the char at
2691 newpos is visible. */
2692 pos
= make_number (newpos
);
2693 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2694 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2697 /* If we ended up on invisible text, proceed to
2698 skip starting with next_stop. */
2700 IT_CHARPOS (*it
) = next_stop
;
2704 /* The position newpos is now either ZV or on visible text. */
2705 IT_CHARPOS (*it
) = newpos
;
2706 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2708 /* If there are before-strings at the start of invisible
2709 text, and the text is invisible because of a text
2710 property, arrange to show before-strings because 20.x did
2711 it that way. (If the text is invisible because of an
2712 overlay property instead of a text property, this is
2713 already handled in the overlay code.) */
2715 && get_overlay_strings (it
, start_charpos
))
2717 handled
= HANDLED_RECOMPUTE_PROPS
;
2718 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2720 else if (display_ellipsis_p
)
2721 setup_for_ellipsis (it
);
2729 /* Make iterator IT return `...' next. */
2732 setup_for_ellipsis (it
)
2736 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2738 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2739 it
->dpvec
= v
->contents
;
2740 it
->dpend
= v
->contents
+ v
->size
;
2744 /* Default `...'. */
2745 it
->dpvec
= default_invis_vector
;
2746 it
->dpend
= default_invis_vector
+ 3;
2749 /* The ellipsis display does not replace the display of the
2750 character at the new position. Indicate this by setting
2751 IT->dpvec_char_len to zero. */
2752 it
->dpvec_char_len
= 0;
2754 it
->current
.dpvec_index
= 0;
2755 it
->method
= next_element_from_display_vector
;
2760 /***********************************************************************
2762 ***********************************************************************/
2764 /* Set up iterator IT from `display' property at its current position.
2765 Called from handle_stop. */
2767 static enum prop_handled
2768 handle_display_prop (it
)
2771 Lisp_Object prop
, object
;
2772 struct text_pos
*position
;
2773 int display_replaced_p
= 0;
2775 if (STRINGP (it
->string
))
2777 object
= it
->string
;
2778 position
= &it
->current
.string_pos
;
2782 object
= it
->w
->buffer
;
2783 position
= &it
->current
.pos
;
2786 /* Reset those iterator values set from display property values. */
2787 it
->font_height
= Qnil
;
2788 it
->space_width
= Qnil
;
2791 /* We don't support recursive `display' properties, i.e. string
2792 values that have a string `display' property, that have a string
2793 `display' property etc. */
2794 if (!it
->string_from_display_prop_p
)
2795 it
->area
= TEXT_AREA
;
2797 prop
= Fget_char_property (make_number (position
->charpos
),
2800 return HANDLED_NORMALLY
;
2803 /* Simple properties. */
2804 && !EQ (XCAR (prop
), Qimage
)
2805 && !EQ (XCAR (prop
), Qspace
)
2806 && !EQ (XCAR (prop
), Qwhen
)
2807 && !EQ (XCAR (prop
), Qspace_width
)
2808 && !EQ (XCAR (prop
), Qheight
)
2809 && !EQ (XCAR (prop
), Qraise
)
2810 /* Marginal area specifications. */
2811 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2812 && !NILP (XCAR (prop
)))
2814 for (; CONSP (prop
); prop
= XCDR (prop
))
2816 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2817 position
, display_replaced_p
))
2818 display_replaced_p
= 1;
2821 else if (VECTORP (prop
))
2824 for (i
= 0; i
< ASIZE (prop
); ++i
)
2825 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2826 position
, display_replaced_p
))
2827 display_replaced_p
= 1;
2831 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2832 display_replaced_p
= 1;
2835 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2839 /* Value is the position of the end of the `display' property starting
2840 at START_POS in OBJECT. */
2842 static struct text_pos
2843 display_prop_end (it
, object
, start_pos
)
2846 struct text_pos start_pos
;
2849 struct text_pos end_pos
;
2851 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2852 Qdisplay
, object
, Qnil
);
2853 CHARPOS (end_pos
) = XFASTINT (end
);
2854 if (STRINGP (object
))
2855 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2857 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2863 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2864 is the object in which the `display' property was found. *POSITION
2865 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2866 means that we previously saw a display sub-property which already
2867 replaced text display with something else, for example an image;
2868 ignore such properties after the first one has been processed.
2870 If PROP is a `space' or `image' sub-property, set *POSITION to the
2871 end position of the `display' property.
2873 Value is non-zero if something was found which replaces the display
2874 of buffer or string text. */
2877 handle_single_display_prop (it
, prop
, object
, position
,
2878 display_replaced_before_p
)
2882 struct text_pos
*position
;
2883 int display_replaced_before_p
;
2886 int replaces_text_display_p
= 0;
2889 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2890 evaluated. If the result is nil, VALUE is ignored. */
2892 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2901 if (!NILP (form
) && !EQ (form
, Qt
))
2903 int count
= SPECPDL_INDEX ();
2904 struct gcpro gcpro1
;
2906 /* Bind `object' to the object having the `display' property, a
2907 buffer or string. Bind `position' to the position in the
2908 object where the property was found, and `buffer-position'
2909 to the current position in the buffer. */
2910 specbind (Qobject
, object
);
2911 specbind (Qposition
, make_number (CHARPOS (*position
)));
2912 specbind (Qbuffer_position
,
2913 make_number (STRINGP (object
)
2914 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2916 form
= safe_eval (form
);
2918 unbind_to (count
, Qnil
);
2925 && EQ (XCAR (prop
), Qheight
)
2926 && CONSP (XCDR (prop
)))
2928 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2931 /* `(height HEIGHT)'. */
2932 it
->font_height
= XCAR (XCDR (prop
));
2933 if (!NILP (it
->font_height
))
2935 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2936 int new_height
= -1;
2938 if (CONSP (it
->font_height
)
2939 && (EQ (XCAR (it
->font_height
), Qplus
)
2940 || EQ (XCAR (it
->font_height
), Qminus
))
2941 && CONSP (XCDR (it
->font_height
))
2942 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2944 /* `(+ N)' or `(- N)' where N is an integer. */
2945 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2946 if (EQ (XCAR (it
->font_height
), Qplus
))
2948 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2950 else if (FUNCTIONP (it
->font_height
))
2952 /* Call function with current height as argument.
2953 Value is the new height. */
2955 height
= safe_call1 (it
->font_height
,
2956 face
->lface
[LFACE_HEIGHT_INDEX
]);
2957 if (NUMBERP (height
))
2958 new_height
= XFLOATINT (height
);
2960 else if (NUMBERP (it
->font_height
))
2962 /* Value is a multiple of the canonical char height. */
2965 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2966 new_height
= (XFLOATINT (it
->font_height
)
2967 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2971 /* Evaluate IT->font_height with `height' bound to the
2972 current specified height to get the new height. */
2974 int count
= SPECPDL_INDEX ();
2976 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2977 value
= safe_eval (it
->font_height
);
2978 unbind_to (count
, Qnil
);
2980 if (NUMBERP (value
))
2981 new_height
= XFLOATINT (value
);
2985 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2988 else if (CONSP (prop
)
2989 && EQ (XCAR (prop
), Qspace_width
)
2990 && CONSP (XCDR (prop
)))
2992 /* `(space_width WIDTH)'. */
2993 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2996 value
= XCAR (XCDR (prop
));
2997 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2998 it
->space_width
= value
;
3000 else if (CONSP (prop
)
3001 && EQ (XCAR (prop
), Qraise
)
3002 && CONSP (XCDR (prop
)))
3004 /* `(raise FACTOR)'. */
3005 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3008 #ifdef HAVE_WINDOW_SYSTEM
3009 value
= XCAR (XCDR (prop
));
3010 if (NUMBERP (value
))
3012 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3013 it
->voffset
= - (XFLOATINT (value
)
3014 * (FONT_HEIGHT (face
->font
)));
3016 #endif /* HAVE_WINDOW_SYSTEM */
3018 else if (!it
->string_from_display_prop_p
)
3020 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3021 VALUE) or `((margin nil) VALUE)' or VALUE. */
3022 Lisp_Object location
, value
;
3023 struct text_pos start_pos
;
3026 /* Characters having this form of property are not displayed, so
3027 we have to find the end of the property. */
3028 start_pos
= *position
;
3029 *position
= display_prop_end (it
, object
, start_pos
);
3032 /* Let's stop at the new position and assume that all
3033 text properties change there. */
3034 it
->stop_charpos
= position
->charpos
;
3036 location
= Qunbound
;
3037 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3041 value
= XCDR (prop
);
3043 value
= XCAR (value
);
3046 if (EQ (XCAR (tem
), Qmargin
)
3047 && (tem
= XCDR (tem
),
3048 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3050 || EQ (tem
, Qleft_margin
)
3051 || EQ (tem
, Qright_margin
))))
3055 if (EQ (location
, Qunbound
))
3061 #ifdef HAVE_WINDOW_SYSTEM
3062 if (FRAME_TERMCAP_P (it
->f
))
3063 valid_p
= STRINGP (value
);
3065 valid_p
= (STRINGP (value
)
3066 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3067 || valid_image_p (value
));
3068 #else /* not HAVE_WINDOW_SYSTEM */
3069 valid_p
= STRINGP (value
);
3070 #endif /* not HAVE_WINDOW_SYSTEM */
3072 if ((EQ (location
, Qleft_margin
)
3073 || EQ (location
, Qright_margin
)
3076 && !display_replaced_before_p
)
3078 replaces_text_display_p
= 1;
3080 /* Save current settings of IT so that we can restore them
3081 when we are finished with the glyph property value. */
3084 if (NILP (location
))
3085 it
->area
= TEXT_AREA
;
3086 else if (EQ (location
, Qleft_margin
))
3087 it
->area
= LEFT_MARGIN_AREA
;
3089 it
->area
= RIGHT_MARGIN_AREA
;
3091 if (STRINGP (value
))
3094 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3095 it
->current
.overlay_string_index
= -1;
3096 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3097 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3098 it
->method
= next_element_from_string
;
3099 it
->stop_charpos
= 0;
3100 it
->string_from_display_prop_p
= 1;
3101 /* Say that we haven't consumed the characters with
3102 `display' property yet. The call to pop_it in
3103 set_iterator_to_next will clean this up. */
3104 *position
= start_pos
;
3106 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3108 it
->method
= next_element_from_stretch
;
3110 it
->current
.pos
= it
->position
= start_pos
;
3112 #ifdef HAVE_WINDOW_SYSTEM
3115 it
->what
= IT_IMAGE
;
3116 it
->image_id
= lookup_image (it
->f
, value
);
3117 it
->position
= start_pos
;
3118 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3119 it
->method
= next_element_from_image
;
3121 /* Say that we haven't consumed the characters with
3122 `display' property yet. The call to pop_it in
3123 set_iterator_to_next will clean this up. */
3124 *position
= start_pos
;
3126 #endif /* HAVE_WINDOW_SYSTEM */
3129 /* Invalid property or property not supported. Restore
3130 the position to what it was before. */
3131 *position
= start_pos
;
3134 return replaces_text_display_p
;
3138 /* Check if PROP is a display sub-property value whose text should be
3139 treated as intangible. */
3142 single_display_prop_intangible_p (prop
)
3145 /* Skip over `when FORM'. */
3146 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3157 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3158 we don't need to treat text as intangible. */
3159 if (EQ (XCAR (prop
), Qmargin
))
3167 || EQ (XCAR (prop
), Qleft_margin
)
3168 || EQ (XCAR (prop
), Qright_margin
))
3172 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3176 /* Check if PROP is a display property value whose text should be
3177 treated as intangible. */
3180 display_prop_intangible_p (prop
)
3184 && CONSP (XCAR (prop
))
3185 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3187 /* A list of sub-properties. */
3188 while (CONSP (prop
))
3190 if (single_display_prop_intangible_p (XCAR (prop
)))
3195 else if (VECTORP (prop
))
3197 /* A vector of sub-properties. */
3199 for (i
= 0; i
< ASIZE (prop
); ++i
)
3200 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3204 return single_display_prop_intangible_p (prop
);
3210 /* Return 1 if PROP is a display sub-property value containing STRING. */
3213 single_display_prop_string_p (prop
, string
)
3214 Lisp_Object prop
, string
;
3216 if (EQ (string
, prop
))
3219 /* Skip over `when FORM'. */
3220 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3229 /* Skip over `margin LOCATION'. */
3230 if (EQ (XCAR (prop
), Qmargin
))
3241 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3245 /* Return 1 if STRING appears in the `display' property PROP. */
3248 display_prop_string_p (prop
, string
)
3249 Lisp_Object prop
, string
;
3252 && CONSP (XCAR (prop
))
3253 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3255 /* A list of sub-properties. */
3256 while (CONSP (prop
))
3258 if (single_display_prop_string_p (XCAR (prop
), string
))
3263 else if (VECTORP (prop
))
3265 /* A vector of sub-properties. */
3267 for (i
= 0; i
< ASIZE (prop
); ++i
)
3268 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3272 return single_display_prop_string_p (prop
, string
);
3278 /* Determine from which buffer position in W's buffer STRING comes
3279 from. AROUND_CHARPOS is an approximate position where it could
3280 be from. Value is the buffer position or 0 if it couldn't be
3283 W's buffer must be current.
3285 This function is necessary because we don't record buffer positions
3286 in glyphs generated from strings (to keep struct glyph small).
3287 This function may only use code that doesn't eval because it is
3288 called asynchronously from note_mouse_highlight. */
3291 string_buffer_position (w
, string
, around_charpos
)
3296 Lisp_Object limit
, prop
, pos
;
3297 const int MAX_DISTANCE
= 1000;
3300 pos
= make_number (around_charpos
);
3301 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3302 while (!found
&& !EQ (pos
, limit
))
3304 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3305 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3308 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3313 pos
= make_number (around_charpos
);
3314 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3315 while (!found
&& !EQ (pos
, limit
))
3317 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3318 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3321 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3326 return found
? XINT (pos
) : 0;
3331 /***********************************************************************
3332 `composition' property
3333 ***********************************************************************/
3335 /* Set up iterator IT from `composition' property at its current
3336 position. Called from handle_stop. */
3338 static enum prop_handled
3339 handle_composition_prop (it
)
3342 Lisp_Object prop
, string
;
3343 int pos
, pos_byte
, end
;
3344 enum prop_handled handled
= HANDLED_NORMALLY
;
3346 if (STRINGP (it
->string
))
3348 pos
= IT_STRING_CHARPOS (*it
);
3349 pos_byte
= IT_STRING_BYTEPOS (*it
);
3350 string
= it
->string
;
3354 pos
= IT_CHARPOS (*it
);
3355 pos_byte
= IT_BYTEPOS (*it
);
3359 /* If there's a valid composition and point is not inside of the
3360 composition (in the case that the composition is from the current
3361 buffer), draw a glyph composed from the composition components. */
3362 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3363 && COMPOSITION_VALID_P (pos
, end
, prop
)
3364 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3366 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3370 it
->method
= next_element_from_composition
;
3372 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3373 /* For a terminal, draw only the first character of the
3375 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3376 it
->len
= (STRINGP (it
->string
)
3377 ? string_char_to_byte (it
->string
, end
)
3378 : CHAR_TO_BYTE (end
)) - pos_byte
;
3379 it
->stop_charpos
= end
;
3380 handled
= HANDLED_RETURN
;
3389 /***********************************************************************
3391 ***********************************************************************/
3393 /* The following structure is used to record overlay strings for
3394 later sorting in load_overlay_strings. */
3396 struct overlay_entry
3398 Lisp_Object overlay
;
3405 /* Set up iterator IT from overlay strings at its current position.
3406 Called from handle_stop. */
3408 static enum prop_handled
3409 handle_overlay_change (it
)
3412 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3413 return HANDLED_RECOMPUTE_PROPS
;
3415 return HANDLED_NORMALLY
;
3419 /* Set up the next overlay string for delivery by IT, if there is an
3420 overlay string to deliver. Called by set_iterator_to_next when the
3421 end of the current overlay string is reached. If there are more
3422 overlay strings to display, IT->string and
3423 IT->current.overlay_string_index are set appropriately here.
3424 Otherwise IT->string is set to nil. */
3427 next_overlay_string (it
)
3430 ++it
->current
.overlay_string_index
;
3431 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3433 /* No more overlay strings. Restore IT's settings to what
3434 they were before overlay strings were processed, and
3435 continue to deliver from current_buffer. */
3436 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3439 xassert (it
->stop_charpos
>= BEGV
3440 && it
->stop_charpos
<= it
->end_charpos
);
3442 it
->current
.overlay_string_index
= -1;
3443 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3444 it
->n_overlay_strings
= 0;
3445 it
->method
= next_element_from_buffer
;
3447 /* If we're at the end of the buffer, record that we have
3448 processed the overlay strings there already, so that
3449 next_element_from_buffer doesn't try it again. */
3450 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3451 it
->overlay_strings_at_end_processed_p
= 1;
3453 /* If we have to display `...' for invisible text, set
3454 the iterator up for that. */
3455 if (display_ellipsis_p
)
3456 setup_for_ellipsis (it
);
3460 /* There are more overlay strings to process. If
3461 IT->current.overlay_string_index has advanced to a position
3462 where we must load IT->overlay_strings with more strings, do
3464 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3466 if (it
->current
.overlay_string_index
&& i
== 0)
3467 load_overlay_strings (it
, 0);
3469 /* Initialize IT to deliver display elements from the overlay
3471 it
->string
= it
->overlay_strings
[i
];
3472 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3473 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3474 it
->method
= next_element_from_string
;
3475 it
->stop_charpos
= 0;
3482 /* Compare two overlay_entry structures E1 and E2. Used as a
3483 comparison function for qsort in load_overlay_strings. Overlay
3484 strings for the same position are sorted so that
3486 1. All after-strings come in front of before-strings, except
3487 when they come from the same overlay.
3489 2. Within after-strings, strings are sorted so that overlay strings
3490 from overlays with higher priorities come first.
3492 2. Within before-strings, strings are sorted so that overlay
3493 strings from overlays with higher priorities come last.
3495 Value is analogous to strcmp. */
3499 compare_overlay_entries (e1
, e2
)
3502 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3503 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3506 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3508 /* Let after-strings appear in front of before-strings if
3509 they come from different overlays. */
3510 if (EQ (entry1
->overlay
, entry2
->overlay
))
3511 result
= entry1
->after_string_p
? 1 : -1;
3513 result
= entry1
->after_string_p
? -1 : 1;
3515 else if (entry1
->after_string_p
)
3516 /* After-strings sorted in order of decreasing priority. */
3517 result
= entry2
->priority
- entry1
->priority
;
3519 /* Before-strings sorted in order of increasing priority. */
3520 result
= entry1
->priority
- entry2
->priority
;
3526 /* Load the vector IT->overlay_strings with overlay strings from IT's
3527 current buffer position, or from CHARPOS if that is > 0. Set
3528 IT->n_overlays to the total number of overlay strings found.
3530 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3531 a time. On entry into load_overlay_strings,
3532 IT->current.overlay_string_index gives the number of overlay
3533 strings that have already been loaded by previous calls to this
3536 IT->add_overlay_start contains an additional overlay start
3537 position to consider for taking overlay strings from, if non-zero.
3538 This position comes into play when the overlay has an `invisible'
3539 property, and both before and after-strings. When we've skipped to
3540 the end of the overlay, because of its `invisible' property, we
3541 nevertheless want its before-string to appear.
3542 IT->add_overlay_start will contain the overlay start position
3545 Overlay strings are sorted so that after-string strings come in
3546 front of before-string strings. Within before and after-strings,
3547 strings are sorted by overlay priority. See also function
3548 compare_overlay_entries. */
3551 load_overlay_strings (it
, charpos
)
3555 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3556 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3559 int n
= 0, i
, j
, invis_p
;
3560 struct overlay_entry
*entries
3561 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3564 charpos
= IT_CHARPOS (*it
);
3566 /* Append the overlay string STRING of overlay OVERLAY to vector
3567 `entries' which has size `size' and currently contains `n'
3568 elements. AFTER_P non-zero means STRING is an after-string of
3570 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3573 Lisp_Object priority; \
3577 int new_size = 2 * size; \
3578 struct overlay_entry *old = entries; \
3580 (struct overlay_entry *) alloca (new_size \
3581 * sizeof *entries); \
3582 bcopy (old, entries, size * sizeof *entries); \
3586 entries[n].string = (STRING); \
3587 entries[n].overlay = (OVERLAY); \
3588 priority = Foverlay_get ((OVERLAY), Qpriority); \
3589 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3590 entries[n].after_string_p = (AFTER_P); \
3595 /* Process overlay before the overlay center. */
3596 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3598 overlay
= XCAR (ov
);
3599 xassert (OVERLAYP (overlay
));
3600 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3601 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3606 /* Skip this overlay if it doesn't start or end at IT's current
3608 if (end
!= charpos
&& start
!= charpos
)
3611 /* Skip this overlay if it doesn't apply to IT->w. */
3612 window
= Foverlay_get (overlay
, Qwindow
);
3613 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3616 /* If the text ``under'' the overlay is invisible, both before-
3617 and after-strings from this overlay are visible; start and
3618 end position are indistinguishable. */
3619 invisible
= Foverlay_get (overlay
, Qinvisible
);
3620 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3622 /* If overlay has a non-empty before-string, record it. */
3623 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3624 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3626 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3628 /* If overlay has a non-empty after-string, record it. */
3629 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3630 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3632 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3635 /* Process overlays after the overlay center. */
3636 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3638 overlay
= XCAR (ov
);
3639 xassert (OVERLAYP (overlay
));
3640 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3641 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3643 if (start
> charpos
)
3646 /* Skip this overlay if it doesn't start or end at IT's current
3648 if (end
!= charpos
&& start
!= charpos
)
3651 /* Skip this overlay if it doesn't apply to IT->w. */
3652 window
= Foverlay_get (overlay
, Qwindow
);
3653 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3656 /* If the text ``under'' the overlay is invisible, it has a zero
3657 dimension, and both before- and after-strings apply. */
3658 invisible
= Foverlay_get (overlay
, Qinvisible
);
3659 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3661 /* If overlay has a non-empty before-string, record it. */
3662 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3663 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3665 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3667 /* If overlay has a non-empty after-string, record it. */
3668 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3669 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3671 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3674 #undef RECORD_OVERLAY_STRING
3678 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3680 /* Record the total number of strings to process. */
3681 it
->n_overlay_strings
= n
;
3683 /* IT->current.overlay_string_index is the number of overlay strings
3684 that have already been consumed by IT. Copy some of the
3685 remaining overlay strings to IT->overlay_strings. */
3687 j
= it
->current
.overlay_string_index
;
3688 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3689 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3695 /* Get the first chunk of overlay strings at IT's current buffer
3696 position, or at CHARPOS if that is > 0. Value is non-zero if at
3697 least one overlay string was found. */
3700 get_overlay_strings (it
, charpos
)
3704 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3705 process. This fills IT->overlay_strings with strings, and sets
3706 IT->n_overlay_strings to the total number of strings to process.
3707 IT->pos.overlay_string_index has to be set temporarily to zero
3708 because load_overlay_strings needs this; it must be set to -1
3709 when no overlay strings are found because a zero value would
3710 indicate a position in the first overlay string. */
3711 it
->current
.overlay_string_index
= 0;
3712 load_overlay_strings (it
, charpos
);
3714 /* If we found overlay strings, set up IT to deliver display
3715 elements from the first one. Otherwise set up IT to deliver
3716 from current_buffer. */
3717 if (it
->n_overlay_strings
)
3719 /* Make sure we know settings in current_buffer, so that we can
3720 restore meaningful values when we're done with the overlay
3722 compute_stop_pos (it
);
3723 xassert (it
->face_id
>= 0);
3725 /* Save IT's settings. They are restored after all overlay
3726 strings have been processed. */
3727 xassert (it
->sp
== 0);
3730 /* Set up IT to deliver display elements from the first overlay
3732 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3733 it
->string
= it
->overlay_strings
[0];
3734 it
->stop_charpos
= 0;
3735 xassert (STRINGP (it
->string
));
3736 it
->end_charpos
= SCHARS (it
->string
);
3737 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3738 it
->method
= next_element_from_string
;
3743 it
->current
.overlay_string_index
= -1;
3744 it
->method
= next_element_from_buffer
;
3749 /* Value is non-zero if we found at least one overlay string. */
3750 return STRINGP (it
->string
);
3755 /***********************************************************************
3756 Saving and restoring state
3757 ***********************************************************************/
3759 /* Save current settings of IT on IT->stack. Called, for example,
3760 before setting up IT for an overlay string, to be able to restore
3761 IT's settings to what they were after the overlay string has been
3768 struct iterator_stack_entry
*p
;
3770 xassert (it
->sp
< 2);
3771 p
= it
->stack
+ it
->sp
;
3773 p
->stop_charpos
= it
->stop_charpos
;
3774 xassert (it
->face_id
>= 0);
3775 p
->face_id
= it
->face_id
;
3776 p
->string
= it
->string
;
3777 p
->pos
= it
->current
;
3778 p
->end_charpos
= it
->end_charpos
;
3779 p
->string_nchars
= it
->string_nchars
;
3781 p
->multibyte_p
= it
->multibyte_p
;
3782 p
->space_width
= it
->space_width
;
3783 p
->font_height
= it
->font_height
;
3784 p
->voffset
= it
->voffset
;
3785 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3786 p
->display_ellipsis_p
= 0;
3791 /* Restore IT's settings from IT->stack. Called, for example, when no
3792 more overlay strings must be processed, and we return to delivering
3793 display elements from a buffer, or when the end of a string from a
3794 `display' property is reached and we return to delivering display
3795 elements from an overlay string, or from a buffer. */
3801 struct iterator_stack_entry
*p
;
3803 xassert (it
->sp
> 0);
3805 p
= it
->stack
+ it
->sp
;
3806 it
->stop_charpos
= p
->stop_charpos
;
3807 it
->face_id
= p
->face_id
;
3808 it
->string
= p
->string
;
3809 it
->current
= p
->pos
;
3810 it
->end_charpos
= p
->end_charpos
;
3811 it
->string_nchars
= p
->string_nchars
;
3813 it
->multibyte_p
= p
->multibyte_p
;
3814 it
->space_width
= p
->space_width
;
3815 it
->font_height
= p
->font_height
;
3816 it
->voffset
= p
->voffset
;
3817 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3822 /***********************************************************************
3824 ***********************************************************************/
3826 /* Set IT's current position to the previous line start. */
3829 back_to_previous_line_start (it
)
3832 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3833 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3837 /* Move IT to the next line start.
3839 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3840 we skipped over part of the text (as opposed to moving the iterator
3841 continuously over the text). Otherwise, don't change the value
3844 Newlines may come from buffer text, overlay strings, or strings
3845 displayed via the `display' property. That's the reason we can't
3846 simply use find_next_newline_no_quit.
3848 Note that this function may not skip over invisible text that is so
3849 because of text properties and immediately follows a newline. If
3850 it would, function reseat_at_next_visible_line_start, when called
3851 from set_iterator_to_next, would effectively make invisible
3852 characters following a newline part of the wrong glyph row, which
3853 leads to wrong cursor motion. */
3856 forward_to_next_line_start (it
, skipped_p
)
3860 int old_selective
, newline_found_p
, n
;
3861 const int MAX_NEWLINE_DISTANCE
= 500;
3863 /* If already on a newline, just consume it to avoid unintended
3864 skipping over invisible text below. */
3865 if (it
->what
== IT_CHARACTER
3867 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3869 set_iterator_to_next (it
, 0);
3874 /* Don't handle selective display in the following. It's (a)
3875 unnecessary because it's done by the caller, and (b) leads to an
3876 infinite recursion because next_element_from_ellipsis indirectly
3877 calls this function. */
3878 old_selective
= it
->selective
;
3881 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3882 from buffer text. */
3883 for (n
= newline_found_p
= 0;
3884 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3885 n
+= STRINGP (it
->string
) ? 0 : 1)
3887 if (!get_next_display_element (it
))
3889 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3890 set_iterator_to_next (it
, 0);
3893 /* If we didn't find a newline near enough, see if we can use a
3895 if (!newline_found_p
)
3897 int start
= IT_CHARPOS (*it
);
3898 int limit
= find_next_newline_no_quit (start
, 1);
3901 xassert (!STRINGP (it
->string
));
3903 /* If there isn't any `display' property in sight, and no
3904 overlays, we can just use the position of the newline in
3906 if (it
->stop_charpos
>= limit
3907 || ((pos
= Fnext_single_property_change (make_number (start
),
3909 Qnil
, make_number (limit
)),
3911 && next_overlay_change (start
) == ZV
))
3913 IT_CHARPOS (*it
) = limit
;
3914 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3915 *skipped_p
= newline_found_p
= 1;
3919 while (get_next_display_element (it
)
3920 && !newline_found_p
)
3922 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3923 set_iterator_to_next (it
, 0);
3928 it
->selective
= old_selective
;
3929 return newline_found_p
;
3933 /* Set IT's current position to the previous visible line start. Skip
3934 invisible text that is so either due to text properties or due to
3935 selective display. Caution: this does not change IT->current_x and
3939 back_to_previous_visible_line_start (it
)
3944 /* Go back one newline if not on BEGV already. */
3945 if (IT_CHARPOS (*it
) > BEGV
)
3946 back_to_previous_line_start (it
);
3948 /* Move over lines that are invisible because of selective display
3949 or text properties. */
3950 while (IT_CHARPOS (*it
) > BEGV
3955 /* If selective > 0, then lines indented more than that values
3957 if (it
->selective
> 0
3958 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3959 (double) it
->selective
)) /* iftc */
3965 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3966 Qinvisible
, it
->window
);
3967 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3971 /* Back one more newline if the current one is invisible. */
3973 back_to_previous_line_start (it
);
3976 xassert (IT_CHARPOS (*it
) >= BEGV
);
3977 xassert (IT_CHARPOS (*it
) == BEGV
3978 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3983 /* Reseat iterator IT at the previous visible line start. Skip
3984 invisible text that is so either due to text properties or due to
3985 selective display. At the end, update IT's overlay information,
3986 face information etc. */
3989 reseat_at_previous_visible_line_start (it
)
3992 back_to_previous_visible_line_start (it
);
3993 reseat (it
, it
->current
.pos
, 1);
3998 /* Reseat iterator IT on the next visible line start in the current
3999 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4000 preceding the line start. Skip over invisible text that is so
4001 because of selective display. Compute faces, overlays etc at the
4002 new position. Note that this function does not skip over text that
4003 is invisible because of text properties. */
4006 reseat_at_next_visible_line_start (it
, on_newline_p
)
4010 int newline_found_p
, skipped_p
= 0;
4012 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4014 /* Skip over lines that are invisible because they are indented
4015 more than the value of IT->selective. */
4016 if (it
->selective
> 0)
4017 while (IT_CHARPOS (*it
) < ZV
4018 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4019 (double) it
->selective
)) /* iftc */
4021 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4022 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4025 /* Position on the newline if that's what's requested. */
4026 if (on_newline_p
&& newline_found_p
)
4028 if (STRINGP (it
->string
))
4030 if (IT_STRING_CHARPOS (*it
) > 0)
4032 --IT_STRING_CHARPOS (*it
);
4033 --IT_STRING_BYTEPOS (*it
);
4036 else if (IT_CHARPOS (*it
) > BEGV
)
4040 reseat (it
, it
->current
.pos
, 0);
4044 reseat (it
, it
->current
.pos
, 0);
4051 /***********************************************************************
4052 Changing an iterator's position
4053 ***********************************************************************/
4055 /* Change IT's current position to POS in current_buffer. If FORCE_P
4056 is non-zero, always check for text properties at the new position.
4057 Otherwise, text properties are only looked up if POS >=
4058 IT->check_charpos of a property. */
4061 reseat (it
, pos
, force_p
)
4063 struct text_pos pos
;
4066 int original_pos
= IT_CHARPOS (*it
);
4068 reseat_1 (it
, pos
, 0);
4070 /* Determine where to check text properties. Avoid doing it
4071 where possible because text property lookup is very expensive. */
4073 || CHARPOS (pos
) > it
->stop_charpos
4074 || CHARPOS (pos
) < original_pos
)
4081 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4082 IT->stop_pos to POS, also. */
4085 reseat_1 (it
, pos
, set_stop_p
)
4087 struct text_pos pos
;
4090 /* Don't call this function when scanning a C string. */
4091 xassert (it
->s
== NULL
);
4093 /* POS must be a reasonable value. */
4094 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4096 it
->current
.pos
= it
->position
= pos
;
4097 XSETBUFFER (it
->object
, current_buffer
);
4098 it
->end_charpos
= ZV
;
4100 it
->current
.dpvec_index
= -1;
4101 it
->current
.overlay_string_index
= -1;
4102 IT_STRING_CHARPOS (*it
) = -1;
4103 IT_STRING_BYTEPOS (*it
) = -1;
4105 it
->method
= next_element_from_buffer
;
4106 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4108 it
->face_before_selective_p
= 0;
4111 it
->stop_charpos
= CHARPOS (pos
);
4115 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4116 If S is non-null, it is a C string to iterate over. Otherwise,
4117 STRING gives a Lisp string to iterate over.
4119 If PRECISION > 0, don't return more then PRECISION number of
4120 characters from the string.
4122 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4123 characters have been returned. FIELD_WIDTH < 0 means an infinite
4126 MULTIBYTE = 0 means disable processing of multibyte characters,
4127 MULTIBYTE > 0 means enable it,
4128 MULTIBYTE < 0 means use IT->multibyte_p.
4130 IT must be initialized via a prior call to init_iterator before
4131 calling this function. */
4134 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4139 int precision
, field_width
, multibyte
;
4141 /* No region in strings. */
4142 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4144 /* No text property checks performed by default, but see below. */
4145 it
->stop_charpos
= -1;
4147 /* Set iterator position and end position. */
4148 bzero (&it
->current
, sizeof it
->current
);
4149 it
->current
.overlay_string_index
= -1;
4150 it
->current
.dpvec_index
= -1;
4151 xassert (charpos
>= 0);
4153 /* If STRING is specified, use its multibyteness, otherwise use the
4154 setting of MULTIBYTE, if specified. */
4156 it
->multibyte_p
= multibyte
> 0;
4160 xassert (STRINGP (string
));
4161 it
->string
= string
;
4163 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4164 it
->method
= next_element_from_string
;
4165 it
->current
.string_pos
= string_pos (charpos
, string
);
4172 /* Note that we use IT->current.pos, not it->current.string_pos,
4173 for displaying C strings. */
4174 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4175 if (it
->multibyte_p
)
4177 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4178 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4182 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4183 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4186 it
->method
= next_element_from_c_string
;
4189 /* PRECISION > 0 means don't return more than PRECISION characters
4191 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4192 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4194 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4195 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4196 FIELD_WIDTH < 0 means infinite field width. This is useful for
4197 padding with `-' at the end of a mode line. */
4198 if (field_width
< 0)
4199 field_width
= INFINITY
;
4200 if (field_width
> it
->end_charpos
- charpos
)
4201 it
->end_charpos
= charpos
+ field_width
;
4203 /* Use the standard display table for displaying strings. */
4204 if (DISP_TABLE_P (Vstandard_display_table
))
4205 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4207 it
->stop_charpos
= charpos
;
4213 /***********************************************************************
4215 ***********************************************************************/
4217 /* Load IT's display element fields with information about the next
4218 display element from the current position of IT. Value is zero if
4219 end of buffer (or C string) is reached. */
4222 get_next_display_element (it
)
4225 /* Non-zero means that we found an display element. Zero means that
4226 we hit the end of what we iterate over. Performance note: the
4227 function pointer `method' used here turns out to be faster than
4228 using a sequence of if-statements. */
4229 int success_p
= (*it
->method
) (it
);
4231 if (it
->what
== IT_CHARACTER
)
4233 /* Map via display table or translate control characters.
4234 IT->c, IT->len etc. have been set to the next character by
4235 the function call above. If we have a display table, and it
4236 contains an entry for IT->c, translate it. Don't do this if
4237 IT->c itself comes from a display table, otherwise we could
4238 end up in an infinite recursion. (An alternative could be to
4239 count the recursion depth of this function and signal an
4240 error when a certain maximum depth is reached.) Is it worth
4242 if (success_p
&& it
->dpvec
== NULL
)
4247 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4250 struct Lisp_Vector
*v
= XVECTOR (dv
);
4252 /* Return the first character from the display table
4253 entry, if not empty. If empty, don't display the
4254 current character. */
4257 it
->dpvec_char_len
= it
->len
;
4258 it
->dpvec
= v
->contents
;
4259 it
->dpend
= v
->contents
+ v
->size
;
4260 it
->current
.dpvec_index
= 0;
4261 it
->method
= next_element_from_display_vector
;
4262 success_p
= get_next_display_element (it
);
4266 set_iterator_to_next (it
, 0);
4267 success_p
= get_next_display_element (it
);
4271 /* Translate control characters into `\003' or `^C' form.
4272 Control characters coming from a display table entry are
4273 currently not translated because we use IT->dpvec to hold
4274 the translation. This could easily be changed but I
4275 don't believe that it is worth doing.
4277 If it->multibyte_p is nonzero, eight-bit characters and
4278 non-printable multibyte characters are also translated to
4281 If it->multibyte_p is zero, eight-bit characters that
4282 don't have corresponding multibyte char code are also
4283 translated to octal form. */
4284 else if (((it
->c
< ' ' || it
->c
== 127)
4285 && (it
->area
!= TEXT_AREA
4286 || (it
->c
!= '\n' && it
->c
!= '\t')))
4290 || !CHAR_PRINTABLE_P (it
->c
))
4292 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4294 /* IT->c is a control character which must be displayed
4295 either as '\003' or as `^C' where the '\\' and '^'
4296 can be defined in the display table. Fill
4297 IT->ctl_chars with glyphs for what we have to
4298 display. Then, set IT->dpvec to these glyphs. */
4301 if (it
->c
< 128 && it
->ctl_arrow_p
)
4303 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4305 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4306 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4307 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4309 g
= FAST_MAKE_GLYPH ('^', 0);
4310 XSETINT (it
->ctl_chars
[0], g
);
4312 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4313 XSETINT (it
->ctl_chars
[1], g
);
4315 /* Set up IT->dpvec and return first character from it. */
4316 it
->dpvec_char_len
= it
->len
;
4317 it
->dpvec
= it
->ctl_chars
;
4318 it
->dpend
= it
->dpvec
+ 2;
4319 it
->current
.dpvec_index
= 0;
4320 it
->method
= next_element_from_display_vector
;
4321 get_next_display_element (it
);
4325 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4330 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4332 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4333 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4334 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4336 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4338 if (SINGLE_BYTE_CHAR_P (it
->c
))
4339 str
[0] = it
->c
, len
= 1;
4342 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4345 /* It's an invalid character, which
4346 shouldn't happen actually, but due to
4347 bugs it may happen. Let's print the char
4348 as is, there's not much meaningful we can
4351 str
[1] = it
->c
>> 8;
4352 str
[2] = it
->c
>> 16;
4353 str
[3] = it
->c
>> 24;
4358 for (i
= 0; i
< len
; i
++)
4360 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4361 /* Insert three more glyphs into IT->ctl_chars for
4362 the octal display of the character. */
4363 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4364 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4365 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4366 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4367 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4368 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4371 /* Set up IT->dpvec and return the first character
4373 it
->dpvec_char_len
= it
->len
;
4374 it
->dpvec
= it
->ctl_chars
;
4375 it
->dpend
= it
->dpvec
+ len
* 4;
4376 it
->current
.dpvec_index
= 0;
4377 it
->method
= next_element_from_display_vector
;
4378 get_next_display_element (it
);
4383 /* Adjust face id for a multibyte character. There are no
4384 multibyte character in unibyte text. */
4387 && FRAME_WINDOW_P (it
->f
))
4389 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4390 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4394 /* Is this character the last one of a run of characters with
4395 box? If yes, set IT->end_of_box_run_p to 1. */
4402 it
->end_of_box_run_p
4403 = ((face_id
= face_after_it_pos (it
),
4404 face_id
!= it
->face_id
)
4405 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4406 face
->box
== FACE_NO_BOX
));
4409 /* Value is 0 if end of buffer or string reached. */
4414 /* Move IT to the next display element.
4416 RESEAT_P non-zero means if called on a newline in buffer text,
4417 skip to the next visible line start.
4419 Functions get_next_display_element and set_iterator_to_next are
4420 separate because I find this arrangement easier to handle than a
4421 get_next_display_element function that also increments IT's
4422 position. The way it is we can first look at an iterator's current
4423 display element, decide whether it fits on a line, and if it does,
4424 increment the iterator position. The other way around we probably
4425 would either need a flag indicating whether the iterator has to be
4426 incremented the next time, or we would have to implement a
4427 decrement position function which would not be easy to write. */
4430 set_iterator_to_next (it
, reseat_p
)
4434 /* Reset flags indicating start and end of a sequence of characters
4435 with box. Reset them at the start of this function because
4436 moving the iterator to a new position might set them. */
4437 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4439 if (it
->method
== next_element_from_buffer
)
4441 /* The current display element of IT is a character from
4442 current_buffer. Advance in the buffer, and maybe skip over
4443 invisible lines that are so because of selective display. */
4444 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4445 reseat_at_next_visible_line_start (it
, 0);
4448 xassert (it
->len
!= 0);
4449 IT_BYTEPOS (*it
) += it
->len
;
4450 IT_CHARPOS (*it
) += 1;
4451 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4454 else if (it
->method
== next_element_from_composition
)
4456 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4457 if (STRINGP (it
->string
))
4459 IT_STRING_BYTEPOS (*it
) += it
->len
;
4460 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4461 it
->method
= next_element_from_string
;
4462 goto consider_string_end
;
4466 IT_BYTEPOS (*it
) += it
->len
;
4467 IT_CHARPOS (*it
) += it
->cmp_len
;
4468 it
->method
= next_element_from_buffer
;
4471 else if (it
->method
== next_element_from_c_string
)
4473 /* Current display element of IT is from a C string. */
4474 IT_BYTEPOS (*it
) += it
->len
;
4475 IT_CHARPOS (*it
) += 1;
4477 else if (it
->method
== next_element_from_display_vector
)
4479 /* Current display element of IT is from a display table entry.
4480 Advance in the display table definition. Reset it to null if
4481 end reached, and continue with characters from buffers/
4483 ++it
->current
.dpvec_index
;
4485 /* Restore face of the iterator to what they were before the
4486 display vector entry (these entries may contain faces). */
4487 it
->face_id
= it
->saved_face_id
;
4489 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4492 it
->method
= next_element_from_c_string
;
4493 else if (STRINGP (it
->string
))
4494 it
->method
= next_element_from_string
;
4496 it
->method
= next_element_from_buffer
;
4499 it
->current
.dpvec_index
= -1;
4501 /* Skip over characters which were displayed via IT->dpvec. */
4502 if (it
->dpvec_char_len
< 0)
4503 reseat_at_next_visible_line_start (it
, 1);
4504 else if (it
->dpvec_char_len
> 0)
4506 it
->len
= it
->dpvec_char_len
;
4507 set_iterator_to_next (it
, reseat_p
);
4511 else if (it
->method
== next_element_from_string
)
4513 /* Current display element is a character from a Lisp string. */
4514 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4515 IT_STRING_BYTEPOS (*it
) += it
->len
;
4516 IT_STRING_CHARPOS (*it
) += 1;
4518 consider_string_end
:
4520 if (it
->current
.overlay_string_index
>= 0)
4522 /* IT->string is an overlay string. Advance to the
4523 next, if there is one. */
4524 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4525 next_overlay_string (it
);
4529 /* IT->string is not an overlay string. If we reached
4530 its end, and there is something on IT->stack, proceed
4531 with what is on the stack. This can be either another
4532 string, this time an overlay string, or a buffer. */
4533 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
4537 if (!STRINGP (it
->string
))
4538 it
->method
= next_element_from_buffer
;
4540 goto consider_string_end
;
4544 else if (it
->method
== next_element_from_image
4545 || it
->method
== next_element_from_stretch
)
4547 /* The position etc with which we have to proceed are on
4548 the stack. The position may be at the end of a string,
4549 if the `display' property takes up the whole string. */
4552 if (STRINGP (it
->string
))
4554 it
->method
= next_element_from_string
;
4555 goto consider_string_end
;
4558 it
->method
= next_element_from_buffer
;
4561 /* There are no other methods defined, so this should be a bug. */
4564 xassert (it
->method
!= next_element_from_string
4565 || (STRINGP (it
->string
)
4566 && IT_STRING_CHARPOS (*it
) >= 0));
4570 /* Load IT's display element fields with information about the next
4571 display element which comes from a display table entry or from the
4572 result of translating a control character to one of the forms `^C'
4573 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4576 next_element_from_display_vector (it
)
4580 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4582 /* Remember the current face id in case glyphs specify faces.
4583 IT's face is restored in set_iterator_to_next. */
4584 it
->saved_face_id
= it
->face_id
;
4586 if (INTEGERP (*it
->dpvec
)
4587 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4592 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4593 it
->c
= FAST_GLYPH_CHAR (g
);
4594 it
->len
= CHAR_BYTES (it
->c
);
4596 /* The entry may contain a face id to use. Such a face id is
4597 the id of a Lisp face, not a realized face. A face id of
4598 zero means no face is specified. */
4599 lface_id
= FAST_GLYPH_FACE (g
);
4602 /* The function returns -1 if lface_id is invalid. */
4603 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4605 it
->face_id
= face_id
;
4609 /* Display table entry is invalid. Return a space. */
4610 it
->c
= ' ', it
->len
= 1;
4612 /* Don't change position and object of the iterator here. They are
4613 still the values of the character that had this display table
4614 entry or was translated, and that's what we want. */
4615 it
->what
= IT_CHARACTER
;
4620 /* Load IT with the next display element from Lisp string IT->string.
4621 IT->current.string_pos is the current position within the string.
4622 If IT->current.overlay_string_index >= 0, the Lisp string is an
4626 next_element_from_string (it
)
4629 struct text_pos position
;
4631 xassert (STRINGP (it
->string
));
4632 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4633 position
= it
->current
.string_pos
;
4635 /* Time to check for invisible text? */
4636 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4637 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4641 /* Since a handler may have changed IT->method, we must
4643 return get_next_display_element (it
);
4646 if (it
->current
.overlay_string_index
>= 0)
4648 /* Get the next character from an overlay string. In overlay
4649 strings, There is no field width or padding with spaces to
4651 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4656 else if (STRING_MULTIBYTE (it
->string
))
4658 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4659 const unsigned char *s
= (SDATA (it
->string
)
4660 + IT_STRING_BYTEPOS (*it
));
4661 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4665 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4671 /* Get the next character from a Lisp string that is not an
4672 overlay string. Such strings come from the mode line, for
4673 example. We may have to pad with spaces, or truncate the
4674 string. See also next_element_from_c_string. */
4675 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4680 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4682 /* Pad with spaces. */
4683 it
->c
= ' ', it
->len
= 1;
4684 CHARPOS (position
) = BYTEPOS (position
) = -1;
4686 else if (STRING_MULTIBYTE (it
->string
))
4688 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4689 const unsigned char *s
= (SDATA (it
->string
)
4690 + IT_STRING_BYTEPOS (*it
));
4691 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4695 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4700 /* Record what we have and where it came from. Note that we store a
4701 buffer position in IT->position although it could arguably be a
4703 it
->what
= IT_CHARACTER
;
4704 it
->object
= it
->string
;
4705 it
->position
= position
;
4710 /* Load IT with next display element from C string IT->s.
4711 IT->string_nchars is the maximum number of characters to return
4712 from the string. IT->end_charpos may be greater than
4713 IT->string_nchars when this function is called, in which case we
4714 may have to return padding spaces. Value is zero if end of string
4715 reached, including padding spaces. */
4718 next_element_from_c_string (it
)
4724 it
->what
= IT_CHARACTER
;
4725 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4728 /* IT's position can be greater IT->string_nchars in case a field
4729 width or precision has been specified when the iterator was
4731 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4733 /* End of the game. */
4737 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4739 /* Pad with spaces. */
4740 it
->c
= ' ', it
->len
= 1;
4741 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4743 else if (it
->multibyte_p
)
4745 /* Implementation note: The calls to strlen apparently aren't a
4746 performance problem because there is no noticeable performance
4747 difference between Emacs running in unibyte or multibyte mode. */
4748 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4749 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4753 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4759 /* Set up IT to return characters from an ellipsis, if appropriate.
4760 The definition of the ellipsis glyphs may come from a display table
4761 entry. This function Fills IT with the first glyph from the
4762 ellipsis if an ellipsis is to be displayed. */
4765 next_element_from_ellipsis (it
)
4768 if (it
->selective_display_ellipsis_p
)
4770 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4772 /* Use the display table definition for `...'. Invalid glyphs
4773 will be handled by the method returning elements from dpvec. */
4774 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4775 it
->dpvec_char_len
= it
->len
;
4776 it
->dpvec
= v
->contents
;
4777 it
->dpend
= v
->contents
+ v
->size
;
4778 it
->current
.dpvec_index
= 0;
4779 it
->method
= next_element_from_display_vector
;
4783 /* Use default `...' which is stored in default_invis_vector. */
4784 it
->dpvec_char_len
= it
->len
;
4785 it
->dpvec
= default_invis_vector
;
4786 it
->dpend
= default_invis_vector
+ 3;
4787 it
->current
.dpvec_index
= 0;
4788 it
->method
= next_element_from_display_vector
;
4793 /* The face at the current position may be different from the
4794 face we find after the invisible text. Remember what it
4795 was in IT->saved_face_id, and signal that it's there by
4796 setting face_before_selective_p. */
4797 it
->saved_face_id
= it
->face_id
;
4798 it
->method
= next_element_from_buffer
;
4799 reseat_at_next_visible_line_start (it
, 1);
4800 it
->face_before_selective_p
= 1;
4803 return get_next_display_element (it
);
4807 /* Deliver an image display element. The iterator IT is already
4808 filled with image information (done in handle_display_prop). Value
4813 next_element_from_image (it
)
4816 it
->what
= IT_IMAGE
;
4821 /* Fill iterator IT with next display element from a stretch glyph
4822 property. IT->object is the value of the text property. Value is
4826 next_element_from_stretch (it
)
4829 it
->what
= IT_STRETCH
;
4834 /* Load IT with the next display element from current_buffer. Value
4835 is zero if end of buffer reached. IT->stop_charpos is the next
4836 position at which to stop and check for text properties or buffer
4840 next_element_from_buffer (it
)
4845 /* Check this assumption, otherwise, we would never enter the
4846 if-statement, below. */
4847 xassert (IT_CHARPOS (*it
) >= BEGV
4848 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4850 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4852 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4854 int overlay_strings_follow_p
;
4856 /* End of the game, except when overlay strings follow that
4857 haven't been returned yet. */
4858 if (it
->overlay_strings_at_end_processed_p
)
4859 overlay_strings_follow_p
= 0;
4862 it
->overlay_strings_at_end_processed_p
= 1;
4863 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4866 if (overlay_strings_follow_p
)
4867 success_p
= get_next_display_element (it
);
4871 it
->position
= it
->current
.pos
;
4878 return get_next_display_element (it
);
4883 /* No face changes, overlays etc. in sight, so just return a
4884 character from current_buffer. */
4887 /* Maybe run the redisplay end trigger hook. Performance note:
4888 This doesn't seem to cost measurable time. */
4889 if (it
->redisplay_end_trigger_charpos
4891 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4892 run_redisplay_end_trigger_hook (it
);
4894 /* Get the next character, maybe multibyte. */
4895 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4896 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4898 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4899 - IT_BYTEPOS (*it
));
4900 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4903 it
->c
= *p
, it
->len
= 1;
4905 /* Record what we have and where it came from. */
4906 it
->what
= IT_CHARACTER
;;
4907 it
->object
= it
->w
->buffer
;
4908 it
->position
= it
->current
.pos
;
4910 /* Normally we return the character found above, except when we
4911 really want to return an ellipsis for selective display. */
4916 /* A value of selective > 0 means hide lines indented more
4917 than that number of columns. */
4918 if (it
->selective
> 0
4919 && IT_CHARPOS (*it
) + 1 < ZV
4920 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4921 IT_BYTEPOS (*it
) + 1,
4922 (double) it
->selective
)) /* iftc */
4924 success_p
= next_element_from_ellipsis (it
);
4925 it
->dpvec_char_len
= -1;
4928 else if (it
->c
== '\r' && it
->selective
== -1)
4930 /* A value of selective == -1 means that everything from the
4931 CR to the end of the line is invisible, with maybe an
4932 ellipsis displayed for it. */
4933 success_p
= next_element_from_ellipsis (it
);
4934 it
->dpvec_char_len
= -1;
4939 /* Value is zero if end of buffer reached. */
4940 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4945 /* Run the redisplay end trigger hook for IT. */
4948 run_redisplay_end_trigger_hook (it
)
4951 Lisp_Object args
[3];
4953 /* IT->glyph_row should be non-null, i.e. we should be actually
4954 displaying something, or otherwise we should not run the hook. */
4955 xassert (it
->glyph_row
);
4957 /* Set up hook arguments. */
4958 args
[0] = Qredisplay_end_trigger_functions
;
4959 args
[1] = it
->window
;
4960 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4961 it
->redisplay_end_trigger_charpos
= 0;
4963 /* Since we are *trying* to run these functions, don't try to run
4964 them again, even if they get an error. */
4965 it
->w
->redisplay_end_trigger
= Qnil
;
4966 Frun_hook_with_args (3, args
);
4968 /* Notice if it changed the face of the character we are on. */
4969 handle_face_prop (it
);
4973 /* Deliver a composition display element. The iterator IT is already
4974 filled with composition information (done in
4975 handle_composition_prop). Value is always 1. */
4978 next_element_from_composition (it
)
4981 it
->what
= IT_COMPOSITION
;
4982 it
->position
= (STRINGP (it
->string
)
4983 ? it
->current
.string_pos
4990 /***********************************************************************
4991 Moving an iterator without producing glyphs
4992 ***********************************************************************/
4994 /* Move iterator IT to a specified buffer or X position within one
4995 line on the display without producing glyphs.
4997 OP should be a bit mask including some or all of these bits:
4998 MOVE_TO_X: Stop on reaching x-position TO_X.
4999 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5000 Regardless of OP's value, stop in reaching the end of the display line.
5002 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5003 This means, in particular, that TO_X includes window's horizontal
5006 The return value has several possible values that
5007 say what condition caused the scan to stop:
5009 MOVE_POS_MATCH_OR_ZV
5010 - when TO_POS or ZV was reached.
5013 -when TO_X was reached before TO_POS or ZV were reached.
5016 - when we reached the end of the display area and the line must
5020 - when we reached the end of the display area and the line is
5024 - when we stopped at a line end, i.e. a newline or a CR and selective
5027 static enum move_it_result
5028 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5030 int to_charpos
, to_x
, op
;
5032 enum move_it_result result
= MOVE_UNDEFINED
;
5033 struct glyph_row
*saved_glyph_row
;
5035 /* Don't produce glyphs in produce_glyphs. */
5036 saved_glyph_row
= it
->glyph_row
;
5037 it
->glyph_row
= NULL
;
5041 int x
, i
, ascent
= 0, descent
= 0;
5043 /* Stop when ZV or TO_CHARPOS reached. */
5044 if (!get_next_display_element (it
)
5045 || ((op
& MOVE_TO_POS
) != 0
5046 && BUFFERP (it
->object
)
5047 && IT_CHARPOS (*it
) >= to_charpos
))
5049 result
= MOVE_POS_MATCH_OR_ZV
;
5053 /* The call to produce_glyphs will get the metrics of the
5054 display element IT is loaded with. We record in x the
5055 x-position before this display element in case it does not
5059 /* Remember the line height so far in case the next element doesn't
5061 if (!it
->truncate_lines_p
)
5063 ascent
= it
->max_ascent
;
5064 descent
= it
->max_descent
;
5067 PRODUCE_GLYPHS (it
);
5069 if (it
->area
!= TEXT_AREA
)
5071 set_iterator_to_next (it
, 1);
5075 /* The number of glyphs we get back in IT->nglyphs will normally
5076 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5077 character on a terminal frame, or (iii) a line end. For the
5078 second case, IT->nglyphs - 1 padding glyphs will be present
5079 (on X frames, there is only one glyph produced for a
5080 composite character.
5082 The behavior implemented below means, for continuation lines,
5083 that as many spaces of a TAB as fit on the current line are
5084 displayed there. For terminal frames, as many glyphs of a
5085 multi-glyph character are displayed in the current line, too.
5086 This is what the old redisplay code did, and we keep it that
5087 way. Under X, the whole shape of a complex character must
5088 fit on the line or it will be completely displayed in the
5091 Note that both for tabs and padding glyphs, all glyphs have
5095 /* More than one glyph or glyph doesn't fit on line. All
5096 glyphs have the same width. */
5097 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5100 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5102 new_x
= x
+ single_glyph_width
;
5104 /* We want to leave anything reaching TO_X to the caller. */
5105 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5108 result
= MOVE_X_REACHED
;
5111 else if (/* Lines are continued. */
5112 !it
->truncate_lines_p
5113 && (/* And glyph doesn't fit on the line. */
5114 new_x
> it
->last_visible_x
5115 /* Or it fits exactly and we're on a window
5117 || (new_x
== it
->last_visible_x
5118 && FRAME_WINDOW_P (it
->f
))))
5120 if (/* IT->hpos == 0 means the very first glyph
5121 doesn't fit on the line, e.g. a wide image. */
5123 || (new_x
== it
->last_visible_x
5124 && FRAME_WINDOW_P (it
->f
)))
5127 it
->current_x
= new_x
;
5128 if (i
== it
->nglyphs
- 1)
5129 set_iterator_to_next (it
, 1);
5134 it
->max_ascent
= ascent
;
5135 it
->max_descent
= descent
;
5138 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5140 result
= MOVE_LINE_CONTINUED
;
5143 else if (new_x
> it
->first_visible_x
)
5145 /* Glyph is visible. Increment number of glyphs that
5146 would be displayed. */
5151 /* Glyph is completely off the left margin of the display
5152 area. Nothing to do. */
5156 if (result
!= MOVE_UNDEFINED
)
5159 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5161 /* Stop when TO_X specified and reached. This check is
5162 necessary here because of lines consisting of a line end,
5163 only. The line end will not produce any glyphs and we
5164 would never get MOVE_X_REACHED. */
5165 xassert (it
->nglyphs
== 0);
5166 result
= MOVE_X_REACHED
;
5170 /* Is this a line end? If yes, we're done. */
5171 if (ITERATOR_AT_END_OF_LINE_P (it
))
5173 result
= MOVE_NEWLINE_OR_CR
;
5177 /* The current display element has been consumed. Advance
5179 set_iterator_to_next (it
, 1);
5181 /* Stop if lines are truncated and IT's current x-position is
5182 past the right edge of the window now. */
5183 if (it
->truncate_lines_p
5184 && it
->current_x
>= it
->last_visible_x
)
5186 result
= MOVE_LINE_TRUNCATED
;
5191 /* Restore the iterator settings altered at the beginning of this
5193 it
->glyph_row
= saved_glyph_row
;
5198 /* Move IT forward until it satisfies one or more of the criteria in
5199 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5201 OP is a bit-mask that specifies where to stop, and in particular,
5202 which of those four position arguments makes a difference. See the
5203 description of enum move_operation_enum.
5205 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5206 screen line, this function will set IT to the next position >
5210 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5212 int to_charpos
, to_x
, to_y
, to_vpos
;
5215 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5221 if (op
& MOVE_TO_VPOS
)
5223 /* If no TO_CHARPOS and no TO_X specified, stop at the
5224 start of the line TO_VPOS. */
5225 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5227 if (it
->vpos
== to_vpos
)
5233 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5237 /* TO_VPOS >= 0 means stop at TO_X in the line at
5238 TO_VPOS, or at TO_POS, whichever comes first. */
5239 if (it
->vpos
== to_vpos
)
5245 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5247 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5252 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5254 /* We have reached TO_X but not in the line we want. */
5255 skip
= move_it_in_display_line_to (it
, to_charpos
,
5257 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5265 else if (op
& MOVE_TO_Y
)
5267 struct it it_backup
;
5269 /* TO_Y specified means stop at TO_X in the line containing
5270 TO_Y---or at TO_CHARPOS if this is reached first. The
5271 problem is that we can't really tell whether the line
5272 contains TO_Y before we have completely scanned it, and
5273 this may skip past TO_X. What we do is to first scan to
5276 If TO_X is not specified, use a TO_X of zero. The reason
5277 is to make the outcome of this function more predictable.
5278 If we didn't use TO_X == 0, we would stop at the end of
5279 the line which is probably not what a caller would expect
5281 skip
= move_it_in_display_line_to (it
, to_charpos
,
5285 | (op
& MOVE_TO_POS
)));
5287 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5288 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5294 /* If TO_X was reached, we would like to know whether TO_Y
5295 is in the line. This can only be said if we know the
5296 total line height which requires us to scan the rest of
5298 if (skip
== MOVE_X_REACHED
)
5301 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5302 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5304 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5307 /* Now, decide whether TO_Y is in this line. */
5308 line_height
= it
->max_ascent
+ it
->max_descent
;
5309 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5311 if (to_y
>= it
->current_y
5312 && to_y
< it
->current_y
+ line_height
)
5314 if (skip
== MOVE_X_REACHED
)
5315 /* If TO_Y is in this line and TO_X was reached above,
5316 we scanned too far. We have to restore IT's settings
5317 to the ones before skipping. */
5321 else if (skip
== MOVE_X_REACHED
)
5324 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5332 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5336 case MOVE_POS_MATCH_OR_ZV
:
5340 case MOVE_NEWLINE_OR_CR
:
5341 set_iterator_to_next (it
, 1);
5342 it
->continuation_lines_width
= 0;
5345 case MOVE_LINE_TRUNCATED
:
5346 it
->continuation_lines_width
= 0;
5347 reseat_at_next_visible_line_start (it
, 0);
5348 if ((op
& MOVE_TO_POS
) != 0
5349 && IT_CHARPOS (*it
) > to_charpos
)
5356 case MOVE_LINE_CONTINUED
:
5357 it
->continuation_lines_width
+= it
->current_x
;
5364 /* Reset/increment for the next run. */
5365 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5366 it
->current_x
= it
->hpos
= 0;
5367 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5369 last_height
= it
->max_ascent
+ it
->max_descent
;
5370 last_max_ascent
= it
->max_ascent
;
5371 it
->max_ascent
= it
->max_descent
= 0;
5376 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5380 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5382 If DY > 0, move IT backward at least that many pixels. DY = 0
5383 means move IT backward to the preceding line start or BEGV. This
5384 function may move over more than DY pixels if IT->current_y - DY
5385 ends up in the middle of a line; in this case IT->current_y will be
5386 set to the top of the line moved to. */
5389 move_it_vertically_backward (it
, dy
)
5395 int start_pos
= IT_CHARPOS (*it
);
5399 /* Estimate how many newlines we must move back. */
5400 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5402 /* Set the iterator's position that many lines back. */
5403 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5404 back_to_previous_visible_line_start (it
);
5406 /* Reseat the iterator here. When moving backward, we don't want
5407 reseat to skip forward over invisible text, set up the iterator
5408 to deliver from overlay strings at the new position etc. So,
5409 use reseat_1 here. */
5410 reseat_1 (it
, it
->current
.pos
, 1);
5412 /* We are now surely at a line start. */
5413 it
->current_x
= it
->hpos
= 0;
5415 /* Move forward and see what y-distance we moved. First move to the
5416 start of the next line so that we get its height. We need this
5417 height to be able to tell whether we reached the specified
5420 it2
.max_ascent
= it2
.max_descent
= 0;
5421 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5422 MOVE_TO_POS
| MOVE_TO_VPOS
);
5423 xassert (IT_CHARPOS (*it
) >= BEGV
);
5426 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5427 xassert (IT_CHARPOS (*it
) >= BEGV
);
5428 h
= it2
.current_y
- it
->current_y
;
5429 nlines
= it2
.vpos
- it
->vpos
;
5431 /* Correct IT's y and vpos position. */
5437 /* DY == 0 means move to the start of the screen line. The
5438 value of nlines is > 0 if continuation lines were involved. */
5440 move_it_by_lines (it
, nlines
, 1);
5441 xassert (IT_CHARPOS (*it
) <= start_pos
);
5445 /* The y-position we try to reach. Note that h has been
5446 subtracted in front of the if-statement. */
5447 int target_y
= it
->current_y
+ h
- dy
;
5448 int y0
= it3
.current_y
;
5449 int y1
= line_bottom_y (&it3
);
5450 int line_height
= y1
- y0
;
5452 /* If we did not reach target_y, try to move further backward if
5453 we can. If we moved too far backward, try to move forward. */
5454 if (target_y
< it
->current_y
5455 /* This is heuristic. In a window that's 3 lines high, with
5456 a line height of 13 pixels each, recentering with point
5457 on the bottom line will try to move -39/2 = 19 pixels
5458 backward. Try to avoid moving into the first line. */
5459 && it
->current_y
- target_y
> line_height
/ 3 * 2
5460 && IT_CHARPOS (*it
) > BEGV
)
5462 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5463 target_y
- it
->current_y
));
5464 move_it_vertically (it
, target_y
- it
->current_y
);
5465 xassert (IT_CHARPOS (*it
) >= BEGV
);
5467 else if (target_y
>= it
->current_y
+ line_height
5468 && IT_CHARPOS (*it
) < ZV
)
5470 /* Should move forward by at least one line, maybe more.
5472 Note: Calling move_it_by_lines can be expensive on
5473 terminal frames, where compute_motion is used (via
5474 vmotion) to do the job, when there are very long lines
5475 and truncate-lines is nil. That's the reason for
5476 treating terminal frames specially here. */
5478 if (!FRAME_WINDOW_P (it
->f
))
5479 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5484 move_it_by_lines (it
, 1, 1);
5486 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5489 xassert (IT_CHARPOS (*it
) >= BEGV
);
5495 /* Move IT by a specified amount of pixel lines DY. DY negative means
5496 move backwards. DY = 0 means move to start of screen line. At the
5497 end, IT will be on the start of a screen line. */
5500 move_it_vertically (it
, dy
)
5505 move_it_vertically_backward (it
, -dy
);
5508 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5509 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5510 MOVE_TO_POS
| MOVE_TO_Y
);
5511 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5513 /* If buffer ends in ZV without a newline, move to the start of
5514 the line to satisfy the post-condition. */
5515 if (IT_CHARPOS (*it
) == ZV
5516 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5517 move_it_by_lines (it
, 0, 0);
5522 /* Move iterator IT past the end of the text line it is in. */
5525 move_it_past_eol (it
)
5528 enum move_it_result rc
;
5530 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5531 if (rc
== MOVE_NEWLINE_OR_CR
)
5532 set_iterator_to_next (it
, 0);
5536 #if 0 /* Currently not used. */
5538 /* Return non-zero if some text between buffer positions START_CHARPOS
5539 and END_CHARPOS is invisible. IT->window is the window for text
5543 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5545 int start_charpos
, end_charpos
;
5547 Lisp_Object prop
, limit
;
5548 int invisible_found_p
;
5550 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5552 /* Is text at START invisible? */
5553 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5555 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5556 invisible_found_p
= 1;
5559 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5561 make_number (end_charpos
));
5562 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5565 return invisible_found_p
;
5571 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5572 negative means move up. DVPOS == 0 means move to the start of the
5573 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5574 NEED_Y_P is zero, IT->current_y will be left unchanged.
5576 Further optimization ideas: If we would know that IT->f doesn't use
5577 a face with proportional font, we could be faster for
5578 truncate-lines nil. */
5581 move_it_by_lines (it
, dvpos
, need_y_p
)
5583 int dvpos
, need_y_p
;
5585 struct position pos
;
5587 if (!FRAME_WINDOW_P (it
->f
))
5589 struct text_pos textpos
;
5591 /* We can use vmotion on frames without proportional fonts. */
5592 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5593 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5594 reseat (it
, textpos
, 1);
5595 it
->vpos
+= pos
.vpos
;
5596 it
->current_y
+= pos
.vpos
;
5598 else if (dvpos
== 0)
5600 /* DVPOS == 0 means move to the start of the screen line. */
5601 move_it_vertically_backward (it
, 0);
5602 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5605 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5609 int start_charpos
, i
;
5611 /* Start at the beginning of the screen line containing IT's
5613 move_it_vertically_backward (it
, 0);
5615 /* Go back -DVPOS visible lines and reseat the iterator there. */
5616 start_charpos
= IT_CHARPOS (*it
);
5617 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5618 back_to_previous_visible_line_start (it
);
5619 reseat (it
, it
->current
.pos
, 1);
5620 it
->current_x
= it
->hpos
= 0;
5622 /* Above call may have moved too far if continuation lines
5623 are involved. Scan forward and see if it did. */
5625 it2
.vpos
= it2
.current_y
= 0;
5626 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5627 it
->vpos
-= it2
.vpos
;
5628 it
->current_y
-= it2
.current_y
;
5629 it
->current_x
= it
->hpos
= 0;
5631 /* If we moved too far, move IT some lines forward. */
5632 if (it2
.vpos
> -dvpos
)
5634 int delta
= it2
.vpos
+ dvpos
;
5635 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5642 /***********************************************************************
5644 ***********************************************************************/
5647 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5651 add_to_log (format
, arg1
, arg2
)
5653 Lisp_Object arg1
, arg2
;
5655 Lisp_Object args
[3];
5656 Lisp_Object msg
, fmt
;
5659 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5661 /* Do nothing if called asynchronously. Inserting text into
5662 a buffer may call after-change-functions and alike and
5663 that would means running Lisp asynchronously. */
5664 if (handling_signal
)
5668 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5670 args
[0] = fmt
= build_string (format
);
5673 msg
= Fformat (3, args
);
5675 len
= SBYTES (msg
) + 1;
5676 buffer
= (char *) alloca (len
);
5677 bcopy (SDATA (msg
), buffer
, len
);
5679 message_dolog (buffer
, len
- 1, 1, 0);
5684 /* Output a newline in the *Messages* buffer if "needs" one. */
5687 message_log_maybe_newline ()
5689 if (message_log_need_newline
)
5690 message_dolog ("", 0, 1, 0);
5694 /* Add a string M of length NBYTES to the message log, optionally
5695 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5696 nonzero, means interpret the contents of M as multibyte. This
5697 function calls low-level routines in order to bypass text property
5698 hooks, etc. which might not be safe to run. */
5701 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5703 int nbytes
, nlflag
, multibyte
;
5705 if (!NILP (Vmemory_full
))
5708 if (!NILP (Vmessage_log_max
))
5710 struct buffer
*oldbuf
;
5711 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5712 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5713 int point_at_end
= 0;
5715 Lisp_Object old_deactivate_mark
, tem
;
5716 struct gcpro gcpro1
;
5718 old_deactivate_mark
= Vdeactivate_mark
;
5719 oldbuf
= current_buffer
;
5720 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5721 current_buffer
->undo_list
= Qt
;
5723 oldpoint
= message_dolog_marker1
;
5724 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
5725 oldbegv
= message_dolog_marker2
;
5726 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
5727 oldzv
= message_dolog_marker3
;
5728 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
5729 GCPRO1 (old_deactivate_mark
);
5737 BEGV_BYTE
= BEG_BYTE
;
5740 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5742 /* Insert the string--maybe converting multibyte to single byte
5743 or vice versa, so that all the text fits the buffer. */
5745 && NILP (current_buffer
->enable_multibyte_characters
))
5747 int i
, c
, char_bytes
;
5748 unsigned char work
[1];
5750 /* Convert a multibyte string to single-byte
5751 for the *Message* buffer. */
5752 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5754 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5755 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5757 : multibyte_char_to_unibyte (c
, Qnil
));
5758 insert_1_both (work
, 1, 1, 1, 0, 0);
5761 else if (! multibyte
5762 && ! NILP (current_buffer
->enable_multibyte_characters
))
5764 int i
, c
, char_bytes
;
5765 unsigned char *msg
= (unsigned char *) m
;
5766 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5767 /* Convert a single-byte string to multibyte
5768 for the *Message* buffer. */
5769 for (i
= 0; i
< nbytes
; i
++)
5771 c
= unibyte_char_to_multibyte (msg
[i
]);
5772 char_bytes
= CHAR_STRING (c
, str
);
5773 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5777 insert_1 (m
, nbytes
, 1, 0, 0);
5781 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5782 insert_1 ("\n", 1, 1, 0, 0);
5784 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5786 this_bol_byte
= PT_BYTE
;
5788 /* See if this line duplicates the previous one.
5789 If so, combine duplicates. */
5792 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5794 prev_bol_byte
= PT_BYTE
;
5796 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5797 this_bol
, this_bol_byte
);
5800 del_range_both (prev_bol
, prev_bol_byte
,
5801 this_bol
, this_bol_byte
, 0);
5807 /* If you change this format, don't forget to also
5808 change message_log_check_duplicate. */
5809 sprintf (dupstr
, " [%d times]", dup
);
5810 duplen
= strlen (dupstr
);
5811 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5812 insert_1 (dupstr
, duplen
, 1, 0, 1);
5817 /* If we have more than the desired maximum number of lines
5818 in the *Messages* buffer now, delete the oldest ones.
5819 This is safe because we don't have undo in this buffer. */
5821 if (NATNUMP (Vmessage_log_max
))
5823 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5824 -XFASTINT (Vmessage_log_max
) - 1, 0);
5825 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5828 BEGV
= XMARKER (oldbegv
)->charpos
;
5829 BEGV_BYTE
= marker_byte_position (oldbegv
);
5838 ZV
= XMARKER (oldzv
)->charpos
;
5839 ZV_BYTE
= marker_byte_position (oldzv
);
5843 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5845 /* We can't do Fgoto_char (oldpoint) because it will run some
5847 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5848 XMARKER (oldpoint
)->bytepos
);
5851 unchain_marker (oldpoint
);
5852 unchain_marker (oldbegv
);
5853 unchain_marker (oldzv
);
5855 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5856 set_buffer_internal (oldbuf
);
5858 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5859 message_log_need_newline
= !nlflag
;
5860 Vdeactivate_mark
= old_deactivate_mark
;
5865 /* We are at the end of the buffer after just having inserted a newline.
5866 (Note: We depend on the fact we won't be crossing the gap.)
5867 Check to see if the most recent message looks a lot like the previous one.
5868 Return 0 if different, 1 if the new one should just replace it, or a
5869 value N > 1 if we should also append " [N times]". */
5872 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5873 int prev_bol
, this_bol
;
5874 int prev_bol_byte
, this_bol_byte
;
5877 int len
= Z_BYTE
- 1 - this_bol_byte
;
5879 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5880 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5882 for (i
= 0; i
< len
; i
++)
5884 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5892 if (*p1
++ == ' ' && *p1
++ == '[')
5895 while (*p1
>= '0' && *p1
<= '9')
5896 n
= n
* 10 + *p1
++ - '0';
5897 if (strncmp (p1
, " times]\n", 8) == 0)
5904 /* Display an echo area message M with a specified length of NBYTES
5905 bytes. The string may include null characters. If M is 0, clear
5906 out any existing message, and let the mini-buffer text show
5909 The buffer M must continue to exist until after the echo area gets
5910 cleared or some other message gets displayed there. This means do
5911 not pass text that is stored in a Lisp string; do not pass text in
5912 a buffer that was alloca'd. */
5915 message2 (m
, nbytes
, multibyte
)
5920 /* First flush out any partial line written with print. */
5921 message_log_maybe_newline ();
5923 message_dolog (m
, nbytes
, 1, multibyte
);
5924 message2_nolog (m
, nbytes
, multibyte
);
5928 /* The non-logging counterpart of message2. */
5931 message2_nolog (m
, nbytes
, multibyte
)
5935 struct frame
*sf
= SELECTED_FRAME ();
5936 message_enable_multibyte
= multibyte
;
5940 if (noninteractive_need_newline
)
5941 putc ('\n', stderr
);
5942 noninteractive_need_newline
= 0;
5944 fwrite (m
, nbytes
, 1, stderr
);
5945 if (cursor_in_echo_area
== 0)
5946 fprintf (stderr
, "\n");
5949 /* A null message buffer means that the frame hasn't really been
5950 initialized yet. Error messages get reported properly by
5951 cmd_error, so this must be just an informative message; toss it. */
5952 else if (INTERACTIVE
5953 && sf
->glyphs_initialized_p
5954 && FRAME_MESSAGE_BUF (sf
))
5956 Lisp_Object mini_window
;
5959 /* Get the frame containing the mini-buffer
5960 that the selected frame is using. */
5961 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5962 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5964 FRAME_SAMPLE_VISIBILITY (f
);
5965 if (FRAME_VISIBLE_P (sf
)
5966 && ! FRAME_VISIBLE_P (f
))
5967 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5971 set_message (m
, Qnil
, nbytes
, multibyte
);
5972 if (minibuffer_auto_raise
)
5973 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5976 clear_message (1, 1);
5978 do_pending_window_change (0);
5979 echo_area_display (1);
5980 do_pending_window_change (0);
5981 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5982 (*frame_up_to_date_hook
) (f
);
5987 /* Display an echo area message M with a specified length of NBYTES
5988 bytes. The string may include null characters. If M is not a
5989 string, clear out any existing message, and let the mini-buffer
5990 text show through. */
5993 message3 (m
, nbytes
, multibyte
)
5998 struct gcpro gcpro1
;
6002 /* First flush out any partial line written with print. */
6003 message_log_maybe_newline ();
6005 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6006 message3_nolog (m
, nbytes
, multibyte
);
6012 /* The non-logging version of message3. */
6015 message3_nolog (m
, nbytes
, multibyte
)
6017 int nbytes
, multibyte
;
6019 struct frame
*sf
= SELECTED_FRAME ();
6020 message_enable_multibyte
= multibyte
;
6024 if (noninteractive_need_newline
)
6025 putc ('\n', stderr
);
6026 noninteractive_need_newline
= 0;
6028 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6029 if (cursor_in_echo_area
== 0)
6030 fprintf (stderr
, "\n");
6033 /* A null message buffer means that the frame hasn't really been
6034 initialized yet. Error messages get reported properly by
6035 cmd_error, so this must be just an informative message; toss it. */
6036 else if (INTERACTIVE
6037 && sf
->glyphs_initialized_p
6038 && FRAME_MESSAGE_BUF (sf
))
6040 Lisp_Object mini_window
;
6044 /* Get the frame containing the mini-buffer
6045 that the selected frame is using. */
6046 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6047 frame
= XWINDOW (mini_window
)->frame
;
6050 FRAME_SAMPLE_VISIBILITY (f
);
6051 if (FRAME_VISIBLE_P (sf
)
6052 && !FRAME_VISIBLE_P (f
))
6053 Fmake_frame_visible (frame
);
6055 if (STRINGP (m
) && SCHARS (m
) > 0)
6057 set_message (NULL
, m
, nbytes
, multibyte
);
6058 if (minibuffer_auto_raise
)
6059 Fraise_frame (frame
);
6062 clear_message (1, 1);
6064 do_pending_window_change (0);
6065 echo_area_display (1);
6066 do_pending_window_change (0);
6067 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6068 (*frame_up_to_date_hook
) (f
);
6073 /* Display a null-terminated echo area message M. If M is 0, clear
6074 out any existing message, and let the mini-buffer text show through.
6076 The buffer M must continue to exist until after the echo area gets
6077 cleared or some other message gets displayed there. Do not pass
6078 text that is stored in a Lisp string. Do not pass text in a buffer
6079 that was alloca'd. */
6085 message2 (m
, (m
? strlen (m
) : 0), 0);
6089 /* The non-logging counterpart of message1. */
6095 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6098 /* Display a message M which contains a single %s
6099 which gets replaced with STRING. */
6102 message_with_string (m
, string
, log
)
6107 CHECK_STRING (string
);
6113 if (noninteractive_need_newline
)
6114 putc ('\n', stderr
);
6115 noninteractive_need_newline
= 0;
6116 fprintf (stderr
, m
, SDATA (string
));
6117 if (cursor_in_echo_area
== 0)
6118 fprintf (stderr
, "\n");
6122 else if (INTERACTIVE
)
6124 /* The frame whose minibuffer we're going to display the message on.
6125 It may be larger than the selected frame, so we need
6126 to use its buffer, not the selected frame's buffer. */
6127 Lisp_Object mini_window
;
6128 struct frame
*f
, *sf
= SELECTED_FRAME ();
6130 /* Get the frame containing the minibuffer
6131 that the selected frame is using. */
6132 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6133 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6135 /* A null message buffer means that the frame hasn't really been
6136 initialized yet. Error messages get reported properly by
6137 cmd_error, so this must be just an informative message; toss it. */
6138 if (FRAME_MESSAGE_BUF (f
))
6140 Lisp_Object args
[2], message
;
6141 struct gcpro gcpro1
, gcpro2
;
6143 args
[0] = build_string (m
);
6144 args
[1] = message
= string
;
6145 GCPRO2 (args
[0], message
);
6148 message
= Fformat (2, args
);
6151 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6153 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6157 /* Print should start at the beginning of the message
6158 buffer next time. */
6159 message_buf_print
= 0;
6165 /* Dump an informative message to the minibuf. If M is 0, clear out
6166 any existing message, and let the mini-buffer text show through. */
6170 message (m
, a1
, a2
, a3
)
6172 EMACS_INT a1
, a2
, a3
;
6178 if (noninteractive_need_newline
)
6179 putc ('\n', stderr
);
6180 noninteractive_need_newline
= 0;
6181 fprintf (stderr
, m
, a1
, a2
, a3
);
6182 if (cursor_in_echo_area
== 0)
6183 fprintf (stderr
, "\n");
6187 else if (INTERACTIVE
)
6189 /* The frame whose mini-buffer we're going to display the message
6190 on. It may be larger than the selected frame, so we need to
6191 use its buffer, not the selected frame's buffer. */
6192 Lisp_Object mini_window
;
6193 struct frame
*f
, *sf
= SELECTED_FRAME ();
6195 /* Get the frame containing the mini-buffer
6196 that the selected frame is using. */
6197 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6198 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6200 /* A null message buffer means that the frame hasn't really been
6201 initialized yet. Error messages get reported properly by
6202 cmd_error, so this must be just an informative message; toss
6204 if (FRAME_MESSAGE_BUF (f
))
6215 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6216 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6218 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6219 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6221 #endif /* NO_ARG_ARRAY */
6223 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6228 /* Print should start at the beginning of the message
6229 buffer next time. */
6230 message_buf_print
= 0;
6236 /* The non-logging version of message. */
6239 message_nolog (m
, a1
, a2
, a3
)
6241 EMACS_INT a1
, a2
, a3
;
6243 Lisp_Object old_log_max
;
6244 old_log_max
= Vmessage_log_max
;
6245 Vmessage_log_max
= Qnil
;
6246 message (m
, a1
, a2
, a3
);
6247 Vmessage_log_max
= old_log_max
;
6251 /* Display the current message in the current mini-buffer. This is
6252 only called from error handlers in process.c, and is not time
6258 if (!NILP (echo_area_buffer
[0]))
6261 string
= Fcurrent_message ();
6262 message3 (string
, SBYTES (string
),
6263 !NILP (current_buffer
->enable_multibyte_characters
));
6268 /* Make sure echo area buffers in `echo_buffers' are live.
6269 If they aren't, make new ones. */
6272 ensure_echo_area_buffers ()
6276 for (i
= 0; i
< 2; ++i
)
6277 if (!BUFFERP (echo_buffer
[i
])
6278 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6281 Lisp_Object old_buffer
;
6284 old_buffer
= echo_buffer
[i
];
6285 sprintf (name
, " *Echo Area %d*", i
);
6286 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6287 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6289 for (j
= 0; j
< 2; ++j
)
6290 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6291 echo_area_buffer
[j
] = echo_buffer
[i
];
6296 /* Call FN with args A1..A4 with either the current or last displayed
6297 echo_area_buffer as current buffer.
6299 WHICH zero means use the current message buffer
6300 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6301 from echo_buffer[] and clear it.
6303 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6304 suitable buffer from echo_buffer[] and clear it.
6306 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6307 that the current message becomes the last displayed one, make
6308 choose a suitable buffer for echo_area_buffer[0], and clear it.
6310 Value is what FN returns. */
6313 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6316 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6322 int this_one
, the_other
, clear_buffer_p
, rc
;
6323 int count
= SPECPDL_INDEX ();
6325 /* If buffers aren't live, make new ones. */
6326 ensure_echo_area_buffers ();
6331 this_one
= 0, the_other
= 1;
6333 this_one
= 1, the_other
= 0;
6336 this_one
= 0, the_other
= 1;
6339 /* We need a fresh one in case the current echo buffer equals
6340 the one containing the last displayed echo area message. */
6341 if (!NILP (echo_area_buffer
[this_one
])
6342 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6343 echo_area_buffer
[this_one
] = Qnil
;
6346 /* Choose a suitable buffer from echo_buffer[] is we don't
6348 if (NILP (echo_area_buffer
[this_one
]))
6350 echo_area_buffer
[this_one
]
6351 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6352 ? echo_buffer
[the_other
]
6353 : echo_buffer
[this_one
]);
6357 buffer
= echo_area_buffer
[this_one
];
6359 /* Don't get confused by reusing the buffer used for echoing
6360 for a different purpose. */
6361 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6364 record_unwind_protect (unwind_with_echo_area_buffer
,
6365 with_echo_area_buffer_unwind_data (w
));
6367 /* Make the echo area buffer current. Note that for display
6368 purposes, it is not necessary that the displayed window's buffer
6369 == current_buffer, except for text property lookup. So, let's
6370 only set that buffer temporarily here without doing a full
6371 Fset_window_buffer. We must also change w->pointm, though,
6372 because otherwise an assertions in unshow_buffer fails, and Emacs
6374 set_buffer_internal_1 (XBUFFER (buffer
));
6378 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6381 current_buffer
->undo_list
= Qt
;
6382 current_buffer
->read_only
= Qnil
;
6383 specbind (Qinhibit_read_only
, Qt
);
6384 specbind (Qinhibit_modification_hooks
, Qt
);
6386 if (clear_buffer_p
&& Z
> BEG
)
6389 xassert (BEGV
>= BEG
);
6390 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6392 rc
= fn (a1
, a2
, a3
, a4
);
6394 xassert (BEGV
>= BEG
);
6395 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6397 unbind_to (count
, Qnil
);
6402 /* Save state that should be preserved around the call to the function
6403 FN called in with_echo_area_buffer. */
6406 with_echo_area_buffer_unwind_data (w
)
6412 /* Reduce consing by keeping one vector in
6413 Vwith_echo_area_save_vector. */
6414 vector
= Vwith_echo_area_save_vector
;
6415 Vwith_echo_area_save_vector
= Qnil
;
6418 vector
= Fmake_vector (make_number (7), Qnil
);
6420 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6421 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6422 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6426 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6427 AREF (vector
, i
) = w
->buffer
; ++i
;
6428 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6429 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6434 for (; i
< end
; ++i
)
6435 AREF (vector
, i
) = Qnil
;
6438 xassert (i
== ASIZE (vector
));
6443 /* Restore global state from VECTOR which was created by
6444 with_echo_area_buffer_unwind_data. */
6447 unwind_with_echo_area_buffer (vector
)
6450 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6451 Vdeactivate_mark
= AREF (vector
, 1);
6452 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6454 if (WINDOWP (AREF (vector
, 3)))
6457 Lisp_Object buffer
, charpos
, bytepos
;
6459 w
= XWINDOW (AREF (vector
, 3));
6460 buffer
= AREF (vector
, 4);
6461 charpos
= AREF (vector
, 5);
6462 bytepos
= AREF (vector
, 6);
6465 set_marker_both (w
->pointm
, buffer
,
6466 XFASTINT (charpos
), XFASTINT (bytepos
));
6469 Vwith_echo_area_save_vector
= vector
;
6474 /* Set up the echo area for use by print functions. MULTIBYTE_P
6475 non-zero means we will print multibyte. */
6478 setup_echo_area_for_printing (multibyte_p
)
6481 ensure_echo_area_buffers ();
6483 if (!message_buf_print
)
6485 /* A message has been output since the last time we printed.
6486 Choose a fresh echo area buffer. */
6487 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6488 echo_area_buffer
[0] = echo_buffer
[1];
6490 echo_area_buffer
[0] = echo_buffer
[0];
6492 /* Switch to that buffer and clear it. */
6493 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6494 current_buffer
->truncate_lines
= Qnil
;
6498 int count
= SPECPDL_INDEX ();
6499 specbind (Qinhibit_read_only
, Qt
);
6500 /* Note that undo recording is always disabled. */
6502 unbind_to (count
, Qnil
);
6504 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6506 /* Set up the buffer for the multibyteness we need. */
6508 != !NILP (current_buffer
->enable_multibyte_characters
))
6509 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6511 /* Raise the frame containing the echo area. */
6512 if (minibuffer_auto_raise
)
6514 struct frame
*sf
= SELECTED_FRAME ();
6515 Lisp_Object mini_window
;
6516 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6517 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6520 message_log_maybe_newline ();
6521 message_buf_print
= 1;
6525 if (NILP (echo_area_buffer
[0]))
6527 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6528 echo_area_buffer
[0] = echo_buffer
[1];
6530 echo_area_buffer
[0] = echo_buffer
[0];
6533 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6535 /* Someone switched buffers between print requests. */
6536 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6537 current_buffer
->truncate_lines
= Qnil
;
6543 /* Display an echo area message in window W. Value is non-zero if W's
6544 height is changed. If display_last_displayed_message_p is
6545 non-zero, display the message that was last displayed, otherwise
6546 display the current message. */
6549 display_echo_area (w
)
6552 int i
, no_message_p
, window_height_changed_p
, count
;
6554 /* Temporarily disable garbage collections while displaying the echo
6555 area. This is done because a GC can print a message itself.
6556 That message would modify the echo area buffer's contents while a
6557 redisplay of the buffer is going on, and seriously confuse
6559 count
= inhibit_garbage_collection ();
6561 /* If there is no message, we must call display_echo_area_1
6562 nevertheless because it resizes the window. But we will have to
6563 reset the echo_area_buffer in question to nil at the end because
6564 with_echo_area_buffer will sets it to an empty buffer. */
6565 i
= display_last_displayed_message_p
? 1 : 0;
6566 no_message_p
= NILP (echo_area_buffer
[i
]);
6568 window_height_changed_p
6569 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6570 display_echo_area_1
,
6571 (EMACS_INT
) w
, Qnil
, 0, 0);
6574 echo_area_buffer
[i
] = Qnil
;
6576 unbind_to (count
, Qnil
);
6577 return window_height_changed_p
;
6581 /* Helper for display_echo_area. Display the current buffer which
6582 contains the current echo area message in window W, a mini-window,
6583 a pointer to which is passed in A1. A2..A4 are currently not used.
6584 Change the height of W so that all of the message is displayed.
6585 Value is non-zero if height of W was changed. */
6588 display_echo_area_1 (a1
, a2
, a3
, a4
)
6593 struct window
*w
= (struct window
*) a1
;
6595 struct text_pos start
;
6596 int window_height_changed_p
= 0;
6598 /* Do this before displaying, so that we have a large enough glyph
6599 matrix for the display. */
6600 window_height_changed_p
= resize_mini_window (w
, 0);
6603 clear_glyph_matrix (w
->desired_matrix
);
6604 XSETWINDOW (window
, w
);
6605 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6606 try_window (window
, start
);
6608 return window_height_changed_p
;
6612 /* Resize the echo area window to exactly the size needed for the
6613 currently displayed message, if there is one. If a mini-buffer
6614 is active, don't shrink it. */
6617 resize_echo_area_exactly ()
6619 if (BUFFERP (echo_area_buffer
[0])
6620 && WINDOWP (echo_area_window
))
6622 struct window
*w
= XWINDOW (echo_area_window
);
6624 Lisp_Object resize_exactly
;
6626 if (minibuf_level
== 0)
6627 resize_exactly
= Qt
;
6629 resize_exactly
= Qnil
;
6631 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6632 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6635 ++windows_or_buffers_changed
;
6636 ++update_mode_lines
;
6637 redisplay_internal (0);
6643 /* Callback function for with_echo_area_buffer, when used from
6644 resize_echo_area_exactly. A1 contains a pointer to the window to
6645 resize, EXACTLY non-nil means resize the mini-window exactly to the
6646 size of the text displayed. A3 and A4 are not used. Value is what
6647 resize_mini_window returns. */
6650 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6652 Lisp_Object exactly
;
6655 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6659 /* Resize mini-window W to fit the size of its contents. EXACT:P
6660 means size the window exactly to the size needed. Otherwise, it's
6661 only enlarged until W's buffer is empty. Value is non-zero if
6662 the window height has been changed. */
6665 resize_mini_window (w
, exact_p
)
6669 struct frame
*f
= XFRAME (w
->frame
);
6670 int window_height_changed_p
= 0;
6672 xassert (MINI_WINDOW_P (w
));
6674 /* Don't resize windows while redisplaying a window; it would
6675 confuse redisplay functions when the size of the window they are
6676 displaying changes from under them. Such a resizing can happen,
6677 for instance, when which-func prints a long message while
6678 we are running fontification-functions. We're running these
6679 functions with safe_call which binds inhibit-redisplay to t. */
6680 if (!NILP (Vinhibit_redisplay
))
6683 /* Nil means don't try to resize. */
6684 if (NILP (Vresize_mini_windows
)
6685 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6688 if (!FRAME_MINIBUF_ONLY_P (f
))
6691 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6692 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6693 int height
, max_height
;
6694 int unit
= CANON_Y_UNIT (f
);
6695 struct text_pos start
;
6696 struct buffer
*old_current_buffer
= NULL
;
6698 if (current_buffer
!= XBUFFER (w
->buffer
))
6700 old_current_buffer
= current_buffer
;
6701 set_buffer_internal (XBUFFER (w
->buffer
));
6704 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6706 /* Compute the max. number of lines specified by the user. */
6707 if (FLOATP (Vmax_mini_window_height
))
6708 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6709 else if (INTEGERP (Vmax_mini_window_height
))
6710 max_height
= XINT (Vmax_mini_window_height
);
6712 max_height
= total_height
/ 4;
6714 /* Correct that max. height if it's bogus. */
6715 max_height
= max (1, max_height
);
6716 max_height
= min (total_height
, max_height
);
6718 /* Find out the height of the text in the window. */
6719 if (it
.truncate_lines_p
)
6724 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6725 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6726 height
= it
.current_y
+ last_height
;
6728 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6729 height
-= it
.extra_line_spacing
;
6730 height
= (height
+ unit
- 1) / unit
;
6733 /* Compute a suitable window start. */
6734 if (height
> max_height
)
6736 height
= max_height
;
6737 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6738 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6739 start
= it
.current
.pos
;
6742 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6743 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6745 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6747 /* Let it grow only, until we display an empty message, in which
6748 case the window shrinks again. */
6749 if (height
> XFASTINT (w
->height
))
6751 int old_height
= XFASTINT (w
->height
);
6752 freeze_window_starts (f
, 1);
6753 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6754 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6756 else if (height
< XFASTINT (w
->height
)
6757 && (exact_p
|| BEGV
== ZV
))
6759 int old_height
= XFASTINT (w
->height
);
6760 freeze_window_starts (f
, 0);
6761 shrink_mini_window (w
);
6762 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6767 /* Always resize to exact size needed. */
6768 if (height
> XFASTINT (w
->height
))
6770 int old_height
= XFASTINT (w
->height
);
6771 freeze_window_starts (f
, 1);
6772 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6773 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6775 else if (height
< XFASTINT (w
->height
))
6777 int old_height
= XFASTINT (w
->height
);
6778 freeze_window_starts (f
, 0);
6779 shrink_mini_window (w
);
6783 freeze_window_starts (f
, 1);
6784 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6787 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6791 if (old_current_buffer
)
6792 set_buffer_internal (old_current_buffer
);
6795 return window_height_changed_p
;
6799 /* Value is the current message, a string, or nil if there is no
6807 if (NILP (echo_area_buffer
[0]))
6811 with_echo_area_buffer (0, 0, current_message_1
,
6812 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6814 echo_area_buffer
[0] = Qnil
;
6822 current_message_1 (a1
, a2
, a3
, a4
)
6827 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6830 *msg
= make_buffer_string (BEG
, Z
, 1);
6837 /* Push the current message on Vmessage_stack for later restauration
6838 by restore_message. Value is non-zero if the current message isn't
6839 empty. This is a relatively infrequent operation, so it's not
6840 worth optimizing. */
6846 msg
= current_message ();
6847 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6848 return STRINGP (msg
);
6852 /* Handler for record_unwind_protect calling pop_message. */
6855 push_message_unwind (dummy
)
6863 /* Restore message display from the top of Vmessage_stack. */
6870 xassert (CONSP (Vmessage_stack
));
6871 msg
= XCAR (Vmessage_stack
);
6873 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
6875 message3_nolog (msg
, 0, 0);
6879 /* Pop the top-most entry off Vmessage_stack. */
6884 xassert (CONSP (Vmessage_stack
));
6885 Vmessage_stack
= XCDR (Vmessage_stack
);
6889 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6890 exits. If the stack is not empty, we have a missing pop_message
6894 check_message_stack ()
6896 if (!NILP (Vmessage_stack
))
6901 /* Truncate to NCHARS what will be displayed in the echo area the next
6902 time we display it---but don't redisplay it now. */
6905 truncate_echo_area (nchars
)
6909 echo_area_buffer
[0] = Qnil
;
6910 /* A null message buffer means that the frame hasn't really been
6911 initialized yet. Error messages get reported properly by
6912 cmd_error, so this must be just an informative message; toss it. */
6913 else if (!noninteractive
6915 && !NILP (echo_area_buffer
[0]))
6917 struct frame
*sf
= SELECTED_FRAME ();
6918 if (FRAME_MESSAGE_BUF (sf
))
6919 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6924 /* Helper function for truncate_echo_area. Truncate the current
6925 message to at most NCHARS characters. */
6928 truncate_message_1 (nchars
, a2
, a3
, a4
)
6933 if (BEG
+ nchars
< Z
)
6934 del_range (BEG
+ nchars
, Z
);
6936 echo_area_buffer
[0] = Qnil
;
6941 /* Set the current message to a substring of S or STRING.
6943 If STRING is a Lisp string, set the message to the first NBYTES
6944 bytes from STRING. NBYTES zero means use the whole string. If
6945 STRING is multibyte, the message will be displayed multibyte.
6947 If S is not null, set the message to the first LEN bytes of S. LEN
6948 zero means use the whole string. MULTIBYTE_P non-zero means S is
6949 multibyte. Display the message multibyte in that case. */
6952 set_message (s
, string
, nbytes
, multibyte_p
)
6957 message_enable_multibyte
6958 = ((s
&& multibyte_p
)
6959 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6961 with_echo_area_buffer (0, -1, set_message_1
,
6962 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6963 message_buf_print
= 0;
6964 help_echo_showing_p
= 0;
6968 /* Helper function for set_message. Arguments have the same meaning
6969 as there, with A1 corresponding to S and A2 corresponding to STRING
6970 This function is called with the echo area buffer being
6974 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6977 EMACS_INT nbytes
, multibyte_p
;
6979 const char *s
= (const char *) a1
;
6980 Lisp_Object string
= a2
;
6984 /* Change multibyteness of the echo buffer appropriately. */
6985 if (message_enable_multibyte
6986 != !NILP (current_buffer
->enable_multibyte_characters
))
6987 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6989 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6991 /* Insert new message at BEG. */
6992 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6994 if (STRINGP (string
))
6999 nbytes
= SBYTES (string
);
7000 nchars
= string_byte_to_char (string
, nbytes
);
7002 /* This function takes care of single/multibyte conversion. We
7003 just have to ensure that the echo area buffer has the right
7004 setting of enable_multibyte_characters. */
7005 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7010 nbytes
= strlen (s
);
7012 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7014 /* Convert from multi-byte to single-byte. */
7016 unsigned char work
[1];
7018 /* Convert a multibyte string to single-byte. */
7019 for (i
= 0; i
< nbytes
; i
+= n
)
7021 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7022 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7024 : multibyte_char_to_unibyte (c
, Qnil
));
7025 insert_1_both (work
, 1, 1, 1, 0, 0);
7028 else if (!multibyte_p
7029 && !NILP (current_buffer
->enable_multibyte_characters
))
7031 /* Convert from single-byte to multi-byte. */
7033 const unsigned char *msg
= (const unsigned char *) s
;
7034 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7036 /* Convert a single-byte string to multibyte. */
7037 for (i
= 0; i
< nbytes
; i
++)
7039 c
= unibyte_char_to_multibyte (msg
[i
]);
7040 n
= CHAR_STRING (c
, str
);
7041 insert_1_both (str
, 1, n
, 1, 0, 0);
7045 insert_1 (s
, nbytes
, 1, 0, 0);
7052 /* Clear messages. CURRENT_P non-zero means clear the current
7053 message. LAST_DISPLAYED_P non-zero means clear the message
7057 clear_message (current_p
, last_displayed_p
)
7058 int current_p
, last_displayed_p
;
7062 echo_area_buffer
[0] = Qnil
;
7063 message_cleared_p
= 1;
7066 if (last_displayed_p
)
7067 echo_area_buffer
[1] = Qnil
;
7069 message_buf_print
= 0;
7072 /* Clear garbaged frames.
7074 This function is used where the old redisplay called
7075 redraw_garbaged_frames which in turn called redraw_frame which in
7076 turn called clear_frame. The call to clear_frame was a source of
7077 flickering. I believe a clear_frame is not necessary. It should
7078 suffice in the new redisplay to invalidate all current matrices,
7079 and ensure a complete redisplay of all windows. */
7082 clear_garbaged_frames ()
7086 Lisp_Object tail
, frame
;
7087 int changed_count
= 0;
7089 FOR_EACH_FRAME (tail
, frame
)
7091 struct frame
*f
= XFRAME (frame
);
7093 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7096 Fredraw_frame (frame
);
7097 clear_current_matrices (f
);
7106 ++windows_or_buffers_changed
;
7111 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7112 is non-zero update selected_frame. Value is non-zero if the
7113 mini-windows height has been changed. */
7116 echo_area_display (update_frame_p
)
7119 Lisp_Object mini_window
;
7122 int window_height_changed_p
= 0;
7123 struct frame
*sf
= SELECTED_FRAME ();
7125 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7126 w
= XWINDOW (mini_window
);
7127 f
= XFRAME (WINDOW_FRAME (w
));
7129 /* Don't display if frame is invisible or not yet initialized. */
7130 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7133 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7135 #ifdef HAVE_WINDOW_SYSTEM
7136 /* When Emacs starts, selected_frame may be a visible terminal
7137 frame, even if we run under a window system. If we let this
7138 through, a message would be displayed on the terminal. */
7139 if (EQ (selected_frame
, Vterminal_frame
)
7140 && !NILP (Vwindow_system
))
7142 #endif /* HAVE_WINDOW_SYSTEM */
7145 /* Redraw garbaged frames. */
7147 clear_garbaged_frames ();
7149 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7151 echo_area_window
= mini_window
;
7152 window_height_changed_p
= display_echo_area (w
);
7153 w
->must_be_updated_p
= 1;
7155 /* Update the display, unless called from redisplay_internal.
7156 Also don't update the screen during redisplay itself. The
7157 update will happen at the end of redisplay, and an update
7158 here could cause confusion. */
7159 if (update_frame_p
&& !redisplaying_p
)
7163 /* If the display update has been interrupted by pending
7164 input, update mode lines in the frame. Due to the
7165 pending input, it might have been that redisplay hasn't
7166 been called, so that mode lines above the echo area are
7167 garbaged. This looks odd, so we prevent it here. */
7168 if (!display_completed
)
7169 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7171 if (window_height_changed_p
7172 /* Don't do this if Emacs is shutting down. Redisplay
7173 needs to run hooks. */
7174 && !NILP (Vrun_hooks
))
7176 /* Must update other windows. Likewise as in other
7177 cases, don't let this update be interrupted by
7179 int count
= SPECPDL_INDEX ();
7180 specbind (Qredisplay_dont_pause
, Qt
);
7181 windows_or_buffers_changed
= 1;
7182 redisplay_internal (0);
7183 unbind_to (count
, Qnil
);
7185 else if (FRAME_WINDOW_P (f
) && n
== 0)
7187 /* Window configuration is the same as before.
7188 Can do with a display update of the echo area,
7189 unless we displayed some mode lines. */
7190 update_single_window (w
, 1);
7191 rif
->flush_display (f
);
7194 update_frame (f
, 1, 1);
7196 /* If cursor is in the echo area, make sure that the next
7197 redisplay displays the minibuffer, so that the cursor will
7198 be replaced with what the minibuffer wants. */
7199 if (cursor_in_echo_area
)
7200 ++windows_or_buffers_changed
;
7203 else if (!EQ (mini_window
, selected_window
))
7204 windows_or_buffers_changed
++;
7206 /* Last displayed message is now the current message. */
7207 echo_area_buffer
[1] = echo_area_buffer
[0];
7209 /* Prevent redisplay optimization in redisplay_internal by resetting
7210 this_line_start_pos. This is done because the mini-buffer now
7211 displays the message instead of its buffer text. */
7212 if (EQ (mini_window
, selected_window
))
7213 CHARPOS (this_line_start_pos
) = 0;
7215 return window_height_changed_p
;
7220 /***********************************************************************
7222 ***********************************************************************/
7225 /* The frame title buffering code is also used by Fformat_mode_line.
7226 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7228 /* A buffer for constructing frame titles in it; allocated from the
7229 heap in init_xdisp and resized as needed in store_frame_title_char. */
7231 static char *frame_title_buf
;
7233 /* The buffer's end, and a current output position in it. */
7235 static char *frame_title_buf_end
;
7236 static char *frame_title_ptr
;
7239 /* Store a single character C for the frame title in frame_title_buf.
7240 Re-allocate frame_title_buf if necessary. */
7243 store_frame_title_char (c
)
7246 /* If output position has reached the end of the allocated buffer,
7247 double the buffer's size. */
7248 if (frame_title_ptr
== frame_title_buf_end
)
7250 int len
= frame_title_ptr
- frame_title_buf
;
7251 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7252 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7253 frame_title_buf_end
= frame_title_buf
+ new_size
;
7254 frame_title_ptr
= frame_title_buf
+ len
;
7257 *frame_title_ptr
++ = c
;
7261 /* Store part of a frame title in frame_title_buf, beginning at
7262 frame_title_ptr. STR is the string to store. Do not copy
7263 characters that yield more columns than PRECISION; PRECISION <= 0
7264 means copy the whole string. Pad with spaces until FIELD_WIDTH
7265 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7266 pad. Called from display_mode_element when it is used to build a
7270 store_frame_title (str
, field_width
, precision
)
7271 const unsigned char *str
;
7272 int field_width
, precision
;
7277 /* Copy at most PRECISION chars from STR. */
7278 nbytes
= strlen (str
);
7279 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7281 store_frame_title_char (*str
++);
7283 /* Fill up with spaces until FIELD_WIDTH reached. */
7284 while (field_width
> 0
7287 store_frame_title_char (' ');
7294 #ifdef HAVE_WINDOW_SYSTEM
7296 /* Set the title of FRAME, if it has changed. The title format is
7297 Vicon_title_format if FRAME is iconified, otherwise it is
7298 frame_title_format. */
7301 x_consider_frame_title (frame
)
7304 struct frame
*f
= XFRAME (frame
);
7306 if (FRAME_WINDOW_P (f
)
7307 || FRAME_MINIBUF_ONLY_P (f
)
7308 || f
->explicit_name
)
7310 /* Do we have more than one visible frame on this X display? */
7313 struct buffer
*obuf
;
7317 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7319 Lisp_Object other_frame
= XCAR (tail
);
7320 struct frame
*tf
= XFRAME (other_frame
);
7323 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7324 && !FRAME_MINIBUF_ONLY_P (tf
)
7325 && !EQ (other_frame
, tip_frame
)
7326 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7330 /* Set global variable indicating that multiple frames exist. */
7331 multiple_frames
= CONSP (tail
);
7333 /* Switch to the buffer of selected window of the frame. Set up
7334 frame_title_ptr so that display_mode_element will output into it;
7335 then display the title. */
7336 obuf
= current_buffer
;
7337 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7338 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7339 frame_title_ptr
= frame_title_buf
;
7340 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7341 NULL
, DEFAULT_FACE_ID
);
7342 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7343 len
= frame_title_ptr
- frame_title_buf
;
7344 frame_title_ptr
= NULL
;
7345 set_buffer_internal_1 (obuf
);
7347 /* Set the title only if it's changed. This avoids consing in
7348 the common case where it hasn't. (If it turns out that we've
7349 already wasted too much time by walking through the list with
7350 display_mode_element, then we might need to optimize at a
7351 higher level than this.) */
7352 if (! STRINGP (f
->name
)
7353 || SBYTES (f
->name
) != len
7354 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7355 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7359 #endif /* not HAVE_WINDOW_SYSTEM */
7364 /***********************************************************************
7366 ***********************************************************************/
7369 /* Prepare for redisplay by updating menu-bar item lists when
7370 appropriate. This can call eval. */
7373 prepare_menu_bars ()
7376 struct gcpro gcpro1
, gcpro2
;
7378 Lisp_Object tooltip_frame
;
7380 #ifdef HAVE_WINDOW_SYSTEM
7381 tooltip_frame
= tip_frame
;
7383 tooltip_frame
= Qnil
;
7386 /* Update all frame titles based on their buffer names, etc. We do
7387 this before the menu bars so that the buffer-menu will show the
7388 up-to-date frame titles. */
7389 #ifdef HAVE_WINDOW_SYSTEM
7390 if (windows_or_buffers_changed
|| update_mode_lines
)
7392 Lisp_Object tail
, frame
;
7394 FOR_EACH_FRAME (tail
, frame
)
7397 if (!EQ (frame
, tooltip_frame
)
7398 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7399 x_consider_frame_title (frame
);
7402 #endif /* HAVE_WINDOW_SYSTEM */
7404 /* Update the menu bar item lists, if appropriate. This has to be
7405 done before any actual redisplay or generation of display lines. */
7406 all_windows
= (update_mode_lines
7407 || buffer_shared
> 1
7408 || windows_or_buffers_changed
);
7411 Lisp_Object tail
, frame
;
7412 int count
= SPECPDL_INDEX ();
7414 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7416 FOR_EACH_FRAME (tail
, frame
)
7420 /* Ignore tooltip frame. */
7421 if (EQ (frame
, tooltip_frame
))
7424 /* If a window on this frame changed size, report that to
7425 the user and clear the size-change flag. */
7426 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7428 Lisp_Object functions
;
7430 /* Clear flag first in case we get an error below. */
7431 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7432 functions
= Vwindow_size_change_functions
;
7433 GCPRO2 (tail
, functions
);
7435 while (CONSP (functions
))
7437 call1 (XCAR (functions
), frame
);
7438 functions
= XCDR (functions
);
7444 update_menu_bar (f
, 0);
7445 #ifdef HAVE_WINDOW_SYSTEM
7446 update_tool_bar (f
, 0);
7451 unbind_to (count
, Qnil
);
7455 struct frame
*sf
= SELECTED_FRAME ();
7456 update_menu_bar (sf
, 1);
7457 #ifdef HAVE_WINDOW_SYSTEM
7458 update_tool_bar (sf
, 1);
7462 /* Motif needs this. See comment in xmenu.c. Turn it off when
7463 pending_menu_activation is not defined. */
7464 #ifdef USE_X_TOOLKIT
7465 pending_menu_activation
= 0;
7470 /* Update the menu bar item list for frame F. This has to be done
7471 before we start to fill in any display lines, because it can call
7474 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7477 update_menu_bar (f
, save_match_data
)
7479 int save_match_data
;
7482 register struct window
*w
;
7484 /* If called recursively during a menu update, do nothing. This can
7485 happen when, for instance, an activate-menubar-hook causes a
7487 if (inhibit_menubar_update
)
7490 window
= FRAME_SELECTED_WINDOW (f
);
7491 w
= XWINDOW (window
);
7493 #if 0 /* The if statement below this if statement used to include the
7494 condition !NILP (w->update_mode_line), rather than using
7495 update_mode_lines directly, and this if statement may have
7496 been added to make that condition work. Now the if
7497 statement below matches its comment, this isn't needed. */
7498 if (update_mode_lines
)
7499 w
->update_mode_line
= Qt
;
7502 if (FRAME_WINDOW_P (f
)
7504 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
7505 FRAME_EXTERNAL_MENU_BAR (f
)
7507 FRAME_MENU_BAR_LINES (f
) > 0
7509 : FRAME_MENU_BAR_LINES (f
) > 0)
7511 /* If the user has switched buffers or windows, we need to
7512 recompute to reflect the new bindings. But we'll
7513 recompute when update_mode_lines is set too; that means
7514 that people can use force-mode-line-update to request
7515 that the menu bar be recomputed. The adverse effect on
7516 the rest of the redisplay algorithm is about the same as
7517 windows_or_buffers_changed anyway. */
7518 if (windows_or_buffers_changed
7519 /* This used to test w->update_mode_line, but we believe
7520 there is no need to recompute the menu in that case. */
7521 || update_mode_lines
7522 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7523 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7524 != !NILP (w
->last_had_star
))
7525 || ((!NILP (Vtransient_mark_mode
)
7526 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7527 != !NILP (w
->region_showing
)))
7529 struct buffer
*prev
= current_buffer
;
7530 int count
= SPECPDL_INDEX ();
7532 specbind (Qinhibit_menubar_update
, Qt
);
7534 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7535 if (save_match_data
)
7536 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7537 if (NILP (Voverriding_local_map_menu_flag
))
7539 specbind (Qoverriding_terminal_local_map
, Qnil
);
7540 specbind (Qoverriding_local_map
, Qnil
);
7543 /* Run the Lucid hook. */
7544 safe_run_hooks (Qactivate_menubar_hook
);
7546 /* If it has changed current-menubar from previous value,
7547 really recompute the menu-bar from the value. */
7548 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7549 call0 (Qrecompute_lucid_menubar
);
7551 safe_run_hooks (Qmenu_bar_update_hook
);
7552 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7554 /* Redisplay the menu bar in case we changed it. */
7555 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
7556 if (FRAME_WINDOW_P (f
)
7557 #if defined (MAC_OS)
7558 /* All frames on Mac OS share the same menubar. So only the
7559 selected frame should be allowed to set it. */
7560 && f
== SELECTED_FRAME ()
7563 set_frame_menubar (f
, 0, 0);
7565 /* On a terminal screen, the menu bar is an ordinary screen
7566 line, and this makes it get updated. */
7567 w
->update_mode_line
= Qt
;
7568 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7569 /* In the non-toolkit version, the menu bar is an ordinary screen
7570 line, and this makes it get updated. */
7571 w
->update_mode_line
= Qt
;
7572 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7574 unbind_to (count
, Qnil
);
7575 set_buffer_internal_1 (prev
);
7582 /***********************************************************************
7584 ***********************************************************************/
7586 #ifdef HAVE_WINDOW_SYSTEM
7588 /* Update the tool-bar item list for frame F. This has to be done
7589 before we start to fill in any display lines. Called from
7590 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7591 and restore it here. */
7594 update_tool_bar (f
, save_match_data
)
7596 int save_match_data
;
7598 if (WINDOWP (f
->tool_bar_window
)
7599 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7604 window
= FRAME_SELECTED_WINDOW (f
);
7605 w
= XWINDOW (window
);
7607 /* If the user has switched buffers or windows, we need to
7608 recompute to reflect the new bindings. But we'll
7609 recompute when update_mode_lines is set too; that means
7610 that people can use force-mode-line-update to request
7611 that the menu bar be recomputed. The adverse effect on
7612 the rest of the redisplay algorithm is about the same as
7613 windows_or_buffers_changed anyway. */
7614 if (windows_or_buffers_changed
7615 || !NILP (w
->update_mode_line
)
7616 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7617 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7618 != !NILP (w
->last_had_star
))
7619 || ((!NILP (Vtransient_mark_mode
)
7620 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7621 != !NILP (w
->region_showing
)))
7623 struct buffer
*prev
= current_buffer
;
7624 int count
= SPECPDL_INDEX ();
7626 /* Set current_buffer to the buffer of the selected
7627 window of the frame, so that we get the right local
7629 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7631 /* Save match data, if we must. */
7632 if (save_match_data
)
7633 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7635 /* Make sure that we don't accidentally use bogus keymaps. */
7636 if (NILP (Voverriding_local_map_menu_flag
))
7638 specbind (Qoverriding_terminal_local_map
, Qnil
);
7639 specbind (Qoverriding_local_map
, Qnil
);
7642 /* Build desired tool-bar items from keymaps. */
7644 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7646 /* Redisplay the tool-bar in case we changed it. */
7647 w
->update_mode_line
= Qt
;
7649 unbind_to (count
, Qnil
);
7650 set_buffer_internal_1 (prev
);
7656 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7657 F's desired tool-bar contents. F->tool_bar_items must have
7658 been set up previously by calling prepare_menu_bars. */
7661 build_desired_tool_bar_string (f
)
7664 int i
, size
, size_needed
;
7665 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7666 Lisp_Object image
, plist
, props
;
7668 image
= plist
= props
= Qnil
;
7669 GCPRO3 (image
, plist
, props
);
7671 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7672 Otherwise, make a new string. */
7674 /* The size of the string we might be able to reuse. */
7675 size
= (STRINGP (f
->desired_tool_bar_string
)
7676 ? SCHARS (f
->desired_tool_bar_string
)
7679 /* We need one space in the string for each image. */
7680 size_needed
= f
->n_tool_bar_items
;
7682 /* Reuse f->desired_tool_bar_string, if possible. */
7683 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7684 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7688 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7689 Fremove_text_properties (make_number (0), make_number (size
),
7690 props
, f
->desired_tool_bar_string
);
7693 /* Put a `display' property on the string for the images to display,
7694 put a `menu_item' property on tool-bar items with a value that
7695 is the index of the item in F's tool-bar item vector. */
7696 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7698 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7700 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7701 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7702 int hmargin
, vmargin
, relief
, idx
, end
;
7703 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7705 /* If image is a vector, choose the image according to the
7707 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7708 if (VECTORP (image
))
7712 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7713 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7716 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7717 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7719 xassert (ASIZE (image
) >= idx
);
7720 image
= AREF (image
, idx
);
7725 /* Ignore invalid image specifications. */
7726 if (!valid_image_p (image
))
7729 /* Display the tool-bar button pressed, or depressed. */
7730 plist
= Fcopy_sequence (XCDR (image
));
7732 /* Compute margin and relief to draw. */
7733 relief
= (tool_bar_button_relief
>= 0
7734 ? tool_bar_button_relief
7735 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7736 hmargin
= vmargin
= relief
;
7738 if (INTEGERP (Vtool_bar_button_margin
)
7739 && XINT (Vtool_bar_button_margin
) > 0)
7741 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7742 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7744 else if (CONSP (Vtool_bar_button_margin
))
7746 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7747 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7748 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7750 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7751 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7752 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7755 if (auto_raise_tool_bar_buttons_p
)
7757 /* Add a `:relief' property to the image spec if the item is
7761 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7768 /* If image is selected, display it pressed, i.e. with a
7769 negative relief. If it's not selected, display it with a
7771 plist
= Fplist_put (plist
, QCrelief
,
7773 ? make_number (-relief
)
7774 : make_number (relief
)));
7779 /* Put a margin around the image. */
7780 if (hmargin
|| vmargin
)
7782 if (hmargin
== vmargin
)
7783 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7785 plist
= Fplist_put (plist
, QCmargin
,
7786 Fcons (make_number (hmargin
),
7787 make_number (vmargin
)));
7790 /* If button is not enabled, and we don't have special images
7791 for the disabled state, make the image appear disabled by
7792 applying an appropriate algorithm to it. */
7793 if (!enabled_p
&& idx
< 0)
7794 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7796 /* Put a `display' text property on the string for the image to
7797 display. Put a `menu-item' property on the string that gives
7798 the start of this item's properties in the tool-bar items
7800 image
= Fcons (Qimage
, plist
);
7801 props
= list4 (Qdisplay
, image
,
7802 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7804 /* Let the last image hide all remaining spaces in the tool bar
7805 string. The string can be longer than needed when we reuse a
7807 if (i
+ 1 == f
->n_tool_bar_items
)
7808 end
= SCHARS (f
->desired_tool_bar_string
);
7811 Fadd_text_properties (make_number (i
), make_number (end
),
7812 props
, f
->desired_tool_bar_string
);
7820 /* Display one line of the tool-bar of frame IT->f. */
7823 display_tool_bar_line (it
)
7826 struct glyph_row
*row
= it
->glyph_row
;
7827 int max_x
= it
->last_visible_x
;
7830 prepare_desired_row (row
);
7831 row
->y
= it
->current_y
;
7833 /* Note that this isn't made use of if the face hasn't a box,
7834 so there's no need to check the face here. */
7835 it
->start_of_box_run_p
= 1;
7837 while (it
->current_x
< max_x
)
7839 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7841 /* Get the next display element. */
7842 if (!get_next_display_element (it
))
7845 /* Produce glyphs. */
7846 x_before
= it
->current_x
;
7847 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7848 PRODUCE_GLYPHS (it
);
7850 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7855 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7857 if (x
+ glyph
->pixel_width
> max_x
)
7859 /* Glyph doesn't fit on line. */
7860 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7866 x
+= glyph
->pixel_width
;
7870 /* Stop at line ends. */
7871 if (ITERATOR_AT_END_OF_LINE_P (it
))
7874 set_iterator_to_next (it
, 1);
7879 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7880 extend_face_to_end_of_line (it
);
7881 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7882 last
->right_box_line_p
= 1;
7883 if (last
== row
->glyphs
[TEXT_AREA
])
7884 last
->left_box_line_p
= 1;
7885 compute_line_metrics (it
);
7887 /* If line is empty, make it occupy the rest of the tool-bar. */
7888 if (!row
->displays_text_p
)
7890 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7891 row
->ascent
= row
->phys_ascent
= 0;
7894 row
->full_width_p
= 1;
7895 row
->continued_p
= 0;
7896 row
->truncated_on_left_p
= 0;
7897 row
->truncated_on_right_p
= 0;
7899 it
->current_x
= it
->hpos
= 0;
7900 it
->current_y
+= row
->height
;
7906 /* Value is the number of screen lines needed to make all tool-bar
7907 items of frame F visible. */
7910 tool_bar_lines_needed (f
)
7913 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7916 /* Initialize an iterator for iteration over
7917 F->desired_tool_bar_string in the tool-bar window of frame F. */
7918 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7919 it
.first_visible_x
= 0;
7920 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7921 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7923 while (!ITERATOR_AT_END_P (&it
))
7925 it
.glyph_row
= w
->desired_matrix
->rows
;
7926 clear_glyph_row (it
.glyph_row
);
7927 display_tool_bar_line (&it
);
7930 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7934 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7936 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
7945 frame
= selected_frame
;
7947 CHECK_FRAME (frame
);
7950 if (WINDOWP (f
->tool_bar_window
)
7951 || (w
= XWINDOW (f
->tool_bar_window
),
7952 XFASTINT (w
->height
) > 0))
7954 update_tool_bar (f
, 1);
7955 if (f
->n_tool_bar_items
)
7957 build_desired_tool_bar_string (f
);
7958 nlines
= tool_bar_lines_needed (f
);
7962 return make_number (nlines
);
7966 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7967 height should be changed. */
7970 redisplay_tool_bar (f
)
7975 struct glyph_row
*row
;
7976 int change_height_p
= 0;
7978 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7979 do anything. This means you must start with tool-bar-lines
7980 non-zero to get the auto-sizing effect. Or in other words, you
7981 can turn off tool-bars by specifying tool-bar-lines zero. */
7982 if (!WINDOWP (f
->tool_bar_window
)
7983 || (w
= XWINDOW (f
->tool_bar_window
),
7984 XFASTINT (w
->height
) == 0))
7987 /* Set up an iterator for the tool-bar window. */
7988 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7989 it
.first_visible_x
= 0;
7990 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7993 /* Build a string that represents the contents of the tool-bar. */
7994 build_desired_tool_bar_string (f
);
7995 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7997 /* Display as many lines as needed to display all tool-bar items. */
7998 while (it
.current_y
< it
.last_visible_y
)
7999 display_tool_bar_line (&it
);
8001 /* It doesn't make much sense to try scrolling in the tool-bar
8002 window, so don't do it. */
8003 w
->desired_matrix
->no_scrolling_p
= 1;
8004 w
->must_be_updated_p
= 1;
8006 if (auto_resize_tool_bars_p
)
8010 /* If we couldn't display everything, change the tool-bar's
8012 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8013 change_height_p
= 1;
8015 /* If there are blank lines at the end, except for a partially
8016 visible blank line at the end that is smaller than
8017 CANON_Y_UNIT, change the tool-bar's height. */
8018 row
= it
.glyph_row
- 1;
8019 if (!row
->displays_text_p
8020 && row
->height
>= CANON_Y_UNIT (f
))
8021 change_height_p
= 1;
8023 /* If row displays tool-bar items, but is partially visible,
8024 change the tool-bar's height. */
8025 if (row
->displays_text_p
8026 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8027 change_height_p
= 1;
8029 /* Resize windows as needed by changing the `tool-bar-lines'
8032 && (nlines
= tool_bar_lines_needed (f
),
8033 nlines
!= XFASTINT (w
->height
)))
8035 extern Lisp_Object Qtool_bar_lines
;
8037 int old_height
= XFASTINT (w
->height
);
8039 XSETFRAME (frame
, f
);
8040 clear_glyph_matrix (w
->desired_matrix
);
8041 Fmodify_frame_parameters (frame
,
8042 Fcons (Fcons (Qtool_bar_lines
,
8043 make_number (nlines
)),
8045 if (XFASTINT (w
->height
) != old_height
)
8046 fonts_changed_p
= 1;
8050 return change_height_p
;
8054 /* Get information about the tool-bar item which is displayed in GLYPH
8055 on frame F. Return in *PROP_IDX the index where tool-bar item
8056 properties start in F->tool_bar_items. Value is zero if
8057 GLYPH doesn't display a tool-bar item. */
8060 tool_bar_item_info (f
, glyph
, prop_idx
)
8062 struct glyph
*glyph
;
8069 /* This function can be called asynchronously, which means we must
8070 exclude any possibility that Fget_text_property signals an
8072 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8073 charpos
= max (0, charpos
);
8075 /* Get the text property `menu-item' at pos. The value of that
8076 property is the start index of this item's properties in
8077 F->tool_bar_items. */
8078 prop
= Fget_text_property (make_number (charpos
),
8079 Qmenu_item
, f
->current_tool_bar_string
);
8080 if (INTEGERP (prop
))
8082 *prop_idx
= XINT (prop
);
8091 #endif /* HAVE_WINDOW_SYSTEM */
8095 /************************************************************************
8096 Horizontal scrolling
8097 ************************************************************************/
8099 static int hscroll_window_tree
P_ ((Lisp_Object
));
8100 static int hscroll_windows
P_ ((Lisp_Object
));
8102 /* For all leaf windows in the window tree rooted at WINDOW, set their
8103 hscroll value so that PT is (i) visible in the window, and (ii) so
8104 that it is not within a certain margin at the window's left and
8105 right border. Value is non-zero if any window's hscroll has been
8109 hscroll_window_tree (window
)
8112 int hscrolled_p
= 0;
8113 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
8114 int hscroll_step_abs
= 0;
8115 double hscroll_step_rel
= 0;
8117 if (hscroll_relative_p
)
8119 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
8120 if (hscroll_step_rel
< 0)
8122 hscroll_relative_p
= 0;
8123 hscroll_step_abs
= 0;
8126 else if (INTEGERP (Vhscroll_step
))
8128 hscroll_step_abs
= XINT (Vhscroll_step
);
8129 if (hscroll_step_abs
< 0)
8130 hscroll_step_abs
= 0;
8133 hscroll_step_abs
= 0;
8135 while (WINDOWP (window
))
8137 struct window
*w
= XWINDOW (window
);
8139 if (WINDOWP (w
->hchild
))
8140 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
8141 else if (WINDOWP (w
->vchild
))
8142 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
8143 else if (w
->cursor
.vpos
>= 0)
8145 int h_margin
, text_area_x
, text_area_y
;
8146 int text_area_width
, text_area_height
;
8147 struct glyph_row
*current_cursor_row
8148 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
8149 struct glyph_row
*desired_cursor_row
8150 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
8151 struct glyph_row
*cursor_row
8152 = (desired_cursor_row
->enabled_p
8153 ? desired_cursor_row
8154 : current_cursor_row
);
8156 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8157 &text_area_width
, &text_area_height
);
8159 /* Scroll when cursor is inside this scroll margin. */
8160 h_margin
= hscroll_margin
* CANON_X_UNIT (XFRAME (w
->frame
));
8162 if ((XFASTINT (w
->hscroll
)
8163 && w
->cursor
.x
<= h_margin
)
8164 || (cursor_row
->enabled_p
8165 && cursor_row
->truncated_on_right_p
8166 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
8170 struct buffer
*saved_current_buffer
;
8174 /* Find point in a display of infinite width. */
8175 saved_current_buffer
= current_buffer
;
8176 current_buffer
= XBUFFER (w
->buffer
);
8178 if (w
== XWINDOW (selected_window
))
8179 pt
= BUF_PT (current_buffer
);
8182 pt
= marker_position (w
->pointm
);
8183 pt
= max (BEGV
, pt
);
8187 /* Move iterator to pt starting at cursor_row->start in
8188 a line with infinite width. */
8189 init_to_row_start (&it
, w
, cursor_row
);
8190 it
.last_visible_x
= INFINITY
;
8191 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8192 current_buffer
= saved_current_buffer
;
8194 /* Position cursor in window. */
8195 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
8196 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
8197 / CANON_X_UNIT (it
.f
);
8198 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
8200 if (hscroll_relative_p
)
8201 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
8204 wanted_x
= text_area_width
8205 - hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8208 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8212 if (hscroll_relative_p
)
8213 wanted_x
= text_area_width
* hscroll_step_rel
8216 wanted_x
= hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8219 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8221 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8223 /* Don't call Fset_window_hscroll if value hasn't
8224 changed because it will prevent redisplay
8226 if (XFASTINT (w
->hscroll
) != hscroll
)
8228 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8229 w
->hscroll
= make_number (hscroll
);
8238 /* Value is non-zero if hscroll of any leaf window has been changed. */
8243 /* Set hscroll so that cursor is visible and not inside horizontal
8244 scroll margins for all windows in the tree rooted at WINDOW. See
8245 also hscroll_window_tree above. Value is non-zero if any window's
8246 hscroll has been changed. If it has, desired matrices on the frame
8247 of WINDOW are cleared. */
8250 hscroll_windows (window
)
8255 if (automatic_hscrolling_p
)
8257 hscrolled_p
= hscroll_window_tree (window
);
8259 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8268 /************************************************************************
8270 ************************************************************************/
8272 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8273 to a non-zero value. This is sometimes handy to have in a debugger
8278 /* First and last unchanged row for try_window_id. */
8280 int debug_first_unchanged_at_end_vpos
;
8281 int debug_last_unchanged_at_beg_vpos
;
8283 /* Delta vpos and y. */
8285 int debug_dvpos
, debug_dy
;
8287 /* Delta in characters and bytes for try_window_id. */
8289 int debug_delta
, debug_delta_bytes
;
8291 /* Values of window_end_pos and window_end_vpos at the end of
8294 EMACS_INT debug_end_pos
, debug_end_vpos
;
8296 /* Append a string to W->desired_matrix->method. FMT is a printf
8297 format string. A1...A9 are a supplement for a variable-length
8298 argument list. If trace_redisplay_p is non-zero also printf the
8299 resulting string to stderr. */
8302 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8305 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8308 char *method
= w
->desired_matrix
->method
;
8309 int len
= strlen (method
);
8310 int size
= sizeof w
->desired_matrix
->method
;
8311 int remaining
= size
- len
- 1;
8313 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8314 if (len
&& remaining
)
8320 strncpy (method
+ len
, buffer
, remaining
);
8322 if (trace_redisplay_p
)
8323 fprintf (stderr
, "%p (%s): %s\n",
8325 ((BUFFERP (w
->buffer
)
8326 && STRINGP (XBUFFER (w
->buffer
)->name
))
8327 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
8332 #endif /* GLYPH_DEBUG */
8335 /* Value is non-zero if all changes in window W, which displays
8336 current_buffer, are in the text between START and END. START is a
8337 buffer position, END is given as a distance from Z. Used in
8338 redisplay_internal for display optimization. */
8341 text_outside_line_unchanged_p (w
, start
, end
)
8345 int unchanged_p
= 1;
8347 /* If text or overlays have changed, see where. */
8348 if (XFASTINT (w
->last_modified
) < MODIFF
8349 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8351 /* Gap in the line? */
8352 if (GPT
< start
|| Z
- GPT
< end
)
8355 /* Changes start in front of the line, or end after it? */
8357 && (BEG_UNCHANGED
< start
- 1
8358 || END_UNCHANGED
< end
))
8361 /* If selective display, can't optimize if changes start at the
8362 beginning of the line. */
8364 && INTEGERP (current_buffer
->selective_display
)
8365 && XINT (current_buffer
->selective_display
) > 0
8366 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8369 /* If there are overlays at the start or end of the line, these
8370 may have overlay strings with newlines in them. A change at
8371 START, for instance, may actually concern the display of such
8372 overlay strings as well, and they are displayed on different
8373 lines. So, quickly rule out this case. (For the future, it
8374 might be desirable to implement something more telling than
8375 just BEG/END_UNCHANGED.) */
8378 if (BEG
+ BEG_UNCHANGED
== start
8379 && overlay_touches_p (start
))
8381 if (END_UNCHANGED
== end
8382 && overlay_touches_p (Z
- end
))
8391 /* Do a frame update, taking possible shortcuts into account. This is
8392 the main external entry point for redisplay.
8394 If the last redisplay displayed an echo area message and that message
8395 is no longer requested, we clear the echo area or bring back the
8396 mini-buffer if that is in use. */
8401 redisplay_internal (0);
8405 /* Return 1 if point moved out of or into a composition. Otherwise
8406 return 0. PREV_BUF and PREV_PT are the last point buffer and
8407 position. BUF and PT are the current point buffer and position. */
8410 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8411 struct buffer
*prev_buf
, *buf
;
8418 XSETBUFFER (buffer
, buf
);
8419 /* Check a composition at the last point if point moved within the
8421 if (prev_buf
== buf
)
8424 /* Point didn't move. */
8427 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8428 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8429 && COMPOSITION_VALID_P (start
, end
, prop
)
8430 && start
< prev_pt
&& end
> prev_pt
)
8431 /* The last point was within the composition. Return 1 iff
8432 point moved out of the composition. */
8433 return (pt
<= start
|| pt
>= end
);
8436 /* Check a composition at the current point. */
8437 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8438 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8439 && COMPOSITION_VALID_P (start
, end
, prop
)
8440 && start
< pt
&& end
> pt
);
8444 /* Reconsider the setting of B->clip_changed which is displayed
8448 reconsider_clip_changes (w
, b
)
8453 && !NILP (w
->window_end_valid
)
8454 && w
->current_matrix
->buffer
== b
8455 && w
->current_matrix
->zv
== BUF_ZV (b
)
8456 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8457 b
->clip_changed
= 0;
8459 /* If display wasn't paused, and W is not a tool bar window, see if
8460 point has been moved into or out of a composition. In that case,
8461 we set b->clip_changed to 1 to force updating the screen. If
8462 b->clip_changed has already been set to 1, we can skip this
8464 if (!b
->clip_changed
8465 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8469 if (w
== XWINDOW (selected_window
))
8470 pt
= BUF_PT (current_buffer
);
8472 pt
= marker_position (w
->pointm
);
8474 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8475 || pt
!= XINT (w
->last_point
))
8476 && check_point_in_composition (w
->current_matrix
->buffer
,
8477 XINT (w
->last_point
),
8478 XBUFFER (w
->buffer
), pt
))
8479 b
->clip_changed
= 1;
8484 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8485 response to any user action; therefore, we should preserve the echo
8486 area. (Actually, our caller does that job.) Perhaps in the future
8487 avoid recentering windows if it is not necessary; currently that
8488 causes some problems. */
8491 redisplay_internal (preserve_echo_area
)
8492 int preserve_echo_area
;
8494 struct window
*w
= XWINDOW (selected_window
);
8495 struct frame
*f
= XFRAME (w
->frame
);
8497 int must_finish
= 0;
8498 struct text_pos tlbufpos
, tlendpos
;
8499 int number_of_visible_frames
;
8501 struct frame
*sf
= SELECTED_FRAME ();
8503 /* Non-zero means redisplay has to consider all windows on all
8504 frames. Zero means, only selected_window is considered. */
8505 int consider_all_windows_p
;
8507 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8509 /* No redisplay if running in batch mode or frame is not yet fully
8510 initialized, or redisplay is explicitly turned off by setting
8511 Vinhibit_redisplay. */
8513 || !NILP (Vinhibit_redisplay
)
8514 || !f
->glyphs_initialized_p
)
8517 /* The flag redisplay_performed_directly_p is set by
8518 direct_output_for_insert when it already did the whole screen
8519 update necessary. */
8520 if (redisplay_performed_directly_p
)
8522 redisplay_performed_directly_p
= 0;
8523 if (!hscroll_windows (selected_window
))
8527 #ifdef USE_X_TOOLKIT
8528 if (popup_activated ())
8532 /* I don't think this happens but let's be paranoid. */
8536 /* Record a function that resets redisplaying_p to its old value
8537 when we leave this function. */
8538 count
= SPECPDL_INDEX ();
8539 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8541 specbind (Qinhibit_free_realized_faces
, Qnil
);
8545 reconsider_clip_changes (w
, current_buffer
);
8547 /* If new fonts have been loaded that make a glyph matrix adjustment
8548 necessary, do it. */
8549 if (fonts_changed_p
)
8551 adjust_glyphs (NULL
);
8552 ++windows_or_buffers_changed
;
8553 fonts_changed_p
= 0;
8556 /* If face_change_count is non-zero, init_iterator will free all
8557 realized faces, which includes the faces referenced from current
8558 matrices. So, we can't reuse current matrices in this case. */
8559 if (face_change_count
)
8560 ++windows_or_buffers_changed
;
8562 if (! FRAME_WINDOW_P (sf
)
8563 && previous_terminal_frame
!= sf
)
8565 /* Since frames on an ASCII terminal share the same display
8566 area, displaying a different frame means redisplay the whole
8568 windows_or_buffers_changed
++;
8569 SET_FRAME_GARBAGED (sf
);
8570 XSETFRAME (Vterminal_frame
, sf
);
8572 previous_terminal_frame
= sf
;
8574 /* Set the visible flags for all frames. Do this before checking
8575 for resized or garbaged frames; they want to know if their frames
8576 are visible. See the comment in frame.h for
8577 FRAME_SAMPLE_VISIBILITY. */
8579 Lisp_Object tail
, frame
;
8581 number_of_visible_frames
= 0;
8583 FOR_EACH_FRAME (tail
, frame
)
8585 struct frame
*f
= XFRAME (frame
);
8587 FRAME_SAMPLE_VISIBILITY (f
);
8588 if (FRAME_VISIBLE_P (f
))
8589 ++number_of_visible_frames
;
8590 clear_desired_matrices (f
);
8594 /* Notice any pending interrupt request to change frame size. */
8595 do_pending_window_change (1);
8597 /* Clear frames marked as garbaged. */
8599 clear_garbaged_frames ();
8601 /* Build menubar and tool-bar items. */
8602 prepare_menu_bars ();
8604 if (windows_or_buffers_changed
)
8605 update_mode_lines
++;
8607 /* Detect case that we need to write or remove a star in the mode line. */
8608 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8610 w
->update_mode_line
= Qt
;
8611 if (buffer_shared
> 1)
8612 update_mode_lines
++;
8615 /* If %c is in the mode line, update it if needed. */
8616 if (!NILP (w
->column_number_displayed
)
8617 /* This alternative quickly identifies a common case
8618 where no change is needed. */
8619 && !(PT
== XFASTINT (w
->last_point
)
8620 && XFASTINT (w
->last_modified
) >= MODIFF
8621 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8622 && (XFASTINT (w
->column_number_displayed
)
8623 != (int) current_column ())) /* iftc */
8624 w
->update_mode_line
= Qt
;
8626 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8628 /* The variable buffer_shared is set in redisplay_window and
8629 indicates that we redisplay a buffer in different windows. See
8631 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
8632 || cursor_type_changed
);
8634 /* If specs for an arrow have changed, do thorough redisplay
8635 to ensure we remove any arrow that should no longer exist. */
8636 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8637 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8638 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8640 /* Normally the message* functions will have already displayed and
8641 updated the echo area, but the frame may have been trashed, or
8642 the update may have been preempted, so display the echo area
8643 again here. Checking message_cleared_p captures the case that
8644 the echo area should be cleared. */
8645 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8646 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8647 || (message_cleared_p
8648 && minibuf_level
== 0
8649 /* If the mini-window is currently selected, this means the
8650 echo-area doesn't show through. */
8651 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8653 int window_height_changed_p
= echo_area_display (0);
8656 /* If we don't display the current message, don't clear the
8657 message_cleared_p flag, because, if we did, we wouldn't clear
8658 the echo area in the next redisplay which doesn't preserve
8660 if (!display_last_displayed_message_p
)
8661 message_cleared_p
= 0;
8663 if (fonts_changed_p
)
8665 else if (window_height_changed_p
)
8667 consider_all_windows_p
= 1;
8668 ++update_mode_lines
;
8669 ++windows_or_buffers_changed
;
8671 /* If window configuration was changed, frames may have been
8672 marked garbaged. Clear them or we will experience
8673 surprises wrt scrolling. */
8675 clear_garbaged_frames ();
8678 else if (EQ (selected_window
, minibuf_window
)
8679 && (current_buffer
->clip_changed
8680 || XFASTINT (w
->last_modified
) < MODIFF
8681 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8682 && resize_mini_window (w
, 0))
8684 /* Resized active mini-window to fit the size of what it is
8685 showing if its contents might have changed. */
8687 consider_all_windows_p
= 1;
8688 ++windows_or_buffers_changed
;
8689 ++update_mode_lines
;
8691 /* If window configuration was changed, frames may have been
8692 marked garbaged. Clear them or we will experience
8693 surprises wrt scrolling. */
8695 clear_garbaged_frames ();
8699 /* If showing the region, and mark has changed, we must redisplay
8700 the whole window. The assignment to this_line_start_pos prevents
8701 the optimization directly below this if-statement. */
8702 if (((!NILP (Vtransient_mark_mode
)
8703 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8704 != !NILP (w
->region_showing
))
8705 || (!NILP (w
->region_showing
)
8706 && !EQ (w
->region_showing
,
8707 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8708 CHARPOS (this_line_start_pos
) = 0;
8710 /* Optimize the case that only the line containing the cursor in the
8711 selected window has changed. Variables starting with this_ are
8712 set in display_line and record information about the line
8713 containing the cursor. */
8714 tlbufpos
= this_line_start_pos
;
8715 tlendpos
= this_line_end_pos
;
8716 if (!consider_all_windows_p
8717 && CHARPOS (tlbufpos
) > 0
8718 && NILP (w
->update_mode_line
)
8719 && !current_buffer
->clip_changed
8720 && !current_buffer
->prevent_redisplay_optimizations_p
8721 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8722 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8723 /* Make sure recorded data applies to current buffer, etc. */
8724 && this_line_buffer
== current_buffer
8725 && current_buffer
== XBUFFER (w
->buffer
)
8726 && NILP (w
->force_start
)
8727 && NILP (w
->optional_new_start
)
8728 /* Point must be on the line that we have info recorded about. */
8729 && PT
>= CHARPOS (tlbufpos
)
8730 && PT
<= Z
- CHARPOS (tlendpos
)
8731 /* All text outside that line, including its final newline,
8732 must be unchanged */
8733 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8734 CHARPOS (tlendpos
)))
8736 if (CHARPOS (tlbufpos
) > BEGV
8737 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8738 && (CHARPOS (tlbufpos
) == ZV
8739 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8740 /* Former continuation line has disappeared by becoming empty */
8742 else if (XFASTINT (w
->last_modified
) < MODIFF
8743 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8744 || MINI_WINDOW_P (w
))
8746 /* We have to handle the case of continuation around a
8747 wide-column character (See the comment in indent.c around
8750 For instance, in the following case:
8752 -------- Insert --------
8753 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8754 J_I_ ==> J_I_ `^^' are cursors.
8758 As we have to redraw the line above, we should goto cancel. */
8761 int line_height_before
= this_line_pixel_height
;
8763 /* Note that start_display will handle the case that the
8764 line starting at tlbufpos is a continuation lines. */
8765 start_display (&it
, w
, tlbufpos
);
8767 /* Implementation note: It this still necessary? */
8768 if (it
.current_x
!= this_line_start_x
)
8771 TRACE ((stderr
, "trying display optimization 1\n"));
8772 w
->cursor
.vpos
= -1;
8773 overlay_arrow_seen
= 0;
8774 it
.vpos
= this_line_vpos
;
8775 it
.current_y
= this_line_y
;
8776 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8779 /* If line contains point, is not continued,
8780 and ends at same distance from eob as before, we win */
8781 if (w
->cursor
.vpos
>= 0
8782 /* Line is not continued, otherwise this_line_start_pos
8783 would have been set to 0 in display_line. */
8784 && CHARPOS (this_line_start_pos
)
8785 /* Line ends as before. */
8786 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8787 /* Line has same height as before. Otherwise other lines
8788 would have to be shifted up or down. */
8789 && this_line_pixel_height
== line_height_before
)
8791 /* If this is not the window's last line, we must adjust
8792 the charstarts of the lines below. */
8793 if (it
.current_y
< it
.last_visible_y
)
8795 struct glyph_row
*row
8796 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8797 int delta
, delta_bytes
;
8799 if (Z
- CHARPOS (tlendpos
) == ZV
)
8801 /* This line ends at end of (accessible part of)
8802 buffer. There is no newline to count. */
8804 - CHARPOS (tlendpos
)
8805 - MATRIX_ROW_START_CHARPOS (row
));
8806 delta_bytes
= (Z_BYTE
8807 - BYTEPOS (tlendpos
)
8808 - MATRIX_ROW_START_BYTEPOS (row
));
8812 /* This line ends in a newline. Must take
8813 account of the newline and the rest of the
8814 text that follows. */
8816 - CHARPOS (tlendpos
)
8817 - MATRIX_ROW_START_CHARPOS (row
));
8818 delta_bytes
= (Z_BYTE
8819 - BYTEPOS (tlendpos
)
8820 - MATRIX_ROW_START_BYTEPOS (row
));
8823 increment_matrix_positions (w
->current_matrix
,
8825 w
->current_matrix
->nrows
,
8826 delta
, delta_bytes
);
8829 /* If this row displays text now but previously didn't,
8830 or vice versa, w->window_end_vpos may have to be
8832 if ((it
.glyph_row
- 1)->displays_text_p
)
8834 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8835 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8837 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8838 && this_line_vpos
> 0)
8839 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8840 w
->window_end_valid
= Qnil
;
8842 /* Update hint: No need to try to scroll in update_window. */
8843 w
->desired_matrix
->no_scrolling_p
= 1;
8846 *w
->desired_matrix
->method
= 0;
8847 debug_method_add (w
, "optimization 1");
8854 else if (/* Cursor position hasn't changed. */
8855 PT
== XFASTINT (w
->last_point
)
8856 /* Make sure the cursor was last displayed
8857 in this window. Otherwise we have to reposition it. */
8858 && 0 <= w
->cursor
.vpos
8859 && XINT (w
->height
) > w
->cursor
.vpos
)
8863 do_pending_window_change (1);
8865 /* We used to always goto end_of_redisplay here, but this
8866 isn't enough if we have a blinking cursor. */
8867 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8868 goto end_of_redisplay
;
8872 /* If highlighting the region, or if the cursor is in the echo area,
8873 then we can't just move the cursor. */
8874 else if (! (!NILP (Vtransient_mark_mode
)
8875 && !NILP (current_buffer
->mark_active
))
8876 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8877 || highlight_nonselected_windows
)
8878 && NILP (w
->region_showing
)
8879 && NILP (Vshow_trailing_whitespace
)
8880 && !cursor_in_echo_area
)
8883 struct glyph_row
*row
;
8885 /* Skip from tlbufpos to PT and see where it is. Note that
8886 PT may be in invisible text. If so, we will end at the
8887 next visible position. */
8888 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8889 NULL
, DEFAULT_FACE_ID
);
8890 it
.current_x
= this_line_start_x
;
8891 it
.current_y
= this_line_y
;
8892 it
.vpos
= this_line_vpos
;
8894 /* The call to move_it_to stops in front of PT, but
8895 moves over before-strings. */
8896 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8898 if (it
.vpos
== this_line_vpos
8899 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8902 xassert (this_line_vpos
== it
.vpos
);
8903 xassert (this_line_y
== it
.current_y
);
8904 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8906 *w
->desired_matrix
->method
= 0;
8907 debug_method_add (w
, "optimization 3");
8916 /* Text changed drastically or point moved off of line. */
8917 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8920 CHARPOS (this_line_start_pos
) = 0;
8921 consider_all_windows_p
|= buffer_shared
> 1;
8922 ++clear_face_cache_count
;
8925 /* Build desired matrices, and update the display. If
8926 consider_all_windows_p is non-zero, do it for all windows on all
8927 frames. Otherwise do it for selected_window, only. */
8929 if (consider_all_windows_p
)
8931 Lisp_Object tail
, frame
;
8932 int i
, n
= 0, size
= 50;
8933 struct frame
**updated
8934 = (struct frame
**) alloca (size
* sizeof *updated
);
8936 /* Clear the face cache eventually. */
8937 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8939 clear_face_cache (0);
8940 clear_face_cache_count
= 0;
8943 /* Recompute # windows showing selected buffer. This will be
8944 incremented each time such a window is displayed. */
8947 FOR_EACH_FRAME (tail
, frame
)
8949 struct frame
*f
= XFRAME (frame
);
8951 if (FRAME_WINDOW_P (f
) || f
== sf
)
8953 #ifdef HAVE_WINDOW_SYSTEM
8954 if (clear_face_cache_count
% 50 == 0
8955 && FRAME_WINDOW_P (f
))
8956 clear_image_cache (f
, 0);
8957 #endif /* HAVE_WINDOW_SYSTEM */
8959 /* Mark all the scroll bars to be removed; we'll redeem
8960 the ones we want when we redisplay their windows. */
8961 if (condemn_scroll_bars_hook
)
8962 condemn_scroll_bars_hook (f
);
8964 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8965 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8967 /* Any scroll bars which redisplay_windows should have
8968 nuked should now go away. */
8969 if (judge_scroll_bars_hook
)
8970 judge_scroll_bars_hook (f
);
8972 /* If fonts changed, display again. */
8973 if (fonts_changed_p
)
8976 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8978 /* See if we have to hscroll. */
8979 if (hscroll_windows (f
->root_window
))
8982 /* Prevent various kinds of signals during display
8983 update. stdio is not robust about handling
8984 signals, which can cause an apparent I/O
8986 if (interrupt_input
)
8990 /* Update the display. */
8991 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8992 pause
|= update_frame (f
, 0, 0);
8998 int nbytes
= size
* sizeof *updated
;
8999 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
9000 bcopy (updated
, p
, nbytes
);
9009 /* Do the mark_window_display_accurate after all windows have
9010 been redisplayed because this call resets flags in buffers
9011 which are needed for proper redisplay. */
9012 for (i
= 0; i
< n
; ++i
)
9014 struct frame
*f
= updated
[i
];
9015 mark_window_display_accurate (f
->root_window
, 1);
9016 if (frame_up_to_date_hook
)
9017 frame_up_to_date_hook (f
);
9020 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9022 Lisp_Object mini_window
;
9023 struct frame
*mini_frame
;
9025 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9026 /* Use list_of_error, not Qerror, so that
9027 we catch only errors and don't run the debugger. */
9028 internal_condition_case_1 (redisplay_window_1
, selected_window
,
9030 redisplay_window_error
);
9032 /* Compare desired and current matrices, perform output. */
9035 /* If fonts changed, display again. */
9036 if (fonts_changed_p
)
9039 /* Prevent various kinds of signals during display update.
9040 stdio is not robust about handling signals,
9041 which can cause an apparent I/O error. */
9042 if (interrupt_input
)
9046 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9048 if (hscroll_windows (selected_window
))
9051 XWINDOW (selected_window
)->must_be_updated_p
= 1;
9052 pause
= update_frame (sf
, 0, 0);
9055 /* We may have called echo_area_display at the top of this
9056 function. If the echo area is on another frame, that may
9057 have put text on a frame other than the selected one, so the
9058 above call to update_frame would not have caught it. Catch
9060 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9061 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9063 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
9065 XWINDOW (mini_window
)->must_be_updated_p
= 1;
9066 pause
|= update_frame (mini_frame
, 0, 0);
9067 if (!pause
&& hscroll_windows (mini_window
))
9072 /* If display was paused because of pending input, make sure we do a
9073 thorough update the next time. */
9076 /* Prevent the optimization at the beginning of
9077 redisplay_internal that tries a single-line update of the
9078 line containing the cursor in the selected window. */
9079 CHARPOS (this_line_start_pos
) = 0;
9081 /* Let the overlay arrow be updated the next time. */
9082 if (!NILP (last_arrow_position
))
9084 last_arrow_position
= Qt
;
9085 last_arrow_string
= Qt
;
9088 /* If we pause after scrolling, some rows in the current
9089 matrices of some windows are not valid. */
9090 if (!WINDOW_FULL_WIDTH_P (w
)
9091 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
9092 update_mode_lines
= 1;
9096 if (!consider_all_windows_p
)
9098 /* This has already been done above if
9099 consider_all_windows_p is set. */
9100 mark_window_display_accurate_1 (w
, 1);
9102 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9103 last_arrow_string
= Voverlay_arrow_string
;
9105 if (frame_up_to_date_hook
!= 0)
9106 frame_up_to_date_hook (sf
);
9109 update_mode_lines
= 0;
9110 windows_or_buffers_changed
= 0;
9111 cursor_type_changed
= 0;
9114 /* Start SIGIO interrupts coming again. Having them off during the
9115 code above makes it less likely one will discard output, but not
9116 impossible, since there might be stuff in the system buffer here.
9117 But it is much hairier to try to do anything about that. */
9118 if (interrupt_input
)
9122 /* If a frame has become visible which was not before, redisplay
9123 again, so that we display it. Expose events for such a frame
9124 (which it gets when becoming visible) don't call the parts of
9125 redisplay constructing glyphs, so simply exposing a frame won't
9126 display anything in this case. So, we have to display these
9127 frames here explicitly. */
9130 Lisp_Object tail
, frame
;
9133 FOR_EACH_FRAME (tail
, frame
)
9135 int this_is_visible
= 0;
9137 if (XFRAME (frame
)->visible
)
9138 this_is_visible
= 1;
9139 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
9140 if (XFRAME (frame
)->visible
)
9141 this_is_visible
= 1;
9143 if (this_is_visible
)
9147 if (new_count
!= number_of_visible_frames
)
9148 windows_or_buffers_changed
++;
9151 /* Change frame size now if a change is pending. */
9152 do_pending_window_change (1);
9154 /* If we just did a pending size change, or have additional
9155 visible frames, redisplay again. */
9156 if (windows_or_buffers_changed
&& !pause
)
9160 unbind_to (count
, Qnil
);
9164 /* Redisplay, but leave alone any recent echo area message unless
9165 another message has been requested in its place.
9167 This is useful in situations where you need to redisplay but no
9168 user action has occurred, making it inappropriate for the message
9169 area to be cleared. See tracking_off and
9170 wait_reading_process_input for examples of these situations.
9172 FROM_WHERE is an integer saying from where this function was
9173 called. This is useful for debugging. */
9176 redisplay_preserve_echo_area (from_where
)
9179 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9181 if (!NILP (echo_area_buffer
[1]))
9183 /* We have a previously displayed message, but no current
9184 message. Redisplay the previous message. */
9185 display_last_displayed_message_p
= 1;
9186 redisplay_internal (1);
9187 display_last_displayed_message_p
= 0;
9190 redisplay_internal (1);
9194 /* Function registered with record_unwind_protect in
9195 redisplay_internal. Reset redisplaying_p to the value it had
9196 before redisplay_internal was called, and clear
9197 prevent_freeing_realized_faces_p. */
9200 unwind_redisplay (old_redisplaying_p
)
9201 Lisp_Object old_redisplaying_p
;
9203 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9208 /* Mark the display of window W as accurate or inaccurate. If
9209 ACCURATE_P is non-zero mark display of W as accurate. If
9210 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9211 redisplay_internal is called. */
9214 mark_window_display_accurate_1 (w
, accurate_p
)
9218 if (BUFFERP (w
->buffer
))
9220 struct buffer
*b
= XBUFFER (w
->buffer
);
9223 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9224 w
->last_overlay_modified
9225 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9227 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9231 b
->clip_changed
= 0;
9232 b
->prevent_redisplay_optimizations_p
= 0;
9234 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9235 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9236 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9237 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9239 w
->current_matrix
->buffer
= b
;
9240 w
->current_matrix
->begv
= BUF_BEGV (b
);
9241 w
->current_matrix
->zv
= BUF_ZV (b
);
9243 w
->last_cursor
= w
->cursor
;
9244 w
->last_cursor_off_p
= w
->cursor_off_p
;
9246 if (w
== XWINDOW (selected_window
))
9247 w
->last_point
= make_number (BUF_PT (b
));
9249 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9255 w
->window_end_valid
= w
->buffer
;
9256 #if 0 /* This is incorrect with variable-height lines. */
9257 xassert (XINT (w
->window_end_vpos
)
9259 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9261 w
->update_mode_line
= Qnil
;
9266 /* Mark the display of windows in the window tree rooted at WINDOW as
9267 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9268 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9269 be redisplayed the next time redisplay_internal is called. */
9272 mark_window_display_accurate (window
, accurate_p
)
9278 for (; !NILP (window
); window
= w
->next
)
9280 w
= XWINDOW (window
);
9281 mark_window_display_accurate_1 (w
, accurate_p
);
9283 if (!NILP (w
->vchild
))
9284 mark_window_display_accurate (w
->vchild
, accurate_p
);
9285 if (!NILP (w
->hchild
))
9286 mark_window_display_accurate (w
->hchild
, accurate_p
);
9291 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9292 last_arrow_string
= Voverlay_arrow_string
;
9296 /* Force a thorough redisplay the next time by setting
9297 last_arrow_position and last_arrow_string to t, which is
9298 unequal to any useful value of Voverlay_arrow_... */
9299 last_arrow_position
= Qt
;
9300 last_arrow_string
= Qt
;
9305 /* Return value in display table DP (Lisp_Char_Table *) for character
9306 C. Since a display table doesn't have any parent, we don't have to
9307 follow parent. Do not call this function directly but use the
9308 macro DISP_CHAR_VECTOR. */
9311 disp_char_vector (dp
, c
)
9312 struct Lisp_Char_Table
*dp
;
9318 if (SINGLE_BYTE_CHAR_P (c
))
9319 return (dp
->contents
[c
]);
9321 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9324 else if (code
[2] < 32)
9327 /* Here, the possible range of code[0] (== charset ID) is
9328 128..max_charset. Since the top level char table contains data
9329 for multibyte characters after 256th element, we must increment
9330 code[0] by 128 to get a correct index. */
9332 code
[3] = -1; /* anchor */
9334 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9336 val
= dp
->contents
[code
[i
]];
9337 if (!SUB_CHAR_TABLE_P (val
))
9338 return (NILP (val
) ? dp
->defalt
: val
);
9341 /* Here, val is a sub char table. We return the default value of
9343 return (dp
->defalt
);
9348 /***********************************************************************
9350 ***********************************************************************/
9352 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9355 redisplay_windows (window
)
9358 while (!NILP (window
))
9360 struct window
*w
= XWINDOW (window
);
9362 if (!NILP (w
->hchild
))
9363 redisplay_windows (w
->hchild
);
9364 else if (!NILP (w
->vchild
))
9365 redisplay_windows (w
->vchild
);
9368 displayed_buffer
= XBUFFER (w
->buffer
);
9369 /* Use list_of_error, not Qerror, so that
9370 we catch only errors and don't run the debugger. */
9371 internal_condition_case_1 (redisplay_window_0
, window
,
9373 redisplay_window_error
);
9381 redisplay_window_error ()
9383 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
9388 redisplay_window_0 (window
)
9391 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9392 redisplay_window (window
, 0);
9397 redisplay_window_1 (window
)
9400 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9401 redisplay_window (window
, 1);
9405 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9406 DELTA is the number of bytes by which positions recorded in ROW
9407 differ from current buffer positions. */
9410 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9412 struct glyph_row
*row
;
9413 struct glyph_matrix
*matrix
;
9414 int delta
, delta_bytes
, dy
, dvpos
;
9416 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9417 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9419 int pt_old
= PT
- delta
;
9421 /* Skip over glyphs not having an object at the start of the row.
9422 These are special glyphs like truncation marks on terminal
9424 if (row
->displays_text_p
)
9426 && INTEGERP (glyph
->object
)
9427 && glyph
->charpos
< 0)
9429 x
+= glyph
->pixel_width
;
9434 && !INTEGERP (glyph
->object
)
9435 && (!BUFFERP (glyph
->object
)
9436 || glyph
->charpos
< pt_old
))
9438 x
+= glyph
->pixel_width
;
9442 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9444 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9445 w
->cursor
.y
= row
->y
+ dy
;
9447 if (w
== XWINDOW (selected_window
))
9449 if (!row
->continued_p
9450 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9453 this_line_buffer
= XBUFFER (w
->buffer
);
9455 CHARPOS (this_line_start_pos
)
9456 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9457 BYTEPOS (this_line_start_pos
)
9458 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9460 CHARPOS (this_line_end_pos
)
9461 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9462 BYTEPOS (this_line_end_pos
)
9463 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9465 this_line_y
= w
->cursor
.y
;
9466 this_line_pixel_height
= row
->height
;
9467 this_line_vpos
= w
->cursor
.vpos
;
9468 this_line_start_x
= row
->x
;
9471 CHARPOS (this_line_start_pos
) = 0;
9476 /* Run window scroll functions, if any, for WINDOW with new window
9477 start STARTP. Sets the window start of WINDOW to that position.
9479 We assume that the window's buffer is really current. */
9481 static INLINE
struct text_pos
9482 run_window_scroll_functions (window
, startp
)
9484 struct text_pos startp
;
9486 struct window
*w
= XWINDOW (window
);
9487 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9489 if (current_buffer
!= XBUFFER (w
->buffer
))
9492 if (!NILP (Vwindow_scroll_functions
))
9494 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9495 make_number (CHARPOS (startp
)));
9496 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9497 /* In case the hook functions switch buffers. */
9498 if (current_buffer
!= XBUFFER (w
->buffer
))
9499 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9506 /* Make sure the line containing the cursor is fully visible.
9507 A value of 1 means there is nothing to be done.
9508 (Either the line is fully visible, or it cannot be made so,
9510 A value of 0 means the caller should do scrolling
9511 as if point had gone off the screen. */
9514 make_cursor_line_fully_visible (w
)
9517 struct glyph_matrix
*matrix
;
9518 struct glyph_row
*row
;
9521 /* It's not always possible to find the cursor, e.g, when a window
9522 is full of overlay strings. Don't do anything in that case. */
9523 if (w
->cursor
.vpos
< 0)
9526 matrix
= w
->desired_matrix
;
9527 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9529 /* If the cursor row is not partially visible, there's nothing to do. */
9530 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9533 /* If the row the cursor is in is taller than the window's height,
9534 it's not clear what to do, so do nothing. */
9535 window_height
= window_box_height (w
);
9536 if (row
->height
>= window_height
)
9542 /* This code used to try to scroll the window just enough to make
9543 the line visible. It returned 0 to say that the caller should
9544 allocate larger glyph matrices. */
9546 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9548 int dy
= row
->height
- row
->visible_height
;
9551 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9553 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9555 int dy
= - (row
->height
- row
->visible_height
);
9558 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9561 /* When we change the cursor y-position of the selected window,
9562 change this_line_y as well so that the display optimization for
9563 the cursor line of the selected window in redisplay_internal uses
9564 the correct y-position. */
9565 if (w
== XWINDOW (selected_window
))
9566 this_line_y
= w
->cursor
.y
;
9568 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9569 redisplay with larger matrices. */
9570 if (matrix
->nrows
< required_matrix_height (w
))
9572 fonts_changed_p
= 1;
9581 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9582 non-zero means only WINDOW is redisplayed in redisplay_internal.
9583 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9584 in redisplay_window to bring a partially visible line into view in
9585 the case that only the cursor has moved.
9589 1 if scrolling succeeded
9591 0 if scrolling didn't find point.
9593 -1 if new fonts have been loaded so that we must interrupt
9594 redisplay, adjust glyph matrices, and try again. */
9600 SCROLLING_NEED_LARGER_MATRICES
9604 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9605 scroll_step
, temp_scroll_step
)
9607 int just_this_one_p
;
9608 EMACS_INT scroll_conservatively
, scroll_step
;
9609 int temp_scroll_step
;
9611 struct window
*w
= XWINDOW (window
);
9612 struct frame
*f
= XFRAME (w
->frame
);
9613 struct text_pos scroll_margin_pos
;
9614 struct text_pos pos
;
9615 struct text_pos startp
;
9617 Lisp_Object window_end
;
9618 int this_scroll_margin
;
9622 int amount_to_scroll
= 0;
9623 Lisp_Object aggressive
;
9627 debug_method_add (w
, "try_scrolling");
9630 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9632 /* Compute scroll margin height in pixels. We scroll when point is
9633 within this distance from the top or bottom of the window. */
9634 if (scroll_margin
> 0)
9636 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9637 this_scroll_margin
*= CANON_Y_UNIT (f
);
9640 this_scroll_margin
= 0;
9642 /* Compute how much we should try to scroll maximally to bring point
9644 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9645 scroll_max
= max (scroll_step
,
9646 max (scroll_conservatively
, temp_scroll_step
));
9647 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9648 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9649 /* We're trying to scroll because of aggressive scrolling
9650 but no scroll_step is set. Choose an arbitrary one. Maybe
9651 there should be a variable for this. */
9655 scroll_max
*= CANON_Y_UNIT (f
);
9657 /* Decide whether we have to scroll down. Start at the window end
9658 and move this_scroll_margin up to find the position of the scroll
9660 window_end
= Fwindow_end (window
, Qt
);
9661 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9662 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9663 if (this_scroll_margin
)
9665 start_display (&it
, w
, scroll_margin_pos
);
9666 move_it_vertically (&it
, - this_scroll_margin
);
9667 scroll_margin_pos
= it
.current
.pos
;
9670 if (PT
>= CHARPOS (scroll_margin_pos
))
9675 /* Point is in the scroll margin at the bottom of the window, or
9676 below. Compute a new window start that makes point visible. */
9678 /* Compute the distance from the scroll margin to PT.
9679 Give up if the distance is greater than scroll_max. */
9680 start_display (&it
, w
, scroll_margin_pos
);
9682 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9683 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9685 /* To make point visible, we have to move the window start
9686 down so that the line the cursor is in is visible, which
9687 means we have to add in the height of the cursor line. */
9688 dy
= line_bottom_y (&it
) - y0
;
9690 if (dy
> scroll_max
)
9691 return SCROLLING_FAILED
;
9693 /* Move the window start down. If scrolling conservatively,
9694 move it just enough down to make point visible. If
9695 scroll_step is set, move it down by scroll_step. */
9696 start_display (&it
, w
, startp
);
9698 if (scroll_conservatively
)
9700 = max (max (dy
, CANON_Y_UNIT (f
)),
9701 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9702 else if (scroll_step
|| temp_scroll_step
)
9703 amount_to_scroll
= scroll_max
;
9706 aggressive
= current_buffer
->scroll_up_aggressively
;
9707 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9708 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9709 if (NUMBERP (aggressive
))
9710 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9713 if (amount_to_scroll
<= 0)
9714 return SCROLLING_FAILED
;
9716 move_it_vertically (&it
, amount_to_scroll
);
9717 startp
= it
.current
.pos
;
9721 /* See if point is inside the scroll margin at the top of the
9723 scroll_margin_pos
= startp
;
9724 if (this_scroll_margin
)
9726 start_display (&it
, w
, startp
);
9727 move_it_vertically (&it
, this_scroll_margin
);
9728 scroll_margin_pos
= it
.current
.pos
;
9731 if (PT
< CHARPOS (scroll_margin_pos
))
9733 /* Point is in the scroll margin at the top of the window or
9734 above what is displayed in the window. */
9737 /* Compute the vertical distance from PT to the scroll
9738 margin position. Give up if distance is greater than
9740 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9741 start_display (&it
, w
, pos
);
9743 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9744 it
.last_visible_y
, -1,
9745 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9746 dy
= it
.current_y
- y0
;
9747 if (dy
> scroll_max
)
9748 return SCROLLING_FAILED
;
9750 /* Compute new window start. */
9751 start_display (&it
, w
, startp
);
9753 if (scroll_conservatively
)
9755 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9756 else if (scroll_step
|| temp_scroll_step
)
9757 amount_to_scroll
= scroll_max
;
9760 aggressive
= current_buffer
->scroll_down_aggressively
;
9761 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9762 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9763 if (NUMBERP (aggressive
))
9764 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9767 if (amount_to_scroll
<= 0)
9768 return SCROLLING_FAILED
;
9770 move_it_vertically (&it
, - amount_to_scroll
);
9771 startp
= it
.current
.pos
;
9775 /* Run window scroll functions. */
9776 startp
= run_window_scroll_functions (window
, startp
);
9778 /* Display the window. Give up if new fonts are loaded, or if point
9780 if (!try_window (window
, startp
))
9781 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9782 else if (w
->cursor
.vpos
< 0)
9784 clear_glyph_matrix (w
->desired_matrix
);
9785 rc
= SCROLLING_FAILED
;
9789 /* Maybe forget recorded base line for line number display. */
9790 if (!just_this_one_p
9791 || current_buffer
->clip_changed
9792 || BEG_UNCHANGED
< CHARPOS (startp
))
9793 w
->base_line_number
= Qnil
;
9795 /* If cursor ends up on a partially visible line,
9796 treat that as being off the bottom of the screen. */
9797 if (! make_cursor_line_fully_visible (w
))
9799 rc
= SCROLLING_SUCCESS
;
9806 /* Compute a suitable window start for window W if display of W starts
9807 on a continuation line. Value is non-zero if a new window start
9810 The new window start will be computed, based on W's width, starting
9811 from the start of the continued line. It is the start of the
9812 screen line with the minimum distance from the old start W->start. */
9815 compute_window_start_on_continuation_line (w
)
9818 struct text_pos pos
, start_pos
;
9819 int window_start_changed_p
= 0;
9821 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9823 /* If window start is on a continuation line... Window start may be
9824 < BEGV in case there's invisible text at the start of the
9825 buffer (M-x rmail, for example). */
9826 if (CHARPOS (start_pos
) > BEGV
9827 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9830 struct glyph_row
*row
;
9832 /* Handle the case that the window start is out of range. */
9833 if (CHARPOS (start_pos
) < BEGV
)
9834 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9835 else if (CHARPOS (start_pos
) > ZV
)
9836 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9838 /* Find the start of the continued line. This should be fast
9839 because scan_buffer is fast (newline cache). */
9840 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9841 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9842 row
, DEFAULT_FACE_ID
);
9843 reseat_at_previous_visible_line_start (&it
);
9845 /* If the line start is "too far" away from the window start,
9846 say it takes too much time to compute a new window start. */
9847 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9848 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9850 int min_distance
, distance
;
9852 /* Move forward by display lines to find the new window
9853 start. If window width was enlarged, the new start can
9854 be expected to be > the old start. If window width was
9855 decreased, the new window start will be < the old start.
9856 So, we're looking for the display line start with the
9857 minimum distance from the old window start. */
9858 pos
= it
.current
.pos
;
9859 min_distance
= INFINITY
;
9860 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9861 distance
< min_distance
)
9863 min_distance
= distance
;
9864 pos
= it
.current
.pos
;
9865 move_it_by_lines (&it
, 1, 0);
9868 /* Set the window start there. */
9869 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9870 window_start_changed_p
= 1;
9874 return window_start_changed_p
;
9878 /* Try cursor movement in case text has not changed in window WINDOW,
9879 with window start STARTP. Value is
9881 CURSOR_MOVEMENT_SUCCESS if successful
9883 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
9885 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
9886 display. *SCROLL_STEP is set to 1, under certain circumstances, if
9887 we want to scroll as if scroll-step were set to 1. See the code.
9889 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
9890 which case we have to abort this redisplay, and adjust matrices
9895 CURSOR_MOVEMENT_SUCCESS
,
9896 CURSOR_MOVEMENT_CANNOT_BE_USED
,
9897 CURSOR_MOVEMENT_MUST_SCROLL
,
9898 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
9902 try_cursor_movement (window
, startp
, scroll_step
)
9904 struct text_pos startp
;
9907 struct window
*w
= XWINDOW (window
);
9908 struct frame
*f
= XFRAME (w
->frame
);
9909 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
9912 if (inhibit_try_cursor_movement
)
9916 /* Handle case where text has not changed, only point, and it has
9917 not moved off the frame. */
9918 if (/* Point may be in this window. */
9919 PT
>= CHARPOS (startp
)
9920 /* Selective display hasn't changed. */
9921 && !current_buffer
->clip_changed
9922 /* Function force-mode-line-update is used to force a thorough
9923 redisplay. It sets either windows_or_buffers_changed or
9924 update_mode_lines. So don't take a shortcut here for these
9926 && !update_mode_lines
9927 && !windows_or_buffers_changed
9928 && !cursor_type_changed
9929 /* Can't use this case if highlighting a region. When a
9930 region exists, cursor movement has to do more than just
9932 && !(!NILP (Vtransient_mark_mode
)
9933 && !NILP (current_buffer
->mark_active
))
9934 && NILP (w
->region_showing
)
9935 && NILP (Vshow_trailing_whitespace
)
9936 /* Right after splitting windows, last_point may be nil. */
9937 && INTEGERP (w
->last_point
)
9938 /* This code is not used for mini-buffer for the sake of the case
9939 of redisplaying to replace an echo area message; since in
9940 that case the mini-buffer contents per se are usually
9941 unchanged. This code is of no real use in the mini-buffer
9942 since the handling of this_line_start_pos, etc., in redisplay
9943 handles the same cases. */
9944 && !EQ (window
, minibuf_window
)
9945 /* When splitting windows or for new windows, it happens that
9946 redisplay is called with a nil window_end_vpos or one being
9947 larger than the window. This should really be fixed in
9948 window.c. I don't have this on my list, now, so we do
9949 approximately the same as the old redisplay code. --gerd. */
9950 && INTEGERP (w
->window_end_vpos
)
9951 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9952 && (FRAME_WINDOW_P (f
)
9953 || !MARKERP (Voverlay_arrow_position
)
9954 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9956 int this_scroll_margin
;
9957 struct glyph_row
*row
= NULL
;
9960 debug_method_add (w
, "cursor movement");
9963 /* Scroll if point within this distance from the top or bottom
9964 of the window. This is a pixel value. */
9965 this_scroll_margin
= max (0, scroll_margin
);
9966 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9967 this_scroll_margin
*= CANON_Y_UNIT (f
);
9969 /* Start with the row the cursor was displayed during the last
9970 not paused redisplay. Give up if that row is not valid. */
9971 if (w
->last_cursor
.vpos
< 0
9972 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9973 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9976 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9977 if (row
->mode_line_p
)
9979 if (!row
->enabled_p
)
9980 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9983 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
9986 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9988 if (PT
> XFASTINT (w
->last_point
))
9990 /* Point has moved forward. */
9991 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9992 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9994 xassert (row
->enabled_p
);
9998 /* The end position of a row equals the start position
9999 of the next row. If PT is there, we would rather
10000 display it in the next line. */
10001 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
10002 && MATRIX_ROW_END_CHARPOS (row
) == PT
10003 && !cursor_row_p (w
, row
))
10006 /* If within the scroll margin, scroll. Note that
10007 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
10008 the next line would be drawn, and that
10009 this_scroll_margin can be zero. */
10010 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
10011 || PT
> MATRIX_ROW_END_CHARPOS (row
)
10012 /* Line is completely visible last line in window
10013 and PT is to be set in the next line. */
10014 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
10015 && PT
== MATRIX_ROW_END_CHARPOS (row
)
10016 && !row
->ends_at_zv_p
10017 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
10020 else if (PT
< XFASTINT (w
->last_point
))
10022 /* Cursor has to be moved backward. Note that PT >=
10023 CHARPOS (startp) because of the outer
10025 while (!row
->mode_line_p
10026 && (MATRIX_ROW_START_CHARPOS (row
) > PT
10027 || (MATRIX_ROW_START_CHARPOS (row
) == PT
10028 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
10029 && (row
->y
> this_scroll_margin
10030 || CHARPOS (startp
) == BEGV
))
10032 xassert (row
->enabled_p
);
10036 /* Consider the following case: Window starts at BEGV,
10037 there is invisible, intangible text at BEGV, so that
10038 display starts at some point START > BEGV. It can
10039 happen that we are called with PT somewhere between
10040 BEGV and START. Try to handle that case. */
10041 if (row
< w
->current_matrix
->rows
10042 || row
->mode_line_p
)
10044 row
= w
->current_matrix
->rows
;
10045 if (row
->mode_line_p
)
10049 /* Due to newlines in overlay strings, we may have to
10050 skip forward over overlay strings. */
10051 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
10052 && MATRIX_ROW_END_CHARPOS (row
) == PT
10053 && !cursor_row_p (w
, row
))
10056 /* If within the scroll margin, scroll. */
10057 if (row
->y
< this_scroll_margin
10058 && CHARPOS (startp
) != BEGV
)
10062 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
10063 || PT
> MATRIX_ROW_END_CHARPOS (row
))
10065 /* if PT is not in the glyph row, give up. */
10066 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10068 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10070 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
10071 && !row
->ends_at_zv_p
10072 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
10073 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10074 else if (row
->height
> window_box_height (w
))
10076 /* If we end up in a partially visible line, let's
10077 make it fully visible, except when it's taller
10078 than the window, in which case we can't do much
10081 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10085 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10086 try_window (window
, startp
);
10087 if (!make_cursor_line_fully_visible (w
))
10088 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10090 rc
= CURSOR_MOVEMENT_SUCCESS
;
10094 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10097 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10098 rc
= CURSOR_MOVEMENT_SUCCESS
;
10107 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
10108 selected_window is redisplayed. */
10111 redisplay_window (window
, just_this_one_p
)
10112 Lisp_Object window
;
10113 int just_this_one_p
;
10115 struct window
*w
= XWINDOW (window
);
10116 struct frame
*f
= XFRAME (w
->frame
);
10117 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10118 struct buffer
*old
= current_buffer
;
10119 struct text_pos lpoint
, opoint
, startp
;
10120 int update_mode_line
;
10123 /* Record it now because it's overwritten. */
10124 int current_matrix_up_to_date_p
= 0;
10125 /* This is less strict than current_matrix_up_to_date_p.
10126 It indictes that the buffer contents and narrowing are unchanged. */
10127 int buffer_unchanged_p
= 0;
10128 int temp_scroll_step
= 0;
10129 int count
= SPECPDL_INDEX ();
10131 int centering_position
;
10133 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10136 /* W must be a leaf window here. */
10137 xassert (!NILP (w
->buffer
));
10139 *w
->desired_matrix
->method
= 0;
10142 specbind (Qinhibit_point_motion_hooks
, Qt
);
10144 reconsider_clip_changes (w
, buffer
);
10146 /* Has the mode line to be updated? */
10147 update_mode_line
= (!NILP (w
->update_mode_line
)
10148 || update_mode_lines
10149 || buffer
->clip_changed
10150 || buffer
->prevent_redisplay_optimizations_p
);
10152 if (MINI_WINDOW_P (w
))
10154 if (w
== XWINDOW (echo_area_window
)
10155 && !NILP (echo_area_buffer
[0]))
10157 if (update_mode_line
)
10158 /* We may have to update a tty frame's menu bar or a
10159 tool-bar. Example `M-x C-h C-h C-g'. */
10160 goto finish_menu_bars
;
10162 /* We've already displayed the echo area glyphs in this window. */
10163 goto finish_scroll_bars
;
10165 else if (w
!= XWINDOW (minibuf_window
))
10167 /* W is a mini-buffer window, but it's not the currently
10168 active one, so clear it. */
10169 int yb
= window_text_bottom_y (w
);
10170 struct glyph_row
*row
;
10173 for (y
= 0, row
= w
->desired_matrix
->rows
;
10175 y
+= row
->height
, ++row
)
10176 blank_row (w
, row
, y
);
10177 goto finish_scroll_bars
;
10180 clear_glyph_matrix (w
->desired_matrix
);
10183 /* Otherwise set up data on this window; select its buffer and point
10185 /* Really select the buffer, for the sake of buffer-local
10187 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10188 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
10190 current_matrix_up_to_date_p
10191 = (!NILP (w
->window_end_valid
)
10192 && !current_buffer
->clip_changed
10193 && !current_buffer
->prevent_redisplay_optimizations_p
10194 && XFASTINT (w
->last_modified
) >= MODIFF
10195 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10198 = (!NILP (w
->window_end_valid
)
10199 && !current_buffer
->clip_changed
10200 && XFASTINT (w
->last_modified
) >= MODIFF
10201 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10203 /* When windows_or_buffers_changed is non-zero, we can't rely on
10204 the window end being valid, so set it to nil there. */
10205 if (windows_or_buffers_changed
)
10207 /* If window starts on a continuation line, maybe adjust the
10208 window start in case the window's width changed. */
10209 if (XMARKER (w
->start
)->buffer
== current_buffer
)
10210 compute_window_start_on_continuation_line (w
);
10212 w
->window_end_valid
= Qnil
;
10215 /* Some sanity checks. */
10216 CHECK_WINDOW_END (w
);
10217 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
10219 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
10222 /* If %c is in mode line, update it if needed. */
10223 if (!NILP (w
->column_number_displayed
)
10224 /* This alternative quickly identifies a common case
10225 where no change is needed. */
10226 && !(PT
== XFASTINT (w
->last_point
)
10227 && XFASTINT (w
->last_modified
) >= MODIFF
10228 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10229 && (XFASTINT (w
->column_number_displayed
)
10230 != (int) current_column ())) /* iftc */
10231 update_mode_line
= 1;
10233 /* Count number of windows showing the selected buffer. An indirect
10234 buffer counts as its base buffer. */
10235 if (!just_this_one_p
)
10237 struct buffer
*current_base
, *window_base
;
10238 current_base
= current_buffer
;
10239 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10240 if (current_base
->base_buffer
)
10241 current_base
= current_base
->base_buffer
;
10242 if (window_base
->base_buffer
)
10243 window_base
= window_base
->base_buffer
;
10244 if (current_base
== window_base
)
10248 /* Point refers normally to the selected window. For any other
10249 window, set up appropriate value. */
10250 if (!EQ (window
, selected_window
))
10252 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10253 int new_pt_byte
= marker_byte_position (w
->pointm
);
10257 new_pt_byte
= BEGV_BYTE
;
10258 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10260 else if (new_pt
> (ZV
- 1))
10263 new_pt_byte
= ZV_BYTE
;
10264 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10267 /* We don't use SET_PT so that the point-motion hooks don't run. */
10268 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10271 /* If any of the character widths specified in the display table
10272 have changed, invalidate the width run cache. It's true that
10273 this may be a bit late to catch such changes, but the rest of
10274 redisplay goes (non-fatally) haywire when the display table is
10275 changed, so why should we worry about doing any better? */
10276 if (current_buffer
->width_run_cache
)
10278 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10280 if (! disptab_matches_widthtab (disptab
,
10281 XVECTOR (current_buffer
->width_table
)))
10283 invalidate_region_cache (current_buffer
,
10284 current_buffer
->width_run_cache
,
10286 recompute_width_table (current_buffer
, disptab
);
10290 /* If window-start is screwed up, choose a new one. */
10291 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10294 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10296 /* If someone specified a new starting point but did not insist,
10297 check whether it can be used. */
10298 if (!NILP (w
->optional_new_start
)
10299 && CHARPOS (startp
) >= BEGV
10300 && CHARPOS (startp
) <= ZV
)
10302 w
->optional_new_start
= Qnil
;
10303 start_display (&it
, w
, startp
);
10304 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10305 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10306 if (IT_CHARPOS (it
) == PT
)
10307 w
->force_start
= Qt
;
10310 /* Handle case where place to start displaying has been specified,
10311 unless the specified location is outside the accessible range. */
10312 if (!NILP (w
->force_start
)
10313 || w
->frozen_window_start_p
)
10315 w
->force_start
= Qnil
;
10317 w
->window_end_valid
= Qnil
;
10319 /* Forget any recorded base line for line number display. */
10320 if (!buffer_unchanged_p
)
10321 w
->base_line_number
= Qnil
;
10323 /* Redisplay the mode line. Select the buffer properly for that.
10324 Also, run the hook window-scroll-functions
10325 because we have scrolled. */
10326 /* Note, we do this after clearing force_start because
10327 if there's an error, it is better to forget about force_start
10328 than to get into an infinite loop calling the hook functions
10329 and having them get more errors. */
10330 if (!update_mode_line
10331 || ! NILP (Vwindow_scroll_functions
))
10333 update_mode_line
= 1;
10334 w
->update_mode_line
= Qt
;
10335 startp
= run_window_scroll_functions (window
, startp
);
10338 w
->last_modified
= make_number (0);
10339 w
->last_overlay_modified
= make_number (0);
10340 if (CHARPOS (startp
) < BEGV
)
10341 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10342 else if (CHARPOS (startp
) > ZV
)
10343 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10345 /* Redisplay, then check if cursor has been set during the
10346 redisplay. Give up if new fonts were loaded. */
10347 if (!try_window (window
, startp
))
10349 w
->force_start
= Qt
;
10350 clear_glyph_matrix (w
->desired_matrix
);
10351 goto finish_scroll_bars
;
10354 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10356 /* If point does not appear, try to move point so it does
10357 appear. The desired matrix has been built above, so we
10358 can use it here. */
10360 struct glyph_row
*row
;
10362 window_height
= window_box_height (w
) / 2;
10363 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10364 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
10367 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10368 MATRIX_ROW_START_BYTEPOS (row
));
10370 if (w
!= XWINDOW (selected_window
))
10371 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10372 else if (current_buffer
== old
)
10373 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10375 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10377 /* If we are highlighting the region, then we just changed
10378 the region, so redisplay to show it. */
10379 if (!NILP (Vtransient_mark_mode
)
10380 && !NILP (current_buffer
->mark_active
))
10382 clear_glyph_matrix (w
->desired_matrix
);
10383 if (!try_window (window
, startp
))
10384 goto need_larger_matrices
;
10388 if (!make_cursor_line_fully_visible (w
))
10390 /* CVS rev. 1.761 had changed this to ``goto try_to_scroll''.
10392 The intention of the fix -- AFAIU -- was to ensure that
10393 the cursor didn't end up on a partially visible last (or
10394 first?) line when scrolling.
10397 But that change causes havoc when scrolling backwards and
10398 a partially visible first (or last?) line is present when
10399 we reach the top of the buffer. In effect, the text
10400 already in the window is repeated (each line is appended
10401 to the same or another lines in the window)...
10403 I changed it back to ``goto need_larger_matrices'' which
10404 in effect mean that we don't go through `try_scrolling'
10405 when the cursor is already at the first line of the buffer,
10406 and there is really only a few pixels [rather than lines]
10407 to scroll backwards. I guess move_it_by_lines etc. really
10408 isn't the right device for doing that, ref. the code in
10409 make_cursor_line_fully_visible which was also disabled by
10412 But how do we know that we are already on the top line of
10413 the window showing the first line in the buffer, so that
10414 scrolling really wont help here?
10416 I cannot find a simple fix for this (I tried various
10417 approaches), but I prefer to an occasional partial line
10418 rather than the visual messup, so I reverted this part of
10421 Someone will need to look into this when time allows.
10423 -- 2002-08-22, Kim F. Storm */
10425 goto need_larger_matrices
;
10428 debug_method_add (w
, "forced window start");
10433 /* Handle case where text has not changed, only point, and it has
10434 not moved off the frame, and we are not retrying after hscroll.
10435 (current_matrix_up_to_date_p is nonzero when retrying.) */
10436 if (current_matrix_up_to_date_p
10437 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10438 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10442 case CURSOR_MOVEMENT_SUCCESS
:
10445 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10446 goto need_larger_matrices
;
10448 case CURSOR_MOVEMENT_MUST_SCROLL
:
10449 goto try_to_scroll
;
10455 /* If current starting point was originally the beginning of a line
10456 but no longer is, find a new starting point. */
10457 else if (!NILP (w
->start_at_line_beg
)
10458 && !(CHARPOS (startp
) <= BEGV
10459 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10462 debug_method_add (w
, "recenter 1");
10467 /* Try scrolling with try_window_id. Value is > 0 if update has
10468 been done, it is -1 if we know that the same window start will
10469 not work. It is 0 if unsuccessful for some other reason. */
10470 else if ((tem
= try_window_id (w
)) != 0)
10473 debug_method_add (w
, "try_window_id %d", tem
);
10476 if (fonts_changed_p
)
10477 goto need_larger_matrices
;
10481 /* Otherwise try_window_id has returned -1 which means that we
10482 don't want the alternative below this comment to execute. */
10484 else if (CHARPOS (startp
) >= BEGV
10485 && CHARPOS (startp
) <= ZV
10486 && PT
>= CHARPOS (startp
)
10487 && (CHARPOS (startp
) < ZV
10488 /* Avoid starting at end of buffer. */
10489 || CHARPOS (startp
) == BEGV
10490 || (XFASTINT (w
->last_modified
) >= MODIFF
10491 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10494 debug_method_add (w
, "same window start");
10497 /* Try to redisplay starting at same place as before.
10498 If point has not moved off frame, accept the results. */
10499 if (!current_matrix_up_to_date_p
10500 /* Don't use try_window_reusing_current_matrix in this case
10501 because a window scroll function can have changed the
10503 || !NILP (Vwindow_scroll_functions
)
10504 || MINI_WINDOW_P (w
)
10505 || !try_window_reusing_current_matrix (w
))
10507 IF_DEBUG (debug_method_add (w
, "1"));
10508 try_window (window
, startp
);
10511 if (fonts_changed_p
)
10512 goto need_larger_matrices
;
10514 if (w
->cursor
.vpos
>= 0)
10516 if (!just_this_one_p
10517 || current_buffer
->clip_changed
10518 || BEG_UNCHANGED
< CHARPOS (startp
))
10519 /* Forget any recorded base line for line number display. */
10520 w
->base_line_number
= Qnil
;
10522 if (!make_cursor_line_fully_visible (w
))
10523 /* Drop through and scroll. */
10528 clear_glyph_matrix (w
->desired_matrix
);
10533 w
->last_modified
= make_number (0);
10534 w
->last_overlay_modified
= make_number (0);
10536 /* Redisplay the mode line. Select the buffer properly for that. */
10537 if (!update_mode_line
)
10539 update_mode_line
= 1;
10540 w
->update_mode_line
= Qt
;
10543 /* Try to scroll by specified few lines. */
10544 if ((scroll_conservatively
10546 || temp_scroll_step
10547 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10548 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10549 && !current_buffer
->clip_changed
10550 && CHARPOS (startp
) >= BEGV
10551 && CHARPOS (startp
) <= ZV
)
10553 /* The function returns -1 if new fonts were loaded, 1 if
10554 successful, 0 if not successful. */
10555 int rc
= try_scrolling (window
, just_this_one_p
,
10556 scroll_conservatively
,
10561 case SCROLLING_SUCCESS
:
10564 case SCROLLING_NEED_LARGER_MATRICES
:
10565 goto need_larger_matrices
;
10567 case SCROLLING_FAILED
:
10575 /* Finally, just choose place to start which centers point */
10578 centering_position
= window_box_height (w
) / 2;
10581 /* Jump here with centering_position already set to 0. */
10584 debug_method_add (w
, "recenter");
10587 /* w->vscroll = 0; */
10589 /* Forget any previously recorded base line for line number display. */
10590 if (!buffer_unchanged_p
)
10591 w
->base_line_number
= Qnil
;
10593 /* Move backward half the height of the window. */
10594 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10595 it
.current_y
= it
.last_visible_y
;
10596 move_it_vertically_backward (&it
, centering_position
);
10597 xassert (IT_CHARPOS (it
) >= BEGV
);
10599 /* The function move_it_vertically_backward may move over more
10600 than the specified y-distance. If it->w is small, e.g. a
10601 mini-buffer window, we may end up in front of the window's
10602 display area. Start displaying at the start of the line
10603 containing PT in this case. */
10604 if (it
.current_y
<= 0)
10606 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10607 move_it_vertically (&it
, 0);
10608 xassert (IT_CHARPOS (it
) <= PT
);
10612 it
.current_x
= it
.hpos
= 0;
10614 /* Set startp here explicitly in case that helps avoid an infinite loop
10615 in case the window-scroll-functions functions get errors. */
10616 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10618 /* Run scroll hooks. */
10619 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10621 /* Redisplay the window. */
10622 if (!current_matrix_up_to_date_p
10623 || windows_or_buffers_changed
10624 || cursor_type_changed
10625 /* Don't use try_window_reusing_current_matrix in this case
10626 because it can have changed the buffer. */
10627 || !NILP (Vwindow_scroll_functions
)
10628 || !just_this_one_p
10629 || MINI_WINDOW_P (w
)
10630 || !try_window_reusing_current_matrix (w
))
10631 try_window (window
, startp
);
10633 /* If new fonts have been loaded (due to fontsets), give up. We
10634 have to start a new redisplay since we need to re-adjust glyph
10636 if (fonts_changed_p
)
10637 goto need_larger_matrices
;
10639 /* If cursor did not appear assume that the middle of the window is
10640 in the first line of the window. Do it again with the next line.
10641 (Imagine a window of height 100, displaying two lines of height
10642 60. Moving back 50 from it->last_visible_y will end in the first
10644 if (w
->cursor
.vpos
< 0)
10646 if (!NILP (w
->window_end_valid
)
10647 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10649 clear_glyph_matrix (w
->desired_matrix
);
10650 move_it_by_lines (&it
, 1, 0);
10651 try_window (window
, it
.current
.pos
);
10653 else if (PT
< IT_CHARPOS (it
))
10655 clear_glyph_matrix (w
->desired_matrix
);
10656 move_it_by_lines (&it
, -1, 0);
10657 try_window (window
, it
.current
.pos
);
10661 /* Not much we can do about it. */
10665 /* Consider the following case: Window starts at BEGV, there is
10666 invisible, intangible text at BEGV, so that display starts at
10667 some point START > BEGV. It can happen that we are called with
10668 PT somewhere between BEGV and START. Try to handle that case. */
10669 if (w
->cursor
.vpos
< 0)
10671 struct glyph_row
*row
= w
->current_matrix
->rows
;
10672 if (row
->mode_line_p
)
10674 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10677 if (!make_cursor_line_fully_visible (w
))
10679 /* If centering point failed to make the whole line visible,
10680 put point at the top instead. That has to make the whole line
10681 visible, if it can be done. */
10682 centering_position
= 0;
10688 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10689 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10690 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10693 /* Display the mode line, if we must. */
10694 if ((update_mode_line
10695 /* If window not full width, must redo its mode line
10696 if (a) the window to its side is being redone and
10697 (b) we do a frame-based redisplay. This is a consequence
10698 of how inverted lines are drawn in frame-based redisplay. */
10699 || (!just_this_one_p
10700 && !FRAME_WINDOW_P (f
)
10701 && !WINDOW_FULL_WIDTH_P (w
))
10702 /* Line number to display. */
10703 || INTEGERP (w
->base_line_pos
)
10704 /* Column number is displayed and different from the one displayed. */
10705 || (!NILP (w
->column_number_displayed
)
10706 && (XFASTINT (w
->column_number_displayed
)
10707 != (int) current_column ()))) /* iftc */
10708 /* This means that the window has a mode line. */
10709 && (WINDOW_WANTS_MODELINE_P (w
)
10710 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10712 display_mode_lines (w
);
10714 /* If mode line height has changed, arrange for a thorough
10715 immediate redisplay using the correct mode line height. */
10716 if (WINDOW_WANTS_MODELINE_P (w
)
10717 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10719 fonts_changed_p
= 1;
10720 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10721 = DESIRED_MODE_LINE_HEIGHT (w
);
10724 /* If top line height has changed, arrange for a thorough
10725 immediate redisplay using the correct mode line height. */
10726 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10727 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10729 fonts_changed_p
= 1;
10730 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10731 = DESIRED_HEADER_LINE_HEIGHT (w
);
10734 if (fonts_changed_p
)
10735 goto need_larger_matrices
;
10738 if (!line_number_displayed
10739 && !BUFFERP (w
->base_line_pos
))
10741 w
->base_line_pos
= Qnil
;
10742 w
->base_line_number
= Qnil
;
10747 /* When we reach a frame's selected window, redo the frame's menu bar. */
10748 if (update_mode_line
10749 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10751 int redisplay_menu_p
= 0;
10753 if (FRAME_WINDOW_P (f
))
10755 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS)
10756 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10758 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10762 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10764 if (redisplay_menu_p
)
10765 display_menu_bar (w
);
10767 #ifdef HAVE_WINDOW_SYSTEM
10768 if (WINDOWP (f
->tool_bar_window
)
10769 && (FRAME_TOOL_BAR_LINES (f
) > 0
10770 || auto_resize_tool_bars_p
))
10771 redisplay_tool_bar (f
);
10775 need_larger_matrices
:
10777 finish_scroll_bars
:
10779 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10781 int start
, end
, whole
;
10783 /* Calculate the start and end positions for the current window.
10784 At some point, it would be nice to choose between scrollbars
10785 which reflect the whole buffer size, with special markers
10786 indicating narrowing, and scrollbars which reflect only the
10789 Note that mini-buffers sometimes aren't displaying any text. */
10790 if (!MINI_WINDOW_P (w
)
10791 || (w
== XWINDOW (minibuf_window
)
10792 && NILP (echo_area_buffer
[0])))
10795 start
= marker_position (w
->start
) - BEGV
;
10796 /* I don't think this is guaranteed to be right. For the
10797 moment, we'll pretend it is. */
10798 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10802 if (whole
< (end
- start
))
10803 whole
= end
- start
;
10806 start
= end
= whole
= 0;
10808 /* Indicate what this scroll bar ought to be displaying now. */
10809 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10811 /* Note that we actually used the scroll bar attached to this
10812 window, so it shouldn't be deleted at the end of redisplay. */
10813 redeem_scroll_bar_hook (w
);
10816 /* Restore current_buffer and value of point in it. */
10817 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10818 set_buffer_internal_1 (old
);
10819 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10821 unbind_to (count
, Qnil
);
10825 /* Build the complete desired matrix of WINDOW with a window start
10826 buffer position POS. Value is non-zero if successful. It is zero
10827 if fonts were loaded during redisplay which makes re-adjusting
10828 glyph matrices necessary. */
10831 try_window (window
, pos
)
10832 Lisp_Object window
;
10833 struct text_pos pos
;
10835 struct window
*w
= XWINDOW (window
);
10837 struct glyph_row
*last_text_row
= NULL
;
10839 /* Make POS the new window start. */
10840 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10842 /* Mark cursor position as unknown. No overlay arrow seen. */
10843 w
->cursor
.vpos
= -1;
10844 overlay_arrow_seen
= 0;
10846 /* Initialize iterator and info to start at POS. */
10847 start_display (&it
, w
, pos
);
10849 /* Display all lines of W. */
10850 while (it
.current_y
< it
.last_visible_y
)
10852 if (display_line (&it
))
10853 last_text_row
= it
.glyph_row
- 1;
10854 if (fonts_changed_p
)
10858 /* If bottom moved off end of frame, change mode line percentage. */
10859 if (XFASTINT (w
->window_end_pos
) <= 0
10860 && Z
!= IT_CHARPOS (it
))
10861 w
->update_mode_line
= Qt
;
10863 /* Set window_end_pos to the offset of the last character displayed
10864 on the window from the end of current_buffer. Set
10865 window_end_vpos to its row number. */
10868 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10869 w
->window_end_bytepos
10870 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10872 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10874 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10875 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10876 ->displays_text_p
);
10880 w
->window_end_bytepos
= 0;
10881 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10884 /* But that is not valid info until redisplay finishes. */
10885 w
->window_end_valid
= Qnil
;
10891 /************************************************************************
10892 Window redisplay reusing current matrix when buffer has not changed
10893 ************************************************************************/
10895 /* Try redisplay of window W showing an unchanged buffer with a
10896 different window start than the last time it was displayed by
10897 reusing its current matrix. Value is non-zero if successful.
10898 W->start is the new window start. */
10901 try_window_reusing_current_matrix (w
)
10904 struct frame
*f
= XFRAME (w
->frame
);
10905 struct glyph_row
*row
, *bottom_row
;
10908 struct text_pos start
, new_start
;
10909 int nrows_scrolled
, i
;
10910 struct glyph_row
*last_text_row
;
10911 struct glyph_row
*last_reused_text_row
;
10912 struct glyph_row
*start_row
;
10913 int start_vpos
, min_y
, max_y
;
10916 if (inhibit_try_window_reusing
)
10920 if (/* This function doesn't handle terminal frames. */
10921 !FRAME_WINDOW_P (f
)
10922 /* Don't try to reuse the display if windows have been split
10924 || windows_or_buffers_changed
10925 || cursor_type_changed
)
10928 /* Can't do this if region may have changed. */
10929 if ((!NILP (Vtransient_mark_mode
)
10930 && !NILP (current_buffer
->mark_active
))
10931 || !NILP (w
->region_showing
)
10932 || !NILP (Vshow_trailing_whitespace
))
10935 /* If top-line visibility has changed, give up. */
10936 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10937 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10940 /* Give up if old or new display is scrolled vertically. We could
10941 make this function handle this, but right now it doesn't. */
10942 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10943 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10946 /* The variable new_start now holds the new window start. The old
10947 start `start' can be determined from the current matrix. */
10948 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10949 start
= start_row
->start
.pos
;
10950 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10952 /* Clear the desired matrix for the display below. */
10953 clear_glyph_matrix (w
->desired_matrix
);
10955 if (CHARPOS (new_start
) <= CHARPOS (start
))
10959 /* Don't use this method if the display starts with an ellipsis
10960 displayed for invisible text. It's not easy to handle that case
10961 below, and it's certainly not worth the effort since this is
10962 not a frequent case. */
10963 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10966 IF_DEBUG (debug_method_add (w
, "twu1"));
10968 /* Display up to a row that can be reused. The variable
10969 last_text_row is set to the last row displayed that displays
10970 text. Note that it.vpos == 0 if or if not there is a
10971 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10972 start_display (&it
, w
, new_start
);
10973 first_row_y
= it
.current_y
;
10974 w
->cursor
.vpos
= -1;
10975 last_text_row
= last_reused_text_row
= NULL
;
10977 while (it
.current_y
< it
.last_visible_y
10978 && IT_CHARPOS (it
) < CHARPOS (start
)
10979 && !fonts_changed_p
)
10980 if (display_line (&it
))
10981 last_text_row
= it
.glyph_row
- 1;
10983 /* A value of current_y < last_visible_y means that we stopped
10984 at the previous window start, which in turn means that we
10985 have at least one reusable row. */
10986 if (it
.current_y
< it
.last_visible_y
)
10988 /* IT.vpos always starts from 0; it counts text lines. */
10989 nrows_scrolled
= it
.vpos
;
10991 /* Find PT if not already found in the lines displayed. */
10992 if (w
->cursor
.vpos
< 0)
10994 int dy
= it
.current_y
- first_row_y
;
10996 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10997 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
10999 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
11000 dy
, nrows_scrolled
);
11003 clear_glyph_matrix (w
->desired_matrix
);
11008 /* Scroll the display. Do it before the current matrix is
11009 changed. The problem here is that update has not yet
11010 run, i.e. part of the current matrix is not up to date.
11011 scroll_run_hook will clear the cursor, and use the
11012 current matrix to get the height of the row the cursor is
11014 run
.current_y
= first_row_y
;
11015 run
.desired_y
= it
.current_y
;
11016 run
.height
= it
.last_visible_y
- it
.current_y
;
11018 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
11021 rif
->update_window_begin_hook (w
);
11022 rif
->clear_mouse_face (w
);
11023 rif
->scroll_run_hook (w
, &run
);
11024 rif
->update_window_end_hook (w
, 0, 0);
11028 /* Shift current matrix down by nrows_scrolled lines. */
11029 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11030 rotate_matrix (w
->current_matrix
,
11032 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11035 /* Disable lines that must be updated. */
11036 for (i
= 0; i
< it
.vpos
; ++i
)
11037 (start_row
+ i
)->enabled_p
= 0;
11039 /* Re-compute Y positions. */
11040 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11041 max_y
= it
.last_visible_y
;
11042 for (row
= start_row
+ nrows_scrolled
;
11046 row
->y
= it
.current_y
;
11047 row
->visible_height
= row
->height
;
11049 if (row
->y
< min_y
)
11050 row
->visible_height
-= min_y
- row
->y
;
11051 if (row
->y
+ row
->height
> max_y
)
11052 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11054 it
.current_y
+= row
->height
;
11056 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11057 last_reused_text_row
= row
;
11058 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
11062 /* Disable lines in the current matrix which are now
11063 below the window. */
11064 for (++row
; row
< bottom_row
; ++row
)
11065 row
->enabled_p
= 0;
11068 /* Update window_end_pos etc.; last_reused_text_row is the last
11069 reused row from the current matrix containing text, if any.
11070 The value of last_text_row is the last displayed line
11071 containing text. */
11072 if (last_reused_text_row
)
11074 w
->window_end_bytepos
11075 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
11077 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
11079 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
11080 w
->current_matrix
));
11082 else if (last_text_row
)
11084 w
->window_end_bytepos
11085 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11087 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11089 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11093 /* This window must be completely empty. */
11094 w
->window_end_bytepos
= 0;
11095 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
11097 w
->window_end_valid
= Qnil
;
11099 /* Update hint: don't try scrolling again in update_window. */
11100 w
->desired_matrix
->no_scrolling_p
= 1;
11103 debug_method_add (w
, "try_window_reusing_current_matrix 1");
11107 else if (CHARPOS (new_start
) > CHARPOS (start
))
11109 struct glyph_row
*pt_row
, *row
;
11110 struct glyph_row
*first_reusable_row
;
11111 struct glyph_row
*first_row_to_display
;
11113 int yb
= window_text_bottom_y (w
);
11115 /* Find the row starting at new_start, if there is one. Don't
11116 reuse a partially visible line at the end. */
11117 first_reusable_row
= start_row
;
11118 while (first_reusable_row
->enabled_p
11119 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
11120 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11121 < CHARPOS (new_start
)))
11122 ++first_reusable_row
;
11124 /* Give up if there is no row to reuse. */
11125 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
11126 || !first_reusable_row
->enabled_p
11127 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11128 != CHARPOS (new_start
)))
11131 /* We can reuse fully visible rows beginning with
11132 first_reusable_row to the end of the window. Set
11133 first_row_to_display to the first row that cannot be reused.
11134 Set pt_row to the row containing point, if there is any. */
11136 for (first_row_to_display
= first_reusable_row
;
11137 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
11138 ++first_row_to_display
)
11140 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
11141 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
11142 pt_row
= first_row_to_display
;
11145 /* Start displaying at the start of first_row_to_display. */
11146 xassert (first_row_to_display
->y
< yb
);
11147 init_to_row_start (&it
, w
, first_row_to_display
);
11149 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
11151 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
11153 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
11154 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
11156 /* Display lines beginning with first_row_to_display in the
11157 desired matrix. Set last_text_row to the last row displayed
11158 that displays text. */
11159 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
11160 if (pt_row
== NULL
)
11161 w
->cursor
.vpos
= -1;
11162 last_text_row
= NULL
;
11163 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
11164 if (display_line (&it
))
11165 last_text_row
= it
.glyph_row
- 1;
11167 /* Give up If point isn't in a row displayed or reused. */
11168 if (w
->cursor
.vpos
< 0)
11170 clear_glyph_matrix (w
->desired_matrix
);
11174 /* If point is in a reused row, adjust y and vpos of the cursor
11178 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
11179 w
->current_matrix
);
11180 w
->cursor
.y
-= first_reusable_row
->y
;
11183 /* Scroll the display. */
11184 run
.current_y
= first_reusable_row
->y
;
11185 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11186 run
.height
= it
.last_visible_y
- run
.current_y
;
11187 dy
= run
.current_y
- run
.desired_y
;
11191 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11193 rif
->update_window_begin_hook (w
);
11194 rif
->clear_mouse_face (w
);
11195 rif
->scroll_run_hook (w
, &run
);
11196 rif
->update_window_end_hook (w
, 0, 0);
11200 /* Adjust Y positions of reused rows. */
11201 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11202 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11203 max_y
= it
.last_visible_y
;
11204 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
11207 row
->visible_height
= row
->height
;
11208 if (row
->y
< min_y
)
11209 row
->visible_height
-= min_y
- row
->y
;
11210 if (row
->y
+ row
->height
> max_y
)
11211 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11214 /* Scroll the current matrix. */
11215 xassert (nrows_scrolled
> 0);
11216 rotate_matrix (w
->current_matrix
,
11218 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11221 /* Disable rows not reused. */
11222 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
11223 row
->enabled_p
= 0;
11225 /* Adjust window end. A null value of last_text_row means that
11226 the window end is in reused rows which in turn means that
11227 only its vpos can have changed. */
11230 w
->window_end_bytepos
11231 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11233 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11235 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11240 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
11243 w
->window_end_valid
= Qnil
;
11244 w
->desired_matrix
->no_scrolling_p
= 1;
11247 debug_method_add (w
, "try_window_reusing_current_matrix 2");
11257 /************************************************************************
11258 Window redisplay reusing current matrix when buffer has changed
11259 ************************************************************************/
11261 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
11262 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
11264 static struct glyph_row
*
11265 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
11266 struct glyph_row
*));
11269 /* Return the last row in MATRIX displaying text. If row START is
11270 non-null, start searching with that row. IT gives the dimensions
11271 of the display. Value is null if matrix is empty; otherwise it is
11272 a pointer to the row found. */
11274 static struct glyph_row
*
11275 find_last_row_displaying_text (matrix
, it
, start
)
11276 struct glyph_matrix
*matrix
;
11278 struct glyph_row
*start
;
11280 struct glyph_row
*row
, *row_found
;
11282 /* Set row_found to the last row in IT->w's current matrix
11283 displaying text. The loop looks funny but think of partially
11286 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11287 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11289 xassert (row
->enabled_p
);
11291 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11300 /* Return the last row in the current matrix of W that is not affected
11301 by changes at the start of current_buffer that occurred since W's
11302 current matrix was built. Value is null if no such row exists.
11304 BEG_UNCHANGED us the number of characters unchanged at the start of
11305 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11306 first changed character in current_buffer. Characters at positions <
11307 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11308 when the current matrix was built. */
11310 static struct glyph_row
*
11311 find_last_unchanged_at_beg_row (w
)
11314 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11315 struct glyph_row
*row
;
11316 struct glyph_row
*row_found
= NULL
;
11317 int yb
= window_text_bottom_y (w
);
11319 /* Find the last row displaying unchanged text. */
11320 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11321 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11322 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11324 if (/* If row ends before first_changed_pos, it is unchanged,
11325 except in some case. */
11326 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11327 /* When row ends in ZV and we write at ZV it is not
11329 && !row
->ends_at_zv_p
11330 /* When first_changed_pos is the end of a continued line,
11331 row is not unchanged because it may be no longer
11333 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11334 && row
->continued_p
))
11337 /* Stop if last visible row. */
11338 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11348 /* Find the first glyph row in the current matrix of W that is not
11349 affected by changes at the end of current_buffer since the
11350 time W's current matrix was built.
11352 Return in *DELTA the number of chars by which buffer positions in
11353 unchanged text at the end of current_buffer must be adjusted.
11355 Return in *DELTA_BYTES the corresponding number of bytes.
11357 Value is null if no such row exists, i.e. all rows are affected by
11360 static struct glyph_row
*
11361 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11363 int *delta
, *delta_bytes
;
11365 struct glyph_row
*row
;
11366 struct glyph_row
*row_found
= NULL
;
11368 *delta
= *delta_bytes
= 0;
11370 /* Display must not have been paused, otherwise the current matrix
11371 is not up to date. */
11372 if (NILP (w
->window_end_valid
))
11375 /* A value of window_end_pos >= END_UNCHANGED means that the window
11376 end is in the range of changed text. If so, there is no
11377 unchanged row at the end of W's current matrix. */
11378 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11381 /* Set row to the last row in W's current matrix displaying text. */
11382 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11384 /* If matrix is entirely empty, no unchanged row exists. */
11385 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11387 /* The value of row is the last glyph row in the matrix having a
11388 meaningful buffer position in it. The end position of row
11389 corresponds to window_end_pos. This allows us to translate
11390 buffer positions in the current matrix to current buffer
11391 positions for characters not in changed text. */
11392 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11393 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11394 int last_unchanged_pos
, last_unchanged_pos_old
;
11395 struct glyph_row
*first_text_row
11396 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11398 *delta
= Z
- Z_old
;
11399 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11401 /* Set last_unchanged_pos to the buffer position of the last
11402 character in the buffer that has not been changed. Z is the
11403 index + 1 of the last character in current_buffer, i.e. by
11404 subtracting END_UNCHANGED we get the index of the last
11405 unchanged character, and we have to add BEG to get its buffer
11407 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11408 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11410 /* Search backward from ROW for a row displaying a line that
11411 starts at a minimum position >= last_unchanged_pos_old. */
11412 for (; row
> first_text_row
; --row
)
11414 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11417 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11422 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11429 /* Make sure that glyph rows in the current matrix of window W
11430 reference the same glyph memory as corresponding rows in the
11431 frame's frame matrix. This function is called after scrolling W's
11432 current matrix on a terminal frame in try_window_id and
11433 try_window_reusing_current_matrix. */
11436 sync_frame_with_window_matrix_rows (w
)
11439 struct frame
*f
= XFRAME (w
->frame
);
11440 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11442 /* Preconditions: W must be a leaf window and full-width. Its frame
11443 must have a frame matrix. */
11444 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11445 xassert (WINDOW_FULL_WIDTH_P (w
));
11446 xassert (!FRAME_WINDOW_P (f
));
11448 /* If W is a full-width window, glyph pointers in W's current matrix
11449 have, by definition, to be the same as glyph pointers in the
11450 corresponding frame matrix. Note that frame matrices have no
11451 marginal areas (see build_frame_matrix). */
11452 window_row
= w
->current_matrix
->rows
;
11453 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11454 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11455 while (window_row
< window_row_end
)
11457 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
11458 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
11460 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
11461 frame_row
->glyphs
[TEXT_AREA
] = start
;
11462 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
11463 frame_row
->glyphs
[LAST_AREA
] = end
;
11465 /* Disable frame rows whose corresponding window rows have
11466 been disabled in try_window_id. */
11467 if (!window_row
->enabled_p
)
11468 frame_row
->enabled_p
= 0;
11470 ++window_row
, ++frame_row
;
11475 /* Find the glyph row in window W containing CHARPOS. Consider all
11476 rows between START and END (not inclusive). END null means search
11477 all rows to the end of the display area of W. Value is the row
11478 containing CHARPOS or null. */
11481 row_containing_pos (w
, charpos
, start
, end
, dy
)
11484 struct glyph_row
*start
, *end
;
11487 struct glyph_row
*row
= start
;
11490 /* If we happen to start on a header-line, skip that. */
11491 if (row
->mode_line_p
)
11494 if ((end
&& row
>= end
) || !row
->enabled_p
)
11497 last_y
= window_text_bottom_y (w
) - dy
;
11499 while ((end
== NULL
|| row
< end
)
11500 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
11501 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11502 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11503 /* The end position of a row equals the start
11504 position of the next row. If CHARPOS is there, we
11505 would rather display it in the next line, except
11506 when this line ends in ZV. */
11507 && !row
->ends_at_zv_p
11508 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))
11511 /* Give up if CHARPOS not found. */
11512 if ((end
&& row
>= end
)
11513 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11514 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11521 /* Try to redisplay window W by reusing its existing display. W's
11522 current matrix must be up to date when this function is called,
11523 i.e. window_end_valid must not be nil.
11527 1 if display has been updated
11528 0 if otherwise unsuccessful
11529 -1 if redisplay with same window start is known not to succeed
11531 The following steps are performed:
11533 1. Find the last row in the current matrix of W that is not
11534 affected by changes at the start of current_buffer. If no such row
11537 2. Find the first row in W's current matrix that is not affected by
11538 changes at the end of current_buffer. Maybe there is no such row.
11540 3. Display lines beginning with the row + 1 found in step 1 to the
11541 row found in step 2 or, if step 2 didn't find a row, to the end of
11544 4. If cursor is not known to appear on the window, give up.
11546 5. If display stopped at the row found in step 2, scroll the
11547 display and current matrix as needed.
11549 6. Maybe display some lines at the end of W, if we must. This can
11550 happen under various circumstances, like a partially visible line
11551 becoming fully visible, or because newly displayed lines are displayed
11552 in smaller font sizes.
11554 7. Update W's window end information. */
11560 struct frame
*f
= XFRAME (w
->frame
);
11561 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11562 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11563 struct glyph_row
*last_unchanged_at_beg_row
;
11564 struct glyph_row
*first_unchanged_at_end_row
;
11565 struct glyph_row
*row
;
11566 struct glyph_row
*bottom_row
;
11569 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11570 struct text_pos start_pos
;
11572 int first_unchanged_at_end_vpos
= 0;
11573 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11574 struct text_pos start
;
11575 int first_changed_charpos
, last_changed_charpos
;
11578 if (inhibit_try_window_id
)
11582 /* This is handy for debugging. */
11584 #define GIVE_UP(X) \
11586 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11590 #define GIVE_UP(X) return 0
11593 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11595 /* Don't use this for mini-windows because these can show
11596 messages and mini-buffers, and we don't handle that here. */
11597 if (MINI_WINDOW_P (w
))
11600 /* This flag is used to prevent redisplay optimizations. */
11601 if (windows_or_buffers_changed
|| cursor_type_changed
)
11604 /* Verify that narrowing has not changed.
11605 Also verify that we were not told to prevent redisplay optimizations.
11606 It would be nice to further
11607 reduce the number of cases where this prevents try_window_id. */
11608 if (current_buffer
->clip_changed
11609 || current_buffer
->prevent_redisplay_optimizations_p
)
11612 /* Window must either use window-based redisplay or be full width. */
11613 if (!FRAME_WINDOW_P (f
)
11614 && (!line_ins_del_ok
11615 || !WINDOW_FULL_WIDTH_P (w
)))
11618 /* Give up if point is not known NOT to appear in W. */
11619 if (PT
< CHARPOS (start
))
11622 /* Another way to prevent redisplay optimizations. */
11623 if (XFASTINT (w
->last_modified
) == 0)
11626 /* Verify that window is not hscrolled. */
11627 if (XFASTINT (w
->hscroll
) != 0)
11630 /* Verify that display wasn't paused. */
11631 if (NILP (w
->window_end_valid
))
11634 /* Can't use this if highlighting a region because a cursor movement
11635 will do more than just set the cursor. */
11636 if (!NILP (Vtransient_mark_mode
)
11637 && !NILP (current_buffer
->mark_active
))
11640 /* Likewise if highlighting trailing whitespace. */
11641 if (!NILP (Vshow_trailing_whitespace
))
11644 /* Likewise if showing a region. */
11645 if (!NILP (w
->region_showing
))
11648 /* Can use this if overlay arrow position and or string have changed. */
11649 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11650 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11654 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11655 only if buffer has really changed. The reason is that the gap is
11656 initially at Z for freshly visited files. The code below would
11657 set end_unchanged to 0 in that case. */
11658 if (MODIFF
> SAVE_MODIFF
11659 /* This seems to happen sometimes after saving a buffer. */
11660 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11662 if (GPT
- BEG
< BEG_UNCHANGED
)
11663 BEG_UNCHANGED
= GPT
- BEG
;
11664 if (Z
- GPT
< END_UNCHANGED
)
11665 END_UNCHANGED
= Z
- GPT
;
11668 /* The position of the first and last character that has been changed. */
11669 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11670 last_changed_charpos
= Z
- END_UNCHANGED
;
11672 /* If window starts after a line end, and the last change is in
11673 front of that newline, then changes don't affect the display.
11674 This case happens with stealth-fontification. Note that although
11675 the display is unchanged, glyph positions in the matrix have to
11676 be adjusted, of course. */
11677 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11678 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11679 && ((last_changed_charpos
< CHARPOS (start
)
11680 && CHARPOS (start
) == BEGV
)
11681 || (last_changed_charpos
< CHARPOS (start
) - 1
11682 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11684 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11685 struct glyph_row
*r0
;
11687 /* Compute how many chars/bytes have been added to or removed
11688 from the buffer. */
11689 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11690 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11692 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11694 /* Give up if PT is not in the window. Note that it already has
11695 been checked at the start of try_window_id that PT is not in
11696 front of the window start. */
11697 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11700 /* If window start is unchanged, we can reuse the whole matrix
11701 as is, after adjusting glyph positions. No need to compute
11702 the window end again, since its offset from Z hasn't changed. */
11703 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11704 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11705 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11707 /* Adjust positions in the glyph matrix. */
11708 if (delta
|| delta_bytes
)
11710 struct glyph_row
*r1
11711 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11712 increment_matrix_positions (w
->current_matrix
,
11713 MATRIX_ROW_VPOS (r0
, current_matrix
),
11714 MATRIX_ROW_VPOS (r1
, current_matrix
),
11715 delta
, delta_bytes
);
11718 /* Set the cursor. */
11719 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11720 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11725 /* Handle the case that changes are all below what is displayed in
11726 the window, and that PT is in the window. This shortcut cannot
11727 be taken if ZV is visible in the window, and text has been added
11728 there that is visible in the window. */
11729 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11730 /* ZV is not visible in the window, or there are no
11731 changes at ZV, actually. */
11732 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11733 || first_changed_charpos
== last_changed_charpos
))
11735 struct glyph_row
*r0
;
11737 /* Give up if PT is not in the window. Note that it already has
11738 been checked at the start of try_window_id that PT is not in
11739 front of the window start. */
11740 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11743 /* If window start is unchanged, we can reuse the whole matrix
11744 as is, without changing glyph positions since no text has
11745 been added/removed in front of the window end. */
11746 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11747 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11749 /* We have to compute the window end anew since text
11750 can have been added/removed after it. */
11752 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11753 w
->window_end_bytepos
11754 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11756 /* Set the cursor. */
11757 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11758 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11763 /* Give up if window start is in the changed area.
11765 The condition used to read
11767 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11769 but why that was tested escapes me at the moment. */
11770 if (CHARPOS (start
) >= first_changed_charpos
11771 && CHARPOS (start
) <= last_changed_charpos
)
11774 /* Check that window start agrees with the start of the first glyph
11775 row in its current matrix. Check this after we know the window
11776 start is not in changed text, otherwise positions would not be
11778 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11779 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11782 /* Give up if the window ends in strings. Overlay strings
11783 at the end are difficult to handle, so don't try. */
11784 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
11785 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
11788 /* Compute the position at which we have to start displaying new
11789 lines. Some of the lines at the top of the window might be
11790 reusable because they are not displaying changed text. Find the
11791 last row in W's current matrix not affected by changes at the
11792 start of current_buffer. Value is null if changes start in the
11793 first line of window. */
11794 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11795 if (last_unchanged_at_beg_row
)
11797 /* Avoid starting to display in the moddle of a character, a TAB
11798 for instance. This is easier than to set up the iterator
11799 exactly, and it's not a frequent case, so the additional
11800 effort wouldn't really pay off. */
11801 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11802 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
11803 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11804 --last_unchanged_at_beg_row
;
11806 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11809 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11811 start_pos
= it
.current
.pos
;
11813 /* Start displaying new lines in the desired matrix at the same
11814 vpos we would use in the current matrix, i.e. below
11815 last_unchanged_at_beg_row. */
11816 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11818 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11819 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11821 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11825 /* There are no reusable lines at the start of the window.
11826 Start displaying in the first line. */
11827 start_display (&it
, w
, start
);
11828 start_pos
= it
.current
.pos
;
11831 /* Find the first row that is not affected by changes at the end of
11832 the buffer. Value will be null if there is no unchanged row, in
11833 which case we must redisplay to the end of the window. delta
11834 will be set to the value by which buffer positions beginning with
11835 first_unchanged_at_end_row have to be adjusted due to text
11837 first_unchanged_at_end_row
11838 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11839 IF_DEBUG (debug_delta
= delta
);
11840 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11842 /* Set stop_pos to the buffer position up to which we will have to
11843 display new lines. If first_unchanged_at_end_row != NULL, this
11844 is the buffer position of the start of the line displayed in that
11845 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11846 that we don't stop at a buffer position. */
11848 if (first_unchanged_at_end_row
)
11850 xassert (last_unchanged_at_beg_row
== NULL
11851 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11853 /* If this is a continuation line, move forward to the next one
11854 that isn't. Changes in lines above affect this line.
11855 Caution: this may move first_unchanged_at_end_row to a row
11856 not displaying text. */
11857 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11858 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11859 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11860 < it
.last_visible_y
))
11861 ++first_unchanged_at_end_row
;
11863 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11864 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11865 >= it
.last_visible_y
))
11866 first_unchanged_at_end_row
= NULL
;
11869 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11871 first_unchanged_at_end_vpos
11872 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11873 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11876 else if (last_unchanged_at_beg_row
== NULL
)
11882 /* Either there is no unchanged row at the end, or the one we have
11883 now displays text. This is a necessary condition for the window
11884 end pos calculation at the end of this function. */
11885 xassert (first_unchanged_at_end_row
== NULL
11886 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11888 debug_last_unchanged_at_beg_vpos
11889 = (last_unchanged_at_beg_row
11890 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11892 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11894 #endif /* GLYPH_DEBUG != 0 */
11897 /* Display new lines. Set last_text_row to the last new line
11898 displayed which has text on it, i.e. might end up as being the
11899 line where the window_end_vpos is. */
11900 w
->cursor
.vpos
= -1;
11901 last_text_row
= NULL
;
11902 overlay_arrow_seen
= 0;
11903 while (it
.current_y
< it
.last_visible_y
11904 && !fonts_changed_p
11905 && (first_unchanged_at_end_row
== NULL
11906 || IT_CHARPOS (it
) < stop_pos
))
11908 if (display_line (&it
))
11909 last_text_row
= it
.glyph_row
- 1;
11912 if (fonts_changed_p
)
11916 /* Compute differences in buffer positions, y-positions etc. for
11917 lines reused at the bottom of the window. Compute what we can
11919 if (first_unchanged_at_end_row
11920 /* No lines reused because we displayed everything up to the
11921 bottom of the window. */
11922 && it
.current_y
< it
.last_visible_y
)
11925 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11927 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11928 run
.current_y
= first_unchanged_at_end_row
->y
;
11929 run
.desired_y
= run
.current_y
+ dy
;
11930 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11934 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11935 first_unchanged_at_end_row
= NULL
;
11937 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11940 /* Find the cursor if not already found. We have to decide whether
11941 PT will appear on this window (it sometimes doesn't, but this is
11942 not a very frequent case.) This decision has to be made before
11943 the current matrix is altered. A value of cursor.vpos < 0 means
11944 that PT is either in one of the lines beginning at
11945 first_unchanged_at_end_row or below the window. Don't care for
11946 lines that might be displayed later at the window end; as
11947 mentioned, this is not a frequent case. */
11948 if (w
->cursor
.vpos
< 0)
11950 /* Cursor in unchanged rows at the top? */
11951 if (PT
< CHARPOS (start_pos
)
11952 && last_unchanged_at_beg_row
)
11954 row
= row_containing_pos (w
, PT
,
11955 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11956 last_unchanged_at_beg_row
+ 1, 0);
11958 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11961 /* Start from first_unchanged_at_end_row looking for PT. */
11962 else if (first_unchanged_at_end_row
)
11964 row
= row_containing_pos (w
, PT
- delta
,
11965 first_unchanged_at_end_row
, NULL
, 0);
11967 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11968 delta_bytes
, dy
, dvpos
);
11971 /* Give up if cursor was not found. */
11972 if (w
->cursor
.vpos
< 0)
11974 clear_glyph_matrix (w
->desired_matrix
);
11979 /* Don't let the cursor end in the scroll margins. */
11981 int this_scroll_margin
, cursor_height
;
11983 this_scroll_margin
= max (0, scroll_margin
);
11984 this_scroll_margin
= min (this_scroll_margin
,
11985 XFASTINT (w
->height
) / 4);
11986 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11987 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11989 if ((w
->cursor
.y
< this_scroll_margin
11990 && CHARPOS (start
) > BEGV
)
11991 /* Don't take scroll margin into account at the bottom because
11992 old redisplay didn't do it either. */
11993 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11995 w
->cursor
.vpos
= -1;
11996 clear_glyph_matrix (w
->desired_matrix
);
12001 /* Scroll the display. Do it before changing the current matrix so
12002 that xterm.c doesn't get confused about where the cursor glyph is
12004 if (dy
&& run
.height
)
12008 if (FRAME_WINDOW_P (f
))
12010 rif
->update_window_begin_hook (w
);
12011 rif
->clear_mouse_face (w
);
12012 rif
->scroll_run_hook (w
, &run
);
12013 rif
->update_window_end_hook (w
, 0, 0);
12017 /* Terminal frame. In this case, dvpos gives the number of
12018 lines to scroll by; dvpos < 0 means scroll up. */
12019 int first_unchanged_at_end_vpos
12020 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
12021 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
12022 int end
= (XFASTINT (w
->top
)
12023 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
12024 + window_internal_height (w
));
12026 /* Perform the operation on the screen. */
12029 /* Scroll last_unchanged_at_beg_row to the end of the
12030 window down dvpos lines. */
12031 set_terminal_window (end
);
12033 /* On dumb terminals delete dvpos lines at the end
12034 before inserting dvpos empty lines. */
12035 if (!scroll_region_ok
)
12036 ins_del_lines (end
- dvpos
, -dvpos
);
12038 /* Insert dvpos empty lines in front of
12039 last_unchanged_at_beg_row. */
12040 ins_del_lines (from
, dvpos
);
12042 else if (dvpos
< 0)
12044 /* Scroll up last_unchanged_at_beg_vpos to the end of
12045 the window to last_unchanged_at_beg_vpos - |dvpos|. */
12046 set_terminal_window (end
);
12048 /* Delete dvpos lines in front of
12049 last_unchanged_at_beg_vpos. ins_del_lines will set
12050 the cursor to the given vpos and emit |dvpos| delete
12052 ins_del_lines (from
+ dvpos
, dvpos
);
12054 /* On a dumb terminal insert dvpos empty lines at the
12056 if (!scroll_region_ok
)
12057 ins_del_lines (end
+ dvpos
, -dvpos
);
12060 set_terminal_window (0);
12066 /* Shift reused rows of the current matrix to the right position.
12067 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
12069 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
12070 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
12073 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
12074 bottom_vpos
, dvpos
);
12075 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
12078 else if (dvpos
> 0)
12080 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
12081 bottom_vpos
, dvpos
);
12082 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
12083 first_unchanged_at_end_vpos
+ dvpos
, 0);
12086 /* For frame-based redisplay, make sure that current frame and window
12087 matrix are in sync with respect to glyph memory. */
12088 if (!FRAME_WINDOW_P (f
))
12089 sync_frame_with_window_matrix_rows (w
);
12091 /* Adjust buffer positions in reused rows. */
12093 increment_matrix_positions (current_matrix
,
12094 first_unchanged_at_end_vpos
+ dvpos
,
12095 bottom_vpos
, delta
, delta_bytes
);
12097 /* Adjust Y positions. */
12099 shift_glyph_matrix (w
, current_matrix
,
12100 first_unchanged_at_end_vpos
+ dvpos
,
12103 if (first_unchanged_at_end_row
)
12104 first_unchanged_at_end_row
+= dvpos
;
12106 /* If scrolling up, there may be some lines to display at the end of
12108 last_text_row_at_end
= NULL
;
12111 /* Scrolling up can leave for example a partially visible line
12112 at the end of the window to be redisplayed. */
12113 /* Set last_row to the glyph row in the current matrix where the
12114 window end line is found. It has been moved up or down in
12115 the matrix by dvpos. */
12116 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
12117 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
12119 /* If last_row is the window end line, it should display text. */
12120 xassert (last_row
->displays_text_p
);
12122 /* If window end line was partially visible before, begin
12123 displaying at that line. Otherwise begin displaying with the
12124 line following it. */
12125 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
12127 init_to_row_start (&it
, w
, last_row
);
12128 it
.vpos
= last_vpos
;
12129 it
.current_y
= last_row
->y
;
12133 init_to_row_end (&it
, w
, last_row
);
12134 it
.vpos
= 1 + last_vpos
;
12135 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
12139 /* We may start in a continuation line. If so, we have to
12140 get the right continuation_lines_width and current_x. */
12141 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
12142 it
.hpos
= it
.current_x
= 0;
12144 /* Display the rest of the lines at the window end. */
12145 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
12146 while (it
.current_y
< it
.last_visible_y
12147 && !fonts_changed_p
)
12149 /* Is it always sure that the display agrees with lines in
12150 the current matrix? I don't think so, so we mark rows
12151 displayed invalid in the current matrix by setting their
12152 enabled_p flag to zero. */
12153 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
12154 if (display_line (&it
))
12155 last_text_row_at_end
= it
.glyph_row
- 1;
12159 /* Update window_end_pos and window_end_vpos. */
12160 if (first_unchanged_at_end_row
12161 && first_unchanged_at_end_row
->y
< it
.last_visible_y
12162 && !last_text_row_at_end
)
12164 /* Window end line if one of the preserved rows from the current
12165 matrix. Set row to the last row displaying text in current
12166 matrix starting at first_unchanged_at_end_row, after
12168 xassert (first_unchanged_at_end_row
->displays_text_p
);
12169 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
12170 first_unchanged_at_end_row
);
12171 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
12173 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12174 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12176 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
12177 xassert (w
->window_end_bytepos
>= 0);
12178 IF_DEBUG (debug_method_add (w
, "A"));
12180 else if (last_text_row_at_end
)
12183 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
12184 w
->window_end_bytepos
12185 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
12187 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
12188 xassert (w
->window_end_bytepos
>= 0);
12189 IF_DEBUG (debug_method_add (w
, "B"));
12191 else if (last_text_row
)
12193 /* We have displayed either to the end of the window or at the
12194 end of the window, i.e. the last row with text is to be found
12195 in the desired matrix. */
12197 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12198 w
->window_end_bytepos
12199 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12201 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
12202 xassert (w
->window_end_bytepos
>= 0);
12204 else if (first_unchanged_at_end_row
== NULL
12205 && last_text_row
== NULL
12206 && last_text_row_at_end
== NULL
)
12208 /* Displayed to end of window, but no line containing text was
12209 displayed. Lines were deleted at the end of the window. */
12210 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
12211 int vpos
= XFASTINT (w
->window_end_vpos
);
12212 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
12213 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
12216 row
== NULL
&& vpos
>= first_vpos
;
12217 --vpos
, --current_row
, --desired_row
)
12219 if (desired_row
->enabled_p
)
12221 if (desired_row
->displays_text_p
)
12224 else if (current_row
->displays_text_p
)
12228 xassert (row
!= NULL
);
12229 w
->window_end_vpos
= make_number (vpos
+ 1);
12230 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12231 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12232 xassert (w
->window_end_bytepos
>= 0);
12233 IF_DEBUG (debug_method_add (w
, "C"));
12238 #if 0 /* This leads to problems, for instance when the cursor is
12239 at ZV, and the cursor line displays no text. */
12240 /* Disable rows below what's displayed in the window. This makes
12241 debugging easier. */
12242 enable_glyph_matrix_rows (current_matrix
,
12243 XFASTINT (w
->window_end_vpos
) + 1,
12247 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
12248 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
12250 /* Record that display has not been completed. */
12251 w
->window_end_valid
= Qnil
;
12252 w
->desired_matrix
->no_scrolling_p
= 1;
12260 /***********************************************************************
12261 More debugging support
12262 ***********************************************************************/
12266 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
12267 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
12268 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
12271 /* Dump the contents of glyph matrix MATRIX on stderr.
12273 GLYPHS 0 means don't show glyph contents.
12274 GLYPHS 1 means show glyphs in short form
12275 GLYPHS > 1 means show glyphs in long form. */
12278 dump_glyph_matrix (matrix
, glyphs
)
12279 struct glyph_matrix
*matrix
;
12283 for (i
= 0; i
< matrix
->nrows
; ++i
)
12284 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12288 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12289 the glyph row and area where the glyph comes from. */
12292 dump_glyph (row
, glyph
, area
)
12293 struct glyph_row
*row
;
12294 struct glyph
*glyph
;
12297 if (glyph
->type
== CHAR_GLYPH
)
12300 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12301 glyph
- row
->glyphs
[TEXT_AREA
],
12304 (BUFFERP (glyph
->object
)
12306 : (STRINGP (glyph
->object
)
12309 glyph
->pixel_width
,
12311 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12315 glyph
->left_box_line_p
,
12316 glyph
->right_box_line_p
);
12318 else if (glyph
->type
== STRETCH_GLYPH
)
12321 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12322 glyph
- row
->glyphs
[TEXT_AREA
],
12325 (BUFFERP (glyph
->object
)
12327 : (STRINGP (glyph
->object
)
12330 glyph
->pixel_width
,
12334 glyph
->left_box_line_p
,
12335 glyph
->right_box_line_p
);
12337 else if (glyph
->type
== IMAGE_GLYPH
)
12340 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12341 glyph
- row
->glyphs
[TEXT_AREA
],
12344 (BUFFERP (glyph
->object
)
12346 : (STRINGP (glyph
->object
)
12349 glyph
->pixel_width
,
12353 glyph
->left_box_line_p
,
12354 glyph
->right_box_line_p
);
12359 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12360 GLYPHS 0 means don't show glyph contents.
12361 GLYPHS 1 means show glyphs in short form
12362 GLYPHS > 1 means show glyphs in long form. */
12365 dump_glyph_row (row
, vpos
, glyphs
)
12366 struct glyph_row
*row
;
12371 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12372 fprintf (stderr
, "=======================================================================\n");
12374 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12375 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12377 MATRIX_ROW_START_CHARPOS (row
),
12378 MATRIX_ROW_END_CHARPOS (row
),
12379 row
->used
[TEXT_AREA
],
12380 row
->contains_overlapping_glyphs_p
,
12382 row
->truncated_on_left_p
,
12383 row
->truncated_on_right_p
,
12384 row
->overlay_arrow_p
,
12386 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12387 row
->displays_text_p
,
12390 row
->ends_in_middle_of_char_p
,
12391 row
->starts_in_middle_of_char_p
,
12397 row
->visible_height
,
12400 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12401 row
->end
.overlay_string_index
,
12402 row
->continuation_lines_width
);
12403 fprintf (stderr
, "%9d %5d\n",
12404 CHARPOS (row
->start
.string_pos
),
12405 CHARPOS (row
->end
.string_pos
));
12406 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12407 row
->end
.dpvec_index
);
12414 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12416 struct glyph
*glyph
= row
->glyphs
[area
];
12417 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12419 /* Glyph for a line end in text. */
12420 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12423 if (glyph
< glyph_end
)
12424 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12426 for (; glyph
< glyph_end
; ++glyph
)
12427 dump_glyph (row
, glyph
, area
);
12430 else if (glyphs
== 1)
12434 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12436 char *s
= (char *) alloca (row
->used
[area
] + 1);
12439 for (i
= 0; i
< row
->used
[area
]; ++i
)
12441 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12442 if (glyph
->type
== CHAR_GLYPH
12443 && glyph
->u
.ch
< 0x80
12444 && glyph
->u
.ch
>= ' ')
12445 s
[i
] = glyph
->u
.ch
;
12451 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12457 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12458 Sdump_glyph_matrix
, 0, 1, "p",
12459 doc
: /* Dump the current matrix of the selected window to stderr.
12460 Shows contents of glyph row structures. With non-nil
12461 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12462 glyphs in short form, otherwise show glyphs in long form. */)
12464 Lisp_Object glyphs
;
12466 struct window
*w
= XWINDOW (selected_window
);
12467 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12469 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12470 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12471 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12472 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12473 fprintf (stderr
, "=============================================\n");
12474 dump_glyph_matrix (w
->current_matrix
,
12475 NILP (glyphs
) ? 0 : XINT (glyphs
));
12480 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
12481 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
12484 struct frame
*f
= XFRAME (selected_frame
);
12485 dump_glyph_matrix (f
->current_matrix
, 1);
12490 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12491 doc
: /* Dump glyph row ROW to stderr.
12492 GLYPH 0 means don't dump glyphs.
12493 GLYPH 1 means dump glyphs in short form.
12494 GLYPH > 1 or omitted means dump glyphs in long form. */)
12496 Lisp_Object row
, glyphs
;
12498 struct glyph_matrix
*matrix
;
12501 CHECK_NUMBER (row
);
12502 matrix
= XWINDOW (selected_window
)->current_matrix
;
12504 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12505 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12507 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12512 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12513 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12514 GLYPH 0 means don't dump glyphs.
12515 GLYPH 1 means dump glyphs in short form.
12516 GLYPH > 1 or omitted means dump glyphs in long form. */)
12518 Lisp_Object row
, glyphs
;
12520 struct frame
*sf
= SELECTED_FRAME ();
12521 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12524 CHECK_NUMBER (row
);
12526 if (vpos
>= 0 && vpos
< m
->nrows
)
12527 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12528 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12533 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12534 doc
: /* Toggle tracing of redisplay.
12535 With ARG, turn tracing on if and only if ARG is positive. */)
12540 trace_redisplay_p
= !trace_redisplay_p
;
12543 arg
= Fprefix_numeric_value (arg
);
12544 trace_redisplay_p
= XINT (arg
) > 0;
12551 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12552 doc
: /* Like `format', but print result to stderr.
12553 usage: (trace-to-stderr STRING &rest OBJECTS) */)
12558 Lisp_Object s
= Fformat (nargs
, args
);
12559 fprintf (stderr
, "%s", SDATA (s
));
12563 #endif /* GLYPH_DEBUG */
12567 /***********************************************************************
12568 Building Desired Matrix Rows
12569 ***********************************************************************/
12571 /* Return a temporary glyph row holding the glyphs of an overlay
12572 arrow. Only used for non-window-redisplay windows. */
12574 static struct glyph_row
*
12575 get_overlay_arrow_glyph_row (w
)
12578 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12579 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12580 struct buffer
*old
= current_buffer
;
12581 const unsigned char *arrow_string
= SDATA (Voverlay_arrow_string
);
12582 int arrow_len
= SCHARS (Voverlay_arrow_string
);
12583 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12584 const unsigned char *p
;
12587 int n_glyphs_before
;
12589 set_buffer_temp (buffer
);
12590 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12591 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12592 SET_TEXT_POS (it
.position
, 0, 0);
12594 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12596 while (p
< arrow_end
)
12598 Lisp_Object face
, ilisp
;
12600 /* Get the next character. */
12602 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12604 it
.c
= *p
, it
.len
= 1;
12607 /* Get its face. */
12608 ilisp
= make_number (p
- arrow_string
);
12609 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12610 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12612 /* Compute its width, get its glyphs. */
12613 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12614 SET_TEXT_POS (it
.position
, -1, -1);
12615 PRODUCE_GLYPHS (&it
);
12617 /* If this character doesn't fit any more in the line, we have
12618 to remove some glyphs. */
12619 if (it
.current_x
> it
.last_visible_x
)
12621 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12626 set_buffer_temp (old
);
12627 return it
.glyph_row
;
12631 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12632 glyphs are only inserted for terminal frames since we can't really
12633 win with truncation glyphs when partially visible glyphs are
12634 involved. Which glyphs to insert is determined by
12635 produce_special_glyphs. */
12638 insert_left_trunc_glyphs (it
)
12641 struct it truncate_it
;
12642 struct glyph
*from
, *end
, *to
, *toend
;
12644 xassert (!FRAME_WINDOW_P (it
->f
));
12646 /* Get the truncation glyphs. */
12648 truncate_it
.current_x
= 0;
12649 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12650 truncate_it
.glyph_row
= &scratch_glyph_row
;
12651 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12652 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12653 truncate_it
.object
= make_number (0);
12654 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12656 /* Overwrite glyphs from IT with truncation glyphs. */
12657 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12658 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12659 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12660 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12665 /* There may be padding glyphs left over. Overwrite them too. */
12666 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12668 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12674 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12678 /* Compute the pixel height and width of IT->glyph_row.
12680 Most of the time, ascent and height of a display line will be equal
12681 to the max_ascent and max_height values of the display iterator
12682 structure. This is not the case if
12684 1. We hit ZV without displaying anything. In this case, max_ascent
12685 and max_height will be zero.
12687 2. We have some glyphs that don't contribute to the line height.
12688 (The glyph row flag contributes_to_line_height_p is for future
12689 pixmap extensions).
12691 The first case is easily covered by using default values because in
12692 these cases, the line height does not really matter, except that it
12693 must not be zero. */
12696 compute_line_metrics (it
)
12699 struct glyph_row
*row
= it
->glyph_row
;
12702 if (FRAME_WINDOW_P (it
->f
))
12704 int i
, min_y
, max_y
;
12706 /* The line may consist of one space only, that was added to
12707 place the cursor on it. If so, the row's height hasn't been
12709 if (row
->height
== 0)
12711 if (it
->max_ascent
+ it
->max_descent
== 0)
12712 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12713 row
->ascent
= it
->max_ascent
;
12714 row
->height
= it
->max_ascent
+ it
->max_descent
;
12715 row
->phys_ascent
= it
->max_phys_ascent
;
12716 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12719 /* Compute the width of this line. */
12720 row
->pixel_width
= row
->x
;
12721 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12722 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12724 xassert (row
->pixel_width
>= 0);
12725 xassert (row
->ascent
>= 0 && row
->height
> 0);
12727 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12728 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12730 /* If first line's physical ascent is larger than its logical
12731 ascent, use the physical ascent, and make the row taller.
12732 This makes accented characters fully visible. */
12733 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12734 && row
->phys_ascent
> row
->ascent
)
12736 row
->height
+= row
->phys_ascent
- row
->ascent
;
12737 row
->ascent
= row
->phys_ascent
;
12740 /* Compute how much of the line is visible. */
12741 row
->visible_height
= row
->height
;
12743 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12744 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12746 if (row
->y
< min_y
)
12747 row
->visible_height
-= min_y
- row
->y
;
12748 if (row
->y
+ row
->height
> max_y
)
12749 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12753 row
->pixel_width
= row
->used
[TEXT_AREA
];
12754 if (row
->continued_p
)
12755 row
->pixel_width
-= it
->continuation_pixel_width
;
12756 else if (row
->truncated_on_right_p
)
12757 row
->pixel_width
-= it
->truncation_pixel_width
;
12758 row
->ascent
= row
->phys_ascent
= 0;
12759 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12762 /* Compute a hash code for this row. */
12764 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12765 for (i
= 0; i
< row
->used
[area
]; ++i
)
12766 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12767 + row
->glyphs
[area
][i
].u
.val
12768 + row
->glyphs
[area
][i
].face_id
12769 + row
->glyphs
[area
][i
].padding_p
12770 + (row
->glyphs
[area
][i
].type
<< 2));
12772 it
->max_ascent
= it
->max_descent
= 0;
12773 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12777 /* Append one space to the glyph row of iterator IT if doing a
12778 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12779 space have the default face, otherwise let it have the same face as
12780 IT->face_id. Value is non-zero if a space was added.
12782 This function is called to make sure that there is always one glyph
12783 at the end of a glyph row that the cursor can be set on under
12784 window-systems. (If there weren't such a glyph we would not know
12785 how wide and tall a box cursor should be displayed).
12787 At the same time this space let's a nicely handle clearing to the
12788 end of the line if the row ends in italic text. */
12791 append_space (it
, default_face_p
)
12793 int default_face_p
;
12795 if (FRAME_WINDOW_P (it
->f
))
12797 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12799 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12800 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12802 /* Save some values that must not be changed.
12803 Must save IT->c and IT->len because otherwise
12804 ITERATOR_AT_END_P wouldn't work anymore after
12805 append_space has been called. */
12806 enum display_element_type saved_what
= it
->what
;
12807 int saved_c
= it
->c
, saved_len
= it
->len
;
12808 int saved_x
= it
->current_x
;
12809 int saved_face_id
= it
->face_id
;
12810 struct text_pos saved_pos
;
12811 Lisp_Object saved_object
;
12814 saved_object
= it
->object
;
12815 saved_pos
= it
->position
;
12817 it
->what
= IT_CHARACTER
;
12818 bzero (&it
->position
, sizeof it
->position
);
12819 it
->object
= make_number (0);
12823 if (default_face_p
)
12824 it
->face_id
= DEFAULT_FACE_ID
;
12825 else if (it
->face_before_selective_p
)
12826 it
->face_id
= it
->saved_face_id
;
12827 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12828 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12830 PRODUCE_GLYPHS (it
);
12832 it
->current_x
= saved_x
;
12833 it
->object
= saved_object
;
12834 it
->position
= saved_pos
;
12835 it
->what
= saved_what
;
12836 it
->face_id
= saved_face_id
;
12837 it
->len
= saved_len
;
12847 /* Extend the face of the last glyph in the text area of IT->glyph_row
12848 to the end of the display line. Called from display_line.
12849 If the glyph row is empty, add a space glyph to it so that we
12850 know the face to draw. Set the glyph row flag fill_line_p. */
12853 extend_face_to_end_of_line (it
)
12857 struct frame
*f
= it
->f
;
12859 /* If line is already filled, do nothing. */
12860 if (it
->current_x
>= it
->last_visible_x
)
12863 /* Face extension extends the background and box of IT->face_id
12864 to the end of the line. If the background equals the background
12865 of the frame, we don't have to do anything. */
12866 if (it
->face_before_selective_p
)
12867 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12869 face
= FACE_FROM_ID (f
, it
->face_id
);
12871 if (FRAME_WINDOW_P (f
)
12872 && face
->box
== FACE_NO_BOX
12873 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12877 /* Set the glyph row flag indicating that the face of the last glyph
12878 in the text area has to be drawn to the end of the text area. */
12879 it
->glyph_row
->fill_line_p
= 1;
12881 /* If current character of IT is not ASCII, make sure we have the
12882 ASCII face. This will be automatically undone the next time
12883 get_next_display_element returns a multibyte character. Note
12884 that the character will always be single byte in unibyte text. */
12885 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12887 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12890 if (FRAME_WINDOW_P (f
))
12892 /* If the row is empty, add a space with the current face of IT,
12893 so that we know which face to draw. */
12894 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12896 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12897 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12898 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12903 /* Save some values that must not be changed. */
12904 int saved_x
= it
->current_x
;
12905 struct text_pos saved_pos
;
12906 Lisp_Object saved_object
;
12907 enum display_element_type saved_what
= it
->what
;
12908 int saved_face_id
= it
->face_id
;
12910 saved_object
= it
->object
;
12911 saved_pos
= it
->position
;
12913 it
->what
= IT_CHARACTER
;
12914 bzero (&it
->position
, sizeof it
->position
);
12915 it
->object
= make_number (0);
12918 it
->face_id
= face
->id
;
12920 PRODUCE_GLYPHS (it
);
12922 while (it
->current_x
<= it
->last_visible_x
)
12923 PRODUCE_GLYPHS (it
);
12925 /* Don't count these blanks really. It would let us insert a left
12926 truncation glyph below and make us set the cursor on them, maybe. */
12927 it
->current_x
= saved_x
;
12928 it
->object
= saved_object
;
12929 it
->position
= saved_pos
;
12930 it
->what
= saved_what
;
12931 it
->face_id
= saved_face_id
;
12936 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12937 trailing whitespace. */
12940 trailing_whitespace_p (charpos
)
12943 int bytepos
= CHAR_TO_BYTE (charpos
);
12946 while (bytepos
< ZV_BYTE
12947 && (c
= FETCH_CHAR (bytepos
),
12948 c
== ' ' || c
== '\t'))
12951 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12953 if (bytepos
!= PT_BYTE
)
12960 /* Highlight trailing whitespace, if any, in ROW. */
12963 highlight_trailing_whitespace (f
, row
)
12965 struct glyph_row
*row
;
12967 int used
= row
->used
[TEXT_AREA
];
12971 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12972 struct glyph
*glyph
= start
+ used
- 1;
12974 /* Skip over glyphs inserted to display the cursor at the
12975 end of a line, for extending the face of the last glyph
12976 to the end of the line on terminals, and for truncation
12977 and continuation glyphs. */
12978 while (glyph
>= start
12979 && glyph
->type
== CHAR_GLYPH
12980 && INTEGERP (glyph
->object
))
12983 /* If last glyph is a space or stretch, and it's trailing
12984 whitespace, set the face of all trailing whitespace glyphs in
12985 IT->glyph_row to `trailing-whitespace'. */
12987 && BUFFERP (glyph
->object
)
12988 && (glyph
->type
== STRETCH_GLYPH
12989 || (glyph
->type
== CHAR_GLYPH
12990 && glyph
->u
.ch
== ' '))
12991 && trailing_whitespace_p (glyph
->charpos
))
12993 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12995 while (glyph
>= start
12996 && BUFFERP (glyph
->object
)
12997 && (glyph
->type
== STRETCH_GLYPH
12998 || (glyph
->type
== CHAR_GLYPH
12999 && glyph
->u
.ch
== ' ')))
13000 (glyph
--)->face_id
= face_id
;
13006 /* Value is non-zero if glyph row ROW in window W should be
13007 used to hold the cursor. */
13010 cursor_row_p (w
, row
)
13012 struct glyph_row
*row
;
13014 int cursor_row_p
= 1;
13016 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
13018 /* If the row ends with a newline from a string, we don't want
13019 the cursor there (if the row is continued it doesn't end in a
13021 if (CHARPOS (row
->end
.string_pos
) >= 0
13022 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13023 cursor_row_p
= row
->continued_p
;
13025 /* If the row ends at ZV, display the cursor at the end of that
13026 row instead of at the start of the row below. */
13027 else if (row
->ends_at_zv_p
)
13033 return cursor_row_p
;
13037 /* Construct the glyph row IT->glyph_row in the desired matrix of
13038 IT->w from text at the current position of IT. See dispextern.h
13039 for an overview of struct it. Value is non-zero if
13040 IT->glyph_row displays text, as opposed to a line displaying ZV
13047 struct glyph_row
*row
= it
->glyph_row
;
13049 /* We always start displaying at hpos zero even if hscrolled. */
13050 xassert (it
->hpos
== 0 && it
->current_x
== 0);
13052 /* We must not display in a row that's not a text row. */
13053 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
13054 < it
->w
->desired_matrix
->nrows
);
13056 /* Is IT->w showing the region? */
13057 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
13059 /* Clear the result glyph row and enable it. */
13060 prepare_desired_row (row
);
13062 row
->y
= it
->current_y
;
13063 row
->start
= it
->current
;
13064 row
->continuation_lines_width
= it
->continuation_lines_width
;
13065 row
->displays_text_p
= 1;
13066 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
13067 it
->starts_in_middle_of_char_p
= 0;
13069 /* Arrange the overlays nicely for our purposes. Usually, we call
13070 display_line on only one line at a time, in which case this
13071 can't really hurt too much, or we call it on lines which appear
13072 one after another in the buffer, in which case all calls to
13073 recenter_overlay_lists but the first will be pretty cheap. */
13074 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
13076 /* Move over display elements that are not visible because we are
13077 hscrolled. This may stop at an x-position < IT->first_visible_x
13078 if the first glyph is partially visible or if we hit a line end. */
13079 if (it
->current_x
< it
->first_visible_x
)
13080 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
13081 MOVE_TO_POS
| MOVE_TO_X
);
13083 /* Get the initial row height. This is either the height of the
13084 text hscrolled, if there is any, or zero. */
13085 row
->ascent
= it
->max_ascent
;
13086 row
->height
= it
->max_ascent
+ it
->max_descent
;
13087 row
->phys_ascent
= it
->max_phys_ascent
;
13088 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13090 /* Loop generating characters. The loop is left with IT on the next
13091 character to display. */
13094 int n_glyphs_before
, hpos_before
, x_before
;
13096 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
13098 /* Retrieve the next thing to display. Value is zero if end of
13100 if (!get_next_display_element (it
))
13102 /* Maybe add a space at the end of this line that is used to
13103 display the cursor there under X. Set the charpos of the
13104 first glyph of blank lines not corresponding to any text
13106 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
13107 || row
->used
[TEXT_AREA
] == 0)
13109 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
13110 row
->displays_text_p
= 0;
13112 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
13113 && (!MINI_WINDOW_P (it
->w
)
13114 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
13115 row
->indicate_empty_line_p
= 1;
13118 it
->continuation_lines_width
= 0;
13119 row
->ends_at_zv_p
= 1;
13123 /* Now, get the metrics of what we want to display. This also
13124 generates glyphs in `row' (which is IT->glyph_row). */
13125 n_glyphs_before
= row
->used
[TEXT_AREA
];
13128 /* Remember the line height so far in case the next element doesn't
13129 fit on the line. */
13130 if (!it
->truncate_lines_p
)
13132 ascent
= it
->max_ascent
;
13133 descent
= it
->max_descent
;
13134 phys_ascent
= it
->max_phys_ascent
;
13135 phys_descent
= it
->max_phys_descent
;
13138 PRODUCE_GLYPHS (it
);
13140 /* If this display element was in marginal areas, continue with
13142 if (it
->area
!= TEXT_AREA
)
13144 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13145 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13146 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13147 row
->phys_height
= max (row
->phys_height
,
13148 it
->max_phys_ascent
+ it
->max_phys_descent
);
13149 set_iterator_to_next (it
, 1);
13153 /* Does the display element fit on the line? If we truncate
13154 lines, we should draw past the right edge of the window. If
13155 we don't truncate, we want to stop so that we can display the
13156 continuation glyph before the right margin. If lines are
13157 continued, there are two possible strategies for characters
13158 resulting in more than 1 glyph (e.g. tabs): Display as many
13159 glyphs as possible in this line and leave the rest for the
13160 continuation line, or display the whole element in the next
13161 line. Original redisplay did the former, so we do it also. */
13162 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
13163 hpos_before
= it
->hpos
;
13166 if (/* Not a newline. */
13168 /* Glyphs produced fit entirely in the line. */
13169 && it
->current_x
< it
->last_visible_x
)
13171 it
->hpos
+= nglyphs
;
13172 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13173 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13174 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13175 row
->phys_height
= max (row
->phys_height
,
13176 it
->max_phys_ascent
+ it
->max_phys_descent
);
13177 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
13178 row
->x
= x
- it
->first_visible_x
;
13183 struct glyph
*glyph
;
13185 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
13187 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13188 new_x
= x
+ glyph
->pixel_width
;
13190 if (/* Lines are continued. */
13191 !it
->truncate_lines_p
13192 && (/* Glyph doesn't fit on the line. */
13193 new_x
> it
->last_visible_x
13194 /* Or it fits exactly on a window system frame. */
13195 || (new_x
== it
->last_visible_x
13196 && FRAME_WINDOW_P (it
->f
))))
13198 /* End of a continued line. */
13201 || (new_x
== it
->last_visible_x
13202 && FRAME_WINDOW_P (it
->f
)))
13204 /* Current glyph is the only one on the line or
13205 fits exactly on the line. We must continue
13206 the line because we can't draw the cursor
13207 after the glyph. */
13208 row
->continued_p
= 1;
13209 it
->current_x
= new_x
;
13210 it
->continuation_lines_width
+= new_x
;
13212 if (i
== nglyphs
- 1)
13213 set_iterator_to_next (it
, 1);
13215 else if (CHAR_GLYPH_PADDING_P (*glyph
)
13216 && !FRAME_WINDOW_P (it
->f
))
13218 /* A padding glyph that doesn't fit on this line.
13219 This means the whole character doesn't fit
13221 row
->used
[TEXT_AREA
] = n_glyphs_before
;
13223 /* Fill the rest of the row with continuation
13224 glyphs like in 20.x. */
13225 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
13226 < row
->glyphs
[1 + TEXT_AREA
])
13227 produce_special_glyphs (it
, IT_CONTINUATION
);
13229 row
->continued_p
= 1;
13230 it
->current_x
= x_before
;
13231 it
->continuation_lines_width
+= x_before
;
13233 /* Restore the height to what it was before the
13234 element not fitting on the line. */
13235 it
->max_ascent
= ascent
;
13236 it
->max_descent
= descent
;
13237 it
->max_phys_ascent
= phys_ascent
;
13238 it
->max_phys_descent
= phys_descent
;
13240 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
13242 /* A TAB that extends past the right edge of the
13243 window. This produces a single glyph on
13244 window system frames. We leave the glyph in
13245 this row and let it fill the row, but don't
13246 consume the TAB. */
13247 it
->continuation_lines_width
+= it
->last_visible_x
;
13248 row
->ends_in_middle_of_char_p
= 1;
13249 row
->continued_p
= 1;
13250 glyph
->pixel_width
= it
->last_visible_x
- x
;
13251 it
->starts_in_middle_of_char_p
= 1;
13255 /* Something other than a TAB that draws past
13256 the right edge of the window. Restore
13257 positions to values before the element. */
13258 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13260 /* Display continuation glyphs. */
13261 if (!FRAME_WINDOW_P (it
->f
))
13262 produce_special_glyphs (it
, IT_CONTINUATION
);
13263 row
->continued_p
= 1;
13265 it
->continuation_lines_width
+= x
;
13267 if (nglyphs
> 1 && i
> 0)
13269 row
->ends_in_middle_of_char_p
= 1;
13270 it
->starts_in_middle_of_char_p
= 1;
13273 /* Restore the height to what it was before the
13274 element not fitting on the line. */
13275 it
->max_ascent
= ascent
;
13276 it
->max_descent
= descent
;
13277 it
->max_phys_ascent
= phys_ascent
;
13278 it
->max_phys_descent
= phys_descent
;
13283 else if (new_x
> it
->first_visible_x
)
13285 /* Increment number of glyphs actually displayed. */
13288 if (x
< it
->first_visible_x
)
13289 /* Glyph is partially visible, i.e. row starts at
13290 negative X position. */
13291 row
->x
= x
- it
->first_visible_x
;
13295 /* Glyph is completely off the left margin of the
13296 window. This should not happen because of the
13297 move_it_in_display_line at the start of this
13298 function, unless the text display area of the
13299 window is empty. */
13300 xassert (it
->first_visible_x
<= it
->last_visible_x
);
13304 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13305 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13306 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13307 row
->phys_height
= max (row
->phys_height
,
13308 it
->max_phys_ascent
+ it
->max_phys_descent
);
13310 /* End of this display line if row is continued. */
13311 if (row
->continued_p
)
13315 /* Is this a line end? If yes, we're also done, after making
13316 sure that a non-default face is extended up to the right
13317 margin of the window. */
13318 if (ITERATOR_AT_END_OF_LINE_P (it
))
13320 int used_before
= row
->used
[TEXT_AREA
];
13322 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13324 /* Add a space at the end of the line that is used to
13325 display the cursor there. */
13326 append_space (it
, 0);
13328 /* Extend the face to the end of the line. */
13329 extend_face_to_end_of_line (it
);
13331 /* Make sure we have the position. */
13332 if (used_before
== 0)
13333 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13335 /* Consume the line end. This skips over invisible lines. */
13336 set_iterator_to_next (it
, 1);
13337 it
->continuation_lines_width
= 0;
13341 /* Proceed with next display element. Note that this skips
13342 over lines invisible because of selective display. */
13343 set_iterator_to_next (it
, 1);
13345 /* If we truncate lines, we are done when the last displayed
13346 glyphs reach past the right margin of the window. */
13347 if (it
->truncate_lines_p
13348 && (FRAME_WINDOW_P (it
->f
)
13349 ? (it
->current_x
>= it
->last_visible_x
)
13350 : (it
->current_x
> it
->last_visible_x
)))
13352 /* Maybe add truncation glyphs. */
13353 if (!FRAME_WINDOW_P (it
->f
))
13357 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13358 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13361 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13363 row
->used
[TEXT_AREA
] = i
;
13364 produce_special_glyphs (it
, IT_TRUNCATION
);
13368 row
->truncated_on_right_p
= 1;
13369 it
->continuation_lines_width
= 0;
13370 reseat_at_next_visible_line_start (it
, 0);
13371 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13372 it
->hpos
= hpos_before
;
13373 it
->current_x
= x_before
;
13378 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13379 at the left window margin. */
13380 if (it
->first_visible_x
13381 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13383 if (!FRAME_WINDOW_P (it
->f
))
13384 insert_left_trunc_glyphs (it
);
13385 row
->truncated_on_left_p
= 1;
13388 /* If the start of this line is the overlay arrow-position, then
13389 mark this glyph row as the one containing the overlay arrow.
13390 This is clearly a mess with variable size fonts. It would be
13391 better to let it be displayed like cursors under X. */
13392 if (MARKERP (Voverlay_arrow_position
)
13393 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13394 && (MATRIX_ROW_START_CHARPOS (row
)
13395 == marker_position (Voverlay_arrow_position
))
13396 && STRINGP (Voverlay_arrow_string
)
13397 && ! overlay_arrow_seen
)
13399 /* Overlay arrow in window redisplay is a fringe bitmap. */
13400 if (!FRAME_WINDOW_P (it
->f
))
13402 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13403 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13404 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13405 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13406 struct glyph
*p2
, *end
;
13408 /* Copy the arrow glyphs. */
13409 while (glyph
< arrow_end
)
13412 /* Throw away padding glyphs. */
13414 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13415 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13421 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13425 overlay_arrow_seen
= 1;
13426 row
->overlay_arrow_p
= 1;
13429 /* Compute pixel dimensions of this line. */
13430 compute_line_metrics (it
);
13432 /* Remember the position at which this line ends. */
13433 row
->end
= it
->current
;
13435 /* Maybe set the cursor. */
13436 if (it
->w
->cursor
.vpos
< 0
13437 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13438 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13439 && cursor_row_p (it
->w
, row
))
13440 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13442 /* Highlight trailing whitespace. */
13443 if (!NILP (Vshow_trailing_whitespace
))
13444 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13446 /* Prepare for the next line. This line starts horizontally at (X
13447 HPOS) = (0 0). Vertical positions are incremented. As a
13448 convenience for the caller, IT->glyph_row is set to the next
13450 it
->current_x
= it
->hpos
= 0;
13451 it
->current_y
+= row
->height
;
13454 return row
->displays_text_p
;
13459 /***********************************************************************
13461 ***********************************************************************/
13463 /* Redisplay the menu bar in the frame for window W.
13465 The menu bar of X frames that don't have X toolkit support is
13466 displayed in a special window W->frame->menu_bar_window.
13468 The menu bar of terminal frames is treated specially as far as
13469 glyph matrices are concerned. Menu bar lines are not part of
13470 windows, so the update is done directly on the frame matrix rows
13471 for the menu bar. */
13474 display_menu_bar (w
)
13477 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13482 /* Don't do all this for graphical frames. */
13484 if (!NILP (Vwindow_system
))
13487 #ifdef USE_X_TOOLKIT
13492 if (FRAME_MAC_P (f
))
13496 #ifdef USE_X_TOOLKIT
13497 xassert (!FRAME_WINDOW_P (f
));
13498 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13499 it
.first_visible_x
= 0;
13500 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13501 #else /* not USE_X_TOOLKIT */
13502 if (FRAME_WINDOW_P (f
))
13504 /* Menu bar lines are displayed in the desired matrix of the
13505 dummy window menu_bar_window. */
13506 struct window
*menu_w
;
13507 xassert (WINDOWP (f
->menu_bar_window
));
13508 menu_w
= XWINDOW (f
->menu_bar_window
);
13509 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13511 it
.first_visible_x
= 0;
13512 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13516 /* This is a TTY frame, i.e. character hpos/vpos are used as
13518 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13520 it
.first_visible_x
= 0;
13521 it
.last_visible_x
= FRAME_WIDTH (f
);
13523 #endif /* not USE_X_TOOLKIT */
13525 if (! mode_line_inverse_video
)
13526 /* Force the menu-bar to be displayed in the default face. */
13527 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13529 /* Clear all rows of the menu bar. */
13530 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13532 struct glyph_row
*row
= it
.glyph_row
+ i
;
13533 clear_glyph_row (row
);
13534 row
->enabled_p
= 1;
13535 row
->full_width_p
= 1;
13538 /* Display all items of the menu bar. */
13539 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13540 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13542 Lisp_Object string
;
13544 /* Stop at nil string. */
13545 string
= AREF (items
, i
+ 1);
13549 /* Remember where item was displayed. */
13550 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13552 /* Display the item, pad with one space. */
13553 if (it
.current_x
< it
.last_visible_x
)
13554 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13555 SCHARS (string
) + 1, 0, 0, -1);
13558 /* Fill out the line with spaces. */
13559 if (it
.current_x
< it
.last_visible_x
)
13560 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13562 /* Compute the total height of the lines. */
13563 compute_line_metrics (&it
);
13568 /***********************************************************************
13570 ***********************************************************************/
13572 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13573 FORCE is non-zero, redisplay mode lines unconditionally.
13574 Otherwise, redisplay only mode lines that are garbaged. Value is
13575 the number of windows whose mode lines were redisplayed. */
13578 redisplay_mode_lines (window
, force
)
13579 Lisp_Object window
;
13584 while (!NILP (window
))
13586 struct window
*w
= XWINDOW (window
);
13588 if (WINDOWP (w
->hchild
))
13589 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13590 else if (WINDOWP (w
->vchild
))
13591 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13593 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13594 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13596 struct text_pos lpoint
;
13597 struct buffer
*old
= current_buffer
;
13599 /* Set the window's buffer for the mode line display. */
13600 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13601 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13603 /* Point refers normally to the selected window. For any
13604 other window, set up appropriate value. */
13605 if (!EQ (window
, selected_window
))
13607 struct text_pos pt
;
13609 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13610 if (CHARPOS (pt
) < BEGV
)
13611 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13612 else if (CHARPOS (pt
) > (ZV
- 1))
13613 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13615 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13618 /* Display mode lines. */
13619 clear_glyph_matrix (w
->desired_matrix
);
13620 if (display_mode_lines (w
))
13623 w
->must_be_updated_p
= 1;
13626 /* Restore old settings. */
13627 set_buffer_internal_1 (old
);
13628 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13638 /* Display the mode and/or top line of window W. Value is the number
13639 of mode lines displayed. */
13642 display_mode_lines (w
)
13645 Lisp_Object old_selected_window
, old_selected_frame
;
13648 old_selected_frame
= selected_frame
;
13649 selected_frame
= w
->frame
;
13650 old_selected_window
= selected_window
;
13651 XSETWINDOW (selected_window
, w
);
13653 /* These will be set while the mode line specs are processed. */
13654 line_number_displayed
= 0;
13655 w
->column_number_displayed
= Qnil
;
13657 if (WINDOW_WANTS_MODELINE_P (w
))
13659 struct window
*sel_w
= XWINDOW (old_selected_window
);
13661 /* Select mode line face based on the real selected window. */
13662 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
13663 current_buffer
->mode_line_format
);
13667 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13669 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13670 current_buffer
->header_line_format
);
13674 selected_frame
= old_selected_frame
;
13675 selected_window
= old_selected_window
;
13680 /* Display mode or top line of window W. FACE_ID specifies which line
13681 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13682 FORMAT is the mode line format to display. Value is the pixel
13683 height of the mode line displayed. */
13686 display_mode_line (w
, face_id
, format
)
13688 enum face_id face_id
;
13689 Lisp_Object format
;
13694 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13695 prepare_desired_row (it
.glyph_row
);
13697 if (! mode_line_inverse_video
)
13698 /* Force the mode-line to be displayed in the default face. */
13699 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13701 /* Temporarily make frame's keyboard the current kboard so that
13702 kboard-local variables in the mode_line_format will get the right
13704 push_frame_kboard (it
.f
);
13705 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
13706 pop_frame_kboard ();
13708 /* Fill up with spaces. */
13709 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13711 compute_line_metrics (&it
);
13712 it
.glyph_row
->full_width_p
= 1;
13713 it
.glyph_row
->mode_line_p
= 1;
13714 it
.glyph_row
->continued_p
= 0;
13715 it
.glyph_row
->truncated_on_left_p
= 0;
13716 it
.glyph_row
->truncated_on_right_p
= 0;
13718 /* Make a 3D mode-line have a shadow at its right end. */
13719 face
= FACE_FROM_ID (it
.f
, face_id
);
13720 extend_face_to_end_of_line (&it
);
13721 if (face
->box
!= FACE_NO_BOX
)
13723 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13724 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13725 last
->right_box_line_p
= 1;
13728 return it
.glyph_row
->height
;
13731 /* Alist that caches the results of :propertize.
13732 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
13733 Lisp_Object mode_line_proptrans_alist
;
13735 /* List of strings making up the mode-line. */
13736 Lisp_Object mode_line_string_list
;
13738 /* Base face property when building propertized mode line string. */
13739 static Lisp_Object mode_line_string_face
;
13740 static Lisp_Object mode_line_string_face_prop
;
13743 /* Contribute ELT to the mode line for window IT->w. How it
13744 translates into text depends on its data type.
13746 IT describes the display environment in which we display, as usual.
13748 DEPTH is the depth in recursion. It is used to prevent
13749 infinite recursion here.
13751 FIELD_WIDTH is the number of characters the display of ELT should
13752 occupy in the mode line, and PRECISION is the maximum number of
13753 characters to display from ELT's representation. See
13754 display_string for details.
13756 Returns the hpos of the end of the text generated by ELT.
13758 PROPS is a property list to add to any string we encounter.
13760 If RISKY is nonzero, remove (disregard) any properties in any string
13761 we encounter, and ignore :eval and :propertize.
13763 If the global variable `frame_title_ptr' is non-NULL, then the output
13764 is passed to `store_frame_title' instead of `display_string'. */
13767 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
13770 int field_width
, precision
;
13771 Lisp_Object elt
, props
;
13774 int n
= 0, field
, prec
;
13783 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13787 /* A string: output it and check for %-constructs within it. */
13789 const unsigned char *this, *lisp_string
;
13791 if (!NILP (props
) || risky
)
13793 Lisp_Object oprops
, aelt
;
13794 oprops
= Ftext_properties_at (make_number (0), elt
);
13796 if (NILP (Fequal (props
, oprops
)) || risky
)
13798 /* If the starting string has properties,
13799 merge the specified ones onto the existing ones. */
13800 if (! NILP (oprops
) && !risky
)
13804 oprops
= Fcopy_sequence (oprops
);
13806 while (CONSP (tem
))
13808 oprops
= Fplist_put (oprops
, XCAR (tem
),
13809 XCAR (XCDR (tem
)));
13810 tem
= XCDR (XCDR (tem
));
13815 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
13816 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
13818 mode_line_proptrans_alist
13819 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
13826 elt
= Fcopy_sequence (elt
);
13827 Fset_text_properties (make_number (0), Flength (elt
),
13829 /* Add this item to mode_line_proptrans_alist. */
13830 mode_line_proptrans_alist
13831 = Fcons (Fcons (elt
, props
),
13832 mode_line_proptrans_alist
);
13833 /* Truncate mode_line_proptrans_alist
13834 to at most 50 elements. */
13835 tem
= Fnthcdr (make_number (50),
13836 mode_line_proptrans_alist
);
13838 XSETCDR (tem
, Qnil
);
13843 this = SDATA (elt
);
13844 lisp_string
= this;
13848 prec
= precision
- n
;
13849 if (frame_title_ptr
)
13850 n
+= store_frame_title (SDATA (elt
), -1, prec
);
13851 else if (!NILP (mode_line_string_list
))
13852 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
13854 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
13855 0, prec
, 0, STRING_MULTIBYTE (elt
));
13860 while ((precision
<= 0 || n
< precision
)
13862 && (frame_title_ptr
13863 || !NILP (mode_line_string_list
)
13864 || it
->current_x
< it
->last_visible_x
))
13866 const unsigned char *last
= this;
13868 /* Advance to end of string or next format specifier. */
13869 while ((c
= *this++) != '\0' && c
!= '%')
13872 if (this - 1 != last
)
13874 /* Output to end of string or up to '%'. Field width
13875 is length of string. Don't output more than
13876 PRECISION allows us. */
13879 prec
= chars_in_text (last
, this - last
);
13880 if (precision
> 0 && prec
> precision
- n
)
13881 prec
= precision
- n
;
13883 if (frame_title_ptr
)
13884 n
+= store_frame_title (last
, 0, prec
);
13885 else if (!NILP (mode_line_string_list
))
13887 int bytepos
= last
- lisp_string
;
13888 int charpos
= string_byte_to_char (elt
, bytepos
);
13889 n
+= store_mode_line_string (NULL
,
13890 Fsubstring (elt
, make_number (charpos
),
13891 make_number (charpos
+ prec
)),
13896 int bytepos
= last
- lisp_string
;
13897 int charpos
= string_byte_to_char (elt
, bytepos
);
13898 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
13900 STRING_MULTIBYTE (elt
));
13903 else /* c == '%' */
13905 const unsigned char *percent_position
= this;
13907 /* Get the specified minimum width. Zero means
13910 while ((c
= *this++) >= '0' && c
<= '9')
13911 field
= field
* 10 + c
- '0';
13913 /* Don't pad beyond the total padding allowed. */
13914 if (field_width
- n
> 0 && field
> field_width
- n
)
13915 field
= field_width
- n
;
13917 /* Note that either PRECISION <= 0 or N < PRECISION. */
13918 prec
= precision
- n
;
13921 n
+= display_mode_element (it
, depth
, field
, prec
,
13922 Vglobal_mode_string
, props
,
13927 int bytepos
, charpos
;
13928 unsigned char *spec
;
13930 bytepos
= percent_position
- lisp_string
;
13931 charpos
= (STRING_MULTIBYTE (elt
)
13932 ? string_byte_to_char (elt
, bytepos
)
13936 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
13938 if (frame_title_ptr
)
13939 n
+= store_frame_title (spec
, field
, prec
);
13940 else if (!NILP (mode_line_string_list
))
13942 int len
= strlen (spec
);
13943 Lisp_Object tem
= make_string (spec
, len
);
13944 props
= Ftext_properties_at (make_number (charpos
), elt
);
13945 /* Should only keep face property in props */
13946 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
13950 int nglyphs_before
, nwritten
;
13952 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13953 nwritten
= display_string (spec
, Qnil
, elt
,
13958 /* Assign to the glyphs written above the
13959 string where the `%x' came from, position
13963 struct glyph
*glyph
13964 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13968 for (i
= 0; i
< nwritten
; ++i
)
13970 glyph
[i
].object
= elt
;
13971 glyph
[i
].charpos
= charpos
;
13986 /* A symbol: process the value of the symbol recursively
13987 as if it appeared here directly. Avoid error if symbol void.
13988 Special case: if value of symbol is a string, output the string
13991 register Lisp_Object tem
;
13993 /* If the variable is not marked as risky to set
13994 then its contents are risky to use. */
13995 if (NILP (Fget (elt
, Qrisky_local_variable
)))
13998 tem
= Fboundp (elt
);
14001 tem
= Fsymbol_value (elt
);
14002 /* If value is a string, output that string literally:
14003 don't check for % within it. */
14007 if (!EQ (tem
, elt
))
14009 /* Give up right away for nil or t. */
14019 register Lisp_Object car
, tem
;
14021 /* A cons cell: five distinct cases.
14022 If first element is :eval or :propertize, do something special.
14023 If first element is a string or a cons, process all the elements
14024 and effectively concatenate them.
14025 If first element is a negative number, truncate displaying cdr to
14026 at most that many characters. If positive, pad (with spaces)
14027 to at least that many characters.
14028 If first element is a symbol, process the cadr or caddr recursively
14029 according to whether the symbol's value is non-nil or nil. */
14031 if (EQ (car
, QCeval
))
14033 /* An element of the form (:eval FORM) means evaluate FORM
14034 and use the result as mode line elements. */
14039 if (CONSP (XCDR (elt
)))
14042 spec
= safe_eval (XCAR (XCDR (elt
)));
14043 n
+= display_mode_element (it
, depth
, field_width
- n
,
14044 precision
- n
, spec
, props
,
14048 else if (EQ (car
, QCpropertize
))
14050 /* An element of the form (:propertize ELT PROPS...)
14051 means display ELT but applying properties PROPS. */
14056 if (CONSP (XCDR (elt
)))
14057 n
+= display_mode_element (it
, depth
, field_width
- n
,
14058 precision
- n
, XCAR (XCDR (elt
)),
14059 XCDR (XCDR (elt
)), risky
);
14061 else if (SYMBOLP (car
))
14063 tem
= Fboundp (car
);
14067 /* elt is now the cdr, and we know it is a cons cell.
14068 Use its car if CAR has a non-nil value. */
14071 tem
= Fsymbol_value (car
);
14078 /* Symbol's value is nil (or symbol is unbound)
14079 Get the cddr of the original list
14080 and if possible find the caddr and use that. */
14084 else if (!CONSP (elt
))
14089 else if (INTEGERP (car
))
14091 register int lim
= XINT (car
);
14095 /* Negative int means reduce maximum width. */
14096 if (precision
<= 0)
14099 precision
= min (precision
, -lim
);
14103 /* Padding specified. Don't let it be more than
14104 current maximum. */
14106 lim
= min (precision
, lim
);
14108 /* If that's more padding than already wanted, queue it.
14109 But don't reduce padding already specified even if
14110 that is beyond the current truncation point. */
14111 field_width
= max (lim
, field_width
);
14115 else if (STRINGP (car
) || CONSP (car
))
14117 register int limit
= 50;
14118 /* Limit is to protect against circular lists. */
14121 && (precision
<= 0 || n
< precision
))
14123 n
+= display_mode_element (it
, depth
, field_width
- n
,
14124 precision
- n
, XCAR (elt
),
14134 if (frame_title_ptr
)
14135 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
14136 else if (!NILP (mode_line_string_list
))
14137 n
+= store_mode_line_string ("*invalid*", Qnil
, 0, 0, precision
- n
, Qnil
);
14139 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
14140 precision
- n
, 0, 0);
14144 /* Pad to FIELD_WIDTH. */
14145 if (field_width
> 0 && n
< field_width
)
14147 if (frame_title_ptr
)
14148 n
+= store_frame_title ("", field_width
- n
, 0);
14149 else if (!NILP (mode_line_string_list
))
14150 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
14152 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
14159 /* Store a mode-line string element in mode_line_string_list.
14161 If STRING is non-null, display that C string. Otherwise, the Lisp
14162 string LISP_STRING is displayed.
14164 FIELD_WIDTH is the minimum number of output glyphs to produce.
14165 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14166 with spaces. FIELD_WIDTH <= 0 means don't pad.
14168 PRECISION is the maximum number of characters to output from
14169 STRING. PRECISION <= 0 means don't truncate the string.
14171 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
14172 properties to the string.
14174 PROPS are the properties to add to the string.
14175 The mode_line_string_face face property is always added to the string.
14178 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
14180 Lisp_Object lisp_string
;
14189 if (string
!= NULL
)
14191 len
= strlen (string
);
14192 if (precision
> 0 && len
> precision
)
14194 lisp_string
= make_string (string
, len
);
14196 props
= mode_line_string_face_prop
;
14197 else if (!NILP (mode_line_string_face
))
14199 Lisp_Object face
= Fplist_get (props
, Qface
);
14200 props
= Fcopy_sequence (props
);
14202 face
= mode_line_string_face
;
14204 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14205 props
= Fplist_put (props
, Qface
, face
);
14207 Fadd_text_properties (make_number (0), make_number (len
),
14208 props
, lisp_string
);
14212 len
= XFASTINT (Flength (lisp_string
));
14213 if (precision
> 0 && len
> precision
)
14216 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
14219 if (!NILP (mode_line_string_face
))
14223 props
= Ftext_properties_at (make_number (0), lisp_string
);
14224 face
= Fplist_get (props
, Qface
);
14226 face
= mode_line_string_face
;
14228 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14229 props
= Fcons (Qface
, Fcons (face
, Qnil
));
14231 lisp_string
= Fcopy_sequence (lisp_string
);
14234 Fadd_text_properties (make_number (0), make_number (len
),
14235 props
, lisp_string
);
14240 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14244 if (field_width
> len
)
14246 field_width
-= len
;
14247 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
14249 Fadd_text_properties (make_number (0), make_number (field_width
),
14250 props
, lisp_string
);
14251 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14259 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
14261 doc
: /* Return the mode-line of selected window as a string.
14262 First optional arg FORMAT specifies a different format string (see
14263 `mode-line-format' for details) to use. If FORMAT is t, return
14264 the buffer's header-line. Second optional arg WINDOW specifies a
14265 different window to use as the context for the formatting.
14266 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
14267 (format
, window
, no_props
)
14268 Lisp_Object format
, window
, no_props
;
14273 struct buffer
*old_buffer
= NULL
;
14274 enum face_id face_id
= DEFAULT_FACE_ID
;
14277 window
= selected_window
;
14278 CHECK_WINDOW (window
);
14279 w
= XWINDOW (window
);
14280 CHECK_BUFFER (w
->buffer
);
14282 if (XBUFFER (w
->buffer
) != current_buffer
)
14284 old_buffer
= current_buffer
;
14285 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14288 if (NILP (format
) || EQ (format
, Qt
))
14290 face_id
= NILP (format
)
14291 ? CURRENT_MODE_LINE_FACE_ID (w
) :
14292 HEADER_LINE_FACE_ID
;
14293 format
= NILP (format
)
14294 ? current_buffer
->mode_line_format
14295 : current_buffer
->header_line_format
;
14298 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
14300 if (NILP (no_props
))
14302 mode_line_string_face
=
14303 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
14304 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
14305 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
14307 mode_line_string_face_prop
=
14308 NILP (mode_line_string_face
) ? Qnil
:
14309 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
14311 /* We need a dummy last element in mode_line_string_list to
14312 indicate we are building the propertized mode-line string.
14313 Using mode_line_string_face_prop here GC protects it. */
14314 mode_line_string_list
=
14315 Fcons (mode_line_string_face_prop
, Qnil
);
14316 frame_title_ptr
= NULL
;
14320 mode_line_string_face_prop
= Qnil
;
14321 mode_line_string_list
= Qnil
;
14322 frame_title_ptr
= frame_title_buf
;
14325 push_frame_kboard (it
.f
);
14326 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
14327 pop_frame_kboard ();
14330 set_buffer_internal_1 (old_buffer
);
14332 if (NILP (no_props
))
14335 mode_line_string_list
= Fnreverse (mode_line_string_list
);
14336 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
14337 make_string ("", 0));
14338 mode_line_string_face_prop
= Qnil
;
14339 mode_line_string_list
= Qnil
;
14343 len
= frame_title_ptr
- frame_title_buf
;
14344 if (len
> 0 && frame_title_ptr
[-1] == '-')
14346 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
14347 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
14349 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
14350 if (len
> frame_title_ptr
- frame_title_buf
)
14351 len
= frame_title_ptr
- frame_title_buf
;
14354 frame_title_ptr
= NULL
;
14355 return make_string (frame_title_buf
, len
);
14358 /* Write a null-terminated, right justified decimal representation of
14359 the positive integer D to BUF using a minimal field width WIDTH. */
14362 pint2str (buf
, width
, d
)
14363 register char *buf
;
14364 register int width
;
14367 register char *p
= buf
;
14375 *p
++ = d
% 10 + '0';
14380 for (width
-= (int) (p
- buf
); width
> 0; --width
)
14391 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
14392 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
14393 type of CODING_SYSTEM. Return updated pointer into BUF. */
14395 static unsigned char invalid_eol_type
[] = "(*invalid*)";
14398 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
14399 Lisp_Object coding_system
;
14400 register char *buf
;
14404 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
14405 const unsigned char *eol_str
;
14407 /* The EOL conversion we are using. */
14408 Lisp_Object eoltype
;
14410 val
= Fget (coding_system
, Qcoding_system
);
14413 if (!VECTORP (val
)) /* Not yet decided. */
14418 eoltype
= eol_mnemonic_undecided
;
14419 /* Don't mention EOL conversion if it isn't decided. */
14423 Lisp_Object eolvalue
;
14425 eolvalue
= Fget (coding_system
, Qeol_type
);
14428 *buf
++ = XFASTINT (AREF (val
, 1));
14432 /* The EOL conversion that is normal on this system. */
14434 if (NILP (eolvalue
)) /* Not yet decided. */
14435 eoltype
= eol_mnemonic_undecided
;
14436 else if (VECTORP (eolvalue
)) /* Not yet decided. */
14437 eoltype
= eol_mnemonic_undecided
;
14438 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
14439 eoltype
= (XFASTINT (eolvalue
) == 0
14440 ? eol_mnemonic_unix
14441 : (XFASTINT (eolvalue
) == 1
14442 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
14448 /* Mention the EOL conversion if it is not the usual one. */
14449 if (STRINGP (eoltype
))
14451 eol_str
= SDATA (eoltype
);
14452 eol_str_len
= SBYTES (eoltype
);
14454 else if (INTEGERP (eoltype
)
14455 && CHAR_VALID_P (XINT (eoltype
), 0))
14457 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
14458 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
14463 eol_str
= invalid_eol_type
;
14464 eol_str_len
= sizeof (invalid_eol_type
) - 1;
14466 bcopy (eol_str
, buf
, eol_str_len
);
14467 buf
+= eol_str_len
;
14473 /* Return a string for the output of a mode line %-spec for window W,
14474 generated by character C. PRECISION >= 0 means don't return a
14475 string longer than that value. FIELD_WIDTH > 0 means pad the
14476 string returned with spaces to that value. Return 1 in *MULTIBYTE
14477 if the result is multibyte text. */
14479 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
14482 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
14485 int field_width
, precision
;
14489 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14490 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
14491 struct buffer
*b
= XBUFFER (w
->buffer
);
14499 if (!NILP (b
->read_only
))
14501 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14506 /* This differs from %* only for a modified read-only buffer. */
14507 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14509 if (!NILP (b
->read_only
))
14514 /* This differs from %* in ignoring read-only-ness. */
14515 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14527 if (command_loop_level
> 5)
14529 p
= decode_mode_spec_buf
;
14530 for (i
= 0; i
< command_loop_level
; i
++)
14533 return decode_mode_spec_buf
;
14541 if (command_loop_level
> 5)
14543 p
= decode_mode_spec_buf
;
14544 for (i
= 0; i
< command_loop_level
; i
++)
14547 return decode_mode_spec_buf
;
14554 /* Let lots_of_dashes be a string of infinite length. */
14555 if (!NILP (mode_line_string_list
))
14557 if (field_width
<= 0
14558 || field_width
> sizeof (lots_of_dashes
))
14560 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
14561 decode_mode_spec_buf
[i
] = '-';
14562 decode_mode_spec_buf
[i
] = '\0';
14563 return decode_mode_spec_buf
;
14566 return lots_of_dashes
;
14575 int col
= (int) current_column (); /* iftc */
14576 w
->column_number_displayed
= make_number (col
);
14577 pint2str (decode_mode_spec_buf
, field_width
, col
);
14578 return decode_mode_spec_buf
;
14582 /* %F displays the frame name. */
14583 if (!NILP (f
->title
))
14584 return (char *) SDATA (f
->title
);
14585 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
14586 return (char *) SDATA (f
->name
);
14595 int startpos
= XMARKER (w
->start
)->charpos
;
14596 int startpos_byte
= marker_byte_position (w
->start
);
14597 int line
, linepos
, linepos_byte
, topline
;
14599 int height
= XFASTINT (w
->height
);
14601 /* If we decided that this buffer isn't suitable for line numbers,
14602 don't forget that too fast. */
14603 if (EQ (w
->base_line_pos
, w
->buffer
))
14605 /* But do forget it, if the window shows a different buffer now. */
14606 else if (BUFFERP (w
->base_line_pos
))
14607 w
->base_line_pos
= Qnil
;
14609 /* If the buffer is very big, don't waste time. */
14610 if (INTEGERP (Vline_number_display_limit
)
14611 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
14613 w
->base_line_pos
= Qnil
;
14614 w
->base_line_number
= Qnil
;
14618 if (!NILP (w
->base_line_number
)
14619 && !NILP (w
->base_line_pos
)
14620 && XFASTINT (w
->base_line_pos
) <= startpos
)
14622 line
= XFASTINT (w
->base_line_number
);
14623 linepos
= XFASTINT (w
->base_line_pos
);
14624 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
14629 linepos
= BUF_BEGV (b
);
14630 linepos_byte
= BUF_BEGV_BYTE (b
);
14633 /* Count lines from base line to window start position. */
14634 nlines
= display_count_lines (linepos
, linepos_byte
,
14638 topline
= nlines
+ line
;
14640 /* Determine a new base line, if the old one is too close
14641 or too far away, or if we did not have one.
14642 "Too close" means it's plausible a scroll-down would
14643 go back past it. */
14644 if (startpos
== BUF_BEGV (b
))
14646 w
->base_line_number
= make_number (topline
);
14647 w
->base_line_pos
= make_number (BUF_BEGV (b
));
14649 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
14650 || linepos
== BUF_BEGV (b
))
14652 int limit
= BUF_BEGV (b
);
14653 int limit_byte
= BUF_BEGV_BYTE (b
);
14655 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
14657 if (startpos
- distance
> limit
)
14659 limit
= startpos
- distance
;
14660 limit_byte
= CHAR_TO_BYTE (limit
);
14663 nlines
= display_count_lines (startpos
, startpos_byte
,
14665 - (height
* 2 + 30),
14667 /* If we couldn't find the lines we wanted within
14668 line_number_display_limit_width chars per line,
14669 give up on line numbers for this window. */
14670 if (position
== limit_byte
&& limit
== startpos
- distance
)
14672 w
->base_line_pos
= w
->buffer
;
14673 w
->base_line_number
= Qnil
;
14677 w
->base_line_number
= make_number (topline
- nlines
);
14678 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
14681 /* Now count lines from the start pos to point. */
14682 nlines
= display_count_lines (startpos
, startpos_byte
,
14683 PT_BYTE
, PT
, &junk
);
14685 /* Record that we did display the line number. */
14686 line_number_displayed
= 1;
14688 /* Make the string to show. */
14689 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
14690 return decode_mode_spec_buf
;
14693 char* p
= decode_mode_spec_buf
;
14694 int pad
= field_width
- 2;
14700 return decode_mode_spec_buf
;
14706 obj
= b
->mode_name
;
14710 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
14716 int pos
= marker_position (w
->start
);
14717 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14719 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
14721 if (pos
<= BUF_BEGV (b
))
14726 else if (pos
<= BUF_BEGV (b
))
14730 if (total
> 1000000)
14731 /* Do it differently for a large value, to avoid overflow. */
14732 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14734 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14735 /* We can't normally display a 3-digit number,
14736 so get us a 2-digit number that is close. */
14739 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14740 return decode_mode_spec_buf
;
14744 /* Display percentage of size above the bottom of the screen. */
14747 int toppos
= marker_position (w
->start
);
14748 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14749 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14751 if (botpos
>= BUF_ZV (b
))
14753 if (toppos
<= BUF_BEGV (b
))
14760 if (total
> 1000000)
14761 /* Do it differently for a large value, to avoid overflow. */
14762 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14764 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14765 /* We can't normally display a 3-digit number,
14766 so get us a 2-digit number that is close. */
14769 if (toppos
<= BUF_BEGV (b
))
14770 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14772 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14773 return decode_mode_spec_buf
;
14778 /* status of process */
14779 obj
= Fget_buffer_process (w
->buffer
);
14781 return "no process";
14782 #ifdef subprocesses
14783 obj
= Fsymbol_name (Fprocess_status (obj
));
14787 case 't': /* indicate TEXT or BINARY */
14788 #ifdef MODE_LINE_BINARY_TEXT
14789 return MODE_LINE_BINARY_TEXT (b
);
14795 /* coding-system (not including end-of-line format) */
14797 /* coding-system (including end-of-line type) */
14799 int eol_flag
= (c
== 'Z');
14800 char *p
= decode_mode_spec_buf
;
14802 if (! FRAME_WINDOW_P (f
))
14804 /* No need to mention EOL here--the terminal never needs
14805 to do EOL conversion. */
14806 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14807 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14809 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14812 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14813 #ifdef subprocesses
14814 obj
= Fget_buffer_process (Fcurrent_buffer ());
14815 if (PROCESSP (obj
))
14817 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14819 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14822 #endif /* subprocesses */
14825 return decode_mode_spec_buf
;
14831 *multibyte
= STRING_MULTIBYTE (obj
);
14832 return (char *) SDATA (obj
);
14839 /* Count up to COUNT lines starting from START / START_BYTE.
14840 But don't go beyond LIMIT_BYTE.
14841 Return the number of lines thus found (always nonnegative).
14843 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14846 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14847 int start
, start_byte
, limit_byte
, count
;
14850 register unsigned char *cursor
;
14851 unsigned char *base
;
14853 register int ceiling
;
14854 register unsigned char *ceiling_addr
;
14855 int orig_count
= count
;
14857 /* If we are not in selective display mode,
14858 check only for newlines. */
14859 int selective_display
= (!NILP (current_buffer
->selective_display
)
14860 && !INTEGERP (current_buffer
->selective_display
));
14864 while (start_byte
< limit_byte
)
14866 ceiling
= BUFFER_CEILING_OF (start_byte
);
14867 ceiling
= min (limit_byte
- 1, ceiling
);
14868 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14869 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14872 if (selective_display
)
14873 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14876 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14879 if (cursor
!= ceiling_addr
)
14883 start_byte
+= cursor
- base
+ 1;
14884 *byte_pos_ptr
= start_byte
;
14888 if (++cursor
== ceiling_addr
)
14894 start_byte
+= cursor
- base
;
14899 while (start_byte
> limit_byte
)
14901 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14902 ceiling
= max (limit_byte
, ceiling
);
14903 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14904 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14907 if (selective_display
)
14908 while (--cursor
!= ceiling_addr
14909 && *cursor
!= '\n' && *cursor
!= 015)
14912 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14915 if (cursor
!= ceiling_addr
)
14919 start_byte
+= cursor
- base
+ 1;
14920 *byte_pos_ptr
= start_byte
;
14921 /* When scanning backwards, we should
14922 not count the newline posterior to which we stop. */
14923 return - orig_count
- 1;
14929 /* Here we add 1 to compensate for the last decrement
14930 of CURSOR, which took it past the valid range. */
14931 start_byte
+= cursor
- base
+ 1;
14935 *byte_pos_ptr
= limit_byte
;
14938 return - orig_count
+ count
;
14939 return orig_count
- count
;
14945 /***********************************************************************
14947 ***********************************************************************/
14949 /* Display a NUL-terminated string, starting with index START.
14951 If STRING is non-null, display that C string. Otherwise, the Lisp
14952 string LISP_STRING is displayed.
14954 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14955 FACE_STRING. Display STRING or LISP_STRING with the face at
14956 FACE_STRING_POS in FACE_STRING:
14958 Display the string in the environment given by IT, but use the
14959 standard display table, temporarily.
14961 FIELD_WIDTH is the minimum number of output glyphs to produce.
14962 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14963 with spaces. If STRING has more characters, more than FIELD_WIDTH
14964 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14966 PRECISION is the maximum number of characters to output from
14967 STRING. PRECISION < 0 means don't truncate the string.
14969 This is roughly equivalent to printf format specifiers:
14971 FIELD_WIDTH PRECISION PRINTF
14972 ----------------------------------------
14978 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14979 display them, and < 0 means obey the current buffer's value of
14980 enable_multibyte_characters.
14982 Value is the number of glyphs produced. */
14985 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14986 start
, it
, field_width
, precision
, max_x
, multibyte
)
14987 unsigned char *string
;
14988 Lisp_Object lisp_string
;
14989 Lisp_Object face_string
;
14990 int face_string_pos
;
14993 int field_width
, precision
, max_x
;
14996 int hpos_at_start
= it
->hpos
;
14997 int saved_face_id
= it
->face_id
;
14998 struct glyph_row
*row
= it
->glyph_row
;
15000 /* Initialize the iterator IT for iteration over STRING beginning
15001 with index START. */
15002 reseat_to_string (it
, string
, lisp_string
, start
,
15003 precision
, field_width
, multibyte
);
15005 /* If displaying STRING, set up the face of the iterator
15006 from LISP_STRING, if that's given. */
15007 if (STRINGP (face_string
))
15013 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
15014 0, it
->region_beg_charpos
,
15015 it
->region_end_charpos
,
15016 &endptr
, it
->base_face_id
, 0);
15017 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15018 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
15021 /* Set max_x to the maximum allowed X position. Don't let it go
15022 beyond the right edge of the window. */
15024 max_x
= it
->last_visible_x
;
15026 max_x
= min (max_x
, it
->last_visible_x
);
15028 /* Skip over display elements that are not visible. because IT->w is
15030 if (it
->current_x
< it
->first_visible_x
)
15031 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
15032 MOVE_TO_POS
| MOVE_TO_X
);
15034 row
->ascent
= it
->max_ascent
;
15035 row
->height
= it
->max_ascent
+ it
->max_descent
;
15036 row
->phys_ascent
= it
->max_phys_ascent
;
15037 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15039 /* This condition is for the case that we are called with current_x
15040 past last_visible_x. */
15041 while (it
->current_x
< max_x
)
15043 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
15045 /* Get the next display element. */
15046 if (!get_next_display_element (it
))
15049 /* Produce glyphs. */
15050 x_before
= it
->current_x
;
15051 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15052 PRODUCE_GLYPHS (it
);
15054 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
15057 while (i
< nglyphs
)
15059 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15061 if (!it
->truncate_lines_p
15062 && x
+ glyph
->pixel_width
> max_x
)
15064 /* End of continued line or max_x reached. */
15065 if (CHAR_GLYPH_PADDING_P (*glyph
))
15067 /* A wide character is unbreakable. */
15068 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15069 it
->current_x
= x_before
;
15073 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15078 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
15080 /* Glyph is at least partially visible. */
15082 if (x
< it
->first_visible_x
)
15083 it
->glyph_row
->x
= x
- it
->first_visible_x
;
15087 /* Glyph is off the left margin of the display area.
15088 Should not happen. */
15092 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15093 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15094 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15095 row
->phys_height
= max (row
->phys_height
,
15096 it
->max_phys_ascent
+ it
->max_phys_descent
);
15097 x
+= glyph
->pixel_width
;
15101 /* Stop if max_x reached. */
15105 /* Stop at line ends. */
15106 if (ITERATOR_AT_END_OF_LINE_P (it
))
15108 it
->continuation_lines_width
= 0;
15112 set_iterator_to_next (it
, 1);
15114 /* Stop if truncating at the right edge. */
15115 if (it
->truncate_lines_p
15116 && it
->current_x
>= it
->last_visible_x
)
15118 /* Add truncation mark, but don't do it if the line is
15119 truncated at a padding space. */
15120 if (IT_CHARPOS (*it
) < it
->string_nchars
)
15122 if (!FRAME_WINDOW_P (it
->f
))
15126 if (it
->current_x
> it
->last_visible_x
)
15128 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15129 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15131 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15133 row
->used
[TEXT_AREA
] = i
;
15134 produce_special_glyphs (it
, IT_TRUNCATION
);
15137 produce_special_glyphs (it
, IT_TRUNCATION
);
15139 it
->glyph_row
->truncated_on_right_p
= 1;
15145 /* Maybe insert a truncation at the left. */
15146 if (it
->first_visible_x
15147 && IT_CHARPOS (*it
) > 0)
15149 if (!FRAME_WINDOW_P (it
->f
))
15150 insert_left_trunc_glyphs (it
);
15151 it
->glyph_row
->truncated_on_left_p
= 1;
15154 it
->face_id
= saved_face_id
;
15156 /* Value is number of columns displayed. */
15157 return it
->hpos
- hpos_at_start
;
15162 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
15163 appears as an element of LIST or as the car of an element of LIST.
15164 If PROPVAL is a list, compare each element against LIST in that
15165 way, and return 1/2 if any element of PROPVAL is found in LIST.
15166 Otherwise return 0. This function cannot quit.
15167 The return value is 2 if the text is invisible but with an ellipsis
15168 and 1 if it's invisible and without an ellipsis. */
15171 invisible_p (propval
, list
)
15172 register Lisp_Object propval
;
15175 register Lisp_Object tail
, proptail
;
15177 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15179 register Lisp_Object tem
;
15181 if (EQ (propval
, tem
))
15183 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
15184 return NILP (XCDR (tem
)) ? 1 : 2;
15187 if (CONSP (propval
))
15189 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
15191 Lisp_Object propelt
;
15192 propelt
= XCAR (proptail
);
15193 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15195 register Lisp_Object tem
;
15197 if (EQ (propelt
, tem
))
15199 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
15200 return NILP (XCDR (tem
)) ? 1 : 2;
15209 /***********************************************************************
15211 ***********************************************************************/
15213 /* Value is the internal representation of the specified cursor type
15214 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
15215 of the bar cursor. */
15217 enum text_cursor_kinds
15218 get_specified_cursor_type (arg
, width
)
15222 enum text_cursor_kinds type
;
15227 if (EQ (arg
, Qbox
))
15228 return FILLED_BOX_CURSOR
;
15230 if (EQ (arg
, Qhollow
))
15231 return HOLLOW_BOX_CURSOR
;
15233 if (EQ (arg
, Qbar
))
15240 && EQ (XCAR (arg
), Qbar
)
15241 && INTEGERP (XCDR (arg
))
15242 && XINT (XCDR (arg
)) >= 0)
15244 *width
= XINT (XCDR (arg
));
15248 if (EQ (arg
, Qhbar
))
15251 return HBAR_CURSOR
;
15255 && EQ (XCAR (arg
), Qhbar
)
15256 && INTEGERP (XCDR (arg
))
15257 && XINT (XCDR (arg
)) >= 0)
15259 *width
= XINT (XCDR (arg
));
15260 return HBAR_CURSOR
;
15263 /* Treat anything unknown as "hollow box cursor".
15264 It was bad to signal an error; people have trouble fixing
15265 .Xdefaults with Emacs, when it has something bad in it. */
15266 type
= HOLLOW_BOX_CURSOR
;
15271 /* Set the default cursor types for specified frame. */
15273 set_frame_cursor_types (f
, arg
)
15280 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
15281 FRAME_CURSOR_WIDTH (f
) = width
;
15283 /* By default, set up the blink-off state depending on the on-state. */
15285 tem
= Fassoc (arg
, Vblink_cursor_alist
);
15288 FRAME_BLINK_OFF_CURSOR (f
)
15289 = get_specified_cursor_type (XCDR (tem
), &width
);
15290 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
15293 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
15297 /* Return the cursor we want to be displayed. In a mini-buffer
15298 window, we want the cursor only to appear if we are reading input
15299 from this window. For the selected window, we want the cursor type
15300 given by the frame parameter or buffer local setting of
15301 cursor-type. If explicitly marked off, draw no cursor. In all
15302 other cases, we want a hollow box cursor. */
15304 enum text_cursor_kinds
15305 get_window_cursor_type (w
, width
)
15309 struct frame
*f
= XFRAME (w
->frame
);
15310 struct buffer
*b
= XBUFFER (w
->buffer
);
15311 int cursor_type
= DEFAULT_CURSOR
;
15312 Lisp_Object alt_cursor
;
15313 int non_selected
= 0;
15316 if (cursor_in_echo_area
15317 && FRAME_HAS_MINIBUF_P (f
)
15318 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
15320 if (w
== XWINDOW (echo_area_window
))
15322 *width
= FRAME_CURSOR_WIDTH (f
);
15323 return FRAME_DESIRED_CURSOR (f
);
15329 /* Nonselected window or nonselected frame. */
15330 else if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
15331 || w
!= XWINDOW (f
->selected_window
))
15333 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
15339 /* Never display a cursor in a window in which cursor-type is nil. */
15340 if (NILP (b
->cursor_type
))
15343 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
15346 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
15347 return get_specified_cursor_type (alt_cursor
, width
);
15350 /* Get the normal cursor type for this window. */
15351 if (EQ (b
->cursor_type
, Qt
))
15353 cursor_type
= FRAME_DESIRED_CURSOR (f
);
15354 *width
= FRAME_CURSOR_WIDTH (f
);
15357 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
15359 /* Use normal cursor if not blinked off. */
15360 if (!w
->cursor_off_p
)
15361 return cursor_type
;
15363 /* Cursor is blinked off, so determine how to "toggle" it. */
15365 /* First try to use alternate-cursor-type, unless it is t. */
15366 alt_cursor
= Fbuffer_local_value (Qalternate_cursor_type
, w
->buffer
);
15367 if (!EQ (alt_cursor
, Qt
))
15368 return get_specified_cursor_type (alt_cursor
, width
);
15370 /* Then unless buffer's cursor-type is t (use default),
15371 look for an entry matching normal cursor in blink-cursor-alist. */
15372 if (!EQ (b
->cursor_type
, Qt
) &&
15373 (alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
15374 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
15376 /* Then see if frame has specified a specific blink off cursor type. */
15377 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
15379 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
15380 return FRAME_BLINK_OFF_CURSOR (f
);
15383 /* Finally perform built-in cursor blinking:
15384 filled box <-> hollow box
15385 wide [h]bar <-> narrow [h]bar
15386 narrow [h]bar <-> no cursor
15387 other type <-> no cursor */
15389 if (cursor_type
== FILLED_BOX_CURSOR
)
15390 return HOLLOW_BOX_CURSOR
;
15392 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
15395 return cursor_type
;
15402 /***********************************************************************
15404 ***********************************************************************/
15409 Vwith_echo_area_save_vector
= Qnil
;
15410 staticpro (&Vwith_echo_area_save_vector
);
15412 Vmessage_stack
= Qnil
;
15413 staticpro (&Vmessage_stack
);
15415 Qinhibit_redisplay
= intern ("inhibit-redisplay");
15416 staticpro (&Qinhibit_redisplay
);
15418 message_dolog_marker1
= Fmake_marker ();
15419 staticpro (&message_dolog_marker1
);
15420 message_dolog_marker2
= Fmake_marker ();
15421 staticpro (&message_dolog_marker2
);
15422 message_dolog_marker3
= Fmake_marker ();
15423 staticpro (&message_dolog_marker3
);
15426 defsubr (&Sdump_frame_glyph_matrix
);
15427 defsubr (&Sdump_glyph_matrix
);
15428 defsubr (&Sdump_glyph_row
);
15429 defsubr (&Sdump_tool_bar_row
);
15430 defsubr (&Strace_redisplay
);
15431 defsubr (&Strace_to_stderr
);
15433 #ifdef HAVE_WINDOW_SYSTEM
15434 defsubr (&Stool_bar_lines_needed
);
15436 defsubr (&Sformat_mode_line
);
15438 staticpro (&Qmenu_bar_update_hook
);
15439 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
15441 staticpro (&Qoverriding_terminal_local_map
);
15442 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
15444 staticpro (&Qoverriding_local_map
);
15445 Qoverriding_local_map
= intern ("overriding-local-map");
15447 staticpro (&Qwindow_scroll_functions
);
15448 Qwindow_scroll_functions
= intern ("window-scroll-functions");
15450 staticpro (&Qredisplay_end_trigger_functions
);
15451 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
15453 staticpro (&Qinhibit_point_motion_hooks
);
15454 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
15456 QCdata
= intern (":data");
15457 staticpro (&QCdata
);
15458 Qdisplay
= intern ("display");
15459 staticpro (&Qdisplay
);
15460 Qspace_width
= intern ("space-width");
15461 staticpro (&Qspace_width
);
15462 Qraise
= intern ("raise");
15463 staticpro (&Qraise
);
15464 Qspace
= intern ("space");
15465 staticpro (&Qspace
);
15466 Qmargin
= intern ("margin");
15467 staticpro (&Qmargin
);
15468 Qleft_margin
= intern ("left-margin");
15469 staticpro (&Qleft_margin
);
15470 Qright_margin
= intern ("right-margin");
15471 staticpro (&Qright_margin
);
15472 Qalign_to
= intern ("align-to");
15473 staticpro (&Qalign_to
);
15474 QCalign_to
= intern (":align-to");
15475 staticpro (&QCalign_to
);
15476 Qrelative_width
= intern ("relative-width");
15477 staticpro (&Qrelative_width
);
15478 QCrelative_width
= intern (":relative-width");
15479 staticpro (&QCrelative_width
);
15480 QCrelative_height
= intern (":relative-height");
15481 staticpro (&QCrelative_height
);
15482 QCeval
= intern (":eval");
15483 staticpro (&QCeval
);
15484 QCpropertize
= intern (":propertize");
15485 staticpro (&QCpropertize
);
15486 Qwhen
= intern ("when");
15487 staticpro (&Qwhen
);
15488 QCfile
= intern (":file");
15489 staticpro (&QCfile
);
15490 Qfontified
= intern ("fontified");
15491 staticpro (&Qfontified
);
15492 Qfontification_functions
= intern ("fontification-functions");
15493 staticpro (&Qfontification_functions
);
15494 Qtrailing_whitespace
= intern ("trailing-whitespace");
15495 staticpro (&Qtrailing_whitespace
);
15496 Qimage
= intern ("image");
15497 staticpro (&Qimage
);
15498 Qmessage_truncate_lines
= intern ("message-truncate-lines");
15499 staticpro (&Qmessage_truncate_lines
);
15500 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
15501 staticpro (&Qcursor_in_non_selected_windows
);
15502 Qalternate_cursor_type
= intern ("alternate-cursor-type");
15503 staticpro (&Qalternate_cursor_type
);
15504 Qgrow_only
= intern ("grow-only");
15505 staticpro (&Qgrow_only
);
15506 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
15507 staticpro (&Qinhibit_menubar_update
);
15508 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
15509 staticpro (&Qinhibit_eval_during_redisplay
);
15510 Qposition
= intern ("position");
15511 staticpro (&Qposition
);
15512 Qbuffer_position
= intern ("buffer-position");
15513 staticpro (&Qbuffer_position
);
15514 Qobject
= intern ("object");
15515 staticpro (&Qobject
);
15516 Qbar
= intern ("bar");
15518 Qhbar
= intern ("hbar");
15519 staticpro (&Qhbar
);
15520 Qbox
= intern ("box");
15522 Qhollow
= intern ("hollow");
15523 staticpro (&Qhollow
);
15524 Qrisky_local_variable
= intern ("risky-local-variable");
15525 staticpro (&Qrisky_local_variable
);
15526 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
15527 staticpro (&Qinhibit_free_realized_faces
);
15529 list_of_error
= Fcons (intern ("error"), Qnil
);
15530 staticpro (&list_of_error
);
15532 last_arrow_position
= Qnil
;
15533 last_arrow_string
= Qnil
;
15534 staticpro (&last_arrow_position
);
15535 staticpro (&last_arrow_string
);
15537 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
15538 staticpro (&echo_buffer
[0]);
15539 staticpro (&echo_buffer
[1]);
15541 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
15542 staticpro (&echo_area_buffer
[0]);
15543 staticpro (&echo_area_buffer
[1]);
15545 Vmessages_buffer_name
= build_string ("*Messages*");
15546 staticpro (&Vmessages_buffer_name
);
15548 mode_line_proptrans_alist
= Qnil
;
15549 staticpro (&mode_line_proptrans_alist
);
15551 mode_line_string_list
= Qnil
;
15552 staticpro (&mode_line_string_list
);
15554 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
15555 doc
: /* Non-nil means highlight trailing whitespace.
15556 The face used for trailing whitespace is `trailing-whitespace'. */);
15557 Vshow_trailing_whitespace
= Qnil
;
15559 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
15560 doc
: /* Non-nil means don't actually do any redisplay.
15561 This is used for internal purposes. */);
15562 Vinhibit_redisplay
= Qnil
;
15564 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
15565 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
15566 Vglobal_mode_string
= Qnil
;
15568 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
15569 doc
: /* Marker for where to display an arrow on top of the buffer text.
15570 This must be the beginning of a line in order to work.
15571 See also `overlay-arrow-string'. */);
15572 Voverlay_arrow_position
= Qnil
;
15574 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
15575 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
15576 Voverlay_arrow_string
= Qnil
;
15578 DEFVAR_INT ("scroll-step", &scroll_step
,
15579 doc
: /* *The number of lines to try scrolling a window by when point moves out.
15580 If that fails to bring point back on frame, point is centered instead.
15581 If this is zero, point is always centered after it moves off frame.
15582 If you want scrolling to always be a line at a time, you should set
15583 `scroll-conservatively' to a large value rather than set this to 1. */);
15585 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
15586 doc
: /* *Scroll up to this many lines, to bring point back on screen.
15587 A value of zero means to scroll the text to center point vertically
15588 in the window. */);
15589 scroll_conservatively
= 0;
15591 DEFVAR_INT ("scroll-margin", &scroll_margin
,
15592 doc
: /* *Number of lines of margin at the top and bottom of a window.
15593 Recenter the window whenever point gets within this many lines
15594 of the top or bottom of the window. */);
15598 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
15601 DEFVAR_BOOL ("truncate-partial-width-windows",
15602 &truncate_partial_width_windows
,
15603 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
15604 truncate_partial_width_windows
= 1;
15606 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
15607 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
15608 Any other value means to use the appropriate face, `mode-line',
15609 `header-line', or `menu' respectively. */);
15610 mode_line_inverse_video
= 1;
15612 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
15613 doc
: /* *Maximum buffer size for which line number should be displayed.
15614 If the buffer is bigger than this, the line number does not appear
15615 in the mode line. A value of nil means no limit. */);
15616 Vline_number_display_limit
= Qnil
;
15618 DEFVAR_INT ("line-number-display-limit-width",
15619 &line_number_display_limit_width
,
15620 doc
: /* *Maximum line width (in characters) for line number display.
15621 If the average length of the lines near point is bigger than this, then the
15622 line number may be omitted from the mode line. */);
15623 line_number_display_limit_width
= 200;
15625 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
15626 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
15627 highlight_nonselected_windows
= 0;
15629 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
15630 doc
: /* Non-nil if more than one frame is visible on this display.
15631 Minibuffer-only frames don't count, but iconified frames do.
15632 This variable is not guaranteed to be accurate except while processing
15633 `frame-title-format' and `icon-title-format'. */);
15635 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
15636 doc
: /* Template for displaying the title bar of visible frames.
15637 \(Assuming the window manager supports this feature.)
15638 This variable has the same structure as `mode-line-format' (which see),
15639 and is used only on frames for which no explicit name has been set
15640 \(see `modify-frame-parameters'). */);
15641 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
15642 doc
: /* Template for displaying the title bar of an iconified frame.
15643 \(Assuming the window manager supports this feature.)
15644 This variable has the same structure as `mode-line-format' (which see),
15645 and is used only on frames for which no explicit name has been set
15646 \(see `modify-frame-parameters'). */);
15648 = Vframe_title_format
15649 = Fcons (intern ("multiple-frames"),
15650 Fcons (build_string ("%b"),
15651 Fcons (Fcons (empty_string
,
15652 Fcons (intern ("invocation-name"),
15653 Fcons (build_string ("@"),
15654 Fcons (intern ("system-name"),
15658 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
15659 doc
: /* Maximum number of lines to keep in the message log buffer.
15660 If nil, disable message logging. If t, log messages but don't truncate
15661 the buffer when it becomes large. */);
15662 Vmessage_log_max
= make_number (50);
15664 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
15665 doc
: /* Functions called before redisplay, if window sizes have changed.
15666 The value should be a list of functions that take one argument.
15667 Just before redisplay, for each frame, if any of its windows have changed
15668 size since the last redisplay, or have been split or deleted,
15669 all the functions in the list are called, with the frame as argument. */);
15670 Vwindow_size_change_functions
= Qnil
;
15672 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
15673 doc
: /* List of Functions to call before redisplaying a window with scrolling.
15674 Each function is called with two arguments, the window
15675 and its new display-start position. Note that the value of `window-end'
15676 is not valid when these functions are called. */);
15677 Vwindow_scroll_functions
= Qnil
;
15679 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
15680 doc
: /* *Non-nil means automatically resize tool-bars.
15681 This increases a tool-bar's height if not all tool-bar items are visible.
15682 It decreases a tool-bar's height when it would display blank lines
15684 auto_resize_tool_bars_p
= 1;
15686 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
15687 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
15688 auto_raise_tool_bar_buttons_p
= 1;
15690 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
15691 doc
: /* *Margin around tool-bar buttons in pixels.
15692 If an integer, use that for both horizontal and vertical margins.
15693 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
15694 HORZ specifying the horizontal margin, and VERT specifying the
15695 vertical margin. */);
15696 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
15698 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
15699 doc
: /* *Relief thickness of tool-bar buttons. */);
15700 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
15702 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
15703 doc
: /* List of functions to call to fontify regions of text.
15704 Each function is called with one argument POS. Functions must
15705 fontify a region starting at POS in the current buffer, and give
15706 fontified regions the property `fontified'. */);
15707 Vfontification_functions
= Qnil
;
15708 Fmake_variable_buffer_local (Qfontification_functions
);
15710 DEFVAR_BOOL ("unibyte-display-via-language-environment",
15711 &unibyte_display_via_language_environment
,
15712 doc
: /* *Non-nil means display unibyte text according to language environment.
15713 Specifically this means that unibyte non-ASCII characters
15714 are displayed by converting them to the equivalent multibyte characters
15715 according to the current language environment. As a result, they are
15716 displayed according to the current fontset. */);
15717 unibyte_display_via_language_environment
= 0;
15719 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
15720 doc
: /* *Maximum height for resizing mini-windows.
15721 If a float, it specifies a fraction of the mini-window frame's height.
15722 If an integer, it specifies a number of lines. */);
15723 Vmax_mini_window_height
= make_float (0.25);
15725 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
15726 doc
: /* *How to resize mini-windows.
15727 A value of nil means don't automatically resize mini-windows.
15728 A value of t means resize them to fit the text displayed in them.
15729 A value of `grow-only', the default, means let mini-windows grow
15730 only, until their display becomes empty, at which point the windows
15731 go back to their normal size. */);
15732 Vresize_mini_windows
= Qgrow_only
;
15734 DEFVAR_LISP ("cursor-in-non-selected-windows",
15735 &Vcursor_in_non_selected_windows
,
15736 doc
: /* *Cursor type to display in non-selected windows.
15737 t means to use hollow box cursor. See `cursor-type' for other values. */);
15738 Vcursor_in_non_selected_windows
= Qt
;
15740 DEFVAR_LISP ("alternate-cursor-type", &Valternate_cursor_type
,
15741 doc
: /* *Cursor type displayed in the blinking cursor off state.
15742 t means to use default. See `cursor-type' for other values. */);
15743 Valternate_cursor_type
= Qt
;
15745 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
15746 doc
: /* Alist specifying how to blink the cursor off.
15747 Each element has the form (ON-STATE . OFF-STATE). Whenever the
15748 `cursor-type' frame-parameter or variable equals ON-STATE,
15749 comparing using `equal', Emacs uses OFF-STATE to specify
15750 how to blink it off. */);
15751 Vblink_cursor_alist
= Qnil
;
15753 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
15754 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
15755 automatic_hscrolling_p
= 1;
15757 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
15758 doc
: /* *How many columns away from the window edge point is allowed to get
15759 before automatic hscrolling will horizontally scroll the window. */);
15760 hscroll_margin
= 5;
15762 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
15763 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
15764 When point is less than `automatic-hscroll-margin' columns from the window
15765 edge, automatic hscrolling will scroll the window by the amount of columns
15766 determined by this variable. If its value is a positive integer, scroll that
15767 many columns. If it's a positive floating-point number, it specifies the
15768 fraction of the window's width to scroll. If it's nil or zero, point will be
15769 centered horizontally after the scroll. Any other value, including negative
15770 numbers, are treated as if the value were zero.
15772 Automatic hscrolling always moves point outside the scroll margin, so if
15773 point was more than scroll step columns inside the margin, the window will
15774 scroll more than the value given by the scroll step.
15776 Note that the lower bound for automatic hscrolling specified by `scroll-left'
15777 and `scroll-right' overrides this variable's effect. */);
15778 Vhscroll_step
= make_number (0);
15780 DEFVAR_LISP ("image-types", &Vimage_types
,
15781 doc
: /* List of supported image types.
15782 Each element of the list is a symbol for a supported image type. */);
15783 Vimage_types
= Qnil
;
15785 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
15786 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
15787 Bind this around calls to `message' to let it take effect. */);
15788 message_truncate_lines
= 0;
15790 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
15791 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
15792 Can be used to update submenus whose contents should vary. */);
15793 Vmenu_bar_update_hook
= Qnil
;
15795 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
15796 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
15797 inhibit_menubar_update
= 0;
15799 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
15800 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
15801 inhibit_eval_during_redisplay
= 0;
15803 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
15804 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
15805 inhibit_free_realized_faces
= 0;
15808 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
15809 doc
: /* Inhibit try_window_id display optimization. */);
15810 inhibit_try_window_id
= 0;
15812 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
15813 doc
: /* Inhibit try_window_reusing display optimization. */);
15814 inhibit_try_window_reusing
= 0;
15816 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
15817 doc
: /* Inhibit try_cursor_movement display optimization. */);
15818 inhibit_try_cursor_movement
= 0;
15819 #endif /* GLYPH_DEBUG */
15823 /* Initialize this module when Emacs starts. */
15828 Lisp_Object root_window
;
15829 struct window
*mini_w
;
15831 current_header_line_height
= current_mode_line_height
= -1;
15833 CHARPOS (this_line_start_pos
) = 0;
15835 mini_w
= XWINDOW (minibuf_window
);
15836 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
15838 if (!noninteractive
)
15840 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
15843 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
15844 set_window_height (root_window
,
15845 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
15847 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
15848 set_window_height (minibuf_window
, 1, 0);
15850 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
15851 mini_w
->width
= make_number (FRAME_WIDTH (f
));
15853 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
15854 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
15855 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
15857 /* The default ellipsis glyphs `...'. */
15858 for (i
= 0; i
< 3; ++i
)
15859 default_invis_vector
[i
] = make_number ('.');
15863 /* Allocate the buffer for frame titles.
15864 Also used for `format-mode-line'. */
15866 frame_title_buf
= (char *) xmalloc (size
);
15867 frame_title_buf_end
= frame_title_buf
+ size
;
15868 frame_title_ptr
= NULL
;
15871 help_echo_showing_p
= 0;