1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
184 #include "termhooks.h"
185 #include "intervals.h"
188 #include "region-cache.h"
191 #ifdef HAVE_X_WINDOWS
201 #define INFINITY 10000000
203 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
205 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
206 extern int pending_menu_activation
;
209 extern int interrupt_input
;
210 extern int command_loop_level
;
212 extern int minibuffer_auto_raise
;
213 extern Lisp_Object Vminibuffer_list
;
215 extern Lisp_Object Qface
;
216 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
218 extern Lisp_Object Voverriding_local_map
;
219 extern Lisp_Object Voverriding_local_map_menu_flag
;
220 extern Lisp_Object Qmenu_item
;
222 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
223 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
224 Lisp_Object Qredisplay_end_trigger_functions
;
225 Lisp_Object Qinhibit_point_motion_hooks
;
226 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
, QCpropertize
;
227 Lisp_Object Qfontified
;
228 Lisp_Object Qgrow_only
;
229 Lisp_Object Qinhibit_eval_during_redisplay
;
230 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
233 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
235 Lisp_Object Qrisky_local_variable
;
237 /* Holds the list (error). */
238 Lisp_Object list_of_error
;
240 /* Functions called to fontify regions of text. */
242 Lisp_Object Vfontification_functions
;
243 Lisp_Object Qfontification_functions
;
245 /* Non-zero means draw tool bar buttons raised when the mouse moves
248 int auto_raise_tool_bar_buttons_p
;
250 /* Margin around tool bar buttons in pixels. */
252 Lisp_Object Vtool_bar_button_margin
;
254 /* Thickness of shadow to draw around tool bar buttons. */
256 EMACS_INT tool_bar_button_relief
;
258 /* Non-zero means automatically resize tool-bars so that all tool-bar
259 items are visible, and no blank lines remain. */
261 int auto_resize_tool_bars_p
;
263 /* Non-nil means don't actually do any redisplay. */
265 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
267 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
269 int inhibit_eval_during_redisplay
;
271 /* Names of text properties relevant for redisplay. */
273 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
274 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
276 /* Symbols used in text property values. */
278 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
279 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
281 extern Lisp_Object Qheight
;
283 /* Non-nil means highlight trailing whitespace. */
285 Lisp_Object Vshow_trailing_whitespace
;
287 /* Name of the face used to highlight trailing whitespace. */
289 Lisp_Object Qtrailing_whitespace
;
291 /* The symbol `image' which is the car of the lists used to represent
296 /* Non-zero means print newline to stdout before next mini-buffer
299 int noninteractive_need_newline
;
301 /* Non-zero means print newline to message log before next message. */
303 static int message_log_need_newline
;
305 /* Three markers that message_dolog uses.
306 It could allocate them itself, but that causes trouble
307 in handling memory-full errors. */
308 static Lisp_Object message_dolog_marker1
;
309 static Lisp_Object message_dolog_marker2
;
310 static Lisp_Object message_dolog_marker3
;
312 /* The buffer position of the first character appearing entirely or
313 partially on the line of the selected window which contains the
314 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
315 redisplay optimization in redisplay_internal. */
317 static struct text_pos this_line_start_pos
;
319 /* Number of characters past the end of the line above, including the
320 terminating newline. */
322 static struct text_pos this_line_end_pos
;
324 /* The vertical positions and the height of this line. */
326 static int this_line_vpos
;
327 static int this_line_y
;
328 static int this_line_pixel_height
;
330 /* X position at which this display line starts. Usually zero;
331 negative if first character is partially visible. */
333 static int this_line_start_x
;
335 /* Buffer that this_line_.* variables are referring to. */
337 static struct buffer
*this_line_buffer
;
339 /* Nonzero means truncate lines in all windows less wide than the
342 int truncate_partial_width_windows
;
344 /* A flag to control how to display unibyte 8-bit character. */
346 int unibyte_display_via_language_environment
;
348 /* Nonzero means we have more than one non-mini-buffer-only frame.
349 Not guaranteed to be accurate except while parsing
350 frame-title-format. */
354 Lisp_Object Vglobal_mode_string
;
356 /* Marker for where to display an arrow on top of the buffer text. */
358 Lisp_Object Voverlay_arrow_position
;
360 /* String to display for the arrow. Only used on terminal frames. */
362 Lisp_Object Voverlay_arrow_string
;
364 /* Values of those variables at last redisplay. However, if
365 Voverlay_arrow_position is a marker, last_arrow_position is its
366 numerical position. */
368 static Lisp_Object last_arrow_position
, last_arrow_string
;
370 /* Like mode-line-format, but for the title bar on a visible frame. */
372 Lisp_Object Vframe_title_format
;
374 /* Like mode-line-format, but for the title bar on an iconified frame. */
376 Lisp_Object Vicon_title_format
;
378 /* List of functions to call when a window's size changes. These
379 functions get one arg, a frame on which one or more windows' sizes
382 static Lisp_Object Vwindow_size_change_functions
;
384 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
386 /* Nonzero if overlay arrow has been displayed once in this window. */
388 static int overlay_arrow_seen
;
390 /* Nonzero means highlight the region even in nonselected windows. */
392 int highlight_nonselected_windows
;
394 /* If cursor motion alone moves point off frame, try scrolling this
395 many lines up or down if that will bring it back. */
397 static EMACS_INT scroll_step
;
399 /* Nonzero means scroll just far enough to bring point back on the
400 screen, when appropriate. */
402 static EMACS_INT scroll_conservatively
;
404 /* Recenter the window whenever point gets within this many lines of
405 the top or bottom of the window. This value is translated into a
406 pixel value by multiplying it with CANON_Y_UNIT, which means that
407 there is really a fixed pixel height scroll margin. */
409 EMACS_INT scroll_margin
;
411 /* Number of windows showing the buffer of the selected window (or
412 another buffer with the same base buffer). keyboard.c refers to
417 /* Vector containing glyphs for an ellipsis `...'. */
419 static Lisp_Object default_invis_vector
[3];
421 /* Zero means display the mode-line/header-line/menu-bar in the default face
422 (this slightly odd definition is for compatibility with previous versions
423 of emacs), non-zero means display them using their respective faces.
425 This variable is deprecated. */
427 int mode_line_inverse_video
;
429 /* Prompt to display in front of the mini-buffer contents. */
431 Lisp_Object minibuf_prompt
;
433 /* Width of current mini-buffer prompt. Only set after display_line
434 of the line that contains the prompt. */
436 int minibuf_prompt_width
;
438 /* This is the window where the echo area message was displayed. It
439 is always a mini-buffer window, but it may not be the same window
440 currently active as a mini-buffer. */
442 Lisp_Object echo_area_window
;
444 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
445 pushes the current message and the value of
446 message_enable_multibyte on the stack, the function restore_message
447 pops the stack and displays MESSAGE again. */
449 Lisp_Object Vmessage_stack
;
451 /* Nonzero means multibyte characters were enabled when the echo area
452 message was specified. */
454 int message_enable_multibyte
;
456 /* Nonzero if we should redraw the mode lines on the next redisplay. */
458 int update_mode_lines
;
460 /* Nonzero if window sizes or contents have changed since last
461 redisplay that finished. */
463 int windows_or_buffers_changed
;
465 /* Nonzero means a frame's cursor type has been changed. */
467 int cursor_type_changed
;
469 /* Nonzero after display_mode_line if %l was used and it displayed a
472 int line_number_displayed
;
474 /* Maximum buffer size for which to display line numbers. */
476 Lisp_Object Vline_number_display_limit
;
478 /* Line width to consider when repositioning for line number display. */
480 static EMACS_INT line_number_display_limit_width
;
482 /* Number of lines to keep in the message log buffer. t means
483 infinite. nil means don't log at all. */
485 Lisp_Object Vmessage_log_max
;
487 /* The name of the *Messages* buffer, a string. */
489 static Lisp_Object Vmessages_buffer_name
;
491 /* Current, index 0, and last displayed echo area message. Either
492 buffers from echo_buffers, or nil to indicate no message. */
494 Lisp_Object echo_area_buffer
[2];
496 /* The buffers referenced from echo_area_buffer. */
498 static Lisp_Object echo_buffer
[2];
500 /* A vector saved used in with_area_buffer to reduce consing. */
502 static Lisp_Object Vwith_echo_area_save_vector
;
504 /* Non-zero means display_echo_area should display the last echo area
505 message again. Set by redisplay_preserve_echo_area. */
507 static int display_last_displayed_message_p
;
509 /* Nonzero if echo area is being used by print; zero if being used by
512 int message_buf_print
;
514 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
516 Lisp_Object Qinhibit_menubar_update
;
517 int inhibit_menubar_update
;
519 /* Maximum height for resizing mini-windows. Either a float
520 specifying a fraction of the available height, or an integer
521 specifying a number of lines. */
523 Lisp_Object Vmax_mini_window_height
;
525 /* Non-zero means messages should be displayed with truncated
526 lines instead of being continued. */
528 int message_truncate_lines
;
529 Lisp_Object Qmessage_truncate_lines
;
531 /* Set to 1 in clear_message to make redisplay_internal aware
532 of an emptied echo area. */
534 static int message_cleared_p
;
536 /* Non-zero means we want a hollow cursor in windows that are not
537 selected. Zero means there's no cursor in such windows. */
539 Lisp_Object Vcursor_in_non_selected_windows
;
540 Lisp_Object Qcursor_in_non_selected_windows
;
542 /* How to blink the default frame cursor off. */
543 Lisp_Object Vblink_cursor_alist
;
545 /* A scratch glyph row with contents used for generating truncation
546 glyphs. Also used in direct_output_for_insert. */
548 #define MAX_SCRATCH_GLYPHS 100
549 struct glyph_row scratch_glyph_row
;
550 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
552 /* Ascent and height of the last line processed by move_it_to. */
554 static int last_max_ascent
, last_height
;
556 /* Non-zero if there's a help-echo in the echo area. */
558 int help_echo_showing_p
;
560 /* If >= 0, computed, exact values of mode-line and header-line height
561 to use in the macros CURRENT_MODE_LINE_HEIGHT and
562 CURRENT_HEADER_LINE_HEIGHT. */
564 int current_mode_line_height
, current_header_line_height
;
566 /* The maximum distance to look ahead for text properties. Values
567 that are too small let us call compute_char_face and similar
568 functions too often which is expensive. Values that are too large
569 let us call compute_char_face and alike too often because we
570 might not be interested in text properties that far away. */
572 #define TEXT_PROP_DISTANCE_LIMIT 100
576 /* Variables to turn off display optimizations from Lisp. */
578 int inhibit_try_window_id
, inhibit_try_window_reusing
;
579 int inhibit_try_cursor_movement
;
581 /* Non-zero means print traces of redisplay if compiled with
584 int trace_redisplay_p
;
586 #endif /* GLYPH_DEBUG */
588 #ifdef DEBUG_TRACE_MOVE
589 /* Non-zero means trace with TRACE_MOVE to stderr. */
592 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
594 #define TRACE_MOVE(x) (void) 0
597 /* Non-zero means automatically scroll windows horizontally to make
600 int automatic_hscrolling_p
;
602 /* How close to the margin can point get before the window is scrolled
604 EMACS_INT hscroll_margin
;
606 /* How much to scroll horizontally when point is inside the above margin. */
607 Lisp_Object Vhscroll_step
;
609 /* A list of symbols, one for each supported image type. */
611 Lisp_Object Vimage_types
;
613 /* The variable `resize-mini-windows'. If nil, don't resize
614 mini-windows. If t, always resize them to fit the text they
615 display. If `grow-only', let mini-windows grow only until they
618 Lisp_Object Vresize_mini_windows
;
620 /* Buffer being redisplayed -- for redisplay_window_error. */
622 struct buffer
*displayed_buffer
;
624 /* Value returned from text property handlers (see below). */
629 HANDLED_RECOMPUTE_PROPS
,
630 HANDLED_OVERLAY_STRING_CONSUMED
,
634 /* A description of text properties that redisplay is interested
639 /* The name of the property. */
642 /* A unique index for the property. */
645 /* A handler function called to set up iterator IT from the property
646 at IT's current position. Value is used to steer handle_stop. */
647 enum prop_handled (*handler
) P_ ((struct it
*it
));
650 static enum prop_handled handle_face_prop
P_ ((struct it
*));
651 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
652 static enum prop_handled handle_display_prop
P_ ((struct it
*));
653 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
654 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
655 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
657 /* Properties handled by iterators. */
659 static struct props it_props
[] =
661 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
662 /* Handle `face' before `display' because some sub-properties of
663 `display' need to know the face. */
664 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
665 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
666 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
667 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
671 /* Value is the position described by X. If X is a marker, value is
672 the marker_position of X. Otherwise, value is X. */
674 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
676 /* Enumeration returned by some move_it_.* functions internally. */
680 /* Not used. Undefined value. */
683 /* Move ended at the requested buffer position or ZV. */
684 MOVE_POS_MATCH_OR_ZV
,
686 /* Move ended at the requested X pixel position. */
689 /* Move within a line ended at the end of a line that must be
693 /* Move within a line ended at the end of a line that would
694 be displayed truncated. */
697 /* Move within a line ended at a line end. */
701 /* This counter is used to clear the face cache every once in a while
702 in redisplay_internal. It is incremented for each redisplay.
703 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
706 #define CLEAR_FACE_CACHE_COUNT 500
707 static int clear_face_cache_count
;
709 /* Record the previous terminal frame we displayed. */
711 static struct frame
*previous_terminal_frame
;
713 /* Non-zero while redisplay_internal is in progress. */
717 /* Non-zero means don't free realized faces. Bound while freeing
718 realized faces is dangerous because glyph matrices might still
721 int inhibit_free_realized_faces
;
722 Lisp_Object Qinhibit_free_realized_faces
;
725 /* Function prototypes. */
727 static void setup_for_ellipsis
P_ ((struct it
*));
728 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
729 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
730 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
731 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
732 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
733 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
736 static int invisible_text_between_p
P_ ((struct it
*, int, int));
739 static int next_element_from_ellipsis
P_ ((struct it
*));
740 static void pint2str
P_ ((char *, int, int));
741 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
743 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
744 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
745 static void store_frame_title_char
P_ ((char));
746 static int store_frame_title
P_ ((const unsigned char *, int, int));
747 static void x_consider_frame_title
P_ ((Lisp_Object
));
748 static void handle_stop
P_ ((struct it
*));
749 static int tool_bar_lines_needed
P_ ((struct frame
*));
750 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
751 static void ensure_echo_area_buffers
P_ ((void));
752 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
753 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
754 static int with_echo_area_buffer
P_ ((struct window
*, int,
755 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
756 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
757 static void clear_garbaged_frames
P_ ((void));
758 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
759 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
760 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
761 static int display_echo_area
P_ ((struct window
*));
762 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
763 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
764 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
765 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
766 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
768 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
769 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
770 static void insert_left_trunc_glyphs
P_ ((struct it
*));
771 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
772 static void extend_face_to_end_of_line
P_ ((struct it
*));
773 static int append_space
P_ ((struct it
*, int));
774 static int make_cursor_line_fully_visible
P_ ((struct window
*));
775 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
776 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
777 static int trailing_whitespace_p
P_ ((int));
778 static int message_log_check_duplicate
P_ ((int, int, int, int));
779 static void push_it
P_ ((struct it
*));
780 static void pop_it
P_ ((struct it
*));
781 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
782 static void redisplay_internal
P_ ((int));
783 static int echo_area_display
P_ ((int));
784 static void redisplay_windows
P_ ((Lisp_Object
));
785 static void redisplay_window
P_ ((Lisp_Object
, int));
786 static Lisp_Object
redisplay_window_error ();
787 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
788 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
789 static void update_menu_bar
P_ ((struct frame
*, int));
790 static int try_window_reusing_current_matrix
P_ ((struct window
*));
791 static int try_window_id
P_ ((struct window
*));
792 static int display_line
P_ ((struct it
*));
793 static int display_mode_lines
P_ ((struct window
*));
794 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
795 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
796 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
797 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
798 static void display_menu_bar
P_ ((struct window
*));
799 static int display_count_lines
P_ ((int, int, int, int, int *));
800 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
801 int, int, struct it
*, int, int, int, int));
802 static void compute_line_metrics
P_ ((struct it
*));
803 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
804 static int get_overlay_strings
P_ ((struct it
*, int));
805 static void next_overlay_string
P_ ((struct it
*));
806 static void reseat
P_ ((struct it
*, struct text_pos
, int));
807 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
808 static void back_to_previous_visible_line_start
P_ ((struct it
*));
809 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
810 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
811 static int next_element_from_display_vector
P_ ((struct it
*));
812 static int next_element_from_string
P_ ((struct it
*));
813 static int next_element_from_c_string
P_ ((struct it
*));
814 static int next_element_from_buffer
P_ ((struct it
*));
815 static int next_element_from_composition
P_ ((struct it
*));
816 static int next_element_from_image
P_ ((struct it
*));
817 static int next_element_from_stretch
P_ ((struct it
*));
818 static void load_overlay_strings
P_ ((struct it
*, int));
819 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
820 struct display_pos
*));
821 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
822 Lisp_Object
, int, int, int, int));
823 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
825 void move_it_vertically_backward
P_ ((struct it
*, int));
826 static void init_to_row_start
P_ ((struct it
*, struct window
*,
827 struct glyph_row
*));
828 static int init_to_row_end
P_ ((struct it
*, struct window
*,
829 struct glyph_row
*));
830 static void back_to_previous_line_start
P_ ((struct it
*));
831 static int forward_to_next_line_start
P_ ((struct it
*, int *));
832 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
834 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
835 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
836 static int number_of_chars
P_ ((unsigned char *, int));
837 static void compute_stop_pos
P_ ((struct it
*));
838 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
840 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
841 static int next_overlay_change
P_ ((int));
842 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
843 Lisp_Object
, struct text_pos
*,
845 static int underlying_face_id
P_ ((struct it
*));
846 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
849 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
850 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
852 #ifdef HAVE_WINDOW_SYSTEM
854 static void update_tool_bar
P_ ((struct frame
*, int));
855 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
856 static int redisplay_tool_bar
P_ ((struct frame
*));
857 static void display_tool_bar_line
P_ ((struct it
*));
859 #endif /* HAVE_WINDOW_SYSTEM */
862 /***********************************************************************
863 Window display dimensions
864 ***********************************************************************/
866 /* Return the bottom boundary y-position for text lines in window W.
867 This is the first y position at which a line cannot start.
868 It is relative to the top of the window.
870 This is the height of W minus the height of a mode line, if any. */
873 window_text_bottom_y (w
)
876 struct frame
*f
= XFRAME (w
->frame
);
877 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
879 if (WINDOW_WANTS_MODELINE_P (w
))
880 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
885 /* Return the pixel width of display area AREA of window W. AREA < 0
886 means return the total width of W, not including fringes to
887 the left and right of the window. */
890 window_box_width (w
, area
)
894 struct frame
*f
= XFRAME (w
->frame
);
895 int width
= XFASTINT (w
->width
);
897 if (!w
->pseudo_window_p
)
899 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FRINGE_COLS (f
);
901 if (area
== TEXT_AREA
)
903 if (INTEGERP (w
->left_margin_width
))
904 width
-= XFASTINT (w
->left_margin_width
);
905 if (INTEGERP (w
->right_margin_width
))
906 width
-= XFASTINT (w
->right_margin_width
);
908 else if (area
== LEFT_MARGIN_AREA
)
909 width
= (INTEGERP (w
->left_margin_width
)
910 ? XFASTINT (w
->left_margin_width
) : 0);
911 else if (area
== RIGHT_MARGIN_AREA
)
912 width
= (INTEGERP (w
->right_margin_width
)
913 ? XFASTINT (w
->right_margin_width
) : 0);
916 return width
* CANON_X_UNIT (f
);
920 /* Return the pixel height of the display area of window W, not
921 including mode lines of W, if any. */
924 window_box_height (w
)
927 struct frame
*f
= XFRAME (w
->frame
);
928 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
930 xassert (height
>= 0);
932 /* Note: the code below that determines the mode-line/header-line
933 height is essentially the same as that contained in the macro
934 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
935 the appropriate glyph row has its `mode_line_p' flag set,
936 and if it doesn't, uses estimate_mode_line_height instead. */
938 if (WINDOW_WANTS_MODELINE_P (w
))
940 struct glyph_row
*ml_row
941 = (w
->current_matrix
&& w
->current_matrix
->rows
942 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
944 if (ml_row
&& ml_row
->mode_line_p
)
945 height
-= ml_row
->height
;
947 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
950 if (WINDOW_WANTS_HEADER_LINE_P (w
))
952 struct glyph_row
*hl_row
953 = (w
->current_matrix
&& w
->current_matrix
->rows
954 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
956 if (hl_row
&& hl_row
->mode_line_p
)
957 height
-= hl_row
->height
;
959 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
962 /* With a very small font and a mode-line that's taller than
963 default, we might end up with a negative height. */
964 return max (0, height
);
968 /* Return the frame-relative coordinate of the left edge of display
969 area AREA of window W. AREA < 0 means return the left edge of the
970 whole window, to the right of the left fringe of W. */
973 window_box_left (w
, area
)
977 struct frame
*f
= XFRAME (w
->frame
);
978 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
980 if (!w
->pseudo_window_p
)
982 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
983 + FRAME_LEFT_FRINGE_WIDTH (f
));
985 if (area
== TEXT_AREA
)
986 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
987 else if (area
== RIGHT_MARGIN_AREA
)
988 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
989 + window_box_width (w
, TEXT_AREA
));
996 /* Return the frame-relative coordinate of the right edge of display
997 area AREA of window W. AREA < 0 means return the left edge of the
998 whole window, to the left of the right fringe of W. */
1001 window_box_right (w
, area
)
1005 return window_box_left (w
, area
) + window_box_width (w
, area
);
1009 /* Get the bounding box of the display area AREA of window W, without
1010 mode lines, in frame-relative coordinates. AREA < 0 means the
1011 whole window, not including the left and right fringes of
1012 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1013 coordinates of the upper-left corner of the box. Return in
1014 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1017 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1020 int *box_x
, *box_y
, *box_width
, *box_height
;
1022 struct frame
*f
= XFRAME (w
->frame
);
1024 *box_width
= window_box_width (w
, area
);
1025 *box_height
= window_box_height (w
);
1026 *box_x
= window_box_left (w
, area
);
1027 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
1028 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
1029 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1030 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1034 /* Get the bounding box of the display area AREA of window W, without
1035 mode lines. AREA < 0 means the whole window, not including the
1036 left and right fringe of the window. Return in *TOP_LEFT_X
1037 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1038 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1039 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1043 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1044 bottom_right_x
, bottom_right_y
)
1047 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1049 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1051 *bottom_right_x
+= *top_left_x
;
1052 *bottom_right_y
+= *top_left_y
;
1057 /***********************************************************************
1059 ***********************************************************************/
1061 /* Return the bottom y-position of the line the iterator IT is in.
1062 This can modify IT's settings. */
1068 int line_height
= it
->max_ascent
+ it
->max_descent
;
1069 int line_top_y
= it
->current_y
;
1071 if (line_height
== 0)
1074 line_height
= last_height
;
1075 else if (IT_CHARPOS (*it
) < ZV
)
1077 move_it_by_lines (it
, 1, 1);
1078 line_height
= (it
->max_ascent
|| it
->max_descent
1079 ? it
->max_ascent
+ it
->max_descent
1084 struct glyph_row
*row
= it
->glyph_row
;
1086 /* Use the default character height. */
1087 it
->glyph_row
= NULL
;
1088 it
->what
= IT_CHARACTER
;
1091 PRODUCE_GLYPHS (it
);
1092 line_height
= it
->ascent
+ it
->descent
;
1093 it
->glyph_row
= row
;
1097 return line_top_y
+ line_height
;
1101 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1102 1 if POS is visible and the line containing POS is fully visible.
1103 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1104 and header-lines heights. */
1107 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1109 int charpos
, *fully
, exact_mode_line_heights_p
;
1112 struct text_pos top
;
1114 struct buffer
*old_buffer
= NULL
;
1116 if (XBUFFER (w
->buffer
) != current_buffer
)
1118 old_buffer
= current_buffer
;
1119 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1122 *fully
= visible_p
= 0;
1123 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1125 /* Compute exact mode line heights, if requested. */
1126 if (exact_mode_line_heights_p
)
1128 if (WINDOW_WANTS_MODELINE_P (w
))
1129 current_mode_line_height
1130 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1131 current_buffer
->mode_line_format
);
1133 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1134 current_header_line_height
1135 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1136 current_buffer
->header_line_format
);
1139 start_display (&it
, w
, top
);
1140 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1141 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1143 /* Note that we may overshoot because of invisible text. */
1144 if (IT_CHARPOS (it
) >= charpos
)
1146 int top_y
= it
.current_y
;
1147 int bottom_y
= line_bottom_y (&it
);
1148 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1150 if (top_y
< window_top_y
)
1151 visible_p
= bottom_y
> window_top_y
;
1152 else if (top_y
< it
.last_visible_y
)
1155 *fully
= bottom_y
<= it
.last_visible_y
;
1158 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1160 move_it_by_lines (&it
, 1, 0);
1161 if (charpos
< IT_CHARPOS (it
))
1169 set_buffer_internal_1 (old_buffer
);
1171 current_header_line_height
= current_mode_line_height
= -1;
1176 /* Return the next character from STR which is MAXLEN bytes long.
1177 Return in *LEN the length of the character. This is like
1178 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1179 we find one, we return a `?', but with the length of the invalid
1183 string_char_and_length (str
, maxlen
, len
)
1184 const unsigned char *str
;
1189 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1190 if (!CHAR_VALID_P (c
, 1))
1191 /* We may not change the length here because other places in Emacs
1192 don't use this function, i.e. they silently accept invalid
1201 /* Given a position POS containing a valid character and byte position
1202 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1204 static struct text_pos
1205 string_pos_nchars_ahead (pos
, string
, nchars
)
1206 struct text_pos pos
;
1210 xassert (STRINGP (string
) && nchars
>= 0);
1212 if (STRING_MULTIBYTE (string
))
1214 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1215 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1220 string_char_and_length (p
, rest
, &len
);
1221 p
+= len
, rest
-= len
;
1222 xassert (rest
>= 0);
1224 BYTEPOS (pos
) += len
;
1228 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1234 /* Value is the text position, i.e. character and byte position,
1235 for character position CHARPOS in STRING. */
1237 static INLINE
struct text_pos
1238 string_pos (charpos
, string
)
1242 struct text_pos pos
;
1243 xassert (STRINGP (string
));
1244 xassert (charpos
>= 0);
1245 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1250 /* Value is a text position, i.e. character and byte position, for
1251 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1252 means recognize multibyte characters. */
1254 static struct text_pos
1255 c_string_pos (charpos
, s
, multibyte_p
)
1260 struct text_pos pos
;
1262 xassert (s
!= NULL
);
1263 xassert (charpos
>= 0);
1267 int rest
= strlen (s
), len
;
1269 SET_TEXT_POS (pos
, 0, 0);
1272 string_char_and_length (s
, rest
, &len
);
1273 s
+= len
, rest
-= len
;
1274 xassert (rest
>= 0);
1276 BYTEPOS (pos
) += len
;
1280 SET_TEXT_POS (pos
, charpos
, charpos
);
1286 /* Value is the number of characters in C string S. MULTIBYTE_P
1287 non-zero means recognize multibyte characters. */
1290 number_of_chars (s
, multibyte_p
)
1298 int rest
= strlen (s
), len
;
1299 unsigned char *p
= (unsigned char *) s
;
1301 for (nchars
= 0; rest
> 0; ++nchars
)
1303 string_char_and_length (p
, rest
, &len
);
1304 rest
-= len
, p
+= len
;
1308 nchars
= strlen (s
);
1314 /* Compute byte position NEWPOS->bytepos corresponding to
1315 NEWPOS->charpos. POS is a known position in string STRING.
1316 NEWPOS->charpos must be >= POS.charpos. */
1319 compute_string_pos (newpos
, pos
, string
)
1320 struct text_pos
*newpos
, pos
;
1323 xassert (STRINGP (string
));
1324 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1326 if (STRING_MULTIBYTE (string
))
1327 *newpos
= string_pos_nchars_ahead (pos
, string
,
1328 CHARPOS (*newpos
) - CHARPOS (pos
));
1330 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1335 /***********************************************************************
1336 Lisp form evaluation
1337 ***********************************************************************/
1339 /* Error handler for safe_eval and safe_call. */
1342 safe_eval_handler (arg
)
1345 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1350 /* Evaluate SEXPR and return the result, or nil if something went
1351 wrong. Prevent redisplay during the evaluation. */
1359 if (inhibit_eval_during_redisplay
)
1363 int count
= SPECPDL_INDEX ();
1364 struct gcpro gcpro1
;
1367 specbind (Qinhibit_redisplay
, Qt
);
1368 /* Use Qt to ensure debugger does not run,
1369 so there is no possibility of wanting to redisplay. */
1370 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1373 val
= unbind_to (count
, val
);
1380 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1381 Return the result, or nil if something went wrong. Prevent
1382 redisplay during the evaluation. */
1385 safe_call (nargs
, args
)
1391 if (inhibit_eval_during_redisplay
)
1395 int count
= SPECPDL_INDEX ();
1396 struct gcpro gcpro1
;
1399 gcpro1
.nvars
= nargs
;
1400 specbind (Qinhibit_redisplay
, Qt
);
1401 /* Use Qt to ensure debugger does not run,
1402 so there is no possibility of wanting to redisplay. */
1403 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1406 val
= unbind_to (count
, val
);
1413 /* Call function FN with one argument ARG.
1414 Return the result, or nil if something went wrong. */
1417 safe_call1 (fn
, arg
)
1418 Lisp_Object fn
, arg
;
1420 Lisp_Object args
[2];
1423 return safe_call (2, args
);
1428 /***********************************************************************
1430 ***********************************************************************/
1434 /* Define CHECK_IT to perform sanity checks on iterators.
1435 This is for debugging. It is too slow to do unconditionally. */
1441 if (it
->method
== next_element_from_string
)
1443 xassert (STRINGP (it
->string
));
1444 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1446 else if (it
->method
== next_element_from_buffer
)
1448 /* Check that character and byte positions agree. */
1449 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1453 xassert (it
->current
.dpvec_index
>= 0);
1455 xassert (it
->current
.dpvec_index
< 0);
1458 #define CHECK_IT(IT) check_it ((IT))
1462 #define CHECK_IT(IT) (void) 0
1469 /* Check that the window end of window W is what we expect it
1470 to be---the last row in the current matrix displaying text. */
1473 check_window_end (w
)
1476 if (!MINI_WINDOW_P (w
)
1477 && !NILP (w
->window_end_valid
))
1479 struct glyph_row
*row
;
1480 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1481 XFASTINT (w
->window_end_vpos
)),
1483 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1484 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1488 #define CHECK_WINDOW_END(W) check_window_end ((W))
1490 #else /* not GLYPH_DEBUG */
1492 #define CHECK_WINDOW_END(W) (void) 0
1494 #endif /* not GLYPH_DEBUG */
1498 /***********************************************************************
1499 Iterator initialization
1500 ***********************************************************************/
1502 /* Initialize IT for displaying current_buffer in window W, starting
1503 at character position CHARPOS. CHARPOS < 0 means that no buffer
1504 position is specified which is useful when the iterator is assigned
1505 a position later. BYTEPOS is the byte position corresponding to
1506 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1508 If ROW is not null, calls to produce_glyphs with IT as parameter
1509 will produce glyphs in that row.
1511 BASE_FACE_ID is the id of a base face to use. It must be one of
1512 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1513 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1514 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1516 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1517 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1518 will be initialized to use the corresponding mode line glyph row of
1519 the desired matrix of W. */
1522 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1525 int charpos
, bytepos
;
1526 struct glyph_row
*row
;
1527 enum face_id base_face_id
;
1529 int highlight_region_p
;
1531 /* Some precondition checks. */
1532 xassert (w
!= NULL
&& it
!= NULL
);
1533 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1536 /* If face attributes have been changed since the last redisplay,
1537 free realized faces now because they depend on face definitions
1538 that might have changed. Don't free faces while there might be
1539 desired matrices pending which reference these faces. */
1540 if (face_change_count
&& !inhibit_free_realized_faces
)
1542 face_change_count
= 0;
1543 free_all_realized_faces (Qnil
);
1546 /* Use one of the mode line rows of W's desired matrix if
1550 if (base_face_id
== MODE_LINE_FACE_ID
1551 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
1552 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1553 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1554 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1558 bzero (it
, sizeof *it
);
1559 it
->current
.overlay_string_index
= -1;
1560 it
->current
.dpvec_index
= -1;
1561 it
->base_face_id
= base_face_id
;
1563 /* The window in which we iterate over current_buffer: */
1564 XSETWINDOW (it
->window
, w
);
1566 it
->f
= XFRAME (w
->frame
);
1568 /* Extra space between lines (on window systems only). */
1569 if (base_face_id
== DEFAULT_FACE_ID
1570 && FRAME_WINDOW_P (it
->f
))
1572 if (NATNUMP (current_buffer
->extra_line_spacing
))
1573 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1574 else if (it
->f
->extra_line_spacing
> 0)
1575 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1578 /* If realized faces have been removed, e.g. because of face
1579 attribute changes of named faces, recompute them. When running
1580 in batch mode, the face cache of Vterminal_frame is null. If
1581 we happen to get called, make a dummy face cache. */
1586 FRAME_FACE_CACHE (it
->f
) == NULL
)
1587 init_frame_faces (it
->f
);
1588 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1589 recompute_basic_faces (it
->f
);
1591 /* Current value of the `space-width', and 'height' properties. */
1592 it
->space_width
= Qnil
;
1593 it
->font_height
= Qnil
;
1595 /* Are control characters displayed as `^C'? */
1596 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1598 /* -1 means everything between a CR and the following line end
1599 is invisible. >0 means lines indented more than this value are
1601 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1602 ? XFASTINT (current_buffer
->selective_display
)
1603 : (!NILP (current_buffer
->selective_display
)
1605 it
->selective_display_ellipsis_p
1606 = !NILP (current_buffer
->selective_display_ellipses
);
1608 /* Display table to use. */
1609 it
->dp
= window_display_table (w
);
1611 /* Are multibyte characters enabled in current_buffer? */
1612 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1614 /* Non-zero if we should highlight the region. */
1616 = (!NILP (Vtransient_mark_mode
)
1617 && !NILP (current_buffer
->mark_active
)
1618 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1620 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1621 start and end of a visible region in window IT->w. Set both to
1622 -1 to indicate no region. */
1623 if (highlight_region_p
1624 /* Maybe highlight only in selected window. */
1625 && (/* Either show region everywhere. */
1626 highlight_nonselected_windows
1627 /* Or show region in the selected window. */
1628 || w
== XWINDOW (selected_window
)
1629 /* Or show the region if we are in the mini-buffer and W is
1630 the window the mini-buffer refers to. */
1631 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1632 && WINDOWP (minibuf_selected_window
)
1633 && w
== XWINDOW (minibuf_selected_window
))))
1635 int charpos
= marker_position (current_buffer
->mark
);
1636 it
->region_beg_charpos
= min (PT
, charpos
);
1637 it
->region_end_charpos
= max (PT
, charpos
);
1640 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1642 /* Get the position at which the redisplay_end_trigger hook should
1643 be run, if it is to be run at all. */
1644 if (MARKERP (w
->redisplay_end_trigger
)
1645 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1646 it
->redisplay_end_trigger_charpos
1647 = marker_position (w
->redisplay_end_trigger
);
1648 else if (INTEGERP (w
->redisplay_end_trigger
))
1649 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1651 /* Correct bogus values of tab_width. */
1652 it
->tab_width
= XINT (current_buffer
->tab_width
);
1653 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1656 /* Are lines in the display truncated? */
1657 it
->truncate_lines_p
1658 = (base_face_id
!= DEFAULT_FACE_ID
1659 || XINT (it
->w
->hscroll
)
1660 || (truncate_partial_width_windows
1661 && !WINDOW_FULL_WIDTH_P (it
->w
))
1662 || !NILP (current_buffer
->truncate_lines
));
1664 /* Get dimensions of truncation and continuation glyphs. These are
1665 displayed as fringe bitmaps under X, so we don't need them for such
1667 if (!FRAME_WINDOW_P (it
->f
))
1669 if (it
->truncate_lines_p
)
1671 /* We will need the truncation glyph. */
1672 xassert (it
->glyph_row
== NULL
);
1673 produce_special_glyphs (it
, IT_TRUNCATION
);
1674 it
->truncation_pixel_width
= it
->pixel_width
;
1678 /* We will need the continuation glyph. */
1679 xassert (it
->glyph_row
== NULL
);
1680 produce_special_glyphs (it
, IT_CONTINUATION
);
1681 it
->continuation_pixel_width
= it
->pixel_width
;
1684 /* Reset these values to zero because the produce_special_glyphs
1685 above has changed them. */
1686 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1687 it
->phys_ascent
= it
->phys_descent
= 0;
1690 /* Set this after getting the dimensions of truncation and
1691 continuation glyphs, so that we don't produce glyphs when calling
1692 produce_special_glyphs, above. */
1693 it
->glyph_row
= row
;
1694 it
->area
= TEXT_AREA
;
1696 /* Get the dimensions of the display area. The display area
1697 consists of the visible window area plus a horizontally scrolled
1698 part to the left of the window. All x-values are relative to the
1699 start of this total display area. */
1700 if (base_face_id
!= DEFAULT_FACE_ID
)
1702 /* Mode lines, menu bar in terminal frames. */
1703 it
->first_visible_x
= 0;
1704 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1709 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1710 it
->last_visible_x
= (it
->first_visible_x
1711 + window_box_width (w
, TEXT_AREA
));
1713 /* If we truncate lines, leave room for the truncator glyph(s) at
1714 the right margin. Otherwise, leave room for the continuation
1715 glyph(s). Truncation and continuation glyphs are not inserted
1716 for window-based redisplay. */
1717 if (!FRAME_WINDOW_P (it
->f
))
1719 if (it
->truncate_lines_p
)
1720 it
->last_visible_x
-= it
->truncation_pixel_width
;
1722 it
->last_visible_x
-= it
->continuation_pixel_width
;
1725 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1726 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1729 /* Leave room for a border glyph. */
1730 if (!FRAME_WINDOW_P (it
->f
)
1731 && !WINDOW_RIGHTMOST_P (it
->w
))
1732 it
->last_visible_x
-= 1;
1734 it
->last_visible_y
= window_text_bottom_y (w
);
1736 /* For mode lines and alike, arrange for the first glyph having a
1737 left box line if the face specifies a box. */
1738 if (base_face_id
!= DEFAULT_FACE_ID
)
1742 it
->face_id
= base_face_id
;
1744 /* If we have a boxed mode line, make the first character appear
1745 with a left box line. */
1746 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1747 if (face
->box
!= FACE_NO_BOX
)
1748 it
->start_of_box_run_p
= 1;
1751 /* If a buffer position was specified, set the iterator there,
1752 getting overlays and face properties from that position. */
1753 if (charpos
>= BUF_BEG (current_buffer
))
1755 it
->end_charpos
= ZV
;
1757 IT_CHARPOS (*it
) = charpos
;
1759 /* Compute byte position if not specified. */
1760 if (bytepos
< charpos
)
1761 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1763 IT_BYTEPOS (*it
) = bytepos
;
1765 /* Compute faces etc. */
1766 reseat (it
, it
->current
.pos
, 1);
1773 /* Initialize IT for the display of window W with window start POS. */
1776 start_display (it
, w
, pos
)
1779 struct text_pos pos
;
1781 struct glyph_row
*row
;
1782 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1784 row
= w
->desired_matrix
->rows
+ first_vpos
;
1785 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1787 if (!it
->truncate_lines_p
)
1789 int start_at_line_beg_p
;
1790 int first_y
= it
->current_y
;
1792 /* If window start is not at a line start, skip forward to POS to
1793 get the correct continuation lines width. */
1794 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1795 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1796 if (!start_at_line_beg_p
)
1800 reseat_at_previous_visible_line_start (it
);
1801 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1803 new_x
= it
->current_x
+ it
->pixel_width
;
1805 /* If lines are continued, this line may end in the middle
1806 of a multi-glyph character (e.g. a control character
1807 displayed as \003, or in the middle of an overlay
1808 string). In this case move_it_to above will not have
1809 taken us to the start of the continuation line but to the
1810 end of the continued line. */
1811 if (it
->current_x
> 0
1812 && !it
->truncate_lines_p
/* Lines are continued. */
1813 && (/* And glyph doesn't fit on the line. */
1814 new_x
> it
->last_visible_x
1815 /* Or it fits exactly and we're on a window
1817 || (new_x
== it
->last_visible_x
1818 && FRAME_WINDOW_P (it
->f
))))
1820 if (it
->current
.dpvec_index
>= 0
1821 || it
->current
.overlay_string_index
>= 0)
1823 set_iterator_to_next (it
, 1);
1824 move_it_in_display_line_to (it
, -1, -1, 0);
1827 it
->continuation_lines_width
+= it
->current_x
;
1830 /* We're starting a new display line, not affected by the
1831 height of the continued line, so clear the appropriate
1832 fields in the iterator structure. */
1833 it
->max_ascent
= it
->max_descent
= 0;
1834 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1836 it
->current_y
= first_y
;
1838 it
->current_x
= it
->hpos
= 0;
1842 #if 0 /* Don't assert the following because start_display is sometimes
1843 called intentionally with a window start that is not at a
1844 line start. Please leave this code in as a comment. */
1846 /* Window start should be on a line start, now. */
1847 xassert (it
->continuation_lines_width
1848 || IT_CHARPOS (it
) == BEGV
1849 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1854 /* Return 1 if POS is a position in ellipses displayed for invisible
1855 text. W is the window we display, for text property lookup. */
1858 in_ellipses_for_invisible_text_p (pos
, w
)
1859 struct display_pos
*pos
;
1862 Lisp_Object prop
, window
;
1864 int charpos
= CHARPOS (pos
->pos
);
1866 /* If POS specifies a position in a display vector, this might
1867 be for an ellipsis displayed for invisible text. We won't
1868 get the iterator set up for delivering that ellipsis unless
1869 we make sure that it gets aware of the invisible text. */
1870 if (pos
->dpvec_index
>= 0
1871 && pos
->overlay_string_index
< 0
1872 && CHARPOS (pos
->string_pos
) < 0
1874 && (XSETWINDOW (window
, w
),
1875 prop
= Fget_char_property (make_number (charpos
),
1876 Qinvisible
, window
),
1877 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1879 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1881 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
1888 /* Initialize IT for stepping through current_buffer in window W,
1889 starting at position POS that includes overlay string and display
1890 vector/ control character translation position information. Value
1891 is zero if there are overlay strings with newlines at POS. */
1894 init_from_display_pos (it
, w
, pos
)
1897 struct display_pos
*pos
;
1899 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1900 int i
, overlay_strings_with_newlines
= 0;
1902 /* If POS specifies a position in a display vector, this might
1903 be for an ellipsis displayed for invisible text. We won't
1904 get the iterator set up for delivering that ellipsis unless
1905 we make sure that it gets aware of the invisible text. */
1906 if (in_ellipses_for_invisible_text_p (pos
, w
))
1912 /* Keep in mind: the call to reseat in init_iterator skips invisible
1913 text, so we might end up at a position different from POS. This
1914 is only a problem when POS is a row start after a newline and an
1915 overlay starts there with an after-string, and the overlay has an
1916 invisible property. Since we don't skip invisible text in
1917 display_line and elsewhere immediately after consuming the
1918 newline before the row start, such a POS will not be in a string,
1919 but the call to init_iterator below will move us to the
1921 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1923 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
1925 const char *s
= SDATA (it
->overlay_strings
[i
]);
1926 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
1928 while (s
< e
&& *s
!= '\n')
1933 overlay_strings_with_newlines
= 1;
1938 /* If position is within an overlay string, set up IT to the right
1940 if (pos
->overlay_string_index
>= 0)
1944 /* If the first overlay string happens to have a `display'
1945 property for an image, the iterator will be set up for that
1946 image, and we have to undo that setup first before we can
1947 correct the overlay string index. */
1948 if (it
->method
== next_element_from_image
)
1951 /* We already have the first chunk of overlay strings in
1952 IT->overlay_strings. Load more until the one for
1953 pos->overlay_string_index is in IT->overlay_strings. */
1954 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1956 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1957 it
->current
.overlay_string_index
= 0;
1960 load_overlay_strings (it
, 0);
1961 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1965 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1966 relative_index
= (it
->current
.overlay_string_index
1967 % OVERLAY_STRING_CHUNK_SIZE
);
1968 it
->string
= it
->overlay_strings
[relative_index
];
1969 xassert (STRINGP (it
->string
));
1970 it
->current
.string_pos
= pos
->string_pos
;
1971 it
->method
= next_element_from_string
;
1974 #if 0 /* This is bogus because POS not having an overlay string
1975 position does not mean it's after the string. Example: A
1976 line starting with a before-string and initialization of IT
1977 to the previous row's end position. */
1978 else if (it
->current
.overlay_string_index
>= 0)
1980 /* If POS says we're already after an overlay string ending at
1981 POS, make sure to pop the iterator because it will be in
1982 front of that overlay string. When POS is ZV, we've thereby
1983 also ``processed'' overlay strings at ZV. */
1986 it
->current
.overlay_string_index
= -1;
1987 it
->method
= next_element_from_buffer
;
1988 if (CHARPOS (pos
->pos
) == ZV
)
1989 it
->overlay_strings_at_end_processed_p
= 1;
1993 if (CHARPOS (pos
->string_pos
) >= 0)
1995 /* Recorded position is not in an overlay string, but in another
1996 string. This can only be a string from a `display' property.
1997 IT should already be filled with that string. */
1998 it
->current
.string_pos
= pos
->string_pos
;
1999 xassert (STRINGP (it
->string
));
2002 /* Restore position in display vector translations, control
2003 character translations or ellipses. */
2004 if (pos
->dpvec_index
>= 0)
2006 if (it
->dpvec
== NULL
)
2007 get_next_display_element (it
);
2008 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2009 it
->current
.dpvec_index
= pos
->dpvec_index
;
2013 return !overlay_strings_with_newlines
;
2017 /* Initialize IT for stepping through current_buffer in window W
2018 starting at ROW->start. */
2021 init_to_row_start (it
, w
, row
)
2024 struct glyph_row
*row
;
2026 init_from_display_pos (it
, w
, &row
->start
);
2027 it
->continuation_lines_width
= row
->continuation_lines_width
;
2032 /* Initialize IT for stepping through current_buffer in window W
2033 starting in the line following ROW, i.e. starting at ROW->end.
2034 Value is zero if there are overlay strings with newlines at ROW's
2038 init_to_row_end (it
, w
, row
)
2041 struct glyph_row
*row
;
2045 if (init_from_display_pos (it
, w
, &row
->end
))
2047 if (row
->continued_p
)
2048 it
->continuation_lines_width
2049 = row
->continuation_lines_width
+ row
->pixel_width
;
2060 /***********************************************************************
2062 ***********************************************************************/
2064 /* Called when IT reaches IT->stop_charpos. Handle text property and
2065 overlay changes. Set IT->stop_charpos to the next position where
2072 enum prop_handled handled
;
2073 int handle_overlay_change_p
= 1;
2077 it
->current
.dpvec_index
= -1;
2081 handled
= HANDLED_NORMALLY
;
2083 /* Call text property handlers. */
2084 for (p
= it_props
; p
->handler
; ++p
)
2086 handled
= p
->handler (it
);
2088 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2090 else if (handled
== HANDLED_RETURN
)
2092 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2093 handle_overlay_change_p
= 0;
2096 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2098 /* Don't check for overlay strings below when set to deliver
2099 characters from a display vector. */
2100 if (it
->method
== next_element_from_display_vector
)
2101 handle_overlay_change_p
= 0;
2103 /* Handle overlay changes. */
2104 if (handle_overlay_change_p
)
2105 handled
= handle_overlay_change (it
);
2107 /* Determine where to stop next. */
2108 if (handled
== HANDLED_NORMALLY
)
2109 compute_stop_pos (it
);
2112 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2116 /* Compute IT->stop_charpos from text property and overlay change
2117 information for IT's current position. */
2120 compute_stop_pos (it
)
2123 register INTERVAL iv
, next_iv
;
2124 Lisp_Object object
, limit
, position
;
2126 /* If nowhere else, stop at the end. */
2127 it
->stop_charpos
= it
->end_charpos
;
2129 if (STRINGP (it
->string
))
2131 /* Strings are usually short, so don't limit the search for
2133 object
= it
->string
;
2135 position
= make_number (IT_STRING_CHARPOS (*it
));
2141 /* If next overlay change is in front of the current stop pos
2142 (which is IT->end_charpos), stop there. Note: value of
2143 next_overlay_change is point-max if no overlay change
2145 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2146 if (charpos
< it
->stop_charpos
)
2147 it
->stop_charpos
= charpos
;
2149 /* If showing the region, we have to stop at the region
2150 start or end because the face might change there. */
2151 if (it
->region_beg_charpos
> 0)
2153 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2154 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2155 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2156 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2159 /* Set up variables for computing the stop position from text
2160 property changes. */
2161 XSETBUFFER (object
, current_buffer
);
2162 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2163 position
= make_number (IT_CHARPOS (*it
));
2167 /* Get the interval containing IT's position. Value is a null
2168 interval if there isn't such an interval. */
2169 iv
= validate_interval_range (object
, &position
, &position
, 0);
2170 if (!NULL_INTERVAL_P (iv
))
2172 Lisp_Object values_here
[LAST_PROP_IDX
];
2175 /* Get properties here. */
2176 for (p
= it_props
; p
->handler
; ++p
)
2177 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2179 /* Look for an interval following iv that has different
2181 for (next_iv
= next_interval (iv
);
2182 (!NULL_INTERVAL_P (next_iv
)
2184 || XFASTINT (limit
) > next_iv
->position
));
2185 next_iv
= next_interval (next_iv
))
2187 for (p
= it_props
; p
->handler
; ++p
)
2189 Lisp_Object new_value
;
2191 new_value
= textget (next_iv
->plist
, *p
->name
);
2192 if (!EQ (values_here
[p
->idx
], new_value
))
2200 if (!NULL_INTERVAL_P (next_iv
))
2202 if (INTEGERP (limit
)
2203 && next_iv
->position
>= XFASTINT (limit
))
2204 /* No text property change up to limit. */
2205 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2207 /* Text properties change in next_iv. */
2208 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2212 xassert (STRINGP (it
->string
)
2213 || (it
->stop_charpos
>= BEGV
2214 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2218 /* Return the position of the next overlay change after POS in
2219 current_buffer. Value is point-max if no overlay change
2220 follows. This is like `next-overlay-change' but doesn't use
2224 next_overlay_change (pos
)
2229 Lisp_Object
*overlays
;
2233 /* Get all overlays at the given position. */
2235 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2236 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2237 if (noverlays
> len
)
2240 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2241 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2244 /* If any of these overlays ends before endpos,
2245 use its ending point instead. */
2246 for (i
= 0; i
< noverlays
; ++i
)
2251 oend
= OVERLAY_END (overlays
[i
]);
2252 oendpos
= OVERLAY_POSITION (oend
);
2253 endpos
= min (endpos
, oendpos
);
2261 /***********************************************************************
2263 ***********************************************************************/
2265 /* Handle changes in the `fontified' property of the current buffer by
2266 calling hook functions from Qfontification_functions to fontify
2269 static enum prop_handled
2270 handle_fontified_prop (it
)
2273 Lisp_Object prop
, pos
;
2274 enum prop_handled handled
= HANDLED_NORMALLY
;
2276 /* Get the value of the `fontified' property at IT's current buffer
2277 position. (The `fontified' property doesn't have a special
2278 meaning in strings.) If the value is nil, call functions from
2279 Qfontification_functions. */
2280 if (!STRINGP (it
->string
)
2282 && !NILP (Vfontification_functions
)
2283 && !NILP (Vrun_hooks
)
2284 && (pos
= make_number (IT_CHARPOS (*it
)),
2285 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2288 int count
= SPECPDL_INDEX ();
2291 val
= Vfontification_functions
;
2292 specbind (Qfontification_functions
, Qnil
);
2294 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2295 safe_call1 (val
, pos
);
2298 Lisp_Object globals
, fn
;
2299 struct gcpro gcpro1
, gcpro2
;
2302 GCPRO2 (val
, globals
);
2304 for (; CONSP (val
); val
= XCDR (val
))
2310 /* A value of t indicates this hook has a local
2311 binding; it means to run the global binding too.
2312 In a global value, t should not occur. If it
2313 does, we must ignore it to avoid an endless
2315 for (globals
= Fdefault_value (Qfontification_functions
);
2317 globals
= XCDR (globals
))
2319 fn
= XCAR (globals
);
2321 safe_call1 (fn
, pos
);
2325 safe_call1 (fn
, pos
);
2331 unbind_to (count
, Qnil
);
2333 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2334 something. This avoids an endless loop if they failed to
2335 fontify the text for which reason ever. */
2336 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2337 handled
= HANDLED_RECOMPUTE_PROPS
;
2345 /***********************************************************************
2347 ***********************************************************************/
2349 /* Set up iterator IT from face properties at its current position.
2350 Called from handle_stop. */
2352 static enum prop_handled
2353 handle_face_prop (it
)
2356 int new_face_id
, next_stop
;
2358 if (!STRINGP (it
->string
))
2361 = face_at_buffer_position (it
->w
,
2363 it
->region_beg_charpos
,
2364 it
->region_end_charpos
,
2367 + TEXT_PROP_DISTANCE_LIMIT
),
2370 /* Is this a start of a run of characters with box face?
2371 Caveat: this can be called for a freshly initialized
2372 iterator; face_id is -1 in this case. We know that the new
2373 face will not change until limit, i.e. if the new face has a
2374 box, all characters up to limit will have one. But, as
2375 usual, we don't know whether limit is really the end. */
2376 if (new_face_id
!= it
->face_id
)
2378 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2380 /* If new face has a box but old face has not, this is
2381 the start of a run of characters with box, i.e. it has
2382 a shadow on the left side. The value of face_id of the
2383 iterator will be -1 if this is the initial call that gets
2384 the face. In this case, we have to look in front of IT's
2385 position and see whether there is a face != new_face_id. */
2386 it
->start_of_box_run_p
2387 = (new_face
->box
!= FACE_NO_BOX
2388 && (it
->face_id
>= 0
2389 || IT_CHARPOS (*it
) == BEG
2390 || new_face_id
!= face_before_it_pos (it
)));
2391 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2396 int base_face_id
, bufpos
;
2398 if (it
->current
.overlay_string_index
>= 0)
2399 bufpos
= IT_CHARPOS (*it
);
2403 /* For strings from a buffer, i.e. overlay strings or strings
2404 from a `display' property, use the face at IT's current
2405 buffer position as the base face to merge with, so that
2406 overlay strings appear in the same face as surrounding
2407 text, unless they specify their own faces. */
2408 base_face_id
= underlying_face_id (it
);
2410 new_face_id
= face_at_string_position (it
->w
,
2412 IT_STRING_CHARPOS (*it
),
2414 it
->region_beg_charpos
,
2415 it
->region_end_charpos
,
2419 #if 0 /* This shouldn't be neccessary. Let's check it. */
2420 /* If IT is used to display a mode line we would really like to
2421 use the mode line face instead of the frame's default face. */
2422 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2423 && new_face_id
== DEFAULT_FACE_ID
)
2424 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2427 /* Is this a start of a run of characters with box? Caveat:
2428 this can be called for a freshly allocated iterator; face_id
2429 is -1 is this case. We know that the new face will not
2430 change until the next check pos, i.e. if the new face has a
2431 box, all characters up to that position will have a
2432 box. But, as usual, we don't know whether that position
2433 is really the end. */
2434 if (new_face_id
!= it
->face_id
)
2436 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2437 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2439 /* If new face has a box but old face hasn't, this is the
2440 start of a run of characters with box, i.e. it has a
2441 shadow on the left side. */
2442 it
->start_of_box_run_p
2443 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2444 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2448 it
->face_id
= new_face_id
;
2449 return HANDLED_NORMALLY
;
2453 /* Return the ID of the face ``underlying'' IT's current position,
2454 which is in a string. If the iterator is associated with a
2455 buffer, return the face at IT's current buffer position.
2456 Otherwise, use the iterator's base_face_id. */
2459 underlying_face_id (it
)
2462 int face_id
= it
->base_face_id
, i
;
2464 xassert (STRINGP (it
->string
));
2466 for (i
= it
->sp
- 1; i
>= 0; --i
)
2467 if (NILP (it
->stack
[i
].string
))
2468 face_id
= it
->stack
[i
].face_id
;
2474 /* Compute the face one character before or after the current position
2475 of IT. BEFORE_P non-zero means get the face in front of IT's
2476 position. Value is the id of the face. */
2479 face_before_or_after_it_pos (it
, before_p
)
2484 int next_check_charpos
;
2485 struct text_pos pos
;
2487 xassert (it
->s
== NULL
);
2489 if (STRINGP (it
->string
))
2491 int bufpos
, base_face_id
;
2493 /* No face change past the end of the string (for the case
2494 we are padding with spaces). No face change before the
2496 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2497 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2500 /* Set pos to the position before or after IT's current position. */
2502 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2504 /* For composition, we must check the character after the
2506 pos
= (it
->what
== IT_COMPOSITION
2507 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2508 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2510 if (it
->current
.overlay_string_index
>= 0)
2511 bufpos
= IT_CHARPOS (*it
);
2515 base_face_id
= underlying_face_id (it
);
2517 /* Get the face for ASCII, or unibyte. */
2518 face_id
= face_at_string_position (it
->w
,
2522 it
->region_beg_charpos
,
2523 it
->region_end_charpos
,
2524 &next_check_charpos
,
2527 /* Correct the face for charsets different from ASCII. Do it
2528 for the multibyte case only. The face returned above is
2529 suitable for unibyte text if IT->string is unibyte. */
2530 if (STRING_MULTIBYTE (it
->string
))
2532 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
2533 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
2535 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2537 c
= string_char_and_length (p
, rest
, &len
);
2538 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2543 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2544 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2547 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2548 pos
= it
->current
.pos
;
2551 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2554 if (it
->what
== IT_COMPOSITION
)
2555 /* For composition, we must check the position after the
2557 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2559 INC_TEXT_POS (pos
, it
->multibyte_p
);
2562 /* Determine face for CHARSET_ASCII, or unibyte. */
2563 face_id
= face_at_buffer_position (it
->w
,
2565 it
->region_beg_charpos
,
2566 it
->region_end_charpos
,
2567 &next_check_charpos
,
2570 /* Correct the face for charsets different from ASCII. Do it
2571 for the multibyte case only. The face returned above is
2572 suitable for unibyte text if current_buffer is unibyte. */
2573 if (it
->multibyte_p
)
2575 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
2576 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2577 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2586 /***********************************************************************
2588 ***********************************************************************/
2590 /* Set up iterator IT from invisible properties at its current
2591 position. Called from handle_stop. */
2593 static enum prop_handled
2594 handle_invisible_prop (it
)
2597 enum prop_handled handled
= HANDLED_NORMALLY
;
2599 if (STRINGP (it
->string
))
2601 extern Lisp_Object Qinvisible
;
2602 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2604 /* Get the value of the invisible text property at the
2605 current position. Value will be nil if there is no such
2607 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2608 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2611 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2613 handled
= HANDLED_RECOMPUTE_PROPS
;
2615 /* Get the position at which the next change of the
2616 invisible text property can be found in IT->string.
2617 Value will be nil if the property value is the same for
2618 all the rest of IT->string. */
2619 XSETINT (limit
, SCHARS (it
->string
));
2620 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2623 /* Text at current position is invisible. The next
2624 change in the property is at position end_charpos.
2625 Move IT's current position to that position. */
2626 if (INTEGERP (end_charpos
)
2627 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2629 struct text_pos old
;
2630 old
= it
->current
.string_pos
;
2631 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2632 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2636 /* The rest of the string is invisible. If this is an
2637 overlay string, proceed with the next overlay string
2638 or whatever comes and return a character from there. */
2639 if (it
->current
.overlay_string_index
>= 0)
2641 next_overlay_string (it
);
2642 /* Don't check for overlay strings when we just
2643 finished processing them. */
2644 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2648 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
2649 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
2656 int invis_p
, newpos
, next_stop
, start_charpos
;
2657 Lisp_Object pos
, prop
, overlay
;
2659 /* First of all, is there invisible text at this position? */
2660 start_charpos
= IT_CHARPOS (*it
);
2661 pos
= make_number (IT_CHARPOS (*it
));
2662 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2664 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2666 /* If we are on invisible text, skip over it. */
2667 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
2669 /* Record whether we have to display an ellipsis for the
2671 int display_ellipsis_p
= invis_p
== 2;
2673 handled
= HANDLED_RECOMPUTE_PROPS
;
2675 /* Loop skipping over invisible text. The loop is left at
2676 ZV or with IT on the first char being visible again. */
2679 /* Try to skip some invisible text. Return value is the
2680 position reached which can be equal to IT's position
2681 if there is nothing invisible here. This skips both
2682 over invisible text properties and overlays with
2683 invisible property. */
2684 newpos
= skip_invisible (IT_CHARPOS (*it
),
2685 &next_stop
, ZV
, it
->window
);
2687 /* If we skipped nothing at all we weren't at invisible
2688 text in the first place. If everything to the end of
2689 the buffer was skipped, end the loop. */
2690 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2694 /* We skipped some characters but not necessarily
2695 all there are. Check if we ended up on visible
2696 text. Fget_char_property returns the property of
2697 the char before the given position, i.e. if we
2698 get invis_p = 0, this means that the char at
2699 newpos is visible. */
2700 pos
= make_number (newpos
);
2701 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2702 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2705 /* If we ended up on invisible text, proceed to
2706 skip starting with next_stop. */
2708 IT_CHARPOS (*it
) = next_stop
;
2712 /* The position newpos is now either ZV or on visible text. */
2713 IT_CHARPOS (*it
) = newpos
;
2714 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2716 /* If there are before-strings at the start of invisible
2717 text, and the text is invisible because of a text
2718 property, arrange to show before-strings because 20.x did
2719 it that way. (If the text is invisible because of an
2720 overlay property instead of a text property, this is
2721 already handled in the overlay code.) */
2723 && get_overlay_strings (it
, start_charpos
))
2725 handled
= HANDLED_RECOMPUTE_PROPS
;
2726 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2728 else if (display_ellipsis_p
)
2729 setup_for_ellipsis (it
);
2737 /* Make iterator IT return `...' next. */
2740 setup_for_ellipsis (it
)
2744 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2746 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2747 it
->dpvec
= v
->contents
;
2748 it
->dpend
= v
->contents
+ v
->size
;
2752 /* Default `...'. */
2753 it
->dpvec
= default_invis_vector
;
2754 it
->dpend
= default_invis_vector
+ 3;
2757 /* The ellipsis display does not replace the display of the
2758 character at the new position. Indicate this by setting
2759 IT->dpvec_char_len to zero. */
2760 it
->dpvec_char_len
= 0;
2762 it
->current
.dpvec_index
= 0;
2763 it
->method
= next_element_from_display_vector
;
2768 /***********************************************************************
2770 ***********************************************************************/
2772 /* Set up iterator IT from `display' property at its current position.
2773 Called from handle_stop. */
2775 static enum prop_handled
2776 handle_display_prop (it
)
2779 Lisp_Object prop
, object
;
2780 struct text_pos
*position
;
2781 int display_replaced_p
= 0;
2783 if (STRINGP (it
->string
))
2785 object
= it
->string
;
2786 position
= &it
->current
.string_pos
;
2790 object
= it
->w
->buffer
;
2791 position
= &it
->current
.pos
;
2794 /* Reset those iterator values set from display property values. */
2795 it
->font_height
= Qnil
;
2796 it
->space_width
= Qnil
;
2799 /* We don't support recursive `display' properties, i.e. string
2800 values that have a string `display' property, that have a string
2801 `display' property etc. */
2802 if (!it
->string_from_display_prop_p
)
2803 it
->area
= TEXT_AREA
;
2805 prop
= Fget_char_property (make_number (position
->charpos
),
2808 return HANDLED_NORMALLY
;
2811 /* Simple properties. */
2812 && !EQ (XCAR (prop
), Qimage
)
2813 && !EQ (XCAR (prop
), Qspace
)
2814 && !EQ (XCAR (prop
), Qwhen
)
2815 && !EQ (XCAR (prop
), Qspace_width
)
2816 && !EQ (XCAR (prop
), Qheight
)
2817 && !EQ (XCAR (prop
), Qraise
)
2818 /* Marginal area specifications. */
2819 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2820 && !NILP (XCAR (prop
)))
2822 for (; CONSP (prop
); prop
= XCDR (prop
))
2824 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2825 position
, display_replaced_p
))
2826 display_replaced_p
= 1;
2829 else if (VECTORP (prop
))
2832 for (i
= 0; i
< ASIZE (prop
); ++i
)
2833 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2834 position
, display_replaced_p
))
2835 display_replaced_p
= 1;
2839 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2840 display_replaced_p
= 1;
2843 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2847 /* Value is the position of the end of the `display' property starting
2848 at START_POS in OBJECT. */
2850 static struct text_pos
2851 display_prop_end (it
, object
, start_pos
)
2854 struct text_pos start_pos
;
2857 struct text_pos end_pos
;
2859 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2860 Qdisplay
, object
, Qnil
);
2861 CHARPOS (end_pos
) = XFASTINT (end
);
2862 if (STRINGP (object
))
2863 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2865 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2871 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2872 is the object in which the `display' property was found. *POSITION
2873 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2874 means that we previously saw a display sub-property which already
2875 replaced text display with something else, for example an image;
2876 ignore such properties after the first one has been processed.
2878 If PROP is a `space' or `image' sub-property, set *POSITION to the
2879 end position of the `display' property.
2881 Value is non-zero if something was found which replaces the display
2882 of buffer or string text. */
2885 handle_single_display_prop (it
, prop
, object
, position
,
2886 display_replaced_before_p
)
2890 struct text_pos
*position
;
2891 int display_replaced_before_p
;
2894 int replaces_text_display_p
= 0;
2897 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2898 evaluated. If the result is nil, VALUE is ignored. */
2900 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2909 if (!NILP (form
) && !EQ (form
, Qt
))
2911 int count
= SPECPDL_INDEX ();
2912 struct gcpro gcpro1
;
2914 /* Bind `object' to the object having the `display' property, a
2915 buffer or string. Bind `position' to the position in the
2916 object where the property was found, and `buffer-position'
2917 to the current position in the buffer. */
2918 specbind (Qobject
, object
);
2919 specbind (Qposition
, make_number (CHARPOS (*position
)));
2920 specbind (Qbuffer_position
,
2921 make_number (STRINGP (object
)
2922 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2924 form
= safe_eval (form
);
2926 unbind_to (count
, Qnil
);
2933 && EQ (XCAR (prop
), Qheight
)
2934 && CONSP (XCDR (prop
)))
2936 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2939 /* `(height HEIGHT)'. */
2940 it
->font_height
= XCAR (XCDR (prop
));
2941 if (!NILP (it
->font_height
))
2943 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2944 int new_height
= -1;
2946 if (CONSP (it
->font_height
)
2947 && (EQ (XCAR (it
->font_height
), Qplus
)
2948 || EQ (XCAR (it
->font_height
), Qminus
))
2949 && CONSP (XCDR (it
->font_height
))
2950 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2952 /* `(+ N)' or `(- N)' where N is an integer. */
2953 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2954 if (EQ (XCAR (it
->font_height
), Qplus
))
2956 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2958 else if (FUNCTIONP (it
->font_height
))
2960 /* Call function with current height as argument.
2961 Value is the new height. */
2963 height
= safe_call1 (it
->font_height
,
2964 face
->lface
[LFACE_HEIGHT_INDEX
]);
2965 if (NUMBERP (height
))
2966 new_height
= XFLOATINT (height
);
2968 else if (NUMBERP (it
->font_height
))
2970 /* Value is a multiple of the canonical char height. */
2973 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2974 new_height
= (XFLOATINT (it
->font_height
)
2975 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2979 /* Evaluate IT->font_height with `height' bound to the
2980 current specified height to get the new height. */
2982 int count
= SPECPDL_INDEX ();
2984 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2985 value
= safe_eval (it
->font_height
);
2986 unbind_to (count
, Qnil
);
2988 if (NUMBERP (value
))
2989 new_height
= XFLOATINT (value
);
2993 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2996 else if (CONSP (prop
)
2997 && EQ (XCAR (prop
), Qspace_width
)
2998 && CONSP (XCDR (prop
)))
3000 /* `(space_width WIDTH)'. */
3001 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3004 value
= XCAR (XCDR (prop
));
3005 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3006 it
->space_width
= value
;
3008 else if (CONSP (prop
)
3009 && EQ (XCAR (prop
), Qraise
)
3010 && CONSP (XCDR (prop
)))
3012 /* `(raise FACTOR)'. */
3013 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3016 #ifdef HAVE_WINDOW_SYSTEM
3017 value
= XCAR (XCDR (prop
));
3018 if (NUMBERP (value
))
3020 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3021 it
->voffset
= - (XFLOATINT (value
)
3022 * (FONT_HEIGHT (face
->font
)));
3024 #endif /* HAVE_WINDOW_SYSTEM */
3026 else if (!it
->string_from_display_prop_p
)
3028 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3029 VALUE) or `((margin nil) VALUE)' or VALUE. */
3030 Lisp_Object location
, value
;
3031 struct text_pos start_pos
;
3034 /* Characters having this form of property are not displayed, so
3035 we have to find the end of the property. */
3036 start_pos
= *position
;
3037 *position
= display_prop_end (it
, object
, start_pos
);
3040 /* Let's stop at the new position and assume that all
3041 text properties change there. */
3042 it
->stop_charpos
= position
->charpos
;
3044 location
= Qunbound
;
3045 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3049 value
= XCDR (prop
);
3051 value
= XCAR (value
);
3054 if (EQ (XCAR (tem
), Qmargin
)
3055 && (tem
= XCDR (tem
),
3056 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3058 || EQ (tem
, Qleft_margin
)
3059 || EQ (tem
, Qright_margin
))))
3063 if (EQ (location
, Qunbound
))
3069 #ifdef HAVE_WINDOW_SYSTEM
3070 if (FRAME_TERMCAP_P (it
->f
))
3071 valid_p
= STRINGP (value
);
3073 valid_p
= (STRINGP (value
)
3074 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3075 || valid_image_p (value
));
3076 #else /* not HAVE_WINDOW_SYSTEM */
3077 valid_p
= STRINGP (value
);
3078 #endif /* not HAVE_WINDOW_SYSTEM */
3080 if ((EQ (location
, Qleft_margin
)
3081 || EQ (location
, Qright_margin
)
3084 && !display_replaced_before_p
)
3086 replaces_text_display_p
= 1;
3088 /* Save current settings of IT so that we can restore them
3089 when we are finished with the glyph property value. */
3092 if (NILP (location
))
3093 it
->area
= TEXT_AREA
;
3094 else if (EQ (location
, Qleft_margin
))
3095 it
->area
= LEFT_MARGIN_AREA
;
3097 it
->area
= RIGHT_MARGIN_AREA
;
3099 if (STRINGP (value
))
3102 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3103 it
->current
.overlay_string_index
= -1;
3104 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3105 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3106 it
->method
= next_element_from_string
;
3107 it
->stop_charpos
= 0;
3108 it
->string_from_display_prop_p
= 1;
3109 /* Say that we haven't consumed the characters with
3110 `display' property yet. The call to pop_it in
3111 set_iterator_to_next will clean this up. */
3112 *position
= start_pos
;
3114 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3116 it
->method
= next_element_from_stretch
;
3118 it
->current
.pos
= it
->position
= start_pos
;
3120 #ifdef HAVE_WINDOW_SYSTEM
3123 it
->what
= IT_IMAGE
;
3124 it
->image_id
= lookup_image (it
->f
, value
);
3125 it
->position
= start_pos
;
3126 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3127 it
->method
= next_element_from_image
;
3129 /* Say that we haven't consumed the characters with
3130 `display' property yet. The call to pop_it in
3131 set_iterator_to_next will clean this up. */
3132 *position
= start_pos
;
3134 #endif /* HAVE_WINDOW_SYSTEM */
3137 /* Invalid property or property not supported. Restore
3138 the position to what it was before. */
3139 *position
= start_pos
;
3142 return replaces_text_display_p
;
3146 /* Check if PROP is a display sub-property value whose text should be
3147 treated as intangible. */
3150 single_display_prop_intangible_p (prop
)
3153 /* Skip over `when FORM'. */
3154 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3168 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3169 we don't need to treat text as intangible. */
3170 if (EQ (XCAR (prop
), Qmargin
))
3178 || EQ (XCAR (prop
), Qleft_margin
)
3179 || EQ (XCAR (prop
), Qright_margin
))
3183 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3187 /* Check if PROP is a display property value whose text should be
3188 treated as intangible. */
3191 display_prop_intangible_p (prop
)
3195 && CONSP (XCAR (prop
))
3196 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3198 /* A list of sub-properties. */
3199 while (CONSP (prop
))
3201 if (single_display_prop_intangible_p (XCAR (prop
)))
3206 else if (VECTORP (prop
))
3208 /* A vector of sub-properties. */
3210 for (i
= 0; i
< ASIZE (prop
); ++i
)
3211 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3215 return single_display_prop_intangible_p (prop
);
3221 /* Return 1 if PROP is a display sub-property value containing STRING. */
3224 single_display_prop_string_p (prop
, string
)
3225 Lisp_Object prop
, string
;
3227 if (EQ (string
, prop
))
3230 /* Skip over `when FORM'. */
3231 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3240 /* Skip over `margin LOCATION'. */
3241 if (EQ (XCAR (prop
), Qmargin
))
3252 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3256 /* Return 1 if STRING appears in the `display' property PROP. */
3259 display_prop_string_p (prop
, string
)
3260 Lisp_Object prop
, string
;
3263 && CONSP (XCAR (prop
))
3264 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3266 /* A list of sub-properties. */
3267 while (CONSP (prop
))
3269 if (single_display_prop_string_p (XCAR (prop
), string
))
3274 else if (VECTORP (prop
))
3276 /* A vector of sub-properties. */
3278 for (i
= 0; i
< ASIZE (prop
); ++i
)
3279 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3283 return single_display_prop_string_p (prop
, string
);
3289 /* Determine from which buffer position in W's buffer STRING comes
3290 from. AROUND_CHARPOS is an approximate position where it could
3291 be from. Value is the buffer position or 0 if it couldn't be
3294 W's buffer must be current.
3296 This function is necessary because we don't record buffer positions
3297 in glyphs generated from strings (to keep struct glyph small).
3298 This function may only use code that doesn't eval because it is
3299 called asynchronously from note_mouse_highlight. */
3302 string_buffer_position (w
, string
, around_charpos
)
3307 Lisp_Object limit
, prop
, pos
;
3308 const int MAX_DISTANCE
= 1000;
3311 pos
= make_number (around_charpos
);
3312 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3313 while (!found
&& !EQ (pos
, limit
))
3315 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3316 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3319 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3324 pos
= make_number (around_charpos
);
3325 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3326 while (!found
&& !EQ (pos
, limit
))
3328 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3329 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3332 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3337 return found
? XINT (pos
) : 0;
3342 /***********************************************************************
3343 `composition' property
3344 ***********************************************************************/
3346 /* Set up iterator IT from `composition' property at its current
3347 position. Called from handle_stop. */
3349 static enum prop_handled
3350 handle_composition_prop (it
)
3353 Lisp_Object prop
, string
;
3354 int pos
, pos_byte
, end
;
3355 enum prop_handled handled
= HANDLED_NORMALLY
;
3357 if (STRINGP (it
->string
))
3359 pos
= IT_STRING_CHARPOS (*it
);
3360 pos_byte
= IT_STRING_BYTEPOS (*it
);
3361 string
= it
->string
;
3365 pos
= IT_CHARPOS (*it
);
3366 pos_byte
= IT_BYTEPOS (*it
);
3370 /* If there's a valid composition and point is not inside of the
3371 composition (in the case that the composition is from the current
3372 buffer), draw a glyph composed from the composition components. */
3373 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3374 && COMPOSITION_VALID_P (pos
, end
, prop
)
3375 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3377 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3381 it
->method
= next_element_from_composition
;
3383 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3384 /* For a terminal, draw only the first character of the
3386 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3387 it
->len
= (STRINGP (it
->string
)
3388 ? string_char_to_byte (it
->string
, end
)
3389 : CHAR_TO_BYTE (end
)) - pos_byte
;
3390 it
->stop_charpos
= end
;
3391 handled
= HANDLED_RETURN
;
3400 /***********************************************************************
3402 ***********************************************************************/
3404 /* The following structure is used to record overlay strings for
3405 later sorting in load_overlay_strings. */
3407 struct overlay_entry
3409 Lisp_Object overlay
;
3416 /* Set up iterator IT from overlay strings at its current position.
3417 Called from handle_stop. */
3419 static enum prop_handled
3420 handle_overlay_change (it
)
3423 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3424 return HANDLED_RECOMPUTE_PROPS
;
3426 return HANDLED_NORMALLY
;
3430 /* Set up the next overlay string for delivery by IT, if there is an
3431 overlay string to deliver. Called by set_iterator_to_next when the
3432 end of the current overlay string is reached. If there are more
3433 overlay strings to display, IT->string and
3434 IT->current.overlay_string_index are set appropriately here.
3435 Otherwise IT->string is set to nil. */
3438 next_overlay_string (it
)
3441 ++it
->current
.overlay_string_index
;
3442 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3444 /* No more overlay strings. Restore IT's settings to what
3445 they were before overlay strings were processed, and
3446 continue to deliver from current_buffer. */
3447 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3450 xassert (it
->stop_charpos
>= BEGV
3451 && it
->stop_charpos
<= it
->end_charpos
);
3453 it
->current
.overlay_string_index
= -1;
3454 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3455 it
->n_overlay_strings
= 0;
3456 it
->method
= next_element_from_buffer
;
3458 /* If we're at the end of the buffer, record that we have
3459 processed the overlay strings there already, so that
3460 next_element_from_buffer doesn't try it again. */
3461 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3462 it
->overlay_strings_at_end_processed_p
= 1;
3464 /* If we have to display `...' for invisible text, set
3465 the iterator up for that. */
3466 if (display_ellipsis_p
)
3467 setup_for_ellipsis (it
);
3471 /* There are more overlay strings to process. If
3472 IT->current.overlay_string_index has advanced to a position
3473 where we must load IT->overlay_strings with more strings, do
3475 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3477 if (it
->current
.overlay_string_index
&& i
== 0)
3478 load_overlay_strings (it
, 0);
3480 /* Initialize IT to deliver display elements from the overlay
3482 it
->string
= it
->overlay_strings
[i
];
3483 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3484 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3485 it
->method
= next_element_from_string
;
3486 it
->stop_charpos
= 0;
3493 /* Compare two overlay_entry structures E1 and E2. Used as a
3494 comparison function for qsort in load_overlay_strings. Overlay
3495 strings for the same position are sorted so that
3497 1. All after-strings come in front of before-strings, except
3498 when they come from the same overlay.
3500 2. Within after-strings, strings are sorted so that overlay strings
3501 from overlays with higher priorities come first.
3503 2. Within before-strings, strings are sorted so that overlay
3504 strings from overlays with higher priorities come last.
3506 Value is analogous to strcmp. */
3510 compare_overlay_entries (e1
, e2
)
3513 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3514 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3517 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3519 /* Let after-strings appear in front of before-strings if
3520 they come from different overlays. */
3521 if (EQ (entry1
->overlay
, entry2
->overlay
))
3522 result
= entry1
->after_string_p
? 1 : -1;
3524 result
= entry1
->after_string_p
? -1 : 1;
3526 else if (entry1
->after_string_p
)
3527 /* After-strings sorted in order of decreasing priority. */
3528 result
= entry2
->priority
- entry1
->priority
;
3530 /* Before-strings sorted in order of increasing priority. */
3531 result
= entry1
->priority
- entry2
->priority
;
3537 /* Load the vector IT->overlay_strings with overlay strings from IT's
3538 current buffer position, or from CHARPOS if that is > 0. Set
3539 IT->n_overlays to the total number of overlay strings found.
3541 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3542 a time. On entry into load_overlay_strings,
3543 IT->current.overlay_string_index gives the number of overlay
3544 strings that have already been loaded by previous calls to this
3547 IT->add_overlay_start contains an additional overlay start
3548 position to consider for taking overlay strings from, if non-zero.
3549 This position comes into play when the overlay has an `invisible'
3550 property, and both before and after-strings. When we've skipped to
3551 the end of the overlay, because of its `invisible' property, we
3552 nevertheless want its before-string to appear.
3553 IT->add_overlay_start will contain the overlay start position
3556 Overlay strings are sorted so that after-string strings come in
3557 front of before-string strings. Within before and after-strings,
3558 strings are sorted by overlay priority. See also function
3559 compare_overlay_entries. */
3562 load_overlay_strings (it
, charpos
)
3566 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3567 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3570 int n
= 0, i
, j
, invis_p
;
3571 struct overlay_entry
*entries
3572 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3575 charpos
= IT_CHARPOS (*it
);
3577 /* Append the overlay string STRING of overlay OVERLAY to vector
3578 `entries' which has size `size' and currently contains `n'
3579 elements. AFTER_P non-zero means STRING is an after-string of
3581 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3584 Lisp_Object priority; \
3588 int new_size = 2 * size; \
3589 struct overlay_entry *old = entries; \
3591 (struct overlay_entry *) alloca (new_size \
3592 * sizeof *entries); \
3593 bcopy (old, entries, size * sizeof *entries); \
3597 entries[n].string = (STRING); \
3598 entries[n].overlay = (OVERLAY); \
3599 priority = Foverlay_get ((OVERLAY), Qpriority); \
3600 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3601 entries[n].after_string_p = (AFTER_P); \
3606 /* Process overlay before the overlay center. */
3607 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3609 overlay
= XCAR (ov
);
3610 xassert (OVERLAYP (overlay
));
3611 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3612 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3617 /* Skip this overlay if it doesn't start or end at IT's current
3619 if (end
!= charpos
&& start
!= charpos
)
3622 /* Skip this overlay if it doesn't apply to IT->w. */
3623 window
= Foverlay_get (overlay
, Qwindow
);
3624 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3627 /* If the text ``under'' the overlay is invisible, both before-
3628 and after-strings from this overlay are visible; start and
3629 end position are indistinguishable. */
3630 invisible
= Foverlay_get (overlay
, Qinvisible
);
3631 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3633 /* If overlay has a non-empty before-string, record it. */
3634 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3635 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3637 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3639 /* If overlay has a non-empty after-string, record it. */
3640 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3641 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3643 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3646 /* Process overlays after the overlay center. */
3647 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3649 overlay
= XCAR (ov
);
3650 xassert (OVERLAYP (overlay
));
3651 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3652 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3654 if (start
> charpos
)
3657 /* Skip this overlay if it doesn't start or end at IT's current
3659 if (end
!= charpos
&& start
!= charpos
)
3662 /* Skip this overlay if it doesn't apply to IT->w. */
3663 window
= Foverlay_get (overlay
, Qwindow
);
3664 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3667 /* If the text ``under'' the overlay is invisible, it has a zero
3668 dimension, and both before- and after-strings apply. */
3669 invisible
= Foverlay_get (overlay
, Qinvisible
);
3670 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3672 /* If overlay has a non-empty before-string, record it. */
3673 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3674 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3676 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3678 /* If overlay has a non-empty after-string, record it. */
3679 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3680 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3682 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3685 #undef RECORD_OVERLAY_STRING
3689 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3691 /* Record the total number of strings to process. */
3692 it
->n_overlay_strings
= n
;
3694 /* IT->current.overlay_string_index is the number of overlay strings
3695 that have already been consumed by IT. Copy some of the
3696 remaining overlay strings to IT->overlay_strings. */
3698 j
= it
->current
.overlay_string_index
;
3699 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3700 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3706 /* Get the first chunk of overlay strings at IT's current buffer
3707 position, or at CHARPOS if that is > 0. Value is non-zero if at
3708 least one overlay string was found. */
3711 get_overlay_strings (it
, charpos
)
3715 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3716 process. This fills IT->overlay_strings with strings, and sets
3717 IT->n_overlay_strings to the total number of strings to process.
3718 IT->pos.overlay_string_index has to be set temporarily to zero
3719 because load_overlay_strings needs this; it must be set to -1
3720 when no overlay strings are found because a zero value would
3721 indicate a position in the first overlay string. */
3722 it
->current
.overlay_string_index
= 0;
3723 load_overlay_strings (it
, charpos
);
3725 /* If we found overlay strings, set up IT to deliver display
3726 elements from the first one. Otherwise set up IT to deliver
3727 from current_buffer. */
3728 if (it
->n_overlay_strings
)
3730 /* Make sure we know settings in current_buffer, so that we can
3731 restore meaningful values when we're done with the overlay
3733 compute_stop_pos (it
);
3734 xassert (it
->face_id
>= 0);
3736 /* Save IT's settings. They are restored after all overlay
3737 strings have been processed. */
3738 xassert (it
->sp
== 0);
3741 /* Set up IT to deliver display elements from the first overlay
3743 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3744 it
->string
= it
->overlay_strings
[0];
3745 it
->stop_charpos
= 0;
3746 xassert (STRINGP (it
->string
));
3747 it
->end_charpos
= SCHARS (it
->string
);
3748 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3749 it
->method
= next_element_from_string
;
3754 it
->current
.overlay_string_index
= -1;
3755 it
->method
= next_element_from_buffer
;
3760 /* Value is non-zero if we found at least one overlay string. */
3761 return STRINGP (it
->string
);
3766 /***********************************************************************
3767 Saving and restoring state
3768 ***********************************************************************/
3770 /* Save current settings of IT on IT->stack. Called, for example,
3771 before setting up IT for an overlay string, to be able to restore
3772 IT's settings to what they were after the overlay string has been
3779 struct iterator_stack_entry
*p
;
3781 xassert (it
->sp
< 2);
3782 p
= it
->stack
+ it
->sp
;
3784 p
->stop_charpos
= it
->stop_charpos
;
3785 xassert (it
->face_id
>= 0);
3786 p
->face_id
= it
->face_id
;
3787 p
->string
= it
->string
;
3788 p
->pos
= it
->current
;
3789 p
->end_charpos
= it
->end_charpos
;
3790 p
->string_nchars
= it
->string_nchars
;
3792 p
->multibyte_p
= it
->multibyte_p
;
3793 p
->space_width
= it
->space_width
;
3794 p
->font_height
= it
->font_height
;
3795 p
->voffset
= it
->voffset
;
3796 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3797 p
->display_ellipsis_p
= 0;
3802 /* Restore IT's settings from IT->stack. Called, for example, when no
3803 more overlay strings must be processed, and we return to delivering
3804 display elements from a buffer, or when the end of a string from a
3805 `display' property is reached and we return to delivering display
3806 elements from an overlay string, or from a buffer. */
3812 struct iterator_stack_entry
*p
;
3814 xassert (it
->sp
> 0);
3816 p
= it
->stack
+ it
->sp
;
3817 it
->stop_charpos
= p
->stop_charpos
;
3818 it
->face_id
= p
->face_id
;
3819 it
->string
= p
->string
;
3820 it
->current
= p
->pos
;
3821 it
->end_charpos
= p
->end_charpos
;
3822 it
->string_nchars
= p
->string_nchars
;
3824 it
->multibyte_p
= p
->multibyte_p
;
3825 it
->space_width
= p
->space_width
;
3826 it
->font_height
= p
->font_height
;
3827 it
->voffset
= p
->voffset
;
3828 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3833 /***********************************************************************
3835 ***********************************************************************/
3837 /* Set IT's current position to the previous line start. */
3840 back_to_previous_line_start (it
)
3843 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3844 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3848 /* Move IT to the next line start.
3850 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3851 we skipped over part of the text (as opposed to moving the iterator
3852 continuously over the text). Otherwise, don't change the value
3855 Newlines may come from buffer text, overlay strings, or strings
3856 displayed via the `display' property. That's the reason we can't
3857 simply use find_next_newline_no_quit.
3859 Note that this function may not skip over invisible text that is so
3860 because of text properties and immediately follows a newline. If
3861 it would, function reseat_at_next_visible_line_start, when called
3862 from set_iterator_to_next, would effectively make invisible
3863 characters following a newline part of the wrong glyph row, which
3864 leads to wrong cursor motion. */
3867 forward_to_next_line_start (it
, skipped_p
)
3871 int old_selective
, newline_found_p
, n
;
3872 const int MAX_NEWLINE_DISTANCE
= 500;
3874 /* If already on a newline, just consume it to avoid unintended
3875 skipping over invisible text below. */
3876 if (it
->what
== IT_CHARACTER
3878 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3880 set_iterator_to_next (it
, 0);
3885 /* Don't handle selective display in the following. It's (a)
3886 unnecessary because it's done by the caller, and (b) leads to an
3887 infinite recursion because next_element_from_ellipsis indirectly
3888 calls this function. */
3889 old_selective
= it
->selective
;
3892 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3893 from buffer text. */
3894 for (n
= newline_found_p
= 0;
3895 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3896 n
+= STRINGP (it
->string
) ? 0 : 1)
3898 if (!get_next_display_element (it
))
3900 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3901 set_iterator_to_next (it
, 0);
3904 /* If we didn't find a newline near enough, see if we can use a
3906 if (!newline_found_p
)
3908 int start
= IT_CHARPOS (*it
);
3909 int limit
= find_next_newline_no_quit (start
, 1);
3912 xassert (!STRINGP (it
->string
));
3914 /* If there isn't any `display' property in sight, and no
3915 overlays, we can just use the position of the newline in
3917 if (it
->stop_charpos
>= limit
3918 || ((pos
= Fnext_single_property_change (make_number (start
),
3920 Qnil
, make_number (limit
)),
3922 && next_overlay_change (start
) == ZV
))
3924 IT_CHARPOS (*it
) = limit
;
3925 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3926 *skipped_p
= newline_found_p
= 1;
3930 while (get_next_display_element (it
)
3931 && !newline_found_p
)
3933 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3934 set_iterator_to_next (it
, 0);
3939 it
->selective
= old_selective
;
3940 return newline_found_p
;
3944 /* Set IT's current position to the previous visible line start. Skip
3945 invisible text that is so either due to text properties or due to
3946 selective display. Caution: this does not change IT->current_x and
3950 back_to_previous_visible_line_start (it
)
3955 /* Go back one newline if not on BEGV already. */
3956 if (IT_CHARPOS (*it
) > BEGV
)
3957 back_to_previous_line_start (it
);
3959 /* Move over lines that are invisible because of selective display
3960 or text properties. */
3961 while (IT_CHARPOS (*it
) > BEGV
3966 /* If selective > 0, then lines indented more than that values
3968 if (it
->selective
> 0
3969 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3970 (double) it
->selective
)) /* iftc */
3976 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3977 Qinvisible
, it
->window
);
3978 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3982 /* Back one more newline if the current one is invisible. */
3984 back_to_previous_line_start (it
);
3987 xassert (IT_CHARPOS (*it
) >= BEGV
);
3988 xassert (IT_CHARPOS (*it
) == BEGV
3989 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3994 /* Reseat iterator IT at the previous visible line start. Skip
3995 invisible text that is so either due to text properties or due to
3996 selective display. At the end, update IT's overlay information,
3997 face information etc. */
4000 reseat_at_previous_visible_line_start (it
)
4003 back_to_previous_visible_line_start (it
);
4004 reseat (it
, it
->current
.pos
, 1);
4009 /* Reseat iterator IT on the next visible line start in the current
4010 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4011 preceding the line start. Skip over invisible text that is so
4012 because of selective display. Compute faces, overlays etc at the
4013 new position. Note that this function does not skip over text that
4014 is invisible because of text properties. */
4017 reseat_at_next_visible_line_start (it
, on_newline_p
)
4021 int newline_found_p
, skipped_p
= 0;
4023 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4025 /* Skip over lines that are invisible because they are indented
4026 more than the value of IT->selective. */
4027 if (it
->selective
> 0)
4028 while (IT_CHARPOS (*it
) < ZV
4029 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4030 (double) it
->selective
)) /* iftc */
4032 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4033 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4036 /* Position on the newline if that's what's requested. */
4037 if (on_newline_p
&& newline_found_p
)
4039 if (STRINGP (it
->string
))
4041 if (IT_STRING_CHARPOS (*it
) > 0)
4043 --IT_STRING_CHARPOS (*it
);
4044 --IT_STRING_BYTEPOS (*it
);
4047 else if (IT_CHARPOS (*it
) > BEGV
)
4051 reseat (it
, it
->current
.pos
, 0);
4055 reseat (it
, it
->current
.pos
, 0);
4062 /***********************************************************************
4063 Changing an iterator's position
4064 ***********************************************************************/
4066 /* Change IT's current position to POS in current_buffer. If FORCE_P
4067 is non-zero, always check for text properties at the new position.
4068 Otherwise, text properties are only looked up if POS >=
4069 IT->check_charpos of a property. */
4072 reseat (it
, pos
, force_p
)
4074 struct text_pos pos
;
4077 int original_pos
= IT_CHARPOS (*it
);
4079 reseat_1 (it
, pos
, 0);
4081 /* Determine where to check text properties. Avoid doing it
4082 where possible because text property lookup is very expensive. */
4084 || CHARPOS (pos
) > it
->stop_charpos
4085 || CHARPOS (pos
) < original_pos
)
4092 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4093 IT->stop_pos to POS, also. */
4096 reseat_1 (it
, pos
, set_stop_p
)
4098 struct text_pos pos
;
4101 /* Don't call this function when scanning a C string. */
4102 xassert (it
->s
== NULL
);
4104 /* POS must be a reasonable value. */
4105 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4107 it
->current
.pos
= it
->position
= pos
;
4108 XSETBUFFER (it
->object
, current_buffer
);
4109 it
->end_charpos
= ZV
;
4111 it
->current
.dpvec_index
= -1;
4112 it
->current
.overlay_string_index
= -1;
4113 IT_STRING_CHARPOS (*it
) = -1;
4114 IT_STRING_BYTEPOS (*it
) = -1;
4116 it
->method
= next_element_from_buffer
;
4117 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4119 it
->face_before_selective_p
= 0;
4122 it
->stop_charpos
= CHARPOS (pos
);
4126 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4127 If S is non-null, it is a C string to iterate over. Otherwise,
4128 STRING gives a Lisp string to iterate over.
4130 If PRECISION > 0, don't return more then PRECISION number of
4131 characters from the string.
4133 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4134 characters have been returned. FIELD_WIDTH < 0 means an infinite
4137 MULTIBYTE = 0 means disable processing of multibyte characters,
4138 MULTIBYTE > 0 means enable it,
4139 MULTIBYTE < 0 means use IT->multibyte_p.
4141 IT must be initialized via a prior call to init_iterator before
4142 calling this function. */
4145 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4150 int precision
, field_width
, multibyte
;
4152 /* No region in strings. */
4153 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4155 /* No text property checks performed by default, but see below. */
4156 it
->stop_charpos
= -1;
4158 /* Set iterator position and end position. */
4159 bzero (&it
->current
, sizeof it
->current
);
4160 it
->current
.overlay_string_index
= -1;
4161 it
->current
.dpvec_index
= -1;
4162 xassert (charpos
>= 0);
4164 /* If STRING is specified, use its multibyteness, otherwise use the
4165 setting of MULTIBYTE, if specified. */
4167 it
->multibyte_p
= multibyte
> 0;
4171 xassert (STRINGP (string
));
4172 it
->string
= string
;
4174 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4175 it
->method
= next_element_from_string
;
4176 it
->current
.string_pos
= string_pos (charpos
, string
);
4183 /* Note that we use IT->current.pos, not it->current.string_pos,
4184 for displaying C strings. */
4185 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4186 if (it
->multibyte_p
)
4188 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4189 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4193 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4194 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4197 it
->method
= next_element_from_c_string
;
4200 /* PRECISION > 0 means don't return more than PRECISION characters
4202 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4203 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4205 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4206 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4207 FIELD_WIDTH < 0 means infinite field width. This is useful for
4208 padding with `-' at the end of a mode line. */
4209 if (field_width
< 0)
4210 field_width
= INFINITY
;
4211 if (field_width
> it
->end_charpos
- charpos
)
4212 it
->end_charpos
= charpos
+ field_width
;
4214 /* Use the standard display table for displaying strings. */
4215 if (DISP_TABLE_P (Vstandard_display_table
))
4216 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4218 it
->stop_charpos
= charpos
;
4224 /***********************************************************************
4226 ***********************************************************************/
4228 /* Load IT's display element fields with information about the next
4229 display element from the current position of IT. Value is zero if
4230 end of buffer (or C string) is reached. */
4233 get_next_display_element (it
)
4236 /* Non-zero means that we found a display element. Zero means that
4237 we hit the end of what we iterate over. Performance note: the
4238 function pointer `method' used here turns out to be faster than
4239 using a sequence of if-statements. */
4240 int success_p
= (*it
->method
) (it
);
4242 if (it
->what
== IT_CHARACTER
)
4244 /* Map via display table or translate control characters.
4245 IT->c, IT->len etc. have been set to the next character by
4246 the function call above. If we have a display table, and it
4247 contains an entry for IT->c, translate it. Don't do this if
4248 IT->c itself comes from a display table, otherwise we could
4249 end up in an infinite recursion. (An alternative could be to
4250 count the recursion depth of this function and signal an
4251 error when a certain maximum depth is reached.) Is it worth
4253 if (success_p
&& it
->dpvec
== NULL
)
4258 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4261 struct Lisp_Vector
*v
= XVECTOR (dv
);
4263 /* Return the first character from the display table
4264 entry, if not empty. If empty, don't display the
4265 current character. */
4268 it
->dpvec_char_len
= it
->len
;
4269 it
->dpvec
= v
->contents
;
4270 it
->dpend
= v
->contents
+ v
->size
;
4271 it
->current
.dpvec_index
= 0;
4272 it
->method
= next_element_from_display_vector
;
4273 success_p
= get_next_display_element (it
);
4277 set_iterator_to_next (it
, 0);
4278 success_p
= get_next_display_element (it
);
4282 /* Translate control characters into `\003' or `^C' form.
4283 Control characters coming from a display table entry are
4284 currently not translated because we use IT->dpvec to hold
4285 the translation. This could easily be changed but I
4286 don't believe that it is worth doing.
4288 If it->multibyte_p is nonzero, eight-bit characters and
4289 non-printable multibyte characters are also translated to
4292 If it->multibyte_p is zero, eight-bit characters that
4293 don't have corresponding multibyte char code are also
4294 translated to octal form. */
4295 else if ((it
->c
< ' '
4296 && (it
->area
!= TEXT_AREA
4297 || (it
->c
!= '\n' && it
->c
!= '\t')))
4301 || !CHAR_PRINTABLE_P (it
->c
))
4303 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4305 /* IT->c is a control character which must be displayed
4306 either as '\003' or as `^C' where the '\\' and '^'
4307 can be defined in the display table. Fill
4308 IT->ctl_chars with glyphs for what we have to
4309 display. Then, set IT->dpvec to these glyphs. */
4312 if (it
->c
< 128 && it
->ctl_arrow_p
)
4314 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4316 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4317 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4318 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4320 g
= FAST_MAKE_GLYPH ('^', 0);
4321 XSETINT (it
->ctl_chars
[0], g
);
4323 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4324 XSETINT (it
->ctl_chars
[1], g
);
4326 /* Set up IT->dpvec and return first character from it. */
4327 it
->dpvec_char_len
= it
->len
;
4328 it
->dpvec
= it
->ctl_chars
;
4329 it
->dpend
= it
->dpvec
+ 2;
4330 it
->current
.dpvec_index
= 0;
4331 it
->method
= next_element_from_display_vector
;
4332 get_next_display_element (it
);
4336 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4341 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4343 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4344 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4345 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4347 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4349 if (SINGLE_BYTE_CHAR_P (it
->c
))
4350 str
[0] = it
->c
, len
= 1;
4353 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4356 /* It's an invalid character, which
4357 shouldn't happen actually, but due to
4358 bugs it may happen. Let's print the char
4359 as is, there's not much meaningful we can
4362 str
[1] = it
->c
>> 8;
4363 str
[2] = it
->c
>> 16;
4364 str
[3] = it
->c
>> 24;
4369 for (i
= 0; i
< len
; i
++)
4371 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4372 /* Insert three more glyphs into IT->ctl_chars for
4373 the octal display of the character. */
4374 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4375 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4376 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4377 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4378 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4379 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4382 /* Set up IT->dpvec and return the first character
4384 it
->dpvec_char_len
= it
->len
;
4385 it
->dpvec
= it
->ctl_chars
;
4386 it
->dpend
= it
->dpvec
+ len
* 4;
4387 it
->current
.dpvec_index
= 0;
4388 it
->method
= next_element_from_display_vector
;
4389 get_next_display_element (it
);
4394 /* Adjust face id for a multibyte character. There are no
4395 multibyte character in unibyte text. */
4398 && FRAME_WINDOW_P (it
->f
))
4400 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4401 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4405 /* Is this character the last one of a run of characters with
4406 box? If yes, set IT->end_of_box_run_p to 1. */
4413 it
->end_of_box_run_p
4414 = ((face_id
= face_after_it_pos (it
),
4415 face_id
!= it
->face_id
)
4416 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4417 face
->box
== FACE_NO_BOX
));
4420 /* Value is 0 if end of buffer or string reached. */
4425 /* Move IT to the next display element.
4427 RESEAT_P non-zero means if called on a newline in buffer text,
4428 skip to the next visible line start.
4430 Functions get_next_display_element and set_iterator_to_next are
4431 separate because I find this arrangement easier to handle than a
4432 get_next_display_element function that also increments IT's
4433 position. The way it is we can first look at an iterator's current
4434 display element, decide whether it fits on a line, and if it does,
4435 increment the iterator position. The other way around we probably
4436 would either need a flag indicating whether the iterator has to be
4437 incremented the next time, or we would have to implement a
4438 decrement position function which would not be easy to write. */
4441 set_iterator_to_next (it
, reseat_p
)
4445 /* Reset flags indicating start and end of a sequence of characters
4446 with box. Reset them at the start of this function because
4447 moving the iterator to a new position might set them. */
4448 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4450 if (it
->method
== next_element_from_buffer
)
4452 /* The current display element of IT is a character from
4453 current_buffer. Advance in the buffer, and maybe skip over
4454 invisible lines that are so because of selective display. */
4455 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4456 reseat_at_next_visible_line_start (it
, 0);
4459 xassert (it
->len
!= 0);
4460 IT_BYTEPOS (*it
) += it
->len
;
4461 IT_CHARPOS (*it
) += 1;
4462 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4465 else if (it
->method
== next_element_from_composition
)
4467 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4468 if (STRINGP (it
->string
))
4470 IT_STRING_BYTEPOS (*it
) += it
->len
;
4471 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4472 it
->method
= next_element_from_string
;
4473 goto consider_string_end
;
4477 IT_BYTEPOS (*it
) += it
->len
;
4478 IT_CHARPOS (*it
) += it
->cmp_len
;
4479 it
->method
= next_element_from_buffer
;
4482 else if (it
->method
== next_element_from_c_string
)
4484 /* Current display element of IT is from a C string. */
4485 IT_BYTEPOS (*it
) += it
->len
;
4486 IT_CHARPOS (*it
) += 1;
4488 else if (it
->method
== next_element_from_display_vector
)
4490 /* Current display element of IT is from a display table entry.
4491 Advance in the display table definition. Reset it to null if
4492 end reached, and continue with characters from buffers/
4494 ++it
->current
.dpvec_index
;
4496 /* Restore face of the iterator to what they were before the
4497 display vector entry (these entries may contain faces). */
4498 it
->face_id
= it
->saved_face_id
;
4500 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4503 it
->method
= next_element_from_c_string
;
4504 else if (STRINGP (it
->string
))
4505 it
->method
= next_element_from_string
;
4507 it
->method
= next_element_from_buffer
;
4510 it
->current
.dpvec_index
= -1;
4512 /* Skip over characters which were displayed via IT->dpvec. */
4513 if (it
->dpvec_char_len
< 0)
4514 reseat_at_next_visible_line_start (it
, 1);
4515 else if (it
->dpvec_char_len
> 0)
4517 it
->len
= it
->dpvec_char_len
;
4518 set_iterator_to_next (it
, reseat_p
);
4522 else if (it
->method
== next_element_from_string
)
4524 /* Current display element is a character from a Lisp string. */
4525 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4526 IT_STRING_BYTEPOS (*it
) += it
->len
;
4527 IT_STRING_CHARPOS (*it
) += 1;
4529 consider_string_end
:
4531 if (it
->current
.overlay_string_index
>= 0)
4533 /* IT->string is an overlay string. Advance to the
4534 next, if there is one. */
4535 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4536 next_overlay_string (it
);
4540 /* IT->string is not an overlay string. If we reached
4541 its end, and there is something on IT->stack, proceed
4542 with what is on the stack. This can be either another
4543 string, this time an overlay string, or a buffer. */
4544 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
4548 if (!STRINGP (it
->string
))
4549 it
->method
= next_element_from_buffer
;
4551 goto consider_string_end
;
4555 else if (it
->method
== next_element_from_image
4556 || it
->method
== next_element_from_stretch
)
4558 /* The position etc with which we have to proceed are on
4559 the stack. The position may be at the end of a string,
4560 if the `display' property takes up the whole string. */
4563 if (STRINGP (it
->string
))
4565 it
->method
= next_element_from_string
;
4566 goto consider_string_end
;
4569 it
->method
= next_element_from_buffer
;
4572 /* There are no other methods defined, so this should be a bug. */
4575 xassert (it
->method
!= next_element_from_string
4576 || (STRINGP (it
->string
)
4577 && IT_STRING_CHARPOS (*it
) >= 0));
4581 /* Load IT's display element fields with information about the next
4582 display element which comes from a display table entry or from the
4583 result of translating a control character to one of the forms `^C'
4584 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4587 next_element_from_display_vector (it
)
4591 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4593 /* Remember the current face id in case glyphs specify faces.
4594 IT's face is restored in set_iterator_to_next. */
4595 it
->saved_face_id
= it
->face_id
;
4597 if (INTEGERP (*it
->dpvec
)
4598 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4603 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4604 it
->c
= FAST_GLYPH_CHAR (g
);
4605 it
->len
= CHAR_BYTES (it
->c
);
4607 /* The entry may contain a face id to use. Such a face id is
4608 the id of a Lisp face, not a realized face. A face id of
4609 zero means no face is specified. */
4610 lface_id
= FAST_GLYPH_FACE (g
);
4613 /* The function returns -1 if lface_id is invalid. */
4614 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4616 it
->face_id
= face_id
;
4620 /* Display table entry is invalid. Return a space. */
4621 it
->c
= ' ', it
->len
= 1;
4623 /* Don't change position and object of the iterator here. They are
4624 still the values of the character that had this display table
4625 entry or was translated, and that's what we want. */
4626 it
->what
= IT_CHARACTER
;
4631 /* Load IT with the next display element from Lisp string IT->string.
4632 IT->current.string_pos is the current position within the string.
4633 If IT->current.overlay_string_index >= 0, the Lisp string is an
4637 next_element_from_string (it
)
4640 struct text_pos position
;
4642 xassert (STRINGP (it
->string
));
4643 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4644 position
= it
->current
.string_pos
;
4646 /* Time to check for invisible text? */
4647 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4648 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4652 /* Since a handler may have changed IT->method, we must
4654 return get_next_display_element (it
);
4657 if (it
->current
.overlay_string_index
>= 0)
4659 /* Get the next character from an overlay string. In overlay
4660 strings, There is no field width or padding with spaces to
4662 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4667 else if (STRING_MULTIBYTE (it
->string
))
4669 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4670 const unsigned char *s
= (SDATA (it
->string
)
4671 + IT_STRING_BYTEPOS (*it
));
4672 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4676 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4682 /* Get the next character from a Lisp string that is not an
4683 overlay string. Such strings come from the mode line, for
4684 example. We may have to pad with spaces, or truncate the
4685 string. See also next_element_from_c_string. */
4686 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4691 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4693 /* Pad with spaces. */
4694 it
->c
= ' ', it
->len
= 1;
4695 CHARPOS (position
) = BYTEPOS (position
) = -1;
4697 else if (STRING_MULTIBYTE (it
->string
))
4699 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4700 const unsigned char *s
= (SDATA (it
->string
)
4701 + IT_STRING_BYTEPOS (*it
));
4702 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4706 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4711 /* Record what we have and where it came from. Note that we store a
4712 buffer position in IT->position although it could arguably be a
4714 it
->what
= IT_CHARACTER
;
4715 it
->object
= it
->string
;
4716 it
->position
= position
;
4721 /* Load IT with next display element from C string IT->s.
4722 IT->string_nchars is the maximum number of characters to return
4723 from the string. IT->end_charpos may be greater than
4724 IT->string_nchars when this function is called, in which case we
4725 may have to return padding spaces. Value is zero if end of string
4726 reached, including padding spaces. */
4729 next_element_from_c_string (it
)
4735 it
->what
= IT_CHARACTER
;
4736 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4739 /* IT's position can be greater IT->string_nchars in case a field
4740 width or precision has been specified when the iterator was
4742 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4744 /* End of the game. */
4748 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4750 /* Pad with spaces. */
4751 it
->c
= ' ', it
->len
= 1;
4752 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4754 else if (it
->multibyte_p
)
4756 /* Implementation note: The calls to strlen apparently aren't a
4757 performance problem because there is no noticeable performance
4758 difference between Emacs running in unibyte or multibyte mode. */
4759 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4760 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4764 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4770 /* Set up IT to return characters from an ellipsis, if appropriate.
4771 The definition of the ellipsis glyphs may come from a display table
4772 entry. This function Fills IT with the first glyph from the
4773 ellipsis if an ellipsis is to be displayed. */
4776 next_element_from_ellipsis (it
)
4779 if (it
->selective_display_ellipsis_p
)
4781 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4783 /* Use the display table definition for `...'. Invalid glyphs
4784 will be handled by the method returning elements from dpvec. */
4785 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4786 it
->dpvec_char_len
= it
->len
;
4787 it
->dpvec
= v
->contents
;
4788 it
->dpend
= v
->contents
+ v
->size
;
4789 it
->current
.dpvec_index
= 0;
4790 it
->method
= next_element_from_display_vector
;
4794 /* Use default `...' which is stored in default_invis_vector. */
4795 it
->dpvec_char_len
= it
->len
;
4796 it
->dpvec
= default_invis_vector
;
4797 it
->dpend
= default_invis_vector
+ 3;
4798 it
->current
.dpvec_index
= 0;
4799 it
->method
= next_element_from_display_vector
;
4804 /* The face at the current position may be different from the
4805 face we find after the invisible text. Remember what it
4806 was in IT->saved_face_id, and signal that it's there by
4807 setting face_before_selective_p. */
4808 it
->saved_face_id
= it
->face_id
;
4809 it
->method
= next_element_from_buffer
;
4810 reseat_at_next_visible_line_start (it
, 1);
4811 it
->face_before_selective_p
= 1;
4814 return get_next_display_element (it
);
4818 /* Deliver an image display element. The iterator IT is already
4819 filled with image information (done in handle_display_prop). Value
4824 next_element_from_image (it
)
4827 it
->what
= IT_IMAGE
;
4832 /* Fill iterator IT with next display element from a stretch glyph
4833 property. IT->object is the value of the text property. Value is
4837 next_element_from_stretch (it
)
4840 it
->what
= IT_STRETCH
;
4845 /* Load IT with the next display element from current_buffer. Value
4846 is zero if end of buffer reached. IT->stop_charpos is the next
4847 position at which to stop and check for text properties or buffer
4851 next_element_from_buffer (it
)
4856 /* Check this assumption, otherwise, we would never enter the
4857 if-statement, below. */
4858 xassert (IT_CHARPOS (*it
) >= BEGV
4859 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4861 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4863 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4865 int overlay_strings_follow_p
;
4867 /* End of the game, except when overlay strings follow that
4868 haven't been returned yet. */
4869 if (it
->overlay_strings_at_end_processed_p
)
4870 overlay_strings_follow_p
= 0;
4873 it
->overlay_strings_at_end_processed_p
= 1;
4874 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4877 if (overlay_strings_follow_p
)
4878 success_p
= get_next_display_element (it
);
4882 it
->position
= it
->current
.pos
;
4889 return get_next_display_element (it
);
4894 /* No face changes, overlays etc. in sight, so just return a
4895 character from current_buffer. */
4898 /* Maybe run the redisplay end trigger hook. Performance note:
4899 This doesn't seem to cost measurable time. */
4900 if (it
->redisplay_end_trigger_charpos
4902 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4903 run_redisplay_end_trigger_hook (it
);
4905 /* Get the next character, maybe multibyte. */
4906 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4907 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4909 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4910 - IT_BYTEPOS (*it
));
4911 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4914 it
->c
= *p
, it
->len
= 1;
4916 /* Record what we have and where it came from. */
4917 it
->what
= IT_CHARACTER
;;
4918 it
->object
= it
->w
->buffer
;
4919 it
->position
= it
->current
.pos
;
4921 /* Normally we return the character found above, except when we
4922 really want to return an ellipsis for selective display. */
4927 /* A value of selective > 0 means hide lines indented more
4928 than that number of columns. */
4929 if (it
->selective
> 0
4930 && IT_CHARPOS (*it
) + 1 < ZV
4931 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4932 IT_BYTEPOS (*it
) + 1,
4933 (double) it
->selective
)) /* iftc */
4935 success_p
= next_element_from_ellipsis (it
);
4936 it
->dpvec_char_len
= -1;
4939 else if (it
->c
== '\r' && it
->selective
== -1)
4941 /* A value of selective == -1 means that everything from the
4942 CR to the end of the line is invisible, with maybe an
4943 ellipsis displayed for it. */
4944 success_p
= next_element_from_ellipsis (it
);
4945 it
->dpvec_char_len
= -1;
4950 /* Value is zero if end of buffer reached. */
4951 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4956 /* Run the redisplay end trigger hook for IT. */
4959 run_redisplay_end_trigger_hook (it
)
4962 Lisp_Object args
[3];
4964 /* IT->glyph_row should be non-null, i.e. we should be actually
4965 displaying something, or otherwise we should not run the hook. */
4966 xassert (it
->glyph_row
);
4968 /* Set up hook arguments. */
4969 args
[0] = Qredisplay_end_trigger_functions
;
4970 args
[1] = it
->window
;
4971 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4972 it
->redisplay_end_trigger_charpos
= 0;
4974 /* Since we are *trying* to run these functions, don't try to run
4975 them again, even if they get an error. */
4976 it
->w
->redisplay_end_trigger
= Qnil
;
4977 Frun_hook_with_args (3, args
);
4979 /* Notice if it changed the face of the character we are on. */
4980 handle_face_prop (it
);
4984 /* Deliver a composition display element. The iterator IT is already
4985 filled with composition information (done in
4986 handle_composition_prop). Value is always 1. */
4989 next_element_from_composition (it
)
4992 it
->what
= IT_COMPOSITION
;
4993 it
->position
= (STRINGP (it
->string
)
4994 ? it
->current
.string_pos
5001 /***********************************************************************
5002 Moving an iterator without producing glyphs
5003 ***********************************************************************/
5005 /* Move iterator IT to a specified buffer or X position within one
5006 line on the display without producing glyphs.
5008 OP should be a bit mask including some or all of these bits:
5009 MOVE_TO_X: Stop on reaching x-position TO_X.
5010 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5011 Regardless of OP's value, stop in reaching the end of the display line.
5013 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5014 This means, in particular, that TO_X includes window's horizontal
5017 The return value has several possible values that
5018 say what condition caused the scan to stop:
5020 MOVE_POS_MATCH_OR_ZV
5021 - when TO_POS or ZV was reached.
5024 -when TO_X was reached before TO_POS or ZV were reached.
5027 - when we reached the end of the display area and the line must
5031 - when we reached the end of the display area and the line is
5035 - when we stopped at a line end, i.e. a newline or a CR and selective
5038 static enum move_it_result
5039 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5041 int to_charpos
, to_x
, op
;
5043 enum move_it_result result
= MOVE_UNDEFINED
;
5044 struct glyph_row
*saved_glyph_row
;
5046 /* Don't produce glyphs in produce_glyphs. */
5047 saved_glyph_row
= it
->glyph_row
;
5048 it
->glyph_row
= NULL
;
5052 int x
, i
, ascent
= 0, descent
= 0;
5054 /* Stop when ZV or TO_CHARPOS reached. */
5055 if (!get_next_display_element (it
)
5056 || ((op
& MOVE_TO_POS
) != 0
5057 && BUFFERP (it
->object
)
5058 && IT_CHARPOS (*it
) >= to_charpos
))
5060 result
= MOVE_POS_MATCH_OR_ZV
;
5064 /* The call to produce_glyphs will get the metrics of the
5065 display element IT is loaded with. We record in x the
5066 x-position before this display element in case it does not
5070 /* Remember the line height so far in case the next element doesn't
5072 if (!it
->truncate_lines_p
)
5074 ascent
= it
->max_ascent
;
5075 descent
= it
->max_descent
;
5078 PRODUCE_GLYPHS (it
);
5080 if (it
->area
!= TEXT_AREA
)
5082 set_iterator_to_next (it
, 1);
5086 /* The number of glyphs we get back in IT->nglyphs will normally
5087 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5088 character on a terminal frame, or (iii) a line end. For the
5089 second case, IT->nglyphs - 1 padding glyphs will be present
5090 (on X frames, there is only one glyph produced for a
5091 composite character.
5093 The behavior implemented below means, for continuation lines,
5094 that as many spaces of a TAB as fit on the current line are
5095 displayed there. For terminal frames, as many glyphs of a
5096 multi-glyph character are displayed in the current line, too.
5097 This is what the old redisplay code did, and we keep it that
5098 way. Under X, the whole shape of a complex character must
5099 fit on the line or it will be completely displayed in the
5102 Note that both for tabs and padding glyphs, all glyphs have
5106 /* More than one glyph or glyph doesn't fit on line. All
5107 glyphs have the same width. */
5108 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5111 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5113 new_x
= x
+ single_glyph_width
;
5115 /* We want to leave anything reaching TO_X to the caller. */
5116 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5119 result
= MOVE_X_REACHED
;
5122 else if (/* Lines are continued. */
5123 !it
->truncate_lines_p
5124 && (/* And glyph doesn't fit on the line. */
5125 new_x
> it
->last_visible_x
5126 /* Or it fits exactly and we're on a window
5128 || (new_x
== it
->last_visible_x
5129 && FRAME_WINDOW_P (it
->f
))))
5131 if (/* IT->hpos == 0 means the very first glyph
5132 doesn't fit on the line, e.g. a wide image. */
5134 || (new_x
== it
->last_visible_x
5135 && FRAME_WINDOW_P (it
->f
)))
5138 it
->current_x
= new_x
;
5139 if (i
== it
->nglyphs
- 1)
5140 set_iterator_to_next (it
, 1);
5145 it
->max_ascent
= ascent
;
5146 it
->max_descent
= descent
;
5149 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5151 result
= MOVE_LINE_CONTINUED
;
5154 else if (new_x
> it
->first_visible_x
)
5156 /* Glyph is visible. Increment number of glyphs that
5157 would be displayed. */
5162 /* Glyph is completely off the left margin of the display
5163 area. Nothing to do. */
5167 if (result
!= MOVE_UNDEFINED
)
5170 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5172 /* Stop when TO_X specified and reached. This check is
5173 necessary here because of lines consisting of a line end,
5174 only. The line end will not produce any glyphs and we
5175 would never get MOVE_X_REACHED. */
5176 xassert (it
->nglyphs
== 0);
5177 result
= MOVE_X_REACHED
;
5181 /* Is this a line end? If yes, we're done. */
5182 if (ITERATOR_AT_END_OF_LINE_P (it
))
5184 result
= MOVE_NEWLINE_OR_CR
;
5188 /* The current display element has been consumed. Advance
5190 set_iterator_to_next (it
, 1);
5192 /* Stop if lines are truncated and IT's current x-position is
5193 past the right edge of the window now. */
5194 if (it
->truncate_lines_p
5195 && it
->current_x
>= it
->last_visible_x
)
5197 result
= MOVE_LINE_TRUNCATED
;
5202 /* Restore the iterator settings altered at the beginning of this
5204 it
->glyph_row
= saved_glyph_row
;
5209 /* Move IT forward until it satisfies one or more of the criteria in
5210 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5212 OP is a bit-mask that specifies where to stop, and in particular,
5213 which of those four position arguments makes a difference. See the
5214 description of enum move_operation_enum.
5216 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5217 screen line, this function will set IT to the next position >
5221 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5223 int to_charpos
, to_x
, to_y
, to_vpos
;
5226 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5232 if (op
& MOVE_TO_VPOS
)
5234 /* If no TO_CHARPOS and no TO_X specified, stop at the
5235 start of the line TO_VPOS. */
5236 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5238 if (it
->vpos
== to_vpos
)
5244 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5248 /* TO_VPOS >= 0 means stop at TO_X in the line at
5249 TO_VPOS, or at TO_POS, whichever comes first. */
5250 if (it
->vpos
== to_vpos
)
5256 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5258 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5263 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5265 /* We have reached TO_X but not in the line we want. */
5266 skip
= move_it_in_display_line_to (it
, to_charpos
,
5268 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5276 else if (op
& MOVE_TO_Y
)
5278 struct it it_backup
;
5280 /* TO_Y specified means stop at TO_X in the line containing
5281 TO_Y---or at TO_CHARPOS if this is reached first. The
5282 problem is that we can't really tell whether the line
5283 contains TO_Y before we have completely scanned it, and
5284 this may skip past TO_X. What we do is to first scan to
5287 If TO_X is not specified, use a TO_X of zero. The reason
5288 is to make the outcome of this function more predictable.
5289 If we didn't use TO_X == 0, we would stop at the end of
5290 the line which is probably not what a caller would expect
5292 skip
= move_it_in_display_line_to (it
, to_charpos
,
5296 | (op
& MOVE_TO_POS
)));
5298 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5299 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5305 /* If TO_X was reached, we would like to know whether TO_Y
5306 is in the line. This can only be said if we know the
5307 total line height which requires us to scan the rest of
5309 if (skip
== MOVE_X_REACHED
)
5312 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5313 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5315 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5318 /* Now, decide whether TO_Y is in this line. */
5319 line_height
= it
->max_ascent
+ it
->max_descent
;
5320 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5322 if (to_y
>= it
->current_y
5323 && to_y
< it
->current_y
+ line_height
)
5325 if (skip
== MOVE_X_REACHED
)
5326 /* If TO_Y is in this line and TO_X was reached above,
5327 we scanned too far. We have to restore IT's settings
5328 to the ones before skipping. */
5332 else if (skip
== MOVE_X_REACHED
)
5335 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5343 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5347 case MOVE_POS_MATCH_OR_ZV
:
5351 case MOVE_NEWLINE_OR_CR
:
5352 set_iterator_to_next (it
, 1);
5353 it
->continuation_lines_width
= 0;
5356 case MOVE_LINE_TRUNCATED
:
5357 it
->continuation_lines_width
= 0;
5358 reseat_at_next_visible_line_start (it
, 0);
5359 if ((op
& MOVE_TO_POS
) != 0
5360 && IT_CHARPOS (*it
) > to_charpos
)
5367 case MOVE_LINE_CONTINUED
:
5368 it
->continuation_lines_width
+= it
->current_x
;
5375 /* Reset/increment for the next run. */
5376 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5377 it
->current_x
= it
->hpos
= 0;
5378 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5380 last_height
= it
->max_ascent
+ it
->max_descent
;
5381 last_max_ascent
= it
->max_ascent
;
5382 it
->max_ascent
= it
->max_descent
= 0;
5387 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5391 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5393 If DY > 0, move IT backward at least that many pixels. DY = 0
5394 means move IT backward to the preceding line start or BEGV. This
5395 function may move over more than DY pixels if IT->current_y - DY
5396 ends up in the middle of a line; in this case IT->current_y will be
5397 set to the top of the line moved to. */
5400 move_it_vertically_backward (it
, dy
)
5406 int start_pos
= IT_CHARPOS (*it
);
5410 /* Estimate how many newlines we must move back. */
5411 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5413 /* Set the iterator's position that many lines back. */
5414 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5415 back_to_previous_visible_line_start (it
);
5417 /* Reseat the iterator here. When moving backward, we don't want
5418 reseat to skip forward over invisible text, set up the iterator
5419 to deliver from overlay strings at the new position etc. So,
5420 use reseat_1 here. */
5421 reseat_1 (it
, it
->current
.pos
, 1);
5423 /* We are now surely at a line start. */
5424 it
->current_x
= it
->hpos
= 0;
5425 it
->continuation_lines_width
= 0;
5427 /* Move forward and see what y-distance we moved. First move to the
5428 start of the next line so that we get its height. We need this
5429 height to be able to tell whether we reached the specified
5432 it2
.max_ascent
= it2
.max_descent
= 0;
5433 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5434 MOVE_TO_POS
| MOVE_TO_VPOS
);
5435 xassert (IT_CHARPOS (*it
) >= BEGV
);
5438 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5439 xassert (IT_CHARPOS (*it
) >= BEGV
);
5440 h
= it2
.current_y
- it
->current_y
;
5441 nlines
= it2
.vpos
- it
->vpos
;
5443 /* Correct IT's y and vpos position. */
5449 /* DY == 0 means move to the start of the screen line. The
5450 value of nlines is > 0 if continuation lines were involved. */
5452 move_it_by_lines (it
, nlines
, 1);
5453 xassert (IT_CHARPOS (*it
) <= start_pos
);
5457 /* The y-position we try to reach. Note that h has been
5458 subtracted in front of the if-statement. */
5459 int target_y
= it
->current_y
+ h
- dy
;
5460 int y0
= it3
.current_y
;
5461 int y1
= line_bottom_y (&it3
);
5462 int line_height
= y1
- y0
;
5464 /* If we did not reach target_y, try to move further backward if
5465 we can. If we moved too far backward, try to move forward. */
5466 if (target_y
< it
->current_y
5467 /* This is heuristic. In a window that's 3 lines high, with
5468 a line height of 13 pixels each, recentering with point
5469 on the bottom line will try to move -39/2 = 19 pixels
5470 backward. Try to avoid moving into the first line. */
5471 && it
->current_y
- target_y
> line_height
/ 3 * 2
5472 && IT_CHARPOS (*it
) > BEGV
)
5474 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5475 target_y
- it
->current_y
));
5476 move_it_vertically (it
, target_y
- it
->current_y
);
5477 xassert (IT_CHARPOS (*it
) >= BEGV
);
5479 else if (target_y
>= it
->current_y
+ line_height
5480 && IT_CHARPOS (*it
) < ZV
)
5482 /* Should move forward by at least one line, maybe more.
5484 Note: Calling move_it_by_lines can be expensive on
5485 terminal frames, where compute_motion is used (via
5486 vmotion) to do the job, when there are very long lines
5487 and truncate-lines is nil. That's the reason for
5488 treating terminal frames specially here. */
5490 if (!FRAME_WINDOW_P (it
->f
))
5491 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5496 move_it_by_lines (it
, 1, 1);
5498 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5501 xassert (IT_CHARPOS (*it
) >= BEGV
);
5507 /* Move IT by a specified amount of pixel lines DY. DY negative means
5508 move backwards. DY = 0 means move to start of screen line. At the
5509 end, IT will be on the start of a screen line. */
5512 move_it_vertically (it
, dy
)
5517 move_it_vertically_backward (it
, -dy
);
5520 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5521 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5522 MOVE_TO_POS
| MOVE_TO_Y
);
5523 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5525 /* If buffer ends in ZV without a newline, move to the start of
5526 the line to satisfy the post-condition. */
5527 if (IT_CHARPOS (*it
) == ZV
5528 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5529 move_it_by_lines (it
, 0, 0);
5534 /* Move iterator IT past the end of the text line it is in. */
5537 move_it_past_eol (it
)
5540 enum move_it_result rc
;
5542 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5543 if (rc
== MOVE_NEWLINE_OR_CR
)
5544 set_iterator_to_next (it
, 0);
5548 #if 0 /* Currently not used. */
5550 /* Return non-zero if some text between buffer positions START_CHARPOS
5551 and END_CHARPOS is invisible. IT->window is the window for text
5555 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5557 int start_charpos
, end_charpos
;
5559 Lisp_Object prop
, limit
;
5560 int invisible_found_p
;
5562 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5564 /* Is text at START invisible? */
5565 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5567 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5568 invisible_found_p
= 1;
5571 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5573 make_number (end_charpos
));
5574 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5577 return invisible_found_p
;
5583 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5584 negative means move up. DVPOS == 0 means move to the start of the
5585 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5586 NEED_Y_P is zero, IT->current_y will be left unchanged.
5588 Further optimization ideas: If we would know that IT->f doesn't use
5589 a face with proportional font, we could be faster for
5590 truncate-lines nil. */
5593 move_it_by_lines (it
, dvpos
, need_y_p
)
5595 int dvpos
, need_y_p
;
5597 struct position pos
;
5599 if (!FRAME_WINDOW_P (it
->f
))
5601 struct text_pos textpos
;
5603 /* We can use vmotion on frames without proportional fonts. */
5604 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5605 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5606 reseat (it
, textpos
, 1);
5607 it
->vpos
+= pos
.vpos
;
5608 it
->current_y
+= pos
.vpos
;
5610 else if (dvpos
== 0)
5612 /* DVPOS == 0 means move to the start of the screen line. */
5613 move_it_vertically_backward (it
, 0);
5614 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5617 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5621 int start_charpos
, i
;
5623 /* Start at the beginning of the screen line containing IT's
5625 move_it_vertically_backward (it
, 0);
5627 /* Go back -DVPOS visible lines and reseat the iterator there. */
5628 start_charpos
= IT_CHARPOS (*it
);
5629 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5630 back_to_previous_visible_line_start (it
);
5631 reseat (it
, it
->current
.pos
, 1);
5632 it
->current_x
= it
->hpos
= 0;
5634 /* Above call may have moved too far if continuation lines
5635 are involved. Scan forward and see if it did. */
5637 it2
.vpos
= it2
.current_y
= 0;
5638 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5639 it
->vpos
-= it2
.vpos
;
5640 it
->current_y
-= it2
.current_y
;
5641 it
->current_x
= it
->hpos
= 0;
5643 /* If we moved too far, move IT some lines forward. */
5644 if (it2
.vpos
> -dvpos
)
5646 int delta
= it2
.vpos
+ dvpos
;
5647 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5654 /***********************************************************************
5656 ***********************************************************************/
5659 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5663 add_to_log (format
, arg1
, arg2
)
5665 Lisp_Object arg1
, arg2
;
5667 Lisp_Object args
[3];
5668 Lisp_Object msg
, fmt
;
5671 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5673 /* Do nothing if called asynchronously. Inserting text into
5674 a buffer may call after-change-functions and alike and
5675 that would means running Lisp asynchronously. */
5676 if (handling_signal
)
5680 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5682 args
[0] = fmt
= build_string (format
);
5685 msg
= Fformat (3, args
);
5687 len
= SBYTES (msg
) + 1;
5688 buffer
= (char *) alloca (len
);
5689 bcopy (SDATA (msg
), buffer
, len
);
5691 message_dolog (buffer
, len
- 1, 1, 0);
5696 /* Output a newline in the *Messages* buffer if "needs" one. */
5699 message_log_maybe_newline ()
5701 if (message_log_need_newline
)
5702 message_dolog ("", 0, 1, 0);
5706 /* Add a string M of length NBYTES to the message log, optionally
5707 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5708 nonzero, means interpret the contents of M as multibyte. This
5709 function calls low-level routines in order to bypass text property
5710 hooks, etc. which might not be safe to run. */
5713 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5715 int nbytes
, nlflag
, multibyte
;
5717 if (!NILP (Vmemory_full
))
5720 if (!NILP (Vmessage_log_max
))
5722 struct buffer
*oldbuf
;
5723 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5724 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5725 int point_at_end
= 0;
5727 Lisp_Object old_deactivate_mark
, tem
;
5728 struct gcpro gcpro1
;
5730 old_deactivate_mark
= Vdeactivate_mark
;
5731 oldbuf
= current_buffer
;
5732 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5733 current_buffer
->undo_list
= Qt
;
5735 oldpoint
= message_dolog_marker1
;
5736 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
5737 oldbegv
= message_dolog_marker2
;
5738 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
5739 oldzv
= message_dolog_marker3
;
5740 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
5741 GCPRO1 (old_deactivate_mark
);
5749 BEGV_BYTE
= BEG_BYTE
;
5752 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5754 /* Insert the string--maybe converting multibyte to single byte
5755 or vice versa, so that all the text fits the buffer. */
5757 && NILP (current_buffer
->enable_multibyte_characters
))
5759 int i
, c
, char_bytes
;
5760 unsigned char work
[1];
5762 /* Convert a multibyte string to single-byte
5763 for the *Message* buffer. */
5764 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
5766 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5767 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5769 : multibyte_char_to_unibyte (c
, Qnil
));
5770 insert_1_both (work
, 1, 1, 1, 0, 0);
5773 else if (! multibyte
5774 && ! NILP (current_buffer
->enable_multibyte_characters
))
5776 int i
, c
, char_bytes
;
5777 unsigned char *msg
= (unsigned char *) m
;
5778 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5779 /* Convert a single-byte string to multibyte
5780 for the *Message* buffer. */
5781 for (i
= 0; i
< nbytes
; i
++)
5783 c
= unibyte_char_to_multibyte (msg
[i
]);
5784 char_bytes
= CHAR_STRING (c
, str
);
5785 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5789 insert_1 (m
, nbytes
, 1, 0, 0);
5793 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5794 insert_1 ("\n", 1, 1, 0, 0);
5796 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5798 this_bol_byte
= PT_BYTE
;
5800 /* See if this line duplicates the previous one.
5801 If so, combine duplicates. */
5804 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5806 prev_bol_byte
= PT_BYTE
;
5808 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5809 this_bol
, this_bol_byte
);
5812 del_range_both (prev_bol
, prev_bol_byte
,
5813 this_bol
, this_bol_byte
, 0);
5819 /* If you change this format, don't forget to also
5820 change message_log_check_duplicate. */
5821 sprintf (dupstr
, " [%d times]", dup
);
5822 duplen
= strlen (dupstr
);
5823 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5824 insert_1 (dupstr
, duplen
, 1, 0, 1);
5829 /* If we have more than the desired maximum number of lines
5830 in the *Messages* buffer now, delete the oldest ones.
5831 This is safe because we don't have undo in this buffer. */
5833 if (NATNUMP (Vmessage_log_max
))
5835 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5836 -XFASTINT (Vmessage_log_max
) - 1, 0);
5837 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5840 BEGV
= XMARKER (oldbegv
)->charpos
;
5841 BEGV_BYTE
= marker_byte_position (oldbegv
);
5850 ZV
= XMARKER (oldzv
)->charpos
;
5851 ZV_BYTE
= marker_byte_position (oldzv
);
5855 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5857 /* We can't do Fgoto_char (oldpoint) because it will run some
5859 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5860 XMARKER (oldpoint
)->bytepos
);
5863 unchain_marker (oldpoint
);
5864 unchain_marker (oldbegv
);
5865 unchain_marker (oldzv
);
5867 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5868 set_buffer_internal (oldbuf
);
5870 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5871 message_log_need_newline
= !nlflag
;
5872 Vdeactivate_mark
= old_deactivate_mark
;
5877 /* We are at the end of the buffer after just having inserted a newline.
5878 (Note: We depend on the fact we won't be crossing the gap.)
5879 Check to see if the most recent message looks a lot like the previous one.
5880 Return 0 if different, 1 if the new one should just replace it, or a
5881 value N > 1 if we should also append " [N times]". */
5884 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5885 int prev_bol
, this_bol
;
5886 int prev_bol_byte
, this_bol_byte
;
5889 int len
= Z_BYTE
- 1 - this_bol_byte
;
5891 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5892 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5894 for (i
= 0; i
< len
; i
++)
5896 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5904 if (*p1
++ == ' ' && *p1
++ == '[')
5907 while (*p1
>= '0' && *p1
<= '9')
5908 n
= n
* 10 + *p1
++ - '0';
5909 if (strncmp (p1
, " times]\n", 8) == 0)
5916 /* Display an echo area message M with a specified length of NBYTES
5917 bytes. The string may include null characters. If M is 0, clear
5918 out any existing message, and let the mini-buffer text show
5921 The buffer M must continue to exist until after the echo area gets
5922 cleared or some other message gets displayed there. This means do
5923 not pass text that is stored in a Lisp string; do not pass text in
5924 a buffer that was alloca'd. */
5927 message2 (m
, nbytes
, multibyte
)
5932 /* First flush out any partial line written with print. */
5933 message_log_maybe_newline ();
5935 message_dolog (m
, nbytes
, 1, multibyte
);
5936 message2_nolog (m
, nbytes
, multibyte
);
5940 /* The non-logging counterpart of message2. */
5943 message2_nolog (m
, nbytes
, multibyte
)
5945 int nbytes
, multibyte
;
5947 struct frame
*sf
= SELECTED_FRAME ();
5948 message_enable_multibyte
= multibyte
;
5952 if (noninteractive_need_newline
)
5953 putc ('\n', stderr
);
5954 noninteractive_need_newline
= 0;
5956 fwrite (m
, nbytes
, 1, stderr
);
5957 if (cursor_in_echo_area
== 0)
5958 fprintf (stderr
, "\n");
5961 /* A null message buffer means that the frame hasn't really been
5962 initialized yet. Error messages get reported properly by
5963 cmd_error, so this must be just an informative message; toss it. */
5964 else if (INTERACTIVE
5965 && sf
->glyphs_initialized_p
5966 && FRAME_MESSAGE_BUF (sf
))
5968 Lisp_Object mini_window
;
5971 /* Get the frame containing the mini-buffer
5972 that the selected frame is using. */
5973 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5974 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5976 FRAME_SAMPLE_VISIBILITY (f
);
5977 if (FRAME_VISIBLE_P (sf
)
5978 && ! FRAME_VISIBLE_P (f
))
5979 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5983 set_message (m
, Qnil
, nbytes
, multibyte
);
5984 if (minibuffer_auto_raise
)
5985 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5988 clear_message (1, 1);
5990 do_pending_window_change (0);
5991 echo_area_display (1);
5992 do_pending_window_change (0);
5993 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5994 (*frame_up_to_date_hook
) (f
);
5999 /* Display an echo area message M with a specified length of NBYTES
6000 bytes. The string may include null characters. If M is not a
6001 string, clear out any existing message, and let the mini-buffer
6002 text show through. */
6005 message3 (m
, nbytes
, multibyte
)
6010 struct gcpro gcpro1
;
6014 /* First flush out any partial line written with print. */
6015 message_log_maybe_newline ();
6017 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6018 message3_nolog (m
, nbytes
, multibyte
);
6024 /* The non-logging version of message3. */
6027 message3_nolog (m
, nbytes
, multibyte
)
6029 int nbytes
, multibyte
;
6031 struct frame
*sf
= SELECTED_FRAME ();
6032 message_enable_multibyte
= multibyte
;
6036 if (noninteractive_need_newline
)
6037 putc ('\n', stderr
);
6038 noninteractive_need_newline
= 0;
6040 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6041 if (cursor_in_echo_area
== 0)
6042 fprintf (stderr
, "\n");
6045 /* A null message buffer means that the frame hasn't really been
6046 initialized yet. Error messages get reported properly by
6047 cmd_error, so this must be just an informative message; toss it. */
6048 else if (INTERACTIVE
6049 && sf
->glyphs_initialized_p
6050 && FRAME_MESSAGE_BUF (sf
))
6052 Lisp_Object mini_window
;
6056 /* Get the frame containing the mini-buffer
6057 that the selected frame is using. */
6058 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6059 frame
= XWINDOW (mini_window
)->frame
;
6062 FRAME_SAMPLE_VISIBILITY (f
);
6063 if (FRAME_VISIBLE_P (sf
)
6064 && !FRAME_VISIBLE_P (f
))
6065 Fmake_frame_visible (frame
);
6067 if (STRINGP (m
) && SCHARS (m
) > 0)
6069 set_message (NULL
, m
, nbytes
, multibyte
);
6070 if (minibuffer_auto_raise
)
6071 Fraise_frame (frame
);
6074 clear_message (1, 1);
6076 do_pending_window_change (0);
6077 echo_area_display (1);
6078 do_pending_window_change (0);
6079 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6080 (*frame_up_to_date_hook
) (f
);
6085 /* Display a null-terminated echo area message M. If M is 0, clear
6086 out any existing message, and let the mini-buffer text show through.
6088 The buffer M must continue to exist until after the echo area gets
6089 cleared or some other message gets displayed there. Do not pass
6090 text that is stored in a Lisp string. Do not pass text in a buffer
6091 that was alloca'd. */
6097 message2 (m
, (m
? strlen (m
) : 0), 0);
6101 /* The non-logging counterpart of message1. */
6107 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6110 /* Display a message M which contains a single %s
6111 which gets replaced with STRING. */
6114 message_with_string (m
, string
, log
)
6119 CHECK_STRING (string
);
6125 if (noninteractive_need_newline
)
6126 putc ('\n', stderr
);
6127 noninteractive_need_newline
= 0;
6128 fprintf (stderr
, m
, SDATA (string
));
6129 if (cursor_in_echo_area
== 0)
6130 fprintf (stderr
, "\n");
6134 else if (INTERACTIVE
)
6136 /* The frame whose minibuffer we're going to display the message on.
6137 It may be larger than the selected frame, so we need
6138 to use its buffer, not the selected frame's buffer. */
6139 Lisp_Object mini_window
;
6140 struct frame
*f
, *sf
= SELECTED_FRAME ();
6142 /* Get the frame containing the minibuffer
6143 that the selected frame is using. */
6144 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6145 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6147 /* A null message buffer means that the frame hasn't really been
6148 initialized yet. Error messages get reported properly by
6149 cmd_error, so this must be just an informative message; toss it. */
6150 if (FRAME_MESSAGE_BUF (f
))
6152 Lisp_Object args
[2], message
;
6153 struct gcpro gcpro1
, gcpro2
;
6155 args
[0] = build_string (m
);
6156 args
[1] = message
= string
;
6157 GCPRO2 (args
[0], message
);
6160 message
= Fformat (2, args
);
6163 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6165 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6169 /* Print should start at the beginning of the message
6170 buffer next time. */
6171 message_buf_print
= 0;
6177 /* Dump an informative message to the minibuf. If M is 0, clear out
6178 any existing message, and let the mini-buffer text show through. */
6182 message (m
, a1
, a2
, a3
)
6184 EMACS_INT a1
, a2
, a3
;
6190 if (noninteractive_need_newline
)
6191 putc ('\n', stderr
);
6192 noninteractive_need_newline
= 0;
6193 fprintf (stderr
, m
, a1
, a2
, a3
);
6194 if (cursor_in_echo_area
== 0)
6195 fprintf (stderr
, "\n");
6199 else if (INTERACTIVE
)
6201 /* The frame whose mini-buffer we're going to display the message
6202 on. It may be larger than the selected frame, so we need to
6203 use its buffer, not the selected frame's buffer. */
6204 Lisp_Object mini_window
;
6205 struct frame
*f
, *sf
= SELECTED_FRAME ();
6207 /* Get the frame containing the mini-buffer
6208 that the selected frame is using. */
6209 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6210 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6212 /* A null message buffer means that the frame hasn't really been
6213 initialized yet. Error messages get reported properly by
6214 cmd_error, so this must be just an informative message; toss
6216 if (FRAME_MESSAGE_BUF (f
))
6227 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6228 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6230 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6231 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6233 #endif /* NO_ARG_ARRAY */
6235 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6240 /* Print should start at the beginning of the message
6241 buffer next time. */
6242 message_buf_print
= 0;
6248 /* The non-logging version of message. */
6251 message_nolog (m
, a1
, a2
, a3
)
6253 EMACS_INT a1
, a2
, a3
;
6255 Lisp_Object old_log_max
;
6256 old_log_max
= Vmessage_log_max
;
6257 Vmessage_log_max
= Qnil
;
6258 message (m
, a1
, a2
, a3
);
6259 Vmessage_log_max
= old_log_max
;
6263 /* Display the current message in the current mini-buffer. This is
6264 only called from error handlers in process.c, and is not time
6270 if (!NILP (echo_area_buffer
[0]))
6273 string
= Fcurrent_message ();
6274 message3 (string
, SBYTES (string
),
6275 !NILP (current_buffer
->enable_multibyte_characters
));
6280 /* Make sure echo area buffers in `echo_buffers' are live.
6281 If they aren't, make new ones. */
6284 ensure_echo_area_buffers ()
6288 for (i
= 0; i
< 2; ++i
)
6289 if (!BUFFERP (echo_buffer
[i
])
6290 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6293 Lisp_Object old_buffer
;
6296 old_buffer
= echo_buffer
[i
];
6297 sprintf (name
, " *Echo Area %d*", i
);
6298 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6299 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6301 for (j
= 0; j
< 2; ++j
)
6302 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6303 echo_area_buffer
[j
] = echo_buffer
[i
];
6308 /* Call FN with args A1..A4 with either the current or last displayed
6309 echo_area_buffer as current buffer.
6311 WHICH zero means use the current message buffer
6312 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6313 from echo_buffer[] and clear it.
6315 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6316 suitable buffer from echo_buffer[] and clear it.
6318 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6319 that the current message becomes the last displayed one, make
6320 choose a suitable buffer for echo_area_buffer[0], and clear it.
6322 Value is what FN returns. */
6325 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6328 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6334 int this_one
, the_other
, clear_buffer_p
, rc
;
6335 int count
= SPECPDL_INDEX ();
6337 /* If buffers aren't live, make new ones. */
6338 ensure_echo_area_buffers ();
6343 this_one
= 0, the_other
= 1;
6345 this_one
= 1, the_other
= 0;
6348 this_one
= 0, the_other
= 1;
6351 /* We need a fresh one in case the current echo buffer equals
6352 the one containing the last displayed echo area message. */
6353 if (!NILP (echo_area_buffer
[this_one
])
6354 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6355 echo_area_buffer
[this_one
] = Qnil
;
6358 /* Choose a suitable buffer from echo_buffer[] is we don't
6360 if (NILP (echo_area_buffer
[this_one
]))
6362 echo_area_buffer
[this_one
]
6363 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6364 ? echo_buffer
[the_other
]
6365 : echo_buffer
[this_one
]);
6369 buffer
= echo_area_buffer
[this_one
];
6371 /* Don't get confused by reusing the buffer used for echoing
6372 for a different purpose. */
6373 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6376 record_unwind_protect (unwind_with_echo_area_buffer
,
6377 with_echo_area_buffer_unwind_data (w
));
6379 /* Make the echo area buffer current. Note that for display
6380 purposes, it is not necessary that the displayed window's buffer
6381 == current_buffer, except for text property lookup. So, let's
6382 only set that buffer temporarily here without doing a full
6383 Fset_window_buffer. We must also change w->pointm, though,
6384 because otherwise an assertions in unshow_buffer fails, and Emacs
6386 set_buffer_internal_1 (XBUFFER (buffer
));
6390 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6393 current_buffer
->undo_list
= Qt
;
6394 current_buffer
->read_only
= Qnil
;
6395 specbind (Qinhibit_read_only
, Qt
);
6396 specbind (Qinhibit_modification_hooks
, Qt
);
6398 if (clear_buffer_p
&& Z
> BEG
)
6401 xassert (BEGV
>= BEG
);
6402 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6404 rc
= fn (a1
, a2
, a3
, a4
);
6406 xassert (BEGV
>= BEG
);
6407 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6409 unbind_to (count
, Qnil
);
6414 /* Save state that should be preserved around the call to the function
6415 FN called in with_echo_area_buffer. */
6418 with_echo_area_buffer_unwind_data (w
)
6424 /* Reduce consing by keeping one vector in
6425 Vwith_echo_area_save_vector. */
6426 vector
= Vwith_echo_area_save_vector
;
6427 Vwith_echo_area_save_vector
= Qnil
;
6430 vector
= Fmake_vector (make_number (7), Qnil
);
6432 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6433 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6434 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6438 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6439 AREF (vector
, i
) = w
->buffer
; ++i
;
6440 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6441 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6446 for (; i
< end
; ++i
)
6447 AREF (vector
, i
) = Qnil
;
6450 xassert (i
== ASIZE (vector
));
6455 /* Restore global state from VECTOR which was created by
6456 with_echo_area_buffer_unwind_data. */
6459 unwind_with_echo_area_buffer (vector
)
6462 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6463 Vdeactivate_mark
= AREF (vector
, 1);
6464 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6466 if (WINDOWP (AREF (vector
, 3)))
6469 Lisp_Object buffer
, charpos
, bytepos
;
6471 w
= XWINDOW (AREF (vector
, 3));
6472 buffer
= AREF (vector
, 4);
6473 charpos
= AREF (vector
, 5);
6474 bytepos
= AREF (vector
, 6);
6477 set_marker_both (w
->pointm
, buffer
,
6478 XFASTINT (charpos
), XFASTINT (bytepos
));
6481 Vwith_echo_area_save_vector
= vector
;
6486 /* Set up the echo area for use by print functions. MULTIBYTE_P
6487 non-zero means we will print multibyte. */
6490 setup_echo_area_for_printing (multibyte_p
)
6493 /* If we can't find an echo area any more, exit. */
6494 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
6497 ensure_echo_area_buffers ();
6499 if (!message_buf_print
)
6501 /* A message has been output since the last time we printed.
6502 Choose a fresh echo area buffer. */
6503 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6504 echo_area_buffer
[0] = echo_buffer
[1];
6506 echo_area_buffer
[0] = echo_buffer
[0];
6508 /* Switch to that buffer and clear it. */
6509 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6510 current_buffer
->truncate_lines
= Qnil
;
6514 int count
= SPECPDL_INDEX ();
6515 specbind (Qinhibit_read_only
, Qt
);
6516 /* Note that undo recording is always disabled. */
6518 unbind_to (count
, Qnil
);
6520 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6522 /* Set up the buffer for the multibyteness we need. */
6524 != !NILP (current_buffer
->enable_multibyte_characters
))
6525 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6527 /* Raise the frame containing the echo area. */
6528 if (minibuffer_auto_raise
)
6530 struct frame
*sf
= SELECTED_FRAME ();
6531 Lisp_Object mini_window
;
6532 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6533 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6536 message_log_maybe_newline ();
6537 message_buf_print
= 1;
6541 if (NILP (echo_area_buffer
[0]))
6543 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6544 echo_area_buffer
[0] = echo_buffer
[1];
6546 echo_area_buffer
[0] = echo_buffer
[0];
6549 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6551 /* Someone switched buffers between print requests. */
6552 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6553 current_buffer
->truncate_lines
= Qnil
;
6559 /* Display an echo area message in window W. Value is non-zero if W's
6560 height is changed. If display_last_displayed_message_p is
6561 non-zero, display the message that was last displayed, otherwise
6562 display the current message. */
6565 display_echo_area (w
)
6568 int i
, no_message_p
, window_height_changed_p
, count
;
6570 /* Temporarily disable garbage collections while displaying the echo
6571 area. This is done because a GC can print a message itself.
6572 That message would modify the echo area buffer's contents while a
6573 redisplay of the buffer is going on, and seriously confuse
6575 count
= inhibit_garbage_collection ();
6577 /* If there is no message, we must call display_echo_area_1
6578 nevertheless because it resizes the window. But we will have to
6579 reset the echo_area_buffer in question to nil at the end because
6580 with_echo_area_buffer will sets it to an empty buffer. */
6581 i
= display_last_displayed_message_p
? 1 : 0;
6582 no_message_p
= NILP (echo_area_buffer
[i
]);
6584 window_height_changed_p
6585 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6586 display_echo_area_1
,
6587 (EMACS_INT
) w
, Qnil
, 0, 0);
6590 echo_area_buffer
[i
] = Qnil
;
6592 unbind_to (count
, Qnil
);
6593 return window_height_changed_p
;
6597 /* Helper for display_echo_area. Display the current buffer which
6598 contains the current echo area message in window W, a mini-window,
6599 a pointer to which is passed in A1. A2..A4 are currently not used.
6600 Change the height of W so that all of the message is displayed.
6601 Value is non-zero if height of W was changed. */
6604 display_echo_area_1 (a1
, a2
, a3
, a4
)
6609 struct window
*w
= (struct window
*) a1
;
6611 struct text_pos start
;
6612 int window_height_changed_p
= 0;
6614 /* Do this before displaying, so that we have a large enough glyph
6615 matrix for the display. */
6616 window_height_changed_p
= resize_mini_window (w
, 0);
6619 clear_glyph_matrix (w
->desired_matrix
);
6620 XSETWINDOW (window
, w
);
6621 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6622 try_window (window
, start
);
6624 return window_height_changed_p
;
6628 /* Resize the echo area window to exactly the size needed for the
6629 currently displayed message, if there is one. If a mini-buffer
6630 is active, don't shrink it. */
6633 resize_echo_area_exactly ()
6635 if (BUFFERP (echo_area_buffer
[0])
6636 && WINDOWP (echo_area_window
))
6638 struct window
*w
= XWINDOW (echo_area_window
);
6640 Lisp_Object resize_exactly
;
6642 if (minibuf_level
== 0)
6643 resize_exactly
= Qt
;
6645 resize_exactly
= Qnil
;
6647 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6648 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6651 ++windows_or_buffers_changed
;
6652 ++update_mode_lines
;
6653 redisplay_internal (0);
6659 /* Callback function for with_echo_area_buffer, when used from
6660 resize_echo_area_exactly. A1 contains a pointer to the window to
6661 resize, EXACTLY non-nil means resize the mini-window exactly to the
6662 size of the text displayed. A3 and A4 are not used. Value is what
6663 resize_mini_window returns. */
6666 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6668 Lisp_Object exactly
;
6671 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6675 /* Resize mini-window W to fit the size of its contents. EXACT:P
6676 means size the window exactly to the size needed. Otherwise, it's
6677 only enlarged until W's buffer is empty. Value is non-zero if
6678 the window height has been changed. */
6681 resize_mini_window (w
, exact_p
)
6685 struct frame
*f
= XFRAME (w
->frame
);
6686 int window_height_changed_p
= 0;
6688 xassert (MINI_WINDOW_P (w
));
6690 /* Don't resize windows while redisplaying a window; it would
6691 confuse redisplay functions when the size of the window they are
6692 displaying changes from under them. Such a resizing can happen,
6693 for instance, when which-func prints a long message while
6694 we are running fontification-functions. We're running these
6695 functions with safe_call which binds inhibit-redisplay to t. */
6696 if (!NILP (Vinhibit_redisplay
))
6699 /* Nil means don't try to resize. */
6700 if (NILP (Vresize_mini_windows
)
6701 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6704 if (!FRAME_MINIBUF_ONLY_P (f
))
6707 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6708 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6709 int height
, max_height
;
6710 int unit
= CANON_Y_UNIT (f
);
6711 struct text_pos start
;
6712 struct buffer
*old_current_buffer
= NULL
;
6714 if (current_buffer
!= XBUFFER (w
->buffer
))
6716 old_current_buffer
= current_buffer
;
6717 set_buffer_internal (XBUFFER (w
->buffer
));
6720 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6722 /* Compute the max. number of lines specified by the user. */
6723 if (FLOATP (Vmax_mini_window_height
))
6724 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6725 else if (INTEGERP (Vmax_mini_window_height
))
6726 max_height
= XINT (Vmax_mini_window_height
);
6728 max_height
= total_height
/ 4;
6730 /* Correct that max. height if it's bogus. */
6731 max_height
= max (1, max_height
);
6732 max_height
= min (total_height
, max_height
);
6734 /* Find out the height of the text in the window. */
6735 if (it
.truncate_lines_p
)
6740 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6741 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6742 height
= it
.current_y
+ last_height
;
6744 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6745 height
-= it
.extra_line_spacing
;
6746 height
= (height
+ unit
- 1) / unit
;
6749 /* Compute a suitable window start. */
6750 if (height
> max_height
)
6752 height
= max_height
;
6753 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6754 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6755 start
= it
.current
.pos
;
6758 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6759 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6761 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6763 /* Let it grow only, until we display an empty message, in which
6764 case the window shrinks again. */
6765 if (height
> XFASTINT (w
->height
))
6767 int old_height
= XFASTINT (w
->height
);
6768 freeze_window_starts (f
, 1);
6769 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6770 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6772 else if (height
< XFASTINT (w
->height
)
6773 && (exact_p
|| BEGV
== ZV
))
6775 int old_height
= XFASTINT (w
->height
);
6776 freeze_window_starts (f
, 0);
6777 shrink_mini_window (w
);
6778 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6783 /* Always resize to exact size needed. */
6784 if (height
> XFASTINT (w
->height
))
6786 int old_height
= XFASTINT (w
->height
);
6787 freeze_window_starts (f
, 1);
6788 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6789 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6791 else if (height
< XFASTINT (w
->height
))
6793 int old_height
= XFASTINT (w
->height
);
6794 freeze_window_starts (f
, 0);
6795 shrink_mini_window (w
);
6799 freeze_window_starts (f
, 1);
6800 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6803 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6807 if (old_current_buffer
)
6808 set_buffer_internal (old_current_buffer
);
6811 return window_height_changed_p
;
6815 /* Value is the current message, a string, or nil if there is no
6823 if (NILP (echo_area_buffer
[0]))
6827 with_echo_area_buffer (0, 0, current_message_1
,
6828 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6830 echo_area_buffer
[0] = Qnil
;
6838 current_message_1 (a1
, a2
, a3
, a4
)
6843 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6846 *msg
= make_buffer_string (BEG
, Z
, 1);
6853 /* Push the current message on Vmessage_stack for later restauration
6854 by restore_message. Value is non-zero if the current message isn't
6855 empty. This is a relatively infrequent operation, so it's not
6856 worth optimizing. */
6862 msg
= current_message ();
6863 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6864 return STRINGP (msg
);
6868 /* Restore message display from the top of Vmessage_stack. */
6875 xassert (CONSP (Vmessage_stack
));
6876 msg
= XCAR (Vmessage_stack
);
6878 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
6880 message3_nolog (msg
, 0, 0);
6884 /* Handler for record_unwind_protect calling pop_message. */
6887 pop_message_unwind (dummy
)
6894 /* Pop the top-most entry off Vmessage_stack. */
6899 xassert (CONSP (Vmessage_stack
));
6900 Vmessage_stack
= XCDR (Vmessage_stack
);
6904 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6905 exits. If the stack is not empty, we have a missing pop_message
6909 check_message_stack ()
6911 if (!NILP (Vmessage_stack
))
6916 /* Truncate to NCHARS what will be displayed in the echo area the next
6917 time we display it---but don't redisplay it now. */
6920 truncate_echo_area (nchars
)
6924 echo_area_buffer
[0] = Qnil
;
6925 /* A null message buffer means that the frame hasn't really been
6926 initialized yet. Error messages get reported properly by
6927 cmd_error, so this must be just an informative message; toss it. */
6928 else if (!noninteractive
6930 && !NILP (echo_area_buffer
[0]))
6932 struct frame
*sf
= SELECTED_FRAME ();
6933 if (FRAME_MESSAGE_BUF (sf
))
6934 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6939 /* Helper function for truncate_echo_area. Truncate the current
6940 message to at most NCHARS characters. */
6943 truncate_message_1 (nchars
, a2
, a3
, a4
)
6948 if (BEG
+ nchars
< Z
)
6949 del_range (BEG
+ nchars
, Z
);
6951 echo_area_buffer
[0] = Qnil
;
6956 /* Set the current message to a substring of S or STRING.
6958 If STRING is a Lisp string, set the message to the first NBYTES
6959 bytes from STRING. NBYTES zero means use the whole string. If
6960 STRING is multibyte, the message will be displayed multibyte.
6962 If S is not null, set the message to the first LEN bytes of S. LEN
6963 zero means use the whole string. MULTIBYTE_P non-zero means S is
6964 multibyte. Display the message multibyte in that case. */
6967 set_message (s
, string
, nbytes
, multibyte_p
)
6970 int nbytes
, multibyte_p
;
6972 message_enable_multibyte
6973 = ((s
&& multibyte_p
)
6974 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6976 with_echo_area_buffer (0, -1, set_message_1
,
6977 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6978 message_buf_print
= 0;
6979 help_echo_showing_p
= 0;
6983 /* Helper function for set_message. Arguments have the same meaning
6984 as there, with A1 corresponding to S and A2 corresponding to STRING
6985 This function is called with the echo area buffer being
6989 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6992 EMACS_INT nbytes
, multibyte_p
;
6994 const char *s
= (const char *) a1
;
6995 Lisp_Object string
= a2
;
6999 /* Change multibyteness of the echo buffer appropriately. */
7000 if (message_enable_multibyte
7001 != !NILP (current_buffer
->enable_multibyte_characters
))
7002 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7004 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7006 /* Insert new message at BEG. */
7007 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7009 if (STRINGP (string
))
7014 nbytes
= SBYTES (string
);
7015 nchars
= string_byte_to_char (string
, nbytes
);
7017 /* This function takes care of single/multibyte conversion. We
7018 just have to ensure that the echo area buffer has the right
7019 setting of enable_multibyte_characters. */
7020 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7025 nbytes
= strlen (s
);
7027 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7029 /* Convert from multi-byte to single-byte. */
7031 unsigned char work
[1];
7033 /* Convert a multibyte string to single-byte. */
7034 for (i
= 0; i
< nbytes
; i
+= n
)
7036 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7037 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7039 : multibyte_char_to_unibyte (c
, Qnil
));
7040 insert_1_both (work
, 1, 1, 1, 0, 0);
7043 else if (!multibyte_p
7044 && !NILP (current_buffer
->enable_multibyte_characters
))
7046 /* Convert from single-byte to multi-byte. */
7048 const unsigned char *msg
= (const unsigned char *) s
;
7049 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7051 /* Convert a single-byte string to multibyte. */
7052 for (i
= 0; i
< nbytes
; i
++)
7054 c
= unibyte_char_to_multibyte (msg
[i
]);
7055 n
= CHAR_STRING (c
, str
);
7056 insert_1_both (str
, 1, n
, 1, 0, 0);
7060 insert_1 (s
, nbytes
, 1, 0, 0);
7067 /* Clear messages. CURRENT_P non-zero means clear the current
7068 message. LAST_DISPLAYED_P non-zero means clear the message
7072 clear_message (current_p
, last_displayed_p
)
7073 int current_p
, last_displayed_p
;
7077 echo_area_buffer
[0] = Qnil
;
7078 message_cleared_p
= 1;
7081 if (last_displayed_p
)
7082 echo_area_buffer
[1] = Qnil
;
7084 message_buf_print
= 0;
7087 /* Clear garbaged frames.
7089 This function is used where the old redisplay called
7090 redraw_garbaged_frames which in turn called redraw_frame which in
7091 turn called clear_frame. The call to clear_frame was a source of
7092 flickering. I believe a clear_frame is not necessary. It should
7093 suffice in the new redisplay to invalidate all current matrices,
7094 and ensure a complete redisplay of all windows. */
7097 clear_garbaged_frames ()
7101 Lisp_Object tail
, frame
;
7102 int changed_count
= 0;
7104 FOR_EACH_FRAME (tail
, frame
)
7106 struct frame
*f
= XFRAME (frame
);
7108 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7111 Fredraw_frame (frame
);
7112 clear_current_matrices (f
);
7121 ++windows_or_buffers_changed
;
7126 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7127 is non-zero update selected_frame. Value is non-zero if the
7128 mini-windows height has been changed. */
7131 echo_area_display (update_frame_p
)
7134 Lisp_Object mini_window
;
7137 int window_height_changed_p
= 0;
7138 struct frame
*sf
= SELECTED_FRAME ();
7140 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7141 w
= XWINDOW (mini_window
);
7142 f
= XFRAME (WINDOW_FRAME (w
));
7144 /* Don't display if frame is invisible or not yet initialized. */
7145 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7148 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7150 #ifdef HAVE_WINDOW_SYSTEM
7151 /* When Emacs starts, selected_frame may be a visible terminal
7152 frame, even if we run under a window system. If we let this
7153 through, a message would be displayed on the terminal. */
7154 if (EQ (selected_frame
, Vterminal_frame
)
7155 && !NILP (Vwindow_system
))
7157 #endif /* HAVE_WINDOW_SYSTEM */
7160 /* Redraw garbaged frames. */
7162 clear_garbaged_frames ();
7164 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7166 echo_area_window
= mini_window
;
7167 window_height_changed_p
= display_echo_area (w
);
7168 w
->must_be_updated_p
= 1;
7170 /* Update the display, unless called from redisplay_internal.
7171 Also don't update the screen during redisplay itself. The
7172 update will happen at the end of redisplay, and an update
7173 here could cause confusion. */
7174 if (update_frame_p
&& !redisplaying_p
)
7178 /* If the display update has been interrupted by pending
7179 input, update mode lines in the frame. Due to the
7180 pending input, it might have been that redisplay hasn't
7181 been called, so that mode lines above the echo area are
7182 garbaged. This looks odd, so we prevent it here. */
7183 if (!display_completed
)
7184 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7186 if (window_height_changed_p
7187 /* Don't do this if Emacs is shutting down. Redisplay
7188 needs to run hooks. */
7189 && !NILP (Vrun_hooks
))
7191 /* Must update other windows. Likewise as in other
7192 cases, don't let this update be interrupted by
7194 int count
= SPECPDL_INDEX ();
7195 specbind (Qredisplay_dont_pause
, Qt
);
7196 windows_or_buffers_changed
= 1;
7197 redisplay_internal (0);
7198 unbind_to (count
, Qnil
);
7200 else if (FRAME_WINDOW_P (f
) && n
== 0)
7202 /* Window configuration is the same as before.
7203 Can do with a display update of the echo area,
7204 unless we displayed some mode lines. */
7205 update_single_window (w
, 1);
7206 rif
->flush_display (f
);
7209 update_frame (f
, 1, 1);
7211 /* If cursor is in the echo area, make sure that the next
7212 redisplay displays the minibuffer, so that the cursor will
7213 be replaced with what the minibuffer wants. */
7214 if (cursor_in_echo_area
)
7215 ++windows_or_buffers_changed
;
7218 else if (!EQ (mini_window
, selected_window
))
7219 windows_or_buffers_changed
++;
7221 /* Last displayed message is now the current message. */
7222 echo_area_buffer
[1] = echo_area_buffer
[0];
7224 /* Prevent redisplay optimization in redisplay_internal by resetting
7225 this_line_start_pos. This is done because the mini-buffer now
7226 displays the message instead of its buffer text. */
7227 if (EQ (mini_window
, selected_window
))
7228 CHARPOS (this_line_start_pos
) = 0;
7230 return window_height_changed_p
;
7235 /***********************************************************************
7237 ***********************************************************************/
7240 /* The frame title buffering code is also used by Fformat_mode_line.
7241 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7243 /* A buffer for constructing frame titles in it; allocated from the
7244 heap in init_xdisp and resized as needed in store_frame_title_char. */
7246 static char *frame_title_buf
;
7248 /* The buffer's end, and a current output position in it. */
7250 static char *frame_title_buf_end
;
7251 static char *frame_title_ptr
;
7254 /* Store a single character C for the frame title in frame_title_buf.
7255 Re-allocate frame_title_buf if necessary. */
7259 store_frame_title_char (char c
)
7261 store_frame_title_char (c
)
7265 /* If output position has reached the end of the allocated buffer,
7266 double the buffer's size. */
7267 if (frame_title_ptr
== frame_title_buf_end
)
7269 int len
= frame_title_ptr
- frame_title_buf
;
7270 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7271 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7272 frame_title_buf_end
= frame_title_buf
+ new_size
;
7273 frame_title_ptr
= frame_title_buf
+ len
;
7276 *frame_title_ptr
++ = c
;
7280 /* Store part of a frame title in frame_title_buf, beginning at
7281 frame_title_ptr. STR is the string to store. Do not copy
7282 characters that yield more columns than PRECISION; PRECISION <= 0
7283 means copy the whole string. Pad with spaces until FIELD_WIDTH
7284 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7285 pad. Called from display_mode_element when it is used to build a
7289 store_frame_title (str
, field_width
, precision
)
7290 const unsigned char *str
;
7291 int field_width
, precision
;
7296 /* Copy at most PRECISION chars from STR. */
7297 nbytes
= strlen (str
);
7298 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7300 store_frame_title_char (*str
++);
7302 /* Fill up with spaces until FIELD_WIDTH reached. */
7303 while (field_width
> 0
7306 store_frame_title_char (' ');
7313 #ifdef HAVE_WINDOW_SYSTEM
7315 /* Set the title of FRAME, if it has changed. The title format is
7316 Vicon_title_format if FRAME is iconified, otherwise it is
7317 frame_title_format. */
7320 x_consider_frame_title (frame
)
7323 struct frame
*f
= XFRAME (frame
);
7325 if (FRAME_WINDOW_P (f
)
7326 || FRAME_MINIBUF_ONLY_P (f
)
7327 || f
->explicit_name
)
7329 /* Do we have more than one visible frame on this X display? */
7332 struct buffer
*obuf
;
7336 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7338 Lisp_Object other_frame
= XCAR (tail
);
7339 struct frame
*tf
= XFRAME (other_frame
);
7342 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7343 && !FRAME_MINIBUF_ONLY_P (tf
)
7344 && !EQ (other_frame
, tip_frame
)
7345 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7349 /* Set global variable indicating that multiple frames exist. */
7350 multiple_frames
= CONSP (tail
);
7352 /* Switch to the buffer of selected window of the frame. Set up
7353 frame_title_ptr so that display_mode_element will output into it;
7354 then display the title. */
7355 obuf
= current_buffer
;
7356 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7357 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7358 frame_title_ptr
= frame_title_buf
;
7359 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7360 NULL
, DEFAULT_FACE_ID
);
7361 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7362 len
= frame_title_ptr
- frame_title_buf
;
7363 frame_title_ptr
= NULL
;
7364 set_buffer_internal_1 (obuf
);
7366 /* Set the title only if it's changed. This avoids consing in
7367 the common case where it hasn't. (If it turns out that we've
7368 already wasted too much time by walking through the list with
7369 display_mode_element, then we might need to optimize at a
7370 higher level than this.) */
7371 if (! STRINGP (f
->name
)
7372 || SBYTES (f
->name
) != len
7373 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7374 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7378 #endif /* not HAVE_WINDOW_SYSTEM */
7383 /***********************************************************************
7385 ***********************************************************************/
7388 /* Prepare for redisplay by updating menu-bar item lists when
7389 appropriate. This can call eval. */
7392 prepare_menu_bars ()
7395 struct gcpro gcpro1
, gcpro2
;
7397 Lisp_Object tooltip_frame
;
7399 #ifdef HAVE_WINDOW_SYSTEM
7400 tooltip_frame
= tip_frame
;
7402 tooltip_frame
= Qnil
;
7405 /* Update all frame titles based on their buffer names, etc. We do
7406 this before the menu bars so that the buffer-menu will show the
7407 up-to-date frame titles. */
7408 #ifdef HAVE_WINDOW_SYSTEM
7409 if (windows_or_buffers_changed
|| update_mode_lines
)
7411 Lisp_Object tail
, frame
;
7413 FOR_EACH_FRAME (tail
, frame
)
7416 if (!EQ (frame
, tooltip_frame
)
7417 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7418 x_consider_frame_title (frame
);
7421 #endif /* HAVE_WINDOW_SYSTEM */
7423 /* Update the menu bar item lists, if appropriate. This has to be
7424 done before any actual redisplay or generation of display lines. */
7425 all_windows
= (update_mode_lines
7426 || buffer_shared
> 1
7427 || windows_or_buffers_changed
);
7430 Lisp_Object tail
, frame
;
7431 int count
= SPECPDL_INDEX ();
7433 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7435 FOR_EACH_FRAME (tail
, frame
)
7439 /* Ignore tooltip frame. */
7440 if (EQ (frame
, tooltip_frame
))
7443 /* If a window on this frame changed size, report that to
7444 the user and clear the size-change flag. */
7445 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7447 Lisp_Object functions
;
7449 /* Clear flag first in case we get an error below. */
7450 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7451 functions
= Vwindow_size_change_functions
;
7452 GCPRO2 (tail
, functions
);
7454 while (CONSP (functions
))
7456 call1 (XCAR (functions
), frame
);
7457 functions
= XCDR (functions
);
7463 update_menu_bar (f
, 0);
7464 #ifdef HAVE_WINDOW_SYSTEM
7465 update_tool_bar (f
, 0);
7470 unbind_to (count
, Qnil
);
7474 struct frame
*sf
= SELECTED_FRAME ();
7475 update_menu_bar (sf
, 1);
7476 #ifdef HAVE_WINDOW_SYSTEM
7477 update_tool_bar (sf
, 1);
7481 /* Motif needs this. See comment in xmenu.c. Turn it off when
7482 pending_menu_activation is not defined. */
7483 #ifdef USE_X_TOOLKIT
7484 pending_menu_activation
= 0;
7489 /* Update the menu bar item list for frame F. This has to be done
7490 before we start to fill in any display lines, because it can call
7493 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7496 update_menu_bar (f
, save_match_data
)
7498 int save_match_data
;
7501 register struct window
*w
;
7503 /* If called recursively during a menu update, do nothing. This can
7504 happen when, for instance, an activate-menubar-hook causes a
7506 if (inhibit_menubar_update
)
7509 window
= FRAME_SELECTED_WINDOW (f
);
7510 w
= XWINDOW (window
);
7512 #if 0 /* The if statement below this if statement used to include the
7513 condition !NILP (w->update_mode_line), rather than using
7514 update_mode_lines directly, and this if statement may have
7515 been added to make that condition work. Now the if
7516 statement below matches its comment, this isn't needed. */
7517 if (update_mode_lines
)
7518 w
->update_mode_line
= Qt
;
7521 if (FRAME_WINDOW_P (f
)
7523 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
7524 || defined (USE_GTK)
7525 FRAME_EXTERNAL_MENU_BAR (f
)
7527 FRAME_MENU_BAR_LINES (f
) > 0
7529 : FRAME_MENU_BAR_LINES (f
) > 0)
7531 /* If the user has switched buffers or windows, we need to
7532 recompute to reflect the new bindings. But we'll
7533 recompute when update_mode_lines is set too; that means
7534 that people can use force-mode-line-update to request
7535 that the menu bar be recomputed. The adverse effect on
7536 the rest of the redisplay algorithm is about the same as
7537 windows_or_buffers_changed anyway. */
7538 if (windows_or_buffers_changed
7539 /* This used to test w->update_mode_line, but we believe
7540 there is no need to recompute the menu in that case. */
7541 || update_mode_lines
7542 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7543 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7544 != !NILP (w
->last_had_star
))
7545 || ((!NILP (Vtransient_mark_mode
)
7546 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7547 != !NILP (w
->region_showing
)))
7549 struct buffer
*prev
= current_buffer
;
7550 int count
= SPECPDL_INDEX ();
7552 specbind (Qinhibit_menubar_update
, Qt
);
7554 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7555 if (save_match_data
)
7556 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7557 if (NILP (Voverriding_local_map_menu_flag
))
7559 specbind (Qoverriding_terminal_local_map
, Qnil
);
7560 specbind (Qoverriding_local_map
, Qnil
);
7563 /* Run the Lucid hook. */
7564 safe_run_hooks (Qactivate_menubar_hook
);
7566 /* If it has changed current-menubar from previous value,
7567 really recompute the menu-bar from the value. */
7568 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7569 call0 (Qrecompute_lucid_menubar
);
7571 safe_run_hooks (Qmenu_bar_update_hook
);
7572 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7574 /* Redisplay the menu bar in case we changed it. */
7575 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
7576 || defined (USE_GTK)
7577 if (FRAME_WINDOW_P (f
)
7578 #if defined (MAC_OS)
7579 /* All frames on Mac OS share the same menubar. So only the
7580 selected frame should be allowed to set it. */
7581 && f
== SELECTED_FRAME ()
7584 set_frame_menubar (f
, 0, 0);
7586 /* On a terminal screen, the menu bar is an ordinary screen
7587 line, and this makes it get updated. */
7588 w
->update_mode_line
= Qt
;
7589 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
7590 /* In the non-toolkit version, the menu bar is an ordinary screen
7591 line, and this makes it get updated. */
7592 w
->update_mode_line
= Qt
;
7593 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
7595 unbind_to (count
, Qnil
);
7596 set_buffer_internal_1 (prev
);
7603 /***********************************************************************
7605 ***********************************************************************/
7607 #ifdef HAVE_WINDOW_SYSTEM
7609 /* Update the tool-bar item list for frame F. This has to be done
7610 before we start to fill in any display lines. Called from
7611 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7612 and restore it here. */
7615 update_tool_bar (f
, save_match_data
)
7617 int save_match_data
;
7620 int do_update
= FRAME_EXTERNAL_TOOL_BAR(f
);
7622 int do_update
= WINDOWP (f
->tool_bar_window
)
7623 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0;
7631 window
= FRAME_SELECTED_WINDOW (f
);
7632 w
= XWINDOW (window
);
7634 /* If the user has switched buffers or windows, we need to
7635 recompute to reflect the new bindings. But we'll
7636 recompute when update_mode_lines is set too; that means
7637 that people can use force-mode-line-update to request
7638 that the menu bar be recomputed. The adverse effect on
7639 the rest of the redisplay algorithm is about the same as
7640 windows_or_buffers_changed anyway. */
7641 if (windows_or_buffers_changed
7642 || !NILP (w
->update_mode_line
)
7643 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7644 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7645 != !NILP (w
->last_had_star
))
7646 || ((!NILP (Vtransient_mark_mode
)
7647 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7648 != !NILP (w
->region_showing
)))
7650 struct buffer
*prev
= current_buffer
;
7651 int count
= SPECPDL_INDEX ();
7653 /* Set current_buffer to the buffer of the selected
7654 window of the frame, so that we get the right local
7656 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7658 /* Save match data, if we must. */
7659 if (save_match_data
)
7660 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7662 /* Make sure that we don't accidentally use bogus keymaps. */
7663 if (NILP (Voverriding_local_map_menu_flag
))
7665 specbind (Qoverriding_terminal_local_map
, Qnil
);
7666 specbind (Qoverriding_local_map
, Qnil
);
7669 /* Build desired tool-bar items from keymaps. */
7671 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7673 /* Redisplay the tool-bar in case we changed it. */
7674 w
->update_mode_line
= Qt
;
7676 unbind_to (count
, Qnil
);
7677 set_buffer_internal_1 (prev
);
7683 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7684 F's desired tool-bar contents. F->tool_bar_items must have
7685 been set up previously by calling prepare_menu_bars. */
7688 build_desired_tool_bar_string (f
)
7691 int i
, size
, size_needed
;
7692 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7693 Lisp_Object image
, plist
, props
;
7695 image
= plist
= props
= Qnil
;
7696 GCPRO3 (image
, plist
, props
);
7698 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7699 Otherwise, make a new string. */
7701 /* The size of the string we might be able to reuse. */
7702 size
= (STRINGP (f
->desired_tool_bar_string
)
7703 ? SCHARS (f
->desired_tool_bar_string
)
7706 /* We need one space in the string for each image. */
7707 size_needed
= f
->n_tool_bar_items
;
7709 /* Reuse f->desired_tool_bar_string, if possible. */
7710 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7711 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7715 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7716 Fremove_text_properties (make_number (0), make_number (size
),
7717 props
, f
->desired_tool_bar_string
);
7720 /* Put a `display' property on the string for the images to display,
7721 put a `menu_item' property on tool-bar items with a value that
7722 is the index of the item in F's tool-bar item vector. */
7723 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7725 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7727 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7728 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7729 int hmargin
, vmargin
, relief
, idx
, end
;
7730 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7732 /* If image is a vector, choose the image according to the
7734 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7735 if (VECTORP (image
))
7739 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7740 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7743 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7744 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7746 xassert (ASIZE (image
) >= idx
);
7747 image
= AREF (image
, idx
);
7752 /* Ignore invalid image specifications. */
7753 if (!valid_image_p (image
))
7756 /* Display the tool-bar button pressed, or depressed. */
7757 plist
= Fcopy_sequence (XCDR (image
));
7759 /* Compute margin and relief to draw. */
7760 relief
= (tool_bar_button_relief
>= 0
7761 ? tool_bar_button_relief
7762 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7763 hmargin
= vmargin
= relief
;
7765 if (INTEGERP (Vtool_bar_button_margin
)
7766 && XINT (Vtool_bar_button_margin
) > 0)
7768 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7769 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7771 else if (CONSP (Vtool_bar_button_margin
))
7773 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7774 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7775 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7777 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7778 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7779 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7782 if (auto_raise_tool_bar_buttons_p
)
7784 /* Add a `:relief' property to the image spec if the item is
7788 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7795 /* If image is selected, display it pressed, i.e. with a
7796 negative relief. If it's not selected, display it with a
7798 plist
= Fplist_put (plist
, QCrelief
,
7800 ? make_number (-relief
)
7801 : make_number (relief
)));
7806 /* Put a margin around the image. */
7807 if (hmargin
|| vmargin
)
7809 if (hmargin
== vmargin
)
7810 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7812 plist
= Fplist_put (plist
, QCmargin
,
7813 Fcons (make_number (hmargin
),
7814 make_number (vmargin
)));
7817 /* If button is not enabled, and we don't have special images
7818 for the disabled state, make the image appear disabled by
7819 applying an appropriate algorithm to it. */
7820 if (!enabled_p
&& idx
< 0)
7821 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7823 /* Put a `display' text property on the string for the image to
7824 display. Put a `menu-item' property on the string that gives
7825 the start of this item's properties in the tool-bar items
7827 image
= Fcons (Qimage
, plist
);
7828 props
= list4 (Qdisplay
, image
,
7829 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7831 /* Let the last image hide all remaining spaces in the tool bar
7832 string. The string can be longer than needed when we reuse a
7834 if (i
+ 1 == f
->n_tool_bar_items
)
7835 end
= SCHARS (f
->desired_tool_bar_string
);
7838 Fadd_text_properties (make_number (i
), make_number (end
),
7839 props
, f
->desired_tool_bar_string
);
7847 /* Display one line of the tool-bar of frame IT->f. */
7850 display_tool_bar_line (it
)
7853 struct glyph_row
*row
= it
->glyph_row
;
7854 int max_x
= it
->last_visible_x
;
7857 prepare_desired_row (row
);
7858 row
->y
= it
->current_y
;
7860 /* Note that this isn't made use of if the face hasn't a box,
7861 so there's no need to check the face here. */
7862 it
->start_of_box_run_p
= 1;
7864 while (it
->current_x
< max_x
)
7866 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7868 /* Get the next display element. */
7869 if (!get_next_display_element (it
))
7872 /* Produce glyphs. */
7873 x_before
= it
->current_x
;
7874 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7875 PRODUCE_GLYPHS (it
);
7877 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7882 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7884 if (x
+ glyph
->pixel_width
> max_x
)
7886 /* Glyph doesn't fit on line. */
7887 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7893 x
+= glyph
->pixel_width
;
7897 /* Stop at line ends. */
7898 if (ITERATOR_AT_END_OF_LINE_P (it
))
7901 set_iterator_to_next (it
, 1);
7906 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7907 extend_face_to_end_of_line (it
);
7908 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7909 last
->right_box_line_p
= 1;
7910 if (last
== row
->glyphs
[TEXT_AREA
])
7911 last
->left_box_line_p
= 1;
7912 compute_line_metrics (it
);
7914 /* If line is empty, make it occupy the rest of the tool-bar. */
7915 if (!row
->displays_text_p
)
7917 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7918 row
->ascent
= row
->phys_ascent
= 0;
7921 row
->full_width_p
= 1;
7922 row
->continued_p
= 0;
7923 row
->truncated_on_left_p
= 0;
7924 row
->truncated_on_right_p
= 0;
7926 it
->current_x
= it
->hpos
= 0;
7927 it
->current_y
+= row
->height
;
7933 /* Value is the number of screen lines needed to make all tool-bar
7934 items of frame F visible. */
7937 tool_bar_lines_needed (f
)
7940 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7943 /* Initialize an iterator for iteration over
7944 F->desired_tool_bar_string in the tool-bar window of frame F. */
7945 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7946 it
.first_visible_x
= 0;
7947 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7948 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7950 while (!ITERATOR_AT_END_P (&it
))
7952 it
.glyph_row
= w
->desired_matrix
->rows
;
7953 clear_glyph_row (it
.glyph_row
);
7954 display_tool_bar_line (&it
);
7957 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7961 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7963 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
7972 frame
= selected_frame
;
7974 CHECK_FRAME (frame
);
7977 if (WINDOWP (f
->tool_bar_window
)
7978 || (w
= XWINDOW (f
->tool_bar_window
),
7979 XFASTINT (w
->height
) > 0))
7981 update_tool_bar (f
, 1);
7982 if (f
->n_tool_bar_items
)
7984 build_desired_tool_bar_string (f
);
7985 nlines
= tool_bar_lines_needed (f
);
7989 return make_number (nlines
);
7993 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7994 height should be changed. */
7997 redisplay_tool_bar (f
)
8002 struct glyph_row
*row
;
8003 int change_height_p
= 0;
8006 if (FRAME_EXTERNAL_TOOL_BAR(f
))
8007 update_frame_tool_bar (f
);
8011 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8012 do anything. This means you must start with tool-bar-lines
8013 non-zero to get the auto-sizing effect. Or in other words, you
8014 can turn off tool-bars by specifying tool-bar-lines zero. */
8015 if (!WINDOWP (f
->tool_bar_window
)
8016 || (w
= XWINDOW (f
->tool_bar_window
),
8017 XFASTINT (w
->height
) == 0))
8020 /* Set up an iterator for the tool-bar window. */
8021 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8022 it
.first_visible_x
= 0;
8023 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
8026 /* Build a string that represents the contents of the tool-bar. */
8027 build_desired_tool_bar_string (f
);
8028 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8030 /* Display as many lines as needed to display all tool-bar items. */
8031 while (it
.current_y
< it
.last_visible_y
)
8032 display_tool_bar_line (&it
);
8034 /* It doesn't make much sense to try scrolling in the tool-bar
8035 window, so don't do it. */
8036 w
->desired_matrix
->no_scrolling_p
= 1;
8037 w
->must_be_updated_p
= 1;
8039 if (auto_resize_tool_bars_p
)
8043 /* If we couldn't display everything, change the tool-bar's
8045 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8046 change_height_p
= 1;
8048 /* If there are blank lines at the end, except for a partially
8049 visible blank line at the end that is smaller than
8050 CANON_Y_UNIT, change the tool-bar's height. */
8051 row
= it
.glyph_row
- 1;
8052 if (!row
->displays_text_p
8053 && row
->height
>= CANON_Y_UNIT (f
))
8054 change_height_p
= 1;
8056 /* If row displays tool-bar items, but is partially visible,
8057 change the tool-bar's height. */
8058 if (row
->displays_text_p
8059 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8060 change_height_p
= 1;
8062 /* Resize windows as needed by changing the `tool-bar-lines'
8065 && (nlines
= tool_bar_lines_needed (f
),
8066 nlines
!= XFASTINT (w
->height
)))
8068 extern Lisp_Object Qtool_bar_lines
;
8070 int old_height
= XFASTINT (w
->height
);
8072 XSETFRAME (frame
, f
);
8073 clear_glyph_matrix (w
->desired_matrix
);
8074 Fmodify_frame_parameters (frame
,
8075 Fcons (Fcons (Qtool_bar_lines
,
8076 make_number (nlines
)),
8078 if (XFASTINT (w
->height
) != old_height
)
8079 fonts_changed_p
= 1;
8083 return change_height_p
;
8087 /* Get information about the tool-bar item which is displayed in GLYPH
8088 on frame F. Return in *PROP_IDX the index where tool-bar item
8089 properties start in F->tool_bar_items. Value is zero if
8090 GLYPH doesn't display a tool-bar item. */
8093 tool_bar_item_info (f
, glyph
, prop_idx
)
8095 struct glyph
*glyph
;
8102 /* This function can be called asynchronously, which means we must
8103 exclude any possibility that Fget_text_property signals an
8105 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8106 charpos
= max (0, charpos
);
8108 /* Get the text property `menu-item' at pos. The value of that
8109 property is the start index of this item's properties in
8110 F->tool_bar_items. */
8111 prop
= Fget_text_property (make_number (charpos
),
8112 Qmenu_item
, f
->current_tool_bar_string
);
8113 if (INTEGERP (prop
))
8115 *prop_idx
= XINT (prop
);
8124 #endif /* HAVE_WINDOW_SYSTEM */
8128 /************************************************************************
8129 Horizontal scrolling
8130 ************************************************************************/
8132 static int hscroll_window_tree
P_ ((Lisp_Object
));
8133 static int hscroll_windows
P_ ((Lisp_Object
));
8135 /* For all leaf windows in the window tree rooted at WINDOW, set their
8136 hscroll value so that PT is (i) visible in the window, and (ii) so
8137 that it is not within a certain margin at the window's left and
8138 right border. Value is non-zero if any window's hscroll has been
8142 hscroll_window_tree (window
)
8145 int hscrolled_p
= 0;
8146 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
8147 int hscroll_step_abs
= 0;
8148 double hscroll_step_rel
= 0;
8150 if (hscroll_relative_p
)
8152 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
8153 if (hscroll_step_rel
< 0)
8155 hscroll_relative_p
= 0;
8156 hscroll_step_abs
= 0;
8159 else if (INTEGERP (Vhscroll_step
))
8161 hscroll_step_abs
= XINT (Vhscroll_step
);
8162 if (hscroll_step_abs
< 0)
8163 hscroll_step_abs
= 0;
8166 hscroll_step_abs
= 0;
8168 while (WINDOWP (window
))
8170 struct window
*w
= XWINDOW (window
);
8172 if (WINDOWP (w
->hchild
))
8173 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
8174 else if (WINDOWP (w
->vchild
))
8175 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
8176 else if (w
->cursor
.vpos
>= 0)
8178 int h_margin
, text_area_x
, text_area_y
;
8179 int text_area_width
, text_area_height
;
8180 struct glyph_row
*current_cursor_row
8181 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
8182 struct glyph_row
*desired_cursor_row
8183 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
8184 struct glyph_row
*cursor_row
8185 = (desired_cursor_row
->enabled_p
8186 ? desired_cursor_row
8187 : current_cursor_row
);
8189 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8190 &text_area_width
, &text_area_height
);
8192 /* Scroll when cursor is inside this scroll margin. */
8193 h_margin
= hscroll_margin
* CANON_X_UNIT (XFRAME (w
->frame
));
8195 if ((XFASTINT (w
->hscroll
)
8196 && w
->cursor
.x
<= h_margin
)
8197 || (cursor_row
->enabled_p
8198 && cursor_row
->truncated_on_right_p
8199 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
8203 struct buffer
*saved_current_buffer
;
8207 /* Find point in a display of infinite width. */
8208 saved_current_buffer
= current_buffer
;
8209 current_buffer
= XBUFFER (w
->buffer
);
8211 if (w
== XWINDOW (selected_window
))
8212 pt
= BUF_PT (current_buffer
);
8215 pt
= marker_position (w
->pointm
);
8216 pt
= max (BEGV
, pt
);
8220 /* Move iterator to pt starting at cursor_row->start in
8221 a line with infinite width. */
8222 init_to_row_start (&it
, w
, cursor_row
);
8223 it
.last_visible_x
= INFINITY
;
8224 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8225 current_buffer
= saved_current_buffer
;
8227 /* Position cursor in window. */
8228 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
8229 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
8230 / CANON_X_UNIT (it
.f
);
8231 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
8233 if (hscroll_relative_p
)
8234 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
8237 wanted_x
= text_area_width
8238 - hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8241 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8245 if (hscroll_relative_p
)
8246 wanted_x
= text_area_width
* hscroll_step_rel
8249 wanted_x
= hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8252 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8254 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8256 /* Don't call Fset_window_hscroll if value hasn't
8257 changed because it will prevent redisplay
8259 if (XFASTINT (w
->hscroll
) != hscroll
)
8261 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8262 w
->hscroll
= make_number (hscroll
);
8271 /* Value is non-zero if hscroll of any leaf window has been changed. */
8276 /* Set hscroll so that cursor is visible and not inside horizontal
8277 scroll margins for all windows in the tree rooted at WINDOW. See
8278 also hscroll_window_tree above. Value is non-zero if any window's
8279 hscroll has been changed. If it has, desired matrices on the frame
8280 of WINDOW are cleared. */
8283 hscroll_windows (window
)
8288 if (automatic_hscrolling_p
)
8290 hscrolled_p
= hscroll_window_tree (window
);
8292 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8301 /************************************************************************
8303 ************************************************************************/
8305 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8306 to a non-zero value. This is sometimes handy to have in a debugger
8311 /* First and last unchanged row for try_window_id. */
8313 int debug_first_unchanged_at_end_vpos
;
8314 int debug_last_unchanged_at_beg_vpos
;
8316 /* Delta vpos and y. */
8318 int debug_dvpos
, debug_dy
;
8320 /* Delta in characters and bytes for try_window_id. */
8322 int debug_delta
, debug_delta_bytes
;
8324 /* Values of window_end_pos and window_end_vpos at the end of
8327 EMACS_INT debug_end_pos
, debug_end_vpos
;
8329 /* Append a string to W->desired_matrix->method. FMT is a printf
8330 format string. A1...A9 are a supplement for a variable-length
8331 argument list. If trace_redisplay_p is non-zero also printf the
8332 resulting string to stderr. */
8335 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8338 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8341 char *method
= w
->desired_matrix
->method
;
8342 int len
= strlen (method
);
8343 int size
= sizeof w
->desired_matrix
->method
;
8344 int remaining
= size
- len
- 1;
8346 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8347 if (len
&& remaining
)
8353 strncpy (method
+ len
, buffer
, remaining
);
8355 if (trace_redisplay_p
)
8356 fprintf (stderr
, "%p (%s): %s\n",
8358 ((BUFFERP (w
->buffer
)
8359 && STRINGP (XBUFFER (w
->buffer
)->name
))
8360 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
8365 #endif /* GLYPH_DEBUG */
8368 /* Value is non-zero if all changes in window W, which displays
8369 current_buffer, are in the text between START and END. START is a
8370 buffer position, END is given as a distance from Z. Used in
8371 redisplay_internal for display optimization. */
8374 text_outside_line_unchanged_p (w
, start
, end
)
8378 int unchanged_p
= 1;
8380 /* If text or overlays have changed, see where. */
8381 if (XFASTINT (w
->last_modified
) < MODIFF
8382 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8384 /* Gap in the line? */
8385 if (GPT
< start
|| Z
- GPT
< end
)
8388 /* Changes start in front of the line, or end after it? */
8390 && (BEG_UNCHANGED
< start
- 1
8391 || END_UNCHANGED
< end
))
8394 /* If selective display, can't optimize if changes start at the
8395 beginning of the line. */
8397 && INTEGERP (current_buffer
->selective_display
)
8398 && XINT (current_buffer
->selective_display
) > 0
8399 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8402 /* If there are overlays at the start or end of the line, these
8403 may have overlay strings with newlines in them. A change at
8404 START, for instance, may actually concern the display of such
8405 overlay strings as well, and they are displayed on different
8406 lines. So, quickly rule out this case. (For the future, it
8407 might be desirable to implement something more telling than
8408 just BEG/END_UNCHANGED.) */
8411 if (BEG
+ BEG_UNCHANGED
== start
8412 && overlay_touches_p (start
))
8414 if (END_UNCHANGED
== end
8415 && overlay_touches_p (Z
- end
))
8424 /* Do a frame update, taking possible shortcuts into account. This is
8425 the main external entry point for redisplay.
8427 If the last redisplay displayed an echo area message and that message
8428 is no longer requested, we clear the echo area or bring back the
8429 mini-buffer if that is in use. */
8434 redisplay_internal (0);
8438 /* Return 1 if point moved out of or into a composition. Otherwise
8439 return 0. PREV_BUF and PREV_PT are the last point buffer and
8440 position. BUF and PT are the current point buffer and position. */
8443 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8444 struct buffer
*prev_buf
, *buf
;
8451 XSETBUFFER (buffer
, buf
);
8452 /* Check a composition at the last point if point moved within the
8454 if (prev_buf
== buf
)
8457 /* Point didn't move. */
8460 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8461 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8462 && COMPOSITION_VALID_P (start
, end
, prop
)
8463 && start
< prev_pt
&& end
> prev_pt
)
8464 /* The last point was within the composition. Return 1 iff
8465 point moved out of the composition. */
8466 return (pt
<= start
|| pt
>= end
);
8469 /* Check a composition at the current point. */
8470 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8471 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8472 && COMPOSITION_VALID_P (start
, end
, prop
)
8473 && start
< pt
&& end
> pt
);
8477 /* Reconsider the setting of B->clip_changed which is displayed
8481 reconsider_clip_changes (w
, b
)
8486 && !NILP (w
->window_end_valid
)
8487 && w
->current_matrix
->buffer
== b
8488 && w
->current_matrix
->zv
== BUF_ZV (b
)
8489 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8490 b
->clip_changed
= 0;
8492 /* If display wasn't paused, and W is not a tool bar window, see if
8493 point has been moved into or out of a composition. In that case,
8494 we set b->clip_changed to 1 to force updating the screen. If
8495 b->clip_changed has already been set to 1, we can skip this
8497 if (!b
->clip_changed
8498 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8502 if (w
== XWINDOW (selected_window
))
8503 pt
= BUF_PT (current_buffer
);
8505 pt
= marker_position (w
->pointm
);
8507 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8508 || pt
!= XINT (w
->last_point
))
8509 && check_point_in_composition (w
->current_matrix
->buffer
,
8510 XINT (w
->last_point
),
8511 XBUFFER (w
->buffer
), pt
))
8512 b
->clip_changed
= 1;
8516 #define STOP_POLLING \
8517 do { if (! polling_stopped_here) stop_polling (); \
8518 polling_stopped_here = 1; } while (0)
8520 #define RESUME_POLLING \
8521 do { if (polling_stopped_here) start_polling (); \
8522 polling_stopped_here = 0; } while (0)
8525 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8526 response to any user action; therefore, we should preserve the echo
8527 area. (Actually, our caller does that job.) Perhaps in the future
8528 avoid recentering windows if it is not necessary; currently that
8529 causes some problems. */
8532 redisplay_internal (preserve_echo_area
)
8533 int preserve_echo_area
;
8535 struct window
*w
= XWINDOW (selected_window
);
8536 struct frame
*f
= XFRAME (w
->frame
);
8538 int must_finish
= 0;
8539 struct text_pos tlbufpos
, tlendpos
;
8540 int number_of_visible_frames
;
8542 struct frame
*sf
= SELECTED_FRAME ();
8543 int polling_stopped_here
= 0;
8545 /* Non-zero means redisplay has to consider all windows on all
8546 frames. Zero means, only selected_window is considered. */
8547 int consider_all_windows_p
;
8549 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8551 /* No redisplay if running in batch mode or frame is not yet fully
8552 initialized, or redisplay is explicitly turned off by setting
8553 Vinhibit_redisplay. */
8555 || !NILP (Vinhibit_redisplay
)
8556 || !f
->glyphs_initialized_p
)
8559 /* The flag redisplay_performed_directly_p is set by
8560 direct_output_for_insert when it already did the whole screen
8561 update necessary. */
8562 if (redisplay_performed_directly_p
)
8564 redisplay_performed_directly_p
= 0;
8565 if (!hscroll_windows (selected_window
))
8569 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
8570 if (popup_activated ())
8574 /* I don't think this happens but let's be paranoid. */
8578 /* Record a function that resets redisplaying_p to its old value
8579 when we leave this function. */
8580 count
= SPECPDL_INDEX ();
8581 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8583 specbind (Qinhibit_free_realized_faces
, Qnil
);
8587 reconsider_clip_changes (w
, current_buffer
);
8589 /* If new fonts have been loaded that make a glyph matrix adjustment
8590 necessary, do it. */
8591 if (fonts_changed_p
)
8593 adjust_glyphs (NULL
);
8594 ++windows_or_buffers_changed
;
8595 fonts_changed_p
= 0;
8598 /* If face_change_count is non-zero, init_iterator will free all
8599 realized faces, which includes the faces referenced from current
8600 matrices. So, we can't reuse current matrices in this case. */
8601 if (face_change_count
)
8602 ++windows_or_buffers_changed
;
8604 if (! FRAME_WINDOW_P (sf
)
8605 && previous_terminal_frame
!= sf
)
8607 /* Since frames on an ASCII terminal share the same display
8608 area, displaying a different frame means redisplay the whole
8610 windows_or_buffers_changed
++;
8611 SET_FRAME_GARBAGED (sf
);
8612 XSETFRAME (Vterminal_frame
, sf
);
8614 previous_terminal_frame
= sf
;
8616 /* Set the visible flags for all frames. Do this before checking
8617 for resized or garbaged frames; they want to know if their frames
8618 are visible. See the comment in frame.h for
8619 FRAME_SAMPLE_VISIBILITY. */
8621 Lisp_Object tail
, frame
;
8623 number_of_visible_frames
= 0;
8625 FOR_EACH_FRAME (tail
, frame
)
8627 struct frame
*f
= XFRAME (frame
);
8629 FRAME_SAMPLE_VISIBILITY (f
);
8630 if (FRAME_VISIBLE_P (f
))
8631 ++number_of_visible_frames
;
8632 clear_desired_matrices (f
);
8636 /* Notice any pending interrupt request to change frame size. */
8637 do_pending_window_change (1);
8639 /* Clear frames marked as garbaged. */
8641 clear_garbaged_frames ();
8643 /* Build menubar and tool-bar items. */
8644 prepare_menu_bars ();
8646 if (windows_or_buffers_changed
)
8647 update_mode_lines
++;
8649 /* Detect case that we need to write or remove a star in the mode line. */
8650 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8652 w
->update_mode_line
= Qt
;
8653 if (buffer_shared
> 1)
8654 update_mode_lines
++;
8657 /* If %c is in the mode line, update it if needed. */
8658 if (!NILP (w
->column_number_displayed
)
8659 /* This alternative quickly identifies a common case
8660 where no change is needed. */
8661 && !(PT
== XFASTINT (w
->last_point
)
8662 && XFASTINT (w
->last_modified
) >= MODIFF
8663 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8664 && (XFASTINT (w
->column_number_displayed
)
8665 != (int) current_column ())) /* iftc */
8666 w
->update_mode_line
= Qt
;
8668 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8670 /* The variable buffer_shared is set in redisplay_window and
8671 indicates that we redisplay a buffer in different windows. See
8673 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
8674 || cursor_type_changed
);
8676 /* If specs for an arrow have changed, do thorough redisplay
8677 to ensure we remove any arrow that should no longer exist. */
8678 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8679 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8680 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8682 /* Normally the message* functions will have already displayed and
8683 updated the echo area, but the frame may have been trashed, or
8684 the update may have been preempted, so display the echo area
8685 again here. Checking message_cleared_p captures the case that
8686 the echo area should be cleared. */
8687 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8688 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8689 || (message_cleared_p
8690 && minibuf_level
== 0
8691 /* If the mini-window is currently selected, this means the
8692 echo-area doesn't show through. */
8693 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8695 int window_height_changed_p
= echo_area_display (0);
8698 /* If we don't display the current message, don't clear the
8699 message_cleared_p flag, because, if we did, we wouldn't clear
8700 the echo area in the next redisplay which doesn't preserve
8702 if (!display_last_displayed_message_p
)
8703 message_cleared_p
= 0;
8705 if (fonts_changed_p
)
8707 else if (window_height_changed_p
)
8709 consider_all_windows_p
= 1;
8710 ++update_mode_lines
;
8711 ++windows_or_buffers_changed
;
8713 /* If window configuration was changed, frames may have been
8714 marked garbaged. Clear them or we will experience
8715 surprises wrt scrolling. */
8717 clear_garbaged_frames ();
8720 else if (EQ (selected_window
, minibuf_window
)
8721 && (current_buffer
->clip_changed
8722 || XFASTINT (w
->last_modified
) < MODIFF
8723 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8724 && resize_mini_window (w
, 0))
8726 /* Resized active mini-window to fit the size of what it is
8727 showing if its contents might have changed. */
8729 consider_all_windows_p
= 1;
8730 ++windows_or_buffers_changed
;
8731 ++update_mode_lines
;
8733 /* If window configuration was changed, frames may have been
8734 marked garbaged. Clear them or we will experience
8735 surprises wrt scrolling. */
8737 clear_garbaged_frames ();
8741 /* If showing the region, and mark has changed, we must redisplay
8742 the whole window. The assignment to this_line_start_pos prevents
8743 the optimization directly below this if-statement. */
8744 if (((!NILP (Vtransient_mark_mode
)
8745 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8746 != !NILP (w
->region_showing
))
8747 || (!NILP (w
->region_showing
)
8748 && !EQ (w
->region_showing
,
8749 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8750 CHARPOS (this_line_start_pos
) = 0;
8752 /* Optimize the case that only the line containing the cursor in the
8753 selected window has changed. Variables starting with this_ are
8754 set in display_line and record information about the line
8755 containing the cursor. */
8756 tlbufpos
= this_line_start_pos
;
8757 tlendpos
= this_line_end_pos
;
8758 if (!consider_all_windows_p
8759 && CHARPOS (tlbufpos
) > 0
8760 && NILP (w
->update_mode_line
)
8761 && !current_buffer
->clip_changed
8762 && !current_buffer
->prevent_redisplay_optimizations_p
8763 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8764 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8765 /* Make sure recorded data applies to current buffer, etc. */
8766 && this_line_buffer
== current_buffer
8767 && current_buffer
== XBUFFER (w
->buffer
)
8768 && NILP (w
->force_start
)
8769 && NILP (w
->optional_new_start
)
8770 /* Point must be on the line that we have info recorded about. */
8771 && PT
>= CHARPOS (tlbufpos
)
8772 && PT
<= Z
- CHARPOS (tlendpos
)
8773 /* All text outside that line, including its final newline,
8774 must be unchanged */
8775 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8776 CHARPOS (tlendpos
)))
8778 if (CHARPOS (tlbufpos
) > BEGV
8779 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8780 && (CHARPOS (tlbufpos
) == ZV
8781 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8782 /* Former continuation line has disappeared by becoming empty */
8784 else if (XFASTINT (w
->last_modified
) < MODIFF
8785 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8786 || MINI_WINDOW_P (w
))
8788 /* We have to handle the case of continuation around a
8789 wide-column character (See the comment in indent.c around
8792 For instance, in the following case:
8794 -------- Insert --------
8795 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8796 J_I_ ==> J_I_ `^^' are cursors.
8800 As we have to redraw the line above, we should goto cancel. */
8803 int line_height_before
= this_line_pixel_height
;
8805 /* Note that start_display will handle the case that the
8806 line starting at tlbufpos is a continuation lines. */
8807 start_display (&it
, w
, tlbufpos
);
8809 /* Implementation note: It this still necessary? */
8810 if (it
.current_x
!= this_line_start_x
)
8813 TRACE ((stderr
, "trying display optimization 1\n"));
8814 w
->cursor
.vpos
= -1;
8815 overlay_arrow_seen
= 0;
8816 it
.vpos
= this_line_vpos
;
8817 it
.current_y
= this_line_y
;
8818 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8821 /* If line contains point, is not continued,
8822 and ends at same distance from eob as before, we win */
8823 if (w
->cursor
.vpos
>= 0
8824 /* Line is not continued, otherwise this_line_start_pos
8825 would have been set to 0 in display_line. */
8826 && CHARPOS (this_line_start_pos
)
8827 /* Line ends as before. */
8828 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8829 /* Line has same height as before. Otherwise other lines
8830 would have to be shifted up or down. */
8831 && this_line_pixel_height
== line_height_before
)
8833 /* If this is not the window's last line, we must adjust
8834 the charstarts of the lines below. */
8835 if (it
.current_y
< it
.last_visible_y
)
8837 struct glyph_row
*row
8838 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8839 int delta
, delta_bytes
;
8841 if (Z
- CHARPOS (tlendpos
) == ZV
)
8843 /* This line ends at end of (accessible part of)
8844 buffer. There is no newline to count. */
8846 - CHARPOS (tlendpos
)
8847 - MATRIX_ROW_START_CHARPOS (row
));
8848 delta_bytes
= (Z_BYTE
8849 - BYTEPOS (tlendpos
)
8850 - MATRIX_ROW_START_BYTEPOS (row
));
8854 /* This line ends in a newline. Must take
8855 account of the newline and the rest of the
8856 text that follows. */
8858 - CHARPOS (tlendpos
)
8859 - MATRIX_ROW_START_CHARPOS (row
));
8860 delta_bytes
= (Z_BYTE
8861 - BYTEPOS (tlendpos
)
8862 - MATRIX_ROW_START_BYTEPOS (row
));
8865 increment_matrix_positions (w
->current_matrix
,
8867 w
->current_matrix
->nrows
,
8868 delta
, delta_bytes
);
8871 /* If this row displays text now but previously didn't,
8872 or vice versa, w->window_end_vpos may have to be
8874 if ((it
.glyph_row
- 1)->displays_text_p
)
8876 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8877 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8879 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8880 && this_line_vpos
> 0)
8881 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8882 w
->window_end_valid
= Qnil
;
8884 /* Update hint: No need to try to scroll in update_window. */
8885 w
->desired_matrix
->no_scrolling_p
= 1;
8888 *w
->desired_matrix
->method
= 0;
8889 debug_method_add (w
, "optimization 1");
8896 else if (/* Cursor position hasn't changed. */
8897 PT
== XFASTINT (w
->last_point
)
8898 /* Make sure the cursor was last displayed
8899 in this window. Otherwise we have to reposition it. */
8900 && 0 <= w
->cursor
.vpos
8901 && XINT (w
->height
) > w
->cursor
.vpos
)
8905 do_pending_window_change (1);
8907 /* We used to always goto end_of_redisplay here, but this
8908 isn't enough if we have a blinking cursor. */
8909 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8910 goto end_of_redisplay
;
8914 /* If highlighting the region, or if the cursor is in the echo area,
8915 then we can't just move the cursor. */
8916 else if (! (!NILP (Vtransient_mark_mode
)
8917 && !NILP (current_buffer
->mark_active
))
8918 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8919 || highlight_nonselected_windows
)
8920 && NILP (w
->region_showing
)
8921 && NILP (Vshow_trailing_whitespace
)
8922 && !cursor_in_echo_area
)
8925 struct glyph_row
*row
;
8927 /* Skip from tlbufpos to PT and see where it is. Note that
8928 PT may be in invisible text. If so, we will end at the
8929 next visible position. */
8930 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8931 NULL
, DEFAULT_FACE_ID
);
8932 it
.current_x
= this_line_start_x
;
8933 it
.current_y
= this_line_y
;
8934 it
.vpos
= this_line_vpos
;
8936 /* The call to move_it_to stops in front of PT, but
8937 moves over before-strings. */
8938 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8940 if (it
.vpos
== this_line_vpos
8941 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8944 xassert (this_line_vpos
== it
.vpos
);
8945 xassert (this_line_y
== it
.current_y
);
8946 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8948 *w
->desired_matrix
->method
= 0;
8949 debug_method_add (w
, "optimization 3");
8958 /* Text changed drastically or point moved off of line. */
8959 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8962 CHARPOS (this_line_start_pos
) = 0;
8963 consider_all_windows_p
|= buffer_shared
> 1;
8964 ++clear_face_cache_count
;
8967 /* Build desired matrices, and update the display. If
8968 consider_all_windows_p is non-zero, do it for all windows on all
8969 frames. Otherwise do it for selected_window, only. */
8971 if (consider_all_windows_p
)
8973 Lisp_Object tail
, frame
;
8974 int i
, n
= 0, size
= 50;
8975 struct frame
**updated
8976 = (struct frame
**) alloca (size
* sizeof *updated
);
8978 /* Clear the face cache eventually. */
8979 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8981 clear_face_cache (0);
8982 clear_face_cache_count
= 0;
8985 /* Recompute # windows showing selected buffer. This will be
8986 incremented each time such a window is displayed. */
8989 FOR_EACH_FRAME (tail
, frame
)
8991 struct frame
*f
= XFRAME (frame
);
8993 if (FRAME_WINDOW_P (f
) || f
== sf
)
8995 #ifdef HAVE_WINDOW_SYSTEM
8996 if (clear_face_cache_count
% 50 == 0
8997 && FRAME_WINDOW_P (f
))
8998 clear_image_cache (f
, 0);
8999 #endif /* HAVE_WINDOW_SYSTEM */
9001 /* Mark all the scroll bars to be removed; we'll redeem
9002 the ones we want when we redisplay their windows. */
9003 if (condemn_scroll_bars_hook
)
9004 condemn_scroll_bars_hook (f
);
9006 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
9007 redisplay_windows (FRAME_ROOT_WINDOW (f
));
9009 /* Any scroll bars which redisplay_windows should have
9010 nuked should now go away. */
9011 if (judge_scroll_bars_hook
)
9012 judge_scroll_bars_hook (f
);
9014 /* If fonts changed, display again. */
9015 /* ??? rms: I suspect it is a mistake to jump all the way
9016 back to retry here. It should just retry this frame. */
9017 if (fonts_changed_p
)
9020 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
9022 /* See if we have to hscroll. */
9023 if (hscroll_windows (f
->root_window
))
9026 /* Prevent various kinds of signals during display
9027 update. stdio is not robust about handling
9028 signals, which can cause an apparent I/O
9030 if (interrupt_input
)
9034 /* Update the display. */
9035 set_window_update_flags (XWINDOW (f
->root_window
), 1);
9036 pause
|= update_frame (f
, 0, 0);
9042 int nbytes
= size
* sizeof *updated
;
9043 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
9044 bcopy (updated
, p
, nbytes
);
9053 /* Do the mark_window_display_accurate after all windows have
9054 been redisplayed because this call resets flags in buffers
9055 which are needed for proper redisplay. */
9056 for (i
= 0; i
< n
; ++i
)
9058 struct frame
*f
= updated
[i
];
9059 mark_window_display_accurate (f
->root_window
, 1);
9060 if (frame_up_to_date_hook
)
9061 frame_up_to_date_hook (f
);
9064 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9066 Lisp_Object mini_window
;
9067 struct frame
*mini_frame
;
9069 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9070 /* Use list_of_error, not Qerror, so that
9071 we catch only errors and don't run the debugger. */
9072 internal_condition_case_1 (redisplay_window_1
, selected_window
,
9074 redisplay_window_error
);
9076 /* Compare desired and current matrices, perform output. */
9079 /* If fonts changed, display again. */
9080 if (fonts_changed_p
)
9083 /* Prevent various kinds of signals during display update.
9084 stdio is not robust about handling signals,
9085 which can cause an apparent I/O error. */
9086 if (interrupt_input
)
9090 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9092 if (hscroll_windows (selected_window
))
9095 XWINDOW (selected_window
)->must_be_updated_p
= 1;
9096 pause
= update_frame (sf
, 0, 0);
9099 /* We may have called echo_area_display at the top of this
9100 function. If the echo area is on another frame, that may
9101 have put text on a frame other than the selected one, so the
9102 above call to update_frame would not have caught it. Catch
9104 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9105 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9107 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
9109 XWINDOW (mini_window
)->must_be_updated_p
= 1;
9110 pause
|= update_frame (mini_frame
, 0, 0);
9111 if (!pause
&& hscroll_windows (mini_window
))
9116 /* If display was paused because of pending input, make sure we do a
9117 thorough update the next time. */
9120 /* Prevent the optimization at the beginning of
9121 redisplay_internal that tries a single-line update of the
9122 line containing the cursor in the selected window. */
9123 CHARPOS (this_line_start_pos
) = 0;
9125 /* Let the overlay arrow be updated the next time. */
9126 if (!NILP (last_arrow_position
))
9128 last_arrow_position
= Qt
;
9129 last_arrow_string
= Qt
;
9132 /* If we pause after scrolling, some rows in the current
9133 matrices of some windows are not valid. */
9134 if (!WINDOW_FULL_WIDTH_P (w
)
9135 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
9136 update_mode_lines
= 1;
9140 if (!consider_all_windows_p
)
9142 /* This has already been done above if
9143 consider_all_windows_p is set. */
9144 mark_window_display_accurate_1 (w
, 1);
9146 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9147 last_arrow_string
= Voverlay_arrow_string
;
9149 if (frame_up_to_date_hook
!= 0)
9150 frame_up_to_date_hook (sf
);
9153 update_mode_lines
= 0;
9154 windows_or_buffers_changed
= 0;
9155 cursor_type_changed
= 0;
9158 /* Start SIGIO interrupts coming again. Having them off during the
9159 code above makes it less likely one will discard output, but not
9160 impossible, since there might be stuff in the system buffer here.
9161 But it is much hairier to try to do anything about that. */
9162 if (interrupt_input
)
9166 /* If a frame has become visible which was not before, redisplay
9167 again, so that we display it. Expose events for such a frame
9168 (which it gets when becoming visible) don't call the parts of
9169 redisplay constructing glyphs, so simply exposing a frame won't
9170 display anything in this case. So, we have to display these
9171 frames here explicitly. */
9174 Lisp_Object tail
, frame
;
9177 FOR_EACH_FRAME (tail
, frame
)
9179 int this_is_visible
= 0;
9181 if (XFRAME (frame
)->visible
)
9182 this_is_visible
= 1;
9183 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
9184 if (XFRAME (frame
)->visible
)
9185 this_is_visible
= 1;
9187 if (this_is_visible
)
9191 if (new_count
!= number_of_visible_frames
)
9192 windows_or_buffers_changed
++;
9195 /* Change frame size now if a change is pending. */
9196 do_pending_window_change (1);
9198 /* If we just did a pending size change, or have additional
9199 visible frames, redisplay again. */
9200 if (windows_or_buffers_changed
&& !pause
)
9204 unbind_to (count
, Qnil
);
9209 /* Redisplay, but leave alone any recent echo area message unless
9210 another message has been requested in its place.
9212 This is useful in situations where you need to redisplay but no
9213 user action has occurred, making it inappropriate for the message
9214 area to be cleared. See tracking_off and
9215 wait_reading_process_input for examples of these situations.
9217 FROM_WHERE is an integer saying from where this function was
9218 called. This is useful for debugging. */
9221 redisplay_preserve_echo_area (from_where
)
9224 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9226 if (!NILP (echo_area_buffer
[1]))
9228 /* We have a previously displayed message, but no current
9229 message. Redisplay the previous message. */
9230 display_last_displayed_message_p
= 1;
9231 redisplay_internal (1);
9232 display_last_displayed_message_p
= 0;
9235 redisplay_internal (1);
9239 /* Function registered with record_unwind_protect in
9240 redisplay_internal. Reset redisplaying_p to the value it had
9241 before redisplay_internal was called, and clear
9242 prevent_freeing_realized_faces_p. */
9245 unwind_redisplay (old_redisplaying_p
)
9246 Lisp_Object old_redisplaying_p
;
9248 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9253 /* Mark the display of window W as accurate or inaccurate. If
9254 ACCURATE_P is non-zero mark display of W as accurate. If
9255 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9256 redisplay_internal is called. */
9259 mark_window_display_accurate_1 (w
, accurate_p
)
9263 if (BUFFERP (w
->buffer
))
9265 struct buffer
*b
= XBUFFER (w
->buffer
);
9268 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9269 w
->last_overlay_modified
9270 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9272 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9276 b
->clip_changed
= 0;
9277 b
->prevent_redisplay_optimizations_p
= 0;
9279 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9280 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9281 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9282 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9284 w
->current_matrix
->buffer
= b
;
9285 w
->current_matrix
->begv
= BUF_BEGV (b
);
9286 w
->current_matrix
->zv
= BUF_ZV (b
);
9288 w
->last_cursor
= w
->cursor
;
9289 w
->last_cursor_off_p
= w
->cursor_off_p
;
9291 if (w
== XWINDOW (selected_window
))
9292 w
->last_point
= make_number (BUF_PT (b
));
9294 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9300 w
->window_end_valid
= w
->buffer
;
9301 #if 0 /* This is incorrect with variable-height lines. */
9302 xassert (XINT (w
->window_end_vpos
)
9304 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9306 w
->update_mode_line
= Qnil
;
9311 /* Mark the display of windows in the window tree rooted at WINDOW as
9312 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9313 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9314 be redisplayed the next time redisplay_internal is called. */
9317 mark_window_display_accurate (window
, accurate_p
)
9323 for (; !NILP (window
); window
= w
->next
)
9325 w
= XWINDOW (window
);
9326 mark_window_display_accurate_1 (w
, accurate_p
);
9328 if (!NILP (w
->vchild
))
9329 mark_window_display_accurate (w
->vchild
, accurate_p
);
9330 if (!NILP (w
->hchild
))
9331 mark_window_display_accurate (w
->hchild
, accurate_p
);
9336 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9337 last_arrow_string
= Voverlay_arrow_string
;
9341 /* Force a thorough redisplay the next time by setting
9342 last_arrow_position and last_arrow_string to t, which is
9343 unequal to any useful value of Voverlay_arrow_... */
9344 last_arrow_position
= Qt
;
9345 last_arrow_string
= Qt
;
9350 /* Return value in display table DP (Lisp_Char_Table *) for character
9351 C. Since a display table doesn't have any parent, we don't have to
9352 follow parent. Do not call this function directly but use the
9353 macro DISP_CHAR_VECTOR. */
9356 disp_char_vector (dp
, c
)
9357 struct Lisp_Char_Table
*dp
;
9363 if (SINGLE_BYTE_CHAR_P (c
))
9364 return (dp
->contents
[c
]);
9366 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9369 else if (code
[2] < 32)
9372 /* Here, the possible range of code[0] (== charset ID) is
9373 128..max_charset. Since the top level char table contains data
9374 for multibyte characters after 256th element, we must increment
9375 code[0] by 128 to get a correct index. */
9377 code
[3] = -1; /* anchor */
9379 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9381 val
= dp
->contents
[code
[i
]];
9382 if (!SUB_CHAR_TABLE_P (val
))
9383 return (NILP (val
) ? dp
->defalt
: val
);
9386 /* Here, val is a sub char table. We return the default value of
9388 return (dp
->defalt
);
9393 /***********************************************************************
9395 ***********************************************************************/
9397 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9400 redisplay_windows (window
)
9403 while (!NILP (window
))
9405 struct window
*w
= XWINDOW (window
);
9407 if (!NILP (w
->hchild
))
9408 redisplay_windows (w
->hchild
);
9409 else if (!NILP (w
->vchild
))
9410 redisplay_windows (w
->vchild
);
9413 displayed_buffer
= XBUFFER (w
->buffer
);
9414 /* Use list_of_error, not Qerror, so that
9415 we catch only errors and don't run the debugger. */
9416 internal_condition_case_1 (redisplay_window_0
, window
,
9418 redisplay_window_error
);
9426 redisplay_window_error ()
9428 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
9433 redisplay_window_0 (window
)
9436 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9437 redisplay_window (window
, 0);
9442 redisplay_window_1 (window
)
9445 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9446 redisplay_window (window
, 1);
9451 /* Increment GLYPH until it reaches END or CONDITION fails while
9452 adding (GLYPH)->pixel_width to X. */
9454 #define SKIP_GLYPHS(glyph, end, x, condition) \
9457 (x) += (glyph)->pixel_width; \
9460 while ((glyph) < (end) && (condition))
9463 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9464 DELTA is the number of bytes by which positions recorded in ROW
9465 differ from current buffer positions. */
9468 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9470 struct glyph_row
*row
;
9471 struct glyph_matrix
*matrix
;
9472 int delta
, delta_bytes
, dy
, dvpos
;
9474 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9475 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9476 /* The first glyph that starts a sequence of glyphs from string. */
9477 struct glyph
*string_start
;
9478 /* The X coordinate of string_start. */
9480 /* The last known character position. */
9481 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
9482 /* The last known character position before string_start. */
9483 int string_before_pos
;
9485 int pt_old
= PT
- delta
;
9487 /* Skip over glyphs not having an object at the start of the row.
9488 These are special glyphs like truncation marks on terminal
9490 if (row
->displays_text_p
)
9492 && INTEGERP (glyph
->object
)
9493 && glyph
->charpos
< 0)
9495 x
+= glyph
->pixel_width
;
9499 string_start
= NULL
;
9501 && !INTEGERP (glyph
->object
)
9502 && (!BUFFERP (glyph
->object
)
9503 || (last_pos
= glyph
->charpos
) < pt_old
))
9505 if (! STRINGP (glyph
->object
))
9507 string_start
= NULL
;
9508 x
+= glyph
->pixel_width
;
9513 string_before_pos
= last_pos
;
9514 string_start
= glyph
;
9516 /* Skip all glyphs from string. */
9517 SKIP_GLYPHS (glyph
, end
, x
, STRINGP (glyph
->object
));
9522 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
9524 /* We may have skipped over point because the previous glyphs
9525 are from string. As there's no easy way to know the
9526 character position of the current glyph, find the correct
9527 glyph on point by scanning from string_start again. */
9532 limit
= make_number (pt_old
+ 1);
9534 glyph
= string_start
;
9536 string
= glyph
->object
;
9537 pos
= string_buffer_position (w
, string
, string_before_pos
);
9538 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
9539 because we always put cursor after overlay strings. */
9540 while (pos
== 0 && glyph
< end
)
9542 string
= glyph
->object
;
9543 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
9545 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
9550 pos
= XINT (Fnext_single_char_property_change
9551 (make_number (pos
), Qdisplay
, Qnil
, limit
));
9554 /* Skip glyphs from the same string. */
9555 string
= glyph
->object
;
9556 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
9557 /* Skip glyphs from an overlay. */
9559 && ! string_buffer_position (w
, glyph
->object
, pos
))
9561 string
= glyph
->object
;
9562 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
9567 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9569 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9570 w
->cursor
.y
= row
->y
+ dy
;
9572 if (w
== XWINDOW (selected_window
))
9574 if (!row
->continued_p
9575 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9578 this_line_buffer
= XBUFFER (w
->buffer
);
9580 CHARPOS (this_line_start_pos
)
9581 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9582 BYTEPOS (this_line_start_pos
)
9583 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9585 CHARPOS (this_line_end_pos
)
9586 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9587 BYTEPOS (this_line_end_pos
)
9588 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9590 this_line_y
= w
->cursor
.y
;
9591 this_line_pixel_height
= row
->height
;
9592 this_line_vpos
= w
->cursor
.vpos
;
9593 this_line_start_x
= row
->x
;
9596 CHARPOS (this_line_start_pos
) = 0;
9601 /* Run window scroll functions, if any, for WINDOW with new window
9602 start STARTP. Sets the window start of WINDOW to that position.
9604 We assume that the window's buffer is really current. */
9606 static INLINE
struct text_pos
9607 run_window_scroll_functions (window
, startp
)
9609 struct text_pos startp
;
9611 struct window
*w
= XWINDOW (window
);
9612 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9614 if (current_buffer
!= XBUFFER (w
->buffer
))
9617 if (!NILP (Vwindow_scroll_functions
))
9619 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9620 make_number (CHARPOS (startp
)));
9621 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9622 /* In case the hook functions switch buffers. */
9623 if (current_buffer
!= XBUFFER (w
->buffer
))
9624 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9631 /* Make sure the line containing the cursor is fully visible.
9632 A value of 1 means there is nothing to be done.
9633 (Either the line is fully visible, or it cannot be made so,
9635 A value of 0 means the caller should do scrolling
9636 as if point had gone off the screen. */
9639 make_cursor_line_fully_visible (w
)
9642 struct glyph_matrix
*matrix
;
9643 struct glyph_row
*row
;
9646 /* It's not always possible to find the cursor, e.g, when a window
9647 is full of overlay strings. Don't do anything in that case. */
9648 if (w
->cursor
.vpos
< 0)
9651 matrix
= w
->desired_matrix
;
9652 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9654 /* If the cursor row is not partially visible, there's nothing to do. */
9655 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9658 /* If the row the cursor is in is taller than the window's height,
9659 it's not clear what to do, so do nothing. */
9660 window_height
= window_box_height (w
);
9661 if (row
->height
>= window_height
)
9667 /* This code used to try to scroll the window just enough to make
9668 the line visible. It returned 0 to say that the caller should
9669 allocate larger glyph matrices. */
9671 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9673 int dy
= row
->height
- row
->visible_height
;
9676 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9678 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9680 int dy
= - (row
->height
- row
->visible_height
);
9683 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9686 /* When we change the cursor y-position of the selected window,
9687 change this_line_y as well so that the display optimization for
9688 the cursor line of the selected window in redisplay_internal uses
9689 the correct y-position. */
9690 if (w
== XWINDOW (selected_window
))
9691 this_line_y
= w
->cursor
.y
;
9693 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9694 redisplay with larger matrices. */
9695 if (matrix
->nrows
< required_matrix_height (w
))
9697 fonts_changed_p
= 1;
9706 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9707 non-zero means only WINDOW is redisplayed in redisplay_internal.
9708 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9709 in redisplay_window to bring a partially visible line into view in
9710 the case that only the cursor has moved.
9712 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
9713 last screen line's vertical height extends past the end of the screen.
9717 1 if scrolling succeeded
9719 0 if scrolling didn't find point.
9721 -1 if new fonts have been loaded so that we must interrupt
9722 redisplay, adjust glyph matrices, and try again. */
9728 SCROLLING_NEED_LARGER_MATRICES
9732 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9733 scroll_step
, temp_scroll_step
, last_line_misfit
)
9735 int just_this_one_p
;
9736 EMACS_INT scroll_conservatively
, scroll_step
;
9737 int temp_scroll_step
;
9738 int last_line_misfit
;
9740 struct window
*w
= XWINDOW (window
);
9741 struct frame
*f
= XFRAME (w
->frame
);
9742 struct text_pos scroll_margin_pos
;
9743 struct text_pos pos
;
9744 struct text_pos startp
;
9746 Lisp_Object window_end
;
9747 int this_scroll_margin
;
9751 int amount_to_scroll
= 0;
9752 Lisp_Object aggressive
;
9754 int end_scroll_margin
;
9757 debug_method_add (w
, "try_scrolling");
9760 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9762 /* Compute scroll margin height in pixels. We scroll when point is
9763 within this distance from the top or bottom of the window. */
9764 if (scroll_margin
> 0)
9766 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9767 this_scroll_margin
*= CANON_Y_UNIT (f
);
9770 this_scroll_margin
= 0;
9772 /* Compute how much we should try to scroll maximally to bring point
9774 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9775 scroll_max
= max (scroll_step
,
9776 max (scroll_conservatively
, temp_scroll_step
));
9777 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9778 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9779 /* We're trying to scroll because of aggressive scrolling
9780 but no scroll_step is set. Choose an arbitrary one. Maybe
9781 there should be a variable for this. */
9785 scroll_max
*= CANON_Y_UNIT (f
);
9787 /* Decide whether we have to scroll down. Start at the window end
9788 and move this_scroll_margin up to find the position of the scroll
9790 window_end
= Fwindow_end (window
, Qt
);
9794 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9795 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9797 end_scroll_margin
= this_scroll_margin
+ !!last_line_misfit
;
9798 if (end_scroll_margin
)
9800 start_display (&it
, w
, scroll_margin_pos
);
9801 move_it_vertically (&it
, - end_scroll_margin
);
9802 scroll_margin_pos
= it
.current
.pos
;
9805 if (PT
>= CHARPOS (scroll_margin_pos
))
9809 /* Point is in the scroll margin at the bottom of the window, or
9810 below. Compute a new window start that makes point visible. */
9812 /* Compute the distance from the scroll margin to PT.
9813 Give up if the distance is greater than scroll_max. */
9814 start_display (&it
, w
, scroll_margin_pos
);
9816 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9817 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9819 /* To make point visible, we have to move the window start
9820 down so that the line the cursor is in is visible, which
9821 means we have to add in the height of the cursor line. */
9822 dy
= line_bottom_y (&it
) - y0
;
9824 if (dy
> scroll_max
)
9825 return SCROLLING_FAILED
;
9827 /* Move the window start down. If scrolling conservatively,
9828 move it just enough down to make point visible. If
9829 scroll_step is set, move it down by scroll_step. */
9830 start_display (&it
, w
, startp
);
9832 if (scroll_conservatively
)
9833 /* Set AMOUNT_TO_SCROLL to at least one line,
9834 and at most scroll_conservatively lines. */
9836 = min (max (dy
, CANON_Y_UNIT (f
)),
9837 CANON_Y_UNIT (f
) * scroll_conservatively
);
9838 else if (scroll_step
|| temp_scroll_step
)
9839 amount_to_scroll
= scroll_max
;
9842 aggressive
= current_buffer
->scroll_up_aggressively
;
9843 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9844 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9845 if (NUMBERP (aggressive
))
9846 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9849 if (amount_to_scroll
<= 0)
9850 return SCROLLING_FAILED
;
9852 /* If moving by amount_to_scroll leaves STARTP unchanged,
9853 move it down one screen line. */
9855 move_it_vertically (&it
, amount_to_scroll
);
9856 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
9857 move_it_by_lines (&it
, 1, 1);
9858 startp
= it
.current
.pos
;
9862 /* See if point is inside the scroll margin at the top of the
9864 scroll_margin_pos
= startp
;
9865 if (this_scroll_margin
)
9867 start_display (&it
, w
, startp
);
9868 move_it_vertically (&it
, this_scroll_margin
);
9869 scroll_margin_pos
= it
.current
.pos
;
9872 if (PT
< CHARPOS (scroll_margin_pos
))
9874 /* Point is in the scroll margin at the top of the window or
9875 above what is displayed in the window. */
9878 /* Compute the vertical distance from PT to the scroll
9879 margin position. Give up if distance is greater than
9881 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9882 start_display (&it
, w
, pos
);
9884 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9885 it
.last_visible_y
, -1,
9886 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9887 dy
= it
.current_y
- y0
;
9888 if (dy
> scroll_max
)
9889 return SCROLLING_FAILED
;
9891 /* Compute new window start. */
9892 start_display (&it
, w
, startp
);
9894 if (scroll_conservatively
)
9896 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9897 else if (scroll_step
|| temp_scroll_step
)
9898 amount_to_scroll
= scroll_max
;
9901 aggressive
= current_buffer
->scroll_down_aggressively
;
9902 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9903 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9904 if (NUMBERP (aggressive
))
9905 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9908 if (amount_to_scroll
<= 0)
9909 return SCROLLING_FAILED
;
9911 move_it_vertically (&it
, - amount_to_scroll
);
9912 startp
= it
.current
.pos
;
9916 /* Run window scroll functions. */
9917 startp
= run_window_scroll_functions (window
, startp
);
9919 /* Display the window. Give up if new fonts are loaded, or if point
9921 if (!try_window (window
, startp
))
9922 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9923 else if (w
->cursor
.vpos
< 0)
9925 clear_glyph_matrix (w
->desired_matrix
);
9926 rc
= SCROLLING_FAILED
;
9930 /* Maybe forget recorded base line for line number display. */
9931 if (!just_this_one_p
9932 || current_buffer
->clip_changed
9933 || BEG_UNCHANGED
< CHARPOS (startp
))
9934 w
->base_line_number
= Qnil
;
9936 /* If cursor ends up on a partially visible line,
9937 treat that as being off the bottom of the screen. */
9938 if (! make_cursor_line_fully_visible (w
))
9940 clear_glyph_matrix (w
->desired_matrix
);
9941 last_line_misfit
= 1;
9944 rc
= SCROLLING_SUCCESS
;
9951 /* Compute a suitable window start for window W if display of W starts
9952 on a continuation line. Value is non-zero if a new window start
9955 The new window start will be computed, based on W's width, starting
9956 from the start of the continued line. It is the start of the
9957 screen line with the minimum distance from the old start W->start. */
9960 compute_window_start_on_continuation_line (w
)
9963 struct text_pos pos
, start_pos
;
9964 int window_start_changed_p
= 0;
9966 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9968 /* If window start is on a continuation line... Window start may be
9969 < BEGV in case there's invisible text at the start of the
9970 buffer (M-x rmail, for example). */
9971 if (CHARPOS (start_pos
) > BEGV
9972 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9975 struct glyph_row
*row
;
9977 /* Handle the case that the window start is out of range. */
9978 if (CHARPOS (start_pos
) < BEGV
)
9979 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9980 else if (CHARPOS (start_pos
) > ZV
)
9981 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9983 /* Find the start of the continued line. This should be fast
9984 because scan_buffer is fast (newline cache). */
9985 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9986 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9987 row
, DEFAULT_FACE_ID
);
9988 reseat_at_previous_visible_line_start (&it
);
9990 /* If the line start is "too far" away from the window start,
9991 say it takes too much time to compute a new window start. */
9992 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9993 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9995 int min_distance
, distance
;
9997 /* Move forward by display lines to find the new window
9998 start. If window width was enlarged, the new start can
9999 be expected to be > the old start. If window width was
10000 decreased, the new window start will be < the old start.
10001 So, we're looking for the display line start with the
10002 minimum distance from the old window start. */
10003 pos
= it
.current
.pos
;
10004 min_distance
= INFINITY
;
10005 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
10006 distance
< min_distance
)
10008 min_distance
= distance
;
10009 pos
= it
.current
.pos
;
10010 move_it_by_lines (&it
, 1, 0);
10013 /* Set the window start there. */
10014 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
10015 window_start_changed_p
= 1;
10019 return window_start_changed_p
;
10023 /* Try cursor movement in case text has not changed in window WINDOW,
10024 with window start STARTP. Value is
10026 CURSOR_MOVEMENT_SUCCESS if successful
10028 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
10030 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
10031 display. *SCROLL_STEP is set to 1, under certain circumstances, if
10032 we want to scroll as if scroll-step were set to 1. See the code.
10034 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
10035 which case we have to abort this redisplay, and adjust matrices
10040 CURSOR_MOVEMENT_SUCCESS
,
10041 CURSOR_MOVEMENT_CANNOT_BE_USED
,
10042 CURSOR_MOVEMENT_MUST_SCROLL
,
10043 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
10047 try_cursor_movement (window
, startp
, scroll_step
)
10048 Lisp_Object window
;
10049 struct text_pos startp
;
10052 struct window
*w
= XWINDOW (window
);
10053 struct frame
*f
= XFRAME (w
->frame
);
10054 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
10057 if (inhibit_try_cursor_movement
)
10061 /* Handle case where text has not changed, only point, and it has
10062 not moved off the frame. */
10063 if (/* Point may be in this window. */
10064 PT
>= CHARPOS (startp
)
10065 /* Selective display hasn't changed. */
10066 && !current_buffer
->clip_changed
10067 /* Function force-mode-line-update is used to force a thorough
10068 redisplay. It sets either windows_or_buffers_changed or
10069 update_mode_lines. So don't take a shortcut here for these
10071 && !update_mode_lines
10072 && !windows_or_buffers_changed
10073 && !cursor_type_changed
10074 /* Can't use this case if highlighting a region. When a
10075 region exists, cursor movement has to do more than just
10077 && !(!NILP (Vtransient_mark_mode
)
10078 && !NILP (current_buffer
->mark_active
))
10079 && NILP (w
->region_showing
)
10080 && NILP (Vshow_trailing_whitespace
)
10081 /* Right after splitting windows, last_point may be nil. */
10082 && INTEGERP (w
->last_point
)
10083 /* This code is not used for mini-buffer for the sake of the case
10084 of redisplaying to replace an echo area message; since in
10085 that case the mini-buffer contents per se are usually
10086 unchanged. This code is of no real use in the mini-buffer
10087 since the handling of this_line_start_pos, etc., in redisplay
10088 handles the same cases. */
10089 && !EQ (window
, minibuf_window
)
10090 /* When splitting windows or for new windows, it happens that
10091 redisplay is called with a nil window_end_vpos or one being
10092 larger than the window. This should really be fixed in
10093 window.c. I don't have this on my list, now, so we do
10094 approximately the same as the old redisplay code. --gerd. */
10095 && INTEGERP (w
->window_end_vpos
)
10096 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
10097 && (FRAME_WINDOW_P (f
)
10098 || !MARKERP (Voverlay_arrow_position
)
10099 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
10101 int this_scroll_margin
;
10102 struct glyph_row
*row
= NULL
;
10105 debug_method_add (w
, "cursor movement");
10108 /* Scroll if point within this distance from the top or bottom
10109 of the window. This is a pixel value. */
10110 this_scroll_margin
= max (0, scroll_margin
);
10111 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
10112 this_scroll_margin
*= CANON_Y_UNIT (f
);
10114 /* Start with the row the cursor was displayed during the last
10115 not paused redisplay. Give up if that row is not valid. */
10116 if (w
->last_cursor
.vpos
< 0
10117 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
10118 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10121 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
10122 if (row
->mode_line_p
)
10124 if (!row
->enabled_p
)
10125 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10128 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
10131 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
10133 if (PT
> XFASTINT (w
->last_point
))
10135 /* Point has moved forward. */
10136 while (MATRIX_ROW_END_CHARPOS (row
) < PT
10137 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
10139 xassert (row
->enabled_p
);
10143 /* The end position of a row equals the start position
10144 of the next row. If PT is there, we would rather
10145 display it in the next line. */
10146 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
10147 && MATRIX_ROW_END_CHARPOS (row
) == PT
10148 && !cursor_row_p (w
, row
))
10151 /* If within the scroll margin, scroll. Note that
10152 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
10153 the next line would be drawn, and that
10154 this_scroll_margin can be zero. */
10155 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
10156 || PT
> MATRIX_ROW_END_CHARPOS (row
)
10157 /* Line is completely visible last line in window
10158 and PT is to be set in the next line. */
10159 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
10160 && PT
== MATRIX_ROW_END_CHARPOS (row
)
10161 && !row
->ends_at_zv_p
10162 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
10165 else if (PT
< XFASTINT (w
->last_point
))
10167 /* Cursor has to be moved backward. Note that PT >=
10168 CHARPOS (startp) because of the outer
10170 while (!row
->mode_line_p
10171 && (MATRIX_ROW_START_CHARPOS (row
) > PT
10172 || (MATRIX_ROW_START_CHARPOS (row
) == PT
10173 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
10174 && (row
->y
> this_scroll_margin
10175 || CHARPOS (startp
) == BEGV
))
10177 xassert (row
->enabled_p
);
10181 /* Consider the following case: Window starts at BEGV,
10182 there is invisible, intangible text at BEGV, so that
10183 display starts at some point START > BEGV. It can
10184 happen that we are called with PT somewhere between
10185 BEGV and START. Try to handle that case. */
10186 if (row
< w
->current_matrix
->rows
10187 || row
->mode_line_p
)
10189 row
= w
->current_matrix
->rows
;
10190 if (row
->mode_line_p
)
10194 /* Due to newlines in overlay strings, we may have to
10195 skip forward over overlay strings. */
10196 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
10197 && MATRIX_ROW_END_CHARPOS (row
) == PT
10198 && !cursor_row_p (w
, row
))
10201 /* If within the scroll margin, scroll. */
10202 if (row
->y
< this_scroll_margin
10203 && CHARPOS (startp
) != BEGV
)
10207 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
10208 || PT
> MATRIX_ROW_END_CHARPOS (row
))
10210 /* if PT is not in the glyph row, give up. */
10211 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10213 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10215 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
10216 && !row
->ends_at_zv_p
10217 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
10218 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10219 else if (row
->height
> window_box_height (w
))
10221 /* If we end up in a partially visible line, let's
10222 make it fully visible, except when it's taller
10223 than the window, in which case we can't do much
10226 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10230 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10231 if (!make_cursor_line_fully_visible (w
))
10232 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10234 rc
= CURSOR_MOVEMENT_SUCCESS
;
10238 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10241 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10242 rc
= CURSOR_MOVEMENT_SUCCESS
;
10251 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
10252 selected_window is redisplayed.
10254 We can return without actually redisplaying the window if
10255 fonts_changed_p is nonzero. In that case, redisplay_internal will
10259 redisplay_window (window
, just_this_one_p
)
10260 Lisp_Object window
;
10261 int just_this_one_p
;
10263 struct window
*w
= XWINDOW (window
);
10264 struct frame
*f
= XFRAME (w
->frame
);
10265 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10266 struct buffer
*old
= current_buffer
;
10267 struct text_pos lpoint
, opoint
, startp
;
10268 int update_mode_line
;
10271 /* Record it now because it's overwritten. */
10272 int current_matrix_up_to_date_p
= 0;
10273 /* This is less strict than current_matrix_up_to_date_p.
10274 It indictes that the buffer contents and narrowing are unchanged. */
10275 int buffer_unchanged_p
= 0;
10276 int temp_scroll_step
= 0;
10277 int count
= SPECPDL_INDEX ();
10279 int centering_position
;
10280 int last_line_misfit
= 0;
10282 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10285 /* W must be a leaf window here. */
10286 xassert (!NILP (w
->buffer
));
10288 *w
->desired_matrix
->method
= 0;
10291 specbind (Qinhibit_point_motion_hooks
, Qt
);
10293 reconsider_clip_changes (w
, buffer
);
10295 /* Has the mode line to be updated? */
10296 update_mode_line
= (!NILP (w
->update_mode_line
)
10297 || update_mode_lines
10298 || buffer
->clip_changed
10299 || buffer
->prevent_redisplay_optimizations_p
);
10301 if (MINI_WINDOW_P (w
))
10303 if (w
== XWINDOW (echo_area_window
)
10304 && !NILP (echo_area_buffer
[0]))
10306 if (update_mode_line
)
10307 /* We may have to update a tty frame's menu bar or a
10308 tool-bar. Example `M-x C-h C-h C-g'. */
10309 goto finish_menu_bars
;
10311 /* We've already displayed the echo area glyphs in this window. */
10312 goto finish_scroll_bars
;
10314 else if ((w
!= XWINDOW (minibuf_window
)
10315 || minibuf_level
== 0)
10316 /* Quail displays non-mini buffers in minibuffer window.
10317 In that case, redisplay the window normally. */
10318 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
10320 /* W is a mini-buffer window, but it's not active, so clear
10322 int yb
= window_text_bottom_y (w
);
10323 struct glyph_row
*row
;
10326 for (y
= 0, row
= w
->desired_matrix
->rows
;
10328 y
+= row
->height
, ++row
)
10329 blank_row (w
, row
, y
);
10330 goto finish_scroll_bars
;
10333 clear_glyph_matrix (w
->desired_matrix
);
10336 /* Otherwise set up data on this window; select its buffer and point
10338 /* Really select the buffer, for the sake of buffer-local
10340 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10341 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
10343 current_matrix_up_to_date_p
10344 = (!NILP (w
->window_end_valid
)
10345 && !current_buffer
->clip_changed
10346 && !current_buffer
->prevent_redisplay_optimizations_p
10347 && XFASTINT (w
->last_modified
) >= MODIFF
10348 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10351 = (!NILP (w
->window_end_valid
)
10352 && !current_buffer
->clip_changed
10353 && XFASTINT (w
->last_modified
) >= MODIFF
10354 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10356 /* When windows_or_buffers_changed is non-zero, we can't rely on
10357 the window end being valid, so set it to nil there. */
10358 if (windows_or_buffers_changed
)
10360 /* If window starts on a continuation line, maybe adjust the
10361 window start in case the window's width changed. */
10362 if (XMARKER (w
->start
)->buffer
== current_buffer
)
10363 compute_window_start_on_continuation_line (w
);
10365 w
->window_end_valid
= Qnil
;
10368 /* Some sanity checks. */
10369 CHECK_WINDOW_END (w
);
10370 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
10372 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
10375 /* If %c is in mode line, update it if needed. */
10376 if (!NILP (w
->column_number_displayed
)
10377 /* This alternative quickly identifies a common case
10378 where no change is needed. */
10379 && !(PT
== XFASTINT (w
->last_point
)
10380 && XFASTINT (w
->last_modified
) >= MODIFF
10381 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10382 && (XFASTINT (w
->column_number_displayed
)
10383 != (int) current_column ())) /* iftc */
10384 update_mode_line
= 1;
10386 /* Count number of windows showing the selected buffer. An indirect
10387 buffer counts as its base buffer. */
10388 if (!just_this_one_p
)
10390 struct buffer
*current_base
, *window_base
;
10391 current_base
= current_buffer
;
10392 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10393 if (current_base
->base_buffer
)
10394 current_base
= current_base
->base_buffer
;
10395 if (window_base
->base_buffer
)
10396 window_base
= window_base
->base_buffer
;
10397 if (current_base
== window_base
)
10401 /* Point refers normally to the selected window. For any other
10402 window, set up appropriate value. */
10403 if (!EQ (window
, selected_window
))
10405 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10406 int new_pt_byte
= marker_byte_position (w
->pointm
);
10410 new_pt_byte
= BEGV_BYTE
;
10411 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10413 else if (new_pt
> (ZV
- 1))
10416 new_pt_byte
= ZV_BYTE
;
10417 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10420 /* We don't use SET_PT so that the point-motion hooks don't run. */
10421 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10424 /* If any of the character widths specified in the display table
10425 have changed, invalidate the width run cache. It's true that
10426 this may be a bit late to catch such changes, but the rest of
10427 redisplay goes (non-fatally) haywire when the display table is
10428 changed, so why should we worry about doing any better? */
10429 if (current_buffer
->width_run_cache
)
10431 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10433 if (! disptab_matches_widthtab (disptab
,
10434 XVECTOR (current_buffer
->width_table
)))
10436 invalidate_region_cache (current_buffer
,
10437 current_buffer
->width_run_cache
,
10439 recompute_width_table (current_buffer
, disptab
);
10443 /* If window-start is screwed up, choose a new one. */
10444 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10447 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10449 /* If someone specified a new starting point but did not insist,
10450 check whether it can be used. */
10451 if (!NILP (w
->optional_new_start
)
10452 && CHARPOS (startp
) >= BEGV
10453 && CHARPOS (startp
) <= ZV
)
10455 w
->optional_new_start
= Qnil
;
10456 start_display (&it
, w
, startp
);
10457 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10458 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10459 if (IT_CHARPOS (it
) == PT
)
10460 w
->force_start
= Qt
;
10463 /* Handle case where place to start displaying has been specified,
10464 unless the specified location is outside the accessible range. */
10465 if (!NILP (w
->force_start
)
10466 || w
->frozen_window_start_p
)
10468 /* We set this later on if we have to adjust point. */
10471 w
->force_start
= Qnil
;
10473 w
->window_end_valid
= Qnil
;
10475 /* Forget any recorded base line for line number display. */
10476 if (!buffer_unchanged_p
)
10477 w
->base_line_number
= Qnil
;
10479 /* Redisplay the mode line. Select the buffer properly for that.
10480 Also, run the hook window-scroll-functions
10481 because we have scrolled. */
10482 /* Note, we do this after clearing force_start because
10483 if there's an error, it is better to forget about force_start
10484 than to get into an infinite loop calling the hook functions
10485 and having them get more errors. */
10486 if (!update_mode_line
10487 || ! NILP (Vwindow_scroll_functions
))
10489 update_mode_line
= 1;
10490 w
->update_mode_line
= Qt
;
10491 startp
= run_window_scroll_functions (window
, startp
);
10494 w
->last_modified
= make_number (0);
10495 w
->last_overlay_modified
= make_number (0);
10496 if (CHARPOS (startp
) < BEGV
)
10497 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10498 else if (CHARPOS (startp
) > ZV
)
10499 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10501 /* Redisplay, then check if cursor has been set during the
10502 redisplay. Give up if new fonts were loaded. */
10503 if (!try_window (window
, startp
))
10505 w
->force_start
= Qt
;
10506 clear_glyph_matrix (w
->desired_matrix
);
10507 goto need_larger_matrices
;
10510 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10512 /* If point does not appear, try to move point so it does
10513 appear. The desired matrix has been built above, so we
10514 can use it here. */
10515 new_vpos
= window_box_height (w
) / 2;
10518 if (!make_cursor_line_fully_visible (w
))
10520 /* Point does appear, but on a line partly visible at end of window.
10521 Move it back to a fully-visible line. */
10522 new_vpos
= window_box_height (w
);
10525 /* If we need to move point for either of the above reasons,
10526 now actually do it. */
10529 struct glyph_row
*row
;
10531 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10532 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
10535 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10536 MATRIX_ROW_START_BYTEPOS (row
));
10538 if (w
!= XWINDOW (selected_window
))
10539 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10540 else if (current_buffer
== old
)
10541 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10543 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10545 /* If we are highlighting the region, then we just changed
10546 the region, so redisplay to show it. */
10547 if (!NILP (Vtransient_mark_mode
)
10548 && !NILP (current_buffer
->mark_active
))
10550 clear_glyph_matrix (w
->desired_matrix
);
10551 if (!try_window (window
, startp
))
10552 goto need_larger_matrices
;
10557 debug_method_add (w
, "forced window start");
10562 /* Handle case where text has not changed, only point, and it has
10563 not moved off the frame, and we are not retrying after hscroll.
10564 (current_matrix_up_to_date_p is nonzero when retrying.) */
10565 if (current_matrix_up_to_date_p
10566 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10567 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10571 case CURSOR_MOVEMENT_SUCCESS
:
10574 #if 0 /* try_cursor_movement never returns this value. */
10575 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10576 goto need_larger_matrices
;
10579 case CURSOR_MOVEMENT_MUST_SCROLL
:
10580 goto try_to_scroll
;
10586 /* If current starting point was originally the beginning of a line
10587 but no longer is, find a new starting point. */
10588 else if (!NILP (w
->start_at_line_beg
)
10589 && !(CHARPOS (startp
) <= BEGV
10590 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10593 debug_method_add (w
, "recenter 1");
10598 /* Try scrolling with try_window_id. Value is > 0 if update has
10599 been done, it is -1 if we know that the same window start will
10600 not work. It is 0 if unsuccessful for some other reason. */
10601 else if ((tem
= try_window_id (w
)) != 0)
10604 debug_method_add (w
, "try_window_id %d", tem
);
10607 if (fonts_changed_p
)
10608 goto need_larger_matrices
;
10612 /* Otherwise try_window_id has returned -1 which means that we
10613 don't want the alternative below this comment to execute. */
10615 else if (CHARPOS (startp
) >= BEGV
10616 && CHARPOS (startp
) <= ZV
10617 && PT
>= CHARPOS (startp
)
10618 && (CHARPOS (startp
) < ZV
10619 /* Avoid starting at end of buffer. */
10620 || CHARPOS (startp
) == BEGV
10621 || (XFASTINT (w
->last_modified
) >= MODIFF
10622 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10625 debug_method_add (w
, "same window start");
10628 /* Try to redisplay starting at same place as before.
10629 If point has not moved off frame, accept the results. */
10630 if (!current_matrix_up_to_date_p
10631 /* Don't use try_window_reusing_current_matrix in this case
10632 because a window scroll function can have changed the
10634 || !NILP (Vwindow_scroll_functions
)
10635 || MINI_WINDOW_P (w
)
10636 || !try_window_reusing_current_matrix (w
))
10638 IF_DEBUG (debug_method_add (w
, "1"));
10639 try_window (window
, startp
);
10642 if (fonts_changed_p
)
10643 goto need_larger_matrices
;
10645 if (w
->cursor
.vpos
>= 0)
10647 if (!just_this_one_p
10648 || current_buffer
->clip_changed
10649 || BEG_UNCHANGED
< CHARPOS (startp
))
10650 /* Forget any recorded base line for line number display. */
10651 w
->base_line_number
= Qnil
;
10653 if (!make_cursor_line_fully_visible (w
))
10655 clear_glyph_matrix (w
->desired_matrix
);
10656 last_line_misfit
= 1;
10658 /* Drop through and scroll. */
10663 clear_glyph_matrix (w
->desired_matrix
);
10668 w
->last_modified
= make_number (0);
10669 w
->last_overlay_modified
= make_number (0);
10671 /* Redisplay the mode line. Select the buffer properly for that. */
10672 if (!update_mode_line
)
10674 update_mode_line
= 1;
10675 w
->update_mode_line
= Qt
;
10678 /* Try to scroll by specified few lines. */
10679 if ((scroll_conservatively
10681 || temp_scroll_step
10682 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10683 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10684 && !current_buffer
->clip_changed
10685 && CHARPOS (startp
) >= BEGV
10686 && CHARPOS (startp
) <= ZV
)
10688 /* The function returns -1 if new fonts were loaded, 1 if
10689 successful, 0 if not successful. */
10690 int rc
= try_scrolling (window
, just_this_one_p
,
10691 scroll_conservatively
,
10693 temp_scroll_step
, last_line_misfit
);
10696 case SCROLLING_SUCCESS
:
10699 case SCROLLING_NEED_LARGER_MATRICES
:
10700 goto need_larger_matrices
;
10702 case SCROLLING_FAILED
:
10710 /* Finally, just choose place to start which centers point */
10713 centering_position
= window_box_height (w
) / 2;
10716 /* Jump here with centering_position already set to 0. */
10719 debug_method_add (w
, "recenter");
10722 /* w->vscroll = 0; */
10724 /* Forget any previously recorded base line for line number display. */
10725 if (!buffer_unchanged_p
)
10726 w
->base_line_number
= Qnil
;
10728 /* Move backward half the height of the window. */
10729 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10730 it
.current_y
= it
.last_visible_y
;
10731 move_it_vertically_backward (&it
, centering_position
);
10732 xassert (IT_CHARPOS (it
) >= BEGV
);
10734 /* The function move_it_vertically_backward may move over more
10735 than the specified y-distance. If it->w is small, e.g. a
10736 mini-buffer window, we may end up in front of the window's
10737 display area. Start displaying at the start of the line
10738 containing PT in this case. */
10739 if (it
.current_y
<= 0)
10741 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10742 move_it_vertically (&it
, 0);
10743 xassert (IT_CHARPOS (it
) <= PT
);
10747 it
.current_x
= it
.hpos
= 0;
10749 /* Set startp here explicitly in case that helps avoid an infinite loop
10750 in case the window-scroll-functions functions get errors. */
10751 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10753 /* Run scroll hooks. */
10754 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10756 /* Redisplay the window. */
10757 if (!current_matrix_up_to_date_p
10758 || windows_or_buffers_changed
10759 || cursor_type_changed
10760 /* Don't use try_window_reusing_current_matrix in this case
10761 because it can have changed the buffer. */
10762 || !NILP (Vwindow_scroll_functions
)
10763 || !just_this_one_p
10764 || MINI_WINDOW_P (w
)
10765 || !try_window_reusing_current_matrix (w
))
10766 try_window (window
, startp
);
10768 /* If new fonts have been loaded (due to fontsets), give up. We
10769 have to start a new redisplay since we need to re-adjust glyph
10771 if (fonts_changed_p
)
10772 goto need_larger_matrices
;
10774 /* If cursor did not appear assume that the middle of the window is
10775 in the first line of the window. Do it again with the next line.
10776 (Imagine a window of height 100, displaying two lines of height
10777 60. Moving back 50 from it->last_visible_y will end in the first
10779 if (w
->cursor
.vpos
< 0)
10781 if (!NILP (w
->window_end_valid
)
10782 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10784 clear_glyph_matrix (w
->desired_matrix
);
10785 move_it_by_lines (&it
, 1, 0);
10786 try_window (window
, it
.current
.pos
);
10788 else if (PT
< IT_CHARPOS (it
))
10790 clear_glyph_matrix (w
->desired_matrix
);
10791 move_it_by_lines (&it
, -1, 0);
10792 try_window (window
, it
.current
.pos
);
10796 /* Not much we can do about it. */
10800 /* Consider the following case: Window starts at BEGV, there is
10801 invisible, intangible text at BEGV, so that display starts at
10802 some point START > BEGV. It can happen that we are called with
10803 PT somewhere between BEGV and START. Try to handle that case. */
10804 if (w
->cursor
.vpos
< 0)
10806 struct glyph_row
*row
= w
->current_matrix
->rows
;
10807 if (row
->mode_line_p
)
10809 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10812 if (!make_cursor_line_fully_visible (w
))
10814 /* If centering point failed to make the whole line visible,
10815 put point at the top instead. That has to make the whole line
10816 visible, if it can be done. */
10817 centering_position
= 0;
10823 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10824 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10825 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10828 /* Display the mode line, if we must. */
10829 if ((update_mode_line
10830 /* If window not full width, must redo its mode line
10831 if (a) the window to its side is being redone and
10832 (b) we do a frame-based redisplay. This is a consequence
10833 of how inverted lines are drawn in frame-based redisplay. */
10834 || (!just_this_one_p
10835 && !FRAME_WINDOW_P (f
)
10836 && !WINDOW_FULL_WIDTH_P (w
))
10837 /* Line number to display. */
10838 || INTEGERP (w
->base_line_pos
)
10839 /* Column number is displayed and different from the one displayed. */
10840 || (!NILP (w
->column_number_displayed
)
10841 && (XFASTINT (w
->column_number_displayed
)
10842 != (int) current_column ()))) /* iftc */
10843 /* This means that the window has a mode line. */
10844 && (WINDOW_WANTS_MODELINE_P (w
)
10845 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10847 display_mode_lines (w
);
10849 /* If mode line height has changed, arrange for a thorough
10850 immediate redisplay using the correct mode line height. */
10851 if (WINDOW_WANTS_MODELINE_P (w
)
10852 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10854 fonts_changed_p
= 1;
10855 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10856 = DESIRED_MODE_LINE_HEIGHT (w
);
10859 /* If top line height has changed, arrange for a thorough
10860 immediate redisplay using the correct mode line height. */
10861 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10862 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10864 fonts_changed_p
= 1;
10865 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10866 = DESIRED_HEADER_LINE_HEIGHT (w
);
10869 if (fonts_changed_p
)
10870 goto need_larger_matrices
;
10873 if (!line_number_displayed
10874 && !BUFFERP (w
->base_line_pos
))
10876 w
->base_line_pos
= Qnil
;
10877 w
->base_line_number
= Qnil
;
10882 /* When we reach a frame's selected window, redo the frame's menu bar. */
10883 if (update_mode_line
10884 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10886 int redisplay_menu_p
= 0;
10887 int redisplay_tool_bar_p
= 0;
10889 if (FRAME_WINDOW_P (f
))
10891 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
10892 || defined (USE_GTK)
10893 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10895 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10899 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10901 if (redisplay_menu_p
)
10902 display_menu_bar (w
);
10904 #ifdef HAVE_WINDOW_SYSTEM
10906 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
10908 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
10909 && (FRAME_TOOL_BAR_LINES (f
) > 0
10910 || auto_resize_tool_bars_p
);
10914 if (redisplay_tool_bar_p
)
10915 redisplay_tool_bar (f
);
10919 /* We go to this label, with fonts_changed_p nonzero,
10920 if it is necessary to try again using larger glyph matrices.
10921 We have to redeem the scroll bar even in this case,
10922 because the loop in redisplay_internal expects that. */
10923 need_larger_matrices
:
10925 finish_scroll_bars
:
10927 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10929 int start
, end
, whole
;
10931 /* Calculate the start and end positions for the current window.
10932 At some point, it would be nice to choose between scrollbars
10933 which reflect the whole buffer size, with special markers
10934 indicating narrowing, and scrollbars which reflect only the
10937 Note that mini-buffers sometimes aren't displaying any text. */
10938 if (!MINI_WINDOW_P (w
)
10939 || (w
== XWINDOW (minibuf_window
)
10940 && NILP (echo_area_buffer
[0])))
10943 start
= marker_position (w
->start
) - BEGV
;
10944 /* I don't think this is guaranteed to be right. For the
10945 moment, we'll pretend it is. */
10946 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10950 if (whole
< (end
- start
))
10951 whole
= end
- start
;
10954 start
= end
= whole
= 0;
10956 /* Indicate what this scroll bar ought to be displaying now. */
10957 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10959 /* Note that we actually used the scroll bar attached to this
10960 window, so it shouldn't be deleted at the end of redisplay. */
10961 redeem_scroll_bar_hook (w
);
10964 /* Restore current_buffer and value of point in it. */
10965 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10966 set_buffer_internal_1 (old
);
10967 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10969 unbind_to (count
, Qnil
);
10973 /* Build the complete desired matrix of WINDOW with a window start
10974 buffer position POS. Value is non-zero if successful. It is zero
10975 if fonts were loaded during redisplay which makes re-adjusting
10976 glyph matrices necessary. */
10979 try_window (window
, pos
)
10980 Lisp_Object window
;
10981 struct text_pos pos
;
10983 struct window
*w
= XWINDOW (window
);
10985 struct glyph_row
*last_text_row
= NULL
;
10987 /* Make POS the new window start. */
10988 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10990 /* Mark cursor position as unknown. No overlay arrow seen. */
10991 w
->cursor
.vpos
= -1;
10992 overlay_arrow_seen
= 0;
10994 /* Initialize iterator and info to start at POS. */
10995 start_display (&it
, w
, pos
);
10997 /* Display all lines of W. */
10998 while (it
.current_y
< it
.last_visible_y
)
11000 if (display_line (&it
))
11001 last_text_row
= it
.glyph_row
- 1;
11002 if (fonts_changed_p
)
11006 /* If bottom moved off end of frame, change mode line percentage. */
11007 if (XFASTINT (w
->window_end_pos
) <= 0
11008 && Z
!= IT_CHARPOS (it
))
11009 w
->update_mode_line
= Qt
;
11011 /* Set window_end_pos to the offset of the last character displayed
11012 on the window from the end of current_buffer. Set
11013 window_end_vpos to its row number. */
11016 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
11017 w
->window_end_bytepos
11018 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11020 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11022 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11023 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
11024 ->displays_text_p
);
11028 w
->window_end_bytepos
= 0;
11029 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
11032 /* But that is not valid info until redisplay finishes. */
11033 w
->window_end_valid
= Qnil
;
11039 /************************************************************************
11040 Window redisplay reusing current matrix when buffer has not changed
11041 ************************************************************************/
11043 /* Try redisplay of window W showing an unchanged buffer with a
11044 different window start than the last time it was displayed by
11045 reusing its current matrix. Value is non-zero if successful.
11046 W->start is the new window start. */
11049 try_window_reusing_current_matrix (w
)
11052 struct frame
*f
= XFRAME (w
->frame
);
11053 struct glyph_row
*row
, *bottom_row
;
11056 struct text_pos start
, new_start
;
11057 int nrows_scrolled
, i
;
11058 struct glyph_row
*last_text_row
;
11059 struct glyph_row
*last_reused_text_row
;
11060 struct glyph_row
*start_row
;
11061 int start_vpos
, min_y
, max_y
;
11064 if (inhibit_try_window_reusing
)
11068 if (/* This function doesn't handle terminal frames. */
11069 !FRAME_WINDOW_P (f
)
11070 /* Don't try to reuse the display if windows have been split
11072 || windows_or_buffers_changed
11073 || cursor_type_changed
)
11076 /* Can't do this if region may have changed. */
11077 if ((!NILP (Vtransient_mark_mode
)
11078 && !NILP (current_buffer
->mark_active
))
11079 || !NILP (w
->region_showing
)
11080 || !NILP (Vshow_trailing_whitespace
))
11083 /* If top-line visibility has changed, give up. */
11084 if (WINDOW_WANTS_HEADER_LINE_P (w
)
11085 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
11088 /* Give up if old or new display is scrolled vertically. We could
11089 make this function handle this, but right now it doesn't. */
11090 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11091 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
11094 /* The variable new_start now holds the new window start. The old
11095 start `start' can be determined from the current matrix. */
11096 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
11097 start
= start_row
->start
.pos
;
11098 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
11100 /* Clear the desired matrix for the display below. */
11101 clear_glyph_matrix (w
->desired_matrix
);
11103 if (CHARPOS (new_start
) <= CHARPOS (start
))
11107 /* Don't use this method if the display starts with an ellipsis
11108 displayed for invisible text. It's not easy to handle that case
11109 below, and it's certainly not worth the effort since this is
11110 not a frequent case. */
11111 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
11114 IF_DEBUG (debug_method_add (w
, "twu1"));
11116 /* Display up to a row that can be reused. The variable
11117 last_text_row is set to the last row displayed that displays
11118 text. Note that it.vpos == 0 if or if not there is a
11119 header-line; it's not the same as the MATRIX_ROW_VPOS! */
11120 start_display (&it
, w
, new_start
);
11121 first_row_y
= it
.current_y
;
11122 w
->cursor
.vpos
= -1;
11123 last_text_row
= last_reused_text_row
= NULL
;
11125 while (it
.current_y
< it
.last_visible_y
11126 && IT_CHARPOS (it
) < CHARPOS (start
)
11127 && !fonts_changed_p
)
11128 if (display_line (&it
))
11129 last_text_row
= it
.glyph_row
- 1;
11131 /* A value of current_y < last_visible_y means that we stopped
11132 at the previous window start, which in turn means that we
11133 have at least one reusable row. */
11134 if (it
.current_y
< it
.last_visible_y
)
11136 /* IT.vpos always starts from 0; it counts text lines. */
11137 nrows_scrolled
= it
.vpos
;
11139 /* Find PT if not already found in the lines displayed. */
11140 if (w
->cursor
.vpos
< 0)
11142 int dy
= it
.current_y
- first_row_y
;
11144 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11145 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
11147 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
11148 dy
, nrows_scrolled
);
11151 clear_glyph_matrix (w
->desired_matrix
);
11156 /* Scroll the display. Do it before the current matrix is
11157 changed. The problem here is that update has not yet
11158 run, i.e. part of the current matrix is not up to date.
11159 scroll_run_hook will clear the cursor, and use the
11160 current matrix to get the height of the row the cursor is
11162 run
.current_y
= first_row_y
;
11163 run
.desired_y
= it
.current_y
;
11164 run
.height
= it
.last_visible_y
- it
.current_y
;
11166 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
11169 rif
->update_window_begin_hook (w
);
11170 rif
->clear_mouse_face (w
);
11171 rif
->scroll_run_hook (w
, &run
);
11172 rif
->update_window_end_hook (w
, 0, 0);
11176 /* Shift current matrix down by nrows_scrolled lines. */
11177 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11178 rotate_matrix (w
->current_matrix
,
11180 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11183 /* Disable lines that must be updated. */
11184 for (i
= 0; i
< it
.vpos
; ++i
)
11185 (start_row
+ i
)->enabled_p
= 0;
11187 /* Re-compute Y positions. */
11188 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11189 max_y
= it
.last_visible_y
;
11190 for (row
= start_row
+ nrows_scrolled
;
11194 row
->y
= it
.current_y
;
11195 row
->visible_height
= row
->height
;
11197 if (row
->y
< min_y
)
11198 row
->visible_height
-= min_y
- row
->y
;
11199 if (row
->y
+ row
->height
> max_y
)
11200 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11202 it
.current_y
+= row
->height
;
11204 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11205 last_reused_text_row
= row
;
11206 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
11210 /* Disable lines in the current matrix which are now
11211 below the window. */
11212 for (++row
; row
< bottom_row
; ++row
)
11213 row
->enabled_p
= 0;
11216 /* Update window_end_pos etc.; last_reused_text_row is the last
11217 reused row from the current matrix containing text, if any.
11218 The value of last_text_row is the last displayed line
11219 containing text. */
11220 if (last_reused_text_row
)
11222 w
->window_end_bytepos
11223 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
11225 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
11227 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
11228 w
->current_matrix
));
11230 else if (last_text_row
)
11232 w
->window_end_bytepos
11233 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11235 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11237 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11241 /* This window must be completely empty. */
11242 w
->window_end_bytepos
= 0;
11243 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
11245 w
->window_end_valid
= Qnil
;
11247 /* Update hint: don't try scrolling again in update_window. */
11248 w
->desired_matrix
->no_scrolling_p
= 1;
11251 debug_method_add (w
, "try_window_reusing_current_matrix 1");
11255 else if (CHARPOS (new_start
) > CHARPOS (start
))
11257 struct glyph_row
*pt_row
, *row
;
11258 struct glyph_row
*first_reusable_row
;
11259 struct glyph_row
*first_row_to_display
;
11261 int yb
= window_text_bottom_y (w
);
11263 /* Find the row starting at new_start, if there is one. Don't
11264 reuse a partially visible line at the end. */
11265 first_reusable_row
= start_row
;
11266 while (first_reusable_row
->enabled_p
11267 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
11268 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11269 < CHARPOS (new_start
)))
11270 ++first_reusable_row
;
11272 /* Give up if there is no row to reuse. */
11273 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
11274 || !first_reusable_row
->enabled_p
11275 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11276 != CHARPOS (new_start
)))
11279 /* We can reuse fully visible rows beginning with
11280 first_reusable_row to the end of the window. Set
11281 first_row_to_display to the first row that cannot be reused.
11282 Set pt_row to the row containing point, if there is any. */
11284 for (first_row_to_display
= first_reusable_row
;
11285 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
11286 ++first_row_to_display
)
11288 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
11289 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
11290 pt_row
= first_row_to_display
;
11293 /* Start displaying at the start of first_row_to_display. */
11294 xassert (first_row_to_display
->y
< yb
);
11295 init_to_row_start (&it
, w
, first_row_to_display
);
11297 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
11299 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
11301 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
11302 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
11304 /* Display lines beginning with first_row_to_display in the
11305 desired matrix. Set last_text_row to the last row displayed
11306 that displays text. */
11307 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
11308 if (pt_row
== NULL
)
11309 w
->cursor
.vpos
= -1;
11310 last_text_row
= NULL
;
11311 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
11312 if (display_line (&it
))
11313 last_text_row
= it
.glyph_row
- 1;
11315 /* Give up If point isn't in a row displayed or reused. */
11316 if (w
->cursor
.vpos
< 0)
11318 clear_glyph_matrix (w
->desired_matrix
);
11322 /* If point is in a reused row, adjust y and vpos of the cursor
11326 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
11327 w
->current_matrix
);
11328 w
->cursor
.y
-= first_reusable_row
->y
;
11331 /* Scroll the display. */
11332 run
.current_y
= first_reusable_row
->y
;
11333 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11334 run
.height
= it
.last_visible_y
- run
.current_y
;
11335 dy
= run
.current_y
- run
.desired_y
;
11339 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11341 rif
->update_window_begin_hook (w
);
11342 rif
->clear_mouse_face (w
);
11343 rif
->scroll_run_hook (w
, &run
);
11344 rif
->update_window_end_hook (w
, 0, 0);
11348 /* Adjust Y positions of reused rows. */
11349 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11350 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11351 max_y
= it
.last_visible_y
;
11352 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
11355 row
->visible_height
= row
->height
;
11356 if (row
->y
< min_y
)
11357 row
->visible_height
-= min_y
- row
->y
;
11358 if (row
->y
+ row
->height
> max_y
)
11359 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11362 /* Scroll the current matrix. */
11363 xassert (nrows_scrolled
> 0);
11364 rotate_matrix (w
->current_matrix
,
11366 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11369 /* Disable rows not reused. */
11370 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
11371 row
->enabled_p
= 0;
11373 /* Adjust window end. A null value of last_text_row means that
11374 the window end is in reused rows which in turn means that
11375 only its vpos can have changed. */
11378 w
->window_end_bytepos
11379 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11381 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11383 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11388 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
11391 w
->window_end_valid
= Qnil
;
11392 w
->desired_matrix
->no_scrolling_p
= 1;
11395 debug_method_add (w
, "try_window_reusing_current_matrix 2");
11405 /************************************************************************
11406 Window redisplay reusing current matrix when buffer has changed
11407 ************************************************************************/
11409 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
11410 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
11412 static struct glyph_row
*
11413 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
11414 struct glyph_row
*));
11417 /* Return the last row in MATRIX displaying text. If row START is
11418 non-null, start searching with that row. IT gives the dimensions
11419 of the display. Value is null if matrix is empty; otherwise it is
11420 a pointer to the row found. */
11422 static struct glyph_row
*
11423 find_last_row_displaying_text (matrix
, it
, start
)
11424 struct glyph_matrix
*matrix
;
11426 struct glyph_row
*start
;
11428 struct glyph_row
*row
, *row_found
;
11430 /* Set row_found to the last row in IT->w's current matrix
11431 displaying text. The loop looks funny but think of partially
11434 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11435 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11437 xassert (row
->enabled_p
);
11439 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11448 /* Return the last row in the current matrix of W that is not affected
11449 by changes at the start of current_buffer that occurred since W's
11450 current matrix was built. Value is null if no such row exists.
11452 BEG_UNCHANGED us the number of characters unchanged at the start of
11453 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11454 first changed character in current_buffer. Characters at positions <
11455 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11456 when the current matrix was built. */
11458 static struct glyph_row
*
11459 find_last_unchanged_at_beg_row (w
)
11462 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11463 struct glyph_row
*row
;
11464 struct glyph_row
*row_found
= NULL
;
11465 int yb
= window_text_bottom_y (w
);
11467 /* Find the last row displaying unchanged text. */
11468 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11469 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11470 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11472 if (/* If row ends before first_changed_pos, it is unchanged,
11473 except in some case. */
11474 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11475 /* When row ends in ZV and we write at ZV it is not
11477 && !row
->ends_at_zv_p
11478 /* When first_changed_pos is the end of a continued line,
11479 row is not unchanged because it may be no longer
11481 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11482 && row
->continued_p
))
11485 /* Stop if last visible row. */
11486 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11496 /* Find the first glyph row in the current matrix of W that is not
11497 affected by changes at the end of current_buffer since the
11498 time W's current matrix was built.
11500 Return in *DELTA the number of chars by which buffer positions in
11501 unchanged text at the end of current_buffer must be adjusted.
11503 Return in *DELTA_BYTES the corresponding number of bytes.
11505 Value is null if no such row exists, i.e. all rows are affected by
11508 static struct glyph_row
*
11509 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11511 int *delta
, *delta_bytes
;
11513 struct glyph_row
*row
;
11514 struct glyph_row
*row_found
= NULL
;
11516 *delta
= *delta_bytes
= 0;
11518 /* Display must not have been paused, otherwise the current matrix
11519 is not up to date. */
11520 if (NILP (w
->window_end_valid
))
11523 /* A value of window_end_pos >= END_UNCHANGED means that the window
11524 end is in the range of changed text. If so, there is no
11525 unchanged row at the end of W's current matrix. */
11526 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11529 /* Set row to the last row in W's current matrix displaying text. */
11530 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11532 /* If matrix is entirely empty, no unchanged row exists. */
11533 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11535 /* The value of row is the last glyph row in the matrix having a
11536 meaningful buffer position in it. The end position of row
11537 corresponds to window_end_pos. This allows us to translate
11538 buffer positions in the current matrix to current buffer
11539 positions for characters not in changed text. */
11540 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11541 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11542 int last_unchanged_pos
, last_unchanged_pos_old
;
11543 struct glyph_row
*first_text_row
11544 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11546 *delta
= Z
- Z_old
;
11547 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11549 /* Set last_unchanged_pos to the buffer position of the last
11550 character in the buffer that has not been changed. Z is the
11551 index + 1 of the last character in current_buffer, i.e. by
11552 subtracting END_UNCHANGED we get the index of the last
11553 unchanged character, and we have to add BEG to get its buffer
11555 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11556 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11558 /* Search backward from ROW for a row displaying a line that
11559 starts at a minimum position >= last_unchanged_pos_old. */
11560 for (; row
> first_text_row
; --row
)
11562 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11565 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11570 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11577 /* Make sure that glyph rows in the current matrix of window W
11578 reference the same glyph memory as corresponding rows in the
11579 frame's frame matrix. This function is called after scrolling W's
11580 current matrix on a terminal frame in try_window_id and
11581 try_window_reusing_current_matrix. */
11584 sync_frame_with_window_matrix_rows (w
)
11587 struct frame
*f
= XFRAME (w
->frame
);
11588 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11590 /* Preconditions: W must be a leaf window and full-width. Its frame
11591 must have a frame matrix. */
11592 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11593 xassert (WINDOW_FULL_WIDTH_P (w
));
11594 xassert (!FRAME_WINDOW_P (f
));
11596 /* If W is a full-width window, glyph pointers in W's current matrix
11597 have, by definition, to be the same as glyph pointers in the
11598 corresponding frame matrix. Note that frame matrices have no
11599 marginal areas (see build_frame_matrix). */
11600 window_row
= w
->current_matrix
->rows
;
11601 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11602 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11603 while (window_row
< window_row_end
)
11605 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
11606 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
11608 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
11609 frame_row
->glyphs
[TEXT_AREA
] = start
;
11610 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
11611 frame_row
->glyphs
[LAST_AREA
] = end
;
11613 /* Disable frame rows whose corresponding window rows have
11614 been disabled in try_window_id. */
11615 if (!window_row
->enabled_p
)
11616 frame_row
->enabled_p
= 0;
11618 ++window_row
, ++frame_row
;
11623 /* Find the glyph row in window W containing CHARPOS. Consider all
11624 rows between START and END (not inclusive). END null means search
11625 all rows to the end of the display area of W. Value is the row
11626 containing CHARPOS or null. */
11629 row_containing_pos (w
, charpos
, start
, end
, dy
)
11632 struct glyph_row
*start
, *end
;
11635 struct glyph_row
*row
= start
;
11638 /* If we happen to start on a header-line, skip that. */
11639 if (row
->mode_line_p
)
11642 if ((end
&& row
>= end
) || !row
->enabled_p
)
11645 last_y
= window_text_bottom_y (w
) - dy
;
11649 /* Give up if we have gone too far. */
11650 if (end
&& row
>= end
)
11652 /* This formerly returned if they were equal.
11653 I think that both quantities are of a "last plus one" type;
11654 if so, when they are equal, the row is within the screen. -- rms. */
11655 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
11658 /* If it is in this row, return this row. */
11659 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
11660 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11661 /* The end position of a row equals the start
11662 position of the next row. If CHARPOS is there, we
11663 would rather display it in the next line, except
11664 when this line ends in ZV. */
11665 && !row
->ends_at_zv_p
11666 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11667 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
11674 /* Try to redisplay window W by reusing its existing display. W's
11675 current matrix must be up to date when this function is called,
11676 i.e. window_end_valid must not be nil.
11680 1 if display has been updated
11681 0 if otherwise unsuccessful
11682 -1 if redisplay with same window start is known not to succeed
11684 The following steps are performed:
11686 1. Find the last row in the current matrix of W that is not
11687 affected by changes at the start of current_buffer. If no such row
11690 2. Find the first row in W's current matrix that is not affected by
11691 changes at the end of current_buffer. Maybe there is no such row.
11693 3. Display lines beginning with the row + 1 found in step 1 to the
11694 row found in step 2 or, if step 2 didn't find a row, to the end of
11697 4. If cursor is not known to appear on the window, give up.
11699 5. If display stopped at the row found in step 2, scroll the
11700 display and current matrix as needed.
11702 6. Maybe display some lines at the end of W, if we must. This can
11703 happen under various circumstances, like a partially visible line
11704 becoming fully visible, or because newly displayed lines are displayed
11705 in smaller font sizes.
11707 7. Update W's window end information. */
11713 struct frame
*f
= XFRAME (w
->frame
);
11714 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11715 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11716 struct glyph_row
*last_unchanged_at_beg_row
;
11717 struct glyph_row
*first_unchanged_at_end_row
;
11718 struct glyph_row
*row
;
11719 struct glyph_row
*bottom_row
;
11722 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11723 struct text_pos start_pos
;
11725 int first_unchanged_at_end_vpos
= 0;
11726 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11727 struct text_pos start
;
11728 int first_changed_charpos
, last_changed_charpos
;
11731 if (inhibit_try_window_id
)
11735 /* This is handy for debugging. */
11737 #define GIVE_UP(X) \
11739 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11743 #define GIVE_UP(X) return 0
11746 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11748 /* Don't use this for mini-windows because these can show
11749 messages and mini-buffers, and we don't handle that here. */
11750 if (MINI_WINDOW_P (w
))
11753 /* This flag is used to prevent redisplay optimizations. */
11754 if (windows_or_buffers_changed
|| cursor_type_changed
)
11757 /* Verify that narrowing has not changed.
11758 Also verify that we were not told to prevent redisplay optimizations.
11759 It would be nice to further
11760 reduce the number of cases where this prevents try_window_id. */
11761 if (current_buffer
->clip_changed
11762 || current_buffer
->prevent_redisplay_optimizations_p
)
11765 /* Window must either use window-based redisplay or be full width. */
11766 if (!FRAME_WINDOW_P (f
)
11767 && (!line_ins_del_ok
11768 || !WINDOW_FULL_WIDTH_P (w
)))
11771 /* Give up if point is not known NOT to appear in W. */
11772 if (PT
< CHARPOS (start
))
11775 /* Another way to prevent redisplay optimizations. */
11776 if (XFASTINT (w
->last_modified
) == 0)
11779 /* Verify that window is not hscrolled. */
11780 if (XFASTINT (w
->hscroll
) != 0)
11783 /* Verify that display wasn't paused. */
11784 if (NILP (w
->window_end_valid
))
11787 /* Can't use this if highlighting a region because a cursor movement
11788 will do more than just set the cursor. */
11789 if (!NILP (Vtransient_mark_mode
)
11790 && !NILP (current_buffer
->mark_active
))
11793 /* Likewise if highlighting trailing whitespace. */
11794 if (!NILP (Vshow_trailing_whitespace
))
11797 /* Likewise if showing a region. */
11798 if (!NILP (w
->region_showing
))
11801 /* Can use this if overlay arrow position and or string have changed. */
11802 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11803 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11807 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11808 only if buffer has really changed. The reason is that the gap is
11809 initially at Z for freshly visited files. The code below would
11810 set end_unchanged to 0 in that case. */
11811 if (MODIFF
> SAVE_MODIFF
11812 /* This seems to happen sometimes after saving a buffer. */
11813 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11815 if (GPT
- BEG
< BEG_UNCHANGED
)
11816 BEG_UNCHANGED
= GPT
- BEG
;
11817 if (Z
- GPT
< END_UNCHANGED
)
11818 END_UNCHANGED
= Z
- GPT
;
11821 /* The position of the first and last character that has been changed. */
11822 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11823 last_changed_charpos
= Z
- END_UNCHANGED
;
11825 /* If window starts after a line end, and the last change is in
11826 front of that newline, then changes don't affect the display.
11827 This case happens with stealth-fontification. Note that although
11828 the display is unchanged, glyph positions in the matrix have to
11829 be adjusted, of course. */
11830 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11831 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11832 && ((last_changed_charpos
< CHARPOS (start
)
11833 && CHARPOS (start
) == BEGV
)
11834 || (last_changed_charpos
< CHARPOS (start
) - 1
11835 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11837 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11838 struct glyph_row
*r0
;
11840 /* Compute how many chars/bytes have been added to or removed
11841 from the buffer. */
11842 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11843 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11845 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11847 /* Give up if PT is not in the window. Note that it already has
11848 been checked at the start of try_window_id that PT is not in
11849 front of the window start. */
11850 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11853 /* If window start is unchanged, we can reuse the whole matrix
11854 as is, after adjusting glyph positions. No need to compute
11855 the window end again, since its offset from Z hasn't changed. */
11856 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11857 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11858 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11860 /* Adjust positions in the glyph matrix. */
11861 if (delta
|| delta_bytes
)
11863 struct glyph_row
*r1
11864 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11865 increment_matrix_positions (w
->current_matrix
,
11866 MATRIX_ROW_VPOS (r0
, current_matrix
),
11867 MATRIX_ROW_VPOS (r1
, current_matrix
),
11868 delta
, delta_bytes
);
11871 /* Set the cursor. */
11872 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11874 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11881 /* Handle the case that changes are all below what is displayed in
11882 the window, and that PT is in the window. This shortcut cannot
11883 be taken if ZV is visible in the window, and text has been added
11884 there that is visible in the window. */
11885 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11886 /* ZV is not visible in the window, or there are no
11887 changes at ZV, actually. */
11888 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11889 || first_changed_charpos
== last_changed_charpos
))
11891 struct glyph_row
*r0
;
11893 /* Give up if PT is not in the window. Note that it already has
11894 been checked at the start of try_window_id that PT is not in
11895 front of the window start. */
11896 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11899 /* If window start is unchanged, we can reuse the whole matrix
11900 as is, without changing glyph positions since no text has
11901 been added/removed in front of the window end. */
11902 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11903 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11905 /* We have to compute the window end anew since text
11906 can have been added/removed after it. */
11908 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11909 w
->window_end_bytepos
11910 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11912 /* Set the cursor. */
11913 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11915 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11922 /* Give up if window start is in the changed area.
11924 The condition used to read
11926 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11928 but why that was tested escapes me at the moment. */
11929 if (CHARPOS (start
) >= first_changed_charpos
11930 && CHARPOS (start
) <= last_changed_charpos
)
11933 /* Check that window start agrees with the start of the first glyph
11934 row in its current matrix. Check this after we know the window
11935 start is not in changed text, otherwise positions would not be
11937 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11938 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11941 /* Give up if the window ends in strings. Overlay strings
11942 at the end are difficult to handle, so don't try. */
11943 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
11944 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
11947 /* Compute the position at which we have to start displaying new
11948 lines. Some of the lines at the top of the window might be
11949 reusable because they are not displaying changed text. Find the
11950 last row in W's current matrix not affected by changes at the
11951 start of current_buffer. Value is null if changes start in the
11952 first line of window. */
11953 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11954 if (last_unchanged_at_beg_row
)
11956 /* Avoid starting to display in the moddle of a character, a TAB
11957 for instance. This is easier than to set up the iterator
11958 exactly, and it's not a frequent case, so the additional
11959 effort wouldn't really pay off. */
11960 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11961 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
11962 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11963 --last_unchanged_at_beg_row
;
11965 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11968 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11970 start_pos
= it
.current
.pos
;
11972 /* Start displaying new lines in the desired matrix at the same
11973 vpos we would use in the current matrix, i.e. below
11974 last_unchanged_at_beg_row. */
11975 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11977 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11978 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11980 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11984 /* There are no reusable lines at the start of the window.
11985 Start displaying in the first line. */
11986 start_display (&it
, w
, start
);
11987 start_pos
= it
.current
.pos
;
11990 /* Find the first row that is not affected by changes at the end of
11991 the buffer. Value will be null if there is no unchanged row, in
11992 which case we must redisplay to the end of the window. delta
11993 will be set to the value by which buffer positions beginning with
11994 first_unchanged_at_end_row have to be adjusted due to text
11996 first_unchanged_at_end_row
11997 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11998 IF_DEBUG (debug_delta
= delta
);
11999 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
12001 /* Set stop_pos to the buffer position up to which we will have to
12002 display new lines. If first_unchanged_at_end_row != NULL, this
12003 is the buffer position of the start of the line displayed in that
12004 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
12005 that we don't stop at a buffer position. */
12007 if (first_unchanged_at_end_row
)
12009 xassert (last_unchanged_at_beg_row
== NULL
12010 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
12012 /* If this is a continuation line, move forward to the next one
12013 that isn't. Changes in lines above affect this line.
12014 Caution: this may move first_unchanged_at_end_row to a row
12015 not displaying text. */
12016 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
12017 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
12018 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
12019 < it
.last_visible_y
))
12020 ++first_unchanged_at_end_row
;
12022 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
12023 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
12024 >= it
.last_visible_y
))
12025 first_unchanged_at_end_row
= NULL
;
12028 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
12030 first_unchanged_at_end_vpos
12031 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
12032 xassert (stop_pos
>= Z
- END_UNCHANGED
);
12035 else if (last_unchanged_at_beg_row
== NULL
)
12041 /* Either there is no unchanged row at the end, or the one we have
12042 now displays text. This is a necessary condition for the window
12043 end pos calculation at the end of this function. */
12044 xassert (first_unchanged_at_end_row
== NULL
12045 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
12047 debug_last_unchanged_at_beg_vpos
12048 = (last_unchanged_at_beg_row
12049 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
12051 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
12053 #endif /* GLYPH_DEBUG != 0 */
12056 /* Display new lines. Set last_text_row to the last new line
12057 displayed which has text on it, i.e. might end up as being the
12058 line where the window_end_vpos is. */
12059 w
->cursor
.vpos
= -1;
12060 last_text_row
= NULL
;
12061 overlay_arrow_seen
= 0;
12062 while (it
.current_y
< it
.last_visible_y
12063 && !fonts_changed_p
12064 && (first_unchanged_at_end_row
== NULL
12065 || IT_CHARPOS (it
) < stop_pos
))
12067 if (display_line (&it
))
12068 last_text_row
= it
.glyph_row
- 1;
12071 if (fonts_changed_p
)
12075 /* Compute differences in buffer positions, y-positions etc. for
12076 lines reused at the bottom of the window. Compute what we can
12078 if (first_unchanged_at_end_row
12079 /* No lines reused because we displayed everything up to the
12080 bottom of the window. */
12081 && it
.current_y
< it
.last_visible_y
)
12084 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
12086 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
12087 run
.current_y
= first_unchanged_at_end_row
->y
;
12088 run
.desired_y
= run
.current_y
+ dy
;
12089 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
12093 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
12094 first_unchanged_at_end_row
= NULL
;
12096 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
12099 /* Find the cursor if not already found. We have to decide whether
12100 PT will appear on this window (it sometimes doesn't, but this is
12101 not a very frequent case.) This decision has to be made before
12102 the current matrix is altered. A value of cursor.vpos < 0 means
12103 that PT is either in one of the lines beginning at
12104 first_unchanged_at_end_row or below the window. Don't care for
12105 lines that might be displayed later at the window end; as
12106 mentioned, this is not a frequent case. */
12107 if (w
->cursor
.vpos
< 0)
12109 /* Cursor in unchanged rows at the top? */
12110 if (PT
< CHARPOS (start_pos
)
12111 && last_unchanged_at_beg_row
)
12113 row
= row_containing_pos (w
, PT
,
12114 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
12115 last_unchanged_at_beg_row
+ 1, 0);
12117 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12120 /* Start from first_unchanged_at_end_row looking for PT. */
12121 else if (first_unchanged_at_end_row
)
12123 row
= row_containing_pos (w
, PT
- delta
,
12124 first_unchanged_at_end_row
, NULL
, 0);
12126 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
12127 delta_bytes
, dy
, dvpos
);
12130 /* Give up if cursor was not found. */
12131 if (w
->cursor
.vpos
< 0)
12133 clear_glyph_matrix (w
->desired_matrix
);
12138 /* Don't let the cursor end in the scroll margins. */
12140 int this_scroll_margin
, cursor_height
;
12142 this_scroll_margin
= max (0, scroll_margin
);
12143 this_scroll_margin
= min (this_scroll_margin
,
12144 XFASTINT (w
->height
) / 4);
12145 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
12146 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
12148 if ((w
->cursor
.y
< this_scroll_margin
12149 && CHARPOS (start
) > BEGV
)
12150 /* Don't take scroll margin into account at the bottom because
12151 old redisplay didn't do it either. */
12152 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
12154 w
->cursor
.vpos
= -1;
12155 clear_glyph_matrix (w
->desired_matrix
);
12160 /* Scroll the display. Do it before changing the current matrix so
12161 that xterm.c doesn't get confused about where the cursor glyph is
12163 if (dy
&& run
.height
)
12167 if (FRAME_WINDOW_P (f
))
12169 rif
->update_window_begin_hook (w
);
12170 rif
->clear_mouse_face (w
);
12171 rif
->scroll_run_hook (w
, &run
);
12172 rif
->update_window_end_hook (w
, 0, 0);
12176 /* Terminal frame. In this case, dvpos gives the number of
12177 lines to scroll by; dvpos < 0 means scroll up. */
12178 int first_unchanged_at_end_vpos
12179 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
12180 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
12181 int end
= (XFASTINT (w
->top
)
12182 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
12183 + window_internal_height (w
));
12185 /* Perform the operation on the screen. */
12188 /* Scroll last_unchanged_at_beg_row to the end of the
12189 window down dvpos lines. */
12190 set_terminal_window (end
);
12192 /* On dumb terminals delete dvpos lines at the end
12193 before inserting dvpos empty lines. */
12194 if (!scroll_region_ok
)
12195 ins_del_lines (end
- dvpos
, -dvpos
);
12197 /* Insert dvpos empty lines in front of
12198 last_unchanged_at_beg_row. */
12199 ins_del_lines (from
, dvpos
);
12201 else if (dvpos
< 0)
12203 /* Scroll up last_unchanged_at_beg_vpos to the end of
12204 the window to last_unchanged_at_beg_vpos - |dvpos|. */
12205 set_terminal_window (end
);
12207 /* Delete dvpos lines in front of
12208 last_unchanged_at_beg_vpos. ins_del_lines will set
12209 the cursor to the given vpos and emit |dvpos| delete
12211 ins_del_lines (from
+ dvpos
, dvpos
);
12213 /* On a dumb terminal insert dvpos empty lines at the
12215 if (!scroll_region_ok
)
12216 ins_del_lines (end
+ dvpos
, -dvpos
);
12219 set_terminal_window (0);
12225 /* Shift reused rows of the current matrix to the right position.
12226 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
12228 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
12229 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
12232 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
12233 bottom_vpos
, dvpos
);
12234 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
12237 else if (dvpos
> 0)
12239 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
12240 bottom_vpos
, dvpos
);
12241 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
12242 first_unchanged_at_end_vpos
+ dvpos
, 0);
12245 /* For frame-based redisplay, make sure that current frame and window
12246 matrix are in sync with respect to glyph memory. */
12247 if (!FRAME_WINDOW_P (f
))
12248 sync_frame_with_window_matrix_rows (w
);
12250 /* Adjust buffer positions in reused rows. */
12252 increment_matrix_positions (current_matrix
,
12253 first_unchanged_at_end_vpos
+ dvpos
,
12254 bottom_vpos
, delta
, delta_bytes
);
12256 /* Adjust Y positions. */
12258 shift_glyph_matrix (w
, current_matrix
,
12259 first_unchanged_at_end_vpos
+ dvpos
,
12262 if (first_unchanged_at_end_row
)
12263 first_unchanged_at_end_row
+= dvpos
;
12265 /* If scrolling up, there may be some lines to display at the end of
12267 last_text_row_at_end
= NULL
;
12270 /* Scrolling up can leave for example a partially visible line
12271 at the end of the window to be redisplayed. */
12272 /* Set last_row to the glyph row in the current matrix where the
12273 window end line is found. It has been moved up or down in
12274 the matrix by dvpos. */
12275 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
12276 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
12278 /* If last_row is the window end line, it should display text. */
12279 xassert (last_row
->displays_text_p
);
12281 /* If window end line was partially visible before, begin
12282 displaying at that line. Otherwise begin displaying with the
12283 line following it. */
12284 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
12286 init_to_row_start (&it
, w
, last_row
);
12287 it
.vpos
= last_vpos
;
12288 it
.current_y
= last_row
->y
;
12292 init_to_row_end (&it
, w
, last_row
);
12293 it
.vpos
= 1 + last_vpos
;
12294 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
12298 /* We may start in a continuation line. If so, we have to
12299 get the right continuation_lines_width and current_x. */
12300 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
12301 it
.hpos
= it
.current_x
= 0;
12303 /* Display the rest of the lines at the window end. */
12304 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
12305 while (it
.current_y
< it
.last_visible_y
12306 && !fonts_changed_p
)
12308 /* Is it always sure that the display agrees with lines in
12309 the current matrix? I don't think so, so we mark rows
12310 displayed invalid in the current matrix by setting their
12311 enabled_p flag to zero. */
12312 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
12313 if (display_line (&it
))
12314 last_text_row_at_end
= it
.glyph_row
- 1;
12318 /* Update window_end_pos and window_end_vpos. */
12319 if (first_unchanged_at_end_row
12320 && first_unchanged_at_end_row
->y
< it
.last_visible_y
12321 && !last_text_row_at_end
)
12323 /* Window end line if one of the preserved rows from the current
12324 matrix. Set row to the last row displaying text in current
12325 matrix starting at first_unchanged_at_end_row, after
12327 xassert (first_unchanged_at_end_row
->displays_text_p
);
12328 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
12329 first_unchanged_at_end_row
);
12330 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
12332 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12333 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12335 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
12336 xassert (w
->window_end_bytepos
>= 0);
12337 IF_DEBUG (debug_method_add (w
, "A"));
12339 else if (last_text_row_at_end
)
12342 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
12343 w
->window_end_bytepos
12344 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
12346 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
12347 xassert (w
->window_end_bytepos
>= 0);
12348 IF_DEBUG (debug_method_add (w
, "B"));
12350 else if (last_text_row
)
12352 /* We have displayed either to the end of the window or at the
12353 end of the window, i.e. the last row with text is to be found
12354 in the desired matrix. */
12356 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12357 w
->window_end_bytepos
12358 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12360 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
12361 xassert (w
->window_end_bytepos
>= 0);
12363 else if (first_unchanged_at_end_row
== NULL
12364 && last_text_row
== NULL
12365 && last_text_row_at_end
== NULL
)
12367 /* Displayed to end of window, but no line containing text was
12368 displayed. Lines were deleted at the end of the window. */
12369 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
12370 int vpos
= XFASTINT (w
->window_end_vpos
);
12371 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
12372 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
12375 row
== NULL
&& vpos
>= first_vpos
;
12376 --vpos
, --current_row
, --desired_row
)
12378 if (desired_row
->enabled_p
)
12380 if (desired_row
->displays_text_p
)
12383 else if (current_row
->displays_text_p
)
12387 xassert (row
!= NULL
);
12388 w
->window_end_vpos
= make_number (vpos
+ 1);
12389 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12390 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12391 xassert (w
->window_end_bytepos
>= 0);
12392 IF_DEBUG (debug_method_add (w
, "C"));
12397 #if 0 /* This leads to problems, for instance when the cursor is
12398 at ZV, and the cursor line displays no text. */
12399 /* Disable rows below what's displayed in the window. This makes
12400 debugging easier. */
12401 enable_glyph_matrix_rows (current_matrix
,
12402 XFASTINT (w
->window_end_vpos
) + 1,
12406 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
12407 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
12409 /* Record that display has not been completed. */
12410 w
->window_end_valid
= Qnil
;
12411 w
->desired_matrix
->no_scrolling_p
= 1;
12419 /***********************************************************************
12420 More debugging support
12421 ***********************************************************************/
12425 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
12426 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
12427 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
12430 /* Dump the contents of glyph matrix MATRIX on stderr.
12432 GLYPHS 0 means don't show glyph contents.
12433 GLYPHS 1 means show glyphs in short form
12434 GLYPHS > 1 means show glyphs in long form. */
12437 dump_glyph_matrix (matrix
, glyphs
)
12438 struct glyph_matrix
*matrix
;
12442 for (i
= 0; i
< matrix
->nrows
; ++i
)
12443 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12447 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12448 the glyph row and area where the glyph comes from. */
12451 dump_glyph (row
, glyph
, area
)
12452 struct glyph_row
*row
;
12453 struct glyph
*glyph
;
12456 if (glyph
->type
== CHAR_GLYPH
)
12459 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12460 glyph
- row
->glyphs
[TEXT_AREA
],
12463 (BUFFERP (glyph
->object
)
12465 : (STRINGP (glyph
->object
)
12468 glyph
->pixel_width
,
12470 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12474 glyph
->left_box_line_p
,
12475 glyph
->right_box_line_p
);
12477 else if (glyph
->type
== STRETCH_GLYPH
)
12480 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12481 glyph
- row
->glyphs
[TEXT_AREA
],
12484 (BUFFERP (glyph
->object
)
12486 : (STRINGP (glyph
->object
)
12489 glyph
->pixel_width
,
12493 glyph
->left_box_line_p
,
12494 glyph
->right_box_line_p
);
12496 else if (glyph
->type
== IMAGE_GLYPH
)
12499 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12500 glyph
- row
->glyphs
[TEXT_AREA
],
12503 (BUFFERP (glyph
->object
)
12505 : (STRINGP (glyph
->object
)
12508 glyph
->pixel_width
,
12512 glyph
->left_box_line_p
,
12513 glyph
->right_box_line_p
);
12518 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12519 GLYPHS 0 means don't show glyph contents.
12520 GLYPHS 1 means show glyphs in short form
12521 GLYPHS > 1 means show glyphs in long form. */
12524 dump_glyph_row (row
, vpos
, glyphs
)
12525 struct glyph_row
*row
;
12530 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12531 fprintf (stderr
, "=======================================================================\n");
12533 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12534 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12536 MATRIX_ROW_START_CHARPOS (row
),
12537 MATRIX_ROW_END_CHARPOS (row
),
12538 row
->used
[TEXT_AREA
],
12539 row
->contains_overlapping_glyphs_p
,
12541 row
->truncated_on_left_p
,
12542 row
->truncated_on_right_p
,
12543 row
->overlay_arrow_p
,
12545 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12546 row
->displays_text_p
,
12549 row
->ends_in_middle_of_char_p
,
12550 row
->starts_in_middle_of_char_p
,
12556 row
->visible_height
,
12559 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12560 row
->end
.overlay_string_index
,
12561 row
->continuation_lines_width
);
12562 fprintf (stderr
, "%9d %5d\n",
12563 CHARPOS (row
->start
.string_pos
),
12564 CHARPOS (row
->end
.string_pos
));
12565 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12566 row
->end
.dpvec_index
);
12573 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12575 struct glyph
*glyph
= row
->glyphs
[area
];
12576 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12578 /* Glyph for a line end in text. */
12579 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12582 if (glyph
< glyph_end
)
12583 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12585 for (; glyph
< glyph_end
; ++glyph
)
12586 dump_glyph (row
, glyph
, area
);
12589 else if (glyphs
== 1)
12593 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12595 char *s
= (char *) alloca (row
->used
[area
] + 1);
12598 for (i
= 0; i
< row
->used
[area
]; ++i
)
12600 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12601 if (glyph
->type
== CHAR_GLYPH
12602 && glyph
->u
.ch
< 0x80
12603 && glyph
->u
.ch
>= ' ')
12604 s
[i
] = glyph
->u
.ch
;
12610 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12616 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12617 Sdump_glyph_matrix
, 0, 1, "p",
12618 doc
: /* Dump the current matrix of the selected window to stderr.
12619 Shows contents of glyph row structures. With non-nil
12620 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12621 glyphs in short form, otherwise show glyphs in long form. */)
12623 Lisp_Object glyphs
;
12625 struct window
*w
= XWINDOW (selected_window
);
12626 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12628 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12629 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12630 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12631 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12632 fprintf (stderr
, "=============================================\n");
12633 dump_glyph_matrix (w
->current_matrix
,
12634 NILP (glyphs
) ? 0 : XINT (glyphs
));
12639 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
12640 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
12643 struct frame
*f
= XFRAME (selected_frame
);
12644 dump_glyph_matrix (f
->current_matrix
, 1);
12649 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12650 doc
: /* Dump glyph row ROW to stderr.
12651 GLYPH 0 means don't dump glyphs.
12652 GLYPH 1 means dump glyphs in short form.
12653 GLYPH > 1 or omitted means dump glyphs in long form. */)
12655 Lisp_Object row
, glyphs
;
12657 struct glyph_matrix
*matrix
;
12660 CHECK_NUMBER (row
);
12661 matrix
= XWINDOW (selected_window
)->current_matrix
;
12663 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12664 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12666 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12671 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12672 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12673 GLYPH 0 means don't dump glyphs.
12674 GLYPH 1 means dump glyphs in short form.
12675 GLYPH > 1 or omitted means dump glyphs in long form. */)
12677 Lisp_Object row
, glyphs
;
12679 struct frame
*sf
= SELECTED_FRAME ();
12680 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12683 CHECK_NUMBER (row
);
12685 if (vpos
>= 0 && vpos
< m
->nrows
)
12686 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12687 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12692 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12693 doc
: /* Toggle tracing of redisplay.
12694 With ARG, turn tracing on if and only if ARG is positive. */)
12699 trace_redisplay_p
= !trace_redisplay_p
;
12702 arg
= Fprefix_numeric_value (arg
);
12703 trace_redisplay_p
= XINT (arg
) > 0;
12710 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12711 doc
: /* Like `format', but print result to stderr.
12712 usage: (trace-to-stderr STRING &rest OBJECTS) */)
12717 Lisp_Object s
= Fformat (nargs
, args
);
12718 fprintf (stderr
, "%s", SDATA (s
));
12722 #endif /* GLYPH_DEBUG */
12726 /***********************************************************************
12727 Building Desired Matrix Rows
12728 ***********************************************************************/
12730 /* Return a temporary glyph row holding the glyphs of an overlay
12731 arrow. Only used for non-window-redisplay windows. */
12733 static struct glyph_row
*
12734 get_overlay_arrow_glyph_row (w
)
12737 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12738 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12739 struct buffer
*old
= current_buffer
;
12740 const unsigned char *arrow_string
= SDATA (Voverlay_arrow_string
);
12741 int arrow_len
= SCHARS (Voverlay_arrow_string
);
12742 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12743 const unsigned char *p
;
12746 int n_glyphs_before
;
12748 set_buffer_temp (buffer
);
12749 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12750 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12751 SET_TEXT_POS (it
.position
, 0, 0);
12753 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12755 while (p
< arrow_end
)
12757 Lisp_Object face
, ilisp
;
12759 /* Get the next character. */
12761 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12763 it
.c
= *p
, it
.len
= 1;
12766 /* Get its face. */
12767 ilisp
= make_number (p
- arrow_string
);
12768 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12769 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12771 /* Compute its width, get its glyphs. */
12772 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12773 SET_TEXT_POS (it
.position
, -1, -1);
12774 PRODUCE_GLYPHS (&it
);
12776 /* If this character doesn't fit any more in the line, we have
12777 to remove some glyphs. */
12778 if (it
.current_x
> it
.last_visible_x
)
12780 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12785 set_buffer_temp (old
);
12786 return it
.glyph_row
;
12790 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12791 glyphs are only inserted for terminal frames since we can't really
12792 win with truncation glyphs when partially visible glyphs are
12793 involved. Which glyphs to insert is determined by
12794 produce_special_glyphs. */
12797 insert_left_trunc_glyphs (it
)
12800 struct it truncate_it
;
12801 struct glyph
*from
, *end
, *to
, *toend
;
12803 xassert (!FRAME_WINDOW_P (it
->f
));
12805 /* Get the truncation glyphs. */
12807 truncate_it
.current_x
= 0;
12808 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12809 truncate_it
.glyph_row
= &scratch_glyph_row
;
12810 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12811 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12812 truncate_it
.object
= make_number (0);
12813 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12815 /* Overwrite glyphs from IT with truncation glyphs. */
12816 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12817 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12818 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12819 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12824 /* There may be padding glyphs left over. Overwrite them too. */
12825 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12827 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12833 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12837 /* Compute the pixel height and width of IT->glyph_row.
12839 Most of the time, ascent and height of a display line will be equal
12840 to the max_ascent and max_height values of the display iterator
12841 structure. This is not the case if
12843 1. We hit ZV without displaying anything. In this case, max_ascent
12844 and max_height will be zero.
12846 2. We have some glyphs that don't contribute to the line height.
12847 (The glyph row flag contributes_to_line_height_p is for future
12848 pixmap extensions).
12850 The first case is easily covered by using default values because in
12851 these cases, the line height does not really matter, except that it
12852 must not be zero. */
12855 compute_line_metrics (it
)
12858 struct glyph_row
*row
= it
->glyph_row
;
12861 if (FRAME_WINDOW_P (it
->f
))
12863 int i
, min_y
, max_y
;
12865 /* The line may consist of one space only, that was added to
12866 place the cursor on it. If so, the row's height hasn't been
12868 if (row
->height
== 0)
12870 if (it
->max_ascent
+ it
->max_descent
== 0)
12871 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12872 row
->ascent
= it
->max_ascent
;
12873 row
->height
= it
->max_ascent
+ it
->max_descent
;
12874 row
->phys_ascent
= it
->max_phys_ascent
;
12875 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12878 /* Compute the width of this line. */
12879 row
->pixel_width
= row
->x
;
12880 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12881 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12883 xassert (row
->pixel_width
>= 0);
12884 xassert (row
->ascent
>= 0 && row
->height
> 0);
12886 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12887 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12889 /* If first line's physical ascent is larger than its logical
12890 ascent, use the physical ascent, and make the row taller.
12891 This makes accented characters fully visible. */
12892 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12893 && row
->phys_ascent
> row
->ascent
)
12895 row
->height
+= row
->phys_ascent
- row
->ascent
;
12896 row
->ascent
= row
->phys_ascent
;
12899 /* Compute how much of the line is visible. */
12900 row
->visible_height
= row
->height
;
12902 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12903 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12905 if (row
->y
< min_y
)
12906 row
->visible_height
-= min_y
- row
->y
;
12907 if (row
->y
+ row
->height
> max_y
)
12908 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12912 row
->pixel_width
= row
->used
[TEXT_AREA
];
12913 if (row
->continued_p
)
12914 row
->pixel_width
-= it
->continuation_pixel_width
;
12915 else if (row
->truncated_on_right_p
)
12916 row
->pixel_width
-= it
->truncation_pixel_width
;
12917 row
->ascent
= row
->phys_ascent
= 0;
12918 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12921 /* Compute a hash code for this row. */
12923 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12924 for (i
= 0; i
< row
->used
[area
]; ++i
)
12925 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12926 + row
->glyphs
[area
][i
].u
.val
12927 + row
->glyphs
[area
][i
].face_id
12928 + row
->glyphs
[area
][i
].padding_p
12929 + (row
->glyphs
[area
][i
].type
<< 2));
12931 it
->max_ascent
= it
->max_descent
= 0;
12932 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12936 /* Append one space to the glyph row of iterator IT if doing a
12937 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12938 space have the default face, otherwise let it have the same face as
12939 IT->face_id. Value is non-zero if a space was added.
12941 This function is called to make sure that there is always one glyph
12942 at the end of a glyph row that the cursor can be set on under
12943 window-systems. (If there weren't such a glyph we would not know
12944 how wide and tall a box cursor should be displayed).
12946 At the same time this space let's a nicely handle clearing to the
12947 end of the line if the row ends in italic text. */
12950 append_space (it
, default_face_p
)
12952 int default_face_p
;
12954 if (FRAME_WINDOW_P (it
->f
))
12956 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12958 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12959 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12961 /* Save some values that must not be changed.
12962 Must save IT->c and IT->len because otherwise
12963 ITERATOR_AT_END_P wouldn't work anymore after
12964 append_space has been called. */
12965 enum display_element_type saved_what
= it
->what
;
12966 int saved_c
= it
->c
, saved_len
= it
->len
;
12967 int saved_x
= it
->current_x
;
12968 int saved_face_id
= it
->face_id
;
12969 struct text_pos saved_pos
;
12970 Lisp_Object saved_object
;
12973 saved_object
= it
->object
;
12974 saved_pos
= it
->position
;
12976 it
->what
= IT_CHARACTER
;
12977 bzero (&it
->position
, sizeof it
->position
);
12978 it
->object
= make_number (0);
12982 if (default_face_p
)
12983 it
->face_id
= DEFAULT_FACE_ID
;
12984 else if (it
->face_before_selective_p
)
12985 it
->face_id
= it
->saved_face_id
;
12986 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12987 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12989 PRODUCE_GLYPHS (it
);
12991 it
->current_x
= saved_x
;
12992 it
->object
= saved_object
;
12993 it
->position
= saved_pos
;
12994 it
->what
= saved_what
;
12995 it
->face_id
= saved_face_id
;
12996 it
->len
= saved_len
;
13006 /* Extend the face of the last glyph in the text area of IT->glyph_row
13007 to the end of the display line. Called from display_line.
13008 If the glyph row is empty, add a space glyph to it so that we
13009 know the face to draw. Set the glyph row flag fill_line_p. */
13012 extend_face_to_end_of_line (it
)
13016 struct frame
*f
= it
->f
;
13018 /* If line is already filled, do nothing. */
13019 if (it
->current_x
>= it
->last_visible_x
)
13022 /* Face extension extends the background and box of IT->face_id
13023 to the end of the line. If the background equals the background
13024 of the frame, we don't have to do anything. */
13025 if (it
->face_before_selective_p
)
13026 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
13028 face
= FACE_FROM_ID (f
, it
->face_id
);
13030 if (FRAME_WINDOW_P (f
)
13031 && face
->box
== FACE_NO_BOX
13032 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
13036 /* Set the glyph row flag indicating that the face of the last glyph
13037 in the text area has to be drawn to the end of the text area. */
13038 it
->glyph_row
->fill_line_p
= 1;
13040 /* If current character of IT is not ASCII, make sure we have the
13041 ASCII face. This will be automatically undone the next time
13042 get_next_display_element returns a multibyte character. Note
13043 that the character will always be single byte in unibyte text. */
13044 if (!SINGLE_BYTE_CHAR_P (it
->c
))
13046 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
13049 if (FRAME_WINDOW_P (f
))
13051 /* If the row is empty, add a space with the current face of IT,
13052 so that we know which face to draw. */
13053 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
13055 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
13056 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
13057 it
->glyph_row
->used
[TEXT_AREA
] = 1;
13062 /* Save some values that must not be changed. */
13063 int saved_x
= it
->current_x
;
13064 struct text_pos saved_pos
;
13065 Lisp_Object saved_object
;
13066 enum display_element_type saved_what
= it
->what
;
13067 int saved_face_id
= it
->face_id
;
13069 saved_object
= it
->object
;
13070 saved_pos
= it
->position
;
13072 it
->what
= IT_CHARACTER
;
13073 bzero (&it
->position
, sizeof it
->position
);
13074 it
->object
= make_number (0);
13077 it
->face_id
= face
->id
;
13079 PRODUCE_GLYPHS (it
);
13081 while (it
->current_x
<= it
->last_visible_x
)
13082 PRODUCE_GLYPHS (it
);
13084 /* Don't count these blanks really. It would let us insert a left
13085 truncation glyph below and make us set the cursor on them, maybe. */
13086 it
->current_x
= saved_x
;
13087 it
->object
= saved_object
;
13088 it
->position
= saved_pos
;
13089 it
->what
= saved_what
;
13090 it
->face_id
= saved_face_id
;
13095 /* Value is non-zero if text starting at CHARPOS in current_buffer is
13096 trailing whitespace. */
13099 trailing_whitespace_p (charpos
)
13102 int bytepos
= CHAR_TO_BYTE (charpos
);
13105 while (bytepos
< ZV_BYTE
13106 && (c
= FETCH_CHAR (bytepos
),
13107 c
== ' ' || c
== '\t'))
13110 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
13112 if (bytepos
!= PT_BYTE
)
13119 /* Highlight trailing whitespace, if any, in ROW. */
13122 highlight_trailing_whitespace (f
, row
)
13124 struct glyph_row
*row
;
13126 int used
= row
->used
[TEXT_AREA
];
13130 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
13131 struct glyph
*glyph
= start
+ used
- 1;
13133 /* Skip over glyphs inserted to display the cursor at the
13134 end of a line, for extending the face of the last glyph
13135 to the end of the line on terminals, and for truncation
13136 and continuation glyphs. */
13137 while (glyph
>= start
13138 && glyph
->type
== CHAR_GLYPH
13139 && INTEGERP (glyph
->object
))
13142 /* If last glyph is a space or stretch, and it's trailing
13143 whitespace, set the face of all trailing whitespace glyphs in
13144 IT->glyph_row to `trailing-whitespace'. */
13146 && BUFFERP (glyph
->object
)
13147 && (glyph
->type
== STRETCH_GLYPH
13148 || (glyph
->type
== CHAR_GLYPH
13149 && glyph
->u
.ch
== ' '))
13150 && trailing_whitespace_p (glyph
->charpos
))
13152 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
13154 while (glyph
>= start
13155 && BUFFERP (glyph
->object
)
13156 && (glyph
->type
== STRETCH_GLYPH
13157 || (glyph
->type
== CHAR_GLYPH
13158 && glyph
->u
.ch
== ' ')))
13159 (glyph
--)->face_id
= face_id
;
13165 /* Value is non-zero if glyph row ROW in window W should be
13166 used to hold the cursor. */
13169 cursor_row_p (w
, row
)
13171 struct glyph_row
*row
;
13173 int cursor_row_p
= 1;
13175 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
13177 /* If the row ends with a newline from a string, we don't want
13178 the cursor there (if the row is continued it doesn't end in a
13180 if (CHARPOS (row
->end
.string_pos
) >= 0
13181 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13182 cursor_row_p
= row
->continued_p
;
13184 /* If the row ends at ZV, display the cursor at the end of that
13185 row instead of at the start of the row below. */
13186 else if (row
->ends_at_zv_p
)
13192 return cursor_row_p
;
13196 /* Construct the glyph row IT->glyph_row in the desired matrix of
13197 IT->w from text at the current position of IT. See dispextern.h
13198 for an overview of struct it. Value is non-zero if
13199 IT->glyph_row displays text, as opposed to a line displaying ZV
13206 struct glyph_row
*row
= it
->glyph_row
;
13208 /* We always start displaying at hpos zero even if hscrolled. */
13209 xassert (it
->hpos
== 0 && it
->current_x
== 0);
13211 /* We must not display in a row that's not a text row. */
13212 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
13213 < it
->w
->desired_matrix
->nrows
);
13215 /* Is IT->w showing the region? */
13216 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
13218 /* Clear the result glyph row and enable it. */
13219 prepare_desired_row (row
);
13221 row
->y
= it
->current_y
;
13222 row
->start
= it
->current
;
13223 row
->continuation_lines_width
= it
->continuation_lines_width
;
13224 row
->displays_text_p
= 1;
13225 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
13226 it
->starts_in_middle_of_char_p
= 0;
13228 /* Arrange the overlays nicely for our purposes. Usually, we call
13229 display_line on only one line at a time, in which case this
13230 can't really hurt too much, or we call it on lines which appear
13231 one after another in the buffer, in which case all calls to
13232 recenter_overlay_lists but the first will be pretty cheap. */
13233 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
13235 /* Move over display elements that are not visible because we are
13236 hscrolled. This may stop at an x-position < IT->first_visible_x
13237 if the first glyph is partially visible or if we hit a line end. */
13238 if (it
->current_x
< it
->first_visible_x
)
13239 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
13240 MOVE_TO_POS
| MOVE_TO_X
);
13242 /* Get the initial row height. This is either the height of the
13243 text hscrolled, if there is any, or zero. */
13244 row
->ascent
= it
->max_ascent
;
13245 row
->height
= it
->max_ascent
+ it
->max_descent
;
13246 row
->phys_ascent
= it
->max_phys_ascent
;
13247 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13249 /* Loop generating characters. The loop is left with IT on the next
13250 character to display. */
13253 int n_glyphs_before
, hpos_before
, x_before
;
13255 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
13257 /* Retrieve the next thing to display. Value is zero if end of
13259 if (!get_next_display_element (it
))
13261 /* Maybe add a space at the end of this line that is used to
13262 display the cursor there under X. Set the charpos of the
13263 first glyph of blank lines not corresponding to any text
13265 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
13266 || row
->used
[TEXT_AREA
] == 0)
13268 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
13269 row
->displays_text_p
= 0;
13271 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
13272 && (!MINI_WINDOW_P (it
->w
)
13273 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
13274 row
->indicate_empty_line_p
= 1;
13277 it
->continuation_lines_width
= 0;
13278 row
->ends_at_zv_p
= 1;
13282 /* Now, get the metrics of what we want to display. This also
13283 generates glyphs in `row' (which is IT->glyph_row). */
13284 n_glyphs_before
= row
->used
[TEXT_AREA
];
13287 /* Remember the line height so far in case the next element doesn't
13288 fit on the line. */
13289 if (!it
->truncate_lines_p
)
13291 ascent
= it
->max_ascent
;
13292 descent
= it
->max_descent
;
13293 phys_ascent
= it
->max_phys_ascent
;
13294 phys_descent
= it
->max_phys_descent
;
13297 PRODUCE_GLYPHS (it
);
13299 /* If this display element was in marginal areas, continue with
13301 if (it
->area
!= TEXT_AREA
)
13303 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13304 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13305 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13306 row
->phys_height
= max (row
->phys_height
,
13307 it
->max_phys_ascent
+ it
->max_phys_descent
);
13308 set_iterator_to_next (it
, 1);
13312 /* Does the display element fit on the line? If we truncate
13313 lines, we should draw past the right edge of the window. If
13314 we don't truncate, we want to stop so that we can display the
13315 continuation glyph before the right margin. If lines are
13316 continued, there are two possible strategies for characters
13317 resulting in more than 1 glyph (e.g. tabs): Display as many
13318 glyphs as possible in this line and leave the rest for the
13319 continuation line, or display the whole element in the next
13320 line. Original redisplay did the former, so we do it also. */
13321 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
13322 hpos_before
= it
->hpos
;
13325 if (/* Not a newline. */
13327 /* Glyphs produced fit entirely in the line. */
13328 && it
->current_x
< it
->last_visible_x
)
13330 it
->hpos
+= nglyphs
;
13331 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13332 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13333 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13334 row
->phys_height
= max (row
->phys_height
,
13335 it
->max_phys_ascent
+ it
->max_phys_descent
);
13336 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
13337 row
->x
= x
- it
->first_visible_x
;
13342 struct glyph
*glyph
;
13344 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
13346 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13347 new_x
= x
+ glyph
->pixel_width
;
13349 if (/* Lines are continued. */
13350 !it
->truncate_lines_p
13351 && (/* Glyph doesn't fit on the line. */
13352 new_x
> it
->last_visible_x
13353 /* Or it fits exactly on a window system frame. */
13354 || (new_x
== it
->last_visible_x
13355 && FRAME_WINDOW_P (it
->f
))))
13357 /* End of a continued line. */
13360 || (new_x
== it
->last_visible_x
13361 && FRAME_WINDOW_P (it
->f
)))
13363 /* Current glyph is the only one on the line or
13364 fits exactly on the line. We must continue
13365 the line because we can't draw the cursor
13366 after the glyph. */
13367 row
->continued_p
= 1;
13368 it
->current_x
= new_x
;
13369 it
->continuation_lines_width
+= new_x
;
13371 if (i
== nglyphs
- 1)
13372 set_iterator_to_next (it
, 1);
13374 else if (CHAR_GLYPH_PADDING_P (*glyph
)
13375 && !FRAME_WINDOW_P (it
->f
))
13377 /* A padding glyph that doesn't fit on this line.
13378 This means the whole character doesn't fit
13380 row
->used
[TEXT_AREA
] = n_glyphs_before
;
13382 /* Fill the rest of the row with continuation
13383 glyphs like in 20.x. */
13384 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
13385 < row
->glyphs
[1 + TEXT_AREA
])
13386 produce_special_glyphs (it
, IT_CONTINUATION
);
13388 row
->continued_p
= 1;
13389 it
->current_x
= x_before
;
13390 it
->continuation_lines_width
+= x_before
;
13392 /* Restore the height to what it was before the
13393 element not fitting on the line. */
13394 it
->max_ascent
= ascent
;
13395 it
->max_descent
= descent
;
13396 it
->max_phys_ascent
= phys_ascent
;
13397 it
->max_phys_descent
= phys_descent
;
13399 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
13401 /* A TAB that extends past the right edge of the
13402 window. This produces a single glyph on
13403 window system frames. We leave the glyph in
13404 this row and let it fill the row, but don't
13405 consume the TAB. */
13406 it
->continuation_lines_width
+= it
->last_visible_x
;
13407 row
->ends_in_middle_of_char_p
= 1;
13408 row
->continued_p
= 1;
13409 glyph
->pixel_width
= it
->last_visible_x
- x
;
13410 it
->starts_in_middle_of_char_p
= 1;
13414 /* Something other than a TAB that draws past
13415 the right edge of the window. Restore
13416 positions to values before the element. */
13417 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13419 /* Display continuation glyphs. */
13420 if (!FRAME_WINDOW_P (it
->f
))
13421 produce_special_glyphs (it
, IT_CONTINUATION
);
13422 row
->continued_p
= 1;
13424 it
->continuation_lines_width
+= x
;
13426 if (nglyphs
> 1 && i
> 0)
13428 row
->ends_in_middle_of_char_p
= 1;
13429 it
->starts_in_middle_of_char_p
= 1;
13432 /* Restore the height to what it was before the
13433 element not fitting on the line. */
13434 it
->max_ascent
= ascent
;
13435 it
->max_descent
= descent
;
13436 it
->max_phys_ascent
= phys_ascent
;
13437 it
->max_phys_descent
= phys_descent
;
13442 else if (new_x
> it
->first_visible_x
)
13444 /* Increment number of glyphs actually displayed. */
13447 if (x
< it
->first_visible_x
)
13448 /* Glyph is partially visible, i.e. row starts at
13449 negative X position. */
13450 row
->x
= x
- it
->first_visible_x
;
13454 /* Glyph is completely off the left margin of the
13455 window. This should not happen because of the
13456 move_it_in_display_line at the start of this
13457 function, unless the text display area of the
13458 window is empty. */
13459 xassert (it
->first_visible_x
<= it
->last_visible_x
);
13463 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13464 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13465 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13466 row
->phys_height
= max (row
->phys_height
,
13467 it
->max_phys_ascent
+ it
->max_phys_descent
);
13469 /* End of this display line if row is continued. */
13470 if (row
->continued_p
)
13474 /* Is this a line end? If yes, we're also done, after making
13475 sure that a non-default face is extended up to the right
13476 margin of the window. */
13477 if (ITERATOR_AT_END_OF_LINE_P (it
))
13479 int used_before
= row
->used
[TEXT_AREA
];
13481 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13483 /* Add a space at the end of the line that is used to
13484 display the cursor there. */
13485 append_space (it
, 0);
13487 /* Extend the face to the end of the line. */
13488 extend_face_to_end_of_line (it
);
13490 /* Make sure we have the position. */
13491 if (used_before
== 0)
13492 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13494 /* Consume the line end. This skips over invisible lines. */
13495 set_iterator_to_next (it
, 1);
13496 it
->continuation_lines_width
= 0;
13500 /* Proceed with next display element. Note that this skips
13501 over lines invisible because of selective display. */
13502 set_iterator_to_next (it
, 1);
13504 /* If we truncate lines, we are done when the last displayed
13505 glyphs reach past the right margin of the window. */
13506 if (it
->truncate_lines_p
13507 && (FRAME_WINDOW_P (it
->f
)
13508 ? (it
->current_x
>= it
->last_visible_x
)
13509 : (it
->current_x
> it
->last_visible_x
)))
13511 /* Maybe add truncation glyphs. */
13512 if (!FRAME_WINDOW_P (it
->f
))
13516 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13517 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13520 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13522 row
->used
[TEXT_AREA
] = i
;
13523 produce_special_glyphs (it
, IT_TRUNCATION
);
13527 row
->truncated_on_right_p
= 1;
13528 it
->continuation_lines_width
= 0;
13529 reseat_at_next_visible_line_start (it
, 0);
13530 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13531 it
->hpos
= hpos_before
;
13532 it
->current_x
= x_before
;
13537 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13538 at the left window margin. */
13539 if (it
->first_visible_x
13540 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13542 if (!FRAME_WINDOW_P (it
->f
))
13543 insert_left_trunc_glyphs (it
);
13544 row
->truncated_on_left_p
= 1;
13547 /* If the start of this line is the overlay arrow-position, then
13548 mark this glyph row as the one containing the overlay arrow.
13549 This is clearly a mess with variable size fonts. It would be
13550 better to let it be displayed like cursors under X. */
13551 if (MARKERP (Voverlay_arrow_position
)
13552 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13553 && (MATRIX_ROW_START_CHARPOS (row
)
13554 == marker_position (Voverlay_arrow_position
))
13555 && STRINGP (Voverlay_arrow_string
)
13556 && ! overlay_arrow_seen
)
13558 /* Overlay arrow in window redisplay is a fringe bitmap. */
13559 if (!FRAME_WINDOW_P (it
->f
))
13561 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13562 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13563 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13564 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13565 struct glyph
*p2
, *end
;
13567 /* Copy the arrow glyphs. */
13568 while (glyph
< arrow_end
)
13571 /* Throw away padding glyphs. */
13573 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13574 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13580 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13584 overlay_arrow_seen
= 1;
13585 row
->overlay_arrow_p
= 1;
13588 /* Compute pixel dimensions of this line. */
13589 compute_line_metrics (it
);
13591 /* Remember the position at which this line ends. */
13592 row
->end
= it
->current
;
13594 /* Maybe set the cursor. */
13595 if (it
->w
->cursor
.vpos
< 0
13596 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13597 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13598 && cursor_row_p (it
->w
, row
))
13599 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13601 /* Highlight trailing whitespace. */
13602 if (!NILP (Vshow_trailing_whitespace
))
13603 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13605 /* Prepare for the next line. This line starts horizontally at (X
13606 HPOS) = (0 0). Vertical positions are incremented. As a
13607 convenience for the caller, IT->glyph_row is set to the next
13609 it
->current_x
= it
->hpos
= 0;
13610 it
->current_y
+= row
->height
;
13613 return row
->displays_text_p
;
13618 /***********************************************************************
13620 ***********************************************************************/
13622 /* Redisplay the menu bar in the frame for window W.
13624 The menu bar of X frames that don't have X toolkit support is
13625 displayed in a special window W->frame->menu_bar_window.
13627 The menu bar of terminal frames is treated specially as far as
13628 glyph matrices are concerned. Menu bar lines are not part of
13629 windows, so the update is done directly on the frame matrix rows
13630 for the menu bar. */
13633 display_menu_bar (w
)
13636 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13641 /* Don't do all this for graphical frames. */
13643 if (!NILP (Vwindow_system
))
13646 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
13651 if (FRAME_MAC_P (f
))
13655 #ifdef USE_X_TOOLKIT
13656 xassert (!FRAME_WINDOW_P (f
));
13657 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13658 it
.first_visible_x
= 0;
13659 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13660 #else /* not USE_X_TOOLKIT */
13661 if (FRAME_WINDOW_P (f
))
13663 /* Menu bar lines are displayed in the desired matrix of the
13664 dummy window menu_bar_window. */
13665 struct window
*menu_w
;
13666 xassert (WINDOWP (f
->menu_bar_window
));
13667 menu_w
= XWINDOW (f
->menu_bar_window
);
13668 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13670 it
.first_visible_x
= 0;
13671 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13675 /* This is a TTY frame, i.e. character hpos/vpos are used as
13677 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13679 it
.first_visible_x
= 0;
13680 it
.last_visible_x
= FRAME_WIDTH (f
);
13682 #endif /* not USE_X_TOOLKIT */
13684 if (! mode_line_inverse_video
)
13685 /* Force the menu-bar to be displayed in the default face. */
13686 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13688 /* Clear all rows of the menu bar. */
13689 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13691 struct glyph_row
*row
= it
.glyph_row
+ i
;
13692 clear_glyph_row (row
);
13693 row
->enabled_p
= 1;
13694 row
->full_width_p
= 1;
13697 /* Display all items of the menu bar. */
13698 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13699 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13701 Lisp_Object string
;
13703 /* Stop at nil string. */
13704 string
= AREF (items
, i
+ 1);
13708 /* Remember where item was displayed. */
13709 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13711 /* Display the item, pad with one space. */
13712 if (it
.current_x
< it
.last_visible_x
)
13713 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13714 SCHARS (string
) + 1, 0, 0, -1);
13717 /* Fill out the line with spaces. */
13718 if (it
.current_x
< it
.last_visible_x
)
13719 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13721 /* Compute the total height of the lines. */
13722 compute_line_metrics (&it
);
13727 /***********************************************************************
13729 ***********************************************************************/
13731 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13732 FORCE is non-zero, redisplay mode lines unconditionally.
13733 Otherwise, redisplay only mode lines that are garbaged. Value is
13734 the number of windows whose mode lines were redisplayed. */
13737 redisplay_mode_lines (window
, force
)
13738 Lisp_Object window
;
13743 while (!NILP (window
))
13745 struct window
*w
= XWINDOW (window
);
13747 if (WINDOWP (w
->hchild
))
13748 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13749 else if (WINDOWP (w
->vchild
))
13750 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13752 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13753 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13755 struct text_pos lpoint
;
13756 struct buffer
*old
= current_buffer
;
13758 /* Set the window's buffer for the mode line display. */
13759 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13760 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13762 /* Point refers normally to the selected window. For any
13763 other window, set up appropriate value. */
13764 if (!EQ (window
, selected_window
))
13766 struct text_pos pt
;
13768 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13769 if (CHARPOS (pt
) < BEGV
)
13770 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13771 else if (CHARPOS (pt
) > (ZV
- 1))
13772 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13774 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13777 /* Display mode lines. */
13778 clear_glyph_matrix (w
->desired_matrix
);
13779 if (display_mode_lines (w
))
13782 w
->must_be_updated_p
= 1;
13785 /* Restore old settings. */
13786 set_buffer_internal_1 (old
);
13787 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13797 /* Display the mode and/or top line of window W. Value is the number
13798 of mode lines displayed. */
13801 display_mode_lines (w
)
13804 Lisp_Object old_selected_window
, old_selected_frame
;
13807 old_selected_frame
= selected_frame
;
13808 selected_frame
= w
->frame
;
13809 old_selected_window
= selected_window
;
13810 XSETWINDOW (selected_window
, w
);
13812 /* These will be set while the mode line specs are processed. */
13813 line_number_displayed
= 0;
13814 w
->column_number_displayed
= Qnil
;
13816 if (WINDOW_WANTS_MODELINE_P (w
))
13818 struct window
*sel_w
= XWINDOW (old_selected_window
);
13820 /* Select mode line face based on the real selected window. */
13821 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
13822 current_buffer
->mode_line_format
);
13826 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13828 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13829 current_buffer
->header_line_format
);
13833 selected_frame
= old_selected_frame
;
13834 selected_window
= old_selected_window
;
13839 /* Display mode or top line of window W. FACE_ID specifies which line
13840 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13841 FORMAT is the mode line format to display. Value is the pixel
13842 height of the mode line displayed. */
13845 display_mode_line (w
, face_id
, format
)
13847 enum face_id face_id
;
13848 Lisp_Object format
;
13853 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13854 prepare_desired_row (it
.glyph_row
);
13856 if (! mode_line_inverse_video
)
13857 /* Force the mode-line to be displayed in the default face. */
13858 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13860 /* Temporarily make frame's keyboard the current kboard so that
13861 kboard-local variables in the mode_line_format will get the right
13863 push_frame_kboard (it
.f
);
13864 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
13865 pop_frame_kboard ();
13867 /* Fill up with spaces. */
13868 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13870 compute_line_metrics (&it
);
13871 it
.glyph_row
->full_width_p
= 1;
13872 it
.glyph_row
->mode_line_p
= 1;
13873 it
.glyph_row
->continued_p
= 0;
13874 it
.glyph_row
->truncated_on_left_p
= 0;
13875 it
.glyph_row
->truncated_on_right_p
= 0;
13877 /* Make a 3D mode-line have a shadow at its right end. */
13878 face
= FACE_FROM_ID (it
.f
, face_id
);
13879 extend_face_to_end_of_line (&it
);
13880 if (face
->box
!= FACE_NO_BOX
)
13882 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13883 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13884 last
->right_box_line_p
= 1;
13887 return it
.glyph_row
->height
;
13890 /* Alist that caches the results of :propertize.
13891 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
13892 Lisp_Object mode_line_proptrans_alist
;
13894 /* List of strings making up the mode-line. */
13895 Lisp_Object mode_line_string_list
;
13897 /* Base face property when building propertized mode line string. */
13898 static Lisp_Object mode_line_string_face
;
13899 static Lisp_Object mode_line_string_face_prop
;
13902 /* Contribute ELT to the mode line for window IT->w. How it
13903 translates into text depends on its data type.
13905 IT describes the display environment in which we display, as usual.
13907 DEPTH is the depth in recursion. It is used to prevent
13908 infinite recursion here.
13910 FIELD_WIDTH is the number of characters the display of ELT should
13911 occupy in the mode line, and PRECISION is the maximum number of
13912 characters to display from ELT's representation. See
13913 display_string for details.
13915 Returns the hpos of the end of the text generated by ELT.
13917 PROPS is a property list to add to any string we encounter.
13919 If RISKY is nonzero, remove (disregard) any properties in any string
13920 we encounter, and ignore :eval and :propertize.
13922 If the global variable `frame_title_ptr' is non-NULL, then the output
13923 is passed to `store_frame_title' instead of `display_string'. */
13926 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
13929 int field_width
, precision
;
13930 Lisp_Object elt
, props
;
13933 int n
= 0, field
, prec
;
13942 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13946 /* A string: output it and check for %-constructs within it. */
13948 const unsigned char *this, *lisp_string
;
13950 if (!NILP (props
) || risky
)
13952 Lisp_Object oprops
, aelt
;
13953 oprops
= Ftext_properties_at (make_number (0), elt
);
13955 if (NILP (Fequal (props
, oprops
)) || risky
)
13957 /* If the starting string has properties,
13958 merge the specified ones onto the existing ones. */
13959 if (! NILP (oprops
) && !risky
)
13963 oprops
= Fcopy_sequence (oprops
);
13965 while (CONSP (tem
))
13967 oprops
= Fplist_put (oprops
, XCAR (tem
),
13968 XCAR (XCDR (tem
)));
13969 tem
= XCDR (XCDR (tem
));
13974 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
13975 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
13977 mode_line_proptrans_alist
13978 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
13985 elt
= Fcopy_sequence (elt
);
13986 Fset_text_properties (make_number (0), Flength (elt
),
13988 /* Add this item to mode_line_proptrans_alist. */
13989 mode_line_proptrans_alist
13990 = Fcons (Fcons (elt
, props
),
13991 mode_line_proptrans_alist
);
13992 /* Truncate mode_line_proptrans_alist
13993 to at most 50 elements. */
13994 tem
= Fnthcdr (make_number (50),
13995 mode_line_proptrans_alist
);
13997 XSETCDR (tem
, Qnil
);
14002 this = SDATA (elt
);
14003 lisp_string
= this;
14007 prec
= precision
- n
;
14008 if (frame_title_ptr
)
14009 n
+= store_frame_title (SDATA (elt
), -1, prec
);
14010 else if (!NILP (mode_line_string_list
))
14011 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
14013 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
14014 0, prec
, 0, STRING_MULTIBYTE (elt
));
14019 while ((precision
<= 0 || n
< precision
)
14021 && (frame_title_ptr
14022 || !NILP (mode_line_string_list
)
14023 || it
->current_x
< it
->last_visible_x
))
14025 const unsigned char *last
= this;
14027 /* Advance to end of string or next format specifier. */
14028 while ((c
= *this++) != '\0' && c
!= '%')
14031 if (this - 1 != last
)
14033 /* Output to end of string or up to '%'. Field width
14034 is length of string. Don't output more than
14035 PRECISION allows us. */
14038 prec
= chars_in_text (last
, this - last
);
14039 if (precision
> 0 && prec
> precision
- n
)
14040 prec
= precision
- n
;
14042 if (frame_title_ptr
)
14043 n
+= store_frame_title (last
, 0, prec
);
14044 else if (!NILP (mode_line_string_list
))
14046 int bytepos
= last
- lisp_string
;
14047 int charpos
= string_byte_to_char (elt
, bytepos
);
14048 n
+= store_mode_line_string (NULL
,
14049 Fsubstring (elt
, make_number (charpos
),
14050 make_number (charpos
+ prec
)),
14055 int bytepos
= last
- lisp_string
;
14056 int charpos
= string_byte_to_char (elt
, bytepos
);
14057 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
14059 STRING_MULTIBYTE (elt
));
14062 else /* c == '%' */
14064 const unsigned char *percent_position
= this;
14066 /* Get the specified minimum width. Zero means
14069 while ((c
= *this++) >= '0' && c
<= '9')
14070 field
= field
* 10 + c
- '0';
14072 /* Don't pad beyond the total padding allowed. */
14073 if (field_width
- n
> 0 && field
> field_width
- n
)
14074 field
= field_width
- n
;
14076 /* Note that either PRECISION <= 0 or N < PRECISION. */
14077 prec
= precision
- n
;
14080 n
+= display_mode_element (it
, depth
, field
, prec
,
14081 Vglobal_mode_string
, props
,
14086 int bytepos
, charpos
;
14087 unsigned char *spec
;
14089 bytepos
= percent_position
- lisp_string
;
14090 charpos
= (STRING_MULTIBYTE (elt
)
14091 ? string_byte_to_char (elt
, bytepos
)
14095 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
14097 if (frame_title_ptr
)
14098 n
+= store_frame_title (spec
, field
, prec
);
14099 else if (!NILP (mode_line_string_list
))
14101 int len
= strlen (spec
);
14102 Lisp_Object tem
= make_string (spec
, len
);
14103 props
= Ftext_properties_at (make_number (charpos
), elt
);
14104 /* Should only keep face property in props */
14105 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
14109 int nglyphs_before
, nwritten
;
14111 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14112 nwritten
= display_string (spec
, Qnil
, elt
,
14117 /* Assign to the glyphs written above the
14118 string where the `%x' came from, position
14122 struct glyph
*glyph
14123 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
14127 for (i
= 0; i
< nwritten
; ++i
)
14129 glyph
[i
].object
= elt
;
14130 glyph
[i
].charpos
= charpos
;
14145 /* A symbol: process the value of the symbol recursively
14146 as if it appeared here directly. Avoid error if symbol void.
14147 Special case: if value of symbol is a string, output the string
14150 register Lisp_Object tem
;
14152 /* If the variable is not marked as risky to set
14153 then its contents are risky to use. */
14154 if (NILP (Fget (elt
, Qrisky_local_variable
)))
14157 tem
= Fboundp (elt
);
14160 tem
= Fsymbol_value (elt
);
14161 /* If value is a string, output that string literally:
14162 don't check for % within it. */
14166 if (!EQ (tem
, elt
))
14168 /* Give up right away for nil or t. */
14178 register Lisp_Object car
, tem
;
14180 /* A cons cell: five distinct cases.
14181 If first element is :eval or :propertize, do something special.
14182 If first element is a string or a cons, process all the elements
14183 and effectively concatenate them.
14184 If first element is a negative number, truncate displaying cdr to
14185 at most that many characters. If positive, pad (with spaces)
14186 to at least that many characters.
14187 If first element is a symbol, process the cadr or caddr recursively
14188 according to whether the symbol's value is non-nil or nil. */
14190 if (EQ (car
, QCeval
))
14192 /* An element of the form (:eval FORM) means evaluate FORM
14193 and use the result as mode line elements. */
14198 if (CONSP (XCDR (elt
)))
14201 spec
= safe_eval (XCAR (XCDR (elt
)));
14202 n
+= display_mode_element (it
, depth
, field_width
- n
,
14203 precision
- n
, spec
, props
,
14207 else if (EQ (car
, QCpropertize
))
14209 /* An element of the form (:propertize ELT PROPS...)
14210 means display ELT but applying properties PROPS. */
14215 if (CONSP (XCDR (elt
)))
14216 n
+= display_mode_element (it
, depth
, field_width
- n
,
14217 precision
- n
, XCAR (XCDR (elt
)),
14218 XCDR (XCDR (elt
)), risky
);
14220 else if (SYMBOLP (car
))
14222 tem
= Fboundp (car
);
14226 /* elt is now the cdr, and we know it is a cons cell.
14227 Use its car if CAR has a non-nil value. */
14230 tem
= Fsymbol_value (car
);
14237 /* Symbol's value is nil (or symbol is unbound)
14238 Get the cddr of the original list
14239 and if possible find the caddr and use that. */
14243 else if (!CONSP (elt
))
14248 else if (INTEGERP (car
))
14250 register int lim
= XINT (car
);
14254 /* Negative int means reduce maximum width. */
14255 if (precision
<= 0)
14258 precision
= min (precision
, -lim
);
14262 /* Padding specified. Don't let it be more than
14263 current maximum. */
14265 lim
= min (precision
, lim
);
14267 /* If that's more padding than already wanted, queue it.
14268 But don't reduce padding already specified even if
14269 that is beyond the current truncation point. */
14270 field_width
= max (lim
, field_width
);
14274 else if (STRINGP (car
) || CONSP (car
))
14276 register int limit
= 50;
14277 /* Limit is to protect against circular lists. */
14280 && (precision
<= 0 || n
< precision
))
14282 n
+= display_mode_element (it
, depth
, field_width
- n
,
14283 precision
- n
, XCAR (elt
),
14293 if (frame_title_ptr
)
14294 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
14295 else if (!NILP (mode_line_string_list
))
14296 n
+= store_mode_line_string ("*invalid*", Qnil
, 0, 0, precision
- n
, Qnil
);
14298 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
14299 precision
- n
, 0, 0);
14303 /* Pad to FIELD_WIDTH. */
14304 if (field_width
> 0 && n
< field_width
)
14306 if (frame_title_ptr
)
14307 n
+= store_frame_title ("", field_width
- n
, 0);
14308 else if (!NILP (mode_line_string_list
))
14309 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
14311 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
14318 /* Store a mode-line string element in mode_line_string_list.
14320 If STRING is non-null, display that C string. Otherwise, the Lisp
14321 string LISP_STRING is displayed.
14323 FIELD_WIDTH is the minimum number of output glyphs to produce.
14324 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14325 with spaces. FIELD_WIDTH <= 0 means don't pad.
14327 PRECISION is the maximum number of characters to output from
14328 STRING. PRECISION <= 0 means don't truncate the string.
14330 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
14331 properties to the string.
14333 PROPS are the properties to add to the string.
14334 The mode_line_string_face face property is always added to the string.
14337 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
14339 Lisp_Object lisp_string
;
14348 if (string
!= NULL
)
14350 len
= strlen (string
);
14351 if (precision
> 0 && len
> precision
)
14353 lisp_string
= make_string (string
, len
);
14355 props
= mode_line_string_face_prop
;
14356 else if (!NILP (mode_line_string_face
))
14358 Lisp_Object face
= Fplist_get (props
, Qface
);
14359 props
= Fcopy_sequence (props
);
14361 face
= mode_line_string_face
;
14363 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14364 props
= Fplist_put (props
, Qface
, face
);
14366 Fadd_text_properties (make_number (0), make_number (len
),
14367 props
, lisp_string
);
14371 len
= XFASTINT (Flength (lisp_string
));
14372 if (precision
> 0 && len
> precision
)
14375 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
14378 if (!NILP (mode_line_string_face
))
14382 props
= Ftext_properties_at (make_number (0), lisp_string
);
14383 face
= Fplist_get (props
, Qface
);
14385 face
= mode_line_string_face
;
14387 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14388 props
= Fcons (Qface
, Fcons (face
, Qnil
));
14390 lisp_string
= Fcopy_sequence (lisp_string
);
14393 Fadd_text_properties (make_number (0), make_number (len
),
14394 props
, lisp_string
);
14399 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14403 if (field_width
> len
)
14405 field_width
-= len
;
14406 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
14408 Fadd_text_properties (make_number (0), make_number (field_width
),
14409 props
, lisp_string
);
14410 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14418 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
14420 doc
: /* Return the mode-line of selected window as a string.
14421 First optional arg FORMAT specifies a different format string (see
14422 `mode-line-format' for details) to use. If FORMAT is t, return
14423 the buffer's header-line. Second optional arg WINDOW specifies a
14424 different window to use as the context for the formatting.
14425 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
14426 (format
, window
, no_props
)
14427 Lisp_Object format
, window
, no_props
;
14432 struct buffer
*old_buffer
= NULL
;
14433 enum face_id face_id
= DEFAULT_FACE_ID
;
14436 window
= selected_window
;
14437 CHECK_WINDOW (window
);
14438 w
= XWINDOW (window
);
14439 CHECK_BUFFER (w
->buffer
);
14441 if (XBUFFER (w
->buffer
) != current_buffer
)
14443 old_buffer
= current_buffer
;
14444 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14447 if (NILP (format
) || EQ (format
, Qt
))
14449 face_id
= NILP (format
)
14450 ? CURRENT_MODE_LINE_FACE_ID (w
) :
14451 HEADER_LINE_FACE_ID
;
14452 format
= NILP (format
)
14453 ? current_buffer
->mode_line_format
14454 : current_buffer
->header_line_format
;
14457 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
14459 if (NILP (no_props
))
14461 mode_line_string_face
=
14462 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
14463 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
14464 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
14466 mode_line_string_face_prop
=
14467 NILP (mode_line_string_face
) ? Qnil
:
14468 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
14470 /* We need a dummy last element in mode_line_string_list to
14471 indicate we are building the propertized mode-line string.
14472 Using mode_line_string_face_prop here GC protects it. */
14473 mode_line_string_list
=
14474 Fcons (mode_line_string_face_prop
, Qnil
);
14475 frame_title_ptr
= NULL
;
14479 mode_line_string_face_prop
= Qnil
;
14480 mode_line_string_list
= Qnil
;
14481 frame_title_ptr
= frame_title_buf
;
14484 push_frame_kboard (it
.f
);
14485 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
14486 pop_frame_kboard ();
14489 set_buffer_internal_1 (old_buffer
);
14491 if (NILP (no_props
))
14494 mode_line_string_list
= Fnreverse (mode_line_string_list
);
14495 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
14496 make_string ("", 0));
14497 mode_line_string_face_prop
= Qnil
;
14498 mode_line_string_list
= Qnil
;
14502 len
= frame_title_ptr
- frame_title_buf
;
14503 if (len
> 0 && frame_title_ptr
[-1] == '-')
14505 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
14506 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
14508 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
14509 if (len
> frame_title_ptr
- frame_title_buf
)
14510 len
= frame_title_ptr
- frame_title_buf
;
14513 frame_title_ptr
= NULL
;
14514 return make_string (frame_title_buf
, len
);
14517 /* Write a null-terminated, right justified decimal representation of
14518 the positive integer D to BUF using a minimal field width WIDTH. */
14521 pint2str (buf
, width
, d
)
14522 register char *buf
;
14523 register int width
;
14526 register char *p
= buf
;
14534 *p
++ = d
% 10 + '0';
14539 for (width
-= (int) (p
- buf
); width
> 0; --width
)
14550 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
14551 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
14552 type of CODING_SYSTEM. Return updated pointer into BUF. */
14554 static unsigned char invalid_eol_type
[] = "(*invalid*)";
14557 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
14558 Lisp_Object coding_system
;
14559 register char *buf
;
14563 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
14564 const unsigned char *eol_str
;
14566 /* The EOL conversion we are using. */
14567 Lisp_Object eoltype
;
14569 val
= Fget (coding_system
, Qcoding_system
);
14572 if (!VECTORP (val
)) /* Not yet decided. */
14577 eoltype
= eol_mnemonic_undecided
;
14578 /* Don't mention EOL conversion if it isn't decided. */
14582 Lisp_Object eolvalue
;
14584 eolvalue
= Fget (coding_system
, Qeol_type
);
14587 *buf
++ = XFASTINT (AREF (val
, 1));
14591 /* The EOL conversion that is normal on this system. */
14593 if (NILP (eolvalue
)) /* Not yet decided. */
14594 eoltype
= eol_mnemonic_undecided
;
14595 else if (VECTORP (eolvalue
)) /* Not yet decided. */
14596 eoltype
= eol_mnemonic_undecided
;
14597 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
14598 eoltype
= (XFASTINT (eolvalue
) == 0
14599 ? eol_mnemonic_unix
14600 : (XFASTINT (eolvalue
) == 1
14601 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
14607 /* Mention the EOL conversion if it is not the usual one. */
14608 if (STRINGP (eoltype
))
14610 eol_str
= SDATA (eoltype
);
14611 eol_str_len
= SBYTES (eoltype
);
14613 else if (INTEGERP (eoltype
)
14614 && CHAR_VALID_P (XINT (eoltype
), 0))
14616 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
14617 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
14622 eol_str
= invalid_eol_type
;
14623 eol_str_len
= sizeof (invalid_eol_type
) - 1;
14625 bcopy (eol_str
, buf
, eol_str_len
);
14626 buf
+= eol_str_len
;
14632 /* Return a string for the output of a mode line %-spec for window W,
14633 generated by character C. PRECISION >= 0 means don't return a
14634 string longer than that value. FIELD_WIDTH > 0 means pad the
14635 string returned with spaces to that value. Return 1 in *MULTIBYTE
14636 if the result is multibyte text. */
14638 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
14641 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
14644 int field_width
, precision
;
14648 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14649 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
14650 struct buffer
*b
= XBUFFER (w
->buffer
);
14658 if (!NILP (b
->read_only
))
14660 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14665 /* This differs from %* only for a modified read-only buffer. */
14666 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14668 if (!NILP (b
->read_only
))
14673 /* This differs from %* in ignoring read-only-ness. */
14674 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14686 if (command_loop_level
> 5)
14688 p
= decode_mode_spec_buf
;
14689 for (i
= 0; i
< command_loop_level
; i
++)
14692 return decode_mode_spec_buf
;
14700 if (command_loop_level
> 5)
14702 p
= decode_mode_spec_buf
;
14703 for (i
= 0; i
< command_loop_level
; i
++)
14706 return decode_mode_spec_buf
;
14713 /* Let lots_of_dashes be a string of infinite length. */
14714 if (!NILP (mode_line_string_list
))
14716 if (field_width
<= 0
14717 || field_width
> sizeof (lots_of_dashes
))
14719 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
14720 decode_mode_spec_buf
[i
] = '-';
14721 decode_mode_spec_buf
[i
] = '\0';
14722 return decode_mode_spec_buf
;
14725 return lots_of_dashes
;
14734 int col
= (int) current_column (); /* iftc */
14735 w
->column_number_displayed
= make_number (col
);
14736 pint2str (decode_mode_spec_buf
, field_width
, col
);
14737 return decode_mode_spec_buf
;
14741 /* %F displays the frame name. */
14742 if (!NILP (f
->title
))
14743 return (char *) SDATA (f
->title
);
14744 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
14745 return (char *) SDATA (f
->name
);
14754 int startpos
= XMARKER (w
->start
)->charpos
;
14755 int startpos_byte
= marker_byte_position (w
->start
);
14756 int line
, linepos
, linepos_byte
, topline
;
14758 int height
= XFASTINT (w
->height
);
14760 /* If we decided that this buffer isn't suitable for line numbers,
14761 don't forget that too fast. */
14762 if (EQ (w
->base_line_pos
, w
->buffer
))
14764 /* But do forget it, if the window shows a different buffer now. */
14765 else if (BUFFERP (w
->base_line_pos
))
14766 w
->base_line_pos
= Qnil
;
14768 /* If the buffer is very big, don't waste time. */
14769 if (INTEGERP (Vline_number_display_limit
)
14770 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
14772 w
->base_line_pos
= Qnil
;
14773 w
->base_line_number
= Qnil
;
14777 if (!NILP (w
->base_line_number
)
14778 && !NILP (w
->base_line_pos
)
14779 && XFASTINT (w
->base_line_pos
) <= startpos
)
14781 line
= XFASTINT (w
->base_line_number
);
14782 linepos
= XFASTINT (w
->base_line_pos
);
14783 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
14788 linepos
= BUF_BEGV (b
);
14789 linepos_byte
= BUF_BEGV_BYTE (b
);
14792 /* Count lines from base line to window start position. */
14793 nlines
= display_count_lines (linepos
, linepos_byte
,
14797 topline
= nlines
+ line
;
14799 /* Determine a new base line, if the old one is too close
14800 or too far away, or if we did not have one.
14801 "Too close" means it's plausible a scroll-down would
14802 go back past it. */
14803 if (startpos
== BUF_BEGV (b
))
14805 w
->base_line_number
= make_number (topline
);
14806 w
->base_line_pos
= make_number (BUF_BEGV (b
));
14808 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
14809 || linepos
== BUF_BEGV (b
))
14811 int limit
= BUF_BEGV (b
);
14812 int limit_byte
= BUF_BEGV_BYTE (b
);
14814 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
14816 if (startpos
- distance
> limit
)
14818 limit
= startpos
- distance
;
14819 limit_byte
= CHAR_TO_BYTE (limit
);
14822 nlines
= display_count_lines (startpos
, startpos_byte
,
14824 - (height
* 2 + 30),
14826 /* If we couldn't find the lines we wanted within
14827 line_number_display_limit_width chars per line,
14828 give up on line numbers for this window. */
14829 if (position
== limit_byte
&& limit
== startpos
- distance
)
14831 w
->base_line_pos
= w
->buffer
;
14832 w
->base_line_number
= Qnil
;
14836 w
->base_line_number
= make_number (topline
- nlines
);
14837 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
14840 /* Now count lines from the start pos to point. */
14841 nlines
= display_count_lines (startpos
, startpos_byte
,
14842 PT_BYTE
, PT
, &junk
);
14844 /* Record that we did display the line number. */
14845 line_number_displayed
= 1;
14847 /* Make the string to show. */
14848 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
14849 return decode_mode_spec_buf
;
14852 char* p
= decode_mode_spec_buf
;
14853 int pad
= field_width
- 2;
14859 return decode_mode_spec_buf
;
14865 obj
= b
->mode_name
;
14869 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
14875 int pos
= marker_position (w
->start
);
14876 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14878 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
14880 if (pos
<= BUF_BEGV (b
))
14885 else if (pos
<= BUF_BEGV (b
))
14889 if (total
> 1000000)
14890 /* Do it differently for a large value, to avoid overflow. */
14891 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14893 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14894 /* We can't normally display a 3-digit number,
14895 so get us a 2-digit number that is close. */
14898 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14899 return decode_mode_spec_buf
;
14903 /* Display percentage of size above the bottom of the screen. */
14906 int toppos
= marker_position (w
->start
);
14907 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14908 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14910 if (botpos
>= BUF_ZV (b
))
14912 if (toppos
<= BUF_BEGV (b
))
14919 if (total
> 1000000)
14920 /* Do it differently for a large value, to avoid overflow. */
14921 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14923 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14924 /* We can't normally display a 3-digit number,
14925 so get us a 2-digit number that is close. */
14928 if (toppos
<= BUF_BEGV (b
))
14929 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14931 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14932 return decode_mode_spec_buf
;
14937 /* status of process */
14938 obj
= Fget_buffer_process (w
->buffer
);
14940 return "no process";
14941 #ifdef subprocesses
14942 obj
= Fsymbol_name (Fprocess_status (obj
));
14946 case 't': /* indicate TEXT or BINARY */
14947 #ifdef MODE_LINE_BINARY_TEXT
14948 return MODE_LINE_BINARY_TEXT (b
);
14954 /* coding-system (not including end-of-line format) */
14956 /* coding-system (including end-of-line type) */
14958 int eol_flag
= (c
== 'Z');
14959 char *p
= decode_mode_spec_buf
;
14961 if (! FRAME_WINDOW_P (f
))
14963 /* No need to mention EOL here--the terminal never needs
14964 to do EOL conversion. */
14965 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14966 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14968 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14971 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14972 #ifdef subprocesses
14973 obj
= Fget_buffer_process (Fcurrent_buffer ());
14974 if (PROCESSP (obj
))
14976 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14978 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14981 #endif /* subprocesses */
14984 return decode_mode_spec_buf
;
14990 *multibyte
= STRING_MULTIBYTE (obj
);
14991 return (char *) SDATA (obj
);
14998 /* Count up to COUNT lines starting from START / START_BYTE.
14999 But don't go beyond LIMIT_BYTE.
15000 Return the number of lines thus found (always nonnegative).
15002 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
15005 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
15006 int start
, start_byte
, limit_byte
, count
;
15009 register unsigned char *cursor
;
15010 unsigned char *base
;
15012 register int ceiling
;
15013 register unsigned char *ceiling_addr
;
15014 int orig_count
= count
;
15016 /* If we are not in selective display mode,
15017 check only for newlines. */
15018 int selective_display
= (!NILP (current_buffer
->selective_display
)
15019 && !INTEGERP (current_buffer
->selective_display
));
15023 while (start_byte
< limit_byte
)
15025 ceiling
= BUFFER_CEILING_OF (start_byte
);
15026 ceiling
= min (limit_byte
- 1, ceiling
);
15027 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
15028 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
15031 if (selective_display
)
15032 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
15035 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
15038 if (cursor
!= ceiling_addr
)
15042 start_byte
+= cursor
- base
+ 1;
15043 *byte_pos_ptr
= start_byte
;
15047 if (++cursor
== ceiling_addr
)
15053 start_byte
+= cursor
- base
;
15058 while (start_byte
> limit_byte
)
15060 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
15061 ceiling
= max (limit_byte
, ceiling
);
15062 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
15063 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
15066 if (selective_display
)
15067 while (--cursor
!= ceiling_addr
15068 && *cursor
!= '\n' && *cursor
!= 015)
15071 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
15074 if (cursor
!= ceiling_addr
)
15078 start_byte
+= cursor
- base
+ 1;
15079 *byte_pos_ptr
= start_byte
;
15080 /* When scanning backwards, we should
15081 not count the newline posterior to which we stop. */
15082 return - orig_count
- 1;
15088 /* Here we add 1 to compensate for the last decrement
15089 of CURSOR, which took it past the valid range. */
15090 start_byte
+= cursor
- base
+ 1;
15094 *byte_pos_ptr
= limit_byte
;
15097 return - orig_count
+ count
;
15098 return orig_count
- count
;
15104 /***********************************************************************
15106 ***********************************************************************/
15108 /* Display a NUL-terminated string, starting with index START.
15110 If STRING is non-null, display that C string. Otherwise, the Lisp
15111 string LISP_STRING is displayed.
15113 If FACE_STRING is not nil, FACE_STRING_POS is a position in
15114 FACE_STRING. Display STRING or LISP_STRING with the face at
15115 FACE_STRING_POS in FACE_STRING:
15117 Display the string in the environment given by IT, but use the
15118 standard display table, temporarily.
15120 FIELD_WIDTH is the minimum number of output glyphs to produce.
15121 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15122 with spaces. If STRING has more characters, more than FIELD_WIDTH
15123 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
15125 PRECISION is the maximum number of characters to output from
15126 STRING. PRECISION < 0 means don't truncate the string.
15128 This is roughly equivalent to printf format specifiers:
15130 FIELD_WIDTH PRECISION PRINTF
15131 ----------------------------------------
15137 MULTIBYTE zero means do not display multibyte chars, > 0 means do
15138 display them, and < 0 means obey the current buffer's value of
15139 enable_multibyte_characters.
15141 Value is the number of glyphs produced. */
15144 display_string (string
, lisp_string
, face_string
, face_string_pos
,
15145 start
, it
, field_width
, precision
, max_x
, multibyte
)
15146 unsigned char *string
;
15147 Lisp_Object lisp_string
;
15148 Lisp_Object face_string
;
15149 int face_string_pos
;
15152 int field_width
, precision
, max_x
;
15155 int hpos_at_start
= it
->hpos
;
15156 int saved_face_id
= it
->face_id
;
15157 struct glyph_row
*row
= it
->glyph_row
;
15159 /* Initialize the iterator IT for iteration over STRING beginning
15160 with index START. */
15161 reseat_to_string (it
, string
, lisp_string
, start
,
15162 precision
, field_width
, multibyte
);
15164 /* If displaying STRING, set up the face of the iterator
15165 from LISP_STRING, if that's given. */
15166 if (STRINGP (face_string
))
15172 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
15173 0, it
->region_beg_charpos
,
15174 it
->region_end_charpos
,
15175 &endptr
, it
->base_face_id
, 0);
15176 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15177 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
15180 /* Set max_x to the maximum allowed X position. Don't let it go
15181 beyond the right edge of the window. */
15183 max_x
= it
->last_visible_x
;
15185 max_x
= min (max_x
, it
->last_visible_x
);
15187 /* Skip over display elements that are not visible. because IT->w is
15189 if (it
->current_x
< it
->first_visible_x
)
15190 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
15191 MOVE_TO_POS
| MOVE_TO_X
);
15193 row
->ascent
= it
->max_ascent
;
15194 row
->height
= it
->max_ascent
+ it
->max_descent
;
15195 row
->phys_ascent
= it
->max_phys_ascent
;
15196 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15198 /* This condition is for the case that we are called with current_x
15199 past last_visible_x. */
15200 while (it
->current_x
< max_x
)
15202 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
15204 /* Get the next display element. */
15205 if (!get_next_display_element (it
))
15208 /* Produce glyphs. */
15209 x_before
= it
->current_x
;
15210 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15211 PRODUCE_GLYPHS (it
);
15213 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
15216 while (i
< nglyphs
)
15218 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15220 if (!it
->truncate_lines_p
15221 && x
+ glyph
->pixel_width
> max_x
)
15223 /* End of continued line or max_x reached. */
15224 if (CHAR_GLYPH_PADDING_P (*glyph
))
15226 /* A wide character is unbreakable. */
15227 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15228 it
->current_x
= x_before
;
15232 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15237 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
15239 /* Glyph is at least partially visible. */
15241 if (x
< it
->first_visible_x
)
15242 it
->glyph_row
->x
= x
- it
->first_visible_x
;
15246 /* Glyph is off the left margin of the display area.
15247 Should not happen. */
15251 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15252 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15253 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15254 row
->phys_height
= max (row
->phys_height
,
15255 it
->max_phys_ascent
+ it
->max_phys_descent
);
15256 x
+= glyph
->pixel_width
;
15260 /* Stop if max_x reached. */
15264 /* Stop at line ends. */
15265 if (ITERATOR_AT_END_OF_LINE_P (it
))
15267 it
->continuation_lines_width
= 0;
15271 set_iterator_to_next (it
, 1);
15273 /* Stop if truncating at the right edge. */
15274 if (it
->truncate_lines_p
15275 && it
->current_x
>= it
->last_visible_x
)
15277 /* Add truncation mark, but don't do it if the line is
15278 truncated at a padding space. */
15279 if (IT_CHARPOS (*it
) < it
->string_nchars
)
15281 if (!FRAME_WINDOW_P (it
->f
))
15285 if (it
->current_x
> it
->last_visible_x
)
15287 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15288 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15290 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15292 row
->used
[TEXT_AREA
] = i
;
15293 produce_special_glyphs (it
, IT_TRUNCATION
);
15296 produce_special_glyphs (it
, IT_TRUNCATION
);
15298 it
->glyph_row
->truncated_on_right_p
= 1;
15304 /* Maybe insert a truncation at the left. */
15305 if (it
->first_visible_x
15306 && IT_CHARPOS (*it
) > 0)
15308 if (!FRAME_WINDOW_P (it
->f
))
15309 insert_left_trunc_glyphs (it
);
15310 it
->glyph_row
->truncated_on_left_p
= 1;
15313 it
->face_id
= saved_face_id
;
15315 /* Value is number of columns displayed. */
15316 return it
->hpos
- hpos_at_start
;
15321 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
15322 appears as an element of LIST or as the car of an element of LIST.
15323 If PROPVAL is a list, compare each element against LIST in that
15324 way, and return 1/2 if any element of PROPVAL is found in LIST.
15325 Otherwise return 0. This function cannot quit.
15326 The return value is 2 if the text is invisible but with an ellipsis
15327 and 1 if it's invisible and without an ellipsis. */
15330 invisible_p (propval
, list
)
15331 register Lisp_Object propval
;
15334 register Lisp_Object tail
, proptail
;
15336 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15338 register Lisp_Object tem
;
15340 if (EQ (propval
, tem
))
15342 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
15343 return NILP (XCDR (tem
)) ? 1 : 2;
15346 if (CONSP (propval
))
15348 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
15350 Lisp_Object propelt
;
15351 propelt
= XCAR (proptail
);
15352 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15354 register Lisp_Object tem
;
15356 if (EQ (propelt
, tem
))
15358 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
15359 return NILP (XCDR (tem
)) ? 1 : 2;
15368 /***********************************************************************
15370 ***********************************************************************/
15372 /* Value is the internal representation of the specified cursor type
15373 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
15374 of the bar cursor. */
15376 enum text_cursor_kinds
15377 get_specified_cursor_type (arg
, width
)
15381 enum text_cursor_kinds type
;
15386 if (EQ (arg
, Qbox
))
15387 return FILLED_BOX_CURSOR
;
15389 if (EQ (arg
, Qhollow
))
15390 return HOLLOW_BOX_CURSOR
;
15392 if (EQ (arg
, Qbar
))
15399 && EQ (XCAR (arg
), Qbar
)
15400 && INTEGERP (XCDR (arg
))
15401 && XINT (XCDR (arg
)) >= 0)
15403 *width
= XINT (XCDR (arg
));
15407 if (EQ (arg
, Qhbar
))
15410 return HBAR_CURSOR
;
15414 && EQ (XCAR (arg
), Qhbar
)
15415 && INTEGERP (XCDR (arg
))
15416 && XINT (XCDR (arg
)) >= 0)
15418 *width
= XINT (XCDR (arg
));
15419 return HBAR_CURSOR
;
15422 /* Treat anything unknown as "hollow box cursor".
15423 It was bad to signal an error; people have trouble fixing
15424 .Xdefaults with Emacs, when it has something bad in it. */
15425 type
= HOLLOW_BOX_CURSOR
;
15430 /* Set the default cursor types for specified frame. */
15432 set_frame_cursor_types (f
, arg
)
15439 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
15440 FRAME_CURSOR_WIDTH (f
) = width
;
15442 /* By default, set up the blink-off state depending on the on-state. */
15444 tem
= Fassoc (arg
, Vblink_cursor_alist
);
15447 FRAME_BLINK_OFF_CURSOR (f
)
15448 = get_specified_cursor_type (XCDR (tem
), &width
);
15449 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
15452 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
15456 /* Return the cursor we want to be displayed in window W. Return
15457 width of bar/hbar cursor through WIDTH arg. Return with
15458 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
15459 (i.e. if the `system caret' should track this cursor).
15461 In a mini-buffer window, we want the cursor only to appear if we
15462 are reading input from this window. For the selected window, we
15463 want the cursor type given by the frame parameter or buffer local
15464 setting of cursor-type. If explicitly marked off, draw no cursor.
15465 In all other cases, we want a hollow box cursor. */
15467 enum text_cursor_kinds
15468 get_window_cursor_type (w
, width
, active_cursor
)
15471 int *active_cursor
;
15473 struct frame
*f
= XFRAME (w
->frame
);
15474 struct buffer
*b
= XBUFFER (w
->buffer
);
15475 int cursor_type
= DEFAULT_CURSOR
;
15476 Lisp_Object alt_cursor
;
15477 int non_selected
= 0;
15479 *active_cursor
= 1;
15482 if (cursor_in_echo_area
15483 && FRAME_HAS_MINIBUF_P (f
)
15484 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
15486 if (w
== XWINDOW (echo_area_window
))
15488 *width
= FRAME_CURSOR_WIDTH (f
);
15489 return FRAME_DESIRED_CURSOR (f
);
15492 *active_cursor
= 0;
15496 /* Nonselected window or nonselected frame. */
15497 else if (w
!= XWINDOW (f
->selected_window
)
15498 #ifdef HAVE_WINDOW_SYSTEM
15499 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
15503 *active_cursor
= 0;
15505 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
15511 /* Never display a cursor in a window in which cursor-type is nil. */
15512 if (NILP (b
->cursor_type
))
15515 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
15518 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
15519 return get_specified_cursor_type (alt_cursor
, width
);
15522 /* Get the normal cursor type for this window. */
15523 if (EQ (b
->cursor_type
, Qt
))
15525 cursor_type
= FRAME_DESIRED_CURSOR (f
);
15526 *width
= FRAME_CURSOR_WIDTH (f
);
15529 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
15531 /* Use normal cursor if not blinked off. */
15532 if (!w
->cursor_off_p
)
15533 return cursor_type
;
15535 /* Cursor is blinked off, so determine how to "toggle" it. */
15537 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
15538 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
15539 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
15541 /* Then see if frame has specified a specific blink off cursor type. */
15542 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
15544 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
15545 return FRAME_BLINK_OFF_CURSOR (f
);
15548 /* Finally perform built-in cursor blinking:
15549 filled box <-> hollow box
15550 wide [h]bar <-> narrow [h]bar
15551 narrow [h]bar <-> no cursor
15552 other type <-> no cursor */
15554 if (cursor_type
== FILLED_BOX_CURSOR
)
15555 return HOLLOW_BOX_CURSOR
;
15557 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
15560 return cursor_type
;
15567 /***********************************************************************
15569 ***********************************************************************/
15574 Vwith_echo_area_save_vector
= Qnil
;
15575 staticpro (&Vwith_echo_area_save_vector
);
15577 Vmessage_stack
= Qnil
;
15578 staticpro (&Vmessage_stack
);
15580 Qinhibit_redisplay
= intern ("inhibit-redisplay");
15581 staticpro (&Qinhibit_redisplay
);
15583 message_dolog_marker1
= Fmake_marker ();
15584 staticpro (&message_dolog_marker1
);
15585 message_dolog_marker2
= Fmake_marker ();
15586 staticpro (&message_dolog_marker2
);
15587 message_dolog_marker3
= Fmake_marker ();
15588 staticpro (&message_dolog_marker3
);
15591 defsubr (&Sdump_frame_glyph_matrix
);
15592 defsubr (&Sdump_glyph_matrix
);
15593 defsubr (&Sdump_glyph_row
);
15594 defsubr (&Sdump_tool_bar_row
);
15595 defsubr (&Strace_redisplay
);
15596 defsubr (&Strace_to_stderr
);
15598 #ifdef HAVE_WINDOW_SYSTEM
15599 defsubr (&Stool_bar_lines_needed
);
15601 defsubr (&Sformat_mode_line
);
15603 staticpro (&Qmenu_bar_update_hook
);
15604 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
15606 staticpro (&Qoverriding_terminal_local_map
);
15607 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
15609 staticpro (&Qoverriding_local_map
);
15610 Qoverriding_local_map
= intern ("overriding-local-map");
15612 staticpro (&Qwindow_scroll_functions
);
15613 Qwindow_scroll_functions
= intern ("window-scroll-functions");
15615 staticpro (&Qredisplay_end_trigger_functions
);
15616 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
15618 staticpro (&Qinhibit_point_motion_hooks
);
15619 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
15621 QCdata
= intern (":data");
15622 staticpro (&QCdata
);
15623 Qdisplay
= intern ("display");
15624 staticpro (&Qdisplay
);
15625 Qspace_width
= intern ("space-width");
15626 staticpro (&Qspace_width
);
15627 Qraise
= intern ("raise");
15628 staticpro (&Qraise
);
15629 Qspace
= intern ("space");
15630 staticpro (&Qspace
);
15631 Qmargin
= intern ("margin");
15632 staticpro (&Qmargin
);
15633 Qleft_margin
= intern ("left-margin");
15634 staticpro (&Qleft_margin
);
15635 Qright_margin
= intern ("right-margin");
15636 staticpro (&Qright_margin
);
15637 Qalign_to
= intern ("align-to");
15638 staticpro (&Qalign_to
);
15639 QCalign_to
= intern (":align-to");
15640 staticpro (&QCalign_to
);
15641 Qrelative_width
= intern ("relative-width");
15642 staticpro (&Qrelative_width
);
15643 QCrelative_width
= intern (":relative-width");
15644 staticpro (&QCrelative_width
);
15645 QCrelative_height
= intern (":relative-height");
15646 staticpro (&QCrelative_height
);
15647 QCeval
= intern (":eval");
15648 staticpro (&QCeval
);
15649 QCpropertize
= intern (":propertize");
15650 staticpro (&QCpropertize
);
15651 Qwhen
= intern ("when");
15652 staticpro (&Qwhen
);
15653 QCfile
= intern (":file");
15654 staticpro (&QCfile
);
15655 Qfontified
= intern ("fontified");
15656 staticpro (&Qfontified
);
15657 Qfontification_functions
= intern ("fontification-functions");
15658 staticpro (&Qfontification_functions
);
15659 Qtrailing_whitespace
= intern ("trailing-whitespace");
15660 staticpro (&Qtrailing_whitespace
);
15661 Qimage
= intern ("image");
15662 staticpro (&Qimage
);
15663 Qmessage_truncate_lines
= intern ("message-truncate-lines");
15664 staticpro (&Qmessage_truncate_lines
);
15665 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
15666 staticpro (&Qcursor_in_non_selected_windows
);
15667 Qgrow_only
= intern ("grow-only");
15668 staticpro (&Qgrow_only
);
15669 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
15670 staticpro (&Qinhibit_menubar_update
);
15671 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
15672 staticpro (&Qinhibit_eval_during_redisplay
);
15673 Qposition
= intern ("position");
15674 staticpro (&Qposition
);
15675 Qbuffer_position
= intern ("buffer-position");
15676 staticpro (&Qbuffer_position
);
15677 Qobject
= intern ("object");
15678 staticpro (&Qobject
);
15679 Qbar
= intern ("bar");
15681 Qhbar
= intern ("hbar");
15682 staticpro (&Qhbar
);
15683 Qbox
= intern ("box");
15685 Qhollow
= intern ("hollow");
15686 staticpro (&Qhollow
);
15687 Qrisky_local_variable
= intern ("risky-local-variable");
15688 staticpro (&Qrisky_local_variable
);
15689 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
15690 staticpro (&Qinhibit_free_realized_faces
);
15692 list_of_error
= Fcons (intern ("error"), Qnil
);
15693 staticpro (&list_of_error
);
15695 last_arrow_position
= Qnil
;
15696 last_arrow_string
= Qnil
;
15697 staticpro (&last_arrow_position
);
15698 staticpro (&last_arrow_string
);
15700 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
15701 staticpro (&echo_buffer
[0]);
15702 staticpro (&echo_buffer
[1]);
15704 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
15705 staticpro (&echo_area_buffer
[0]);
15706 staticpro (&echo_area_buffer
[1]);
15708 Vmessages_buffer_name
= build_string ("*Messages*");
15709 staticpro (&Vmessages_buffer_name
);
15711 mode_line_proptrans_alist
= Qnil
;
15712 staticpro (&mode_line_proptrans_alist
);
15714 mode_line_string_list
= Qnil
;
15715 staticpro (&mode_line_string_list
);
15717 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
15718 doc
: /* Non-nil means highlight trailing whitespace.
15719 The face used for trailing whitespace is `trailing-whitespace'. */);
15720 Vshow_trailing_whitespace
= Qnil
;
15722 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
15723 doc
: /* Non-nil means don't actually do any redisplay.
15724 This is used for internal purposes. */);
15725 Vinhibit_redisplay
= Qnil
;
15727 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
15728 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
15729 Vglobal_mode_string
= Qnil
;
15731 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
15732 doc
: /* Marker for where to display an arrow on top of the buffer text.
15733 This must be the beginning of a line in order to work.
15734 See also `overlay-arrow-string'. */);
15735 Voverlay_arrow_position
= Qnil
;
15737 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
15738 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
15739 Voverlay_arrow_string
= Qnil
;
15741 DEFVAR_INT ("scroll-step", &scroll_step
,
15742 doc
: /* *The number of lines to try scrolling a window by when point moves out.
15743 If that fails to bring point back on frame, point is centered instead.
15744 If this is zero, point is always centered after it moves off frame.
15745 If you want scrolling to always be a line at a time, you should set
15746 `scroll-conservatively' to a large value rather than set this to 1. */);
15748 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
15749 doc
: /* *Scroll up to this many lines, to bring point back on screen.
15750 A value of zero means to scroll the text to center point vertically
15751 in the window. */);
15752 scroll_conservatively
= 0;
15754 DEFVAR_INT ("scroll-margin", &scroll_margin
,
15755 doc
: /* *Number of lines of margin at the top and bottom of a window.
15756 Recenter the window whenever point gets within this many lines
15757 of the top or bottom of the window. */);
15761 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
15764 DEFVAR_BOOL ("truncate-partial-width-windows",
15765 &truncate_partial_width_windows
,
15766 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
15767 truncate_partial_width_windows
= 1;
15769 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
15770 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
15771 Any other value means to use the appropriate face, `mode-line',
15772 `header-line', or `menu' respectively. */);
15773 mode_line_inverse_video
= 1;
15775 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
15776 doc
: /* *Maximum buffer size for which line number should be displayed.
15777 If the buffer is bigger than this, the line number does not appear
15778 in the mode line. A value of nil means no limit. */);
15779 Vline_number_display_limit
= Qnil
;
15781 DEFVAR_INT ("line-number-display-limit-width",
15782 &line_number_display_limit_width
,
15783 doc
: /* *Maximum line width (in characters) for line number display.
15784 If the average length of the lines near point is bigger than this, then the
15785 line number may be omitted from the mode line. */);
15786 line_number_display_limit_width
= 200;
15788 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
15789 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
15790 highlight_nonselected_windows
= 0;
15792 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
15793 doc
: /* Non-nil if more than one frame is visible on this display.
15794 Minibuffer-only frames don't count, but iconified frames do.
15795 This variable is not guaranteed to be accurate except while processing
15796 `frame-title-format' and `icon-title-format'. */);
15798 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
15799 doc
: /* Template for displaying the title bar of visible frames.
15800 \(Assuming the window manager supports this feature.)
15801 This variable has the same structure as `mode-line-format' (which see),
15802 and is used only on frames for which no explicit name has been set
15803 \(see `modify-frame-parameters'). */);
15804 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
15805 doc
: /* Template for displaying the title bar of an iconified frame.
15806 \(Assuming the window manager supports this feature.)
15807 This variable has the same structure as `mode-line-format' (which see),
15808 and is used only on frames for which no explicit name has been set
15809 \(see `modify-frame-parameters'). */);
15811 = Vframe_title_format
15812 = Fcons (intern ("multiple-frames"),
15813 Fcons (build_string ("%b"),
15814 Fcons (Fcons (empty_string
,
15815 Fcons (intern ("invocation-name"),
15816 Fcons (build_string ("@"),
15817 Fcons (intern ("system-name"),
15821 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
15822 doc
: /* Maximum number of lines to keep in the message log buffer.
15823 If nil, disable message logging. If t, log messages but don't truncate
15824 the buffer when it becomes large. */);
15825 Vmessage_log_max
= make_number (50);
15827 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
15828 doc
: /* Functions called before redisplay, if window sizes have changed.
15829 The value should be a list of functions that take one argument.
15830 Just before redisplay, for each frame, if any of its windows have changed
15831 size since the last redisplay, or have been split or deleted,
15832 all the functions in the list are called, with the frame as argument. */);
15833 Vwindow_size_change_functions
= Qnil
;
15835 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
15836 doc
: /* List of Functions to call before redisplaying a window with scrolling.
15837 Each function is called with two arguments, the window
15838 and its new display-start position. Note that the value of `window-end'
15839 is not valid when these functions are called. */);
15840 Vwindow_scroll_functions
= Qnil
;
15842 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
15843 doc
: /* *Non-nil means automatically resize tool-bars.
15844 This increases a tool-bar's height if not all tool-bar items are visible.
15845 It decreases a tool-bar's height when it would display blank lines
15847 auto_resize_tool_bars_p
= 1;
15849 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
15850 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
15851 auto_raise_tool_bar_buttons_p
= 1;
15853 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
15854 doc
: /* *Margin around tool-bar buttons in pixels.
15855 If an integer, use that for both horizontal and vertical margins.
15856 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
15857 HORZ specifying the horizontal margin, and VERT specifying the
15858 vertical margin. */);
15859 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
15861 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
15862 doc
: /* *Relief thickness of tool-bar buttons. */);
15863 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
15865 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
15866 doc
: /* List of functions to call to fontify regions of text.
15867 Each function is called with one argument POS. Functions must
15868 fontify a region starting at POS in the current buffer, and give
15869 fontified regions the property `fontified'. */);
15870 Vfontification_functions
= Qnil
;
15871 Fmake_variable_buffer_local (Qfontification_functions
);
15873 DEFVAR_BOOL ("unibyte-display-via-language-environment",
15874 &unibyte_display_via_language_environment
,
15875 doc
: /* *Non-nil means display unibyte text according to language environment.
15876 Specifically this means that unibyte non-ASCII characters
15877 are displayed by converting them to the equivalent multibyte characters
15878 according to the current language environment. As a result, they are
15879 displayed according to the current fontset. */);
15880 unibyte_display_via_language_environment
= 0;
15882 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
15883 doc
: /* *Maximum height for resizing mini-windows.
15884 If a float, it specifies a fraction of the mini-window frame's height.
15885 If an integer, it specifies a number of lines. */);
15886 Vmax_mini_window_height
= make_float (0.25);
15888 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
15889 doc
: /* *How to resize mini-windows.
15890 A value of nil means don't automatically resize mini-windows.
15891 A value of t means resize them to fit the text displayed in them.
15892 A value of `grow-only', the default, means let mini-windows grow
15893 only, until their display becomes empty, at which point the windows
15894 go back to their normal size. */);
15895 Vresize_mini_windows
= Qgrow_only
;
15897 DEFVAR_LISP ("cursor-in-non-selected-windows",
15898 &Vcursor_in_non_selected_windows
,
15899 doc
: /* *Cursor type to display in non-selected windows.
15900 t means to use hollow box cursor. See `cursor-type' for other values. */);
15901 Vcursor_in_non_selected_windows
= Qt
;
15903 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
15904 doc
: /* Alist specifying how to blink the cursor off.
15905 Each element has the form (ON-STATE . OFF-STATE). Whenever the
15906 `cursor-type' frame-parameter or variable equals ON-STATE,
15907 comparing using `equal', Emacs uses OFF-STATE to specify
15908 how to blink it off. */);
15909 Vblink_cursor_alist
= Qnil
;
15911 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
15912 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
15913 automatic_hscrolling_p
= 1;
15915 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
15916 doc
: /* *How many columns away from the window edge point is allowed to get
15917 before automatic hscrolling will horizontally scroll the window. */);
15918 hscroll_margin
= 5;
15920 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
15921 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
15922 When point is less than `automatic-hscroll-margin' columns from the window
15923 edge, automatic hscrolling will scroll the window by the amount of columns
15924 determined by this variable. If its value is a positive integer, scroll that
15925 many columns. If it's a positive floating-point number, it specifies the
15926 fraction of the window's width to scroll. If it's nil or zero, point will be
15927 centered horizontally after the scroll. Any other value, including negative
15928 numbers, are treated as if the value were zero.
15930 Automatic hscrolling always moves point outside the scroll margin, so if
15931 point was more than scroll step columns inside the margin, the window will
15932 scroll more than the value given by the scroll step.
15934 Note that the lower bound for automatic hscrolling specified by `scroll-left'
15935 and `scroll-right' overrides this variable's effect. */);
15936 Vhscroll_step
= make_number (0);
15938 DEFVAR_LISP ("image-types", &Vimage_types
,
15939 doc
: /* List of supported image types.
15940 Each element of the list is a symbol for a supported image type. */);
15941 Vimage_types
= Qnil
;
15943 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
15944 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
15945 Bind this around calls to `message' to let it take effect. */);
15946 message_truncate_lines
= 0;
15948 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
15949 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
15950 Can be used to update submenus whose contents should vary. */);
15951 Vmenu_bar_update_hook
= Qnil
;
15953 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
15954 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
15955 inhibit_menubar_update
= 0;
15957 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
15958 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
15959 inhibit_eval_during_redisplay
= 0;
15961 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
15962 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
15963 inhibit_free_realized_faces
= 0;
15966 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
15967 doc
: /* Inhibit try_window_id display optimization. */);
15968 inhibit_try_window_id
= 0;
15970 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
15971 doc
: /* Inhibit try_window_reusing display optimization. */);
15972 inhibit_try_window_reusing
= 0;
15974 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
15975 doc
: /* Inhibit try_cursor_movement display optimization. */);
15976 inhibit_try_cursor_movement
= 0;
15977 #endif /* GLYPH_DEBUG */
15981 /* Initialize this module when Emacs starts. */
15986 Lisp_Object root_window
;
15987 struct window
*mini_w
;
15989 current_header_line_height
= current_mode_line_height
= -1;
15991 CHARPOS (this_line_start_pos
) = 0;
15993 mini_w
= XWINDOW (minibuf_window
);
15994 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
15996 if (!noninteractive
)
15998 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
16001 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
16002 set_window_height (root_window
,
16003 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
16005 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
16006 set_window_height (minibuf_window
, 1, 0);
16008 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
16009 mini_w
->width
= make_number (FRAME_WIDTH (f
));
16011 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
16012 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
16013 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
16015 /* The default ellipsis glyphs `...'. */
16016 for (i
= 0; i
< 3; ++i
)
16017 default_invis_vector
[i
] = make_number ('.');
16021 /* Allocate the buffer for frame titles.
16022 Also used for `format-mode-line'. */
16024 frame_title_buf
= (char *) xmalloc (size
);
16025 frame_title_buf_end
= frame_title_buf
+ size
;
16026 frame_title_ptr
= NULL
;
16029 help_echo_showing_p
= 0;