1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking a iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
184 #include "termhooks.h"
185 #include "intervals.h"
188 #include "region-cache.h"
191 #ifdef HAVE_X_WINDOWS
201 #define INFINITY 10000000
203 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
204 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
205 extern int pending_menu_activation
;
208 extern int interrupt_input
;
209 extern int command_loop_level
;
211 extern int minibuffer_auto_raise
;
213 extern Lisp_Object Qface
;
215 extern Lisp_Object Voverriding_local_map
;
216 extern Lisp_Object Voverriding_local_map_menu_flag
;
217 extern Lisp_Object Qmenu_item
;
219 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
220 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
221 Lisp_Object Qredisplay_end_trigger_functions
;
222 Lisp_Object Qinhibit_point_motion_hooks
;
223 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
;
224 Lisp_Object Qfontified
;
225 Lisp_Object Qgrow_only
;
226 Lisp_Object Qinhibit_eval_during_redisplay
;
227 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
229 /* Functions called to fontify regions of text. */
231 Lisp_Object Vfontification_functions
;
232 Lisp_Object Qfontification_functions
;
234 /* Non-zero means draw tool bar buttons raised when the mouse moves
237 int auto_raise_tool_bar_buttons_p
;
239 /* Margin around tool bar buttons in pixels. */
241 Lisp_Object Vtool_bar_button_margin
;
243 /* Thickness of shadow to draw around tool bar buttons. */
245 int tool_bar_button_relief
;
247 /* Non-zero means automatically resize tool-bars so that all tool-bar
248 items are visible, and no blank lines remain. */
250 int auto_resize_tool_bars_p
;
252 /* Non-nil means don't actually do any redisplay. */
254 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
256 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
258 int inhibit_eval_during_redisplay
;
260 /* Names of text properties relevant for redisplay. */
262 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
263 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
265 /* Symbols used in text property values. */
267 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
268 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
270 extern Lisp_Object Qheight
;
272 /* Non-nil means highlight trailing whitespace. */
274 Lisp_Object Vshow_trailing_whitespace
;
276 /* Name of the face used to highlight trailing whitespace. */
278 Lisp_Object Qtrailing_whitespace
;
280 /* The symbol `image' which is the car of the lists used to represent
285 /* Non-zero means print newline to stdout before next mini-buffer
288 int noninteractive_need_newline
;
290 /* Non-zero means print newline to message log before next message. */
292 static int message_log_need_newline
;
294 /* Three markers that message_dolog uses.
295 It could allocate them itself, but that causes trouble
296 in handling memory-full errors. */
297 static Lisp_Object message_dolog_marker1
;
298 static Lisp_Object message_dolog_marker2
;
299 static Lisp_Object message_dolog_marker3
;
301 /* The buffer position of the first character appearing entirely or
302 partially on the line of the selected window which contains the
303 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
304 redisplay optimization in redisplay_internal. */
306 static struct text_pos this_line_start_pos
;
308 /* Number of characters past the end of the line above, including the
309 terminating newline. */
311 static struct text_pos this_line_end_pos
;
313 /* The vertical positions and the height of this line. */
315 static int this_line_vpos
;
316 static int this_line_y
;
317 static int this_line_pixel_height
;
319 /* X position at which this display line starts. Usually zero;
320 negative if first character is partially visible. */
322 static int this_line_start_x
;
324 /* Buffer that this_line_.* variables are referring to. */
326 static struct buffer
*this_line_buffer
;
328 /* Nonzero means truncate lines in all windows less wide than the
331 int truncate_partial_width_windows
;
333 /* A flag to control how to display unibyte 8-bit character. */
335 int unibyte_display_via_language_environment
;
337 /* Nonzero means we have more than one non-mini-buffer-only frame.
338 Not guaranteed to be accurate except while parsing
339 frame-title-format. */
343 Lisp_Object Vglobal_mode_string
;
345 /* Marker for where to display an arrow on top of the buffer text. */
347 Lisp_Object Voverlay_arrow_position
;
349 /* String to display for the arrow. Only used on terminal frames. */
351 Lisp_Object Voverlay_arrow_string
;
353 /* Values of those variables at last redisplay. However, if
354 Voverlay_arrow_position is a marker, last_arrow_position is its
355 numerical position. */
357 static Lisp_Object last_arrow_position
, last_arrow_string
;
359 /* Like mode-line-format, but for the title bar on a visible frame. */
361 Lisp_Object Vframe_title_format
;
363 /* Like mode-line-format, but for the title bar on an iconified frame. */
365 Lisp_Object Vicon_title_format
;
367 /* List of functions to call when a window's size changes. These
368 functions get one arg, a frame on which one or more windows' sizes
371 static Lisp_Object Vwindow_size_change_functions
;
373 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
375 /* Nonzero if overlay arrow has been displayed once in this window. */
377 static int overlay_arrow_seen
;
379 /* Nonzero means highlight the region even in nonselected windows. */
381 int highlight_nonselected_windows
;
383 /* If cursor motion alone moves point off frame, try scrolling this
384 many lines up or down if that will bring it back. */
386 static int scroll_step
;
388 /* Nonzero means scroll just far enough to bring point back on the
389 screen, when appropriate. */
391 static int scroll_conservatively
;
393 /* Recenter the window whenever point gets within this many lines of
394 the top or bottom of the window. This value is translated into a
395 pixel value by multiplying it with CANON_Y_UNIT, which means that
396 there is really a fixed pixel height scroll margin. */
400 /* Number of windows showing the buffer of the selected window (or
401 another buffer with the same base buffer). keyboard.c refers to
406 /* Vector containing glyphs for an ellipsis `...'. */
408 static Lisp_Object default_invis_vector
[3];
410 /* Zero means display the mode-line/header-line/menu-bar in the default face
411 (this slightly odd definition is for compatibility with previous versions
412 of emacs), non-zero means display them using their respective faces.
414 This variable is deprecated. */
416 int mode_line_inverse_video
;
418 /* Prompt to display in front of the mini-buffer contents. */
420 Lisp_Object minibuf_prompt
;
422 /* Width of current mini-buffer prompt. Only set after display_line
423 of the line that contains the prompt. */
425 int minibuf_prompt_width
;
426 int minibuf_prompt_pixel_width
;
428 /* This is the window where the echo area message was displayed. It
429 is always a mini-buffer window, but it may not be the same window
430 currently active as a mini-buffer. */
432 Lisp_Object echo_area_window
;
434 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
435 pushes the current message and the value of
436 message_enable_multibyte on the stack, the function restore_message
437 pops the stack and displays MESSAGE again. */
439 Lisp_Object Vmessage_stack
;
441 /* Nonzero means multibyte characters were enabled when the echo area
442 message was specified. */
444 int message_enable_multibyte
;
446 /* Nonzero if we should redraw the mode lines on the next redisplay. */
448 int update_mode_lines
;
450 /* Nonzero if window sizes or contents have changed since last
451 redisplay that finished. */
453 int windows_or_buffers_changed
;
455 /* Nonzero after display_mode_line if %l was used and it displayed a
458 int line_number_displayed
;
460 /* Maximum buffer size for which to display line numbers. */
462 Lisp_Object Vline_number_display_limit
;
464 /* Line width to consider when repositioning for line number display. */
466 static int line_number_display_limit_width
;
468 /* Number of lines to keep in the message log buffer. t means
469 infinite. nil means don't log at all. */
471 Lisp_Object Vmessage_log_max
;
473 /* The name of the *Messages* buffer, a string. */
475 static Lisp_Object Vmessages_buffer_name
;
477 /* Current, index 0, and last displayed echo area message. Either
478 buffers from echo_buffers, or nil to indicate no message. */
480 Lisp_Object echo_area_buffer
[2];
482 /* The buffers referenced from echo_area_buffer. */
484 static Lisp_Object echo_buffer
[2];
486 /* A vector saved used in with_area_buffer to reduce consing. */
488 static Lisp_Object Vwith_echo_area_save_vector
;
490 /* Non-zero means display_echo_area should display the last echo area
491 message again. Set by redisplay_preserve_echo_area. */
493 static int display_last_displayed_message_p
;
495 /* Nonzero if echo area is being used by print; zero if being used by
498 int message_buf_print
;
500 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
502 Lisp_Object Qinhibit_menubar_update
;
503 int inhibit_menubar_update
;
505 /* Maximum height for resizing mini-windows. Either a float
506 specifying a fraction of the available height, or an integer
507 specifying a number of lines. */
509 Lisp_Object Vmax_mini_window_height
;
511 /* Non-zero means messages should be displayed with truncated
512 lines instead of being continued. */
514 int message_truncate_lines
;
515 Lisp_Object Qmessage_truncate_lines
;
517 /* Set to 1 in clear_message to make redisplay_internal aware
518 of an emptied echo area. */
520 static int message_cleared_p
;
522 /* Non-zero means we want a hollow cursor in windows that are not
523 selected. Zero means there's no cursor in such windows. */
525 int cursor_in_non_selected_windows
;
526 Lisp_Object Qcursor_in_non_selected_windows
;
528 /* A scratch glyph row with contents used for generating truncation
529 glyphs. Also used in direct_output_for_insert. */
531 #define MAX_SCRATCH_GLYPHS 100
532 struct glyph_row scratch_glyph_row
;
533 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
535 /* Ascent and height of the last line processed by move_it_to. */
537 static int last_max_ascent
, last_height
;
539 /* Non-zero if there's a help-echo in the echo area. */
541 int help_echo_showing_p
;
543 /* If >= 0, computed, exact values of mode-line and header-line height
544 to use in the macros CURRENT_MODE_LINE_HEIGHT and
545 CURRENT_HEADER_LINE_HEIGHT. */
547 int current_mode_line_height
, current_header_line_height
;
549 /* The maximum distance to look ahead for text properties. Values
550 that are too small let us call compute_char_face and similar
551 functions too often which is expensive. Values that are too large
552 let us call compute_char_face and alike too often because we
553 might not be interested in text properties that far away. */
555 #define TEXT_PROP_DISTANCE_LIMIT 100
559 /* Variables to turn off display optimizations from Lisp. */
561 int inhibit_try_window_id
, inhibit_try_window_reusing
;
562 int inhibit_try_cursor_movement
;
564 /* Non-zero means print traces of redisplay if compiled with
567 int trace_redisplay_p
;
569 #endif /* GLYPH_DEBUG */
571 #ifdef DEBUG_TRACE_MOVE
572 /* Non-zero means trace with TRACE_MOVE to stderr. */
575 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
577 #define TRACE_MOVE(x) (void) 0
580 /* Non-zero means automatically scroll windows horizontally to make
583 int automatic_hscrolling_p
;
585 /* A list of symbols, one for each supported image type. */
587 Lisp_Object Vimage_types
;
589 /* The variable `resize-mini-windows'. If nil, don't resize
590 mini-windows. If t, always resize them to fit the text they
591 display. If `grow-only', let mini-windows grow only until they
594 Lisp_Object Vresize_mini_windows
;
596 /* Buffer being redisplayed -- for redisplay_window_error. */
598 struct buffer
*displayed_buffer
;
600 /* Value returned from text property handlers (see below). */
605 HANDLED_RECOMPUTE_PROPS
,
606 HANDLED_OVERLAY_STRING_CONSUMED
,
610 /* A description of text properties that redisplay is interested
615 /* The name of the property. */
618 /* A unique index for the property. */
621 /* A handler function called to set up iterator IT from the property
622 at IT's current position. Value is used to steer handle_stop. */
623 enum prop_handled (*handler
) P_ ((struct it
*it
));
626 static enum prop_handled handle_face_prop
P_ ((struct it
*));
627 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
628 static enum prop_handled handle_display_prop
P_ ((struct it
*));
629 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
630 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
631 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
633 /* Properties handled by iterators. */
635 static struct props it_props
[] =
637 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
638 /* Handle `face' before `display' because some sub-properties of
639 `display' need to know the face. */
640 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
641 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
642 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
643 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
647 /* Value is the position described by X. If X is a marker, value is
648 the marker_position of X. Otherwise, value is X. */
650 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
652 /* Enumeration returned by some move_it_.* functions internally. */
656 /* Not used. Undefined value. */
659 /* Move ended at the requested buffer position or ZV. */
660 MOVE_POS_MATCH_OR_ZV
,
662 /* Move ended at the requested X pixel position. */
665 /* Move within a line ended at the end of a line that must be
669 /* Move within a line ended at the end of a line that would
670 be displayed truncated. */
673 /* Move within a line ended at a line end. */
679 /* Function prototypes. */
681 static void setup_for_ellipsis
P_ ((struct it
*));
682 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
683 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
684 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
685 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
686 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
687 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
690 static int invisible_text_between_p
P_ ((struct it
*, int, int));
693 static int next_element_from_ellipsis
P_ ((struct it
*));
694 static void pint2str
P_ ((char *, int, int));
695 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
697 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
698 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
699 static void store_frame_title_char
P_ ((char));
700 static int store_frame_title
P_ ((unsigned char *, int, int));
701 static void x_consider_frame_title
P_ ((Lisp_Object
));
702 static void handle_stop
P_ ((struct it
*));
703 static int tool_bar_lines_needed
P_ ((struct frame
*));
704 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
705 static void ensure_echo_area_buffers
P_ ((void));
706 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
707 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
708 static int with_echo_area_buffer
P_ ((struct window
*, int,
709 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
710 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
711 static void clear_garbaged_frames
P_ ((void));
712 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
713 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
714 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
715 static int display_echo_area
P_ ((struct window
*));
716 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
717 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
718 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
719 static int string_char_and_length
P_ ((unsigned char *, int, int *));
720 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
722 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
723 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
724 static void insert_left_trunc_glyphs
P_ ((struct it
*));
725 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
726 static void extend_face_to_end_of_line
P_ ((struct it
*));
727 static int append_space
P_ ((struct it
*, int));
728 static int make_cursor_line_fully_visible
P_ ((struct window
*));
729 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
730 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
731 static int trailing_whitespace_p
P_ ((int));
732 static int message_log_check_duplicate
P_ ((int, int, int, int));
733 static void push_it
P_ ((struct it
*));
734 static void pop_it
P_ ((struct it
*));
735 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
736 static void redisplay_internal
P_ ((int));
737 static int echo_area_display
P_ ((int));
738 static void redisplay_windows
P_ ((Lisp_Object
));
739 static void redisplay_window
P_ ((Lisp_Object
, int));
740 static Lisp_Object
redisplay_window_error ();
741 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
742 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
743 static void update_menu_bar
P_ ((struct frame
*, int));
744 static int try_window_reusing_current_matrix
P_ ((struct window
*));
745 static int try_window_id
P_ ((struct window
*));
746 static int display_line
P_ ((struct it
*));
747 static int display_mode_lines
P_ ((struct window
*));
748 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
749 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
750 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
751 static void display_menu_bar
P_ ((struct window
*));
752 static int display_count_lines
P_ ((int, int, int, int, int *));
753 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
754 int, int, struct it
*, int, int, int, int));
755 static void compute_line_metrics
P_ ((struct it
*));
756 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
757 static int get_overlay_strings
P_ ((struct it
*, int));
758 static void next_overlay_string
P_ ((struct it
*));
759 static void reseat
P_ ((struct it
*, struct text_pos
, int));
760 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
761 static void back_to_previous_visible_line_start
P_ ((struct it
*));
762 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
763 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
764 static int next_element_from_display_vector
P_ ((struct it
*));
765 static int next_element_from_string
P_ ((struct it
*));
766 static int next_element_from_c_string
P_ ((struct it
*));
767 static int next_element_from_buffer
P_ ((struct it
*));
768 static int next_element_from_composition
P_ ((struct it
*));
769 static int next_element_from_image
P_ ((struct it
*));
770 static int next_element_from_stretch
P_ ((struct it
*));
771 static void load_overlay_strings
P_ ((struct it
*, int));
772 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
773 struct display_pos
*));
774 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
775 Lisp_Object
, int, int, int, int));
776 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
778 void move_it_vertically_backward
P_ ((struct it
*, int));
779 static void init_to_row_start
P_ ((struct it
*, struct window
*,
780 struct glyph_row
*));
781 static int init_to_row_end
P_ ((struct it
*, struct window
*,
782 struct glyph_row
*));
783 static void back_to_previous_line_start
P_ ((struct it
*));
784 static int forward_to_next_line_start
P_ ((struct it
*, int *));
785 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
787 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
788 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
789 static int number_of_chars
P_ ((unsigned char *, int));
790 static void compute_stop_pos
P_ ((struct it
*));
791 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
793 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
794 static int next_overlay_change
P_ ((int));
795 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
796 Lisp_Object
, struct text_pos
*,
798 static int underlying_face_id
P_ ((struct it
*));
799 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
802 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
803 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
805 #ifdef HAVE_WINDOW_SYSTEM
807 static void update_tool_bar
P_ ((struct frame
*, int));
808 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
809 static int redisplay_tool_bar
P_ ((struct frame
*));
810 static void display_tool_bar_line
P_ ((struct it
*));
812 #endif /* HAVE_WINDOW_SYSTEM */
815 /***********************************************************************
816 Window display dimensions
817 ***********************************************************************/
819 /* Return the window-relative maximum y + 1 for glyph rows displaying
820 text in window W. This is the height of W minus the height of a
821 mode line, if any. */
824 window_text_bottom_y (w
)
827 struct frame
*f
= XFRAME (w
->frame
);
828 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
830 if (WINDOW_WANTS_MODELINE_P (w
))
831 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
836 /* Return the pixel width of display area AREA of window W. AREA < 0
837 means return the total width of W, not including fringes to
838 the left and right of the window. */
841 window_box_width (w
, area
)
845 struct frame
*f
= XFRAME (w
->frame
);
846 int width
= XFASTINT (w
->width
);
848 if (!w
->pseudo_window_p
)
850 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FRINGE_COLS (f
);
852 if (area
== TEXT_AREA
)
854 if (INTEGERP (w
->left_margin_width
))
855 width
-= XFASTINT (w
->left_margin_width
);
856 if (INTEGERP (w
->right_margin_width
))
857 width
-= XFASTINT (w
->right_margin_width
);
859 else if (area
== LEFT_MARGIN_AREA
)
860 width
= (INTEGERP (w
->left_margin_width
)
861 ? XFASTINT (w
->left_margin_width
) : 0);
862 else if (area
== RIGHT_MARGIN_AREA
)
863 width
= (INTEGERP (w
->right_margin_width
)
864 ? XFASTINT (w
->right_margin_width
) : 0);
867 return width
* CANON_X_UNIT (f
);
871 /* Return the pixel height of the display area of window W, not
872 including mode lines of W, if any. */
875 window_box_height (w
)
878 struct frame
*f
= XFRAME (w
->frame
);
879 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
881 xassert (height
>= 0);
883 /* Note: the code below that determines the mode-line/header-line
884 height is essentially the same as that contained in the macro
885 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
886 the appropriate glyph row has its `mode_line_p' flag set,
887 and if it doesn't, uses estimate_mode_line_height instead. */
889 if (WINDOW_WANTS_MODELINE_P (w
))
891 struct glyph_row
*ml_row
892 = (w
->current_matrix
&& w
->current_matrix
->rows
893 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
895 if (ml_row
&& ml_row
->mode_line_p
)
896 height
-= ml_row
->height
;
898 height
-= estimate_mode_line_height (f
, MODE_LINE_FACE_ID
);
901 if (WINDOW_WANTS_HEADER_LINE_P (w
))
903 struct glyph_row
*hl_row
904 = (w
->current_matrix
&& w
->current_matrix
->rows
905 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
907 if (hl_row
&& hl_row
->mode_line_p
)
908 height
-= hl_row
->height
;
910 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
913 /* With a very small font and a mode-line that's taller than
914 default, we might end up with a negative height. */
915 return max (0, height
);
919 /* Return the frame-relative coordinate of the left edge of display
920 area AREA of window W. AREA < 0 means return the left edge of the
921 whole window, to the right of the left fringe of W. */
924 window_box_left (w
, area
)
928 struct frame
*f
= XFRAME (w
->frame
);
929 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
931 if (!w
->pseudo_window_p
)
933 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
934 + FRAME_LEFT_FRINGE_WIDTH (f
));
936 if (area
== TEXT_AREA
)
937 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
938 else if (area
== RIGHT_MARGIN_AREA
)
939 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
940 + window_box_width (w
, TEXT_AREA
));
947 /* Return the frame-relative coordinate of the right edge of display
948 area AREA of window W. AREA < 0 means return the left edge of the
949 whole window, to the left of the right fringe of W. */
952 window_box_right (w
, area
)
956 return window_box_left (w
, area
) + window_box_width (w
, area
);
960 /* Get the bounding box of the display area AREA of window W, without
961 mode lines, in frame-relative coordinates. AREA < 0 means the
962 whole window, not including the left and right fringes of
963 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
964 coordinates of the upper-left corner of the box. Return in
965 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
968 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
971 int *box_x
, *box_y
, *box_width
, *box_height
;
973 struct frame
*f
= XFRAME (w
->frame
);
975 *box_width
= window_box_width (w
, area
);
976 *box_height
= window_box_height (w
);
977 *box_x
= window_box_left (w
, area
);
978 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
979 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
980 if (WINDOW_WANTS_HEADER_LINE_P (w
))
981 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
985 /* Get the bounding box of the display area AREA of window W, without
986 mode lines. AREA < 0 means the whole window, not including the
987 left and right fringe of the window. Return in *TOP_LEFT_X
988 and TOP_LEFT_Y the frame-relative pixel coordinates of the
989 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
990 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
994 window_box_edges (w
, area
, top_left_x
, top_left_y
,
995 bottom_right_x
, bottom_right_y
)
998 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1000 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1002 *bottom_right_x
+= *top_left_x
;
1003 *bottom_right_y
+= *top_left_y
;
1008 /***********************************************************************
1010 ***********************************************************************/
1012 /* Return the bottom y-position of the line the iterator IT is in.
1013 This can modify IT's settings. */
1019 int line_height
= it
->max_ascent
+ it
->max_descent
;
1020 int line_top_y
= it
->current_y
;
1022 if (line_height
== 0)
1025 line_height
= last_height
;
1026 else if (IT_CHARPOS (*it
) < ZV
)
1028 move_it_by_lines (it
, 1, 1);
1029 line_height
= (it
->max_ascent
|| it
->max_descent
1030 ? it
->max_ascent
+ it
->max_descent
1035 struct glyph_row
*row
= it
->glyph_row
;
1037 /* Use the default character height. */
1038 it
->glyph_row
= NULL
;
1039 it
->what
= IT_CHARACTER
;
1042 PRODUCE_GLYPHS (it
);
1043 line_height
= it
->ascent
+ it
->descent
;
1044 it
->glyph_row
= row
;
1048 return line_top_y
+ line_height
;
1052 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1053 1 if POS is visible and the line containing POS is fully visible.
1054 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1055 and header-lines heights. */
1058 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1060 int charpos
, *fully
, exact_mode_line_heights_p
;
1063 struct text_pos top
;
1065 struct buffer
*old_buffer
= NULL
;
1067 if (XBUFFER (w
->buffer
) != current_buffer
)
1069 old_buffer
= current_buffer
;
1070 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1073 *fully
= visible_p
= 0;
1074 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1076 /* Compute exact mode line heights, if requested. */
1077 if (exact_mode_line_heights_p
)
1079 if (WINDOW_WANTS_MODELINE_P (w
))
1080 current_mode_line_height
1081 = display_mode_line (w
, MODE_LINE_FACE_ID
,
1082 current_buffer
->mode_line_format
);
1084 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1085 current_header_line_height
1086 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1087 current_buffer
->header_line_format
);
1090 start_display (&it
, w
, top
);
1091 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1092 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1094 /* Note that we may overshoot because of invisible text. */
1095 if (IT_CHARPOS (it
) >= charpos
)
1097 int top_y
= it
.current_y
;
1098 int bottom_y
= line_bottom_y (&it
);
1099 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1101 if (top_y
< window_top_y
)
1102 visible_p
= bottom_y
> window_top_y
;
1103 else if (top_y
< it
.last_visible_y
)
1106 *fully
= bottom_y
<= it
.last_visible_y
;
1109 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1111 move_it_by_lines (&it
, 1, 0);
1112 if (charpos
< IT_CHARPOS (it
))
1120 set_buffer_internal_1 (old_buffer
);
1122 current_header_line_height
= current_mode_line_height
= -1;
1127 /* Return the next character from STR which is MAXLEN bytes long.
1128 Return in *LEN the length of the character. This is like
1129 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1130 we find one, we return a `?', but with the length of the invalid
1134 string_char_and_length (str
, maxlen
, len
)
1140 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1141 if (!CHAR_VALID_P (c
, 1))
1142 /* We may not change the length here because other places in Emacs
1143 don't use this function, i.e. they silently accept invalid
1152 /* Given a position POS containing a valid character and byte position
1153 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1155 static struct text_pos
1156 string_pos_nchars_ahead (pos
, string
, nchars
)
1157 struct text_pos pos
;
1161 xassert (STRINGP (string
) && nchars
>= 0);
1163 if (STRING_MULTIBYTE (string
))
1165 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
1166 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
1171 string_char_and_length (p
, rest
, &len
);
1172 p
+= len
, rest
-= len
;
1173 xassert (rest
>= 0);
1175 BYTEPOS (pos
) += len
;
1179 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1185 /* Value is the text position, i.e. character and byte position,
1186 for character position CHARPOS in STRING. */
1188 static INLINE
struct text_pos
1189 string_pos (charpos
, string
)
1193 struct text_pos pos
;
1194 xassert (STRINGP (string
));
1195 xassert (charpos
>= 0);
1196 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1201 /* Value is a text position, i.e. character and byte position, for
1202 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1203 means recognize multibyte characters. */
1205 static struct text_pos
1206 c_string_pos (charpos
, s
, multibyte_p
)
1211 struct text_pos pos
;
1213 xassert (s
!= NULL
);
1214 xassert (charpos
>= 0);
1218 int rest
= strlen (s
), len
;
1220 SET_TEXT_POS (pos
, 0, 0);
1223 string_char_and_length (s
, rest
, &len
);
1224 s
+= len
, rest
-= len
;
1225 xassert (rest
>= 0);
1227 BYTEPOS (pos
) += len
;
1231 SET_TEXT_POS (pos
, charpos
, charpos
);
1237 /* Value is the number of characters in C string S. MULTIBYTE_P
1238 non-zero means recognize multibyte characters. */
1241 number_of_chars (s
, multibyte_p
)
1249 int rest
= strlen (s
), len
;
1250 unsigned char *p
= (unsigned char *) s
;
1252 for (nchars
= 0; rest
> 0; ++nchars
)
1254 string_char_and_length (p
, rest
, &len
);
1255 rest
-= len
, p
+= len
;
1259 nchars
= strlen (s
);
1265 /* Compute byte position NEWPOS->bytepos corresponding to
1266 NEWPOS->charpos. POS is a known position in string STRING.
1267 NEWPOS->charpos must be >= POS.charpos. */
1270 compute_string_pos (newpos
, pos
, string
)
1271 struct text_pos
*newpos
, pos
;
1274 xassert (STRINGP (string
));
1275 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1277 if (STRING_MULTIBYTE (string
))
1278 *newpos
= string_pos_nchars_ahead (pos
, string
,
1279 CHARPOS (*newpos
) - CHARPOS (pos
));
1281 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1286 /***********************************************************************
1287 Lisp form evaluation
1288 ***********************************************************************/
1290 /* Error handler for safe_eval and safe_call. */
1293 safe_eval_handler (arg
)
1296 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1301 /* Evaluate SEXPR and return the result, or nil if something went
1302 wrong. Prevent redisplay during the evaluation. */
1310 if (inhibit_eval_during_redisplay
)
1314 int count
= BINDING_STACK_SIZE ();
1315 struct gcpro gcpro1
;
1318 specbind (Qinhibit_redisplay
, Qt
);
1319 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
1322 val
= unbind_to (count
, val
);
1329 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1330 Return the result, or nil if something went wrong. Prevent
1331 redisplay during the evaluation. */
1334 safe_call (nargs
, args
)
1340 if (inhibit_eval_during_redisplay
)
1344 int count
= BINDING_STACK_SIZE ();
1345 struct gcpro gcpro1
;
1348 gcpro1
.nvars
= nargs
;
1349 specbind (Qinhibit_redisplay
, Qt
);
1350 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1353 val
= unbind_to (count
, val
);
1360 /* Call function FN with one argument ARG.
1361 Return the result, or nil if something went wrong. */
1364 safe_call1 (fn
, arg
)
1365 Lisp_Object fn
, arg
;
1367 Lisp_Object args
[2];
1370 return safe_call (2, args
);
1375 /***********************************************************************
1377 ***********************************************************************/
1381 /* Define CHECK_IT to perform sanity checks on iterators.
1382 This is for debugging. It is too slow to do unconditionally. */
1388 if (it
->method
== next_element_from_string
)
1390 xassert (STRINGP (it
->string
));
1391 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1393 else if (it
->method
== next_element_from_buffer
)
1395 /* Check that character and byte positions agree. */
1396 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1400 xassert (it
->current
.dpvec_index
>= 0);
1402 xassert (it
->current
.dpvec_index
< 0);
1405 #define CHECK_IT(IT) check_it ((IT))
1409 #define CHECK_IT(IT) (void) 0
1416 /* Check that the window end of window W is what we expect it
1417 to be---the last row in the current matrix displaying text. */
1420 check_window_end (w
)
1423 if (!MINI_WINDOW_P (w
)
1424 && !NILP (w
->window_end_valid
))
1426 struct glyph_row
*row
;
1427 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1428 XFASTINT (w
->window_end_vpos
)),
1430 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1431 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1435 #define CHECK_WINDOW_END(W) check_window_end ((W))
1437 #else /* not GLYPH_DEBUG */
1439 #define CHECK_WINDOW_END(W) (void) 0
1441 #endif /* not GLYPH_DEBUG */
1445 /***********************************************************************
1446 Iterator initialization
1447 ***********************************************************************/
1449 /* Initialize IT for displaying current_buffer in window W, starting
1450 at character position CHARPOS. CHARPOS < 0 means that no buffer
1451 position is specified which is useful when the iterator is assigned
1452 a position later. BYTEPOS is the byte position corresponding to
1453 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1455 If ROW is not null, calls to produce_glyphs with IT as parameter
1456 will produce glyphs in that row.
1458 BASE_FACE_ID is the id of a base face to use. It must be one of
1459 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1460 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1461 displaying the tool-bar.
1463 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1464 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1465 corresponding mode line glyph row of the desired matrix of W. */
1468 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1471 int charpos
, bytepos
;
1472 struct glyph_row
*row
;
1473 enum face_id base_face_id
;
1475 int highlight_region_p
;
1477 /* Some precondition checks. */
1478 xassert (w
!= NULL
&& it
!= NULL
);
1479 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1482 /* If face attributes have been changed since the last redisplay,
1483 free realized faces now because they depend on face definitions
1484 that might have changed. */
1485 if (face_change_count
)
1487 face_change_count
= 0;
1488 free_all_realized_faces (Qnil
);
1491 /* Use one of the mode line rows of W's desired matrix if
1495 if (base_face_id
== MODE_LINE_FACE_ID
)
1496 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1497 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1498 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1502 bzero (it
, sizeof *it
);
1503 it
->current
.overlay_string_index
= -1;
1504 it
->current
.dpvec_index
= -1;
1505 it
->base_face_id
= base_face_id
;
1507 /* The window in which we iterate over current_buffer: */
1508 XSETWINDOW (it
->window
, w
);
1510 it
->f
= XFRAME (w
->frame
);
1512 /* Extra space between lines (on window systems only). */
1513 if (base_face_id
== DEFAULT_FACE_ID
1514 && FRAME_WINDOW_P (it
->f
))
1516 if (NATNUMP (current_buffer
->extra_line_spacing
))
1517 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1518 else if (it
->f
->extra_line_spacing
> 0)
1519 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1522 /* If realized faces have been removed, e.g. because of face
1523 attribute changes of named faces, recompute them. When running
1524 in batch mode, the face cache of Vterminal_frame is null. If
1525 we happen to get called, make a dummy face cache. */
1530 FRAME_FACE_CACHE (it
->f
) == NULL
)
1531 init_frame_faces (it
->f
);
1532 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1533 recompute_basic_faces (it
->f
);
1535 /* Current value of the `space-width', and 'height' properties. */
1536 it
->space_width
= Qnil
;
1537 it
->font_height
= Qnil
;
1539 /* Are control characters displayed as `^C'? */
1540 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1542 /* -1 means everything between a CR and the following line end
1543 is invisible. >0 means lines indented more than this value are
1545 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1546 ? XFASTINT (current_buffer
->selective_display
)
1547 : (!NILP (current_buffer
->selective_display
)
1549 it
->selective_display_ellipsis_p
1550 = !NILP (current_buffer
->selective_display_ellipses
);
1552 /* Display table to use. */
1553 it
->dp
= window_display_table (w
);
1555 /* Are multibyte characters enabled in current_buffer? */
1556 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1558 /* Non-zero if we should highlight the region. */
1560 = (!NILP (Vtransient_mark_mode
)
1561 && !NILP (current_buffer
->mark_active
)
1562 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1564 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1565 start and end of a visible region in window IT->w. Set both to
1566 -1 to indicate no region. */
1567 if (highlight_region_p
1568 /* Maybe highlight only in selected window. */
1569 && (/* Either show region everywhere. */
1570 highlight_nonselected_windows
1571 /* Or show region in the selected window. */
1572 || w
== XWINDOW (selected_window
)
1573 /* Or show the region if we are in the mini-buffer and W is
1574 the window the mini-buffer refers to. */
1575 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1576 && WINDOWP (Vminibuf_scroll_window
)
1577 && w
== XWINDOW (Vminibuf_scroll_window
))))
1579 int charpos
= marker_position (current_buffer
->mark
);
1580 it
->region_beg_charpos
= min (PT
, charpos
);
1581 it
->region_end_charpos
= max (PT
, charpos
);
1584 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1586 /* Get the position at which the redisplay_end_trigger hook should
1587 be run, if it is to be run at all. */
1588 if (MARKERP (w
->redisplay_end_trigger
)
1589 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1590 it
->redisplay_end_trigger_charpos
1591 = marker_position (w
->redisplay_end_trigger
);
1592 else if (INTEGERP (w
->redisplay_end_trigger
))
1593 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1595 /* Correct bogus values of tab_width. */
1596 it
->tab_width
= XINT (current_buffer
->tab_width
);
1597 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1600 /* Are lines in the display truncated? */
1601 it
->truncate_lines_p
1602 = (base_face_id
!= DEFAULT_FACE_ID
1603 || XINT (it
->w
->hscroll
)
1604 || (truncate_partial_width_windows
1605 && !WINDOW_FULL_WIDTH_P (it
->w
))
1606 || !NILP (current_buffer
->truncate_lines
));
1608 /* Get dimensions of truncation and continuation glyphs. These are
1609 displayed as fringe bitmaps under X, so we don't need them for such
1611 if (!FRAME_WINDOW_P (it
->f
))
1613 if (it
->truncate_lines_p
)
1615 /* We will need the truncation glyph. */
1616 xassert (it
->glyph_row
== NULL
);
1617 produce_special_glyphs (it
, IT_TRUNCATION
);
1618 it
->truncation_pixel_width
= it
->pixel_width
;
1622 /* We will need the continuation glyph. */
1623 xassert (it
->glyph_row
== NULL
);
1624 produce_special_glyphs (it
, IT_CONTINUATION
);
1625 it
->continuation_pixel_width
= it
->pixel_width
;
1628 /* Reset these values to zero because the produce_special_glyphs
1629 above has changed them. */
1630 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1631 it
->phys_ascent
= it
->phys_descent
= 0;
1634 /* Set this after getting the dimensions of truncation and
1635 continuation glyphs, so that we don't produce glyphs when calling
1636 produce_special_glyphs, above. */
1637 it
->glyph_row
= row
;
1638 it
->area
= TEXT_AREA
;
1640 /* Get the dimensions of the display area. The display area
1641 consists of the visible window area plus a horizontally scrolled
1642 part to the left of the window. All x-values are relative to the
1643 start of this total display area. */
1644 if (base_face_id
!= DEFAULT_FACE_ID
)
1646 /* Mode lines, menu bar in terminal frames. */
1647 it
->first_visible_x
= 0;
1648 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1653 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1654 it
->last_visible_x
= (it
->first_visible_x
1655 + window_box_width (w
, TEXT_AREA
));
1657 /* If we truncate lines, leave room for the truncator glyph(s) at
1658 the right margin. Otherwise, leave room for the continuation
1659 glyph(s). Truncation and continuation glyphs are not inserted
1660 for window-based redisplay. */
1661 if (!FRAME_WINDOW_P (it
->f
))
1663 if (it
->truncate_lines_p
)
1664 it
->last_visible_x
-= it
->truncation_pixel_width
;
1666 it
->last_visible_x
-= it
->continuation_pixel_width
;
1669 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1670 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1673 /* Leave room for a border glyph. */
1674 if (!FRAME_WINDOW_P (it
->f
)
1675 && !WINDOW_RIGHTMOST_P (it
->w
))
1676 it
->last_visible_x
-= 1;
1678 it
->last_visible_y
= window_text_bottom_y (w
);
1680 /* For mode lines and alike, arrange for the first glyph having a
1681 left box line if the face specifies a box. */
1682 if (base_face_id
!= DEFAULT_FACE_ID
)
1686 it
->face_id
= base_face_id
;
1688 /* If we have a boxed mode line, make the first character appear
1689 with a left box line. */
1690 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1691 if (face
->box
!= FACE_NO_BOX
)
1692 it
->start_of_box_run_p
= 1;
1695 /* If a buffer position was specified, set the iterator there,
1696 getting overlays and face properties from that position. */
1697 if (charpos
>= BUF_BEG (current_buffer
))
1699 it
->end_charpos
= ZV
;
1701 IT_CHARPOS (*it
) = charpos
;
1703 /* Compute byte position if not specified. */
1704 if (bytepos
< charpos
)
1705 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1707 IT_BYTEPOS (*it
) = bytepos
;
1709 /* Compute faces etc. */
1710 reseat (it
, it
->current
.pos
, 1);
1717 /* Initialize IT for the display of window W with window start POS. */
1720 start_display (it
, w
, pos
)
1723 struct text_pos pos
;
1725 struct glyph_row
*row
;
1726 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1728 row
= w
->desired_matrix
->rows
+ first_vpos
;
1729 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1731 if (!it
->truncate_lines_p
)
1733 int start_at_line_beg_p
;
1734 int first_y
= it
->current_y
;
1736 /* If window start is not at a line start, skip forward to POS to
1737 get the correct continuation lines width. */
1738 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1739 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1740 if (!start_at_line_beg_p
)
1742 reseat_at_previous_visible_line_start (it
);
1743 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1745 /* If lines are continued, this line may end in the middle
1746 of a multi-glyph character (e.g. a control character
1747 displayed as \003, or in the middle of an overlay
1748 string). In this case move_it_to above will not have
1749 taken us to the start of the continuation line but to the
1750 end of the continued line. */
1751 if (it
->current_x
> 0)
1753 if (it
->current
.dpvec_index
>= 0
1754 || it
->current
.overlay_string_index
>= 0)
1756 set_iterator_to_next (it
, 1);
1757 move_it_in_display_line_to (it
, -1, -1, 0);
1760 it
->continuation_lines_width
+= it
->current_x
;
1763 /* We're starting a new display line, not affected by the
1764 height of the continued line, so clear the appropriate
1765 fields in the iterator structure. */
1766 it
->max_ascent
= it
->max_descent
= 0;
1767 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1769 it
->current_y
= first_y
;
1771 it
->current_x
= it
->hpos
= 0;
1775 #if 0 /* Don't assert the following because start_display is sometimes
1776 called intentionally with a window start that is not at a
1777 line start. Please leave this code in as a comment. */
1779 /* Window start should be on a line start, now. */
1780 xassert (it
->continuation_lines_width
1781 || IT_CHARPOS (it
) == BEGV
1782 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1787 /* Return 1 if POS is a position in ellipses displayed for invisible
1788 text. W is the window we display, for text property lookup. */
1791 in_ellipses_for_invisible_text_p (pos
, w
)
1792 struct display_pos
*pos
;
1795 Lisp_Object prop
, window
;
1797 int charpos
= CHARPOS (pos
->pos
);
1799 /* If POS specifies a position in a display vector, this might
1800 be for an ellipsis displayed for invisible text. We won't
1801 get the iterator set up for delivering that ellipsis unless
1802 we make sure that it gets aware of the invisible text. */
1803 if (pos
->dpvec_index
>= 0
1804 && pos
->overlay_string_index
< 0
1805 && CHARPOS (pos
->string_pos
) < 0
1807 && (XSETWINDOW (window
, w
),
1808 prop
= Fget_char_property (make_number (charpos
),
1809 Qinvisible
, window
),
1810 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1812 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1814 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
1821 /* Initialize IT for stepping through current_buffer in window W,
1822 starting at position POS that includes overlay string and display
1823 vector/ control character translation position information. Value
1824 is zero if there are overlay strings with newlines at POS. */
1827 init_from_display_pos (it
, w
, pos
)
1830 struct display_pos
*pos
;
1832 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1833 int i
, overlay_strings_with_newlines
= 0;
1835 /* If POS specifies a position in a display vector, this might
1836 be for an ellipsis displayed for invisible text. We won't
1837 get the iterator set up for delivering that ellipsis unless
1838 we make sure that it gets aware of the invisible text. */
1839 if (in_ellipses_for_invisible_text_p (pos
, w
))
1845 /* Keep in mind: the call to reseat in init_iterator skips invisible
1846 text, so we might end up at a position different from POS. This
1847 is only a problem when POS is a row start after a newline and an
1848 overlay starts there with an after-string, and the overlay has an
1849 invisible property. Since we don't skip invisible text in
1850 display_line and elsewhere immediately after consuming the
1851 newline before the row start, such a POS will not be in a string,
1852 but the call to init_iterator below will move us to the
1854 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1856 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
1858 char *s
= XSTRING (it
->overlay_strings
[i
])->data
;
1859 char *e
= s
+ STRING_BYTES (XSTRING (it
->overlay_strings
[i
]));
1861 while (s
< e
&& *s
!= '\n')
1866 overlay_strings_with_newlines
= 1;
1871 /* If position is within an overlay string, set up IT to the right
1873 if (pos
->overlay_string_index
>= 0)
1877 /* If the first overlay string happens to have a `display'
1878 property for an image, the iterator will be set up for that
1879 image, and we have to undo that setup first before we can
1880 correct the overlay string index. */
1881 if (it
->method
== next_element_from_image
)
1884 /* We already have the first chunk of overlay strings in
1885 IT->overlay_strings. Load more until the one for
1886 pos->overlay_string_index is in IT->overlay_strings. */
1887 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1889 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1890 it
->current
.overlay_string_index
= 0;
1893 load_overlay_strings (it
, 0);
1894 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1898 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1899 relative_index
= (it
->current
.overlay_string_index
1900 % OVERLAY_STRING_CHUNK_SIZE
);
1901 it
->string
= it
->overlay_strings
[relative_index
];
1902 xassert (STRINGP (it
->string
));
1903 it
->current
.string_pos
= pos
->string_pos
;
1904 it
->method
= next_element_from_string
;
1907 #if 0 /* This is bogus because POS not having an overlay string
1908 position does not mean it's after the string. Example: A
1909 line starting with a before-string and initialization of IT
1910 to the previous row's end position. */
1911 else if (it
->current
.overlay_string_index
>= 0)
1913 /* If POS says we're already after an overlay string ending at
1914 POS, make sure to pop the iterator because it will be in
1915 front of that overlay string. When POS is ZV, we've thereby
1916 also ``processed'' overlay strings at ZV. */
1919 it
->current
.overlay_string_index
= -1;
1920 it
->method
= next_element_from_buffer
;
1921 if (CHARPOS (pos
->pos
) == ZV
)
1922 it
->overlay_strings_at_end_processed_p
= 1;
1926 if (CHARPOS (pos
->string_pos
) >= 0)
1928 /* Recorded position is not in an overlay string, but in another
1929 string. This can only be a string from a `display' property.
1930 IT should already be filled with that string. */
1931 it
->current
.string_pos
= pos
->string_pos
;
1932 xassert (STRINGP (it
->string
));
1935 /* Restore position in display vector translations, control
1936 character translations or ellipses. */
1937 if (pos
->dpvec_index
>= 0)
1939 if (it
->dpvec
== NULL
)
1940 get_next_display_element (it
);
1941 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1942 it
->current
.dpvec_index
= pos
->dpvec_index
;
1946 return !overlay_strings_with_newlines
;
1950 /* Initialize IT for stepping through current_buffer in window W
1951 starting at ROW->start. */
1954 init_to_row_start (it
, w
, row
)
1957 struct glyph_row
*row
;
1959 init_from_display_pos (it
, w
, &row
->start
);
1960 it
->continuation_lines_width
= row
->continuation_lines_width
;
1965 /* Initialize IT for stepping through current_buffer in window W
1966 starting in the line following ROW, i.e. starting at ROW->end.
1967 Value is zero if there are overlay strings with newlines at ROW's
1971 init_to_row_end (it
, w
, row
)
1974 struct glyph_row
*row
;
1978 if (init_from_display_pos (it
, w
, &row
->end
))
1980 if (row
->continued_p
)
1981 it
->continuation_lines_width
1982 = row
->continuation_lines_width
+ row
->pixel_width
;
1993 /***********************************************************************
1995 ***********************************************************************/
1997 /* Called when IT reaches IT->stop_charpos. Handle text property and
1998 overlay changes. Set IT->stop_charpos to the next position where
2005 enum prop_handled handled
;
2006 int handle_overlay_change_p
= 1;
2010 it
->current
.dpvec_index
= -1;
2014 handled
= HANDLED_NORMALLY
;
2016 /* Call text property handlers. */
2017 for (p
= it_props
; p
->handler
; ++p
)
2019 handled
= p
->handler (it
);
2021 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2023 else if (handled
== HANDLED_RETURN
)
2025 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2026 handle_overlay_change_p
= 0;
2029 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2031 /* Don't check for overlay strings below when set to deliver
2032 characters from a display vector. */
2033 if (it
->method
== next_element_from_display_vector
)
2034 handle_overlay_change_p
= 0;
2036 /* Handle overlay changes. */
2037 if (handle_overlay_change_p
)
2038 handled
= handle_overlay_change (it
);
2040 /* Determine where to stop next. */
2041 if (handled
== HANDLED_NORMALLY
)
2042 compute_stop_pos (it
);
2045 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2049 /* Compute IT->stop_charpos from text property and overlay change
2050 information for IT's current position. */
2053 compute_stop_pos (it
)
2056 register INTERVAL iv
, next_iv
;
2057 Lisp_Object object
, limit
, position
;
2059 /* If nowhere else, stop at the end. */
2060 it
->stop_charpos
= it
->end_charpos
;
2062 if (STRINGP (it
->string
))
2064 /* Strings are usually short, so don't limit the search for
2066 object
= it
->string
;
2068 position
= make_number (IT_STRING_CHARPOS (*it
));
2074 /* If next overlay change is in front of the current stop pos
2075 (which is IT->end_charpos), stop there. Note: value of
2076 next_overlay_change is point-max if no overlay change
2078 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2079 if (charpos
< it
->stop_charpos
)
2080 it
->stop_charpos
= charpos
;
2082 /* If showing the region, we have to stop at the region
2083 start or end because the face might change there. */
2084 if (it
->region_beg_charpos
> 0)
2086 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2087 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2088 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2089 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2092 /* Set up variables for computing the stop position from text
2093 property changes. */
2094 XSETBUFFER (object
, current_buffer
);
2095 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2096 position
= make_number (IT_CHARPOS (*it
));
2100 /* Get the interval containing IT's position. Value is a null
2101 interval if there isn't such an interval. */
2102 iv
= validate_interval_range (object
, &position
, &position
, 0);
2103 if (!NULL_INTERVAL_P (iv
))
2105 Lisp_Object values_here
[LAST_PROP_IDX
];
2108 /* Get properties here. */
2109 for (p
= it_props
; p
->handler
; ++p
)
2110 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2112 /* Look for an interval following iv that has different
2114 for (next_iv
= next_interval (iv
);
2115 (!NULL_INTERVAL_P (next_iv
)
2117 || XFASTINT (limit
) > next_iv
->position
));
2118 next_iv
= next_interval (next_iv
))
2120 for (p
= it_props
; p
->handler
; ++p
)
2122 Lisp_Object new_value
;
2124 new_value
= textget (next_iv
->plist
, *p
->name
);
2125 if (!EQ (values_here
[p
->idx
], new_value
))
2133 if (!NULL_INTERVAL_P (next_iv
))
2135 if (INTEGERP (limit
)
2136 && next_iv
->position
>= XFASTINT (limit
))
2137 /* No text property change up to limit. */
2138 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2140 /* Text properties change in next_iv. */
2141 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2145 xassert (STRINGP (it
->string
)
2146 || (it
->stop_charpos
>= BEGV
2147 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2151 /* Return the position of the next overlay change after POS in
2152 current_buffer. Value is point-max if no overlay change
2153 follows. This is like `next-overlay-change' but doesn't use
2157 next_overlay_change (pos
)
2162 Lisp_Object
*overlays
;
2166 /* Get all overlays at the given position. */
2168 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2169 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2170 if (noverlays
> len
)
2173 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2174 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2177 /* If any of these overlays ends before endpos,
2178 use its ending point instead. */
2179 for (i
= 0; i
< noverlays
; ++i
)
2184 oend
= OVERLAY_END (overlays
[i
]);
2185 oendpos
= OVERLAY_POSITION (oend
);
2186 endpos
= min (endpos
, oendpos
);
2194 /***********************************************************************
2196 ***********************************************************************/
2198 /* Handle changes in the `fontified' property of the current buffer by
2199 calling hook functions from Qfontification_functions to fontify
2202 static enum prop_handled
2203 handle_fontified_prop (it
)
2206 Lisp_Object prop
, pos
;
2207 enum prop_handled handled
= HANDLED_NORMALLY
;
2209 /* Get the value of the `fontified' property at IT's current buffer
2210 position. (The `fontified' property doesn't have a special
2211 meaning in strings.) If the value is nil, call functions from
2212 Qfontification_functions. */
2213 if (!STRINGP (it
->string
)
2215 && !NILP (Vfontification_functions
)
2216 && !NILP (Vrun_hooks
)
2217 && (pos
= make_number (IT_CHARPOS (*it
)),
2218 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2221 int count
= BINDING_STACK_SIZE ();
2224 val
= Vfontification_functions
;
2225 specbind (Qfontification_functions
, Qnil
);
2227 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2228 safe_call1 (val
, pos
);
2231 Lisp_Object globals
, fn
;
2232 struct gcpro gcpro1
, gcpro2
;
2235 GCPRO2 (val
, globals
);
2237 for (; CONSP (val
); val
= XCDR (val
))
2243 /* A value of t indicates this hook has a local
2244 binding; it means to run the global binding too.
2245 In a global value, t should not occur. If it
2246 does, we must ignore it to avoid an endless
2248 for (globals
= Fdefault_value (Qfontification_functions
);
2250 globals
= XCDR (globals
))
2252 fn
= XCAR (globals
);
2254 safe_call1 (fn
, pos
);
2258 safe_call1 (fn
, pos
);
2264 unbind_to (count
, Qnil
);
2266 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2267 something. This avoids an endless loop if they failed to
2268 fontify the text for which reason ever. */
2269 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2270 handled
= HANDLED_RECOMPUTE_PROPS
;
2278 /***********************************************************************
2280 ***********************************************************************/
2282 /* Set up iterator IT from face properties at its current position.
2283 Called from handle_stop. */
2285 static enum prop_handled
2286 handle_face_prop (it
)
2289 int new_face_id
, next_stop
;
2291 if (!STRINGP (it
->string
))
2294 = face_at_buffer_position (it
->w
,
2296 it
->region_beg_charpos
,
2297 it
->region_end_charpos
,
2300 + TEXT_PROP_DISTANCE_LIMIT
),
2303 /* Is this a start of a run of characters with box face?
2304 Caveat: this can be called for a freshly initialized
2305 iterator; face_id is -1 in this case. We know that the new
2306 face will not change until limit, i.e. if the new face has a
2307 box, all characters up to limit will have one. But, as
2308 usual, we don't know whether limit is really the end. */
2309 if (new_face_id
!= it
->face_id
)
2311 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2313 /* If new face has a box but old face has not, this is
2314 the start of a run of characters with box, i.e. it has
2315 a shadow on the left side. The value of face_id of the
2316 iterator will be -1 if this is the initial call that gets
2317 the face. In this case, we have to look in front of IT's
2318 position and see whether there is a face != new_face_id. */
2319 it
->start_of_box_run_p
2320 = (new_face
->box
!= FACE_NO_BOX
2321 && (it
->face_id
>= 0
2322 || IT_CHARPOS (*it
) == BEG
2323 || new_face_id
!= face_before_it_pos (it
)));
2324 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2329 int base_face_id
, bufpos
;
2331 if (it
->current
.overlay_string_index
>= 0)
2332 bufpos
= IT_CHARPOS (*it
);
2336 /* For strings from a buffer, i.e. overlay strings or strings
2337 from a `display' property, use the face at IT's current
2338 buffer position as the base face to merge with, so that
2339 overlay strings appear in the same face as surrounding
2340 text, unless they specify their own faces. */
2341 base_face_id
= underlying_face_id (it
);
2343 new_face_id
= face_at_string_position (it
->w
,
2345 IT_STRING_CHARPOS (*it
),
2347 it
->region_beg_charpos
,
2348 it
->region_end_charpos
,
2352 #if 0 /* This shouldn't be neccessary. Let's check it. */
2353 /* If IT is used to display a mode line we would really like to
2354 use the mode line face instead of the frame's default face. */
2355 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2356 && new_face_id
== DEFAULT_FACE_ID
)
2357 new_face_id
= MODE_LINE_FACE_ID
;
2360 /* Is this a start of a run of characters with box? Caveat:
2361 this can be called for a freshly allocated iterator; face_id
2362 is -1 is this case. We know that the new face will not
2363 change until the next check pos, i.e. if the new face has a
2364 box, all characters up to that position will have a
2365 box. But, as usual, we don't know whether that position
2366 is really the end. */
2367 if (new_face_id
!= it
->face_id
)
2369 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2370 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2372 /* If new face has a box but old face hasn't, this is the
2373 start of a run of characters with box, i.e. it has a
2374 shadow on the left side. */
2375 it
->start_of_box_run_p
2376 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2377 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2381 it
->face_id
= new_face_id
;
2382 return HANDLED_NORMALLY
;
2386 /* Return the ID of the face ``underlying'' IT's current position,
2387 which is in a string. If the iterator is associated with a
2388 buffer, return the face at IT's current buffer position.
2389 Otherwise, use the iterator's base_face_id. */
2392 underlying_face_id (it
)
2395 int face_id
= it
->base_face_id
, i
;
2397 xassert (STRINGP (it
->string
));
2399 for (i
= it
->sp
- 1; i
>= 0; --i
)
2400 if (NILP (it
->stack
[i
].string
))
2401 face_id
= it
->stack
[i
].face_id
;
2407 /* Compute the face one character before or after the current position
2408 of IT. BEFORE_P non-zero means get the face in front of IT's
2409 position. Value is the id of the face. */
2412 face_before_or_after_it_pos (it
, before_p
)
2417 int next_check_charpos
;
2418 struct text_pos pos
;
2420 xassert (it
->s
== NULL
);
2422 if (STRINGP (it
->string
))
2424 int bufpos
, base_face_id
;
2426 /* No face change past the end of the string (for the case
2427 we are padding with spaces). No face change before the
2429 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2430 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2433 /* Set pos to the position before or after IT's current position. */
2435 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2437 /* For composition, we must check the character after the
2439 pos
= (it
->what
== IT_COMPOSITION
2440 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2441 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2443 if (it
->current
.overlay_string_index
>= 0)
2444 bufpos
= IT_CHARPOS (*it
);
2448 base_face_id
= underlying_face_id (it
);
2450 /* Get the face for ASCII, or unibyte. */
2451 face_id
= face_at_string_position (it
->w
,
2455 it
->region_beg_charpos
,
2456 it
->region_end_charpos
,
2457 &next_check_charpos
,
2460 /* Correct the face for charsets different from ASCII. Do it
2461 for the multibyte case only. The face returned above is
2462 suitable for unibyte text if IT->string is unibyte. */
2463 if (STRING_MULTIBYTE (it
->string
))
2465 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2466 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2468 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2470 c
= string_char_and_length (p
, rest
, &len
);
2471 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2476 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2477 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2480 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2481 pos
= it
->current
.pos
;
2484 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2487 if (it
->what
== IT_COMPOSITION
)
2488 /* For composition, we must check the position after the
2490 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2492 INC_TEXT_POS (pos
, it
->multibyte_p
);
2495 /* Determine face for CHARSET_ASCII, or unibyte. */
2496 face_id
= face_at_buffer_position (it
->w
,
2498 it
->region_beg_charpos
,
2499 it
->region_end_charpos
,
2500 &next_check_charpos
,
2503 /* Correct the face for charsets different from ASCII. Do it
2504 for the multibyte case only. The face returned above is
2505 suitable for unibyte text if current_buffer is unibyte. */
2506 if (it
->multibyte_p
)
2508 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2509 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2510 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2519 /***********************************************************************
2521 ***********************************************************************/
2523 /* Set up iterator IT from invisible properties at its current
2524 position. Called from handle_stop. */
2526 static enum prop_handled
2527 handle_invisible_prop (it
)
2530 enum prop_handled handled
= HANDLED_NORMALLY
;
2532 if (STRINGP (it
->string
))
2534 extern Lisp_Object Qinvisible
;
2535 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2537 /* Get the value of the invisible text property at the
2538 current position. Value will be nil if there is no such
2540 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2541 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2544 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2546 handled
= HANDLED_RECOMPUTE_PROPS
;
2548 /* Get the position at which the next change of the
2549 invisible text property can be found in IT->string.
2550 Value will be nil if the property value is the same for
2551 all the rest of IT->string. */
2552 XSETINT (limit
, XSTRING (it
->string
)->size
);
2553 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2556 /* Text at current position is invisible. The next
2557 change in the property is at position end_charpos.
2558 Move IT's current position to that position. */
2559 if (INTEGERP (end_charpos
)
2560 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2562 struct text_pos old
;
2563 old
= it
->current
.string_pos
;
2564 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2565 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2569 /* The rest of the string is invisible. If this is an
2570 overlay string, proceed with the next overlay string
2571 or whatever comes and return a character from there. */
2572 if (it
->current
.overlay_string_index
>= 0)
2574 next_overlay_string (it
);
2575 /* Don't check for overlay strings when we just
2576 finished processing them. */
2577 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2581 struct Lisp_String
*s
= XSTRING (it
->string
);
2582 IT_STRING_CHARPOS (*it
) = s
->size
;
2583 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2590 int invis_p
, newpos
, next_stop
, start_charpos
;
2591 Lisp_Object pos
, prop
, overlay
;
2593 /* First of all, is there invisible text at this position? */
2594 start_charpos
= IT_CHARPOS (*it
);
2595 pos
= make_number (IT_CHARPOS (*it
));
2596 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2598 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2600 /* If we are on invisible text, skip over it. */
2601 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
2603 /* Record whether we have to display an ellipsis for the
2605 int display_ellipsis_p
= invis_p
== 2;
2607 handled
= HANDLED_RECOMPUTE_PROPS
;
2609 /* Loop skipping over invisible text. The loop is left at
2610 ZV or with IT on the first char being visible again. */
2613 /* Try to skip some invisible text. Return value is the
2614 position reached which can be equal to IT's position
2615 if there is nothing invisible here. This skips both
2616 over invisible text properties and overlays with
2617 invisible property. */
2618 newpos
= skip_invisible (IT_CHARPOS (*it
),
2619 &next_stop
, ZV
, it
->window
);
2621 /* If we skipped nothing at all we weren't at invisible
2622 text in the first place. If everything to the end of
2623 the buffer was skipped, end the loop. */
2624 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2628 /* We skipped some characters but not necessarily
2629 all there are. Check if we ended up on visible
2630 text. Fget_char_property returns the property of
2631 the char before the given position, i.e. if we
2632 get invis_p = 0, this means that the char at
2633 newpos is visible. */
2634 pos
= make_number (newpos
);
2635 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2636 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2639 /* If we ended up on invisible text, proceed to
2640 skip starting with next_stop. */
2642 IT_CHARPOS (*it
) = next_stop
;
2646 /* The position newpos is now either ZV or on visible text. */
2647 IT_CHARPOS (*it
) = newpos
;
2648 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2650 /* If there are before-strings at the start of invisible
2651 text, and the text is invisible because of a text
2652 property, arrange to show before-strings because 20.x did
2653 it that way. (If the text is invisible because of an
2654 overlay property instead of a text property, this is
2655 already handled in the overlay code.) */
2657 && get_overlay_strings (it
, start_charpos
))
2659 handled
= HANDLED_RECOMPUTE_PROPS
;
2660 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2662 else if (display_ellipsis_p
)
2663 setup_for_ellipsis (it
);
2671 /* Make iterator IT return `...' next. */
2674 setup_for_ellipsis (it
)
2678 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2680 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2681 it
->dpvec
= v
->contents
;
2682 it
->dpend
= v
->contents
+ v
->size
;
2686 /* Default `...'. */
2687 it
->dpvec
= default_invis_vector
;
2688 it
->dpend
= default_invis_vector
+ 3;
2691 /* The ellipsis display does not replace the display of the
2692 character at the new position. Indicate this by setting
2693 IT->dpvec_char_len to zero. */
2694 it
->dpvec_char_len
= 0;
2696 it
->current
.dpvec_index
= 0;
2697 it
->method
= next_element_from_display_vector
;
2702 /***********************************************************************
2704 ***********************************************************************/
2706 /* Set up iterator IT from `display' property at its current position.
2707 Called from handle_stop. */
2709 static enum prop_handled
2710 handle_display_prop (it
)
2713 Lisp_Object prop
, object
;
2714 struct text_pos
*position
;
2715 int display_replaced_p
= 0;
2717 if (STRINGP (it
->string
))
2719 object
= it
->string
;
2720 position
= &it
->current
.string_pos
;
2724 object
= it
->w
->buffer
;
2725 position
= &it
->current
.pos
;
2728 /* Reset those iterator values set from display property values. */
2729 it
->font_height
= Qnil
;
2730 it
->space_width
= Qnil
;
2733 /* We don't support recursive `display' properties, i.e. string
2734 values that have a string `display' property, that have a string
2735 `display' property etc. */
2736 if (!it
->string_from_display_prop_p
)
2737 it
->area
= TEXT_AREA
;
2739 prop
= Fget_char_property (make_number (position
->charpos
),
2742 return HANDLED_NORMALLY
;
2745 /* Simple properties. */
2746 && !EQ (XCAR (prop
), Qimage
)
2747 && !EQ (XCAR (prop
), Qspace
)
2748 && !EQ (XCAR (prop
), Qwhen
)
2749 && !EQ (XCAR (prop
), Qspace_width
)
2750 && !EQ (XCAR (prop
), Qheight
)
2751 && !EQ (XCAR (prop
), Qraise
)
2752 /* Marginal area specifications. */
2753 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2754 && !NILP (XCAR (prop
)))
2756 for (; CONSP (prop
); prop
= XCDR (prop
))
2758 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2759 position
, display_replaced_p
))
2760 display_replaced_p
= 1;
2763 else if (VECTORP (prop
))
2766 for (i
= 0; i
< ASIZE (prop
); ++i
)
2767 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2768 position
, display_replaced_p
))
2769 display_replaced_p
= 1;
2773 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2774 display_replaced_p
= 1;
2777 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2781 /* Value is the position of the end of the `display' property starting
2782 at START_POS in OBJECT. */
2784 static struct text_pos
2785 display_prop_end (it
, object
, start_pos
)
2788 struct text_pos start_pos
;
2791 struct text_pos end_pos
;
2793 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2794 Qdisplay
, object
, Qnil
);
2795 CHARPOS (end_pos
) = XFASTINT (end
);
2796 if (STRINGP (object
))
2797 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2799 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2805 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2806 is the object in which the `display' property was found. *POSITION
2807 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2808 means that we previously saw a display sub-property which already
2809 replaced text display with something else, for example an image;
2810 ignore such properties after the first one has been processed.
2812 If PROP is a `space' or `image' sub-property, set *POSITION to the
2813 end position of the `display' property.
2815 Value is non-zero if something was found which replaces the display
2816 of buffer or string text. */
2819 handle_single_display_prop (it
, prop
, object
, position
,
2820 display_replaced_before_p
)
2824 struct text_pos
*position
;
2825 int display_replaced_before_p
;
2828 int replaces_text_display_p
= 0;
2831 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2832 evaluated. If the result is nil, VALUE is ignored. */
2834 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2843 if (!NILP (form
) && !EQ (form
, Qt
))
2845 int count
= BINDING_STACK_SIZE ();
2846 struct gcpro gcpro1
;
2848 /* Bind `object' to the object having the `display' property, a
2849 buffer or string. Bind `position' to the position in the
2850 object where the property was found, and `buffer-position'
2851 to the current position in the buffer. */
2852 specbind (Qobject
, object
);
2853 specbind (Qposition
, make_number (CHARPOS (*position
)));
2854 specbind (Qbuffer_position
,
2855 make_number (STRINGP (object
)
2856 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2858 form
= safe_eval (form
);
2860 unbind_to (count
, Qnil
);
2867 && EQ (XCAR (prop
), Qheight
)
2868 && CONSP (XCDR (prop
)))
2870 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2873 /* `(height HEIGHT)'. */
2874 it
->font_height
= XCAR (XCDR (prop
));
2875 if (!NILP (it
->font_height
))
2877 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2878 int new_height
= -1;
2880 if (CONSP (it
->font_height
)
2881 && (EQ (XCAR (it
->font_height
), Qplus
)
2882 || EQ (XCAR (it
->font_height
), Qminus
))
2883 && CONSP (XCDR (it
->font_height
))
2884 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2886 /* `(+ N)' or `(- N)' where N is an integer. */
2887 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2888 if (EQ (XCAR (it
->font_height
), Qplus
))
2890 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2892 else if (FUNCTIONP (it
->font_height
))
2894 /* Call function with current height as argument.
2895 Value is the new height. */
2897 height
= safe_call1 (it
->font_height
,
2898 face
->lface
[LFACE_HEIGHT_INDEX
]);
2899 if (NUMBERP (height
))
2900 new_height
= XFLOATINT (height
);
2902 else if (NUMBERP (it
->font_height
))
2904 /* Value is a multiple of the canonical char height. */
2907 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2908 new_height
= (XFLOATINT (it
->font_height
)
2909 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2913 /* Evaluate IT->font_height with `height' bound to the
2914 current specified height to get the new height. */
2916 int count
= BINDING_STACK_SIZE ();
2918 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2919 value
= safe_eval (it
->font_height
);
2920 unbind_to (count
, Qnil
);
2922 if (NUMBERP (value
))
2923 new_height
= XFLOATINT (value
);
2927 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2930 else if (CONSP (prop
)
2931 && EQ (XCAR (prop
), Qspace_width
)
2932 && CONSP (XCDR (prop
)))
2934 /* `(space_width WIDTH)'. */
2935 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2938 value
= XCAR (XCDR (prop
));
2939 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2940 it
->space_width
= value
;
2942 else if (CONSP (prop
)
2943 && EQ (XCAR (prop
), Qraise
)
2944 && CONSP (XCDR (prop
)))
2946 /* `(raise FACTOR)'. */
2947 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2950 #ifdef HAVE_WINDOW_SYSTEM
2951 value
= XCAR (XCDR (prop
));
2952 if (NUMBERP (value
))
2954 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2955 it
->voffset
= - (XFLOATINT (value
)
2956 * (FONT_HEIGHT (face
->font
)));
2958 #endif /* HAVE_WINDOW_SYSTEM */
2960 else if (!it
->string_from_display_prop_p
)
2962 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2963 VALUE) or `((margin nil) VALUE)' or VALUE. */
2964 Lisp_Object location
, value
;
2965 struct text_pos start_pos
;
2968 /* Characters having this form of property are not displayed, so
2969 we have to find the end of the property. */
2970 start_pos
= *position
;
2971 *position
= display_prop_end (it
, object
, start_pos
);
2974 /* Let's stop at the new position and assume that all
2975 text properties change there. */
2976 it
->stop_charpos
= position
->charpos
;
2978 location
= Qunbound
;
2979 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2983 value
= XCDR (prop
);
2985 value
= XCAR (value
);
2988 if (EQ (XCAR (tem
), Qmargin
)
2989 && (tem
= XCDR (tem
),
2990 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2992 || EQ (tem
, Qleft_margin
)
2993 || EQ (tem
, Qright_margin
))))
2997 if (EQ (location
, Qunbound
))
3003 #ifdef HAVE_WINDOW_SYSTEM
3004 if (FRAME_TERMCAP_P (it
->f
))
3005 valid_p
= STRINGP (value
);
3007 valid_p
= (STRINGP (value
)
3008 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3009 || valid_image_p (value
));
3010 #else /* not HAVE_WINDOW_SYSTEM */
3011 valid_p
= STRINGP (value
);
3012 #endif /* not HAVE_WINDOW_SYSTEM */
3014 if ((EQ (location
, Qleft_margin
)
3015 || EQ (location
, Qright_margin
)
3018 && !display_replaced_before_p
)
3020 replaces_text_display_p
= 1;
3022 /* Save current settings of IT so that we can restore them
3023 when we are finished with the glyph property value. */
3026 if (NILP (location
))
3027 it
->area
= TEXT_AREA
;
3028 else if (EQ (location
, Qleft_margin
))
3029 it
->area
= LEFT_MARGIN_AREA
;
3031 it
->area
= RIGHT_MARGIN_AREA
;
3033 if (STRINGP (value
))
3036 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3037 it
->current
.overlay_string_index
= -1;
3038 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3039 it
->end_charpos
= it
->string_nchars
3040 = XSTRING (it
->string
)->size
;
3041 it
->method
= next_element_from_string
;
3042 it
->stop_charpos
= 0;
3043 it
->string_from_display_prop_p
= 1;
3044 /* Say that we haven't consumed the characters with
3045 `display' property yet. The call to pop_it in
3046 set_iterator_to_next will clean this up. */
3047 *position
= start_pos
;
3049 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3051 it
->method
= next_element_from_stretch
;
3053 it
->current
.pos
= it
->position
= start_pos
;
3055 #ifdef HAVE_WINDOW_SYSTEM
3058 it
->what
= IT_IMAGE
;
3059 it
->image_id
= lookup_image (it
->f
, value
);
3060 it
->position
= start_pos
;
3061 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3062 it
->method
= next_element_from_image
;
3064 /* Say that we haven't consumed the characters with
3065 `display' property yet. The call to pop_it in
3066 set_iterator_to_next will clean this up. */
3067 *position
= start_pos
;
3069 #endif /* HAVE_WINDOW_SYSTEM */
3072 /* Invalid property or property not supported. Restore
3073 the position to what it was before. */
3074 *position
= start_pos
;
3077 return replaces_text_display_p
;
3081 /* Check if PROP is a display sub-property value whose text should be
3082 treated as intangible. */
3085 single_display_prop_intangible_p (prop
)
3088 /* Skip over `when FORM'. */
3089 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3100 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3101 we don't need to treat text as intangible. */
3102 if (EQ (XCAR (prop
), Qmargin
))
3110 || EQ (XCAR (prop
), Qleft_margin
)
3111 || EQ (XCAR (prop
), Qright_margin
))
3115 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3119 /* Check if PROP is a display property value whose text should be
3120 treated as intangible. */
3123 display_prop_intangible_p (prop
)
3127 && CONSP (XCAR (prop
))
3128 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3130 /* A list of sub-properties. */
3131 while (CONSP (prop
))
3133 if (single_display_prop_intangible_p (XCAR (prop
)))
3138 else if (VECTORP (prop
))
3140 /* A vector of sub-properties. */
3142 for (i
= 0; i
< ASIZE (prop
); ++i
)
3143 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3147 return single_display_prop_intangible_p (prop
);
3153 /* Return 1 if PROP is a display sub-property value containing STRING. */
3156 single_display_prop_string_p (prop
, string
)
3157 Lisp_Object prop
, string
;
3159 if (EQ (string
, prop
))
3162 /* Skip over `when FORM'. */
3163 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3172 /* Skip over `margin LOCATION'. */
3173 if (EQ (XCAR (prop
), Qmargin
))
3184 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3188 /* Return 1 if STRING appears in the `display' property PROP. */
3191 display_prop_string_p (prop
, string
)
3192 Lisp_Object prop
, string
;
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_string_p (XCAR (prop
), string
))
3206 else if (VECTORP (prop
))
3208 /* A vector of sub-properties. */
3210 for (i
= 0; i
< ASIZE (prop
); ++i
)
3211 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3215 return single_display_prop_string_p (prop
, string
);
3221 /* Determine from which buffer position in W's buffer STRING comes
3222 from. AROUND_CHARPOS is an approximate position where it could
3223 be from. Value is the buffer position or 0 if it couldn't be
3226 W's buffer must be current.
3228 This function is necessary because we don't record buffer positions
3229 in glyphs generated from strings (to keep struct glyph small).
3230 This function may only use code that doesn't eval because it is
3231 called asynchronously from note_mouse_highlight. */
3234 string_buffer_position (w
, string
, around_charpos
)
3239 Lisp_Object limit
, prop
, pos
;
3240 const int MAX_DISTANCE
= 1000;
3243 pos
= make_number (around_charpos
);
3244 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3245 while (!found
&& !EQ (pos
, limit
))
3247 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3248 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3251 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3256 pos
= make_number (around_charpos
);
3257 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3258 while (!found
&& !EQ (pos
, limit
))
3260 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3261 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3264 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3269 return found
? XINT (pos
) : 0;
3274 /***********************************************************************
3275 `composition' property
3276 ***********************************************************************/
3278 /* Set up iterator IT from `composition' property at its current
3279 position. Called from handle_stop. */
3281 static enum prop_handled
3282 handle_composition_prop (it
)
3285 Lisp_Object prop
, string
;
3286 int pos
, pos_byte
, end
;
3287 enum prop_handled handled
= HANDLED_NORMALLY
;
3289 if (STRINGP (it
->string
))
3291 pos
= IT_STRING_CHARPOS (*it
);
3292 pos_byte
= IT_STRING_BYTEPOS (*it
);
3293 string
= it
->string
;
3297 pos
= IT_CHARPOS (*it
);
3298 pos_byte
= IT_BYTEPOS (*it
);
3302 /* If there's a valid composition and point is not inside of the
3303 composition (in the case that the composition is from the current
3304 buffer), draw a glyph composed from the composition components. */
3305 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3306 && COMPOSITION_VALID_P (pos
, end
, prop
)
3307 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3309 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3313 it
->method
= next_element_from_composition
;
3315 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3316 /* For a terminal, draw only the first character of the
3318 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3319 it
->len
= (STRINGP (it
->string
)
3320 ? string_char_to_byte (it
->string
, end
)
3321 : CHAR_TO_BYTE (end
)) - pos_byte
;
3322 it
->stop_charpos
= end
;
3323 handled
= HANDLED_RETURN
;
3332 /***********************************************************************
3334 ***********************************************************************/
3336 /* The following structure is used to record overlay strings for
3337 later sorting in load_overlay_strings. */
3339 struct overlay_entry
3341 Lisp_Object overlay
;
3348 /* Set up iterator IT from overlay strings at its current position.
3349 Called from handle_stop. */
3351 static enum prop_handled
3352 handle_overlay_change (it
)
3355 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3356 return HANDLED_RECOMPUTE_PROPS
;
3358 return HANDLED_NORMALLY
;
3362 /* Set up the next overlay string for delivery by IT, if there is an
3363 overlay string to deliver. Called by set_iterator_to_next when the
3364 end of the current overlay string is reached. If there are more
3365 overlay strings to display, IT->string and
3366 IT->current.overlay_string_index are set appropriately here.
3367 Otherwise IT->string is set to nil. */
3370 next_overlay_string (it
)
3373 ++it
->current
.overlay_string_index
;
3374 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3376 /* No more overlay strings. Restore IT's settings to what
3377 they were before overlay strings were processed, and
3378 continue to deliver from current_buffer. */
3379 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3382 xassert (it
->stop_charpos
>= BEGV
3383 && it
->stop_charpos
<= it
->end_charpos
);
3385 it
->current
.overlay_string_index
= -1;
3386 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3387 it
->n_overlay_strings
= 0;
3388 it
->method
= next_element_from_buffer
;
3390 /* If we're at the end of the buffer, record that we have
3391 processed the overlay strings there already, so that
3392 next_element_from_buffer doesn't try it again. */
3393 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3394 it
->overlay_strings_at_end_processed_p
= 1;
3396 /* If we have to display `...' for invisible text, set
3397 the iterator up for that. */
3398 if (display_ellipsis_p
)
3399 setup_for_ellipsis (it
);
3403 /* There are more overlay strings to process. If
3404 IT->current.overlay_string_index has advanced to a position
3405 where we must load IT->overlay_strings with more strings, do
3407 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3409 if (it
->current
.overlay_string_index
&& i
== 0)
3410 load_overlay_strings (it
, 0);
3412 /* Initialize IT to deliver display elements from the overlay
3414 it
->string
= it
->overlay_strings
[i
];
3415 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3416 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3417 it
->method
= next_element_from_string
;
3418 it
->stop_charpos
= 0;
3425 /* Compare two overlay_entry structures E1 and E2. Used as a
3426 comparison function for qsort in load_overlay_strings. Overlay
3427 strings for the same position are sorted so that
3429 1. All after-strings come in front of before-strings, except
3430 when they come from the same overlay.
3432 2. Within after-strings, strings are sorted so that overlay strings
3433 from overlays with higher priorities come first.
3435 2. Within before-strings, strings are sorted so that overlay
3436 strings from overlays with higher priorities come last.
3438 Value is analogous to strcmp. */
3442 compare_overlay_entries (e1
, e2
)
3445 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3446 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3449 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3451 /* Let after-strings appear in front of before-strings if
3452 they come from different overlays. */
3453 if (EQ (entry1
->overlay
, entry2
->overlay
))
3454 result
= entry1
->after_string_p
? 1 : -1;
3456 result
= entry1
->after_string_p
? -1 : 1;
3458 else if (entry1
->after_string_p
)
3459 /* After-strings sorted in order of decreasing priority. */
3460 result
= entry2
->priority
- entry1
->priority
;
3462 /* Before-strings sorted in order of increasing priority. */
3463 result
= entry1
->priority
- entry2
->priority
;
3469 /* Load the vector IT->overlay_strings with overlay strings from IT's
3470 current buffer position, or from CHARPOS if that is > 0. Set
3471 IT->n_overlays to the total number of overlay strings found.
3473 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3474 a time. On entry into load_overlay_strings,
3475 IT->current.overlay_string_index gives the number of overlay
3476 strings that have already been loaded by previous calls to this
3479 IT->add_overlay_start contains an additional overlay start
3480 position to consider for taking overlay strings from, if non-zero.
3481 This position comes into play when the overlay has an `invisible'
3482 property, and both before and after-strings. When we've skipped to
3483 the end of the overlay, because of its `invisible' property, we
3484 nevertheless want its before-string to appear.
3485 IT->add_overlay_start will contain the overlay start position
3488 Overlay strings are sorted so that after-string strings come in
3489 front of before-string strings. Within before and after-strings,
3490 strings are sorted by overlay priority. See also function
3491 compare_overlay_entries. */
3494 load_overlay_strings (it
, charpos
)
3498 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3499 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3502 int n
= 0, i
, j
, invis_p
;
3503 struct overlay_entry
*entries
3504 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3507 charpos
= IT_CHARPOS (*it
);
3509 /* Append the overlay string STRING of overlay OVERLAY to vector
3510 `entries' which has size `size' and currently contains `n'
3511 elements. AFTER_P non-zero means STRING is an after-string of
3513 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3516 Lisp_Object priority; \
3520 int new_size = 2 * size; \
3521 struct overlay_entry *old = entries; \
3523 (struct overlay_entry *) alloca (new_size \
3524 * sizeof *entries); \
3525 bcopy (old, entries, size * sizeof *entries); \
3529 entries[n].string = (STRING); \
3530 entries[n].overlay = (OVERLAY); \
3531 priority = Foverlay_get ((OVERLAY), Qpriority); \
3532 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3533 entries[n].after_string_p = (AFTER_P); \
3538 /* Process overlay before the overlay center. */
3539 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3541 overlay
= XCAR (ov
);
3542 xassert (OVERLAYP (overlay
));
3543 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3544 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3549 /* Skip this overlay if it doesn't start or end at IT's current
3551 if (end
!= charpos
&& start
!= charpos
)
3554 /* Skip this overlay if it doesn't apply to IT->w. */
3555 window
= Foverlay_get (overlay
, Qwindow
);
3556 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3559 /* If the text ``under'' the overlay is invisible, both before-
3560 and after-strings from this overlay are visible; start and
3561 end position are indistinguishable. */
3562 invisible
= Foverlay_get (overlay
, Qinvisible
);
3563 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3565 /* If overlay has a non-empty before-string, record it. */
3566 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3567 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3568 && XSTRING (str
)->size
)
3569 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3571 /* If overlay has a non-empty after-string, record it. */
3572 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3573 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3574 && XSTRING (str
)->size
)
3575 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3578 /* Process overlays after the overlay center. */
3579 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3581 overlay
= XCAR (ov
);
3582 xassert (OVERLAYP (overlay
));
3583 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3584 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3586 if (start
> charpos
)
3589 /* Skip this overlay if it doesn't start or end at IT's current
3591 if (end
!= charpos
&& start
!= charpos
)
3594 /* Skip this overlay if it doesn't apply to IT->w. */
3595 window
= Foverlay_get (overlay
, Qwindow
);
3596 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3599 /* If the text ``under'' the overlay is invisible, it has a zero
3600 dimension, and both before- and after-strings apply. */
3601 invisible
= Foverlay_get (overlay
, Qinvisible
);
3602 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3604 /* If overlay has a non-empty before-string, record it. */
3605 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3606 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3607 && XSTRING (str
)->size
)
3608 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3610 /* If overlay has a non-empty after-string, record it. */
3611 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3612 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3613 && XSTRING (str
)->size
)
3614 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3617 #undef RECORD_OVERLAY_STRING
3621 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3623 /* Record the total number of strings to process. */
3624 it
->n_overlay_strings
= n
;
3626 /* IT->current.overlay_string_index is the number of overlay strings
3627 that have already been consumed by IT. Copy some of the
3628 remaining overlay strings to IT->overlay_strings. */
3630 j
= it
->current
.overlay_string_index
;
3631 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3632 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3638 /* Get the first chunk of overlay strings at IT's current buffer
3639 position, or at CHARPOS if that is > 0. Value is non-zero if at
3640 least one overlay string was found. */
3643 get_overlay_strings (it
, charpos
)
3647 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3648 process. This fills IT->overlay_strings with strings, and sets
3649 IT->n_overlay_strings to the total number of strings to process.
3650 IT->pos.overlay_string_index has to be set temporarily to zero
3651 because load_overlay_strings needs this; it must be set to -1
3652 when no overlay strings are found because a zero value would
3653 indicate a position in the first overlay string. */
3654 it
->current
.overlay_string_index
= 0;
3655 load_overlay_strings (it
, charpos
);
3657 /* If we found overlay strings, set up IT to deliver display
3658 elements from the first one. Otherwise set up IT to deliver
3659 from current_buffer. */
3660 if (it
->n_overlay_strings
)
3662 /* Make sure we know settings in current_buffer, so that we can
3663 restore meaningful values when we're done with the overlay
3665 compute_stop_pos (it
);
3666 xassert (it
->face_id
>= 0);
3668 /* Save IT's settings. They are restored after all overlay
3669 strings have been processed. */
3670 xassert (it
->sp
== 0);
3673 /* Set up IT to deliver display elements from the first overlay
3675 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3676 it
->string
= it
->overlay_strings
[0];
3677 it
->stop_charpos
= 0;
3678 it
->end_charpos
= XSTRING (it
->string
)->size
;
3679 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3680 xassert (STRINGP (it
->string
));
3681 it
->method
= next_element_from_string
;
3686 it
->current
.overlay_string_index
= -1;
3687 it
->method
= next_element_from_buffer
;
3692 /* Value is non-zero if we found at least one overlay string. */
3693 return STRINGP (it
->string
);
3698 /***********************************************************************
3699 Saving and restoring state
3700 ***********************************************************************/
3702 /* Save current settings of IT on IT->stack. Called, for example,
3703 before setting up IT for an overlay string, to be able to restore
3704 IT's settings to what they were after the overlay string has been
3711 struct iterator_stack_entry
*p
;
3713 xassert (it
->sp
< 2);
3714 p
= it
->stack
+ it
->sp
;
3716 p
->stop_charpos
= it
->stop_charpos
;
3717 xassert (it
->face_id
>= 0);
3718 p
->face_id
= it
->face_id
;
3719 p
->string
= it
->string
;
3720 p
->pos
= it
->current
;
3721 p
->end_charpos
= it
->end_charpos
;
3722 p
->string_nchars
= it
->string_nchars
;
3724 p
->multibyte_p
= it
->multibyte_p
;
3725 p
->space_width
= it
->space_width
;
3726 p
->font_height
= it
->font_height
;
3727 p
->voffset
= it
->voffset
;
3728 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3729 p
->display_ellipsis_p
= 0;
3734 /* Restore IT's settings from IT->stack. Called, for example, when no
3735 more overlay strings must be processed, and we return to delivering
3736 display elements from a buffer, or when the end of a string from a
3737 `display' property is reached and we return to delivering display
3738 elements from an overlay string, or from a buffer. */
3744 struct iterator_stack_entry
*p
;
3746 xassert (it
->sp
> 0);
3748 p
= it
->stack
+ it
->sp
;
3749 it
->stop_charpos
= p
->stop_charpos
;
3750 it
->face_id
= p
->face_id
;
3751 it
->string
= p
->string
;
3752 it
->current
= p
->pos
;
3753 it
->end_charpos
= p
->end_charpos
;
3754 it
->string_nchars
= p
->string_nchars
;
3756 it
->multibyte_p
= p
->multibyte_p
;
3757 it
->space_width
= p
->space_width
;
3758 it
->font_height
= p
->font_height
;
3759 it
->voffset
= p
->voffset
;
3760 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3765 /***********************************************************************
3767 ***********************************************************************/
3769 /* Set IT's current position to the previous line start. */
3772 back_to_previous_line_start (it
)
3775 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3776 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3780 /* Move IT to the next line start.
3782 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3783 we skipped over part of the text (as opposed to moving the iterator
3784 continuously over the text). Otherwise, don't change the value
3787 Newlines may come from buffer text, overlay strings, or strings
3788 displayed via the `display' property. That's the reason we can't
3789 simply use find_next_newline_no_quit.
3791 Note that this function may not skip over invisible text that is so
3792 because of text properties and immediately follows a newline. If
3793 it would, function reseat_at_next_visible_line_start, when called
3794 from set_iterator_to_next, would effectively make invisible
3795 characters following a newline part of the wrong glyph row, which
3796 leads to wrong cursor motion. */
3799 forward_to_next_line_start (it
, skipped_p
)
3803 int old_selective
, newline_found_p
, n
;
3804 const int MAX_NEWLINE_DISTANCE
= 500;
3806 /* If already on a newline, just consume it to avoid unintended
3807 skipping over invisible text below. */
3808 if (it
->what
== IT_CHARACTER
3810 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3812 set_iterator_to_next (it
, 0);
3817 /* Don't handle selective display in the following. It's (a)
3818 unnecessary because it's done by the caller, and (b) leads to an
3819 infinite recursion because next_element_from_ellipsis indirectly
3820 calls this function. */
3821 old_selective
= it
->selective
;
3824 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3825 from buffer text. */
3826 for (n
= newline_found_p
= 0;
3827 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3828 n
+= STRINGP (it
->string
) ? 0 : 1)
3830 if (!get_next_display_element (it
))
3832 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3833 set_iterator_to_next (it
, 0);
3836 /* If we didn't find a newline near enough, see if we can use a
3838 if (n
== MAX_NEWLINE_DISTANCE
)
3840 int start
= IT_CHARPOS (*it
);
3841 int limit
= find_next_newline_no_quit (start
, 1);
3844 xassert (!STRINGP (it
->string
));
3846 /* If there isn't any `display' property in sight, and no
3847 overlays, we can just use the position of the newline in
3849 if (it
->stop_charpos
>= limit
3850 || ((pos
= Fnext_single_property_change (make_number (start
),
3852 Qnil
, make_number (limit
)),
3854 && next_overlay_change (start
) == ZV
))
3856 IT_CHARPOS (*it
) = limit
;
3857 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3858 *skipped_p
= newline_found_p
= 1;
3862 while (get_next_display_element (it
)
3863 && !newline_found_p
)
3865 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3866 set_iterator_to_next (it
, 0);
3871 it
->selective
= old_selective
;
3872 return newline_found_p
;
3876 /* Set IT's current position to the previous visible line start. Skip
3877 invisible text that is so either due to text properties or due to
3878 selective display. Caution: this does not change IT->current_x and
3882 back_to_previous_visible_line_start (it
)
3887 /* Go back one newline if not on BEGV already. */
3888 if (IT_CHARPOS (*it
) > BEGV
)
3889 back_to_previous_line_start (it
);
3891 /* Move over lines that are invisible because of selective display
3892 or text properties. */
3893 while (IT_CHARPOS (*it
) > BEGV
3898 /* If selective > 0, then lines indented more than that values
3900 if (it
->selective
> 0
3901 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3908 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3909 Qinvisible
, it
->window
);
3910 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3914 /* Back one more newline if the current one is invisible. */
3916 back_to_previous_line_start (it
);
3919 xassert (IT_CHARPOS (*it
) >= BEGV
);
3920 xassert (IT_CHARPOS (*it
) == BEGV
3921 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3926 /* Reseat iterator IT at the previous visible line start. Skip
3927 invisible text that is so either due to text properties or due to
3928 selective display. At the end, update IT's overlay information,
3929 face information etc. */
3932 reseat_at_previous_visible_line_start (it
)
3935 back_to_previous_visible_line_start (it
);
3936 reseat (it
, it
->current
.pos
, 1);
3941 /* Reseat iterator IT on the next visible line start in the current
3942 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3943 preceding the line start. Skip over invisible text that is so
3944 because of selective display. Compute faces, overlays etc at the
3945 new position. Note that this function does not skip over text that
3946 is invisible because of text properties. */
3949 reseat_at_next_visible_line_start (it
, on_newline_p
)
3953 int newline_found_p
, skipped_p
= 0;
3955 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3957 /* Skip over lines that are invisible because they are indented
3958 more than the value of IT->selective. */
3959 if (it
->selective
> 0)
3960 while (IT_CHARPOS (*it
) < ZV
3961 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3964 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3965 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3968 /* Position on the newline if that's what's requested. */
3969 if (on_newline_p
&& newline_found_p
)
3971 if (STRINGP (it
->string
))
3973 if (IT_STRING_CHARPOS (*it
) > 0)
3975 --IT_STRING_CHARPOS (*it
);
3976 --IT_STRING_BYTEPOS (*it
);
3979 else if (IT_CHARPOS (*it
) > BEGV
)
3983 reseat (it
, it
->current
.pos
, 0);
3987 reseat (it
, it
->current
.pos
, 0);
3994 /***********************************************************************
3995 Changing an iterator's position
3996 ***********************************************************************/
3998 /* Change IT's current position to POS in current_buffer. If FORCE_P
3999 is non-zero, always check for text properties at the new position.
4000 Otherwise, text properties are only looked up if POS >=
4001 IT->check_charpos of a property. */
4004 reseat (it
, pos
, force_p
)
4006 struct text_pos pos
;
4009 int original_pos
= IT_CHARPOS (*it
);
4011 reseat_1 (it
, pos
, 0);
4013 /* Determine where to check text properties. Avoid doing it
4014 where possible because text property lookup is very expensive. */
4016 || CHARPOS (pos
) > it
->stop_charpos
4017 || CHARPOS (pos
) < original_pos
)
4024 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4025 IT->stop_pos to POS, also. */
4028 reseat_1 (it
, pos
, set_stop_p
)
4030 struct text_pos pos
;
4033 /* Don't call this function when scanning a C string. */
4034 xassert (it
->s
== NULL
);
4036 /* POS must be a reasonable value. */
4037 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4039 it
->current
.pos
= it
->position
= pos
;
4040 XSETBUFFER (it
->object
, current_buffer
);
4041 it
->end_charpos
= ZV
;
4043 it
->current
.dpvec_index
= -1;
4044 it
->current
.overlay_string_index
= -1;
4045 IT_STRING_CHARPOS (*it
) = -1;
4046 IT_STRING_BYTEPOS (*it
) = -1;
4048 it
->method
= next_element_from_buffer
;
4049 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4051 it
->face_before_selective_p
= 0;
4054 it
->stop_charpos
= CHARPOS (pos
);
4058 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4059 If S is non-null, it is a C string to iterate over. Otherwise,
4060 STRING gives a Lisp string to iterate over.
4062 If PRECISION > 0, don't return more then PRECISION number of
4063 characters from the string.
4065 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4066 characters have been returned. FIELD_WIDTH < 0 means an infinite
4069 MULTIBYTE = 0 means disable processing of multibyte characters,
4070 MULTIBYTE > 0 means enable it,
4071 MULTIBYTE < 0 means use IT->multibyte_p.
4073 IT must be initialized via a prior call to init_iterator before
4074 calling this function. */
4077 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4082 int precision
, field_width
, multibyte
;
4084 /* No region in strings. */
4085 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4087 /* No text property checks performed by default, but see below. */
4088 it
->stop_charpos
= -1;
4090 /* Set iterator position and end position. */
4091 bzero (&it
->current
, sizeof it
->current
);
4092 it
->current
.overlay_string_index
= -1;
4093 it
->current
.dpvec_index
= -1;
4094 xassert (charpos
>= 0);
4096 /* If STRING is specified, use its multibyteness, otherwise use the
4097 setting of MULTIBYTE, if specified. */
4099 it
->multibyte_p
= multibyte
> 0;
4103 xassert (STRINGP (string
));
4104 it
->string
= string
;
4106 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
4107 it
->method
= next_element_from_string
;
4108 it
->current
.string_pos
= string_pos (charpos
, string
);
4115 /* Note that we use IT->current.pos, not it->current.string_pos,
4116 for displaying C strings. */
4117 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4118 if (it
->multibyte_p
)
4120 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4121 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4125 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4126 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4129 it
->method
= next_element_from_c_string
;
4132 /* PRECISION > 0 means don't return more than PRECISION characters
4134 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4135 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4137 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4138 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4139 FIELD_WIDTH < 0 means infinite field width. This is useful for
4140 padding with `-' at the end of a mode line. */
4141 if (field_width
< 0)
4142 field_width
= INFINITY
;
4143 if (field_width
> it
->end_charpos
- charpos
)
4144 it
->end_charpos
= charpos
+ field_width
;
4146 /* Use the standard display table for displaying strings. */
4147 if (DISP_TABLE_P (Vstandard_display_table
))
4148 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4150 it
->stop_charpos
= charpos
;
4156 /***********************************************************************
4158 ***********************************************************************/
4160 /* Load IT's display element fields with information about the next
4161 display element from the current position of IT. Value is zero if
4162 end of buffer (or C string) is reached. */
4165 get_next_display_element (it
)
4168 /* Non-zero means that we found an display element. Zero means that
4169 we hit the end of what we iterate over. Performance note: the
4170 function pointer `method' used here turns out to be faster than
4171 using a sequence of if-statements. */
4172 int success_p
= (*it
->method
) (it
);
4174 if (it
->what
== IT_CHARACTER
)
4176 /* Map via display table or translate control characters.
4177 IT->c, IT->len etc. have been set to the next character by
4178 the function call above. If we have a display table, and it
4179 contains an entry for IT->c, translate it. Don't do this if
4180 IT->c itself comes from a display table, otherwise we could
4181 end up in an infinite recursion. (An alternative could be to
4182 count the recursion depth of this function and signal an
4183 error when a certain maximum depth is reached.) Is it worth
4185 if (success_p
&& it
->dpvec
== NULL
)
4190 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4193 struct Lisp_Vector
*v
= XVECTOR (dv
);
4195 /* Return the first character from the display table
4196 entry, if not empty. If empty, don't display the
4197 current character. */
4200 it
->dpvec_char_len
= it
->len
;
4201 it
->dpvec
= v
->contents
;
4202 it
->dpend
= v
->contents
+ v
->size
;
4203 it
->current
.dpvec_index
= 0;
4204 it
->method
= next_element_from_display_vector
;
4205 success_p
= get_next_display_element (it
);
4209 set_iterator_to_next (it
, 0);
4210 success_p
= get_next_display_element (it
);
4214 /* Translate control characters into `\003' or `^C' form.
4215 Control characters coming from a display table entry are
4216 currently not translated because we use IT->dpvec to hold
4217 the translation. This could easily be changed but I
4218 don't believe that it is worth doing.
4220 Non-printable multibyte characters are also translated
4222 else if ((it
->c
< ' '
4223 && (it
->area
!= TEXT_AREA
4224 || (it
->c
!= '\n' && it
->c
!= '\t')))
4227 || !CHAR_PRINTABLE_P (it
->c
))
4229 /* IT->c is a control character which must be displayed
4230 either as '\003' or as `^C' where the '\\' and '^'
4231 can be defined in the display table. Fill
4232 IT->ctl_chars with glyphs for what we have to
4233 display. Then, set IT->dpvec to these glyphs. */
4236 if (it
->c
< 128 && it
->ctl_arrow_p
)
4238 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4240 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4241 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4242 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4244 g
= FAST_MAKE_GLYPH ('^', 0);
4245 XSETINT (it
->ctl_chars
[0], g
);
4247 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4248 XSETINT (it
->ctl_chars
[1], g
);
4250 /* Set up IT->dpvec and return first character from it. */
4251 it
->dpvec_char_len
= it
->len
;
4252 it
->dpvec
= it
->ctl_chars
;
4253 it
->dpend
= it
->dpvec
+ 2;
4254 it
->current
.dpvec_index
= 0;
4255 it
->method
= next_element_from_display_vector
;
4256 get_next_display_element (it
);
4260 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4265 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4267 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4268 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4269 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4271 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4273 if (SINGLE_BYTE_CHAR_P (it
->c
))
4274 str
[0] = it
->c
, len
= 1;
4277 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4280 /* It's an invalid character, which
4281 shouldn't happen actually, but due to
4282 bugs it may happen. Let's print the char
4283 as is, there's not much meaningful we can
4286 str
[1] = it
->c
>> 8;
4287 str
[2] = it
->c
>> 16;
4288 str
[3] = it
->c
>> 24;
4293 for (i
= 0; i
< len
; i
++)
4295 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4296 /* Insert three more glyphs into IT->ctl_chars for
4297 the octal display of the character. */
4298 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4299 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4300 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4301 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4302 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4303 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4306 /* Set up IT->dpvec and return the first character
4308 it
->dpvec_char_len
= it
->len
;
4309 it
->dpvec
= it
->ctl_chars
;
4310 it
->dpend
= it
->dpvec
+ len
* 4;
4311 it
->current
.dpvec_index
= 0;
4312 it
->method
= next_element_from_display_vector
;
4313 get_next_display_element (it
);
4318 /* Adjust face id for a multibyte character. There are no
4319 multibyte character in unibyte text. */
4322 && FRAME_WINDOW_P (it
->f
))
4324 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4325 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4329 /* Is this character the last one of a run of characters with
4330 box? If yes, set IT->end_of_box_run_p to 1. */
4337 it
->end_of_box_run_p
4338 = ((face_id
= face_after_it_pos (it
),
4339 face_id
!= it
->face_id
)
4340 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4341 face
->box
== FACE_NO_BOX
));
4344 /* Value is 0 if end of buffer or string reached. */
4349 /* Move IT to the next display element.
4351 RESEAT_P non-zero means if called on a newline in buffer text,
4352 skip to the next visible line start.
4354 Functions get_next_display_element and set_iterator_to_next are
4355 separate because I find this arrangement easier to handle than a
4356 get_next_display_element function that also increments IT's
4357 position. The way it is we can first look at an iterator's current
4358 display element, decide whether it fits on a line, and if it does,
4359 increment the iterator position. The other way around we probably
4360 would either need a flag indicating whether the iterator has to be
4361 incremented the next time, or we would have to implement a
4362 decrement position function which would not be easy to write. */
4365 set_iterator_to_next (it
, reseat_p
)
4369 /* Reset flags indicating start and end of a sequence of characters
4370 with box. Reset them at the start of this function because
4371 moving the iterator to a new position might set them. */
4372 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4374 if (it
->method
== next_element_from_buffer
)
4376 /* The current display element of IT is a character from
4377 current_buffer. Advance in the buffer, and maybe skip over
4378 invisible lines that are so because of selective display. */
4379 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4380 reseat_at_next_visible_line_start (it
, 0);
4383 xassert (it
->len
!= 0);
4384 IT_BYTEPOS (*it
) += it
->len
;
4385 IT_CHARPOS (*it
) += 1;
4386 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4389 else if (it
->method
== next_element_from_composition
)
4391 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4392 if (STRINGP (it
->string
))
4394 IT_STRING_BYTEPOS (*it
) += it
->len
;
4395 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4396 it
->method
= next_element_from_string
;
4397 goto consider_string_end
;
4401 IT_BYTEPOS (*it
) += it
->len
;
4402 IT_CHARPOS (*it
) += it
->cmp_len
;
4403 it
->method
= next_element_from_buffer
;
4406 else if (it
->method
== next_element_from_c_string
)
4408 /* Current display element of IT is from a C string. */
4409 IT_BYTEPOS (*it
) += it
->len
;
4410 IT_CHARPOS (*it
) += 1;
4412 else if (it
->method
== next_element_from_display_vector
)
4414 /* Current display element of IT is from a display table entry.
4415 Advance in the display table definition. Reset it to null if
4416 end reached, and continue with characters from buffers/
4418 ++it
->current
.dpvec_index
;
4420 /* Restore face of the iterator to what they were before the
4421 display vector entry (these entries may contain faces). */
4422 it
->face_id
= it
->saved_face_id
;
4424 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4427 it
->method
= next_element_from_c_string
;
4428 else if (STRINGP (it
->string
))
4429 it
->method
= next_element_from_string
;
4431 it
->method
= next_element_from_buffer
;
4434 it
->current
.dpvec_index
= -1;
4436 /* Skip over characters which were displayed via IT->dpvec. */
4437 if (it
->dpvec_char_len
< 0)
4438 reseat_at_next_visible_line_start (it
, 1);
4439 else if (it
->dpvec_char_len
> 0)
4441 it
->len
= it
->dpvec_char_len
;
4442 set_iterator_to_next (it
, reseat_p
);
4446 else if (it
->method
== next_element_from_string
)
4448 /* Current display element is a character from a Lisp string. */
4449 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4450 IT_STRING_BYTEPOS (*it
) += it
->len
;
4451 IT_STRING_CHARPOS (*it
) += 1;
4453 consider_string_end
:
4455 if (it
->current
.overlay_string_index
>= 0)
4457 /* IT->string is an overlay string. Advance to the
4458 next, if there is one. */
4459 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4460 next_overlay_string (it
);
4464 /* IT->string is not an overlay string. If we reached
4465 its end, and there is something on IT->stack, proceed
4466 with what is on the stack. This can be either another
4467 string, this time an overlay string, or a buffer. */
4468 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4472 if (!STRINGP (it
->string
))
4473 it
->method
= next_element_from_buffer
;
4475 goto consider_string_end
;
4479 else if (it
->method
== next_element_from_image
4480 || it
->method
== next_element_from_stretch
)
4482 /* The position etc with which we have to proceed are on
4483 the stack. The position may be at the end of a string,
4484 if the `display' property takes up the whole string. */
4487 if (STRINGP (it
->string
))
4489 it
->method
= next_element_from_string
;
4490 goto consider_string_end
;
4493 it
->method
= next_element_from_buffer
;
4496 /* There are no other methods defined, so this should be a bug. */
4499 xassert (it
->method
!= next_element_from_string
4500 || (STRINGP (it
->string
)
4501 && IT_STRING_CHARPOS (*it
) >= 0));
4505 /* Load IT's display element fields with information about the next
4506 display element which comes from a display table entry or from the
4507 result of translating a control character to one of the forms `^C'
4508 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4511 next_element_from_display_vector (it
)
4515 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4517 /* Remember the current face id in case glyphs specify faces.
4518 IT's face is restored in set_iterator_to_next. */
4519 it
->saved_face_id
= it
->face_id
;
4521 if (INTEGERP (*it
->dpvec
)
4522 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4527 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4528 it
->c
= FAST_GLYPH_CHAR (g
);
4529 it
->len
= CHAR_BYTES (it
->c
);
4531 /* The entry may contain a face id to use. Such a face id is
4532 the id of a Lisp face, not a realized face. A face id of
4533 zero means no face is specified. */
4534 lface_id
= FAST_GLYPH_FACE (g
);
4537 /* The function returns -1 if lface_id is invalid. */
4538 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4540 it
->face_id
= face_id
;
4544 /* Display table entry is invalid. Return a space. */
4545 it
->c
= ' ', it
->len
= 1;
4547 /* Don't change position and object of the iterator here. They are
4548 still the values of the character that had this display table
4549 entry or was translated, and that's what we want. */
4550 it
->what
= IT_CHARACTER
;
4555 /* Load IT with the next display element from Lisp string IT->string.
4556 IT->current.string_pos is the current position within the string.
4557 If IT->current.overlay_string_index >= 0, the Lisp string is an
4561 next_element_from_string (it
)
4564 struct text_pos position
;
4566 xassert (STRINGP (it
->string
));
4567 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4568 position
= it
->current
.string_pos
;
4570 /* Time to check for invisible text? */
4571 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4572 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4576 /* Since a handler may have changed IT->method, we must
4578 return get_next_display_element (it
);
4581 if (it
->current
.overlay_string_index
>= 0)
4583 /* Get the next character from an overlay string. In overlay
4584 strings, There is no field width or padding with spaces to
4586 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4591 else if (STRING_MULTIBYTE (it
->string
))
4593 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4594 - IT_STRING_BYTEPOS (*it
));
4595 unsigned char *s
= (XSTRING (it
->string
)->data
4596 + IT_STRING_BYTEPOS (*it
));
4597 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4601 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4607 /* Get the next character from a Lisp string that is not an
4608 overlay string. Such strings come from the mode line, for
4609 example. We may have to pad with spaces, or truncate the
4610 string. See also next_element_from_c_string. */
4611 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4616 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4618 /* Pad with spaces. */
4619 it
->c
= ' ', it
->len
= 1;
4620 CHARPOS (position
) = BYTEPOS (position
) = -1;
4622 else if (STRING_MULTIBYTE (it
->string
))
4624 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4625 - IT_STRING_BYTEPOS (*it
));
4626 unsigned char *s
= (XSTRING (it
->string
)->data
4627 + IT_STRING_BYTEPOS (*it
));
4628 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4632 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4637 /* Record what we have and where it came from. Note that we store a
4638 buffer position in IT->position although it could arguably be a
4640 it
->what
= IT_CHARACTER
;
4641 it
->object
= it
->string
;
4642 it
->position
= position
;
4647 /* Load IT with next display element from C string IT->s.
4648 IT->string_nchars is the maximum number of characters to return
4649 from the string. IT->end_charpos may be greater than
4650 IT->string_nchars when this function is called, in which case we
4651 may have to return padding spaces. Value is zero if end of string
4652 reached, including padding spaces. */
4655 next_element_from_c_string (it
)
4661 it
->what
= IT_CHARACTER
;
4662 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4665 /* IT's position can be greater IT->string_nchars in case a field
4666 width or precision has been specified when the iterator was
4668 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4670 /* End of the game. */
4674 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4676 /* Pad with spaces. */
4677 it
->c
= ' ', it
->len
= 1;
4678 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4680 else if (it
->multibyte_p
)
4682 /* Implementation note: The calls to strlen apparently aren't a
4683 performance problem because there is no noticeable performance
4684 difference between Emacs running in unibyte or multibyte mode. */
4685 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4686 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4690 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4696 /* Set up IT to return characters from an ellipsis, if appropriate.
4697 The definition of the ellipsis glyphs may come from a display table
4698 entry. This function Fills IT with the first glyph from the
4699 ellipsis if an ellipsis is to be displayed. */
4702 next_element_from_ellipsis (it
)
4705 if (it
->selective_display_ellipsis_p
)
4707 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4709 /* Use the display table definition for `...'. Invalid glyphs
4710 will be handled by the method returning elements from dpvec. */
4711 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4712 it
->dpvec_char_len
= it
->len
;
4713 it
->dpvec
= v
->contents
;
4714 it
->dpend
= v
->contents
+ v
->size
;
4715 it
->current
.dpvec_index
= 0;
4716 it
->method
= next_element_from_display_vector
;
4720 /* Use default `...' which is stored in default_invis_vector. */
4721 it
->dpvec_char_len
= it
->len
;
4722 it
->dpvec
= default_invis_vector
;
4723 it
->dpend
= default_invis_vector
+ 3;
4724 it
->current
.dpvec_index
= 0;
4725 it
->method
= next_element_from_display_vector
;
4730 /* The face at the current position may be different from the
4731 face we find after the invisible text. Remember what it
4732 was in IT->saved_face_id, and signal that it's there by
4733 setting face_before_selective_p. */
4734 it
->saved_face_id
= it
->face_id
;
4735 it
->method
= next_element_from_buffer
;
4736 reseat_at_next_visible_line_start (it
, 1);
4737 it
->face_before_selective_p
= 1;
4740 return get_next_display_element (it
);
4744 /* Deliver an image display element. The iterator IT is already
4745 filled with image information (done in handle_display_prop). Value
4750 next_element_from_image (it
)
4753 it
->what
= IT_IMAGE
;
4758 /* Fill iterator IT with next display element from a stretch glyph
4759 property. IT->object is the value of the text property. Value is
4763 next_element_from_stretch (it
)
4766 it
->what
= IT_STRETCH
;
4771 /* Load IT with the next display element from current_buffer. Value
4772 is zero if end of buffer reached. IT->stop_charpos is the next
4773 position at which to stop and check for text properties or buffer
4777 next_element_from_buffer (it
)
4782 /* Check this assumption, otherwise, we would never enter the
4783 if-statement, below. */
4784 xassert (IT_CHARPOS (*it
) >= BEGV
4785 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4787 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4789 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4791 int overlay_strings_follow_p
;
4793 /* End of the game, except when overlay strings follow that
4794 haven't been returned yet. */
4795 if (it
->overlay_strings_at_end_processed_p
)
4796 overlay_strings_follow_p
= 0;
4799 it
->overlay_strings_at_end_processed_p
= 1;
4800 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4803 if (overlay_strings_follow_p
)
4804 success_p
= get_next_display_element (it
);
4808 it
->position
= it
->current
.pos
;
4815 return get_next_display_element (it
);
4820 /* No face changes, overlays etc. in sight, so just return a
4821 character from current_buffer. */
4824 /* Maybe run the redisplay end trigger hook. Performance note:
4825 This doesn't seem to cost measurable time. */
4826 if (it
->redisplay_end_trigger_charpos
4828 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4829 run_redisplay_end_trigger_hook (it
);
4831 /* Get the next character, maybe multibyte. */
4832 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4833 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4835 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4836 - IT_BYTEPOS (*it
));
4837 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4840 it
->c
= *p
, it
->len
= 1;
4842 /* Record what we have and where it came from. */
4843 it
->what
= IT_CHARACTER
;;
4844 it
->object
= it
->w
->buffer
;
4845 it
->position
= it
->current
.pos
;
4847 /* Normally we return the character found above, except when we
4848 really want to return an ellipsis for selective display. */
4853 /* A value of selective > 0 means hide lines indented more
4854 than that number of columns. */
4855 if (it
->selective
> 0
4856 && IT_CHARPOS (*it
) + 1 < ZV
4857 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4858 IT_BYTEPOS (*it
) + 1,
4861 success_p
= next_element_from_ellipsis (it
);
4862 it
->dpvec_char_len
= -1;
4865 else if (it
->c
== '\r' && it
->selective
== -1)
4867 /* A value of selective == -1 means that everything from the
4868 CR to the end of the line is invisible, with maybe an
4869 ellipsis displayed for it. */
4870 success_p
= next_element_from_ellipsis (it
);
4871 it
->dpvec_char_len
= -1;
4876 /* Value is zero if end of buffer reached. */
4877 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4882 /* Run the redisplay end trigger hook for IT. */
4885 run_redisplay_end_trigger_hook (it
)
4888 Lisp_Object args
[3];
4890 /* IT->glyph_row should be non-null, i.e. we should be actually
4891 displaying something, or otherwise we should not run the hook. */
4892 xassert (it
->glyph_row
);
4894 /* Set up hook arguments. */
4895 args
[0] = Qredisplay_end_trigger_functions
;
4896 args
[1] = it
->window
;
4897 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4898 it
->redisplay_end_trigger_charpos
= 0;
4900 /* Since we are *trying* to run these functions, don't try to run
4901 them again, even if they get an error. */
4902 it
->w
->redisplay_end_trigger
= Qnil
;
4903 Frun_hook_with_args (3, args
);
4905 /* Notice if it changed the face of the character we are on. */
4906 handle_face_prop (it
);
4910 /* Deliver a composition display element. The iterator IT is already
4911 filled with composition information (done in
4912 handle_composition_prop). Value is always 1. */
4915 next_element_from_composition (it
)
4918 it
->what
= IT_COMPOSITION
;
4919 it
->position
= (STRINGP (it
->string
)
4920 ? it
->current
.string_pos
4927 /***********************************************************************
4928 Moving an iterator without producing glyphs
4929 ***********************************************************************/
4931 /* Move iterator IT to a specified buffer or X position within one
4932 line on the display without producing glyphs.
4934 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4935 whichever is reached first.
4937 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4939 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4940 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4941 TO_X includes the amount by which a window is horizontally
4946 MOVE_POS_MATCH_OR_ZV
4947 - when TO_POS or ZV was reached.
4950 -when TO_X was reached before TO_POS or ZV were reached.
4953 - when we reached the end of the display area and the line must
4957 - when we reached the end of the display area and the line is
4961 - when we stopped at a line end, i.e. a newline or a CR and selective
4964 static enum move_it_result
4965 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4967 int to_charpos
, to_x
, op
;
4969 enum move_it_result result
= MOVE_UNDEFINED
;
4970 struct glyph_row
*saved_glyph_row
;
4972 /* Don't produce glyphs in produce_glyphs. */
4973 saved_glyph_row
= it
->glyph_row
;
4974 it
->glyph_row
= NULL
;
4978 int x
, i
, ascent
= 0, descent
= 0;
4980 /* Stop when ZV or TO_CHARPOS reached. */
4981 if (!get_next_display_element (it
)
4982 || ((op
& MOVE_TO_POS
) != 0
4983 && BUFFERP (it
->object
)
4984 && IT_CHARPOS (*it
) >= to_charpos
))
4986 result
= MOVE_POS_MATCH_OR_ZV
;
4990 /* The call to produce_glyphs will get the metrics of the
4991 display element IT is loaded with. We record in x the
4992 x-position before this display element in case it does not
4996 /* Remember the line height so far in case the next element doesn't
4998 if (!it
->truncate_lines_p
)
5000 ascent
= it
->max_ascent
;
5001 descent
= it
->max_descent
;
5004 PRODUCE_GLYPHS (it
);
5006 if (it
->area
!= TEXT_AREA
)
5008 set_iterator_to_next (it
, 1);
5012 /* The number of glyphs we get back in IT->nglyphs will normally
5013 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5014 character on a terminal frame, or (iii) a line end. For the
5015 second case, IT->nglyphs - 1 padding glyphs will be present
5016 (on X frames, there is only one glyph produced for a
5017 composite character.
5019 The behavior implemented below means, for continuation lines,
5020 that as many spaces of a TAB as fit on the current line are
5021 displayed there. For terminal frames, as many glyphs of a
5022 multi-glyph character are displayed in the current line, too.
5023 This is what the old redisplay code did, and we keep it that
5024 way. Under X, the whole shape of a complex character must
5025 fit on the line or it will be completely displayed in the
5028 Note that both for tabs and padding glyphs, all glyphs have
5032 /* More than one glyph or glyph doesn't fit on line. All
5033 glyphs have the same width. */
5034 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5037 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5039 new_x
= x
+ single_glyph_width
;
5041 /* We want to leave anything reaching TO_X to the caller. */
5042 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5045 result
= MOVE_X_REACHED
;
5048 else if (/* Lines are continued. */
5049 !it
->truncate_lines_p
5050 && (/* And glyph doesn't fit on the line. */
5051 new_x
> it
->last_visible_x
5052 /* Or it fits exactly and we're on a window
5054 || (new_x
== it
->last_visible_x
5055 && FRAME_WINDOW_P (it
->f
))))
5057 if (/* IT->hpos == 0 means the very first glyph
5058 doesn't fit on the line, e.g. a wide image. */
5060 || (new_x
== it
->last_visible_x
5061 && FRAME_WINDOW_P (it
->f
)))
5064 it
->current_x
= new_x
;
5065 if (i
== it
->nglyphs
- 1)
5066 set_iterator_to_next (it
, 1);
5071 it
->max_ascent
= ascent
;
5072 it
->max_descent
= descent
;
5075 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5077 result
= MOVE_LINE_CONTINUED
;
5080 else if (new_x
> it
->first_visible_x
)
5082 /* Glyph is visible. Increment number of glyphs that
5083 would be displayed. */
5088 /* Glyph is completely off the left margin of the display
5089 area. Nothing to do. */
5093 if (result
!= MOVE_UNDEFINED
)
5096 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5098 /* Stop when TO_X specified and reached. This check is
5099 necessary here because of lines consisting of a line end,
5100 only. The line end will not produce any glyphs and we
5101 would never get MOVE_X_REACHED. */
5102 xassert (it
->nglyphs
== 0);
5103 result
= MOVE_X_REACHED
;
5107 /* Is this a line end? If yes, we're done. */
5108 if (ITERATOR_AT_END_OF_LINE_P (it
))
5110 result
= MOVE_NEWLINE_OR_CR
;
5114 /* The current display element has been consumed. Advance
5116 set_iterator_to_next (it
, 1);
5118 /* Stop if lines are truncated and IT's current x-position is
5119 past the right edge of the window now. */
5120 if (it
->truncate_lines_p
5121 && it
->current_x
>= it
->last_visible_x
)
5123 result
= MOVE_LINE_TRUNCATED
;
5128 /* Restore the iterator settings altered at the beginning of this
5130 it
->glyph_row
= saved_glyph_row
;
5135 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
5136 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
5137 the description of enum move_operation_enum.
5139 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5140 screen line, this function will set IT to the next position >
5144 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5146 int to_charpos
, to_x
, to_y
, to_vpos
;
5149 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5155 if (op
& MOVE_TO_VPOS
)
5157 /* If no TO_CHARPOS and no TO_X specified, stop at the
5158 start of the line TO_VPOS. */
5159 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5161 if (it
->vpos
== to_vpos
)
5167 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5171 /* TO_VPOS >= 0 means stop at TO_X in the line at
5172 TO_VPOS, or at TO_POS, whichever comes first. */
5173 if (it
->vpos
== to_vpos
)
5179 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5181 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5186 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5188 /* We have reached TO_X but not in the line we want. */
5189 skip
= move_it_in_display_line_to (it
, to_charpos
,
5191 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5199 else if (op
& MOVE_TO_Y
)
5201 struct it it_backup
;
5203 /* TO_Y specified means stop at TO_X in the line containing
5204 TO_Y---or at TO_CHARPOS if this is reached first. The
5205 problem is that we can't really tell whether the line
5206 contains TO_Y before we have completely scanned it, and
5207 this may skip past TO_X. What we do is to first scan to
5210 If TO_X is not specified, use a TO_X of zero. The reason
5211 is to make the outcome of this function more predictable.
5212 If we didn't use TO_X == 0, we would stop at the end of
5213 the line which is probably not what a caller would expect
5215 skip
= move_it_in_display_line_to (it
, to_charpos
,
5219 | (op
& MOVE_TO_POS
)));
5221 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5222 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5228 /* If TO_X was reached, we would like to know whether TO_Y
5229 is in the line. This can only be said if we know the
5230 total line height which requires us to scan the rest of
5232 if (skip
== MOVE_X_REACHED
)
5235 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5236 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5238 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5241 /* Now, decide whether TO_Y is in this line. */
5242 line_height
= it
->max_ascent
+ it
->max_descent
;
5243 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5245 if (to_y
>= it
->current_y
5246 && to_y
< it
->current_y
+ line_height
)
5248 if (skip
== MOVE_X_REACHED
)
5249 /* If TO_Y is in this line and TO_X was reached above,
5250 we scanned too far. We have to restore IT's settings
5251 to the ones before skipping. */
5255 else if (skip
== MOVE_X_REACHED
)
5258 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5266 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5270 case MOVE_POS_MATCH_OR_ZV
:
5274 case MOVE_NEWLINE_OR_CR
:
5275 set_iterator_to_next (it
, 1);
5276 it
->continuation_lines_width
= 0;
5279 case MOVE_LINE_TRUNCATED
:
5280 it
->continuation_lines_width
= 0;
5281 reseat_at_next_visible_line_start (it
, 0);
5282 if ((op
& MOVE_TO_POS
) != 0
5283 && IT_CHARPOS (*it
) > to_charpos
)
5290 case MOVE_LINE_CONTINUED
:
5291 it
->continuation_lines_width
+= it
->current_x
;
5298 /* Reset/increment for the next run. */
5299 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5300 it
->current_x
= it
->hpos
= 0;
5301 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5303 last_height
= it
->max_ascent
+ it
->max_descent
;
5304 last_max_ascent
= it
->max_ascent
;
5305 it
->max_ascent
= it
->max_descent
= 0;
5310 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5314 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5316 If DY > 0, move IT backward at least that many pixels. DY = 0
5317 means move IT backward to the preceding line start or BEGV. This
5318 function may move over more than DY pixels if IT->current_y - DY
5319 ends up in the middle of a line; in this case IT->current_y will be
5320 set to the top of the line moved to. */
5323 move_it_vertically_backward (it
, dy
)
5329 int start_pos
= IT_CHARPOS (*it
);
5333 /* Estimate how many newlines we must move back. */
5334 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5336 /* Set the iterator's position that many lines back. */
5337 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5338 back_to_previous_visible_line_start (it
);
5340 /* Reseat the iterator here. When moving backward, we don't want
5341 reseat to skip forward over invisible text, set up the iterator
5342 to deliver from overlay strings at the new position etc. So,
5343 use reseat_1 here. */
5344 reseat_1 (it
, it
->current
.pos
, 1);
5346 /* We are now surely at a line start. */
5347 it
->current_x
= it
->hpos
= 0;
5349 /* Move forward and see what y-distance we moved. First move to the
5350 start of the next line so that we get its height. We need this
5351 height to be able to tell whether we reached the specified
5354 it2
.max_ascent
= it2
.max_descent
= 0;
5355 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5356 MOVE_TO_POS
| MOVE_TO_VPOS
);
5357 xassert (IT_CHARPOS (*it
) >= BEGV
);
5360 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5361 xassert (IT_CHARPOS (*it
) >= BEGV
);
5362 h
= it2
.current_y
- it
->current_y
;
5363 nlines
= it2
.vpos
- it
->vpos
;
5365 /* Correct IT's y and vpos position. */
5371 /* DY == 0 means move to the start of the screen line. The
5372 value of nlines is > 0 if continuation lines were involved. */
5374 move_it_by_lines (it
, nlines
, 1);
5375 xassert (IT_CHARPOS (*it
) <= start_pos
);
5379 /* The y-position we try to reach. Note that h has been
5380 subtracted in front of the if-statement. */
5381 int target_y
= it
->current_y
+ h
- dy
;
5382 int y0
= it3
.current_y
;
5383 int y1
= line_bottom_y (&it3
);
5384 int line_height
= y1
- y0
;
5386 /* If we did not reach target_y, try to move further backward if
5387 we can. If we moved too far backward, try to move forward. */
5388 if (target_y
< it
->current_y
5389 /* This is heuristic. In a window that's 3 lines high, with
5390 a line height of 13 pixels each, recentering with point
5391 on the bottom line will try to move -39/2 = 19 pixels
5392 backward. Try to avoid moving into the first line. */
5393 && it
->current_y
- target_y
> line_height
/ 3 * 2
5394 && IT_CHARPOS (*it
) > BEGV
)
5396 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5397 target_y
- it
->current_y
));
5398 move_it_vertically (it
, target_y
- it
->current_y
);
5399 xassert (IT_CHARPOS (*it
) >= BEGV
);
5401 else if (target_y
>= it
->current_y
+ line_height
5402 && IT_CHARPOS (*it
) < ZV
)
5404 /* Should move forward by at least one line, maybe more. */
5407 move_it_by_lines (it
, 1, 1);
5409 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5411 xassert (IT_CHARPOS (*it
) >= BEGV
);
5417 /* Move IT by a specified amount of pixel lines DY. DY negative means
5418 move backwards. DY = 0 means move to start of screen line. At the
5419 end, IT will be on the start of a screen line. */
5422 move_it_vertically (it
, dy
)
5427 move_it_vertically_backward (it
, -dy
);
5430 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5431 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5432 MOVE_TO_POS
| MOVE_TO_Y
);
5433 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5435 /* If buffer ends in ZV without a newline, move to the start of
5436 the line to satisfy the post-condition. */
5437 if (IT_CHARPOS (*it
) == ZV
5438 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5439 move_it_by_lines (it
, 0, 0);
5444 /* Move iterator IT past the end of the text line it is in. */
5447 move_it_past_eol (it
)
5450 enum move_it_result rc
;
5452 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5453 if (rc
== MOVE_NEWLINE_OR_CR
)
5454 set_iterator_to_next (it
, 0);
5458 #if 0 /* Currently not used. */
5460 /* Return non-zero if some text between buffer positions START_CHARPOS
5461 and END_CHARPOS is invisible. IT->window is the window for text
5465 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5467 int start_charpos
, end_charpos
;
5469 Lisp_Object prop
, limit
;
5470 int invisible_found_p
;
5472 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5474 /* Is text at START invisible? */
5475 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5477 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5478 invisible_found_p
= 1;
5481 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5483 make_number (end_charpos
));
5484 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5487 return invisible_found_p
;
5493 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5494 negative means move up. DVPOS == 0 means move to the start of the
5495 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5496 NEED_Y_P is zero, IT->current_y will be left unchanged.
5498 Further optimization ideas: If we would know that IT->f doesn't use
5499 a face with proportional font, we could be faster for
5500 truncate-lines nil. */
5503 move_it_by_lines (it
, dvpos
, need_y_p
)
5505 int dvpos
, need_y_p
;
5507 struct position pos
;
5509 if (!FRAME_WINDOW_P (it
->f
))
5511 struct text_pos textpos
;
5513 /* We can use vmotion on frames without proportional fonts. */
5514 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5515 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5516 reseat (it
, textpos
, 1);
5517 it
->vpos
+= pos
.vpos
;
5518 it
->current_y
+= pos
.vpos
;
5520 else if (dvpos
== 0)
5522 /* DVPOS == 0 means move to the start of the screen line. */
5523 move_it_vertically_backward (it
, 0);
5524 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5527 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5531 int start_charpos
, i
;
5533 /* Start at the beginning of the screen line containing IT's
5535 move_it_vertically_backward (it
, 0);
5537 /* Go back -DVPOS visible lines and reseat the iterator there. */
5538 start_charpos
= IT_CHARPOS (*it
);
5539 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5540 back_to_previous_visible_line_start (it
);
5541 reseat (it
, it
->current
.pos
, 1);
5542 it
->current_x
= it
->hpos
= 0;
5544 /* Above call may have moved too far if continuation lines
5545 are involved. Scan forward and see if it did. */
5547 it2
.vpos
= it2
.current_y
= 0;
5548 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5549 it
->vpos
-= it2
.vpos
;
5550 it
->current_y
-= it2
.current_y
;
5551 it
->current_x
= it
->hpos
= 0;
5553 /* If we moved too far, move IT some lines forward. */
5554 if (it2
.vpos
> -dvpos
)
5556 int delta
= it2
.vpos
+ dvpos
;
5557 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5564 /***********************************************************************
5566 ***********************************************************************/
5569 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5573 add_to_log (format
, arg1
, arg2
)
5575 Lisp_Object arg1
, arg2
;
5577 Lisp_Object args
[3];
5578 Lisp_Object msg
, fmt
;
5581 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5583 /* Do nothing if called asynchronously. Inserting text into
5584 a buffer may call after-change-functions and alike and
5585 that would means running Lisp asynchronously. */
5586 if (handling_signal
)
5590 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5592 args
[0] = fmt
= build_string (format
);
5595 msg
= Fformat (3, args
);
5597 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5598 buffer
= (char *) alloca (len
);
5599 bcopy (XSTRING (msg
)->data
, buffer
, len
);
5601 message_dolog (buffer
, len
- 1, 1, 0);
5606 /* Output a newline in the *Messages* buffer if "needs" one. */
5609 message_log_maybe_newline ()
5611 if (message_log_need_newline
)
5612 message_dolog ("", 0, 1, 0);
5616 /* Add a string M of length NBYTES to the message log, optionally
5617 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5618 nonzero, means interpret the contents of M as multibyte. This
5619 function calls low-level routines in order to bypass text property
5620 hooks, etc. which might not be safe to run. */
5623 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5625 int nbytes
, nlflag
, multibyte
;
5627 if (!NILP (Vmessage_log_max
))
5629 struct buffer
*oldbuf
;
5630 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5631 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5632 int point_at_end
= 0;
5634 Lisp_Object old_deactivate_mark
, tem
;
5635 struct gcpro gcpro1
;
5637 old_deactivate_mark
= Vdeactivate_mark
;
5638 oldbuf
= current_buffer
;
5639 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5640 current_buffer
->undo_list
= Qt
;
5642 oldpoint
= message_dolog_marker1
;
5643 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
5644 oldbegv
= message_dolog_marker2
;
5645 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
5646 oldzv
= message_dolog_marker3
;
5647 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
5648 GCPRO1 (old_deactivate_mark
);
5656 BEGV_BYTE
= BEG_BYTE
;
5659 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5661 /* Insert the string--maybe converting multibyte to single byte
5662 or vice versa, so that all the text fits the buffer. */
5664 && NILP (current_buffer
->enable_multibyte_characters
))
5666 int i
, c
, char_bytes
;
5667 unsigned char work
[1];
5669 /* Convert a multibyte string to single-byte
5670 for the *Message* buffer. */
5671 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5673 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5674 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5676 : multibyte_char_to_unibyte (c
, Qnil
));
5677 insert_1_both (work
, 1, 1, 1, 0, 0);
5680 else if (! multibyte
5681 && ! NILP (current_buffer
->enable_multibyte_characters
))
5683 int i
, c
, char_bytes
;
5684 unsigned char *msg
= (unsigned char *) m
;
5685 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5686 /* Convert a single-byte string to multibyte
5687 for the *Message* buffer. */
5688 for (i
= 0; i
< nbytes
; i
++)
5690 c
= unibyte_char_to_multibyte (msg
[i
]);
5691 char_bytes
= CHAR_STRING (c
, str
);
5692 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5696 insert_1 (m
, nbytes
, 1, 0, 0);
5700 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5701 insert_1 ("\n", 1, 1, 0, 0);
5703 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5705 this_bol_byte
= PT_BYTE
;
5707 /* See if this line duplicates the previous one.
5708 If so, combine duplicates. */
5711 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5713 prev_bol_byte
= PT_BYTE
;
5715 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5716 this_bol
, this_bol_byte
);
5719 del_range_both (prev_bol
, prev_bol_byte
,
5720 this_bol
, this_bol_byte
, 0);
5726 /* If you change this format, don't forget to also
5727 change message_log_check_duplicate. */
5728 sprintf (dupstr
, " [%d times]", dup
);
5729 duplen
= strlen (dupstr
);
5730 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5731 insert_1 (dupstr
, duplen
, 1, 0, 1);
5736 /* If we have more than the desired maximum number of lines
5737 in the *Messages* buffer now, delete the oldest ones.
5738 This is safe because we don't have undo in this buffer. */
5740 if (NATNUMP (Vmessage_log_max
))
5742 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5743 -XFASTINT (Vmessage_log_max
) - 1, 0);
5744 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5747 BEGV
= XMARKER (oldbegv
)->charpos
;
5748 BEGV_BYTE
= marker_byte_position (oldbegv
);
5757 ZV
= XMARKER (oldzv
)->charpos
;
5758 ZV_BYTE
= marker_byte_position (oldzv
);
5762 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5764 /* We can't do Fgoto_char (oldpoint) because it will run some
5766 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5767 XMARKER (oldpoint
)->bytepos
);
5770 unchain_marker (oldpoint
);
5771 unchain_marker (oldbegv
);
5772 unchain_marker (oldzv
);
5774 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5775 set_buffer_internal (oldbuf
);
5777 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5778 message_log_need_newline
= !nlflag
;
5779 Vdeactivate_mark
= old_deactivate_mark
;
5784 /* We are at the end of the buffer after just having inserted a newline.
5785 (Note: We depend on the fact we won't be crossing the gap.)
5786 Check to see if the most recent message looks a lot like the previous one.
5787 Return 0 if different, 1 if the new one should just replace it, or a
5788 value N > 1 if we should also append " [N times]". */
5791 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5792 int prev_bol
, this_bol
;
5793 int prev_bol_byte
, this_bol_byte
;
5796 int len
= Z_BYTE
- 1 - this_bol_byte
;
5798 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5799 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5801 for (i
= 0; i
< len
; i
++)
5803 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5811 if (*p1
++ == ' ' && *p1
++ == '[')
5814 while (*p1
>= '0' && *p1
<= '9')
5815 n
= n
* 10 + *p1
++ - '0';
5816 if (strncmp (p1
, " times]\n", 8) == 0)
5823 /* Display an echo area message M with a specified length of NBYTES
5824 bytes. The string may include null characters. If M is 0, clear
5825 out any existing message, and let the mini-buffer text show
5828 The buffer M must continue to exist until after the echo area gets
5829 cleared or some other message gets displayed there. This means do
5830 not pass text that is stored in a Lisp string; do not pass text in
5831 a buffer that was alloca'd. */
5834 message2 (m
, nbytes
, multibyte
)
5839 /* First flush out any partial line written with print. */
5840 message_log_maybe_newline ();
5842 message_dolog (m
, nbytes
, 1, multibyte
);
5843 message2_nolog (m
, nbytes
, multibyte
);
5847 /* The non-logging counterpart of message2. */
5850 message2_nolog (m
, nbytes
, multibyte
)
5854 struct frame
*sf
= SELECTED_FRAME ();
5855 message_enable_multibyte
= multibyte
;
5859 if (noninteractive_need_newline
)
5860 putc ('\n', stderr
);
5861 noninteractive_need_newline
= 0;
5863 fwrite (m
, nbytes
, 1, stderr
);
5864 if (cursor_in_echo_area
== 0)
5865 fprintf (stderr
, "\n");
5868 /* A null message buffer means that the frame hasn't really been
5869 initialized yet. Error messages get reported properly by
5870 cmd_error, so this must be just an informative message; toss it. */
5871 else if (INTERACTIVE
5872 && sf
->glyphs_initialized_p
5873 && FRAME_MESSAGE_BUF (sf
))
5875 Lisp_Object mini_window
;
5878 /* Get the frame containing the mini-buffer
5879 that the selected frame is using. */
5880 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5881 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5883 FRAME_SAMPLE_VISIBILITY (f
);
5884 if (FRAME_VISIBLE_P (sf
)
5885 && ! FRAME_VISIBLE_P (f
))
5886 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5890 set_message (m
, Qnil
, nbytes
, multibyte
);
5891 if (minibuffer_auto_raise
)
5892 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5895 clear_message (1, 1);
5897 do_pending_window_change (0);
5898 echo_area_display (1);
5899 do_pending_window_change (0);
5900 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5901 (*frame_up_to_date_hook
) (f
);
5906 /* Display an echo area message M with a specified length of NBYTES
5907 bytes. The string may include null characters. If M is not a
5908 string, clear out any existing message, and let the mini-buffer
5909 text show through. */
5912 message3 (m
, nbytes
, multibyte
)
5917 struct gcpro gcpro1
;
5921 /* First flush out any partial line written with print. */
5922 message_log_maybe_newline ();
5924 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5925 message3_nolog (m
, nbytes
, multibyte
);
5931 /* The non-logging version of message3. */
5934 message3_nolog (m
, nbytes
, multibyte
)
5936 int nbytes
, multibyte
;
5938 struct frame
*sf
= SELECTED_FRAME ();
5939 message_enable_multibyte
= multibyte
;
5943 if (noninteractive_need_newline
)
5944 putc ('\n', stderr
);
5945 noninteractive_need_newline
= 0;
5947 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5948 if (cursor_in_echo_area
== 0)
5949 fprintf (stderr
, "\n");
5952 /* A null message buffer means that the frame hasn't really been
5953 initialized yet. Error messages get reported properly by
5954 cmd_error, so this must be just an informative message; toss it. */
5955 else if (INTERACTIVE
5956 && sf
->glyphs_initialized_p
5957 && FRAME_MESSAGE_BUF (sf
))
5959 Lisp_Object mini_window
;
5963 /* Get the frame containing the mini-buffer
5964 that the selected frame is using. */
5965 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5966 frame
= XWINDOW (mini_window
)->frame
;
5969 FRAME_SAMPLE_VISIBILITY (f
);
5970 if (FRAME_VISIBLE_P (sf
)
5971 && !FRAME_VISIBLE_P (f
))
5972 Fmake_frame_visible (frame
);
5974 if (STRINGP (m
) && XSTRING (m
)->size
)
5976 set_message (NULL
, m
, nbytes
, multibyte
);
5977 if (minibuffer_auto_raise
)
5978 Fraise_frame (frame
);
5981 clear_message (1, 1);
5983 do_pending_window_change (0);
5984 echo_area_display (1);
5985 do_pending_window_change (0);
5986 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5987 (*frame_up_to_date_hook
) (f
);
5992 /* Display a null-terminated echo area message M. If M is 0, clear
5993 out any existing message, and let the mini-buffer text show through.
5995 The buffer M must continue to exist until after the echo area gets
5996 cleared or some other message gets displayed there. Do not pass
5997 text that is stored in a Lisp string. Do not pass text in a buffer
5998 that was alloca'd. */
6004 message2 (m
, (m
? strlen (m
) : 0), 0);
6008 /* The non-logging counterpart of message1. */
6014 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6017 /* Display a message M which contains a single %s
6018 which gets replaced with STRING. */
6021 message_with_string (m
, string
, log
)
6030 if (noninteractive_need_newline
)
6031 putc ('\n', stderr
);
6032 noninteractive_need_newline
= 0;
6033 fprintf (stderr
, m
, XSTRING (string
)->data
);
6034 if (cursor_in_echo_area
== 0)
6035 fprintf (stderr
, "\n");
6039 else if (INTERACTIVE
)
6041 /* The frame whose minibuffer we're going to display the message on.
6042 It may be larger than the selected frame, so we need
6043 to use its buffer, not the selected frame's buffer. */
6044 Lisp_Object mini_window
;
6045 struct frame
*f
, *sf
= SELECTED_FRAME ();
6047 /* Get the frame containing the minibuffer
6048 that the selected frame is using. */
6049 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6050 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6052 /* A null message buffer means that the frame hasn't really been
6053 initialized yet. Error messages get reported properly by
6054 cmd_error, so this must be just an informative message; toss it. */
6055 if (FRAME_MESSAGE_BUF (f
))
6059 a
[0] = (char *) XSTRING (string
)->data
;
6061 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6062 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6065 message2 (FRAME_MESSAGE_BUF (f
), len
,
6066 STRING_MULTIBYTE (string
));
6068 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
6069 STRING_MULTIBYTE (string
));
6071 /* Print should start at the beginning of the message
6072 buffer next time. */
6073 message_buf_print
= 0;
6079 /* Dump an informative message to the minibuf. If M is 0, clear out
6080 any existing message, and let the mini-buffer text show through. */
6084 message (m
, a1
, a2
, a3
)
6086 EMACS_INT a1
, a2
, a3
;
6092 if (noninteractive_need_newline
)
6093 putc ('\n', stderr
);
6094 noninteractive_need_newline
= 0;
6095 fprintf (stderr
, m
, a1
, a2
, a3
);
6096 if (cursor_in_echo_area
== 0)
6097 fprintf (stderr
, "\n");
6101 else if (INTERACTIVE
)
6103 /* The frame whose mini-buffer we're going to display the message
6104 on. It may be larger than the selected frame, so we need to
6105 use its buffer, not the selected frame's buffer. */
6106 Lisp_Object mini_window
;
6107 struct frame
*f
, *sf
= SELECTED_FRAME ();
6109 /* Get the frame containing the mini-buffer
6110 that the selected frame is using. */
6111 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6112 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6114 /* A null message buffer means that the frame hasn't really been
6115 initialized yet. Error messages get reported properly by
6116 cmd_error, so this must be just an informative message; toss
6118 if (FRAME_MESSAGE_BUF (f
))
6129 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6130 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6132 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6133 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6135 #endif /* NO_ARG_ARRAY */
6137 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6142 /* Print should start at the beginning of the message
6143 buffer next time. */
6144 message_buf_print
= 0;
6150 /* The non-logging version of message. */
6153 message_nolog (m
, a1
, a2
, a3
)
6155 EMACS_INT a1
, a2
, a3
;
6157 Lisp_Object old_log_max
;
6158 old_log_max
= Vmessage_log_max
;
6159 Vmessage_log_max
= Qnil
;
6160 message (m
, a1
, a2
, a3
);
6161 Vmessage_log_max
= old_log_max
;
6165 /* Display the current message in the current mini-buffer. This is
6166 only called from error handlers in process.c, and is not time
6172 if (!NILP (echo_area_buffer
[0]))
6175 string
= Fcurrent_message ();
6176 message3 (string
, XSTRING (string
)->size
,
6177 !NILP (current_buffer
->enable_multibyte_characters
));
6182 /* Make sure echo area buffers in echo_buffers[] are life. If they
6183 aren't, make new ones. */
6186 ensure_echo_area_buffers ()
6190 for (i
= 0; i
< 2; ++i
)
6191 if (!BUFFERP (echo_buffer
[i
])
6192 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6195 Lisp_Object old_buffer
;
6198 old_buffer
= echo_buffer
[i
];
6199 sprintf (name
, " *Echo Area %d*", i
);
6200 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6201 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6203 for (j
= 0; j
< 2; ++j
)
6204 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6205 echo_area_buffer
[j
] = echo_buffer
[i
];
6210 /* Call FN with args A1..A4 with either the current or last displayed
6211 echo_area_buffer as current buffer.
6213 WHICH zero means use the current message buffer
6214 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6215 from echo_buffer[] and clear it.
6217 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6218 suitable buffer from echo_buffer[] and clear it.
6220 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6221 that the current message becomes the last displayed one, make
6222 choose a suitable buffer for echo_area_buffer[0], and clear it.
6224 Value is what FN returns. */
6227 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6230 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6236 int this_one
, the_other
, clear_buffer_p
, rc
;
6237 int count
= BINDING_STACK_SIZE ();
6239 /* If buffers aren't life, make new ones. */
6240 ensure_echo_area_buffers ();
6245 this_one
= 0, the_other
= 1;
6247 this_one
= 1, the_other
= 0;
6250 this_one
= 0, the_other
= 1;
6253 /* We need a fresh one in case the current echo buffer equals
6254 the one containing the last displayed echo area message. */
6255 if (!NILP (echo_area_buffer
[this_one
])
6256 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6257 echo_area_buffer
[this_one
] = Qnil
;
6260 /* Choose a suitable buffer from echo_buffer[] is we don't
6262 if (NILP (echo_area_buffer
[this_one
]))
6264 echo_area_buffer
[this_one
]
6265 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6266 ? echo_buffer
[the_other
]
6267 : echo_buffer
[this_one
]);
6271 buffer
= echo_area_buffer
[this_one
];
6273 /* Don't get confused by reusing the buffer used for echoing
6274 for a different purpose. */
6275 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6278 record_unwind_protect (unwind_with_echo_area_buffer
,
6279 with_echo_area_buffer_unwind_data (w
));
6281 /* Make the echo area buffer current. Note that for display
6282 purposes, it is not necessary that the displayed window's buffer
6283 == current_buffer, except for text property lookup. So, let's
6284 only set that buffer temporarily here without doing a full
6285 Fset_window_buffer. We must also change w->pointm, though,
6286 because otherwise an assertions in unshow_buffer fails, and Emacs
6288 set_buffer_internal_1 (XBUFFER (buffer
));
6292 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6295 current_buffer
->undo_list
= Qt
;
6296 current_buffer
->read_only
= Qnil
;
6297 specbind (Qinhibit_read_only
, Qt
);
6298 specbind (Qinhibit_modification_hooks
, Qt
);
6300 if (clear_buffer_p
&& Z
> BEG
)
6303 xassert (BEGV
>= BEG
);
6304 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6306 rc
= fn (a1
, a2
, a3
, a4
);
6308 xassert (BEGV
>= BEG
);
6309 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6311 unbind_to (count
, Qnil
);
6316 /* Save state that should be preserved around the call to the function
6317 FN called in with_echo_area_buffer. */
6320 with_echo_area_buffer_unwind_data (w
)
6326 /* Reduce consing by keeping one vector in
6327 Vwith_echo_area_save_vector. */
6328 vector
= Vwith_echo_area_save_vector
;
6329 Vwith_echo_area_save_vector
= Qnil
;
6332 vector
= Fmake_vector (make_number (7), Qnil
);
6334 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6335 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6336 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6340 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6341 AREF (vector
, i
) = w
->buffer
; ++i
;
6342 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6343 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6348 for (; i
< end
; ++i
)
6349 AREF (vector
, i
) = Qnil
;
6352 xassert (i
== ASIZE (vector
));
6357 /* Restore global state from VECTOR which was created by
6358 with_echo_area_buffer_unwind_data. */
6361 unwind_with_echo_area_buffer (vector
)
6364 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6365 Vdeactivate_mark
= AREF (vector
, 1);
6366 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6368 if (WINDOWP (AREF (vector
, 3)))
6371 Lisp_Object buffer
, charpos
, bytepos
;
6373 w
= XWINDOW (AREF (vector
, 3));
6374 buffer
= AREF (vector
, 4);
6375 charpos
= AREF (vector
, 5);
6376 bytepos
= AREF (vector
, 6);
6379 set_marker_both (w
->pointm
, buffer
,
6380 XFASTINT (charpos
), XFASTINT (bytepos
));
6383 Vwith_echo_area_save_vector
= vector
;
6388 /* Set up the echo area for use by print functions. MULTIBYTE_P
6389 non-zero means we will print multibyte. */
6392 setup_echo_area_for_printing (multibyte_p
)
6395 ensure_echo_area_buffers ();
6397 if (!message_buf_print
)
6399 /* A message has been output since the last time we printed.
6400 Choose a fresh echo area buffer. */
6401 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6402 echo_area_buffer
[0] = echo_buffer
[1];
6404 echo_area_buffer
[0] = echo_buffer
[0];
6406 /* Switch to that buffer and clear it. */
6407 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6408 current_buffer
->truncate_lines
= Qnil
;
6412 int count
= BINDING_STACK_SIZE ();
6413 specbind (Qinhibit_read_only
, Qt
);
6415 unbind_to (count
, Qnil
);
6417 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6419 /* Set up the buffer for the multibyteness we need. */
6421 != !NILP (current_buffer
->enable_multibyte_characters
))
6422 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6424 /* Raise the frame containing the echo area. */
6425 if (minibuffer_auto_raise
)
6427 struct frame
*sf
= SELECTED_FRAME ();
6428 Lisp_Object mini_window
;
6429 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6430 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6433 message_log_maybe_newline ();
6434 message_buf_print
= 1;
6438 if (NILP (echo_area_buffer
[0]))
6440 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6441 echo_area_buffer
[0] = echo_buffer
[1];
6443 echo_area_buffer
[0] = echo_buffer
[0];
6446 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6448 /* Someone switched buffers between print requests. */
6449 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6450 current_buffer
->truncate_lines
= Qnil
;
6456 /* Display an echo area message in window W. Value is non-zero if W's
6457 height is changed. If display_last_displayed_message_p is
6458 non-zero, display the message that was last displayed, otherwise
6459 display the current message. */
6462 display_echo_area (w
)
6465 int i
, no_message_p
, window_height_changed_p
, count
;
6467 /* Temporarily disable garbage collections while displaying the echo
6468 area. This is done because a GC can print a message itself.
6469 That message would modify the echo area buffer's contents while a
6470 redisplay of the buffer is going on, and seriously confuse
6472 count
= inhibit_garbage_collection ();
6474 /* If there is no message, we must call display_echo_area_1
6475 nevertheless because it resizes the window. But we will have to
6476 reset the echo_area_buffer in question to nil at the end because
6477 with_echo_area_buffer will sets it to an empty buffer. */
6478 i
= display_last_displayed_message_p
? 1 : 0;
6479 no_message_p
= NILP (echo_area_buffer
[i
]);
6481 window_height_changed_p
6482 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6483 display_echo_area_1
,
6484 (EMACS_INT
) w
, Qnil
, 0, 0);
6487 echo_area_buffer
[i
] = Qnil
;
6489 unbind_to (count
, Qnil
);
6490 return window_height_changed_p
;
6494 /* Helper for display_echo_area. Display the current buffer which
6495 contains the current echo area message in window W, a mini-window,
6496 a pointer to which is passed in A1. A2..A4 are currently not used.
6497 Change the height of W so that all of the message is displayed.
6498 Value is non-zero if height of W was changed. */
6501 display_echo_area_1 (a1
, a2
, a3
, a4
)
6506 struct window
*w
= (struct window
*) a1
;
6508 struct text_pos start
;
6509 int window_height_changed_p
= 0;
6511 /* Do this before displaying, so that we have a large enough glyph
6512 matrix for the display. */
6513 window_height_changed_p
= resize_mini_window (w
, 0);
6516 clear_glyph_matrix (w
->desired_matrix
);
6517 XSETWINDOW (window
, w
);
6518 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6519 try_window (window
, start
);
6521 return window_height_changed_p
;
6525 /* Resize the echo area window to exactly the size needed for the
6526 currently displayed message, if there is one. If a mini-buffer
6527 is active, don't shrink it. */
6530 resize_echo_area_exactly ()
6532 if (BUFFERP (echo_area_buffer
[0])
6533 && WINDOWP (echo_area_window
))
6535 struct window
*w
= XWINDOW (echo_area_window
);
6537 Lisp_Object resize_exactly
;
6539 if (minibuf_level
== 0)
6540 resize_exactly
= Qt
;
6542 resize_exactly
= Qnil
;
6544 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6545 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6548 ++windows_or_buffers_changed
;
6549 ++update_mode_lines
;
6550 redisplay_internal (0);
6556 /* Callback function for with_echo_area_buffer, when used from
6557 resize_echo_area_exactly. A1 contains a pointer to the window to
6558 resize, EXACTLY non-nil means resize the mini-window exactly to the
6559 size of the text displayed. A3 and A4 are not used. Value is what
6560 resize_mini_window returns. */
6563 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6565 Lisp_Object exactly
;
6568 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6572 /* Resize mini-window W to fit the size of its contents. EXACT:P
6573 means size the window exactly to the size needed. Otherwise, it's
6574 only enlarged until W's buffer is empty. Value is non-zero if
6575 the window height has been changed. */
6578 resize_mini_window (w
, exact_p
)
6582 struct frame
*f
= XFRAME (w
->frame
);
6583 int window_height_changed_p
= 0;
6585 xassert (MINI_WINDOW_P (w
));
6587 /* Don't resize windows while redisplaying a window; it would
6588 confuse redisplay functions when the size of the window they are
6589 displaying changes from under them. Such a resizing can happen,
6590 for instance, when which-func prints a long message while
6591 we are running fontification-functions. We're running these
6592 functions with safe_call which binds inhibit-redisplay to t. */
6593 if (!NILP (Vinhibit_redisplay
))
6596 /* Nil means don't try to resize. */
6597 if (NILP (Vresize_mini_windows
)
6598 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6601 if (!FRAME_MINIBUF_ONLY_P (f
))
6604 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6605 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6606 int height
, max_height
;
6607 int unit
= CANON_Y_UNIT (f
);
6608 struct text_pos start
;
6609 struct buffer
*old_current_buffer
= NULL
;
6611 if (current_buffer
!= XBUFFER (w
->buffer
))
6613 old_current_buffer
= current_buffer
;
6614 set_buffer_internal (XBUFFER (w
->buffer
));
6617 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6619 /* Compute the max. number of lines specified by the user. */
6620 if (FLOATP (Vmax_mini_window_height
))
6621 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6622 else if (INTEGERP (Vmax_mini_window_height
))
6623 max_height
= XINT (Vmax_mini_window_height
);
6625 max_height
= total_height
/ 4;
6627 /* Correct that max. height if it's bogus. */
6628 max_height
= max (1, max_height
);
6629 max_height
= min (total_height
, max_height
);
6631 /* Find out the height of the text in the window. */
6632 if (it
.truncate_lines_p
)
6637 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6638 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6639 height
= it
.current_y
+ last_height
;
6641 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6642 height
-= it
.extra_line_spacing
;
6643 height
= (height
+ unit
- 1) / unit
;
6646 /* Compute a suitable window start. */
6647 if (height
> max_height
)
6649 height
= max_height
;
6650 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6651 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6652 start
= it
.current
.pos
;
6655 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6656 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6658 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6660 /* Let it grow only, until we display an empty message, in which
6661 case the window shrinks again. */
6662 if (height
> XFASTINT (w
->height
))
6664 int old_height
= XFASTINT (w
->height
);
6665 freeze_window_starts (f
, 1);
6666 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6667 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6669 else if (height
< XFASTINT (w
->height
)
6670 && (exact_p
|| BEGV
== ZV
))
6672 int old_height
= XFASTINT (w
->height
);
6673 freeze_window_starts (f
, 0);
6674 shrink_mini_window (w
);
6675 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6680 /* Always resize to exact size needed. */
6681 if (height
> XFASTINT (w
->height
))
6683 int old_height
= XFASTINT (w
->height
);
6684 freeze_window_starts (f
, 1);
6685 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6686 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6688 else if (height
< XFASTINT (w
->height
))
6690 int old_height
= XFASTINT (w
->height
);
6691 freeze_window_starts (f
, 0);
6692 shrink_mini_window (w
);
6696 freeze_window_starts (f
, 1);
6697 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6700 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6704 if (old_current_buffer
)
6705 set_buffer_internal (old_current_buffer
);
6708 return window_height_changed_p
;
6712 /* Value is the current message, a string, or nil if there is no
6720 if (NILP (echo_area_buffer
[0]))
6724 with_echo_area_buffer (0, 0, current_message_1
,
6725 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6727 echo_area_buffer
[0] = Qnil
;
6735 current_message_1 (a1
, a2
, a3
, a4
)
6740 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6743 *msg
= make_buffer_string (BEG
, Z
, 1);
6750 /* Push the current message on Vmessage_stack for later restauration
6751 by restore_message. Value is non-zero if the current message isn't
6752 empty. This is a relatively infrequent operation, so it's not
6753 worth optimizing. */
6759 msg
= current_message ();
6760 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6761 return STRINGP (msg
);
6765 /* Handler for record_unwind_protect calling pop_message. */
6768 push_message_unwind (dummy
)
6776 /* Restore message display from the top of Vmessage_stack. */
6783 xassert (CONSP (Vmessage_stack
));
6784 msg
= XCAR (Vmessage_stack
);
6786 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6788 message3_nolog (msg
, 0, 0);
6792 /* Pop the top-most entry off Vmessage_stack. */
6797 xassert (CONSP (Vmessage_stack
));
6798 Vmessage_stack
= XCDR (Vmessage_stack
);
6802 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6803 exits. If the stack is not empty, we have a missing pop_message
6807 check_message_stack ()
6809 if (!NILP (Vmessage_stack
))
6814 /* Truncate to NCHARS what will be displayed in the echo area the next
6815 time we display it---but don't redisplay it now. */
6818 truncate_echo_area (nchars
)
6822 echo_area_buffer
[0] = Qnil
;
6823 /* A null message buffer means that the frame hasn't really been
6824 initialized yet. Error messages get reported properly by
6825 cmd_error, so this must be just an informative message; toss it. */
6826 else if (!noninteractive
6828 && !NILP (echo_area_buffer
[0]))
6830 struct frame
*sf
= SELECTED_FRAME ();
6831 if (FRAME_MESSAGE_BUF (sf
))
6832 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6837 /* Helper function for truncate_echo_area. Truncate the current
6838 message to at most NCHARS characters. */
6841 truncate_message_1 (nchars
, a2
, a3
, a4
)
6846 if (BEG
+ nchars
< Z
)
6847 del_range (BEG
+ nchars
, Z
);
6849 echo_area_buffer
[0] = Qnil
;
6854 /* Set the current message to a substring of S or STRING.
6856 If STRING is a Lisp string, set the message to the first NBYTES
6857 bytes from STRING. NBYTES zero means use the whole string. If
6858 STRING is multibyte, the message will be displayed multibyte.
6860 If S is not null, set the message to the first LEN bytes of S. LEN
6861 zero means use the whole string. MULTIBYTE_P non-zero means S is
6862 multibyte. Display the message multibyte in that case. */
6865 set_message (s
, string
, nbytes
, multibyte_p
)
6870 message_enable_multibyte
6871 = ((s
&& multibyte_p
)
6872 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6874 with_echo_area_buffer (0, -1, set_message_1
,
6875 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6876 message_buf_print
= 0;
6877 help_echo_showing_p
= 0;
6881 /* Helper function for set_message. Arguments have the same meaning
6882 as there, with A1 corresponding to S and A2 corresponding to STRING
6883 This function is called with the echo area buffer being
6887 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6890 EMACS_INT nbytes
, multibyte_p
;
6892 char *s
= (char *) a1
;
6893 Lisp_Object string
= a2
;
6897 /* Change multibyteness of the echo buffer appropriately. */
6898 if (message_enable_multibyte
6899 != !NILP (current_buffer
->enable_multibyte_characters
))
6900 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6902 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6904 /* Insert new message at BEG. */
6905 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6907 if (STRINGP (string
))
6912 nbytes
= XSTRING (string
)->size_byte
;
6913 nchars
= string_byte_to_char (string
, nbytes
);
6915 /* This function takes care of single/multibyte conversion. We
6916 just have to ensure that the echo area buffer has the right
6917 setting of enable_multibyte_characters. */
6918 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6923 nbytes
= strlen (s
);
6925 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6927 /* Convert from multi-byte to single-byte. */
6929 unsigned char work
[1];
6931 /* Convert a multibyte string to single-byte. */
6932 for (i
= 0; i
< nbytes
; i
+= n
)
6934 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6935 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6937 : multibyte_char_to_unibyte (c
, Qnil
));
6938 insert_1_both (work
, 1, 1, 1, 0, 0);
6941 else if (!multibyte_p
6942 && !NILP (current_buffer
->enable_multibyte_characters
))
6944 /* Convert from single-byte to multi-byte. */
6946 unsigned char *msg
= (unsigned char *) s
;
6947 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6949 /* Convert a single-byte string to multibyte. */
6950 for (i
= 0; i
< nbytes
; i
++)
6952 c
= unibyte_char_to_multibyte (msg
[i
]);
6953 n
= CHAR_STRING (c
, str
);
6954 insert_1_both (str
, 1, n
, 1, 0, 0);
6958 insert_1 (s
, nbytes
, 1, 0, 0);
6965 /* Clear messages. CURRENT_P non-zero means clear the current
6966 message. LAST_DISPLAYED_P non-zero means clear the message
6970 clear_message (current_p
, last_displayed_p
)
6971 int current_p
, last_displayed_p
;
6975 echo_area_buffer
[0] = Qnil
;
6976 message_cleared_p
= 1;
6979 if (last_displayed_p
)
6980 echo_area_buffer
[1] = Qnil
;
6982 message_buf_print
= 0;
6985 /* Clear garbaged frames.
6987 This function is used where the old redisplay called
6988 redraw_garbaged_frames which in turn called redraw_frame which in
6989 turn called clear_frame. The call to clear_frame was a source of
6990 flickering. I believe a clear_frame is not necessary. It should
6991 suffice in the new redisplay to invalidate all current matrices,
6992 and ensure a complete redisplay of all windows. */
6995 clear_garbaged_frames ()
6999 Lisp_Object tail
, frame
;
7001 FOR_EACH_FRAME (tail
, frame
)
7003 struct frame
*f
= XFRAME (frame
);
7005 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7008 Fredraw_frame (frame
);
7009 clear_current_matrices (f
);
7016 ++windows_or_buffers_changed
;
7021 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7022 is non-zero update selected_frame. Value is non-zero if the
7023 mini-windows height has been changed. */
7026 echo_area_display (update_frame_p
)
7029 Lisp_Object mini_window
;
7032 int window_height_changed_p
= 0;
7033 struct frame
*sf
= SELECTED_FRAME ();
7035 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7036 w
= XWINDOW (mini_window
);
7037 f
= XFRAME (WINDOW_FRAME (w
));
7039 /* Don't display if frame is invisible or not yet initialized. */
7040 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7043 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7045 #ifdef HAVE_WINDOW_SYSTEM
7046 /* When Emacs starts, selected_frame may be a visible terminal
7047 frame, even if we run under a window system. If we let this
7048 through, a message would be displayed on the terminal. */
7049 if (EQ (selected_frame
, Vterminal_frame
)
7050 && !NILP (Vwindow_system
))
7052 #endif /* HAVE_WINDOW_SYSTEM */
7055 /* Redraw garbaged frames. */
7057 clear_garbaged_frames ();
7059 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7061 echo_area_window
= mini_window
;
7062 window_height_changed_p
= display_echo_area (w
);
7063 w
->must_be_updated_p
= 1;
7065 /* Update the display, unless called from redisplay_internal.
7066 Also don't update the screen during redisplay itself. The
7067 update will happen at the end of redisplay, and an update
7068 here could cause confusion. */
7069 if (update_frame_p
&& !redisplaying_p
)
7073 /* If the display update has been interrupted by pending
7074 input, update mode lines in the frame. Due to the
7075 pending input, it might have been that redisplay hasn't
7076 been called, so that mode lines above the echo area are
7077 garbaged. This looks odd, so we prevent it here. */
7078 if (!display_completed
)
7079 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7081 if (window_height_changed_p
7082 /* Don't do this if Emacs is shutting down. Redisplay
7083 needs to run hooks. */
7084 && !NILP (Vrun_hooks
))
7086 /* Must update other windows. Likewise as in other
7087 cases, don't let this update be interrupted by
7089 int count
= BINDING_STACK_SIZE ();
7090 specbind (Qredisplay_dont_pause
, Qt
);
7091 windows_or_buffers_changed
= 1;
7092 redisplay_internal (0);
7093 unbind_to (count
, Qnil
);
7095 else if (FRAME_WINDOW_P (f
) && n
== 0)
7097 /* Window configuration is the same as before.
7098 Can do with a display update of the echo area,
7099 unless we displayed some mode lines. */
7100 update_single_window (w
, 1);
7101 rif
->flush_display (f
);
7104 update_frame (f
, 1, 1);
7106 /* If cursor is in the echo area, make sure that the next
7107 redisplay displays the minibuffer, so that the cursor will
7108 be replaced with what the minibuffer wants. */
7109 if (cursor_in_echo_area
)
7110 ++windows_or_buffers_changed
;
7113 else if (!EQ (mini_window
, selected_window
))
7114 windows_or_buffers_changed
++;
7116 /* Last displayed message is now the current message. */
7117 echo_area_buffer
[1] = echo_area_buffer
[0];
7119 /* Prevent redisplay optimization in redisplay_internal by resetting
7120 this_line_start_pos. This is done because the mini-buffer now
7121 displays the message instead of its buffer text. */
7122 if (EQ (mini_window
, selected_window
))
7123 CHARPOS (this_line_start_pos
) = 0;
7125 return window_height_changed_p
;
7130 /***********************************************************************
7132 ***********************************************************************/
7135 #ifdef HAVE_WINDOW_SYSTEM
7137 /* A buffer for constructing frame titles in it; allocated from the
7138 heap in init_xdisp and resized as needed in store_frame_title_char. */
7140 static char *frame_title_buf
;
7142 /* The buffer's end, and a current output position in it. */
7144 static char *frame_title_buf_end
;
7145 static char *frame_title_ptr
;
7148 /* Store a single character C for the frame title in frame_title_buf.
7149 Re-allocate frame_title_buf if necessary. */
7152 store_frame_title_char (c
)
7155 /* If output position has reached the end of the allocated buffer,
7156 double the buffer's size. */
7157 if (frame_title_ptr
== frame_title_buf_end
)
7159 int len
= frame_title_ptr
- frame_title_buf
;
7160 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7161 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7162 frame_title_buf_end
= frame_title_buf
+ new_size
;
7163 frame_title_ptr
= frame_title_buf
+ len
;
7166 *frame_title_ptr
++ = c
;
7170 /* Store part of a frame title in frame_title_buf, beginning at
7171 frame_title_ptr. STR is the string to store. Do not copy
7172 characters that yield more columns than PRECISION; PRECISION <= 0
7173 means copy the whole string. Pad with spaces until FIELD_WIDTH
7174 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7175 pad. Called from display_mode_element when it is used to build a
7179 store_frame_title (str
, field_width
, precision
)
7181 int field_width
, precision
;
7186 /* Copy at most PRECISION chars from STR. */
7187 nbytes
= strlen (str
);
7188 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7190 store_frame_title_char (*str
++);
7192 /* Fill up with spaces until FIELD_WIDTH reached. */
7193 while (field_width
> 0
7196 store_frame_title_char (' ');
7204 /* Set the title of FRAME, if it has changed. The title format is
7205 Vicon_title_format if FRAME is iconified, otherwise it is
7206 frame_title_format. */
7209 x_consider_frame_title (frame
)
7212 struct frame
*f
= XFRAME (frame
);
7214 if (FRAME_WINDOW_P (f
)
7215 || FRAME_MINIBUF_ONLY_P (f
)
7216 || f
->explicit_name
)
7218 /* Do we have more than one visible frame on this X display? */
7221 struct buffer
*obuf
;
7225 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7227 Lisp_Object other_frame
= XCAR (tail
);
7228 struct frame
*tf
= XFRAME (other_frame
);
7231 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7232 && !FRAME_MINIBUF_ONLY_P (tf
)
7233 && !EQ (other_frame
, tip_frame
)
7234 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7238 /* Set global variable indicating that multiple frames exist. */
7239 multiple_frames
= CONSP (tail
);
7241 /* Switch to the buffer of selected window of the frame. Set up
7242 frame_title_ptr so that display_mode_element will output into it;
7243 then display the title. */
7244 obuf
= current_buffer
;
7245 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7246 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7247 frame_title_ptr
= frame_title_buf
;
7248 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7249 NULL
, DEFAULT_FACE_ID
);
7250 display_mode_element (&it
, 0, -1, -1, fmt
);
7251 len
= frame_title_ptr
- frame_title_buf
;
7252 frame_title_ptr
= NULL
;
7253 set_buffer_internal_1 (obuf
);
7255 /* Set the title only if it's changed. This avoids consing in
7256 the common case where it hasn't. (If it turns out that we've
7257 already wasted too much time by walking through the list with
7258 display_mode_element, then we might need to optimize at a
7259 higher level than this.) */
7260 if (! STRINGP (f
->name
)
7261 || STRING_BYTES (XSTRING (f
->name
)) != len
7262 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
7263 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7267 #else /* not HAVE_WINDOW_SYSTEM */
7269 #define frame_title_ptr ((char *)0)
7270 #define store_frame_title(str, mincol, maxcol) 0
7272 #endif /* not HAVE_WINDOW_SYSTEM */
7277 /***********************************************************************
7279 ***********************************************************************/
7282 /* Prepare for redisplay by updating menu-bar item lists when
7283 appropriate. This can call eval. */
7286 prepare_menu_bars ()
7289 struct gcpro gcpro1
, gcpro2
;
7291 Lisp_Object tooltip_frame
;
7293 #ifdef HAVE_WINDOW_SYSTEM
7294 tooltip_frame
= tip_frame
;
7296 tooltip_frame
= Qnil
;
7299 /* Update all frame titles based on their buffer names, etc. We do
7300 this before the menu bars so that the buffer-menu will show the
7301 up-to-date frame titles. */
7302 #ifdef HAVE_WINDOW_SYSTEM
7303 if (windows_or_buffers_changed
|| update_mode_lines
)
7305 Lisp_Object tail
, frame
;
7307 FOR_EACH_FRAME (tail
, frame
)
7310 if (!EQ (frame
, tooltip_frame
)
7311 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7312 x_consider_frame_title (frame
);
7315 #endif /* HAVE_WINDOW_SYSTEM */
7317 /* Update the menu bar item lists, if appropriate. This has to be
7318 done before any actual redisplay or generation of display lines. */
7319 all_windows
= (update_mode_lines
7320 || buffer_shared
> 1
7321 || windows_or_buffers_changed
);
7324 Lisp_Object tail
, frame
;
7325 int count
= BINDING_STACK_SIZE ();
7327 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7329 FOR_EACH_FRAME (tail
, frame
)
7333 /* Ignore tooltip frame. */
7334 if (EQ (frame
, tooltip_frame
))
7337 /* If a window on this frame changed size, report that to
7338 the user and clear the size-change flag. */
7339 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7341 Lisp_Object functions
;
7343 /* Clear flag first in case we get an error below. */
7344 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7345 functions
= Vwindow_size_change_functions
;
7346 GCPRO2 (tail
, functions
);
7348 while (CONSP (functions
))
7350 call1 (XCAR (functions
), frame
);
7351 functions
= XCDR (functions
);
7357 update_menu_bar (f
, 0);
7358 #ifdef HAVE_WINDOW_SYSTEM
7359 update_tool_bar (f
, 0);
7364 unbind_to (count
, Qnil
);
7368 struct frame
*sf
= SELECTED_FRAME ();
7369 update_menu_bar (sf
, 1);
7370 #ifdef HAVE_WINDOW_SYSTEM
7371 update_tool_bar (sf
, 1);
7375 /* Motif needs this. See comment in xmenu.c. Turn it off when
7376 pending_menu_activation is not defined. */
7377 #ifdef USE_X_TOOLKIT
7378 pending_menu_activation
= 0;
7383 /* Update the menu bar item list for frame F. This has to be done
7384 before we start to fill in any display lines, because it can call
7387 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7390 update_menu_bar (f
, save_match_data
)
7392 int save_match_data
;
7395 register struct window
*w
;
7397 /* If called recursively during a menu update, do nothing. This can
7398 happen when, for instance, an activate-menubar-hook causes a
7400 if (inhibit_menubar_update
)
7403 window
= FRAME_SELECTED_WINDOW (f
);
7404 w
= XWINDOW (window
);
7406 if (update_mode_lines
)
7407 w
->update_mode_line
= Qt
;
7409 if (FRAME_WINDOW_P (f
)
7411 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7412 FRAME_EXTERNAL_MENU_BAR (f
)
7414 FRAME_MENU_BAR_LINES (f
) > 0
7416 : FRAME_MENU_BAR_LINES (f
) > 0)
7418 /* If the user has switched buffers or windows, we need to
7419 recompute to reflect the new bindings. But we'll
7420 recompute when update_mode_lines is set too; that means
7421 that people can use force-mode-line-update to request
7422 that the menu bar be recomputed. The adverse effect on
7423 the rest of the redisplay algorithm is about the same as
7424 windows_or_buffers_changed anyway. */
7425 if (windows_or_buffers_changed
7426 || !NILP (w
->update_mode_line
)
7427 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7428 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7429 != !NILP (w
->last_had_star
))
7430 || ((!NILP (Vtransient_mark_mode
)
7431 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7432 != !NILP (w
->region_showing
)))
7434 struct buffer
*prev
= current_buffer
;
7435 int count
= BINDING_STACK_SIZE ();
7437 specbind (Qinhibit_menubar_update
, Qt
);
7439 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7440 if (save_match_data
)
7441 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7442 if (NILP (Voverriding_local_map_menu_flag
))
7444 specbind (Qoverriding_terminal_local_map
, Qnil
);
7445 specbind (Qoverriding_local_map
, Qnil
);
7448 /* Run the Lucid hook. */
7449 safe_run_hooks (Qactivate_menubar_hook
);
7451 /* If it has changed current-menubar from previous value,
7452 really recompute the menu-bar from the value. */
7453 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7454 call0 (Qrecompute_lucid_menubar
);
7456 safe_run_hooks (Qmenu_bar_update_hook
);
7457 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7459 /* Redisplay the menu bar in case we changed it. */
7460 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7461 if (FRAME_WINDOW_P (f
)
7462 #if defined (macintosh)
7463 /* All frames on Mac OS share the same menubar. So only the
7464 selected frame should be allowed to set it. */
7465 && f
== SELECTED_FRAME ()
7468 set_frame_menubar (f
, 0, 0);
7470 /* On a terminal screen, the menu bar is an ordinary screen
7471 line, and this makes it get updated. */
7472 w
->update_mode_line
= Qt
;
7473 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7474 /* In the non-toolkit version, the menu bar is an ordinary screen
7475 line, and this makes it get updated. */
7476 w
->update_mode_line
= Qt
;
7477 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7479 unbind_to (count
, Qnil
);
7480 set_buffer_internal_1 (prev
);
7487 /***********************************************************************
7489 ***********************************************************************/
7491 #ifdef HAVE_WINDOW_SYSTEM
7493 /* Update the tool-bar item list for frame F. This has to be done
7494 before we start to fill in any display lines. Called from
7495 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7496 and restore it here. */
7499 update_tool_bar (f
, save_match_data
)
7501 int save_match_data
;
7503 if (WINDOWP (f
->tool_bar_window
)
7504 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7509 window
= FRAME_SELECTED_WINDOW (f
);
7510 w
= XWINDOW (window
);
7512 /* If the user has switched buffers or windows, we need to
7513 recompute to reflect the new bindings. But we'll
7514 recompute when update_mode_lines is set too; that means
7515 that people can use force-mode-line-update to request
7516 that the menu bar be recomputed. The adverse effect on
7517 the rest of the redisplay algorithm is about the same as
7518 windows_or_buffers_changed anyway. */
7519 if (windows_or_buffers_changed
7520 || !NILP (w
->update_mode_line
)
7521 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7522 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7523 != !NILP (w
->last_had_star
))
7524 || ((!NILP (Vtransient_mark_mode
)
7525 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7526 != !NILP (w
->region_showing
)))
7528 struct buffer
*prev
= current_buffer
;
7529 int count
= BINDING_STACK_SIZE ();
7531 /* Set current_buffer to the buffer of the selected
7532 window of the frame, so that we get the right local
7534 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7536 /* Save match data, if we must. */
7537 if (save_match_data
)
7538 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7540 /* Make sure that we don't accidentally use bogus keymaps. */
7541 if (NILP (Voverriding_local_map_menu_flag
))
7543 specbind (Qoverriding_terminal_local_map
, Qnil
);
7544 specbind (Qoverriding_local_map
, Qnil
);
7547 /* Build desired tool-bar items from keymaps. */
7549 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7551 /* Redisplay the tool-bar in case we changed it. */
7552 w
->update_mode_line
= Qt
;
7554 unbind_to (count
, Qnil
);
7555 set_buffer_internal_1 (prev
);
7561 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7562 F's desired tool-bar contents. F->tool_bar_items must have
7563 been set up previously by calling prepare_menu_bars. */
7566 build_desired_tool_bar_string (f
)
7569 int i
, size
, size_needed
;
7570 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7571 Lisp_Object image
, plist
, props
;
7573 image
= plist
= props
= Qnil
;
7574 GCPRO3 (image
, plist
, props
);
7576 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7577 Otherwise, make a new string. */
7579 /* The size of the string we might be able to reuse. */
7580 size
= (STRINGP (f
->desired_tool_bar_string
)
7581 ? XSTRING (f
->desired_tool_bar_string
)->size
7584 /* We need one space in the string for each image. */
7585 size_needed
= f
->n_tool_bar_items
;
7587 /* Reuse f->desired_tool_bar_string, if possible. */
7588 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7589 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7593 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7594 Fremove_text_properties (make_number (0), make_number (size
),
7595 props
, f
->desired_tool_bar_string
);
7598 /* Put a `display' property on the string for the images to display,
7599 put a `menu_item' property on tool-bar items with a value that
7600 is the index of the item in F's tool-bar item vector. */
7601 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7603 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7605 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7606 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7607 int hmargin
, vmargin
, relief
, idx
, end
;
7608 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7610 /* If image is a vector, choose the image according to the
7612 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7613 if (VECTORP (image
))
7617 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7618 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7621 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7622 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7624 xassert (ASIZE (image
) >= idx
);
7625 image
= AREF (image
, idx
);
7630 /* Ignore invalid image specifications. */
7631 if (!valid_image_p (image
))
7634 /* Display the tool-bar button pressed, or depressed. */
7635 plist
= Fcopy_sequence (XCDR (image
));
7637 /* Compute margin and relief to draw. */
7638 relief
= (tool_bar_button_relief
>= 0
7639 ? tool_bar_button_relief
7640 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7641 hmargin
= vmargin
= relief
;
7643 if (INTEGERP (Vtool_bar_button_margin
)
7644 && XINT (Vtool_bar_button_margin
) > 0)
7646 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7647 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7649 else if (CONSP (Vtool_bar_button_margin
))
7651 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7652 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7653 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7655 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7656 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7657 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7660 if (auto_raise_tool_bar_buttons_p
)
7662 /* Add a `:relief' property to the image spec if the item is
7666 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7673 /* If image is selected, display it pressed, i.e. with a
7674 negative relief. If it's not selected, display it with a
7676 plist
= Fplist_put (plist
, QCrelief
,
7678 ? make_number (-relief
)
7679 : make_number (relief
)));
7684 /* Put a margin around the image. */
7685 if (hmargin
|| vmargin
)
7687 if (hmargin
== vmargin
)
7688 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7690 plist
= Fplist_put (plist
, QCmargin
,
7691 Fcons (make_number (hmargin
),
7692 make_number (vmargin
)));
7695 /* If button is not enabled, and we don't have special images
7696 for the disabled state, make the image appear disabled by
7697 applying an appropriate algorithm to it. */
7698 if (!enabled_p
&& idx
< 0)
7699 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7701 /* Put a `display' text property on the string for the image to
7702 display. Put a `menu-item' property on the string that gives
7703 the start of this item's properties in the tool-bar items
7705 image
= Fcons (Qimage
, plist
);
7706 props
= list4 (Qdisplay
, image
,
7707 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7709 /* Let the last image hide all remaining spaces in the tool bar
7710 string. The string can be longer than needed when we reuse a
7712 if (i
+ 1 == f
->n_tool_bar_items
)
7713 end
= XSTRING (f
->desired_tool_bar_string
)->size
;
7716 Fadd_text_properties (make_number (i
), make_number (end
),
7717 props
, f
->desired_tool_bar_string
);
7725 /* Display one line of the tool-bar of frame IT->f. */
7728 display_tool_bar_line (it
)
7731 struct glyph_row
*row
= it
->glyph_row
;
7732 int max_x
= it
->last_visible_x
;
7735 prepare_desired_row (row
);
7736 row
->y
= it
->current_y
;
7738 /* Note that this isn't made use of if the face hasn't a box,
7739 so there's no need to check the face here. */
7740 it
->start_of_box_run_p
= 1;
7742 while (it
->current_x
< max_x
)
7744 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7746 /* Get the next display element. */
7747 if (!get_next_display_element (it
))
7750 /* Produce glyphs. */
7751 x_before
= it
->current_x
;
7752 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7753 PRODUCE_GLYPHS (it
);
7755 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7760 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7762 if (x
+ glyph
->pixel_width
> max_x
)
7764 /* Glyph doesn't fit on line. */
7765 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7771 x
+= glyph
->pixel_width
;
7775 /* Stop at line ends. */
7776 if (ITERATOR_AT_END_OF_LINE_P (it
))
7779 set_iterator_to_next (it
, 1);
7784 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7785 extend_face_to_end_of_line (it
);
7786 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7787 last
->right_box_line_p
= 1;
7788 if (last
== row
->glyphs
[TEXT_AREA
])
7789 last
->left_box_line_p
= 1;
7790 compute_line_metrics (it
);
7792 /* If line is empty, make it occupy the rest of the tool-bar. */
7793 if (!row
->displays_text_p
)
7795 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7796 row
->ascent
= row
->phys_ascent
= 0;
7799 row
->full_width_p
= 1;
7800 row
->continued_p
= 0;
7801 row
->truncated_on_left_p
= 0;
7802 row
->truncated_on_right_p
= 0;
7804 it
->current_x
= it
->hpos
= 0;
7805 it
->current_y
+= row
->height
;
7811 /* Value is the number of screen lines needed to make all tool-bar
7812 items of frame F visible. */
7815 tool_bar_lines_needed (f
)
7818 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7821 /* Initialize an iterator for iteration over
7822 F->desired_tool_bar_string in the tool-bar window of frame F. */
7823 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7824 it
.first_visible_x
= 0;
7825 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7826 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7828 while (!ITERATOR_AT_END_P (&it
))
7830 it
.glyph_row
= w
->desired_matrix
->rows
;
7831 clear_glyph_row (it
.glyph_row
);
7832 display_tool_bar_line (&it
);
7835 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7839 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7841 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
7850 frame
= selected_frame
;
7852 CHECK_FRAME (frame
);
7855 if (WINDOWP (f
->tool_bar_window
)
7856 || (w
= XWINDOW (f
->tool_bar_window
),
7857 XFASTINT (w
->height
) > 0))
7859 update_tool_bar (f
, 1);
7860 if (f
->n_tool_bar_items
)
7862 build_desired_tool_bar_string (f
);
7863 nlines
= tool_bar_lines_needed (f
);
7867 return make_number (nlines
);
7871 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7872 height should be changed. */
7875 redisplay_tool_bar (f
)
7880 struct glyph_row
*row
;
7881 int change_height_p
= 0;
7883 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7884 do anything. This means you must start with tool-bar-lines
7885 non-zero to get the auto-sizing effect. Or in other words, you
7886 can turn off tool-bars by specifying tool-bar-lines zero. */
7887 if (!WINDOWP (f
->tool_bar_window
)
7888 || (w
= XWINDOW (f
->tool_bar_window
),
7889 XFASTINT (w
->height
) == 0))
7892 /* Set up an iterator for the tool-bar window. */
7893 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7894 it
.first_visible_x
= 0;
7895 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7898 /* Build a string that represents the contents of the tool-bar. */
7899 build_desired_tool_bar_string (f
);
7900 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7902 /* Display as many lines as needed to display all tool-bar items. */
7903 while (it
.current_y
< it
.last_visible_y
)
7904 display_tool_bar_line (&it
);
7906 /* It doesn't make much sense to try scrolling in the tool-bar
7907 window, so don't do it. */
7908 w
->desired_matrix
->no_scrolling_p
= 1;
7909 w
->must_be_updated_p
= 1;
7911 if (auto_resize_tool_bars_p
)
7915 /* If we couldn't display everything, change the tool-bar's
7917 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7918 change_height_p
= 1;
7920 /* If there are blank lines at the end, except for a partially
7921 visible blank line at the end that is smaller than
7922 CANON_Y_UNIT, change the tool-bar's height. */
7923 row
= it
.glyph_row
- 1;
7924 if (!row
->displays_text_p
7925 && row
->height
>= CANON_Y_UNIT (f
))
7926 change_height_p
= 1;
7928 /* If row displays tool-bar items, but is partially visible,
7929 change the tool-bar's height. */
7930 if (row
->displays_text_p
7931 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7932 change_height_p
= 1;
7934 /* Resize windows as needed by changing the `tool-bar-lines'
7937 && (nlines
= tool_bar_lines_needed (f
),
7938 nlines
!= XFASTINT (w
->height
)))
7940 extern Lisp_Object Qtool_bar_lines
;
7942 int old_height
= XFASTINT (w
->height
);
7944 XSETFRAME (frame
, f
);
7945 clear_glyph_matrix (w
->desired_matrix
);
7946 Fmodify_frame_parameters (frame
,
7947 Fcons (Fcons (Qtool_bar_lines
,
7948 make_number (nlines
)),
7950 if (XFASTINT (w
->height
) != old_height
)
7951 fonts_changed_p
= 1;
7955 return change_height_p
;
7959 /* Get information about the tool-bar item which is displayed in GLYPH
7960 on frame F. Return in *PROP_IDX the index where tool-bar item
7961 properties start in F->tool_bar_items. Value is zero if
7962 GLYPH doesn't display a tool-bar item. */
7965 tool_bar_item_info (f
, glyph
, prop_idx
)
7967 struct glyph
*glyph
;
7974 /* This function can be called asynchronously, which means we must
7975 exclude any possibility that Fget_text_property signals an
7977 charpos
= min (XSTRING (f
->current_tool_bar_string
)->size
, glyph
->charpos
);
7978 charpos
= max (0, charpos
);
7980 /* Get the text property `menu-item' at pos. The value of that
7981 property is the start index of this item's properties in
7982 F->tool_bar_items. */
7983 prop
= Fget_text_property (make_number (charpos
),
7984 Qmenu_item
, f
->current_tool_bar_string
);
7985 if (INTEGERP (prop
))
7987 *prop_idx
= XINT (prop
);
7996 #endif /* HAVE_WINDOW_SYSTEM */
8000 /************************************************************************
8001 Horizontal scrolling
8002 ************************************************************************/
8004 static int hscroll_window_tree
P_ ((Lisp_Object
));
8005 static int hscroll_windows
P_ ((Lisp_Object
));
8007 /* For all leaf windows in the window tree rooted at WINDOW, set their
8008 hscroll value so that PT is (i) visible in the window, and (ii) so
8009 that it is not within a certain margin at the window's left and
8010 right border. Value is non-zero if any window's hscroll has been
8014 hscroll_window_tree (window
)
8017 int hscrolled_p
= 0;
8019 while (WINDOWP (window
))
8021 struct window
*w
= XWINDOW (window
);
8023 if (WINDOWP (w
->hchild
))
8024 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
8025 else if (WINDOWP (w
->vchild
))
8026 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
8027 else if (w
->cursor
.vpos
>= 0)
8029 int hscroll_margin
, text_area_x
, text_area_y
;
8030 int text_area_width
, text_area_height
;
8031 struct glyph_row
*current_cursor_row
8032 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
8033 struct glyph_row
*desired_cursor_row
8034 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
8035 struct glyph_row
*cursor_row
8036 = (desired_cursor_row
->enabled_p
8037 ? desired_cursor_row
8038 : current_cursor_row
);
8040 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8041 &text_area_width
, &text_area_height
);
8043 /* Scroll when cursor is inside this scroll margin. */
8044 /* Shouldn't we export this `5' for customization ? -stef */
8045 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
8047 if ((XFASTINT (w
->hscroll
)
8048 && w
->cursor
.x
< hscroll_margin
)
8049 || (cursor_row
->enabled_p
8050 && cursor_row
->truncated_on_right_p
8051 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
8055 struct buffer
*saved_current_buffer
;
8058 /* Find point in a display of infinite width. */
8059 saved_current_buffer
= current_buffer
;
8060 current_buffer
= XBUFFER (w
->buffer
);
8062 if (w
== XWINDOW (selected_window
))
8063 pt
= BUF_PT (current_buffer
);
8066 pt
= marker_position (w
->pointm
);
8067 pt
= max (BEGV
, pt
);
8071 /* Move iterator to pt starting at cursor_row->start in
8072 a line with infinite width. */
8073 init_to_row_start (&it
, w
, cursor_row
);
8074 it
.last_visible_x
= INFINITY
;
8075 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8076 current_buffer
= saved_current_buffer
;
8078 /* Center cursor in window. */
8079 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
8080 / CANON_X_UNIT (it
.f
));
8081 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8083 /* Don't call Fset_window_hscroll if value hasn't
8084 changed because it will prevent redisplay
8086 if (XFASTINT (w
->hscroll
) != hscroll
)
8088 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8089 w
->hscroll
= make_number (hscroll
);
8098 /* Value is non-zero if hscroll of any leaf window has been changed. */
8103 /* Set hscroll so that cursor is visible and not inside horizontal
8104 scroll margins for all windows in the tree rooted at WINDOW. See
8105 also hscroll_window_tree above. Value is non-zero if any window's
8106 hscroll has been changed. If it has, desired matrices on the frame
8107 of WINDOW are cleared. */
8110 hscroll_windows (window
)
8115 if (automatic_hscrolling_p
)
8117 hscrolled_p
= hscroll_window_tree (window
);
8119 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8128 /************************************************************************
8130 ************************************************************************/
8132 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8133 to a non-zero value. This is sometimes handy to have in a debugger
8138 /* First and last unchanged row for try_window_id. */
8140 int debug_first_unchanged_at_end_vpos
;
8141 int debug_last_unchanged_at_beg_vpos
;
8143 /* Delta vpos and y. */
8145 int debug_dvpos
, debug_dy
;
8147 /* Delta in characters and bytes for try_window_id. */
8149 int debug_delta
, debug_delta_bytes
;
8151 /* Values of window_end_pos and window_end_vpos at the end of
8154 int debug_end_pos
, debug_end_vpos
;
8156 /* Append a string to W->desired_matrix->method. FMT is a printf
8157 format string. A1...A9 are a supplement for a variable-length
8158 argument list. If trace_redisplay_p is non-zero also printf the
8159 resulting string to stderr. */
8162 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8165 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8168 char *method
= w
->desired_matrix
->method
;
8169 int len
= strlen (method
);
8170 int size
= sizeof w
->desired_matrix
->method
;
8171 int remaining
= size
- len
- 1;
8173 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8174 if (len
&& remaining
)
8180 strncpy (method
+ len
, buffer
, remaining
);
8182 if (trace_redisplay_p
)
8183 fprintf (stderr
, "%p (%s): %s\n",
8185 ((BUFFERP (w
->buffer
)
8186 && STRINGP (XBUFFER (w
->buffer
)->name
))
8187 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
8192 #endif /* GLYPH_DEBUG */
8195 /* This counter is used to clear the face cache every once in a while
8196 in redisplay_internal. It is incremented for each redisplay.
8197 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8200 #define CLEAR_FACE_CACHE_COUNT 500
8201 static int clear_face_cache_count
;
8203 /* Record the previous terminal frame we displayed. */
8205 static struct frame
*previous_terminal_frame
;
8207 /* Non-zero while redisplay_internal is in progress. */
8212 /* Value is non-zero if all changes in window W, which displays
8213 current_buffer, are in the text between START and END. START is a
8214 buffer position, END is given as a distance from Z. Used in
8215 redisplay_internal for display optimization. */
8218 text_outside_line_unchanged_p (w
, start
, end
)
8222 int unchanged_p
= 1;
8224 /* If text or overlays have changed, see where. */
8225 if (XFASTINT (w
->last_modified
) < MODIFF
8226 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8228 /* Gap in the line? */
8229 if (GPT
< start
|| Z
- GPT
< end
)
8232 /* Changes start in front of the line, or end after it? */
8234 && (BEG_UNCHANGED
< start
- 1
8235 || END_UNCHANGED
< end
))
8238 /* If selective display, can't optimize if changes start at the
8239 beginning of the line. */
8241 && INTEGERP (current_buffer
->selective_display
)
8242 && XINT (current_buffer
->selective_display
) > 0
8243 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8246 /* If there are overlays at the start or end of the line, these
8247 may have overlay strings with newlines in them. A change at
8248 START, for instance, may actually concern the display of such
8249 overlay strings as well, and they are displayed on different
8250 lines. So, quickly rule out this case. (For the future, it
8251 might be desirable to implement something more telling than
8252 just BEG/END_UNCHANGED.) */
8255 if (BEG
+ BEG_UNCHANGED
== start
8256 && overlay_touches_p (start
))
8258 if (END_UNCHANGED
== end
8259 && overlay_touches_p (Z
- end
))
8268 /* Do a frame update, taking possible shortcuts into account. This is
8269 the main external entry point for redisplay.
8271 If the last redisplay displayed an echo area message and that message
8272 is no longer requested, we clear the echo area or bring back the
8273 mini-buffer if that is in use. */
8278 redisplay_internal (0);
8282 /* Return 1 if point moved out of or into a composition. Otherwise
8283 return 0. PREV_BUF and PREV_PT are the last point buffer and
8284 position. BUF and PT are the current point buffer and position. */
8287 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8288 struct buffer
*prev_buf
, *buf
;
8295 XSETBUFFER (buffer
, buf
);
8296 /* Check a composition at the last point if point moved within the
8298 if (prev_buf
== buf
)
8301 /* Point didn't move. */
8304 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8305 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8306 && COMPOSITION_VALID_P (start
, end
, prop
)
8307 && start
< prev_pt
&& end
> prev_pt
)
8308 /* The last point was within the composition. Return 1 iff
8309 point moved out of the composition. */
8310 return (pt
<= start
|| pt
>= end
);
8313 /* Check a composition at the current point. */
8314 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8315 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8316 && COMPOSITION_VALID_P (start
, end
, prop
)
8317 && start
< pt
&& end
> pt
);
8321 /* Reconsider the setting of B->clip_changed which is displayed
8325 reconsider_clip_changes (w
, b
)
8329 if (b
->prevent_redisplay_optimizations_p
)
8330 b
->clip_changed
= 1;
8331 else if (b
->clip_changed
8332 && !NILP (w
->window_end_valid
)
8333 && w
->current_matrix
->buffer
== b
8334 && w
->current_matrix
->zv
== BUF_ZV (b
)
8335 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8336 b
->clip_changed
= 0;
8338 /* If display wasn't paused, and W is not a tool bar window, see if
8339 point has been moved into or out of a composition. In that case,
8340 we set b->clip_changed to 1 to force updating the screen. If
8341 b->clip_changed has already been set to 1, we can skip this
8343 if (!b
->clip_changed
8344 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8348 if (w
== XWINDOW (selected_window
))
8349 pt
= BUF_PT (current_buffer
);
8351 pt
= marker_position (w
->pointm
);
8353 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8354 || pt
!= XINT (w
->last_point
))
8355 && check_point_in_composition (w
->current_matrix
->buffer
,
8356 XINT (w
->last_point
),
8357 XBUFFER (w
->buffer
), pt
))
8358 b
->clip_changed
= 1;
8363 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8364 response to any user action; therefore, we should preserve the echo
8365 area. (Actually, our caller does that job.) Perhaps in the future
8366 avoid recentering windows if it is not necessary; currently that
8367 causes some problems. */
8370 redisplay_internal (preserve_echo_area
)
8371 int preserve_echo_area
;
8373 struct window
*w
= XWINDOW (selected_window
);
8374 struct frame
*f
= XFRAME (w
->frame
);
8376 int must_finish
= 0;
8377 struct text_pos tlbufpos
, tlendpos
;
8378 int number_of_visible_frames
;
8380 struct frame
*sf
= SELECTED_FRAME ();
8382 /* Non-zero means redisplay has to consider all windows on all
8383 frames. Zero means, only selected_window is considered. */
8384 int consider_all_windows_p
;
8386 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8388 /* No redisplay if running in batch mode or frame is not yet fully
8389 initialized, or redisplay is explicitly turned off by setting
8390 Vinhibit_redisplay. */
8392 || !NILP (Vinhibit_redisplay
)
8393 || !f
->glyphs_initialized_p
)
8396 /* The flag redisplay_performed_directly_p is set by
8397 direct_output_for_insert when it already did the whole screen
8398 update necessary. */
8399 if (redisplay_performed_directly_p
)
8401 redisplay_performed_directly_p
= 0;
8402 if (!hscroll_windows (selected_window
))
8406 #ifdef USE_X_TOOLKIT
8407 if (popup_activated ())
8411 /* I don't think this happens but let's be paranoid. */
8415 /* Record a function that resets redisplaying_p to its old value
8416 when we leave this function. */
8417 count
= BINDING_STACK_SIZE ();
8418 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8423 reconsider_clip_changes (w
, current_buffer
);
8425 /* If new fonts have been loaded that make a glyph matrix adjustment
8426 necessary, do it. */
8427 if (fonts_changed_p
)
8429 adjust_glyphs (NULL
);
8430 ++windows_or_buffers_changed
;
8431 fonts_changed_p
= 0;
8434 /* If face_change_count is non-zero, init_iterator will free all
8435 realized faces, which includes the faces referenced from current
8436 matrices. So, we can't reuse current matrices in this case. */
8437 if (face_change_count
)
8438 ++windows_or_buffers_changed
;
8440 if (! FRAME_WINDOW_P (sf
)
8441 && previous_terminal_frame
!= sf
)
8443 /* Since frames on an ASCII terminal share the same display
8444 area, displaying a different frame means redisplay the whole
8446 windows_or_buffers_changed
++;
8447 SET_FRAME_GARBAGED (sf
);
8448 XSETFRAME (Vterminal_frame
, sf
);
8450 previous_terminal_frame
= sf
;
8452 /* Set the visible flags for all frames. Do this before checking
8453 for resized or garbaged frames; they want to know if their frames
8454 are visible. See the comment in frame.h for
8455 FRAME_SAMPLE_VISIBILITY. */
8457 Lisp_Object tail
, frame
;
8459 number_of_visible_frames
= 0;
8461 FOR_EACH_FRAME (tail
, frame
)
8463 struct frame
*f
= XFRAME (frame
);
8465 FRAME_SAMPLE_VISIBILITY (f
);
8466 if (FRAME_VISIBLE_P (f
))
8467 ++number_of_visible_frames
;
8468 clear_desired_matrices (f
);
8472 /* Notice any pending interrupt request to change frame size. */
8473 do_pending_window_change (1);
8475 /* Clear frames marked as garbaged. */
8477 clear_garbaged_frames ();
8479 /* Build menubar and tool-bar items. */
8480 prepare_menu_bars ();
8482 if (windows_or_buffers_changed
)
8483 update_mode_lines
++;
8485 /* Detect case that we need to write or remove a star in the mode line. */
8486 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8488 w
->update_mode_line
= Qt
;
8489 if (buffer_shared
> 1)
8490 update_mode_lines
++;
8493 /* If %c is in the mode line, update it if needed. */
8494 if (!NILP (w
->column_number_displayed
)
8495 /* This alternative quickly identifies a common case
8496 where no change is needed. */
8497 && !(PT
== XFASTINT (w
->last_point
)
8498 && XFASTINT (w
->last_modified
) >= MODIFF
8499 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8500 && XFASTINT (w
->column_number_displayed
) != current_column ())
8501 w
->update_mode_line
= Qt
;
8503 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8505 /* The variable buffer_shared is set in redisplay_window and
8506 indicates that we redisplay a buffer in different windows. See
8508 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8510 /* If specs for an arrow have changed, do thorough redisplay
8511 to ensure we remove any arrow that should no longer exist. */
8512 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8513 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8514 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8516 /* Normally the message* functions will have already displayed and
8517 updated the echo area, but the frame may have been trashed, or
8518 the update may have been preempted, so display the echo area
8519 again here. Checking message_cleared_p captures the case that
8520 the echo area should be cleared. */
8521 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8522 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8523 || (message_cleared_p
8524 && minibuf_level
== 0
8525 /* If the mini-window is currently selected, this means the
8526 echo-area doesn't show through. */
8527 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8529 int window_height_changed_p
= echo_area_display (0);
8532 /* If we don't display the current message, don't clear the
8533 message_cleared_p flag, because, if we did, we wouldn't clear
8534 the echo area in the next redisplay which doesn't preserve
8536 if (!display_last_displayed_message_p
)
8537 message_cleared_p
= 0;
8539 if (fonts_changed_p
)
8541 else if (window_height_changed_p
)
8543 consider_all_windows_p
= 1;
8544 ++update_mode_lines
;
8545 ++windows_or_buffers_changed
;
8547 /* If window configuration was changed, frames may have been
8548 marked garbaged. Clear them or we will experience
8549 surprises wrt scrolling. */
8551 clear_garbaged_frames ();
8554 else if (EQ (selected_window
, minibuf_window
)
8555 && (current_buffer
->clip_changed
8556 || XFASTINT (w
->last_modified
) < MODIFF
8557 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8558 && resize_mini_window (w
, 0))
8560 /* Resized active mini-window to fit the size of what it is
8561 showing if its contents might have changed. */
8563 consider_all_windows_p
= 1;
8564 ++windows_or_buffers_changed
;
8565 ++update_mode_lines
;
8567 /* If window configuration was changed, frames may have been
8568 marked garbaged. Clear them or we will experience
8569 surprises wrt scrolling. */
8571 clear_garbaged_frames ();
8575 /* If showing the region, and mark has changed, we must redisplay
8576 the whole window. The assignment to this_line_start_pos prevents
8577 the optimization directly below this if-statement. */
8578 if (((!NILP (Vtransient_mark_mode
)
8579 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8580 != !NILP (w
->region_showing
))
8581 || (!NILP (w
->region_showing
)
8582 && !EQ (w
->region_showing
,
8583 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8584 CHARPOS (this_line_start_pos
) = 0;
8586 /* Optimize the case that only the line containing the cursor in the
8587 selected window has changed. Variables starting with this_ are
8588 set in display_line and record information about the line
8589 containing the cursor. */
8590 tlbufpos
= this_line_start_pos
;
8591 tlendpos
= this_line_end_pos
;
8592 if (!consider_all_windows_p
8593 && CHARPOS (tlbufpos
) > 0
8594 && NILP (w
->update_mode_line
)
8595 && !current_buffer
->clip_changed
8596 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8597 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8598 /* Make sure recorded data applies to current buffer, etc. */
8599 && this_line_buffer
== current_buffer
8600 && current_buffer
== XBUFFER (w
->buffer
)
8601 && NILP (w
->force_start
)
8602 /* Point must be on the line that we have info recorded about. */
8603 && PT
>= CHARPOS (tlbufpos
)
8604 && PT
<= Z
- CHARPOS (tlendpos
)
8605 /* All text outside that line, including its final newline,
8606 must be unchanged */
8607 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8608 CHARPOS (tlendpos
)))
8610 if (CHARPOS (tlbufpos
) > BEGV
8611 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8612 && (CHARPOS (tlbufpos
) == ZV
8613 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8614 /* Former continuation line has disappeared by becoming empty */
8616 else if (XFASTINT (w
->last_modified
) < MODIFF
8617 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8618 || MINI_WINDOW_P (w
))
8620 /* We have to handle the case of continuation around a
8621 wide-column character (See the comment in indent.c around
8624 For instance, in the following case:
8626 -------- Insert --------
8627 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8628 J_I_ ==> J_I_ `^^' are cursors.
8632 As we have to redraw the line above, we should goto cancel. */
8635 int line_height_before
= this_line_pixel_height
;
8637 /* Note that start_display will handle the case that the
8638 line starting at tlbufpos is a continuation lines. */
8639 start_display (&it
, w
, tlbufpos
);
8641 /* Implementation note: It this still necessary? */
8642 if (it
.current_x
!= this_line_start_x
)
8645 TRACE ((stderr
, "trying display optimization 1\n"));
8646 w
->cursor
.vpos
= -1;
8647 overlay_arrow_seen
= 0;
8648 it
.vpos
= this_line_vpos
;
8649 it
.current_y
= this_line_y
;
8650 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8653 /* If line contains point, is not continued,
8654 and ends at same distance from eob as before, we win */
8655 if (w
->cursor
.vpos
>= 0
8656 /* Line is not continued, otherwise this_line_start_pos
8657 would have been set to 0 in display_line. */
8658 && CHARPOS (this_line_start_pos
)
8659 /* Line ends as before. */
8660 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8661 /* Line has same height as before. Otherwise other lines
8662 would have to be shifted up or down. */
8663 && this_line_pixel_height
== line_height_before
)
8665 /* If this is not the window's last line, we must adjust
8666 the charstarts of the lines below. */
8667 if (it
.current_y
< it
.last_visible_y
)
8669 struct glyph_row
*row
8670 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8671 int delta
, delta_bytes
;
8673 if (Z
- CHARPOS (tlendpos
) == ZV
)
8675 /* This line ends at end of (accessible part of)
8676 buffer. There is no newline to count. */
8678 - CHARPOS (tlendpos
)
8679 - MATRIX_ROW_START_CHARPOS (row
));
8680 delta_bytes
= (Z_BYTE
8681 - BYTEPOS (tlendpos
)
8682 - MATRIX_ROW_START_BYTEPOS (row
));
8686 /* This line ends in a newline. Must take
8687 account of the newline and the rest of the
8688 text that follows. */
8690 - CHARPOS (tlendpos
)
8691 - MATRIX_ROW_START_CHARPOS (row
));
8692 delta_bytes
= (Z_BYTE
8693 - BYTEPOS (tlendpos
)
8694 - MATRIX_ROW_START_BYTEPOS (row
));
8697 increment_matrix_positions (w
->current_matrix
,
8699 w
->current_matrix
->nrows
,
8700 delta
, delta_bytes
);
8703 /* If this row displays text now but previously didn't,
8704 or vice versa, w->window_end_vpos may have to be
8706 if ((it
.glyph_row
- 1)->displays_text_p
)
8708 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8709 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8711 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8712 && this_line_vpos
> 0)
8713 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8714 w
->window_end_valid
= Qnil
;
8716 /* Update hint: No need to try to scroll in update_window. */
8717 w
->desired_matrix
->no_scrolling_p
= 1;
8720 *w
->desired_matrix
->method
= 0;
8721 debug_method_add (w
, "optimization 1");
8728 else if (/* Cursor position hasn't changed. */
8729 PT
== XFASTINT (w
->last_point
)
8730 /* Make sure the cursor was last displayed
8731 in this window. Otherwise we have to reposition it. */
8732 && 0 <= w
->cursor
.vpos
8733 && XINT (w
->height
) > w
->cursor
.vpos
)
8737 do_pending_window_change (1);
8739 /* We used to always goto end_of_redisplay here, but this
8740 isn't enough if we have a blinking cursor. */
8741 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8742 goto end_of_redisplay
;
8746 /* If highlighting the region, or if the cursor is in the echo area,
8747 then we can't just move the cursor. */
8748 else if (! (!NILP (Vtransient_mark_mode
)
8749 && !NILP (current_buffer
->mark_active
))
8750 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8751 || highlight_nonselected_windows
)
8752 && NILP (w
->region_showing
)
8753 && NILP (Vshow_trailing_whitespace
)
8754 && !cursor_in_echo_area
)
8757 struct glyph_row
*row
;
8759 /* Skip from tlbufpos to PT and see where it is. Note that
8760 PT may be in invisible text. If so, we will end at the
8761 next visible position. */
8762 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8763 NULL
, DEFAULT_FACE_ID
);
8764 it
.current_x
= this_line_start_x
;
8765 it
.current_y
= this_line_y
;
8766 it
.vpos
= this_line_vpos
;
8768 /* The call to move_it_to stops in front of PT, but
8769 moves over before-strings. */
8770 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8772 if (it
.vpos
== this_line_vpos
8773 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8776 xassert (this_line_vpos
== it
.vpos
);
8777 xassert (this_line_y
== it
.current_y
);
8778 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8780 *w
->desired_matrix
->method
= 0;
8781 debug_method_add (w
, "optimization 3");
8790 /* Text changed drastically or point moved off of line. */
8791 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8794 CHARPOS (this_line_start_pos
) = 0;
8795 consider_all_windows_p
|= buffer_shared
> 1;
8796 ++clear_face_cache_count
;
8799 /* Build desired matrices, and update the display. If
8800 consider_all_windows_p is non-zero, do it for all windows on all
8801 frames. Otherwise do it for selected_window, only. */
8803 if (consider_all_windows_p
)
8805 Lisp_Object tail
, frame
;
8806 int i
, n
= 0, size
= 50;
8807 struct frame
**updated
8808 = (struct frame
**) alloca (size
* sizeof *updated
);
8810 /* Clear the face cache eventually. */
8811 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8813 clear_face_cache (0);
8814 clear_face_cache_count
= 0;
8817 /* Recompute # windows showing selected buffer. This will be
8818 incremented each time such a window is displayed. */
8821 FOR_EACH_FRAME (tail
, frame
)
8823 struct frame
*f
= XFRAME (frame
);
8825 if (FRAME_WINDOW_P (f
) || f
== sf
)
8827 if (clear_face_cache_count
% 50 == 0
8828 && FRAME_WINDOW_P (f
))
8829 clear_image_cache (f
, 0);
8831 /* Mark all the scroll bars to be removed; we'll redeem
8832 the ones we want when we redisplay their windows. */
8833 if (condemn_scroll_bars_hook
)
8834 condemn_scroll_bars_hook (f
);
8836 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8837 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8839 /* Any scroll bars which redisplay_windows should have
8840 nuked should now go away. */
8841 if (judge_scroll_bars_hook
)
8842 judge_scroll_bars_hook (f
);
8844 /* If fonts changed, display again. */
8845 if (fonts_changed_p
)
8848 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8850 /* See if we have to hscroll. */
8851 if (hscroll_windows (f
->root_window
))
8854 /* Prevent various kinds of signals during display
8855 update. stdio is not robust about handling
8856 signals, which can cause an apparent I/O
8858 if (interrupt_input
)
8862 /* Update the display. */
8863 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8864 pause
|= update_frame (f
, 0, 0);
8870 int nbytes
= size
* sizeof *updated
;
8871 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8872 bcopy (updated
, p
, nbytes
);
8881 /* Do the mark_window_display_accurate after all windows have
8882 been redisplayed because this call resets flags in buffers
8883 which are needed for proper redisplay. */
8884 for (i
= 0; i
< n
; ++i
)
8886 struct frame
*f
= updated
[i
];
8887 mark_window_display_accurate (f
->root_window
, 1);
8888 if (frame_up_to_date_hook
)
8889 frame_up_to_date_hook (f
);
8892 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8894 Lisp_Object mini_window
;
8895 struct frame
*mini_frame
;
8897 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
8898 internal_condition_case_1 (redisplay_window_1
, selected_window
, Qerror
,
8899 redisplay_window_error
);
8901 /* Compare desired and current matrices, perform output. */
8904 /* If fonts changed, display again. */
8905 if (fonts_changed_p
)
8908 /* Prevent various kinds of signals during display update.
8909 stdio is not robust about handling signals,
8910 which can cause an apparent I/O error. */
8911 if (interrupt_input
)
8915 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8917 if (hscroll_windows (selected_window
))
8920 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8921 pause
= update_frame (sf
, 0, 0);
8924 /* We may have called echo_area_display at the top of this
8925 function. If the echo area is on another frame, that may
8926 have put text on a frame other than the selected one, so the
8927 above call to update_frame would not have caught it. Catch
8929 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8930 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8932 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8934 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8935 pause
|= update_frame (mini_frame
, 0, 0);
8936 if (!pause
&& hscroll_windows (mini_window
))
8941 /* If display was paused because of pending input, make sure we do a
8942 thorough update the next time. */
8945 /* Prevent the optimization at the beginning of
8946 redisplay_internal that tries a single-line update of the
8947 line containing the cursor in the selected window. */
8948 CHARPOS (this_line_start_pos
) = 0;
8950 /* Let the overlay arrow be updated the next time. */
8951 if (!NILP (last_arrow_position
))
8953 last_arrow_position
= Qt
;
8954 last_arrow_string
= Qt
;
8957 /* If we pause after scrolling, some rows in the current
8958 matrices of some windows are not valid. */
8959 if (!WINDOW_FULL_WIDTH_P (w
)
8960 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8961 update_mode_lines
= 1;
8965 if (!consider_all_windows_p
)
8967 /* This has already been done above if
8968 consider_all_windows_p is set. */
8969 mark_window_display_accurate_1 (w
, 1);
8971 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8972 last_arrow_string
= Voverlay_arrow_string
;
8974 if (frame_up_to_date_hook
!= 0)
8975 frame_up_to_date_hook (sf
);
8978 update_mode_lines
= 0;
8979 windows_or_buffers_changed
= 0;
8982 /* Start SIGIO interrupts coming again. Having them off during the
8983 code above makes it less likely one will discard output, but not
8984 impossible, since there might be stuff in the system buffer here.
8985 But it is much hairier to try to do anything about that. */
8986 if (interrupt_input
)
8990 /* If a frame has become visible which was not before, redisplay
8991 again, so that we display it. Expose events for such a frame
8992 (which it gets when becoming visible) don't call the parts of
8993 redisplay constructing glyphs, so simply exposing a frame won't
8994 display anything in this case. So, we have to display these
8995 frames here explicitly. */
8998 Lisp_Object tail
, frame
;
9001 FOR_EACH_FRAME (tail
, frame
)
9003 int this_is_visible
= 0;
9005 if (XFRAME (frame
)->visible
)
9006 this_is_visible
= 1;
9007 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
9008 if (XFRAME (frame
)->visible
)
9009 this_is_visible
= 1;
9011 if (this_is_visible
)
9015 if (new_count
!= number_of_visible_frames
)
9016 windows_or_buffers_changed
++;
9019 /* Change frame size now if a change is pending. */
9020 do_pending_window_change (1);
9022 /* If we just did a pending size change, or have additional
9023 visible frames, redisplay again. */
9024 if (windows_or_buffers_changed
&& !pause
)
9029 unbind_to (count
, Qnil
);
9033 /* Redisplay, but leave alone any recent echo area message unless
9034 another message has been requested in its place.
9036 This is useful in situations where you need to redisplay but no
9037 user action has occurred, making it inappropriate for the message
9038 area to be cleared. See tracking_off and
9039 wait_reading_process_input for examples of these situations.
9041 FROM_WHERE is an integer saying from where this function was
9042 called. This is useful for debugging. */
9045 redisplay_preserve_echo_area (from_where
)
9048 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9050 if (!NILP (echo_area_buffer
[1]))
9052 /* We have a previously displayed message, but no current
9053 message. Redisplay the previous message. */
9054 display_last_displayed_message_p
= 1;
9055 redisplay_internal (1);
9056 display_last_displayed_message_p
= 0;
9059 redisplay_internal (1);
9063 /* Function registered with record_unwind_protect in
9064 redisplay_internal. Clears the flag indicating that a redisplay is
9068 unwind_redisplay (old_redisplaying_p
)
9069 Lisp_Object old_redisplaying_p
;
9071 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9076 /* Mark the display of window W as accurate or inaccurate. If
9077 ACCURATE_P is non-zero mark display of W as accurate. If
9078 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9079 redisplay_internal is called. */
9082 mark_window_display_accurate_1 (w
, accurate_p
)
9086 if (BUFFERP (w
->buffer
))
9088 struct buffer
*b
= XBUFFER (w
->buffer
);
9091 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9092 w
->last_overlay_modified
9093 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9095 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9099 b
->clip_changed
= 0;
9100 b
->prevent_redisplay_optimizations_p
= 0;
9102 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9103 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9104 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9105 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9107 w
->current_matrix
->buffer
= b
;
9108 w
->current_matrix
->begv
= BUF_BEGV (b
);
9109 w
->current_matrix
->zv
= BUF_ZV (b
);
9111 w
->last_cursor
= w
->cursor
;
9112 w
->last_cursor_off_p
= w
->cursor_off_p
;
9114 if (w
== XWINDOW (selected_window
))
9115 w
->last_point
= make_number (BUF_PT (b
));
9117 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9123 w
->window_end_valid
= w
->buffer
;
9124 #if 0 /* This is incorrect with variable-height lines. */
9125 xassert (XINT (w
->window_end_vpos
)
9127 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9129 w
->update_mode_line
= Qnil
;
9134 /* Mark the display of windows in the window tree rooted at WINDOW as
9135 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9136 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9137 be redisplayed the next time redisplay_internal is called. */
9140 mark_window_display_accurate (window
, accurate_p
)
9146 for (; !NILP (window
); window
= w
->next
)
9148 w
= XWINDOW (window
);
9149 mark_window_display_accurate_1 (w
, accurate_p
);
9151 if (!NILP (w
->vchild
))
9152 mark_window_display_accurate (w
->vchild
, accurate_p
);
9153 if (!NILP (w
->hchild
))
9154 mark_window_display_accurate (w
->hchild
, accurate_p
);
9159 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9160 last_arrow_string
= Voverlay_arrow_string
;
9164 /* Force a thorough redisplay the next time by setting
9165 last_arrow_position and last_arrow_string to t, which is
9166 unequal to any useful value of Voverlay_arrow_... */
9167 last_arrow_position
= Qt
;
9168 last_arrow_string
= Qt
;
9173 /* Return value in display table DP (Lisp_Char_Table *) for character
9174 C. Since a display table doesn't have any parent, we don't have to
9175 follow parent. Do not call this function directly but use the
9176 macro DISP_CHAR_VECTOR. */
9179 disp_char_vector (dp
, c
)
9180 struct Lisp_Char_Table
*dp
;
9186 if (SINGLE_BYTE_CHAR_P (c
))
9187 return (dp
->contents
[c
]);
9189 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9192 else if (code
[2] < 32)
9195 /* Here, the possible range of code[0] (== charset ID) is
9196 128..max_charset. Since the top level char table contains data
9197 for multibyte characters after 256th element, we must increment
9198 code[0] by 128 to get a correct index. */
9200 code
[3] = -1; /* anchor */
9202 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9204 val
= dp
->contents
[code
[i
]];
9205 if (!SUB_CHAR_TABLE_P (val
))
9206 return (NILP (val
) ? dp
->defalt
: val
);
9209 /* Here, val is a sub char table. We return the default value of
9211 return (dp
->defalt
);
9216 /***********************************************************************
9218 ***********************************************************************/
9220 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9223 redisplay_windows (window
)
9226 while (!NILP (window
))
9228 struct window
*w
= XWINDOW (window
);
9230 if (!NILP (w
->hchild
))
9231 redisplay_windows (w
->hchild
);
9232 else if (!NILP (w
->vchild
))
9233 redisplay_windows (w
->vchild
);
9236 displayed_buffer
= XBUFFER (w
->buffer
);
9237 internal_condition_case_1 (redisplay_window_0
, window
, Qerror
,
9238 redisplay_window_error
);
9246 redisplay_window_error ()
9248 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
9253 redisplay_window_0 (window
)
9256 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9257 redisplay_window (window
, 0);
9262 redisplay_window_1 (window
)
9265 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9266 redisplay_window (window
, 1);
9270 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9271 DELTA is the number of bytes by which positions recorded in ROW
9272 differ from current buffer positions. */
9275 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9277 struct glyph_row
*row
;
9278 struct glyph_matrix
*matrix
;
9279 int delta
, delta_bytes
, dy
, dvpos
;
9281 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9282 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9284 int pt_old
= PT
- delta
;
9286 /* Skip over glyphs not having an object at the start of the row.
9287 These are special glyphs like truncation marks on terminal
9289 if (row
->displays_text_p
)
9291 && INTEGERP (glyph
->object
)
9292 && glyph
->charpos
< 0)
9294 x
+= glyph
->pixel_width
;
9299 && !INTEGERP (glyph
->object
)
9300 && (!BUFFERP (glyph
->object
)
9301 || glyph
->charpos
< pt_old
))
9303 x
+= glyph
->pixel_width
;
9307 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9309 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9310 w
->cursor
.y
= row
->y
+ dy
;
9312 if (w
== XWINDOW (selected_window
))
9314 if (!row
->continued_p
9315 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9318 this_line_buffer
= XBUFFER (w
->buffer
);
9320 CHARPOS (this_line_start_pos
)
9321 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9322 BYTEPOS (this_line_start_pos
)
9323 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9325 CHARPOS (this_line_end_pos
)
9326 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9327 BYTEPOS (this_line_end_pos
)
9328 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9330 this_line_y
= w
->cursor
.y
;
9331 this_line_pixel_height
= row
->height
;
9332 this_line_vpos
= w
->cursor
.vpos
;
9333 this_line_start_x
= row
->x
;
9336 CHARPOS (this_line_start_pos
) = 0;
9341 /* Run window scroll functions, if any, for WINDOW with new window
9342 start STARTP. Sets the window start of WINDOW to that position.
9344 We assume that the window's buffer is really current. */
9346 static INLINE
struct text_pos
9347 run_window_scroll_functions (window
, startp
)
9349 struct text_pos startp
;
9351 struct window
*w
= XWINDOW (window
);
9352 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9354 if (current_buffer
!= XBUFFER (w
->buffer
))
9357 if (!NILP (Vwindow_scroll_functions
))
9359 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9360 make_number (CHARPOS (startp
)));
9361 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9362 /* In case the hook functions switch buffers. */
9363 if (current_buffer
!= XBUFFER (w
->buffer
))
9364 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9371 /* Modify the desired matrix of window W and W->vscroll so that the
9372 line containing the cursor is fully visible. If this requires
9373 larger matrices than are allocated, set fonts_changed_p and return
9377 make_cursor_line_fully_visible (w
)
9380 struct glyph_matrix
*matrix
;
9381 struct glyph_row
*row
;
9384 /* It's not always possible to find the cursor, e.g, when a window
9385 is full of overlay strings. Don't do anything in that case. */
9386 if (w
->cursor
.vpos
< 0)
9389 matrix
= w
->desired_matrix
;
9390 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9392 /* If the cursor row is not partially visible, there's nothing
9394 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9397 /* If the row the cursor is in is taller than the window's height,
9398 it's not clear what to do, so do nothing. */
9399 window_height
= window_box_height (w
);
9400 if (row
->height
>= window_height
)
9403 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9405 int dy
= row
->height
- row
->visible_height
;
9408 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9410 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9412 int dy
= - (row
->height
- row
->visible_height
);
9415 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9418 /* When we change the cursor y-position of the selected window,
9419 change this_line_y as well so that the display optimization for
9420 the cursor line of the selected window in redisplay_internal uses
9421 the correct y-position. */
9422 if (w
== XWINDOW (selected_window
))
9423 this_line_y
= w
->cursor
.y
;
9425 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9426 redisplay with larger matrices. */
9427 if (matrix
->nrows
< required_matrix_height (w
))
9429 fonts_changed_p
= 1;
9437 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9438 non-zero means only WINDOW is redisplayed in redisplay_internal.
9439 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9440 in redisplay_window to bring a partially visible line into view in
9441 the case that only the cursor has moved.
9445 1 if scrolling succeeded
9447 0 if scrolling didn't find point.
9449 -1 if new fonts have been loaded so that we must interrupt
9450 redisplay, adjust glyph matrices, and try again. */
9456 SCROLLING_NEED_LARGER_MATRICES
9460 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9461 scroll_step
, temp_scroll_step
)
9463 int just_this_one_p
;
9464 int scroll_conservatively
, scroll_step
;
9465 int temp_scroll_step
;
9467 struct window
*w
= XWINDOW (window
);
9468 struct frame
*f
= XFRAME (w
->frame
);
9469 struct text_pos scroll_margin_pos
;
9470 struct text_pos pos
;
9471 struct text_pos startp
;
9473 Lisp_Object window_end
;
9474 int this_scroll_margin
;
9478 int amount_to_scroll
= 0;
9479 Lisp_Object aggressive
;
9483 debug_method_add (w
, "try_scrolling");
9486 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9488 /* Compute scroll margin height in pixels. We scroll when point is
9489 within this distance from the top or bottom of the window. */
9490 if (scroll_margin
> 0)
9492 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9493 this_scroll_margin
*= CANON_Y_UNIT (f
);
9496 this_scroll_margin
= 0;
9498 /* Compute how much we should try to scroll maximally to bring point
9500 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9501 scroll_max
= max (scroll_step
,
9502 max (scroll_conservatively
, temp_scroll_step
));
9503 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9504 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9505 /* We're trying to scroll because of aggressive scrolling
9506 but no scroll_step is set. Choose an arbitrary one. Maybe
9507 there should be a variable for this. */
9511 scroll_max
*= CANON_Y_UNIT (f
);
9513 /* Decide whether we have to scroll down. Start at the window end
9514 and move this_scroll_margin up to find the position of the scroll
9516 window_end
= Fwindow_end (window
, Qt
);
9517 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9518 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9519 if (this_scroll_margin
)
9521 start_display (&it
, w
, scroll_margin_pos
);
9522 move_it_vertically (&it
, - this_scroll_margin
);
9523 scroll_margin_pos
= it
.current
.pos
;
9526 if (PT
>= CHARPOS (scroll_margin_pos
))
9530 /* Point is in the scroll margin at the bottom of the window, or
9531 below. Compute a new window start that makes point visible. */
9533 /* Compute the distance from the scroll margin to PT.
9534 Give up if the distance is greater than scroll_max. */
9535 start_display (&it
, w
, scroll_margin_pos
);
9537 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9538 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9540 /* To make point visible, we have to move the window start
9541 down so that the line the cursor is in is visible, which
9542 means we have to add in the height of the cursor line. */
9543 dy
= line_bottom_y (&it
) - y0
;
9545 if (dy
> scroll_max
)
9546 return SCROLLING_FAILED
;
9548 /* Move the window start down. If scrolling conservatively,
9549 move it just enough down to make point visible. If
9550 scroll_step is set, move it down by scroll_step. */
9551 start_display (&it
, w
, startp
);
9553 if (scroll_conservatively
)
9555 = max (max (dy
, CANON_Y_UNIT (f
)),
9556 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9557 else if (scroll_step
|| temp_scroll_step
)
9558 amount_to_scroll
= scroll_max
;
9561 aggressive
= current_buffer
->scroll_up_aggressively
;
9562 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9563 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9564 if (NUMBERP (aggressive
))
9565 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9568 if (amount_to_scroll
<= 0)
9569 return SCROLLING_FAILED
;
9571 move_it_vertically (&it
, amount_to_scroll
);
9572 startp
= it
.current
.pos
;
9576 /* See if point is inside the scroll margin at the top of the
9578 scroll_margin_pos
= startp
;
9579 if (this_scroll_margin
)
9581 start_display (&it
, w
, startp
);
9582 move_it_vertically (&it
, this_scroll_margin
);
9583 scroll_margin_pos
= it
.current
.pos
;
9586 if (PT
< CHARPOS (scroll_margin_pos
))
9588 /* Point is in the scroll margin at the top of the window or
9589 above what is displayed in the window. */
9592 /* Compute the vertical distance from PT to the scroll
9593 margin position. Give up if distance is greater than
9595 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9596 start_display (&it
, w
, pos
);
9598 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9599 it
.last_visible_y
, -1,
9600 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9601 dy
= it
.current_y
- y0
;
9602 if (dy
> scroll_max
)
9603 return SCROLLING_FAILED
;
9605 /* Compute new window start. */
9606 start_display (&it
, w
, startp
);
9608 if (scroll_conservatively
)
9610 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9611 else if (scroll_step
|| temp_scroll_step
)
9612 amount_to_scroll
= scroll_max
;
9615 aggressive
= current_buffer
->scroll_down_aggressively
;
9616 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9617 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9618 if (NUMBERP (aggressive
))
9619 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9622 if (amount_to_scroll
<= 0)
9623 return SCROLLING_FAILED
;
9625 move_it_vertically (&it
, - amount_to_scroll
);
9626 startp
= it
.current
.pos
;
9630 /* Run window scroll functions. */
9631 startp
= run_window_scroll_functions (window
, startp
);
9633 /* Display the window. Give up if new fonts are loaded, or if point
9635 if (!try_window (window
, startp
))
9636 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9637 else if (w
->cursor
.vpos
< 0)
9639 clear_glyph_matrix (w
->desired_matrix
);
9640 rc
= SCROLLING_FAILED
;
9644 /* Maybe forget recorded base line for line number display. */
9645 if (!just_this_one_p
9646 || current_buffer
->clip_changed
9647 || BEG_UNCHANGED
< CHARPOS (startp
))
9648 w
->base_line_number
= Qnil
;
9650 /* If cursor ends up on a partially visible line, shift display
9651 lines up or down. If that fails because we need larger
9652 matrices, give up. */
9653 if (!make_cursor_line_fully_visible (w
))
9654 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9656 rc
= SCROLLING_SUCCESS
;
9663 /* Compute a suitable window start for window W if display of W starts
9664 on a continuation line. Value is non-zero if a new window start
9667 The new window start will be computed, based on W's width, starting
9668 from the start of the continued line. It is the start of the
9669 screen line with the minimum distance from the old start W->start. */
9672 compute_window_start_on_continuation_line (w
)
9675 struct text_pos pos
, start_pos
;
9676 int window_start_changed_p
= 0;
9678 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9680 /* If window start is on a continuation line... Window start may be
9681 < BEGV in case there's invisible text at the start of the
9682 buffer (M-x rmail, for example). */
9683 if (CHARPOS (start_pos
) > BEGV
9684 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9687 struct glyph_row
*row
;
9689 /* Handle the case that the window start is out of range. */
9690 if (CHARPOS (start_pos
) < BEGV
)
9691 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9692 else if (CHARPOS (start_pos
) > ZV
)
9693 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9695 /* Find the start of the continued line. This should be fast
9696 because scan_buffer is fast (newline cache). */
9697 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9698 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9699 row
, DEFAULT_FACE_ID
);
9700 reseat_at_previous_visible_line_start (&it
);
9702 /* If the line start is "too far" away from the window start,
9703 say it takes too much time to compute a new window start. */
9704 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9705 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9707 int min_distance
, distance
;
9709 /* Move forward by display lines to find the new window
9710 start. If window width was enlarged, the new start can
9711 be expected to be > the old start. If window width was
9712 decreased, the new window start will be < the old start.
9713 So, we're looking for the display line start with the
9714 minimum distance from the old window start. */
9715 pos
= it
.current
.pos
;
9716 min_distance
= INFINITY
;
9717 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9718 distance
< min_distance
)
9720 min_distance
= distance
;
9721 pos
= it
.current
.pos
;
9722 move_it_by_lines (&it
, 1, 0);
9725 /* Set the window start there. */
9726 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9727 window_start_changed_p
= 1;
9731 return window_start_changed_p
;
9735 /* Try cursor movement in case text has not changes in window WINDOW,
9736 with window start STARTP. Value is
9738 CURSOR_MOVEMENT_SUCCESS if successful
9740 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
9742 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
9743 display. *SCROLL_STEP is set to 1, under certain circumstances, if
9744 we want to scroll as if scroll-step were set to 1. See the code.
9746 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
9747 which case we have to abort this redisplay, and adjust matrices
9752 CURSOR_MOVEMENT_SUCCESS
,
9753 CURSOR_MOVEMENT_CANNOT_BE_USED
,
9754 CURSOR_MOVEMENT_MUST_SCROLL
,
9755 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
9759 try_cursor_movement (window
, startp
, scroll_step
)
9761 struct text_pos startp
;
9764 struct window
*w
= XWINDOW (window
);
9765 struct frame
*f
= XFRAME (w
->frame
);
9766 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
9769 if (inhibit_try_cursor_movement
)
9773 /* Handle case where text has not changed, only point, and it has
9774 not moved off the frame. */
9775 if (/* Point may be in this window. */
9776 PT
>= CHARPOS (startp
)
9777 /* Selective display hasn't changed. */
9778 && !current_buffer
->clip_changed
9779 /* Function force-mode-line-update is used to force a thorough
9780 redisplay. It sets either windows_or_buffers_changed or
9781 update_mode_lines. So don't take a shortcut here for these
9783 && !update_mode_lines
9784 && !windows_or_buffers_changed
9785 /* Can't use this case if highlighting a region. When a
9786 region exists, cursor movement has to do more than just
9788 && !(!NILP (Vtransient_mark_mode
)
9789 && !NILP (current_buffer
->mark_active
))
9790 && NILP (w
->region_showing
)
9791 && NILP (Vshow_trailing_whitespace
)
9792 /* Right after splitting windows, last_point may be nil. */
9793 && INTEGERP (w
->last_point
)
9794 /* This code is not used for mini-buffer for the sake of the case
9795 of redisplaying to replace an echo area message; since in
9796 that case the mini-buffer contents per se are usually
9797 unchanged. This code is of no real use in the mini-buffer
9798 since the handling of this_line_start_pos, etc., in redisplay
9799 handles the same cases. */
9800 && !EQ (window
, minibuf_window
)
9801 /* When splitting windows or for new windows, it happens that
9802 redisplay is called with a nil window_end_vpos or one being
9803 larger than the window. This should really be fixed in
9804 window.c. I don't have this on my list, now, so we do
9805 approximately the same as the old redisplay code. --gerd. */
9806 && INTEGERP (w
->window_end_vpos
)
9807 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9808 && (FRAME_WINDOW_P (f
)
9809 || !MARKERP (Voverlay_arrow_position
)
9810 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9812 int this_scroll_margin
;
9813 struct glyph_row
*row
= NULL
;
9816 debug_method_add (w
, "cursor movement");
9819 /* Scroll if point within this distance from the top or bottom
9820 of the window. This is a pixel value. */
9821 this_scroll_margin
= max (0, scroll_margin
);
9822 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9823 this_scroll_margin
*= CANON_Y_UNIT (f
);
9825 /* Start with the row the cursor was displayed during the last
9826 not paused redisplay. Give up if that row is not valid. */
9827 if (w
->last_cursor
.vpos
< 0
9828 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9829 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9832 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9833 if (row
->mode_line_p
)
9835 if (!row
->enabled_p
)
9836 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9839 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
9842 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9844 if (PT
> XFASTINT (w
->last_point
))
9846 /* Point has moved forward. */
9847 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9848 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9850 xassert (row
->enabled_p
);
9854 /* The end position of a row equals the start position
9855 of the next row. If PT is there, we would rather
9856 display it in the next line. */
9857 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9858 && MATRIX_ROW_END_CHARPOS (row
) == PT
9859 && !cursor_row_p (w
, row
))
9862 /* If within the scroll margin, scroll. Note that
9863 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9864 the next line would be drawn, and that
9865 this_scroll_margin can be zero. */
9866 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9867 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9868 /* Line is completely visible last line in window
9869 and PT is to be set in the next line. */
9870 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9871 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9872 && !row
->ends_at_zv_p
9873 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9876 else if (PT
< XFASTINT (w
->last_point
))
9878 /* Cursor has to be moved backward. Note that PT >=
9879 CHARPOS (startp) because of the outer
9881 while (!row
->mode_line_p
9882 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9883 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9884 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9885 && (row
->y
> this_scroll_margin
9886 || CHARPOS (startp
) == BEGV
))
9888 xassert (row
->enabled_p
);
9892 /* Consider the following case: Window starts at BEGV,
9893 there is invisible, intangible text at BEGV, so that
9894 display starts at some point START > BEGV. It can
9895 happen that we are called with PT somewhere between
9896 BEGV and START. Try to handle that case. */
9897 if (row
< w
->current_matrix
->rows
9898 || row
->mode_line_p
)
9900 row
= w
->current_matrix
->rows
;
9901 if (row
->mode_line_p
)
9905 /* Due to newlines in overlay strings, we may have to
9906 skip forward over overlay strings. */
9907 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9908 && MATRIX_ROW_END_CHARPOS (row
) == PT
9909 && !cursor_row_p (w
, row
))
9912 /* If within the scroll margin, scroll. */
9913 if (row
->y
< this_scroll_margin
9914 && CHARPOS (startp
) != BEGV
)
9918 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9919 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9921 /* if PT is not in the glyph row, give up. */
9922 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9924 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9926 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
9927 && !row
->ends_at_zv_p
9928 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
9929 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9930 else if (row
->height
> window_box_height (w
))
9932 /* If we end up in a partially visible line, let's
9933 make it fully visible, except when it's taller
9934 than the window, in which case we can't do much
9937 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9941 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9942 try_window (window
, startp
);
9943 if (!make_cursor_line_fully_visible (w
))
9944 rc
= CURSOR_MOVEMENT_NEED_LARGER_MATRICES
;
9946 rc
= CURSOR_MOVEMENT_SUCCESS
;
9950 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9953 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9954 rc
= CURSOR_MOVEMENT_SUCCESS
;
9963 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9964 selected_window is redisplayed. */
9967 redisplay_window (window
, just_this_one_p
)
9969 int just_this_one_p
;
9971 struct window
*w
= XWINDOW (window
);
9972 struct frame
*f
= XFRAME (w
->frame
);
9973 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9974 struct buffer
*old
= current_buffer
;
9975 struct text_pos lpoint
, opoint
, startp
;
9976 int update_mode_line
;
9979 /* Record it now because it's overwritten. */
9980 int current_matrix_up_to_date_p
= 0;
9981 int temp_scroll_step
= 0;
9982 int count
= BINDING_STACK_SIZE ();
9985 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9988 /* W must be a leaf window here. */
9989 xassert (!NILP (w
->buffer
));
9991 *w
->desired_matrix
->method
= 0;
9994 specbind (Qinhibit_point_motion_hooks
, Qt
);
9996 reconsider_clip_changes (w
, buffer
);
9998 /* Has the mode line to be updated? */
9999 update_mode_line
= (!NILP (w
->update_mode_line
)
10000 || update_mode_lines
10001 || buffer
->clip_changed
);
10003 if (MINI_WINDOW_P (w
))
10005 if (w
== XWINDOW (echo_area_window
)
10006 && !NILP (echo_area_buffer
[0]))
10008 if (update_mode_line
)
10009 /* We may have to update a tty frame's menu bar or a
10010 tool-bar. Example `M-x C-h C-h C-g'. */
10011 goto finish_menu_bars
;
10013 /* We've already displayed the echo area glyphs in this window. */
10014 goto finish_scroll_bars
;
10016 else if (w
!= XWINDOW (minibuf_window
))
10018 /* W is a mini-buffer window, but it's not the currently
10019 active one, so clear it. */
10020 int yb
= window_text_bottom_y (w
);
10021 struct glyph_row
*row
;
10024 for (y
= 0, row
= w
->desired_matrix
->rows
;
10026 y
+= row
->height
, ++row
)
10027 blank_row (w
, row
, y
);
10028 goto finish_scroll_bars
;
10031 clear_glyph_matrix (w
->desired_matrix
);
10034 /* Otherwise set up data on this window; select its buffer and point
10036 /* Really select the buffer, for the sake of buffer-local
10038 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10039 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
10041 current_matrix_up_to_date_p
10042 = (!NILP (w
->window_end_valid
)
10043 && !current_buffer
->clip_changed
10044 && XFASTINT (w
->last_modified
) >= MODIFF
10045 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10047 /* When windows_or_buffers_changed is non-zero, we can't rely on
10048 the window end being valid, so set it to nil there. */
10049 if (windows_or_buffers_changed
)
10051 /* If window starts on a continuation line, maybe adjust the
10052 window start in case the window's width changed. */
10053 if (XMARKER (w
->start
)->buffer
== current_buffer
)
10054 compute_window_start_on_continuation_line (w
);
10056 w
->window_end_valid
= Qnil
;
10059 /* Some sanity checks. */
10060 CHECK_WINDOW_END (w
);
10061 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
10063 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
10066 /* If %c is in mode line, update it if needed. */
10067 if (!NILP (w
->column_number_displayed
)
10068 /* This alternative quickly identifies a common case
10069 where no change is needed. */
10070 && !(PT
== XFASTINT (w
->last_point
)
10071 && XFASTINT (w
->last_modified
) >= MODIFF
10072 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10073 && XFASTINT (w
->column_number_displayed
) != current_column ())
10074 update_mode_line
= 1;
10076 /* Count number of windows showing the selected buffer. An indirect
10077 buffer counts as its base buffer. */
10078 if (!just_this_one_p
)
10080 struct buffer
*current_base
, *window_base
;
10081 current_base
= current_buffer
;
10082 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10083 if (current_base
->base_buffer
)
10084 current_base
= current_base
->base_buffer
;
10085 if (window_base
->base_buffer
)
10086 window_base
= window_base
->base_buffer
;
10087 if (current_base
== window_base
)
10091 /* Point refers normally to the selected window. For any other
10092 window, set up appropriate value. */
10093 if (!EQ (window
, selected_window
))
10095 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10096 int new_pt_byte
= marker_byte_position (w
->pointm
);
10100 new_pt_byte
= BEGV_BYTE
;
10101 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10103 else if (new_pt
> (ZV
- 1))
10106 new_pt_byte
= ZV_BYTE
;
10107 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10110 /* We don't use SET_PT so that the point-motion hooks don't run. */
10111 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10114 /* If any of the character widths specified in the display table
10115 have changed, invalidate the width run cache. It's true that
10116 this may be a bit late to catch such changes, but the rest of
10117 redisplay goes (non-fatally) haywire when the display table is
10118 changed, so why should we worry about doing any better? */
10119 if (current_buffer
->width_run_cache
)
10121 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10123 if (! disptab_matches_widthtab (disptab
,
10124 XVECTOR (current_buffer
->width_table
)))
10126 invalidate_region_cache (current_buffer
,
10127 current_buffer
->width_run_cache
,
10129 recompute_width_table (current_buffer
, disptab
);
10133 /* If window-start is screwed up, choose a new one. */
10134 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10137 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10139 /* If someone specified a new starting point but did not insist,
10140 check whether it can be used. */
10141 if (!NILP (w
->optional_new_start
)
10142 && CHARPOS (startp
) >= BEGV
10143 && CHARPOS (startp
) <= ZV
)
10145 w
->optional_new_start
= Qnil
;
10146 start_display (&it
, w
, startp
);
10147 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10148 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10149 if (IT_CHARPOS (it
) == PT
)
10150 w
->force_start
= Qt
;
10153 /* Handle case where place to start displaying has been specified,
10154 unless the specified location is outside the accessible range. */
10155 if (!NILP (w
->force_start
)
10156 || w
->frozen_window_start_p
)
10158 w
->force_start
= Qnil
;
10160 w
->window_end_valid
= Qnil
;
10162 /* Forget any recorded base line for line number display. */
10163 if (!current_matrix_up_to_date_p
10164 || current_buffer
->clip_changed
)
10165 w
->base_line_number
= Qnil
;
10167 /* Redisplay the mode line. Select the buffer properly for that.
10168 Also, run the hook window-scroll-functions
10169 because we have scrolled. */
10170 /* Note, we do this after clearing force_start because
10171 if there's an error, it is better to forget about force_start
10172 than to get into an infinite loop calling the hook functions
10173 and having them get more errors. */
10174 if (!update_mode_line
10175 || ! NILP (Vwindow_scroll_functions
))
10177 update_mode_line
= 1;
10178 w
->update_mode_line
= Qt
;
10179 startp
= run_window_scroll_functions (window
, startp
);
10182 w
->last_modified
= make_number (0);
10183 w
->last_overlay_modified
= make_number (0);
10184 if (CHARPOS (startp
) < BEGV
)
10185 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10186 else if (CHARPOS (startp
) > ZV
)
10187 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10189 /* Redisplay, then check if cursor has been set during the
10190 redisplay. Give up if new fonts were loaded. */
10191 if (!try_window (window
, startp
))
10193 w
->force_start
= Qt
;
10194 clear_glyph_matrix (w
->desired_matrix
);
10195 goto finish_scroll_bars
;
10198 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10200 /* If point does not appear, try to move point so it does
10201 appear. The desired matrix has been built above, so we
10202 can use it here. */
10204 struct glyph_row
*row
;
10206 window_height
= window_box_height (w
) / 2;
10207 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10208 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
10211 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10212 MATRIX_ROW_START_BYTEPOS (row
));
10214 if (w
!= XWINDOW (selected_window
))
10215 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10216 else if (current_buffer
== old
)
10217 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10219 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10221 /* If we are highlighting the region, then we just changed
10222 the region, so redisplay to show it. */
10223 if (!NILP (Vtransient_mark_mode
)
10224 && !NILP (current_buffer
->mark_active
))
10226 clear_glyph_matrix (w
->desired_matrix
);
10227 if (!try_window (window
, startp
))
10228 goto need_larger_matrices
;
10232 if (!make_cursor_line_fully_visible (w
))
10233 goto need_larger_matrices
;
10235 debug_method_add (w
, "forced window start");
10240 /* Handle case where text has not changed, only point, and it has
10241 not moved off the frame. */
10242 if (current_matrix_up_to_date_p
10243 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10244 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10248 case CURSOR_MOVEMENT_SUCCESS
:
10251 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10252 goto need_larger_matrices
;
10254 case CURSOR_MOVEMENT_MUST_SCROLL
:
10255 goto try_to_scroll
;
10261 /* If current starting point was originally the beginning of a line
10262 but no longer is, find a new starting point. */
10263 else if (!NILP (w
->start_at_line_beg
)
10264 && !(CHARPOS (startp
) <= BEGV
10265 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10268 debug_method_add (w
, "recenter 1");
10273 /* Try scrolling with try_window_id. Value is > 0 if update has
10274 been done, it is -1 if we know that the same window start will
10275 not work. It is 0 if unsuccessful for some other reason. */
10276 else if ((tem
= try_window_id (w
)) != 0)
10279 debug_method_add (w
, "try_window_id %d", tem
);
10282 if (fonts_changed_p
)
10283 goto need_larger_matrices
;
10287 /* Otherwise try_window_id has returned -1 which means that we
10288 don't want the alternative below this comment to execute. */
10290 else if (CHARPOS (startp
) >= BEGV
10291 && CHARPOS (startp
) <= ZV
10292 && PT
>= CHARPOS (startp
)
10293 && (CHARPOS (startp
) < ZV
10294 /* Avoid starting at end of buffer. */
10295 || CHARPOS (startp
) == BEGV
10296 || (XFASTINT (w
->last_modified
) >= MODIFF
10297 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10300 debug_method_add (w
, "same window start");
10303 /* Try to redisplay starting at same place as before.
10304 If point has not moved off frame, accept the results. */
10305 if (!current_matrix_up_to_date_p
10306 /* Don't use try_window_reusing_current_matrix in this case
10307 because a window scroll function can have changed the
10309 || !NILP (Vwindow_scroll_functions
)
10310 || MINI_WINDOW_P (w
)
10311 || !try_window_reusing_current_matrix (w
))
10313 IF_DEBUG (debug_method_add (w
, "1"));
10314 try_window (window
, startp
);
10317 if (fonts_changed_p
)
10318 goto need_larger_matrices
;
10320 if (w
->cursor
.vpos
>= 0)
10322 if (!just_this_one_p
10323 || current_buffer
->clip_changed
10324 || BEG_UNCHANGED
< CHARPOS (startp
))
10325 /* Forget any recorded base line for line number display. */
10326 w
->base_line_number
= Qnil
;
10328 if (!make_cursor_line_fully_visible (w
))
10329 goto need_larger_matrices
;
10333 clear_glyph_matrix (w
->desired_matrix
);
10338 w
->last_modified
= make_number (0);
10339 w
->last_overlay_modified
= make_number (0);
10341 /* Redisplay the mode line. Select the buffer properly for that. */
10342 if (!update_mode_line
)
10344 update_mode_line
= 1;
10345 w
->update_mode_line
= Qt
;
10348 /* Try to scroll by specified few lines. */
10349 if ((scroll_conservatively
10351 || temp_scroll_step
10352 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10353 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10354 && !current_buffer
->clip_changed
10355 && CHARPOS (startp
) >= BEGV
10356 && CHARPOS (startp
) <= ZV
)
10358 /* The function returns -1 if new fonts were loaded, 1 if
10359 successful, 0 if not successful. */
10360 int rc
= try_scrolling (window
, just_this_one_p
,
10361 scroll_conservatively
,
10366 case SCROLLING_SUCCESS
:
10369 case SCROLLING_NEED_LARGER_MATRICES
:
10370 goto need_larger_matrices
;
10372 case SCROLLING_FAILED
:
10380 /* Finally, just choose place to start which centers point */
10385 debug_method_add (w
, "recenter");
10388 /* w->vscroll = 0; */
10390 /* Forget any previously recorded base line for line number display. */
10391 if (!current_matrix_up_to_date_p
10392 || current_buffer
->clip_changed
)
10393 w
->base_line_number
= Qnil
;
10395 /* Move backward half the height of the window. */
10396 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10397 it
.current_y
= it
.last_visible_y
;
10398 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
10399 xassert (IT_CHARPOS (it
) >= BEGV
);
10401 /* The function move_it_vertically_backward may move over more
10402 than the specified y-distance. If it->w is small, e.g. a
10403 mini-buffer window, we may end up in front of the window's
10404 display area. Start displaying at the start of the line
10405 containing PT in this case. */
10406 if (it
.current_y
<= 0)
10408 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10409 move_it_vertically (&it
, 0);
10410 xassert (IT_CHARPOS (it
) <= PT
);
10414 it
.current_x
= it
.hpos
= 0;
10416 /* Set startp here explicitly in case that helps avoid an infinite loop
10417 in case the window-scroll-functions functions get errors. */
10418 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10420 /* Run scroll hooks. */
10421 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10423 /* Redisplay the window. */
10424 if (!current_matrix_up_to_date_p
10425 || windows_or_buffers_changed
10426 /* Don't use try_window_reusing_current_matrix in this case
10427 because it can have changed the buffer. */
10428 || !NILP (Vwindow_scroll_functions
)
10429 || !just_this_one_p
10430 || MINI_WINDOW_P (w
)
10431 || !try_window_reusing_current_matrix (w
))
10432 try_window (window
, startp
);
10434 /* If new fonts have been loaded (due to fontsets), give up. We
10435 have to start a new redisplay since we need to re-adjust glyph
10437 if (fonts_changed_p
)
10438 goto need_larger_matrices
;
10440 /* If cursor did not appear assume that the middle of the window is
10441 in the first line of the window. Do it again with the next line.
10442 (Imagine a window of height 100, displaying two lines of height
10443 60. Moving back 50 from it->last_visible_y will end in the first
10445 if (w
->cursor
.vpos
< 0)
10447 if (!NILP (w
->window_end_valid
)
10448 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10450 clear_glyph_matrix (w
->desired_matrix
);
10451 move_it_by_lines (&it
, 1, 0);
10452 try_window (window
, it
.current
.pos
);
10454 else if (PT
< IT_CHARPOS (it
))
10456 clear_glyph_matrix (w
->desired_matrix
);
10457 move_it_by_lines (&it
, -1, 0);
10458 try_window (window
, it
.current
.pos
);
10462 /* Not much we can do about it. */
10466 /* Consider the following case: Window starts at BEGV, there is
10467 invisible, intangible text at BEGV, so that display starts at
10468 some point START > BEGV. It can happen that we are called with
10469 PT somewhere between BEGV and START. Try to handle that case. */
10470 if (w
->cursor
.vpos
< 0)
10472 struct glyph_row
*row
= w
->current_matrix
->rows
;
10473 if (row
->mode_line_p
)
10475 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10478 if (!make_cursor_line_fully_visible (w
))
10479 goto need_larger_matrices
;
10483 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10484 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10485 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10488 /* Display the mode line, if we must. */
10489 if ((update_mode_line
10490 /* If window not full width, must redo its mode line
10491 if (a) the window to its side is being redone and
10492 (b) we do a frame-based redisplay. This is a consequence
10493 of how inverted lines are drawn in frame-based redisplay. */
10494 || (!just_this_one_p
10495 && !FRAME_WINDOW_P (f
)
10496 && !WINDOW_FULL_WIDTH_P (w
))
10497 /* Line number to display. */
10498 || INTEGERP (w
->base_line_pos
)
10499 /* Column number is displayed and different from the one displayed. */
10500 || (!NILP (w
->column_number_displayed
)
10501 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10502 /* This means that the window has a mode line. */
10503 && (WINDOW_WANTS_MODELINE_P (w
)
10504 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10506 display_mode_lines (w
);
10508 /* If mode line height has changed, arrange for a thorough
10509 immediate redisplay using the correct mode line height. */
10510 if (WINDOW_WANTS_MODELINE_P (w
)
10511 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10513 fonts_changed_p
= 1;
10514 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10515 = DESIRED_MODE_LINE_HEIGHT (w
);
10518 /* If top line height has changed, arrange for a thorough
10519 immediate redisplay using the correct mode line height. */
10520 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10521 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10523 fonts_changed_p
= 1;
10524 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10525 = DESIRED_HEADER_LINE_HEIGHT (w
);
10528 if (fonts_changed_p
)
10529 goto need_larger_matrices
;
10532 if (!line_number_displayed
10533 && !BUFFERP (w
->base_line_pos
))
10535 w
->base_line_pos
= Qnil
;
10536 w
->base_line_number
= Qnil
;
10541 /* When we reach a frame's selected window, redo the frame's menu bar. */
10542 if (update_mode_line
10543 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10545 int redisplay_menu_p
= 0;
10547 if (FRAME_WINDOW_P (f
))
10549 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10550 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10552 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10556 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10558 if (redisplay_menu_p
)
10559 display_menu_bar (w
);
10561 #ifdef HAVE_WINDOW_SYSTEM
10562 if (WINDOWP (f
->tool_bar_window
)
10563 && (FRAME_TOOL_BAR_LINES (f
) > 0
10564 || auto_resize_tool_bars_p
))
10565 redisplay_tool_bar (f
);
10569 need_larger_matrices
:
10571 finish_scroll_bars
:
10573 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10575 int start
, end
, whole
;
10577 /* Calculate the start and end positions for the current window.
10578 At some point, it would be nice to choose between scrollbars
10579 which reflect the whole buffer size, with special markers
10580 indicating narrowing, and scrollbars which reflect only the
10583 Note that mini-buffers sometimes aren't displaying any text. */
10584 if (!MINI_WINDOW_P (w
)
10585 || (w
== XWINDOW (minibuf_window
)
10586 && NILP (echo_area_buffer
[0])))
10589 start
= marker_position (w
->start
) - BEGV
;
10590 /* I don't think this is guaranteed to be right. For the
10591 moment, we'll pretend it is. */
10592 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10596 if (whole
< (end
- start
))
10597 whole
= end
- start
;
10600 start
= end
= whole
= 0;
10602 /* Indicate what this scroll bar ought to be displaying now. */
10603 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10605 /* Note that we actually used the scroll bar attached to this
10606 window, so it shouldn't be deleted at the end of redisplay. */
10607 redeem_scroll_bar_hook (w
);
10610 /* Restore current_buffer and value of point in it. */
10611 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10612 set_buffer_internal_1 (old
);
10613 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10615 unbind_to (count
, Qnil
);
10619 /* Build the complete desired matrix of WINDOW with a window start
10620 buffer position POS. Value is non-zero if successful. It is zero
10621 if fonts were loaded during redisplay which makes re-adjusting
10622 glyph matrices necessary. */
10625 try_window (window
, pos
)
10626 Lisp_Object window
;
10627 struct text_pos pos
;
10629 struct window
*w
= XWINDOW (window
);
10631 struct glyph_row
*last_text_row
= NULL
;
10633 /* Make POS the new window start. */
10634 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10636 /* Mark cursor position as unknown. No overlay arrow seen. */
10637 w
->cursor
.vpos
= -1;
10638 overlay_arrow_seen
= 0;
10640 /* Initialize iterator and info to start at POS. */
10641 start_display (&it
, w
, pos
);
10643 /* Display all lines of W. */
10644 while (it
.current_y
< it
.last_visible_y
)
10646 if (display_line (&it
))
10647 last_text_row
= it
.glyph_row
- 1;
10648 if (fonts_changed_p
)
10652 /* If bottom moved off end of frame, change mode line percentage. */
10653 if (XFASTINT (w
->window_end_pos
) <= 0
10654 && Z
!= IT_CHARPOS (it
))
10655 w
->update_mode_line
= Qt
;
10657 /* Set window_end_pos to the offset of the last character displayed
10658 on the window from the end of current_buffer. Set
10659 window_end_vpos to its row number. */
10662 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10663 w
->window_end_bytepos
10664 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10666 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10668 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10669 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10670 ->displays_text_p
);
10674 w
->window_end_bytepos
= 0;
10675 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10678 /* But that is not valid info until redisplay finishes. */
10679 w
->window_end_valid
= Qnil
;
10685 /************************************************************************
10686 Window redisplay reusing current matrix when buffer has not changed
10687 ************************************************************************/
10689 /* Try redisplay of window W showing an unchanged buffer with a
10690 different window start than the last time it was displayed by
10691 reusing its current matrix. Value is non-zero if successful.
10692 W->start is the new window start. */
10695 try_window_reusing_current_matrix (w
)
10698 struct frame
*f
= XFRAME (w
->frame
);
10699 struct glyph_row
*row
, *bottom_row
;
10702 struct text_pos start
, new_start
;
10703 int nrows_scrolled
, i
;
10704 struct glyph_row
*last_text_row
;
10705 struct glyph_row
*last_reused_text_row
;
10706 struct glyph_row
*start_row
;
10707 int start_vpos
, min_y
, max_y
;
10710 if (inhibit_try_window_reusing
)
10714 if (/* This function doesn't handle terminal frames. */
10715 !FRAME_WINDOW_P (f
)
10716 /* Don't try to reuse the display if windows have been split
10718 || windows_or_buffers_changed
)
10721 /* Can't do this if region may have changed. */
10722 if ((!NILP (Vtransient_mark_mode
)
10723 && !NILP (current_buffer
->mark_active
))
10724 || !NILP (w
->region_showing
)
10725 || !NILP (Vshow_trailing_whitespace
))
10728 /* If top-line visibility has changed, give up. */
10729 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10730 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10733 /* Give up if old or new display is scrolled vertically. We could
10734 make this function handle this, but right now it doesn't. */
10735 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10736 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10739 /* The variable new_start now holds the new window start. The old
10740 start `start' can be determined from the current matrix. */
10741 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10742 start
= start_row
->start
.pos
;
10743 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10745 /* Clear the desired matrix for the display below. */
10746 clear_glyph_matrix (w
->desired_matrix
);
10748 if (CHARPOS (new_start
) <= CHARPOS (start
))
10752 /* Don't use this method if the display starts with an ellipsis
10753 displayed for invisible text. It's not easy to handle that case
10754 below, and it's certainly not worth the effort since this is
10755 not a frequent case. */
10756 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10759 IF_DEBUG (debug_method_add (w
, "twu1"));
10761 /* Display up to a row that can be reused. The variable
10762 last_text_row is set to the last row displayed that displays
10763 text. Note that it.vpos == 0 if or if not there is a
10764 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10765 start_display (&it
, w
, new_start
);
10766 first_row_y
= it
.current_y
;
10767 w
->cursor
.vpos
= -1;
10768 last_text_row
= last_reused_text_row
= NULL
;
10770 while (it
.current_y
< it
.last_visible_y
10771 && IT_CHARPOS (it
) < CHARPOS (start
)
10772 && !fonts_changed_p
)
10773 if (display_line (&it
))
10774 last_text_row
= it
.glyph_row
- 1;
10776 /* A value of current_y < last_visible_y means that we stopped
10777 at the previous window start, which in turn means that we
10778 have at least one reusable row. */
10779 if (it
.current_y
< it
.last_visible_y
)
10781 /* IT.vpos always starts from 0; it counts text lines. */
10782 nrows_scrolled
= it
.vpos
;
10784 /* Find PT if not already found in the lines displayed. */
10785 if (w
->cursor
.vpos
< 0)
10787 int dy
= it
.current_y
- first_row_y
;
10789 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10790 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
10792 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10793 dy
, nrows_scrolled
);
10796 clear_glyph_matrix (w
->desired_matrix
);
10801 /* Scroll the display. Do it before the current matrix is
10802 changed. The problem here is that update has not yet
10803 run, i.e. part of the current matrix is not up to date.
10804 scroll_run_hook will clear the cursor, and use the
10805 current matrix to get the height of the row the cursor is
10807 run
.current_y
= first_row_y
;
10808 run
.desired_y
= it
.current_y
;
10809 run
.height
= it
.last_visible_y
- it
.current_y
;
10811 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10814 rif
->update_window_begin_hook (w
);
10815 rif
->clear_mouse_face (w
);
10816 rif
->scroll_run_hook (w
, &run
);
10817 rif
->update_window_end_hook (w
, 0, 0);
10821 /* Shift current matrix down by nrows_scrolled lines. */
10822 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10823 rotate_matrix (w
->current_matrix
,
10825 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10828 /* Disable lines that must be updated. */
10829 for (i
= 0; i
< it
.vpos
; ++i
)
10830 (start_row
+ i
)->enabled_p
= 0;
10832 /* Re-compute Y positions. */
10833 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10834 max_y
= it
.last_visible_y
;
10835 for (row
= start_row
+ nrows_scrolled
;
10839 row
->y
= it
.current_y
;
10840 row
->visible_height
= row
->height
;
10842 if (row
->y
< min_y
)
10843 row
->visible_height
-= min_y
- row
->y
;
10844 if (row
->y
+ row
->height
> max_y
)
10845 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10847 it
.current_y
+= row
->height
;
10849 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10850 last_reused_text_row
= row
;
10851 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10855 /* Disable lines in the current matrix which are now
10856 below the window. */
10857 for (++row
; row
< bottom_row
; ++row
)
10858 row
->enabled_p
= 0;
10861 /* Update window_end_pos etc.; last_reused_text_row is the last
10862 reused row from the current matrix containing text, if any.
10863 The value of last_text_row is the last displayed line
10864 containing text. */
10865 if (last_reused_text_row
)
10867 w
->window_end_bytepos
10868 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10870 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10872 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10873 w
->current_matrix
));
10875 else if (last_text_row
)
10877 w
->window_end_bytepos
10878 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10880 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10882 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10886 /* This window must be completely empty. */
10887 w
->window_end_bytepos
= 0;
10888 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10890 w
->window_end_valid
= Qnil
;
10892 /* Update hint: don't try scrolling again in update_window. */
10893 w
->desired_matrix
->no_scrolling_p
= 1;
10896 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10900 else if (CHARPOS (new_start
) > CHARPOS (start
))
10902 struct glyph_row
*pt_row
, *row
;
10903 struct glyph_row
*first_reusable_row
;
10904 struct glyph_row
*first_row_to_display
;
10906 int yb
= window_text_bottom_y (w
);
10908 /* Find the row starting at new_start, if there is one. Don't
10909 reuse a partially visible line at the end. */
10910 first_reusable_row
= start_row
;
10911 while (first_reusable_row
->enabled_p
10912 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10913 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10914 < CHARPOS (new_start
)))
10915 ++first_reusable_row
;
10917 /* Give up if there is no row to reuse. */
10918 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10919 || !first_reusable_row
->enabled_p
10920 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10921 != CHARPOS (new_start
)))
10924 /* We can reuse fully visible rows beginning with
10925 first_reusable_row to the end of the window. Set
10926 first_row_to_display to the first row that cannot be reused.
10927 Set pt_row to the row containing point, if there is any. */
10929 for (first_row_to_display
= first_reusable_row
;
10930 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
10931 ++first_row_to_display
)
10933 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10934 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10935 pt_row
= first_row_to_display
;
10938 /* Start displaying at the start of first_row_to_display. */
10939 xassert (first_row_to_display
->y
< yb
);
10940 init_to_row_start (&it
, w
, first_row_to_display
);
10942 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10944 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10946 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10947 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10949 /* Display lines beginning with first_row_to_display in the
10950 desired matrix. Set last_text_row to the last row displayed
10951 that displays text. */
10952 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10953 if (pt_row
== NULL
)
10954 w
->cursor
.vpos
= -1;
10955 last_text_row
= NULL
;
10956 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10957 if (display_line (&it
))
10958 last_text_row
= it
.glyph_row
- 1;
10960 /* Give up If point isn't in a row displayed or reused. */
10961 if (w
->cursor
.vpos
< 0)
10963 clear_glyph_matrix (w
->desired_matrix
);
10967 /* If point is in a reused row, adjust y and vpos of the cursor
10971 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10972 w
->current_matrix
);
10973 w
->cursor
.y
-= first_reusable_row
->y
;
10976 /* Scroll the display. */
10977 run
.current_y
= first_reusable_row
->y
;
10978 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10979 run
.height
= it
.last_visible_y
- run
.current_y
;
10980 dy
= run
.current_y
- run
.desired_y
;
10984 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10986 rif
->update_window_begin_hook (w
);
10987 rif
->clear_mouse_face (w
);
10988 rif
->scroll_run_hook (w
, &run
);
10989 rif
->update_window_end_hook (w
, 0, 0);
10993 /* Adjust Y positions of reused rows. */
10994 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10995 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10996 max_y
= it
.last_visible_y
;
10997 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
11000 row
->visible_height
= row
->height
;
11001 if (row
->y
< min_y
)
11002 row
->visible_height
-= min_y
- row
->y
;
11003 if (row
->y
+ row
->height
> max_y
)
11004 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11007 /* Scroll the current matrix. */
11008 xassert (nrows_scrolled
> 0);
11009 rotate_matrix (w
->current_matrix
,
11011 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11014 /* Disable rows not reused. */
11015 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
11016 row
->enabled_p
= 0;
11018 /* Adjust window end. A null value of last_text_row means that
11019 the window end is in reused rows which in turn means that
11020 only its vpos can have changed. */
11023 w
->window_end_bytepos
11024 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11026 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11028 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11033 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
11036 w
->window_end_valid
= Qnil
;
11037 w
->desired_matrix
->no_scrolling_p
= 1;
11040 debug_method_add (w
, "try_window_reusing_current_matrix 2");
11050 /************************************************************************
11051 Window redisplay reusing current matrix when buffer has changed
11052 ************************************************************************/
11054 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
11055 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
11057 static struct glyph_row
*
11058 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
11059 struct glyph_row
*));
11062 /* Return the last row in MATRIX displaying text. If row START is
11063 non-null, start searching with that row. IT gives the dimensions
11064 of the display. Value is null if matrix is empty; otherwise it is
11065 a pointer to the row found. */
11067 static struct glyph_row
*
11068 find_last_row_displaying_text (matrix
, it
, start
)
11069 struct glyph_matrix
*matrix
;
11071 struct glyph_row
*start
;
11073 struct glyph_row
*row
, *row_found
;
11075 /* Set row_found to the last row in IT->w's current matrix
11076 displaying text. The loop looks funny but think of partially
11079 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11080 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11082 xassert (row
->enabled_p
);
11084 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11093 /* Return the last row in the current matrix of W that is not affected
11094 by changes at the start of current_buffer that occurred since W's
11095 current matrix was built. Value is null if no such row exists.
11097 BEG_UNCHANGED us the number of characters unchanged at the start of
11098 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11099 first changed character in current_buffer. Characters at positions <
11100 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11101 when the current matrix was built. */
11103 static struct glyph_row
*
11104 find_last_unchanged_at_beg_row (w
)
11107 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11108 struct glyph_row
*row
;
11109 struct glyph_row
*row_found
= NULL
;
11110 int yb
= window_text_bottom_y (w
);
11112 /* Find the last row displaying unchanged text. */
11113 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11114 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11115 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11117 if (/* If row ends before first_changed_pos, it is unchanged,
11118 except in some case. */
11119 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11120 /* When row ends in ZV and we write at ZV it is not
11122 && !row
->ends_at_zv_p
11123 /* When first_changed_pos is the end of a continued line,
11124 row is not unchanged because it may be no longer
11126 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11127 && row
->continued_p
))
11130 /* Stop if last visible row. */
11131 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11141 /* Find the first glyph row in the current matrix of W that is not
11142 affected by changes at the end of current_buffer since the
11143 time W's current matrix was built.
11145 Return in *DELTA the number of chars by which buffer positions in
11146 unchanged text at the end of current_buffer must be adjusted.
11148 Return in *DELTA_BYTES the corresponding number of bytes.
11150 Value is null if no such row exists, i.e. all rows are affected by
11153 static struct glyph_row
*
11154 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11156 int *delta
, *delta_bytes
;
11158 struct glyph_row
*row
;
11159 struct glyph_row
*row_found
= NULL
;
11161 *delta
= *delta_bytes
= 0;
11163 /* Display must not have been paused, otherwise the current matrix
11164 is not up to date. */
11165 if (NILP (w
->window_end_valid
))
11168 /* A value of window_end_pos >= END_UNCHANGED means that the window
11169 end is in the range of changed text. If so, there is no
11170 unchanged row at the end of W's current matrix. */
11171 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11174 /* Set row to the last row in W's current matrix displaying text. */
11175 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11177 /* If matrix is entirely empty, no unchanged row exists. */
11178 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11180 /* The value of row is the last glyph row in the matrix having a
11181 meaningful buffer position in it. The end position of row
11182 corresponds to window_end_pos. This allows us to translate
11183 buffer positions in the current matrix to current buffer
11184 positions for characters not in changed text. */
11185 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11186 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11187 int last_unchanged_pos
, last_unchanged_pos_old
;
11188 struct glyph_row
*first_text_row
11189 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11191 *delta
= Z
- Z_old
;
11192 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11194 /* Set last_unchanged_pos to the buffer position of the last
11195 character in the buffer that has not been changed. Z is the
11196 index + 1 of the last character in current_buffer, i.e. by
11197 subtracting END_UNCHANGED we get the index of the last
11198 unchanged character, and we have to add BEG to get its buffer
11200 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11201 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11203 /* Search backward from ROW for a row displaying a line that
11204 starts at a minimum position >= last_unchanged_pos_old. */
11205 for (; row
> first_text_row
; --row
)
11207 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11210 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11215 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11222 /* Make sure that glyph rows in the current matrix of window W
11223 reference the same glyph memory as corresponding rows in the
11224 frame's frame matrix. This function is called after scrolling W's
11225 current matrix on a terminal frame in try_window_id and
11226 try_window_reusing_current_matrix. */
11229 sync_frame_with_window_matrix_rows (w
)
11232 struct frame
*f
= XFRAME (w
->frame
);
11233 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11235 /* Preconditions: W must be a leaf window and full-width. Its frame
11236 must have a frame matrix. */
11237 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11238 xassert (WINDOW_FULL_WIDTH_P (w
));
11239 xassert (!FRAME_WINDOW_P (f
));
11241 /* If W is a full-width window, glyph pointers in W's current matrix
11242 have, by definition, to be the same as glyph pointers in the
11243 corresponding frame matrix. */
11244 window_row
= w
->current_matrix
->rows
;
11245 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11246 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11247 while (window_row
< window_row_end
)
11251 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
11252 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
11254 /* Disable frame rows whose corresponding window rows have
11255 been disabled in try_window_id. */
11256 if (!window_row
->enabled_p
)
11257 frame_row
->enabled_p
= 0;
11259 ++window_row
, ++frame_row
;
11264 /* Find the glyph row in window W containing CHARPOS. Consider all
11265 rows between START and END (not inclusive). END null means search
11266 all rows to the end of the display area of W. Value is the row
11267 containing CHARPOS or null. */
11270 row_containing_pos (w
, charpos
, start
, end
, dy
)
11273 struct glyph_row
*start
, *end
;
11276 struct glyph_row
*row
= start
;
11279 /* If we happen to start on a header-line, skip that. */
11280 if (row
->mode_line_p
)
11283 if ((end
&& row
>= end
) || !row
->enabled_p
)
11286 last_y
= window_text_bottom_y (w
) - dy
;
11288 while ((end
== NULL
|| row
< end
)
11289 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
11290 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11291 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11292 /* The end position of a row equals the start
11293 position of the next row. If CHARPOS is there, we
11294 would rather display it in the next line, except
11295 when this line ends in ZV. */
11296 && !row
->ends_at_zv_p
11297 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))
11300 /* Give up if CHARPOS not found. */
11301 if ((end
&& row
>= end
)
11302 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11303 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11310 /* Try to redisplay window W by reusing its existing display. W's
11311 current matrix must be up to date when this function is called,
11312 i.e. window_end_valid must not be nil.
11316 1 if display has been updated
11317 0 if otherwise unsuccessful
11318 -1 if redisplay with same window start is known not to succeed
11320 The following steps are performed:
11322 1. Find the last row in the current matrix of W that is not
11323 affected by changes at the start of current_buffer. If no such row
11326 2. Find the first row in W's current matrix that is not affected by
11327 changes at the end of current_buffer. Maybe there is no such row.
11329 3. Display lines beginning with the row + 1 found in step 1 to the
11330 row found in step 2 or, if step 2 didn't find a row, to the end of
11333 4. If cursor is not known to appear on the window, give up.
11335 5. If display stopped at the row found in step 2, scroll the
11336 display and current matrix as needed.
11338 6. Maybe display some lines at the end of W, if we must. This can
11339 happen under various circumstances, like a partially visible line
11340 becoming fully visible, or because newly displayed lines are displayed
11341 in smaller font sizes.
11343 7. Update W's window end information. */
11349 struct frame
*f
= XFRAME (w
->frame
);
11350 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11351 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11352 struct glyph_row
*last_unchanged_at_beg_row
;
11353 struct glyph_row
*first_unchanged_at_end_row
;
11354 struct glyph_row
*row
;
11355 struct glyph_row
*bottom_row
;
11358 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11359 struct text_pos start_pos
;
11361 int first_unchanged_at_end_vpos
= 0;
11362 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11363 struct text_pos start
;
11364 int first_changed_charpos
, last_changed_charpos
;
11367 if (inhibit_try_window_id
)
11371 /* This is handy for debugging. */
11373 #define GIVE_UP(X) \
11375 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11379 #define GIVE_UP(X) return 0
11382 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11384 /* Don't use this for mini-windows because these can show
11385 messages and mini-buffers, and we don't handle that here. */
11386 if (MINI_WINDOW_P (w
))
11389 /* This flag is used to prevent redisplay optimizations. */
11390 if (windows_or_buffers_changed
)
11393 /* Verify that narrowing has not changed. This flag is also set to prevent
11394 redisplay optimizations. It would be nice to further
11395 reduce the number of cases where this prevents try_window_id. */
11396 if (current_buffer
->clip_changed
)
11399 /* Window must either use window-based redisplay or be full width. */
11400 if (!FRAME_WINDOW_P (f
)
11401 && (!line_ins_del_ok
11402 || !WINDOW_FULL_WIDTH_P (w
)))
11405 /* Give up if point is not known NOT to appear in W. */
11406 if (PT
< CHARPOS (start
))
11409 /* Another way to prevent redisplay optimizations. */
11410 if (XFASTINT (w
->last_modified
) == 0)
11413 /* Verify that window is not hscrolled. */
11414 if (XFASTINT (w
->hscroll
) != 0)
11417 /* Verify that display wasn't paused. */
11418 if (NILP (w
->window_end_valid
))
11421 /* Can't use this if highlighting a region because a cursor movement
11422 will do more than just set the cursor. */
11423 if (!NILP (Vtransient_mark_mode
)
11424 && !NILP (current_buffer
->mark_active
))
11427 /* Likewise if highlighting trailing whitespace. */
11428 if (!NILP (Vshow_trailing_whitespace
))
11431 /* Likewise if showing a region. */
11432 if (!NILP (w
->region_showing
))
11435 /* Can use this if overlay arrow position and or string have changed. */
11436 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11437 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11441 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11442 only if buffer has really changed. The reason is that the gap is
11443 initially at Z for freshly visited files. The code below would
11444 set end_unchanged to 0 in that case. */
11445 if (MODIFF
> SAVE_MODIFF
11446 /* This seems to happen sometimes after saving a buffer. */
11447 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11449 if (GPT
- BEG
< BEG_UNCHANGED
)
11450 BEG_UNCHANGED
= GPT
- BEG
;
11451 if (Z
- GPT
< END_UNCHANGED
)
11452 END_UNCHANGED
= Z
- GPT
;
11455 /* The position of the first and last character that has been changed. */
11456 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11457 last_changed_charpos
= Z
- END_UNCHANGED
;
11459 /* If window starts after a line end, and the last change is in
11460 front of that newline, then changes don't affect the display.
11461 This case happens with stealth-fontification. Note that although
11462 the display is unchanged, glyph positions in the matrix have to
11463 be adjusted, of course. */
11464 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11465 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11466 && ((last_changed_charpos
< CHARPOS (start
)
11467 && CHARPOS (start
) == BEGV
)
11468 || (last_changed_charpos
< CHARPOS (start
) - 1
11469 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11471 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11472 struct glyph_row
*r0
;
11474 /* Compute how many chars/bytes have been added to or removed
11475 from the buffer. */
11476 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11477 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11479 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11481 /* Give up if PT is not in the window. Note that it already has
11482 been checked at the start of try_window_id that PT is not in
11483 front of the window start. */
11484 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11487 /* If window start is unchanged, we can reuse the whole matrix
11488 as is, after adjusting glyph positions. No need to compute
11489 the window end again, since its offset from Z hasn't changed. */
11490 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11491 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11492 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11494 /* Adjust positions in the glyph matrix. */
11495 if (delta
|| delta_bytes
)
11497 struct glyph_row
*r1
11498 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11499 increment_matrix_positions (w
->current_matrix
,
11500 MATRIX_ROW_VPOS (r0
, current_matrix
),
11501 MATRIX_ROW_VPOS (r1
, current_matrix
),
11502 delta
, delta_bytes
);
11505 /* Set the cursor. */
11506 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11507 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11512 /* Handle the case that changes are all below what is displayed in
11513 the window, and that PT is in the window. This shortcut cannot
11514 be taken if ZV is visible in the window, and text has been added
11515 there that is visible in the window. */
11516 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11517 /* ZV is not visible in the window, or there are no
11518 changes at ZV, actually. */
11519 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11520 || first_changed_charpos
== last_changed_charpos
))
11522 struct glyph_row
*r0
;
11524 /* Give up if PT is not in the window. Note that it already has
11525 been checked at the start of try_window_id that PT is not in
11526 front of the window start. */
11527 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11530 /* If window start is unchanged, we can reuse the whole matrix
11531 as is, without changing glyph positions since no text has
11532 been added/removed in front of the window end. */
11533 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11534 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11536 /* We have to compute the window end anew since text
11537 can have been added/removed after it. */
11539 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11540 w
->window_end_bytepos
11541 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11543 /* Set the cursor. */
11544 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11545 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11550 /* Give up if window start is in the changed area.
11552 The condition used to read
11554 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11556 but why that was tested escapes me at the moment. */
11557 if (CHARPOS (start
) >= first_changed_charpos
11558 && CHARPOS (start
) <= last_changed_charpos
)
11561 /* Check that window start agrees with the start of the first glyph
11562 row in its current matrix. Check this after we know the window
11563 start is not in changed text, otherwise positions would not be
11565 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11566 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11569 /* Give up if the window ends in strings. Overlay strings
11570 at the end are difficult to handle, so don't try. */
11571 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
11572 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
11575 /* Compute the position at which we have to start displaying new
11576 lines. Some of the lines at the top of the window might be
11577 reusable because they are not displaying changed text. Find the
11578 last row in W's current matrix not affected by changes at the
11579 start of current_buffer. Value is null if changes start in the
11580 first line of window. */
11581 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11582 if (last_unchanged_at_beg_row
)
11584 /* Avoid starting to display in the moddle of a character, a TAB
11585 for instance. This is easier than to set up the iterator
11586 exactly, and it's not a frequent case, so the additional
11587 effort wouldn't really pay off. */
11588 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11589 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
11590 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11591 --last_unchanged_at_beg_row
;
11593 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11596 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11598 start_pos
= it
.current
.pos
;
11600 /* Start displaying new lines in the desired matrix at the same
11601 vpos we would use in the current matrix, i.e. below
11602 last_unchanged_at_beg_row. */
11603 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11605 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11606 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11608 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11612 /* There are no reusable lines at the start of the window.
11613 Start displaying in the first line. */
11614 start_display (&it
, w
, start
);
11615 start_pos
= it
.current
.pos
;
11618 /* Find the first row that is not affected by changes at the end of
11619 the buffer. Value will be null if there is no unchanged row, in
11620 which case we must redisplay to the end of the window. delta
11621 will be set to the value by which buffer positions beginning with
11622 first_unchanged_at_end_row have to be adjusted due to text
11624 first_unchanged_at_end_row
11625 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11626 IF_DEBUG (debug_delta
= delta
);
11627 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11629 /* Set stop_pos to the buffer position up to which we will have to
11630 display new lines. If first_unchanged_at_end_row != NULL, this
11631 is the buffer position of the start of the line displayed in that
11632 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11633 that we don't stop at a buffer position. */
11635 if (first_unchanged_at_end_row
)
11637 xassert (last_unchanged_at_beg_row
== NULL
11638 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11640 /* If this is a continuation line, move forward to the next one
11641 that isn't. Changes in lines above affect this line.
11642 Caution: this may move first_unchanged_at_end_row to a row
11643 not displaying text. */
11644 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11645 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11646 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11647 < it
.last_visible_y
))
11648 ++first_unchanged_at_end_row
;
11650 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11651 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11652 >= it
.last_visible_y
))
11653 first_unchanged_at_end_row
= NULL
;
11656 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11658 first_unchanged_at_end_vpos
11659 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11660 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11663 else if (last_unchanged_at_beg_row
== NULL
)
11669 /* Either there is no unchanged row at the end, or the one we have
11670 now displays text. This is a necessary condition for the window
11671 end pos calculation at the end of this function. */
11672 xassert (first_unchanged_at_end_row
== NULL
11673 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11675 debug_last_unchanged_at_beg_vpos
11676 = (last_unchanged_at_beg_row
11677 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11679 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11681 #endif /* GLYPH_DEBUG != 0 */
11684 /* Display new lines. Set last_text_row to the last new line
11685 displayed which has text on it, i.e. might end up as being the
11686 line where the window_end_vpos is. */
11687 w
->cursor
.vpos
= -1;
11688 last_text_row
= NULL
;
11689 overlay_arrow_seen
= 0;
11690 while (it
.current_y
< it
.last_visible_y
11691 && !fonts_changed_p
11692 && (first_unchanged_at_end_row
== NULL
11693 || IT_CHARPOS (it
) < stop_pos
))
11695 if (display_line (&it
))
11696 last_text_row
= it
.glyph_row
- 1;
11699 if (fonts_changed_p
)
11703 /* Compute differences in buffer positions, y-positions etc. for
11704 lines reused at the bottom of the window. Compute what we can
11706 if (first_unchanged_at_end_row
11707 /* No lines reused because we displayed everything up to the
11708 bottom of the window. */
11709 && it
.current_y
< it
.last_visible_y
)
11712 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11714 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11715 run
.current_y
= first_unchanged_at_end_row
->y
;
11716 run
.desired_y
= run
.current_y
+ dy
;
11717 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11721 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11722 first_unchanged_at_end_row
= NULL
;
11724 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11727 /* Find the cursor if not already found. We have to decide whether
11728 PT will appear on this window (it sometimes doesn't, but this is
11729 not a very frequent case.) This decision has to be made before
11730 the current matrix is altered. A value of cursor.vpos < 0 means
11731 that PT is either in one of the lines beginning at
11732 first_unchanged_at_end_row or below the window. Don't care for
11733 lines that might be displayed later at the window end; as
11734 mentioned, this is not a frequent case. */
11735 if (w
->cursor
.vpos
< 0)
11737 /* Cursor in unchanged rows at the top? */
11738 if (PT
< CHARPOS (start_pos
)
11739 && last_unchanged_at_beg_row
)
11741 row
= row_containing_pos (w
, PT
,
11742 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11743 last_unchanged_at_beg_row
+ 1, 0);
11745 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11748 /* Start from first_unchanged_at_end_row looking for PT. */
11749 else if (first_unchanged_at_end_row
)
11751 row
= row_containing_pos (w
, PT
- delta
,
11752 first_unchanged_at_end_row
, NULL
, 0);
11754 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11755 delta_bytes
, dy
, dvpos
);
11758 /* Give up if cursor was not found. */
11759 if (w
->cursor
.vpos
< 0)
11761 clear_glyph_matrix (w
->desired_matrix
);
11766 /* Don't let the cursor end in the scroll margins. */
11768 int this_scroll_margin
, cursor_height
;
11770 this_scroll_margin
= max (0, scroll_margin
);
11771 this_scroll_margin
= min (this_scroll_margin
,
11772 XFASTINT (w
->height
) / 4);
11773 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11774 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11776 if ((w
->cursor
.y
< this_scroll_margin
11777 && CHARPOS (start
) > BEGV
)
11778 /* Don't take scroll margin into account at the bottom because
11779 old redisplay didn't do it either. */
11780 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11782 w
->cursor
.vpos
= -1;
11783 clear_glyph_matrix (w
->desired_matrix
);
11788 /* Scroll the display. Do it before changing the current matrix so
11789 that xterm.c doesn't get confused about where the cursor glyph is
11791 if (dy
&& run
.height
)
11795 if (FRAME_WINDOW_P (f
))
11797 rif
->update_window_begin_hook (w
);
11798 rif
->clear_mouse_face (w
);
11799 rif
->scroll_run_hook (w
, &run
);
11800 rif
->update_window_end_hook (w
, 0, 0);
11804 /* Terminal frame. In this case, dvpos gives the number of
11805 lines to scroll by; dvpos < 0 means scroll up. */
11806 int first_unchanged_at_end_vpos
11807 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11808 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11809 int end
= (XFASTINT (w
->top
)
11810 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
11811 + window_internal_height (w
));
11813 /* Perform the operation on the screen. */
11816 /* Scroll last_unchanged_at_beg_row to the end of the
11817 window down dvpos lines. */
11818 set_terminal_window (end
);
11820 /* On dumb terminals delete dvpos lines at the end
11821 before inserting dvpos empty lines. */
11822 if (!scroll_region_ok
)
11823 ins_del_lines (end
- dvpos
, -dvpos
);
11825 /* Insert dvpos empty lines in front of
11826 last_unchanged_at_beg_row. */
11827 ins_del_lines (from
, dvpos
);
11829 else if (dvpos
< 0)
11831 /* Scroll up last_unchanged_at_beg_vpos to the end of
11832 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11833 set_terminal_window (end
);
11835 /* Delete dvpos lines in front of
11836 last_unchanged_at_beg_vpos. ins_del_lines will set
11837 the cursor to the given vpos and emit |dvpos| delete
11839 ins_del_lines (from
+ dvpos
, dvpos
);
11841 /* On a dumb terminal insert dvpos empty lines at the
11843 if (!scroll_region_ok
)
11844 ins_del_lines (end
+ dvpos
, -dvpos
);
11847 set_terminal_window (0);
11853 /* Shift reused rows of the current matrix to the right position.
11854 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11856 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11857 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11860 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11861 bottom_vpos
, dvpos
);
11862 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11865 else if (dvpos
> 0)
11867 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11868 bottom_vpos
, dvpos
);
11869 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11870 first_unchanged_at_end_vpos
+ dvpos
, 0);
11873 /* For frame-based redisplay, make sure that current frame and window
11874 matrix are in sync with respect to glyph memory. */
11875 if (!FRAME_WINDOW_P (f
))
11876 sync_frame_with_window_matrix_rows (w
);
11878 /* Adjust buffer positions in reused rows. */
11880 increment_matrix_positions (current_matrix
,
11881 first_unchanged_at_end_vpos
+ dvpos
,
11882 bottom_vpos
, delta
, delta_bytes
);
11884 /* Adjust Y positions. */
11886 shift_glyph_matrix (w
, current_matrix
,
11887 first_unchanged_at_end_vpos
+ dvpos
,
11890 if (first_unchanged_at_end_row
)
11891 first_unchanged_at_end_row
+= dvpos
;
11893 /* If scrolling up, there may be some lines to display at the end of
11895 last_text_row_at_end
= NULL
;
11898 /* Scrolling up can leave for example a partially visible line
11899 at the end of the window to be redisplayed. */
11900 /* Set last_row to the glyph row in the current matrix where the
11901 window end line is found. It has been moved up or down in
11902 the matrix by dvpos. */
11903 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11904 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11906 /* If last_row is the window end line, it should display text. */
11907 xassert (last_row
->displays_text_p
);
11909 /* If window end line was partially visible before, begin
11910 displaying at that line. Otherwise begin displaying with the
11911 line following it. */
11912 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11914 init_to_row_start (&it
, w
, last_row
);
11915 it
.vpos
= last_vpos
;
11916 it
.current_y
= last_row
->y
;
11920 init_to_row_end (&it
, w
, last_row
);
11921 it
.vpos
= 1 + last_vpos
;
11922 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11926 /* We may start in a continuation line. If so, we have to
11927 get the right continuation_lines_width and current_x. */
11928 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11929 it
.hpos
= it
.current_x
= 0;
11931 /* Display the rest of the lines at the window end. */
11932 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11933 while (it
.current_y
< it
.last_visible_y
11934 && !fonts_changed_p
)
11936 /* Is it always sure that the display agrees with lines in
11937 the current matrix? I don't think so, so we mark rows
11938 displayed invalid in the current matrix by setting their
11939 enabled_p flag to zero. */
11940 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11941 if (display_line (&it
))
11942 last_text_row_at_end
= it
.glyph_row
- 1;
11946 /* Update window_end_pos and window_end_vpos. */
11947 if (first_unchanged_at_end_row
11948 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11949 && !last_text_row_at_end
)
11951 /* Window end line if one of the preserved rows from the current
11952 matrix. Set row to the last row displaying text in current
11953 matrix starting at first_unchanged_at_end_row, after
11955 xassert (first_unchanged_at_end_row
->displays_text_p
);
11956 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11957 first_unchanged_at_end_row
);
11958 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11960 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11961 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11963 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11964 xassert (w
->window_end_bytepos
>= 0);
11965 IF_DEBUG (debug_method_add (w
, "A"));
11967 else if (last_text_row_at_end
)
11970 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11971 w
->window_end_bytepos
11972 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11974 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11975 xassert (w
->window_end_bytepos
>= 0);
11976 IF_DEBUG (debug_method_add (w
, "B"));
11978 else if (last_text_row
)
11980 /* We have displayed either to the end of the window or at the
11981 end of the window, i.e. the last row with text is to be found
11982 in the desired matrix. */
11984 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11985 w
->window_end_bytepos
11986 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11988 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11989 xassert (w
->window_end_bytepos
>= 0);
11991 else if (first_unchanged_at_end_row
== NULL
11992 && last_text_row
== NULL
11993 && last_text_row_at_end
== NULL
)
11995 /* Displayed to end of window, but no line containing text was
11996 displayed. Lines were deleted at the end of the window. */
11997 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11998 int vpos
= XFASTINT (w
->window_end_vpos
);
11999 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
12000 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
12003 row
== NULL
&& vpos
>= first_vpos
;
12004 --vpos
, --current_row
, --desired_row
)
12006 if (desired_row
->enabled_p
)
12008 if (desired_row
->displays_text_p
)
12011 else if (current_row
->displays_text_p
)
12015 xassert (row
!= NULL
);
12016 w
->window_end_vpos
= make_number (vpos
+ 1);
12017 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12018 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12019 xassert (w
->window_end_bytepos
>= 0);
12020 IF_DEBUG (debug_method_add (w
, "C"));
12025 #if 0 /* This leads to problems, for instance when the cursor is
12026 at ZV, and the cursor line displays no text. */
12027 /* Disable rows below what's displayed in the window. This makes
12028 debugging easier. */
12029 enable_glyph_matrix_rows (current_matrix
,
12030 XFASTINT (w
->window_end_vpos
) + 1,
12034 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
12035 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
12037 /* Record that display has not been completed. */
12038 w
->window_end_valid
= Qnil
;
12039 w
->desired_matrix
->no_scrolling_p
= 1;
12047 /***********************************************************************
12048 More debugging support
12049 ***********************************************************************/
12053 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
12054 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
12055 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
12058 /* Dump the contents of glyph matrix MATRIX on stderr.
12060 GLYPHS 0 means don't show glyph contents.
12061 GLYPHS 1 means show glyphs in short form
12062 GLYPHS > 1 means show glyphs in long form. */
12065 dump_glyph_matrix (matrix
, glyphs
)
12066 struct glyph_matrix
*matrix
;
12070 for (i
= 0; i
< matrix
->nrows
; ++i
)
12071 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12075 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12076 the glyph row and area where the glyph comes from. */
12079 dump_glyph (row
, glyph
, area
)
12080 struct glyph_row
*row
;
12081 struct glyph
*glyph
;
12084 if (glyph
->type
== CHAR_GLYPH
)
12087 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12088 glyph
- row
->glyphs
[TEXT_AREA
],
12091 (BUFFERP (glyph
->object
)
12093 : (STRINGP (glyph
->object
)
12096 glyph
->pixel_width
,
12098 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12102 glyph
->left_box_line_p
,
12103 glyph
->right_box_line_p
);
12105 else if (glyph
->type
== STRETCH_GLYPH
)
12108 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12109 glyph
- row
->glyphs
[TEXT_AREA
],
12112 (BUFFERP (glyph
->object
)
12114 : (STRINGP (glyph
->object
)
12117 glyph
->pixel_width
,
12121 glyph
->left_box_line_p
,
12122 glyph
->right_box_line_p
);
12124 else if (glyph
->type
== IMAGE_GLYPH
)
12127 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12128 glyph
- row
->glyphs
[TEXT_AREA
],
12131 (BUFFERP (glyph
->object
)
12133 : (STRINGP (glyph
->object
)
12136 glyph
->pixel_width
,
12140 glyph
->left_box_line_p
,
12141 glyph
->right_box_line_p
);
12146 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12147 GLYPHS 0 means don't show glyph contents.
12148 GLYPHS 1 means show glyphs in short form
12149 GLYPHS > 1 means show glyphs in long form. */
12152 dump_glyph_row (row
, vpos
, glyphs
)
12153 struct glyph_row
*row
;
12158 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12159 fprintf (stderr
, "=======================================================================\n");
12161 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12162 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12164 MATRIX_ROW_START_CHARPOS (row
),
12165 MATRIX_ROW_END_CHARPOS (row
),
12166 row
->used
[TEXT_AREA
],
12167 row
->contains_overlapping_glyphs_p
,
12169 row
->truncated_on_left_p
,
12170 row
->truncated_on_right_p
,
12171 row
->overlay_arrow_p
,
12173 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12174 row
->displays_text_p
,
12177 row
->ends_in_middle_of_char_p
,
12178 row
->starts_in_middle_of_char_p
,
12184 row
->visible_height
,
12187 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12188 row
->end
.overlay_string_index
,
12189 row
->continuation_lines_width
);
12190 fprintf (stderr
, "%9d %5d\n",
12191 CHARPOS (row
->start
.string_pos
),
12192 CHARPOS (row
->end
.string_pos
));
12193 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12194 row
->end
.dpvec_index
);
12201 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12203 struct glyph
*glyph
= row
->glyphs
[area
];
12204 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12206 /* Glyph for a line end in text. */
12207 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12210 if (glyph
< glyph_end
)
12211 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12213 for (; glyph
< glyph_end
; ++glyph
)
12214 dump_glyph (row
, glyph
, area
);
12217 else if (glyphs
== 1)
12221 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12223 char *s
= (char *) alloca (row
->used
[area
] + 1);
12226 for (i
= 0; i
< row
->used
[area
]; ++i
)
12228 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12229 if (glyph
->type
== CHAR_GLYPH
12230 && glyph
->u
.ch
< 0x80
12231 && glyph
->u
.ch
>= ' ')
12232 s
[i
] = glyph
->u
.ch
;
12238 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12244 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12245 Sdump_glyph_matrix
, 0, 1, "p",
12246 doc
: /* Dump the current matrix of the selected window to stderr.
12247 Shows contents of glyph row structures. With non-nil
12248 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12249 glyphs in short form, otherwise show glyphs in long form. */)
12251 Lisp_Object glyphs
;
12253 struct window
*w
= XWINDOW (selected_window
);
12254 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12256 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12257 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12258 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12259 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12260 fprintf (stderr
, "=============================================\n");
12261 dump_glyph_matrix (w
->current_matrix
,
12262 NILP (glyphs
) ? 0 : XINT (glyphs
));
12267 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12268 doc
: /* Dump glyph row ROW to stderr.
12269 GLYPH 0 means don't dump glyphs.
12270 GLYPH 1 means dump glyphs in short form.
12271 GLYPH > 1 or omitted means dump glyphs in long form. */)
12273 Lisp_Object row
, glyphs
;
12275 struct glyph_matrix
*matrix
;
12278 CHECK_NUMBER (row
);
12279 matrix
= XWINDOW (selected_window
)->current_matrix
;
12281 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12282 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12284 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12289 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12290 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12291 GLYPH 0 means don't dump glyphs.
12292 GLYPH 1 means dump glyphs in short form.
12293 GLYPH > 1 or omitted means dump glyphs in long form. */)
12295 Lisp_Object row
, glyphs
;
12297 struct frame
*sf
= SELECTED_FRAME ();
12298 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12301 CHECK_NUMBER (row
);
12303 if (vpos
>= 0 && vpos
< m
->nrows
)
12304 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12305 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12310 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12311 doc
: /* Toggle tracing of redisplay.
12312 With ARG, turn tracing on if and only if ARG is positive. */)
12317 trace_redisplay_p
= !trace_redisplay_p
;
12320 arg
= Fprefix_numeric_value (arg
);
12321 trace_redisplay_p
= XINT (arg
) > 0;
12328 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12329 doc
: /* Like `format', but print result to stderr. */)
12334 Lisp_Object s
= Fformat (nargs
, args
);
12335 fprintf (stderr
, "%s", XSTRING (s
)->data
);
12339 #endif /* GLYPH_DEBUG */
12343 /***********************************************************************
12344 Building Desired Matrix Rows
12345 ***********************************************************************/
12347 /* Return a temporary glyph row holding the glyphs of an overlay
12348 arrow. Only used for non-window-redisplay windows. */
12350 static struct glyph_row
*
12351 get_overlay_arrow_glyph_row (w
)
12354 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12355 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12356 struct buffer
*old
= current_buffer
;
12357 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
12358 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
12359 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12363 int n_glyphs_before
;
12365 set_buffer_temp (buffer
);
12366 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12367 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12368 SET_TEXT_POS (it
.position
, 0, 0);
12370 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12372 while (p
< arrow_end
)
12374 Lisp_Object face
, ilisp
;
12376 /* Get the next character. */
12378 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12380 it
.c
= *p
, it
.len
= 1;
12383 /* Get its face. */
12384 ilisp
= make_number (p
- arrow_string
);
12385 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12386 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12388 /* Compute its width, get its glyphs. */
12389 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12390 SET_TEXT_POS (it
.position
, -1, -1);
12391 PRODUCE_GLYPHS (&it
);
12393 /* If this character doesn't fit any more in the line, we have
12394 to remove some glyphs. */
12395 if (it
.current_x
> it
.last_visible_x
)
12397 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12402 set_buffer_temp (old
);
12403 return it
.glyph_row
;
12407 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12408 glyphs are only inserted for terminal frames since we can't really
12409 win with truncation glyphs when partially visible glyphs are
12410 involved. Which glyphs to insert is determined by
12411 produce_special_glyphs. */
12414 insert_left_trunc_glyphs (it
)
12417 struct it truncate_it
;
12418 struct glyph
*from
, *end
, *to
, *toend
;
12420 xassert (!FRAME_WINDOW_P (it
->f
));
12422 /* Get the truncation glyphs. */
12424 truncate_it
.current_x
= 0;
12425 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12426 truncate_it
.glyph_row
= &scratch_glyph_row
;
12427 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12428 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12429 truncate_it
.object
= make_number (0);
12430 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12432 /* Overwrite glyphs from IT with truncation glyphs. */
12433 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12434 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12435 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12436 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12441 /* There may be padding glyphs left over. Overwrite them too. */
12442 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12444 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12450 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12454 /* Compute the pixel height and width of IT->glyph_row.
12456 Most of the time, ascent and height of a display line will be equal
12457 to the max_ascent and max_height values of the display iterator
12458 structure. This is not the case if
12460 1. We hit ZV without displaying anything. In this case, max_ascent
12461 and max_height will be zero.
12463 2. We have some glyphs that don't contribute to the line height.
12464 (The glyph row flag contributes_to_line_height_p is for future
12465 pixmap extensions).
12467 The first case is easily covered by using default values because in
12468 these cases, the line height does not really matter, except that it
12469 must not be zero. */
12472 compute_line_metrics (it
)
12475 struct glyph_row
*row
= it
->glyph_row
;
12478 if (FRAME_WINDOW_P (it
->f
))
12480 int i
, min_y
, max_y
;
12482 /* The line may consist of one space only, that was added to
12483 place the cursor on it. If so, the row's height hasn't been
12485 if (row
->height
== 0)
12487 if (it
->max_ascent
+ it
->max_descent
== 0)
12488 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12489 row
->ascent
= it
->max_ascent
;
12490 row
->height
= it
->max_ascent
+ it
->max_descent
;
12491 row
->phys_ascent
= it
->max_phys_ascent
;
12492 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12495 /* Compute the width of this line. */
12496 row
->pixel_width
= row
->x
;
12497 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12498 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12500 xassert (row
->pixel_width
>= 0);
12501 xassert (row
->ascent
>= 0 && row
->height
> 0);
12503 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12504 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12506 /* If first line's physical ascent is larger than its logical
12507 ascent, use the physical ascent, and make the row taller.
12508 This makes accented characters fully visible. */
12509 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12510 && row
->phys_ascent
> row
->ascent
)
12512 row
->height
+= row
->phys_ascent
- row
->ascent
;
12513 row
->ascent
= row
->phys_ascent
;
12516 /* Compute how much of the line is visible. */
12517 row
->visible_height
= row
->height
;
12519 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12520 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12522 if (row
->y
< min_y
)
12523 row
->visible_height
-= min_y
- row
->y
;
12524 if (row
->y
+ row
->height
> max_y
)
12525 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12529 row
->pixel_width
= row
->used
[TEXT_AREA
];
12530 if (row
->continued_p
)
12531 row
->pixel_width
-= it
->continuation_pixel_width
;
12532 else if (row
->truncated_on_right_p
)
12533 row
->pixel_width
-= it
->truncation_pixel_width
;
12534 row
->ascent
= row
->phys_ascent
= 0;
12535 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12538 /* Compute a hash code for this row. */
12540 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12541 for (i
= 0; i
< row
->used
[area
]; ++i
)
12542 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12543 + row
->glyphs
[area
][i
].u
.val
12544 + row
->glyphs
[area
][i
].face_id
12545 + row
->glyphs
[area
][i
].padding_p
12546 + (row
->glyphs
[area
][i
].type
<< 2));
12548 it
->max_ascent
= it
->max_descent
= 0;
12549 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12553 /* Append one space to the glyph row of iterator IT if doing a
12554 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12555 space have the default face, otherwise let it have the same face as
12556 IT->face_id. Value is non-zero if a space was added.
12558 This function is called to make sure that there is always one glyph
12559 at the end of a glyph row that the cursor can be set on under
12560 window-systems. (If there weren't such a glyph we would not know
12561 how wide and tall a box cursor should be displayed).
12563 At the same time this space let's a nicely handle clearing to the
12564 end of the line if the row ends in italic text. */
12567 append_space (it
, default_face_p
)
12569 int default_face_p
;
12571 if (FRAME_WINDOW_P (it
->f
))
12573 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12575 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12576 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12578 /* Save some values that must not be changed.
12579 Must save IT->c and IT->len because otherwise
12580 ITERATOR_AT_END_P wouldn't work anymore after
12581 append_space has been called. */
12582 enum display_element_type saved_what
= it
->what
;
12583 int saved_c
= it
->c
, saved_len
= it
->len
;
12584 int saved_x
= it
->current_x
;
12585 int saved_face_id
= it
->face_id
;
12586 struct text_pos saved_pos
;
12587 Lisp_Object saved_object
;
12590 saved_object
= it
->object
;
12591 saved_pos
= it
->position
;
12593 it
->what
= IT_CHARACTER
;
12594 bzero (&it
->position
, sizeof it
->position
);
12595 it
->object
= make_number (0);
12599 if (default_face_p
)
12600 it
->face_id
= DEFAULT_FACE_ID
;
12601 else if (it
->face_before_selective_p
)
12602 it
->face_id
= it
->saved_face_id
;
12603 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12604 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12606 PRODUCE_GLYPHS (it
);
12608 it
->current_x
= saved_x
;
12609 it
->object
= saved_object
;
12610 it
->position
= saved_pos
;
12611 it
->what
= saved_what
;
12612 it
->face_id
= saved_face_id
;
12613 it
->len
= saved_len
;
12623 /* Extend the face of the last glyph in the text area of IT->glyph_row
12624 to the end of the display line. Called from display_line.
12625 If the glyph row is empty, add a space glyph to it so that we
12626 know the face to draw. Set the glyph row flag fill_line_p. */
12629 extend_face_to_end_of_line (it
)
12633 struct frame
*f
= it
->f
;
12635 /* If line is already filled, do nothing. */
12636 if (it
->current_x
>= it
->last_visible_x
)
12639 /* Face extension extends the background and box of IT->face_id
12640 to the end of the line. If the background equals the background
12641 of the frame, we don't have to do anything. */
12642 if (it
->face_before_selective_p
)
12643 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12645 face
= FACE_FROM_ID (f
, it
->face_id
);
12647 if (FRAME_WINDOW_P (f
)
12648 && face
->box
== FACE_NO_BOX
12649 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12653 /* Set the glyph row flag indicating that the face of the last glyph
12654 in the text area has to be drawn to the end of the text area. */
12655 it
->glyph_row
->fill_line_p
= 1;
12657 /* If current character of IT is not ASCII, make sure we have the
12658 ASCII face. This will be automatically undone the next time
12659 get_next_display_element returns a multibyte character. Note
12660 that the character will always be single byte in unibyte text. */
12661 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12663 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12666 if (FRAME_WINDOW_P (f
))
12668 /* If the row is empty, add a space with the current face of IT,
12669 so that we know which face to draw. */
12670 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12672 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12673 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12674 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12679 /* Save some values that must not be changed. */
12680 int saved_x
= it
->current_x
;
12681 struct text_pos saved_pos
;
12682 Lisp_Object saved_object
;
12683 enum display_element_type saved_what
= it
->what
;
12684 int saved_face_id
= it
->face_id
;
12686 saved_object
= it
->object
;
12687 saved_pos
= it
->position
;
12689 it
->what
= IT_CHARACTER
;
12690 bzero (&it
->position
, sizeof it
->position
);
12691 it
->object
= make_number (0);
12694 it
->face_id
= face
->id
;
12696 PRODUCE_GLYPHS (it
);
12698 while (it
->current_x
<= it
->last_visible_x
)
12699 PRODUCE_GLYPHS (it
);
12701 /* Don't count these blanks really. It would let us insert a left
12702 truncation glyph below and make us set the cursor on them, maybe. */
12703 it
->current_x
= saved_x
;
12704 it
->object
= saved_object
;
12705 it
->position
= saved_pos
;
12706 it
->what
= saved_what
;
12707 it
->face_id
= saved_face_id
;
12712 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12713 trailing whitespace. */
12716 trailing_whitespace_p (charpos
)
12719 int bytepos
= CHAR_TO_BYTE (charpos
);
12722 while (bytepos
< ZV_BYTE
12723 && (c
= FETCH_CHAR (bytepos
),
12724 c
== ' ' || c
== '\t'))
12727 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12729 if (bytepos
!= PT_BYTE
)
12736 /* Highlight trailing whitespace, if any, in ROW. */
12739 highlight_trailing_whitespace (f
, row
)
12741 struct glyph_row
*row
;
12743 int used
= row
->used
[TEXT_AREA
];
12747 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12748 struct glyph
*glyph
= start
+ used
- 1;
12750 /* Skip over glyphs inserted to display the cursor at the
12751 end of a line, for extending the face of the last glyph
12752 to the end of the line on terminals, and for truncation
12753 and continuation glyphs. */
12754 while (glyph
>= start
12755 && glyph
->type
== CHAR_GLYPH
12756 && INTEGERP (glyph
->object
))
12759 /* If last glyph is a space or stretch, and it's trailing
12760 whitespace, set the face of all trailing whitespace glyphs in
12761 IT->glyph_row to `trailing-whitespace'. */
12763 && BUFFERP (glyph
->object
)
12764 && (glyph
->type
== STRETCH_GLYPH
12765 || (glyph
->type
== CHAR_GLYPH
12766 && glyph
->u
.ch
== ' '))
12767 && trailing_whitespace_p (glyph
->charpos
))
12769 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12771 while (glyph
>= start
12772 && BUFFERP (glyph
->object
)
12773 && (glyph
->type
== STRETCH_GLYPH
12774 || (glyph
->type
== CHAR_GLYPH
12775 && glyph
->u
.ch
== ' ')))
12776 (glyph
--)->face_id
= face_id
;
12782 /* Value is non-zero if glyph row ROW in window W should be
12783 used to hold the cursor. */
12786 cursor_row_p (w
, row
)
12788 struct glyph_row
*row
;
12790 int cursor_row_p
= 1;
12792 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12794 /* If the row ends with a newline from a string, we don't want
12795 the cursor there (if the row is continued it doesn't end in a
12797 if (CHARPOS (row
->end
.string_pos
) >= 0
12798 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12799 cursor_row_p
= row
->continued_p
;
12801 /* If the row ends at ZV, display the cursor at the end of that
12802 row instead of at the start of the row below. */
12803 else if (row
->ends_at_zv_p
)
12809 return cursor_row_p
;
12813 /* Construct the glyph row IT->glyph_row in the desired matrix of
12814 IT->w from text at the current position of IT. See dispextern.h
12815 for an overview of struct it. Value is non-zero if
12816 IT->glyph_row displays text, as opposed to a line displaying ZV
12823 struct glyph_row
*row
= it
->glyph_row
;
12825 /* We always start displaying at hpos zero even if hscrolled. */
12826 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12828 /* We must not display in a row that's not a text row. */
12829 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12830 < it
->w
->desired_matrix
->nrows
);
12832 /* Is IT->w showing the region? */
12833 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12835 /* Clear the result glyph row and enable it. */
12836 prepare_desired_row (row
);
12838 row
->y
= it
->current_y
;
12839 row
->start
= it
->current
;
12840 row
->continuation_lines_width
= it
->continuation_lines_width
;
12841 row
->displays_text_p
= 1;
12842 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12843 it
->starts_in_middle_of_char_p
= 0;
12845 /* Arrange the overlays nicely for our purposes. Usually, we call
12846 display_line on only one line at a time, in which case this
12847 can't really hurt too much, or we call it on lines which appear
12848 one after another in the buffer, in which case all calls to
12849 recenter_overlay_lists but the first will be pretty cheap. */
12850 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12852 /* Move over display elements that are not visible because we are
12853 hscrolled. This may stop at an x-position < IT->first_visible_x
12854 if the first glyph is partially visible or if we hit a line end. */
12855 if (it
->current_x
< it
->first_visible_x
)
12856 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12857 MOVE_TO_POS
| MOVE_TO_X
);
12859 /* Get the initial row height. This is either the height of the
12860 text hscrolled, if there is any, or zero. */
12861 row
->ascent
= it
->max_ascent
;
12862 row
->height
= it
->max_ascent
+ it
->max_descent
;
12863 row
->phys_ascent
= it
->max_phys_ascent
;
12864 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12866 /* Loop generating characters. The loop is left with IT on the next
12867 character to display. */
12870 int n_glyphs_before
, hpos_before
, x_before
;
12872 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12874 /* Retrieve the next thing to display. Value is zero if end of
12876 if (!get_next_display_element (it
))
12878 /* Maybe add a space at the end of this line that is used to
12879 display the cursor there under X. Set the charpos of the
12880 first glyph of blank lines not corresponding to any text
12882 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12883 || row
->used
[TEXT_AREA
] == 0)
12885 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12886 row
->displays_text_p
= 0;
12888 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
12889 && (!MINI_WINDOW_P (it
->w
)
12890 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
12891 row
->indicate_empty_line_p
= 1;
12894 it
->continuation_lines_width
= 0;
12895 row
->ends_at_zv_p
= 1;
12899 /* Now, get the metrics of what we want to display. This also
12900 generates glyphs in `row' (which is IT->glyph_row). */
12901 n_glyphs_before
= row
->used
[TEXT_AREA
];
12904 /* Remember the line height so far in case the next element doesn't
12905 fit on the line. */
12906 if (!it
->truncate_lines_p
)
12908 ascent
= it
->max_ascent
;
12909 descent
= it
->max_descent
;
12910 phys_ascent
= it
->max_phys_ascent
;
12911 phys_descent
= it
->max_phys_descent
;
12914 PRODUCE_GLYPHS (it
);
12916 /* If this display element was in marginal areas, continue with
12918 if (it
->area
!= TEXT_AREA
)
12920 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12921 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12922 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12923 row
->phys_height
= max (row
->phys_height
,
12924 it
->max_phys_ascent
+ it
->max_phys_descent
);
12925 set_iterator_to_next (it
, 1);
12929 /* Does the display element fit on the line? If we truncate
12930 lines, we should draw past the right edge of the window. If
12931 we don't truncate, we want to stop so that we can display the
12932 continuation glyph before the right margin. If lines are
12933 continued, there are two possible strategies for characters
12934 resulting in more than 1 glyph (e.g. tabs): Display as many
12935 glyphs as possible in this line and leave the rest for the
12936 continuation line, or display the whole element in the next
12937 line. Original redisplay did the former, so we do it also. */
12938 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12939 hpos_before
= it
->hpos
;
12942 if (/* Not a newline. */
12944 /* Glyphs produced fit entirely in the line. */
12945 && it
->current_x
< it
->last_visible_x
)
12947 it
->hpos
+= nglyphs
;
12948 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12949 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12950 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12951 row
->phys_height
= max (row
->phys_height
,
12952 it
->max_phys_ascent
+ it
->max_phys_descent
);
12953 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
12954 row
->x
= x
- it
->first_visible_x
;
12959 struct glyph
*glyph
;
12961 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
12963 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12964 new_x
= x
+ glyph
->pixel_width
;
12966 if (/* Lines are continued. */
12967 !it
->truncate_lines_p
12968 && (/* Glyph doesn't fit on the line. */
12969 new_x
> it
->last_visible_x
12970 /* Or it fits exactly on a window system frame. */
12971 || (new_x
== it
->last_visible_x
12972 && FRAME_WINDOW_P (it
->f
))))
12974 /* End of a continued line. */
12977 || (new_x
== it
->last_visible_x
12978 && FRAME_WINDOW_P (it
->f
)))
12980 /* Current glyph is the only one on the line or
12981 fits exactly on the line. We must continue
12982 the line because we can't draw the cursor
12983 after the glyph. */
12984 row
->continued_p
= 1;
12985 it
->current_x
= new_x
;
12986 it
->continuation_lines_width
+= new_x
;
12988 if (i
== nglyphs
- 1)
12989 set_iterator_to_next (it
, 1);
12991 else if (CHAR_GLYPH_PADDING_P (*glyph
)
12992 && !FRAME_WINDOW_P (it
->f
))
12994 /* A padding glyph that doesn't fit on this line.
12995 This means the whole character doesn't fit
12997 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12999 /* Fill the rest of the row with continuation
13000 glyphs like in 20.x. */
13001 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
13002 < row
->glyphs
[1 + TEXT_AREA
])
13003 produce_special_glyphs (it
, IT_CONTINUATION
);
13005 row
->continued_p
= 1;
13006 it
->current_x
= x_before
;
13007 it
->continuation_lines_width
+= x_before
;
13009 /* Restore the height to what it was before the
13010 element not fitting on the line. */
13011 it
->max_ascent
= ascent
;
13012 it
->max_descent
= descent
;
13013 it
->max_phys_ascent
= phys_ascent
;
13014 it
->max_phys_descent
= phys_descent
;
13016 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
13018 /* A TAB that extends past the right edge of the
13019 window. This produces a single glyph on
13020 window system frames. We leave the glyph in
13021 this row and let it fill the row, but don't
13022 consume the TAB. */
13023 it
->continuation_lines_width
+= it
->last_visible_x
;
13024 row
->ends_in_middle_of_char_p
= 1;
13025 row
->continued_p
= 1;
13026 glyph
->pixel_width
= it
->last_visible_x
- x
;
13027 it
->starts_in_middle_of_char_p
= 1;
13031 /* Something other than a TAB that draws past
13032 the right edge of the window. Restore
13033 positions to values before the element. */
13034 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13036 /* Display continuation glyphs. */
13037 if (!FRAME_WINDOW_P (it
->f
))
13038 produce_special_glyphs (it
, IT_CONTINUATION
);
13039 row
->continued_p
= 1;
13041 it
->continuation_lines_width
+= x
;
13043 if (nglyphs
> 1 && i
> 0)
13045 row
->ends_in_middle_of_char_p
= 1;
13046 it
->starts_in_middle_of_char_p
= 1;
13049 /* Restore the height to what it was before the
13050 element not fitting on the line. */
13051 it
->max_ascent
= ascent
;
13052 it
->max_descent
= descent
;
13053 it
->max_phys_ascent
= phys_ascent
;
13054 it
->max_phys_descent
= phys_descent
;
13059 else if (new_x
> it
->first_visible_x
)
13061 /* Increment number of glyphs actually displayed. */
13064 if (x
< it
->first_visible_x
)
13065 /* Glyph is partially visible, i.e. row starts at
13066 negative X position. */
13067 row
->x
= x
- it
->first_visible_x
;
13071 /* Glyph is completely off the left margin of the
13072 window. This should not happen because of the
13073 move_it_in_display_line at the start of
13079 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13080 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13081 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13082 row
->phys_height
= max (row
->phys_height
,
13083 it
->max_phys_ascent
+ it
->max_phys_descent
);
13085 /* End of this display line if row is continued. */
13086 if (row
->continued_p
)
13090 /* Is this a line end? If yes, we're also done, after making
13091 sure that a non-default face is extended up to the right
13092 margin of the window. */
13093 if (ITERATOR_AT_END_OF_LINE_P (it
))
13095 int used_before
= row
->used
[TEXT_AREA
];
13097 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13099 /* Add a space at the end of the line that is used to
13100 display the cursor there. */
13101 append_space (it
, 0);
13103 /* Extend the face to the end of the line. */
13104 extend_face_to_end_of_line (it
);
13106 /* Make sure we have the position. */
13107 if (used_before
== 0)
13108 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13110 /* Consume the line end. This skips over invisible lines. */
13111 set_iterator_to_next (it
, 1);
13112 it
->continuation_lines_width
= 0;
13116 /* Proceed with next display element. Note that this skips
13117 over lines invisible because of selective display. */
13118 set_iterator_to_next (it
, 1);
13120 /* If we truncate lines, we are done when the last displayed
13121 glyphs reach past the right margin of the window. */
13122 if (it
->truncate_lines_p
13123 && (FRAME_WINDOW_P (it
->f
)
13124 ? (it
->current_x
>= it
->last_visible_x
)
13125 : (it
->current_x
> it
->last_visible_x
)))
13127 /* Maybe add truncation glyphs. */
13128 if (!FRAME_WINDOW_P (it
->f
))
13132 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13133 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13136 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13138 row
->used
[TEXT_AREA
] = i
;
13139 produce_special_glyphs (it
, IT_TRUNCATION
);
13143 row
->truncated_on_right_p
= 1;
13144 it
->continuation_lines_width
= 0;
13145 reseat_at_next_visible_line_start (it
, 0);
13146 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13147 it
->hpos
= hpos_before
;
13148 it
->current_x
= x_before
;
13153 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13154 at the left window margin. */
13155 if (it
->first_visible_x
13156 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13158 if (!FRAME_WINDOW_P (it
->f
))
13159 insert_left_trunc_glyphs (it
);
13160 row
->truncated_on_left_p
= 1;
13163 /* If the start of this line is the overlay arrow-position, then
13164 mark this glyph row as the one containing the overlay arrow.
13165 This is clearly a mess with variable size fonts. It would be
13166 better to let it be displayed like cursors under X. */
13167 if (MARKERP (Voverlay_arrow_position
)
13168 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13169 && (MATRIX_ROW_START_CHARPOS (row
)
13170 == marker_position (Voverlay_arrow_position
))
13171 && STRINGP (Voverlay_arrow_string
)
13172 && ! overlay_arrow_seen
)
13174 /* Overlay arrow in window redisplay is a fringe bitmap. */
13175 if (!FRAME_WINDOW_P (it
->f
))
13177 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13178 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13179 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13180 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13181 struct glyph
*p2
, *end
;
13183 /* Copy the arrow glyphs. */
13184 while (glyph
< arrow_end
)
13187 /* Throw away padding glyphs. */
13189 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13190 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13196 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13200 overlay_arrow_seen
= 1;
13201 row
->overlay_arrow_p
= 1;
13204 /* Compute pixel dimensions of this line. */
13205 compute_line_metrics (it
);
13207 /* Remember the position at which this line ends. */
13208 row
->end
= it
->current
;
13210 /* Maybe set the cursor. */
13211 if (it
->w
->cursor
.vpos
< 0
13212 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13213 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13214 && cursor_row_p (it
->w
, row
))
13215 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13217 /* Highlight trailing whitespace. */
13218 if (!NILP (Vshow_trailing_whitespace
))
13219 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13221 /* Prepare for the next line. This line starts horizontally at (X
13222 HPOS) = (0 0). Vertical positions are incremented. As a
13223 convenience for the caller, IT->glyph_row is set to the next
13225 it
->current_x
= it
->hpos
= 0;
13226 it
->current_y
+= row
->height
;
13229 return row
->displays_text_p
;
13234 /***********************************************************************
13236 ***********************************************************************/
13238 /* Redisplay the menu bar in the frame for window W.
13240 The menu bar of X frames that don't have X toolkit support is
13241 displayed in a special window W->frame->menu_bar_window.
13243 The menu bar of terminal frames is treated specially as far as
13244 glyph matrices are concerned. Menu bar lines are not part of
13245 windows, so the update is done directly on the frame matrix rows
13246 for the menu bar. */
13249 display_menu_bar (w
)
13252 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13257 /* Don't do all this for graphical frames. */
13259 if (!NILP (Vwindow_system
))
13262 #ifdef USE_X_TOOLKIT
13267 if (FRAME_MAC_P (f
))
13271 #ifdef USE_X_TOOLKIT
13272 xassert (!FRAME_WINDOW_P (f
));
13273 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13274 it
.first_visible_x
= 0;
13275 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13276 #else /* not USE_X_TOOLKIT */
13277 if (FRAME_WINDOW_P (f
))
13279 /* Menu bar lines are displayed in the desired matrix of the
13280 dummy window menu_bar_window. */
13281 struct window
*menu_w
;
13282 xassert (WINDOWP (f
->menu_bar_window
));
13283 menu_w
= XWINDOW (f
->menu_bar_window
);
13284 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13286 it
.first_visible_x
= 0;
13287 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13291 /* This is a TTY frame, i.e. character hpos/vpos are used as
13293 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13295 it
.first_visible_x
= 0;
13296 it
.last_visible_x
= FRAME_WIDTH (f
);
13298 #endif /* not USE_X_TOOLKIT */
13300 if (! mode_line_inverse_video
)
13301 /* Force the menu-bar to be displayed in the default face. */
13302 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13304 /* Clear all rows of the menu bar. */
13305 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13307 struct glyph_row
*row
= it
.glyph_row
+ i
;
13308 clear_glyph_row (row
);
13309 row
->enabled_p
= 1;
13310 row
->full_width_p
= 1;
13313 /* Display all items of the menu bar. */
13314 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13315 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13317 Lisp_Object string
;
13319 /* Stop at nil string. */
13320 string
= AREF (items
, i
+ 1);
13324 /* Remember where item was displayed. */
13325 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13327 /* Display the item, pad with one space. */
13328 if (it
.current_x
< it
.last_visible_x
)
13329 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13330 XSTRING (string
)->size
+ 1, 0, 0, -1);
13333 /* Fill out the line with spaces. */
13334 if (it
.current_x
< it
.last_visible_x
)
13335 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13337 /* Compute the total height of the lines. */
13338 compute_line_metrics (&it
);
13343 /***********************************************************************
13345 ***********************************************************************/
13347 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13348 FORCE is non-zero, redisplay mode lines unconditionally.
13349 Otherwise, redisplay only mode lines that are garbaged. Value is
13350 the number of windows whose mode lines were redisplayed. */
13353 redisplay_mode_lines (window
, force
)
13354 Lisp_Object window
;
13359 while (!NILP (window
))
13361 struct window
*w
= XWINDOW (window
);
13363 if (WINDOWP (w
->hchild
))
13364 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13365 else if (WINDOWP (w
->vchild
))
13366 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13368 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13369 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13371 struct text_pos lpoint
;
13372 struct buffer
*old
= current_buffer
;
13374 /* Set the window's buffer for the mode line display. */
13375 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13376 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13378 /* Point refers normally to the selected window. For any
13379 other window, set up appropriate value. */
13380 if (!EQ (window
, selected_window
))
13382 struct text_pos pt
;
13384 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13385 if (CHARPOS (pt
) < BEGV
)
13386 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13387 else if (CHARPOS (pt
) > (ZV
- 1))
13388 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13390 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13393 /* Display mode lines. */
13394 clear_glyph_matrix (w
->desired_matrix
);
13395 if (display_mode_lines (w
))
13398 w
->must_be_updated_p
= 1;
13401 /* Restore old settings. */
13402 set_buffer_internal_1 (old
);
13403 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13413 /* Display the mode and/or top line of window W. Value is the number
13414 of mode lines displayed. */
13417 display_mode_lines (w
)
13420 Lisp_Object old_selected_window
, old_selected_frame
;
13423 old_selected_frame
= selected_frame
;
13424 selected_frame
= w
->frame
;
13425 old_selected_window
= selected_window
;
13426 XSETWINDOW (selected_window
, w
);
13428 /* These will be set while the mode line specs are processed. */
13429 line_number_displayed
= 0;
13430 w
->column_number_displayed
= Qnil
;
13432 if (WINDOW_WANTS_MODELINE_P (w
))
13434 display_mode_line (w
, MODE_LINE_FACE_ID
,
13435 current_buffer
->mode_line_format
);
13439 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13441 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13442 current_buffer
->header_line_format
);
13446 selected_frame
= old_selected_frame
;
13447 selected_window
= old_selected_window
;
13452 /* Display mode or top line of window W. FACE_ID specifies which line
13453 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13454 FORMAT is the mode line format to display. Value is the pixel
13455 height of the mode line displayed. */
13458 display_mode_line (w
, face_id
, format
)
13460 enum face_id face_id
;
13461 Lisp_Object format
;
13466 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13467 prepare_desired_row (it
.glyph_row
);
13469 if (! mode_line_inverse_video
)
13470 /* Force the mode-line to be displayed in the default face. */
13471 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13473 /* Temporarily make frame's keyboard the current kboard so that
13474 kboard-local variables in the mode_line_format will get the right
13476 push_frame_kboard (it
.f
);
13477 display_mode_element (&it
, 0, 0, 0, format
);
13478 pop_frame_kboard ();
13480 /* Fill up with spaces. */
13481 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13483 compute_line_metrics (&it
);
13484 it
.glyph_row
->full_width_p
= 1;
13485 it
.glyph_row
->mode_line_p
= 1;
13486 it
.glyph_row
->continued_p
= 0;
13487 it
.glyph_row
->truncated_on_left_p
= 0;
13488 it
.glyph_row
->truncated_on_right_p
= 0;
13490 /* Make a 3D mode-line have a shadow at its right end. */
13491 face
= FACE_FROM_ID (it
.f
, face_id
);
13492 extend_face_to_end_of_line (&it
);
13493 if (face
->box
!= FACE_NO_BOX
)
13495 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13496 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13497 last
->right_box_line_p
= 1;
13500 return it
.glyph_row
->height
;
13504 /* Contribute ELT to the mode line for window IT->w. How it
13505 translates into text depends on its data type.
13507 IT describes the display environment in which we display, as usual.
13509 DEPTH is the depth in recursion. It is used to prevent
13510 infinite recursion here.
13512 FIELD_WIDTH is the number of characters the display of ELT should
13513 occupy in the mode line, and PRECISION is the maximum number of
13514 characters to display from ELT's representation. See
13515 display_string for details.
13517 Returns the hpos of the end of the text generated by ELT. */
13520 display_mode_element (it
, depth
, field_width
, precision
, elt
)
13523 int field_width
, precision
;
13526 int n
= 0, field
, prec
;
13534 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13538 /* A string: output it and check for %-constructs within it. */
13540 unsigned char *this = XSTRING (elt
)->data
;
13541 unsigned char *lisp_string
= this;
13543 while ((precision
<= 0 || n
< precision
)
13545 && (frame_title_ptr
13546 || it
->current_x
< it
->last_visible_x
))
13548 unsigned char *last
= this;
13550 /* Advance to end of string or next format specifier. */
13551 while ((c
= *this++) != '\0' && c
!= '%')
13554 if (this - 1 != last
)
13556 /* Output to end of string or up to '%'. Field width
13557 is length of string. Don't output more than
13558 PRECISION allows us. */
13561 prec
= chars_in_text (last
, this - last
);
13562 if (precision
> 0 && prec
> precision
- n
)
13563 prec
= precision
- n
;
13565 if (frame_title_ptr
)
13566 n
+= store_frame_title (last
, 0, prec
);
13569 int bytepos
= last
- lisp_string
;
13570 int charpos
= string_byte_to_char (elt
, bytepos
);
13571 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
13573 STRING_MULTIBYTE (elt
));
13576 else /* c == '%' */
13578 unsigned char *percent_position
= this;
13580 /* Get the specified minimum width. Zero means
13583 while ((c
= *this++) >= '0' && c
<= '9')
13584 field
= field
* 10 + c
- '0';
13586 /* Don't pad beyond the total padding allowed. */
13587 if (field_width
- n
> 0 && field
> field_width
- n
)
13588 field
= field_width
- n
;
13590 /* Note that either PRECISION <= 0 or N < PRECISION. */
13591 prec
= precision
- n
;
13594 n
+= display_mode_element (it
, depth
, field
, prec
,
13595 Vglobal_mode_string
);
13599 unsigned char *spec
13600 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
13602 if (frame_title_ptr
)
13603 n
+= store_frame_title (spec
, field
, prec
);
13606 int nglyphs_before
, bytepos
, charpos
, nwritten
;
13608 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13609 bytepos
= percent_position
- XSTRING (elt
)->data
;
13610 charpos
= (STRING_MULTIBYTE (elt
)
13611 ? string_byte_to_char (elt
, bytepos
)
13613 nwritten
= display_string (spec
, Qnil
, elt
,
13618 /* Assign to the glyphs written above the
13619 string where the `%x' came from, position
13623 struct glyph
*glyph
13624 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13628 for (i
= 0; i
< nwritten
; ++i
)
13630 glyph
[i
].object
= elt
;
13631 glyph
[i
].charpos
= charpos
;
13646 /* A symbol: process the value of the symbol recursively
13647 as if it appeared here directly. Avoid error if symbol void.
13648 Special case: if value of symbol is a string, output the string
13651 register Lisp_Object tem
;
13652 tem
= Fboundp (elt
);
13655 tem
= Fsymbol_value (elt
);
13656 /* If value is a string, output that string literally:
13657 don't check for % within it. */
13660 prec
= precision
- n
;
13661 if (frame_title_ptr
)
13662 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
13664 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
13665 0, prec
, 0, STRING_MULTIBYTE (tem
));
13667 else if (!EQ (tem
, elt
))
13669 /* Give up right away for nil or t. */
13679 register Lisp_Object car
, tem
;
13681 /* A cons cell: three distinct cases.
13682 If first element is a string or a cons, process all the elements
13683 and effectively concatenate them.
13684 If first element is a negative number, truncate displaying cdr to
13685 at most that many characters. If positive, pad (with spaces)
13686 to at least that many characters.
13687 If first element is a symbol, process the cadr or caddr recursively
13688 according to whether the symbol's value is non-nil or nil. */
13690 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
13692 /* An element of the form (:eval FORM) means evaluate FORM
13693 and use the result as mode line elements. */
13694 struct gcpro gcpro1
;
13697 spec
= safe_eval (XCAR (XCDR (elt
)));
13699 n
+= display_mode_element (it
, depth
, field_width
- n
,
13700 precision
- n
, spec
);
13703 else if (SYMBOLP (car
))
13705 tem
= Fboundp (car
);
13709 /* elt is now the cdr, and we know it is a cons cell.
13710 Use its car if CAR has a non-nil value. */
13713 tem
= Fsymbol_value (car
);
13720 /* Symbol's value is nil (or symbol is unbound)
13721 Get the cddr of the original list
13722 and if possible find the caddr and use that. */
13726 else if (!CONSP (elt
))
13731 else if (INTEGERP (car
))
13733 register int lim
= XINT (car
);
13737 /* Negative int means reduce maximum width. */
13738 if (precision
<= 0)
13741 precision
= min (precision
, -lim
);
13745 /* Padding specified. Don't let it be more than
13746 current maximum. */
13748 lim
= min (precision
, lim
);
13750 /* If that's more padding than already wanted, queue it.
13751 But don't reduce padding already specified even if
13752 that is beyond the current truncation point. */
13753 field_width
= max (lim
, field_width
);
13757 else if (STRINGP (car
) || CONSP (car
))
13759 register int limit
= 50;
13760 /* Limit is to protect against circular lists. */
13763 && (precision
<= 0 || n
< precision
))
13765 n
+= display_mode_element (it
, depth
, field_width
- n
,
13766 precision
- n
, XCAR (elt
));
13775 if (frame_title_ptr
)
13776 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13778 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13779 precision
- n
, 0, 0);
13783 /* Pad to FIELD_WIDTH. */
13784 if (field_width
> 0 && n
< field_width
)
13786 if (frame_title_ptr
)
13787 n
+= store_frame_title ("", field_width
- n
, 0);
13789 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13797 /* Write a null-terminated, right justified decimal representation of
13798 the positive integer D to BUF using a minimal field width WIDTH. */
13801 pint2str (buf
, width
, d
)
13802 register char *buf
;
13803 register int width
;
13806 register char *p
= buf
;
13814 *p
++ = d
% 10 + '0';
13819 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13830 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13831 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13832 type of CODING_SYSTEM. Return updated pointer into BUF. */
13834 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13837 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13838 Lisp_Object coding_system
;
13839 register char *buf
;
13843 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13844 unsigned char *eol_str
;
13846 /* The EOL conversion we are using. */
13847 Lisp_Object eoltype
;
13849 val
= Fget (coding_system
, Qcoding_system
);
13852 if (!VECTORP (val
)) /* Not yet decided. */
13857 eoltype
= eol_mnemonic_undecided
;
13858 /* Don't mention EOL conversion if it isn't decided. */
13862 Lisp_Object eolvalue
;
13864 eolvalue
= Fget (coding_system
, Qeol_type
);
13867 *buf
++ = XFASTINT (AREF (val
, 1));
13871 /* The EOL conversion that is normal on this system. */
13873 if (NILP (eolvalue
)) /* Not yet decided. */
13874 eoltype
= eol_mnemonic_undecided
;
13875 else if (VECTORP (eolvalue
)) /* Not yet decided. */
13876 eoltype
= eol_mnemonic_undecided
;
13877 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
13878 eoltype
= (XFASTINT (eolvalue
) == 0
13879 ? eol_mnemonic_unix
13880 : (XFASTINT (eolvalue
) == 1
13881 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
13887 /* Mention the EOL conversion if it is not the usual one. */
13888 if (STRINGP (eoltype
))
13890 eol_str
= XSTRING (eoltype
)->data
;
13891 eol_str_len
= XSTRING (eoltype
)->size
;
13893 else if (INTEGERP (eoltype
)
13894 && CHAR_VALID_P (XINT (eoltype
), 0))
13896 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
13897 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
13901 eol_str
= invalid_eol_type
;
13902 eol_str_len
= sizeof (invalid_eol_type
) - 1;
13904 bcopy (eol_str
, buf
, eol_str_len
);
13905 buf
+= eol_str_len
;
13911 /* Return a string for the output of a mode line %-spec for window W,
13912 generated by character C. PRECISION >= 0 means don't return a
13913 string longer than that value. FIELD_WIDTH > 0 means pad the
13914 string returned with spaces to that value. Return 1 in *MULTIBYTE
13915 if the result is multibyte text. */
13917 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
13920 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
13923 int field_width
, precision
;
13927 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13928 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
13929 struct buffer
*b
= XBUFFER (w
->buffer
);
13937 if (!NILP (b
->read_only
))
13939 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13944 /* This differs from %* only for a modified read-only buffer. */
13945 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13947 if (!NILP (b
->read_only
))
13952 /* This differs from %* in ignoring read-only-ness. */
13953 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13965 if (command_loop_level
> 5)
13967 p
= decode_mode_spec_buf
;
13968 for (i
= 0; i
< command_loop_level
; i
++)
13971 return decode_mode_spec_buf
;
13979 if (command_loop_level
> 5)
13981 p
= decode_mode_spec_buf
;
13982 for (i
= 0; i
< command_loop_level
; i
++)
13985 return decode_mode_spec_buf
;
13992 /* Let lots_of_dashes be a string of infinite length. */
13993 if (field_width
<= 0
13994 || field_width
> sizeof (lots_of_dashes
))
13996 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
13997 decode_mode_spec_buf
[i
] = '-';
13998 decode_mode_spec_buf
[i
] = '\0';
13999 return decode_mode_spec_buf
;
14002 return lots_of_dashes
;
14011 int col
= current_column ();
14012 w
->column_number_displayed
= make_number (col
);
14013 pint2str (decode_mode_spec_buf
, field_width
, col
);
14014 return decode_mode_spec_buf
;
14018 /* %F displays the frame name. */
14019 if (!NILP (f
->title
))
14020 return (char *) XSTRING (f
->title
)->data
;
14021 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
14022 return (char *) XSTRING (f
->name
)->data
;
14031 int startpos
= XMARKER (w
->start
)->charpos
;
14032 int startpos_byte
= marker_byte_position (w
->start
);
14033 int line
, linepos
, linepos_byte
, topline
;
14035 int height
= XFASTINT (w
->height
);
14037 /* If we decided that this buffer isn't suitable for line numbers,
14038 don't forget that too fast. */
14039 if (EQ (w
->base_line_pos
, w
->buffer
))
14041 /* But do forget it, if the window shows a different buffer now. */
14042 else if (BUFFERP (w
->base_line_pos
))
14043 w
->base_line_pos
= Qnil
;
14045 /* If the buffer is very big, don't waste time. */
14046 if (INTEGERP (Vline_number_display_limit
)
14047 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
14049 w
->base_line_pos
= Qnil
;
14050 w
->base_line_number
= Qnil
;
14054 if (!NILP (w
->base_line_number
)
14055 && !NILP (w
->base_line_pos
)
14056 && XFASTINT (w
->base_line_pos
) <= startpos
)
14058 line
= XFASTINT (w
->base_line_number
);
14059 linepos
= XFASTINT (w
->base_line_pos
);
14060 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
14065 linepos
= BUF_BEGV (b
);
14066 linepos_byte
= BUF_BEGV_BYTE (b
);
14069 /* Count lines from base line to window start position. */
14070 nlines
= display_count_lines (linepos
, linepos_byte
,
14074 topline
= nlines
+ line
;
14076 /* Determine a new base line, if the old one is too close
14077 or too far away, or if we did not have one.
14078 "Too close" means it's plausible a scroll-down would
14079 go back past it. */
14080 if (startpos
== BUF_BEGV (b
))
14082 w
->base_line_number
= make_number (topline
);
14083 w
->base_line_pos
= make_number (BUF_BEGV (b
));
14085 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
14086 || linepos
== BUF_BEGV (b
))
14088 int limit
= BUF_BEGV (b
);
14089 int limit_byte
= BUF_BEGV_BYTE (b
);
14091 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
14093 if (startpos
- distance
> limit
)
14095 limit
= startpos
- distance
;
14096 limit_byte
= CHAR_TO_BYTE (limit
);
14099 nlines
= display_count_lines (startpos
, startpos_byte
,
14101 - (height
* 2 + 30),
14103 /* If we couldn't find the lines we wanted within
14104 line_number_display_limit_width chars per line,
14105 give up on line numbers for this window. */
14106 if (position
== limit_byte
&& limit
== startpos
- distance
)
14108 w
->base_line_pos
= w
->buffer
;
14109 w
->base_line_number
= Qnil
;
14113 w
->base_line_number
= make_number (topline
- nlines
);
14114 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
14117 /* Now count lines from the start pos to point. */
14118 nlines
= display_count_lines (startpos
, startpos_byte
,
14119 PT_BYTE
, PT
, &junk
);
14121 /* Record that we did display the line number. */
14122 line_number_displayed
= 1;
14124 /* Make the string to show. */
14125 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
14126 return decode_mode_spec_buf
;
14129 char* p
= decode_mode_spec_buf
;
14130 int pad
= field_width
- 2;
14136 return decode_mode_spec_buf
;
14142 obj
= b
->mode_name
;
14146 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
14152 int pos
= marker_position (w
->start
);
14153 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14155 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
14157 if (pos
<= BUF_BEGV (b
))
14162 else if (pos
<= BUF_BEGV (b
))
14166 if (total
> 1000000)
14167 /* Do it differently for a large value, to avoid overflow. */
14168 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14170 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14171 /* We can't normally display a 3-digit number,
14172 so get us a 2-digit number that is close. */
14175 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14176 return decode_mode_spec_buf
;
14180 /* Display percentage of size above the bottom of the screen. */
14183 int toppos
= marker_position (w
->start
);
14184 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14185 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14187 if (botpos
>= BUF_ZV (b
))
14189 if (toppos
<= BUF_BEGV (b
))
14196 if (total
> 1000000)
14197 /* Do it differently for a large value, to avoid overflow. */
14198 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14200 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14201 /* We can't normally display a 3-digit number,
14202 so get us a 2-digit number that is close. */
14205 if (toppos
<= BUF_BEGV (b
))
14206 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14208 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14209 return decode_mode_spec_buf
;
14214 /* status of process */
14215 obj
= Fget_buffer_process (w
->buffer
);
14217 return "no process";
14218 #ifdef subprocesses
14219 obj
= Fsymbol_name (Fprocess_status (obj
));
14223 case 't': /* indicate TEXT or BINARY */
14224 #ifdef MODE_LINE_BINARY_TEXT
14225 return MODE_LINE_BINARY_TEXT (b
);
14231 /* coding-system (not including end-of-line format) */
14233 /* coding-system (including end-of-line type) */
14235 int eol_flag
= (c
== 'Z');
14236 char *p
= decode_mode_spec_buf
;
14238 if (! FRAME_WINDOW_P (f
))
14240 /* No need to mention EOL here--the terminal never needs
14241 to do EOL conversion. */
14242 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14243 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14245 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14248 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14249 #ifdef subprocesses
14250 obj
= Fget_buffer_process (Fcurrent_buffer ());
14251 if (PROCESSP (obj
))
14253 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14255 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14258 #endif /* subprocesses */
14261 return decode_mode_spec_buf
;
14267 *multibyte
= STRING_MULTIBYTE (obj
);
14268 return (char *) XSTRING (obj
)->data
;
14275 /* Count up to COUNT lines starting from START / START_BYTE.
14276 But don't go beyond LIMIT_BYTE.
14277 Return the number of lines thus found (always nonnegative).
14279 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14282 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14283 int start
, start_byte
, limit_byte
, count
;
14286 register unsigned char *cursor
;
14287 unsigned char *base
;
14289 register int ceiling
;
14290 register unsigned char *ceiling_addr
;
14291 int orig_count
= count
;
14293 /* If we are not in selective display mode,
14294 check only for newlines. */
14295 int selective_display
= (!NILP (current_buffer
->selective_display
)
14296 && !INTEGERP (current_buffer
->selective_display
));
14300 while (start_byte
< limit_byte
)
14302 ceiling
= BUFFER_CEILING_OF (start_byte
);
14303 ceiling
= min (limit_byte
- 1, ceiling
);
14304 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14305 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14308 if (selective_display
)
14309 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14312 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14315 if (cursor
!= ceiling_addr
)
14319 start_byte
+= cursor
- base
+ 1;
14320 *byte_pos_ptr
= start_byte
;
14324 if (++cursor
== ceiling_addr
)
14330 start_byte
+= cursor
- base
;
14335 while (start_byte
> limit_byte
)
14337 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14338 ceiling
= max (limit_byte
, ceiling
);
14339 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14340 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14343 if (selective_display
)
14344 while (--cursor
!= ceiling_addr
14345 && *cursor
!= '\n' && *cursor
!= 015)
14348 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14351 if (cursor
!= ceiling_addr
)
14355 start_byte
+= cursor
- base
+ 1;
14356 *byte_pos_ptr
= start_byte
;
14357 /* When scanning backwards, we should
14358 not count the newline posterior to which we stop. */
14359 return - orig_count
- 1;
14365 /* Here we add 1 to compensate for the last decrement
14366 of CURSOR, which took it past the valid range. */
14367 start_byte
+= cursor
- base
+ 1;
14371 *byte_pos_ptr
= limit_byte
;
14374 return - orig_count
+ count
;
14375 return orig_count
- count
;
14381 /***********************************************************************
14383 ***********************************************************************/
14385 /* Display a NUL-terminated string, starting with index START.
14387 If STRING is non-null, display that C string. Otherwise, the Lisp
14388 string LISP_STRING is displayed.
14390 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14391 FACE_STRING. Display STRING or LISP_STRING with the face at
14392 FACE_STRING_POS in FACE_STRING:
14394 Display the string in the environment given by IT, but use the
14395 standard display table, temporarily.
14397 FIELD_WIDTH is the minimum number of output glyphs to produce.
14398 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14399 with spaces. If STRING has more characters, more than FIELD_WIDTH
14400 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14402 PRECISION is the maximum number of characters to output from
14403 STRING. PRECISION < 0 means don't truncate the string.
14405 This is roughly equivalent to printf format specifiers:
14407 FIELD_WIDTH PRECISION PRINTF
14408 ----------------------------------------
14414 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14415 display them, and < 0 means obey the current buffer's value of
14416 enable_multibyte_characters.
14418 Value is the number of glyphs produced. */
14421 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14422 start
, it
, field_width
, precision
, max_x
, multibyte
)
14423 unsigned char *string
;
14424 Lisp_Object lisp_string
;
14425 Lisp_Object face_string
;
14426 int face_string_pos
;
14429 int field_width
, precision
, max_x
;
14432 int hpos_at_start
= it
->hpos
;
14433 int saved_face_id
= it
->face_id
;
14434 struct glyph_row
*row
= it
->glyph_row
;
14436 /* Initialize the iterator IT for iteration over STRING beginning
14437 with index START. */
14438 reseat_to_string (it
, string
, lisp_string
, start
,
14439 precision
, field_width
, multibyte
);
14441 /* If displaying STRING, set up the face of the iterator
14442 from LISP_STRING, if that's given. */
14443 if (STRINGP (face_string
))
14449 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
14450 0, it
->region_beg_charpos
,
14451 it
->region_end_charpos
,
14452 &endptr
, it
->base_face_id
, 0);
14453 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14454 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
14457 /* Set max_x to the maximum allowed X position. Don't let it go
14458 beyond the right edge of the window. */
14460 max_x
= it
->last_visible_x
;
14462 max_x
= min (max_x
, it
->last_visible_x
);
14464 /* Skip over display elements that are not visible. because IT->w is
14466 if (it
->current_x
< it
->first_visible_x
)
14467 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
14468 MOVE_TO_POS
| MOVE_TO_X
);
14470 row
->ascent
= it
->max_ascent
;
14471 row
->height
= it
->max_ascent
+ it
->max_descent
;
14472 row
->phys_ascent
= it
->max_phys_ascent
;
14473 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14475 /* This condition is for the case that we are called with current_x
14476 past last_visible_x. */
14477 while (it
->current_x
< max_x
)
14479 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14481 /* Get the next display element. */
14482 if (!get_next_display_element (it
))
14485 /* Produce glyphs. */
14486 x_before
= it
->current_x
;
14487 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14488 PRODUCE_GLYPHS (it
);
14490 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14493 while (i
< nglyphs
)
14495 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14497 if (!it
->truncate_lines_p
14498 && x
+ glyph
->pixel_width
> max_x
)
14500 /* End of continued line or max_x reached. */
14501 if (CHAR_GLYPH_PADDING_P (*glyph
))
14503 /* A wide character is unbreakable. */
14504 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14505 it
->current_x
= x_before
;
14509 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14514 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
14516 /* Glyph is at least partially visible. */
14518 if (x
< it
->first_visible_x
)
14519 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14523 /* Glyph is off the left margin of the display area.
14524 Should not happen. */
14528 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14529 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14530 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14531 row
->phys_height
= max (row
->phys_height
,
14532 it
->max_phys_ascent
+ it
->max_phys_descent
);
14533 x
+= glyph
->pixel_width
;
14537 /* Stop if max_x reached. */
14541 /* Stop at line ends. */
14542 if (ITERATOR_AT_END_OF_LINE_P (it
))
14544 it
->continuation_lines_width
= 0;
14548 set_iterator_to_next (it
, 1);
14550 /* Stop if truncating at the right edge. */
14551 if (it
->truncate_lines_p
14552 && it
->current_x
>= it
->last_visible_x
)
14554 /* Add truncation mark, but don't do it if the line is
14555 truncated at a padding space. */
14556 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14558 if (!FRAME_WINDOW_P (it
->f
))
14562 if (it
->current_x
> it
->last_visible_x
)
14564 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14565 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14567 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14569 row
->used
[TEXT_AREA
] = i
;
14570 produce_special_glyphs (it
, IT_TRUNCATION
);
14573 produce_special_glyphs (it
, IT_TRUNCATION
);
14575 it
->glyph_row
->truncated_on_right_p
= 1;
14581 /* Maybe insert a truncation at the left. */
14582 if (it
->first_visible_x
14583 && IT_CHARPOS (*it
) > 0)
14585 if (!FRAME_WINDOW_P (it
->f
))
14586 insert_left_trunc_glyphs (it
);
14587 it
->glyph_row
->truncated_on_left_p
= 1;
14590 it
->face_id
= saved_face_id
;
14592 /* Value is number of columns displayed. */
14593 return it
->hpos
- hpos_at_start
;
14598 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
14599 appears as an element of LIST or as the car of an element of LIST.
14600 If PROPVAL is a list, compare each element against LIST in that
14601 way, and return 1/2 if any element of PROPVAL is found in LIST.
14602 Otherwise return 0. This function cannot quit.
14603 The return value is 2 if the text is invisible but with an ellipsis
14604 and 1 if it's invisible and without an ellipsis. */
14607 invisible_p (propval
, list
)
14608 register Lisp_Object propval
;
14611 register Lisp_Object tail
, proptail
;
14613 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14615 register Lisp_Object tem
;
14617 if (EQ (propval
, tem
))
14619 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14620 return NILP (XCDR (tem
)) ? 1 : 2;
14623 if (CONSP (propval
))
14625 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14627 Lisp_Object propelt
;
14628 propelt
= XCAR (proptail
);
14629 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14631 register Lisp_Object tem
;
14633 if (EQ (propelt
, tem
))
14635 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14636 return NILP (XCDR (tem
)) ? 1 : 2;
14645 /***********************************************************************
14647 ***********************************************************************/
14652 Vwith_echo_area_save_vector
= Qnil
;
14653 staticpro (&Vwith_echo_area_save_vector
);
14655 Vmessage_stack
= Qnil
;
14656 staticpro (&Vmessage_stack
);
14658 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14659 staticpro (&Qinhibit_redisplay
);
14661 message_dolog_marker1
= Fmake_marker ();
14662 staticpro (&message_dolog_marker1
);
14663 message_dolog_marker2
= Fmake_marker ();
14664 staticpro (&message_dolog_marker2
);
14665 message_dolog_marker3
= Fmake_marker ();
14666 staticpro (&message_dolog_marker3
);
14669 defsubr (&Sdump_glyph_matrix
);
14670 defsubr (&Sdump_glyph_row
);
14671 defsubr (&Sdump_tool_bar_row
);
14672 defsubr (&Strace_redisplay
);
14673 defsubr (&Strace_to_stderr
);
14675 #ifdef HAVE_WINDOW_SYSTEM
14676 defsubr (&Stool_bar_lines_needed
);
14679 staticpro (&Qmenu_bar_update_hook
);
14680 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14682 staticpro (&Qoverriding_terminal_local_map
);
14683 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14685 staticpro (&Qoverriding_local_map
);
14686 Qoverriding_local_map
= intern ("overriding-local-map");
14688 staticpro (&Qwindow_scroll_functions
);
14689 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14691 staticpro (&Qredisplay_end_trigger_functions
);
14692 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14694 staticpro (&Qinhibit_point_motion_hooks
);
14695 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14697 QCdata
= intern (":data");
14698 staticpro (&QCdata
);
14699 Qdisplay
= intern ("display");
14700 staticpro (&Qdisplay
);
14701 Qspace_width
= intern ("space-width");
14702 staticpro (&Qspace_width
);
14703 Qraise
= intern ("raise");
14704 staticpro (&Qraise
);
14705 Qspace
= intern ("space");
14706 staticpro (&Qspace
);
14707 Qmargin
= intern ("margin");
14708 staticpro (&Qmargin
);
14709 Qleft_margin
= intern ("left-margin");
14710 staticpro (&Qleft_margin
);
14711 Qright_margin
= intern ("right-margin");
14712 staticpro (&Qright_margin
);
14713 Qalign_to
= intern ("align-to");
14714 staticpro (&Qalign_to
);
14715 QCalign_to
= intern (":align-to");
14716 staticpro (&QCalign_to
);
14717 Qrelative_width
= intern ("relative-width");
14718 staticpro (&Qrelative_width
);
14719 QCrelative_width
= intern (":relative-width");
14720 staticpro (&QCrelative_width
);
14721 QCrelative_height
= intern (":relative-height");
14722 staticpro (&QCrelative_height
);
14723 QCeval
= intern (":eval");
14724 staticpro (&QCeval
);
14725 Qwhen
= intern ("when");
14726 staticpro (&Qwhen
);
14727 QCfile
= intern (":file");
14728 staticpro (&QCfile
);
14729 Qfontified
= intern ("fontified");
14730 staticpro (&Qfontified
);
14731 Qfontification_functions
= intern ("fontification-functions");
14732 staticpro (&Qfontification_functions
);
14733 Qtrailing_whitespace
= intern ("trailing-whitespace");
14734 staticpro (&Qtrailing_whitespace
);
14735 Qimage
= intern ("image");
14736 staticpro (&Qimage
);
14737 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14738 staticpro (&Qmessage_truncate_lines
);
14739 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
14740 staticpro (&Qcursor_in_non_selected_windows
);
14741 Qgrow_only
= intern ("grow-only");
14742 staticpro (&Qgrow_only
);
14743 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14744 staticpro (&Qinhibit_menubar_update
);
14745 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
14746 staticpro (&Qinhibit_eval_during_redisplay
);
14747 Qposition
= intern ("position");
14748 staticpro (&Qposition
);
14749 Qbuffer_position
= intern ("buffer-position");
14750 staticpro (&Qbuffer_position
);
14751 Qobject
= intern ("object");
14752 staticpro (&Qobject
);
14754 last_arrow_position
= Qnil
;
14755 last_arrow_string
= Qnil
;
14756 staticpro (&last_arrow_position
);
14757 staticpro (&last_arrow_string
);
14759 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14760 staticpro (&echo_buffer
[0]);
14761 staticpro (&echo_buffer
[1]);
14763 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14764 staticpro (&echo_area_buffer
[0]);
14765 staticpro (&echo_area_buffer
[1]);
14767 Vmessages_buffer_name
= build_string ("*Messages*");
14768 staticpro (&Vmessages_buffer_name
);
14770 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14771 doc
: /* Non-nil means highlight trailing whitespace.
14772 The face used for trailing whitespace is `trailing-whitespace'. */);
14773 Vshow_trailing_whitespace
= Qnil
;
14775 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14776 doc
: /* Non-nil means don't actually do any redisplay.
14777 This is used for internal purposes. */);
14778 Vinhibit_redisplay
= Qnil
;
14780 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14781 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
14782 Vglobal_mode_string
= Qnil
;
14784 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14785 doc
: /* Marker for where to display an arrow on top of the buffer text.
14786 This must be the beginning of a line in order to work.
14787 See also `overlay-arrow-string'. */);
14788 Voverlay_arrow_position
= Qnil
;
14790 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14791 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
14792 Voverlay_arrow_string
= Qnil
;
14794 DEFVAR_INT ("scroll-step", &scroll_step
,
14795 doc
: /* *The number of lines to try scrolling a window by when point moves out.
14796 If that fails to bring point back on frame, point is centered instead.
14797 If this is zero, point is always centered after it moves off frame.
14798 If you want scrolling to always be a line at a time, you should set
14799 `scroll-conservatively' to a large value rather than set this to 1. */);
14801 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14802 doc
: /* *Scroll up to this many lines, to bring point back on screen.
14803 A value of zero means to scroll the text to center point vertically
14804 in the window. */);
14805 scroll_conservatively
= 0;
14807 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14808 doc
: /* *Number of lines of margin at the top and bottom of a window.
14809 Recenter the window whenever point gets within this many lines
14810 of the top or bottom of the window. */);
14814 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
14817 DEFVAR_BOOL ("truncate-partial-width-windows",
14818 &truncate_partial_width_windows
,
14819 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
14820 truncate_partial_width_windows
= 1;
14822 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14823 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
14824 Any other value means to use the appropriate face, `mode-line',
14825 `header-line', or `menu' respectively.
14827 This variable is deprecated; please change the above faces instead. */);
14828 mode_line_inverse_video
= 1;
14830 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14831 doc
: /* *Maximum buffer size for which line number should be displayed.
14832 If the buffer is bigger than this, the line number does not appear
14833 in the mode line. A value of nil means no limit. */);
14834 Vline_number_display_limit
= Qnil
;
14836 DEFVAR_INT ("line-number-display-limit-width",
14837 &line_number_display_limit_width
,
14838 doc
: /* *Maximum line width (in characters) for line number display.
14839 If the average length of the lines near point is bigger than this, then the
14840 line number may be omitted from the mode line. */);
14841 line_number_display_limit_width
= 200;
14843 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14844 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
14845 highlight_nonselected_windows
= 0;
14847 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14848 doc
: /* Non-nil if more than one frame is visible on this display.
14849 Minibuffer-only frames don't count, but iconified frames do.
14850 This variable is not guaranteed to be accurate except while processing
14851 `frame-title-format' and `icon-title-format'. */);
14853 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14854 doc
: /* Template for displaying the title bar of visible frames.
14855 \(Assuming the window manager supports this feature.)
14856 This variable has the same structure as `mode-line-format' (which see),
14857 and is used only on frames for which no explicit name has been set
14858 \(see `modify-frame-parameters'). */);
14859 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
14860 doc
: /* Template for displaying the title bar of an iconified frame.
14861 \(Assuming the window manager supports this feature.)
14862 This variable has the same structure as `mode-line-format' (which see),
14863 and is used only on frames for which no explicit name has been set
14864 \(see `modify-frame-parameters'). */);
14866 = Vframe_title_format
14867 = Fcons (intern ("multiple-frames"),
14868 Fcons (build_string ("%b"),
14869 Fcons (Fcons (empty_string
,
14870 Fcons (intern ("invocation-name"),
14871 Fcons (build_string ("@"),
14872 Fcons (intern ("system-name"),
14876 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
14877 doc
: /* Maximum number of lines to keep in the message log buffer.
14878 If nil, disable message logging. If t, log messages but don't truncate
14879 the buffer when it becomes large. */);
14880 Vmessage_log_max
= make_number (50);
14882 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
14883 doc
: /* Functions called before redisplay, if window sizes have changed.
14884 The value should be a list of functions that take one argument.
14885 Just before redisplay, for each frame, if any of its windows have changed
14886 size since the last redisplay, or have been split or deleted,
14887 all the functions in the list are called, with the frame as argument. */);
14888 Vwindow_size_change_functions
= Qnil
;
14890 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
14891 doc
: /* List of Functions to call before redisplaying a window with scrolling.
14892 Each function is called with two arguments, the window
14893 and its new display-start position. Note that the value of `window-end'
14894 is not valid when these functions are called. */);
14895 Vwindow_scroll_functions
= Qnil
;
14897 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
14898 doc
: /* *Non-nil means automatically resize tool-bars.
14899 This increases a tool-bar's height if not all tool-bar items are visible.
14900 It decreases a tool-bar's height when it would display blank lines
14902 auto_resize_tool_bars_p
= 1;
14904 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
14905 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
14906 auto_raise_tool_bar_buttons_p
= 1;
14908 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
14909 doc
: /* *Margin around tool-bar buttons in pixels.
14910 If an integer, use that for both horizontal and vertical margins.
14911 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
14912 HORZ specifying the horizontal margin, and VERT specifying the
14913 vertical margin. */);
14914 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
14916 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
14917 doc
: /* *Relief thickness of tool-bar buttons. */);
14918 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
14920 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
14921 doc
: /* List of functions to call to fontify regions of text.
14922 Each function is called with one argument POS. Functions must
14923 fontify a region starting at POS in the current buffer, and give
14924 fontified regions the property `fontified'. */);
14925 Vfontification_functions
= Qnil
;
14926 Fmake_variable_buffer_local (Qfontification_functions
);
14928 DEFVAR_BOOL ("unibyte-display-via-language-environment",
14929 &unibyte_display_via_language_environment
,
14930 doc
: /* *Non-nil means display unibyte text according to language environment.
14931 Specifically this means that unibyte non-ASCII characters
14932 are displayed by converting them to the equivalent multibyte characters
14933 according to the current language environment. As a result, they are
14934 displayed according to the current fontset. */);
14935 unibyte_display_via_language_environment
= 0;
14937 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
14938 doc
: /* *Maximum height for resizing mini-windows.
14939 If a float, it specifies a fraction of the mini-window frame's height.
14940 If an integer, it specifies a number of lines. */);
14941 Vmax_mini_window_height
= make_float (0.25);
14943 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
14944 doc
: /* *How to resize mini-windows.
14945 A value of nil means don't automatically resize mini-windows.
14946 A value of t means resize them to fit the text displayed in them.
14947 A value of `grow-only', the default, means let mini-windows grow
14948 only, until their display becomes empty, at which point the windows
14949 go back to their normal size. */);
14950 Vresize_mini_windows
= Qgrow_only
;
14952 DEFVAR_BOOL ("cursor-in-non-selected-windows",
14953 &cursor_in_non_selected_windows
,
14954 doc
: /* *Non-nil means display a hollow cursor in non-selected windows.
14955 nil means don't display a cursor there. */);
14956 cursor_in_non_selected_windows
= 1;
14958 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
14959 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
14960 automatic_hscrolling_p
= 1;
14962 DEFVAR_LISP ("image-types", &Vimage_types
,
14963 doc
: /* List of supported image types.
14964 Each element of the list is a symbol for a supported image type. */);
14965 Vimage_types
= Qnil
;
14967 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
14968 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
14969 Bind this around calls to `message' to let it take effect. */);
14970 message_truncate_lines
= 0;
14972 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
14973 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
14974 Can be used to update submenus whose contents should vary. */);
14975 Vmenu_bar_update_hook
= Qnil
;
14977 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
14978 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
14979 inhibit_menubar_update
= 0;
14981 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
14982 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
14983 inhibit_eval_during_redisplay
= 0;
14986 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
14987 doc
: /* Inhibit try_window_id display optimization. */);
14988 inhibit_try_window_id
= 0;
14990 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
14991 doc
: /* Inhibit try_window_reusing display optimization. */);
14992 inhibit_try_window_reusing
= 0;
14994 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
14995 doc
: /* Inhibit try_cursor_movement display optimization. */);
14996 inhibit_try_cursor_movement
= 0;
14997 #endif /* GLYPH_DEBUG */
15001 /* Initialize this module when Emacs starts. */
15006 Lisp_Object root_window
;
15007 struct window
*mini_w
;
15009 current_header_line_height
= current_mode_line_height
= -1;
15011 CHARPOS (this_line_start_pos
) = 0;
15013 mini_w
= XWINDOW (minibuf_window
);
15014 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
15016 if (!noninteractive
)
15018 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
15021 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
15022 set_window_height (root_window
,
15023 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
15025 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
15026 set_window_height (minibuf_window
, 1, 0);
15028 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
15029 mini_w
->width
= make_number (FRAME_WIDTH (f
));
15031 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
15032 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
15033 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
15035 /* The default ellipsis glyphs `...'. */
15036 for (i
= 0; i
< 3; ++i
)
15037 default_invis_vector
[i
] = make_number ('.');
15040 #ifdef HAVE_WINDOW_SYSTEM
15042 /* Allocate the buffer for frame titles. */
15044 frame_title_buf
= (char *) xmalloc (size
);
15045 frame_title_buf_end
= frame_title_buf
+ size
;
15046 frame_title_ptr
= NULL
;
15048 #endif /* HAVE_WINDOW_SYSTEM */
15050 help_echo_showing_p
= 0;