1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000
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 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 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 be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator
128 (or init_string_iterator for that matter). Calls to
129 get_next_display_element fill the iterator structure with relevant
130 information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 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 min(a, b) ((a) < (b) ? (a) : (b))
202 #define max(a, b) ((a) > (b) ? (a) : (b))
204 #define INFINITY 10000000
206 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
207 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
208 extern int pending_menu_activation
;
211 extern int interrupt_input
;
212 extern int command_loop_level
;
214 extern int minibuffer_auto_raise
;
216 extern Lisp_Object Qface
;
218 extern Lisp_Object Voverriding_local_map
;
219 extern Lisp_Object Voverriding_local_map_menu_flag
;
220 extern Lisp_Object Qmenu_item
;
222 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
223 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
224 Lisp_Object Qredisplay_end_trigger_functions
;
225 Lisp_Object Qinhibit_point_motion_hooks
;
226 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
;
227 Lisp_Object Qfontified
;
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 int tool_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 /* Names of text properties relevant for redisplay. */
258 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
259 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
261 /* Symbols used in text property values. */
263 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
264 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
266 extern Lisp_Object Qheight
;
268 /* Non-nil means highlight trailing whitespace. */
270 Lisp_Object Vshow_trailing_whitespace
;
272 /* Name of the face used to highlight trailing whitespace. */
274 Lisp_Object Qtrailing_whitespace
;
276 /* The symbol `image' which is the car of the lists used to represent
281 /* Non-zero means print newline to stdout before next mini-buffer
284 int noninteractive_need_newline
;
286 /* Non-zero means print newline to message log before next message. */
288 static int message_log_need_newline
;
291 /* The buffer position of the first character appearing entirely or
292 partially on the line of the selected window which contains the
293 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
294 redisplay optimization in redisplay_internal. */
296 static struct text_pos this_line_start_pos
;
298 /* Number of characters past the end of the line above, including the
299 terminating newline. */
301 static struct text_pos this_line_end_pos
;
303 /* The vertical positions and the height of this line. */
305 static int this_line_vpos
;
306 static int this_line_y
;
307 static int this_line_pixel_height
;
309 /* X position at which this display line starts. Usually zero;
310 negative if first character is partially visible. */
312 static int this_line_start_x
;
314 /* Buffer that this_line_.* variables are referring to. */
316 static struct buffer
*this_line_buffer
;
318 /* Nonzero means truncate lines in all windows less wide than the
321 int truncate_partial_width_windows
;
323 /* A flag to control how to display unibyte 8-bit character. */
325 int unibyte_display_via_language_environment
;
327 /* Nonzero means we have more than one non-mini-buffer-only frame.
328 Not guaranteed to be accurate except while parsing
329 frame-title-format. */
333 Lisp_Object Vglobal_mode_string
;
335 /* Marker for where to display an arrow on top of the buffer text. */
337 Lisp_Object Voverlay_arrow_position
;
339 /* String to display for the arrow. Only used on terminal frames. */
341 Lisp_Object Voverlay_arrow_string
;
343 /* Values of those variables at last redisplay. However, if
344 Voverlay_arrow_position is a marker, last_arrow_position is its
345 numerical position. */
347 static Lisp_Object last_arrow_position
, last_arrow_string
;
349 /* Like mode-line-format, but for the title bar on a visible frame. */
351 Lisp_Object Vframe_title_format
;
353 /* Like mode-line-format, but for the title bar on an iconified frame. */
355 Lisp_Object Vicon_title_format
;
357 /* List of functions to call when a window's size changes. These
358 functions get one arg, a frame on which one or more windows' sizes
361 static Lisp_Object Vwindow_size_change_functions
;
363 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
365 /* Nonzero if overlay arrow has been displayed once in this window. */
367 static int overlay_arrow_seen
;
369 /* Nonzero means highlight the region even in nonselected windows. */
371 int highlight_nonselected_windows
;
373 /* If cursor motion alone moves point off frame, try scrolling this
374 many lines up or down if that will bring it back. */
376 static int scroll_step
;
378 /* Non-0 means scroll just far enough to bring point back on the
379 screen, when appropriate. */
381 static int scroll_conservatively
;
383 /* Recenter the window whenever point gets within this many lines of
384 the top or bottom of the window. This value is translated into a
385 pixel value by multiplying it with CANON_Y_UNIT, which means that
386 there is really a fixed pixel height scroll margin. */
390 /* Number of windows showing the buffer of the selected window (or
391 another buffer with the same base buffer). keyboard.c refers to
396 /* Vector containing glyphs for an ellipsis `...'. */
398 static Lisp_Object default_invis_vector
[3];
400 /* Nonzero means display mode line highlighted. */
402 int mode_line_inverse_video
;
404 /* Prompt to display in front of the mini-buffer contents. */
406 Lisp_Object minibuf_prompt
;
408 /* Width of current mini-buffer prompt. Only set after display_line
409 of the line that contains the prompt. */
411 int minibuf_prompt_width
;
412 int minibuf_prompt_pixel_width
;
414 /* This is the window where the echo area message was displayed. It
415 is always a mini-buffer window, but it may not be the same window
416 currently active as a mini-buffer. */
418 Lisp_Object echo_area_window
;
420 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
421 pushes the current message and the value of
422 message_enable_multibyte on the stack, the function restore_message
423 pops the stack and displays MESSAGE again. */
425 Lisp_Object Vmessage_stack
;
427 /* Nonzero means multibyte characters were enabled when the echo area
428 message was specified. */
430 int message_enable_multibyte
;
432 /* True if we should redraw the mode lines on the next redisplay. */
434 int update_mode_lines
;
436 /* Nonzero if window sizes or contents have changed since last
437 redisplay that finished */
439 int windows_or_buffers_changed
;
441 /* Nonzero after display_mode_line if %l was used and it displayed a
444 int line_number_displayed
;
446 /* Maximum buffer size for which to display line numbers. */
448 Lisp_Object Vline_number_display_limit
;
450 /* line width to consider when repostioning for line number display */
452 static int line_number_display_limit_width
;
454 /* Number of lines to keep in the message log buffer. t means
455 infinite. nil means don't log at all. */
457 Lisp_Object Vmessage_log_max
;
459 /* The name of the *Messages* buffer, a string. */
461 static Lisp_Object Vmessages_buffer_name
;
463 /* Current, index 0, and last displayed echo area message. Either
464 buffers from echo_buffers, or nil to indicate no message. */
466 Lisp_Object echo_area_buffer
[2];
468 /* The buffers referenced from echo_area_buffer. */
470 static Lisp_Object echo_buffer
[2];
472 /* A vector saved used in with_area_buffer to reduce consing. */
474 static Lisp_Object Vwith_echo_area_save_vector
;
476 /* Non-zero means display_echo_area should display the last echo area
477 message again. Set by redisplay_preserve_echo_area. */
479 static int display_last_displayed_message_p
;
481 /* Nonzero if echo area is being used by print; zero if being used by
484 int message_buf_print
;
486 /* Maximum height for resizing mini-windows. Either a float
487 specifying a fraction of the available height, or an integer
488 specifying a number of lines. */
490 Lisp_Object Vmax_mini_window_height
;
492 /* Non-zero means messages should be displayed with truncated
493 lines instead of being continued. */
495 int message_truncate_lines
;
496 Lisp_Object Qmessage_truncate_lines
;
498 /* Non-zero means we want a hollow cursor in windows that are not
499 selected. Zero means there's no cursor in such windows. */
501 int cursor_in_non_selected_windows
;
503 /* A scratch glyph row with contents used for generating truncation
504 glyphs. Also used in direct_output_for_insert. */
506 #define MAX_SCRATCH_GLYPHS 100
507 struct glyph_row scratch_glyph_row
;
508 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
510 /* Ascent and height of the last line processed by move_it_to. */
512 static int last_max_ascent
, last_height
;
514 /* Non-zero if there's a help-echo in the echo area. */
516 int help_echo_showing_p
;
518 /* The maximum distance to look ahead for text properties. Values
519 that are too small let us call compute_char_face and similar
520 functions too often which is expensive. Values that are too large
521 let us call compute_char_face and alike too often because we
522 might not be interested in text properties that far away. */
524 #define TEXT_PROP_DISTANCE_LIMIT 100
528 /* Non-zero means print traces of redisplay if compiled with
531 int trace_redisplay_p
;
533 #endif /* GLYPH_DEBUG */
535 #ifdef DEBUG_TRACE_MOVE
536 /* Non-zero means trace with TRACE_MOVE to stderr. */
539 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
541 #define TRACE_MOVE(x) (void) 0
544 /* Non-zero means automatically scroll windows horizontally to make
547 int automatic_hscrolling_p
;
549 /* A list of symbols, one for each supported image type. */
551 Lisp_Object Vimage_types
;
553 /* Value returned from text property handlers (see below). */
558 HANDLED_RECOMPUTE_PROPS
,
559 HANDLED_OVERLAY_STRING_CONSUMED
,
563 /* A description of text properties that redisplay is interested
568 /* The name of the property. */
571 /* A unique index for the property. */
574 /* A handler function called to set up iterator IT from the property
575 at IT's current position. Value is used to steer handle_stop. */
576 enum prop_handled (*handler
) P_ ((struct it
*it
));
579 static enum prop_handled handle_face_prop
P_ ((struct it
*));
580 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
581 static enum prop_handled handle_display_prop
P_ ((struct it
*));
582 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
583 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
584 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
586 /* Properties handled by iterators. */
588 static struct props it_props
[] =
590 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
591 /* Handle `face' before `display' because some sub-properties of
592 `display' need to know the face. */
593 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
594 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
595 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
596 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
600 /* Value is the position described by X. If X is a marker, value is
601 the marker_position of X. Otherwise, value is X. */
603 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
605 /* Enumeration returned by some move_it_.* functions internally. */
609 /* Not used. Undefined value. */
612 /* Move ended at the requested buffer position or ZV. */
613 MOVE_POS_MATCH_OR_ZV
,
615 /* Move ended at the requested X pixel position. */
618 /* Move within a line ended at the end of a line that must be
622 /* Move within a line ended at the end of a line that would
623 be displayed truncated. */
626 /* Move within a line ended at a line end. */
632 /* Function prototypes. */
634 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
635 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
636 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
637 static int invisible_text_between_p
P_ ((struct it
*, int, int));
638 static int next_element_from_ellipsis
P_ ((struct it
*));
639 static void pint2str
P_ ((char *, int, int));
640 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
642 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
643 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
644 static void store_frame_title_char
P_ ((char));
645 static int store_frame_title
P_ ((unsigned char *, int, int));
646 static void x_consider_frame_title
P_ ((Lisp_Object
));
647 static void handle_stop
P_ ((struct it
*));
648 static int tool_bar_lines_needed
P_ ((struct frame
*));
649 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
650 static void ensure_echo_area_buffers
P_ ((void));
651 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
653 struct glyph_row
*));
654 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
655 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
656 static int with_echo_area_buffer
P_ ((struct window
*, int,
657 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
658 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
659 static void clear_garbaged_frames
P_ ((void));
660 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
661 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
662 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
663 static int display_echo_area
P_ ((struct window
*));
664 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
665 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
666 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
667 static int string_char_and_length
P_ ((unsigned char *, int, int *));
668 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
670 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
671 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
672 static void insert_left_trunc_glyphs
P_ ((struct it
*));
673 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
674 static void extend_face_to_end_of_line
P_ ((struct it
*));
675 static int append_space
P_ ((struct it
*, int));
676 static void make_cursor_line_fully_visible
P_ ((struct window
*));
677 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
678 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
679 static int trailing_whitespace_p
P_ ((int));
680 static int message_log_check_duplicate
P_ ((int, int, int, int));
681 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
682 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
683 static void push_it
P_ ((struct it
*));
684 static void pop_it
P_ ((struct it
*));
685 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
686 static void redisplay_internal
P_ ((int));
687 static int echo_area_display
P_ ((int));
688 static void redisplay_windows
P_ ((Lisp_Object
));
689 static void redisplay_window
P_ ((Lisp_Object
, int));
690 static void update_menu_bar
P_ ((struct frame
*, int));
691 static int try_window_reusing_current_matrix
P_ ((struct window
*));
692 static int try_window_id
P_ ((struct window
*));
693 static int display_line
P_ ((struct it
*));
694 static int display_mode_lines
P_ ((struct window
*));
695 static void display_mode_line
P_ ((struct window
*, enum face_id
,
697 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
698 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
699 static void display_menu_bar
P_ ((struct window
*));
700 static int display_count_lines
P_ ((int, int, int, int, int *));
701 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
702 int, int, struct it
*, int, int, int, int));
703 static void compute_line_metrics
P_ ((struct it
*));
704 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
705 static int get_overlay_strings
P_ ((struct it
*));
706 static void next_overlay_string
P_ ((struct it
*));
707 static void reseat
P_ ((struct it
*, struct text_pos
, int));
708 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
709 static void back_to_previous_visible_line_start
P_ ((struct it
*));
710 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
711 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
712 static int next_element_from_display_vector
P_ ((struct it
*));
713 static int next_element_from_string
P_ ((struct it
*));
714 static int next_element_from_c_string
P_ ((struct it
*));
715 static int next_element_from_buffer
P_ ((struct it
*));
716 static int next_element_from_composition
P_ ((struct it
*));
717 static int next_element_from_image
P_ ((struct it
*));
718 static int next_element_from_stretch
P_ ((struct it
*));
719 static void load_overlay_strings
P_ ((struct it
*));
720 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
721 struct display_pos
*));
722 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
723 Lisp_Object
, int, int, int, int));
724 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
726 void move_it_vertically_backward
P_ ((struct it
*, int));
727 static void init_to_row_start
P_ ((struct it
*, struct window
*,
728 struct glyph_row
*));
729 static void init_to_row_end
P_ ((struct it
*, struct window
*,
730 struct glyph_row
*));
731 static void back_to_previous_line_start
P_ ((struct it
*));
732 static int forward_to_next_line_start
P_ ((struct it
*, int *));
733 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
735 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
736 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
737 static int number_of_chars
P_ ((unsigned char *, int));
738 static void compute_stop_pos
P_ ((struct it
*));
739 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
741 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
742 static int next_overlay_change
P_ ((int));
743 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
744 Lisp_Object
, struct text_pos
*));
746 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
747 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
749 #ifdef HAVE_WINDOW_SYSTEM
751 static void update_tool_bar
P_ ((struct frame
*, int));
752 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
753 static int redisplay_tool_bar
P_ ((struct frame
*));
754 static void display_tool_bar_line
P_ ((struct it
*));
756 #endif /* HAVE_WINDOW_SYSTEM */
759 /***********************************************************************
760 Window display dimensions
761 ***********************************************************************/
763 /* Return the window-relative maximum y + 1 for glyph rows displaying
764 text in window W. This is the height of W minus the height of a
765 mode line, if any. */
768 window_text_bottom_y (w
)
771 struct frame
*f
= XFRAME (w
->frame
);
772 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
774 if (WINDOW_WANTS_MODELINE_P (w
))
775 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
780 /* Return the pixel width of display area AREA of window W. AREA < 0
781 means return the total width of W, not including bitmap areas to
782 the left and right of the window. */
785 window_box_width (w
, area
)
789 struct frame
*f
= XFRAME (w
->frame
);
790 int width
= XFASTINT (w
->width
);
792 if (!w
->pseudo_window_p
)
794 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
796 if (area
== TEXT_AREA
)
798 if (INTEGERP (w
->left_margin_width
))
799 width
-= XFASTINT (w
->left_margin_width
);
800 if (INTEGERP (w
->right_margin_width
))
801 width
-= XFASTINT (w
->right_margin_width
);
803 else if (area
== LEFT_MARGIN_AREA
)
804 width
= (INTEGERP (w
->left_margin_width
)
805 ? XFASTINT (w
->left_margin_width
) : 0);
806 else if (area
== RIGHT_MARGIN_AREA
)
807 width
= (INTEGERP (w
->right_margin_width
)
808 ? XFASTINT (w
->right_margin_width
) : 0);
811 return width
* CANON_X_UNIT (f
);
815 /* Return the pixel height of the display area of window W, not
816 including mode lines of W, if any.. */
819 window_box_height (w
)
822 struct frame
*f
= XFRAME (w
->frame
);
823 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
825 xassert (height
>= 0);
827 if (WINDOW_WANTS_MODELINE_P (w
))
828 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
830 if (WINDOW_WANTS_HEADER_LINE_P (w
))
831 height
-= CURRENT_HEADER_LINE_HEIGHT (w
);
837 /* Return the frame-relative coordinate of the left edge of display
838 area AREA of window W. AREA < 0 means return the left edge of the
839 whole window, to the right of any bitmap area at the left side of
843 window_box_left (w
, area
)
847 struct frame
*f
= XFRAME (w
->frame
);
848 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
850 if (!w
->pseudo_window_p
)
852 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
853 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
855 if (area
== TEXT_AREA
)
856 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
857 else if (area
== RIGHT_MARGIN_AREA
)
858 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
859 + window_box_width (w
, TEXT_AREA
));
866 /* Return the frame-relative coordinate of the right edge of display
867 area AREA of window W. AREA < 0 means return the left edge of the
868 whole window, to the left of any bitmap area at the right side of
872 window_box_right (w
, area
)
876 return window_box_left (w
, area
) + window_box_width (w
, area
);
880 /* Get the bounding box of the display area AREA of window W, without
881 mode lines, in frame-relative coordinates. AREA < 0 means the
882 whole window, not including bitmap areas to the left and right of
883 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
884 coordinates of the upper-left corner of the box. Return in
885 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
888 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
891 int *box_x
, *box_y
, *box_width
, *box_height
;
893 struct frame
*f
= XFRAME (w
->frame
);
895 *box_width
= window_box_width (w
, area
);
896 *box_height
= window_box_height (w
);
897 *box_x
= window_box_left (w
, area
);
898 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
899 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
900 if (WINDOW_WANTS_HEADER_LINE_P (w
))
901 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
905 /* Get the bounding box of the display area AREA of window W, without
906 mode lines. AREA < 0 means the whole window, not including bitmap
907 areas to the left and right of the window. Return in *TOP_LEFT_X
908 and TOP_LEFT_Y the frame-relative pixel coordinates of the
909 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
910 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
914 window_box_edges (w
, area
, top_left_x
, top_left_y
,
915 bottom_right_x
, bottom_right_y
)
918 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
920 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
922 *bottom_right_x
+= *top_left_x
;
923 *bottom_right_y
+= *top_left_y
;
928 /***********************************************************************
930 ***********************************************************************/
932 /* Return the next character from STR which is MAXLEN bytes long.
933 Return in *LEN the length of the character. This is like
934 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
935 we find one, we return a `?', but with the length of the invalid
939 string_char_and_length (str
, maxlen
, len
)
945 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
946 if (!CHAR_VALID_P (c
, 1))
947 /* We may not change the length here because other places in Emacs
948 don't use this function, i.e. they silently accept invalid
957 /* Given a position POS containing a valid character and byte position
958 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
960 static struct text_pos
961 string_pos_nchars_ahead (pos
, string
, nchars
)
966 xassert (STRINGP (string
) && nchars
>= 0);
968 if (STRING_MULTIBYTE (string
))
970 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
971 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
976 string_char_and_length (p
, rest
, &len
);
977 p
+= len
, rest
-= len
;
980 BYTEPOS (pos
) += len
;
984 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
990 /* Value is the text position, i.e. character and byte position,
991 for character position CHARPOS in STRING. */
993 static INLINE
struct text_pos
994 string_pos (charpos
, string
)
999 xassert (STRINGP (string
));
1000 xassert (charpos
>= 0);
1001 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1006 /* Value is a text position, i.e. character and byte position, for
1007 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1008 means recognize multibyte characters. */
1010 static struct text_pos
1011 c_string_pos (charpos
, s
, multibyte_p
)
1016 struct text_pos pos
;
1018 xassert (s
!= NULL
);
1019 xassert (charpos
>= 0);
1023 int rest
= strlen (s
), len
;
1025 SET_TEXT_POS (pos
, 0, 0);
1028 string_char_and_length (s
, rest
, &len
);
1029 s
+= len
, rest
-= len
;
1030 xassert (rest
>= 0);
1032 BYTEPOS (pos
) += len
;
1036 SET_TEXT_POS (pos
, charpos
, charpos
);
1042 /* Value is the number of characters in C string S. MULTIBYTE_P
1043 non-zero means recognize multibyte characters. */
1046 number_of_chars (s
, multibyte_p
)
1054 int rest
= strlen (s
), len
;
1055 unsigned char *p
= (unsigned char *) s
;
1057 for (nchars
= 0; rest
> 0; ++nchars
)
1059 string_char_and_length (p
, rest
, &len
);
1060 rest
-= len
, p
+= len
;
1064 nchars
= strlen (s
);
1070 /* Compute byte position NEWPOS->bytepos corresponding to
1071 NEWPOS->charpos. POS is a known position in string STRING.
1072 NEWPOS->charpos must be >= POS.charpos. */
1075 compute_string_pos (newpos
, pos
, string
)
1076 struct text_pos
*newpos
, pos
;
1079 xassert (STRINGP (string
));
1080 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1082 if (STRING_MULTIBYTE (string
))
1083 *newpos
= string_pos_nchars_ahead (pos
, string
,
1084 CHARPOS (*newpos
) - CHARPOS (pos
));
1086 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1091 /***********************************************************************
1092 Lisp form evaluation
1093 ***********************************************************************/
1095 /* Error handler for safe_eval and safe_call. */
1098 safe_eval_handler (arg
)
1105 /* Evaluate SEXPR and return the result, or nil if something went
1112 int count
= specpdl_ptr
- specpdl
;
1113 struct gcpro gcpro1
;
1117 specbind (Qinhibit_redisplay
, Qt
);
1118 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, safe_eval_handler
);
1120 return unbind_to (count
, val
);
1124 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1125 Return the result, or nil if something went wrong. */
1128 safe_call (nargs
, args
)
1132 int count
= specpdl_ptr
- specpdl
;
1134 struct gcpro gcpro1
;
1137 gcpro1
.nvars
= nargs
;
1138 specbind (Qinhibit_redisplay
, Qt
);
1139 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1142 return unbind_to (count
, val
);
1146 /* Call function FN with one argument ARG.
1147 Return the result, or nil if something went wrong. */
1150 safe_call1 (fn
, arg
)
1151 Lisp_Object fn
, arg
;
1153 Lisp_Object args
[2];
1156 return safe_call (2, args
);
1161 /***********************************************************************
1163 ***********************************************************************/
1167 /* Define CHECK_IT to perform sanity checks on iterators.
1168 This is for debugging. It is too slow to do unconditionally. */
1174 if (it
->method
== next_element_from_string
)
1176 xassert (STRINGP (it
->string
));
1177 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1179 else if (it
->method
== next_element_from_buffer
)
1181 /* Check that character and byte positions agree. */
1182 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1186 xassert (it
->current
.dpvec_index
>= 0);
1188 xassert (it
->current
.dpvec_index
< 0);
1191 #define CHECK_IT(IT) check_it ((IT))
1195 #define CHECK_IT(IT) (void) 0
1202 /* Check that the window end of window W is what we expect it
1203 to be---the last row in the current matrix displaying text. */
1206 check_window_end (w
)
1209 if (!MINI_WINDOW_P (w
)
1210 && !NILP (w
->window_end_valid
))
1212 struct glyph_row
*row
;
1213 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1214 XFASTINT (w
->window_end_vpos
)),
1216 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1217 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1221 #define CHECK_WINDOW_END(W) check_window_end ((W))
1223 #else /* not GLYPH_DEBUG */
1225 #define CHECK_WINDOW_END(W) (void) 0
1227 #endif /* not GLYPH_DEBUG */
1231 /***********************************************************************
1232 Iterator initialization
1233 ***********************************************************************/
1235 /* Initialize IT for displaying current_buffer in window W, starting
1236 at character position CHARPOS. CHARPOS < 0 means that no buffer
1237 position is specified which is useful when the iterator is assigned
1238 a position later. BYTEPOS is the byte position corresponding to
1239 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1241 If ROW is not null, calls to produce_glyphs with IT as parameter
1242 will produce glyphs in that row.
1244 BASE_FACE_ID is the id of a base face to use. It must be one of
1245 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1246 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1247 displaying the tool-bar.
1249 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1250 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1251 corresponding mode line glyph row of the desired matrix of W. */
1254 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1257 int charpos
, bytepos
;
1258 struct glyph_row
*row
;
1259 enum face_id base_face_id
;
1261 int highlight_region_p
;
1263 /* Some precondition checks. */
1264 xassert (w
!= NULL
&& it
!= NULL
);
1265 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1267 /* If face attributes have been changed since the last redisplay,
1268 free realized faces now because they depend on face definitions
1269 that might have changed. */
1270 if (face_change_count
)
1272 face_change_count
= 0;
1273 free_all_realized_faces (Qnil
);
1276 /* Use one of the mode line rows of W's desired matrix if
1280 if (base_face_id
== MODE_LINE_FACE_ID
)
1281 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1282 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1283 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1287 bzero (it
, sizeof *it
);
1288 it
->current
.overlay_string_index
= -1;
1289 it
->current
.dpvec_index
= -1;
1290 it
->base_face_id
= base_face_id
;
1292 /* The window in which we iterate over current_buffer: */
1293 XSETWINDOW (it
->window
, w
);
1295 it
->f
= XFRAME (w
->frame
);
1297 /* Extra space between lines (on window systems only). */
1298 if (base_face_id
== DEFAULT_FACE_ID
1299 && FRAME_WINDOW_P (it
->f
))
1301 if (NATNUMP (current_buffer
->extra_line_spacing
))
1302 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1303 else if (it
->f
->extra_line_spacing
> 0)
1304 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1307 /* If realized faces have been removed, e.g. because of face
1308 attribute changes of named faces, recompute them. */
1309 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1310 recompute_basic_faces (it
->f
);
1312 /* Current value of the `space-width', and 'height' properties. */
1313 it
->space_width
= Qnil
;
1314 it
->font_height
= Qnil
;
1316 /* Are control characters displayed as `^C'? */
1317 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1319 /* -1 means everything between a CR and the following line end
1320 is invisible. >0 means lines indented more than this value are
1322 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1323 ? XFASTINT (current_buffer
->selective_display
)
1324 : (!NILP (current_buffer
->selective_display
)
1326 it
->selective_display_ellipsis_p
1327 = !NILP (current_buffer
->selective_display_ellipses
);
1329 /* Display table to use. */
1330 it
->dp
= window_display_table (w
);
1332 /* Are multibyte characters enabled in current_buffer? */
1333 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1335 /* Non-zero if we should highlight the region. */
1337 = (!NILP (Vtransient_mark_mode
)
1338 && !NILP (current_buffer
->mark_active
)
1339 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1341 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1342 start and end of a visible region in window IT->w. Set both to
1343 -1 to indicate no region. */
1344 if (highlight_region_p
1345 /* Maybe highlight only in selected window. */
1346 && (/* Either show region everywhere. */
1347 highlight_nonselected_windows
1348 /* Or show region in the selected window. */
1349 || w
== XWINDOW (selected_window
)
1350 /* Or show the region if we are in the mini-buffer and W is
1351 the window the mini-buffer refers to. */
1352 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1353 && w
== XWINDOW (Vminibuf_scroll_window
))))
1355 int charpos
= marker_position (current_buffer
->mark
);
1356 it
->region_beg_charpos
= min (PT
, charpos
);
1357 it
->region_end_charpos
= max (PT
, charpos
);
1360 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1362 /* Get the position at which the redisplay_end_trigger hook should
1363 be run, if it is to be run at all. */
1364 if (MARKERP (w
->redisplay_end_trigger
)
1365 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1366 it
->redisplay_end_trigger_charpos
1367 = marker_position (w
->redisplay_end_trigger
);
1368 else if (INTEGERP (w
->redisplay_end_trigger
))
1369 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1371 /* Correct bogus values of tab_width. */
1372 it
->tab_width
= XINT (current_buffer
->tab_width
);
1373 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1376 /* Are lines in the display truncated? */
1377 it
->truncate_lines_p
1378 = (base_face_id
!= DEFAULT_FACE_ID
1379 || XINT (it
->w
->hscroll
)
1380 || (truncate_partial_width_windows
1381 && !WINDOW_FULL_WIDTH_P (it
->w
))
1382 || !NILP (current_buffer
->truncate_lines
));
1384 /* Get dimensions of truncation and continuation glyphs. These are
1385 displayed as bitmaps under X, so we don't need them for such
1387 if (!FRAME_WINDOW_P (it
->f
))
1389 if (it
->truncate_lines_p
)
1391 /* We will need the truncation glyph. */
1392 xassert (it
->glyph_row
== NULL
);
1393 produce_special_glyphs (it
, IT_TRUNCATION
);
1394 it
->truncation_pixel_width
= it
->pixel_width
;
1398 /* We will need the continuation glyph. */
1399 xassert (it
->glyph_row
== NULL
);
1400 produce_special_glyphs (it
, IT_CONTINUATION
);
1401 it
->continuation_pixel_width
= it
->pixel_width
;
1404 /* Reset these values to zero becaue the produce_special_glyphs
1405 above has changed them. */
1406 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1407 it
->phys_ascent
= it
->phys_descent
= 0;
1410 /* Set this after getting the dimensions of truncation and
1411 continuation glyphs, so that we don't produce glyphs when calling
1412 produce_special_glyphs, above. */
1413 it
->glyph_row
= row
;
1414 it
->area
= TEXT_AREA
;
1416 /* Get the dimensions of the display area. The display area
1417 consists of the visible window area plus a horizontally scrolled
1418 part to the left of the window. All x-values are relative to the
1419 start of this total display area. */
1420 if (base_face_id
!= DEFAULT_FACE_ID
)
1422 /* Mode lines, menu bar in terminal frames. */
1423 it
->first_visible_x
= 0;
1424 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1429 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1430 it
->last_visible_x
= (it
->first_visible_x
1431 + window_box_width (w
, TEXT_AREA
));
1433 /* If we truncate lines, leave room for the truncator glyph(s) at
1434 the right margin. Otherwise, leave room for the continuation
1435 glyph(s). Truncation and continuation glyphs are not inserted
1436 for window-based redisplay. */
1437 if (!FRAME_WINDOW_P (it
->f
))
1439 if (it
->truncate_lines_p
)
1440 it
->last_visible_x
-= it
->truncation_pixel_width
;
1442 it
->last_visible_x
-= it
->continuation_pixel_width
;
1445 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1446 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1449 /* Leave room for a border glyph. */
1450 if (!FRAME_WINDOW_P (it
->f
)
1451 && !WINDOW_RIGHTMOST_P (it
->w
))
1452 it
->last_visible_x
-= 1;
1454 it
->last_visible_y
= window_text_bottom_y (w
);
1456 /* For mode lines and alike, arrange for the first glyph having a
1457 left box line if the face specifies a box. */
1458 if (base_face_id
!= DEFAULT_FACE_ID
)
1462 it
->face_id
= base_face_id
;
1464 /* If we have a boxed mode line, make the first character appear
1465 with a left box line. */
1466 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1467 if (face
->box
!= FACE_NO_BOX
)
1468 it
->start_of_box_run_p
= 1;
1471 /* If a buffer position was specified, set the iterator there,
1472 getting overlays and face properties from that position. */
1475 it
->end_charpos
= ZV
;
1477 IT_CHARPOS (*it
) = charpos
;
1479 /* Compute byte position if not specified. */
1481 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1483 IT_BYTEPOS (*it
) = bytepos
;
1485 /* Compute faces etc. */
1486 reseat (it
, it
->current
.pos
, 1);
1493 /* Initialize IT for the display of window W with window start POS. */
1496 start_display (it
, w
, pos
)
1499 struct text_pos pos
;
1501 int start_at_line_beg_p
;
1502 struct glyph_row
*row
;
1503 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1506 row
= w
->desired_matrix
->rows
+ first_vpos
;
1507 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1508 first_y
= it
->current_y
;
1510 /* If window start is not at a line start, move back to the line
1511 start. This makes sure that we take continuation lines into
1513 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1514 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1515 if (!start_at_line_beg_p
)
1516 reseat_at_previous_visible_line_start (it
);
1518 /* If window start is not at a line start, skip forward to POS to
1519 get the correct continuation_lines_width and current_x. */
1520 if (!start_at_line_beg_p
)
1522 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1524 /* If lines are continued, this line may end in the middle of a
1525 multi-glyph character (e.g. a control character displayed as
1526 \003, or in the middle of an overlay string). In this case
1527 move_it_to above will not have taken us to the start of
1528 the continuation line but to the end of the continued line. */
1529 if (!it
->truncate_lines_p
)
1531 if (it
->current_x
> 0)
1533 if (it
->current
.dpvec_index
>= 0
1534 || it
->current
.overlay_string_index
>= 0)
1536 set_iterator_to_next (it
, 1);
1537 move_it_in_display_line_to (it
, -1, -1, 0);
1540 it
->continuation_lines_width
+= it
->current_x
;
1543 /* We're starting a new display line, not affected by the
1544 height of the continued line, so clear the appropriate
1545 fields in the iterator structure. */
1546 it
->max_ascent
= it
->max_descent
= 0;
1547 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1550 it
->current_y
= first_y
;
1552 it
->current_x
= it
->hpos
= 0;
1555 #if 0 /* Don't assert the following because start_display is sometimes
1556 called intentionally with a window start that is not at a
1557 line start. Please leave this code in as a comment. */
1559 /* Window start should be on a line start, now. */
1560 xassert (it
->continuation_lines_width
1561 || IT_CHARPOS (it
) == BEGV
1562 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1567 /* Initialize IT for stepping through current_buffer in window W,
1568 starting at position POS that includes overlay string and display
1569 vector/ control character translation position information. */
1572 init_from_display_pos (it
, w
, pos
)
1575 struct display_pos
*pos
;
1577 /* Keep in mind: the call to reseat in init_iterator skips invisible
1578 text, so we might end up at a position different from POS. This
1579 is only a problem when POS is a row start after a newline and an
1580 overlay starts there with an after-string, and the overlay has an
1581 invisible property. Since we don't skip invisible text in
1582 display_line and elsewhere immediately after consuming the
1583 newline before the row start, such a POS will not be in a string,
1584 but the call to init_iterator below will move us to the
1586 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1587 NULL
, DEFAULT_FACE_ID
);
1589 /* If position is within an overlay string, set up IT to
1590 the right overlay string. */
1591 if (pos
->overlay_string_index
>= 0)
1595 /* We already have the first chunk of overlay strings in
1596 IT->overlay_strings. Load more until the one for
1597 pos->overlay_string_index is in IT->overlay_strings. */
1598 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1600 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1601 it
->current
.overlay_string_index
= 0;
1604 load_overlay_strings (it
);
1605 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1609 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1610 relative_index
= (it
->current
.overlay_string_index
1611 % OVERLAY_STRING_CHUNK_SIZE
);
1612 it
->string
= it
->overlay_strings
[relative_index
];
1613 xassert (STRINGP (it
->string
));
1614 it
->current
.string_pos
= pos
->string_pos
;
1615 it
->method
= next_element_from_string
;
1617 else if (CHARPOS (pos
->string_pos
) >= 0)
1619 /* Recorded position is not in an overlay string, but in another
1620 string. This can only be a string from a `display' property.
1621 IT should already be filled with that string. */
1622 it
->current
.string_pos
= pos
->string_pos
;
1623 xassert (STRINGP (it
->string
));
1626 /* Restore position in display vector translations or control
1627 character translations. */
1628 if (pos
->dpvec_index
>= 0)
1630 /* This fills IT->dpvec. */
1631 get_next_display_element (it
);
1632 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1633 it
->current
.dpvec_index
= pos
->dpvec_index
;
1640 /* Initialize IT for stepping through current_buffer in window W
1641 starting at ROW->start. */
1644 init_to_row_start (it
, w
, row
)
1647 struct glyph_row
*row
;
1649 init_from_display_pos (it
, w
, &row
->start
);
1650 it
->continuation_lines_width
= row
->continuation_lines_width
;
1655 /* Initialize IT for stepping through current_buffer in window W
1656 starting in the line following ROW, i.e. starting at ROW->end. */
1659 init_to_row_end (it
, w
, row
)
1662 struct glyph_row
*row
;
1664 init_from_display_pos (it
, w
, &row
->end
);
1666 if (row
->continued_p
)
1667 it
->continuation_lines_width
= (row
->continuation_lines_width
1668 + row
->pixel_width
);
1675 /***********************************************************************
1677 ***********************************************************************/
1679 /* Called when IT reaches IT->stop_charpos. Handle text property and
1680 overlay changes. Set IT->stop_charpos to the next position where
1687 enum prop_handled handled
;
1688 int handle_overlay_change_p
= 1;
1692 it
->current
.dpvec_index
= -1;
1696 handled
= HANDLED_NORMALLY
;
1698 /* Call text property handlers. */
1699 for (p
= it_props
; p
->handler
; ++p
)
1701 handled
= p
->handler (it
);
1703 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1705 else if (handled
== HANDLED_RETURN
)
1707 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1708 handle_overlay_change_p
= 0;
1711 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1713 /* Don't check for overlay strings below when set to deliver
1714 characters from a display vector. */
1715 if (it
->method
== next_element_from_display_vector
)
1716 handle_overlay_change_p
= 0;
1718 /* Handle overlay changes. */
1719 if (handle_overlay_change_p
)
1720 handled
= handle_overlay_change (it
);
1722 /* Determine where to stop next. */
1723 if (handled
== HANDLED_NORMALLY
)
1724 compute_stop_pos (it
);
1727 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1731 /* Compute IT->stop_charpos from text property and overlay change
1732 information for IT's current position. */
1735 compute_stop_pos (it
)
1738 register INTERVAL iv
, next_iv
;
1739 Lisp_Object object
, limit
, position
;
1741 /* If nowhere else, stop at the end. */
1742 it
->stop_charpos
= it
->end_charpos
;
1744 if (STRINGP (it
->string
))
1746 /* Strings are usually short, so don't limit the search for
1748 object
= it
->string
;
1750 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1756 /* If next overlay change is in front of the current stop pos
1757 (which is IT->end_charpos), stop there. Note: value of
1758 next_overlay_change is point-max if no overlay change
1760 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1761 if (charpos
< it
->stop_charpos
)
1762 it
->stop_charpos
= charpos
;
1764 /* If showing the region, we have to stop at the region
1765 start or end because the face might change there. */
1766 if (it
->region_beg_charpos
> 0)
1768 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1769 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1770 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1771 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1774 /* Set up variables for computing the stop position from text
1775 property changes. */
1776 XSETBUFFER (object
, current_buffer
);
1777 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1778 XSETFASTINT (position
, IT_CHARPOS (*it
));
1782 /* Get the interval containing IT's position. Value is a null
1783 interval if there isn't such an interval. */
1784 iv
= validate_interval_range (object
, &position
, &position
, 0);
1785 if (!NULL_INTERVAL_P (iv
))
1787 Lisp_Object values_here
[LAST_PROP_IDX
];
1790 /* Get properties here. */
1791 for (p
= it_props
; p
->handler
; ++p
)
1792 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1794 /* Look for an interval following iv that has different
1796 for (next_iv
= next_interval (iv
);
1797 (!NULL_INTERVAL_P (next_iv
)
1799 || XFASTINT (limit
) > next_iv
->position
));
1800 next_iv
= next_interval (next_iv
))
1802 for (p
= it_props
; p
->handler
; ++p
)
1804 Lisp_Object new_value
;
1806 new_value
= textget (next_iv
->plist
, *p
->name
);
1807 if (!EQ (values_here
[p
->idx
], new_value
))
1815 if (!NULL_INTERVAL_P (next_iv
))
1817 if (INTEGERP (limit
)
1818 && next_iv
->position
>= XFASTINT (limit
))
1819 /* No text property change up to limit. */
1820 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1822 /* Text properties change in next_iv. */
1823 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1827 xassert (STRINGP (it
->string
)
1828 || (it
->stop_charpos
>= BEGV
1829 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1833 /* Return the position of the next overlay change after POS in
1834 current_buffer. Value is point-max if no overlay change
1835 follows. This is like `next-overlay-change' but doesn't use
1839 next_overlay_change (pos
)
1844 Lisp_Object
*overlays
;
1848 /* Get all overlays at the given position. */
1850 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1851 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
1852 if (noverlays
> len
)
1855 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1856 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
1859 /* If any of these overlays ends before endpos,
1860 use its ending point instead. */
1861 for (i
= 0; i
< noverlays
; ++i
)
1866 oend
= OVERLAY_END (overlays
[i
]);
1867 oendpos
= OVERLAY_POSITION (oend
);
1868 endpos
= min (endpos
, oendpos
);
1876 /***********************************************************************
1878 ***********************************************************************/
1880 /* Handle changes in the `fontified' property of the current buffer by
1881 calling hook functions from Qfontification_functions to fontify
1884 static enum prop_handled
1885 handle_fontified_prop (it
)
1888 Lisp_Object prop
, pos
;
1889 enum prop_handled handled
= HANDLED_NORMALLY
;
1891 /* Get the value of the `fontified' property at IT's current buffer
1892 position. (The `fontified' property doesn't have a special
1893 meaning in strings.) If the value is nil, call functions from
1894 Qfontification_functions. */
1895 if (!STRINGP (it
->string
)
1897 && !NILP (Vfontification_functions
)
1898 && !NILP (Vrun_hooks
)
1899 && (pos
= make_number (IT_CHARPOS (*it
)),
1900 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1903 int count
= specpdl_ptr
- specpdl
;
1906 val
= Vfontification_functions
;
1907 specbind (Qfontification_functions
, Qnil
);
1908 specbind (Qafter_change_functions
, Qnil
);
1910 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
1911 safe_call1 (val
, pos
);
1914 Lisp_Object globals
, fn
;
1915 struct gcpro gcpro1
, gcpro2
;
1918 GCPRO2 (val
, globals
);
1920 for (; CONSP (val
); val
= XCDR (val
))
1926 /* A value of t indicates this hook has a local
1927 binding; it means to run the global binding too.
1928 In a global value, t should not occur. If it
1929 does, we must ignore it to avoid an endless
1931 for (globals
= Fdefault_value (Qfontification_functions
);
1933 globals
= XCDR (globals
))
1935 fn
= XCAR (globals
);
1937 safe_call1 (fn
, pos
);
1941 safe_call1 (fn
, pos
);
1947 unbind_to (count
, Qnil
);
1949 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
1950 something. This avoids an endless loop if they failed to
1951 fontify the text for which reason ever. */
1952 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
1953 handled
= HANDLED_RECOMPUTE_PROPS
;
1961 /***********************************************************************
1963 ***********************************************************************/
1965 /* Set up iterator IT from face properties at its current position.
1966 Called from handle_stop. */
1968 static enum prop_handled
1969 handle_face_prop (it
)
1972 int new_face_id
, next_stop
;
1974 if (!STRINGP (it
->string
))
1977 = face_at_buffer_position (it
->w
,
1979 it
->region_beg_charpos
,
1980 it
->region_end_charpos
,
1983 + TEXT_PROP_DISTANCE_LIMIT
),
1986 /* Is this a start of a run of characters with box face?
1987 Caveat: this can be called for a freshly initialized
1988 iterator; face_id is -1 is this case. We know that the new
1989 face will not change until limit, i.e. if the new face has a
1990 box, all characters up to limit will have one. But, as
1991 usual, we don't know whether limit is really the end. */
1992 if (new_face_id
!= it
->face_id
)
1994 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1996 /* If new face has a box but old face has not, this is
1997 the start of a run of characters with box, i.e. it has
1998 a shadow on the left side. The value of face_id of the
1999 iterator will be -1 if this is the initial call that gets
2000 the face. In this case, we have to look in front of IT's
2001 position and see whether there is a face != new_face_id. */
2002 it
->start_of_box_run_p
2003 = (new_face
->box
!= FACE_NO_BOX
2004 && (it
->face_id
>= 0
2005 || IT_CHARPOS (*it
) == BEG
2006 || new_face_id
!= face_before_it_pos (it
)));
2007 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2013 = face_at_string_position (it
->w
,
2015 IT_STRING_CHARPOS (*it
),
2016 (it
->current
.overlay_string_index
>= 0
2019 it
->region_beg_charpos
,
2020 it
->region_end_charpos
,
2024 #if 0 /* This shouldn't be neccessary. Let's check it. */
2025 /* If IT is used to display a mode line we would really like to
2026 use the mode line face instead of the frame's default face. */
2027 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2028 && new_face_id
== DEFAULT_FACE_ID
)
2029 new_face_id
= MODE_LINE_FACE_ID
;
2032 /* Is this a start of a run of characters with box? Caveat:
2033 this can be called for a freshly allocated iterator; face_id
2034 is -1 is this case. We know that the new face will not
2035 change until the next check pos, i.e. if the new face has a
2036 box, all characters up to that position will have a
2037 box. But, as usual, we don't know whether that position
2038 is really the end. */
2039 if (new_face_id
!= it
->face_id
)
2041 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2042 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2044 /* If new face has a box but old face hasn't, this is the
2045 start of a run of characters with box, i.e. it has a
2046 shadow on the left side. */
2047 it
->start_of_box_run_p
2048 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2049 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2053 it
->face_id
= new_face_id
;
2054 return HANDLED_NORMALLY
;
2058 /* Compute the face one character before or after the current position
2059 of IT. BEFORE_P non-zero means get the face in front of IT's
2060 position. Value is the id of the face. */
2063 face_before_or_after_it_pos (it
, before_p
)
2068 int next_check_charpos
;
2069 struct text_pos pos
;
2071 xassert (it
->s
== NULL
);
2073 if (STRINGP (it
->string
))
2075 /* No face change past the end of the string (for the case
2076 we are padding with spaces). No face change before the
2078 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2079 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2082 /* Set pos to the position before or after IT's current position. */
2084 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2086 /* For composition, we must check the character after the
2088 pos
= (it
->what
== IT_COMPOSITION
2089 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2090 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2092 /* Get the face for ASCII, or unibyte. */
2094 = face_at_string_position (it
->w
,
2097 (it
->current
.overlay_string_index
>= 0
2100 it
->region_beg_charpos
,
2101 it
->region_end_charpos
,
2102 &next_check_charpos
,
2105 /* Correct the face for charsets different from ASCII. Do it
2106 for the multibyte case only. The face returned above is
2107 suitable for unibyte text if IT->string is unibyte. */
2108 if (STRING_MULTIBYTE (it
->string
))
2110 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2111 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2113 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2115 c
= string_char_and_length (p
, rest
, &len
);
2116 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2121 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2122 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2125 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2126 pos
= it
->current
.pos
;
2129 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2132 if (it
->what
== IT_COMPOSITION
)
2133 /* For composition, we must check the position after the
2135 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2137 INC_TEXT_POS (pos
, it
->multibyte_p
);
2139 /* Determine face for CHARSET_ASCII, or unibyte. */
2140 face_id
= face_at_buffer_position (it
->w
,
2142 it
->region_beg_charpos
,
2143 it
->region_end_charpos
,
2144 &next_check_charpos
,
2147 /* Correct the face for charsets different from ASCII. Do it
2148 for the multibyte case only. The face returned above is
2149 suitable for unibyte text if current_buffer is unibyte. */
2150 if (it
->multibyte_p
)
2152 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2153 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2154 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2163 /***********************************************************************
2165 ***********************************************************************/
2167 /* Set up iterator IT from invisible properties at its current
2168 position. Called from handle_stop. */
2170 static enum prop_handled
2171 handle_invisible_prop (it
)
2174 enum prop_handled handled
= HANDLED_NORMALLY
;
2176 if (STRINGP (it
->string
))
2178 extern Lisp_Object Qinvisible
;
2179 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2181 /* Get the value of the invisible text property at the
2182 current position. Value will be nil if there is no such
2184 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2185 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2188 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2190 handled
= HANDLED_RECOMPUTE_PROPS
;
2192 /* Get the position at which the next change of the
2193 invisible text property can be found in IT->string.
2194 Value will be nil if the property value is the same for
2195 all the rest of IT->string. */
2196 XSETINT (limit
, XSTRING (it
->string
)->size
);
2197 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2200 /* Text at current position is invisible. The next
2201 change in the property is at position end_charpos.
2202 Move IT's current position to that position. */
2203 if (INTEGERP (end_charpos
)
2204 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2206 struct text_pos old
;
2207 old
= it
->current
.string_pos
;
2208 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2209 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2213 /* The rest of the string is invisible. If this is an
2214 overlay string, proceed with the next overlay string
2215 or whatever comes and return a character from there. */
2216 if (it
->current
.overlay_string_index
>= 0)
2218 next_overlay_string (it
);
2219 /* Don't check for overlay strings when we just
2220 finished processing them. */
2221 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2225 struct Lisp_String
*s
= XSTRING (it
->string
);
2226 IT_STRING_CHARPOS (*it
) = s
->size
;
2227 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2234 int visible_p
, newpos
, next_stop
;
2235 Lisp_Object pos
, prop
;
2237 /* First of all, is there invisible text at this position? */
2238 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2239 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2241 /* If we are on invisible text, skip over it. */
2242 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2243 && IT_CHARPOS (*it
) < it
->end_charpos
)
2245 /* Record whether we have to display an ellipsis for the
2247 int display_ellipsis_p
2248 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2250 handled
= HANDLED_RECOMPUTE_PROPS
;
2252 /* Loop skipping over invisible text. The loop is left at
2253 ZV or with IT on the first char being visible again. */
2256 /* Try to skip some invisible text. Return value is the
2257 position reached which can be equal to IT's position
2258 if there is nothing invisible here. This skips both
2259 over invisible text properties and overlays with
2260 invisible property. */
2261 newpos
= skip_invisible (IT_CHARPOS (*it
),
2262 &next_stop
, ZV
, it
->window
);
2264 /* If we skipped nothing at all we weren't at invisible
2265 text in the first place. If everything to the end of
2266 the buffer was skipped, end the loop. */
2267 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2271 /* We skipped some characters but not necessarily
2272 all there are. Check if we ended up on visible
2273 text. Fget_char_property returns the property of
2274 the char before the given position, i.e. if we
2275 get visible_p = 1, this means that the char at
2276 newpos is visible. */
2277 XSETFASTINT (pos
, newpos
);
2278 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2279 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2282 /* If we ended up on invisible text, proceed to
2283 skip starting with next_stop. */
2285 IT_CHARPOS (*it
) = next_stop
;
2289 /* The position newpos is now either ZV or on visible text. */
2290 IT_CHARPOS (*it
) = newpos
;
2291 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2293 /* Maybe return `...' next for the end of the invisible text. */
2294 if (display_ellipsis_p
)
2297 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2299 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2300 it
->dpvec
= v
->contents
;
2301 it
->dpend
= v
->contents
+ v
->size
;
2305 /* Default `...'. */
2306 it
->dpvec
= default_invis_vector
;
2307 it
->dpend
= default_invis_vector
+ 3;
2310 /* The ellipsis display does not replace the display of
2311 the character at the new position. Indicate this by
2312 setting IT->dpvec_char_len to zero. */
2313 it
->dpvec_char_len
= 0;
2315 it
->current
.dpvec_index
= 0;
2316 it
->method
= next_element_from_display_vector
;
2326 /***********************************************************************
2328 ***********************************************************************/
2330 /* Set up iterator IT from `display' property at its current position.
2331 Called from handle_stop. */
2333 static enum prop_handled
2334 handle_display_prop (it
)
2337 Lisp_Object prop
, object
;
2338 struct text_pos
*position
;
2339 int space_or_image_found_p
;
2341 if (STRINGP (it
->string
))
2343 object
= it
->string
;
2344 position
= &it
->current
.string_pos
;
2349 position
= &it
->current
.pos
;
2352 /* Reset those iterator values set from display property values. */
2353 it
->font_height
= Qnil
;
2354 it
->space_width
= Qnil
;
2357 /* We don't support recursive `display' properties, i.e. string
2358 values that have a string `display' property, that have a string
2359 `display' property etc. */
2360 if (!it
->string_from_display_prop_p
)
2361 it
->area
= TEXT_AREA
;
2363 prop
= Fget_char_property (make_number (position
->charpos
),
2366 return HANDLED_NORMALLY
;
2368 space_or_image_found_p
= 0;
2370 && CONSP (XCAR (prop
))
2371 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2373 /* A list of sub-properties. */
2374 while (CONSP (prop
))
2376 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2377 space_or_image_found_p
= 1;
2381 else if (VECTORP (prop
))
2384 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2385 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2387 space_or_image_found_p
= 1;
2391 if (handle_single_display_prop (it
, prop
, object
, position
))
2392 space_or_image_found_p
= 1;
2395 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2399 /* Value is the position of the end of the `display' property starting
2400 at START_POS in OBJECT. */
2402 static struct text_pos
2403 display_prop_end (it
, object
, start_pos
)
2406 struct text_pos start_pos
;
2409 struct text_pos end_pos
;
2411 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2412 Qdisplay
, object
, Qnil
);
2413 CHARPOS (end_pos
) = XFASTINT (end
);
2414 if (STRINGP (object
))
2415 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2417 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2423 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2424 is the object in which the `display' property was found. *POSITION
2425 is the position at which it was found.
2427 If PROP is a `space' or `image' sub-property, set *POSITION to the
2428 end position of the `display' property.
2430 Value is non-zero if a `space' or `image' property value was found. */
2433 handle_single_display_prop (it
, prop
, object
, position
)
2437 struct text_pos
*position
;
2440 int space_or_image_found_p
= 0;
2443 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2444 evaluated. If the result is nil, VALUE is ignored. */
2446 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2455 if (!NILP (form
) && !EQ (form
, Qt
))
2457 struct gcpro gcpro1
;
2458 struct text_pos end_pos
, pt
;
2461 end_pos
= display_prop_end (it
, object
, *position
);
2463 /* Temporarily set point to the end position, and then evaluate
2464 the form. This makes `(eolp)' work as FORM. */
2465 if (BUFFERP (object
))
2468 BYTEPOS (pt
) = PT_BYTE
;
2469 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2472 form
= safe_eval (form
);
2474 if (BUFFERP (object
))
2475 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2483 && EQ (XCAR (prop
), Qheight
)
2484 && CONSP (XCDR (prop
)))
2486 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2489 /* `(height HEIGHT)'. */
2490 it
->font_height
= XCAR (XCDR (prop
));
2491 if (!NILP (it
->font_height
))
2493 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2494 int new_height
= -1;
2496 if (CONSP (it
->font_height
)
2497 && (EQ (XCAR (it
->font_height
), Qplus
)
2498 || EQ (XCAR (it
->font_height
), Qminus
))
2499 && CONSP (XCDR (it
->font_height
))
2500 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2502 /* `(+ N)' or `(- N)' where N is an integer. */
2503 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2504 if (EQ (XCAR (it
->font_height
), Qplus
))
2506 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2508 else if (FUNCTIONP (it
->font_height
))
2510 /* Call function with current height as argument.
2511 Value is the new height. */
2513 height
= safe_call1 (it
->font_height
,
2514 face
->lface
[LFACE_HEIGHT_INDEX
]);
2515 if (NUMBERP (height
))
2516 new_height
= XFLOATINT (height
);
2518 else if (NUMBERP (it
->font_height
))
2520 /* Value is a multiple of the canonical char height. */
2523 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2524 new_height
= (XFLOATINT (it
->font_height
)
2525 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2529 /* Evaluate IT->font_height with `height' bound to the
2530 current specified height to get the new height. */
2532 int count
= specpdl_ptr
- specpdl
;
2534 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2535 value
= safe_eval (it
->font_height
);
2536 unbind_to (count
, Qnil
);
2538 if (NUMBERP (value
))
2539 new_height
= XFLOATINT (value
);
2543 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2546 else if (CONSP (prop
)
2547 && EQ (XCAR (prop
), Qspace_width
)
2548 && CONSP (XCDR (prop
)))
2550 /* `(space_width WIDTH)'. */
2551 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2554 value
= XCAR (XCDR (prop
));
2555 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2556 it
->space_width
= value
;
2558 else if (CONSP (prop
)
2559 && EQ (XCAR (prop
), Qraise
)
2560 && CONSP (XCDR (prop
)))
2562 /* `(raise FACTOR)'. */
2563 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2566 #ifdef HAVE_WINDOW_SYSTEM
2567 value
= XCAR (XCDR (prop
));
2568 if (NUMBERP (value
))
2570 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2571 it
->voffset
= - (XFLOATINT (value
)
2572 * (FONT_HEIGHT (face
->font
)));
2574 #endif /* HAVE_WINDOW_SYSTEM */
2576 else if (!it
->string_from_display_prop_p
)
2578 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2579 VALUE) or `((margin nil) VALUE)' or VALUE. */
2580 Lisp_Object location
, value
;
2581 struct text_pos start_pos
;
2584 /* Characters having this form of property are not displayed, so
2585 we have to find the end of the property. */
2586 start_pos
= *position
;
2587 *position
= display_prop_end (it
, object
, start_pos
);
2590 /* Let's stop at the new position and assume that all
2591 text properties change there. */
2592 it
->stop_charpos
= position
->charpos
;
2594 location
= Qunbound
;
2595 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2599 value
= XCDR (prop
);
2601 value
= XCAR (value
);
2604 if (EQ (XCAR (tem
), Qmargin
)
2605 && (tem
= XCDR (tem
),
2606 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2608 || EQ (tem
, Qleft_margin
)
2609 || EQ (tem
, Qright_margin
))))
2613 if (EQ (location
, Qunbound
))
2619 #ifdef HAVE_WINDOW_SYSTEM
2620 if (FRAME_TERMCAP_P (it
->f
))
2621 valid_p
= STRINGP (value
);
2623 valid_p
= (STRINGP (value
)
2624 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2625 || valid_image_p (value
));
2626 #else /* not HAVE_WINDOW_SYSTEM */
2627 valid_p
= STRINGP (value
);
2628 #endif /* not HAVE_WINDOW_SYSTEM */
2630 if ((EQ (location
, Qleft_margin
)
2631 || EQ (location
, Qright_margin
)
2635 space_or_image_found_p
= 1;
2637 /* Save current settings of IT so that we can restore them
2638 when we are finished with the glyph property value. */
2641 if (NILP (location
))
2642 it
->area
= TEXT_AREA
;
2643 else if (EQ (location
, Qleft_margin
))
2644 it
->area
= LEFT_MARGIN_AREA
;
2646 it
->area
= RIGHT_MARGIN_AREA
;
2648 if (STRINGP (value
))
2651 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2652 it
->current
.overlay_string_index
= -1;
2653 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2654 it
->end_charpos
= it
->string_nchars
2655 = XSTRING (it
->string
)->size
;
2656 it
->method
= next_element_from_string
;
2657 it
->stop_charpos
= 0;
2658 it
->string_from_display_prop_p
= 1;
2660 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2662 it
->method
= next_element_from_stretch
;
2664 it
->current
.pos
= it
->position
= start_pos
;
2666 #ifdef HAVE_WINDOW_SYSTEM
2669 it
->what
= IT_IMAGE
;
2670 it
->image_id
= lookup_image (it
->f
, value
);
2671 it
->position
= start_pos
;
2672 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2673 it
->method
= next_element_from_image
;
2675 /* Say that we haven't consumed the characters with
2676 `display' property yet. The call to pop_it in
2677 set_iterator_to_next will clean this up. */
2678 *position
= start_pos
;
2680 #endif /* HAVE_WINDOW_SYSTEM */
2683 /* Invalid property or property not supported. Restore
2684 the position to what it was before. */
2685 *position
= start_pos
;
2688 return space_or_image_found_p
;
2692 /* Check if PROP is a display sub-property value whose text should be
2693 treated as intangible. */
2696 single_display_prop_intangible_p (prop
)
2699 /* Skip over `when FORM'. */
2700 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2711 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
2712 we don't need to treat text as intangible. */
2713 if (EQ (XCAR (prop
), Qmargin
))
2721 || EQ (XCAR (prop
), Qleft_margin
)
2722 || EQ (XCAR (prop
), Qright_margin
))
2726 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
2730 /* Check if PROP is a display property value whose text should be
2731 treated as intangible. */
2734 display_prop_intangible_p (prop
)
2738 && CONSP (XCAR (prop
))
2739 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2741 /* A list of sub-properties. */
2742 while (CONSP (prop
))
2744 if (single_display_prop_intangible_p (XCAR (prop
)))
2749 else if (VECTORP (prop
))
2751 /* A vector of sub-properties. */
2753 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2754 if (single_display_prop_intangible_p (XVECTOR (prop
)->contents
[i
]))
2758 return single_display_prop_intangible_p (prop
);
2764 /***********************************************************************
2765 `composition' property
2766 ***********************************************************************/
2768 /* Set up iterator IT from `composition' property at its current
2769 position. Called from handle_stop. */
2771 static enum prop_handled
2772 handle_composition_prop (it
)
2775 Lisp_Object prop
, string
;
2776 int pos
, pos_byte
, end
;
2777 enum prop_handled handled
= HANDLED_NORMALLY
;
2779 if (STRINGP (it
->string
))
2781 pos
= IT_STRING_CHARPOS (*it
);
2782 pos_byte
= IT_STRING_BYTEPOS (*it
);
2783 string
= it
->string
;
2787 pos
= IT_CHARPOS (*it
);
2788 pos_byte
= IT_BYTEPOS (*it
);
2792 /* If there's a valid composition and point is not inside of the
2793 composition (in the case that the composition is from the current
2794 buffer), draw a glyph composed from the composition components. */
2795 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
2796 && COMPOSITION_VALID_P (pos
, end
, prop
)
2797 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
2799 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
2803 it
->method
= next_element_from_composition
;
2805 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
2806 /* For a terminal, draw only the first character of the
2808 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
2809 it
->len
= (STRINGP (it
->string
)
2810 ? string_char_to_byte (it
->string
, end
)
2811 : CHAR_TO_BYTE (end
)) - pos_byte
;
2812 it
->stop_charpos
= end
;
2813 handled
= HANDLED_RETURN
;
2822 /***********************************************************************
2824 ***********************************************************************/
2826 /* The following structure is used to record overlay strings for
2827 later sorting in load_overlay_strings. */
2829 struct overlay_entry
2831 Lisp_Object overlay
;
2838 /* Set up iterator IT from overlay strings at its current position.
2839 Called from handle_stop. */
2841 static enum prop_handled
2842 handle_overlay_change (it
)
2845 if (!STRINGP (it
->string
) && get_overlay_strings (it
))
2846 return HANDLED_RECOMPUTE_PROPS
;
2848 return HANDLED_NORMALLY
;
2852 /* Set up the next overlay string for delivery by IT, if there is an
2853 overlay string to deliver. Called by set_iterator_to_next when the
2854 end of the current overlay string is reached. If there are more
2855 overlay strings to display, IT->string and
2856 IT->current.overlay_string_index are set appropriately here.
2857 Otherwise IT->string is set to nil. */
2860 next_overlay_string (it
)
2863 ++it
->current
.overlay_string_index
;
2864 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2866 /* No more overlay strings. Restore IT's settings to what
2867 they were before overlay strings were processed, and
2868 continue to deliver from current_buffer. */
2870 xassert (it
->stop_charpos
>= BEGV
2871 && it
->stop_charpos
<= it
->end_charpos
);
2873 it
->current
.overlay_string_index
= -1;
2874 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2875 it
->n_overlay_strings
= 0;
2876 it
->method
= next_element_from_buffer
;
2878 /* If we're at the end of the buffer, record that we have
2879 processed the overlay strings there already, so that
2880 next_element_from_buffer doesn't try it again. */
2881 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
2882 it
->overlay_strings_at_end_processed_p
= 1;
2886 /* There are more overlay strings to process. If
2887 IT->current.overlay_string_index has advanced to a position
2888 where we must load IT->overlay_strings with more strings, do
2890 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2892 if (it
->current
.overlay_string_index
&& i
== 0)
2893 load_overlay_strings (it
);
2895 /* Initialize IT to deliver display elements from the overlay
2897 it
->string
= it
->overlay_strings
[i
];
2898 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2899 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2900 it
->method
= next_element_from_string
;
2901 it
->stop_charpos
= 0;
2908 /* Compare two overlay_entry structures E1 and E2. Used as a
2909 comparison function for qsort in load_overlay_strings. Overlay
2910 strings for the same position are sorted so that
2912 1. All after-strings come in front of before-strings, except
2913 when they come from the same overlay.
2915 2. Within after-strings, strings are sorted so that overlay strings
2916 from overlays with higher priorities come first.
2918 2. Within before-strings, strings are sorted so that overlay
2919 strings from overlays with higher priorities come last.
2921 Value is analogous to strcmp. */
2925 compare_overlay_entries (e1
, e2
)
2928 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
2929 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
2932 if (entry1
->after_string_p
!= entry2
->after_string_p
)
2934 /* Let after-strings appear in front of before-strings if
2935 they come from different overlays. */
2936 if (EQ (entry1
->overlay
, entry2
->overlay
))
2937 result
= entry1
->after_string_p
? 1 : -1;
2939 result
= entry1
->after_string_p
? -1 : 1;
2941 else if (entry1
->after_string_p
)
2942 /* After-strings sorted in order of decreasing priority. */
2943 result
= entry2
->priority
- entry1
->priority
;
2945 /* Before-strings sorted in order of increasing priority. */
2946 result
= entry1
->priority
- entry2
->priority
;
2952 /* Load the vector IT->overlay_strings with overlay strings from IT's
2953 current buffer position. Set IT->n_overlays to the total number of
2954 overlay strings found.
2956 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
2957 a time. On entry into load_overlay_strings,
2958 IT->current.overlay_string_index gives the number of overlay
2959 strings that have already been loaded by previous calls to this
2962 IT->add_overlay_start contains an additional overlay start
2963 position to consider for taking overlay strings from, if non-zero.
2964 This position comes into play when the overlay has an `invisible'
2965 property, and both before and after-strings. When we've skipped to
2966 the end of the overlay, because of its `invisible' property, we
2967 nevertheless want its before-string to appear.
2968 IT->add_overlay_start will contain the overlay start position
2971 Overlay strings are sorted so that after-string strings come in
2972 front of before-string strings. Within before and after-strings,
2973 strings are sorted by overlay priority. See also function
2974 compare_overlay_entries. */
2977 load_overlay_strings (it
)
2980 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
2981 Lisp_Object ov
, overlay
, window
, str
, invisible
;
2984 int n
= 0, i
, j
, invis_p
;
2985 struct overlay_entry
*entries
2986 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
2987 int charpos
= IT_CHARPOS (*it
);
2989 /* Append the overlay string STRING of overlay OVERLAY to vector
2990 `entries' which has size `size' and currently contains `n'
2991 elements. AFTER_P non-zero means STRING is an after-string of
2993 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
2996 Lisp_Object priority; \
3000 int new_size = 2 * size; \
3001 struct overlay_entry *old = entries; \
3003 (struct overlay_entry *) alloca (new_size \
3004 * sizeof *entries); \
3005 bcopy (old, entries, size * sizeof *entries); \
3009 entries[n].string = (STRING); \
3010 entries[n].overlay = (OVERLAY); \
3011 priority = Foverlay_get ((OVERLAY), Qpriority); \
3012 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3013 entries[n].after_string_p = (AFTER_P); \
3018 /* Process overlay before the overlay center. */
3019 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3021 overlay
= XCAR (ov
);
3022 xassert (OVERLAYP (overlay
));
3023 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3024 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3029 /* Skip this overlay if it doesn't start or end at IT's current
3031 if (end
!= charpos
&& start
!= charpos
)
3034 /* Skip this overlay if it doesn't apply to IT->w. */
3035 window
= Foverlay_get (overlay
, Qwindow
);
3036 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3039 /* If the text ``under'' the overlay is invisible, both before-
3040 and after-strings from this overlay are visible; start and
3041 end position are indistinguishable. */
3042 invisible
= Foverlay_get (overlay
, Qinvisible
);
3043 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3045 /* If overlay has a non-empty before-string, record it. */
3046 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3047 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3048 && XSTRING (str
)->size
)
3049 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3051 /* If overlay has a non-empty after-string, record it. */
3052 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3053 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3054 && XSTRING (str
)->size
)
3055 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3058 /* Process overlays after the overlay center. */
3059 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3061 overlay
= XCAR (ov
);
3062 xassert (OVERLAYP (overlay
));
3063 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3064 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3066 if (start
> charpos
)
3069 /* Skip this overlay if it doesn't start or end at IT's current
3071 if (end
!= charpos
&& start
!= charpos
)
3074 /* Skip this overlay if it doesn't apply to IT->w. */
3075 window
= Foverlay_get (overlay
, Qwindow
);
3076 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3079 /* If the text ``under'' the overlay is invisible, it has a zero
3080 dimension, and both before- and after-strings apply. */
3081 invisible
= Foverlay_get (overlay
, Qinvisible
);
3082 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3084 /* If overlay has a non-empty before-string, record it. */
3085 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3086 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3087 && XSTRING (str
)->size
)
3088 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3090 /* If overlay has a non-empty after-string, record it. */
3091 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3092 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3093 && XSTRING (str
)->size
)
3094 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3097 #undef RECORD_OVERLAY_STRING
3101 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3103 /* Record the total number of strings to process. */
3104 it
->n_overlay_strings
= n
;
3106 /* IT->current.overlay_string_index is the number of overlay strings
3107 that have already been consumed by IT. Copy some of the
3108 remaining overlay strings to IT->overlay_strings. */
3110 j
= it
->current
.overlay_string_index
;
3111 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3112 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3118 /* Get the first chunk of overlay strings at IT's current buffer
3119 position. Value is non-zero if at least one overlay string was
3123 get_overlay_strings (it
)
3126 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3127 process. This fills IT->overlay_strings with strings, and sets
3128 IT->n_overlay_strings to the total number of strings to process.
3129 IT->pos.overlay_string_index has to be set temporarily to zero
3130 because load_overlay_strings needs this; it must be set to -1
3131 when no overlay strings are found because a zero value would
3132 indicate a position in the first overlay string. */
3133 it
->current
.overlay_string_index
= 0;
3134 load_overlay_strings (it
);
3136 /* If we found overlay strings, set up IT to deliver display
3137 elements from the first one. Otherwise set up IT to deliver
3138 from current_buffer. */
3139 if (it
->n_overlay_strings
)
3141 /* Make sure we know settings in current_buffer, so that we can
3142 restore meaningful values when we're done with the overlay
3144 compute_stop_pos (it
);
3145 xassert (it
->face_id
>= 0);
3147 /* Save IT's settings. They are restored after all overlay
3148 strings have been processed. */
3149 xassert (it
->sp
== 0);
3152 /* Set up IT to deliver display elements from the first overlay
3154 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3155 it
->stop_charpos
= 0;
3156 it
->string
= it
->overlay_strings
[0];
3157 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3158 xassert (STRINGP (it
->string
));
3159 it
->method
= next_element_from_string
;
3164 it
->current
.overlay_string_index
= -1;
3165 it
->method
= next_element_from_buffer
;
3170 /* Value is non-zero if we found at least one overlay string. */
3171 return STRINGP (it
->string
);
3176 /***********************************************************************
3177 Saving and restoring state
3178 ***********************************************************************/
3180 /* Save current settings of IT on IT->stack. Called, for example,
3181 before setting up IT for an overlay string, to be able to restore
3182 IT's settings to what they were after the overlay string has been
3189 struct iterator_stack_entry
*p
;
3191 xassert (it
->sp
< 2);
3192 p
= it
->stack
+ it
->sp
;
3194 p
->stop_charpos
= it
->stop_charpos
;
3195 xassert (it
->face_id
>= 0);
3196 p
->face_id
= it
->face_id
;
3197 p
->string
= it
->string
;
3198 p
->pos
= it
->current
;
3199 p
->end_charpos
= it
->end_charpos
;
3200 p
->string_nchars
= it
->string_nchars
;
3202 p
->multibyte_p
= it
->multibyte_p
;
3203 p
->space_width
= it
->space_width
;
3204 p
->font_height
= it
->font_height
;
3205 p
->voffset
= it
->voffset
;
3206 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3211 /* Restore IT's settings from IT->stack. Called, for example, when no
3212 more overlay strings must be processed, and we return to delivering
3213 display elements from a buffer, or when the end of a string from a
3214 `display' property is reached and we return to delivering display
3215 elements from an overlay string, or from a buffer. */
3221 struct iterator_stack_entry
*p
;
3223 xassert (it
->sp
> 0);
3225 p
= it
->stack
+ it
->sp
;
3226 it
->stop_charpos
= p
->stop_charpos
;
3227 it
->face_id
= p
->face_id
;
3228 it
->string
= p
->string
;
3229 it
->current
= p
->pos
;
3230 it
->end_charpos
= p
->end_charpos
;
3231 it
->string_nchars
= p
->string_nchars
;
3233 it
->multibyte_p
= p
->multibyte_p
;
3234 it
->space_width
= p
->space_width
;
3235 it
->font_height
= p
->font_height
;
3236 it
->voffset
= p
->voffset
;
3237 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3242 /***********************************************************************
3244 ***********************************************************************/
3246 /* Set IT's current position to the previous line start. */
3249 back_to_previous_line_start (it
)
3252 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3253 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3257 /* Move IT to the next line start.
3259 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3260 we skipped over part of the text (as opposed to moving the iterator
3261 continuously over the text). Otherwise, don't change the value
3264 Newlines may come from buffer text, overlay strings, or strings
3265 displayed via the `display' property. That's the reason we can't
3266 simply use find_next_newline_no_quit. */
3269 forward_to_next_line_start (it
, skipped_p
)
3273 int old_selective
, newline_found_p
, n
;
3274 const int MAX_NEWLINE_DISTANCE
= 500;
3276 /* Don't handle selective display in the following. It's (a)
3277 unnecessary and (b) leads to an infinite recursion because
3278 next_element_from_ellipsis indirectly calls this function. */
3279 old_selective
= it
->selective
;
3282 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3283 from buffer text. */
3284 n
= newline_found_p
= 0;
3285 while (n
< MAX_NEWLINE_DISTANCE
3286 && get_next_display_element (it
)
3287 && !newline_found_p
)
3289 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3290 set_iterator_to_next (it
, 0);
3291 if (!STRINGP (it
->string
))
3295 /* If we didn't find a newline near enough, see if we can use a
3297 if (!newline_found_p
&& n
== MAX_NEWLINE_DISTANCE
)
3299 int start
= IT_CHARPOS (*it
);
3300 int limit
= find_next_newline_no_quit (start
, 1);
3303 xassert (!STRINGP (it
->string
));
3305 /* If there isn't any `display' property in sight, and no
3306 overlays, we can just use the position of the newline in
3308 if (it
->stop_charpos
>= limit
3309 || ((pos
= Fnext_single_property_change (make_number (start
),
3311 Qnil
, make_number (limit
)),
3313 && next_overlay_change (start
) == ZV
))
3315 IT_CHARPOS (*it
) = limit
;
3316 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3317 *skipped_p
= newline_found_p
= 1;
3321 while (get_next_display_element (it
)
3322 && !newline_found_p
)
3324 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3325 set_iterator_to_next (it
, 0);
3330 it
->selective
= old_selective
;
3331 return newline_found_p
;
3335 /* Set IT's current position to the previous visible line start. Skip
3336 invisible text that is so either due to text properties or due to
3337 selective display. Caution: this does not change IT->current_x and
3341 back_to_previous_visible_line_start (it
)
3346 /* Go back one newline if not on BEGV already. */
3347 if (IT_CHARPOS (*it
) > BEGV
)
3348 back_to_previous_line_start (it
);
3350 /* Move over lines that are invisible because of selective display
3351 or text properties. */
3352 while (IT_CHARPOS (*it
) > BEGV
3357 /* If selective > 0, then lines indented more than that values
3359 if (it
->selective
> 0
3360 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3367 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3368 Qinvisible
, it
->window
);
3369 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3373 /* Back one more newline if the current one is invisible. */
3375 back_to_previous_line_start (it
);
3378 xassert (IT_CHARPOS (*it
) >= BEGV
);
3379 xassert (IT_CHARPOS (*it
) == BEGV
3380 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3385 /* Reseat iterator IT at the previous visible line start. Skip
3386 invisible text that is so either due to text properties or due to
3387 selective display. At the end, update IT's overlay information,
3388 face information etc. */
3391 reseat_at_previous_visible_line_start (it
)
3394 back_to_previous_visible_line_start (it
);
3395 reseat (it
, it
->current
.pos
, 1);
3400 /* Reseat iterator IT on the next visible line start in the current
3401 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3402 preceding the line start. Skip over invisible text that is so
3403 because of selective display. Compute faces, overlays etc at the
3404 new position. Note that this function does not skip over text that
3405 is invisible because of text properties. */
3408 reseat_at_next_visible_line_start (it
, on_newline_p
)
3412 int newline_found_p
, skipped_p
= 0;
3414 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3416 /* Skip over lines that are invisible because they are indented
3417 more than the value of IT->selective. */
3418 if (it
->selective
> 0)
3419 while (IT_CHARPOS (*it
) < ZV
3420 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3422 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3424 /* Position on the newline if that's what's requested. */
3425 if (on_newline_p
&& newline_found_p
)
3427 if (STRINGP (it
->string
))
3429 if (IT_STRING_CHARPOS (*it
) > 0)
3431 --IT_STRING_CHARPOS (*it
);
3432 --IT_STRING_BYTEPOS (*it
);
3435 else if (IT_CHARPOS (*it
) > BEGV
)
3439 reseat (it
, it
->current
.pos
, 0);
3443 reseat (it
, it
->current
.pos
, 0);
3450 /***********************************************************************
3451 Changing an iterator's position
3452 ***********************************************************************/
3454 /* Change IT's current position to POS in current_buffer. If FORCE_P
3455 is non-zero, always check for text properties at the new position.
3456 Otherwise, text properties are only looked up if POS >=
3457 IT->check_charpos of a property. */
3460 reseat (it
, pos
, force_p
)
3462 struct text_pos pos
;
3465 int original_pos
= IT_CHARPOS (*it
);
3467 reseat_1 (it
, pos
, 0);
3469 /* Determine where to check text properties. Avoid doing it
3470 where possible because text property lookup is very expensive. */
3472 || CHARPOS (pos
) > it
->stop_charpos
3473 || CHARPOS (pos
) < original_pos
)
3480 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3481 IT->stop_pos to POS, also. */
3484 reseat_1 (it
, pos
, set_stop_p
)
3486 struct text_pos pos
;
3489 /* Don't call this function when scanning a C string. */
3490 xassert (it
->s
== NULL
);
3492 /* POS must be a reasonable value. */
3493 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3495 it
->current
.pos
= it
->position
= pos
;
3496 XSETBUFFER (it
->object
, current_buffer
);
3498 it
->current
.dpvec_index
= -1;
3499 it
->current
.overlay_string_index
= -1;
3500 IT_STRING_CHARPOS (*it
) = -1;
3501 IT_STRING_BYTEPOS (*it
) = -1;
3503 it
->method
= next_element_from_buffer
;
3507 it
->stop_charpos
= CHARPOS (pos
);
3511 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3512 If S is non-null, it is a C string to iterate over. Otherwise,
3513 STRING gives a Lisp string to iterate over.
3515 If PRECISION > 0, don't return more then PRECISION number of
3516 characters from the string.
3518 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3519 characters have been returned. FIELD_WIDTH < 0 means an infinite
3522 MULTIBYTE = 0 means disable processing of multibyte characters,
3523 MULTIBYTE > 0 means enable it,
3524 MULTIBYTE < 0 means use IT->multibyte_p.
3526 IT must be initialized via a prior call to init_iterator before
3527 calling this function. */
3530 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3535 int precision
, field_width
, multibyte
;
3537 /* No region in strings. */
3538 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3540 /* No text property checks performed by default, but see below. */
3541 it
->stop_charpos
= -1;
3543 /* Set iterator position and end position. */
3544 bzero (&it
->current
, sizeof it
->current
);
3545 it
->current
.overlay_string_index
= -1;
3546 it
->current
.dpvec_index
= -1;
3547 xassert (charpos
>= 0);
3549 /* Use the setting of MULTIBYTE if specified. */
3551 it
->multibyte_p
= multibyte
> 0;
3555 xassert (STRINGP (string
));
3556 it
->string
= string
;
3558 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3559 it
->method
= next_element_from_string
;
3560 it
->current
.string_pos
= string_pos (charpos
, string
);
3567 /* Note that we use IT->current.pos, not it->current.string_pos,
3568 for displaying C strings. */
3569 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3570 if (it
->multibyte_p
)
3572 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3573 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3577 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3578 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3581 it
->method
= next_element_from_c_string
;
3584 /* PRECISION > 0 means don't return more than PRECISION characters
3586 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3587 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3589 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3590 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3591 FIELD_WIDTH < 0 means infinite field width. This is useful for
3592 padding with `-' at the end of a mode line. */
3593 if (field_width
< 0)
3594 field_width
= INFINITY
;
3595 if (field_width
> it
->end_charpos
- charpos
)
3596 it
->end_charpos
= charpos
+ field_width
;
3598 /* Use the standard display table for displaying strings. */
3599 if (DISP_TABLE_P (Vstandard_display_table
))
3600 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3602 it
->stop_charpos
= charpos
;
3608 /***********************************************************************
3610 ***********************************************************************/
3612 /* Load IT's display element fields with information about the next
3613 display element from the current position of IT. Value is zero if
3614 end of buffer (or C string) is reached. */
3617 get_next_display_element (it
)
3620 /* Non-zero means that we found an display element. Zero means that
3621 we hit the end of what we iterate over. Performance note: the
3622 function pointer `method' used here turns out to be faster than
3623 using a sequence of if-statements. */
3624 int success_p
= (*it
->method
) (it
);
3626 if (it
->what
== IT_CHARACTER
)
3628 /* Map via display table or translate control characters.
3629 IT->c, IT->len etc. have been set to the next character by
3630 the function call above. If we have a display table, and it
3631 contains an entry for IT->c, translate it. Don't do this if
3632 IT->c itself comes from a display table, otherwise we could
3633 end up in an infinite recursion. (An alternative could be to
3634 count the recursion depth of this function and signal an
3635 error when a certain maximum depth is reached.) Is it worth
3637 if (success_p
&& it
->dpvec
== NULL
)
3642 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3645 struct Lisp_Vector
*v
= XVECTOR (dv
);
3647 /* Return the first character from the display table
3648 entry, if not empty. If empty, don't display the
3649 current character. */
3652 it
->dpvec_char_len
= it
->len
;
3653 it
->dpvec
= v
->contents
;
3654 it
->dpend
= v
->contents
+ v
->size
;
3655 it
->current
.dpvec_index
= 0;
3656 it
->method
= next_element_from_display_vector
;
3659 success_p
= get_next_display_element (it
);
3662 /* Translate control characters into `\003' or `^C' form.
3663 Control characters coming from a display table entry are
3664 currently not translated because we use IT->dpvec to hold
3665 the translation. This could easily be changed but I
3666 don't believe that it is worth doing.
3668 Non-printable multibyte characters are also translated
3670 else if ((it
->c
< ' '
3671 && (it
->area
!= TEXT_AREA
3672 || (it
->c
!= '\n' && it
->c
!= '\t')))
3675 || !CHAR_PRINTABLE_P (it
->c
))
3677 /* IT->c is a control character which must be displayed
3678 either as '\003' or as `^C' where the '\\' and '^'
3679 can be defined in the display table. Fill
3680 IT->ctl_chars with glyphs for what we have to
3681 display. Then, set IT->dpvec to these glyphs. */
3684 if (it
->c
< 128 && it
->ctl_arrow_p
)
3686 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3688 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3689 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3690 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3692 g
= FAST_MAKE_GLYPH ('^', 0);
3693 XSETINT (it
->ctl_chars
[0], g
);
3695 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3696 XSETINT (it
->ctl_chars
[1], g
);
3698 /* Set up IT->dpvec and return first character from it. */
3699 it
->dpvec_char_len
= it
->len
;
3700 it
->dpvec
= it
->ctl_chars
;
3701 it
->dpend
= it
->dpvec
+ 2;
3702 it
->current
.dpvec_index
= 0;
3703 it
->method
= next_element_from_display_vector
;
3704 get_next_display_element (it
);
3708 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
3713 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3715 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3716 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3717 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3719 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
3721 if (SINGLE_BYTE_CHAR_P (it
->c
))
3722 str
[0] = it
->c
, len
= 1;
3724 len
= CHAR_STRING (it
->c
, str
);
3726 for (i
= 0; i
< len
; i
++)
3728 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
3729 /* Insert three more glyphs into IT->ctl_chars for
3730 the octal display of the character. */
3731 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
3732 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
3733 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
3734 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
3735 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
3736 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
3739 /* Set up IT->dpvec and return the first character
3741 it
->dpvec_char_len
= it
->len
;
3742 it
->dpvec
= it
->ctl_chars
;
3743 it
->dpend
= it
->dpvec
+ len
* 4;
3744 it
->current
.dpvec_index
= 0;
3745 it
->method
= next_element_from_display_vector
;
3746 get_next_display_element (it
);
3751 /* Adjust face id for a multibyte character. There are no
3752 multibyte character in unibyte text. */
3755 && FRAME_WINDOW_P (it
->f
))
3757 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3758 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
3762 /* Is this character the last one of a run of characters with
3763 box? If yes, set IT->end_of_box_run_p to 1. */
3770 it
->end_of_box_run_p
3771 = ((face_id
= face_after_it_pos (it
),
3772 face_id
!= it
->face_id
)
3773 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3774 face
->box
== FACE_NO_BOX
));
3777 /* Value is 0 if end of buffer or string reached. */
3782 /* Move IT to the next display element.
3784 RESEAT_P non-zero means if called on a newline in buffer text,
3785 skip to the next visible line start.
3787 Functions get_next_display_element and set_iterator_to_next are
3788 separate because I find this arrangement easier to handle than a
3789 get_next_display_element function that also increments IT's
3790 position. The way it is we can first look at an iterator's current
3791 display element, decide whether it fits on a line, and if it does,
3792 increment the iterator position. The other way around we probably
3793 would either need a flag indicating whether the iterator has to be
3794 incremented the next time, or we would have to implement a
3795 decrement position function which would not be easy to write. */
3798 set_iterator_to_next (it
, reseat_p
)
3802 /* Reset flags indicating start and end of a sequence of characters
3803 with box. Reset them at the start of this function because
3804 moving the iterator to a new position might set them. */
3805 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3807 if (it
->method
== next_element_from_buffer
)
3809 /* The current display element of IT is a character from
3810 current_buffer. Advance in the buffer, and maybe skip over
3811 invisible lines that are so because of selective display. */
3812 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
3813 reseat_at_next_visible_line_start (it
, 0);
3816 xassert (it
->len
!= 0);
3817 IT_BYTEPOS (*it
) += it
->len
;
3818 IT_CHARPOS (*it
) += 1;
3819 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3822 else if (it
->method
== next_element_from_composition
)
3824 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
3825 if (STRINGP (it
->string
))
3827 IT_STRING_BYTEPOS (*it
) += it
->len
;
3828 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
3829 it
->method
= next_element_from_string
;
3830 goto consider_string_end
;
3834 IT_BYTEPOS (*it
) += it
->len
;
3835 IT_CHARPOS (*it
) += it
->cmp_len
;
3836 it
->method
= next_element_from_buffer
;
3839 else if (it
->method
== next_element_from_c_string
)
3841 /* Current display element of IT is from a C string. */
3842 IT_BYTEPOS (*it
) += it
->len
;
3843 IT_CHARPOS (*it
) += 1;
3845 else if (it
->method
== next_element_from_display_vector
)
3847 /* Current display element of IT is from a display table entry.
3848 Advance in the display table definition. Reset it to null if
3849 end reached, and continue with characters from buffers/
3851 ++it
->current
.dpvec_index
;
3853 /* Restore face of the iterator to what they were before the
3854 display vector entry (these entries may contain faces). */
3855 it
->face_id
= it
->saved_face_id
;
3857 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3860 it
->method
= next_element_from_c_string
;
3861 else if (STRINGP (it
->string
))
3862 it
->method
= next_element_from_string
;
3864 it
->method
= next_element_from_buffer
;
3867 it
->current
.dpvec_index
= -1;
3869 /* Skip over characters which were displayed via IT->dpvec. */
3870 if (it
->dpvec_char_len
< 0)
3871 reseat_at_next_visible_line_start (it
, 1);
3872 else if (it
->dpvec_char_len
> 0)
3874 it
->len
= it
->dpvec_char_len
;
3875 set_iterator_to_next (it
, reseat_p
);
3879 else if (it
->method
== next_element_from_string
)
3881 /* Current display element is a character from a Lisp string. */
3882 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3883 IT_STRING_BYTEPOS (*it
) += it
->len
;
3884 IT_STRING_CHARPOS (*it
) += 1;
3886 consider_string_end
:
3888 if (it
->current
.overlay_string_index
>= 0)
3890 /* IT->string is an overlay string. Advance to the
3891 next, if there is one. */
3892 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3893 next_overlay_string (it
);
3897 /* IT->string is not an overlay string. If we reached
3898 its end, and there is something on IT->stack, proceed
3899 with what is on the stack. This can be either another
3900 string, this time an overlay string, or a buffer. */
3901 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3905 if (!STRINGP (it
->string
))
3906 it
->method
= next_element_from_buffer
;
3910 else if (it
->method
== next_element_from_image
3911 || it
->method
== next_element_from_stretch
)
3913 /* The position etc with which we have to proceed are on
3914 the stack. The position may be at the end of a string,
3915 if the `display' property takes up the whole string. */
3918 if (STRINGP (it
->string
))
3920 it
->method
= next_element_from_string
;
3921 goto consider_string_end
;
3924 it
->method
= next_element_from_buffer
;
3927 /* There are no other methods defined, so this should be a bug. */
3930 xassert (it
->method
!= next_element_from_string
3931 || (STRINGP (it
->string
)
3932 && IT_STRING_CHARPOS (*it
) >= 0));
3936 /* Load IT's display element fields with information about the next
3937 display element which comes from a display table entry or from the
3938 result of translating a control character to one of the forms `^C'
3939 or `\003'. IT->dpvec holds the glyphs to return as characters. */
3942 next_element_from_display_vector (it
)
3946 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
3948 /* Remember the current face id in case glyphs specify faces.
3949 IT's face is restored in set_iterator_to_next. */
3950 it
->saved_face_id
= it
->face_id
;
3952 if (INTEGERP (*it
->dpvec
)
3953 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
3958 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
3959 it
->c
= FAST_GLYPH_CHAR (g
);
3960 it
->len
= CHAR_BYTES (it
->c
);
3962 /* The entry may contain a face id to use. Such a face id is
3963 the id of a Lisp face, not a realized face. A face id of
3964 zero means no face is specified. */
3965 lface_id
= FAST_GLYPH_FACE (g
);
3968 /* The function returns -1 if lface_id is invalid. */
3969 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
3971 it
->face_id
= face_id
;
3975 /* Display table entry is invalid. Return a space. */
3976 it
->c
= ' ', it
->len
= 1;
3978 /* Don't change position and object of the iterator here. They are
3979 still the values of the character that had this display table
3980 entry or was translated, and that's what we want. */
3981 it
->what
= IT_CHARACTER
;
3986 /* Load IT with the next display element from Lisp string IT->string.
3987 IT->current.string_pos is the current position within the string.
3988 If IT->current.overlay_string_index >= 0, the Lisp string is an
3992 next_element_from_string (it
)
3995 struct text_pos position
;
3997 xassert (STRINGP (it
->string
));
3998 xassert (IT_STRING_CHARPOS (*it
) >= 0);
3999 position
= it
->current
.string_pos
;
4001 /* Time to check for invisible text? */
4002 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4003 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4007 /* Since a handler may have changed IT->method, we must
4009 return get_next_display_element (it
);
4012 if (it
->current
.overlay_string_index
>= 0)
4014 /* Get the next character from an overlay string. In overlay
4015 strings, There is no field width or padding with spaces to
4017 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4022 else if (STRING_MULTIBYTE (it
->string
))
4024 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4025 - IT_STRING_BYTEPOS (*it
));
4026 unsigned char *s
= (XSTRING (it
->string
)->data
4027 + IT_STRING_BYTEPOS (*it
));
4028 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4032 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4038 /* Get the next character from a Lisp string that is not an
4039 overlay string. Such strings come from the mode line, for
4040 example. We may have to pad with spaces, or truncate the
4041 string. See also next_element_from_c_string. */
4042 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4047 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4049 /* Pad with spaces. */
4050 it
->c
= ' ', it
->len
= 1;
4051 CHARPOS (position
) = BYTEPOS (position
) = -1;
4053 else if (STRING_MULTIBYTE (it
->string
))
4055 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4056 - IT_STRING_BYTEPOS (*it
));
4057 unsigned char *s
= (XSTRING (it
->string
)->data
4058 + IT_STRING_BYTEPOS (*it
));
4059 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4063 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4068 /* Record what we have and where it came from. Note that we store a
4069 buffer position in IT->position although it could arguably be a
4071 it
->what
= IT_CHARACTER
;
4072 it
->object
= it
->string
;
4073 it
->position
= position
;
4078 /* Load IT with next display element from C string IT->s.
4079 IT->string_nchars is the maximum number of characters to return
4080 from the string. IT->end_charpos may be greater than
4081 IT->string_nchars when this function is called, in which case we
4082 may have to return padding spaces. Value is zero if end of string
4083 reached, including padding spaces. */
4086 next_element_from_c_string (it
)
4092 it
->what
= IT_CHARACTER
;
4093 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4096 /* IT's position can be greater IT->string_nchars in case a field
4097 width or precision has been specified when the iterator was
4099 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4101 /* End of the game. */
4105 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4107 /* Pad with spaces. */
4108 it
->c
= ' ', it
->len
= 1;
4109 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4111 else if (it
->multibyte_p
)
4113 /* Implementation note: The calls to strlen apparently aren't a
4114 performance problem because there is no noticeable performance
4115 difference between Emacs running in unibyte or multibyte mode. */
4116 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4117 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4121 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4127 /* Set up IT to return characters from an ellipsis, if appropriate.
4128 The definition of the ellipsis glyphs may come from a display table
4129 entry. This function Fills IT with the first glyph from the
4130 ellipsis if an ellipsis is to be displayed. */
4133 next_element_from_ellipsis (it
)
4136 if (it
->selective_display_ellipsis_p
)
4138 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4140 /* Use the display table definition for `...'. Invalid glyphs
4141 will be handled by the method returning elements from dpvec. */
4142 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4143 it
->dpvec_char_len
= it
->len
;
4144 it
->dpvec
= v
->contents
;
4145 it
->dpend
= v
->contents
+ v
->size
;
4146 it
->current
.dpvec_index
= 0;
4147 it
->method
= next_element_from_display_vector
;
4151 /* Use default `...' which is stored in default_invis_vector. */
4152 it
->dpvec_char_len
= it
->len
;
4153 it
->dpvec
= default_invis_vector
;
4154 it
->dpend
= default_invis_vector
+ 3;
4155 it
->current
.dpvec_index
= 0;
4156 it
->method
= next_element_from_display_vector
;
4161 it
->method
= next_element_from_buffer
;
4162 reseat_at_next_visible_line_start (it
, 1);
4165 return get_next_display_element (it
);
4169 /* Deliver an image display element. The iterator IT is already
4170 filled with image information (done in handle_display_prop). Value
4175 next_element_from_image (it
)
4178 it
->what
= IT_IMAGE
;
4183 /* Fill iterator IT with next display element from a stretch glyph
4184 property. IT->object is the value of the text property. Value is
4188 next_element_from_stretch (it
)
4191 it
->what
= IT_STRETCH
;
4196 /* Load IT with the next display element from current_buffer. Value
4197 is zero if end of buffer reached. IT->stop_charpos is the next
4198 position at which to stop and check for text properties or buffer
4202 next_element_from_buffer (it
)
4207 /* Check this assumption, otherwise, we would never enter the
4208 if-statement, below. */
4209 xassert (IT_CHARPOS (*it
) >= BEGV
4210 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4212 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4214 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4216 int overlay_strings_follow_p
;
4218 /* End of the game, except when overlay strings follow that
4219 haven't been returned yet. */
4220 if (it
->overlay_strings_at_end_processed_p
)
4221 overlay_strings_follow_p
= 0;
4224 it
->overlay_strings_at_end_processed_p
= 1;
4225 overlay_strings_follow_p
= get_overlay_strings (it
);
4228 if (overlay_strings_follow_p
)
4229 success_p
= get_next_display_element (it
);
4233 it
->position
= it
->current
.pos
;
4240 return get_next_display_element (it
);
4245 /* No face changes, overlays etc. in sight, so just return a
4246 character from current_buffer. */
4249 /* Maybe run the redisplay end trigger hook. Performance note:
4250 This doesn't seem to cost measurable time. */
4251 if (it
->redisplay_end_trigger_charpos
4253 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4254 run_redisplay_end_trigger_hook (it
);
4256 /* Get the next character, maybe multibyte. */
4257 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4258 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4260 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4261 - IT_BYTEPOS (*it
));
4262 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4265 it
->c
= *p
, it
->len
= 1;
4267 /* Record what we have and where it came from. */
4268 it
->what
= IT_CHARACTER
;;
4269 it
->object
= it
->w
->buffer
;
4270 it
->position
= it
->current
.pos
;
4272 /* Normally we return the character found above, except when we
4273 really want to return an ellipsis for selective display. */
4278 /* A value of selective > 0 means hide lines indented more
4279 than that number of columns. */
4280 if (it
->selective
> 0
4281 && IT_CHARPOS (*it
) + 1 < ZV
4282 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4283 IT_BYTEPOS (*it
) + 1,
4286 success_p
= next_element_from_ellipsis (it
);
4287 it
->dpvec_char_len
= -1;
4290 else if (it
->c
== '\r' && it
->selective
== -1)
4292 /* A value of selective == -1 means that everything from the
4293 CR to the end of the line is invisible, with maybe an
4294 ellipsis displayed for it. */
4295 success_p
= next_element_from_ellipsis (it
);
4296 it
->dpvec_char_len
= -1;
4301 /* Value is zero if end of buffer reached. */
4302 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4307 /* Run the redisplay end trigger hook for IT. */
4310 run_redisplay_end_trigger_hook (it
)
4313 Lisp_Object args
[3];
4315 /* IT->glyph_row should be non-null, i.e. we should be actually
4316 displaying something, or otherwise we should not run the hook. */
4317 xassert (it
->glyph_row
);
4319 /* Set up hook arguments. */
4320 args
[0] = Qredisplay_end_trigger_functions
;
4321 args
[1] = it
->window
;
4322 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4323 it
->redisplay_end_trigger_charpos
= 0;
4325 /* Since we are *trying* to run these functions, don't try to run
4326 them again, even if they get an error. */
4327 it
->w
->redisplay_end_trigger
= Qnil
;
4328 Frun_hook_with_args (3, args
);
4330 /* Notice if it changed the face of the character we are on. */
4331 handle_face_prop (it
);
4335 /* Deliver a composition display element. The iterator IT is already
4336 filled with composition information (done in
4337 handle_composition_prop). Value is always 1. */
4340 next_element_from_composition (it
)
4343 it
->what
= IT_COMPOSITION
;
4344 it
->position
= (STRINGP (it
->string
)
4345 ? it
->current
.string_pos
4352 /***********************************************************************
4353 Moving an iterator without producing glyphs
4354 ***********************************************************************/
4356 /* Move iterator IT to a specified buffer or X position within one
4357 line on the display without producing glyphs.
4359 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4360 whichever is reached first.
4362 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4364 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4365 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4366 TO_X includes the amount by which a window is horizontally
4371 MOVE_POS_MATCH_OR_ZV
4372 - when TO_POS or ZV was reached.
4375 -when TO_X was reached before TO_POS or ZV were reached.
4378 - when we reached the end of the display area and the line must
4382 - when we reached the end of the display area and the line is
4386 - when we stopped at a line end, i.e. a newline or a CR and selective
4389 static enum move_it_result
4390 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4392 int to_charpos
, to_x
, op
;
4394 enum move_it_result result
= MOVE_UNDEFINED
;
4395 struct glyph_row
*saved_glyph_row
;
4397 /* Don't produce glyphs in produce_glyphs. */
4398 saved_glyph_row
= it
->glyph_row
;
4399 it
->glyph_row
= NULL
;
4403 int x
, i
, ascent
= 0, descent
= 0;
4405 /* Stop when ZV or TO_CHARPOS reached. */
4406 if (!get_next_display_element (it
)
4407 || ((op
& MOVE_TO_POS
) != 0
4408 && BUFFERP (it
->object
)
4409 && IT_CHARPOS (*it
) >= to_charpos
))
4411 result
= MOVE_POS_MATCH_OR_ZV
;
4415 /* The call to produce_glyphs will get the metrics of the
4416 display element IT is loaded with. We record in x the
4417 x-position before this display element in case it does not
4421 /* Remember the line height so far in case the next element doesn't
4423 if (!it
->truncate_lines_p
)
4425 ascent
= it
->max_ascent
;
4426 descent
= it
->max_descent
;
4429 PRODUCE_GLYPHS (it
);
4431 if (it
->area
!= TEXT_AREA
)
4433 set_iterator_to_next (it
, 1);
4437 /* The number of glyphs we get back in IT->nglyphs will normally
4438 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4439 character on a terminal frame, or (iii) a line end. For the
4440 second case, IT->nglyphs - 1 padding glyphs will be present
4441 (on X frames, there is only one glyph produced for a
4442 composite character.
4444 The behavior implemented below means, for continuation lines,
4445 that as many spaces of a TAB as fit on the current line are
4446 displayed there. For terminal frames, as many glyphs of a
4447 multi-glyph character are displayed in the current line, too.
4448 This is what the old redisplay code did, and we keep it that
4449 way. Under X, the whole shape of a complex character must
4450 fit on the line or it will be completely displayed in the
4453 Note that both for tabs and padding glyphs, all glyphs have
4457 /* More than one glyph or glyph doesn't fit on line. All
4458 glyphs have the same width. */
4459 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4462 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4464 new_x
= x
+ single_glyph_width
;
4466 /* We want to leave anything reaching TO_X to the caller. */
4467 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4470 result
= MOVE_X_REACHED
;
4473 else if (/* Lines are continued. */
4474 !it
->truncate_lines_p
4475 && (/* And glyph doesn't fit on the line. */
4476 new_x
> it
->last_visible_x
4477 /* Or it fits exactly and we're on a window
4479 || (new_x
== it
->last_visible_x
4480 && FRAME_WINDOW_P (it
->f
))))
4482 if (/* IT->hpos == 0 means the very first glyph
4483 doesn't fit on the line, e.g. a wide image. */
4485 || (new_x
== it
->last_visible_x
4486 && FRAME_WINDOW_P (it
->f
)))
4489 it
->current_x
= new_x
;
4490 if (i
== it
->nglyphs
- 1)
4491 set_iterator_to_next (it
, 1);
4496 it
->max_ascent
= ascent
;
4497 it
->max_descent
= descent
;
4500 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
4502 result
= MOVE_LINE_CONTINUED
;
4505 else if (new_x
> it
->first_visible_x
)
4507 /* Glyph is visible. Increment number of glyphs that
4508 would be displayed. */
4513 /* Glyph is completely off the left margin of the display
4514 area. Nothing to do. */
4518 if (result
!= MOVE_UNDEFINED
)
4521 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4523 /* Stop when TO_X specified and reached. This check is
4524 necessary here because of lines consisting of a line end,
4525 only. The line end will not produce any glyphs and we
4526 would never get MOVE_X_REACHED. */
4527 xassert (it
->nglyphs
== 0);
4528 result
= MOVE_X_REACHED
;
4532 /* Is this a line end? If yes, we're done. */
4533 if (ITERATOR_AT_END_OF_LINE_P (it
))
4535 result
= MOVE_NEWLINE_OR_CR
;
4539 /* The current display element has been consumed. Advance
4541 set_iterator_to_next (it
, 1);
4543 /* Stop if lines are truncated and IT's current x-position is
4544 past the right edge of the window now. */
4545 if (it
->truncate_lines_p
4546 && it
->current_x
>= it
->last_visible_x
)
4548 result
= MOVE_LINE_TRUNCATED
;
4553 /* Restore the iterator settings altered at the beginning of this
4555 it
->glyph_row
= saved_glyph_row
;
4560 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4561 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4562 the description of enum move_operation_enum.
4564 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4565 screen line, this function will set IT to the next position >
4569 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4571 int to_charpos
, to_x
, to_y
, to_vpos
;
4574 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4580 if (op
& MOVE_TO_VPOS
)
4582 /* If no TO_CHARPOS and no TO_X specified, stop at the
4583 start of the line TO_VPOS. */
4584 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4586 if (it
->vpos
== to_vpos
)
4592 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4596 /* TO_VPOS >= 0 means stop at TO_X in the line at
4597 TO_VPOS, or at TO_POS, whichever comes first. */
4598 if (it
->vpos
== to_vpos
)
4604 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4606 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4611 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4613 /* We have reached TO_X but not in the line we want. */
4614 skip
= move_it_in_display_line_to (it
, to_charpos
,
4616 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4624 else if (op
& MOVE_TO_Y
)
4626 struct it it_backup
;
4628 /* TO_Y specified means stop at TO_X in the line containing
4629 TO_Y---or at TO_CHARPOS if this is reached first. The
4630 problem is that we can't really tell whether the line
4631 contains TO_Y before we have completely scanned it, and
4632 this may skip past TO_X. What we do is to first scan to
4635 If TO_X is not specified, use a TO_X of zero. The reason
4636 is to make the outcome of this function more predictable.
4637 If we didn't use TO_X == 0, we would stop at the end of
4638 the line which is probably not what a caller would expect
4640 skip
= move_it_in_display_line_to (it
, to_charpos
,
4644 | (op
& MOVE_TO_POS
)));
4646 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4647 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4653 /* If TO_X was reached, we would like to know whether TO_Y
4654 is in the line. This can only be said if we know the
4655 total line height which requires us to scan the rest of
4657 if (skip
== MOVE_X_REACHED
)
4660 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
4661 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4663 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
4666 /* Now, decide whether TO_Y is in this line. */
4667 line_height
= it
->max_ascent
+ it
->max_descent
;
4668 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
4670 if (to_y
>= it
->current_y
4671 && to_y
< it
->current_y
+ line_height
)
4673 if (skip
== MOVE_X_REACHED
)
4674 /* If TO_Y is in this line and TO_X was reached above,
4675 we scanned too far. We have to restore IT's settings
4676 to the ones before skipping. */
4680 else if (skip
== MOVE_X_REACHED
)
4683 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4691 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4695 case MOVE_POS_MATCH_OR_ZV
:
4699 case MOVE_NEWLINE_OR_CR
:
4700 set_iterator_to_next (it
, 1);
4701 it
->continuation_lines_width
= 0;
4704 case MOVE_LINE_TRUNCATED
:
4705 it
->continuation_lines_width
= 0;
4706 reseat_at_next_visible_line_start (it
, 0);
4707 if ((op
& MOVE_TO_POS
) != 0
4708 && IT_CHARPOS (*it
) > to_charpos
)
4715 case MOVE_LINE_CONTINUED
:
4716 it
->continuation_lines_width
+= it
->current_x
;
4723 /* Reset/increment for the next run. */
4724 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4725 it
->current_x
= it
->hpos
= 0;
4726 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4728 last_height
= it
->max_ascent
+ it
->max_descent
;
4729 last_max_ascent
= it
->max_ascent
;
4730 it
->max_ascent
= it
->max_descent
= 0;
4735 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
4739 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4741 If DY > 0, move IT backward at least that many pixels. DY = 0
4742 means move IT backward to the preceding line start or BEGV. This
4743 function may move over more than DY pixels if IT->current_y - DY
4744 ends up in the middle of a line; in this case IT->current_y will be
4745 set to the top of the line moved to. */
4748 move_it_vertically_backward (it
, dy
)
4752 int nlines
, h
, line_height
;
4754 int start_pos
= IT_CHARPOS (*it
);
4758 /* Estimate how many newlines we must move back. */
4759 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4761 /* Set the iterator's position that many lines back. */
4762 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4763 back_to_previous_visible_line_start (it
);
4765 /* Reseat the iterator here. When moving backward, we don't want
4766 reseat to skip forward over invisible text, set up the iterator
4767 to deliver from overlay strings at the new position etc. So,
4768 use reseat_1 here. */
4769 reseat_1 (it
, it
->current
.pos
, 1);
4771 /* We are now surely at a line start. */
4772 it
->current_x
= it
->hpos
= 0;
4774 /* Move forward and see what y-distance we moved. First move to the
4775 start of the next line so that we get its height. We need this
4776 height to be able to tell whether we reached the specified
4779 it2
.max_ascent
= it2
.max_descent
= 0;
4780 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4781 MOVE_TO_POS
| MOVE_TO_VPOS
);
4782 xassert (IT_CHARPOS (*it
) >= BEGV
);
4783 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4785 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4786 xassert (IT_CHARPOS (*it
) >= BEGV
);
4787 h
= it2
.current_y
- it
->current_y
;
4788 nlines
= it2
.vpos
- it
->vpos
;
4790 /* Correct IT's y and vpos position. */
4796 /* DY == 0 means move to the start of the screen line. The
4797 value of nlines is > 0 if continuation lines were involved. */
4799 move_it_by_lines (it
, nlines
, 1);
4800 xassert (IT_CHARPOS (*it
) <= start_pos
);
4804 /* The y-position we try to reach. Note that h has been
4805 subtracted in front of the if-statement. */
4806 int target_y
= it
->current_y
+ h
- dy
;
4808 /* If we did not reach target_y, try to move further backward if
4809 we can. If we moved too far backward, try to move forward. */
4810 if (target_y
< it
->current_y
4811 && IT_CHARPOS (*it
) > BEGV
)
4813 move_it_vertically (it
, target_y
- it
->current_y
);
4814 xassert (IT_CHARPOS (*it
) >= BEGV
);
4816 else if (target_y
>= it
->current_y
+ line_height
4817 && IT_CHARPOS (*it
) < ZV
)
4819 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4820 xassert (IT_CHARPOS (*it
) >= BEGV
);
4826 /* Move IT by a specified amount of pixel lines DY. DY negative means
4827 move backwards. DY = 0 means move to start of screen line. At the
4828 end, IT will be on the start of a screen line. */
4831 move_it_vertically (it
, dy
)
4836 move_it_vertically_backward (it
, -dy
);
4839 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
4840 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4841 MOVE_TO_POS
| MOVE_TO_Y
);
4842 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
4844 /* If buffer ends in ZV without a newline, move to the start of
4845 the line to satisfy the post-condition. */
4846 if (IT_CHARPOS (*it
) == ZV
4847 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4848 move_it_by_lines (it
, 0, 0);
4853 /* Return non-zero if some text between buffer positions START_CHARPOS
4854 and END_CHARPOS is invisible. IT->window is the window for text
4858 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4860 int start_charpos
, end_charpos
;
4862 Lisp_Object prop
, limit
;
4863 int invisible_found_p
;
4865 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4867 /* Is text at START invisible? */
4868 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4870 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4871 invisible_found_p
= 1;
4874 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
4876 make_number (end_charpos
));
4877 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4880 return invisible_found_p
;
4884 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4885 negative means move up. DVPOS == 0 means move to the start of the
4886 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4887 NEED_Y_P is zero, IT->current_y will be left unchanged.
4889 Further optimization ideas: If we would know that IT->f doesn't use
4890 a face with proportional font, we could be faster for
4891 truncate-lines nil. */
4894 move_it_by_lines (it
, dvpos
, need_y_p
)
4896 int dvpos
, need_y_p
;
4898 struct position pos
;
4900 if (!FRAME_WINDOW_P (it
->f
))
4902 struct text_pos textpos
;
4904 /* We can use vmotion on frames without proportional fonts. */
4905 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4906 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4907 reseat (it
, textpos
, 1);
4908 it
->vpos
+= pos
.vpos
;
4909 it
->current_y
+= pos
.vpos
;
4911 else if (dvpos
== 0)
4913 /* DVPOS == 0 means move to the start of the screen line. */
4914 move_it_vertically_backward (it
, 0);
4915 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4919 /* If there are no continuation lines, and if there is no
4920 selective display, try the simple method of moving forward
4921 DVPOS newlines, then see where we are. */
4922 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4924 int shortage
= 0, charpos
;
4926 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
4927 charpos
= IT_CHARPOS (*it
) + 1;
4929 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
4932 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
4934 struct text_pos pos
;
4935 CHARPOS (pos
) = charpos
;
4936 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4937 reseat (it
, pos
, 1);
4938 it
->vpos
+= dvpos
- shortage
;
4939 it
->hpos
= it
->current_x
= 0;
4944 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
4949 int start_charpos
, i
;
4951 /* If there are no continuation lines, and if there is no
4952 selective display, try the simple method of moving backward
4954 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4957 int charpos
= IT_CHARPOS (*it
);
4958 int bytepos
= IT_BYTEPOS (*it
);
4960 /* If in the middle of a line, go to its start. */
4961 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
4963 charpos
= find_next_newline_no_quit (charpos
, -1);
4964 bytepos
= CHAR_TO_BYTE (charpos
);
4967 if (charpos
== BEGV
)
4969 struct text_pos pos
;
4970 CHARPOS (pos
) = charpos
;
4971 BYTEPOS (pos
) = bytepos
;
4972 reseat (it
, pos
, 1);
4973 it
->hpos
= it
->current_x
= 0;
4978 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
4979 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
4981 struct text_pos pos
;
4982 CHARPOS (pos
) = charpos
;
4983 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4984 reseat (it
, pos
, 1);
4985 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
4986 it
->hpos
= it
->current_x
= 0;
4992 /* Go back -DVPOS visible lines and reseat the iterator there. */
4993 start_charpos
= IT_CHARPOS (*it
);
4994 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
4995 back_to_previous_visible_line_start (it
);
4996 reseat (it
, it
->current
.pos
, 1);
4997 it
->current_x
= it
->hpos
= 0;
4999 /* Above call may have moved too far if continuation lines
5000 are involved. Scan forward and see if it did. */
5002 it2
.vpos
= it2
.current_y
= 0;
5003 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5004 it
->vpos
-= it2
.vpos
;
5005 it
->current_y
-= it2
.current_y
;
5006 it
->current_x
= it
->hpos
= 0;
5008 /* If we moved too far, move IT some lines forward. */
5009 if (it2
.vpos
> -dvpos
)
5011 int delta
= it2
.vpos
+ dvpos
;
5012 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5019 /***********************************************************************
5021 ***********************************************************************/
5024 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5028 add_to_log (format
, arg1
, arg2
)
5030 Lisp_Object arg1
, arg2
;
5032 Lisp_Object args
[3];
5033 Lisp_Object msg
, fmt
;
5036 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5039 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5041 args
[0] = fmt
= build_string (format
);
5044 msg
= Fformat (3, args
);
5046 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5047 buffer
= (char *) alloca (len
);
5048 strcpy (buffer
, XSTRING (msg
)->data
);
5050 message_dolog (buffer
, len
- 1, 1, 0);
5055 /* Output a newline in the *Messages* buffer if "needs" one. */
5058 message_log_maybe_newline ()
5060 if (message_log_need_newline
)
5061 message_dolog ("", 0, 1, 0);
5065 /* Add a string M of length LEN to the message log, optionally
5066 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5067 nonzero, means interpret the contents of M as multibyte. This
5068 function calls low-level routines in order to bypass text property
5069 hooks, etc. which might not be safe to run. */
5072 message_dolog (m
, len
, nlflag
, multibyte
)
5074 int len
, nlflag
, multibyte
;
5076 if (!NILP (Vmessage_log_max
))
5078 struct buffer
*oldbuf
;
5079 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5080 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5081 int point_at_end
= 0;
5083 Lisp_Object old_deactivate_mark
, tem
;
5084 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5086 old_deactivate_mark
= Vdeactivate_mark
;
5087 oldbuf
= current_buffer
;
5088 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5089 current_buffer
->undo_list
= Qt
;
5091 oldpoint
= Fpoint_marker ();
5092 oldbegv
= Fpoint_min_marker ();
5093 oldzv
= Fpoint_max_marker ();
5094 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5102 BEGV_BYTE
= BEG_BYTE
;
5105 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5107 /* Insert the string--maybe converting multibyte to single byte
5108 or vice versa, so that all the text fits the buffer. */
5110 && NILP (current_buffer
->enable_multibyte_characters
))
5113 unsigned char work
[1];
5115 /* Convert a multibyte string to single-byte
5116 for the *Message* buffer. */
5117 for (i
= 0; i
< len
; i
+= nbytes
)
5119 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
5120 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5122 : multibyte_char_to_unibyte (c
, Qnil
));
5123 insert_1_both (work
, 1, 1, 1, 0, 0);
5126 else if (! multibyte
5127 && ! NILP (current_buffer
->enable_multibyte_characters
))
5130 unsigned char *msg
= (unsigned char *) m
;
5131 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5132 /* Convert a single-byte string to multibyte
5133 for the *Message* buffer. */
5134 for (i
= 0; i
< len
; i
++)
5136 c
= unibyte_char_to_multibyte (msg
[i
]);
5137 nbytes
= CHAR_STRING (c
, str
);
5138 insert_1_both (str
, 1, nbytes
, 1, 0, 0);
5142 insert_1 (m
, len
, 1, 0, 0);
5146 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5147 insert_1 ("\n", 1, 1, 0, 0);
5149 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5151 this_bol_byte
= PT_BYTE
;
5155 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5157 prev_bol_byte
= PT_BYTE
;
5159 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5160 this_bol
, this_bol_byte
);
5163 del_range_both (prev_bol
, prev_bol_byte
,
5164 this_bol
, this_bol_byte
, 0);
5170 /* If you change this format, don't forget to also
5171 change message_log_check_duplicate. */
5172 sprintf (dupstr
, " [%d times]", dup
);
5173 duplen
= strlen (dupstr
);
5174 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5175 insert_1 (dupstr
, duplen
, 1, 0, 1);
5180 if (NATNUMP (Vmessage_log_max
))
5182 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5183 -XFASTINT (Vmessage_log_max
) - 1, 0);
5184 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5187 BEGV
= XMARKER (oldbegv
)->charpos
;
5188 BEGV_BYTE
= marker_byte_position (oldbegv
);
5197 ZV
= XMARKER (oldzv
)->charpos
;
5198 ZV_BYTE
= marker_byte_position (oldzv
);
5202 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5204 /* We can't do Fgoto_char (oldpoint) because it will run some
5206 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5207 XMARKER (oldpoint
)->bytepos
);
5210 free_marker (oldpoint
);
5211 free_marker (oldbegv
);
5212 free_marker (oldzv
);
5214 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5215 set_buffer_internal (oldbuf
);
5217 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5218 message_log_need_newline
= !nlflag
;
5219 Vdeactivate_mark
= old_deactivate_mark
;
5224 /* We are at the end of the buffer after just having inserted a newline.
5225 (Note: We depend on the fact we won't be crossing the gap.)
5226 Check to see if the most recent message looks a lot like the previous one.
5227 Return 0 if different, 1 if the new one should just replace it, or a
5228 value N > 1 if we should also append " [N times]". */
5231 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5232 int prev_bol
, this_bol
;
5233 int prev_bol_byte
, this_bol_byte
;
5236 int len
= Z_BYTE
- 1 - this_bol_byte
;
5238 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5239 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5241 for (i
= 0; i
< len
; i
++)
5243 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
5252 if (*p1
++ == ' ' && *p1
++ == '[')
5255 while (*p1
>= '0' && *p1
<= '9')
5256 n
= n
* 10 + *p1
++ - '0';
5257 if (strncmp (p1
, " times]\n", 8) == 0)
5264 /* Display an echo area message M with a specified length of LEN
5265 chars. The string may include null characters. If M is 0, clear
5266 out any existing message, and let the mini-buffer text show through.
5268 The buffer M must continue to exist until after the echo area gets
5269 cleared or some other message gets displayed there. This means do
5270 not pass text that is stored in a Lisp string; do not pass text in
5271 a buffer that was alloca'd. */
5274 message2 (m
, len
, multibyte
)
5279 /* First flush out any partial line written with print. */
5280 message_log_maybe_newline ();
5282 message_dolog (m
, len
, 1, multibyte
);
5283 message2_nolog (m
, len
, multibyte
);
5287 /* The non-logging counterpart of message2. */
5290 message2_nolog (m
, len
, multibyte
)
5294 struct frame
*sf
= SELECTED_FRAME ();
5295 message_enable_multibyte
= multibyte
;
5299 if (noninteractive_need_newline
)
5300 putc ('\n', stderr
);
5301 noninteractive_need_newline
= 0;
5303 fwrite (m
, len
, 1, stderr
);
5304 if (cursor_in_echo_area
== 0)
5305 fprintf (stderr
, "\n");
5308 /* A null message buffer means that the frame hasn't really been
5309 initialized yet. Error messages get reported properly by
5310 cmd_error, so this must be just an informative message; toss it. */
5311 else if (INTERACTIVE
5312 && sf
->glyphs_initialized_p
5313 && FRAME_MESSAGE_BUF (sf
))
5315 Lisp_Object mini_window
;
5318 /* Get the frame containing the mini-buffer
5319 that the selected frame is using. */
5320 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5321 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5323 FRAME_SAMPLE_VISIBILITY (f
);
5324 if (FRAME_VISIBLE_P (sf
)
5325 && ! FRAME_VISIBLE_P (f
))
5326 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5330 set_message (m
, Qnil
, len
, multibyte
);
5331 if (minibuffer_auto_raise
)
5332 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5335 clear_message (1, 1);
5337 do_pending_window_change (0);
5338 echo_area_display (1);
5339 do_pending_window_change (0);
5340 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5341 (*frame_up_to_date_hook
) (f
);
5346 /* Display an echo area message M with a specified length of NBYTES
5347 bytes. The string may include null characters. If M is not a
5348 string, clear out any existing message, and let the mini-buffer
5349 text show through. */
5352 message3 (m
, nbytes
, multibyte
)
5357 struct gcpro gcpro1
;
5361 /* First flush out any partial line written with print. */
5362 message_log_maybe_newline ();
5364 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5365 message3_nolog (m
, nbytes
, multibyte
);
5371 /* The non-logging version of message3. */
5374 message3_nolog (m
, nbytes
, multibyte
)
5376 int nbytes
, multibyte
;
5378 struct frame
*sf
= SELECTED_FRAME ();
5379 message_enable_multibyte
= multibyte
;
5383 if (noninteractive_need_newline
)
5384 putc ('\n', stderr
);
5385 noninteractive_need_newline
= 0;
5387 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5388 if (cursor_in_echo_area
== 0)
5389 fprintf (stderr
, "\n");
5392 /* A null message buffer means that the frame hasn't really been
5393 initialized yet. Error messages get reported properly by
5394 cmd_error, so this must be just an informative message; toss it. */
5395 else if (INTERACTIVE
5396 && sf
->glyphs_initialized_p
5397 && FRAME_MESSAGE_BUF (sf
))
5399 Lisp_Object mini_window
;
5403 /* Get the frame containing the mini-buffer
5404 that the selected frame is using. */
5405 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5406 frame
= XWINDOW (mini_window
)->frame
;
5409 FRAME_SAMPLE_VISIBILITY (f
);
5410 if (FRAME_VISIBLE_P (sf
)
5411 && !FRAME_VISIBLE_P (f
))
5412 Fmake_frame_visible (frame
);
5414 if (STRINGP (m
) && XSTRING (m
)->size
)
5416 set_message (NULL
, m
, nbytes
, multibyte
);
5417 if (minibuffer_auto_raise
)
5418 Fraise_frame (frame
);
5421 clear_message (1, 1);
5423 do_pending_window_change (0);
5424 echo_area_display (1);
5425 do_pending_window_change (0);
5426 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5427 (*frame_up_to_date_hook
) (f
);
5432 /* Display a null-terminated echo area message M. If M is 0, clear
5433 out any existing message, and let the mini-buffer text show through.
5435 The buffer M must continue to exist until after the echo area gets
5436 cleared or some other message gets displayed there. Do not pass
5437 text that is stored in a Lisp string. Do not pass text in a buffer
5438 that was alloca'd. */
5444 message2 (m
, (m
? strlen (m
) : 0), 0);
5448 /* The non-logging counterpart of message1. */
5454 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5457 /* Display a message M which contains a single %s
5458 which gets replaced with STRING. */
5461 message_with_string (m
, string
, log
)
5470 if (noninteractive_need_newline
)
5471 putc ('\n', stderr
);
5472 noninteractive_need_newline
= 0;
5473 fprintf (stderr
, m
, XSTRING (string
)->data
);
5474 if (cursor_in_echo_area
== 0)
5475 fprintf (stderr
, "\n");
5479 else if (INTERACTIVE
)
5481 /* The frame whose minibuffer we're going to display the message on.
5482 It may be larger than the selected frame, so we need
5483 to use its buffer, not the selected frame's buffer. */
5484 Lisp_Object mini_window
;
5485 struct frame
*f
, *sf
= SELECTED_FRAME ();
5487 /* Get the frame containing the minibuffer
5488 that the selected frame is using. */
5489 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5490 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5492 /* A null message buffer means that the frame hasn't really been
5493 initialized yet. Error messages get reported properly by
5494 cmd_error, so this must be just an informative message; toss it. */
5495 if (FRAME_MESSAGE_BUF (f
))
5499 a
[0] = (char *) XSTRING (string
)->data
;
5501 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5502 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5505 message2 (FRAME_MESSAGE_BUF (f
), len
,
5506 STRING_MULTIBYTE (string
));
5508 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5509 STRING_MULTIBYTE (string
));
5511 /* Print should start at the beginning of the message
5512 buffer next time. */
5513 message_buf_print
= 0;
5519 /* Dump an informative message to the minibuf. If M is 0, clear out
5520 any existing message, and let the mini-buffer text show through. */
5524 message (m
, a1
, a2
, a3
)
5526 EMACS_INT a1
, a2
, a3
;
5532 if (noninteractive_need_newline
)
5533 putc ('\n', stderr
);
5534 noninteractive_need_newline
= 0;
5535 fprintf (stderr
, m
, a1
, a2
, a3
);
5536 if (cursor_in_echo_area
== 0)
5537 fprintf (stderr
, "\n");
5541 else if (INTERACTIVE
)
5543 /* The frame whose mini-buffer we're going to display the message
5544 on. It may be larger than the selected frame, so we need to
5545 use its buffer, not the selected frame's buffer. */
5546 Lisp_Object mini_window
;
5547 struct frame
*f
, *sf
= SELECTED_FRAME ();
5549 /* Get the frame containing the mini-buffer
5550 that the selected frame is using. */
5551 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5552 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5554 /* A null message buffer means that the frame hasn't really been
5555 initialized yet. Error messages get reported properly by
5556 cmd_error, so this must be just an informative message; toss
5558 if (FRAME_MESSAGE_BUF (f
))
5569 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5570 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5572 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5573 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5575 #endif /* NO_ARG_ARRAY */
5577 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5582 /* Print should start at the beginning of the message
5583 buffer next time. */
5584 message_buf_print
= 0;
5590 /* The non-logging version of message. */
5593 message_nolog (m
, a1
, a2
, a3
)
5595 EMACS_INT a1
, a2
, a3
;
5597 Lisp_Object old_log_max
;
5598 old_log_max
= Vmessage_log_max
;
5599 Vmessage_log_max
= Qnil
;
5600 message (m
, a1
, a2
, a3
);
5601 Vmessage_log_max
= old_log_max
;
5605 /* Display the current message in the current mini-buffer. This is
5606 only called from error handlers in process.c, and is not time
5612 if (!NILP (echo_area_buffer
[0]))
5615 string
= Fcurrent_message ();
5616 message3 (string
, XSTRING (string
)->size
,
5617 !NILP (current_buffer
->enable_multibyte_characters
));
5622 /* Make sure echo area buffers in echo_buffers[] are life. If they
5623 aren't, make new ones. */
5626 ensure_echo_area_buffers ()
5630 for (i
= 0; i
< 2; ++i
)
5631 if (!BUFFERP (echo_buffer
[i
])
5632 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5635 Lisp_Object old_buffer
;
5638 old_buffer
= echo_buffer
[i
];
5639 sprintf (name
, " *Echo Area %d*", i
);
5640 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5641 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
5643 for (j
= 0; j
< 2; ++j
)
5644 if (EQ (old_buffer
, echo_area_buffer
[j
]))
5645 echo_area_buffer
[j
] = echo_buffer
[i
];
5650 /* Call FN with args A1..A4 with either the current or last displayed
5651 echo_area_buffer as current buffer.
5653 WHICH zero means use the current message buffer
5654 echo_area_buffer[0]. If that is nil, choose a suitable buffer
5655 from echo_buffer[] and clear it.
5657 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
5658 suitable buffer from echo_buffer[] and clear it.
5660 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
5661 that the current message becomes the last displayed one, make
5662 choose a suitable buffer for echo_area_buffer[0], and clear it.
5664 Value is what FN returns. */
5667 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
5670 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
5676 int this_one
, the_other
, clear_buffer_p
, rc
;
5677 int count
= specpdl_ptr
- specpdl
;
5679 /* If buffers aren't life, make new ones. */
5680 ensure_echo_area_buffers ();
5685 this_one
= 0, the_other
= 1;
5687 this_one
= 1, the_other
= 0;
5690 this_one
= 0, the_other
= 1;
5693 /* We need a fresh one in case the current echo buffer equals
5694 the one containing the last displayed echo area message. */
5695 if (!NILP (echo_area_buffer
[this_one
])
5696 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
5697 echo_area_buffer
[this_one
] = Qnil
;
5700 /* Choose a suitable buffer from echo_buffer[] is we don't
5702 if (NILP (echo_area_buffer
[this_one
]))
5704 echo_area_buffer
[this_one
]
5705 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
5706 ? echo_buffer
[the_other
]
5707 : echo_buffer
[this_one
]);
5711 buffer
= echo_area_buffer
[this_one
];
5713 record_unwind_protect (unwind_with_echo_area_buffer
,
5714 with_echo_area_buffer_unwind_data (w
));
5716 /* Make the echo area buffer current. Note that for display
5717 purposes, it is not necessary that the displayed window's buffer
5718 == current_buffer, except for text property lookup. So, let's
5719 only set that buffer temporarily here without doing a full
5720 Fset_window_buffer. We must also change w->pointm, though,
5721 because otherwise an assertions in unshow_buffer fails, and Emacs
5723 set_buffer_internal_1 (XBUFFER (buffer
));
5727 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
5730 current_buffer
->undo_list
= Qt
;
5731 current_buffer
->read_only
= Qnil
;
5733 if (clear_buffer_p
&& Z
> BEG
)
5736 xassert (BEGV
>= BEG
);
5737 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5739 rc
= fn (a1
, a2
, a3
, a4
);
5741 xassert (BEGV
>= BEG
);
5742 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5744 unbind_to (count
, Qnil
);
5749 /* Save state that should be preserved around the call to the function
5750 FN called in with_echo_area_buffer. */
5753 with_echo_area_buffer_unwind_data (w
)
5759 /* Reduce consing by keeping one vector in
5760 Vwith_echo_area_save_vector. */
5761 vector
= Vwith_echo_area_save_vector
;
5762 Vwith_echo_area_save_vector
= Qnil
;
5765 vector
= Fmake_vector (make_number (7), Qnil
);
5767 XSETBUFFER (XVECTOR (vector
)->contents
[i
], current_buffer
); ++i
;
5768 XVECTOR (vector
)->contents
[i
++] = Vdeactivate_mark
;
5769 XVECTOR (vector
)->contents
[i
++] = make_number (windows_or_buffers_changed
);
5773 XSETWINDOW (XVECTOR (vector
)->contents
[i
], w
); ++i
;
5774 XVECTOR (vector
)->contents
[i
++] = w
->buffer
;
5775 XVECTOR (vector
)->contents
[i
++]
5776 = make_number (XMARKER (w
->pointm
)->charpos
);
5777 XVECTOR (vector
)->contents
[i
++]
5778 = make_number (XMARKER (w
->pointm
)->bytepos
);
5784 XVECTOR (vector
)->contents
[i
++] = Qnil
;
5787 xassert (i
== XVECTOR (vector
)->size
);
5792 /* Restore global state from VECTOR which was created by
5793 with_echo_area_buffer_unwind_data. */
5796 unwind_with_echo_area_buffer (vector
)
5801 set_buffer_internal_1 (XBUFFER (XVECTOR (vector
)->contents
[i
])); ++i
;
5802 Vdeactivate_mark
= XVECTOR (vector
)->contents
[i
]; ++i
;
5803 windows_or_buffers_changed
= XFASTINT (XVECTOR (vector
)->contents
[i
]); ++i
;
5805 if (WINDOWP (XVECTOR (vector
)->contents
[i
]))
5808 Lisp_Object buffer
, charpos
, bytepos
;
5810 w
= XWINDOW (XVECTOR (vector
)->contents
[i
]); ++i
;
5811 buffer
= XVECTOR (vector
)->contents
[i
]; ++i
;
5812 charpos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5813 bytepos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5816 set_marker_both (w
->pointm
, buffer
,
5817 XFASTINT (charpos
), XFASTINT (bytepos
));
5820 Vwith_echo_area_save_vector
= vector
;
5825 /* Set up the echo area for use by print functions. MULTIBYTE_P
5826 non-zero means we will print multibyte. */
5829 setup_echo_area_for_printing (multibyte_p
)
5832 ensure_echo_area_buffers ();
5834 if (!message_buf_print
)
5836 /* A message has been output since the last time we printed.
5837 Choose a fresh echo area buffer. */
5838 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5839 echo_area_buffer
[0] = echo_buffer
[1];
5841 echo_area_buffer
[0] = echo_buffer
[0];
5843 /* Switch to that buffer and clear it. */
5844 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5847 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5849 /* Set up the buffer for the multibyteness we need. */
5851 != !NILP (current_buffer
->enable_multibyte_characters
))
5852 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
5854 /* Raise the frame containing the echo area. */
5855 if (minibuffer_auto_raise
)
5857 struct frame
*sf
= SELECTED_FRAME ();
5858 Lisp_Object mini_window
;
5859 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5860 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5863 message_log_maybe_newline ();
5864 message_buf_print
= 1;
5868 if (NILP (echo_area_buffer
[0]))
5870 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5871 echo_area_buffer
[0] = echo_buffer
[1];
5873 echo_area_buffer
[0] = echo_buffer
[0];
5876 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
5877 /* Someone switched buffers between print requests. */
5878 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5883 /* Display an echo area message in window W. Value is non-zero if W's
5884 height is changed. If display_last_displayed_message_p is
5885 non-zero, display the message that was last displayed, otherwise
5886 display the current message. */
5889 display_echo_area (w
)
5892 int i
, no_message_p
, window_height_changed_p
, count
;
5894 /* Temporarily disable garbage collections while displaying the echo
5895 area. This is done because a GC can print a message itself.
5896 That message would modify the echo area buffer's contents while a
5897 redisplay of the buffer is going on, and seriously confuse
5899 count
= inhibit_garbage_collection ();
5901 /* If there is no message, we must call display_echo_area_1
5902 nevertheless because it resizes the window. But we will have to
5903 reset the echo_area_buffer in question to nil at the end because
5904 with_echo_area_buffer will sets it to an empty buffer. */
5905 i
= display_last_displayed_message_p
? 1 : 0;
5906 no_message_p
= NILP (echo_area_buffer
[i
]);
5908 window_height_changed_p
5909 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
5910 display_echo_area_1
,
5911 (EMACS_INT
) w
, Qnil
, 0, 0);
5914 echo_area_buffer
[i
] = Qnil
;
5916 unbind_to (count
, Qnil
);
5917 return window_height_changed_p
;
5921 /* Helper for display_echo_area. Display the current buffer which
5922 contains the current echo area message in window W, a mini-window,
5923 a pointer to which is passed in A1. A2..A4 are currently not used.
5924 Change the height of W so that all of the message is displayed.
5925 Value is non-zero if height of W was changed. */
5928 display_echo_area_1 (a1
, a2
, a3
, a4
)
5933 struct window
*w
= (struct window
*) a1
;
5935 struct text_pos start
;
5936 int window_height_changed_p
= 0;
5938 /* Do this before displaying, so that we have a large enough glyph
5939 matrix for the display. */
5940 window_height_changed_p
= resize_mini_window (w
, 0);
5943 clear_glyph_matrix (w
->desired_matrix
);
5944 XSETWINDOW (window
, w
);
5945 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
5946 try_window (window
, start
);
5948 return window_height_changed_p
;
5952 /* Resize the echo area window to exactly the size needed for the
5953 currently displayed message, if there is one. */
5956 resize_echo_area_axactly ()
5958 if (BUFFERP (echo_area_buffer
[0])
5959 && WINDOWP (echo_area_window
))
5961 struct window
*w
= XWINDOW (echo_area_window
);
5964 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
5965 (EMACS_INT
) w
, Qnil
, 0, 0);
5968 ++windows_or_buffers_changed
;
5969 ++update_mode_lines
;
5970 redisplay_internal (0);
5976 /* Callback function for with_echo_area_buffer, when used from
5977 resize_echo_area_axactly. A1 contains a pointer to the window to
5978 resize, A2 to A4 are not used. Value is what resize_mini_window
5982 resize_mini_window_1 (a1
, a2
, a3
, a4
)
5987 return resize_mini_window ((struct window
*) a1
, 1);
5991 /* Resize mini-window W to fit the size of its contents. EXACT:P
5992 means size the window exactly to the size needed. Otherwise, it's
5993 only enlarged until W's buffer is empty. Value is non-zero if
5994 the window height has been changed. */
5997 resize_mini_window (w
, exact_p
)
6001 struct frame
*f
= XFRAME (w
->frame
);
6002 int window_height_changed_p
= 0;
6004 xassert (MINI_WINDOW_P (w
));
6006 /* Nil means don't try to resize. */
6007 if (NILP (Vmax_mini_window_height
)
6008 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6011 if (!FRAME_MINIBUF_ONLY_P (f
))
6014 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6015 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6016 int height
, max_height
;
6017 int unit
= CANON_Y_UNIT (f
);
6018 struct text_pos start
;
6020 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6022 /* Compute the max. number of lines specified by the user. */
6023 if (FLOATP (Vmax_mini_window_height
))
6024 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
6025 else if (INTEGERP (Vmax_mini_window_height
))
6026 max_height
= XINT (Vmax_mini_window_height
);
6028 max_height
= total_height
/ 4;
6030 /* Correct that max. height if it's bogus. */
6031 max_height
= max (1, max_height
);
6032 max_height
= min (total_height
, max_height
);
6034 /* Find out the height of the text in the window. */
6035 if (it
.truncate_lines_p
)
6040 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6041 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6042 height
= it
.current_y
+ last_height
;
6044 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6045 height
-= it
.extra_line_spacing
;
6046 height
= (height
+ unit
- 1) / unit
;
6049 /* Compute a suitable window start. */
6050 if (height
> max_height
)
6052 height
= max_height
;
6053 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6054 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6055 start
= it
.current
.pos
;
6058 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6059 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6061 /* Let it grow only, until we display an empty message, in which
6062 case the window shrinks again. */
6063 if (height
> XFASTINT (w
->height
))
6065 int old_height
= XFASTINT (w
->height
);
6066 freeze_window_starts (f
, 1);
6067 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6068 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6070 else if (height
< XFASTINT (w
->height
)
6071 && (exact_p
|| BEGV
== ZV
))
6073 int old_height
= XFASTINT (w
->height
);
6074 freeze_window_starts (f
, 0);
6075 shrink_mini_window (w
);
6076 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6080 return window_height_changed_p
;
6084 /* Value is the current message, a string, or nil if there is no
6092 if (NILP (echo_area_buffer
[0]))
6096 with_echo_area_buffer (0, 0, current_message_1
,
6097 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6099 echo_area_buffer
[0] = Qnil
;
6107 current_message_1 (a1
, a2
, a3
, a4
)
6112 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6115 *msg
= make_buffer_string (BEG
, Z
, 1);
6122 /* Push the current message on Vmessage_stack for later restauration
6123 by restore_message. Value is non-zero if the current message isn't
6124 empty. This is a relatively infrequent operation, so it's not
6125 worth optimizing. */
6131 msg
= current_message ();
6132 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6133 return STRINGP (msg
);
6137 /* Restore message display from the top of Vmessage_stack. */
6144 xassert (CONSP (Vmessage_stack
));
6145 msg
= XCAR (Vmessage_stack
);
6147 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6149 message3_nolog (msg
, 0, 0);
6153 /* Pop the top-most entry off Vmessage_stack. */
6158 xassert (CONSP (Vmessage_stack
));
6159 Vmessage_stack
= XCDR (Vmessage_stack
);
6163 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6164 exits. If the stack is not empty, we have a missing pop_message
6168 check_message_stack ()
6170 if (!NILP (Vmessage_stack
))
6175 /* Truncate to NCHARS what will be displayed in the echo area the next
6176 time we display it---but don't redisplay it now. */
6179 truncate_echo_area (nchars
)
6183 echo_area_buffer
[0] = Qnil
;
6184 /* A null message buffer means that the frame hasn't really been
6185 initialized yet. Error messages get reported properly by
6186 cmd_error, so this must be just an informative message; toss it. */
6187 else if (!noninteractive
6189 && !NILP (echo_area_buffer
[0]))
6191 struct frame
*sf
= SELECTED_FRAME ();
6192 if (FRAME_MESSAGE_BUF (sf
))
6193 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6198 /* Helper function for truncate_echo_area. Truncate the current
6199 message to at most NCHARS characters. */
6202 truncate_message_1 (nchars
, a2
, a3
, a4
)
6207 if (BEG
+ nchars
< Z
)
6208 del_range (BEG
+ nchars
, Z
);
6210 echo_area_buffer
[0] = Qnil
;
6215 /* Set the current message to a substring of S or STRING.
6217 If STRING is a Lisp string, set the message to the first NBYTES
6218 bytes from STRING. NBYTES zero means use the whole string. If
6219 STRING is multibyte, the message will be displayed multibyte.
6221 If S is not null, set the message to the first LEN bytes of S. LEN
6222 zero means use the whole string. MULTIBYTE_P non-zero means S is
6223 multibyte. Display the message multibyte in that case. */
6226 set_message (s
, string
, nbytes
, multibyte_p
)
6231 message_enable_multibyte
6232 = ((s
&& multibyte_p
)
6233 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6235 with_echo_area_buffer (0, -1, set_message_1
,
6236 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6237 message_buf_print
= 0;
6238 help_echo_showing_p
= 0;
6242 /* Helper function for set_message. Arguments have the same meaning
6243 as there, with A1 corresponding to S and A2 corresponding to STRING
6244 This function is called with the echo area buffer being
6248 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6251 EMACS_INT nbytes
, multibyte_p
;
6253 char *s
= (char *) a1
;
6254 Lisp_Object string
= a2
;
6258 /* Change multibyteness of the echo buffer appropriately. */
6259 if (message_enable_multibyte
6260 != !NILP (current_buffer
->enable_multibyte_characters
))
6261 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6263 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6265 /* Insert new message at BEG. */
6266 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6268 if (STRINGP (string
))
6273 nbytes
= XSTRING (string
)->size_byte
;
6274 nchars
= string_byte_to_char (string
, nbytes
);
6276 /* This function takes care of single/multibyte conversion. We
6277 just have to ensure that the echo area buffer has the right
6278 setting of enable_multibyte_characters. */
6279 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6284 nbytes
= strlen (s
);
6286 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6288 /* Convert from multi-byte to single-byte. */
6290 unsigned char work
[1];
6292 /* Convert a multibyte string to single-byte. */
6293 for (i
= 0; i
< nbytes
; i
+= n
)
6295 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6296 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6298 : multibyte_char_to_unibyte (c
, Qnil
));
6299 insert_1_both (work
, 1, 1, 1, 0, 0);
6302 else if (!multibyte_p
6303 && !NILP (current_buffer
->enable_multibyte_characters
))
6305 /* Convert from single-byte to multi-byte. */
6307 unsigned char *msg
= (unsigned char *) s
;
6308 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6310 /* Convert a single-byte string to multibyte. */
6311 for (i
= 0; i
< nbytes
; i
++)
6313 c
= unibyte_char_to_multibyte (msg
[i
]);
6314 n
= CHAR_STRING (c
, str
);
6315 insert_1_both (str
, 1, n
, 1, 0, 0);
6319 insert_1 (s
, nbytes
, 1, 0, 0);
6326 /* Clear messages. CURRENT_P non-zero means clear the current
6327 message. LAST_DISPLAYED_P non-zero means clear the message
6331 clear_message (current_p
, last_displayed_p
)
6332 int current_p
, last_displayed_p
;
6335 echo_area_buffer
[0] = Qnil
;
6337 if (last_displayed_p
)
6338 echo_area_buffer
[1] = Qnil
;
6340 message_buf_print
= 0;
6343 /* Clear garbaged frames.
6345 This function is used where the old redisplay called
6346 redraw_garbaged_frames which in turn called redraw_frame which in
6347 turn called clear_frame. The call to clear_frame was a source of
6348 flickering. I believe a clear_frame is not necessary. It should
6349 suffice in the new redisplay to invalidate all current matrices,
6350 and ensure a complete redisplay of all windows. */
6353 clear_garbaged_frames ()
6357 Lisp_Object tail
, frame
;
6359 FOR_EACH_FRAME (tail
, frame
)
6361 struct frame
*f
= XFRAME (frame
);
6363 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6365 clear_current_matrices (f
);
6371 ++windows_or_buffers_changed
;
6376 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6377 is non-zero update selected_frame. Value is non-zero if the
6378 mini-windows height has been changed. */
6381 echo_area_display (update_frame_p
)
6384 Lisp_Object mini_window
;
6387 int window_height_changed_p
= 0;
6388 struct frame
*sf
= SELECTED_FRAME ();
6390 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6391 w
= XWINDOW (mini_window
);
6392 f
= XFRAME (WINDOW_FRAME (w
));
6394 /* Don't display if frame is invisible or not yet initialized. */
6395 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6398 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
6400 #ifdef HAVE_WINDOW_SYSTEM
6401 /* When Emacs starts, selected_frame may be a visible terminal
6402 frame, even if we run under a window system. If we let this
6403 through, a message would be displayed on the terminal. */
6404 if (EQ (selected_frame
, Vterminal_frame
)
6405 && !NILP (Vwindow_system
))
6407 #endif /* HAVE_WINDOW_SYSTEM */
6410 /* Redraw garbaged frames. */
6412 clear_garbaged_frames ();
6414 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6416 echo_area_window
= mini_window
;
6417 window_height_changed_p
= display_echo_area (w
);
6418 w
->must_be_updated_p
= 1;
6420 /* Update the display, unless called from redisplay_internal. */
6425 /* If the display update has been interrupted by pending
6426 input, update mode lines in the frame. Due to the
6427 pending input, it might have been that redisplay hasn't
6428 been called, so that mode lines above the echo area are
6429 garbaged. This looks odd, so we prevent it here. */
6430 if (!display_completed
)
6431 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
6433 if (window_height_changed_p
)
6435 /* Must update other windows. */
6436 windows_or_buffers_changed
= 1;
6437 redisplay_internal (0);
6439 else if (FRAME_WINDOW_P (f
) && n
== 0)
6441 /* Window configuration is the same as before.
6442 Can do with a display update of the echo area,
6443 unless we displayed some mode lines. */
6444 update_single_window (w
, 1);
6445 rif
->flush_display (f
);
6448 update_frame (f
, 1, 1);
6451 else if (!EQ (mini_window
, selected_window
))
6452 windows_or_buffers_changed
++;
6454 /* Last displayed message is now the current message. */
6455 echo_area_buffer
[1] = echo_area_buffer
[0];
6457 /* Prevent redisplay optimization in redisplay_internal by resetting
6458 this_line_start_pos. This is done because the mini-buffer now
6459 displays the message instead of its buffer text. */
6460 if (EQ (mini_window
, selected_window
))
6461 CHARPOS (this_line_start_pos
) = 0;
6463 return window_height_changed_p
;
6468 /***********************************************************************
6470 ***********************************************************************/
6473 #ifdef HAVE_WINDOW_SYSTEM
6475 /* A buffer for constructing frame titles in it; allocated from the
6476 heap in init_xdisp and resized as needed in store_frame_title_char. */
6478 static char *frame_title_buf
;
6480 /* The buffer's end, and a current output position in it. */
6482 static char *frame_title_buf_end
;
6483 static char *frame_title_ptr
;
6486 /* Store a single character C for the frame title in frame_title_buf.
6487 Re-allocate frame_title_buf if necessary. */
6490 store_frame_title_char (c
)
6493 /* If output position has reached the end of the allocated buffer,
6494 double the buffer's size. */
6495 if (frame_title_ptr
== frame_title_buf_end
)
6497 int len
= frame_title_ptr
- frame_title_buf
;
6498 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6499 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6500 frame_title_buf_end
= frame_title_buf
+ new_size
;
6501 frame_title_ptr
= frame_title_buf
+ len
;
6504 *frame_title_ptr
++ = c
;
6508 /* Store part of a frame title in frame_title_buf, beginning at
6509 frame_title_ptr. STR is the string to store. Do not copy more
6510 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
6511 the whole string. Pad with spaces until FIELD_WIDTH number of
6512 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
6513 Called from display_mode_element when it is used to build a frame
6517 store_frame_title (str
, field_width
, precision
)
6519 int field_width
, precision
;
6523 /* Copy at most PRECISION chars from STR. */
6524 while ((precision
<= 0 || n
< precision
)
6527 store_frame_title_char (*str
++);
6531 /* Fill up with spaces until FIELD_WIDTH reached. */
6532 while (field_width
> 0
6535 store_frame_title_char (' ');
6543 /* Set the title of FRAME, if it has changed. The title format is
6544 Vicon_title_format if FRAME is iconified, otherwise it is
6545 frame_title_format. */
6548 x_consider_frame_title (frame
)
6551 struct frame
*f
= XFRAME (frame
);
6553 if (FRAME_WINDOW_P (f
)
6554 || FRAME_MINIBUF_ONLY_P (f
)
6555 || f
->explicit_name
)
6557 /* Do we have more than one visible frame on this X display? */
6560 struct buffer
*obuf
;
6564 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
6566 struct frame
*tf
= XFRAME (XCAR (tail
));
6569 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
6570 && !FRAME_MINIBUF_ONLY_P (tf
)
6571 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
6575 /* Set global variable indicating that multiple frames exist. */
6576 multiple_frames
= CONSP (tail
);
6578 /* Switch to the buffer of selected window of the frame. Set up
6579 frame_title_ptr so that display_mode_element will output into it;
6580 then display the title. */
6581 obuf
= current_buffer
;
6582 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
6583 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
6584 frame_title_ptr
= frame_title_buf
;
6585 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
6586 NULL
, DEFAULT_FACE_ID
);
6587 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
6588 frame_title_ptr
= NULL
;
6589 set_buffer_internal (obuf
);
6591 /* Set the title only if it's changed. This avoids consing in
6592 the common case where it hasn't. (If it turns out that we've
6593 already wasted too much time by walking through the list with
6594 display_mode_element, then we might need to optimize at a
6595 higher level than this.) */
6596 if (! STRINGP (f
->name
)
6597 || STRING_BYTES (XSTRING (f
->name
)) != len
6598 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
6599 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
6603 #else /* not HAVE_WINDOW_SYSTEM */
6605 #define frame_title_ptr ((char *)0)
6606 #define store_frame_title(str, mincol, maxcol) 0
6608 #endif /* not HAVE_WINDOW_SYSTEM */
6613 /***********************************************************************
6615 ***********************************************************************/
6618 /* Prepare for redisplay by updating menu-bar item lists when
6619 appropriate. This can call eval. */
6622 prepare_menu_bars ()
6625 struct gcpro gcpro1
, gcpro2
;
6627 struct frame
*tooltip_frame
;
6629 #ifdef HAVE_X_WINDOWS
6630 tooltip_frame
= tip_frame
;
6632 tooltip_frame
= NULL
;
6635 /* Update all frame titles based on their buffer names, etc. We do
6636 this before the menu bars so that the buffer-menu will show the
6637 up-to-date frame titles. */
6638 #ifdef HAVE_WINDOW_SYSTEM
6639 if (windows_or_buffers_changed
|| update_mode_lines
)
6641 Lisp_Object tail
, frame
;
6643 FOR_EACH_FRAME (tail
, frame
)
6646 if (f
!= tooltip_frame
6647 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
6648 x_consider_frame_title (frame
);
6651 #endif /* HAVE_WINDOW_SYSTEM */
6653 /* Update the menu bar item lists, if appropriate. This has to be
6654 done before any actual redisplay or generation of display lines. */
6655 all_windows
= (update_mode_lines
6656 || buffer_shared
> 1
6657 || windows_or_buffers_changed
);
6660 Lisp_Object tail
, frame
;
6661 int count
= specpdl_ptr
- specpdl
;
6663 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6665 FOR_EACH_FRAME (tail
, frame
)
6669 /* Ignore tooltip frame. */
6670 if (f
== tooltip_frame
)
6673 /* If a window on this frame changed size, report that to
6674 the user and clear the size-change flag. */
6675 if (FRAME_WINDOW_SIZES_CHANGED (f
))
6677 Lisp_Object functions
;
6679 /* Clear flag first in case we get an error below. */
6680 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
6681 functions
= Vwindow_size_change_functions
;
6682 GCPRO2 (tail
, functions
);
6684 while (CONSP (functions
))
6686 call1 (XCAR (functions
), frame
);
6687 functions
= XCDR (functions
);
6693 update_menu_bar (f
, 0);
6694 #ifdef HAVE_WINDOW_SYSTEM
6695 update_tool_bar (f
, 0);
6700 unbind_to (count
, Qnil
);
6704 struct frame
*sf
= SELECTED_FRAME ();
6705 update_menu_bar (sf
, 1);
6706 #ifdef HAVE_WINDOW_SYSTEM
6707 update_tool_bar (sf
, 1);
6711 /* Motif needs this. See comment in xmenu.c. Turn it off when
6712 pending_menu_activation is not defined. */
6713 #ifdef USE_X_TOOLKIT
6714 pending_menu_activation
= 0;
6719 /* Update the menu bar item list for frame F. This has to be done
6720 before we start to fill in any display lines, because it can call
6723 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
6726 update_menu_bar (f
, save_match_data
)
6728 int save_match_data
;
6731 register struct window
*w
;
6733 window
= FRAME_SELECTED_WINDOW (f
);
6734 w
= XWINDOW (window
);
6736 if (update_mode_lines
)
6737 w
->update_mode_line
= Qt
;
6739 if (FRAME_WINDOW_P (f
)
6741 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
6742 FRAME_EXTERNAL_MENU_BAR (f
)
6744 FRAME_MENU_BAR_LINES (f
) > 0
6746 : FRAME_MENU_BAR_LINES (f
) > 0)
6748 /* If the user has switched buffers or windows, we need to
6749 recompute to reflect the new bindings. But we'll
6750 recompute when update_mode_lines is set too; that means
6751 that people can use force-mode-line-update to request
6752 that the menu bar be recomputed. The adverse effect on
6753 the rest of the redisplay algorithm is about the same as
6754 windows_or_buffers_changed anyway. */
6755 if (windows_or_buffers_changed
6756 || !NILP (w
->update_mode_line
)
6757 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6758 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6759 != !NILP (w
->last_had_star
))
6760 || ((!NILP (Vtransient_mark_mode
)
6761 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6762 != !NILP (w
->region_showing
)))
6764 struct buffer
*prev
= current_buffer
;
6765 int count
= specpdl_ptr
- specpdl
;
6767 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6768 if (save_match_data
)
6769 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6770 if (NILP (Voverriding_local_map_menu_flag
))
6772 specbind (Qoverriding_terminal_local_map
, Qnil
);
6773 specbind (Qoverriding_local_map
, Qnil
);
6776 /* Run the Lucid hook. */
6777 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
6779 /* If it has changed current-menubar from previous value,
6780 really recompute the menu-bar from the value. */
6781 if (! NILP (Vlucid_menu_bar_dirty_flag
))
6782 call0 (Qrecompute_lucid_menubar
);
6784 safe_run_hooks (Qmenu_bar_update_hook
);
6785 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
6787 /* Redisplay the menu bar in case we changed it. */
6788 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
6789 if (FRAME_WINDOW_P (f
)
6790 #if defined (macintosh)
6791 /* All frames on Mac OS share the same menubar. So only the
6792 selected frame should be allowed to set it. */
6793 && f
== SELECTED_FRAME ()
6796 set_frame_menubar (f
, 0, 0);
6798 /* On a terminal screen, the menu bar is an ordinary screen
6799 line, and this makes it get updated. */
6800 w
->update_mode_line
= Qt
;
6801 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6802 /* In the non-toolkit version, the menu bar is an ordinary screen
6803 line, and this makes it get updated. */
6804 w
->update_mode_line
= Qt
;
6805 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6807 unbind_to (count
, Qnil
);
6808 set_buffer_internal_1 (prev
);
6815 /***********************************************************************
6817 ***********************************************************************/
6819 #ifdef HAVE_WINDOW_SYSTEM
6821 /* Update the tool-bar item list for frame F. This has to be done
6822 before we start to fill in any display lines. Called from
6823 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
6824 and restore it here. */
6827 update_tool_bar (f
, save_match_data
)
6829 int save_match_data
;
6831 if (WINDOWP (f
->tool_bar_window
)
6832 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
6837 window
= FRAME_SELECTED_WINDOW (f
);
6838 w
= XWINDOW (window
);
6840 /* If the user has switched buffers or windows, we need to
6841 recompute to reflect the new bindings. But we'll
6842 recompute when update_mode_lines is set too; that means
6843 that people can use force-mode-line-update to request
6844 that the menu bar be recomputed. The adverse effect on
6845 the rest of the redisplay algorithm is about the same as
6846 windows_or_buffers_changed anyway. */
6847 if (windows_or_buffers_changed
6848 || !NILP (w
->update_mode_line
)
6849 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6850 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6851 != !NILP (w
->last_had_star
))
6852 || ((!NILP (Vtransient_mark_mode
)
6853 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6854 != !NILP (w
->region_showing
)))
6856 struct buffer
*prev
= current_buffer
;
6857 int count
= specpdl_ptr
- specpdl
;
6859 /* Set current_buffer to the buffer of the selected
6860 window of the frame, so that we get the right local
6862 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6864 /* Save match data, if we must. */
6865 if (save_match_data
)
6866 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6868 /* Make sure that we don't accidentally use bogus keymaps. */
6869 if (NILP (Voverriding_local_map_menu_flag
))
6871 specbind (Qoverriding_terminal_local_map
, Qnil
);
6872 specbind (Qoverriding_local_map
, Qnil
);
6875 /* Build desired tool-bar items from keymaps. */
6876 f
->desired_tool_bar_items
6877 = tool_bar_items (f
->desired_tool_bar_items
,
6878 &f
->n_desired_tool_bar_items
);
6880 /* Redisplay the tool-bar in case we changed it. */
6881 w
->update_mode_line
= Qt
;
6883 unbind_to (count
, Qnil
);
6884 set_buffer_internal_1 (prev
);
6890 /* Set F->desired_tool_bar_string to a Lisp string representing frame
6891 F's desired tool-bar contents. F->desired_tool_bar_items must have
6892 been set up previously by calling prepare_menu_bars. */
6895 build_desired_tool_bar_string (f
)
6898 int i
, size
, size_needed
, string_idx
;
6899 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6900 Lisp_Object image
, plist
, props
;
6902 image
= plist
= props
= Qnil
;
6903 GCPRO3 (image
, plist
, props
);
6905 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
6906 Otherwise, make a new string. */
6908 /* The size of the string we might be able to reuse. */
6909 size
= (STRINGP (f
->desired_tool_bar_string
)
6910 ? XSTRING (f
->desired_tool_bar_string
)->size
6913 /* Each image in the string we build is preceded by a space,
6914 and there is a space at the end. */
6915 size_needed
= f
->n_desired_tool_bar_items
+ 1;
6917 /* Reuse f->desired_tool_bar_string, if possible. */
6918 if (size
< size_needed
)
6919 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
6923 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
6924 Fremove_text_properties (make_number (0), make_number (size
),
6925 props
, f
->desired_tool_bar_string
);
6928 /* Put a `display' property on the string for the images to display,
6929 put a `menu_item' property on tool-bar items with a value that
6930 is the index of the item in F's tool-bar item vector. */
6931 for (i
= 0, string_idx
= 0;
6932 i
< f
->n_desired_tool_bar_items
;
6933 ++i
, string_idx
+= 1)
6936 (XVECTOR (f->desired_tool_bar_items) \
6937 ->contents[i * TOOL_BAR_ITEM_NSLOTS + (IDX)])
6939 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
6940 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
6941 int margin
, relief
, idx
;
6942 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
6943 extern Lisp_Object Qlaplace
;
6945 /* If image is a vector, choose the image according to the
6947 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
6948 if (VECTORP (image
))
6952 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
6953 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
6956 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
6957 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
6959 xassert (ASIZE (image
) >= idx
);
6960 image
= AREF (image
, idx
);
6965 /* Ignore invalid image specifications. */
6966 if (!valid_image_p (image
))
6969 /* Display the tool-bar button pressed, or depressed. */
6970 plist
= Fcopy_sequence (XCDR (image
));
6972 /* Compute margin and relief to draw. */
6973 relief
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
6974 margin
= relief
+ max (0, tool_bar_button_margin
);
6976 if (auto_raise_tool_bar_buttons_p
)
6978 /* Add a `:relief' property to the image spec if the item is
6982 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
6988 /* If image is selected, display it pressed, i.e. with a
6989 negative relief. If it's not selected, display it with a
6991 plist
= Fplist_put (plist
, QCrelief
,
6993 ? make_number (-relief
)
6994 : make_number (relief
)));
6998 /* Put a margin around the image. */
7000 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
7002 /* If button is not enabled, and we don't have special images
7003 for the disabled state, make the image appear disabled by
7004 applying an appropriate algorithm to it. */
7005 if (!enabled_p
&& idx
< 0)
7006 plist
= Fplist_put (plist
, QCalgorithm
, Qdisabled
);
7008 /* Put a `display' text property on the string for the image to
7009 display. Put a `menu-item' property on the string that gives
7010 the start of this item's properties in the tool-bar items
7012 image
= Fcons (Qimage
, plist
);
7013 props
= list4 (Qdisplay
, image
,
7014 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
)),
7015 Fadd_text_properties (make_number (string_idx
),
7016 make_number (string_idx
+ 1),
7017 props
, f
->desired_tool_bar_string
);
7025 /* Display one line of the tool-bar of frame IT->f. */
7028 display_tool_bar_line (it
)
7031 struct glyph_row
*row
= it
->glyph_row
;
7032 int max_x
= it
->last_visible_x
;
7035 prepare_desired_row (row
);
7036 row
->y
= it
->current_y
;
7038 while (it
->current_x
< max_x
)
7040 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7042 /* Get the next display element. */
7043 if (!get_next_display_element (it
))
7046 /* Produce glyphs. */
7047 x_before
= it
->current_x
;
7048 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7049 PRODUCE_GLYPHS (it
);
7051 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7056 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7058 if (x
+ glyph
->pixel_width
> max_x
)
7060 /* Glyph doesn't fit on line. */
7061 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7067 x
+= glyph
->pixel_width
;
7071 /* Stop at line ends. */
7072 if (ITERATOR_AT_END_OF_LINE_P (it
))
7075 set_iterator_to_next (it
, 1);
7080 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7081 extend_face_to_end_of_line (it
);
7082 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7083 last
->right_box_line_p
= 1;
7084 compute_line_metrics (it
);
7086 /* If line is empty, make it occupy the rest of the tool-bar. */
7087 if (!row
->displays_text_p
)
7089 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7090 row
->ascent
= row
->phys_ascent
= 0;
7093 row
->full_width_p
= 1;
7094 row
->continued_p
= 0;
7095 row
->truncated_on_left_p
= 0;
7096 row
->truncated_on_right_p
= 0;
7098 it
->current_x
= it
->hpos
= 0;
7099 it
->current_y
+= row
->height
;
7105 /* Value is the number of screen lines needed to make all tool-bar
7106 items of frame F visible. */
7109 tool_bar_lines_needed (f
)
7112 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7115 /* Initialize an iterator for iteration over
7116 F->desired_tool_bar_string in the tool-bar window of frame F. */
7117 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7118 it
.first_visible_x
= 0;
7119 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7120 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7122 while (!ITERATOR_AT_END_P (&it
))
7124 it
.glyph_row
= w
->desired_matrix
->rows
;
7125 clear_glyph_row (it
.glyph_row
);
7126 display_tool_bar_line (&it
);
7129 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7133 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7134 height should be changed. */
7137 redisplay_tool_bar (f
)
7142 struct glyph_row
*row
;
7143 int change_height_p
= 0;
7145 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7146 do anything. This means you must start with tool-bar-lines
7147 non-zero to get the auto-sizing effect. Or in other words, you
7148 can turn off tool-bars by specifying tool-bar-lines zero. */
7149 if (!WINDOWP (f
->tool_bar_window
)
7150 || (w
= XWINDOW (f
->tool_bar_window
),
7151 XFASTINT (w
->height
) == 0))
7154 /* Set up an iterator for the tool-bar window. */
7155 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7156 it
.first_visible_x
= 0;
7157 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7160 /* Build a string that represents the contents of the tool-bar. */
7161 build_desired_tool_bar_string (f
);
7162 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7164 /* Display as many lines as needed to display all tool-bar items. */
7165 while (it
.current_y
< it
.last_visible_y
)
7166 display_tool_bar_line (&it
);
7168 /* It doesn't make much sense to try scrolling in the tool-bar
7169 window, so don't do it. */
7170 w
->desired_matrix
->no_scrolling_p
= 1;
7171 w
->must_be_updated_p
= 1;
7173 if (auto_resize_tool_bars_p
)
7177 /* If there are blank lines at the end, except for a partially
7178 visible blank line at the end that is smaller than
7179 CANON_Y_UNIT, change the tool-bar's height. */
7180 row
= it
.glyph_row
- 1;
7181 if (!row
->displays_text_p
7182 && row
->height
>= CANON_Y_UNIT (f
))
7183 change_height_p
= 1;
7185 /* If row displays tool-bar items, but is partially visible,
7186 change the tool-bar's height. */
7187 if (row
->displays_text_p
7188 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7189 change_height_p
= 1;
7191 /* Resize windows as needed by changing the `tool-bar-lines'
7194 && (nlines
= tool_bar_lines_needed (f
),
7195 nlines
!= XFASTINT (w
->height
)))
7197 extern Lisp_Object Qtool_bar_lines
;
7200 XSETFRAME (frame
, f
);
7201 clear_glyph_matrix (w
->desired_matrix
);
7202 Fmodify_frame_parameters (frame
,
7203 Fcons (Fcons (Qtool_bar_lines
,
7204 make_number (nlines
)),
7206 fonts_changed_p
= 1;
7210 return change_height_p
;
7214 /* Get information about the tool-bar item which is displayed in GLYPH
7215 on frame F. Return in *PROP_IDX the index where tool-bar item
7216 properties start in F->current_tool_bar_items. Value is zero if
7217 GLYPH doesn't display a tool-bar item. */
7220 tool_bar_item_info (f
, glyph
, prop_idx
)
7222 struct glyph
*glyph
;
7228 /* Get the text property `menu-item' at pos. The value of that
7229 property is the start index of this item's properties in
7230 F->current_tool_bar_items. */
7231 prop
= Fget_text_property (make_number (glyph
->charpos
),
7232 Qmenu_item
, f
->current_tool_bar_string
);
7233 if (INTEGERP (prop
))
7235 *prop_idx
= XINT (prop
);
7244 #endif /* HAVE_WINDOW_SYSTEM */
7248 /************************************************************************
7249 Horizontal scrolling
7250 ************************************************************************/
7252 static int hscroll_window_tree
P_ ((Lisp_Object
));
7253 static int hscroll_windows
P_ ((Lisp_Object
));
7255 /* For all leaf windows in the window tree rooted at WINDOW, set their
7256 hscroll value so that PT is (i) visible in the window, and (ii) so
7257 that it is not within a certain margin at the window's left and
7258 right border. Value is non-zero if any window's hscroll has been
7262 hscroll_window_tree (window
)
7265 int hscrolled_p
= 0;
7267 while (WINDOWP (window
))
7269 struct window
*w
= XWINDOW (window
);
7271 if (WINDOWP (w
->hchild
))
7272 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7273 else if (WINDOWP (w
->vchild
))
7274 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7275 else if (w
->cursor
.vpos
>= 0)
7277 int hscroll_margin
, text_area_x
, text_area_y
;
7278 int text_area_width
, text_area_height
;
7279 struct glyph_row
*current_cursor_row
7280 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7281 struct glyph_row
*desired_cursor_row
7282 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7283 struct glyph_row
*cursor_row
7284 = (desired_cursor_row
->enabled_p
7285 ? desired_cursor_row
7286 : current_cursor_row
);
7288 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7289 &text_area_width
, &text_area_height
);
7291 /* Scroll when cursor is inside this scroll margin. */
7292 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
7294 if ((XFASTINT (w
->hscroll
)
7295 && w
->cursor
.x
< hscroll_margin
)
7296 || (cursor_row
->enabled_p
7297 && cursor_row
->truncated_on_right_p
7298 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
7302 struct buffer
*saved_current_buffer
;
7305 /* Find point in a display of infinite width. */
7306 saved_current_buffer
= current_buffer
;
7307 current_buffer
= XBUFFER (w
->buffer
);
7309 if (w
== XWINDOW (selected_window
))
7310 pt
= BUF_PT (current_buffer
);
7313 pt
= marker_position (w
->pointm
);
7314 pt
= max (BEGV
, pt
);
7318 /* Move iterator to pt starting at cursor_row->start in
7319 a line with infinite width. */
7320 init_to_row_start (&it
, w
, cursor_row
);
7321 it
.last_visible_x
= INFINITY
;
7322 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
7323 current_buffer
= saved_current_buffer
;
7325 /* Center cursor in window. */
7326 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
7327 / CANON_X_UNIT (it
.f
));
7329 /* Don't call Fset_window_hscroll if value hasn't
7330 changed because it will prevent redisplay
7332 if (XFASTINT (w
->hscroll
) != hscroll
)
7334 Fset_window_hscroll (window
, make_number (hscroll
));
7343 /* Value is non-zero if hscroll of any leaf window has been changed. */
7348 /* Set hscroll so that cursor is visible and not inside horizontal
7349 scroll margins for all windows in the tree rooted at WINDOW. See
7350 also hscroll_window_tree above. Value is non-zero if any window's
7351 hscroll has been changed. If it has, desired matrices on the frame
7352 of WINDOW are cleared. */
7355 hscroll_windows (window
)
7360 if (automatic_hscrolling_p
)
7362 hscrolled_p
= hscroll_window_tree (window
);
7364 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
7373 /************************************************************************
7375 ************************************************************************/
7377 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
7378 to a non-zero value. This is sometimes handy to have in a debugger
7383 /* First and last unchanged row for try_window_id. */
7385 int debug_first_unchanged_at_end_vpos
;
7386 int debug_last_unchanged_at_beg_vpos
;
7388 /* Delta vpos and y. */
7390 int debug_dvpos
, debug_dy
;
7392 /* Delta in characters and bytes for try_window_id. */
7394 int debug_delta
, debug_delta_bytes
;
7396 /* Values of window_end_pos and window_end_vpos at the end of
7399 int debug_end_pos
, debug_end_vpos
;
7401 /* Append a string to W->desired_matrix->method. FMT is a printf
7402 format string. A1...A9 are a supplement for a variable-length
7403 argument list. If trace_redisplay_p is non-zero also printf the
7404 resulting string to stderr. */
7407 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
7410 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
7413 char *method
= w
->desired_matrix
->method
;
7414 int len
= strlen (method
);
7415 int size
= sizeof w
->desired_matrix
->method
;
7416 int remaining
= size
- len
- 1;
7418 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
7419 if (len
&& remaining
)
7425 strncpy (method
+ len
, buffer
, remaining
);
7427 if (trace_redisplay_p
)
7428 fprintf (stderr
, "%p (%s): %s\n",
7430 ((BUFFERP (w
->buffer
)
7431 && STRINGP (XBUFFER (w
->buffer
)->name
))
7432 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
7437 #endif /* GLYPH_DEBUG */
7440 /* This counter is used to clear the face cache every once in a while
7441 in redisplay_internal. It is incremented for each redisplay.
7442 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
7445 #define CLEAR_FACE_CACHE_COUNT 10000
7446 static int clear_face_cache_count
;
7448 /* Record the previous terminal frame we displayed. */
7450 static struct frame
*previous_terminal_frame
;
7452 /* Non-zero while redisplay_internal is in progress. */
7457 /* Value is non-zero if all changes in window W, which displays
7458 current_buffer, are in the text between START and END. START is a
7459 buffer position, END is given as a distance from Z. Used in
7460 redisplay_internal for display optimization. */
7463 text_outside_line_unchanged_p (w
, start
, end
)
7467 int unchanged_p
= 1;
7469 /* If text or overlays have changed, see where. */
7470 if (XFASTINT (w
->last_modified
) < MODIFF
7471 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7473 /* Gap in the line? */
7474 if (GPT
< start
|| Z
- GPT
< end
)
7477 /* Changes start in front of the line, or end after it? */
7479 && (BEG_UNCHANGED
< start
- 1
7480 || END_UNCHANGED
< end
))
7483 /* If selective display, can't optimize if changes start at the
7484 beginning of the line. */
7486 && INTEGERP (current_buffer
->selective_display
)
7487 && XINT (current_buffer
->selective_display
) > 0
7488 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
7496 /* Do a frame update, taking possible shortcuts into account. This is
7497 the main external entry point for redisplay.
7499 If the last redisplay displayed an echo area message and that message
7500 is no longer requested, we clear the echo area or bring back the
7501 mini-buffer if that is in use. */
7506 redisplay_internal (0);
7509 /* Return 1 if point moved out of or into a composition. Otherwise
7510 return 0. PREV_BUF and PREV_PT are the last point buffer and
7511 position. BUF and PT are the current point buffer and position. */
7514 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
7515 struct buffer
*prev_buf
, *buf
;
7522 XSETBUFFER (buffer
, buf
);
7523 /* Check a composition at the last point if point moved within the
7525 if (prev_buf
== buf
)
7528 /* Point didn't move. */
7531 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
7532 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
7533 && COMPOSITION_VALID_P (start
, end
, prop
)
7534 && start
< prev_pt
&& end
> prev_pt
)
7535 /* The last point was within the composition. Return 1 iff
7536 point moved out of the composition. */
7537 return (pt
<= start
|| pt
>= end
);
7540 /* Check a composition at the current point. */
7541 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
7542 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
7543 && COMPOSITION_VALID_P (start
, end
, prop
)
7544 && start
< pt
&& end
> pt
);
7547 /* Reconsider the setting of B->clip_changed which is displayed
7551 reconsider_clip_changes (w
, b
)
7555 if (b
->prevent_redisplay_optimizations_p
)
7556 b
->clip_changed
= 1;
7557 else if (b
->clip_changed
7558 && !NILP (w
->window_end_valid
)
7559 && w
->current_matrix
->buffer
== b
7560 && w
->current_matrix
->zv
== BUF_ZV (b
)
7561 && w
->current_matrix
->begv
== BUF_BEGV (b
))
7562 b
->clip_changed
= 0;
7564 /* If display wasn't paused, and W is not a tool bar window, see if
7565 point has been moved into or out of a composition. In that case,
7566 we set b->clip_changed to 1 to force updating the screen. If
7567 b->clip_changed has already been set to 1, we can skip this
7569 if (!b
->clip_changed
7570 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
7574 if (w
== XWINDOW (selected_window
))
7575 pt
= BUF_PT (current_buffer
);
7577 pt
= marker_position (w
->pointm
);
7579 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
7580 || pt
!= XINT (w
->last_point
))
7581 && check_point_in_composition (w
->current_matrix
->buffer
,
7582 XINT (w
->last_point
),
7583 XBUFFER (w
->buffer
), pt
))
7584 b
->clip_changed
= 1;
7589 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
7590 response to any user action; therefore, we should preserve the echo
7591 area. (Actually, our caller does that job.) Perhaps in the future
7592 avoid recentering windows if it is not necessary; currently that
7593 causes some problems. */
7596 redisplay_internal (preserve_echo_area
)
7597 int preserve_echo_area
;
7599 struct window
*w
= XWINDOW (selected_window
);
7600 struct frame
*f
= XFRAME (w
->frame
);
7602 int must_finish
= 0;
7603 struct text_pos tlbufpos
, tlendpos
;
7604 int number_of_visible_frames
;
7606 struct frame
*sf
= SELECTED_FRAME ();
7608 /* Non-zero means redisplay has to consider all windows on all
7609 frames. Zero means, only selected_window is considered. */
7610 int consider_all_windows_p
;
7612 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
7614 /* No redisplay if running in batch mode or frame is not yet fully
7615 initialized, or redisplay is explicitly turned off by setting
7616 Vinhibit_redisplay. */
7618 || !NILP (Vinhibit_redisplay
)
7619 || !f
->glyphs_initialized_p
)
7622 /* The flag redisplay_performed_directly_p is set by
7623 direct_output_for_insert when it already did the whole screen
7624 update necessary. */
7625 if (redisplay_performed_directly_p
)
7627 redisplay_performed_directly_p
= 0;
7628 if (!hscroll_windows (selected_window
))
7632 #ifdef USE_X_TOOLKIT
7633 if (popup_activated ())
7637 /* I don't think this happens but let's be paranoid. */
7641 /* Record a function that resets redisplaying_p to its old value
7642 when we leave this function. */
7643 count
= specpdl_ptr
- specpdl
;
7644 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
7649 reconsider_clip_changes (w
, current_buffer
);
7651 /* If new fonts have been loaded that make a glyph matrix adjustment
7652 necessary, do it. */
7653 if (fonts_changed_p
)
7655 adjust_glyphs (NULL
);
7656 ++windows_or_buffers_changed
;
7657 fonts_changed_p
= 0;
7660 if (! FRAME_WINDOW_P (sf
)
7661 && previous_terminal_frame
!= sf
)
7663 /* Since frames on an ASCII terminal share the same display
7664 area, displaying a different frame means redisplay the whole
7666 windows_or_buffers_changed
++;
7667 SET_FRAME_GARBAGED (sf
);
7668 XSETFRAME (Vterminal_frame
, sf
);
7670 previous_terminal_frame
= sf
;
7672 /* Set the visible flags for all frames. Do this before checking
7673 for resized or garbaged frames; they want to know if their frames
7674 are visible. See the comment in frame.h for
7675 FRAME_SAMPLE_VISIBILITY. */
7677 Lisp_Object tail
, frame
;
7679 number_of_visible_frames
= 0;
7681 FOR_EACH_FRAME (tail
, frame
)
7683 struct frame
*f
= XFRAME (frame
);
7685 FRAME_SAMPLE_VISIBILITY (f
);
7686 if (FRAME_VISIBLE_P (f
))
7687 ++number_of_visible_frames
;
7688 clear_desired_matrices (f
);
7692 /* Notice any pending interrupt request to change frame size. */
7693 do_pending_window_change (1);
7695 /* Clear frames marked as garbaged. */
7697 clear_garbaged_frames ();
7699 /* Build menubar and tool-bar items. */
7700 prepare_menu_bars ();
7702 if (windows_or_buffers_changed
)
7703 update_mode_lines
++;
7705 /* Detect case that we need to write or remove a star in the mode line. */
7706 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
7708 w
->update_mode_line
= Qt
;
7709 if (buffer_shared
> 1)
7710 update_mode_lines
++;
7713 /* If %c is in the mode line, update it if needed. */
7714 if (!NILP (w
->column_number_displayed
)
7715 /* This alternative quickly identifies a common case
7716 where no change is needed. */
7717 && !(PT
== XFASTINT (w
->last_point
)
7718 && XFASTINT (w
->last_modified
) >= MODIFF
7719 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7720 && XFASTINT (w
->column_number_displayed
) != current_column ())
7721 w
->update_mode_line
= Qt
;
7723 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
7725 /* The variable buffer_shared is set in redisplay_window and
7726 indicates that we redisplay a buffer in different windows. See
7728 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
7730 /* If specs for an arrow have changed, do thorough redisplay
7731 to ensure we remove any arrow that should no longer exist. */
7732 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
7733 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
7734 consider_all_windows_p
= windows_or_buffers_changed
= 1;
7736 /* Normally the message* functions will have already displayed and
7737 updated the echo area, but the frame may have been trashed, or
7738 the update may have been preempted, so display the echo area
7739 again here. Checking both message buffers captures the case that
7740 the echo area should be cleared. */
7741 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
7743 int window_height_changed_p
= echo_area_display (0);
7746 if (fonts_changed_p
)
7748 else if (window_height_changed_p
)
7750 consider_all_windows_p
= 1;
7751 ++update_mode_lines
;
7752 ++windows_or_buffers_changed
;
7754 /* If window configuration was changed, frames may have been
7755 marked garbaged. Clear them or we will experience
7756 surprises wrt scrolling. */
7758 clear_garbaged_frames ();
7761 else if (EQ (selected_window
, minibuf_window
)
7762 && (current_buffer
->clip_changed
7763 || XFASTINT (w
->last_modified
) < MODIFF
7764 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7765 && resize_mini_window (w
, 0))
7767 /* Resized active mini-window to fit the size of what it is
7768 showing if its contents might have changed. */
7770 consider_all_windows_p
= 1;
7771 ++windows_or_buffers_changed
;
7772 ++update_mode_lines
;
7774 /* If window configuration was changed, frames may have been
7775 marked garbaged. Clear them or we will experience
7776 surprises wrt scrolling. */
7778 clear_garbaged_frames ();
7782 /* If showing the region, and mark has changed, we must redisplay
7783 the whole window. The assignment to this_line_start_pos prevents
7784 the optimization directly below this if-statement. */
7785 if (((!NILP (Vtransient_mark_mode
)
7786 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7787 != !NILP (w
->region_showing
))
7788 || (!NILP (w
->region_showing
)
7789 && !EQ (w
->region_showing
,
7790 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
7791 CHARPOS (this_line_start_pos
) = 0;
7793 /* Optimize the case that only the line containing the cursor in the
7794 selected window has changed. Variables starting with this_ are
7795 set in display_line and record information about the line
7796 containing the cursor. */
7797 tlbufpos
= this_line_start_pos
;
7798 tlendpos
= this_line_end_pos
;
7799 if (!consider_all_windows_p
7800 && CHARPOS (tlbufpos
) > 0
7801 && NILP (w
->update_mode_line
)
7802 && !current_buffer
->clip_changed
7803 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
7804 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
7805 /* Make sure recorded data applies to current buffer, etc. */
7806 && this_line_buffer
== current_buffer
7807 && current_buffer
== XBUFFER (w
->buffer
)
7808 && NILP (w
->force_start
)
7809 /* Point must be on the line that we have info recorded about. */
7810 && PT
>= CHARPOS (tlbufpos
)
7811 && PT
<= Z
- CHARPOS (tlendpos
)
7812 /* All text outside that line, including its final newline,
7813 must be unchanged */
7814 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
7815 CHARPOS (tlendpos
)))
7817 if (CHARPOS (tlbufpos
) > BEGV
7818 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
7819 && (CHARPOS (tlbufpos
) == ZV
7820 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
7821 /* Former continuation line has disappeared by becoming empty */
7823 else if (XFASTINT (w
->last_modified
) < MODIFF
7824 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
7825 || MINI_WINDOW_P (w
))
7827 /* We have to handle the case of continuation around a
7828 wide-column character (See the comment in indent.c around
7831 For instance, in the following case:
7833 -------- Insert --------
7834 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
7835 J_I_ ==> J_I_ `^^' are cursors.
7839 As we have to redraw the line above, we should goto cancel. */
7842 int line_height_before
= this_line_pixel_height
;
7844 /* Note that start_display will handle the case that the
7845 line starting at tlbufpos is a continuation lines. */
7846 start_display (&it
, w
, tlbufpos
);
7848 /* Implementation note: It this still necessary? */
7849 if (it
.current_x
!= this_line_start_x
)
7852 TRACE ((stderr
, "trying display optimization 1\n"));
7853 w
->cursor
.vpos
= -1;
7854 overlay_arrow_seen
= 0;
7855 it
.vpos
= this_line_vpos
;
7856 it
.current_y
= this_line_y
;
7857 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
7860 /* If line contains point, is not continued,
7861 and ends at same distance from eob as before, we win */
7862 if (w
->cursor
.vpos
>= 0
7863 /* Line is not continued, otherwise this_line_start_pos
7864 would have been set to 0 in display_line. */
7865 && CHARPOS (this_line_start_pos
)
7866 /* Line ends as before. */
7867 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
7868 /* Line has same height as before. Otherwise other lines
7869 would have to be shifted up or down. */
7870 && this_line_pixel_height
== line_height_before
)
7872 /* If this is not the window's last line, we must adjust
7873 the charstarts of the lines below. */
7874 if (it
.current_y
< it
.last_visible_y
)
7876 struct glyph_row
*row
7877 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
7878 int delta
, delta_bytes
;
7880 if (Z
- CHARPOS (tlendpos
) == ZV
)
7882 /* This line ends at end of (accessible part of)
7883 buffer. There is no newline to count. */
7885 - CHARPOS (tlendpos
)
7886 - MATRIX_ROW_START_CHARPOS (row
));
7887 delta_bytes
= (Z_BYTE
7888 - BYTEPOS (tlendpos
)
7889 - MATRIX_ROW_START_BYTEPOS (row
));
7893 /* This line ends in a newline. Must take
7894 account of the newline and the rest of the
7895 text that follows. */
7897 - CHARPOS (tlendpos
)
7898 - MATRIX_ROW_START_CHARPOS (row
));
7899 delta_bytes
= (Z_BYTE
7900 - BYTEPOS (tlendpos
)
7901 - MATRIX_ROW_START_BYTEPOS (row
));
7904 increment_matrix_positions (w
->current_matrix
,
7906 w
->current_matrix
->nrows
,
7907 delta
, delta_bytes
);
7910 /* If this row displays text now but previously didn't,
7911 or vice versa, w->window_end_vpos may have to be
7913 if ((it
.glyph_row
- 1)->displays_text_p
)
7915 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
7916 XSETINT (w
->window_end_vpos
, this_line_vpos
);
7918 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
7919 && this_line_vpos
> 0)
7920 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
7921 w
->window_end_valid
= Qnil
;
7923 /* Update hint: No need to try to scroll in update_window. */
7924 w
->desired_matrix
->no_scrolling_p
= 1;
7927 *w
->desired_matrix
->method
= 0;
7928 debug_method_add (w
, "optimization 1");
7935 else if (/* Cursor position hasn't changed. */
7936 PT
== XFASTINT (w
->last_point
)
7937 /* Make sure the cursor was last displayed
7938 in this window. Otherwise we have to reposition it. */
7939 && 0 <= w
->cursor
.vpos
7940 && XINT (w
->height
) > w
->cursor
.vpos
)
7944 do_pending_window_change (1);
7946 /* We used to always goto end_of_redisplay here, but this
7947 isn't enough if we have a blinking cursor. */
7948 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
7949 goto end_of_redisplay
;
7953 /* If highlighting the region, or if the cursor is in the echo area,
7954 then we can't just move the cursor. */
7955 else if (! (!NILP (Vtransient_mark_mode
)
7956 && !NILP (current_buffer
->mark_active
))
7957 && (EQ (selected_window
, current_buffer
->last_selected_window
)
7958 || highlight_nonselected_windows
)
7959 && NILP (w
->region_showing
)
7960 && NILP (Vshow_trailing_whitespace
)
7961 && !cursor_in_echo_area
)
7964 struct glyph_row
*row
;
7966 /* Skip from tlbufpos to PT and see where it is. Note that
7967 PT may be in invisible text. If so, we will end at the
7968 next visible position. */
7969 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
7970 NULL
, DEFAULT_FACE_ID
);
7971 it
.current_x
= this_line_start_x
;
7972 it
.current_y
= this_line_y
;
7973 it
.vpos
= this_line_vpos
;
7975 /* The call to move_it_to stops in front of PT, but
7976 moves over before-strings. */
7977 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
7979 if (it
.vpos
== this_line_vpos
7980 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
7983 xassert (this_line_vpos
== it
.vpos
);
7984 xassert (this_line_y
== it
.current_y
);
7985 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
7993 /* Text changed drastically or point moved off of line. */
7994 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
7997 CHARPOS (this_line_start_pos
) = 0;
7998 consider_all_windows_p
|= buffer_shared
> 1;
7999 ++clear_face_cache_count
;
8002 /* Build desired matrices, and update the display. If
8003 consider_all_windows_p is non-zero, do it for all windows on all
8004 frames. Otherwise do it for selected_window, only. */
8006 if (consider_all_windows_p
)
8008 Lisp_Object tail
, frame
;
8010 /* Clear the face cache eventually. */
8011 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8013 clear_face_cache (0);
8014 clear_face_cache_count
= 0;
8017 /* Recompute # windows showing selected buffer. This will be
8018 incremented each time such a window is displayed. */
8021 FOR_EACH_FRAME (tail
, frame
)
8023 struct frame
*f
= XFRAME (frame
);
8025 if (FRAME_WINDOW_P (f
) || f
== sf
)
8027 /* Mark all the scroll bars to be removed; we'll redeem
8028 the ones we want when we redisplay their windows. */
8029 if (condemn_scroll_bars_hook
)
8030 (*condemn_scroll_bars_hook
) (f
);
8032 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8033 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8035 /* Any scroll bars which redisplay_windows should have
8036 nuked should now go away. */
8037 if (judge_scroll_bars_hook
)
8038 (*judge_scroll_bars_hook
) (f
);
8040 /* If fonts changed, display again. */
8041 if (fonts_changed_p
)
8044 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8046 /* See if we have to hscroll. */
8047 if (hscroll_windows (f
->root_window
))
8050 /* Prevent various kinds of signals during display
8051 update. stdio is not robust about handling
8052 signals, which can cause an apparent I/O
8054 if (interrupt_input
)
8058 /* Update the display. */
8059 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8060 pause
|= update_frame (f
, 0, 0);
8064 mark_window_display_accurate (f
->root_window
, 1);
8065 if (frame_up_to_date_hook
)
8066 frame_up_to_date_hook (f
);
8071 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8073 Lisp_Object mini_window
;
8074 struct frame
*mini_frame
;
8076 redisplay_window (selected_window
, 1);
8078 /* Compare desired and current matrices, perform output. */
8081 /* If fonts changed, display again. */
8082 if (fonts_changed_p
)
8085 /* Prevent various kinds of signals during display update.
8086 stdio is not robust about handling signals,
8087 which can cause an apparent I/O error. */
8088 if (interrupt_input
)
8092 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8094 if (hscroll_windows (selected_window
))
8097 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8098 pause
= update_frame (sf
, 0, 0);
8101 /* We may have called echo_area_display at the top of this
8102 function. If the echo area is on another frame, that may
8103 have put text on a frame other than the selected one, so the
8104 above call to update_frame would not have caught it. Catch
8106 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8107 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8109 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8111 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8112 pause
|= update_frame (mini_frame
, 0, 0);
8113 if (!pause
&& hscroll_windows (mini_window
))
8118 /* If display was paused because of pending input, make sure we do a
8119 thorough update the next time. */
8122 /* Prevent the optimization at the beginning of
8123 redisplay_internal that tries a single-line update of the
8124 line containing the cursor in the selected window. */
8125 CHARPOS (this_line_start_pos
) = 0;
8127 /* Let the overlay arrow be updated the next time. */
8128 if (!NILP (last_arrow_position
))
8130 last_arrow_position
= Qt
;
8131 last_arrow_string
= Qt
;
8134 /* If we pause after scrolling, some rows in the current
8135 matrices of some windows are not valid. */
8136 if (!WINDOW_FULL_WIDTH_P (w
)
8137 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8138 update_mode_lines
= 1;
8141 /* Now text on frame agrees with windows, so put info into the
8142 windows for partial redisplay to follow. */
8145 register struct buffer
*b
= XBUFFER (w
->buffer
);
8147 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
8148 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
8149 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
8150 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
8152 if (consider_all_windows_p
)
8153 mark_window_display_accurate (FRAME_ROOT_WINDOW (sf
), 1);
8156 XSETFASTINT (w
->last_point
, BUF_PT (b
));
8157 w
->last_cursor
= w
->cursor
;
8158 w
->last_cursor_off_p
= w
->cursor_off_p
;
8160 b
->clip_changed
= 0;
8161 b
->prevent_redisplay_optimizations_p
= 0;
8162 w
->update_mode_line
= Qnil
;
8163 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
8164 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
8166 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8169 /* Record if we are showing a region, so can make sure to
8170 update it fully at next redisplay. */
8171 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
8172 && (EQ (selected_window
,
8173 current_buffer
->last_selected_window
)
8174 || highlight_nonselected_windows
)
8175 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
8176 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
8179 w
->window_end_valid
= w
->buffer
;
8180 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8181 last_arrow_string
= Voverlay_arrow_string
;
8182 if (frame_up_to_date_hook
!= 0)
8183 (*frame_up_to_date_hook
) (sf
);
8185 w
->current_matrix
->buffer
= b
;
8186 w
->current_matrix
->begv
= BUF_BEGV (b
);
8187 w
->current_matrix
->zv
= BUF_ZV (b
);
8190 update_mode_lines
= 0;
8191 windows_or_buffers_changed
= 0;
8194 /* Start SIGIO interrupts coming again. Having them off during the
8195 code above makes it less likely one will discard output, but not
8196 impossible, since there might be stuff in the system buffer here.
8197 But it is much hairier to try to do anything about that. */
8198 if (interrupt_input
)
8202 /* If a frame has become visible which was not before, redisplay
8203 again, so that we display it. Expose events for such a frame
8204 (which it gets when becoming visible) don't call the parts of
8205 redisplay constructing glyphs, so simply exposing a frame won't
8206 display anything in this case. So, we have to display these
8207 frames here explicitly. */
8210 Lisp_Object tail
, frame
;
8213 FOR_EACH_FRAME (tail
, frame
)
8215 int this_is_visible
= 0;
8217 if (XFRAME (frame
)->visible
)
8218 this_is_visible
= 1;
8219 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8220 if (XFRAME (frame
)->visible
)
8221 this_is_visible
= 1;
8223 if (this_is_visible
)
8227 if (new_count
!= number_of_visible_frames
)
8228 windows_or_buffers_changed
++;
8231 /* Change frame size now if a change is pending. */
8232 do_pending_window_change (1);
8234 /* If we just did a pending size change, or have additional
8235 visible frames, redisplay again. */
8236 if (windows_or_buffers_changed
&& !pause
)
8241 unbind_to (count
, Qnil
);
8245 /* Redisplay, but leave alone any recent echo area message unless
8246 another message has been requested in its place.
8248 This is useful in situations where you need to redisplay but no
8249 user action has occurred, making it inappropriate for the message
8250 area to be cleared. See tracking_off and
8251 wait_reading_process_input for examples of these situations. */
8254 redisplay_preserve_echo_area ()
8256 if (!NILP (echo_area_buffer
[1]))
8258 /* We have a previously displayed message, but no current
8259 message. Redisplay the previous message. */
8260 display_last_displayed_message_p
= 1;
8261 redisplay_internal (1);
8262 display_last_displayed_message_p
= 0;
8265 redisplay_internal (1);
8269 /* Function registered with record_unwind_protect in
8270 redisplay_internal. Clears the flag indicating that a redisplay is
8274 unwind_redisplay (old_redisplaying_p
)
8275 Lisp_Object old_redisplaying_p
;
8277 redisplaying_p
= XFASTINT (old_redisplaying_p
);
8282 /* Mark the display of windows in the window tree rooted at WINDOW as
8283 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
8284 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
8285 the next time redisplay_internal is called. */
8288 mark_window_display_accurate (window
, accurate_p
)
8294 for (; !NILP (window
); window
= w
->next
)
8296 w
= XWINDOW (window
);
8298 if (BUFFERP (w
->buffer
))
8300 struct buffer
*b
= XBUFFER (w
->buffer
);
8302 XSETFASTINT (w
->last_modified
,
8303 accurate_p
? BUF_MODIFF (b
) : 0);
8304 XSETFASTINT (w
->last_overlay_modified
,
8305 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
8306 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
8309 #if 0 /* I don't think this is necessary because display_line does it.
8311 /* Record if we are showing a region, so can make sure to
8312 update it fully at next redisplay. */
8314 = (!NILP (Vtransient_mark_mode
)
8315 && (w
== XWINDOW (current_buffer
->last_selected_window
)
8316 || highlight_nonselected_windows
)
8317 && (!NILP (b
->mark_active
)
8318 ? Fmarker_position (b
->mark
)
8324 b
->clip_changed
= 0;
8325 b
->prevent_redisplay_optimizations_p
= 0;
8326 w
->current_matrix
->buffer
= b
;
8327 w
->current_matrix
->begv
= BUF_BEGV (b
);
8328 w
->current_matrix
->zv
= BUF_ZV (b
);
8329 w
->last_cursor
= w
->cursor
;
8330 w
->last_cursor_off_p
= w
->cursor_off_p
;
8331 if (w
== XWINDOW (selected_window
))
8332 w
->last_point
= make_number (BUF_PT (b
));
8334 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
8338 w
->window_end_valid
= w
->buffer
;
8339 w
->update_mode_line
= Qnil
;
8341 if (!NILP (w
->vchild
))
8342 mark_window_display_accurate (w
->vchild
, accurate_p
);
8343 if (!NILP (w
->hchild
))
8344 mark_window_display_accurate (w
->hchild
, accurate_p
);
8349 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8350 last_arrow_string
= Voverlay_arrow_string
;
8354 /* Force a thorough redisplay the next time by setting
8355 last_arrow_position and last_arrow_string to t, which is
8356 unequal to any useful value of Voverlay_arrow_... */
8357 last_arrow_position
= Qt
;
8358 last_arrow_string
= Qt
;
8363 /* Return value in display table DP (Lisp_Char_Table *) for character
8364 C. Since a display table doesn't have any parent, we don't have to
8365 follow parent. Do not call this function directly but use the
8366 macro DISP_CHAR_VECTOR. */
8369 disp_char_vector (dp
, c
)
8370 struct Lisp_Char_Table
*dp
;
8376 if (SINGLE_BYTE_CHAR_P (c
))
8377 return (dp
->contents
[c
]);
8379 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
8382 else if (code
[2] < 32)
8385 /* Here, the possible range of code[0] (== charset ID) is
8386 128..max_charset. Since the top level char table contains data
8387 for multibyte characters after 256th element, we must increment
8388 code[0] by 128 to get a correct index. */
8390 code
[3] = -1; /* anchor */
8392 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
8394 val
= dp
->contents
[code
[i
]];
8395 if (!SUB_CHAR_TABLE_P (val
))
8396 return (NILP (val
) ? dp
->defalt
: val
);
8399 /* Here, val is a sub char table. We return the default value of
8401 return (dp
->defalt
);
8406 /***********************************************************************
8408 ***********************************************************************/
8410 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
8413 redisplay_windows (window
)
8416 while (!NILP (window
))
8418 struct window
*w
= XWINDOW (window
);
8420 if (!NILP (w
->hchild
))
8421 redisplay_windows (w
->hchild
);
8422 else if (!NILP (w
->vchild
))
8423 redisplay_windows (w
->vchild
);
8425 redisplay_window (window
, 0);
8432 /* Set cursor position of W. PT is assumed to be displayed in ROW.
8433 DELTA is the number of bytes by which positions recorded in ROW
8434 differ from current buffer positions. */
8437 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
8439 struct glyph_row
*row
;
8440 struct glyph_matrix
*matrix
;
8441 int delta
, delta_bytes
, dy
, dvpos
;
8443 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
8444 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
8446 int pt_old
= PT
- delta
;
8448 /* Skip over glyphs not having an object at the start of the row.
8449 These are special glyphs like truncation marks on terminal
8451 if (row
->displays_text_p
)
8453 && INTEGERP (glyph
->object
)
8454 && glyph
->charpos
< 0)
8456 x
+= glyph
->pixel_width
;
8461 && !INTEGERP (glyph
->object
)
8462 && (!BUFFERP (glyph
->object
)
8463 || glyph
->charpos
< pt_old
))
8465 x
+= glyph
->pixel_width
;
8469 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
8471 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
8472 w
->cursor
.y
= row
->y
+ dy
;
8474 if (w
== XWINDOW (selected_window
))
8476 if (!row
->continued_p
8477 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
8480 this_line_buffer
= XBUFFER (w
->buffer
);
8482 CHARPOS (this_line_start_pos
)
8483 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
8484 BYTEPOS (this_line_start_pos
)
8485 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
8487 CHARPOS (this_line_end_pos
)
8488 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
8489 BYTEPOS (this_line_end_pos
)
8490 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
8492 this_line_y
= w
->cursor
.y
;
8493 this_line_pixel_height
= row
->height
;
8494 this_line_vpos
= w
->cursor
.vpos
;
8495 this_line_start_x
= row
->x
;
8498 CHARPOS (this_line_start_pos
) = 0;
8503 /* Run window scroll functions, if any, for WINDOW with new window
8504 start STARTP. Sets the window start of WINDOW to that position.
8506 We assume that the window's buffer is really current. */
8508 static INLINE
struct text_pos
8509 run_window_scroll_functions (window
, startp
)
8511 struct text_pos startp
;
8513 struct window
*w
= XWINDOW (window
);
8514 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
8516 if (current_buffer
!= XBUFFER (w
->buffer
))
8519 if (!NILP (Vwindow_scroll_functions
))
8521 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
8522 make_number (CHARPOS (startp
)));
8523 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8524 /* In case the hook functions switch buffers. */
8525 if (current_buffer
!= XBUFFER (w
->buffer
))
8526 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8533 /* Modify the desired matrix of window W and W->vscroll so that the
8534 line containing the cursor is fully visible. */
8537 make_cursor_line_fully_visible (w
)
8540 struct glyph_matrix
*matrix
;
8541 struct glyph_row
*row
;
8542 int window_height
, header_line_height
;
8544 /* It's not always possible to find the cursor, e.g, when a window
8545 is full of overlay strings. Don't do anything in that case. */
8546 if (w
->cursor
.vpos
< 0)
8549 matrix
= w
->desired_matrix
;
8550 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
8552 /* If the cursor row is not partially visible, there's nothing
8554 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8557 /* If the row the cursor is in is taller than the window's height,
8558 it's not clear what to do, so do nothing. */
8559 window_height
= window_box_height (w
);
8560 if (row
->height
>= window_height
)
8563 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
8565 int dy
= row
->height
- row
->visible_height
;
8568 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8570 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
8572 int dy
= - (row
->height
- row
->visible_height
);
8575 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8578 /* When we change the cursor y-position of the selected window,
8579 change this_line_y as well so that the display optimization for
8580 the cursor line of the selected window in redisplay_internal uses
8581 the correct y-position. */
8582 if (w
== XWINDOW (selected_window
))
8583 this_line_y
= w
->cursor
.y
;
8587 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
8588 non-zero means only WINDOW is redisplayed in redisplay_internal.
8589 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
8590 in redisplay_window to bring a partially visible line into view in
8591 the case that only the cursor has moved.
8595 1 if scrolling succeeded
8597 0 if scrolling didn't find point.
8599 -1 if new fonts have been loaded so that we must interrupt
8600 redisplay, adjust glyph matrices, and try again. */
8603 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
8604 scroll_step
, temp_scroll_step
)
8606 int just_this_one_p
;
8607 int scroll_conservatively
, scroll_step
;
8608 int temp_scroll_step
;
8610 struct window
*w
= XWINDOW (window
);
8611 struct frame
*f
= XFRAME (w
->frame
);
8612 struct text_pos scroll_margin_pos
;
8613 struct text_pos pos
;
8614 struct text_pos startp
;
8616 Lisp_Object window_end
;
8617 int this_scroll_margin
;
8621 int amount_to_scroll
= 0;
8622 Lisp_Object aggressive
;
8626 debug_method_add (w
, "try_scrolling");
8629 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8631 /* Compute scroll margin height in pixels. We scroll when point is
8632 within this distance from the top or bottom of the window. */
8633 if (scroll_margin
> 0)
8635 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
8636 this_scroll_margin
*= CANON_Y_UNIT (f
);
8639 this_scroll_margin
= 0;
8641 /* Compute how much we should try to scroll maximally to bring point
8644 scroll_max
= scroll_step
;
8645 else if (scroll_conservatively
)
8646 scroll_max
= scroll_conservatively
;
8647 else if (temp_scroll_step
)
8648 scroll_max
= temp_scroll_step
;
8649 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
8650 || NUMBERP (current_buffer
->scroll_up_aggressively
))
8651 /* We're trying to scroll because of aggressive scrolling
8652 but no scroll_step is set. Choose an arbitrary one. Maybe
8653 there should be a variable for this. */
8657 scroll_max
*= CANON_Y_UNIT (f
);
8659 /* Decide whether we have to scroll down. Start at the window end
8660 and move this_scroll_margin up to find the position of the scroll
8662 window_end
= Fwindow_end (window
, Qt
);
8663 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
8664 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
8665 if (this_scroll_margin
)
8667 start_display (&it
, w
, scroll_margin_pos
);
8668 move_it_vertically (&it
, - this_scroll_margin
);
8669 scroll_margin_pos
= it
.current
.pos
;
8672 if (PT
>= CHARPOS (scroll_margin_pos
))
8679 /* Point is in the scroll margin at the bottom of the window, or
8680 below. Compute a new window start that makes point visible. */
8682 /* Compute the distance from the scroll margin to PT.
8683 Give up if the distance is greater than scroll_max. */
8684 start_display (&it
, w
, scroll_margin_pos
);
8686 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8687 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8688 #if 0 /* Taking the line's height into account here looks wrong. */
8689 line_height
= (it
.max_ascent
+ it
.max_descent
8690 ? it
.max_ascent
+ it
.max_descent
8692 dy
= it
.current_y
+ line_height
- y0
;
8694 dy
= it
.current_y
- y0
;
8697 if (dy
> scroll_max
)
8700 /* Move the window start down. If scrolling conservatively,
8701 move it just enough down to make point visible. If
8702 scroll_step is set, move it down by scroll_step. */
8703 start_display (&it
, w
, startp
);
8705 if (scroll_conservatively
)
8706 amount_to_scroll
= dy
;
8707 else if (scroll_step
|| temp_scroll_step
)
8708 amount_to_scroll
= scroll_max
;
8711 aggressive
= current_buffer
->scroll_down_aggressively
;
8712 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8713 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8714 if (NUMBERP (aggressive
))
8715 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8718 if (amount_to_scroll
<= 0)
8721 move_it_vertically (&it
, amount_to_scroll
);
8722 startp
= it
.current
.pos
;
8726 /* See if point is inside the scroll margin at the top of the
8728 scroll_margin_pos
= startp
;
8729 if (this_scroll_margin
)
8731 start_display (&it
, w
, startp
);
8732 move_it_vertically (&it
, this_scroll_margin
);
8733 scroll_margin_pos
= it
.current
.pos
;
8736 if (PT
< CHARPOS (scroll_margin_pos
))
8738 /* Point is in the scroll margin at the top of the window or
8739 above what is displayed in the window. */
8742 /* Compute the vertical distance from PT to the scroll
8743 margin position. Give up if distance is greater than
8745 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
8746 start_display (&it
, w
, pos
);
8748 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
8749 it
.last_visible_y
, -1,
8750 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8751 dy
= it
.current_y
- y0
;
8752 if (dy
> scroll_max
)
8755 /* Compute new window start. */
8756 start_display (&it
, w
, startp
);
8758 if (scroll_conservatively
)
8759 amount_to_scroll
= dy
;
8760 else if (scroll_step
|| temp_scroll_step
)
8761 amount_to_scroll
= scroll_max
;
8764 aggressive
= current_buffer
->scroll_up_aggressively
;
8765 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8766 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8767 if (NUMBERP (aggressive
))
8768 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8771 if (amount_to_scroll
<= 0)
8774 move_it_vertically (&it
, - amount_to_scroll
);
8775 startp
= it
.current
.pos
;
8779 /* Run window scroll functions. */
8780 startp
= run_window_scroll_functions (window
, startp
);
8782 /* Display the window. Give up if new fonts are loaded, or if point
8784 if (!try_window (window
, startp
))
8786 else if (w
->cursor
.vpos
< 0)
8788 clear_glyph_matrix (w
->desired_matrix
);
8793 /* Maybe forget recorded base line for line number display. */
8794 if (!just_this_one_p
8795 || current_buffer
->clip_changed
8796 || BEG_UNCHANGED
< CHARPOS (startp
))
8797 w
->base_line_number
= Qnil
;
8799 /* If cursor ends up on a partially visible line, shift display
8800 lines up or down. */
8801 make_cursor_line_fully_visible (w
);
8809 /* Compute a suitable window start for window W if display of W starts
8810 on a continuation line. Value is non-zero if a new window start
8813 The new window start will be computed, based on W's width, starting
8814 from the start of the continued line. It is the start of the
8815 screen line with the minimum distance from the old start W->start. */
8818 compute_window_start_on_continuation_line (w
)
8821 struct text_pos pos
, start_pos
;
8822 int window_start_changed_p
= 0;
8824 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
8826 /* If window start is on a continuation line... Window start may be
8827 < BEGV in case there's invisible text at the start of the
8828 buffer (M-x rmail, for example). */
8829 if (CHARPOS (start_pos
) > BEGV
8830 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
8833 struct glyph_row
*row
;
8835 /* Handle the case that the window start is out of range. */
8836 if (CHARPOS (start_pos
) < BEGV
)
8837 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
8838 else if (CHARPOS (start_pos
) > ZV
)
8839 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
8841 /* Find the start of the continued line. This should be fast
8842 because scan_buffer is fast (newline cache). */
8843 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
8844 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
8845 row
, DEFAULT_FACE_ID
);
8846 reseat_at_previous_visible_line_start (&it
);
8848 /* If the line start is "too far" away from the window start,
8849 say it takes too much time to compute a new window start. */
8850 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
8851 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
8853 int min_distance
, distance
;
8855 /* Move forward by display lines to find the new window
8856 start. If window width was enlarged, the new start can
8857 be expected to be > the old start. If window width was
8858 decreased, the new window start will be < the old start.
8859 So, we're looking for the display line start with the
8860 minimum distance from the old window start. */
8861 pos
= it
.current
.pos
;
8862 min_distance
= INFINITY
;
8863 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
8864 distance
< min_distance
)
8866 min_distance
= distance
;
8867 pos
= it
.current
.pos
;
8868 move_it_by_lines (&it
, 1, 0);
8871 /* Set the window start there. */
8872 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
8873 window_start_changed_p
= 1;
8877 return window_start_changed_p
;
8881 /* Try cursor movement in case text has not changes in window WINDOW,
8882 with window start STARTP. Value is
8886 0 if this method cannot be used
8888 -1 if we know we have to scroll the display. *SCROLL_STEP is
8889 set to 1, under certain circumstances, if we want to scroll as
8890 if scroll-step were set to 1. See the code. */
8893 try_cursor_movement (window
, startp
, scroll_step
)
8895 struct text_pos startp
;
8898 struct window
*w
= XWINDOW (window
);
8899 struct frame
*f
= XFRAME (w
->frame
);
8902 /* Handle case where text has not changed, only point, and it has
8903 not moved off the frame. */
8904 if (/* Point may be in this window. */
8905 PT
>= CHARPOS (startp
)
8906 /* If we don't check this, we are called to move the cursor in a
8907 horizontally split window with a current matrix that doesn't
8909 && !windows_or_buffers_changed
8910 /* Selective display hasn't changed. */
8911 && !current_buffer
->clip_changed
8912 /* If force-mode-line-update was called, really redisplay;
8913 that's how redisplay is forced after e.g. changing
8914 buffer-invisibility-spec. */
8915 && NILP (w
->update_mode_line
)
8916 /* Can't use this case if highlighting a region. When a
8917 region exists, cursor movement has to do more than just
8919 && !(!NILP (Vtransient_mark_mode
)
8920 && !NILP (current_buffer
->mark_active
))
8921 && NILP (w
->region_showing
)
8922 && NILP (Vshow_trailing_whitespace
)
8923 /* Right after splitting windows, last_point may be nil. */
8924 && INTEGERP (w
->last_point
)
8925 /* This code is not used for mini-buffer for the sake of the case
8926 of redisplaying to replace an echo area message; since in
8927 that case the mini-buffer contents per se are usually
8928 unchanged. This code is of no real use in the mini-buffer
8929 since the handling of this_line_start_pos, etc., in redisplay
8930 handles the same cases. */
8931 && !EQ (window
, minibuf_window
)
8932 /* When splitting windows or for new windows, it happens that
8933 redisplay is called with a nil window_end_vpos or one being
8934 larger than the window. This should really be fixed in
8935 window.c. I don't have this on my list, now, so we do
8936 approximately the same as the old redisplay code. --gerd. */
8937 && INTEGERP (w
->window_end_vpos
)
8938 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
8939 && (FRAME_WINDOW_P (f
)
8940 || !MARKERP (Voverlay_arrow_position
)
8941 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
8943 int this_scroll_margin
;
8944 struct glyph_row
*row
;
8947 debug_method_add (w
, "cursor movement");
8950 /* Scroll if point within this distance from the top or bottom
8951 of the window. This is a pixel value. */
8952 this_scroll_margin
= max (0, scroll_margin
);
8953 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
8954 this_scroll_margin
*= CANON_Y_UNIT (f
);
8956 /* Start with the row the cursor was displayed during the last
8957 not paused redisplay. Give up if that row is not valid. */
8958 if (w
->last_cursor
.vpos
< 0
8959 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
8963 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
8964 if (row
->mode_line_p
)
8966 if (!row
->enabled_p
)
8973 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
8976 if (PT
> XFASTINT (w
->last_point
))
8978 /* Point has moved forward. */
8979 while (MATRIX_ROW_END_CHARPOS (row
) < PT
8980 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
8982 xassert (row
->enabled_p
);
8986 /* The end position of a row equals the start position
8987 of the next row. If PT is there, we would rather
8988 display it in the next line. */
8989 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
8990 && MATRIX_ROW_END_CHARPOS (row
) == PT
8991 && !cursor_row_p (w
, row
))
8994 /* If within the scroll margin, scroll. Note that
8995 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
8996 the next line would be drawn, and that
8997 this_scroll_margin can be zero. */
8998 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
8999 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9000 /* Line is completely visible last line in window
9001 and PT is to be set in the next line. */
9002 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9003 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9004 && !row
->ends_at_zv_p
9005 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9008 else if (PT
< XFASTINT (w
->last_point
))
9010 /* Cursor has to be moved backward. Note that PT >=
9011 CHARPOS (startp) because of the outer
9013 while (!row
->mode_line_p
9014 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9015 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9016 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9017 && (row
->y
> this_scroll_margin
9018 || CHARPOS (startp
) == BEGV
))
9020 xassert (row
->enabled_p
);
9024 /* Consider the following case: Window starts at BEGV,
9025 there is invisible, intangible text at BEGV, so that
9026 display starts at some point START > BEGV. It can
9027 happen that we are called with PT somewhere between
9028 BEGV and START. Try to handle that case. */
9029 if (row
< w
->current_matrix
->rows
9030 || row
->mode_line_p
)
9032 row
= w
->current_matrix
->rows
;
9033 if (row
->mode_line_p
)
9037 /* Due to newlines in overlay strings, we may have to
9038 skip forward over overlay strings. */
9039 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9040 && MATRIX_ROW_END_CHARPOS (row
) == PT
9041 && !cursor_row_p (w
, row
))
9044 /* If within the scroll margin, scroll. */
9045 if (row
->y
< this_scroll_margin
9046 && CHARPOS (startp
) != BEGV
)
9050 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9051 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9053 /* if PT is not in the glyph row, give up. */
9056 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9058 /* If we end up in a partially visible line, let's make it
9059 fully visible, except when it's taller than the window,
9060 in which case we can't do much about it. */
9061 if (row
->height
> window_box_height (w
))
9068 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9069 try_window (window
, startp
);
9070 make_cursor_line_fully_visible (w
);
9078 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9088 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9089 selected_window is redisplayed. */
9092 redisplay_window (window
, just_this_one_p
)
9094 int just_this_one_p
;
9096 struct window
*w
= XWINDOW (window
);
9097 struct frame
*f
= XFRAME (w
->frame
);
9098 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9099 struct buffer
*old
= current_buffer
;
9100 struct text_pos lpoint
, opoint
, startp
;
9101 int update_mode_line
;
9104 /* Record it now because it's overwritten. */
9105 int current_matrix_up_to_date_p
= 0;
9106 int temp_scroll_step
= 0;
9107 int count
= specpdl_ptr
- specpdl
;
9110 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9113 /* W must be a leaf window here. */
9114 xassert (!NILP (w
->buffer
));
9116 *w
->desired_matrix
->method
= 0;
9119 specbind (Qinhibit_point_motion_hooks
, Qt
);
9121 reconsider_clip_changes (w
, buffer
);
9123 /* Has the mode line to be updated? */
9124 update_mode_line
= (!NILP (w
->update_mode_line
)
9125 || update_mode_lines
9126 || buffer
->clip_changed
);
9128 if (MINI_WINDOW_P (w
))
9130 if (w
== XWINDOW (echo_area_window
)
9131 && !NILP (echo_area_buffer
[0]))
9133 if (update_mode_line
)
9134 /* We may have to update a tty frame's menu bar or a
9135 tool-bar. Example `M-x C-h C-h C-g'. */
9136 goto finish_menu_bars
;
9138 /* We've already displayed the echo area glyphs in this window. */
9139 goto finish_scroll_bars
;
9141 else if (w
!= XWINDOW (minibuf_window
))
9143 /* W is a mini-buffer window, but it's not the currently
9144 active one, so clear it. */
9145 int yb
= window_text_bottom_y (w
);
9146 struct glyph_row
*row
;
9149 for (y
= 0, row
= w
->desired_matrix
->rows
;
9151 y
+= row
->height
, ++row
)
9152 blank_row (w
, row
, y
);
9153 goto finish_scroll_bars
;
9157 /* Otherwise set up data on this window; select its buffer and point
9159 /* Really select the buffer, for the sake of buffer-local
9161 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9162 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9164 current_matrix_up_to_date_p
9165 = (!NILP (w
->window_end_valid
)
9166 && !current_buffer
->clip_changed
9167 && XFASTINT (w
->last_modified
) >= MODIFF
9168 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9170 /* When windows_or_buffers_changed is non-zero, we can't rely on
9171 the window end being valid, so set it to nil there. */
9172 if (windows_or_buffers_changed
)
9174 /* If window starts on a continuation line, maybe adjust the
9175 window start in case the window's width changed. */
9176 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9177 compute_window_start_on_continuation_line (w
);
9179 w
->window_end_valid
= Qnil
;
9182 /* Some sanity checks. */
9183 CHECK_WINDOW_END (w
);
9184 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9186 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9189 /* If %c is in mode line, update it if needed. */
9190 if (!NILP (w
->column_number_displayed
)
9191 /* This alternative quickly identifies a common case
9192 where no change is needed. */
9193 && !(PT
== XFASTINT (w
->last_point
)
9194 && XFASTINT (w
->last_modified
) >= MODIFF
9195 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9196 && XFASTINT (w
->column_number_displayed
) != current_column ())
9197 update_mode_line
= 1;
9199 /* Count number of windows showing the selected buffer. An indirect
9200 buffer counts as its base buffer. */
9201 if (!just_this_one_p
)
9203 struct buffer
*current_base
, *window_base
;
9204 current_base
= current_buffer
;
9205 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9206 if (current_base
->base_buffer
)
9207 current_base
= current_base
->base_buffer
;
9208 if (window_base
->base_buffer
)
9209 window_base
= window_base
->base_buffer
;
9210 if (current_base
== window_base
)
9214 /* Point refers normally to the selected window. For any other
9215 window, set up appropriate value. */
9216 if (!EQ (window
, selected_window
))
9218 int new_pt
= XMARKER (w
->pointm
)->charpos
;
9219 int new_pt_byte
= marker_byte_position (w
->pointm
);
9223 new_pt_byte
= BEGV_BYTE
;
9224 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
9226 else if (new_pt
> (ZV
- 1))
9229 new_pt_byte
= ZV_BYTE
;
9230 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
9233 /* We don't use SET_PT so that the point-motion hooks don't run. */
9234 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
9237 /* If any of the character widths specified in the display table
9238 have changed, invalidate the width run cache. It's true that
9239 this may be a bit late to catch such changes, but the rest of
9240 redisplay goes (non-fatally) haywire when the display table is
9241 changed, so why should we worry about doing any better? */
9242 if (current_buffer
->width_run_cache
)
9244 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
9246 if (! disptab_matches_widthtab (disptab
,
9247 XVECTOR (current_buffer
->width_table
)))
9249 invalidate_region_cache (current_buffer
,
9250 current_buffer
->width_run_cache
,
9252 recompute_width_table (current_buffer
, disptab
);
9256 /* If window-start is screwed up, choose a new one. */
9257 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
9260 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9262 /* If someone specified a new starting point but did not insist,
9263 check whether it can be used. */
9264 if (!NILP (w
->optional_new_start
)
9265 && CHARPOS (startp
) >= BEGV
9266 && CHARPOS (startp
) <= ZV
)
9268 w
->optional_new_start
= Qnil
;
9269 start_display (&it
, w
, startp
);
9270 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9271 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9272 if (IT_CHARPOS (it
) == PT
)
9273 w
->force_start
= Qt
;
9276 /* Handle case where place to start displaying has been specified,
9277 unless the specified location is outside the accessible range. */
9278 if (!NILP (w
->force_start
)
9279 || w
->frozen_window_start_p
)
9281 w
->force_start
= Qnil
;
9283 w
->window_end_valid
= Qnil
;
9285 /* Forget any recorded base line for line number display. */
9286 if (!current_matrix_up_to_date_p
9287 || current_buffer
->clip_changed
)
9288 w
->base_line_number
= Qnil
;
9290 /* Redisplay the mode line. Select the buffer properly for that.
9291 Also, run the hook window-scroll-functions
9292 because we have scrolled. */
9293 /* Note, we do this after clearing force_start because
9294 if there's an error, it is better to forget about force_start
9295 than to get into an infinite loop calling the hook functions
9296 and having them get more errors. */
9297 if (!update_mode_line
9298 || ! NILP (Vwindow_scroll_functions
))
9300 update_mode_line
= 1;
9301 w
->update_mode_line
= Qt
;
9302 startp
= run_window_scroll_functions (window
, startp
);
9305 XSETFASTINT (w
->last_modified
, 0);
9306 XSETFASTINT (w
->last_overlay_modified
, 0);
9307 if (CHARPOS (startp
) < BEGV
)
9308 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
9309 else if (CHARPOS (startp
) > ZV
)
9310 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
9312 /* Redisplay, then check if cursor has been set during the
9313 redisplay. Give up if new fonts were loaded. */
9314 if (!try_window (window
, startp
))
9316 w
->force_start
= Qt
;
9317 clear_glyph_matrix (w
->desired_matrix
);
9318 goto restore_buffers
;
9321 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
9323 /* If point does not appear, try to move point so it does
9324 appear. The desired matrix has been built above, so we
9327 struct glyph_row
*row
;
9329 window_height
= window_box_height (w
) / 2;
9330 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
9331 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
9334 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
9335 MATRIX_ROW_START_BYTEPOS (row
));
9337 if (w
!= XWINDOW (selected_window
))
9338 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
9339 else if (current_buffer
== old
)
9340 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9342 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
9344 /* If we are highlighting the region, then we just changed
9345 the region, so redisplay to show it. */
9346 if (!NILP (Vtransient_mark_mode
)
9347 && !NILP (current_buffer
->mark_active
))
9349 clear_glyph_matrix (w
->desired_matrix
);
9350 if (!try_window (window
, startp
))
9351 goto restore_buffers
;
9355 make_cursor_line_fully_visible (w
);
9357 debug_method_add (w
, "forced window start");
9362 /* Handle case where text has not changed, only point, and it has
9363 not moved off the frame. */
9364 if (current_matrix_up_to_date_p
9365 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
9373 /* If current starting point was originally the beginning of a line
9374 but no longer is, find a new starting point. */
9375 else if (!NILP (w
->start_at_line_beg
)
9376 && !(CHARPOS (startp
) <= BEGV
9377 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
9380 debug_method_add (w
, "recenter 1");
9385 /* Try scrolling with try_window_id. */
9386 else if (/* Windows and buffers haven't changed. */
9387 !windows_or_buffers_changed
9388 /* Window must be either use window-based redisplay or
9390 && (FRAME_WINDOW_P (f
)
9391 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
9392 && !MINI_WINDOW_P (w
)
9393 /* Point is not known NOT to appear in window. */
9394 && PT
>= CHARPOS (startp
)
9395 && XFASTINT (w
->last_modified
)
9396 /* Window is not hscrolled. */
9397 && XFASTINT (w
->hscroll
) == 0
9398 /* Selective display has not changed. */
9399 && !current_buffer
->clip_changed
9400 /* Current matrix is up to date. */
9401 && !NILP (w
->window_end_valid
)
9402 /* Can't use this case if highlighting a region because
9403 a cursor movement will do more than just set the cursor. */
9404 && !(!NILP (Vtransient_mark_mode
)
9405 && !NILP (current_buffer
->mark_active
))
9406 && NILP (w
->region_showing
)
9407 && NILP (Vshow_trailing_whitespace
)
9408 /* Overlay arrow position and string not changed. */
9409 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
9410 && EQ (last_arrow_string
, Voverlay_arrow_string
)
9411 /* Value is > 0 if update has been done, it is -1 if we
9412 know that the same window start will not work. It is 0
9413 if unsuccessful for some other reason. */
9414 && (tem
= try_window_id (w
)) != 0)
9417 debug_method_add (w
, "try_window_id %d", tem
);
9420 if (fonts_changed_p
)
9421 goto restore_buffers
;
9425 /* Otherwise try_window_id has returned -1 which means that we
9426 don't want the alternative below this comment to execute. */
9428 else if (CHARPOS (startp
) >= BEGV
9429 && CHARPOS (startp
) <= ZV
9430 && PT
>= CHARPOS (startp
)
9431 && (CHARPOS (startp
) < ZV
9432 /* Avoid starting at end of buffer. */
9433 || CHARPOS (startp
) == BEGV
9434 || (XFASTINT (w
->last_modified
) >= MODIFF
9435 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
9438 debug_method_add (w
, "same window start");
9441 /* Try to redisplay starting at same place as before.
9442 If point has not moved off frame, accept the results. */
9443 if (!current_matrix_up_to_date_p
9444 /* Don't use try_window_reusing_current_matrix in this case
9445 because a window scroll function can have changed the
9447 || !NILP (Vwindow_scroll_functions
)
9448 || MINI_WINDOW_P (w
)
9449 || !try_window_reusing_current_matrix (w
))
9451 IF_DEBUG (debug_method_add (w
, "1"));
9452 try_window (window
, startp
);
9455 if (fonts_changed_p
)
9456 goto restore_buffers
;
9458 if (w
->cursor
.vpos
>= 0)
9460 if (!just_this_one_p
9461 || current_buffer
->clip_changed
9462 || BEG_UNCHANGED
< CHARPOS (startp
))
9463 /* Forget any recorded base line for line number display. */
9464 w
->base_line_number
= Qnil
;
9466 make_cursor_line_fully_visible (w
);
9470 clear_glyph_matrix (w
->desired_matrix
);
9475 XSETFASTINT (w
->last_modified
, 0);
9476 XSETFASTINT (w
->last_overlay_modified
, 0);
9478 /* Redisplay the mode line. Select the buffer properly for that. */
9479 if (!update_mode_line
)
9481 update_mode_line
= 1;
9482 w
->update_mode_line
= Qt
;
9485 /* Try to scroll by specified few lines. */
9486 if ((scroll_conservatively
9489 || NUMBERP (current_buffer
->scroll_up_aggressively
)
9490 || NUMBERP (current_buffer
->scroll_down_aggressively
))
9491 && !current_buffer
->clip_changed
9492 && CHARPOS (startp
) >= BEGV
9493 && CHARPOS (startp
) <= ZV
)
9495 /* The function returns -1 if new fonts were loaded, 1 if
9496 successful, 0 if not successful. */
9497 int rc
= try_scrolling (window
, just_this_one_p
,
9498 scroll_conservatively
,
9504 goto restore_buffers
;
9507 /* Finally, just choose place to start which centers point */
9512 debug_method_add (w
, "recenter");
9515 /* w->vscroll = 0; */
9517 /* Forget any previously recorded base line for line number display. */
9518 if (!current_matrix_up_to_date_p
9519 || current_buffer
->clip_changed
)
9520 w
->base_line_number
= Qnil
;
9522 /* Move backward half the height of the window. */
9523 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9524 it
.current_y
= it
.last_visible_y
;
9525 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
9526 xassert (IT_CHARPOS (it
) >= BEGV
);
9528 /* The function move_it_vertically_backward may move over more
9529 than the specified y-distance. If it->w is small, e.g. a
9530 mini-buffer window, we may end up in front of the window's
9531 display area. Start displaying at the start of the line
9532 containing PT in this case. */
9533 if (it
.current_y
<= 0)
9535 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9536 move_it_vertically (&it
, 0);
9537 xassert (IT_CHARPOS (it
) <= PT
);
9541 it
.current_x
= it
.hpos
= 0;
9543 /* Set startp here explicitly in case that helps avoid an infinite loop
9544 in case the window-scroll-functions functions get errors. */
9545 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
9547 /* Run scroll hooks. */
9548 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
9550 /* Redisplay the window. */
9551 if (!current_matrix_up_to_date_p
9552 || windows_or_buffers_changed
9553 /* Don't use try_window_reusing_current_matrix in this case
9554 because it can have changed the buffer. */
9555 || !NILP (Vwindow_scroll_functions
)
9557 || MINI_WINDOW_P (w
)
9558 || !try_window_reusing_current_matrix (w
))
9559 try_window (window
, startp
);
9561 /* If new fonts have been loaded (due to fontsets), give up. We
9562 have to start a new redisplay since we need to re-adjust glyph
9564 if (fonts_changed_p
)
9565 goto restore_buffers
;
9567 /* If cursor did not appear assume that the middle of the window is
9568 in the first line of the window. Do it again with the next line.
9569 (Imagine a window of height 100, displaying two lines of height
9570 60. Moving back 50 from it->last_visible_y will end in the first
9572 if (w
->cursor
.vpos
< 0)
9574 if (!NILP (w
->window_end_valid
)
9575 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
9577 clear_glyph_matrix (w
->desired_matrix
);
9578 move_it_by_lines (&it
, 1, 0);
9579 try_window (window
, it
.current
.pos
);
9581 else if (PT
< IT_CHARPOS (it
))
9583 clear_glyph_matrix (w
->desired_matrix
);
9584 move_it_by_lines (&it
, -1, 0);
9585 try_window (window
, it
.current
.pos
);
9589 /* Not much we can do about it. */
9593 /* Consider the following case: Window starts at BEGV, there is
9594 invisible, intangible text at BEGV, so that display starts at
9595 some point START > BEGV. It can happen that we are called with
9596 PT somewhere between BEGV and START. Try to handle that case. */
9597 if (w
->cursor
.vpos
< 0)
9599 struct glyph_row
*row
= w
->current_matrix
->rows
;
9600 if (row
->mode_line_p
)
9602 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9605 make_cursor_line_fully_visible (w
);
9609 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9610 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
9611 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
9614 /* Display the mode line, if we must. */
9615 if ((update_mode_line
9616 /* If window not full width, must redo its mode line
9617 if (a) the window to its side is being redone and
9618 (b) we do a frame-based redisplay. This is a consequence
9619 of how inverted lines are drawn in frame-based redisplay. */
9620 || (!just_this_one_p
9621 && !FRAME_WINDOW_P (f
)
9622 && !WINDOW_FULL_WIDTH_P (w
))
9623 /* Line number to display. */
9624 || INTEGERP (w
->base_line_pos
)
9625 /* Column number is displayed and different from the one displayed. */
9626 || (!NILP (w
->column_number_displayed
)
9627 && XFASTINT (w
->column_number_displayed
) != current_column ()))
9628 /* This means that the window has a mode line. */
9629 && (WINDOW_WANTS_MODELINE_P (w
)
9630 || WINDOW_WANTS_HEADER_LINE_P (w
)))
9632 Lisp_Object old_selected_frame
;
9634 old_selected_frame
= selected_frame
;
9636 XSETFRAME (selected_frame
, f
);
9637 display_mode_lines (w
);
9638 selected_frame
= old_selected_frame
;
9640 /* If mode line height has changed, arrange for a thorough
9641 immediate redisplay using the correct mode line height. */
9642 if (WINDOW_WANTS_MODELINE_P (w
)
9643 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
9645 fonts_changed_p
= 1;
9646 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
9647 = DESIRED_MODE_LINE_HEIGHT (w
);
9650 /* If top line height has changed, arrange for a thorough
9651 immediate redisplay using the correct mode line height. */
9652 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9653 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
9655 fonts_changed_p
= 1;
9656 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
9657 = DESIRED_HEADER_LINE_HEIGHT (w
);
9660 if (fonts_changed_p
)
9661 goto restore_buffers
;
9664 if (!line_number_displayed
9665 && !BUFFERP (w
->base_line_pos
))
9667 w
->base_line_pos
= Qnil
;
9668 w
->base_line_number
= Qnil
;
9673 /* When we reach a frame's selected window, redo the frame's menu bar. */
9674 if (update_mode_line
9675 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
9677 int redisplay_menu_p
= 0;
9679 if (FRAME_WINDOW_P (f
))
9681 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
9682 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
9684 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9688 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9690 if (redisplay_menu_p
)
9691 display_menu_bar (w
);
9693 #ifdef HAVE_WINDOW_SYSTEM
9694 if (WINDOWP (f
->tool_bar_window
)
9695 && (FRAME_TOOL_BAR_LINES (f
) > 0
9696 || auto_resize_tool_bars_p
))
9697 redisplay_tool_bar (f
);
9703 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9705 int start
, end
, whole
;
9707 /* Calculate the start and end positions for the current window.
9708 At some point, it would be nice to choose between scrollbars
9709 which reflect the whole buffer size, with special markers
9710 indicating narrowing, and scrollbars which reflect only the
9713 Note that mini-buffers sometimes aren't displaying any text. */
9714 if (!MINI_WINDOW_P (w
)
9715 || (w
== XWINDOW (minibuf_window
)
9716 && NILP (echo_area_buffer
[0])))
9719 start
= marker_position (w
->start
) - BEGV
;
9720 /* I don't think this is guaranteed to be right. For the
9721 moment, we'll pretend it is. */
9722 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
9726 if (whole
< (end
- start
))
9727 whole
= end
- start
;
9730 start
= end
= whole
= 0;
9732 /* Indicate what this scroll bar ought to be displaying now. */
9733 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
9735 /* Note that we actually used the scroll bar attached to this
9736 window, so it shouldn't be deleted at the end of redisplay. */
9737 (*redeem_scroll_bar_hook
) (w
);
9742 /* Restore current_buffer and value of point in it. */
9743 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
9744 set_buffer_internal_1 (old
);
9745 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
9747 unbind_to (count
, Qnil
);
9751 /* Build the complete desired matrix of WINDOW with a window start
9752 buffer position POS. Value is non-zero if successful. It is zero
9753 if fonts were loaded during redisplay which makes re-adjusting
9754 glyph matrices necessary. */
9757 try_window (window
, pos
)
9759 struct text_pos pos
;
9761 struct window
*w
= XWINDOW (window
);
9763 struct glyph_row
*last_text_row
= NULL
;
9765 /* Make POS the new window start. */
9766 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
9768 /* Mark cursor position as unknown. No overlay arrow seen. */
9769 w
->cursor
.vpos
= -1;
9770 overlay_arrow_seen
= 0;
9772 /* Initialize iterator and info to start at POS. */
9773 start_display (&it
, w
, pos
);
9775 /* Display all lines of W. */
9776 while (it
.current_y
< it
.last_visible_y
)
9778 if (display_line (&it
))
9779 last_text_row
= it
.glyph_row
- 1;
9780 if (fonts_changed_p
)
9784 /* If bottom moved off end of frame, change mode line percentage. */
9785 if (XFASTINT (w
->window_end_pos
) <= 0
9786 && Z
!= IT_CHARPOS (it
))
9787 w
->update_mode_line
= Qt
;
9789 /* Set window_end_pos to the offset of the last character displayed
9790 on the window from the end of current_buffer. Set
9791 window_end_vpos to its row number. */
9794 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
9795 w
->window_end_bytepos
9796 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9797 XSETFASTINT (w
->window_end_pos
,
9798 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9799 XSETFASTINT (w
->window_end_vpos
,
9800 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9801 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
9806 w
->window_end_bytepos
= 0;
9807 XSETFASTINT (w
->window_end_pos
, 0);
9808 XSETFASTINT (w
->window_end_vpos
, 0);
9811 /* But that is not valid info until redisplay finishes. */
9812 w
->window_end_valid
= Qnil
;
9818 /************************************************************************
9819 Window redisplay reusing current matrix when buffer has not changed
9820 ************************************************************************/
9822 /* Try redisplay of window W showing an unchanged buffer with a
9823 different window start than the last time it was displayed by
9824 reusing its current matrix. Value is non-zero if successful.
9825 W->start is the new window start. */
9828 try_window_reusing_current_matrix (w
)
9831 struct frame
*f
= XFRAME (w
->frame
);
9832 struct glyph_row
*row
, *bottom_row
;
9835 struct text_pos start
, new_start
;
9836 int nrows_scrolled
, i
;
9837 struct glyph_row
*last_text_row
;
9838 struct glyph_row
*last_reused_text_row
;
9839 struct glyph_row
*start_row
;
9840 int start_vpos
, min_y
, max_y
;
9842 if (/* This function doesn't handle terminal frames. */
9844 /* Don't try to reuse the display if windows have been split
9846 || windows_or_buffers_changed
)
9849 /* Can't do this if region may have changed. */
9850 if ((!NILP (Vtransient_mark_mode
)
9851 && !NILP (current_buffer
->mark_active
))
9852 || !NILP (w
->region_showing
)
9853 || !NILP (Vshow_trailing_whitespace
))
9856 /* If top-line visibility has changed, give up. */
9857 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9858 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
9861 /* Give up if old or new display is scrolled vertically. We could
9862 make this function handle this, but right now it doesn't. */
9863 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9864 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
9867 /* The variable new_start now holds the new window start. The old
9868 start `start' can be determined from the current matrix. */
9869 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
9870 start
= start_row
->start
.pos
;
9871 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
9873 /* Clear the desired matrix for the display below. */
9874 clear_glyph_matrix (w
->desired_matrix
);
9876 if (CHARPOS (new_start
) <= CHARPOS (start
))
9880 IF_DEBUG (debug_method_add (w
, "twu1"));
9882 /* Display up to a row that can be reused. The variable
9883 last_text_row is set to the last row displayed that displays
9884 text. Note that it.vpos == 0 if or if not there is a
9885 header-line; it's not the same as the MATRIX_ROW_VPOS! */
9886 start_display (&it
, w
, new_start
);
9887 first_row_y
= it
.current_y
;
9888 w
->cursor
.vpos
= -1;
9889 last_text_row
= last_reused_text_row
= NULL
;
9891 while (it
.current_y
< it
.last_visible_y
9892 && IT_CHARPOS (it
) < CHARPOS (start
)
9893 && !fonts_changed_p
)
9894 if (display_line (&it
))
9895 last_text_row
= it
.glyph_row
- 1;
9897 /* A value of current_y < last_visible_y means that we stopped
9898 at the previous window start, which in turn means that we
9899 have at least one reusable row. */
9900 if (it
.current_y
< it
.last_visible_y
)
9902 /* IT.vpos always starts from 0; it counts text lines. */
9903 nrows_scrolled
= it
.vpos
;
9905 /* Find PT if not already found in the lines displayed. */
9906 if (w
->cursor
.vpos
< 0)
9908 int dy
= it
.current_y
- first_row_y
;
9910 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9911 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9913 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
9914 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9916 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
9917 dy
, nrows_scrolled
);
9921 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
9927 /* Give up if point was not found. This shouldn't
9928 happen often; not more often than with try_window
9930 if (w
->cursor
.vpos
< 0)
9932 clear_glyph_matrix (w
->desired_matrix
);
9937 /* Scroll the display. Do it before the current matrix is
9938 changed. The problem here is that update has not yet
9939 run, i.e. part of the current matrix is not up to date.
9940 scroll_run_hook will clear the cursor, and use the
9941 current matrix to get the height of the row the cursor is
9943 run
.current_y
= first_row_y
;
9944 run
.desired_y
= it
.current_y
;
9945 run
.height
= it
.last_visible_y
- it
.current_y
;
9947 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
9950 rif
->update_window_begin_hook (w
);
9951 rif
->clear_mouse_face (w
);
9952 rif
->scroll_run_hook (w
, &run
);
9953 rif
->update_window_end_hook (w
, 0, 0);
9957 /* Shift current matrix down by nrows_scrolled lines. */
9958 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9959 rotate_matrix (w
->current_matrix
,
9961 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9964 /* Disable lines not reused. */
9965 for (i
= 0; i
< it
.vpos
; ++i
)
9966 (start_row
+ i
)->enabled_p
= 0;
9968 /* Re-compute Y positions. */
9969 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9970 max_y
= it
.last_visible_y
;
9971 for (row
= start_row
+ nrows_scrolled
;
9975 row
->y
= it
.current_y
;
9978 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9979 else if (row
->y
+ row
->height
> max_y
)
9981 = row
->height
- (row
->y
+ row
->height
- max_y
);
9983 row
->visible_height
= row
->height
;
9985 it
.current_y
+= row
->height
;
9987 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9988 last_reused_text_row
= row
;
9989 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
9994 /* Update window_end_pos etc.; last_reused_text_row is the last
9995 reused row from the current matrix containing text, if any.
9996 The value of last_text_row is the last displayed line
9998 if (last_reused_text_row
)
10000 w
->window_end_bytepos
10001 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10002 XSETFASTINT (w
->window_end_pos
,
10003 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10004 XSETFASTINT (w
->window_end_vpos
,
10005 MATRIX_ROW_VPOS (last_reused_text_row
,
10006 w
->current_matrix
));
10008 else if (last_text_row
)
10010 w
->window_end_bytepos
10011 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10012 XSETFASTINT (w
->window_end_pos
,
10013 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10014 XSETFASTINT (w
->window_end_vpos
,
10015 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10019 /* This window must be completely empty. */
10020 w
->window_end_bytepos
= 0;
10021 XSETFASTINT (w
->window_end_pos
, 0);
10022 XSETFASTINT (w
->window_end_vpos
, 0);
10024 w
->window_end_valid
= Qnil
;
10026 /* Update hint: don't try scrolling again in update_window. */
10027 w
->desired_matrix
->no_scrolling_p
= 1;
10030 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10034 else if (CHARPOS (new_start
) > CHARPOS (start
))
10036 struct glyph_row
*pt_row
, *row
;
10037 struct glyph_row
*first_reusable_row
;
10038 struct glyph_row
*first_row_to_display
;
10040 int yb
= window_text_bottom_y (w
);
10042 IF_DEBUG (debug_method_add (w
, "twu2"));
10044 /* Find the row starting at new_start, if there is one. Don't
10045 reuse a partially visible line at the end. */
10046 first_reusable_row
= start_row
;
10047 while (first_reusable_row
->enabled_p
10048 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10049 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10050 < CHARPOS (new_start
)))
10051 ++first_reusable_row
;
10053 /* Give up if there is no row to reuse. */
10054 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10055 || !first_reusable_row
->enabled_p
10056 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10057 != CHARPOS (new_start
)))
10060 /* We can reuse fully visible rows beginning with
10061 first_reusable_row to the end of the window. Set
10062 first_row_to_display to the first row that cannot be reused.
10063 Set pt_row to the row containing point, if there is any. */
10064 first_row_to_display
= first_reusable_row
;
10066 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
10068 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10069 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10070 pt_row
= first_row_to_display
;
10072 ++first_row_to_display
;
10075 /* Start displaying at the start of first_row_to_display. */
10076 xassert (first_row_to_display
->y
< yb
);
10077 init_to_row_start (&it
, w
, first_row_to_display
);
10078 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10080 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10082 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10083 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10085 /* Display lines beginning with first_row_to_display in the
10086 desired matrix. Set last_text_row to the last row displayed
10087 that displays text. */
10088 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10089 if (pt_row
== NULL
)
10090 w
->cursor
.vpos
= -1;
10091 last_text_row
= NULL
;
10092 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10093 if (display_line (&it
))
10094 last_text_row
= it
.glyph_row
- 1;
10096 /* Give up If point isn't in a row displayed or reused. */
10097 if (w
->cursor
.vpos
< 0)
10099 clear_glyph_matrix (w
->desired_matrix
);
10103 /* If point is in a reused row, adjust y and vpos of the cursor
10107 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10108 w
->current_matrix
);
10109 w
->cursor
.y
-= first_reusable_row
->y
;
10112 /* Scroll the display. */
10113 run
.current_y
= first_reusable_row
->y
;
10114 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10115 run
.height
= it
.last_visible_y
- run
.current_y
;
10116 dy
= run
.current_y
- run
.desired_y
;
10120 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10122 rif
->update_window_begin_hook (w
);
10123 rif
->clear_mouse_face (w
);
10124 rif
->scroll_run_hook (w
, &run
);
10125 rif
->update_window_end_hook (w
, 0, 0);
10129 /* Adjust Y positions of reused rows. */
10130 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10131 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10132 max_y
= it
.last_visible_y
;
10133 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10136 if (row
->y
< min_y
)
10137 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10138 else if (row
->y
+ row
->height
> max_y
)
10139 row
->visible_height
10140 = row
->height
- (row
->y
+ row
->height
- max_y
);
10142 row
->visible_height
= row
->height
;
10145 /* Disable rows not reused. */
10146 while (row
< bottom_row
)
10148 row
->enabled_p
= 0;
10152 /* Scroll the current matrix. */
10153 xassert (nrows_scrolled
> 0);
10154 rotate_matrix (w
->current_matrix
,
10156 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10159 /* Adjust window end. A null value of last_text_row means that
10160 the window end is in reused rows which in turn means that
10161 only its vpos can have changed. */
10164 w
->window_end_bytepos
10165 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10166 XSETFASTINT (w
->window_end_pos
,
10167 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10168 XSETFASTINT (w
->window_end_vpos
,
10169 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10173 XSETFASTINT (w
->window_end_vpos
,
10174 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10177 w
->window_end_valid
= Qnil
;
10178 w
->desired_matrix
->no_scrolling_p
= 1;
10181 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10191 /************************************************************************
10192 Window redisplay reusing current matrix when buffer has changed
10193 ************************************************************************/
10195 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10196 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10198 static struct glyph_row
*
10199 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10200 struct glyph_row
*));
10203 /* Return the last row in MATRIX displaying text. If row START is
10204 non-null, start searching with that row. IT gives the dimensions
10205 of the display. Value is null if matrix is empty; otherwise it is
10206 a pointer to the row found. */
10208 static struct glyph_row
*
10209 find_last_row_displaying_text (matrix
, it
, start
)
10210 struct glyph_matrix
*matrix
;
10212 struct glyph_row
*start
;
10214 struct glyph_row
*row
, *row_found
;
10216 /* Set row_found to the last row in IT->w's current matrix
10217 displaying text. The loop looks funny but think of partially
10220 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
10221 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10223 xassert (row
->enabled_p
);
10225 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
10234 /* Return the last row in the current matrix of W that is not affected
10235 by changes at the start of current_buffer that occurred since the
10236 last time W was redisplayed. Value is null if no such row exists.
10238 The global variable beg_unchanged has to contain the number of
10239 bytes unchanged at the start of current_buffer. BEG +
10240 beg_unchanged is the buffer position of the first changed byte in
10241 current_buffer. Characters at positions < BEG + beg_unchanged are
10242 at the same buffer positions as they were when the current matrix
10245 static struct glyph_row
*
10246 find_last_unchanged_at_beg_row (w
)
10249 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
10250 struct glyph_row
*row
;
10251 struct glyph_row
*row_found
= NULL
;
10252 int yb
= window_text_bottom_y (w
);
10254 /* Find the last row displaying unchanged text. */
10255 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10256 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
10257 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
10259 if (/* If row ends before first_changed_pos, it is unchanged,
10260 except in some case. */
10261 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
10262 /* When row ends in ZV and we write at ZV it is not
10264 && !row
->ends_at_zv_p
10265 /* When first_changed_pos is the end of a continued line,
10266 row is not unchanged because it may be no longer
10268 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
10269 && row
->continued_p
))
10272 /* Stop if last visible row. */
10273 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
10283 /* Find the first glyph row in the current matrix of W that is not
10284 affected by changes at the end of current_buffer since the last
10285 time the window was redisplayed. Return in *DELTA the number of
10286 chars by which buffer positions in unchanged text at the end of
10287 current_buffer must be adjusted. Return in *DELTA_BYTES the
10288 corresponding number of bytes. Value is null if no such row
10289 exists, i.e. all rows are affected by changes. */
10291 static struct glyph_row
*
10292 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
10294 int *delta
, *delta_bytes
;
10296 struct glyph_row
*row
;
10297 struct glyph_row
*row_found
= NULL
;
10299 *delta
= *delta_bytes
= 0;
10301 /* Display must not have been paused, otherwise the current matrix
10302 is not up to date. */
10303 if (NILP (w
->window_end_valid
))
10306 /* A value of window_end_pos >= END_UNCHANGED means that the window
10307 end is in the range of changed text. If so, there is no
10308 unchanged row at the end of W's current matrix. */
10309 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
10312 /* Set row to the last row in W's current matrix displaying text. */
10313 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10315 /* If matrix is entirely empty, no unchanged row exists. */
10316 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10318 /* The value of row is the last glyph row in the matrix having a
10319 meaningful buffer position in it. The end position of row
10320 corresponds to window_end_pos. This allows us to translate
10321 buffer positions in the current matrix to current buffer
10322 positions for characters not in changed text. */
10323 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
10324 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
10325 int last_unchanged_pos
, last_unchanged_pos_old
;
10326 struct glyph_row
*first_text_row
10327 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10329 *delta
= Z
- Z_old
;
10330 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
10332 /* Set last_unchanged_pos to the buffer position of the last
10333 character in the buffer that has not been changed. Z is the
10334 index + 1 of the last byte in current_buffer, i.e. by
10335 subtracting end_unchanged we get the index of the last
10336 unchanged character, and we have to add BEG to get its buffer
10338 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
10339 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
10341 /* Search backward from ROW for a row displaying a line that
10342 starts at a minimum position >= last_unchanged_pos_old. */
10343 for (; row
> first_text_row
; --row
)
10345 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10348 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
10353 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
10360 /* Make sure that glyph rows in the current matrix of window W
10361 reference the same glyph memory as corresponding rows in the
10362 frame's frame matrix. This function is called after scrolling W's
10363 current matrix on a terminal frame in try_window_id and
10364 try_window_reusing_current_matrix. */
10367 sync_frame_with_window_matrix_rows (w
)
10370 struct frame
*f
= XFRAME (w
->frame
);
10371 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
10373 /* Preconditions: W must be a leaf window and full-width. Its frame
10374 must have a frame matrix. */
10375 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
10376 xassert (WINDOW_FULL_WIDTH_P (w
));
10377 xassert (!FRAME_WINDOW_P (f
));
10379 /* If W is a full-width window, glyph pointers in W's current matrix
10380 have, by definition, to be the same as glyph pointers in the
10381 corresponding frame matrix. */
10382 window_row
= w
->current_matrix
->rows
;
10383 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
10384 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
10385 while (window_row
< window_row_end
)
10389 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
10390 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
10392 /* Disable frame rows whose corresponding window rows have
10393 been disabled in try_window_id. */
10394 if (!window_row
->enabled_p
)
10395 frame_row
->enabled_p
= 0;
10397 ++window_row
, ++frame_row
;
10402 /* Find the glyph row in window W containing CHARPOS. Consider all
10403 rows between START and END (not inclusive). END null means search
10404 all rows to the end of the display area of W. Value is the row
10405 containing CHARPOS or null. */
10407 static struct glyph_row
*
10408 row_containing_pos (w
, charpos
, start
, end
)
10411 struct glyph_row
*start
, *end
;
10413 struct glyph_row
*row
= start
;
10416 /* If we happen to start on a header-line, skip that. */
10417 if (row
->mode_line_p
)
10420 if ((end
&& row
>= end
) || !row
->enabled_p
)
10423 last_y
= window_text_bottom_y (w
);
10425 while ((end
== NULL
|| row
< end
)
10426 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
10427 /* The end position of a row equals the start
10428 position of the next row. If CHARPOS is there, we
10429 would rather display it in the next line, except
10430 when this line ends in ZV. */
10431 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
10432 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
10433 || !row
->ends_at_zv_p
)))
10434 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
10437 /* Give up if CHARPOS not found. */
10438 if ((end
&& row
>= end
)
10439 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
10440 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
10447 /* Try to redisplay window W by reusing its existing display. W's
10448 current matrix must be up to date when this function is called,
10449 i.e. window_end_valid must not be nil.
10453 1 if display has been updated
10454 0 if otherwise unsuccessful
10455 -1 if redisplay with same window start is known not to succeed
10457 The following steps are performed:
10459 1. Find the last row in the current matrix of W that is not
10460 affected by changes at the start of current_buffer. If no such row
10463 2. Find the first row in W's current matrix that is not affected by
10464 changes at the end of current_buffer. Maybe there is no such row.
10466 3. Display lines beginning with the row + 1 found in step 1 to the
10467 row found in step 2 or, if step 2 didn't find a row, to the end of
10470 4. If cursor is not known to appear on the window, give up.
10472 5. If display stopped at the row found in step 2, scroll the
10473 display and current matrix as needed.
10475 6. Maybe display some lines at the end of W, if we must. This can
10476 happen under various circumstances, like a partially visible line
10477 becoming fully visible, or because newly displayed lines are displayed
10478 in smaller font sizes.
10480 7. Update W's window end information. */
10482 /* Check that window end is what we expect it to be. */
10488 struct frame
*f
= XFRAME (w
->frame
);
10489 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
10490 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
10491 struct glyph_row
*last_unchanged_at_beg_row
;
10492 struct glyph_row
*first_unchanged_at_end_row
;
10493 struct glyph_row
*row
;
10494 struct glyph_row
*bottom_row
;
10497 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
10498 struct text_pos start_pos
;
10500 int first_unchanged_at_end_vpos
= 0;
10501 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
10502 struct text_pos start
;
10504 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10506 /* Check pre-conditions. Window end must be valid, otherwise
10507 the current matrix would not be up to date. */
10508 xassert (!NILP (w
->window_end_valid
));
10509 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
10510 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
10512 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
10513 only if buffer has really changed. The reason is that the gap is
10514 initially at Z for freshly visited files. The code below would
10515 set end_unchanged to 0 in that case. */
10516 if (MODIFF
> SAVE_MODIFF
10517 /* This seems to happen sometimes after saving a buffer. */
10518 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
10520 if (GPT
- BEG
< BEG_UNCHANGED
)
10521 BEG_UNCHANGED
= GPT
- BEG
;
10522 if (Z
- GPT
< END_UNCHANGED
)
10523 END_UNCHANGED
= Z
- GPT
;
10526 /* If window starts after a line end, and the last change is in
10527 front of that newline, then changes don't affect the display.
10528 This case happens with stealth-fontification. Note that although
10529 the display is unchanged, glyph positions in the matrix have to
10530 be adjusted, of course. */
10531 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10532 if (CHARPOS (start
) > BEGV
10533 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
10534 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
10535 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10537 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
10538 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
10542 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10543 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
10545 increment_matrix_positions (w
->current_matrix
,
10546 MATRIX_ROW_VPOS (r0
, current_matrix
),
10547 MATRIX_ROW_VPOS (r1
, current_matrix
),
10548 delta
, delta_bytes
);
10551 #if 0 /* If changes are all in front of the window start, the
10552 distance of the last displayed glyph from Z hasn't
10555 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10556 w
->window_end_bytepos
10557 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10563 /* Return quickly if changes are all below what is displayed in the
10564 window, and if PT is in the window. */
10565 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
10566 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10568 /* We have to update window end positions because the buffer's
10569 size has changed. */
10571 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10572 w
->window_end_bytepos
10573 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10575 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10576 row
= row_containing_pos (w
, PT
, row
, NULL
);
10577 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10581 /* Check that window start agrees with the start of the first glyph
10582 row in its current matrix. Check this after we know the window
10583 start is not in changed text, otherwise positions would not be
10585 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10586 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
10589 /* Compute the position at which we have to start displaying new
10590 lines. Some of the lines at the top of the window might be
10591 reusable because they are not displaying changed text. Find the
10592 last row in W's current matrix not affected by changes at the
10593 start of current_buffer. Value is null if changes start in the
10594 first line of window. */
10595 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
10596 if (last_unchanged_at_beg_row
)
10598 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
10599 start_pos
= it
.current
.pos
;
10601 /* Start displaying new lines in the desired matrix at the same
10602 vpos we would use in the current matrix, i.e. below
10603 last_unchanged_at_beg_row. */
10604 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
10606 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10607 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
10609 xassert (it
.hpos
== 0 && it
.current_x
== 0);
10613 /* There are no reusable lines at the start of the window.
10614 Start displaying in the first line. */
10615 start_display (&it
, w
, start
);
10616 start_pos
= it
.current
.pos
;
10619 /* Find the first row that is not affected by changes at the end of
10620 the buffer. Value will be null if there is no unchanged row, in
10621 which case we must redisplay to the end of the window. delta
10622 will be set to the value by which buffer positions beginning with
10623 first_unchanged_at_end_row have to be adjusted due to text
10625 first_unchanged_at_end_row
10626 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
10627 IF_DEBUG (debug_delta
= delta
);
10628 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
10630 /* Set stop_pos to the buffer position up to which we will have to
10631 display new lines. If first_unchanged_at_end_row != NULL, this
10632 is the buffer position of the start of the line displayed in that
10633 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
10634 that we don't stop at a buffer position. */
10636 if (first_unchanged_at_end_row
)
10638 xassert (last_unchanged_at_beg_row
== NULL
10639 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
10641 /* If this is a continuation line, move forward to the next one
10642 that isn't. Changes in lines above affect this line.
10643 Caution: this may move first_unchanged_at_end_row to a row
10644 not displaying text. */
10645 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
10646 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10647 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10648 < it
.last_visible_y
))
10649 ++first_unchanged_at_end_row
;
10651 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10652 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10653 >= it
.last_visible_y
))
10654 first_unchanged_at_end_row
= NULL
;
10657 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
10659 first_unchanged_at_end_vpos
10660 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
10661 xassert (stop_pos
>= Z
- END_UNCHANGED
);
10664 else if (last_unchanged_at_beg_row
== NULL
)
10670 /* Either there is no unchanged row at the end, or the one we have
10671 now displays text. This is a necessary condition for the window
10672 end pos calculation at the end of this function. */
10673 xassert (first_unchanged_at_end_row
== NULL
10674 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
10676 debug_last_unchanged_at_beg_vpos
10677 = (last_unchanged_at_beg_row
10678 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
10680 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
10682 #endif /* GLYPH_DEBUG != 0 */
10685 /* Display new lines. Set last_text_row to the last new line
10686 displayed which has text on it, i.e. might end up as being the
10687 line where the window_end_vpos is. */
10688 w
->cursor
.vpos
= -1;
10689 last_text_row
= NULL
;
10690 overlay_arrow_seen
= 0;
10691 while (it
.current_y
< it
.last_visible_y
10692 && !fonts_changed_p
10693 && (first_unchanged_at_end_row
== NULL
10694 || IT_CHARPOS (it
) < stop_pos
))
10696 if (display_line (&it
))
10697 last_text_row
= it
.glyph_row
- 1;
10700 if (fonts_changed_p
)
10704 /* Compute differences in buffer positions, y-positions etc. for
10705 lines reused at the bottom of the window. Compute what we can
10707 if (first_unchanged_at_end_row
10708 /* No lines reused because we displayed everything up to the
10709 bottom of the window. */
10710 && it
.current_y
< it
.last_visible_y
)
10713 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
10715 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
10716 run
.current_y
= first_unchanged_at_end_row
->y
;
10717 run
.desired_y
= run
.current_y
+ dy
;
10718 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
10722 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
10723 first_unchanged_at_end_row
= NULL
;
10725 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
10728 /* Find the cursor if not already found. We have to decide whether
10729 PT will appear on this window (it sometimes doesn't, but this is
10730 not a very frequent case.) This decision has to be made before
10731 the current matrix is altered. A value of cursor.vpos < 0 means
10732 that PT is either in one of the lines beginning at
10733 first_unchanged_at_end_row or below the window. Don't care for
10734 lines that might be displayed later at the window end; as
10735 mentioned, this is not a frequent case. */
10736 if (w
->cursor
.vpos
< 0)
10738 /* Cursor in unchanged rows at the top? */
10739 if (PT
< CHARPOS (start_pos
)
10740 && last_unchanged_at_beg_row
)
10742 row
= row_containing_pos (w
, PT
,
10743 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
10744 last_unchanged_at_beg_row
+ 1);
10746 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10749 /* Start from first_unchanged_at_end_row looking for PT. */
10750 else if (first_unchanged_at_end_row
)
10752 row
= row_containing_pos (w
, PT
- delta
,
10753 first_unchanged_at_end_row
, NULL
);
10755 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
10756 delta_bytes
, dy
, dvpos
);
10759 /* Give up if cursor was not found. */
10760 if (w
->cursor
.vpos
< 0)
10762 clear_glyph_matrix (w
->desired_matrix
);
10767 /* Don't let the cursor end in the scroll margins. */
10769 int this_scroll_margin
, cursor_height
;
10771 this_scroll_margin
= max (0, scroll_margin
);
10772 this_scroll_margin
= min (this_scroll_margin
,
10773 XFASTINT (w
->height
) / 4);
10774 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
10775 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
10777 if ((w
->cursor
.y
< this_scroll_margin
10778 && CHARPOS (start
) > BEGV
)
10779 /* Don't take scroll margin into account at the bottom because
10780 old redisplay didn't do it either. */
10781 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
10783 w
->cursor
.vpos
= -1;
10784 clear_glyph_matrix (w
->desired_matrix
);
10789 /* Scroll the display. Do it before changing the current matrix so
10790 that xterm.c doesn't get confused about where the cursor glyph is
10792 if (dy
&& run
.height
)
10796 if (FRAME_WINDOW_P (f
))
10798 rif
->update_window_begin_hook (w
);
10799 rif
->clear_mouse_face (w
);
10800 rif
->scroll_run_hook (w
, &run
);
10801 rif
->update_window_end_hook (w
, 0, 0);
10805 /* Terminal frame. In this case, dvpos gives the number of
10806 lines to scroll by; dvpos < 0 means scroll up. */
10807 int first_unchanged_at_end_vpos
10808 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
10809 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
10810 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
10812 /* Perform the operation on the screen. */
10815 /* Scroll last_unchanged_at_beg_row to the end of the
10816 window down dvpos lines. */
10817 set_terminal_window (end
);
10819 /* On dumb terminals delete dvpos lines at the end
10820 before inserting dvpos empty lines. */
10821 if (!scroll_region_ok
)
10822 ins_del_lines (end
- dvpos
, -dvpos
);
10824 /* Insert dvpos empty lines in front of
10825 last_unchanged_at_beg_row. */
10826 ins_del_lines (from
, dvpos
);
10828 else if (dvpos
< 0)
10830 /* Scroll up last_unchanged_at_beg_vpos to the end of
10831 the window to last_unchanged_at_beg_vpos - |dvpos|. */
10832 set_terminal_window (end
);
10834 /* Delete dvpos lines in front of
10835 last_unchanged_at_beg_vpos. ins_del_lines will set
10836 the cursor to the given vpos and emit |dvpos| delete
10838 ins_del_lines (from
+ dvpos
, dvpos
);
10840 /* On a dumb terminal insert dvpos empty lines at the
10842 if (!scroll_region_ok
)
10843 ins_del_lines (end
+ dvpos
, -dvpos
);
10846 set_terminal_window (0);
10852 /* Shift reused rows of the current matrix to the right position.
10853 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
10855 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10856 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
10859 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
10860 bottom_vpos
, dvpos
);
10861 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
10864 else if (dvpos
> 0)
10866 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
10867 bottom_vpos
, dvpos
);
10868 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
10869 first_unchanged_at_end_vpos
+ dvpos
, 0);
10872 /* For frame-based redisplay, make sure that current frame and window
10873 matrix are in sync with respect to glyph memory. */
10874 if (!FRAME_WINDOW_P (f
))
10875 sync_frame_with_window_matrix_rows (w
);
10877 /* Adjust buffer positions in reused rows. */
10879 increment_matrix_positions (current_matrix
,
10880 first_unchanged_at_end_vpos
+ dvpos
,
10881 bottom_vpos
, delta
, delta_bytes
);
10883 /* Adjust Y positions. */
10885 shift_glyph_matrix (w
, current_matrix
,
10886 first_unchanged_at_end_vpos
+ dvpos
,
10889 if (first_unchanged_at_end_row
)
10890 first_unchanged_at_end_row
+= dvpos
;
10892 /* If scrolling up, there may be some lines to display at the end of
10894 last_text_row_at_end
= NULL
;
10897 /* Set last_row to the glyph row in the current matrix where the
10898 window end line is found. It has been moved up or down in
10899 the matrix by dvpos. */
10900 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
10901 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
10903 /* If last_row is the window end line, it should display text. */
10904 xassert (last_row
->displays_text_p
);
10906 /* If window end line was partially visible before, begin
10907 displaying at that line. Otherwise begin displaying with the
10908 line following it. */
10909 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
10911 init_to_row_start (&it
, w
, last_row
);
10912 it
.vpos
= last_vpos
;
10913 it
.current_y
= last_row
->y
;
10917 init_to_row_end (&it
, w
, last_row
);
10918 it
.vpos
= 1 + last_vpos
;
10919 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
10923 /* We may start in a continuation line. If so, we have to get
10924 the right continuation_lines_width and current_x. */
10925 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
10926 it
.hpos
= it
.current_x
= 0;
10928 /* Display the rest of the lines at the window end. */
10929 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10930 while (it
.current_y
< it
.last_visible_y
10931 && !fonts_changed_p
)
10933 /* Is it always sure that the display agrees with lines in
10934 the current matrix? I don't think so, so we mark rows
10935 displayed invalid in the current matrix by setting their
10936 enabled_p flag to zero. */
10937 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
10938 if (display_line (&it
))
10939 last_text_row_at_end
= it
.glyph_row
- 1;
10943 /* Update window_end_pos and window_end_vpos. */
10944 if (first_unchanged_at_end_row
10945 && first_unchanged_at_end_row
->y
< it
.last_visible_y
10946 && !last_text_row_at_end
)
10948 /* Window end line if one of the preserved rows from the current
10949 matrix. Set row to the last row displaying text in current
10950 matrix starting at first_unchanged_at_end_row, after
10952 xassert (first_unchanged_at_end_row
->displays_text_p
);
10953 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
10954 first_unchanged_at_end_row
);
10955 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
10957 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
10958 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10959 XSETFASTINT (w
->window_end_vpos
,
10960 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
10962 else if (last_text_row_at_end
)
10964 XSETFASTINT (w
->window_end_pos
,
10965 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
10966 w
->window_end_bytepos
10967 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
10968 XSETFASTINT (w
->window_end_vpos
,
10969 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
10971 else if (last_text_row
)
10973 /* We have displayed either to the end of the window or at the
10974 end of the window, i.e. the last row with text is to be found
10975 in the desired matrix. */
10976 XSETFASTINT (w
->window_end_pos
,
10977 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10978 w
->window_end_bytepos
10979 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10980 XSETFASTINT (w
->window_end_vpos
,
10981 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
10983 else if (first_unchanged_at_end_row
== NULL
10984 && last_text_row
== NULL
10985 && last_text_row_at_end
== NULL
)
10987 /* Displayed to end of window, but no line containing text was
10988 displayed. Lines were deleted at the end of the window. */
10990 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
10992 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
10993 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10994 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
10995 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10996 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
10999 w
->window_end_vpos
= make_number (vpos
);
11004 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11005 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11007 /* Record that display has not been completed. */
11008 w
->window_end_valid
= Qnil
;
11009 w
->desired_matrix
->no_scrolling_p
= 1;
11015 /***********************************************************************
11016 More debugging support
11017 ***********************************************************************/
11021 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
11022 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11025 /* Dump the contents of glyph matrix MATRIX on stderr. If
11026 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
11029 dump_glyph_matrix (matrix
, with_glyphs_p
)
11030 struct glyph_matrix
*matrix
;
11034 for (i
= 0; i
< matrix
->nrows
; ++i
)
11035 dump_glyph_row (matrix
, i
, with_glyphs_p
);
11039 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
11040 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
11043 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
11044 struct glyph_matrix
*matrix
;
11045 int vpos
, with_glyphs_p
;
11047 struct glyph_row
*row
;
11049 if (vpos
< 0 || vpos
>= matrix
->nrows
)
11052 row
= MATRIX_ROW (matrix
, vpos
);
11054 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFes X Y W H V A P\n");
11055 fprintf (stderr
, "=======================================================================\n");
11057 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d\
11058 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
11059 row
- matrix
->rows
,
11060 MATRIX_ROW_START_CHARPOS (row
),
11061 MATRIX_ROW_END_CHARPOS (row
),
11062 row
->used
[TEXT_AREA
],
11063 row
->contains_overlapping_glyphs_p
,
11066 row
->truncated_on_left_p
,
11067 row
->truncated_on_right_p
,
11068 row
->overlay_arrow_p
,
11070 MATRIX_ROW_CONTINUATION_LINE_P (row
),
11071 row
->displays_text_p
,
11074 row
->ends_in_middle_of_char_p
,
11075 row
->starts_in_middle_of_char_p
,
11080 row
->visible_height
,
11083 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
11084 row
->end
.overlay_string_index
);
11085 fprintf (stderr
, "%9d %5d\n",
11086 CHARPOS (row
->start
.string_pos
),
11087 CHARPOS (row
->end
.string_pos
));
11088 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
11089 row
->end
.dpvec_index
);
11093 struct glyph
*glyph
, *glyph_end
;
11094 int prev_had_glyphs_p
;
11096 glyph
= row
->glyphs
[TEXT_AREA
];
11097 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
11099 /* Glyph for a line end in text. */
11100 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
11103 if (glyph
< glyph_end
)
11105 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
11106 prev_had_glyphs_p
= 1;
11109 prev_had_glyphs_p
= 0;
11111 while (glyph
< glyph_end
)
11113 if (glyph
->type
== CHAR_GLYPH
)
11116 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11117 glyph
- row
->glyphs
[TEXT_AREA
],
11120 (BUFFERP (glyph
->object
)
11122 : (STRINGP (glyph
->object
)
11125 glyph
->pixel_width
,
11127 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
11131 glyph
->left_box_line_p
,
11132 glyph
->right_box_line_p
);
11134 else if (glyph
->type
== STRETCH_GLYPH
)
11137 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11138 glyph
- row
->glyphs
[TEXT_AREA
],
11141 (BUFFERP (glyph
->object
)
11143 : (STRINGP (glyph
->object
)
11146 glyph
->pixel_width
,
11150 glyph
->left_box_line_p
,
11151 glyph
->right_box_line_p
);
11153 else if (glyph
->type
== IMAGE_GLYPH
)
11156 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11157 glyph
- row
->glyphs
[TEXT_AREA
],
11160 (BUFFERP (glyph
->object
)
11162 : (STRINGP (glyph
->object
)
11165 glyph
->pixel_width
,
11169 glyph
->left_box_line_p
,
11170 glyph
->right_box_line_p
);
11178 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
11179 Sdump_glyph_matrix
, 0, 1, "p",
11180 "Dump the current matrix of the selected window to stderr.\n\
11181 Shows contents of glyph row structures. With non-nil optional\n\
11182 parameter WITH-GLYPHS-P, dump glyphs as well.")
11184 Lisp_Object with_glyphs_p
;
11186 struct window
*w
= XWINDOW (selected_window
);
11187 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11189 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
11190 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
11191 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
11192 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
11193 fprintf (stderr
, "=============================================\n");
11194 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
11199 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
11200 "Dump glyph row ROW to stderr.")
11204 CHECK_NUMBER (row
, 0);
11205 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
11210 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
,
11214 struct frame
*sf
= SELECTED_FRAME ();
11215 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)
11217 dump_glyph_row (m
, 0, 1);
11222 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
11223 Strace_redisplay_toggle
, 0, 0, "",
11224 "Toggle tracing of redisplay.")
11227 trace_redisplay_p
= !trace_redisplay_p
;
11232 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
11233 "Print STRING to stderr.")
11235 Lisp_Object string
;
11237 CHECK_STRING (string
, 0);
11238 fprintf (stderr
, "%s", XSTRING (string
)->data
);
11242 #endif /* GLYPH_DEBUG */
11246 /***********************************************************************
11247 Building Desired Matrix Rows
11248 ***********************************************************************/
11250 /* Return a temporary glyph row holding the glyphs of an overlay
11251 arrow. Only used for non-window-redisplay windows. */
11253 static struct glyph_row
*
11254 get_overlay_arrow_glyph_row (w
)
11257 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11258 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11259 struct buffer
*old
= current_buffer
;
11260 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
11261 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
11262 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
11266 int n_glyphs_before
;
11268 set_buffer_temp (buffer
);
11269 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
11270 it
.glyph_row
->used
[TEXT_AREA
] = 0;
11271 SET_TEXT_POS (it
.position
, 0, 0);
11273 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
11275 while (p
< arrow_end
)
11277 Lisp_Object face
, ilisp
;
11279 /* Get the next character. */
11281 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
11283 it
.c
= *p
, it
.len
= 1;
11286 /* Get its face. */
11287 XSETFASTINT (ilisp
, p
- arrow_string
);
11288 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
11289 it
.face_id
= compute_char_face (f
, it
.c
, face
);
11291 /* Compute its width, get its glyphs. */
11292 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
11293 SET_TEXT_POS (it
.position
, -1, -1);
11294 PRODUCE_GLYPHS (&it
);
11296 /* If this character doesn't fit any more in the line, we have
11297 to remove some glyphs. */
11298 if (it
.current_x
> it
.last_visible_x
)
11300 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
11305 set_buffer_temp (old
);
11306 return it
.glyph_row
;
11310 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
11311 glyphs are only inserted for terminal frames since we can't really
11312 win with truncation glyphs when partially visible glyphs are
11313 involved. Which glyphs to insert is determined by
11314 produce_special_glyphs. */
11317 insert_left_trunc_glyphs (it
)
11320 struct it truncate_it
;
11321 struct glyph
*from
, *end
, *to
, *toend
;
11323 xassert (!FRAME_WINDOW_P (it
->f
));
11325 /* Get the truncation glyphs. */
11327 truncate_it
.current_x
= 0;
11328 truncate_it
.face_id
= DEFAULT_FACE_ID
;
11329 truncate_it
.glyph_row
= &scratch_glyph_row
;
11330 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
11331 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
11332 truncate_it
.object
= make_number (0);
11333 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
11335 /* Overwrite glyphs from IT with truncation glyphs. */
11336 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
11337 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
11338 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
11339 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
11344 /* There may be padding glyphs left over. Remove them. */
11346 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
11348 while (from
< toend
)
11351 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
11355 /* Compute the pixel height and width of IT->glyph_row.
11357 Most of the time, ascent and height of a display line will be equal
11358 to the max_ascent and max_height values of the display iterator
11359 structure. This is not the case if
11361 1. We hit ZV without displaying anything. In this case, max_ascent
11362 and max_height will be zero.
11364 2. We have some glyphs that don't contribute to the line height.
11365 (The glyph row flag contributes_to_line_height_p is for future
11366 pixmap extensions).
11368 The first case is easily covered by using default values because in
11369 these cases, the line height does not really matter, except that it
11370 must not be zero. */
11373 compute_line_metrics (it
)
11376 struct glyph_row
*row
= it
->glyph_row
;
11379 if (FRAME_WINDOW_P (it
->f
))
11381 int i
, header_line_height
;
11383 /* The line may consist of one space only, that was added to
11384 place the cursor on it. If so, the row's height hasn't been
11386 if (row
->height
== 0)
11388 if (it
->max_ascent
+ it
->max_descent
== 0)
11389 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
11390 row
->ascent
= it
->max_ascent
;
11391 row
->height
= it
->max_ascent
+ it
->max_descent
;
11392 row
->phys_ascent
= it
->max_phys_ascent
;
11393 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11396 /* Compute the width of this line. */
11397 row
->pixel_width
= row
->x
;
11398 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
11399 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11401 xassert (row
->pixel_width
>= 0);
11402 xassert (row
->ascent
>= 0 && row
->height
> 0);
11404 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
11405 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
11407 /* If first line's physical ascent is larger than its logical
11408 ascent, use the physical ascent, and make the row taller.
11409 This makes accented characters fully visible. */
11410 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
11411 && row
->phys_ascent
> row
->ascent
)
11413 row
->height
+= row
->phys_ascent
- row
->ascent
;
11414 row
->ascent
= row
->phys_ascent
;
11417 /* Compute how much of the line is visible. */
11418 row
->visible_height
= row
->height
;
11420 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
11421 if (row
->y
< header_line_height
)
11422 row
->visible_height
-= header_line_height
- row
->y
;
11425 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
11426 if (row
->y
+ row
->height
> max_y
)
11427 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11432 row
->pixel_width
= row
->used
[TEXT_AREA
];
11433 row
->ascent
= row
->phys_ascent
= 0;
11434 row
->height
= row
->phys_height
= row
->visible_height
= 1;
11437 /* Compute a hash code for this row. */
11439 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11440 for (i
= 0; i
< row
->used
[area
]; ++i
)
11441 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
11442 + row
->glyphs
[area
][i
].u
.val
11443 + row
->glyphs
[area
][i
].face_id
11444 + row
->glyphs
[area
][i
].padding_p
11445 + (row
->glyphs
[area
][i
].type
<< 2));
11447 it
->max_ascent
= it
->max_descent
= 0;
11448 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
11452 /* Append one space to the glyph row of iterator IT if doing a
11453 window-based redisplay. DEFAULT_FACE_P non-zero means let the
11454 space have the default face, otherwise let it have the same face as
11455 IT->face_id. Value is non-zero if a space was added.
11457 This function is called to make sure that there is always one glyph
11458 at the end of a glyph row that the cursor can be set on under
11459 window-systems. (If there weren't such a glyph we would not know
11460 how wide and tall a box cursor should be displayed).
11462 At the same time this space let's a nicely handle clearing to the
11463 end of the line if the row ends in italic text. */
11466 append_space (it
, default_face_p
)
11468 int default_face_p
;
11470 if (FRAME_WINDOW_P (it
->f
))
11472 int n
= it
->glyph_row
->used
[TEXT_AREA
];
11474 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
11475 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
11477 /* Save some values that must not be changed.
11478 Must save IT->c and IT->len because otherwise
11479 ITERATOR_AT_END_P wouldn't work anymore after
11480 append_space has been called. */
11481 int saved_what
= it
->what
;
11482 int saved_c
= it
->c
, saved_len
= it
->len
;
11483 int saved_x
= it
->current_x
;
11484 int saved_face_id
= it
->face_id
;
11485 struct text_pos saved_pos
;
11486 Lisp_Object saved_object
;
11489 saved_object
= it
->object
;
11490 saved_pos
= it
->position
;
11492 it
->what
= IT_CHARACTER
;
11493 bzero (&it
->position
, sizeof it
->position
);
11494 it
->object
= make_number (0);
11498 if (default_face_p
)
11499 it
->face_id
= DEFAULT_FACE_ID
;
11500 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11501 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
11503 PRODUCE_GLYPHS (it
);
11505 it
->current_x
= saved_x
;
11506 it
->object
= saved_object
;
11507 it
->position
= saved_pos
;
11508 it
->what
= saved_what
;
11509 it
->face_id
= saved_face_id
;
11510 it
->len
= saved_len
;
11520 /* Extend the face of the last glyph in the text area of IT->glyph_row
11521 to the end of the display line. Called from display_line.
11522 If the glyph row is empty, add a space glyph to it so that we
11523 know the face to draw. Set the glyph row flag fill_line_p. */
11526 extend_face_to_end_of_line (it
)
11530 struct frame
*f
= it
->f
;
11532 /* If line is already filled, do nothing. */
11533 if (it
->current_x
>= it
->last_visible_x
)
11536 /* Face extension extends the background and box of IT->face_id
11537 to the end of the line. If the background equals the background
11538 of the frame, we haven't to do anything. */
11539 face
= FACE_FROM_ID (f
, it
->face_id
);
11540 if (FRAME_WINDOW_P (f
)
11541 && face
->box
== FACE_NO_BOX
11542 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
11546 /* Set the glyph row flag indicating that the face of the last glyph
11547 in the text area has to be drawn to the end of the text area. */
11548 it
->glyph_row
->fill_line_p
= 1;
11550 /* If current character of IT is not ASCII, make sure we have the
11551 ASCII face. This will be automatically undone the next time
11552 get_next_display_element returns a multibyte character. Note
11553 that the character will always be single byte in unibyte text. */
11554 if (!SINGLE_BYTE_CHAR_P (it
->c
))
11556 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
11559 if (FRAME_WINDOW_P (f
))
11561 /* If the row is empty, add a space with the current face of IT,
11562 so that we know which face to draw. */
11563 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
11565 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
11566 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
11567 it
->glyph_row
->used
[TEXT_AREA
] = 1;
11572 /* Save some values that must not be changed. */
11573 int saved_x
= it
->current_x
;
11574 struct text_pos saved_pos
;
11575 Lisp_Object saved_object
;
11576 int saved_what
= it
->what
;
11578 saved_object
= it
->object
;
11579 saved_pos
= it
->position
;
11581 it
->what
= IT_CHARACTER
;
11582 bzero (&it
->position
, sizeof it
->position
);
11583 it
->object
= make_number (0);
11587 PRODUCE_GLYPHS (it
);
11589 while (it
->current_x
<= it
->last_visible_x
)
11590 PRODUCE_GLYPHS (it
);
11592 /* Don't count these blanks really. It would let us insert a left
11593 truncation glyph below and make us set the cursor on them, maybe. */
11594 it
->current_x
= saved_x
;
11595 it
->object
= saved_object
;
11596 it
->position
= saved_pos
;
11597 it
->what
= saved_what
;
11602 /* Value is non-zero if text starting at CHARPOS in current_buffer is
11603 trailing whitespace. */
11606 trailing_whitespace_p (charpos
)
11609 int bytepos
= CHAR_TO_BYTE (charpos
);
11612 while (bytepos
< ZV_BYTE
11613 && (c
= FETCH_CHAR (bytepos
),
11614 c
== ' ' || c
== '\t'))
11617 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
11619 if (bytepos
!= PT_BYTE
)
11626 /* Highlight trailing whitespace, if any, in ROW. */
11629 highlight_trailing_whitespace (f
, row
)
11631 struct glyph_row
*row
;
11633 int used
= row
->used
[TEXT_AREA
];
11637 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
11638 struct glyph
*glyph
= start
+ used
- 1;
11640 /* Skip over the space glyph inserted to display the
11641 cursor at the end of a line. */
11642 if (glyph
->type
== CHAR_GLYPH
11643 && glyph
->u
.ch
== ' '
11644 && INTEGERP (glyph
->object
))
11647 /* If last glyph is a space or stretch, and it's trailing
11648 whitespace, set the face of all trailing whitespace glyphs in
11649 IT->glyph_row to `trailing-whitespace'. */
11651 && BUFFERP (glyph
->object
)
11652 && (glyph
->type
== STRETCH_GLYPH
11653 || (glyph
->type
== CHAR_GLYPH
11654 && glyph
->u
.ch
== ' '))
11655 && trailing_whitespace_p (glyph
->charpos
))
11657 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
11659 while (glyph
>= start
11660 && BUFFERP (glyph
->object
)
11661 && (glyph
->type
== STRETCH_GLYPH
11662 || (glyph
->type
== CHAR_GLYPH
11663 && glyph
->u
.ch
== ' ')))
11664 (glyph
--)->face_id
= face_id
;
11670 /* Value is non-zero if glyph row ROW in window W should be
11671 used to put the cursor on. */
11674 cursor_row_p (w
, row
)
11676 struct glyph_row
*row
;
11678 int cursor_row_p
= 1;
11680 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
11682 /* If the row ends with a newline from a string, we don't want
11683 the cursor there (if the row is continued it doesn't end in a
11685 if (CHARPOS (row
->end
.string_pos
) >= 0
11686 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11687 cursor_row_p
= row
->continued_p
;
11689 /* If the row ends at ZV, display the cursor at the end of that
11690 row instead of at the start of the row below. */
11691 else if (row
->ends_at_zv_p
)
11697 return cursor_row_p
;
11701 /* Construct the glyph row IT->glyph_row in the desired matrix of
11702 IT->w from text at the current position of IT. See dispextern.h
11703 for an overview of struct it. Value is non-zero if
11704 IT->glyph_row displays text, as opposed to a line displaying ZV
11711 struct glyph_row
*row
= it
->glyph_row
;
11713 /* We always start displaying at hpos zero even if hscrolled. */
11714 xassert (it
->hpos
== 0 && it
->current_x
== 0);
11716 /* We must not display in a row that's not a text row. */
11717 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
11718 < it
->w
->desired_matrix
->nrows
);
11720 /* Is IT->w showing the region? */
11721 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
11723 /* Clear the result glyph row and enable it. */
11724 prepare_desired_row (row
);
11726 row
->y
= it
->current_y
;
11727 row
->start
= it
->current
;
11728 row
->continuation_lines_width
= it
->continuation_lines_width
;
11729 row
->displays_text_p
= 1;
11730 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
11731 it
->starts_in_middle_of_char_p
= 0;
11733 /* Arrange the overlays nicely for our purposes. Usually, we call
11734 display_line on only one line at a time, in which case this
11735 can't really hurt too much, or we call it on lines which appear
11736 one after another in the buffer, in which case all calls to
11737 recenter_overlay_lists but the first will be pretty cheap. */
11738 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
11740 /* Move over display elements that are not visible because we are
11741 hscrolled. This may stop at an x-position < IT->first_visible_x
11742 if the first glyph is partially visible or if we hit a line end. */
11743 if (it
->current_x
< it
->first_visible_x
)
11744 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
11745 MOVE_TO_POS
| MOVE_TO_X
);
11747 /* Get the initial row height. This is either the height of the
11748 text hscrolled, if there is any, or zero. */
11749 row
->ascent
= it
->max_ascent
;
11750 row
->height
= it
->max_ascent
+ it
->max_descent
;
11751 row
->phys_ascent
= it
->max_phys_ascent
;
11752 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11754 /* Loop generating characters. The loop is left with IT on the next
11755 character to display. */
11758 int n_glyphs_before
, hpos_before
, x_before
;
11760 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
11762 /* Retrieve the next thing to display. Value is zero if end of
11764 if (!get_next_display_element (it
))
11766 /* Maybe add a space at the end of this line that is used to
11767 display the cursor there under X. Set the charpos of the
11768 first glyph of blank lines not corresponding to any text
11770 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
11771 || row
->used
[TEXT_AREA
] == 0)
11773 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
11774 row
->displays_text_p
= 0;
11776 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
11777 row
->indicate_empty_line_p
= 1;
11780 it
->continuation_lines_width
= 0;
11781 row
->ends_at_zv_p
= 1;
11785 /* Now, get the metrics of what we want to display. This also
11786 generates glyphs in `row' (which is IT->glyph_row). */
11787 n_glyphs_before
= row
->used
[TEXT_AREA
];
11790 /* Remember the line height so far in case the next element doesn't
11791 fit on the line. */
11792 if (!it
->truncate_lines_p
)
11794 ascent
= it
->max_ascent
;
11795 descent
= it
->max_descent
;
11796 phys_ascent
= it
->max_phys_ascent
;
11797 phys_descent
= it
->max_phys_descent
;
11800 PRODUCE_GLYPHS (it
);
11802 /* If this display element was in marginal areas, continue with
11804 if (it
->area
!= TEXT_AREA
)
11806 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11807 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11808 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11809 row
->phys_height
= max (row
->phys_height
,
11810 it
->max_phys_ascent
+ it
->max_phys_descent
);
11811 set_iterator_to_next (it
, 1);
11815 /* Does the display element fit on the line? If we truncate
11816 lines, we should draw past the right edge of the window. If
11817 we don't truncate, we want to stop so that we can display the
11818 continuation glyph before the right margin. If lines are
11819 continued, there are two possible strategies for characters
11820 resulting in more than 1 glyph (e.g. tabs): Display as many
11821 glyphs as possible in this line and leave the rest for the
11822 continuation line, or display the whole element in the next
11823 line. Original redisplay did the former, so we do it also. */
11824 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11825 hpos_before
= it
->hpos
;
11829 && it
->current_x
< it
->last_visible_x
)
11832 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11833 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11834 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11835 row
->phys_height
= max (row
->phys_height
,
11836 it
->max_phys_ascent
+ it
->max_phys_descent
);
11837 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
11838 row
->x
= x
- it
->first_visible_x
;
11843 struct glyph
*glyph
;
11845 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
11847 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11848 new_x
= x
+ glyph
->pixel_width
;
11850 if (/* Lines are continued. */
11851 !it
->truncate_lines_p
11852 && (/* Glyph doesn't fit on the line. */
11853 new_x
> it
->last_visible_x
11854 /* Or it fits exactly on a window system frame. */
11855 || (new_x
== it
->last_visible_x
11856 && FRAME_WINDOW_P (it
->f
))))
11858 /* End of a continued line. */
11861 || (new_x
== it
->last_visible_x
11862 && FRAME_WINDOW_P (it
->f
)))
11864 /* Current glyph is the only one on the line or
11865 fits exactly on the line. We must continue
11866 the line because we can't draw the cursor
11867 after the glyph. */
11868 row
->continued_p
= 1;
11869 it
->current_x
= new_x
;
11870 it
->continuation_lines_width
+= new_x
;
11872 if (i
== nglyphs
- 1)
11873 set_iterator_to_next (it
, 1);
11875 else if (CHAR_GLYPH_PADDING_P (*glyph
)
11876 && !FRAME_WINDOW_P (it
->f
))
11878 /* A padding glyph that doesn't fit on this line.
11879 This means the whole character doesn't fit
11881 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11883 /* Fill the rest of the row with continuation
11884 glyphs like in 20.x. */
11885 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
11886 < row
->glyphs
[1 + TEXT_AREA
])
11887 produce_special_glyphs (it
, IT_CONTINUATION
);
11889 row
->continued_p
= 1;
11890 it
->current_x
= x_before
;
11891 it
->continuation_lines_width
+= x_before
;
11893 /* Restore the height to what it was before the
11894 element not fitting on the line. */
11895 it
->max_ascent
= ascent
;
11896 it
->max_descent
= descent
;
11897 it
->max_phys_ascent
= phys_ascent
;
11898 it
->max_phys_descent
= phys_descent
;
11902 /* Display element draws past the right edge of
11903 the window. Restore positions to values
11904 before the element. The next line starts
11905 with current_x before the glyph that could
11906 not be displayed, so that TAB works right. */
11907 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11909 /* Display continuation glyphs. */
11910 if (!FRAME_WINDOW_P (it
->f
))
11911 produce_special_glyphs (it
, IT_CONTINUATION
);
11912 row
->continued_p
= 1;
11915 it
->continuation_lines_width
+= x
;
11916 if (nglyphs
> 1 && i
> 0)
11918 row
->ends_in_middle_of_char_p
= 1;
11919 it
->starts_in_middle_of_char_p
= 1;
11922 /* Restore the height to what it was before the
11923 element not fitting on the line. */
11924 it
->max_ascent
= ascent
;
11925 it
->max_descent
= descent
;
11926 it
->max_phys_ascent
= phys_ascent
;
11927 it
->max_phys_descent
= phys_descent
;
11932 else if (new_x
> it
->first_visible_x
)
11934 /* Increment number of glyphs actually displayed. */
11937 if (x
< it
->first_visible_x
)
11938 /* Glyph is partially visible, i.e. row starts at
11939 negative X position. */
11940 row
->x
= x
- it
->first_visible_x
;
11944 /* Glyph is completely off the left margin of the
11945 window. This should not happen because of the
11946 move_it_in_display_line at the start of
11952 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11953 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11954 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11955 row
->phys_height
= max (row
->phys_height
,
11956 it
->max_phys_ascent
+ it
->max_phys_descent
);
11958 /* End of this display line if row is continued. */
11959 if (row
->continued_p
)
11963 /* Is this a line end? If yes, we're also done, after making
11964 sure that a non-default face is extended up to the right
11965 margin of the window. */
11966 if (ITERATOR_AT_END_OF_LINE_P (it
))
11968 int used_before
= row
->used
[TEXT_AREA
];
11970 /* Add a space at the end of the line that is used to
11971 display the cursor there. */
11972 append_space (it
, 0);
11974 /* Extend the face to the end of the line. */
11975 extend_face_to_end_of_line (it
);
11977 /* Make sure we have the position. */
11978 if (used_before
== 0)
11979 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
11981 /* Consume the line end. This skips over invisible lines. */
11982 set_iterator_to_next (it
, 1);
11983 it
->continuation_lines_width
= 0;
11987 /* Proceed with next display element. Note that this skips
11988 over lines invisible because of selective display. */
11989 set_iterator_to_next (it
, 1);
11991 /* If we truncate lines, we are done when the last displayed
11992 glyphs reach past the right margin of the window. */
11993 if (it
->truncate_lines_p
11994 && (FRAME_WINDOW_P (it
->f
)
11995 ? (it
->current_x
>= it
->last_visible_x
)
11996 : (it
->current_x
> it
->last_visible_x
)))
11998 /* Maybe add truncation glyphs. */
11999 if (!FRAME_WINDOW_P (it
->f
))
12001 --it
->glyph_row
->used
[TEXT_AREA
];
12002 produce_special_glyphs (it
, IT_TRUNCATION
);
12005 row
->truncated_on_right_p
= 1;
12006 it
->continuation_lines_width
= 0;
12007 reseat_at_next_visible_line_start (it
, 0);
12008 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
12009 it
->hpos
= hpos_before
;
12010 it
->current_x
= x_before
;
12015 /* If line is not empty and hscrolled, maybe insert truncation glyphs
12016 at the left window margin. */
12017 if (it
->first_visible_x
12018 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
12020 if (!FRAME_WINDOW_P (it
->f
))
12021 insert_left_trunc_glyphs (it
);
12022 row
->truncated_on_left_p
= 1;
12025 /* If the start of this line is the overlay arrow-position, then
12026 mark this glyph row as the one containing the overlay arrow.
12027 This is clearly a mess with variable size fonts. It would be
12028 better to let it be displayed like cursors under X. */
12029 if (MARKERP (Voverlay_arrow_position
)
12030 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
12031 && (MATRIX_ROW_START_CHARPOS (row
)
12032 == marker_position (Voverlay_arrow_position
))
12033 && STRINGP (Voverlay_arrow_string
)
12034 && ! overlay_arrow_seen
)
12036 /* Overlay arrow in window redisplay is a bitmap. */
12037 if (!FRAME_WINDOW_P (it
->f
))
12039 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
12040 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
12041 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
12042 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
12043 struct glyph
*p2
, *end
;
12045 /* Copy the arrow glyphs. */
12046 while (glyph
< arrow_end
)
12049 /* Throw away padding glyphs. */
12051 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
12052 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
12058 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
12062 overlay_arrow_seen
= 1;
12063 row
->overlay_arrow_p
= 1;
12066 /* Compute pixel dimensions of this line. */
12067 compute_line_metrics (it
);
12069 /* Remember the position at which this line ends. */
12070 row
->end
= it
->current
;
12072 /* Maybe set the cursor. */
12073 if (it
->w
->cursor
.vpos
< 0
12074 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
12075 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
12076 && cursor_row_p (it
->w
, row
))
12077 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
12079 /* Highlight trailing whitespace. */
12080 if (!NILP (Vshow_trailing_whitespace
))
12081 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
12083 /* Prepare for the next line. This line starts horizontally at (X
12084 HPOS) = (0 0). Vertical positions are incremented. As a
12085 convenience for the caller, IT->glyph_row is set to the next
12087 it
->current_x
= it
->hpos
= 0;
12088 it
->current_y
+= row
->height
;
12091 return row
->displays_text_p
;
12096 /***********************************************************************
12098 ***********************************************************************/
12100 /* Redisplay the menu bar in the frame for window W.
12102 The menu bar of X frames that don't have X toolkit support is
12103 displayed in a special window W->frame->menu_bar_window.
12105 The menu bar of terminal frames is treated specially as far as
12106 glyph matrices are concerned. Menu bar lines are not part of
12107 windows, so the update is done directly on the frame matrix rows
12108 for the menu bar. */
12111 display_menu_bar (w
)
12114 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12119 /* Don't do all this for graphical frames. */
12121 if (!NILP (Vwindow_system
))
12124 #ifdef USE_X_TOOLKIT
12129 if (FRAME_MAC_P (f
))
12133 #ifdef USE_X_TOOLKIT
12134 xassert (!FRAME_WINDOW_P (f
));
12135 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
12136 it
.first_visible_x
= 0;
12137 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12138 #else /* not USE_X_TOOLKIT */
12139 if (FRAME_WINDOW_P (f
))
12141 /* Menu bar lines are displayed in the desired matrix of the
12142 dummy window menu_bar_window. */
12143 struct window
*menu_w
;
12144 xassert (WINDOWP (f
->menu_bar_window
));
12145 menu_w
= XWINDOW (f
->menu_bar_window
);
12146 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
12148 it
.first_visible_x
= 0;
12149 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12153 /* This is a TTY frame, i.e. character hpos/vpos are used as
12155 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
12157 it
.first_visible_x
= 0;
12158 it
.last_visible_x
= FRAME_WIDTH (f
);
12160 #endif /* not USE_X_TOOLKIT */
12162 /* Clear all rows of the menu bar. */
12163 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
12165 struct glyph_row
*row
= it
.glyph_row
+ i
;
12166 clear_glyph_row (row
);
12167 row
->enabled_p
= 1;
12168 row
->full_width_p
= 1;
12171 /* Make the first line of the menu bar appear in reverse video. */
12172 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
12174 /* Display all items of the menu bar. */
12175 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
12176 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
12178 Lisp_Object string
;
12180 /* Stop at nil string. */
12181 string
= XVECTOR (items
)->contents
[i
+ 1];
12185 /* Remember where item was displayed. */
12186 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
12188 /* Display the item, pad with one space. */
12189 if (it
.current_x
< it
.last_visible_x
)
12190 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
12191 XSTRING (string
)->size
+ 1, 0, 0, -1);
12194 /* Fill out the line with spaces. */
12195 if (it
.current_x
< it
.last_visible_x
)
12196 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
12198 /* Compute the total height of the lines. */
12199 compute_line_metrics (&it
);
12204 /***********************************************************************
12206 ***********************************************************************/
12208 /* Redisplay mode lines in the window tree whose root is WINDOW. If
12209 FORCE is non-zero, redisplay mode lines unconditionally.
12210 Otherwise, redisplay only mode lines that are garbaged. Value is
12211 the number of windows whose mode lines were redisplayed. */
12214 redisplay_mode_lines (window
, force
)
12215 Lisp_Object window
;
12220 while (!NILP (window
))
12222 struct window
*w
= XWINDOW (window
);
12224 if (WINDOWP (w
->hchild
))
12225 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
12226 else if (WINDOWP (w
->vchild
))
12227 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
12229 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
12230 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
12232 Lisp_Object old_selected_frame
;
12233 struct text_pos lpoint
;
12234 struct buffer
*old
= current_buffer
;
12236 /* Set the window's buffer for the mode line display. */
12237 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12238 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12240 /* Point refers normally to the selected window. For any
12241 other window, set up appropriate value. */
12242 if (!EQ (window
, selected_window
))
12244 struct text_pos pt
;
12246 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
12247 if (CHARPOS (pt
) < BEGV
)
12248 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
12249 else if (CHARPOS (pt
) > (ZV
- 1))
12250 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
12252 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
12255 /* Temporarily set up the selected frame. */
12256 old_selected_frame
= selected_frame
;
12257 selected_frame
= w
->frame
;
12259 /* Display mode lines. */
12260 clear_glyph_matrix (w
->desired_matrix
);
12261 if (display_mode_lines (w
))
12264 w
->must_be_updated_p
= 1;
12267 /* Restore old settings. */
12268 selected_frame
= old_selected_frame
;
12269 set_buffer_internal_1 (old
);
12270 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12280 /* Display the mode and/or top line of window W. Value is the number
12281 of mode lines displayed. */
12284 display_mode_lines (w
)
12289 /* These will be set while the mode line specs are processed. */
12290 line_number_displayed
= 0;
12291 w
->column_number_displayed
= Qnil
;
12293 if (WINDOW_WANTS_MODELINE_P (w
))
12295 display_mode_line (w
, MODE_LINE_FACE_ID
,
12296 current_buffer
->mode_line_format
);
12300 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12302 display_mode_line (w
, HEADER_LINE_FACE_ID
,
12303 current_buffer
->header_line_format
);
12311 /* Display mode or top line of window W. FACE_ID specifies which line
12312 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
12313 FORMAT is the mode line format to display. */
12316 display_mode_line (w
, face_id
, format
)
12318 enum face_id face_id
;
12319 Lisp_Object format
;
12324 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
12325 prepare_desired_row (it
.glyph_row
);
12327 /* Temporarily make frame's keyboard the current kboard so that
12328 kboard-local variables in the mode_line_format will get the right
12330 push_frame_kboard (it
.f
);
12331 display_mode_element (&it
, 0, 0, 0, format
);
12332 pop_frame_kboard ();
12334 /* Fill up with spaces. */
12335 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
12337 compute_line_metrics (&it
);
12338 it
.glyph_row
->full_width_p
= 1;
12339 it
.glyph_row
->mode_line_p
= 1;
12340 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
12341 it
.glyph_row
->continued_p
= 0;
12342 it
.glyph_row
->truncated_on_left_p
= 0;
12343 it
.glyph_row
->truncated_on_right_p
= 0;
12345 /* Make a 3D mode-line have a shadow at its right end. */
12346 face
= FACE_FROM_ID (it
.f
, face_id
);
12347 extend_face_to_end_of_line (&it
);
12348 if (face
->box
!= FACE_NO_BOX
)
12350 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
12351 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
12352 last
->right_box_line_p
= 1;
12357 /* Contribute ELT to the mode line for window IT->w. How it
12358 translates into text depends on its data type.
12360 IT describes the display environment in which we display, as usual.
12362 DEPTH is the depth in recursion. It is used to prevent
12363 infinite recursion here.
12365 FIELD_WIDTH is the number of characters the display of ELT should
12366 occupy in the mode line, and PRECISION is the maximum number of
12367 characters to display from ELT's representation. See
12368 display_string for details. *
12370 Returns the hpos of the end of the text generated by ELT. */
12373 display_mode_element (it
, depth
, field_width
, precision
, elt
)
12376 int field_width
, precision
;
12379 int n
= 0, field
, prec
;
12387 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
12391 /* A string: output it and check for %-constructs within it. */
12393 unsigned char *this = XSTRING (elt
)->data
;
12394 unsigned char *lisp_string
= this;
12396 while ((precision
<= 0 || n
< precision
)
12398 && (frame_title_ptr
12399 || it
->current_x
< it
->last_visible_x
))
12401 unsigned char *last
= this;
12403 /* Advance to end of string or next format specifier. */
12404 while ((c
= *this++) != '\0' && c
!= '%')
12407 if (this - 1 != last
)
12409 /* Output to end of string or up to '%'. Field width
12410 is length of string. Don't output more than
12411 PRECISION allows us. */
12412 prec
= --this - last
;
12413 if (precision
> 0 && prec
> precision
- n
)
12414 prec
= precision
- n
;
12416 if (frame_title_ptr
)
12417 n
+= store_frame_title (last
, prec
, prec
);
12419 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
12420 it
, 0, prec
, 0, -1);
12422 else /* c == '%' */
12424 unsigned char *percent_position
= this;
12426 /* Get the specified minimum width. Zero means
12429 while ((c
= *this++) >= '0' && c
<= '9')
12430 field
= field
* 10 + c
- '0';
12432 /* Don't pad beyond the total padding allowed. */
12433 if (field_width
- n
> 0 && field
> field_width
- n
)
12434 field
= field_width
- n
;
12436 /* Note that either PRECISION <= 0 or N < PRECISION. */
12437 prec
= precision
- n
;
12440 n
+= display_mode_element (it
, depth
, field
, prec
,
12441 Vglobal_mode_string
);
12444 unsigned char *spec
12445 = decode_mode_spec (it
->w
, c
, field
, prec
);
12447 if (frame_title_ptr
)
12448 n
+= store_frame_title (spec
, field
, prec
);
12452 = it
->glyph_row
->used
[TEXT_AREA
];
12454 = percent_position
- XSTRING (elt
)->data
;
12456 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
12457 field
, prec
, 0, -1);
12459 /* Assign to the glyphs written above the
12460 string where the `%x' came from, position
12464 struct glyph
*glyph
12465 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
12469 for (i
= 0; i
< nwritten
; ++i
)
12471 glyph
[i
].object
= elt
;
12472 glyph
[i
].charpos
= charpos
;
12485 /* A symbol: process the value of the symbol recursively
12486 as if it appeared here directly. Avoid error if symbol void.
12487 Special case: if value of symbol is a string, output the string
12490 register Lisp_Object tem
;
12491 tem
= Fboundp (elt
);
12494 tem
= Fsymbol_value (elt
);
12495 /* If value is a string, output that string literally:
12496 don't check for % within it. */
12499 prec
= XSTRING (tem
)->size
;
12500 if (precision
> 0 && prec
> precision
- n
)
12501 prec
= precision
- n
;
12502 if (frame_title_ptr
)
12503 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
12505 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
12508 else if (!EQ (tem
, elt
))
12510 /* Give up right away for nil or t. */
12520 register Lisp_Object car
, tem
;
12522 /* A cons cell: three distinct cases.
12523 If first element is a string or a cons, process all the elements
12524 and effectively concatenate them.
12525 If first element is a negative number, truncate displaying cdr to
12526 at most that many characters. If positive, pad (with spaces)
12527 to at least that many characters.
12528 If first element is a symbol, process the cadr or caddr recursively
12529 according to whether the symbol's value is non-nil or nil. */
12531 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
12533 /* An element of the form (:eval FORM) means evaluate FORM
12534 and use the result as mode line elements. */
12535 struct gcpro gcpro1
;
12538 spec
= safe_eval (XCAR (XCDR (elt
)));
12540 n
+= display_mode_element (it
, depth
, field_width
- n
,
12541 precision
- n
, spec
);
12544 else if (SYMBOLP (car
))
12546 tem
= Fboundp (car
);
12550 /* elt is now the cdr, and we know it is a cons cell.
12551 Use its car if CAR has a non-nil value. */
12554 tem
= Fsymbol_value (car
);
12561 /* Symbol's value is nil (or symbol is unbound)
12562 Get the cddr of the original list
12563 and if possible find the caddr and use that. */
12567 else if (!CONSP (elt
))
12572 else if (INTEGERP (car
))
12574 register int lim
= XINT (car
);
12578 /* Negative int means reduce maximum width. */
12579 if (precision
<= 0)
12582 precision
= min (precision
, -lim
);
12586 /* Padding specified. Don't let it be more than
12587 current maximum. */
12589 lim
= min (precision
, lim
);
12591 /* If that's more padding than already wanted, queue it.
12592 But don't reduce padding already specified even if
12593 that is beyond the current truncation point. */
12594 field_width
= max (lim
, field_width
);
12598 else if (STRINGP (car
) || CONSP (car
))
12600 register int limit
= 50;
12601 /* Limit is to protect against circular lists. */
12604 && (precision
<= 0 || n
< precision
))
12606 n
+= display_mode_element (it
, depth
, field_width
- n
,
12607 precision
- n
, XCAR (elt
));
12616 if (frame_title_ptr
)
12617 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
12619 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
12620 precision
- n
, 0, 0);
12624 /* Pad to FIELD_WIDTH. */
12625 if (field_width
> 0 && n
< field_width
)
12627 if (frame_title_ptr
)
12628 n
+= store_frame_title ("", field_width
- n
, 0);
12630 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
12638 /* Write a null-terminated, right justified decimal representation of
12639 the positive integer D to BUF using a minimal field width WIDTH. */
12642 pint2str (buf
, width
, d
)
12643 register char *buf
;
12644 register int width
;
12647 register char *p
= buf
;
12655 *p
++ = d
% 10 + '0';
12660 for (width
-= (int) (p
- buf
); width
> 0; --width
)
12671 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
12672 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
12673 type of CODING_SYSTEM. Return updated pointer into BUF. */
12675 static unsigned char invalid_eol_type
[] = "(*invalid*)";
12678 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
12679 Lisp_Object coding_system
;
12680 register char *buf
;
12684 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
12685 unsigned char *eol_str
;
12687 /* The EOL conversion we are using. */
12688 Lisp_Object eoltype
;
12690 val
= Fget (coding_system
, Qcoding_system
);
12693 if (!VECTORP (val
)) /* Not yet decided. */
12698 eoltype
= eol_mnemonic_undecided
;
12699 /* Don't mention EOL conversion if it isn't decided. */
12703 Lisp_Object eolvalue
;
12705 eolvalue
= Fget (coding_system
, Qeol_type
);
12708 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
12712 /* The EOL conversion that is normal on this system. */
12714 if (NILP (eolvalue
)) /* Not yet decided. */
12715 eoltype
= eol_mnemonic_undecided
;
12716 else if (VECTORP (eolvalue
)) /* Not yet decided. */
12717 eoltype
= eol_mnemonic_undecided
;
12718 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
12719 eoltype
= (XFASTINT (eolvalue
) == 0
12720 ? eol_mnemonic_unix
12721 : (XFASTINT (eolvalue
) == 1
12722 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
12728 /* Mention the EOL conversion if it is not the usual one. */
12729 if (STRINGP (eoltype
))
12731 eol_str
= XSTRING (eoltype
)->data
;
12732 eol_str_len
= XSTRING (eoltype
)->size
;
12734 else if (INTEGERP (eoltype
)
12735 && CHAR_VALID_P (XINT (eoltype
), 0))
12737 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
12738 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
12742 eol_str
= invalid_eol_type
;
12743 eol_str_len
= sizeof (invalid_eol_type
) - 1;
12745 bcopy (eol_str
, buf
, eol_str_len
);
12746 buf
+= eol_str_len
;
12752 /* Return a string for the output of a mode line %-spec for window W,
12753 generated by character C. PRECISION >= 0 means don't return a
12754 string longer than that value. FIELD_WIDTH > 0 means pad the
12755 string returned with spaces to that value. */
12757 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
12760 decode_mode_spec (w
, c
, field_width
, precision
)
12763 int field_width
, precision
;
12766 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12767 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
12768 struct buffer
*b
= XBUFFER (w
->buffer
);
12775 if (!NILP (b
->read_only
))
12777 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12782 /* This differs from %* only for a modified read-only buffer. */
12783 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12785 if (!NILP (b
->read_only
))
12790 /* This differs from %* in ignoring read-only-ness. */
12791 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12803 if (command_loop_level
> 5)
12805 p
= decode_mode_spec_buf
;
12806 for (i
= 0; i
< command_loop_level
; i
++)
12809 return decode_mode_spec_buf
;
12817 if (command_loop_level
> 5)
12819 p
= decode_mode_spec_buf
;
12820 for (i
= 0; i
< command_loop_level
; i
++)
12823 return decode_mode_spec_buf
;
12830 /* Let lots_of_dashes be a string of infinite length. */
12831 if (field_width
<= 0
12832 || field_width
> sizeof (lots_of_dashes
))
12834 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
12835 decode_mode_spec_buf
[i
] = '-';
12836 decode_mode_spec_buf
[i
] = '\0';
12837 return decode_mode_spec_buf
;
12840 return lots_of_dashes
;
12849 int col
= current_column ();
12850 XSETFASTINT (w
->column_number_displayed
, col
);
12851 pint2str (decode_mode_spec_buf
, field_width
, col
);
12852 return decode_mode_spec_buf
;
12856 /* %F displays the frame name. */
12857 if (!NILP (f
->title
))
12858 return (char *) XSTRING (f
->title
)->data
;
12859 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
12860 return (char *) XSTRING (f
->name
)->data
;
12869 int startpos
= XMARKER (w
->start
)->charpos
;
12870 int startpos_byte
= marker_byte_position (w
->start
);
12871 int line
, linepos
, linepos_byte
, topline
;
12873 int height
= XFASTINT (w
->height
);
12875 /* If we decided that this buffer isn't suitable for line numbers,
12876 don't forget that too fast. */
12877 if (EQ (w
->base_line_pos
, w
->buffer
))
12879 /* But do forget it, if the window shows a different buffer now. */
12880 else if (BUFFERP (w
->base_line_pos
))
12881 w
->base_line_pos
= Qnil
;
12883 /* If the buffer is very big, don't waste time. */
12884 if (INTEGERP (Vline_number_display_limit
)
12885 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
12887 w
->base_line_pos
= Qnil
;
12888 w
->base_line_number
= Qnil
;
12892 if (!NILP (w
->base_line_number
)
12893 && !NILP (w
->base_line_pos
)
12894 && XFASTINT (w
->base_line_pos
) <= startpos
)
12896 line
= XFASTINT (w
->base_line_number
);
12897 linepos
= XFASTINT (w
->base_line_pos
);
12898 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
12903 linepos
= BUF_BEGV (b
);
12904 linepos_byte
= BUF_BEGV_BYTE (b
);
12907 /* Count lines from base line to window start position. */
12908 nlines
= display_count_lines (linepos
, linepos_byte
,
12912 topline
= nlines
+ line
;
12914 /* Determine a new base line, if the old one is too close
12915 or too far away, or if we did not have one.
12916 "Too close" means it's plausible a scroll-down would
12917 go back past it. */
12918 if (startpos
== BUF_BEGV (b
))
12920 XSETFASTINT (w
->base_line_number
, topline
);
12921 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
12923 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
12924 || linepos
== BUF_BEGV (b
))
12926 int limit
= BUF_BEGV (b
);
12927 int limit_byte
= BUF_BEGV_BYTE (b
);
12929 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
12931 if (startpos
- distance
> limit
)
12933 limit
= startpos
- distance
;
12934 limit_byte
= CHAR_TO_BYTE (limit
);
12937 nlines
= display_count_lines (startpos
, startpos_byte
,
12939 - (height
* 2 + 30),
12941 /* If we couldn't find the lines we wanted within
12942 line_number_display_limit_width chars per line,
12943 give up on line numbers for this window. */
12944 if (position
== limit_byte
&& limit
== startpos
- distance
)
12946 w
->base_line_pos
= w
->buffer
;
12947 w
->base_line_number
= Qnil
;
12951 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
12952 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
12955 /* Now count lines from the start pos to point. */
12956 nlines
= display_count_lines (startpos
, startpos_byte
,
12957 PT_BYTE
, PT
, &junk
);
12959 /* Record that we did display the line number. */
12960 line_number_displayed
= 1;
12962 /* Make the string to show. */
12963 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
12964 return decode_mode_spec_buf
;
12967 char* p
= decode_mode_spec_buf
;
12968 int pad
= field_width
- 2;
12974 return decode_mode_spec_buf
;
12980 obj
= b
->mode_name
;
12984 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
12990 int pos
= marker_position (w
->start
);
12991 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12993 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
12995 if (pos
<= BUF_BEGV (b
))
13000 else if (pos
<= BUF_BEGV (b
))
13004 if (total
> 1000000)
13005 /* Do it differently for a large value, to avoid overflow. */
13006 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13008 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13009 /* We can't normally display a 3-digit number,
13010 so get us a 2-digit number that is close. */
13013 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13014 return decode_mode_spec_buf
;
13018 /* Display percentage of size above the bottom of the screen. */
13021 int toppos
= marker_position (w
->start
);
13022 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
13023 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13025 if (botpos
>= BUF_ZV (b
))
13027 if (toppos
<= BUF_BEGV (b
))
13034 if (total
> 1000000)
13035 /* Do it differently for a large value, to avoid overflow. */
13036 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13038 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13039 /* We can't normally display a 3-digit number,
13040 so get us a 2-digit number that is close. */
13043 if (toppos
<= BUF_BEGV (b
))
13044 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
13046 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13047 return decode_mode_spec_buf
;
13052 /* status of process */
13053 obj
= Fget_buffer_process (w
->buffer
);
13055 return "no process";
13056 #ifdef subprocesses
13057 obj
= Fsymbol_name (Fprocess_status (obj
));
13061 case 't': /* indicate TEXT or BINARY */
13062 #ifdef MODE_LINE_BINARY_TEXT
13063 return MODE_LINE_BINARY_TEXT (b
);
13069 /* coding-system (not including end-of-line format) */
13071 /* coding-system (including end-of-line type) */
13073 int eol_flag
= (c
== 'Z');
13074 char *p
= decode_mode_spec_buf
;
13076 if (! FRAME_WINDOW_P (f
))
13078 /* No need to mention EOL here--the terminal never needs
13079 to do EOL conversion. */
13080 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
13081 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
13083 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
13086 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
13087 #ifdef subprocesses
13088 obj
= Fget_buffer_process (Fcurrent_buffer ());
13089 if (PROCESSP (obj
))
13091 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
13093 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
13096 #endif /* subprocesses */
13099 return decode_mode_spec_buf
;
13104 return (char *) XSTRING (obj
)->data
;
13110 /* Count up to COUNT lines starting from START / START_BYTE.
13111 But don't go beyond LIMIT_BYTE.
13112 Return the number of lines thus found (always nonnegative).
13114 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
13117 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
13118 int start
, start_byte
, limit_byte
, count
;
13121 register unsigned char *cursor
;
13122 unsigned char *base
;
13124 register int ceiling
;
13125 register unsigned char *ceiling_addr
;
13126 int orig_count
= count
;
13128 /* If we are not in selective display mode,
13129 check only for newlines. */
13130 int selective_display
= (!NILP (current_buffer
->selective_display
)
13131 && !INTEGERP (current_buffer
->selective_display
));
13135 while (start_byte
< limit_byte
)
13137 ceiling
= BUFFER_CEILING_OF (start_byte
);
13138 ceiling
= min (limit_byte
- 1, ceiling
);
13139 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
13140 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
13143 if (selective_display
)
13144 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
13147 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
13150 if (cursor
!= ceiling_addr
)
13154 start_byte
+= cursor
- base
+ 1;
13155 *byte_pos_ptr
= start_byte
;
13159 if (++cursor
== ceiling_addr
)
13165 start_byte
+= cursor
- base
;
13170 while (start_byte
> limit_byte
)
13172 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
13173 ceiling
= max (limit_byte
, ceiling
);
13174 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
13175 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
13178 if (selective_display
)
13179 while (--cursor
!= ceiling_addr
13180 && *cursor
!= '\n' && *cursor
!= 015)
13183 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
13186 if (cursor
!= ceiling_addr
)
13190 start_byte
+= cursor
- base
+ 1;
13191 *byte_pos_ptr
= start_byte
;
13192 /* When scanning backwards, we should
13193 not count the newline posterior to which we stop. */
13194 return - orig_count
- 1;
13200 /* Here we add 1 to compensate for the last decrement
13201 of CURSOR, which took it past the valid range. */
13202 start_byte
+= cursor
- base
+ 1;
13206 *byte_pos_ptr
= limit_byte
;
13209 return - orig_count
+ count
;
13210 return orig_count
- count
;
13216 /***********************************************************************
13218 ***********************************************************************/
13220 /* Display a NUL-terminated string, starting with index START.
13222 If STRING is non-null, display that C string. Otherwise, the Lisp
13223 string LISP_STRING is displayed.
13225 If FACE_STRING is not nil, FACE_STRING_POS is a position in
13226 FACE_STRING. Display STRING or LISP_STRING with the face at
13227 FACE_STRING_POS in FACE_STRING:
13229 Display the string in the environment given by IT, but use the
13230 standard display table, temporarily.
13232 FIELD_WIDTH is the minimum number of output glyphs to produce.
13233 If STRING has fewer characters than FIELD_WIDTH, pad to the right
13234 with spaces. If STRING has more characters, more than FIELD_WIDTH
13235 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
13237 PRECISION is the maximum number of characters to output from
13238 STRING. PRECISION < 0 means don't truncate the string.
13240 This is roughly equivalent to printf format specifiers:
13242 FIELD_WIDTH PRECISION PRINTF
13243 ----------------------------------------
13249 MULTIBYTE zero means do not display multibyte chars, > 0 means do
13250 display them, and < 0 means obey the current buffer's value of
13251 enable_multibyte_characters.
13253 Value is the number of glyphs produced. */
13256 display_string (string
, lisp_string
, face_string
, face_string_pos
,
13257 start
, it
, field_width
, precision
, max_x
, multibyte
)
13258 unsigned char *string
;
13259 Lisp_Object lisp_string
;
13260 Lisp_Object face_string
;
13261 int face_string_pos
;
13264 int field_width
, precision
, max_x
;
13267 int hpos_at_start
= it
->hpos
;
13268 int saved_face_id
= it
->face_id
;
13269 struct glyph_row
*row
= it
->glyph_row
;
13271 /* Initialize the iterator IT for iteration over STRING beginning
13272 with index START. We assume that IT may be modified here (which
13273 means that display_line has to do something when displaying a
13274 mini-buffer prompt, which it does). */
13275 reseat_to_string (it
, string
, lisp_string
, start
,
13276 precision
, field_width
, multibyte
);
13278 /* If displaying STRING, set up the face of the iterator
13279 from LISP_STRING, if that's given. */
13280 if (STRINGP (face_string
))
13286 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
13287 0, it
->region_beg_charpos
,
13288 it
->region_end_charpos
,
13289 &endptr
, it
->base_face_id
);
13290 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
13291 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
13294 /* Set max_x to the maximum allowed X position. Don't let it go
13295 beyond the right edge of the window. */
13297 max_x
= it
->last_visible_x
;
13299 max_x
= min (max_x
, it
->last_visible_x
);
13301 /* Skip over display elements that are not visible. because IT->w is
13303 if (it
->current_x
< it
->first_visible_x
)
13304 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
13305 MOVE_TO_POS
| MOVE_TO_X
);
13307 row
->ascent
= it
->max_ascent
;
13308 row
->height
= it
->max_ascent
+ it
->max_descent
;
13309 row
->phys_ascent
= it
->max_phys_ascent
;
13310 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13312 /* This condition is for the case that we are called with current_x
13313 past last_visible_x. */
13314 while (it
->current_x
< max_x
)
13316 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
13318 /* Get the next display element. */
13319 if (!get_next_display_element (it
))
13322 /* Produce glyphs. */
13323 x_before
= it
->current_x
;
13324 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13325 PRODUCE_GLYPHS (it
);
13327 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
13330 while (i
< nglyphs
)
13332 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13334 if (!it
->truncate_lines_p
13335 && x
+ glyph
->pixel_width
> max_x
)
13337 /* End of continued line or max_x reached. */
13338 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13342 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
13344 /* Glyph is at least partially visible. */
13346 if (x
< it
->first_visible_x
)
13347 it
->glyph_row
->x
= x
- it
->first_visible_x
;
13351 /* Glyph is off the left margin of the display area.
13352 Should not happen. */
13356 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13357 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13358 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13359 row
->phys_height
= max (row
->phys_height
,
13360 it
->max_phys_ascent
+ it
->max_phys_descent
);
13361 x
+= glyph
->pixel_width
;
13365 /* Stop if max_x reached. */
13369 /* Stop at line ends. */
13370 if (ITERATOR_AT_END_OF_LINE_P (it
))
13372 it
->continuation_lines_width
= 0;
13376 set_iterator_to_next (it
, 1);
13378 /* Stop if truncating at the right edge. */
13379 if (it
->truncate_lines_p
13380 && it
->current_x
>= it
->last_visible_x
)
13382 /* Add truncation mark, but don't do it if the line is
13383 truncated at a padding space. */
13384 if (IT_CHARPOS (*it
) < it
->string_nchars
)
13386 if (!FRAME_WINDOW_P (it
->f
))
13387 produce_special_glyphs (it
, IT_TRUNCATION
);
13388 it
->glyph_row
->truncated_on_right_p
= 1;
13394 /* Maybe insert a truncation at the left. */
13395 if (it
->first_visible_x
13396 && IT_CHARPOS (*it
) > 0)
13398 if (!FRAME_WINDOW_P (it
->f
))
13399 insert_left_trunc_glyphs (it
);
13400 it
->glyph_row
->truncated_on_left_p
= 1;
13403 it
->face_id
= saved_face_id
;
13405 /* Value is number of columns displayed. */
13406 return it
->hpos
- hpos_at_start
;
13411 /* This is like a combination of memq and assq. Return 1 if PROPVAL
13412 appears as an element of LIST or as the car of an element of LIST.
13413 If PROPVAL is a list, compare each element against LIST in that
13414 way, and return 1 if any element of PROPVAL is found in LIST.
13415 Otherwise return 0. This function cannot quit. */
13418 invisible_p (propval
, list
)
13419 register Lisp_Object propval
;
13422 register Lisp_Object tail
, proptail
;
13424 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13426 register Lisp_Object tem
;
13428 if (EQ (propval
, tem
))
13430 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
13434 if (CONSP (propval
))
13436 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
13438 Lisp_Object propelt
;
13439 propelt
= XCAR (proptail
);
13440 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13442 register Lisp_Object tem
;
13444 if (EQ (propelt
, tem
))
13446 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
13456 /* Return 1 if PROPVAL appears as the car of an element of LIST and
13457 the cdr of that element is non-nil. If PROPVAL is a list, check
13458 each element of PROPVAL in that way, and the first time some
13459 element is found, return 1 if the cdr of that element is non-nil.
13460 Otherwise return 0. This function cannot quit. */
13463 invisible_ellipsis_p (propval
, list
)
13464 register Lisp_Object propval
;
13467 register Lisp_Object tail
, proptail
;
13469 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13471 register Lisp_Object tem
;
13473 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
13474 return ! NILP (XCDR (tem
));
13477 if (CONSP (propval
))
13478 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
13480 Lisp_Object propelt
;
13481 propelt
= XCAR (proptail
);
13482 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13484 register Lisp_Object tem
;
13486 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
13487 return ! NILP (XCDR (tem
));
13496 /***********************************************************************
13498 ***********************************************************************/
13503 Vwith_echo_area_save_vector
= Qnil
;
13504 staticpro (&Vwith_echo_area_save_vector
);
13506 Vmessage_stack
= Qnil
;
13507 staticpro (&Vmessage_stack
);
13509 Qinhibit_redisplay
= intern ("inhibit-redisplay");
13510 staticpro (&Qinhibit_redisplay
);
13513 defsubr (&Sdump_glyph_matrix
);
13514 defsubr (&Sdump_glyph_row
);
13515 defsubr (&Sdump_tool_bar_row
);
13516 defsubr (&Strace_redisplay_toggle
);
13517 defsubr (&Strace_to_stderr
);
13520 staticpro (&Qmenu_bar_update_hook
);
13521 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
13523 staticpro (&Qoverriding_terminal_local_map
);
13524 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
13526 staticpro (&Qoverriding_local_map
);
13527 Qoverriding_local_map
= intern ("overriding-local-map");
13529 staticpro (&Qwindow_scroll_functions
);
13530 Qwindow_scroll_functions
= intern ("window-scroll-functions");
13532 staticpro (&Qredisplay_end_trigger_functions
);
13533 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
13535 staticpro (&Qinhibit_point_motion_hooks
);
13536 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
13538 QCdata
= intern (":data");
13539 staticpro (&QCdata
);
13540 Qdisplay
= intern ("display");
13541 staticpro (&Qdisplay
);
13542 Qspace_width
= intern ("space-width");
13543 staticpro (&Qspace_width
);
13544 Qraise
= intern ("raise");
13545 staticpro (&Qraise
);
13546 Qspace
= intern ("space");
13547 staticpro (&Qspace
);
13548 Qmargin
= intern ("margin");
13549 staticpro (&Qmargin
);
13550 Qleft_margin
= intern ("left-margin");
13551 staticpro (&Qleft_margin
);
13552 Qright_margin
= intern ("right-margin");
13553 staticpro (&Qright_margin
);
13554 Qalign_to
= intern ("align-to");
13555 staticpro (&Qalign_to
);
13556 QCalign_to
= intern (":align-to");
13557 staticpro (&QCalign_to
);
13558 Qrelative_width
= intern ("relative-width");
13559 staticpro (&Qrelative_width
);
13560 QCrelative_width
= intern (":relative-width");
13561 staticpro (&QCrelative_width
);
13562 QCrelative_height
= intern (":relative-height");
13563 staticpro (&QCrelative_height
);
13564 QCeval
= intern (":eval");
13565 staticpro (&QCeval
);
13566 Qwhen
= intern ("when");
13567 staticpro (&Qwhen
);
13568 QCfile
= intern (":file");
13569 staticpro (&QCfile
);
13570 Qfontified
= intern ("fontified");
13571 staticpro (&Qfontified
);
13572 Qfontification_functions
= intern ("fontification-functions");
13573 staticpro (&Qfontification_functions
);
13574 Qtrailing_whitespace
= intern ("trailing-whitespace");
13575 staticpro (&Qtrailing_whitespace
);
13576 Qimage
= intern ("image");
13577 staticpro (&Qimage
);
13578 Qmessage_truncate_lines
= intern ("message-truncate-lines");
13579 staticpro (&Qmessage_truncate_lines
);
13581 last_arrow_position
= Qnil
;
13582 last_arrow_string
= Qnil
;
13583 staticpro (&last_arrow_position
);
13584 staticpro (&last_arrow_string
);
13586 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
13587 staticpro (&echo_buffer
[0]);
13588 staticpro (&echo_buffer
[1]);
13590 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
13591 staticpro (&echo_area_buffer
[0]);
13592 staticpro (&echo_area_buffer
[1]);
13594 Vmessages_buffer_name
= build_string ("*Messages*");
13595 staticpro (&Vmessages_buffer_name
);
13597 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
13598 "Non-nil means highlight trailing whitespace.\n\
13599 The face used for trailing whitespace is `trailing-whitespace'.");
13600 Vshow_trailing_whitespace
= Qnil
;
13602 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
13603 "Non-nil means don't actually do any redisplay.\n\
13604 This is used for internal purposes.");
13605 Vinhibit_redisplay
= Qnil
;
13607 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
13608 "String (or mode line construct) included (normally) in `mode-line-format'.");
13609 Vglobal_mode_string
= Qnil
;
13611 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
13612 "Marker for where to display an arrow on top of the buffer text.\n\
13613 This must be the beginning of a line in order to work.\n\
13614 See also `overlay-arrow-string'.");
13615 Voverlay_arrow_position
= Qnil
;
13617 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
13618 "String to display as an arrow. See also `overlay-arrow-position'.");
13619 Voverlay_arrow_string
= Qnil
;
13621 DEFVAR_INT ("scroll-step", &scroll_step
,
13622 "*The number of lines to try scrolling a window by when point moves out.\n\
13623 If that fails to bring point back on frame, point is centered instead.\n\
13624 If this is zero, point is always centered after it moves off frame.");
13626 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
13627 "*Scroll up to this many lines, to bring point back on screen.\n\
13628 A value of zero means to scroll the text to center point vertically\n\
13630 scroll_conservatively
= 0;
13632 DEFVAR_INT ("scroll-margin", &scroll_margin
,
13633 "*Number of lines of margin at the top and bottom of a window.\n\
13634 Recenter the window whenever point gets within this many lines\n\
13635 of the top or bottom of the window.");
13639 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
13642 DEFVAR_BOOL ("truncate-partial-width-windows",
13643 &truncate_partial_width_windows
,
13644 "*Non-nil means truncate lines in all windows less than full frame wide.");
13645 truncate_partial_width_windows
= 1;
13647 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
13648 "*Non-nil means use inverse video for the mode line.");
13649 mode_line_inverse_video
= 1;
13651 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
13652 "*Maximum buffer size for which line number should be displayed.\n\
13653 If the buffer is bigger than this, the line number does not appear\n\
13654 in the mode line. A value of nil means no limit.");
13655 Vline_number_display_limit
= Qnil
;
13657 DEFVAR_INT ("line-number-display-limit-width",
13658 &line_number_display_limit_width
,
13659 "*Maximum line width (in characters) for line number display.\n\
13660 If the average length of the lines near point is bigger than this, then the\n\
13661 line number may be omitted from the mode line.");
13662 line_number_display_limit_width
= 200;
13664 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
13665 "*Non-nil means highlight region even in nonselected windows.");
13666 highlight_nonselected_windows
= 0;
13668 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
13669 "Non-nil if more than one frame is visible on this display.\n\
13670 Minibuffer-only frames don't count, but iconified frames do.\n\
13671 This variable is not guaranteed to be accurate except while processing\n\
13672 `frame-title-format' and `icon-title-format'.");
13674 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
13675 "Template for displaying the title bar of visible frames.\n\
13676 \(Assuming the window manager supports this feature.)\n\
13677 This variable has the same structure as `mode-line-format' (which see),\n\
13678 and is used only on frames for which no explicit name has been set\n\
13679 \(see `modify-frame-parameters').");
13680 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
13681 "Template for displaying the title bar of an iconified frame.\n\
13682 \(Assuming the window manager supports this feature.)\n\
13683 This variable has the same structure as `mode-line-format' (which see),\n\
13684 and is used only on frames for which no explicit name has been set\n\
13685 \(see `modify-frame-parameters').");
13687 = Vframe_title_format
13688 = Fcons (intern ("multiple-frames"),
13689 Fcons (build_string ("%b"),
13690 Fcons (Fcons (build_string (""),
13691 Fcons (intern ("invocation-name"),
13692 Fcons (build_string ("@"),
13693 Fcons (intern ("system-name"),
13697 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
13698 "Maximum number of lines to keep in the message log buffer.\n\
13699 If nil, disable message logging. If t, log messages but don't truncate\n\
13700 the buffer when it becomes large.");
13701 XSETFASTINT (Vmessage_log_max
, 50);
13703 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
13704 "Functions called before redisplay, if window sizes have changed.\n\
13705 The value should be a list of functions that take one argument.\n\
13706 Just before redisplay, for each frame, if any of its windows have changed\n\
13707 size since the last redisplay, or have been split or deleted,\n\
13708 all the functions in the list are called, with the frame as argument.");
13709 Vwindow_size_change_functions
= Qnil
;
13711 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
13712 "List of Functions to call before redisplaying a window with scrolling.\n\
13713 Each function is called with two arguments, the window\n\
13714 and its new display-start position. Note that the value of `window-end'\n\
13715 is not valid when these functions are called.");
13716 Vwindow_scroll_functions
= Qnil
;
13718 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
13719 "*Non-nil means automatically resize tool-bars.\n\
13720 This increases a tool-bar's height if not all tool-bar items are visible.\n\
13721 It decreases a tool-bar's height when it would display blank lines\n\
13723 auto_resize_tool_bars_p
= 1;
13725 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
13726 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
13727 auto_raise_tool_bar_buttons_p
= 1;
13729 DEFVAR_INT ("tool-bar-button-margin", &tool_bar_button_margin
,
13730 "*Margin around tool-bar buttons in pixels.");
13731 tool_bar_button_margin
= 1;
13733 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
13734 "Relief thickness of tool-bar buttons.");
13735 tool_bar_button_relief
= 3;
13737 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
13738 "List of functions to call to fontify regions of text.\n\
13739 Each function is called with one argument POS. Functions must\n\
13740 fontify a region starting at POS in the current buffer, and give\n\
13741 fontified regions the property `fontified'.\n\
13742 This variable automatically becomes buffer-local when set.");
13743 Vfontification_functions
= Qnil
;
13744 Fmake_local_variable (Qfontification_functions
);
13746 DEFVAR_BOOL ("unibyte-display-via-language-environment",
13747 &unibyte_display_via_language_environment
,
13748 "*Non-nil means display unibyte text according to language environment.\n\
13749 Specifically this means that unibyte non-ASCII characters\n\
13750 are displayed by converting them to the equivalent multibyte characters\n\
13751 according to the current language environment. As a result, they are\n\
13752 displayed according to the current fontset.");
13753 unibyte_display_via_language_environment
= 0;
13755 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
13756 "*Maximum height for resizing mini-windows.\n\
13757 If a float, it specifies a fraction of the mini-window frame's height.\n\
13758 If an integer, it specifies a number of lines.\n\
13759 If nil, don't resize.");
13760 Vmax_mini_window_height
= make_float (0.25);
13762 DEFVAR_BOOL ("cursor-in-non-selected-windows",
13763 &cursor_in_non_selected_windows
,
13764 "*Non-nil means display a hollow cursor in non-selected windows.\n\
13765 Nil means don't display a cursor there.");
13766 cursor_in_non_selected_windows
= 1;
13768 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
13769 "*Non-nil means scroll the display automatically to make point visible.");
13770 automatic_hscrolling_p
= 1;
13772 DEFVAR_LISP ("image-types", &Vimage_types
,
13773 "List of supported image types.\n\
13774 Each element of the list is a symbol for a supported image type.");
13775 Vimage_types
= Qnil
;
13777 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
13778 "If non-nil, messages are truncated instead of resizing the echo area.\n\
13779 Bind this around calls to `message' to let it take effect.");
13780 message_truncate_lines
= 0;
13782 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
13783 "Normal hook run for clicks on menu bar, before displaying a submenu.\n\
13784 Can be used to update submenus whose contents should vary.");
13789 /* Initialize this module when Emacs starts. */
13794 Lisp_Object root_window
;
13795 struct window
*mini_w
;
13797 CHARPOS (this_line_start_pos
) = 0;
13799 mini_w
= XWINDOW (minibuf_window
);
13800 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
13802 if (!noninteractive
)
13804 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
13807 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
13808 set_window_height (root_window
,
13809 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
13811 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
13812 set_window_height (minibuf_window
, 1, 0);
13814 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
13815 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
13817 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
13818 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
13819 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
13821 /* The default ellipsis glyphs `...'. */
13822 for (i
= 0; i
< 3; ++i
)
13823 XSETFASTINT (default_invis_vector
[i
], '.');
13826 #ifdef HAVE_WINDOW_SYSTEM
13828 /* Allocate the buffer for frame titles. */
13830 frame_title_buf
= (char *) xmalloc (size
);
13831 frame_title_buf_end
= frame_title_buf
+ size
;
13832 frame_title_ptr
= NULL
;
13834 #endif /* HAVE_WINDOW_SYSTEM */
13836 help_echo_showing_p
= 0;