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 1 if position CHARPOS is visible in window W.
933 Set *FULLY to 1 if POS is visible and the line containing
934 POS is fully visible. */
937 pos_visible_p (w
, charpos
, fully
)
944 struct buffer
*old_buffer
= NULL
;
946 if (XBUFFER (w
->buffer
) != current_buffer
)
948 old_buffer
= current_buffer
;
949 set_buffer_internal_1 (XBUFFER (w
->buffer
));
952 *fully
= visible_p
= 0;
953 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
954 start_display (&it
, w
, top
);
956 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
957 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
959 if (IT_CHARPOS (it
) == charpos
)
961 int line_height
, line_bottom_y
;
962 int line_top_y
= it
.current_y
;
963 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
965 line_height
= it
.max_ascent
+ it
.max_descent
;
966 if (line_height
== 0)
969 line_height
= last_height
;
972 move_it_by_lines (&it
, 1, 1);
973 line_height
= (it
.max_ascent
|| it
.max_descent
974 ? it
.max_ascent
+ it
.max_descent
978 line_bottom_y
= line_top_y
+ line_height
;
980 if (line_top_y
< window_top_y
)
981 visible_p
= line_bottom_y
> window_top_y
;
982 else if (line_top_y
< it
.last_visible_y
)
985 *fully
= line_bottom_y
<= it
.last_visible_y
;
988 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
990 move_it_by_lines (&it
, 1, 0);
991 if (charpos
< IT_CHARPOS (it
))
999 set_buffer_internal_1 (old_buffer
);
1005 /* Return the next character from STR which is MAXLEN bytes long.
1006 Return in *LEN the length of the character. This is like
1007 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1008 we find one, we return a `?', but with the length of the invalid
1012 string_char_and_length (str
, maxlen
, len
)
1018 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1019 if (!CHAR_VALID_P (c
, 1))
1020 /* We may not change the length here because other places in Emacs
1021 don't use this function, i.e. they silently accept invalid
1030 /* Given a position POS containing a valid character and byte position
1031 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1033 static struct text_pos
1034 string_pos_nchars_ahead (pos
, string
, nchars
)
1035 struct text_pos pos
;
1039 xassert (STRINGP (string
) && nchars
>= 0);
1041 if (STRING_MULTIBYTE (string
))
1043 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
1044 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
1049 string_char_and_length (p
, rest
, &len
);
1050 p
+= len
, rest
-= len
;
1051 xassert (rest
>= 0);
1053 BYTEPOS (pos
) += len
;
1057 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1063 /* Value is the text position, i.e. character and byte position,
1064 for character position CHARPOS in STRING. */
1066 static INLINE
struct text_pos
1067 string_pos (charpos
, string
)
1071 struct text_pos pos
;
1072 xassert (STRINGP (string
));
1073 xassert (charpos
>= 0);
1074 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1079 /* Value is a text position, i.e. character and byte position, for
1080 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1081 means recognize multibyte characters. */
1083 static struct text_pos
1084 c_string_pos (charpos
, s
, multibyte_p
)
1089 struct text_pos pos
;
1091 xassert (s
!= NULL
);
1092 xassert (charpos
>= 0);
1096 int rest
= strlen (s
), len
;
1098 SET_TEXT_POS (pos
, 0, 0);
1101 string_char_and_length (s
, rest
, &len
);
1102 s
+= len
, rest
-= len
;
1103 xassert (rest
>= 0);
1105 BYTEPOS (pos
) += len
;
1109 SET_TEXT_POS (pos
, charpos
, charpos
);
1115 /* Value is the number of characters in C string S. MULTIBYTE_P
1116 non-zero means recognize multibyte characters. */
1119 number_of_chars (s
, multibyte_p
)
1127 int rest
= strlen (s
), len
;
1128 unsigned char *p
= (unsigned char *) s
;
1130 for (nchars
= 0; rest
> 0; ++nchars
)
1132 string_char_and_length (p
, rest
, &len
);
1133 rest
-= len
, p
+= len
;
1137 nchars
= strlen (s
);
1143 /* Compute byte position NEWPOS->bytepos corresponding to
1144 NEWPOS->charpos. POS is a known position in string STRING.
1145 NEWPOS->charpos must be >= POS.charpos. */
1148 compute_string_pos (newpos
, pos
, string
)
1149 struct text_pos
*newpos
, pos
;
1152 xassert (STRINGP (string
));
1153 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1155 if (STRING_MULTIBYTE (string
))
1156 *newpos
= string_pos_nchars_ahead (pos
, string
,
1157 CHARPOS (*newpos
) - CHARPOS (pos
));
1159 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1164 /***********************************************************************
1165 Lisp form evaluation
1166 ***********************************************************************/
1168 /* Error handler for safe_eval and safe_call. */
1171 safe_eval_handler (arg
)
1174 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1179 /* Evaluate SEXPR and return the result, or nil if something went
1186 int count
= specpdl_ptr
- specpdl
;
1187 struct gcpro gcpro1
;
1191 specbind (Qinhibit_redisplay
, Qt
);
1192 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, safe_eval_handler
);
1194 return unbind_to (count
, val
);
1198 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1199 Return the result, or nil if something went wrong. */
1202 safe_call (nargs
, args
)
1206 int count
= specpdl_ptr
- specpdl
;
1208 struct gcpro gcpro1
;
1211 gcpro1
.nvars
= nargs
;
1212 specbind (Qinhibit_redisplay
, Qt
);
1213 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1216 return unbind_to (count
, val
);
1220 /* Call function FN with one argument ARG.
1221 Return the result, or nil if something went wrong. */
1224 safe_call1 (fn
, arg
)
1225 Lisp_Object fn
, arg
;
1227 Lisp_Object args
[2];
1230 return safe_call (2, args
);
1235 /***********************************************************************
1237 ***********************************************************************/
1241 /* Define CHECK_IT to perform sanity checks on iterators.
1242 This is for debugging. It is too slow to do unconditionally. */
1248 if (it
->method
== next_element_from_string
)
1250 xassert (STRINGP (it
->string
));
1251 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1253 else if (it
->method
== next_element_from_buffer
)
1255 /* Check that character and byte positions agree. */
1256 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1260 xassert (it
->current
.dpvec_index
>= 0);
1262 xassert (it
->current
.dpvec_index
< 0);
1265 #define CHECK_IT(IT) check_it ((IT))
1269 #define CHECK_IT(IT) (void) 0
1276 /* Check that the window end of window W is what we expect it
1277 to be---the last row in the current matrix displaying text. */
1280 check_window_end (w
)
1283 if (!MINI_WINDOW_P (w
)
1284 && !NILP (w
->window_end_valid
))
1286 struct glyph_row
*row
;
1287 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1288 XFASTINT (w
->window_end_vpos
)),
1290 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1291 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1295 #define CHECK_WINDOW_END(W) check_window_end ((W))
1297 #else /* not GLYPH_DEBUG */
1299 #define CHECK_WINDOW_END(W) (void) 0
1301 #endif /* not GLYPH_DEBUG */
1305 /***********************************************************************
1306 Iterator initialization
1307 ***********************************************************************/
1309 /* Initialize IT for displaying current_buffer in window W, starting
1310 at character position CHARPOS. CHARPOS < 0 means that no buffer
1311 position is specified which is useful when the iterator is assigned
1312 a position later. BYTEPOS is the byte position corresponding to
1313 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1315 If ROW is not null, calls to produce_glyphs with IT as parameter
1316 will produce glyphs in that row.
1318 BASE_FACE_ID is the id of a base face to use. It must be one of
1319 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1320 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1321 displaying the tool-bar.
1323 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1324 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1325 corresponding mode line glyph row of the desired matrix of W. */
1328 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1331 int charpos
, bytepos
;
1332 struct glyph_row
*row
;
1333 enum face_id base_face_id
;
1335 int highlight_region_p
;
1337 /* Some precondition checks. */
1338 xassert (w
!= NULL
&& it
!= NULL
);
1339 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1341 /* If face attributes have been changed since the last redisplay,
1342 free realized faces now because they depend on face definitions
1343 that might have changed. */
1344 if (face_change_count
)
1346 face_change_count
= 0;
1347 free_all_realized_faces (Qnil
);
1350 /* Use one of the mode line rows of W's desired matrix if
1354 if (base_face_id
== MODE_LINE_FACE_ID
)
1355 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1356 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1357 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1361 bzero (it
, sizeof *it
);
1362 it
->current
.overlay_string_index
= -1;
1363 it
->current
.dpvec_index
= -1;
1364 it
->base_face_id
= base_face_id
;
1366 /* The window in which we iterate over current_buffer: */
1367 XSETWINDOW (it
->window
, w
);
1369 it
->f
= XFRAME (w
->frame
);
1371 /* Extra space between lines (on window systems only). */
1372 if (base_face_id
== DEFAULT_FACE_ID
1373 && FRAME_WINDOW_P (it
->f
))
1375 if (NATNUMP (current_buffer
->extra_line_spacing
))
1376 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1377 else if (it
->f
->extra_line_spacing
> 0)
1378 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1381 /* If realized faces have been removed, e.g. because of face
1382 attribute changes of named faces, recompute them. */
1383 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1384 recompute_basic_faces (it
->f
);
1386 /* Current value of the `space-width', and 'height' properties. */
1387 it
->space_width
= Qnil
;
1388 it
->font_height
= Qnil
;
1390 /* Are control characters displayed as `^C'? */
1391 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1393 /* -1 means everything between a CR and the following line end
1394 is invisible. >0 means lines indented more than this value are
1396 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1397 ? XFASTINT (current_buffer
->selective_display
)
1398 : (!NILP (current_buffer
->selective_display
)
1400 it
->selective_display_ellipsis_p
1401 = !NILP (current_buffer
->selective_display_ellipses
);
1403 /* Display table to use. */
1404 it
->dp
= window_display_table (w
);
1406 /* Are multibyte characters enabled in current_buffer? */
1407 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1409 /* Non-zero if we should highlight the region. */
1411 = (!NILP (Vtransient_mark_mode
)
1412 && !NILP (current_buffer
->mark_active
)
1413 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1415 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1416 start and end of a visible region in window IT->w. Set both to
1417 -1 to indicate no region. */
1418 if (highlight_region_p
1419 /* Maybe highlight only in selected window. */
1420 && (/* Either show region everywhere. */
1421 highlight_nonselected_windows
1422 /* Or show region in the selected window. */
1423 || w
== XWINDOW (selected_window
)
1424 /* Or show the region if we are in the mini-buffer and W is
1425 the window the mini-buffer refers to. */
1426 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1427 && w
== XWINDOW (Vminibuf_scroll_window
))))
1429 int charpos
= marker_position (current_buffer
->mark
);
1430 it
->region_beg_charpos
= min (PT
, charpos
);
1431 it
->region_end_charpos
= max (PT
, charpos
);
1434 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1436 /* Get the position at which the redisplay_end_trigger hook should
1437 be run, if it is to be run at all. */
1438 if (MARKERP (w
->redisplay_end_trigger
)
1439 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1440 it
->redisplay_end_trigger_charpos
1441 = marker_position (w
->redisplay_end_trigger
);
1442 else if (INTEGERP (w
->redisplay_end_trigger
))
1443 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1445 /* Correct bogus values of tab_width. */
1446 it
->tab_width
= XINT (current_buffer
->tab_width
);
1447 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1450 /* Are lines in the display truncated? */
1451 it
->truncate_lines_p
1452 = (base_face_id
!= DEFAULT_FACE_ID
1453 || XINT (it
->w
->hscroll
)
1454 || (truncate_partial_width_windows
1455 && !WINDOW_FULL_WIDTH_P (it
->w
))
1456 || !NILP (current_buffer
->truncate_lines
));
1458 /* Get dimensions of truncation and continuation glyphs. These are
1459 displayed as bitmaps under X, so we don't need them for such
1461 if (!FRAME_WINDOW_P (it
->f
))
1463 if (it
->truncate_lines_p
)
1465 /* We will need the truncation glyph. */
1466 xassert (it
->glyph_row
== NULL
);
1467 produce_special_glyphs (it
, IT_TRUNCATION
);
1468 it
->truncation_pixel_width
= it
->pixel_width
;
1472 /* We will need the continuation glyph. */
1473 xassert (it
->glyph_row
== NULL
);
1474 produce_special_glyphs (it
, IT_CONTINUATION
);
1475 it
->continuation_pixel_width
= it
->pixel_width
;
1478 /* Reset these values to zero becaue the produce_special_glyphs
1479 above has changed them. */
1480 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1481 it
->phys_ascent
= it
->phys_descent
= 0;
1484 /* Set this after getting the dimensions of truncation and
1485 continuation glyphs, so that we don't produce glyphs when calling
1486 produce_special_glyphs, above. */
1487 it
->glyph_row
= row
;
1488 it
->area
= TEXT_AREA
;
1490 /* Get the dimensions of the display area. The display area
1491 consists of the visible window area plus a horizontally scrolled
1492 part to the left of the window. All x-values are relative to the
1493 start of this total display area. */
1494 if (base_face_id
!= DEFAULT_FACE_ID
)
1496 /* Mode lines, menu bar in terminal frames. */
1497 it
->first_visible_x
= 0;
1498 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1503 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1504 it
->last_visible_x
= (it
->first_visible_x
1505 + window_box_width (w
, TEXT_AREA
));
1507 /* If we truncate lines, leave room for the truncator glyph(s) at
1508 the right margin. Otherwise, leave room for the continuation
1509 glyph(s). Truncation and continuation glyphs are not inserted
1510 for window-based redisplay. */
1511 if (!FRAME_WINDOW_P (it
->f
))
1513 if (it
->truncate_lines_p
)
1514 it
->last_visible_x
-= it
->truncation_pixel_width
;
1516 it
->last_visible_x
-= it
->continuation_pixel_width
;
1519 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1520 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1523 /* Leave room for a border glyph. */
1524 if (!FRAME_WINDOW_P (it
->f
)
1525 && !WINDOW_RIGHTMOST_P (it
->w
))
1526 it
->last_visible_x
-= 1;
1528 it
->last_visible_y
= window_text_bottom_y (w
);
1530 /* For mode lines and alike, arrange for the first glyph having a
1531 left box line if the face specifies a box. */
1532 if (base_face_id
!= DEFAULT_FACE_ID
)
1536 it
->face_id
= base_face_id
;
1538 /* If we have a boxed mode line, make the first character appear
1539 with a left box line. */
1540 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1541 if (face
->box
!= FACE_NO_BOX
)
1542 it
->start_of_box_run_p
= 1;
1545 /* If a buffer position was specified, set the iterator there,
1546 getting overlays and face properties from that position. */
1549 it
->end_charpos
= ZV
;
1551 IT_CHARPOS (*it
) = charpos
;
1553 /* Compute byte position if not specified. */
1555 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1557 IT_BYTEPOS (*it
) = bytepos
;
1559 /* Compute faces etc. */
1560 reseat (it
, it
->current
.pos
, 1);
1567 /* Initialize IT for the display of window W with window start POS. */
1570 start_display (it
, w
, pos
)
1573 struct text_pos pos
;
1575 int start_at_line_beg_p
;
1576 struct glyph_row
*row
;
1577 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1580 row
= w
->desired_matrix
->rows
+ first_vpos
;
1581 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1582 first_y
= it
->current_y
;
1584 /* If window start is not at a line start, move back to the line
1585 start. This makes sure that we take continuation lines into
1587 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1588 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1589 if (!start_at_line_beg_p
)
1590 reseat_at_previous_visible_line_start (it
);
1592 /* If window start is not at a line start, skip forward to POS to
1593 get the correct continuation_lines_width and current_x. */
1594 if (!start_at_line_beg_p
)
1596 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1598 /* If lines are continued, this line may end in the middle of a
1599 multi-glyph character (e.g. a control character displayed as
1600 \003, or in the middle of an overlay string). In this case
1601 move_it_to above will not have taken us to the start of
1602 the continuation line but to the end of the continued line. */
1603 if (!it
->truncate_lines_p
)
1605 if (it
->current_x
> 0)
1607 if (it
->current
.dpvec_index
>= 0
1608 || it
->current
.overlay_string_index
>= 0)
1610 set_iterator_to_next (it
, 1);
1611 move_it_in_display_line_to (it
, -1, -1, 0);
1614 it
->continuation_lines_width
+= it
->current_x
;
1617 /* We're starting a new display line, not affected by the
1618 height of the continued line, so clear the appropriate
1619 fields in the iterator structure. */
1620 it
->max_ascent
= it
->max_descent
= 0;
1621 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1624 it
->current_y
= first_y
;
1626 it
->current_x
= it
->hpos
= 0;
1629 #if 0 /* Don't assert the following because start_display is sometimes
1630 called intentionally with a window start that is not at a
1631 line start. Please leave this code in as a comment. */
1633 /* Window start should be on a line start, now. */
1634 xassert (it
->continuation_lines_width
1635 || IT_CHARPOS (it
) == BEGV
1636 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1641 /* Initialize IT for stepping through current_buffer in window W,
1642 starting at position POS that includes overlay string and display
1643 vector/ control character translation position information. */
1646 init_from_display_pos (it
, w
, pos
)
1649 struct display_pos
*pos
;
1651 /* Keep in mind: the call to reseat in init_iterator skips invisible
1652 text, so we might end up at a position different from POS. This
1653 is only a problem when POS is a row start after a newline and an
1654 overlay starts there with an after-string, and the overlay has an
1655 invisible property. Since we don't skip invisible text in
1656 display_line and elsewhere immediately after consuming the
1657 newline before the row start, such a POS will not be in a string,
1658 but the call to init_iterator below will move us to the
1660 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1661 NULL
, DEFAULT_FACE_ID
);
1663 /* If position is within an overlay string, set up IT to
1664 the right overlay string. */
1665 if (pos
->overlay_string_index
>= 0)
1669 /* We already have the first chunk of overlay strings in
1670 IT->overlay_strings. Load more until the one for
1671 pos->overlay_string_index is in IT->overlay_strings. */
1672 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1674 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1675 it
->current
.overlay_string_index
= 0;
1678 load_overlay_strings (it
);
1679 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1683 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1684 relative_index
= (it
->current
.overlay_string_index
1685 % OVERLAY_STRING_CHUNK_SIZE
);
1686 it
->string
= it
->overlay_strings
[relative_index
];
1687 xassert (STRINGP (it
->string
));
1688 it
->current
.string_pos
= pos
->string_pos
;
1689 it
->method
= next_element_from_string
;
1691 else if (CHARPOS (pos
->string_pos
) >= 0)
1693 /* Recorded position is not in an overlay string, but in another
1694 string. This can only be a string from a `display' property.
1695 IT should already be filled with that string. */
1696 it
->current
.string_pos
= pos
->string_pos
;
1697 xassert (STRINGP (it
->string
));
1700 /* Restore position in display vector translations or control
1701 character translations. */
1702 if (pos
->dpvec_index
>= 0)
1704 /* This fills IT->dpvec. */
1705 get_next_display_element (it
);
1706 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1707 it
->current
.dpvec_index
= pos
->dpvec_index
;
1714 /* Initialize IT for stepping through current_buffer in window W
1715 starting at ROW->start. */
1718 init_to_row_start (it
, w
, row
)
1721 struct glyph_row
*row
;
1723 init_from_display_pos (it
, w
, &row
->start
);
1724 it
->continuation_lines_width
= row
->continuation_lines_width
;
1729 /* Initialize IT for stepping through current_buffer in window W
1730 starting in the line following ROW, i.e. starting at ROW->end. */
1733 init_to_row_end (it
, w
, row
)
1736 struct glyph_row
*row
;
1738 init_from_display_pos (it
, w
, &row
->end
);
1740 if (row
->continued_p
)
1741 it
->continuation_lines_width
= (row
->continuation_lines_width
1742 + row
->pixel_width
);
1749 /***********************************************************************
1751 ***********************************************************************/
1753 /* Called when IT reaches IT->stop_charpos. Handle text property and
1754 overlay changes. Set IT->stop_charpos to the next position where
1761 enum prop_handled handled
;
1762 int handle_overlay_change_p
= 1;
1766 it
->current
.dpvec_index
= -1;
1770 handled
= HANDLED_NORMALLY
;
1772 /* Call text property handlers. */
1773 for (p
= it_props
; p
->handler
; ++p
)
1775 handled
= p
->handler (it
);
1777 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1779 else if (handled
== HANDLED_RETURN
)
1781 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1782 handle_overlay_change_p
= 0;
1785 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1787 /* Don't check for overlay strings below when set to deliver
1788 characters from a display vector. */
1789 if (it
->method
== next_element_from_display_vector
)
1790 handle_overlay_change_p
= 0;
1792 /* Handle overlay changes. */
1793 if (handle_overlay_change_p
)
1794 handled
= handle_overlay_change (it
);
1796 /* Determine where to stop next. */
1797 if (handled
== HANDLED_NORMALLY
)
1798 compute_stop_pos (it
);
1801 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1805 /* Compute IT->stop_charpos from text property and overlay change
1806 information for IT's current position. */
1809 compute_stop_pos (it
)
1812 register INTERVAL iv
, next_iv
;
1813 Lisp_Object object
, limit
, position
;
1815 /* If nowhere else, stop at the end. */
1816 it
->stop_charpos
= it
->end_charpos
;
1818 if (STRINGP (it
->string
))
1820 /* Strings are usually short, so don't limit the search for
1822 object
= it
->string
;
1824 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1830 /* If next overlay change is in front of the current stop pos
1831 (which is IT->end_charpos), stop there. Note: value of
1832 next_overlay_change is point-max if no overlay change
1834 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1835 if (charpos
< it
->stop_charpos
)
1836 it
->stop_charpos
= charpos
;
1838 /* If showing the region, we have to stop at the region
1839 start or end because the face might change there. */
1840 if (it
->region_beg_charpos
> 0)
1842 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1843 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1844 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1845 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1848 /* Set up variables for computing the stop position from text
1849 property changes. */
1850 XSETBUFFER (object
, current_buffer
);
1851 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1852 XSETFASTINT (position
, IT_CHARPOS (*it
));
1856 /* Get the interval containing IT's position. Value is a null
1857 interval if there isn't such an interval. */
1858 iv
= validate_interval_range (object
, &position
, &position
, 0);
1859 if (!NULL_INTERVAL_P (iv
))
1861 Lisp_Object values_here
[LAST_PROP_IDX
];
1864 /* Get properties here. */
1865 for (p
= it_props
; p
->handler
; ++p
)
1866 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1868 /* Look for an interval following iv that has different
1870 for (next_iv
= next_interval (iv
);
1871 (!NULL_INTERVAL_P (next_iv
)
1873 || XFASTINT (limit
) > next_iv
->position
));
1874 next_iv
= next_interval (next_iv
))
1876 for (p
= it_props
; p
->handler
; ++p
)
1878 Lisp_Object new_value
;
1880 new_value
= textget (next_iv
->plist
, *p
->name
);
1881 if (!EQ (values_here
[p
->idx
], new_value
))
1889 if (!NULL_INTERVAL_P (next_iv
))
1891 if (INTEGERP (limit
)
1892 && next_iv
->position
>= XFASTINT (limit
))
1893 /* No text property change up to limit. */
1894 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1896 /* Text properties change in next_iv. */
1897 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1901 xassert (STRINGP (it
->string
)
1902 || (it
->stop_charpos
>= BEGV
1903 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1907 /* Return the position of the next overlay change after POS in
1908 current_buffer. Value is point-max if no overlay change
1909 follows. This is like `next-overlay-change' but doesn't use
1913 next_overlay_change (pos
)
1918 Lisp_Object
*overlays
;
1922 /* Get all overlays at the given position. */
1924 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1925 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
1926 if (noverlays
> len
)
1929 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1930 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
1933 /* If any of these overlays ends before endpos,
1934 use its ending point instead. */
1935 for (i
= 0; i
< noverlays
; ++i
)
1940 oend
= OVERLAY_END (overlays
[i
]);
1941 oendpos
= OVERLAY_POSITION (oend
);
1942 endpos
= min (endpos
, oendpos
);
1950 /***********************************************************************
1952 ***********************************************************************/
1954 /* Handle changes in the `fontified' property of the current buffer by
1955 calling hook functions from Qfontification_functions to fontify
1958 static enum prop_handled
1959 handle_fontified_prop (it
)
1962 Lisp_Object prop
, pos
;
1963 enum prop_handled handled
= HANDLED_NORMALLY
;
1965 /* Get the value of the `fontified' property at IT's current buffer
1966 position. (The `fontified' property doesn't have a special
1967 meaning in strings.) If the value is nil, call functions from
1968 Qfontification_functions. */
1969 if (!STRINGP (it
->string
)
1971 && !NILP (Vfontification_functions
)
1972 && !NILP (Vrun_hooks
)
1973 && (pos
= make_number (IT_CHARPOS (*it
)),
1974 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1977 int count
= specpdl_ptr
- specpdl
;
1980 val
= Vfontification_functions
;
1981 specbind (Qfontification_functions
, Qnil
);
1982 specbind (Qafter_change_functions
, Qnil
);
1984 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
1985 safe_call1 (val
, pos
);
1988 Lisp_Object globals
, fn
;
1989 struct gcpro gcpro1
, gcpro2
;
1992 GCPRO2 (val
, globals
);
1994 for (; CONSP (val
); val
= XCDR (val
))
2000 /* A value of t indicates this hook has a local
2001 binding; it means to run the global binding too.
2002 In a global value, t should not occur. If it
2003 does, we must ignore it to avoid an endless
2005 for (globals
= Fdefault_value (Qfontification_functions
);
2007 globals
= XCDR (globals
))
2009 fn
= XCAR (globals
);
2011 safe_call1 (fn
, pos
);
2015 safe_call1 (fn
, pos
);
2021 unbind_to (count
, Qnil
);
2023 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2024 something. This avoids an endless loop if they failed to
2025 fontify the text for which reason ever. */
2026 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2027 handled
= HANDLED_RECOMPUTE_PROPS
;
2035 /***********************************************************************
2037 ***********************************************************************/
2039 /* Set up iterator IT from face properties at its current position.
2040 Called from handle_stop. */
2042 static enum prop_handled
2043 handle_face_prop (it
)
2046 int new_face_id
, next_stop
;
2048 if (!STRINGP (it
->string
))
2051 = face_at_buffer_position (it
->w
,
2053 it
->region_beg_charpos
,
2054 it
->region_end_charpos
,
2057 + TEXT_PROP_DISTANCE_LIMIT
),
2060 /* Is this a start of a run of characters with box face?
2061 Caveat: this can be called for a freshly initialized
2062 iterator; face_id is -1 is this case. We know that the new
2063 face will not change until limit, i.e. if the new face has a
2064 box, all characters up to limit will have one. But, as
2065 usual, we don't know whether limit is really the end. */
2066 if (new_face_id
!= it
->face_id
)
2068 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2070 /* If new face has a box but old face has not, this is
2071 the start of a run of characters with box, i.e. it has
2072 a shadow on the left side. The value of face_id of the
2073 iterator will be -1 if this is the initial call that gets
2074 the face. In this case, we have to look in front of IT's
2075 position and see whether there is a face != new_face_id. */
2076 it
->start_of_box_run_p
2077 = (new_face
->box
!= FACE_NO_BOX
2078 && (it
->face_id
>= 0
2079 || IT_CHARPOS (*it
) == BEG
2080 || new_face_id
!= face_before_it_pos (it
)));
2081 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2087 = face_at_string_position (it
->w
,
2089 IT_STRING_CHARPOS (*it
),
2090 (it
->current
.overlay_string_index
>= 0
2093 it
->region_beg_charpos
,
2094 it
->region_end_charpos
,
2098 #if 0 /* This shouldn't be neccessary. Let's check it. */
2099 /* If IT is used to display a mode line we would really like to
2100 use the mode line face instead of the frame's default face. */
2101 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2102 && new_face_id
== DEFAULT_FACE_ID
)
2103 new_face_id
= MODE_LINE_FACE_ID
;
2106 /* Is this a start of a run of characters with box? Caveat:
2107 this can be called for a freshly allocated iterator; face_id
2108 is -1 is this case. We know that the new face will not
2109 change until the next check pos, i.e. if the new face has a
2110 box, all characters up to that position will have a
2111 box. But, as usual, we don't know whether that position
2112 is really the end. */
2113 if (new_face_id
!= it
->face_id
)
2115 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2116 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2118 /* If new face has a box but old face hasn't, this is the
2119 start of a run of characters with box, i.e. it has a
2120 shadow on the left side. */
2121 it
->start_of_box_run_p
2122 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2123 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2127 it
->face_id
= new_face_id
;
2128 return HANDLED_NORMALLY
;
2132 /* Compute the face one character before or after the current position
2133 of IT. BEFORE_P non-zero means get the face in front of IT's
2134 position. Value is the id of the face. */
2137 face_before_or_after_it_pos (it
, before_p
)
2142 int next_check_charpos
;
2143 struct text_pos pos
;
2145 xassert (it
->s
== NULL
);
2147 if (STRINGP (it
->string
))
2149 /* No face change past the end of the string (for the case
2150 we are padding with spaces). No face change before the
2152 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2153 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2156 /* Set pos to the position before or after IT's current position. */
2158 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2160 /* For composition, we must check the character after the
2162 pos
= (it
->what
== IT_COMPOSITION
2163 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2164 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2166 /* Get the face for ASCII, or unibyte. */
2168 = face_at_string_position (it
->w
,
2171 (it
->current
.overlay_string_index
>= 0
2174 it
->region_beg_charpos
,
2175 it
->region_end_charpos
,
2176 &next_check_charpos
,
2179 /* Correct the face for charsets different from ASCII. Do it
2180 for the multibyte case only. The face returned above is
2181 suitable for unibyte text if IT->string is unibyte. */
2182 if (STRING_MULTIBYTE (it
->string
))
2184 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2185 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2187 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2189 c
= string_char_and_length (p
, rest
, &len
);
2190 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2195 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2196 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2199 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2200 pos
= it
->current
.pos
;
2203 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2206 if (it
->what
== IT_COMPOSITION
)
2207 /* For composition, we must check the position after the
2209 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2211 INC_TEXT_POS (pos
, it
->multibyte_p
);
2213 /* Determine face for CHARSET_ASCII, or unibyte. */
2214 face_id
= face_at_buffer_position (it
->w
,
2216 it
->region_beg_charpos
,
2217 it
->region_end_charpos
,
2218 &next_check_charpos
,
2221 /* Correct the face for charsets different from ASCII. Do it
2222 for the multibyte case only. The face returned above is
2223 suitable for unibyte text if current_buffer is unibyte. */
2224 if (it
->multibyte_p
)
2226 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2227 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2228 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2237 /***********************************************************************
2239 ***********************************************************************/
2241 /* Set up iterator IT from invisible properties at its current
2242 position. Called from handle_stop. */
2244 static enum prop_handled
2245 handle_invisible_prop (it
)
2248 enum prop_handled handled
= HANDLED_NORMALLY
;
2250 if (STRINGP (it
->string
))
2252 extern Lisp_Object Qinvisible
;
2253 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2255 /* Get the value of the invisible text property at the
2256 current position. Value will be nil if there is no such
2258 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2259 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2262 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2264 handled
= HANDLED_RECOMPUTE_PROPS
;
2266 /* Get the position at which the next change of the
2267 invisible text property can be found in IT->string.
2268 Value will be nil if the property value is the same for
2269 all the rest of IT->string. */
2270 XSETINT (limit
, XSTRING (it
->string
)->size
);
2271 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2274 /* Text at current position is invisible. The next
2275 change in the property is at position end_charpos.
2276 Move IT's current position to that position. */
2277 if (INTEGERP (end_charpos
)
2278 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2280 struct text_pos old
;
2281 old
= it
->current
.string_pos
;
2282 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2283 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2287 /* The rest of the string is invisible. If this is an
2288 overlay string, proceed with the next overlay string
2289 or whatever comes and return a character from there. */
2290 if (it
->current
.overlay_string_index
>= 0)
2292 next_overlay_string (it
);
2293 /* Don't check for overlay strings when we just
2294 finished processing them. */
2295 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2299 struct Lisp_String
*s
= XSTRING (it
->string
);
2300 IT_STRING_CHARPOS (*it
) = s
->size
;
2301 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2308 int visible_p
, newpos
, next_stop
;
2309 Lisp_Object pos
, prop
;
2311 /* First of all, is there invisible text at this position? */
2312 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2313 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2315 /* If we are on invisible text, skip over it. */
2316 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2317 && IT_CHARPOS (*it
) < it
->end_charpos
)
2319 /* Record whether we have to display an ellipsis for the
2321 int display_ellipsis_p
2322 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2324 handled
= HANDLED_RECOMPUTE_PROPS
;
2326 /* Loop skipping over invisible text. The loop is left at
2327 ZV or with IT on the first char being visible again. */
2330 /* Try to skip some invisible text. Return value is the
2331 position reached which can be equal to IT's position
2332 if there is nothing invisible here. This skips both
2333 over invisible text properties and overlays with
2334 invisible property. */
2335 newpos
= skip_invisible (IT_CHARPOS (*it
),
2336 &next_stop
, ZV
, it
->window
);
2338 /* If we skipped nothing at all we weren't at invisible
2339 text in the first place. If everything to the end of
2340 the buffer was skipped, end the loop. */
2341 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2345 /* We skipped some characters but not necessarily
2346 all there are. Check if we ended up on visible
2347 text. Fget_char_property returns the property of
2348 the char before the given position, i.e. if we
2349 get visible_p = 1, this means that the char at
2350 newpos is visible. */
2351 XSETFASTINT (pos
, newpos
);
2352 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2353 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2356 /* If we ended up on invisible text, proceed to
2357 skip starting with next_stop. */
2359 IT_CHARPOS (*it
) = next_stop
;
2363 /* The position newpos is now either ZV or on visible text. */
2364 IT_CHARPOS (*it
) = newpos
;
2365 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2367 /* Maybe return `...' next for the end of the invisible text. */
2368 if (display_ellipsis_p
)
2371 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2373 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2374 it
->dpvec
= v
->contents
;
2375 it
->dpend
= v
->contents
+ v
->size
;
2379 /* Default `...'. */
2380 it
->dpvec
= default_invis_vector
;
2381 it
->dpend
= default_invis_vector
+ 3;
2384 /* The ellipsis display does not replace the display of
2385 the character at the new position. Indicate this by
2386 setting IT->dpvec_char_len to zero. */
2387 it
->dpvec_char_len
= 0;
2389 it
->current
.dpvec_index
= 0;
2390 it
->method
= next_element_from_display_vector
;
2400 /***********************************************************************
2402 ***********************************************************************/
2404 /* Set up iterator IT from `display' property at its current position.
2405 Called from handle_stop. */
2407 static enum prop_handled
2408 handle_display_prop (it
)
2411 Lisp_Object prop
, object
;
2412 struct text_pos
*position
;
2413 int space_or_image_found_p
;
2415 if (STRINGP (it
->string
))
2417 object
= it
->string
;
2418 position
= &it
->current
.string_pos
;
2423 position
= &it
->current
.pos
;
2426 /* Reset those iterator values set from display property values. */
2427 it
->font_height
= Qnil
;
2428 it
->space_width
= Qnil
;
2431 /* We don't support recursive `display' properties, i.e. string
2432 values that have a string `display' property, that have a string
2433 `display' property etc. */
2434 if (!it
->string_from_display_prop_p
)
2435 it
->area
= TEXT_AREA
;
2437 prop
= Fget_char_property (make_number (position
->charpos
),
2440 return HANDLED_NORMALLY
;
2442 space_or_image_found_p
= 0;
2444 && CONSP (XCAR (prop
))
2445 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2447 /* A list of sub-properties. */
2448 while (CONSP (prop
))
2450 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2451 space_or_image_found_p
= 1;
2455 else if (VECTORP (prop
))
2458 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2459 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2461 space_or_image_found_p
= 1;
2465 if (handle_single_display_prop (it
, prop
, object
, position
))
2466 space_or_image_found_p
= 1;
2469 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2473 /* Value is the position of the end of the `display' property starting
2474 at START_POS in OBJECT. */
2476 static struct text_pos
2477 display_prop_end (it
, object
, start_pos
)
2480 struct text_pos start_pos
;
2483 struct text_pos end_pos
;
2485 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2486 Qdisplay
, object
, Qnil
);
2487 CHARPOS (end_pos
) = XFASTINT (end
);
2488 if (STRINGP (object
))
2489 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2491 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2497 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2498 is the object in which the `display' property was found. *POSITION
2499 is the position at which it was found.
2501 If PROP is a `space' or `image' sub-property, set *POSITION to the
2502 end position of the `display' property.
2504 Value is non-zero if a `space' or `image' property value was found. */
2507 handle_single_display_prop (it
, prop
, object
, position
)
2511 struct text_pos
*position
;
2514 int space_or_image_found_p
= 0;
2517 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2518 evaluated. If the result is nil, VALUE is ignored. */
2520 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2529 if (!NILP (form
) && !EQ (form
, Qt
))
2531 struct gcpro gcpro1
;
2532 struct text_pos end_pos
, pt
;
2535 end_pos
= display_prop_end (it
, object
, *position
);
2537 /* Temporarily set point to the end position, and then evaluate
2538 the form. This makes `(eolp)' work as FORM. */
2539 if (BUFFERP (object
))
2542 BYTEPOS (pt
) = PT_BYTE
;
2543 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2546 form
= safe_eval (form
);
2548 if (BUFFERP (object
))
2549 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2557 && EQ (XCAR (prop
), Qheight
)
2558 && CONSP (XCDR (prop
)))
2560 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2563 /* `(height HEIGHT)'. */
2564 it
->font_height
= XCAR (XCDR (prop
));
2565 if (!NILP (it
->font_height
))
2567 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2568 int new_height
= -1;
2570 if (CONSP (it
->font_height
)
2571 && (EQ (XCAR (it
->font_height
), Qplus
)
2572 || EQ (XCAR (it
->font_height
), Qminus
))
2573 && CONSP (XCDR (it
->font_height
))
2574 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2576 /* `(+ N)' or `(- N)' where N is an integer. */
2577 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2578 if (EQ (XCAR (it
->font_height
), Qplus
))
2580 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2582 else if (FUNCTIONP (it
->font_height
))
2584 /* Call function with current height as argument.
2585 Value is the new height. */
2587 height
= safe_call1 (it
->font_height
,
2588 face
->lface
[LFACE_HEIGHT_INDEX
]);
2589 if (NUMBERP (height
))
2590 new_height
= XFLOATINT (height
);
2592 else if (NUMBERP (it
->font_height
))
2594 /* Value is a multiple of the canonical char height. */
2597 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2598 new_height
= (XFLOATINT (it
->font_height
)
2599 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2603 /* Evaluate IT->font_height with `height' bound to the
2604 current specified height to get the new height. */
2606 int count
= specpdl_ptr
- specpdl
;
2608 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2609 value
= safe_eval (it
->font_height
);
2610 unbind_to (count
, Qnil
);
2612 if (NUMBERP (value
))
2613 new_height
= XFLOATINT (value
);
2617 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2620 else if (CONSP (prop
)
2621 && EQ (XCAR (prop
), Qspace_width
)
2622 && CONSP (XCDR (prop
)))
2624 /* `(space_width WIDTH)'. */
2625 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2628 value
= XCAR (XCDR (prop
));
2629 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2630 it
->space_width
= value
;
2632 else if (CONSP (prop
)
2633 && EQ (XCAR (prop
), Qraise
)
2634 && CONSP (XCDR (prop
)))
2636 /* `(raise FACTOR)'. */
2637 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2640 #ifdef HAVE_WINDOW_SYSTEM
2641 value
= XCAR (XCDR (prop
));
2642 if (NUMBERP (value
))
2644 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2645 it
->voffset
= - (XFLOATINT (value
)
2646 * (FONT_HEIGHT (face
->font
)));
2648 #endif /* HAVE_WINDOW_SYSTEM */
2650 else if (!it
->string_from_display_prop_p
)
2652 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2653 VALUE) or `((margin nil) VALUE)' or VALUE. */
2654 Lisp_Object location
, value
;
2655 struct text_pos start_pos
;
2658 /* Characters having this form of property are not displayed, so
2659 we have to find the end of the property. */
2660 start_pos
= *position
;
2661 *position
= display_prop_end (it
, object
, start_pos
);
2664 /* Let's stop at the new position and assume that all
2665 text properties change there. */
2666 it
->stop_charpos
= position
->charpos
;
2668 location
= Qunbound
;
2669 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2673 value
= XCDR (prop
);
2675 value
= XCAR (value
);
2678 if (EQ (XCAR (tem
), Qmargin
)
2679 && (tem
= XCDR (tem
),
2680 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2682 || EQ (tem
, Qleft_margin
)
2683 || EQ (tem
, Qright_margin
))))
2687 if (EQ (location
, Qunbound
))
2693 #ifdef HAVE_WINDOW_SYSTEM
2694 if (FRAME_TERMCAP_P (it
->f
))
2695 valid_p
= STRINGP (value
);
2697 valid_p
= (STRINGP (value
)
2698 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2699 || valid_image_p (value
));
2700 #else /* not HAVE_WINDOW_SYSTEM */
2701 valid_p
= STRINGP (value
);
2702 #endif /* not HAVE_WINDOW_SYSTEM */
2704 if ((EQ (location
, Qleft_margin
)
2705 || EQ (location
, Qright_margin
)
2709 space_or_image_found_p
= 1;
2711 /* Save current settings of IT so that we can restore them
2712 when we are finished with the glyph property value. */
2715 if (NILP (location
))
2716 it
->area
= TEXT_AREA
;
2717 else if (EQ (location
, Qleft_margin
))
2718 it
->area
= LEFT_MARGIN_AREA
;
2720 it
->area
= RIGHT_MARGIN_AREA
;
2722 if (STRINGP (value
))
2725 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2726 it
->current
.overlay_string_index
= -1;
2727 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2728 it
->end_charpos
= it
->string_nchars
2729 = XSTRING (it
->string
)->size
;
2730 it
->method
= next_element_from_string
;
2731 it
->stop_charpos
= 0;
2732 it
->string_from_display_prop_p
= 1;
2734 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2736 it
->method
= next_element_from_stretch
;
2738 it
->current
.pos
= it
->position
= start_pos
;
2740 #ifdef HAVE_WINDOW_SYSTEM
2743 it
->what
= IT_IMAGE
;
2744 it
->image_id
= lookup_image (it
->f
, value
);
2745 it
->position
= start_pos
;
2746 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2747 it
->method
= next_element_from_image
;
2749 /* Say that we haven't consumed the characters with
2750 `display' property yet. The call to pop_it in
2751 set_iterator_to_next will clean this up. */
2752 *position
= start_pos
;
2754 #endif /* HAVE_WINDOW_SYSTEM */
2757 /* Invalid property or property not supported. Restore
2758 the position to what it was before. */
2759 *position
= start_pos
;
2762 return space_or_image_found_p
;
2766 /* Check if PROP is a display sub-property value whose text should be
2767 treated as intangible. */
2770 single_display_prop_intangible_p (prop
)
2773 /* Skip over `when FORM'. */
2774 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2785 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
2786 we don't need to treat text as intangible. */
2787 if (EQ (XCAR (prop
), Qmargin
))
2795 || EQ (XCAR (prop
), Qleft_margin
)
2796 || EQ (XCAR (prop
), Qright_margin
))
2800 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
2804 /* Check if PROP is a display property value whose text should be
2805 treated as intangible. */
2808 display_prop_intangible_p (prop
)
2812 && CONSP (XCAR (prop
))
2813 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2815 /* A list of sub-properties. */
2816 while (CONSP (prop
))
2818 if (single_display_prop_intangible_p (XCAR (prop
)))
2823 else if (VECTORP (prop
))
2825 /* A vector of sub-properties. */
2827 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2828 if (single_display_prop_intangible_p (XVECTOR (prop
)->contents
[i
]))
2832 return single_display_prop_intangible_p (prop
);
2838 /***********************************************************************
2839 `composition' property
2840 ***********************************************************************/
2842 /* Set up iterator IT from `composition' property at its current
2843 position. Called from handle_stop. */
2845 static enum prop_handled
2846 handle_composition_prop (it
)
2849 Lisp_Object prop
, string
;
2850 int pos
, pos_byte
, end
;
2851 enum prop_handled handled
= HANDLED_NORMALLY
;
2853 if (STRINGP (it
->string
))
2855 pos
= IT_STRING_CHARPOS (*it
);
2856 pos_byte
= IT_STRING_BYTEPOS (*it
);
2857 string
= it
->string
;
2861 pos
= IT_CHARPOS (*it
);
2862 pos_byte
= IT_BYTEPOS (*it
);
2866 /* If there's a valid composition and point is not inside of the
2867 composition (in the case that the composition is from the current
2868 buffer), draw a glyph composed from the composition components. */
2869 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
2870 && COMPOSITION_VALID_P (pos
, end
, prop
)
2871 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
2873 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
2877 it
->method
= next_element_from_composition
;
2879 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
2880 /* For a terminal, draw only the first character of the
2882 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
2883 it
->len
= (STRINGP (it
->string
)
2884 ? string_char_to_byte (it
->string
, end
)
2885 : CHAR_TO_BYTE (end
)) - pos_byte
;
2886 it
->stop_charpos
= end
;
2887 handled
= HANDLED_RETURN
;
2896 /***********************************************************************
2898 ***********************************************************************/
2900 /* The following structure is used to record overlay strings for
2901 later sorting in load_overlay_strings. */
2903 struct overlay_entry
2905 Lisp_Object overlay
;
2912 /* Set up iterator IT from overlay strings at its current position.
2913 Called from handle_stop. */
2915 static enum prop_handled
2916 handle_overlay_change (it
)
2919 if (!STRINGP (it
->string
) && get_overlay_strings (it
))
2920 return HANDLED_RECOMPUTE_PROPS
;
2922 return HANDLED_NORMALLY
;
2926 /* Set up the next overlay string for delivery by IT, if there is an
2927 overlay string to deliver. Called by set_iterator_to_next when the
2928 end of the current overlay string is reached. If there are more
2929 overlay strings to display, IT->string and
2930 IT->current.overlay_string_index are set appropriately here.
2931 Otherwise IT->string is set to nil. */
2934 next_overlay_string (it
)
2937 ++it
->current
.overlay_string_index
;
2938 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2940 /* No more overlay strings. Restore IT's settings to what
2941 they were before overlay strings were processed, and
2942 continue to deliver from current_buffer. */
2944 xassert (it
->stop_charpos
>= BEGV
2945 && it
->stop_charpos
<= it
->end_charpos
);
2947 it
->current
.overlay_string_index
= -1;
2948 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2949 it
->n_overlay_strings
= 0;
2950 it
->method
= next_element_from_buffer
;
2952 /* If we're at the end of the buffer, record that we have
2953 processed the overlay strings there already, so that
2954 next_element_from_buffer doesn't try it again. */
2955 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
2956 it
->overlay_strings_at_end_processed_p
= 1;
2960 /* There are more overlay strings to process. If
2961 IT->current.overlay_string_index has advanced to a position
2962 where we must load IT->overlay_strings with more strings, do
2964 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2966 if (it
->current
.overlay_string_index
&& i
== 0)
2967 load_overlay_strings (it
);
2969 /* Initialize IT to deliver display elements from the overlay
2971 it
->string
= it
->overlay_strings
[i
];
2972 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2973 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2974 it
->method
= next_element_from_string
;
2975 it
->stop_charpos
= 0;
2982 /* Compare two overlay_entry structures E1 and E2. Used as a
2983 comparison function for qsort in load_overlay_strings. Overlay
2984 strings for the same position are sorted so that
2986 1. All after-strings come in front of before-strings, except
2987 when they come from the same overlay.
2989 2. Within after-strings, strings are sorted so that overlay strings
2990 from overlays with higher priorities come first.
2992 2. Within before-strings, strings are sorted so that overlay
2993 strings from overlays with higher priorities come last.
2995 Value is analogous to strcmp. */
2999 compare_overlay_entries (e1
, e2
)
3002 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3003 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3006 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3008 /* Let after-strings appear in front of before-strings if
3009 they come from different overlays. */
3010 if (EQ (entry1
->overlay
, entry2
->overlay
))
3011 result
= entry1
->after_string_p
? 1 : -1;
3013 result
= entry1
->after_string_p
? -1 : 1;
3015 else if (entry1
->after_string_p
)
3016 /* After-strings sorted in order of decreasing priority. */
3017 result
= entry2
->priority
- entry1
->priority
;
3019 /* Before-strings sorted in order of increasing priority. */
3020 result
= entry1
->priority
- entry2
->priority
;
3026 /* Load the vector IT->overlay_strings with overlay strings from IT's
3027 current buffer position. Set IT->n_overlays to the total number of
3028 overlay strings found.
3030 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3031 a time. On entry into load_overlay_strings,
3032 IT->current.overlay_string_index gives the number of overlay
3033 strings that have already been loaded by previous calls to this
3036 IT->add_overlay_start contains an additional overlay start
3037 position to consider for taking overlay strings from, if non-zero.
3038 This position comes into play when the overlay has an `invisible'
3039 property, and both before and after-strings. When we've skipped to
3040 the end of the overlay, because of its `invisible' property, we
3041 nevertheless want its before-string to appear.
3042 IT->add_overlay_start will contain the overlay start position
3045 Overlay strings are sorted so that after-string strings come in
3046 front of before-string strings. Within before and after-strings,
3047 strings are sorted by overlay priority. See also function
3048 compare_overlay_entries. */
3051 load_overlay_strings (it
)
3054 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3055 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3058 int n
= 0, i
, j
, invis_p
;
3059 struct overlay_entry
*entries
3060 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3061 int charpos
= IT_CHARPOS (*it
);
3063 /* Append the overlay string STRING of overlay OVERLAY to vector
3064 `entries' which has size `size' and currently contains `n'
3065 elements. AFTER_P non-zero means STRING is an after-string of
3067 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3070 Lisp_Object priority; \
3074 int new_size = 2 * size; \
3075 struct overlay_entry *old = entries; \
3077 (struct overlay_entry *) alloca (new_size \
3078 * sizeof *entries); \
3079 bcopy (old, entries, size * sizeof *entries); \
3083 entries[n].string = (STRING); \
3084 entries[n].overlay = (OVERLAY); \
3085 priority = Foverlay_get ((OVERLAY), Qpriority); \
3086 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3087 entries[n].after_string_p = (AFTER_P); \
3092 /* Process overlay before the overlay center. */
3093 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3095 overlay
= XCAR (ov
);
3096 xassert (OVERLAYP (overlay
));
3097 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3098 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3103 /* Skip this overlay if it doesn't start or end at IT's current
3105 if (end
!= charpos
&& start
!= charpos
)
3108 /* Skip this overlay if it doesn't apply to IT->w. */
3109 window
= Foverlay_get (overlay
, Qwindow
);
3110 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3113 /* If the text ``under'' the overlay is invisible, both before-
3114 and after-strings from this overlay are visible; start and
3115 end position are indistinguishable. */
3116 invisible
= Foverlay_get (overlay
, Qinvisible
);
3117 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3119 /* If overlay has a non-empty before-string, record it. */
3120 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3121 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3122 && XSTRING (str
)->size
)
3123 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3125 /* If overlay has a non-empty after-string, record it. */
3126 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3127 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3128 && XSTRING (str
)->size
)
3129 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3132 /* Process overlays after the overlay center. */
3133 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3135 overlay
= XCAR (ov
);
3136 xassert (OVERLAYP (overlay
));
3137 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3138 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3140 if (start
> charpos
)
3143 /* Skip this overlay if it doesn't start or end at IT's current
3145 if (end
!= charpos
&& start
!= charpos
)
3148 /* Skip this overlay if it doesn't apply to IT->w. */
3149 window
= Foverlay_get (overlay
, Qwindow
);
3150 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3153 /* If the text ``under'' the overlay is invisible, it has a zero
3154 dimension, and both before- and after-strings apply. */
3155 invisible
= Foverlay_get (overlay
, Qinvisible
);
3156 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3158 /* If overlay has a non-empty before-string, record it. */
3159 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3160 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3161 && XSTRING (str
)->size
)
3162 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3164 /* If overlay has a non-empty after-string, record it. */
3165 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3166 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3167 && XSTRING (str
)->size
)
3168 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3171 #undef RECORD_OVERLAY_STRING
3175 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3177 /* Record the total number of strings to process. */
3178 it
->n_overlay_strings
= n
;
3180 /* IT->current.overlay_string_index is the number of overlay strings
3181 that have already been consumed by IT. Copy some of the
3182 remaining overlay strings to IT->overlay_strings. */
3184 j
= it
->current
.overlay_string_index
;
3185 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3186 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3192 /* Get the first chunk of overlay strings at IT's current buffer
3193 position. Value is non-zero if at least one overlay string was
3197 get_overlay_strings (it
)
3200 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3201 process. This fills IT->overlay_strings with strings, and sets
3202 IT->n_overlay_strings to the total number of strings to process.
3203 IT->pos.overlay_string_index has to be set temporarily to zero
3204 because load_overlay_strings needs this; it must be set to -1
3205 when no overlay strings are found because a zero value would
3206 indicate a position in the first overlay string. */
3207 it
->current
.overlay_string_index
= 0;
3208 load_overlay_strings (it
);
3210 /* If we found overlay strings, set up IT to deliver display
3211 elements from the first one. Otherwise set up IT to deliver
3212 from current_buffer. */
3213 if (it
->n_overlay_strings
)
3215 /* Make sure we know settings in current_buffer, so that we can
3216 restore meaningful values when we're done with the overlay
3218 compute_stop_pos (it
);
3219 xassert (it
->face_id
>= 0);
3221 /* Save IT's settings. They are restored after all overlay
3222 strings have been processed. */
3223 xassert (it
->sp
== 0);
3226 /* Set up IT to deliver display elements from the first overlay
3228 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3229 it
->stop_charpos
= 0;
3230 it
->string
= it
->overlay_strings
[0];
3231 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3232 xassert (STRINGP (it
->string
));
3233 it
->method
= next_element_from_string
;
3238 it
->current
.overlay_string_index
= -1;
3239 it
->method
= next_element_from_buffer
;
3244 /* Value is non-zero if we found at least one overlay string. */
3245 return STRINGP (it
->string
);
3250 /***********************************************************************
3251 Saving and restoring state
3252 ***********************************************************************/
3254 /* Save current settings of IT on IT->stack. Called, for example,
3255 before setting up IT for an overlay string, to be able to restore
3256 IT's settings to what they were after the overlay string has been
3263 struct iterator_stack_entry
*p
;
3265 xassert (it
->sp
< 2);
3266 p
= it
->stack
+ it
->sp
;
3268 p
->stop_charpos
= it
->stop_charpos
;
3269 xassert (it
->face_id
>= 0);
3270 p
->face_id
= it
->face_id
;
3271 p
->string
= it
->string
;
3272 p
->pos
= it
->current
;
3273 p
->end_charpos
= it
->end_charpos
;
3274 p
->string_nchars
= it
->string_nchars
;
3276 p
->multibyte_p
= it
->multibyte_p
;
3277 p
->space_width
= it
->space_width
;
3278 p
->font_height
= it
->font_height
;
3279 p
->voffset
= it
->voffset
;
3280 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3285 /* Restore IT's settings from IT->stack. Called, for example, when no
3286 more overlay strings must be processed, and we return to delivering
3287 display elements from a buffer, or when the end of a string from a
3288 `display' property is reached and we return to delivering display
3289 elements from an overlay string, or from a buffer. */
3295 struct iterator_stack_entry
*p
;
3297 xassert (it
->sp
> 0);
3299 p
= it
->stack
+ it
->sp
;
3300 it
->stop_charpos
= p
->stop_charpos
;
3301 it
->face_id
= p
->face_id
;
3302 it
->string
= p
->string
;
3303 it
->current
= p
->pos
;
3304 it
->end_charpos
= p
->end_charpos
;
3305 it
->string_nchars
= p
->string_nchars
;
3307 it
->multibyte_p
= p
->multibyte_p
;
3308 it
->space_width
= p
->space_width
;
3309 it
->font_height
= p
->font_height
;
3310 it
->voffset
= p
->voffset
;
3311 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3316 /***********************************************************************
3318 ***********************************************************************/
3320 /* Set IT's current position to the previous line start. */
3323 back_to_previous_line_start (it
)
3326 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3327 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3331 /* Move IT to the next line start.
3333 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3334 we skipped over part of the text (as opposed to moving the iterator
3335 continuously over the text). Otherwise, don't change the value
3338 Newlines may come from buffer text, overlay strings, or strings
3339 displayed via the `display' property. That's the reason we can't
3340 simply use find_next_newline_no_quit. */
3343 forward_to_next_line_start (it
, skipped_p
)
3347 int old_selective
, newline_found_p
, n
;
3348 const int MAX_NEWLINE_DISTANCE
= 500;
3350 /* Don't handle selective display in the following. It's (a)
3351 unnecessary and (b) leads to an infinite recursion because
3352 next_element_from_ellipsis indirectly calls this function. */
3353 old_selective
= it
->selective
;
3356 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3357 from buffer text. */
3358 n
= newline_found_p
= 0;
3359 while (n
< MAX_NEWLINE_DISTANCE
3360 && get_next_display_element (it
)
3361 && !newline_found_p
)
3363 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3364 set_iterator_to_next (it
, 0);
3365 if (!STRINGP (it
->string
))
3369 /* If we didn't find a newline near enough, see if we can use a
3371 if (!newline_found_p
&& n
== MAX_NEWLINE_DISTANCE
)
3373 int start
= IT_CHARPOS (*it
);
3374 int limit
= find_next_newline_no_quit (start
, 1);
3377 xassert (!STRINGP (it
->string
));
3379 /* If there isn't any `display' property in sight, and no
3380 overlays, we can just use the position of the newline in
3382 if (it
->stop_charpos
>= limit
3383 || ((pos
= Fnext_single_property_change (make_number (start
),
3385 Qnil
, make_number (limit
)),
3387 && next_overlay_change (start
) == ZV
))
3389 IT_CHARPOS (*it
) = limit
;
3390 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3391 *skipped_p
= newline_found_p
= 1;
3395 while (get_next_display_element (it
)
3396 && !newline_found_p
)
3398 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3399 set_iterator_to_next (it
, 0);
3404 it
->selective
= old_selective
;
3405 return newline_found_p
;
3409 /* Set IT's current position to the previous visible line start. Skip
3410 invisible text that is so either due to text properties or due to
3411 selective display. Caution: this does not change IT->current_x and
3415 back_to_previous_visible_line_start (it
)
3420 /* Go back one newline if not on BEGV already. */
3421 if (IT_CHARPOS (*it
) > BEGV
)
3422 back_to_previous_line_start (it
);
3424 /* Move over lines that are invisible because of selective display
3425 or text properties. */
3426 while (IT_CHARPOS (*it
) > BEGV
3431 /* If selective > 0, then lines indented more than that values
3433 if (it
->selective
> 0
3434 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3441 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3442 Qinvisible
, it
->window
);
3443 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3447 /* Back one more newline if the current one is invisible. */
3449 back_to_previous_line_start (it
);
3452 xassert (IT_CHARPOS (*it
) >= BEGV
);
3453 xassert (IT_CHARPOS (*it
) == BEGV
3454 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3459 /* Reseat iterator IT at the previous visible line start. Skip
3460 invisible text that is so either due to text properties or due to
3461 selective display. At the end, update IT's overlay information,
3462 face information etc. */
3465 reseat_at_previous_visible_line_start (it
)
3468 back_to_previous_visible_line_start (it
);
3469 reseat (it
, it
->current
.pos
, 1);
3474 /* Reseat iterator IT on the next visible line start in the current
3475 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3476 preceding the line start. Skip over invisible text that is so
3477 because of selective display. Compute faces, overlays etc at the
3478 new position. Note that this function does not skip over text that
3479 is invisible because of text properties. */
3482 reseat_at_next_visible_line_start (it
, on_newline_p
)
3486 int newline_found_p
, skipped_p
= 0;
3488 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3490 /* Skip over lines that are invisible because they are indented
3491 more than the value of IT->selective. */
3492 if (it
->selective
> 0)
3493 while (IT_CHARPOS (*it
) < ZV
3494 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3496 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3498 /* Position on the newline if that's what's requested. */
3499 if (on_newline_p
&& newline_found_p
)
3501 if (STRINGP (it
->string
))
3503 if (IT_STRING_CHARPOS (*it
) > 0)
3505 --IT_STRING_CHARPOS (*it
);
3506 --IT_STRING_BYTEPOS (*it
);
3509 else if (IT_CHARPOS (*it
) > BEGV
)
3513 reseat (it
, it
->current
.pos
, 0);
3517 reseat (it
, it
->current
.pos
, 0);
3524 /***********************************************************************
3525 Changing an iterator's position
3526 ***********************************************************************/
3528 /* Change IT's current position to POS in current_buffer. If FORCE_P
3529 is non-zero, always check for text properties at the new position.
3530 Otherwise, text properties are only looked up if POS >=
3531 IT->check_charpos of a property. */
3534 reseat (it
, pos
, force_p
)
3536 struct text_pos pos
;
3539 int original_pos
= IT_CHARPOS (*it
);
3541 reseat_1 (it
, pos
, 0);
3543 /* Determine where to check text properties. Avoid doing it
3544 where possible because text property lookup is very expensive. */
3546 || CHARPOS (pos
) > it
->stop_charpos
3547 || CHARPOS (pos
) < original_pos
)
3554 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3555 IT->stop_pos to POS, also. */
3558 reseat_1 (it
, pos
, set_stop_p
)
3560 struct text_pos pos
;
3563 /* Don't call this function when scanning a C string. */
3564 xassert (it
->s
== NULL
);
3566 /* POS must be a reasonable value. */
3567 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3569 it
->current
.pos
= it
->position
= pos
;
3570 XSETBUFFER (it
->object
, current_buffer
);
3572 it
->current
.dpvec_index
= -1;
3573 it
->current
.overlay_string_index
= -1;
3574 IT_STRING_CHARPOS (*it
) = -1;
3575 IT_STRING_BYTEPOS (*it
) = -1;
3577 it
->method
= next_element_from_buffer
;
3581 it
->stop_charpos
= CHARPOS (pos
);
3585 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3586 If S is non-null, it is a C string to iterate over. Otherwise,
3587 STRING gives a Lisp string to iterate over.
3589 If PRECISION > 0, don't return more then PRECISION number of
3590 characters from the string.
3592 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3593 characters have been returned. FIELD_WIDTH < 0 means an infinite
3596 MULTIBYTE = 0 means disable processing of multibyte characters,
3597 MULTIBYTE > 0 means enable it,
3598 MULTIBYTE < 0 means use IT->multibyte_p.
3600 IT must be initialized via a prior call to init_iterator before
3601 calling this function. */
3604 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3609 int precision
, field_width
, multibyte
;
3611 /* No region in strings. */
3612 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3614 /* No text property checks performed by default, but see below. */
3615 it
->stop_charpos
= -1;
3617 /* Set iterator position and end position. */
3618 bzero (&it
->current
, sizeof it
->current
);
3619 it
->current
.overlay_string_index
= -1;
3620 it
->current
.dpvec_index
= -1;
3621 xassert (charpos
>= 0);
3623 /* Use the setting of MULTIBYTE if specified. */
3625 it
->multibyte_p
= multibyte
> 0;
3629 xassert (STRINGP (string
));
3630 it
->string
= string
;
3632 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3633 it
->method
= next_element_from_string
;
3634 it
->current
.string_pos
= string_pos (charpos
, string
);
3641 /* Note that we use IT->current.pos, not it->current.string_pos,
3642 for displaying C strings. */
3643 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3644 if (it
->multibyte_p
)
3646 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3647 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3651 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3652 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3655 it
->method
= next_element_from_c_string
;
3658 /* PRECISION > 0 means don't return more than PRECISION characters
3660 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3661 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3663 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3664 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3665 FIELD_WIDTH < 0 means infinite field width. This is useful for
3666 padding with `-' at the end of a mode line. */
3667 if (field_width
< 0)
3668 field_width
= INFINITY
;
3669 if (field_width
> it
->end_charpos
- charpos
)
3670 it
->end_charpos
= charpos
+ field_width
;
3672 /* Use the standard display table for displaying strings. */
3673 if (DISP_TABLE_P (Vstandard_display_table
))
3674 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3676 it
->stop_charpos
= charpos
;
3682 /***********************************************************************
3684 ***********************************************************************/
3686 /* Load IT's display element fields with information about the next
3687 display element from the current position of IT. Value is zero if
3688 end of buffer (or C string) is reached. */
3691 get_next_display_element (it
)
3694 /* Non-zero means that we found an display element. Zero means that
3695 we hit the end of what we iterate over. Performance note: the
3696 function pointer `method' used here turns out to be faster than
3697 using a sequence of if-statements. */
3698 int success_p
= (*it
->method
) (it
);
3700 if (it
->what
== IT_CHARACTER
)
3702 /* Map via display table or translate control characters.
3703 IT->c, IT->len etc. have been set to the next character by
3704 the function call above. If we have a display table, and it
3705 contains an entry for IT->c, translate it. Don't do this if
3706 IT->c itself comes from a display table, otherwise we could
3707 end up in an infinite recursion. (An alternative could be to
3708 count the recursion depth of this function and signal an
3709 error when a certain maximum depth is reached.) Is it worth
3711 if (success_p
&& it
->dpvec
== NULL
)
3716 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3719 struct Lisp_Vector
*v
= XVECTOR (dv
);
3721 /* Return the first character from the display table
3722 entry, if not empty. If empty, don't display the
3723 current character. */
3726 it
->dpvec_char_len
= it
->len
;
3727 it
->dpvec
= v
->contents
;
3728 it
->dpend
= v
->contents
+ v
->size
;
3729 it
->current
.dpvec_index
= 0;
3730 it
->method
= next_element_from_display_vector
;
3733 success_p
= get_next_display_element (it
);
3736 /* Translate control characters into `\003' or `^C' form.
3737 Control characters coming from a display table entry are
3738 currently not translated because we use IT->dpvec to hold
3739 the translation. This could easily be changed but I
3740 don't believe that it is worth doing.
3742 Non-printable multibyte characters are also translated
3744 else if ((it
->c
< ' '
3745 && (it
->area
!= TEXT_AREA
3746 || (it
->c
!= '\n' && it
->c
!= '\t')))
3749 || !CHAR_PRINTABLE_P (it
->c
))
3751 /* IT->c is a control character which must be displayed
3752 either as '\003' or as `^C' where the '\\' and '^'
3753 can be defined in the display table. Fill
3754 IT->ctl_chars with glyphs for what we have to
3755 display. Then, set IT->dpvec to these glyphs. */
3758 if (it
->c
< 128 && it
->ctl_arrow_p
)
3760 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3762 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3763 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3764 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3766 g
= FAST_MAKE_GLYPH ('^', 0);
3767 XSETINT (it
->ctl_chars
[0], g
);
3769 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3770 XSETINT (it
->ctl_chars
[1], g
);
3772 /* Set up IT->dpvec and return first character from it. */
3773 it
->dpvec_char_len
= it
->len
;
3774 it
->dpvec
= it
->ctl_chars
;
3775 it
->dpend
= it
->dpvec
+ 2;
3776 it
->current
.dpvec_index
= 0;
3777 it
->method
= next_element_from_display_vector
;
3778 get_next_display_element (it
);
3782 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
3787 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3789 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3790 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3791 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3793 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
3795 if (SINGLE_BYTE_CHAR_P (it
->c
))
3796 str
[0] = it
->c
, len
= 1;
3798 len
= CHAR_STRING (it
->c
, str
);
3800 for (i
= 0; i
< len
; i
++)
3802 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
3803 /* Insert three more glyphs into IT->ctl_chars for
3804 the octal display of the character. */
3805 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
3806 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
3807 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
3808 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
3809 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
3810 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
3813 /* Set up IT->dpvec and return the first character
3815 it
->dpvec_char_len
= it
->len
;
3816 it
->dpvec
= it
->ctl_chars
;
3817 it
->dpend
= it
->dpvec
+ len
* 4;
3818 it
->current
.dpvec_index
= 0;
3819 it
->method
= next_element_from_display_vector
;
3820 get_next_display_element (it
);
3825 /* Adjust face id for a multibyte character. There are no
3826 multibyte character in unibyte text. */
3829 && FRAME_WINDOW_P (it
->f
))
3831 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3832 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
3836 /* Is this character the last one of a run of characters with
3837 box? If yes, set IT->end_of_box_run_p to 1. */
3844 it
->end_of_box_run_p
3845 = ((face_id
= face_after_it_pos (it
),
3846 face_id
!= it
->face_id
)
3847 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3848 face
->box
== FACE_NO_BOX
));
3851 /* Value is 0 if end of buffer or string reached. */
3856 /* Move IT to the next display element.
3858 RESEAT_P non-zero means if called on a newline in buffer text,
3859 skip to the next visible line start.
3861 Functions get_next_display_element and set_iterator_to_next are
3862 separate because I find this arrangement easier to handle than a
3863 get_next_display_element function that also increments IT's
3864 position. The way it is we can first look at an iterator's current
3865 display element, decide whether it fits on a line, and if it does,
3866 increment the iterator position. The other way around we probably
3867 would either need a flag indicating whether the iterator has to be
3868 incremented the next time, or we would have to implement a
3869 decrement position function which would not be easy to write. */
3872 set_iterator_to_next (it
, reseat_p
)
3876 /* Reset flags indicating start and end of a sequence of characters
3877 with box. Reset them at the start of this function because
3878 moving the iterator to a new position might set them. */
3879 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3881 if (it
->method
== next_element_from_buffer
)
3883 /* The current display element of IT is a character from
3884 current_buffer. Advance in the buffer, and maybe skip over
3885 invisible lines that are so because of selective display. */
3886 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
3887 reseat_at_next_visible_line_start (it
, 0);
3890 xassert (it
->len
!= 0);
3891 IT_BYTEPOS (*it
) += it
->len
;
3892 IT_CHARPOS (*it
) += 1;
3893 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3896 else if (it
->method
== next_element_from_composition
)
3898 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
3899 if (STRINGP (it
->string
))
3901 IT_STRING_BYTEPOS (*it
) += it
->len
;
3902 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
3903 it
->method
= next_element_from_string
;
3904 goto consider_string_end
;
3908 IT_BYTEPOS (*it
) += it
->len
;
3909 IT_CHARPOS (*it
) += it
->cmp_len
;
3910 it
->method
= next_element_from_buffer
;
3913 else if (it
->method
== next_element_from_c_string
)
3915 /* Current display element of IT is from a C string. */
3916 IT_BYTEPOS (*it
) += it
->len
;
3917 IT_CHARPOS (*it
) += 1;
3919 else if (it
->method
== next_element_from_display_vector
)
3921 /* Current display element of IT is from a display table entry.
3922 Advance in the display table definition. Reset it to null if
3923 end reached, and continue with characters from buffers/
3925 ++it
->current
.dpvec_index
;
3927 /* Restore face of the iterator to what they were before the
3928 display vector entry (these entries may contain faces). */
3929 it
->face_id
= it
->saved_face_id
;
3931 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3934 it
->method
= next_element_from_c_string
;
3935 else if (STRINGP (it
->string
))
3936 it
->method
= next_element_from_string
;
3938 it
->method
= next_element_from_buffer
;
3941 it
->current
.dpvec_index
= -1;
3943 /* Skip over characters which were displayed via IT->dpvec. */
3944 if (it
->dpvec_char_len
< 0)
3945 reseat_at_next_visible_line_start (it
, 1);
3946 else if (it
->dpvec_char_len
> 0)
3948 it
->len
= it
->dpvec_char_len
;
3949 set_iterator_to_next (it
, reseat_p
);
3953 else if (it
->method
== next_element_from_string
)
3955 /* Current display element is a character from a Lisp string. */
3956 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3957 IT_STRING_BYTEPOS (*it
) += it
->len
;
3958 IT_STRING_CHARPOS (*it
) += 1;
3960 consider_string_end
:
3962 if (it
->current
.overlay_string_index
>= 0)
3964 /* IT->string is an overlay string. Advance to the
3965 next, if there is one. */
3966 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3967 next_overlay_string (it
);
3971 /* IT->string is not an overlay string. If we reached
3972 its end, and there is something on IT->stack, proceed
3973 with what is on the stack. This can be either another
3974 string, this time an overlay string, or a buffer. */
3975 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3979 if (!STRINGP (it
->string
))
3980 it
->method
= next_element_from_buffer
;
3984 else if (it
->method
== next_element_from_image
3985 || it
->method
== next_element_from_stretch
)
3987 /* The position etc with which we have to proceed are on
3988 the stack. The position may be at the end of a string,
3989 if the `display' property takes up the whole string. */
3992 if (STRINGP (it
->string
))
3994 it
->method
= next_element_from_string
;
3995 goto consider_string_end
;
3998 it
->method
= next_element_from_buffer
;
4001 /* There are no other methods defined, so this should be a bug. */
4004 xassert (it
->method
!= next_element_from_string
4005 || (STRINGP (it
->string
)
4006 && IT_STRING_CHARPOS (*it
) >= 0));
4010 /* Load IT's display element fields with information about the next
4011 display element which comes from a display table entry or from the
4012 result of translating a control character to one of the forms `^C'
4013 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4016 next_element_from_display_vector (it
)
4020 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4022 /* Remember the current face id in case glyphs specify faces.
4023 IT's face is restored in set_iterator_to_next. */
4024 it
->saved_face_id
= it
->face_id
;
4026 if (INTEGERP (*it
->dpvec
)
4027 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4032 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4033 it
->c
= FAST_GLYPH_CHAR (g
);
4034 it
->len
= CHAR_BYTES (it
->c
);
4036 /* The entry may contain a face id to use. Such a face id is
4037 the id of a Lisp face, not a realized face. A face id of
4038 zero means no face is specified. */
4039 lface_id
= FAST_GLYPH_FACE (g
);
4042 /* The function returns -1 if lface_id is invalid. */
4043 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4045 it
->face_id
= face_id
;
4049 /* Display table entry is invalid. Return a space. */
4050 it
->c
= ' ', it
->len
= 1;
4052 /* Don't change position and object of the iterator here. They are
4053 still the values of the character that had this display table
4054 entry or was translated, and that's what we want. */
4055 it
->what
= IT_CHARACTER
;
4060 /* Load IT with the next display element from Lisp string IT->string.
4061 IT->current.string_pos is the current position within the string.
4062 If IT->current.overlay_string_index >= 0, the Lisp string is an
4066 next_element_from_string (it
)
4069 struct text_pos position
;
4071 xassert (STRINGP (it
->string
));
4072 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4073 position
= it
->current
.string_pos
;
4075 /* Time to check for invisible text? */
4076 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4077 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4081 /* Since a handler may have changed IT->method, we must
4083 return get_next_display_element (it
);
4086 if (it
->current
.overlay_string_index
>= 0)
4088 /* Get the next character from an overlay string. In overlay
4089 strings, There is no field width or padding with spaces to
4091 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4096 else if (STRING_MULTIBYTE (it
->string
))
4098 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4099 - IT_STRING_BYTEPOS (*it
));
4100 unsigned char *s
= (XSTRING (it
->string
)->data
4101 + IT_STRING_BYTEPOS (*it
));
4102 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4106 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4112 /* Get the next character from a Lisp string that is not an
4113 overlay string. Such strings come from the mode line, for
4114 example. We may have to pad with spaces, or truncate the
4115 string. See also next_element_from_c_string. */
4116 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4121 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4123 /* Pad with spaces. */
4124 it
->c
= ' ', it
->len
= 1;
4125 CHARPOS (position
) = BYTEPOS (position
) = -1;
4127 else if (STRING_MULTIBYTE (it
->string
))
4129 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4130 - IT_STRING_BYTEPOS (*it
));
4131 unsigned char *s
= (XSTRING (it
->string
)->data
4132 + IT_STRING_BYTEPOS (*it
));
4133 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4137 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4142 /* Record what we have and where it came from. Note that we store a
4143 buffer position in IT->position although it could arguably be a
4145 it
->what
= IT_CHARACTER
;
4146 it
->object
= it
->string
;
4147 it
->position
= position
;
4152 /* Load IT with next display element from C string IT->s.
4153 IT->string_nchars is the maximum number of characters to return
4154 from the string. IT->end_charpos may be greater than
4155 IT->string_nchars when this function is called, in which case we
4156 may have to return padding spaces. Value is zero if end of string
4157 reached, including padding spaces. */
4160 next_element_from_c_string (it
)
4166 it
->what
= IT_CHARACTER
;
4167 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4170 /* IT's position can be greater IT->string_nchars in case a field
4171 width or precision has been specified when the iterator was
4173 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4175 /* End of the game. */
4179 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4181 /* Pad with spaces. */
4182 it
->c
= ' ', it
->len
= 1;
4183 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4185 else if (it
->multibyte_p
)
4187 /* Implementation note: The calls to strlen apparently aren't a
4188 performance problem because there is no noticeable performance
4189 difference between Emacs running in unibyte or multibyte mode. */
4190 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4191 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4195 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4201 /* Set up IT to return characters from an ellipsis, if appropriate.
4202 The definition of the ellipsis glyphs may come from a display table
4203 entry. This function Fills IT with the first glyph from the
4204 ellipsis if an ellipsis is to be displayed. */
4207 next_element_from_ellipsis (it
)
4210 if (it
->selective_display_ellipsis_p
)
4212 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4214 /* Use the display table definition for `...'. Invalid glyphs
4215 will be handled by the method returning elements from dpvec. */
4216 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4217 it
->dpvec_char_len
= it
->len
;
4218 it
->dpvec
= v
->contents
;
4219 it
->dpend
= v
->contents
+ v
->size
;
4220 it
->current
.dpvec_index
= 0;
4221 it
->method
= next_element_from_display_vector
;
4225 /* Use default `...' which is stored in default_invis_vector. */
4226 it
->dpvec_char_len
= it
->len
;
4227 it
->dpvec
= default_invis_vector
;
4228 it
->dpend
= default_invis_vector
+ 3;
4229 it
->current
.dpvec_index
= 0;
4230 it
->method
= next_element_from_display_vector
;
4235 it
->method
= next_element_from_buffer
;
4236 reseat_at_next_visible_line_start (it
, 1);
4239 return get_next_display_element (it
);
4243 /* Deliver an image display element. The iterator IT is already
4244 filled with image information (done in handle_display_prop). Value
4249 next_element_from_image (it
)
4252 it
->what
= IT_IMAGE
;
4257 /* Fill iterator IT with next display element from a stretch glyph
4258 property. IT->object is the value of the text property. Value is
4262 next_element_from_stretch (it
)
4265 it
->what
= IT_STRETCH
;
4270 /* Load IT with the next display element from current_buffer. Value
4271 is zero if end of buffer reached. IT->stop_charpos is the next
4272 position at which to stop and check for text properties or buffer
4276 next_element_from_buffer (it
)
4281 /* Check this assumption, otherwise, we would never enter the
4282 if-statement, below. */
4283 xassert (IT_CHARPOS (*it
) >= BEGV
4284 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4286 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4288 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4290 int overlay_strings_follow_p
;
4292 /* End of the game, except when overlay strings follow that
4293 haven't been returned yet. */
4294 if (it
->overlay_strings_at_end_processed_p
)
4295 overlay_strings_follow_p
= 0;
4298 it
->overlay_strings_at_end_processed_p
= 1;
4299 overlay_strings_follow_p
= get_overlay_strings (it
);
4302 if (overlay_strings_follow_p
)
4303 success_p
= get_next_display_element (it
);
4307 it
->position
= it
->current
.pos
;
4314 return get_next_display_element (it
);
4319 /* No face changes, overlays etc. in sight, so just return a
4320 character from current_buffer. */
4323 /* Maybe run the redisplay end trigger hook. Performance note:
4324 This doesn't seem to cost measurable time. */
4325 if (it
->redisplay_end_trigger_charpos
4327 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4328 run_redisplay_end_trigger_hook (it
);
4330 /* Get the next character, maybe multibyte. */
4331 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4332 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4334 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4335 - IT_BYTEPOS (*it
));
4336 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4339 it
->c
= *p
, it
->len
= 1;
4341 /* Record what we have and where it came from. */
4342 it
->what
= IT_CHARACTER
;;
4343 it
->object
= it
->w
->buffer
;
4344 it
->position
= it
->current
.pos
;
4346 /* Normally we return the character found above, except when we
4347 really want to return an ellipsis for selective display. */
4352 /* A value of selective > 0 means hide lines indented more
4353 than that number of columns. */
4354 if (it
->selective
> 0
4355 && IT_CHARPOS (*it
) + 1 < ZV
4356 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4357 IT_BYTEPOS (*it
) + 1,
4360 success_p
= next_element_from_ellipsis (it
);
4361 it
->dpvec_char_len
= -1;
4364 else if (it
->c
== '\r' && it
->selective
== -1)
4366 /* A value of selective == -1 means that everything from the
4367 CR to the end of the line is invisible, with maybe an
4368 ellipsis displayed for it. */
4369 success_p
= next_element_from_ellipsis (it
);
4370 it
->dpvec_char_len
= -1;
4375 /* Value is zero if end of buffer reached. */
4376 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4381 /* Run the redisplay end trigger hook for IT. */
4384 run_redisplay_end_trigger_hook (it
)
4387 Lisp_Object args
[3];
4389 /* IT->glyph_row should be non-null, i.e. we should be actually
4390 displaying something, or otherwise we should not run the hook. */
4391 xassert (it
->glyph_row
);
4393 /* Set up hook arguments. */
4394 args
[0] = Qredisplay_end_trigger_functions
;
4395 args
[1] = it
->window
;
4396 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4397 it
->redisplay_end_trigger_charpos
= 0;
4399 /* Since we are *trying* to run these functions, don't try to run
4400 them again, even if they get an error. */
4401 it
->w
->redisplay_end_trigger
= Qnil
;
4402 Frun_hook_with_args (3, args
);
4404 /* Notice if it changed the face of the character we are on. */
4405 handle_face_prop (it
);
4409 /* Deliver a composition display element. The iterator IT is already
4410 filled with composition information (done in
4411 handle_composition_prop). Value is always 1. */
4414 next_element_from_composition (it
)
4417 it
->what
= IT_COMPOSITION
;
4418 it
->position
= (STRINGP (it
->string
)
4419 ? it
->current
.string_pos
4426 /***********************************************************************
4427 Moving an iterator without producing glyphs
4428 ***********************************************************************/
4430 /* Move iterator IT to a specified buffer or X position within one
4431 line on the display without producing glyphs.
4433 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4434 whichever is reached first.
4436 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4438 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4439 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4440 TO_X includes the amount by which a window is horizontally
4445 MOVE_POS_MATCH_OR_ZV
4446 - when TO_POS or ZV was reached.
4449 -when TO_X was reached before TO_POS or ZV were reached.
4452 - when we reached the end of the display area and the line must
4456 - when we reached the end of the display area and the line is
4460 - when we stopped at a line end, i.e. a newline or a CR and selective
4463 static enum move_it_result
4464 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4466 int to_charpos
, to_x
, op
;
4468 enum move_it_result result
= MOVE_UNDEFINED
;
4469 struct glyph_row
*saved_glyph_row
;
4471 /* Don't produce glyphs in produce_glyphs. */
4472 saved_glyph_row
= it
->glyph_row
;
4473 it
->glyph_row
= NULL
;
4477 int x
, i
, ascent
= 0, descent
= 0;
4479 /* Stop when ZV or TO_CHARPOS reached. */
4480 if (!get_next_display_element (it
)
4481 || ((op
& MOVE_TO_POS
) != 0
4482 && BUFFERP (it
->object
)
4483 && IT_CHARPOS (*it
) >= to_charpos
))
4485 result
= MOVE_POS_MATCH_OR_ZV
;
4489 /* The call to produce_glyphs will get the metrics of the
4490 display element IT is loaded with. We record in x the
4491 x-position before this display element in case it does not
4495 /* Remember the line height so far in case the next element doesn't
4497 if (!it
->truncate_lines_p
)
4499 ascent
= it
->max_ascent
;
4500 descent
= it
->max_descent
;
4503 PRODUCE_GLYPHS (it
);
4505 if (it
->area
!= TEXT_AREA
)
4507 set_iterator_to_next (it
, 1);
4511 /* The number of glyphs we get back in IT->nglyphs will normally
4512 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4513 character on a terminal frame, or (iii) a line end. For the
4514 second case, IT->nglyphs - 1 padding glyphs will be present
4515 (on X frames, there is only one glyph produced for a
4516 composite character.
4518 The behavior implemented below means, for continuation lines,
4519 that as many spaces of a TAB as fit on the current line are
4520 displayed there. For terminal frames, as many glyphs of a
4521 multi-glyph character are displayed in the current line, too.
4522 This is what the old redisplay code did, and we keep it that
4523 way. Under X, the whole shape of a complex character must
4524 fit on the line or it will be completely displayed in the
4527 Note that both for tabs and padding glyphs, all glyphs have
4531 /* More than one glyph or glyph doesn't fit on line. All
4532 glyphs have the same width. */
4533 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4536 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4538 new_x
= x
+ single_glyph_width
;
4540 /* We want to leave anything reaching TO_X to the caller. */
4541 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4544 result
= MOVE_X_REACHED
;
4547 else if (/* Lines are continued. */
4548 !it
->truncate_lines_p
4549 && (/* And glyph doesn't fit on the line. */
4550 new_x
> it
->last_visible_x
4551 /* Or it fits exactly and we're on a window
4553 || (new_x
== it
->last_visible_x
4554 && FRAME_WINDOW_P (it
->f
))))
4556 if (/* IT->hpos == 0 means the very first glyph
4557 doesn't fit on the line, e.g. a wide image. */
4559 || (new_x
== it
->last_visible_x
4560 && FRAME_WINDOW_P (it
->f
)))
4563 it
->current_x
= new_x
;
4564 if (i
== it
->nglyphs
- 1)
4565 set_iterator_to_next (it
, 1);
4570 it
->max_ascent
= ascent
;
4571 it
->max_descent
= descent
;
4574 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
4576 result
= MOVE_LINE_CONTINUED
;
4579 else if (new_x
> it
->first_visible_x
)
4581 /* Glyph is visible. Increment number of glyphs that
4582 would be displayed. */
4587 /* Glyph is completely off the left margin of the display
4588 area. Nothing to do. */
4592 if (result
!= MOVE_UNDEFINED
)
4595 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4597 /* Stop when TO_X specified and reached. This check is
4598 necessary here because of lines consisting of a line end,
4599 only. The line end will not produce any glyphs and we
4600 would never get MOVE_X_REACHED. */
4601 xassert (it
->nglyphs
== 0);
4602 result
= MOVE_X_REACHED
;
4606 /* Is this a line end? If yes, we're done. */
4607 if (ITERATOR_AT_END_OF_LINE_P (it
))
4609 result
= MOVE_NEWLINE_OR_CR
;
4613 /* The current display element has been consumed. Advance
4615 set_iterator_to_next (it
, 1);
4617 /* Stop if lines are truncated and IT's current x-position is
4618 past the right edge of the window now. */
4619 if (it
->truncate_lines_p
4620 && it
->current_x
>= it
->last_visible_x
)
4622 result
= MOVE_LINE_TRUNCATED
;
4627 /* Restore the iterator settings altered at the beginning of this
4629 it
->glyph_row
= saved_glyph_row
;
4634 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4635 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4636 the description of enum move_operation_enum.
4638 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4639 screen line, this function will set IT to the next position >
4643 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4645 int to_charpos
, to_x
, to_y
, to_vpos
;
4648 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4654 if (op
& MOVE_TO_VPOS
)
4656 /* If no TO_CHARPOS and no TO_X specified, stop at the
4657 start of the line TO_VPOS. */
4658 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4660 if (it
->vpos
== to_vpos
)
4666 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4670 /* TO_VPOS >= 0 means stop at TO_X in the line at
4671 TO_VPOS, or at TO_POS, whichever comes first. */
4672 if (it
->vpos
== to_vpos
)
4678 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4680 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4685 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4687 /* We have reached TO_X but not in the line we want. */
4688 skip
= move_it_in_display_line_to (it
, to_charpos
,
4690 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4698 else if (op
& MOVE_TO_Y
)
4700 struct it it_backup
;
4702 /* TO_Y specified means stop at TO_X in the line containing
4703 TO_Y---or at TO_CHARPOS if this is reached first. The
4704 problem is that we can't really tell whether the line
4705 contains TO_Y before we have completely scanned it, and
4706 this may skip past TO_X. What we do is to first scan to
4709 If TO_X is not specified, use a TO_X of zero. The reason
4710 is to make the outcome of this function more predictable.
4711 If we didn't use TO_X == 0, we would stop at the end of
4712 the line which is probably not what a caller would expect
4714 skip
= move_it_in_display_line_to (it
, to_charpos
,
4718 | (op
& MOVE_TO_POS
)));
4720 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4721 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4727 /* If TO_X was reached, we would like to know whether TO_Y
4728 is in the line. This can only be said if we know the
4729 total line height which requires us to scan the rest of
4731 if (skip
== MOVE_X_REACHED
)
4734 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
4735 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4737 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
4740 /* Now, decide whether TO_Y is in this line. */
4741 line_height
= it
->max_ascent
+ it
->max_descent
;
4742 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
4744 if (to_y
>= it
->current_y
4745 && to_y
< it
->current_y
+ line_height
)
4747 if (skip
== MOVE_X_REACHED
)
4748 /* If TO_Y is in this line and TO_X was reached above,
4749 we scanned too far. We have to restore IT's settings
4750 to the ones before skipping. */
4754 else if (skip
== MOVE_X_REACHED
)
4757 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4765 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4769 case MOVE_POS_MATCH_OR_ZV
:
4773 case MOVE_NEWLINE_OR_CR
:
4774 set_iterator_to_next (it
, 1);
4775 it
->continuation_lines_width
= 0;
4778 case MOVE_LINE_TRUNCATED
:
4779 it
->continuation_lines_width
= 0;
4780 reseat_at_next_visible_line_start (it
, 0);
4781 if ((op
& MOVE_TO_POS
) != 0
4782 && IT_CHARPOS (*it
) > to_charpos
)
4789 case MOVE_LINE_CONTINUED
:
4790 it
->continuation_lines_width
+= it
->current_x
;
4797 /* Reset/increment for the next run. */
4798 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4799 it
->current_x
= it
->hpos
= 0;
4800 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4802 last_height
= it
->max_ascent
+ it
->max_descent
;
4803 last_max_ascent
= it
->max_ascent
;
4804 it
->max_ascent
= it
->max_descent
= 0;
4809 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
4813 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4815 If DY > 0, move IT backward at least that many pixels. DY = 0
4816 means move IT backward to the preceding line start or BEGV. This
4817 function may move over more than DY pixels if IT->current_y - DY
4818 ends up in the middle of a line; in this case IT->current_y will be
4819 set to the top of the line moved to. */
4822 move_it_vertically_backward (it
, dy
)
4826 int nlines
, h
, line_height
;
4828 int start_pos
= IT_CHARPOS (*it
);
4832 /* Estimate how many newlines we must move back. */
4833 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4835 /* Set the iterator's position that many lines back. */
4836 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4837 back_to_previous_visible_line_start (it
);
4839 /* Reseat the iterator here. When moving backward, we don't want
4840 reseat to skip forward over invisible text, set up the iterator
4841 to deliver from overlay strings at the new position etc. So,
4842 use reseat_1 here. */
4843 reseat_1 (it
, it
->current
.pos
, 1);
4845 /* We are now surely at a line start. */
4846 it
->current_x
= it
->hpos
= 0;
4848 /* Move forward and see what y-distance we moved. First move to the
4849 start of the next line so that we get its height. We need this
4850 height to be able to tell whether we reached the specified
4853 it2
.max_ascent
= it2
.max_descent
= 0;
4854 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4855 MOVE_TO_POS
| MOVE_TO_VPOS
);
4856 xassert (IT_CHARPOS (*it
) >= BEGV
);
4857 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4859 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4860 xassert (IT_CHARPOS (*it
) >= BEGV
);
4861 h
= it2
.current_y
- it
->current_y
;
4862 nlines
= it2
.vpos
- it
->vpos
;
4864 /* Correct IT's y and vpos position. */
4870 /* DY == 0 means move to the start of the screen line. The
4871 value of nlines is > 0 if continuation lines were involved. */
4873 move_it_by_lines (it
, nlines
, 1);
4874 xassert (IT_CHARPOS (*it
) <= start_pos
);
4878 /* The y-position we try to reach. Note that h has been
4879 subtracted in front of the if-statement. */
4880 int target_y
= it
->current_y
+ h
- dy
;
4882 /* If we did not reach target_y, try to move further backward if
4883 we can. If we moved too far backward, try to move forward. */
4884 if (target_y
< it
->current_y
4885 && IT_CHARPOS (*it
) > BEGV
)
4887 move_it_vertically (it
, target_y
- it
->current_y
);
4888 xassert (IT_CHARPOS (*it
) >= BEGV
);
4890 else if (target_y
>= it
->current_y
+ line_height
4891 && IT_CHARPOS (*it
) < ZV
)
4893 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4894 xassert (IT_CHARPOS (*it
) >= BEGV
);
4900 /* Move IT by a specified amount of pixel lines DY. DY negative means
4901 move backwards. DY = 0 means move to start of screen line. At the
4902 end, IT will be on the start of a screen line. */
4905 move_it_vertically (it
, dy
)
4910 move_it_vertically_backward (it
, -dy
);
4913 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
4914 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4915 MOVE_TO_POS
| MOVE_TO_Y
);
4916 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
4918 /* If buffer ends in ZV without a newline, move to the start of
4919 the line to satisfy the post-condition. */
4920 if (IT_CHARPOS (*it
) == ZV
4921 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4922 move_it_by_lines (it
, 0, 0);
4927 /* Return non-zero if some text between buffer positions START_CHARPOS
4928 and END_CHARPOS is invisible. IT->window is the window for text
4932 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4934 int start_charpos
, end_charpos
;
4936 Lisp_Object prop
, limit
;
4937 int invisible_found_p
;
4939 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4941 /* Is text at START invisible? */
4942 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4944 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4945 invisible_found_p
= 1;
4948 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
4950 make_number (end_charpos
));
4951 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4954 return invisible_found_p
;
4958 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4959 negative means move up. DVPOS == 0 means move to the start of the
4960 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4961 NEED_Y_P is zero, IT->current_y will be left unchanged.
4963 Further optimization ideas: If we would know that IT->f doesn't use
4964 a face with proportional font, we could be faster for
4965 truncate-lines nil. */
4968 move_it_by_lines (it
, dvpos
, need_y_p
)
4970 int dvpos
, need_y_p
;
4972 struct position pos
;
4974 if (!FRAME_WINDOW_P (it
->f
))
4976 struct text_pos textpos
;
4978 /* We can use vmotion on frames without proportional fonts. */
4979 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4980 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4981 reseat (it
, textpos
, 1);
4982 it
->vpos
+= pos
.vpos
;
4983 it
->current_y
+= pos
.vpos
;
4985 else if (dvpos
== 0)
4987 /* DVPOS == 0 means move to the start of the screen line. */
4988 move_it_vertically_backward (it
, 0);
4989 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4993 /* If there are no continuation lines, and if there is no
4994 selective display, try the simple method of moving forward
4995 DVPOS newlines, then see where we are. */
4996 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4998 int shortage
= 0, charpos
;
5000 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
5001 charpos
= IT_CHARPOS (*it
) + 1;
5003 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
5006 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
5008 struct text_pos pos
;
5009 CHARPOS (pos
) = charpos
;
5010 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
5011 reseat (it
, pos
, 1);
5012 it
->vpos
+= dvpos
- shortage
;
5013 it
->hpos
= it
->current_x
= 0;
5018 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5023 int start_charpos
, i
;
5025 /* If there are no continuation lines, and if there is no
5026 selective display, try the simple method of moving backward
5028 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
5031 int charpos
= IT_CHARPOS (*it
);
5032 int bytepos
= IT_BYTEPOS (*it
);
5034 /* If in the middle of a line, go to its start. */
5035 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
5037 charpos
= find_next_newline_no_quit (charpos
, -1);
5038 bytepos
= CHAR_TO_BYTE (charpos
);
5041 if (charpos
== BEGV
)
5043 struct text_pos pos
;
5044 CHARPOS (pos
) = charpos
;
5045 BYTEPOS (pos
) = bytepos
;
5046 reseat (it
, pos
, 1);
5047 it
->hpos
= it
->current_x
= 0;
5052 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
5053 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
5055 struct text_pos pos
;
5056 CHARPOS (pos
) = charpos
;
5057 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
5058 reseat (it
, pos
, 1);
5059 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
5060 it
->hpos
= it
->current_x
= 0;
5066 /* Go back -DVPOS visible lines and reseat the iterator there. */
5067 start_charpos
= IT_CHARPOS (*it
);
5068 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5069 back_to_previous_visible_line_start (it
);
5070 reseat (it
, it
->current
.pos
, 1);
5071 it
->current_x
= it
->hpos
= 0;
5073 /* Above call may have moved too far if continuation lines
5074 are involved. Scan forward and see if it did. */
5076 it2
.vpos
= it2
.current_y
= 0;
5077 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5078 it
->vpos
-= it2
.vpos
;
5079 it
->current_y
-= it2
.current_y
;
5080 it
->current_x
= it
->hpos
= 0;
5082 /* If we moved too far, move IT some lines forward. */
5083 if (it2
.vpos
> -dvpos
)
5085 int delta
= it2
.vpos
+ dvpos
;
5086 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5093 /***********************************************************************
5095 ***********************************************************************/
5098 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5102 add_to_log (format
, arg1
, arg2
)
5104 Lisp_Object arg1
, arg2
;
5106 Lisp_Object args
[3];
5107 Lisp_Object msg
, fmt
;
5110 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5113 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5115 args
[0] = fmt
= build_string (format
);
5118 msg
= Fformat (3, args
);
5120 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5121 buffer
= (char *) alloca (len
);
5122 strcpy (buffer
, XSTRING (msg
)->data
);
5124 message_dolog (buffer
, len
- 1, 1, 0);
5129 /* Output a newline in the *Messages* buffer if "needs" one. */
5132 message_log_maybe_newline ()
5134 if (message_log_need_newline
)
5135 message_dolog ("", 0, 1, 0);
5139 /* Add a string M of length LEN to the message log, optionally
5140 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5141 nonzero, means interpret the contents of M as multibyte. This
5142 function calls low-level routines in order to bypass text property
5143 hooks, etc. which might not be safe to run. */
5146 message_dolog (m
, len
, nlflag
, multibyte
)
5148 int len
, nlflag
, multibyte
;
5150 if (!NILP (Vmessage_log_max
))
5152 struct buffer
*oldbuf
;
5153 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5154 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5155 int point_at_end
= 0;
5157 Lisp_Object old_deactivate_mark
, tem
;
5158 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5160 old_deactivate_mark
= Vdeactivate_mark
;
5161 oldbuf
= current_buffer
;
5162 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5163 current_buffer
->undo_list
= Qt
;
5165 oldpoint
= Fpoint_marker ();
5166 oldbegv
= Fpoint_min_marker ();
5167 oldzv
= Fpoint_max_marker ();
5168 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5176 BEGV_BYTE
= BEG_BYTE
;
5179 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5181 /* Insert the string--maybe converting multibyte to single byte
5182 or vice versa, so that all the text fits the buffer. */
5184 && NILP (current_buffer
->enable_multibyte_characters
))
5187 unsigned char work
[1];
5189 /* Convert a multibyte string to single-byte
5190 for the *Message* buffer. */
5191 for (i
= 0; i
< len
; i
+= nbytes
)
5193 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
5194 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5196 : multibyte_char_to_unibyte (c
, Qnil
));
5197 insert_1_both (work
, 1, 1, 1, 0, 0);
5200 else if (! multibyte
5201 && ! NILP (current_buffer
->enable_multibyte_characters
))
5204 unsigned char *msg
= (unsigned char *) m
;
5205 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5206 /* Convert a single-byte string to multibyte
5207 for the *Message* buffer. */
5208 for (i
= 0; i
< len
; i
++)
5210 c
= unibyte_char_to_multibyte (msg
[i
]);
5211 nbytes
= CHAR_STRING (c
, str
);
5212 insert_1_both (str
, 1, nbytes
, 1, 0, 0);
5216 insert_1 (m
, len
, 1, 0, 0);
5220 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5221 insert_1 ("\n", 1, 1, 0, 0);
5223 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5225 this_bol_byte
= PT_BYTE
;
5229 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5231 prev_bol_byte
= PT_BYTE
;
5233 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5234 this_bol
, this_bol_byte
);
5237 del_range_both (prev_bol
, prev_bol_byte
,
5238 this_bol
, this_bol_byte
, 0);
5244 /* If you change this format, don't forget to also
5245 change message_log_check_duplicate. */
5246 sprintf (dupstr
, " [%d times]", dup
);
5247 duplen
= strlen (dupstr
);
5248 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5249 insert_1 (dupstr
, duplen
, 1, 0, 1);
5254 if (NATNUMP (Vmessage_log_max
))
5256 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5257 -XFASTINT (Vmessage_log_max
) - 1, 0);
5258 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5261 BEGV
= XMARKER (oldbegv
)->charpos
;
5262 BEGV_BYTE
= marker_byte_position (oldbegv
);
5271 ZV
= XMARKER (oldzv
)->charpos
;
5272 ZV_BYTE
= marker_byte_position (oldzv
);
5276 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5278 /* We can't do Fgoto_char (oldpoint) because it will run some
5280 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5281 XMARKER (oldpoint
)->bytepos
);
5284 free_marker (oldpoint
);
5285 free_marker (oldbegv
);
5286 free_marker (oldzv
);
5288 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5289 set_buffer_internal (oldbuf
);
5291 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5292 message_log_need_newline
= !nlflag
;
5293 Vdeactivate_mark
= old_deactivate_mark
;
5298 /* We are at the end of the buffer after just having inserted a newline.
5299 (Note: We depend on the fact we won't be crossing the gap.)
5300 Check to see if the most recent message looks a lot like the previous one.
5301 Return 0 if different, 1 if the new one should just replace it, or a
5302 value N > 1 if we should also append " [N times]". */
5305 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5306 int prev_bol
, this_bol
;
5307 int prev_bol_byte
, this_bol_byte
;
5310 int len
= Z_BYTE
- 1 - this_bol_byte
;
5312 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5313 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5315 for (i
= 0; i
< len
; i
++)
5317 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
5326 if (*p1
++ == ' ' && *p1
++ == '[')
5329 while (*p1
>= '0' && *p1
<= '9')
5330 n
= n
* 10 + *p1
++ - '0';
5331 if (strncmp (p1
, " times]\n", 8) == 0)
5338 /* Display an echo area message M with a specified length of LEN
5339 chars. The string may include null characters. If M is 0, clear
5340 out any existing message, and let the mini-buffer text show through.
5342 The buffer M must continue to exist until after the echo area gets
5343 cleared or some other message gets displayed there. This means do
5344 not pass text that is stored in a Lisp string; do not pass text in
5345 a buffer that was alloca'd. */
5348 message2 (m
, len
, multibyte
)
5353 /* First flush out any partial line written with print. */
5354 message_log_maybe_newline ();
5356 message_dolog (m
, len
, 1, multibyte
);
5357 message2_nolog (m
, len
, multibyte
);
5361 /* The non-logging counterpart of message2. */
5364 message2_nolog (m
, len
, multibyte
)
5368 struct frame
*sf
= SELECTED_FRAME ();
5369 message_enable_multibyte
= multibyte
;
5373 if (noninteractive_need_newline
)
5374 putc ('\n', stderr
);
5375 noninteractive_need_newline
= 0;
5377 fwrite (m
, len
, 1, stderr
);
5378 if (cursor_in_echo_area
== 0)
5379 fprintf (stderr
, "\n");
5382 /* A null message buffer means that the frame hasn't really been
5383 initialized yet. Error messages get reported properly by
5384 cmd_error, so this must be just an informative message; toss it. */
5385 else if (INTERACTIVE
5386 && sf
->glyphs_initialized_p
5387 && FRAME_MESSAGE_BUF (sf
))
5389 Lisp_Object mini_window
;
5392 /* Get the frame containing the mini-buffer
5393 that the selected frame is using. */
5394 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5395 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5397 FRAME_SAMPLE_VISIBILITY (f
);
5398 if (FRAME_VISIBLE_P (sf
)
5399 && ! FRAME_VISIBLE_P (f
))
5400 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5404 set_message (m
, Qnil
, len
, multibyte
);
5405 if (minibuffer_auto_raise
)
5406 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5409 clear_message (1, 1);
5411 do_pending_window_change (0);
5412 echo_area_display (1);
5413 do_pending_window_change (0);
5414 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5415 (*frame_up_to_date_hook
) (f
);
5420 /* Display an echo area message M with a specified length of NBYTES
5421 bytes. The string may include null characters. If M is not a
5422 string, clear out any existing message, and let the mini-buffer
5423 text show through. */
5426 message3 (m
, nbytes
, multibyte
)
5431 struct gcpro gcpro1
;
5435 /* First flush out any partial line written with print. */
5436 message_log_maybe_newline ();
5438 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5439 message3_nolog (m
, nbytes
, multibyte
);
5445 /* The non-logging version of message3. */
5448 message3_nolog (m
, nbytes
, multibyte
)
5450 int nbytes
, multibyte
;
5452 struct frame
*sf
= SELECTED_FRAME ();
5453 message_enable_multibyte
= multibyte
;
5457 if (noninteractive_need_newline
)
5458 putc ('\n', stderr
);
5459 noninteractive_need_newline
= 0;
5461 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5462 if (cursor_in_echo_area
== 0)
5463 fprintf (stderr
, "\n");
5466 /* A null message buffer means that the frame hasn't really been
5467 initialized yet. Error messages get reported properly by
5468 cmd_error, so this must be just an informative message; toss it. */
5469 else if (INTERACTIVE
5470 && sf
->glyphs_initialized_p
5471 && FRAME_MESSAGE_BUF (sf
))
5473 Lisp_Object mini_window
;
5477 /* Get the frame containing the mini-buffer
5478 that the selected frame is using. */
5479 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5480 frame
= XWINDOW (mini_window
)->frame
;
5483 FRAME_SAMPLE_VISIBILITY (f
);
5484 if (FRAME_VISIBLE_P (sf
)
5485 && !FRAME_VISIBLE_P (f
))
5486 Fmake_frame_visible (frame
);
5488 if (STRINGP (m
) && XSTRING (m
)->size
)
5490 set_message (NULL
, m
, nbytes
, multibyte
);
5491 if (minibuffer_auto_raise
)
5492 Fraise_frame (frame
);
5495 clear_message (1, 1);
5497 do_pending_window_change (0);
5498 echo_area_display (1);
5499 do_pending_window_change (0);
5500 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5501 (*frame_up_to_date_hook
) (f
);
5506 /* Display a null-terminated echo area message M. If M is 0, clear
5507 out any existing message, and let the mini-buffer text show through.
5509 The buffer M must continue to exist until after the echo area gets
5510 cleared or some other message gets displayed there. Do not pass
5511 text that is stored in a Lisp string. Do not pass text in a buffer
5512 that was alloca'd. */
5518 message2 (m
, (m
? strlen (m
) : 0), 0);
5522 /* The non-logging counterpart of message1. */
5528 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5531 /* Display a message M which contains a single %s
5532 which gets replaced with STRING. */
5535 message_with_string (m
, string
, log
)
5544 if (noninteractive_need_newline
)
5545 putc ('\n', stderr
);
5546 noninteractive_need_newline
= 0;
5547 fprintf (stderr
, m
, XSTRING (string
)->data
);
5548 if (cursor_in_echo_area
== 0)
5549 fprintf (stderr
, "\n");
5553 else if (INTERACTIVE
)
5555 /* The frame whose minibuffer we're going to display the message on.
5556 It may be larger than the selected frame, so we need
5557 to use its buffer, not the selected frame's buffer. */
5558 Lisp_Object mini_window
;
5559 struct frame
*f
, *sf
= SELECTED_FRAME ();
5561 /* Get the frame containing the minibuffer
5562 that the selected frame is using. */
5563 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5564 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5566 /* A null message buffer means that the frame hasn't really been
5567 initialized yet. Error messages get reported properly by
5568 cmd_error, so this must be just an informative message; toss it. */
5569 if (FRAME_MESSAGE_BUF (f
))
5573 a
[0] = (char *) XSTRING (string
)->data
;
5575 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5576 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5579 message2 (FRAME_MESSAGE_BUF (f
), len
,
5580 STRING_MULTIBYTE (string
));
5582 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5583 STRING_MULTIBYTE (string
));
5585 /* Print should start at the beginning of the message
5586 buffer next time. */
5587 message_buf_print
= 0;
5593 /* Dump an informative message to the minibuf. If M is 0, clear out
5594 any existing message, and let the mini-buffer text show through. */
5598 message (m
, a1
, a2
, a3
)
5600 EMACS_INT a1
, a2
, a3
;
5606 if (noninteractive_need_newline
)
5607 putc ('\n', stderr
);
5608 noninteractive_need_newline
= 0;
5609 fprintf (stderr
, m
, a1
, a2
, a3
);
5610 if (cursor_in_echo_area
== 0)
5611 fprintf (stderr
, "\n");
5615 else if (INTERACTIVE
)
5617 /* The frame whose mini-buffer we're going to display the message
5618 on. It may be larger than the selected frame, so we need to
5619 use its buffer, not the selected frame's buffer. */
5620 Lisp_Object mini_window
;
5621 struct frame
*f
, *sf
= SELECTED_FRAME ();
5623 /* Get the frame containing the mini-buffer
5624 that the selected frame is using. */
5625 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5626 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5628 /* A null message buffer means that the frame hasn't really been
5629 initialized yet. Error messages get reported properly by
5630 cmd_error, so this must be just an informative message; toss
5632 if (FRAME_MESSAGE_BUF (f
))
5643 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5644 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5646 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5647 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5649 #endif /* NO_ARG_ARRAY */
5651 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5656 /* Print should start at the beginning of the message
5657 buffer next time. */
5658 message_buf_print
= 0;
5664 /* The non-logging version of message. */
5667 message_nolog (m
, a1
, a2
, a3
)
5669 EMACS_INT a1
, a2
, a3
;
5671 Lisp_Object old_log_max
;
5672 old_log_max
= Vmessage_log_max
;
5673 Vmessage_log_max
= Qnil
;
5674 message (m
, a1
, a2
, a3
);
5675 Vmessage_log_max
= old_log_max
;
5679 /* Display the current message in the current mini-buffer. This is
5680 only called from error handlers in process.c, and is not time
5686 if (!NILP (echo_area_buffer
[0]))
5689 string
= Fcurrent_message ();
5690 message3 (string
, XSTRING (string
)->size
,
5691 !NILP (current_buffer
->enable_multibyte_characters
));
5696 /* Make sure echo area buffers in echo_buffers[] are life. If they
5697 aren't, make new ones. */
5700 ensure_echo_area_buffers ()
5704 for (i
= 0; i
< 2; ++i
)
5705 if (!BUFFERP (echo_buffer
[i
])
5706 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5709 Lisp_Object old_buffer
;
5712 old_buffer
= echo_buffer
[i
];
5713 sprintf (name
, " *Echo Area %d*", i
);
5714 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5715 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
5717 for (j
= 0; j
< 2; ++j
)
5718 if (EQ (old_buffer
, echo_area_buffer
[j
]))
5719 echo_area_buffer
[j
] = echo_buffer
[i
];
5724 /* Call FN with args A1..A4 with either the current or last displayed
5725 echo_area_buffer as current buffer.
5727 WHICH zero means use the current message buffer
5728 echo_area_buffer[0]. If that is nil, choose a suitable buffer
5729 from echo_buffer[] and clear it.
5731 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
5732 suitable buffer from echo_buffer[] and clear it.
5734 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
5735 that the current message becomes the last displayed one, make
5736 choose a suitable buffer for echo_area_buffer[0], and clear it.
5738 Value is what FN returns. */
5741 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
5744 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
5750 int this_one
, the_other
, clear_buffer_p
, rc
;
5751 int count
= specpdl_ptr
- specpdl
;
5753 /* If buffers aren't life, make new ones. */
5754 ensure_echo_area_buffers ();
5759 this_one
= 0, the_other
= 1;
5761 this_one
= 1, the_other
= 0;
5764 this_one
= 0, the_other
= 1;
5767 /* We need a fresh one in case the current echo buffer equals
5768 the one containing the last displayed echo area message. */
5769 if (!NILP (echo_area_buffer
[this_one
])
5770 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
5771 echo_area_buffer
[this_one
] = Qnil
;
5774 /* Choose a suitable buffer from echo_buffer[] is we don't
5776 if (NILP (echo_area_buffer
[this_one
]))
5778 echo_area_buffer
[this_one
]
5779 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
5780 ? echo_buffer
[the_other
]
5781 : echo_buffer
[this_one
]);
5785 buffer
= echo_area_buffer
[this_one
];
5787 record_unwind_protect (unwind_with_echo_area_buffer
,
5788 with_echo_area_buffer_unwind_data (w
));
5790 /* Make the echo area buffer current. Note that for display
5791 purposes, it is not necessary that the displayed window's buffer
5792 == current_buffer, except for text property lookup. So, let's
5793 only set that buffer temporarily here without doing a full
5794 Fset_window_buffer. We must also change w->pointm, though,
5795 because otherwise an assertions in unshow_buffer fails, and Emacs
5797 set_buffer_internal_1 (XBUFFER (buffer
));
5801 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
5804 current_buffer
->undo_list
= Qt
;
5805 current_buffer
->read_only
= Qnil
;
5807 if (clear_buffer_p
&& Z
> BEG
)
5810 xassert (BEGV
>= BEG
);
5811 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5813 rc
= fn (a1
, a2
, a3
, a4
);
5815 xassert (BEGV
>= BEG
);
5816 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5818 unbind_to (count
, Qnil
);
5823 /* Save state that should be preserved around the call to the function
5824 FN called in with_echo_area_buffer. */
5827 with_echo_area_buffer_unwind_data (w
)
5833 /* Reduce consing by keeping one vector in
5834 Vwith_echo_area_save_vector. */
5835 vector
= Vwith_echo_area_save_vector
;
5836 Vwith_echo_area_save_vector
= Qnil
;
5839 vector
= Fmake_vector (make_number (7), Qnil
);
5841 XSETBUFFER (XVECTOR (vector
)->contents
[i
], current_buffer
); ++i
;
5842 XVECTOR (vector
)->contents
[i
++] = Vdeactivate_mark
;
5843 XVECTOR (vector
)->contents
[i
++] = make_number (windows_or_buffers_changed
);
5847 XSETWINDOW (XVECTOR (vector
)->contents
[i
], w
); ++i
;
5848 XVECTOR (vector
)->contents
[i
++] = w
->buffer
;
5849 XVECTOR (vector
)->contents
[i
++]
5850 = make_number (XMARKER (w
->pointm
)->charpos
);
5851 XVECTOR (vector
)->contents
[i
++]
5852 = make_number (XMARKER (w
->pointm
)->bytepos
);
5858 XVECTOR (vector
)->contents
[i
++] = Qnil
;
5861 xassert (i
== XVECTOR (vector
)->size
);
5866 /* Restore global state from VECTOR which was created by
5867 with_echo_area_buffer_unwind_data. */
5870 unwind_with_echo_area_buffer (vector
)
5875 set_buffer_internal_1 (XBUFFER (XVECTOR (vector
)->contents
[i
])); ++i
;
5876 Vdeactivate_mark
= XVECTOR (vector
)->contents
[i
]; ++i
;
5877 windows_or_buffers_changed
= XFASTINT (XVECTOR (vector
)->contents
[i
]); ++i
;
5879 if (WINDOWP (XVECTOR (vector
)->contents
[i
]))
5882 Lisp_Object buffer
, charpos
, bytepos
;
5884 w
= XWINDOW (XVECTOR (vector
)->contents
[i
]); ++i
;
5885 buffer
= XVECTOR (vector
)->contents
[i
]; ++i
;
5886 charpos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5887 bytepos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5890 set_marker_both (w
->pointm
, buffer
,
5891 XFASTINT (charpos
), XFASTINT (bytepos
));
5894 Vwith_echo_area_save_vector
= vector
;
5899 /* Set up the echo area for use by print functions. MULTIBYTE_P
5900 non-zero means we will print multibyte. */
5903 setup_echo_area_for_printing (multibyte_p
)
5906 ensure_echo_area_buffers ();
5908 if (!message_buf_print
)
5910 /* A message has been output since the last time we printed.
5911 Choose a fresh echo area buffer. */
5912 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5913 echo_area_buffer
[0] = echo_buffer
[1];
5915 echo_area_buffer
[0] = echo_buffer
[0];
5917 /* Switch to that buffer and clear it. */
5918 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5921 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5923 /* Set up the buffer for the multibyteness we need. */
5925 != !NILP (current_buffer
->enable_multibyte_characters
))
5926 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
5928 /* Raise the frame containing the echo area. */
5929 if (minibuffer_auto_raise
)
5931 struct frame
*sf
= SELECTED_FRAME ();
5932 Lisp_Object mini_window
;
5933 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5934 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5937 message_log_maybe_newline ();
5938 message_buf_print
= 1;
5942 if (NILP (echo_area_buffer
[0]))
5944 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5945 echo_area_buffer
[0] = echo_buffer
[1];
5947 echo_area_buffer
[0] = echo_buffer
[0];
5950 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
5951 /* Someone switched buffers between print requests. */
5952 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5957 /* Display an echo area message in window W. Value is non-zero if W's
5958 height is changed. If display_last_displayed_message_p is
5959 non-zero, display the message that was last displayed, otherwise
5960 display the current message. */
5963 display_echo_area (w
)
5966 int i
, no_message_p
, window_height_changed_p
, count
;
5968 /* Temporarily disable garbage collections while displaying the echo
5969 area. This is done because a GC can print a message itself.
5970 That message would modify the echo area buffer's contents while a
5971 redisplay of the buffer is going on, and seriously confuse
5973 count
= inhibit_garbage_collection ();
5975 /* If there is no message, we must call display_echo_area_1
5976 nevertheless because it resizes the window. But we will have to
5977 reset the echo_area_buffer in question to nil at the end because
5978 with_echo_area_buffer will sets it to an empty buffer. */
5979 i
= display_last_displayed_message_p
? 1 : 0;
5980 no_message_p
= NILP (echo_area_buffer
[i
]);
5982 window_height_changed_p
5983 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
5984 display_echo_area_1
,
5985 (EMACS_INT
) w
, Qnil
, 0, 0);
5988 echo_area_buffer
[i
] = Qnil
;
5990 unbind_to (count
, Qnil
);
5991 return window_height_changed_p
;
5995 /* Helper for display_echo_area. Display the current buffer which
5996 contains the current echo area message in window W, a mini-window,
5997 a pointer to which is passed in A1. A2..A4 are currently not used.
5998 Change the height of W so that all of the message is displayed.
5999 Value is non-zero if height of W was changed. */
6002 display_echo_area_1 (a1
, a2
, a3
, a4
)
6007 struct window
*w
= (struct window
*) a1
;
6009 struct text_pos start
;
6010 int window_height_changed_p
= 0;
6012 /* Do this before displaying, so that we have a large enough glyph
6013 matrix for the display. */
6014 window_height_changed_p
= resize_mini_window (w
, 0);
6017 clear_glyph_matrix (w
->desired_matrix
);
6018 XSETWINDOW (window
, w
);
6019 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6020 try_window (window
, start
);
6022 return window_height_changed_p
;
6026 /* Resize the echo area window to exactly the size needed for the
6027 currently displayed message, if there is one. */
6030 resize_echo_area_axactly ()
6032 if (BUFFERP (echo_area_buffer
[0])
6033 && WINDOWP (echo_area_window
))
6035 struct window
*w
= XWINDOW (echo_area_window
);
6038 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6039 (EMACS_INT
) w
, Qnil
, 0, 0);
6042 ++windows_or_buffers_changed
;
6043 ++update_mode_lines
;
6044 redisplay_internal (0);
6050 /* Callback function for with_echo_area_buffer, when used from
6051 resize_echo_area_axactly. A1 contains a pointer to the window to
6052 resize, A2 to A4 are not used. Value is what resize_mini_window
6056 resize_mini_window_1 (a1
, a2
, a3
, a4
)
6061 return resize_mini_window ((struct window
*) a1
, 1);
6065 /* Resize mini-window W to fit the size of its contents. EXACT:P
6066 means size the window exactly to the size needed. Otherwise, it's
6067 only enlarged until W's buffer is empty. Value is non-zero if
6068 the window height has been changed. */
6071 resize_mini_window (w
, exact_p
)
6075 struct frame
*f
= XFRAME (w
->frame
);
6076 int window_height_changed_p
= 0;
6078 xassert (MINI_WINDOW_P (w
));
6080 /* Nil means don't try to resize. */
6081 if (NILP (Vmax_mini_window_height
)
6082 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6085 if (!FRAME_MINIBUF_ONLY_P (f
))
6088 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6089 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6090 int height
, max_height
;
6091 int unit
= CANON_Y_UNIT (f
);
6092 struct text_pos start
;
6094 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6096 /* Compute the max. number of lines specified by the user. */
6097 if (FLOATP (Vmax_mini_window_height
))
6098 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
6099 else if (INTEGERP (Vmax_mini_window_height
))
6100 max_height
= XINT (Vmax_mini_window_height
);
6102 max_height
= total_height
/ 4;
6104 /* Correct that max. height if it's bogus. */
6105 max_height
= max (1, max_height
);
6106 max_height
= min (total_height
, max_height
);
6108 /* Find out the height of the text in the window. */
6109 if (it
.truncate_lines_p
)
6114 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6115 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6116 height
= it
.current_y
+ last_height
;
6118 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6119 height
-= it
.extra_line_spacing
;
6120 height
= (height
+ unit
- 1) / unit
;
6123 /* Compute a suitable window start. */
6124 if (height
> max_height
)
6126 height
= max_height
;
6127 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6128 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6129 start
= it
.current
.pos
;
6132 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6133 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6135 /* Let it grow only, until we display an empty message, in which
6136 case the window shrinks again. */
6137 if (height
> XFASTINT (w
->height
))
6139 int old_height
= XFASTINT (w
->height
);
6140 freeze_window_starts (f
, 1);
6141 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6142 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6144 else if (height
< XFASTINT (w
->height
)
6145 && (exact_p
|| BEGV
== ZV
))
6147 int old_height
= XFASTINT (w
->height
);
6148 freeze_window_starts (f
, 0);
6149 shrink_mini_window (w
);
6150 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6154 return window_height_changed_p
;
6158 /* Value is the current message, a string, or nil if there is no
6166 if (NILP (echo_area_buffer
[0]))
6170 with_echo_area_buffer (0, 0, current_message_1
,
6171 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6173 echo_area_buffer
[0] = Qnil
;
6181 current_message_1 (a1
, a2
, a3
, a4
)
6186 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6189 *msg
= make_buffer_string (BEG
, Z
, 1);
6196 /* Push the current message on Vmessage_stack for later restauration
6197 by restore_message. Value is non-zero if the current message isn't
6198 empty. This is a relatively infrequent operation, so it's not
6199 worth optimizing. */
6205 msg
= current_message ();
6206 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6207 return STRINGP (msg
);
6211 /* Restore message display from the top of Vmessage_stack. */
6218 xassert (CONSP (Vmessage_stack
));
6219 msg
= XCAR (Vmessage_stack
);
6221 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6223 message3_nolog (msg
, 0, 0);
6227 /* Pop the top-most entry off Vmessage_stack. */
6232 xassert (CONSP (Vmessage_stack
));
6233 Vmessage_stack
= XCDR (Vmessage_stack
);
6237 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6238 exits. If the stack is not empty, we have a missing pop_message
6242 check_message_stack ()
6244 if (!NILP (Vmessage_stack
))
6249 /* Truncate to NCHARS what will be displayed in the echo area the next
6250 time we display it---but don't redisplay it now. */
6253 truncate_echo_area (nchars
)
6257 echo_area_buffer
[0] = Qnil
;
6258 /* A null message buffer means that the frame hasn't really been
6259 initialized yet. Error messages get reported properly by
6260 cmd_error, so this must be just an informative message; toss it. */
6261 else if (!noninteractive
6263 && !NILP (echo_area_buffer
[0]))
6265 struct frame
*sf
= SELECTED_FRAME ();
6266 if (FRAME_MESSAGE_BUF (sf
))
6267 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6272 /* Helper function for truncate_echo_area. Truncate the current
6273 message to at most NCHARS characters. */
6276 truncate_message_1 (nchars
, a2
, a3
, a4
)
6281 if (BEG
+ nchars
< Z
)
6282 del_range (BEG
+ nchars
, Z
);
6284 echo_area_buffer
[0] = Qnil
;
6289 /* Set the current message to a substring of S or STRING.
6291 If STRING is a Lisp string, set the message to the first NBYTES
6292 bytes from STRING. NBYTES zero means use the whole string. If
6293 STRING is multibyte, the message will be displayed multibyte.
6295 If S is not null, set the message to the first LEN bytes of S. LEN
6296 zero means use the whole string. MULTIBYTE_P non-zero means S is
6297 multibyte. Display the message multibyte in that case. */
6300 set_message (s
, string
, nbytes
, multibyte_p
)
6305 message_enable_multibyte
6306 = ((s
&& multibyte_p
)
6307 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6309 with_echo_area_buffer (0, -1, set_message_1
,
6310 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6311 message_buf_print
= 0;
6312 help_echo_showing_p
= 0;
6316 /* Helper function for set_message. Arguments have the same meaning
6317 as there, with A1 corresponding to S and A2 corresponding to STRING
6318 This function is called with the echo area buffer being
6322 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6325 EMACS_INT nbytes
, multibyte_p
;
6327 char *s
= (char *) a1
;
6328 Lisp_Object string
= a2
;
6332 /* Change multibyteness of the echo buffer appropriately. */
6333 if (message_enable_multibyte
6334 != !NILP (current_buffer
->enable_multibyte_characters
))
6335 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6337 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6339 /* Insert new message at BEG. */
6340 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6342 if (STRINGP (string
))
6347 nbytes
= XSTRING (string
)->size_byte
;
6348 nchars
= string_byte_to_char (string
, nbytes
);
6350 /* This function takes care of single/multibyte conversion. We
6351 just have to ensure that the echo area buffer has the right
6352 setting of enable_multibyte_characters. */
6353 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6358 nbytes
= strlen (s
);
6360 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6362 /* Convert from multi-byte to single-byte. */
6364 unsigned char work
[1];
6366 /* Convert a multibyte string to single-byte. */
6367 for (i
= 0; i
< nbytes
; i
+= n
)
6369 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6370 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6372 : multibyte_char_to_unibyte (c
, Qnil
));
6373 insert_1_both (work
, 1, 1, 1, 0, 0);
6376 else if (!multibyte_p
6377 && !NILP (current_buffer
->enable_multibyte_characters
))
6379 /* Convert from single-byte to multi-byte. */
6381 unsigned char *msg
= (unsigned char *) s
;
6382 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6384 /* Convert a single-byte string to multibyte. */
6385 for (i
= 0; i
< nbytes
; i
++)
6387 c
= unibyte_char_to_multibyte (msg
[i
]);
6388 n
= CHAR_STRING (c
, str
);
6389 insert_1_both (str
, 1, n
, 1, 0, 0);
6393 insert_1 (s
, nbytes
, 1, 0, 0);
6400 /* Clear messages. CURRENT_P non-zero means clear the current
6401 message. LAST_DISPLAYED_P non-zero means clear the message
6405 clear_message (current_p
, last_displayed_p
)
6406 int current_p
, last_displayed_p
;
6409 echo_area_buffer
[0] = Qnil
;
6411 if (last_displayed_p
)
6412 echo_area_buffer
[1] = Qnil
;
6414 message_buf_print
= 0;
6417 /* Clear garbaged frames.
6419 This function is used where the old redisplay called
6420 redraw_garbaged_frames which in turn called redraw_frame which in
6421 turn called clear_frame. The call to clear_frame was a source of
6422 flickering. I believe a clear_frame is not necessary. It should
6423 suffice in the new redisplay to invalidate all current matrices,
6424 and ensure a complete redisplay of all windows. */
6427 clear_garbaged_frames ()
6431 Lisp_Object tail
, frame
;
6433 FOR_EACH_FRAME (tail
, frame
)
6435 struct frame
*f
= XFRAME (frame
);
6437 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6439 clear_current_matrices (f
);
6445 ++windows_or_buffers_changed
;
6450 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6451 is non-zero update selected_frame. Value is non-zero if the
6452 mini-windows height has been changed. */
6455 echo_area_display (update_frame_p
)
6458 Lisp_Object mini_window
;
6461 int window_height_changed_p
= 0;
6462 struct frame
*sf
= SELECTED_FRAME ();
6464 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6465 w
= XWINDOW (mini_window
);
6466 f
= XFRAME (WINDOW_FRAME (w
));
6468 /* Don't display if frame is invisible or not yet initialized. */
6469 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6472 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
6474 #ifdef HAVE_WINDOW_SYSTEM
6475 /* When Emacs starts, selected_frame may be a visible terminal
6476 frame, even if we run under a window system. If we let this
6477 through, a message would be displayed on the terminal. */
6478 if (EQ (selected_frame
, Vterminal_frame
)
6479 && !NILP (Vwindow_system
))
6481 #endif /* HAVE_WINDOW_SYSTEM */
6484 /* Redraw garbaged frames. */
6486 clear_garbaged_frames ();
6488 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6490 echo_area_window
= mini_window
;
6491 window_height_changed_p
= display_echo_area (w
);
6492 w
->must_be_updated_p
= 1;
6494 /* Update the display, unless called from redisplay_internal.
6495 Also don't update the screen during redisplay itself. The
6496 update will happen at the end of redisplay, and an update
6497 here could cause confusion. */
6498 if (update_frame_p
&& !redisplaying_p
)
6502 /* If the display update has been interrupted by pending
6503 input, update mode lines in the frame. Due to the
6504 pending input, it might have been that redisplay hasn't
6505 been called, so that mode lines above the echo area are
6506 garbaged. This looks odd, so we prevent it here. */
6507 if (!display_completed
)
6508 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
6510 if (window_height_changed_p
)
6512 /* Must update other windows. */
6513 windows_or_buffers_changed
= 1;
6514 redisplay_internal (0);
6516 else if (FRAME_WINDOW_P (f
) && n
== 0)
6518 /* Window configuration is the same as before.
6519 Can do with a display update of the echo area,
6520 unless we displayed some mode lines. */
6521 update_single_window (w
, 1);
6522 rif
->flush_display (f
);
6525 update_frame (f
, 1, 1);
6528 else if (!EQ (mini_window
, selected_window
))
6529 windows_or_buffers_changed
++;
6531 /* Last displayed message is now the current message. */
6532 echo_area_buffer
[1] = echo_area_buffer
[0];
6534 /* Prevent redisplay optimization in redisplay_internal by resetting
6535 this_line_start_pos. This is done because the mini-buffer now
6536 displays the message instead of its buffer text. */
6537 if (EQ (mini_window
, selected_window
))
6538 CHARPOS (this_line_start_pos
) = 0;
6540 return window_height_changed_p
;
6545 /***********************************************************************
6547 ***********************************************************************/
6550 #ifdef HAVE_WINDOW_SYSTEM
6552 /* A buffer for constructing frame titles in it; allocated from the
6553 heap in init_xdisp and resized as needed in store_frame_title_char. */
6555 static char *frame_title_buf
;
6557 /* The buffer's end, and a current output position in it. */
6559 static char *frame_title_buf_end
;
6560 static char *frame_title_ptr
;
6563 /* Store a single character C for the frame title in frame_title_buf.
6564 Re-allocate frame_title_buf if necessary. */
6567 store_frame_title_char (c
)
6570 /* If output position has reached the end of the allocated buffer,
6571 double the buffer's size. */
6572 if (frame_title_ptr
== frame_title_buf_end
)
6574 int len
= frame_title_ptr
- frame_title_buf
;
6575 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6576 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6577 frame_title_buf_end
= frame_title_buf
+ new_size
;
6578 frame_title_ptr
= frame_title_buf
+ len
;
6581 *frame_title_ptr
++ = c
;
6585 /* Store part of a frame title in frame_title_buf, beginning at
6586 frame_title_ptr. STR is the string to store. Do not copy more
6587 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
6588 the whole string. Pad with spaces until FIELD_WIDTH number of
6589 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
6590 Called from display_mode_element when it is used to build a frame
6594 store_frame_title (str
, field_width
, precision
)
6596 int field_width
, precision
;
6600 /* Copy at most PRECISION chars from STR. */
6601 while ((precision
<= 0 || n
< precision
)
6604 store_frame_title_char (*str
++);
6608 /* Fill up with spaces until FIELD_WIDTH reached. */
6609 while (field_width
> 0
6612 store_frame_title_char (' ');
6620 /* Set the title of FRAME, if it has changed. The title format is
6621 Vicon_title_format if FRAME is iconified, otherwise it is
6622 frame_title_format. */
6625 x_consider_frame_title (frame
)
6628 struct frame
*f
= XFRAME (frame
);
6630 if (FRAME_WINDOW_P (f
)
6631 || FRAME_MINIBUF_ONLY_P (f
)
6632 || f
->explicit_name
)
6634 /* Do we have more than one visible frame on this X display? */
6637 struct buffer
*obuf
;
6641 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
6643 struct frame
*tf
= XFRAME (XCAR (tail
));
6646 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
6647 && !FRAME_MINIBUF_ONLY_P (tf
)
6648 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
6652 /* Set global variable indicating that multiple frames exist. */
6653 multiple_frames
= CONSP (tail
);
6655 /* Switch to the buffer of selected window of the frame. Set up
6656 frame_title_ptr so that display_mode_element will output into it;
6657 then display the title. */
6658 obuf
= current_buffer
;
6659 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
6660 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
6661 frame_title_ptr
= frame_title_buf
;
6662 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
6663 NULL
, DEFAULT_FACE_ID
);
6664 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
6665 frame_title_ptr
= NULL
;
6666 set_buffer_internal (obuf
);
6668 /* Set the title only if it's changed. This avoids consing in
6669 the common case where it hasn't. (If it turns out that we've
6670 already wasted too much time by walking through the list with
6671 display_mode_element, then we might need to optimize at a
6672 higher level than this.) */
6673 if (! STRINGP (f
->name
)
6674 || STRING_BYTES (XSTRING (f
->name
)) != len
6675 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
6676 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
6680 #else /* not HAVE_WINDOW_SYSTEM */
6682 #define frame_title_ptr ((char *)0)
6683 #define store_frame_title(str, mincol, maxcol) 0
6685 #endif /* not HAVE_WINDOW_SYSTEM */
6690 /***********************************************************************
6692 ***********************************************************************/
6695 /* Prepare for redisplay by updating menu-bar item lists when
6696 appropriate. This can call eval. */
6699 prepare_menu_bars ()
6702 struct gcpro gcpro1
, gcpro2
;
6704 struct frame
*tooltip_frame
;
6706 #ifdef HAVE_X_WINDOWS
6707 tooltip_frame
= tip_frame
;
6709 tooltip_frame
= NULL
;
6712 /* Update all frame titles based on their buffer names, etc. We do
6713 this before the menu bars so that the buffer-menu will show the
6714 up-to-date frame titles. */
6715 #ifdef HAVE_WINDOW_SYSTEM
6716 if (windows_or_buffers_changed
|| update_mode_lines
)
6718 Lisp_Object tail
, frame
;
6720 FOR_EACH_FRAME (tail
, frame
)
6723 if (f
!= tooltip_frame
6724 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
6725 x_consider_frame_title (frame
);
6728 #endif /* HAVE_WINDOW_SYSTEM */
6730 /* Update the menu bar item lists, if appropriate. This has to be
6731 done before any actual redisplay or generation of display lines. */
6732 all_windows
= (update_mode_lines
6733 || buffer_shared
> 1
6734 || windows_or_buffers_changed
);
6737 Lisp_Object tail
, frame
;
6738 int count
= specpdl_ptr
- specpdl
;
6740 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6742 FOR_EACH_FRAME (tail
, frame
)
6746 /* Ignore tooltip frame. */
6747 if (f
== tooltip_frame
)
6750 /* If a window on this frame changed size, report that to
6751 the user and clear the size-change flag. */
6752 if (FRAME_WINDOW_SIZES_CHANGED (f
))
6754 Lisp_Object functions
;
6756 /* Clear flag first in case we get an error below. */
6757 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
6758 functions
= Vwindow_size_change_functions
;
6759 GCPRO2 (tail
, functions
);
6761 while (CONSP (functions
))
6763 call1 (XCAR (functions
), frame
);
6764 functions
= XCDR (functions
);
6770 update_menu_bar (f
, 0);
6771 #ifdef HAVE_WINDOW_SYSTEM
6772 update_tool_bar (f
, 0);
6777 unbind_to (count
, Qnil
);
6781 struct frame
*sf
= SELECTED_FRAME ();
6782 update_menu_bar (sf
, 1);
6783 #ifdef HAVE_WINDOW_SYSTEM
6784 update_tool_bar (sf
, 1);
6788 /* Motif needs this. See comment in xmenu.c. Turn it off when
6789 pending_menu_activation is not defined. */
6790 #ifdef USE_X_TOOLKIT
6791 pending_menu_activation
= 0;
6796 /* Update the menu bar item list for frame F. This has to be done
6797 before we start to fill in any display lines, because it can call
6800 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
6803 update_menu_bar (f
, save_match_data
)
6805 int save_match_data
;
6808 register struct window
*w
;
6810 window
= FRAME_SELECTED_WINDOW (f
);
6811 w
= XWINDOW (window
);
6813 if (update_mode_lines
)
6814 w
->update_mode_line
= Qt
;
6816 if (FRAME_WINDOW_P (f
)
6818 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
6819 FRAME_EXTERNAL_MENU_BAR (f
)
6821 FRAME_MENU_BAR_LINES (f
) > 0
6823 : FRAME_MENU_BAR_LINES (f
) > 0)
6825 /* If the user has switched buffers or windows, we need to
6826 recompute to reflect the new bindings. But we'll
6827 recompute when update_mode_lines is set too; that means
6828 that people can use force-mode-line-update to request
6829 that the menu bar be recomputed. The adverse effect on
6830 the rest of the redisplay algorithm is about the same as
6831 windows_or_buffers_changed anyway. */
6832 if (windows_or_buffers_changed
6833 || !NILP (w
->update_mode_line
)
6834 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6835 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6836 != !NILP (w
->last_had_star
))
6837 || ((!NILP (Vtransient_mark_mode
)
6838 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6839 != !NILP (w
->region_showing
)))
6841 struct buffer
*prev
= current_buffer
;
6842 int count
= specpdl_ptr
- specpdl
;
6844 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6845 if (save_match_data
)
6846 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6847 if (NILP (Voverriding_local_map_menu_flag
))
6849 specbind (Qoverriding_terminal_local_map
, Qnil
);
6850 specbind (Qoverriding_local_map
, Qnil
);
6853 /* Run the Lucid hook. */
6854 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
6856 /* If it has changed current-menubar from previous value,
6857 really recompute the menu-bar from the value. */
6858 if (! NILP (Vlucid_menu_bar_dirty_flag
))
6859 call0 (Qrecompute_lucid_menubar
);
6861 safe_run_hooks (Qmenu_bar_update_hook
);
6862 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
6864 /* Redisplay the menu bar in case we changed it. */
6865 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
6866 if (FRAME_WINDOW_P (f
)
6867 #if defined (macintosh)
6868 /* All frames on Mac OS share the same menubar. So only the
6869 selected frame should be allowed to set it. */
6870 && f
== SELECTED_FRAME ()
6873 set_frame_menubar (f
, 0, 0);
6875 /* On a terminal screen, the menu bar is an ordinary screen
6876 line, and this makes it get updated. */
6877 w
->update_mode_line
= Qt
;
6878 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6879 /* In the non-toolkit version, the menu bar is an ordinary screen
6880 line, and this makes it get updated. */
6881 w
->update_mode_line
= Qt
;
6882 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6884 unbind_to (count
, Qnil
);
6885 set_buffer_internal_1 (prev
);
6892 /***********************************************************************
6894 ***********************************************************************/
6896 #ifdef HAVE_WINDOW_SYSTEM
6898 /* Update the tool-bar item list for frame F. This has to be done
6899 before we start to fill in any display lines. Called from
6900 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
6901 and restore it here. */
6904 update_tool_bar (f
, save_match_data
)
6906 int save_match_data
;
6908 if (WINDOWP (f
->tool_bar_window
)
6909 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
6914 window
= FRAME_SELECTED_WINDOW (f
);
6915 w
= XWINDOW (window
);
6917 /* If the user has switched buffers or windows, we need to
6918 recompute to reflect the new bindings. But we'll
6919 recompute when update_mode_lines is set too; that means
6920 that people can use force-mode-line-update to request
6921 that the menu bar be recomputed. The adverse effect on
6922 the rest of the redisplay algorithm is about the same as
6923 windows_or_buffers_changed anyway. */
6924 if (windows_or_buffers_changed
6925 || !NILP (w
->update_mode_line
)
6926 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6927 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6928 != !NILP (w
->last_had_star
))
6929 || ((!NILP (Vtransient_mark_mode
)
6930 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6931 != !NILP (w
->region_showing
)))
6933 struct buffer
*prev
= current_buffer
;
6934 int count
= specpdl_ptr
- specpdl
;
6936 /* Set current_buffer to the buffer of the selected
6937 window of the frame, so that we get the right local
6939 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6941 /* Save match data, if we must. */
6942 if (save_match_data
)
6943 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6945 /* Make sure that we don't accidentally use bogus keymaps. */
6946 if (NILP (Voverriding_local_map_menu_flag
))
6948 specbind (Qoverriding_terminal_local_map
, Qnil
);
6949 specbind (Qoverriding_local_map
, Qnil
);
6952 /* Build desired tool-bar items from keymaps. */
6953 f
->desired_tool_bar_items
6954 = tool_bar_items (f
->desired_tool_bar_items
,
6955 &f
->n_desired_tool_bar_items
);
6957 /* Redisplay the tool-bar in case we changed it. */
6958 w
->update_mode_line
= Qt
;
6960 unbind_to (count
, Qnil
);
6961 set_buffer_internal_1 (prev
);
6967 /* Set F->desired_tool_bar_string to a Lisp string representing frame
6968 F's desired tool-bar contents. F->desired_tool_bar_items must have
6969 been set up previously by calling prepare_menu_bars. */
6972 build_desired_tool_bar_string (f
)
6975 int i
, size
, size_needed
, string_idx
;
6976 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6977 Lisp_Object image
, plist
, props
;
6979 image
= plist
= props
= Qnil
;
6980 GCPRO3 (image
, plist
, props
);
6982 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
6983 Otherwise, make a new string. */
6985 /* The size of the string we might be able to reuse. */
6986 size
= (STRINGP (f
->desired_tool_bar_string
)
6987 ? XSTRING (f
->desired_tool_bar_string
)->size
6990 /* Each image in the string we build is preceded by a space,
6991 and there is a space at the end. */
6992 size_needed
= f
->n_desired_tool_bar_items
+ 1;
6994 /* Reuse f->desired_tool_bar_string, if possible. */
6995 if (size
< size_needed
)
6996 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7000 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7001 Fremove_text_properties (make_number (0), make_number (size
),
7002 props
, f
->desired_tool_bar_string
);
7005 /* Put a `display' property on the string for the images to display,
7006 put a `menu_item' property on tool-bar items with a value that
7007 is the index of the item in F's tool-bar item vector. */
7008 for (i
= 0, string_idx
= 0;
7009 i
< f
->n_desired_tool_bar_items
;
7010 ++i
, string_idx
+= 1)
7013 (XVECTOR (f->desired_tool_bar_items) \
7014 ->contents[i * TOOL_BAR_ITEM_NSLOTS + (IDX)])
7016 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7017 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7018 int margin
, relief
, idx
;
7019 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
7020 extern Lisp_Object Qlaplace
;
7022 /* If image is a vector, choose the image according to the
7024 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7025 if (VECTORP (image
))
7029 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7030 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7033 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7034 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7036 xassert (ASIZE (image
) >= idx
);
7037 image
= AREF (image
, idx
);
7042 /* Ignore invalid image specifications. */
7043 if (!valid_image_p (image
))
7046 /* Display the tool-bar button pressed, or depressed. */
7047 plist
= Fcopy_sequence (XCDR (image
));
7049 /* Compute margin and relief to draw. */
7050 relief
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
7051 margin
= relief
+ max (0, tool_bar_button_margin
);
7053 if (auto_raise_tool_bar_buttons_p
)
7055 /* Add a `:relief' property to the image spec if the item is
7059 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7065 /* If image is selected, display it pressed, i.e. with a
7066 negative relief. If it's not selected, display it with a
7068 plist
= Fplist_put (plist
, QCrelief
,
7070 ? make_number (-relief
)
7071 : make_number (relief
)));
7075 /* Put a margin around the image. */
7077 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
7079 /* If button is not enabled, and we don't have special images
7080 for the disabled state, make the image appear disabled by
7081 applying an appropriate algorithm to it. */
7082 if (!enabled_p
&& idx
< 0)
7083 plist
= Fplist_put (plist
, QCalgorithm
, Qdisabled
);
7085 /* Put a `display' text property on the string for the image to
7086 display. Put a `menu-item' property on the string that gives
7087 the start of this item's properties in the tool-bar items
7089 image
= Fcons (Qimage
, plist
);
7090 props
= list4 (Qdisplay
, image
,
7091 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
)),
7092 Fadd_text_properties (make_number (string_idx
),
7093 make_number (string_idx
+ 1),
7094 props
, f
->desired_tool_bar_string
);
7102 /* Display one line of the tool-bar of frame IT->f. */
7105 display_tool_bar_line (it
)
7108 struct glyph_row
*row
= it
->glyph_row
;
7109 int max_x
= it
->last_visible_x
;
7112 prepare_desired_row (row
);
7113 row
->y
= it
->current_y
;
7115 while (it
->current_x
< max_x
)
7117 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7119 /* Get the next display element. */
7120 if (!get_next_display_element (it
))
7123 /* Produce glyphs. */
7124 x_before
= it
->current_x
;
7125 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7126 PRODUCE_GLYPHS (it
);
7128 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7133 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7135 if (x
+ glyph
->pixel_width
> max_x
)
7137 /* Glyph doesn't fit on line. */
7138 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7144 x
+= glyph
->pixel_width
;
7148 /* Stop at line ends. */
7149 if (ITERATOR_AT_END_OF_LINE_P (it
))
7152 set_iterator_to_next (it
, 1);
7157 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7158 extend_face_to_end_of_line (it
);
7159 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7160 last
->right_box_line_p
= 1;
7161 compute_line_metrics (it
);
7163 /* If line is empty, make it occupy the rest of the tool-bar. */
7164 if (!row
->displays_text_p
)
7166 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7167 row
->ascent
= row
->phys_ascent
= 0;
7170 row
->full_width_p
= 1;
7171 row
->continued_p
= 0;
7172 row
->truncated_on_left_p
= 0;
7173 row
->truncated_on_right_p
= 0;
7175 it
->current_x
= it
->hpos
= 0;
7176 it
->current_y
+= row
->height
;
7182 /* Value is the number of screen lines needed to make all tool-bar
7183 items of frame F visible. */
7186 tool_bar_lines_needed (f
)
7189 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7192 /* Initialize an iterator for iteration over
7193 F->desired_tool_bar_string in the tool-bar window of frame F. */
7194 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7195 it
.first_visible_x
= 0;
7196 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7197 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7199 while (!ITERATOR_AT_END_P (&it
))
7201 it
.glyph_row
= w
->desired_matrix
->rows
;
7202 clear_glyph_row (it
.glyph_row
);
7203 display_tool_bar_line (&it
);
7206 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7210 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7211 height should be changed. */
7214 redisplay_tool_bar (f
)
7219 struct glyph_row
*row
;
7220 int change_height_p
= 0;
7222 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7223 do anything. This means you must start with tool-bar-lines
7224 non-zero to get the auto-sizing effect. Or in other words, you
7225 can turn off tool-bars by specifying tool-bar-lines zero. */
7226 if (!WINDOWP (f
->tool_bar_window
)
7227 || (w
= XWINDOW (f
->tool_bar_window
),
7228 XFASTINT (w
->height
) == 0))
7231 /* Set up an iterator for the tool-bar window. */
7232 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7233 it
.first_visible_x
= 0;
7234 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7237 /* Build a string that represents the contents of the tool-bar. */
7238 build_desired_tool_bar_string (f
);
7239 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7241 /* Display as many lines as needed to display all tool-bar items. */
7242 while (it
.current_y
< it
.last_visible_y
)
7243 display_tool_bar_line (&it
);
7245 /* It doesn't make much sense to try scrolling in the tool-bar
7246 window, so don't do it. */
7247 w
->desired_matrix
->no_scrolling_p
= 1;
7248 w
->must_be_updated_p
= 1;
7250 if (auto_resize_tool_bars_p
)
7254 /* If there are blank lines at the end, except for a partially
7255 visible blank line at the end that is smaller than
7256 CANON_Y_UNIT, change the tool-bar's height. */
7257 row
= it
.glyph_row
- 1;
7258 if (!row
->displays_text_p
7259 && row
->height
>= CANON_Y_UNIT (f
))
7260 change_height_p
= 1;
7262 /* If row displays tool-bar items, but is partially visible,
7263 change the tool-bar's height. */
7264 if (row
->displays_text_p
7265 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7266 change_height_p
= 1;
7268 /* Resize windows as needed by changing the `tool-bar-lines'
7271 && (nlines
= tool_bar_lines_needed (f
),
7272 nlines
!= XFASTINT (w
->height
)))
7274 extern Lisp_Object Qtool_bar_lines
;
7276 int old_height
= XFASTINT (w
->height
);
7278 XSETFRAME (frame
, f
);
7279 clear_glyph_matrix (w
->desired_matrix
);
7280 Fmodify_frame_parameters (frame
,
7281 Fcons (Fcons (Qtool_bar_lines
,
7282 make_number (nlines
)),
7284 if (XFASTINT (w
->height
) != old_height
)
7285 fonts_changed_p
= 1;
7289 return change_height_p
;
7293 /* Get information about the tool-bar item which is displayed in GLYPH
7294 on frame F. Return in *PROP_IDX the index where tool-bar item
7295 properties start in F->current_tool_bar_items. Value is zero if
7296 GLYPH doesn't display a tool-bar item. */
7299 tool_bar_item_info (f
, glyph
, prop_idx
)
7301 struct glyph
*glyph
;
7307 /* Get the text property `menu-item' at pos. The value of that
7308 property is the start index of this item's properties in
7309 F->current_tool_bar_items. */
7310 prop
= Fget_text_property (make_number (glyph
->charpos
),
7311 Qmenu_item
, f
->current_tool_bar_string
);
7312 if (INTEGERP (prop
))
7314 *prop_idx
= XINT (prop
);
7323 #endif /* HAVE_WINDOW_SYSTEM */
7327 /************************************************************************
7328 Horizontal scrolling
7329 ************************************************************************/
7331 static int hscroll_window_tree
P_ ((Lisp_Object
));
7332 static int hscroll_windows
P_ ((Lisp_Object
));
7334 /* For all leaf windows in the window tree rooted at WINDOW, set their
7335 hscroll value so that PT is (i) visible in the window, and (ii) so
7336 that it is not within a certain margin at the window's left and
7337 right border. Value is non-zero if any window's hscroll has been
7341 hscroll_window_tree (window
)
7344 int hscrolled_p
= 0;
7346 while (WINDOWP (window
))
7348 struct window
*w
= XWINDOW (window
);
7350 if (WINDOWP (w
->hchild
))
7351 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7352 else if (WINDOWP (w
->vchild
))
7353 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7354 else if (w
->cursor
.vpos
>= 0)
7356 int hscroll_margin
, text_area_x
, text_area_y
;
7357 int text_area_width
, text_area_height
;
7358 struct glyph_row
*current_cursor_row
7359 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7360 struct glyph_row
*desired_cursor_row
7361 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7362 struct glyph_row
*cursor_row
7363 = (desired_cursor_row
->enabled_p
7364 ? desired_cursor_row
7365 : current_cursor_row
);
7367 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7368 &text_area_width
, &text_area_height
);
7370 /* Scroll when cursor is inside this scroll margin. */
7371 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
7373 if ((XFASTINT (w
->hscroll
)
7374 && w
->cursor
.x
< hscroll_margin
)
7375 || (cursor_row
->enabled_p
7376 && cursor_row
->truncated_on_right_p
7377 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
7381 struct buffer
*saved_current_buffer
;
7384 /* Find point in a display of infinite width. */
7385 saved_current_buffer
= current_buffer
;
7386 current_buffer
= XBUFFER (w
->buffer
);
7388 if (w
== XWINDOW (selected_window
))
7389 pt
= BUF_PT (current_buffer
);
7392 pt
= marker_position (w
->pointm
);
7393 pt
= max (BEGV
, pt
);
7397 /* Move iterator to pt starting at cursor_row->start in
7398 a line with infinite width. */
7399 init_to_row_start (&it
, w
, cursor_row
);
7400 it
.last_visible_x
= INFINITY
;
7401 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
7402 current_buffer
= saved_current_buffer
;
7404 /* Center cursor in window. */
7405 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
7406 / CANON_X_UNIT (it
.f
));
7408 /* Don't call Fset_window_hscroll if value hasn't
7409 changed because it will prevent redisplay
7411 if (XFASTINT (w
->hscroll
) != hscroll
)
7413 Fset_window_hscroll (window
, make_number (hscroll
));
7422 /* Value is non-zero if hscroll of any leaf window has been changed. */
7427 /* Set hscroll so that cursor is visible and not inside horizontal
7428 scroll margins for all windows in the tree rooted at WINDOW. See
7429 also hscroll_window_tree above. Value is non-zero if any window's
7430 hscroll has been changed. If it has, desired matrices on the frame
7431 of WINDOW are cleared. */
7434 hscroll_windows (window
)
7439 if (automatic_hscrolling_p
)
7441 hscrolled_p
= hscroll_window_tree (window
);
7443 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
7452 /************************************************************************
7454 ************************************************************************/
7456 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
7457 to a non-zero value. This is sometimes handy to have in a debugger
7462 /* First and last unchanged row for try_window_id. */
7464 int debug_first_unchanged_at_end_vpos
;
7465 int debug_last_unchanged_at_beg_vpos
;
7467 /* Delta vpos and y. */
7469 int debug_dvpos
, debug_dy
;
7471 /* Delta in characters and bytes for try_window_id. */
7473 int debug_delta
, debug_delta_bytes
;
7475 /* Values of window_end_pos and window_end_vpos at the end of
7478 int debug_end_pos
, debug_end_vpos
;
7480 /* Append a string to W->desired_matrix->method. FMT is a printf
7481 format string. A1...A9 are a supplement for a variable-length
7482 argument list. If trace_redisplay_p is non-zero also printf the
7483 resulting string to stderr. */
7486 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
7489 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
7492 char *method
= w
->desired_matrix
->method
;
7493 int len
= strlen (method
);
7494 int size
= sizeof w
->desired_matrix
->method
;
7495 int remaining
= size
- len
- 1;
7497 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
7498 if (len
&& remaining
)
7504 strncpy (method
+ len
, buffer
, remaining
);
7506 if (trace_redisplay_p
)
7507 fprintf (stderr
, "%p (%s): %s\n",
7509 ((BUFFERP (w
->buffer
)
7510 && STRINGP (XBUFFER (w
->buffer
)->name
))
7511 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
7516 #endif /* GLYPH_DEBUG */
7519 /* This counter is used to clear the face cache every once in a while
7520 in redisplay_internal. It is incremented for each redisplay.
7521 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
7524 #define CLEAR_FACE_CACHE_COUNT 10000
7525 static int clear_face_cache_count
;
7527 /* Record the previous terminal frame we displayed. */
7529 static struct frame
*previous_terminal_frame
;
7531 /* Non-zero while redisplay_internal is in progress. */
7536 /* Value is non-zero if all changes in window W, which displays
7537 current_buffer, are in the text between START and END. START is a
7538 buffer position, END is given as a distance from Z. Used in
7539 redisplay_internal for display optimization. */
7542 text_outside_line_unchanged_p (w
, start
, end
)
7546 int unchanged_p
= 1;
7548 /* If text or overlays have changed, see where. */
7549 if (XFASTINT (w
->last_modified
) < MODIFF
7550 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7552 /* Gap in the line? */
7553 if (GPT
< start
|| Z
- GPT
< end
)
7556 /* Changes start in front of the line, or end after it? */
7558 && (BEG_UNCHANGED
< start
- 1
7559 || END_UNCHANGED
< end
))
7562 /* If selective display, can't optimize if changes start at the
7563 beginning of the line. */
7565 && INTEGERP (current_buffer
->selective_display
)
7566 && XINT (current_buffer
->selective_display
) > 0
7567 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
7575 /* Do a frame update, taking possible shortcuts into account. This is
7576 the main external entry point for redisplay.
7578 If the last redisplay displayed an echo area message and that message
7579 is no longer requested, we clear the echo area or bring back the
7580 mini-buffer if that is in use. */
7585 redisplay_internal (0);
7588 /* Return 1 if point moved out of or into a composition. Otherwise
7589 return 0. PREV_BUF and PREV_PT are the last point buffer and
7590 position. BUF and PT are the current point buffer and position. */
7593 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
7594 struct buffer
*prev_buf
, *buf
;
7601 XSETBUFFER (buffer
, buf
);
7602 /* Check a composition at the last point if point moved within the
7604 if (prev_buf
== buf
)
7607 /* Point didn't move. */
7610 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
7611 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
7612 && COMPOSITION_VALID_P (start
, end
, prop
)
7613 && start
< prev_pt
&& end
> prev_pt
)
7614 /* The last point was within the composition. Return 1 iff
7615 point moved out of the composition. */
7616 return (pt
<= start
|| pt
>= end
);
7619 /* Check a composition at the current point. */
7620 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
7621 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
7622 && COMPOSITION_VALID_P (start
, end
, prop
)
7623 && start
< pt
&& end
> pt
);
7626 /* Reconsider the setting of B->clip_changed which is displayed
7630 reconsider_clip_changes (w
, b
)
7634 if (b
->prevent_redisplay_optimizations_p
)
7635 b
->clip_changed
= 1;
7636 else if (b
->clip_changed
7637 && !NILP (w
->window_end_valid
)
7638 && w
->current_matrix
->buffer
== b
7639 && w
->current_matrix
->zv
== BUF_ZV (b
)
7640 && w
->current_matrix
->begv
== BUF_BEGV (b
))
7641 b
->clip_changed
= 0;
7643 /* If display wasn't paused, and W is not a tool bar window, see if
7644 point has been moved into or out of a composition. In that case,
7645 we set b->clip_changed to 1 to force updating the screen. If
7646 b->clip_changed has already been set to 1, we can skip this
7648 if (!b
->clip_changed
7649 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
7653 if (w
== XWINDOW (selected_window
))
7654 pt
= BUF_PT (current_buffer
);
7656 pt
= marker_position (w
->pointm
);
7658 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
7659 || pt
!= XINT (w
->last_point
))
7660 && check_point_in_composition (w
->current_matrix
->buffer
,
7661 XINT (w
->last_point
),
7662 XBUFFER (w
->buffer
), pt
))
7663 b
->clip_changed
= 1;
7668 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
7669 response to any user action; therefore, we should preserve the echo
7670 area. (Actually, our caller does that job.) Perhaps in the future
7671 avoid recentering windows if it is not necessary; currently that
7672 causes some problems. */
7675 redisplay_internal (preserve_echo_area
)
7676 int preserve_echo_area
;
7678 struct window
*w
= XWINDOW (selected_window
);
7679 struct frame
*f
= XFRAME (w
->frame
);
7681 int must_finish
= 0;
7682 struct text_pos tlbufpos
, tlendpos
;
7683 int number_of_visible_frames
;
7685 struct frame
*sf
= SELECTED_FRAME ();
7687 /* Non-zero means redisplay has to consider all windows on all
7688 frames. Zero means, only selected_window is considered. */
7689 int consider_all_windows_p
;
7691 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
7693 /* No redisplay if running in batch mode or frame is not yet fully
7694 initialized, or redisplay is explicitly turned off by setting
7695 Vinhibit_redisplay. */
7697 || !NILP (Vinhibit_redisplay
)
7698 || !f
->glyphs_initialized_p
)
7701 /* The flag redisplay_performed_directly_p is set by
7702 direct_output_for_insert when it already did the whole screen
7703 update necessary. */
7704 if (redisplay_performed_directly_p
)
7706 redisplay_performed_directly_p
= 0;
7707 if (!hscroll_windows (selected_window
))
7711 #ifdef USE_X_TOOLKIT
7712 if (popup_activated ())
7716 /* I don't think this happens but let's be paranoid. */
7720 /* Record a function that resets redisplaying_p to its old value
7721 when we leave this function. */
7722 count
= specpdl_ptr
- specpdl
;
7723 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
7728 reconsider_clip_changes (w
, current_buffer
);
7730 /* If new fonts have been loaded that make a glyph matrix adjustment
7731 necessary, do it. */
7732 if (fonts_changed_p
)
7734 adjust_glyphs (NULL
);
7735 ++windows_or_buffers_changed
;
7736 fonts_changed_p
= 0;
7739 if (! FRAME_WINDOW_P (sf
)
7740 && previous_terminal_frame
!= sf
)
7742 /* Since frames on an ASCII terminal share the same display
7743 area, displaying a different frame means redisplay the whole
7745 windows_or_buffers_changed
++;
7746 SET_FRAME_GARBAGED (sf
);
7747 XSETFRAME (Vterminal_frame
, sf
);
7749 previous_terminal_frame
= sf
;
7751 /* Set the visible flags for all frames. Do this before checking
7752 for resized or garbaged frames; they want to know if their frames
7753 are visible. See the comment in frame.h for
7754 FRAME_SAMPLE_VISIBILITY. */
7756 Lisp_Object tail
, frame
;
7758 number_of_visible_frames
= 0;
7760 FOR_EACH_FRAME (tail
, frame
)
7762 struct frame
*f
= XFRAME (frame
);
7764 FRAME_SAMPLE_VISIBILITY (f
);
7765 if (FRAME_VISIBLE_P (f
))
7766 ++number_of_visible_frames
;
7767 clear_desired_matrices (f
);
7771 /* Notice any pending interrupt request to change frame size. */
7772 do_pending_window_change (1);
7774 /* Clear frames marked as garbaged. */
7776 clear_garbaged_frames ();
7778 /* Build menubar and tool-bar items. */
7779 prepare_menu_bars ();
7781 if (windows_or_buffers_changed
)
7782 update_mode_lines
++;
7784 /* Detect case that we need to write or remove a star in the mode line. */
7785 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
7787 w
->update_mode_line
= Qt
;
7788 if (buffer_shared
> 1)
7789 update_mode_lines
++;
7792 /* If %c is in the mode line, update it if needed. */
7793 if (!NILP (w
->column_number_displayed
)
7794 /* This alternative quickly identifies a common case
7795 where no change is needed. */
7796 && !(PT
== XFASTINT (w
->last_point
)
7797 && XFASTINT (w
->last_modified
) >= MODIFF
7798 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7799 && XFASTINT (w
->column_number_displayed
) != current_column ())
7800 w
->update_mode_line
= Qt
;
7802 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
7804 /* The variable buffer_shared is set in redisplay_window and
7805 indicates that we redisplay a buffer in different windows. See
7807 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
7809 /* If specs for an arrow have changed, do thorough redisplay
7810 to ensure we remove any arrow that should no longer exist. */
7811 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
7812 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
7813 consider_all_windows_p
= windows_or_buffers_changed
= 1;
7815 /* Normally the message* functions will have already displayed and
7816 updated the echo area, but the frame may have been trashed, or
7817 the update may have been preempted, so display the echo area
7818 again here. Checking both message buffers captures the case that
7819 the echo area should be cleared. */
7820 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
7822 int window_height_changed_p
= echo_area_display (0);
7825 if (fonts_changed_p
)
7827 else if (window_height_changed_p
)
7829 consider_all_windows_p
= 1;
7830 ++update_mode_lines
;
7831 ++windows_or_buffers_changed
;
7833 /* If window configuration was changed, frames may have been
7834 marked garbaged. Clear them or we will experience
7835 surprises wrt scrolling. */
7837 clear_garbaged_frames ();
7840 else if (EQ (selected_window
, minibuf_window
)
7841 && (current_buffer
->clip_changed
7842 || XFASTINT (w
->last_modified
) < MODIFF
7843 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7844 && resize_mini_window (w
, 0))
7846 /* Resized active mini-window to fit the size of what it is
7847 showing if its contents might have changed. */
7849 consider_all_windows_p
= 1;
7850 ++windows_or_buffers_changed
;
7851 ++update_mode_lines
;
7853 /* If window configuration was changed, frames may have been
7854 marked garbaged. Clear them or we will experience
7855 surprises wrt scrolling. */
7857 clear_garbaged_frames ();
7861 /* If showing the region, and mark has changed, we must redisplay
7862 the whole window. The assignment to this_line_start_pos prevents
7863 the optimization directly below this if-statement. */
7864 if (((!NILP (Vtransient_mark_mode
)
7865 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7866 != !NILP (w
->region_showing
))
7867 || (!NILP (w
->region_showing
)
7868 && !EQ (w
->region_showing
,
7869 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
7870 CHARPOS (this_line_start_pos
) = 0;
7872 /* Optimize the case that only the line containing the cursor in the
7873 selected window has changed. Variables starting with this_ are
7874 set in display_line and record information about the line
7875 containing the cursor. */
7876 tlbufpos
= this_line_start_pos
;
7877 tlendpos
= this_line_end_pos
;
7878 if (!consider_all_windows_p
7879 && CHARPOS (tlbufpos
) > 0
7880 && NILP (w
->update_mode_line
)
7881 && !current_buffer
->clip_changed
7882 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
7883 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
7884 /* Make sure recorded data applies to current buffer, etc. */
7885 && this_line_buffer
== current_buffer
7886 && current_buffer
== XBUFFER (w
->buffer
)
7887 && NILP (w
->force_start
)
7888 /* Point must be on the line that we have info recorded about. */
7889 && PT
>= CHARPOS (tlbufpos
)
7890 && PT
<= Z
- CHARPOS (tlendpos
)
7891 /* All text outside that line, including its final newline,
7892 must be unchanged */
7893 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
7894 CHARPOS (tlendpos
)))
7896 if (CHARPOS (tlbufpos
) > BEGV
7897 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
7898 && (CHARPOS (tlbufpos
) == ZV
7899 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
7900 /* Former continuation line has disappeared by becoming empty */
7902 else if (XFASTINT (w
->last_modified
) < MODIFF
7903 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
7904 || MINI_WINDOW_P (w
))
7906 /* We have to handle the case of continuation around a
7907 wide-column character (See the comment in indent.c around
7910 For instance, in the following case:
7912 -------- Insert --------
7913 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
7914 J_I_ ==> J_I_ `^^' are cursors.
7918 As we have to redraw the line above, we should goto cancel. */
7921 int line_height_before
= this_line_pixel_height
;
7923 /* Note that start_display will handle the case that the
7924 line starting at tlbufpos is a continuation lines. */
7925 start_display (&it
, w
, tlbufpos
);
7927 /* Implementation note: It this still necessary? */
7928 if (it
.current_x
!= this_line_start_x
)
7931 TRACE ((stderr
, "trying display optimization 1\n"));
7932 w
->cursor
.vpos
= -1;
7933 overlay_arrow_seen
= 0;
7934 it
.vpos
= this_line_vpos
;
7935 it
.current_y
= this_line_y
;
7936 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
7939 /* If line contains point, is not continued,
7940 and ends at same distance from eob as before, we win */
7941 if (w
->cursor
.vpos
>= 0
7942 /* Line is not continued, otherwise this_line_start_pos
7943 would have been set to 0 in display_line. */
7944 && CHARPOS (this_line_start_pos
)
7945 /* Line ends as before. */
7946 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
7947 /* Line has same height as before. Otherwise other lines
7948 would have to be shifted up or down. */
7949 && this_line_pixel_height
== line_height_before
)
7951 /* If this is not the window's last line, we must adjust
7952 the charstarts of the lines below. */
7953 if (it
.current_y
< it
.last_visible_y
)
7955 struct glyph_row
*row
7956 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
7957 int delta
, delta_bytes
;
7959 if (Z
- CHARPOS (tlendpos
) == ZV
)
7961 /* This line ends at end of (accessible part of)
7962 buffer. There is no newline to count. */
7964 - CHARPOS (tlendpos
)
7965 - MATRIX_ROW_START_CHARPOS (row
));
7966 delta_bytes
= (Z_BYTE
7967 - BYTEPOS (tlendpos
)
7968 - MATRIX_ROW_START_BYTEPOS (row
));
7972 /* This line ends in a newline. Must take
7973 account of the newline and the rest of the
7974 text that follows. */
7976 - CHARPOS (tlendpos
)
7977 - MATRIX_ROW_START_CHARPOS (row
));
7978 delta_bytes
= (Z_BYTE
7979 - BYTEPOS (tlendpos
)
7980 - MATRIX_ROW_START_BYTEPOS (row
));
7983 increment_matrix_positions (w
->current_matrix
,
7985 w
->current_matrix
->nrows
,
7986 delta
, delta_bytes
);
7989 /* If this row displays text now but previously didn't,
7990 or vice versa, w->window_end_vpos may have to be
7992 if ((it
.glyph_row
- 1)->displays_text_p
)
7994 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
7995 XSETINT (w
->window_end_vpos
, this_line_vpos
);
7997 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
7998 && this_line_vpos
> 0)
7999 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8000 w
->window_end_valid
= Qnil
;
8002 /* Update hint: No need to try to scroll in update_window. */
8003 w
->desired_matrix
->no_scrolling_p
= 1;
8006 *w
->desired_matrix
->method
= 0;
8007 debug_method_add (w
, "optimization 1");
8014 else if (/* Cursor position hasn't changed. */
8015 PT
== XFASTINT (w
->last_point
)
8016 /* Make sure the cursor was last displayed
8017 in this window. Otherwise we have to reposition it. */
8018 && 0 <= w
->cursor
.vpos
8019 && XINT (w
->height
) > w
->cursor
.vpos
)
8023 do_pending_window_change (1);
8025 /* We used to always goto end_of_redisplay here, but this
8026 isn't enough if we have a blinking cursor. */
8027 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8028 goto end_of_redisplay
;
8032 /* If highlighting the region, or if the cursor is in the echo area,
8033 then we can't just move the cursor. */
8034 else if (! (!NILP (Vtransient_mark_mode
)
8035 && !NILP (current_buffer
->mark_active
))
8036 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8037 || highlight_nonselected_windows
)
8038 && NILP (w
->region_showing
)
8039 && NILP (Vshow_trailing_whitespace
)
8040 && !cursor_in_echo_area
)
8043 struct glyph_row
*row
;
8045 /* Skip from tlbufpos to PT and see where it is. Note that
8046 PT may be in invisible text. If so, we will end at the
8047 next visible position. */
8048 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8049 NULL
, DEFAULT_FACE_ID
);
8050 it
.current_x
= this_line_start_x
;
8051 it
.current_y
= this_line_y
;
8052 it
.vpos
= this_line_vpos
;
8054 /* The call to move_it_to stops in front of PT, but
8055 moves over before-strings. */
8056 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8058 if (it
.vpos
== this_line_vpos
8059 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8062 xassert (this_line_vpos
== it
.vpos
);
8063 xassert (this_line_y
== it
.current_y
);
8064 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8072 /* Text changed drastically or point moved off of line. */
8073 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8076 CHARPOS (this_line_start_pos
) = 0;
8077 consider_all_windows_p
|= buffer_shared
> 1;
8078 ++clear_face_cache_count
;
8081 /* Build desired matrices, and update the display. If
8082 consider_all_windows_p is non-zero, do it for all windows on all
8083 frames. Otherwise do it for selected_window, only. */
8085 if (consider_all_windows_p
)
8087 Lisp_Object tail
, frame
;
8089 /* Clear the face cache eventually. */
8090 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8092 clear_face_cache (0);
8093 clear_face_cache_count
= 0;
8096 /* Recompute # windows showing selected buffer. This will be
8097 incremented each time such a window is displayed. */
8100 FOR_EACH_FRAME (tail
, frame
)
8102 struct frame
*f
= XFRAME (frame
);
8104 if (FRAME_WINDOW_P (f
) || f
== sf
)
8106 /* Mark all the scroll bars to be removed; we'll redeem
8107 the ones we want when we redisplay their windows. */
8108 if (condemn_scroll_bars_hook
)
8109 (*condemn_scroll_bars_hook
) (f
);
8111 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8112 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8114 /* Any scroll bars which redisplay_windows should have
8115 nuked should now go away. */
8116 if (judge_scroll_bars_hook
)
8117 (*judge_scroll_bars_hook
) (f
);
8119 /* If fonts changed, display again. */
8120 if (fonts_changed_p
)
8123 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8125 /* See if we have to hscroll. */
8126 if (hscroll_windows (f
->root_window
))
8129 /* Prevent various kinds of signals during display
8130 update. stdio is not robust about handling
8131 signals, which can cause an apparent I/O
8133 if (interrupt_input
)
8137 /* Update the display. */
8138 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8139 pause
|= update_frame (f
, 0, 0);
8143 mark_window_display_accurate (f
->root_window
, 1);
8144 if (frame_up_to_date_hook
)
8145 frame_up_to_date_hook (f
);
8150 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8152 Lisp_Object mini_window
;
8153 struct frame
*mini_frame
;
8155 redisplay_window (selected_window
, 1);
8157 /* Compare desired and current matrices, perform output. */
8160 /* If fonts changed, display again. */
8161 if (fonts_changed_p
)
8164 /* Prevent various kinds of signals during display update.
8165 stdio is not robust about handling signals,
8166 which can cause an apparent I/O error. */
8167 if (interrupt_input
)
8171 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8173 if (hscroll_windows (selected_window
))
8176 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8177 pause
= update_frame (sf
, 0, 0);
8180 /* We may have called echo_area_display at the top of this
8181 function. If the echo area is on another frame, that may
8182 have put text on a frame other than the selected one, so the
8183 above call to update_frame would not have caught it. Catch
8185 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8186 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8188 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8190 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8191 pause
|= update_frame (mini_frame
, 0, 0);
8192 if (!pause
&& hscroll_windows (mini_window
))
8197 /* If display was paused because of pending input, make sure we do a
8198 thorough update the next time. */
8201 /* Prevent the optimization at the beginning of
8202 redisplay_internal that tries a single-line update of the
8203 line containing the cursor in the selected window. */
8204 CHARPOS (this_line_start_pos
) = 0;
8206 /* Let the overlay arrow be updated the next time. */
8207 if (!NILP (last_arrow_position
))
8209 last_arrow_position
= Qt
;
8210 last_arrow_string
= Qt
;
8213 /* If we pause after scrolling, some rows in the current
8214 matrices of some windows are not valid. */
8215 if (!WINDOW_FULL_WIDTH_P (w
)
8216 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8217 update_mode_lines
= 1;
8220 /* Now text on frame agrees with windows, so put info into the
8221 windows for partial redisplay to follow. */
8224 register struct buffer
*b
= XBUFFER (w
->buffer
);
8226 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
8227 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
8228 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
8229 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
8231 if (consider_all_windows_p
)
8232 mark_window_display_accurate (FRAME_ROOT_WINDOW (sf
), 1);
8235 XSETFASTINT (w
->last_point
, BUF_PT (b
));
8236 w
->last_cursor
= w
->cursor
;
8237 w
->last_cursor_off_p
= w
->cursor_off_p
;
8239 b
->clip_changed
= 0;
8240 b
->prevent_redisplay_optimizations_p
= 0;
8241 w
->update_mode_line
= Qnil
;
8242 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
8243 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
8245 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8248 /* Record if we are showing a region, so can make sure to
8249 update it fully at next redisplay. */
8250 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
8251 && (EQ (selected_window
,
8252 current_buffer
->last_selected_window
)
8253 || highlight_nonselected_windows
)
8254 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
8255 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
8258 w
->window_end_valid
= w
->buffer
;
8259 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8260 last_arrow_string
= Voverlay_arrow_string
;
8261 if (frame_up_to_date_hook
!= 0)
8262 (*frame_up_to_date_hook
) (sf
);
8264 w
->current_matrix
->buffer
= b
;
8265 w
->current_matrix
->begv
= BUF_BEGV (b
);
8266 w
->current_matrix
->zv
= BUF_ZV (b
);
8269 update_mode_lines
= 0;
8270 windows_or_buffers_changed
= 0;
8273 /* Start SIGIO interrupts coming again. Having them off during the
8274 code above makes it less likely one will discard output, but not
8275 impossible, since there might be stuff in the system buffer here.
8276 But it is much hairier to try to do anything about that. */
8277 if (interrupt_input
)
8281 /* If a frame has become visible which was not before, redisplay
8282 again, so that we display it. Expose events for such a frame
8283 (which it gets when becoming visible) don't call the parts of
8284 redisplay constructing glyphs, so simply exposing a frame won't
8285 display anything in this case. So, we have to display these
8286 frames here explicitly. */
8289 Lisp_Object tail
, frame
;
8292 FOR_EACH_FRAME (tail
, frame
)
8294 int this_is_visible
= 0;
8296 if (XFRAME (frame
)->visible
)
8297 this_is_visible
= 1;
8298 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8299 if (XFRAME (frame
)->visible
)
8300 this_is_visible
= 1;
8302 if (this_is_visible
)
8306 if (new_count
!= number_of_visible_frames
)
8307 windows_or_buffers_changed
++;
8310 /* Change frame size now if a change is pending. */
8311 do_pending_window_change (1);
8313 /* If we just did a pending size change, or have additional
8314 visible frames, redisplay again. */
8315 if (windows_or_buffers_changed
&& !pause
)
8320 unbind_to (count
, Qnil
);
8324 /* Redisplay, but leave alone any recent echo area message unless
8325 another message has been requested in its place.
8327 This is useful in situations where you need to redisplay but no
8328 user action has occurred, making it inappropriate for the message
8329 area to be cleared. See tracking_off and
8330 wait_reading_process_input for examples of these situations. */
8333 redisplay_preserve_echo_area ()
8335 if (!NILP (echo_area_buffer
[1]))
8337 /* We have a previously displayed message, but no current
8338 message. Redisplay the previous message. */
8339 display_last_displayed_message_p
= 1;
8340 redisplay_internal (1);
8341 display_last_displayed_message_p
= 0;
8344 redisplay_internal (1);
8348 /* Function registered with record_unwind_protect in
8349 redisplay_internal. Clears the flag indicating that a redisplay is
8353 unwind_redisplay (old_redisplaying_p
)
8354 Lisp_Object old_redisplaying_p
;
8356 redisplaying_p
= XFASTINT (old_redisplaying_p
);
8361 /* Mark the display of windows in the window tree rooted at WINDOW as
8362 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
8363 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
8364 the next time redisplay_internal is called. */
8367 mark_window_display_accurate (window
, accurate_p
)
8373 for (; !NILP (window
); window
= w
->next
)
8375 w
= XWINDOW (window
);
8377 if (BUFFERP (w
->buffer
))
8379 struct buffer
*b
= XBUFFER (w
->buffer
);
8381 XSETFASTINT (w
->last_modified
,
8382 accurate_p
? BUF_MODIFF (b
) : 0);
8383 XSETFASTINT (w
->last_overlay_modified
,
8384 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
8385 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
8388 #if 0 /* I don't think this is necessary because display_line does it.
8390 /* Record if we are showing a region, so can make sure to
8391 update it fully at next redisplay. */
8393 = (!NILP (Vtransient_mark_mode
)
8394 && (w
== XWINDOW (current_buffer
->last_selected_window
)
8395 || highlight_nonselected_windows
)
8396 && (!NILP (b
->mark_active
)
8397 ? Fmarker_position (b
->mark
)
8403 b
->clip_changed
= 0;
8404 b
->prevent_redisplay_optimizations_p
= 0;
8405 w
->current_matrix
->buffer
= b
;
8406 w
->current_matrix
->begv
= BUF_BEGV (b
);
8407 w
->current_matrix
->zv
= BUF_ZV (b
);
8408 w
->last_cursor
= w
->cursor
;
8409 w
->last_cursor_off_p
= w
->cursor_off_p
;
8410 if (w
== XWINDOW (selected_window
))
8411 w
->last_point
= make_number (BUF_PT (b
));
8413 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
8417 w
->window_end_valid
= w
->buffer
;
8418 w
->update_mode_line
= Qnil
;
8420 if (!NILP (w
->vchild
))
8421 mark_window_display_accurate (w
->vchild
, accurate_p
);
8422 if (!NILP (w
->hchild
))
8423 mark_window_display_accurate (w
->hchild
, accurate_p
);
8428 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8429 last_arrow_string
= Voverlay_arrow_string
;
8433 /* Force a thorough redisplay the next time by setting
8434 last_arrow_position and last_arrow_string to t, which is
8435 unequal to any useful value of Voverlay_arrow_... */
8436 last_arrow_position
= Qt
;
8437 last_arrow_string
= Qt
;
8442 /* Return value in display table DP (Lisp_Char_Table *) for character
8443 C. Since a display table doesn't have any parent, we don't have to
8444 follow parent. Do not call this function directly but use the
8445 macro DISP_CHAR_VECTOR. */
8448 disp_char_vector (dp
, c
)
8449 struct Lisp_Char_Table
*dp
;
8455 if (SINGLE_BYTE_CHAR_P (c
))
8456 return (dp
->contents
[c
]);
8458 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
8461 else if (code
[2] < 32)
8464 /* Here, the possible range of code[0] (== charset ID) is
8465 128..max_charset. Since the top level char table contains data
8466 for multibyte characters after 256th element, we must increment
8467 code[0] by 128 to get a correct index. */
8469 code
[3] = -1; /* anchor */
8471 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
8473 val
= dp
->contents
[code
[i
]];
8474 if (!SUB_CHAR_TABLE_P (val
))
8475 return (NILP (val
) ? dp
->defalt
: val
);
8478 /* Here, val is a sub char table. We return the default value of
8480 return (dp
->defalt
);
8485 /***********************************************************************
8487 ***********************************************************************/
8489 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
8492 redisplay_windows (window
)
8495 while (!NILP (window
))
8497 struct window
*w
= XWINDOW (window
);
8499 if (!NILP (w
->hchild
))
8500 redisplay_windows (w
->hchild
);
8501 else if (!NILP (w
->vchild
))
8502 redisplay_windows (w
->vchild
);
8504 redisplay_window (window
, 0);
8511 /* Set cursor position of W. PT is assumed to be displayed in ROW.
8512 DELTA is the number of bytes by which positions recorded in ROW
8513 differ from current buffer positions. */
8516 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
8518 struct glyph_row
*row
;
8519 struct glyph_matrix
*matrix
;
8520 int delta
, delta_bytes
, dy
, dvpos
;
8522 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
8523 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
8525 int pt_old
= PT
- delta
;
8527 /* Skip over glyphs not having an object at the start of the row.
8528 These are special glyphs like truncation marks on terminal
8530 if (row
->displays_text_p
)
8532 && INTEGERP (glyph
->object
)
8533 && glyph
->charpos
< 0)
8535 x
+= glyph
->pixel_width
;
8540 && !INTEGERP (glyph
->object
)
8541 && (!BUFFERP (glyph
->object
)
8542 || glyph
->charpos
< pt_old
))
8544 x
+= glyph
->pixel_width
;
8548 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
8550 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
8551 w
->cursor
.y
= row
->y
+ dy
;
8553 if (w
== XWINDOW (selected_window
))
8555 if (!row
->continued_p
8556 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
8559 this_line_buffer
= XBUFFER (w
->buffer
);
8561 CHARPOS (this_line_start_pos
)
8562 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
8563 BYTEPOS (this_line_start_pos
)
8564 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
8566 CHARPOS (this_line_end_pos
)
8567 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
8568 BYTEPOS (this_line_end_pos
)
8569 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
8571 this_line_y
= w
->cursor
.y
;
8572 this_line_pixel_height
= row
->height
;
8573 this_line_vpos
= w
->cursor
.vpos
;
8574 this_line_start_x
= row
->x
;
8577 CHARPOS (this_line_start_pos
) = 0;
8582 /* Run window scroll functions, if any, for WINDOW with new window
8583 start STARTP. Sets the window start of WINDOW to that position.
8585 We assume that the window's buffer is really current. */
8587 static INLINE
struct text_pos
8588 run_window_scroll_functions (window
, startp
)
8590 struct text_pos startp
;
8592 struct window
*w
= XWINDOW (window
);
8593 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
8595 if (current_buffer
!= XBUFFER (w
->buffer
))
8598 if (!NILP (Vwindow_scroll_functions
))
8600 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
8601 make_number (CHARPOS (startp
)));
8602 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8603 /* In case the hook functions switch buffers. */
8604 if (current_buffer
!= XBUFFER (w
->buffer
))
8605 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8612 /* Modify the desired matrix of window W and W->vscroll so that the
8613 line containing the cursor is fully visible. */
8616 make_cursor_line_fully_visible (w
)
8619 struct glyph_matrix
*matrix
;
8620 struct glyph_row
*row
;
8621 int window_height
, header_line_height
;
8623 /* It's not always possible to find the cursor, e.g, when a window
8624 is full of overlay strings. Don't do anything in that case. */
8625 if (w
->cursor
.vpos
< 0)
8628 matrix
= w
->desired_matrix
;
8629 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
8631 /* If the cursor row is not partially visible, there's nothing
8633 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8636 /* If the row the cursor is in is taller than the window's height,
8637 it's not clear what to do, so do nothing. */
8638 window_height
= window_box_height (w
);
8639 if (row
->height
>= window_height
)
8642 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
8644 int dy
= row
->height
- row
->visible_height
;
8647 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8649 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
8651 int dy
= - (row
->height
- row
->visible_height
);
8654 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8657 /* When we change the cursor y-position of the selected window,
8658 change this_line_y as well so that the display optimization for
8659 the cursor line of the selected window in redisplay_internal uses
8660 the correct y-position. */
8661 if (w
== XWINDOW (selected_window
))
8662 this_line_y
= w
->cursor
.y
;
8666 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
8667 non-zero means only WINDOW is redisplayed in redisplay_internal.
8668 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
8669 in redisplay_window to bring a partially visible line into view in
8670 the case that only the cursor has moved.
8674 1 if scrolling succeeded
8676 0 if scrolling didn't find point.
8678 -1 if new fonts have been loaded so that we must interrupt
8679 redisplay, adjust glyph matrices, and try again. */
8682 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
8683 scroll_step
, temp_scroll_step
)
8685 int just_this_one_p
;
8686 int scroll_conservatively
, scroll_step
;
8687 int temp_scroll_step
;
8689 struct window
*w
= XWINDOW (window
);
8690 struct frame
*f
= XFRAME (w
->frame
);
8691 struct text_pos scroll_margin_pos
;
8692 struct text_pos pos
;
8693 struct text_pos startp
;
8695 Lisp_Object window_end
;
8696 int this_scroll_margin
;
8700 int amount_to_scroll
= 0;
8701 Lisp_Object aggressive
;
8705 debug_method_add (w
, "try_scrolling");
8708 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8710 /* Compute scroll margin height in pixels. We scroll when point is
8711 within this distance from the top or bottom of the window. */
8712 if (scroll_margin
> 0)
8714 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
8715 this_scroll_margin
*= CANON_Y_UNIT (f
);
8718 this_scroll_margin
= 0;
8720 /* Compute how much we should try to scroll maximally to bring point
8723 scroll_max
= scroll_step
;
8724 else if (scroll_conservatively
)
8725 scroll_max
= scroll_conservatively
;
8726 else if (temp_scroll_step
)
8727 scroll_max
= temp_scroll_step
;
8728 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
8729 || NUMBERP (current_buffer
->scroll_up_aggressively
))
8730 /* We're trying to scroll because of aggressive scrolling
8731 but no scroll_step is set. Choose an arbitrary one. Maybe
8732 there should be a variable for this. */
8736 scroll_max
*= CANON_Y_UNIT (f
);
8738 /* Decide whether we have to scroll down. Start at the window end
8739 and move this_scroll_margin up to find the position of the scroll
8741 window_end
= Fwindow_end (window
, Qt
);
8742 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
8743 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
8744 if (this_scroll_margin
)
8746 start_display (&it
, w
, scroll_margin_pos
);
8747 move_it_vertically (&it
, - this_scroll_margin
);
8748 scroll_margin_pos
= it
.current
.pos
;
8751 if (PT
>= CHARPOS (scroll_margin_pos
))
8758 /* Point is in the scroll margin at the bottom of the window, or
8759 below. Compute a new window start that makes point visible. */
8761 /* Compute the distance from the scroll margin to PT.
8762 Give up if the distance is greater than scroll_max. */
8763 start_display (&it
, w
, scroll_margin_pos
);
8765 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8766 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8767 #if 0 /* Taking the line's height into account here looks wrong. */
8768 line_height
= (it
.max_ascent
+ it
.max_descent
8769 ? it
.max_ascent
+ it
.max_descent
8771 dy
= it
.current_y
+ line_height
- y0
;
8773 /* With a scroll_margin of 0, scroll_margin_pos is at the window
8774 end, which is one line below the window. The iterator's
8775 current_y will be same as y0 in that case, but we have to
8776 scroll a line to make PT visible. That's the reason why 1 is
8778 dy
= 1 + it
.current_y
- y0
;
8781 if (dy
> scroll_max
)
8784 /* Move the window start down. If scrolling conservatively,
8785 move it just enough down to make point visible. If
8786 scroll_step is set, move it down by scroll_step. */
8787 start_display (&it
, w
, startp
);
8789 if (scroll_conservatively
)
8790 amount_to_scroll
= dy
;
8791 else if (scroll_step
|| temp_scroll_step
)
8792 amount_to_scroll
= scroll_max
;
8795 aggressive
= current_buffer
->scroll_down_aggressively
;
8796 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8797 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8798 if (NUMBERP (aggressive
))
8799 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8802 if (amount_to_scroll
<= 0)
8805 move_it_vertically (&it
, amount_to_scroll
);
8806 startp
= it
.current
.pos
;
8810 /* See if point is inside the scroll margin at the top of the
8812 scroll_margin_pos
= startp
;
8813 if (this_scroll_margin
)
8815 start_display (&it
, w
, startp
);
8816 move_it_vertically (&it
, this_scroll_margin
);
8817 scroll_margin_pos
= it
.current
.pos
;
8820 if (PT
< CHARPOS (scroll_margin_pos
))
8822 /* Point is in the scroll margin at the top of the window or
8823 above what is displayed in the window. */
8826 /* Compute the vertical distance from PT to the scroll
8827 margin position. Give up if distance is greater than
8829 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
8830 start_display (&it
, w
, pos
);
8832 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
8833 it
.last_visible_y
, -1,
8834 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8835 dy
= it
.current_y
- y0
;
8836 if (dy
> scroll_max
)
8839 /* Compute new window start. */
8840 start_display (&it
, w
, startp
);
8842 if (scroll_conservatively
)
8843 amount_to_scroll
= dy
;
8844 else if (scroll_step
|| temp_scroll_step
)
8845 amount_to_scroll
= scroll_max
;
8848 aggressive
= current_buffer
->scroll_up_aggressively
;
8849 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8850 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8851 if (NUMBERP (aggressive
))
8852 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8855 if (amount_to_scroll
<= 0)
8858 move_it_vertically (&it
, - amount_to_scroll
);
8859 startp
= it
.current
.pos
;
8863 /* Run window scroll functions. */
8864 startp
= run_window_scroll_functions (window
, startp
);
8866 /* Display the window. Give up if new fonts are loaded, or if point
8868 if (!try_window (window
, startp
))
8870 else if (w
->cursor
.vpos
< 0)
8872 clear_glyph_matrix (w
->desired_matrix
);
8877 /* Maybe forget recorded base line for line number display. */
8878 if (!just_this_one_p
8879 || current_buffer
->clip_changed
8880 || BEG_UNCHANGED
< CHARPOS (startp
))
8881 w
->base_line_number
= Qnil
;
8883 /* If cursor ends up on a partially visible line, shift display
8884 lines up or down. */
8885 make_cursor_line_fully_visible (w
);
8893 /* Compute a suitable window start for window W if display of W starts
8894 on a continuation line. Value is non-zero if a new window start
8897 The new window start will be computed, based on W's width, starting
8898 from the start of the continued line. It is the start of the
8899 screen line with the minimum distance from the old start W->start. */
8902 compute_window_start_on_continuation_line (w
)
8905 struct text_pos pos
, start_pos
;
8906 int window_start_changed_p
= 0;
8908 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
8910 /* If window start is on a continuation line... Window start may be
8911 < BEGV in case there's invisible text at the start of the
8912 buffer (M-x rmail, for example). */
8913 if (CHARPOS (start_pos
) > BEGV
8914 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
8917 struct glyph_row
*row
;
8919 /* Handle the case that the window start is out of range. */
8920 if (CHARPOS (start_pos
) < BEGV
)
8921 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
8922 else if (CHARPOS (start_pos
) > ZV
)
8923 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
8925 /* Find the start of the continued line. This should be fast
8926 because scan_buffer is fast (newline cache). */
8927 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
8928 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
8929 row
, DEFAULT_FACE_ID
);
8930 reseat_at_previous_visible_line_start (&it
);
8932 /* If the line start is "too far" away from the window start,
8933 say it takes too much time to compute a new window start. */
8934 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
8935 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
8937 int min_distance
, distance
;
8939 /* Move forward by display lines to find the new window
8940 start. If window width was enlarged, the new start can
8941 be expected to be > the old start. If window width was
8942 decreased, the new window start will be < the old start.
8943 So, we're looking for the display line start with the
8944 minimum distance from the old window start. */
8945 pos
= it
.current
.pos
;
8946 min_distance
= INFINITY
;
8947 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
8948 distance
< min_distance
)
8950 min_distance
= distance
;
8951 pos
= it
.current
.pos
;
8952 move_it_by_lines (&it
, 1, 0);
8955 /* Set the window start there. */
8956 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
8957 window_start_changed_p
= 1;
8961 return window_start_changed_p
;
8965 /* Try cursor movement in case text has not changes in window WINDOW,
8966 with window start STARTP. Value is
8970 0 if this method cannot be used
8972 -1 if we know we have to scroll the display. *SCROLL_STEP is
8973 set to 1, under certain circumstances, if we want to scroll as
8974 if scroll-step were set to 1. See the code. */
8977 try_cursor_movement (window
, startp
, scroll_step
)
8979 struct text_pos startp
;
8982 struct window
*w
= XWINDOW (window
);
8983 struct frame
*f
= XFRAME (w
->frame
);
8986 /* Handle case where text has not changed, only point, and it has
8987 not moved off the frame. */
8988 if (/* Point may be in this window. */
8989 PT
>= CHARPOS (startp
)
8990 /* If we don't check this, we are called to move the cursor in a
8991 horizontally split window with a current matrix that doesn't
8993 && !windows_or_buffers_changed
8994 /* Selective display hasn't changed. */
8995 && !current_buffer
->clip_changed
8996 /* If force-mode-line-update was called, really redisplay;
8997 that's how redisplay is forced after e.g. changing
8998 buffer-invisibility-spec. */
8999 && NILP (w
->update_mode_line
)
9000 /* Can't use this case if highlighting a region. When a
9001 region exists, cursor movement has to do more than just
9003 && !(!NILP (Vtransient_mark_mode
)
9004 && !NILP (current_buffer
->mark_active
))
9005 && NILP (w
->region_showing
)
9006 && NILP (Vshow_trailing_whitespace
)
9007 /* Right after splitting windows, last_point may be nil. */
9008 && INTEGERP (w
->last_point
)
9009 /* This code is not used for mini-buffer for the sake of the case
9010 of redisplaying to replace an echo area message; since in
9011 that case the mini-buffer contents per se are usually
9012 unchanged. This code is of no real use in the mini-buffer
9013 since the handling of this_line_start_pos, etc., in redisplay
9014 handles the same cases. */
9015 && !EQ (window
, minibuf_window
)
9016 /* When splitting windows or for new windows, it happens that
9017 redisplay is called with a nil window_end_vpos or one being
9018 larger than the window. This should really be fixed in
9019 window.c. I don't have this on my list, now, so we do
9020 approximately the same as the old redisplay code. --gerd. */
9021 && INTEGERP (w
->window_end_vpos
)
9022 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9023 && (FRAME_WINDOW_P (f
)
9024 || !MARKERP (Voverlay_arrow_position
)
9025 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9027 int this_scroll_margin
;
9028 struct glyph_row
*row
;
9031 debug_method_add (w
, "cursor movement");
9034 /* Scroll if point within this distance from the top or bottom
9035 of the window. This is a pixel value. */
9036 this_scroll_margin
= max (0, scroll_margin
);
9037 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9038 this_scroll_margin
*= CANON_Y_UNIT (f
);
9040 /* Start with the row the cursor was displayed during the last
9041 not paused redisplay. Give up if that row is not valid. */
9042 if (w
->last_cursor
.vpos
< 0
9043 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9047 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9048 if (row
->mode_line_p
)
9050 if (!row
->enabled_p
)
9057 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9060 if (PT
> XFASTINT (w
->last_point
))
9062 /* Point has moved forward. */
9063 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9064 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9066 xassert (row
->enabled_p
);
9070 /* The end position of a row equals the start position
9071 of the next row. If PT is there, we would rather
9072 display it in the next line. */
9073 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9074 && MATRIX_ROW_END_CHARPOS (row
) == PT
9075 && !cursor_row_p (w
, row
))
9078 /* If within the scroll margin, scroll. Note that
9079 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9080 the next line would be drawn, and that
9081 this_scroll_margin can be zero. */
9082 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9083 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9084 /* Line is completely visible last line in window
9085 and PT is to be set in the next line. */
9086 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9087 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9088 && !row
->ends_at_zv_p
9089 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9092 else if (PT
< XFASTINT (w
->last_point
))
9094 /* Cursor has to be moved backward. Note that PT >=
9095 CHARPOS (startp) because of the outer
9097 while (!row
->mode_line_p
9098 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9099 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9100 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9101 && (row
->y
> this_scroll_margin
9102 || CHARPOS (startp
) == BEGV
))
9104 xassert (row
->enabled_p
);
9108 /* Consider the following case: Window starts at BEGV,
9109 there is invisible, intangible text at BEGV, so that
9110 display starts at some point START > BEGV. It can
9111 happen that we are called with PT somewhere between
9112 BEGV and START. Try to handle that case. */
9113 if (row
< w
->current_matrix
->rows
9114 || row
->mode_line_p
)
9116 row
= w
->current_matrix
->rows
;
9117 if (row
->mode_line_p
)
9121 /* Due to newlines in overlay strings, we may have to
9122 skip forward over overlay strings. */
9123 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9124 && MATRIX_ROW_END_CHARPOS (row
) == PT
9125 && !cursor_row_p (w
, row
))
9128 /* If within the scroll margin, scroll. */
9129 if (row
->y
< this_scroll_margin
9130 && CHARPOS (startp
) != BEGV
)
9134 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9135 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9137 /* if PT is not in the glyph row, give up. */
9140 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9142 /* If we end up in a partially visible line, let's make it
9143 fully visible, except when it's taller than the window,
9144 in which case we can't do much about it. */
9145 if (row
->height
> window_box_height (w
))
9152 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9153 try_window (window
, startp
);
9154 make_cursor_line_fully_visible (w
);
9162 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9172 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9173 selected_window is redisplayed. */
9176 redisplay_window (window
, just_this_one_p
)
9178 int just_this_one_p
;
9180 struct window
*w
= XWINDOW (window
);
9181 struct frame
*f
= XFRAME (w
->frame
);
9182 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9183 struct buffer
*old
= current_buffer
;
9184 struct text_pos lpoint
, opoint
, startp
;
9185 int update_mode_line
;
9188 /* Record it now because it's overwritten. */
9189 int current_matrix_up_to_date_p
= 0;
9190 int temp_scroll_step
= 0;
9191 int count
= specpdl_ptr
- specpdl
;
9194 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9197 /* W must be a leaf window here. */
9198 xassert (!NILP (w
->buffer
));
9200 *w
->desired_matrix
->method
= 0;
9203 specbind (Qinhibit_point_motion_hooks
, Qt
);
9205 reconsider_clip_changes (w
, buffer
);
9207 /* Has the mode line to be updated? */
9208 update_mode_line
= (!NILP (w
->update_mode_line
)
9209 || update_mode_lines
9210 || buffer
->clip_changed
);
9212 if (MINI_WINDOW_P (w
))
9214 if (w
== XWINDOW (echo_area_window
)
9215 && !NILP (echo_area_buffer
[0]))
9217 if (update_mode_line
)
9218 /* We may have to update a tty frame's menu bar or a
9219 tool-bar. Example `M-x C-h C-h C-g'. */
9220 goto finish_menu_bars
;
9222 /* We've already displayed the echo area glyphs in this window. */
9223 goto finish_scroll_bars
;
9225 else if (w
!= XWINDOW (minibuf_window
))
9227 /* W is a mini-buffer window, but it's not the currently
9228 active one, so clear it. */
9229 int yb
= window_text_bottom_y (w
);
9230 struct glyph_row
*row
;
9233 for (y
= 0, row
= w
->desired_matrix
->rows
;
9235 y
+= row
->height
, ++row
)
9236 blank_row (w
, row
, y
);
9237 goto finish_scroll_bars
;
9241 /* Otherwise set up data on this window; select its buffer and point
9243 /* Really select the buffer, for the sake of buffer-local
9245 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9246 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9248 current_matrix_up_to_date_p
9249 = (!NILP (w
->window_end_valid
)
9250 && !current_buffer
->clip_changed
9251 && XFASTINT (w
->last_modified
) >= MODIFF
9252 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9254 /* When windows_or_buffers_changed is non-zero, we can't rely on
9255 the window end being valid, so set it to nil there. */
9256 if (windows_or_buffers_changed
)
9258 /* If window starts on a continuation line, maybe adjust the
9259 window start in case the window's width changed. */
9260 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9261 compute_window_start_on_continuation_line (w
);
9263 w
->window_end_valid
= Qnil
;
9266 /* Some sanity checks. */
9267 CHECK_WINDOW_END (w
);
9268 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9270 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9273 /* If %c is in mode line, update it if needed. */
9274 if (!NILP (w
->column_number_displayed
)
9275 /* This alternative quickly identifies a common case
9276 where no change is needed. */
9277 && !(PT
== XFASTINT (w
->last_point
)
9278 && XFASTINT (w
->last_modified
) >= MODIFF
9279 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9280 && XFASTINT (w
->column_number_displayed
) != current_column ())
9281 update_mode_line
= 1;
9283 /* Count number of windows showing the selected buffer. An indirect
9284 buffer counts as its base buffer. */
9285 if (!just_this_one_p
)
9287 struct buffer
*current_base
, *window_base
;
9288 current_base
= current_buffer
;
9289 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9290 if (current_base
->base_buffer
)
9291 current_base
= current_base
->base_buffer
;
9292 if (window_base
->base_buffer
)
9293 window_base
= window_base
->base_buffer
;
9294 if (current_base
== window_base
)
9298 /* Point refers normally to the selected window. For any other
9299 window, set up appropriate value. */
9300 if (!EQ (window
, selected_window
))
9302 int new_pt
= XMARKER (w
->pointm
)->charpos
;
9303 int new_pt_byte
= marker_byte_position (w
->pointm
);
9307 new_pt_byte
= BEGV_BYTE
;
9308 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
9310 else if (new_pt
> (ZV
- 1))
9313 new_pt_byte
= ZV_BYTE
;
9314 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
9317 /* We don't use SET_PT so that the point-motion hooks don't run. */
9318 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
9321 /* If any of the character widths specified in the display table
9322 have changed, invalidate the width run cache. It's true that
9323 this may be a bit late to catch such changes, but the rest of
9324 redisplay goes (non-fatally) haywire when the display table is
9325 changed, so why should we worry about doing any better? */
9326 if (current_buffer
->width_run_cache
)
9328 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
9330 if (! disptab_matches_widthtab (disptab
,
9331 XVECTOR (current_buffer
->width_table
)))
9333 invalidate_region_cache (current_buffer
,
9334 current_buffer
->width_run_cache
,
9336 recompute_width_table (current_buffer
, disptab
);
9340 /* If window-start is screwed up, choose a new one. */
9341 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
9344 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9346 /* If someone specified a new starting point but did not insist,
9347 check whether it can be used. */
9348 if (!NILP (w
->optional_new_start
)
9349 && CHARPOS (startp
) >= BEGV
9350 && CHARPOS (startp
) <= ZV
)
9352 w
->optional_new_start
= Qnil
;
9353 start_display (&it
, w
, startp
);
9354 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9355 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9356 if (IT_CHARPOS (it
) == PT
)
9357 w
->force_start
= Qt
;
9360 /* Handle case where place to start displaying has been specified,
9361 unless the specified location is outside the accessible range. */
9362 if (!NILP (w
->force_start
)
9363 || w
->frozen_window_start_p
)
9365 w
->force_start
= Qnil
;
9367 w
->window_end_valid
= Qnil
;
9369 /* Forget any recorded base line for line number display. */
9370 if (!current_matrix_up_to_date_p
9371 || current_buffer
->clip_changed
)
9372 w
->base_line_number
= Qnil
;
9374 /* Redisplay the mode line. Select the buffer properly for that.
9375 Also, run the hook window-scroll-functions
9376 because we have scrolled. */
9377 /* Note, we do this after clearing force_start because
9378 if there's an error, it is better to forget about force_start
9379 than to get into an infinite loop calling the hook functions
9380 and having them get more errors. */
9381 if (!update_mode_line
9382 || ! NILP (Vwindow_scroll_functions
))
9384 update_mode_line
= 1;
9385 w
->update_mode_line
= Qt
;
9386 startp
= run_window_scroll_functions (window
, startp
);
9389 XSETFASTINT (w
->last_modified
, 0);
9390 XSETFASTINT (w
->last_overlay_modified
, 0);
9391 if (CHARPOS (startp
) < BEGV
)
9392 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
9393 else if (CHARPOS (startp
) > ZV
)
9394 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
9396 /* Redisplay, then check if cursor has been set during the
9397 redisplay. Give up if new fonts were loaded. */
9398 if (!try_window (window
, startp
))
9400 w
->force_start
= Qt
;
9401 clear_glyph_matrix (w
->desired_matrix
);
9402 goto restore_buffers
;
9405 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
9407 /* If point does not appear, try to move point so it does
9408 appear. The desired matrix has been built above, so we
9411 struct glyph_row
*row
;
9413 window_height
= window_box_height (w
) / 2;
9414 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
9415 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
9418 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
9419 MATRIX_ROW_START_BYTEPOS (row
));
9421 if (w
!= XWINDOW (selected_window
))
9422 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
9423 else if (current_buffer
== old
)
9424 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9426 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
9428 /* If we are highlighting the region, then we just changed
9429 the region, so redisplay to show it. */
9430 if (!NILP (Vtransient_mark_mode
)
9431 && !NILP (current_buffer
->mark_active
))
9433 clear_glyph_matrix (w
->desired_matrix
);
9434 if (!try_window (window
, startp
))
9435 goto restore_buffers
;
9439 make_cursor_line_fully_visible (w
);
9441 debug_method_add (w
, "forced window start");
9446 /* Handle case where text has not changed, only point, and it has
9447 not moved off the frame. */
9448 if (current_matrix_up_to_date_p
9449 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
9457 /* If current starting point was originally the beginning of a line
9458 but no longer is, find a new starting point. */
9459 else if (!NILP (w
->start_at_line_beg
)
9460 && !(CHARPOS (startp
) <= BEGV
9461 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
9464 debug_method_add (w
, "recenter 1");
9469 /* Try scrolling with try_window_id. */
9470 else if (/* Windows and buffers haven't changed. */
9471 !windows_or_buffers_changed
9472 /* Window must be either use window-based redisplay or
9474 && (FRAME_WINDOW_P (f
)
9475 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
9476 && !MINI_WINDOW_P (w
)
9477 /* Point is not known NOT to appear in window. */
9478 && PT
>= CHARPOS (startp
)
9479 && XFASTINT (w
->last_modified
)
9480 /* Window is not hscrolled. */
9481 && XFASTINT (w
->hscroll
) == 0
9482 /* Selective display has not changed. */
9483 && !current_buffer
->clip_changed
9484 /* Current matrix is up to date. */
9485 && !NILP (w
->window_end_valid
)
9486 /* Can't use this case if highlighting a region because
9487 a cursor movement will do more than just set the cursor. */
9488 && !(!NILP (Vtransient_mark_mode
)
9489 && !NILP (current_buffer
->mark_active
))
9490 && NILP (w
->region_showing
)
9491 && NILP (Vshow_trailing_whitespace
)
9492 /* Overlay arrow position and string not changed. */
9493 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
9494 && EQ (last_arrow_string
, Voverlay_arrow_string
)
9495 /* Value is > 0 if update has been done, it is -1 if we
9496 know that the same window start will not work. It is 0
9497 if unsuccessful for some other reason. */
9498 && (tem
= try_window_id (w
)) != 0)
9501 debug_method_add (w
, "try_window_id %d", tem
);
9504 if (fonts_changed_p
)
9505 goto restore_buffers
;
9509 /* Otherwise try_window_id has returned -1 which means that we
9510 don't want the alternative below this comment to execute. */
9512 else if (CHARPOS (startp
) >= BEGV
9513 && CHARPOS (startp
) <= ZV
9514 && PT
>= CHARPOS (startp
)
9515 && (CHARPOS (startp
) < ZV
9516 /* Avoid starting at end of buffer. */
9517 || CHARPOS (startp
) == BEGV
9518 || (XFASTINT (w
->last_modified
) >= MODIFF
9519 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
9522 debug_method_add (w
, "same window start");
9525 /* Try to redisplay starting at same place as before.
9526 If point has not moved off frame, accept the results. */
9527 if (!current_matrix_up_to_date_p
9528 /* Don't use try_window_reusing_current_matrix in this case
9529 because a window scroll function can have changed the
9531 || !NILP (Vwindow_scroll_functions
)
9532 || MINI_WINDOW_P (w
)
9533 || !try_window_reusing_current_matrix (w
))
9535 IF_DEBUG (debug_method_add (w
, "1"));
9536 try_window (window
, startp
);
9539 if (fonts_changed_p
)
9540 goto restore_buffers
;
9542 if (w
->cursor
.vpos
>= 0)
9544 if (!just_this_one_p
9545 || current_buffer
->clip_changed
9546 || BEG_UNCHANGED
< CHARPOS (startp
))
9547 /* Forget any recorded base line for line number display. */
9548 w
->base_line_number
= Qnil
;
9550 make_cursor_line_fully_visible (w
);
9554 clear_glyph_matrix (w
->desired_matrix
);
9559 XSETFASTINT (w
->last_modified
, 0);
9560 XSETFASTINT (w
->last_overlay_modified
, 0);
9562 /* Redisplay the mode line. Select the buffer properly for that. */
9563 if (!update_mode_line
)
9565 update_mode_line
= 1;
9566 w
->update_mode_line
= Qt
;
9569 /* Try to scroll by specified few lines. */
9570 if ((scroll_conservatively
9573 || NUMBERP (current_buffer
->scroll_up_aggressively
)
9574 || NUMBERP (current_buffer
->scroll_down_aggressively
))
9575 && !current_buffer
->clip_changed
9576 && CHARPOS (startp
) >= BEGV
9577 && CHARPOS (startp
) <= ZV
)
9579 /* The function returns -1 if new fonts were loaded, 1 if
9580 successful, 0 if not successful. */
9581 int rc
= try_scrolling (window
, just_this_one_p
,
9582 scroll_conservatively
,
9588 goto restore_buffers
;
9591 /* Finally, just choose place to start which centers point */
9596 debug_method_add (w
, "recenter");
9599 /* w->vscroll = 0; */
9601 /* Forget any previously recorded base line for line number display. */
9602 if (!current_matrix_up_to_date_p
9603 || current_buffer
->clip_changed
)
9604 w
->base_line_number
= Qnil
;
9606 /* Move backward half the height of the window. */
9607 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9608 it
.current_y
= it
.last_visible_y
;
9609 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
9610 xassert (IT_CHARPOS (it
) >= BEGV
);
9612 /* The function move_it_vertically_backward may move over more
9613 than the specified y-distance. If it->w is small, e.g. a
9614 mini-buffer window, we may end up in front of the window's
9615 display area. Start displaying at the start of the line
9616 containing PT in this case. */
9617 if (it
.current_y
<= 0)
9619 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9620 move_it_vertically (&it
, 0);
9621 xassert (IT_CHARPOS (it
) <= PT
);
9625 it
.current_x
= it
.hpos
= 0;
9627 /* Set startp here explicitly in case that helps avoid an infinite loop
9628 in case the window-scroll-functions functions get errors. */
9629 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
9631 /* Run scroll hooks. */
9632 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
9634 /* Redisplay the window. */
9635 if (!current_matrix_up_to_date_p
9636 || windows_or_buffers_changed
9637 /* Don't use try_window_reusing_current_matrix in this case
9638 because it can have changed the buffer. */
9639 || !NILP (Vwindow_scroll_functions
)
9641 || MINI_WINDOW_P (w
)
9642 || !try_window_reusing_current_matrix (w
))
9643 try_window (window
, startp
);
9645 /* If new fonts have been loaded (due to fontsets), give up. We
9646 have to start a new redisplay since we need to re-adjust glyph
9648 if (fonts_changed_p
)
9649 goto restore_buffers
;
9651 /* If cursor did not appear assume that the middle of the window is
9652 in the first line of the window. Do it again with the next line.
9653 (Imagine a window of height 100, displaying two lines of height
9654 60. Moving back 50 from it->last_visible_y will end in the first
9656 if (w
->cursor
.vpos
< 0)
9658 if (!NILP (w
->window_end_valid
)
9659 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
9661 clear_glyph_matrix (w
->desired_matrix
);
9662 move_it_by_lines (&it
, 1, 0);
9663 try_window (window
, it
.current
.pos
);
9665 else if (PT
< IT_CHARPOS (it
))
9667 clear_glyph_matrix (w
->desired_matrix
);
9668 move_it_by_lines (&it
, -1, 0);
9669 try_window (window
, it
.current
.pos
);
9673 /* Not much we can do about it. */
9677 /* Consider the following case: Window starts at BEGV, there is
9678 invisible, intangible text at BEGV, so that display starts at
9679 some point START > BEGV. It can happen that we are called with
9680 PT somewhere between BEGV and START. Try to handle that case. */
9681 if (w
->cursor
.vpos
< 0)
9683 struct glyph_row
*row
= w
->current_matrix
->rows
;
9684 if (row
->mode_line_p
)
9686 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9689 make_cursor_line_fully_visible (w
);
9693 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9694 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
9695 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
9698 /* Display the mode line, if we must. */
9699 if ((update_mode_line
9700 /* If window not full width, must redo its mode line
9701 if (a) the window to its side is being redone and
9702 (b) we do a frame-based redisplay. This is a consequence
9703 of how inverted lines are drawn in frame-based redisplay. */
9704 || (!just_this_one_p
9705 && !FRAME_WINDOW_P (f
)
9706 && !WINDOW_FULL_WIDTH_P (w
))
9707 /* Line number to display. */
9708 || INTEGERP (w
->base_line_pos
)
9709 /* Column number is displayed and different from the one displayed. */
9710 || (!NILP (w
->column_number_displayed
)
9711 && XFASTINT (w
->column_number_displayed
) != current_column ()))
9712 /* This means that the window has a mode line. */
9713 && (WINDOW_WANTS_MODELINE_P (w
)
9714 || WINDOW_WANTS_HEADER_LINE_P (w
)))
9716 Lisp_Object old_selected_frame
;
9718 old_selected_frame
= selected_frame
;
9720 XSETFRAME (selected_frame
, f
);
9721 display_mode_lines (w
);
9722 selected_frame
= old_selected_frame
;
9724 /* If mode line height has changed, arrange for a thorough
9725 immediate redisplay using the correct mode line height. */
9726 if (WINDOW_WANTS_MODELINE_P (w
)
9727 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
9729 fonts_changed_p
= 1;
9730 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
9731 = DESIRED_MODE_LINE_HEIGHT (w
);
9734 /* If top line height has changed, arrange for a thorough
9735 immediate redisplay using the correct mode line height. */
9736 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9737 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
9739 fonts_changed_p
= 1;
9740 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
9741 = DESIRED_HEADER_LINE_HEIGHT (w
);
9744 if (fonts_changed_p
)
9745 goto restore_buffers
;
9748 if (!line_number_displayed
9749 && !BUFFERP (w
->base_line_pos
))
9751 w
->base_line_pos
= Qnil
;
9752 w
->base_line_number
= Qnil
;
9757 /* When we reach a frame's selected window, redo the frame's menu bar. */
9758 if (update_mode_line
9759 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
9761 int redisplay_menu_p
= 0;
9763 if (FRAME_WINDOW_P (f
))
9765 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
9766 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
9768 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9772 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9774 if (redisplay_menu_p
)
9775 display_menu_bar (w
);
9777 #ifdef HAVE_WINDOW_SYSTEM
9778 if (WINDOWP (f
->tool_bar_window
)
9779 && (FRAME_TOOL_BAR_LINES (f
) > 0
9780 || auto_resize_tool_bars_p
))
9781 redisplay_tool_bar (f
);
9787 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9789 int start
, end
, whole
;
9791 /* Calculate the start and end positions for the current window.
9792 At some point, it would be nice to choose between scrollbars
9793 which reflect the whole buffer size, with special markers
9794 indicating narrowing, and scrollbars which reflect only the
9797 Note that mini-buffers sometimes aren't displaying any text. */
9798 if (!MINI_WINDOW_P (w
)
9799 || (w
== XWINDOW (minibuf_window
)
9800 && NILP (echo_area_buffer
[0])))
9803 start
= marker_position (w
->start
) - BEGV
;
9804 /* I don't think this is guaranteed to be right. For the
9805 moment, we'll pretend it is. */
9806 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
9810 if (whole
< (end
- start
))
9811 whole
= end
- start
;
9814 start
= end
= whole
= 0;
9816 /* Indicate what this scroll bar ought to be displaying now. */
9817 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
9819 /* Note that we actually used the scroll bar attached to this
9820 window, so it shouldn't be deleted at the end of redisplay. */
9821 (*redeem_scroll_bar_hook
) (w
);
9826 /* Restore current_buffer and value of point in it. */
9827 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
9828 set_buffer_internal_1 (old
);
9829 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
9831 unbind_to (count
, Qnil
);
9835 /* Build the complete desired matrix of WINDOW with a window start
9836 buffer position POS. Value is non-zero if successful. It is zero
9837 if fonts were loaded during redisplay which makes re-adjusting
9838 glyph matrices necessary. */
9841 try_window (window
, pos
)
9843 struct text_pos pos
;
9845 struct window
*w
= XWINDOW (window
);
9847 struct glyph_row
*last_text_row
= NULL
;
9849 /* Make POS the new window start. */
9850 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
9852 /* Mark cursor position as unknown. No overlay arrow seen. */
9853 w
->cursor
.vpos
= -1;
9854 overlay_arrow_seen
= 0;
9856 /* Initialize iterator and info to start at POS. */
9857 start_display (&it
, w
, pos
);
9859 /* Display all lines of W. */
9860 while (it
.current_y
< it
.last_visible_y
)
9862 if (display_line (&it
))
9863 last_text_row
= it
.glyph_row
- 1;
9864 if (fonts_changed_p
)
9868 /* If bottom moved off end of frame, change mode line percentage. */
9869 if (XFASTINT (w
->window_end_pos
) <= 0
9870 && Z
!= IT_CHARPOS (it
))
9871 w
->update_mode_line
= Qt
;
9873 /* Set window_end_pos to the offset of the last character displayed
9874 on the window from the end of current_buffer. Set
9875 window_end_vpos to its row number. */
9878 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
9879 w
->window_end_bytepos
9880 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9881 XSETFASTINT (w
->window_end_pos
,
9882 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9883 XSETFASTINT (w
->window_end_vpos
,
9884 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9885 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
9890 w
->window_end_bytepos
= 0;
9891 XSETFASTINT (w
->window_end_pos
, 0);
9892 XSETFASTINT (w
->window_end_vpos
, 0);
9895 /* But that is not valid info until redisplay finishes. */
9896 w
->window_end_valid
= Qnil
;
9902 /************************************************************************
9903 Window redisplay reusing current matrix when buffer has not changed
9904 ************************************************************************/
9906 /* Try redisplay of window W showing an unchanged buffer with a
9907 different window start than the last time it was displayed by
9908 reusing its current matrix. Value is non-zero if successful.
9909 W->start is the new window start. */
9912 try_window_reusing_current_matrix (w
)
9915 struct frame
*f
= XFRAME (w
->frame
);
9916 struct glyph_row
*row
, *bottom_row
;
9919 struct text_pos start
, new_start
;
9920 int nrows_scrolled
, i
;
9921 struct glyph_row
*last_text_row
;
9922 struct glyph_row
*last_reused_text_row
;
9923 struct glyph_row
*start_row
;
9924 int start_vpos
, min_y
, max_y
;
9926 if (/* This function doesn't handle terminal frames. */
9928 /* Don't try to reuse the display if windows have been split
9930 || windows_or_buffers_changed
)
9933 /* Can't do this if region may have changed. */
9934 if ((!NILP (Vtransient_mark_mode
)
9935 && !NILP (current_buffer
->mark_active
))
9936 || !NILP (w
->region_showing
)
9937 || !NILP (Vshow_trailing_whitespace
))
9940 /* If top-line visibility has changed, give up. */
9941 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9942 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
9945 /* Give up if old or new display is scrolled vertically. We could
9946 make this function handle this, but right now it doesn't. */
9947 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9948 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
9951 /* The variable new_start now holds the new window start. The old
9952 start `start' can be determined from the current matrix. */
9953 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
9954 start
= start_row
->start
.pos
;
9955 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
9957 /* Clear the desired matrix for the display below. */
9958 clear_glyph_matrix (w
->desired_matrix
);
9960 if (CHARPOS (new_start
) <= CHARPOS (start
))
9964 IF_DEBUG (debug_method_add (w
, "twu1"));
9966 /* Display up to a row that can be reused. The variable
9967 last_text_row is set to the last row displayed that displays
9968 text. Note that it.vpos == 0 if or if not there is a
9969 header-line; it's not the same as the MATRIX_ROW_VPOS! */
9970 start_display (&it
, w
, new_start
);
9971 first_row_y
= it
.current_y
;
9972 w
->cursor
.vpos
= -1;
9973 last_text_row
= last_reused_text_row
= NULL
;
9975 while (it
.current_y
< it
.last_visible_y
9976 && IT_CHARPOS (it
) < CHARPOS (start
)
9977 && !fonts_changed_p
)
9978 if (display_line (&it
))
9979 last_text_row
= it
.glyph_row
- 1;
9981 /* A value of current_y < last_visible_y means that we stopped
9982 at the previous window start, which in turn means that we
9983 have at least one reusable row. */
9984 if (it
.current_y
< it
.last_visible_y
)
9986 /* IT.vpos always starts from 0; it counts text lines. */
9987 nrows_scrolled
= it
.vpos
;
9989 /* Find PT if not already found in the lines displayed. */
9990 if (w
->cursor
.vpos
< 0)
9992 int dy
= it
.current_y
- first_row_y
;
9994 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9995 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9997 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
9998 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10000 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10001 dy
, nrows_scrolled
);
10005 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
10011 /* Give up if point was not found. This shouldn't
10012 happen often; not more often than with try_window
10014 if (w
->cursor
.vpos
< 0)
10016 clear_glyph_matrix (w
->desired_matrix
);
10021 /* Scroll the display. Do it before the current matrix is
10022 changed. The problem here is that update has not yet
10023 run, i.e. part of the current matrix is not up to date.
10024 scroll_run_hook will clear the cursor, and use the
10025 current matrix to get the height of the row the cursor is
10027 run
.current_y
= first_row_y
;
10028 run
.desired_y
= it
.current_y
;
10029 run
.height
= it
.last_visible_y
- it
.current_y
;
10031 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10034 rif
->update_window_begin_hook (w
);
10035 rif
->clear_mouse_face (w
);
10036 rif
->scroll_run_hook (w
, &run
);
10037 rif
->update_window_end_hook (w
, 0, 0);
10041 /* Shift current matrix down by nrows_scrolled lines. */
10042 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10043 rotate_matrix (w
->current_matrix
,
10045 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10048 /* Disable lines not reused. */
10049 for (i
= 0; i
< it
.vpos
; ++i
)
10050 (start_row
+ i
)->enabled_p
= 0;
10052 /* Re-compute Y positions. */
10053 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10054 max_y
= it
.last_visible_y
;
10055 for (row
= start_row
+ nrows_scrolled
;
10059 row
->y
= it
.current_y
;
10061 if (row
->y
< min_y
)
10062 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10063 else if (row
->y
+ row
->height
> max_y
)
10064 row
->visible_height
10065 = row
->height
- (row
->y
+ row
->height
- max_y
);
10067 row
->visible_height
= row
->height
;
10069 it
.current_y
+= row
->height
;
10071 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10072 last_reused_text_row
= row
;
10073 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10078 /* Update window_end_pos etc.; last_reused_text_row is the last
10079 reused row from the current matrix containing text, if any.
10080 The value of last_text_row is the last displayed line
10081 containing text. */
10082 if (last_reused_text_row
)
10084 w
->window_end_bytepos
10085 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10086 XSETFASTINT (w
->window_end_pos
,
10087 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10088 XSETFASTINT (w
->window_end_vpos
,
10089 MATRIX_ROW_VPOS (last_reused_text_row
,
10090 w
->current_matrix
));
10092 else if (last_text_row
)
10094 w
->window_end_bytepos
10095 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10096 XSETFASTINT (w
->window_end_pos
,
10097 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10098 XSETFASTINT (w
->window_end_vpos
,
10099 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10103 /* This window must be completely empty. */
10104 w
->window_end_bytepos
= 0;
10105 XSETFASTINT (w
->window_end_pos
, 0);
10106 XSETFASTINT (w
->window_end_vpos
, 0);
10108 w
->window_end_valid
= Qnil
;
10110 /* Update hint: don't try scrolling again in update_window. */
10111 w
->desired_matrix
->no_scrolling_p
= 1;
10114 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10118 else if (CHARPOS (new_start
) > CHARPOS (start
))
10120 struct glyph_row
*pt_row
, *row
;
10121 struct glyph_row
*first_reusable_row
;
10122 struct glyph_row
*first_row_to_display
;
10124 int yb
= window_text_bottom_y (w
);
10126 IF_DEBUG (debug_method_add (w
, "twu2"));
10128 /* Find the row starting at new_start, if there is one. Don't
10129 reuse a partially visible line at the end. */
10130 first_reusable_row
= start_row
;
10131 while (first_reusable_row
->enabled_p
10132 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10133 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10134 < CHARPOS (new_start
)))
10135 ++first_reusable_row
;
10137 /* Give up if there is no row to reuse. */
10138 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10139 || !first_reusable_row
->enabled_p
10140 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10141 != CHARPOS (new_start
)))
10144 /* We can reuse fully visible rows beginning with
10145 first_reusable_row to the end of the window. Set
10146 first_row_to_display to the first row that cannot be reused.
10147 Set pt_row to the row containing point, if there is any. */
10148 first_row_to_display
= first_reusable_row
;
10150 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
10152 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10153 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10154 pt_row
= first_row_to_display
;
10156 ++first_row_to_display
;
10159 /* Start displaying at the start of first_row_to_display. */
10160 xassert (first_row_to_display
->y
< yb
);
10161 init_to_row_start (&it
, w
, first_row_to_display
);
10162 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10164 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10166 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10167 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10169 /* Display lines beginning with first_row_to_display in the
10170 desired matrix. Set last_text_row to the last row displayed
10171 that displays text. */
10172 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10173 if (pt_row
== NULL
)
10174 w
->cursor
.vpos
= -1;
10175 last_text_row
= NULL
;
10176 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10177 if (display_line (&it
))
10178 last_text_row
= it
.glyph_row
- 1;
10180 /* Give up If point isn't in a row displayed or reused. */
10181 if (w
->cursor
.vpos
< 0)
10183 clear_glyph_matrix (w
->desired_matrix
);
10187 /* If point is in a reused row, adjust y and vpos of the cursor
10191 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10192 w
->current_matrix
);
10193 w
->cursor
.y
-= first_reusable_row
->y
;
10196 /* Scroll the display. */
10197 run
.current_y
= first_reusable_row
->y
;
10198 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10199 run
.height
= it
.last_visible_y
- run
.current_y
;
10200 dy
= run
.current_y
- run
.desired_y
;
10204 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10206 rif
->update_window_begin_hook (w
);
10207 rif
->clear_mouse_face (w
);
10208 rif
->scroll_run_hook (w
, &run
);
10209 rif
->update_window_end_hook (w
, 0, 0);
10213 /* Adjust Y positions of reused rows. */
10214 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10215 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10216 max_y
= it
.last_visible_y
;
10217 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10220 if (row
->y
< min_y
)
10221 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10222 else if (row
->y
+ row
->height
> max_y
)
10223 row
->visible_height
10224 = row
->height
- (row
->y
+ row
->height
- max_y
);
10226 row
->visible_height
= row
->height
;
10229 /* Disable rows not reused. */
10230 while (row
< bottom_row
)
10232 row
->enabled_p
= 0;
10236 /* Scroll the current matrix. */
10237 xassert (nrows_scrolled
> 0);
10238 rotate_matrix (w
->current_matrix
,
10240 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10243 /* Adjust window end. A null value of last_text_row means that
10244 the window end is in reused rows which in turn means that
10245 only its vpos can have changed. */
10248 w
->window_end_bytepos
10249 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10250 XSETFASTINT (w
->window_end_pos
,
10251 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10252 XSETFASTINT (w
->window_end_vpos
,
10253 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10257 XSETFASTINT (w
->window_end_vpos
,
10258 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10261 w
->window_end_valid
= Qnil
;
10262 w
->desired_matrix
->no_scrolling_p
= 1;
10265 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10275 /************************************************************************
10276 Window redisplay reusing current matrix when buffer has changed
10277 ************************************************************************/
10279 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10280 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10282 static struct glyph_row
*
10283 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10284 struct glyph_row
*));
10287 /* Return the last row in MATRIX displaying text. If row START is
10288 non-null, start searching with that row. IT gives the dimensions
10289 of the display. Value is null if matrix is empty; otherwise it is
10290 a pointer to the row found. */
10292 static struct glyph_row
*
10293 find_last_row_displaying_text (matrix
, it
, start
)
10294 struct glyph_matrix
*matrix
;
10296 struct glyph_row
*start
;
10298 struct glyph_row
*row
, *row_found
;
10300 /* Set row_found to the last row in IT->w's current matrix
10301 displaying text. The loop looks funny but think of partially
10304 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
10305 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10307 xassert (row
->enabled_p
);
10309 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
10318 /* Return the last row in the current matrix of W that is not affected
10319 by changes at the start of current_buffer that occurred since the
10320 last time W was redisplayed. Value is null if no such row exists.
10322 The global variable beg_unchanged has to contain the number of
10323 bytes unchanged at the start of current_buffer. BEG +
10324 beg_unchanged is the buffer position of the first changed byte in
10325 current_buffer. Characters at positions < BEG + beg_unchanged are
10326 at the same buffer positions as they were when the current matrix
10329 static struct glyph_row
*
10330 find_last_unchanged_at_beg_row (w
)
10333 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
10334 struct glyph_row
*row
;
10335 struct glyph_row
*row_found
= NULL
;
10336 int yb
= window_text_bottom_y (w
);
10338 /* Find the last row displaying unchanged text. */
10339 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10340 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
10341 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
10343 if (/* If row ends before first_changed_pos, it is unchanged,
10344 except in some case. */
10345 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
10346 /* When row ends in ZV and we write at ZV it is not
10348 && !row
->ends_at_zv_p
10349 /* When first_changed_pos is the end of a continued line,
10350 row is not unchanged because it may be no longer
10352 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
10353 && row
->continued_p
))
10356 /* Stop if last visible row. */
10357 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
10367 /* Find the first glyph row in the current matrix of W that is not
10368 affected by changes at the end of current_buffer since the last
10369 time the window was redisplayed. Return in *DELTA the number of
10370 chars by which buffer positions in unchanged text at the end of
10371 current_buffer must be adjusted. Return in *DELTA_BYTES the
10372 corresponding number of bytes. Value is null if no such row
10373 exists, i.e. all rows are affected by changes. */
10375 static struct glyph_row
*
10376 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
10378 int *delta
, *delta_bytes
;
10380 struct glyph_row
*row
;
10381 struct glyph_row
*row_found
= NULL
;
10383 *delta
= *delta_bytes
= 0;
10385 /* Display must not have been paused, otherwise the current matrix
10386 is not up to date. */
10387 if (NILP (w
->window_end_valid
))
10390 /* A value of window_end_pos >= END_UNCHANGED means that the window
10391 end is in the range of changed text. If so, there is no
10392 unchanged row at the end of W's current matrix. */
10393 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
10396 /* Set row to the last row in W's current matrix displaying text. */
10397 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10399 /* If matrix is entirely empty, no unchanged row exists. */
10400 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10402 /* The value of row is the last glyph row in the matrix having a
10403 meaningful buffer position in it. The end position of row
10404 corresponds to window_end_pos. This allows us to translate
10405 buffer positions in the current matrix to current buffer
10406 positions for characters not in changed text. */
10407 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
10408 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
10409 int last_unchanged_pos
, last_unchanged_pos_old
;
10410 struct glyph_row
*first_text_row
10411 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10413 *delta
= Z
- Z_old
;
10414 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
10416 /* Set last_unchanged_pos to the buffer position of the last
10417 character in the buffer that has not been changed. Z is the
10418 index + 1 of the last byte in current_buffer, i.e. by
10419 subtracting end_unchanged we get the index of the last
10420 unchanged character, and we have to add BEG to get its buffer
10422 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
10423 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
10425 /* Search backward from ROW for a row displaying a line that
10426 starts at a minimum position >= last_unchanged_pos_old. */
10427 for (; row
> first_text_row
; --row
)
10429 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10432 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
10437 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
10444 /* Make sure that glyph rows in the current matrix of window W
10445 reference the same glyph memory as corresponding rows in the
10446 frame's frame matrix. This function is called after scrolling W's
10447 current matrix on a terminal frame in try_window_id and
10448 try_window_reusing_current_matrix. */
10451 sync_frame_with_window_matrix_rows (w
)
10454 struct frame
*f
= XFRAME (w
->frame
);
10455 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
10457 /* Preconditions: W must be a leaf window and full-width. Its frame
10458 must have a frame matrix. */
10459 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
10460 xassert (WINDOW_FULL_WIDTH_P (w
));
10461 xassert (!FRAME_WINDOW_P (f
));
10463 /* If W is a full-width window, glyph pointers in W's current matrix
10464 have, by definition, to be the same as glyph pointers in the
10465 corresponding frame matrix. */
10466 window_row
= w
->current_matrix
->rows
;
10467 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
10468 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
10469 while (window_row
< window_row_end
)
10473 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
10474 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
10476 /* Disable frame rows whose corresponding window rows have
10477 been disabled in try_window_id. */
10478 if (!window_row
->enabled_p
)
10479 frame_row
->enabled_p
= 0;
10481 ++window_row
, ++frame_row
;
10486 /* Find the glyph row in window W containing CHARPOS. Consider all
10487 rows between START and END (not inclusive). END null means search
10488 all rows to the end of the display area of W. Value is the row
10489 containing CHARPOS or null. */
10491 static struct glyph_row
*
10492 row_containing_pos (w
, charpos
, start
, end
)
10495 struct glyph_row
*start
, *end
;
10497 struct glyph_row
*row
= start
;
10500 /* If we happen to start on a header-line, skip that. */
10501 if (row
->mode_line_p
)
10504 if ((end
&& row
>= end
) || !row
->enabled_p
)
10507 last_y
= window_text_bottom_y (w
);
10509 while ((end
== NULL
|| row
< end
)
10510 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
10511 /* The end position of a row equals the start
10512 position of the next row. If CHARPOS is there, we
10513 would rather display it in the next line, except
10514 when this line ends in ZV. */
10515 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
10516 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
10517 || !row
->ends_at_zv_p
)))
10518 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
10521 /* Give up if CHARPOS not found. */
10522 if ((end
&& row
>= end
)
10523 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
10524 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
10531 /* Try to redisplay window W by reusing its existing display. W's
10532 current matrix must be up to date when this function is called,
10533 i.e. window_end_valid must not be nil.
10537 1 if display has been updated
10538 0 if otherwise unsuccessful
10539 -1 if redisplay with same window start is known not to succeed
10541 The following steps are performed:
10543 1. Find the last row in the current matrix of W that is not
10544 affected by changes at the start of current_buffer. If no such row
10547 2. Find the first row in W's current matrix that is not affected by
10548 changes at the end of current_buffer. Maybe there is no such row.
10550 3. Display lines beginning with the row + 1 found in step 1 to the
10551 row found in step 2 or, if step 2 didn't find a row, to the end of
10554 4. If cursor is not known to appear on the window, give up.
10556 5. If display stopped at the row found in step 2, scroll the
10557 display and current matrix as needed.
10559 6. Maybe display some lines at the end of W, if we must. This can
10560 happen under various circumstances, like a partially visible line
10561 becoming fully visible, or because newly displayed lines are displayed
10562 in smaller font sizes.
10564 7. Update W's window end information. */
10566 /* Check that window end is what we expect it to be. */
10572 struct frame
*f
= XFRAME (w
->frame
);
10573 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
10574 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
10575 struct glyph_row
*last_unchanged_at_beg_row
;
10576 struct glyph_row
*first_unchanged_at_end_row
;
10577 struct glyph_row
*row
;
10578 struct glyph_row
*bottom_row
;
10581 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
10582 struct text_pos start_pos
;
10584 int first_unchanged_at_end_vpos
= 0;
10585 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
10586 struct text_pos start
;
10588 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10590 /* Check pre-conditions. Window end must be valid, otherwise
10591 the current matrix would not be up to date. */
10592 xassert (!NILP (w
->window_end_valid
));
10593 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
10594 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
10596 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
10597 only if buffer has really changed. The reason is that the gap is
10598 initially at Z for freshly visited files. The code below would
10599 set end_unchanged to 0 in that case. */
10600 if (MODIFF
> SAVE_MODIFF
10601 /* This seems to happen sometimes after saving a buffer. */
10602 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
10604 if (GPT
- BEG
< BEG_UNCHANGED
)
10605 BEG_UNCHANGED
= GPT
- BEG
;
10606 if (Z
- GPT
< END_UNCHANGED
)
10607 END_UNCHANGED
= Z
- GPT
;
10610 /* If window starts after a line end, and the last change is in
10611 front of that newline, then changes don't affect the display.
10612 This case happens with stealth-fontification. Note that although
10613 the display is unchanged, glyph positions in the matrix have to
10614 be adjusted, of course. */
10615 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10616 if (CHARPOS (start
) > BEGV
10617 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
10618 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
10619 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10621 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
10622 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
10626 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10627 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
10629 increment_matrix_positions (w
->current_matrix
,
10630 MATRIX_ROW_VPOS (r0
, current_matrix
),
10631 MATRIX_ROW_VPOS (r1
, current_matrix
),
10632 delta
, delta_bytes
);
10635 #if 0 /* If changes are all in front of the window start, the
10636 distance of the last displayed glyph from Z hasn't
10639 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10640 w
->window_end_bytepos
10641 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10647 /* Return quickly if changes are all below what is displayed in the
10648 window, and if PT is in the window. */
10649 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
10650 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10652 /* We have to update window end positions because the buffer's
10653 size has changed. */
10655 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10656 w
->window_end_bytepos
10657 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10659 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10660 row
= row_containing_pos (w
, PT
, row
, NULL
);
10661 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10665 /* Check that window start agrees with the start of the first glyph
10666 row in its current matrix. Check this after we know the window
10667 start is not in changed text, otherwise positions would not be
10669 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10670 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
10673 /* Compute the position at which we have to start displaying new
10674 lines. Some of the lines at the top of the window might be
10675 reusable because they are not displaying changed text. Find the
10676 last row in W's current matrix not affected by changes at the
10677 start of current_buffer. Value is null if changes start in the
10678 first line of window. */
10679 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
10680 if (last_unchanged_at_beg_row
)
10682 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
10683 start_pos
= it
.current
.pos
;
10685 /* Start displaying new lines in the desired matrix at the same
10686 vpos we would use in the current matrix, i.e. below
10687 last_unchanged_at_beg_row. */
10688 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
10690 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10691 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
10693 xassert (it
.hpos
== 0 && it
.current_x
== 0);
10697 /* There are no reusable lines at the start of the window.
10698 Start displaying in the first line. */
10699 start_display (&it
, w
, start
);
10700 start_pos
= it
.current
.pos
;
10703 /* Find the first row that is not affected by changes at the end of
10704 the buffer. Value will be null if there is no unchanged row, in
10705 which case we must redisplay to the end of the window. delta
10706 will be set to the value by which buffer positions beginning with
10707 first_unchanged_at_end_row have to be adjusted due to text
10709 first_unchanged_at_end_row
10710 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
10711 IF_DEBUG (debug_delta
= delta
);
10712 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
10714 /* Set stop_pos to the buffer position up to which we will have to
10715 display new lines. If first_unchanged_at_end_row != NULL, this
10716 is the buffer position of the start of the line displayed in that
10717 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
10718 that we don't stop at a buffer position. */
10720 if (first_unchanged_at_end_row
)
10722 xassert (last_unchanged_at_beg_row
== NULL
10723 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
10725 /* If this is a continuation line, move forward to the next one
10726 that isn't. Changes in lines above affect this line.
10727 Caution: this may move first_unchanged_at_end_row to a row
10728 not displaying text. */
10729 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
10730 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10731 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10732 < it
.last_visible_y
))
10733 ++first_unchanged_at_end_row
;
10735 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10736 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10737 >= it
.last_visible_y
))
10738 first_unchanged_at_end_row
= NULL
;
10741 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
10743 first_unchanged_at_end_vpos
10744 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
10745 xassert (stop_pos
>= Z
- END_UNCHANGED
);
10748 else if (last_unchanged_at_beg_row
== NULL
)
10754 /* Either there is no unchanged row at the end, or the one we have
10755 now displays text. This is a necessary condition for the window
10756 end pos calculation at the end of this function. */
10757 xassert (first_unchanged_at_end_row
== NULL
10758 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
10760 debug_last_unchanged_at_beg_vpos
10761 = (last_unchanged_at_beg_row
10762 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
10764 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
10766 #endif /* GLYPH_DEBUG != 0 */
10769 /* Display new lines. Set last_text_row to the last new line
10770 displayed which has text on it, i.e. might end up as being the
10771 line where the window_end_vpos is. */
10772 w
->cursor
.vpos
= -1;
10773 last_text_row
= NULL
;
10774 overlay_arrow_seen
= 0;
10775 while (it
.current_y
< it
.last_visible_y
10776 && !fonts_changed_p
10777 && (first_unchanged_at_end_row
== NULL
10778 || IT_CHARPOS (it
) < stop_pos
))
10780 if (display_line (&it
))
10781 last_text_row
= it
.glyph_row
- 1;
10784 if (fonts_changed_p
)
10788 /* Compute differences in buffer positions, y-positions etc. for
10789 lines reused at the bottom of the window. Compute what we can
10791 if (first_unchanged_at_end_row
10792 /* No lines reused because we displayed everything up to the
10793 bottom of the window. */
10794 && it
.current_y
< it
.last_visible_y
)
10797 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
10799 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
10800 run
.current_y
= first_unchanged_at_end_row
->y
;
10801 run
.desired_y
= run
.current_y
+ dy
;
10802 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
10806 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
10807 first_unchanged_at_end_row
= NULL
;
10809 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
10812 /* Find the cursor if not already found. We have to decide whether
10813 PT will appear on this window (it sometimes doesn't, but this is
10814 not a very frequent case.) This decision has to be made before
10815 the current matrix is altered. A value of cursor.vpos < 0 means
10816 that PT is either in one of the lines beginning at
10817 first_unchanged_at_end_row or below the window. Don't care for
10818 lines that might be displayed later at the window end; as
10819 mentioned, this is not a frequent case. */
10820 if (w
->cursor
.vpos
< 0)
10822 /* Cursor in unchanged rows at the top? */
10823 if (PT
< CHARPOS (start_pos
)
10824 && last_unchanged_at_beg_row
)
10826 row
= row_containing_pos (w
, PT
,
10827 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
10828 last_unchanged_at_beg_row
+ 1);
10830 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10833 /* Start from first_unchanged_at_end_row looking for PT. */
10834 else if (first_unchanged_at_end_row
)
10836 row
= row_containing_pos (w
, PT
- delta
,
10837 first_unchanged_at_end_row
, NULL
);
10839 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
10840 delta_bytes
, dy
, dvpos
);
10843 /* Give up if cursor was not found. */
10844 if (w
->cursor
.vpos
< 0)
10846 clear_glyph_matrix (w
->desired_matrix
);
10851 /* Don't let the cursor end in the scroll margins. */
10853 int this_scroll_margin
, cursor_height
;
10855 this_scroll_margin
= max (0, scroll_margin
);
10856 this_scroll_margin
= min (this_scroll_margin
,
10857 XFASTINT (w
->height
) / 4);
10858 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
10859 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
10861 if ((w
->cursor
.y
< this_scroll_margin
10862 && CHARPOS (start
) > BEGV
)
10863 /* Don't take scroll margin into account at the bottom because
10864 old redisplay didn't do it either. */
10865 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
10867 w
->cursor
.vpos
= -1;
10868 clear_glyph_matrix (w
->desired_matrix
);
10873 /* Scroll the display. Do it before changing the current matrix so
10874 that xterm.c doesn't get confused about where the cursor glyph is
10876 if (dy
&& run
.height
)
10880 if (FRAME_WINDOW_P (f
))
10882 rif
->update_window_begin_hook (w
);
10883 rif
->clear_mouse_face (w
);
10884 rif
->scroll_run_hook (w
, &run
);
10885 rif
->update_window_end_hook (w
, 0, 0);
10889 /* Terminal frame. In this case, dvpos gives the number of
10890 lines to scroll by; dvpos < 0 means scroll up. */
10891 int first_unchanged_at_end_vpos
10892 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
10893 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
10894 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
10896 /* Perform the operation on the screen. */
10899 /* Scroll last_unchanged_at_beg_row to the end of the
10900 window down dvpos lines. */
10901 set_terminal_window (end
);
10903 /* On dumb terminals delete dvpos lines at the end
10904 before inserting dvpos empty lines. */
10905 if (!scroll_region_ok
)
10906 ins_del_lines (end
- dvpos
, -dvpos
);
10908 /* Insert dvpos empty lines in front of
10909 last_unchanged_at_beg_row. */
10910 ins_del_lines (from
, dvpos
);
10912 else if (dvpos
< 0)
10914 /* Scroll up last_unchanged_at_beg_vpos to the end of
10915 the window to last_unchanged_at_beg_vpos - |dvpos|. */
10916 set_terminal_window (end
);
10918 /* Delete dvpos lines in front of
10919 last_unchanged_at_beg_vpos. ins_del_lines will set
10920 the cursor to the given vpos and emit |dvpos| delete
10922 ins_del_lines (from
+ dvpos
, dvpos
);
10924 /* On a dumb terminal insert dvpos empty lines at the
10926 if (!scroll_region_ok
)
10927 ins_del_lines (end
+ dvpos
, -dvpos
);
10930 set_terminal_window (0);
10936 /* Shift reused rows of the current matrix to the right position.
10937 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
10939 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10940 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
10943 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
10944 bottom_vpos
, dvpos
);
10945 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
10948 else if (dvpos
> 0)
10950 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
10951 bottom_vpos
, dvpos
);
10952 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
10953 first_unchanged_at_end_vpos
+ dvpos
, 0);
10956 /* For frame-based redisplay, make sure that current frame and window
10957 matrix are in sync with respect to glyph memory. */
10958 if (!FRAME_WINDOW_P (f
))
10959 sync_frame_with_window_matrix_rows (w
);
10961 /* Adjust buffer positions in reused rows. */
10963 increment_matrix_positions (current_matrix
,
10964 first_unchanged_at_end_vpos
+ dvpos
,
10965 bottom_vpos
, delta
, delta_bytes
);
10967 /* Adjust Y positions. */
10969 shift_glyph_matrix (w
, current_matrix
,
10970 first_unchanged_at_end_vpos
+ dvpos
,
10973 if (first_unchanged_at_end_row
)
10974 first_unchanged_at_end_row
+= dvpos
;
10976 /* If scrolling up, there may be some lines to display at the end of
10978 last_text_row_at_end
= NULL
;
10981 /* Set last_row to the glyph row in the current matrix where the
10982 window end line is found. It has been moved up or down in
10983 the matrix by dvpos. */
10984 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
10985 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
10987 /* If last_row is the window end line, it should display text. */
10988 xassert (last_row
->displays_text_p
);
10990 /* If window end line was partially visible before, begin
10991 displaying at that line. Otherwise begin displaying with the
10992 line following it. */
10993 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
10995 init_to_row_start (&it
, w
, last_row
);
10996 it
.vpos
= last_vpos
;
10997 it
.current_y
= last_row
->y
;
11001 init_to_row_end (&it
, w
, last_row
);
11002 it
.vpos
= 1 + last_vpos
;
11003 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11007 /* We may start in a continuation line. If so, we have to get
11008 the right continuation_lines_width and current_x. */
11009 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11010 it
.hpos
= it
.current_x
= 0;
11012 /* Display the rest of the lines at the window end. */
11013 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11014 while (it
.current_y
< it
.last_visible_y
11015 && !fonts_changed_p
)
11017 /* Is it always sure that the display agrees with lines in
11018 the current matrix? I don't think so, so we mark rows
11019 displayed invalid in the current matrix by setting their
11020 enabled_p flag to zero. */
11021 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11022 if (display_line (&it
))
11023 last_text_row_at_end
= it
.glyph_row
- 1;
11027 /* Update window_end_pos and window_end_vpos. */
11028 if (first_unchanged_at_end_row
11029 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11030 && !last_text_row_at_end
)
11032 /* Window end line if one of the preserved rows from the current
11033 matrix. Set row to the last row displaying text in current
11034 matrix starting at first_unchanged_at_end_row, after
11036 xassert (first_unchanged_at_end_row
->displays_text_p
);
11037 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11038 first_unchanged_at_end_row
);
11039 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11041 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
11042 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11043 XSETFASTINT (w
->window_end_vpos
,
11044 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11046 else if (last_text_row_at_end
)
11048 XSETFASTINT (w
->window_end_pos
,
11049 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11050 w
->window_end_bytepos
11051 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11052 XSETFASTINT (w
->window_end_vpos
,
11053 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11055 else if (last_text_row
)
11057 /* We have displayed either to the end of the window or at the
11058 end of the window, i.e. the last row with text is to be found
11059 in the desired matrix. */
11060 XSETFASTINT (w
->window_end_pos
,
11061 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11062 w
->window_end_bytepos
11063 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11064 XSETFASTINT (w
->window_end_vpos
,
11065 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11067 else if (first_unchanged_at_end_row
== NULL
11068 && last_text_row
== NULL
11069 && last_text_row_at_end
== NULL
)
11071 /* Displayed to end of window, but no line containing text was
11072 displayed. Lines were deleted at the end of the window. */
11074 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11076 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
11077 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
11078 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
11079 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
11080 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
11083 w
->window_end_vpos
= make_number (vpos
);
11088 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11089 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11091 /* Record that display has not been completed. */
11092 w
->window_end_valid
= Qnil
;
11093 w
->desired_matrix
->no_scrolling_p
= 1;
11099 /***********************************************************************
11100 More debugging support
11101 ***********************************************************************/
11105 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
11106 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11109 /* Dump the contents of glyph matrix MATRIX on stderr. If
11110 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
11113 dump_glyph_matrix (matrix
, with_glyphs_p
)
11114 struct glyph_matrix
*matrix
;
11118 for (i
= 0; i
< matrix
->nrows
; ++i
)
11119 dump_glyph_row (matrix
, i
, with_glyphs_p
);
11123 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
11124 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
11127 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
11128 struct glyph_matrix
*matrix
;
11129 int vpos
, with_glyphs_p
;
11131 struct glyph_row
*row
;
11133 if (vpos
< 0 || vpos
>= matrix
->nrows
)
11136 row
= MATRIX_ROW (matrix
, vpos
);
11138 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFes X Y W H V A P\n");
11139 fprintf (stderr
, "=======================================================================\n");
11141 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d\
11142 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
11143 row
- matrix
->rows
,
11144 MATRIX_ROW_START_CHARPOS (row
),
11145 MATRIX_ROW_END_CHARPOS (row
),
11146 row
->used
[TEXT_AREA
],
11147 row
->contains_overlapping_glyphs_p
,
11150 row
->truncated_on_left_p
,
11151 row
->truncated_on_right_p
,
11152 row
->overlay_arrow_p
,
11154 MATRIX_ROW_CONTINUATION_LINE_P (row
),
11155 row
->displays_text_p
,
11158 row
->ends_in_middle_of_char_p
,
11159 row
->starts_in_middle_of_char_p
,
11164 row
->visible_height
,
11167 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
11168 row
->end
.overlay_string_index
);
11169 fprintf (stderr
, "%9d %5d\n",
11170 CHARPOS (row
->start
.string_pos
),
11171 CHARPOS (row
->end
.string_pos
));
11172 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
11173 row
->end
.dpvec_index
);
11177 struct glyph
*glyph
, *glyph_end
;
11178 int prev_had_glyphs_p
;
11180 glyph
= row
->glyphs
[TEXT_AREA
];
11181 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
11183 /* Glyph for a line end in text. */
11184 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
11187 if (glyph
< glyph_end
)
11189 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
11190 prev_had_glyphs_p
= 1;
11193 prev_had_glyphs_p
= 0;
11195 while (glyph
< glyph_end
)
11197 if (glyph
->type
== CHAR_GLYPH
)
11200 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11201 glyph
- row
->glyphs
[TEXT_AREA
],
11204 (BUFFERP (glyph
->object
)
11206 : (STRINGP (glyph
->object
)
11209 glyph
->pixel_width
,
11211 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
11215 glyph
->left_box_line_p
,
11216 glyph
->right_box_line_p
);
11218 else if (glyph
->type
== STRETCH_GLYPH
)
11221 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11222 glyph
- row
->glyphs
[TEXT_AREA
],
11225 (BUFFERP (glyph
->object
)
11227 : (STRINGP (glyph
->object
)
11230 glyph
->pixel_width
,
11234 glyph
->left_box_line_p
,
11235 glyph
->right_box_line_p
);
11237 else if (glyph
->type
== IMAGE_GLYPH
)
11240 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11241 glyph
- row
->glyphs
[TEXT_AREA
],
11244 (BUFFERP (glyph
->object
)
11246 : (STRINGP (glyph
->object
)
11249 glyph
->pixel_width
,
11253 glyph
->left_box_line_p
,
11254 glyph
->right_box_line_p
);
11262 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
11263 Sdump_glyph_matrix
, 0, 1, "p",
11264 "Dump the current matrix of the selected window to stderr.\n\
11265 Shows contents of glyph row structures. With non-nil optional\n\
11266 parameter WITH-GLYPHS-P, dump glyphs as well.")
11268 Lisp_Object with_glyphs_p
;
11270 struct window
*w
= XWINDOW (selected_window
);
11271 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11273 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
11274 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
11275 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
11276 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
11277 fprintf (stderr
, "=============================================\n");
11278 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
11283 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
11284 "Dump glyph row ROW to stderr.")
11288 CHECK_NUMBER (row
, 0);
11289 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
11294 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
,
11298 struct frame
*sf
= SELECTED_FRAME ();
11299 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)
11301 dump_glyph_row (m
, 0, 1);
11306 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
11307 Strace_redisplay_toggle
, 0, 0, "",
11308 "Toggle tracing of redisplay.")
11311 trace_redisplay_p
= !trace_redisplay_p
;
11316 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
11317 "Print STRING to stderr.")
11319 Lisp_Object string
;
11321 CHECK_STRING (string
, 0);
11322 fprintf (stderr
, "%s", XSTRING (string
)->data
);
11326 #endif /* GLYPH_DEBUG */
11330 /***********************************************************************
11331 Building Desired Matrix Rows
11332 ***********************************************************************/
11334 /* Return a temporary glyph row holding the glyphs of an overlay
11335 arrow. Only used for non-window-redisplay windows. */
11337 static struct glyph_row
*
11338 get_overlay_arrow_glyph_row (w
)
11341 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11342 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11343 struct buffer
*old
= current_buffer
;
11344 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
11345 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
11346 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
11350 int n_glyphs_before
;
11352 set_buffer_temp (buffer
);
11353 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
11354 it
.glyph_row
->used
[TEXT_AREA
] = 0;
11355 SET_TEXT_POS (it
.position
, 0, 0);
11357 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
11359 while (p
< arrow_end
)
11361 Lisp_Object face
, ilisp
;
11363 /* Get the next character. */
11365 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
11367 it
.c
= *p
, it
.len
= 1;
11370 /* Get its face. */
11371 XSETFASTINT (ilisp
, p
- arrow_string
);
11372 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
11373 it
.face_id
= compute_char_face (f
, it
.c
, face
);
11375 /* Compute its width, get its glyphs. */
11376 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
11377 SET_TEXT_POS (it
.position
, -1, -1);
11378 PRODUCE_GLYPHS (&it
);
11380 /* If this character doesn't fit any more in the line, we have
11381 to remove some glyphs. */
11382 if (it
.current_x
> it
.last_visible_x
)
11384 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
11389 set_buffer_temp (old
);
11390 return it
.glyph_row
;
11394 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
11395 glyphs are only inserted for terminal frames since we can't really
11396 win with truncation glyphs when partially visible glyphs are
11397 involved. Which glyphs to insert is determined by
11398 produce_special_glyphs. */
11401 insert_left_trunc_glyphs (it
)
11404 struct it truncate_it
;
11405 struct glyph
*from
, *end
, *to
, *toend
;
11407 xassert (!FRAME_WINDOW_P (it
->f
));
11409 /* Get the truncation glyphs. */
11411 truncate_it
.current_x
= 0;
11412 truncate_it
.face_id
= DEFAULT_FACE_ID
;
11413 truncate_it
.glyph_row
= &scratch_glyph_row
;
11414 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
11415 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
11416 truncate_it
.object
= make_number (0);
11417 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
11419 /* Overwrite glyphs from IT with truncation glyphs. */
11420 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
11421 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
11422 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
11423 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
11428 /* There may be padding glyphs left over. Remove them. */
11430 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
11432 while (from
< toend
)
11435 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
11439 /* Compute the pixel height and width of IT->glyph_row.
11441 Most of the time, ascent and height of a display line will be equal
11442 to the max_ascent and max_height values of the display iterator
11443 structure. This is not the case if
11445 1. We hit ZV without displaying anything. In this case, max_ascent
11446 and max_height will be zero.
11448 2. We have some glyphs that don't contribute to the line height.
11449 (The glyph row flag contributes_to_line_height_p is for future
11450 pixmap extensions).
11452 The first case is easily covered by using default values because in
11453 these cases, the line height does not really matter, except that it
11454 must not be zero. */
11457 compute_line_metrics (it
)
11460 struct glyph_row
*row
= it
->glyph_row
;
11463 if (FRAME_WINDOW_P (it
->f
))
11465 int i
, header_line_height
;
11467 /* The line may consist of one space only, that was added to
11468 place the cursor on it. If so, the row's height hasn't been
11470 if (row
->height
== 0)
11472 if (it
->max_ascent
+ it
->max_descent
== 0)
11473 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
11474 row
->ascent
= it
->max_ascent
;
11475 row
->height
= it
->max_ascent
+ it
->max_descent
;
11476 row
->phys_ascent
= it
->max_phys_ascent
;
11477 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11480 /* Compute the width of this line. */
11481 row
->pixel_width
= row
->x
;
11482 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
11483 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11485 xassert (row
->pixel_width
>= 0);
11486 xassert (row
->ascent
>= 0 && row
->height
> 0);
11488 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
11489 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
11491 /* If first line's physical ascent is larger than its logical
11492 ascent, use the physical ascent, and make the row taller.
11493 This makes accented characters fully visible. */
11494 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
11495 && row
->phys_ascent
> row
->ascent
)
11497 row
->height
+= row
->phys_ascent
- row
->ascent
;
11498 row
->ascent
= row
->phys_ascent
;
11501 /* Compute how much of the line is visible. */
11502 row
->visible_height
= row
->height
;
11504 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
11505 if (row
->y
< header_line_height
)
11506 row
->visible_height
-= header_line_height
- row
->y
;
11509 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
11510 if (row
->y
+ row
->height
> max_y
)
11511 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11516 row
->pixel_width
= row
->used
[TEXT_AREA
];
11517 row
->ascent
= row
->phys_ascent
= 0;
11518 row
->height
= row
->phys_height
= row
->visible_height
= 1;
11521 /* Compute a hash code for this row. */
11523 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11524 for (i
= 0; i
< row
->used
[area
]; ++i
)
11525 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
11526 + row
->glyphs
[area
][i
].u
.val
11527 + row
->glyphs
[area
][i
].face_id
11528 + row
->glyphs
[area
][i
].padding_p
11529 + (row
->glyphs
[area
][i
].type
<< 2));
11531 it
->max_ascent
= it
->max_descent
= 0;
11532 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
11536 /* Append one space to the glyph row of iterator IT if doing a
11537 window-based redisplay. DEFAULT_FACE_P non-zero means let the
11538 space have the default face, otherwise let it have the same face as
11539 IT->face_id. Value is non-zero if a space was added.
11541 This function is called to make sure that there is always one glyph
11542 at the end of a glyph row that the cursor can be set on under
11543 window-systems. (If there weren't such a glyph we would not know
11544 how wide and tall a box cursor should be displayed).
11546 At the same time this space let's a nicely handle clearing to the
11547 end of the line if the row ends in italic text. */
11550 append_space (it
, default_face_p
)
11552 int default_face_p
;
11554 if (FRAME_WINDOW_P (it
->f
))
11556 int n
= it
->glyph_row
->used
[TEXT_AREA
];
11558 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
11559 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
11561 /* Save some values that must not be changed.
11562 Must save IT->c and IT->len because otherwise
11563 ITERATOR_AT_END_P wouldn't work anymore after
11564 append_space has been called. */
11565 int saved_what
= it
->what
;
11566 int saved_c
= it
->c
, saved_len
= it
->len
;
11567 int saved_x
= it
->current_x
;
11568 int saved_face_id
= it
->face_id
;
11569 struct text_pos saved_pos
;
11570 Lisp_Object saved_object
;
11573 saved_object
= it
->object
;
11574 saved_pos
= it
->position
;
11576 it
->what
= IT_CHARACTER
;
11577 bzero (&it
->position
, sizeof it
->position
);
11578 it
->object
= make_number (0);
11582 if (default_face_p
)
11583 it
->face_id
= DEFAULT_FACE_ID
;
11584 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11585 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
11587 PRODUCE_GLYPHS (it
);
11589 it
->current_x
= saved_x
;
11590 it
->object
= saved_object
;
11591 it
->position
= saved_pos
;
11592 it
->what
= saved_what
;
11593 it
->face_id
= saved_face_id
;
11594 it
->len
= saved_len
;
11604 /* Extend the face of the last glyph in the text area of IT->glyph_row
11605 to the end of the display line. Called from display_line.
11606 If the glyph row is empty, add a space glyph to it so that we
11607 know the face to draw. Set the glyph row flag fill_line_p. */
11610 extend_face_to_end_of_line (it
)
11614 struct frame
*f
= it
->f
;
11616 /* If line is already filled, do nothing. */
11617 if (it
->current_x
>= it
->last_visible_x
)
11620 /* Face extension extends the background and box of IT->face_id
11621 to the end of the line. If the background equals the background
11622 of the frame, we haven't to do anything. */
11623 face
= FACE_FROM_ID (f
, it
->face_id
);
11624 if (FRAME_WINDOW_P (f
)
11625 && face
->box
== FACE_NO_BOX
11626 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
11630 /* Set the glyph row flag indicating that the face of the last glyph
11631 in the text area has to be drawn to the end of the text area. */
11632 it
->glyph_row
->fill_line_p
= 1;
11634 /* If current character of IT is not ASCII, make sure we have the
11635 ASCII face. This will be automatically undone the next time
11636 get_next_display_element returns a multibyte character. Note
11637 that the character will always be single byte in unibyte text. */
11638 if (!SINGLE_BYTE_CHAR_P (it
->c
))
11640 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
11643 if (FRAME_WINDOW_P (f
))
11645 /* If the row is empty, add a space with the current face of IT,
11646 so that we know which face to draw. */
11647 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
11649 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
11650 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
11651 it
->glyph_row
->used
[TEXT_AREA
] = 1;
11656 /* Save some values that must not be changed. */
11657 int saved_x
= it
->current_x
;
11658 struct text_pos saved_pos
;
11659 Lisp_Object saved_object
;
11660 int saved_what
= it
->what
;
11662 saved_object
= it
->object
;
11663 saved_pos
= it
->position
;
11665 it
->what
= IT_CHARACTER
;
11666 bzero (&it
->position
, sizeof it
->position
);
11667 it
->object
= make_number (0);
11671 PRODUCE_GLYPHS (it
);
11673 while (it
->current_x
<= it
->last_visible_x
)
11674 PRODUCE_GLYPHS (it
);
11676 /* Don't count these blanks really. It would let us insert a left
11677 truncation glyph below and make us set the cursor on them, maybe. */
11678 it
->current_x
= saved_x
;
11679 it
->object
= saved_object
;
11680 it
->position
= saved_pos
;
11681 it
->what
= saved_what
;
11686 /* Value is non-zero if text starting at CHARPOS in current_buffer is
11687 trailing whitespace. */
11690 trailing_whitespace_p (charpos
)
11693 int bytepos
= CHAR_TO_BYTE (charpos
);
11696 while (bytepos
< ZV_BYTE
11697 && (c
= FETCH_CHAR (bytepos
),
11698 c
== ' ' || c
== '\t'))
11701 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
11703 if (bytepos
!= PT_BYTE
)
11710 /* Highlight trailing whitespace, if any, in ROW. */
11713 highlight_trailing_whitespace (f
, row
)
11715 struct glyph_row
*row
;
11717 int used
= row
->used
[TEXT_AREA
];
11721 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
11722 struct glyph
*glyph
= start
+ used
- 1;
11724 /* Skip over the space glyph inserted to display the
11725 cursor at the end of a line. */
11726 if (glyph
->type
== CHAR_GLYPH
11727 && glyph
->u
.ch
== ' '
11728 && INTEGERP (glyph
->object
))
11731 /* If last glyph is a space or stretch, and it's trailing
11732 whitespace, set the face of all trailing whitespace glyphs in
11733 IT->glyph_row to `trailing-whitespace'. */
11735 && BUFFERP (glyph
->object
)
11736 && (glyph
->type
== STRETCH_GLYPH
11737 || (glyph
->type
== CHAR_GLYPH
11738 && glyph
->u
.ch
== ' '))
11739 && trailing_whitespace_p (glyph
->charpos
))
11741 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
11743 while (glyph
>= start
11744 && BUFFERP (glyph
->object
)
11745 && (glyph
->type
== STRETCH_GLYPH
11746 || (glyph
->type
== CHAR_GLYPH
11747 && glyph
->u
.ch
== ' ')))
11748 (glyph
--)->face_id
= face_id
;
11754 /* Value is non-zero if glyph row ROW in window W should be
11755 used to put the cursor on. */
11758 cursor_row_p (w
, row
)
11760 struct glyph_row
*row
;
11762 int cursor_row_p
= 1;
11764 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
11766 /* If the row ends with a newline from a string, we don't want
11767 the cursor there (if the row is continued it doesn't end in a
11769 if (CHARPOS (row
->end
.string_pos
) >= 0
11770 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11771 cursor_row_p
= row
->continued_p
;
11773 /* If the row ends at ZV, display the cursor at the end of that
11774 row instead of at the start of the row below. */
11775 else if (row
->ends_at_zv_p
)
11781 return cursor_row_p
;
11785 /* Construct the glyph row IT->glyph_row in the desired matrix of
11786 IT->w from text at the current position of IT. See dispextern.h
11787 for an overview of struct it. Value is non-zero if
11788 IT->glyph_row displays text, as opposed to a line displaying ZV
11795 struct glyph_row
*row
= it
->glyph_row
;
11797 /* We always start displaying at hpos zero even if hscrolled. */
11798 xassert (it
->hpos
== 0 && it
->current_x
== 0);
11800 /* We must not display in a row that's not a text row. */
11801 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
11802 < it
->w
->desired_matrix
->nrows
);
11804 /* Is IT->w showing the region? */
11805 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
11807 /* Clear the result glyph row and enable it. */
11808 prepare_desired_row (row
);
11810 row
->y
= it
->current_y
;
11811 row
->start
= it
->current
;
11812 row
->continuation_lines_width
= it
->continuation_lines_width
;
11813 row
->displays_text_p
= 1;
11814 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
11815 it
->starts_in_middle_of_char_p
= 0;
11817 /* Arrange the overlays nicely for our purposes. Usually, we call
11818 display_line on only one line at a time, in which case this
11819 can't really hurt too much, or we call it on lines which appear
11820 one after another in the buffer, in which case all calls to
11821 recenter_overlay_lists but the first will be pretty cheap. */
11822 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
11824 /* Move over display elements that are not visible because we are
11825 hscrolled. This may stop at an x-position < IT->first_visible_x
11826 if the first glyph is partially visible or if we hit a line end. */
11827 if (it
->current_x
< it
->first_visible_x
)
11828 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
11829 MOVE_TO_POS
| MOVE_TO_X
);
11831 /* Get the initial row height. This is either the height of the
11832 text hscrolled, if there is any, or zero. */
11833 row
->ascent
= it
->max_ascent
;
11834 row
->height
= it
->max_ascent
+ it
->max_descent
;
11835 row
->phys_ascent
= it
->max_phys_ascent
;
11836 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11838 /* Loop generating characters. The loop is left with IT on the next
11839 character to display. */
11842 int n_glyphs_before
, hpos_before
, x_before
;
11844 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
11846 /* Retrieve the next thing to display. Value is zero if end of
11848 if (!get_next_display_element (it
))
11850 /* Maybe add a space at the end of this line that is used to
11851 display the cursor there under X. Set the charpos of the
11852 first glyph of blank lines not corresponding to any text
11854 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
11855 || row
->used
[TEXT_AREA
] == 0)
11857 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
11858 row
->displays_text_p
= 0;
11860 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
11861 row
->indicate_empty_line_p
= 1;
11864 it
->continuation_lines_width
= 0;
11865 row
->ends_at_zv_p
= 1;
11869 /* Now, get the metrics of what we want to display. This also
11870 generates glyphs in `row' (which is IT->glyph_row). */
11871 n_glyphs_before
= row
->used
[TEXT_AREA
];
11874 /* Remember the line height so far in case the next element doesn't
11875 fit on the line. */
11876 if (!it
->truncate_lines_p
)
11878 ascent
= it
->max_ascent
;
11879 descent
= it
->max_descent
;
11880 phys_ascent
= it
->max_phys_ascent
;
11881 phys_descent
= it
->max_phys_descent
;
11884 PRODUCE_GLYPHS (it
);
11886 /* If this display element was in marginal areas, continue with
11888 if (it
->area
!= TEXT_AREA
)
11890 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11891 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11892 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11893 row
->phys_height
= max (row
->phys_height
,
11894 it
->max_phys_ascent
+ it
->max_phys_descent
);
11895 set_iterator_to_next (it
, 1);
11899 /* Does the display element fit on the line? If we truncate
11900 lines, we should draw past the right edge of the window. If
11901 we don't truncate, we want to stop so that we can display the
11902 continuation glyph before the right margin. If lines are
11903 continued, there are two possible strategies for characters
11904 resulting in more than 1 glyph (e.g. tabs): Display as many
11905 glyphs as possible in this line and leave the rest for the
11906 continuation line, or display the whole element in the next
11907 line. Original redisplay did the former, so we do it also. */
11908 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11909 hpos_before
= it
->hpos
;
11913 && it
->current_x
< it
->last_visible_x
)
11916 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11917 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11918 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11919 row
->phys_height
= max (row
->phys_height
,
11920 it
->max_phys_ascent
+ it
->max_phys_descent
);
11921 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
11922 row
->x
= x
- it
->first_visible_x
;
11927 struct glyph
*glyph
;
11929 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
11931 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11932 new_x
= x
+ glyph
->pixel_width
;
11934 if (/* Lines are continued. */
11935 !it
->truncate_lines_p
11936 && (/* Glyph doesn't fit on the line. */
11937 new_x
> it
->last_visible_x
11938 /* Or it fits exactly on a window system frame. */
11939 || (new_x
== it
->last_visible_x
11940 && FRAME_WINDOW_P (it
->f
))))
11942 /* End of a continued line. */
11945 || (new_x
== it
->last_visible_x
11946 && FRAME_WINDOW_P (it
->f
)))
11948 /* Current glyph is the only one on the line or
11949 fits exactly on the line. We must continue
11950 the line because we can't draw the cursor
11951 after the glyph. */
11952 row
->continued_p
= 1;
11953 it
->current_x
= new_x
;
11954 it
->continuation_lines_width
+= new_x
;
11956 if (i
== nglyphs
- 1)
11957 set_iterator_to_next (it
, 1);
11959 else if (CHAR_GLYPH_PADDING_P (*glyph
)
11960 && !FRAME_WINDOW_P (it
->f
))
11962 /* A padding glyph that doesn't fit on this line.
11963 This means the whole character doesn't fit
11965 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11967 /* Fill the rest of the row with continuation
11968 glyphs like in 20.x. */
11969 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
11970 < row
->glyphs
[1 + TEXT_AREA
])
11971 produce_special_glyphs (it
, IT_CONTINUATION
);
11973 row
->continued_p
= 1;
11974 it
->current_x
= x_before
;
11975 it
->continuation_lines_width
+= x_before
;
11977 /* Restore the height to what it was before the
11978 element not fitting on the line. */
11979 it
->max_ascent
= ascent
;
11980 it
->max_descent
= descent
;
11981 it
->max_phys_ascent
= phys_ascent
;
11982 it
->max_phys_descent
= phys_descent
;
11986 /* Display element draws past the right edge of
11987 the window. Restore positions to values
11988 before the element. The next line starts
11989 with current_x before the glyph that could
11990 not be displayed, so that TAB works right. */
11991 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11993 /* Display continuation glyphs. */
11994 if (!FRAME_WINDOW_P (it
->f
))
11995 produce_special_glyphs (it
, IT_CONTINUATION
);
11996 row
->continued_p
= 1;
11999 it
->continuation_lines_width
+= x
;
12000 if (nglyphs
> 1 && i
> 0)
12002 row
->ends_in_middle_of_char_p
= 1;
12003 it
->starts_in_middle_of_char_p
= 1;
12006 /* Restore the height to what it was before the
12007 element not fitting on the line. */
12008 it
->max_ascent
= ascent
;
12009 it
->max_descent
= descent
;
12010 it
->max_phys_ascent
= phys_ascent
;
12011 it
->max_phys_descent
= phys_descent
;
12016 else if (new_x
> it
->first_visible_x
)
12018 /* Increment number of glyphs actually displayed. */
12021 if (x
< it
->first_visible_x
)
12022 /* Glyph is partially visible, i.e. row starts at
12023 negative X position. */
12024 row
->x
= x
- it
->first_visible_x
;
12028 /* Glyph is completely off the left margin of the
12029 window. This should not happen because of the
12030 move_it_in_display_line at the start of
12036 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12037 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12038 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12039 row
->phys_height
= max (row
->phys_height
,
12040 it
->max_phys_ascent
+ it
->max_phys_descent
);
12042 /* End of this display line if row is continued. */
12043 if (row
->continued_p
)
12047 /* Is this a line end? If yes, we're also done, after making
12048 sure that a non-default face is extended up to the right
12049 margin of the window. */
12050 if (ITERATOR_AT_END_OF_LINE_P (it
))
12052 int used_before
= row
->used
[TEXT_AREA
];
12054 /* Add a space at the end of the line that is used to
12055 display the cursor there. */
12056 append_space (it
, 0);
12058 /* Extend the face to the end of the line. */
12059 extend_face_to_end_of_line (it
);
12061 /* Make sure we have the position. */
12062 if (used_before
== 0)
12063 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
12065 /* Consume the line end. This skips over invisible lines. */
12066 set_iterator_to_next (it
, 1);
12067 it
->continuation_lines_width
= 0;
12071 /* Proceed with next display element. Note that this skips
12072 over lines invisible because of selective display. */
12073 set_iterator_to_next (it
, 1);
12075 /* If we truncate lines, we are done when the last displayed
12076 glyphs reach past the right margin of the window. */
12077 if (it
->truncate_lines_p
12078 && (FRAME_WINDOW_P (it
->f
)
12079 ? (it
->current_x
>= it
->last_visible_x
)
12080 : (it
->current_x
> it
->last_visible_x
)))
12082 /* Maybe add truncation glyphs. */
12083 if (!FRAME_WINDOW_P (it
->f
))
12085 --it
->glyph_row
->used
[TEXT_AREA
];
12086 produce_special_glyphs (it
, IT_TRUNCATION
);
12089 row
->truncated_on_right_p
= 1;
12090 it
->continuation_lines_width
= 0;
12091 reseat_at_next_visible_line_start (it
, 0);
12092 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
12093 it
->hpos
= hpos_before
;
12094 it
->current_x
= x_before
;
12099 /* If line is not empty and hscrolled, maybe insert truncation glyphs
12100 at the left window margin. */
12101 if (it
->first_visible_x
12102 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
12104 if (!FRAME_WINDOW_P (it
->f
))
12105 insert_left_trunc_glyphs (it
);
12106 row
->truncated_on_left_p
= 1;
12109 /* If the start of this line is the overlay arrow-position, then
12110 mark this glyph row as the one containing the overlay arrow.
12111 This is clearly a mess with variable size fonts. It would be
12112 better to let it be displayed like cursors under X. */
12113 if (MARKERP (Voverlay_arrow_position
)
12114 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
12115 && (MATRIX_ROW_START_CHARPOS (row
)
12116 == marker_position (Voverlay_arrow_position
))
12117 && STRINGP (Voverlay_arrow_string
)
12118 && ! overlay_arrow_seen
)
12120 /* Overlay arrow in window redisplay is a bitmap. */
12121 if (!FRAME_WINDOW_P (it
->f
))
12123 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
12124 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
12125 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
12126 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
12127 struct glyph
*p2
, *end
;
12129 /* Copy the arrow glyphs. */
12130 while (glyph
< arrow_end
)
12133 /* Throw away padding glyphs. */
12135 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
12136 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
12142 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
12146 overlay_arrow_seen
= 1;
12147 row
->overlay_arrow_p
= 1;
12150 /* Compute pixel dimensions of this line. */
12151 compute_line_metrics (it
);
12153 /* Remember the position at which this line ends. */
12154 row
->end
= it
->current
;
12156 /* Maybe set the cursor. */
12157 if (it
->w
->cursor
.vpos
< 0
12158 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
12159 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
12160 && cursor_row_p (it
->w
, row
))
12161 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
12163 /* Highlight trailing whitespace. */
12164 if (!NILP (Vshow_trailing_whitespace
))
12165 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
12167 /* Prepare for the next line. This line starts horizontally at (X
12168 HPOS) = (0 0). Vertical positions are incremented. As a
12169 convenience for the caller, IT->glyph_row is set to the next
12171 it
->current_x
= it
->hpos
= 0;
12172 it
->current_y
+= row
->height
;
12175 return row
->displays_text_p
;
12180 /***********************************************************************
12182 ***********************************************************************/
12184 /* Redisplay the menu bar in the frame for window W.
12186 The menu bar of X frames that don't have X toolkit support is
12187 displayed in a special window W->frame->menu_bar_window.
12189 The menu bar of terminal frames is treated specially as far as
12190 glyph matrices are concerned. Menu bar lines are not part of
12191 windows, so the update is done directly on the frame matrix rows
12192 for the menu bar. */
12195 display_menu_bar (w
)
12198 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12203 /* Don't do all this for graphical frames. */
12205 if (!NILP (Vwindow_system
))
12208 #ifdef USE_X_TOOLKIT
12213 if (FRAME_MAC_P (f
))
12217 #ifdef USE_X_TOOLKIT
12218 xassert (!FRAME_WINDOW_P (f
));
12219 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
12220 it
.first_visible_x
= 0;
12221 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12222 #else /* not USE_X_TOOLKIT */
12223 if (FRAME_WINDOW_P (f
))
12225 /* Menu bar lines are displayed in the desired matrix of the
12226 dummy window menu_bar_window. */
12227 struct window
*menu_w
;
12228 xassert (WINDOWP (f
->menu_bar_window
));
12229 menu_w
= XWINDOW (f
->menu_bar_window
);
12230 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
12232 it
.first_visible_x
= 0;
12233 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12237 /* This is a TTY frame, i.e. character hpos/vpos are used as
12239 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
12241 it
.first_visible_x
= 0;
12242 it
.last_visible_x
= FRAME_WIDTH (f
);
12244 #endif /* not USE_X_TOOLKIT */
12246 /* Clear all rows of the menu bar. */
12247 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
12249 struct glyph_row
*row
= it
.glyph_row
+ i
;
12250 clear_glyph_row (row
);
12251 row
->enabled_p
= 1;
12252 row
->full_width_p
= 1;
12255 /* Make the first line of the menu bar appear in reverse video. */
12256 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
12258 /* Display all items of the menu bar. */
12259 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
12260 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
12262 Lisp_Object string
;
12264 /* Stop at nil string. */
12265 string
= XVECTOR (items
)->contents
[i
+ 1];
12269 /* Remember where item was displayed. */
12270 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
12272 /* Display the item, pad with one space. */
12273 if (it
.current_x
< it
.last_visible_x
)
12274 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
12275 XSTRING (string
)->size
+ 1, 0, 0, -1);
12278 /* Fill out the line with spaces. */
12279 if (it
.current_x
< it
.last_visible_x
)
12280 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
12282 /* Compute the total height of the lines. */
12283 compute_line_metrics (&it
);
12288 /***********************************************************************
12290 ***********************************************************************/
12292 /* Redisplay mode lines in the window tree whose root is WINDOW. If
12293 FORCE is non-zero, redisplay mode lines unconditionally.
12294 Otherwise, redisplay only mode lines that are garbaged. Value is
12295 the number of windows whose mode lines were redisplayed. */
12298 redisplay_mode_lines (window
, force
)
12299 Lisp_Object window
;
12304 while (!NILP (window
))
12306 struct window
*w
= XWINDOW (window
);
12308 if (WINDOWP (w
->hchild
))
12309 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
12310 else if (WINDOWP (w
->vchild
))
12311 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
12313 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
12314 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
12316 Lisp_Object old_selected_frame
;
12317 struct text_pos lpoint
;
12318 struct buffer
*old
= current_buffer
;
12320 /* Set the window's buffer for the mode line display. */
12321 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12322 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12324 /* Point refers normally to the selected window. For any
12325 other window, set up appropriate value. */
12326 if (!EQ (window
, selected_window
))
12328 struct text_pos pt
;
12330 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
12331 if (CHARPOS (pt
) < BEGV
)
12332 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
12333 else if (CHARPOS (pt
) > (ZV
- 1))
12334 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
12336 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
12339 /* Temporarily set up the selected frame. */
12340 old_selected_frame
= selected_frame
;
12341 selected_frame
= w
->frame
;
12343 /* Display mode lines. */
12344 clear_glyph_matrix (w
->desired_matrix
);
12345 if (display_mode_lines (w
))
12348 w
->must_be_updated_p
= 1;
12351 /* Restore old settings. */
12352 selected_frame
= old_selected_frame
;
12353 set_buffer_internal_1 (old
);
12354 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12364 /* Display the mode and/or top line of window W. Value is the number
12365 of mode lines displayed. */
12368 display_mode_lines (w
)
12373 /* These will be set while the mode line specs are processed. */
12374 line_number_displayed
= 0;
12375 w
->column_number_displayed
= Qnil
;
12377 if (WINDOW_WANTS_MODELINE_P (w
))
12379 display_mode_line (w
, MODE_LINE_FACE_ID
,
12380 current_buffer
->mode_line_format
);
12384 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12386 display_mode_line (w
, HEADER_LINE_FACE_ID
,
12387 current_buffer
->header_line_format
);
12395 /* Display mode or top line of window W. FACE_ID specifies which line
12396 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
12397 FORMAT is the mode line format to display. */
12400 display_mode_line (w
, face_id
, format
)
12402 enum face_id face_id
;
12403 Lisp_Object format
;
12408 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
12409 prepare_desired_row (it
.glyph_row
);
12411 /* Temporarily make frame's keyboard the current kboard so that
12412 kboard-local variables in the mode_line_format will get the right
12414 push_frame_kboard (it
.f
);
12415 display_mode_element (&it
, 0, 0, 0, format
);
12416 pop_frame_kboard ();
12418 /* Fill up with spaces. */
12419 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
12421 compute_line_metrics (&it
);
12422 it
.glyph_row
->full_width_p
= 1;
12423 it
.glyph_row
->mode_line_p
= 1;
12424 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
12425 it
.glyph_row
->continued_p
= 0;
12426 it
.glyph_row
->truncated_on_left_p
= 0;
12427 it
.glyph_row
->truncated_on_right_p
= 0;
12429 /* Make a 3D mode-line have a shadow at its right end. */
12430 face
= FACE_FROM_ID (it
.f
, face_id
);
12431 extend_face_to_end_of_line (&it
);
12432 if (face
->box
!= FACE_NO_BOX
)
12434 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
12435 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
12436 last
->right_box_line_p
= 1;
12441 /* Contribute ELT to the mode line for window IT->w. How it
12442 translates into text depends on its data type.
12444 IT describes the display environment in which we display, as usual.
12446 DEPTH is the depth in recursion. It is used to prevent
12447 infinite recursion here.
12449 FIELD_WIDTH is the number of characters the display of ELT should
12450 occupy in the mode line, and PRECISION is the maximum number of
12451 characters to display from ELT's representation. See
12452 display_string for details. *
12454 Returns the hpos of the end of the text generated by ELT. */
12457 display_mode_element (it
, depth
, field_width
, precision
, elt
)
12460 int field_width
, precision
;
12463 int n
= 0, field
, prec
;
12471 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
12475 /* A string: output it and check for %-constructs within it. */
12477 unsigned char *this = XSTRING (elt
)->data
;
12478 unsigned char *lisp_string
= this;
12480 while ((precision
<= 0 || n
< precision
)
12482 && (frame_title_ptr
12483 || it
->current_x
< it
->last_visible_x
))
12485 unsigned char *last
= this;
12487 /* Advance to end of string or next format specifier. */
12488 while ((c
= *this++) != '\0' && c
!= '%')
12491 if (this - 1 != last
)
12493 /* Output to end of string or up to '%'. Field width
12494 is length of string. Don't output more than
12495 PRECISION allows us. */
12496 prec
= --this - last
;
12497 if (precision
> 0 && prec
> precision
- n
)
12498 prec
= precision
- n
;
12500 if (frame_title_ptr
)
12501 n
+= store_frame_title (last
, prec
, prec
);
12503 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
12504 it
, 0, prec
, 0, -1);
12506 else /* c == '%' */
12508 unsigned char *percent_position
= this;
12510 /* Get the specified minimum width. Zero means
12513 while ((c
= *this++) >= '0' && c
<= '9')
12514 field
= field
* 10 + c
- '0';
12516 /* Don't pad beyond the total padding allowed. */
12517 if (field_width
- n
> 0 && field
> field_width
- n
)
12518 field
= field_width
- n
;
12520 /* Note that either PRECISION <= 0 or N < PRECISION. */
12521 prec
= precision
- n
;
12524 n
+= display_mode_element (it
, depth
, field
, prec
,
12525 Vglobal_mode_string
);
12528 unsigned char *spec
12529 = decode_mode_spec (it
->w
, c
, field
, prec
);
12531 if (frame_title_ptr
)
12532 n
+= store_frame_title (spec
, field
, prec
);
12536 = it
->glyph_row
->used
[TEXT_AREA
];
12538 = percent_position
- XSTRING (elt
)->data
;
12540 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
12541 field
, prec
, 0, -1);
12543 /* Assign to the glyphs written above the
12544 string where the `%x' came from, position
12548 struct glyph
*glyph
12549 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
12553 for (i
= 0; i
< nwritten
; ++i
)
12555 glyph
[i
].object
= elt
;
12556 glyph
[i
].charpos
= charpos
;
12569 /* A symbol: process the value of the symbol recursively
12570 as if it appeared here directly. Avoid error if symbol void.
12571 Special case: if value of symbol is a string, output the string
12574 register Lisp_Object tem
;
12575 tem
= Fboundp (elt
);
12578 tem
= Fsymbol_value (elt
);
12579 /* If value is a string, output that string literally:
12580 don't check for % within it. */
12583 prec
= XSTRING (tem
)->size
;
12584 if (precision
> 0 && prec
> precision
- n
)
12585 prec
= precision
- n
;
12586 if (frame_title_ptr
)
12587 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
12589 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
12592 else if (!EQ (tem
, elt
))
12594 /* Give up right away for nil or t. */
12604 register Lisp_Object car
, tem
;
12606 /* A cons cell: three distinct cases.
12607 If first element is a string or a cons, process all the elements
12608 and effectively concatenate them.
12609 If first element is a negative number, truncate displaying cdr to
12610 at most that many characters. If positive, pad (with spaces)
12611 to at least that many characters.
12612 If first element is a symbol, process the cadr or caddr recursively
12613 according to whether the symbol's value is non-nil or nil. */
12615 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
12617 /* An element of the form (:eval FORM) means evaluate FORM
12618 and use the result as mode line elements. */
12619 struct gcpro gcpro1
;
12622 spec
= safe_eval (XCAR (XCDR (elt
)));
12624 n
+= display_mode_element (it
, depth
, field_width
- n
,
12625 precision
- n
, spec
);
12628 else if (SYMBOLP (car
))
12630 tem
= Fboundp (car
);
12634 /* elt is now the cdr, and we know it is a cons cell.
12635 Use its car if CAR has a non-nil value. */
12638 tem
= Fsymbol_value (car
);
12645 /* Symbol's value is nil (or symbol is unbound)
12646 Get the cddr of the original list
12647 and if possible find the caddr and use that. */
12651 else if (!CONSP (elt
))
12656 else if (INTEGERP (car
))
12658 register int lim
= XINT (car
);
12662 /* Negative int means reduce maximum width. */
12663 if (precision
<= 0)
12666 precision
= min (precision
, -lim
);
12670 /* Padding specified. Don't let it be more than
12671 current maximum. */
12673 lim
= min (precision
, lim
);
12675 /* If that's more padding than already wanted, queue it.
12676 But don't reduce padding already specified even if
12677 that is beyond the current truncation point. */
12678 field_width
= max (lim
, field_width
);
12682 else if (STRINGP (car
) || CONSP (car
))
12684 register int limit
= 50;
12685 /* Limit is to protect against circular lists. */
12688 && (precision
<= 0 || n
< precision
))
12690 n
+= display_mode_element (it
, depth
, field_width
- n
,
12691 precision
- n
, XCAR (elt
));
12700 if (frame_title_ptr
)
12701 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
12703 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
12704 precision
- n
, 0, 0);
12708 /* Pad to FIELD_WIDTH. */
12709 if (field_width
> 0 && n
< field_width
)
12711 if (frame_title_ptr
)
12712 n
+= store_frame_title ("", field_width
- n
, 0);
12714 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
12722 /* Write a null-terminated, right justified decimal representation of
12723 the positive integer D to BUF using a minimal field width WIDTH. */
12726 pint2str (buf
, width
, d
)
12727 register char *buf
;
12728 register int width
;
12731 register char *p
= buf
;
12739 *p
++ = d
% 10 + '0';
12744 for (width
-= (int) (p
- buf
); width
> 0; --width
)
12755 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
12756 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
12757 type of CODING_SYSTEM. Return updated pointer into BUF. */
12759 static unsigned char invalid_eol_type
[] = "(*invalid*)";
12762 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
12763 Lisp_Object coding_system
;
12764 register char *buf
;
12768 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
12769 unsigned char *eol_str
;
12771 /* The EOL conversion we are using. */
12772 Lisp_Object eoltype
;
12774 val
= Fget (coding_system
, Qcoding_system
);
12777 if (!VECTORP (val
)) /* Not yet decided. */
12782 eoltype
= eol_mnemonic_undecided
;
12783 /* Don't mention EOL conversion if it isn't decided. */
12787 Lisp_Object eolvalue
;
12789 eolvalue
= Fget (coding_system
, Qeol_type
);
12792 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
12796 /* The EOL conversion that is normal on this system. */
12798 if (NILP (eolvalue
)) /* Not yet decided. */
12799 eoltype
= eol_mnemonic_undecided
;
12800 else if (VECTORP (eolvalue
)) /* Not yet decided. */
12801 eoltype
= eol_mnemonic_undecided
;
12802 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
12803 eoltype
= (XFASTINT (eolvalue
) == 0
12804 ? eol_mnemonic_unix
12805 : (XFASTINT (eolvalue
) == 1
12806 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
12812 /* Mention the EOL conversion if it is not the usual one. */
12813 if (STRINGP (eoltype
))
12815 eol_str
= XSTRING (eoltype
)->data
;
12816 eol_str_len
= XSTRING (eoltype
)->size
;
12818 else if (INTEGERP (eoltype
)
12819 && CHAR_VALID_P (XINT (eoltype
), 0))
12821 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
12822 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
12826 eol_str
= invalid_eol_type
;
12827 eol_str_len
= sizeof (invalid_eol_type
) - 1;
12829 bcopy (eol_str
, buf
, eol_str_len
);
12830 buf
+= eol_str_len
;
12836 /* Return a string for the output of a mode line %-spec for window W,
12837 generated by character C. PRECISION >= 0 means don't return a
12838 string longer than that value. FIELD_WIDTH > 0 means pad the
12839 string returned with spaces to that value. */
12841 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
12844 decode_mode_spec (w
, c
, field_width
, precision
)
12847 int field_width
, precision
;
12850 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12851 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
12852 struct buffer
*b
= XBUFFER (w
->buffer
);
12859 if (!NILP (b
->read_only
))
12861 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12866 /* This differs from %* only for a modified read-only buffer. */
12867 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12869 if (!NILP (b
->read_only
))
12874 /* This differs from %* in ignoring read-only-ness. */
12875 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12887 if (command_loop_level
> 5)
12889 p
= decode_mode_spec_buf
;
12890 for (i
= 0; i
< command_loop_level
; i
++)
12893 return decode_mode_spec_buf
;
12901 if (command_loop_level
> 5)
12903 p
= decode_mode_spec_buf
;
12904 for (i
= 0; i
< command_loop_level
; i
++)
12907 return decode_mode_spec_buf
;
12914 /* Let lots_of_dashes be a string of infinite length. */
12915 if (field_width
<= 0
12916 || field_width
> sizeof (lots_of_dashes
))
12918 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
12919 decode_mode_spec_buf
[i
] = '-';
12920 decode_mode_spec_buf
[i
] = '\0';
12921 return decode_mode_spec_buf
;
12924 return lots_of_dashes
;
12933 int col
= current_column ();
12934 XSETFASTINT (w
->column_number_displayed
, col
);
12935 pint2str (decode_mode_spec_buf
, field_width
, col
);
12936 return decode_mode_spec_buf
;
12940 /* %F displays the frame name. */
12941 if (!NILP (f
->title
))
12942 return (char *) XSTRING (f
->title
)->data
;
12943 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
12944 return (char *) XSTRING (f
->name
)->data
;
12953 int startpos
= XMARKER (w
->start
)->charpos
;
12954 int startpos_byte
= marker_byte_position (w
->start
);
12955 int line
, linepos
, linepos_byte
, topline
;
12957 int height
= XFASTINT (w
->height
);
12959 /* If we decided that this buffer isn't suitable for line numbers,
12960 don't forget that too fast. */
12961 if (EQ (w
->base_line_pos
, w
->buffer
))
12963 /* But do forget it, if the window shows a different buffer now. */
12964 else if (BUFFERP (w
->base_line_pos
))
12965 w
->base_line_pos
= Qnil
;
12967 /* If the buffer is very big, don't waste time. */
12968 if (INTEGERP (Vline_number_display_limit
)
12969 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
12971 w
->base_line_pos
= Qnil
;
12972 w
->base_line_number
= Qnil
;
12976 if (!NILP (w
->base_line_number
)
12977 && !NILP (w
->base_line_pos
)
12978 && XFASTINT (w
->base_line_pos
) <= startpos
)
12980 line
= XFASTINT (w
->base_line_number
);
12981 linepos
= XFASTINT (w
->base_line_pos
);
12982 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
12987 linepos
= BUF_BEGV (b
);
12988 linepos_byte
= BUF_BEGV_BYTE (b
);
12991 /* Count lines from base line to window start position. */
12992 nlines
= display_count_lines (linepos
, linepos_byte
,
12996 topline
= nlines
+ line
;
12998 /* Determine a new base line, if the old one is too close
12999 or too far away, or if we did not have one.
13000 "Too close" means it's plausible a scroll-down would
13001 go back past it. */
13002 if (startpos
== BUF_BEGV (b
))
13004 XSETFASTINT (w
->base_line_number
, topline
);
13005 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
13007 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
13008 || linepos
== BUF_BEGV (b
))
13010 int limit
= BUF_BEGV (b
);
13011 int limit_byte
= BUF_BEGV_BYTE (b
);
13013 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
13015 if (startpos
- distance
> limit
)
13017 limit
= startpos
- distance
;
13018 limit_byte
= CHAR_TO_BYTE (limit
);
13021 nlines
= display_count_lines (startpos
, startpos_byte
,
13023 - (height
* 2 + 30),
13025 /* If we couldn't find the lines we wanted within
13026 line_number_display_limit_width chars per line,
13027 give up on line numbers for this window. */
13028 if (position
== limit_byte
&& limit
== startpos
- distance
)
13030 w
->base_line_pos
= w
->buffer
;
13031 w
->base_line_number
= Qnil
;
13035 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
13036 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
13039 /* Now count lines from the start pos to point. */
13040 nlines
= display_count_lines (startpos
, startpos_byte
,
13041 PT_BYTE
, PT
, &junk
);
13043 /* Record that we did display the line number. */
13044 line_number_displayed
= 1;
13046 /* Make the string to show. */
13047 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
13048 return decode_mode_spec_buf
;
13051 char* p
= decode_mode_spec_buf
;
13052 int pad
= field_width
- 2;
13058 return decode_mode_spec_buf
;
13064 obj
= b
->mode_name
;
13068 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
13074 int pos
= marker_position (w
->start
);
13075 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13077 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
13079 if (pos
<= BUF_BEGV (b
))
13084 else if (pos
<= BUF_BEGV (b
))
13088 if (total
> 1000000)
13089 /* Do it differently for a large value, to avoid overflow. */
13090 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13092 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13093 /* We can't normally display a 3-digit number,
13094 so get us a 2-digit number that is close. */
13097 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13098 return decode_mode_spec_buf
;
13102 /* Display percentage of size above the bottom of the screen. */
13105 int toppos
= marker_position (w
->start
);
13106 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
13107 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13109 if (botpos
>= BUF_ZV (b
))
13111 if (toppos
<= BUF_BEGV (b
))
13118 if (total
> 1000000)
13119 /* Do it differently for a large value, to avoid overflow. */
13120 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13122 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13123 /* We can't normally display a 3-digit number,
13124 so get us a 2-digit number that is close. */
13127 if (toppos
<= BUF_BEGV (b
))
13128 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
13130 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13131 return decode_mode_spec_buf
;
13136 /* status of process */
13137 obj
= Fget_buffer_process (w
->buffer
);
13139 return "no process";
13140 #ifdef subprocesses
13141 obj
= Fsymbol_name (Fprocess_status (obj
));
13145 case 't': /* indicate TEXT or BINARY */
13146 #ifdef MODE_LINE_BINARY_TEXT
13147 return MODE_LINE_BINARY_TEXT (b
);
13153 /* coding-system (not including end-of-line format) */
13155 /* coding-system (including end-of-line type) */
13157 int eol_flag
= (c
== 'Z');
13158 char *p
= decode_mode_spec_buf
;
13160 if (! FRAME_WINDOW_P (f
))
13162 /* No need to mention EOL here--the terminal never needs
13163 to do EOL conversion. */
13164 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
13165 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
13167 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
13170 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
13171 #ifdef subprocesses
13172 obj
= Fget_buffer_process (Fcurrent_buffer ());
13173 if (PROCESSP (obj
))
13175 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
13177 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
13180 #endif /* subprocesses */
13183 return decode_mode_spec_buf
;
13188 return (char *) XSTRING (obj
)->data
;
13194 /* Count up to COUNT lines starting from START / START_BYTE.
13195 But don't go beyond LIMIT_BYTE.
13196 Return the number of lines thus found (always nonnegative).
13198 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
13201 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
13202 int start
, start_byte
, limit_byte
, count
;
13205 register unsigned char *cursor
;
13206 unsigned char *base
;
13208 register int ceiling
;
13209 register unsigned char *ceiling_addr
;
13210 int orig_count
= count
;
13212 /* If we are not in selective display mode,
13213 check only for newlines. */
13214 int selective_display
= (!NILP (current_buffer
->selective_display
)
13215 && !INTEGERP (current_buffer
->selective_display
));
13219 while (start_byte
< limit_byte
)
13221 ceiling
= BUFFER_CEILING_OF (start_byte
);
13222 ceiling
= min (limit_byte
- 1, ceiling
);
13223 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
13224 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
13227 if (selective_display
)
13228 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
13231 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
13234 if (cursor
!= ceiling_addr
)
13238 start_byte
+= cursor
- base
+ 1;
13239 *byte_pos_ptr
= start_byte
;
13243 if (++cursor
== ceiling_addr
)
13249 start_byte
+= cursor
- base
;
13254 while (start_byte
> limit_byte
)
13256 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
13257 ceiling
= max (limit_byte
, ceiling
);
13258 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
13259 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
13262 if (selective_display
)
13263 while (--cursor
!= ceiling_addr
13264 && *cursor
!= '\n' && *cursor
!= 015)
13267 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
13270 if (cursor
!= ceiling_addr
)
13274 start_byte
+= cursor
- base
+ 1;
13275 *byte_pos_ptr
= start_byte
;
13276 /* When scanning backwards, we should
13277 not count the newline posterior to which we stop. */
13278 return - orig_count
- 1;
13284 /* Here we add 1 to compensate for the last decrement
13285 of CURSOR, which took it past the valid range. */
13286 start_byte
+= cursor
- base
+ 1;
13290 *byte_pos_ptr
= limit_byte
;
13293 return - orig_count
+ count
;
13294 return orig_count
- count
;
13300 /***********************************************************************
13302 ***********************************************************************/
13304 /* Display a NUL-terminated string, starting with index START.
13306 If STRING is non-null, display that C string. Otherwise, the Lisp
13307 string LISP_STRING is displayed.
13309 If FACE_STRING is not nil, FACE_STRING_POS is a position in
13310 FACE_STRING. Display STRING or LISP_STRING with the face at
13311 FACE_STRING_POS in FACE_STRING:
13313 Display the string in the environment given by IT, but use the
13314 standard display table, temporarily.
13316 FIELD_WIDTH is the minimum number of output glyphs to produce.
13317 If STRING has fewer characters than FIELD_WIDTH, pad to the right
13318 with spaces. If STRING has more characters, more than FIELD_WIDTH
13319 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
13321 PRECISION is the maximum number of characters to output from
13322 STRING. PRECISION < 0 means don't truncate the string.
13324 This is roughly equivalent to printf format specifiers:
13326 FIELD_WIDTH PRECISION PRINTF
13327 ----------------------------------------
13333 MULTIBYTE zero means do not display multibyte chars, > 0 means do
13334 display them, and < 0 means obey the current buffer's value of
13335 enable_multibyte_characters.
13337 Value is the number of glyphs produced. */
13340 display_string (string
, lisp_string
, face_string
, face_string_pos
,
13341 start
, it
, field_width
, precision
, max_x
, multibyte
)
13342 unsigned char *string
;
13343 Lisp_Object lisp_string
;
13344 Lisp_Object face_string
;
13345 int face_string_pos
;
13348 int field_width
, precision
, max_x
;
13351 int hpos_at_start
= it
->hpos
;
13352 int saved_face_id
= it
->face_id
;
13353 struct glyph_row
*row
= it
->glyph_row
;
13355 /* Initialize the iterator IT for iteration over STRING beginning
13356 with index START. We assume that IT may be modified here (which
13357 means that display_line has to do something when displaying a
13358 mini-buffer prompt, which it does). */
13359 reseat_to_string (it
, string
, lisp_string
, start
,
13360 precision
, field_width
, multibyte
);
13362 /* If displaying STRING, set up the face of the iterator
13363 from LISP_STRING, if that's given. */
13364 if (STRINGP (face_string
))
13370 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
13371 0, it
->region_beg_charpos
,
13372 it
->region_end_charpos
,
13373 &endptr
, it
->base_face_id
);
13374 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
13375 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
13378 /* Set max_x to the maximum allowed X position. Don't let it go
13379 beyond the right edge of the window. */
13381 max_x
= it
->last_visible_x
;
13383 max_x
= min (max_x
, it
->last_visible_x
);
13385 /* Skip over display elements that are not visible. because IT->w is
13387 if (it
->current_x
< it
->first_visible_x
)
13388 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
13389 MOVE_TO_POS
| MOVE_TO_X
);
13391 row
->ascent
= it
->max_ascent
;
13392 row
->height
= it
->max_ascent
+ it
->max_descent
;
13393 row
->phys_ascent
= it
->max_phys_ascent
;
13394 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13396 /* This condition is for the case that we are called with current_x
13397 past last_visible_x. */
13398 while (it
->current_x
< max_x
)
13400 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
13402 /* Get the next display element. */
13403 if (!get_next_display_element (it
))
13406 /* Produce glyphs. */
13407 x_before
= it
->current_x
;
13408 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13409 PRODUCE_GLYPHS (it
);
13411 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
13414 while (i
< nglyphs
)
13416 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13418 if (!it
->truncate_lines_p
13419 && x
+ glyph
->pixel_width
> max_x
)
13421 /* End of continued line or max_x reached. */
13422 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13426 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
13428 /* Glyph is at least partially visible. */
13430 if (x
< it
->first_visible_x
)
13431 it
->glyph_row
->x
= x
- it
->first_visible_x
;
13435 /* Glyph is off the left margin of the display area.
13436 Should not happen. */
13440 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13441 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13442 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13443 row
->phys_height
= max (row
->phys_height
,
13444 it
->max_phys_ascent
+ it
->max_phys_descent
);
13445 x
+= glyph
->pixel_width
;
13449 /* Stop if max_x reached. */
13453 /* Stop at line ends. */
13454 if (ITERATOR_AT_END_OF_LINE_P (it
))
13456 it
->continuation_lines_width
= 0;
13460 set_iterator_to_next (it
, 1);
13462 /* Stop if truncating at the right edge. */
13463 if (it
->truncate_lines_p
13464 && it
->current_x
>= it
->last_visible_x
)
13466 /* Add truncation mark, but don't do it if the line is
13467 truncated at a padding space. */
13468 if (IT_CHARPOS (*it
) < it
->string_nchars
)
13470 if (!FRAME_WINDOW_P (it
->f
))
13471 produce_special_glyphs (it
, IT_TRUNCATION
);
13472 it
->glyph_row
->truncated_on_right_p
= 1;
13478 /* Maybe insert a truncation at the left. */
13479 if (it
->first_visible_x
13480 && IT_CHARPOS (*it
) > 0)
13482 if (!FRAME_WINDOW_P (it
->f
))
13483 insert_left_trunc_glyphs (it
);
13484 it
->glyph_row
->truncated_on_left_p
= 1;
13487 it
->face_id
= saved_face_id
;
13489 /* Value is number of columns displayed. */
13490 return it
->hpos
- hpos_at_start
;
13495 /* This is like a combination of memq and assq. Return 1 if PROPVAL
13496 appears as an element of LIST or as the car of an element of LIST.
13497 If PROPVAL is a list, compare each element against LIST in that
13498 way, and return 1 if any element of PROPVAL is found in LIST.
13499 Otherwise return 0. This function cannot quit. */
13502 invisible_p (propval
, list
)
13503 register Lisp_Object propval
;
13506 register Lisp_Object tail
, proptail
;
13508 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13510 register Lisp_Object tem
;
13512 if (EQ (propval
, tem
))
13514 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
13518 if (CONSP (propval
))
13520 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
13522 Lisp_Object propelt
;
13523 propelt
= XCAR (proptail
);
13524 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13526 register Lisp_Object tem
;
13528 if (EQ (propelt
, tem
))
13530 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
13540 /* Return 1 if PROPVAL appears as the car of an element of LIST and
13541 the cdr of that element is non-nil. If PROPVAL is a list, check
13542 each element of PROPVAL in that way, and the first time some
13543 element is found, return 1 if the cdr of that element is non-nil.
13544 Otherwise return 0. This function cannot quit. */
13547 invisible_ellipsis_p (propval
, list
)
13548 register Lisp_Object propval
;
13551 register Lisp_Object tail
, proptail
;
13553 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13555 register Lisp_Object tem
;
13557 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
13558 return ! NILP (XCDR (tem
));
13561 if (CONSP (propval
))
13562 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
13564 Lisp_Object propelt
;
13565 propelt
= XCAR (proptail
);
13566 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13568 register Lisp_Object tem
;
13570 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
13571 return ! NILP (XCDR (tem
));
13580 /***********************************************************************
13582 ***********************************************************************/
13587 Vwith_echo_area_save_vector
= Qnil
;
13588 staticpro (&Vwith_echo_area_save_vector
);
13590 Vmessage_stack
= Qnil
;
13591 staticpro (&Vmessage_stack
);
13593 Qinhibit_redisplay
= intern ("inhibit-redisplay");
13594 staticpro (&Qinhibit_redisplay
);
13597 defsubr (&Sdump_glyph_matrix
);
13598 defsubr (&Sdump_glyph_row
);
13599 defsubr (&Sdump_tool_bar_row
);
13600 defsubr (&Strace_redisplay_toggle
);
13601 defsubr (&Strace_to_stderr
);
13604 staticpro (&Qmenu_bar_update_hook
);
13605 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
13607 staticpro (&Qoverriding_terminal_local_map
);
13608 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
13610 staticpro (&Qoverriding_local_map
);
13611 Qoverriding_local_map
= intern ("overriding-local-map");
13613 staticpro (&Qwindow_scroll_functions
);
13614 Qwindow_scroll_functions
= intern ("window-scroll-functions");
13616 staticpro (&Qredisplay_end_trigger_functions
);
13617 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
13619 staticpro (&Qinhibit_point_motion_hooks
);
13620 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
13622 QCdata
= intern (":data");
13623 staticpro (&QCdata
);
13624 Qdisplay
= intern ("display");
13625 staticpro (&Qdisplay
);
13626 Qspace_width
= intern ("space-width");
13627 staticpro (&Qspace_width
);
13628 Qraise
= intern ("raise");
13629 staticpro (&Qraise
);
13630 Qspace
= intern ("space");
13631 staticpro (&Qspace
);
13632 Qmargin
= intern ("margin");
13633 staticpro (&Qmargin
);
13634 Qleft_margin
= intern ("left-margin");
13635 staticpro (&Qleft_margin
);
13636 Qright_margin
= intern ("right-margin");
13637 staticpro (&Qright_margin
);
13638 Qalign_to
= intern ("align-to");
13639 staticpro (&Qalign_to
);
13640 QCalign_to
= intern (":align-to");
13641 staticpro (&QCalign_to
);
13642 Qrelative_width
= intern ("relative-width");
13643 staticpro (&Qrelative_width
);
13644 QCrelative_width
= intern (":relative-width");
13645 staticpro (&QCrelative_width
);
13646 QCrelative_height
= intern (":relative-height");
13647 staticpro (&QCrelative_height
);
13648 QCeval
= intern (":eval");
13649 staticpro (&QCeval
);
13650 Qwhen
= intern ("when");
13651 staticpro (&Qwhen
);
13652 QCfile
= intern (":file");
13653 staticpro (&QCfile
);
13654 Qfontified
= intern ("fontified");
13655 staticpro (&Qfontified
);
13656 Qfontification_functions
= intern ("fontification-functions");
13657 staticpro (&Qfontification_functions
);
13658 Qtrailing_whitespace
= intern ("trailing-whitespace");
13659 staticpro (&Qtrailing_whitespace
);
13660 Qimage
= intern ("image");
13661 staticpro (&Qimage
);
13662 Qmessage_truncate_lines
= intern ("message-truncate-lines");
13663 staticpro (&Qmessage_truncate_lines
);
13665 last_arrow_position
= Qnil
;
13666 last_arrow_string
= Qnil
;
13667 staticpro (&last_arrow_position
);
13668 staticpro (&last_arrow_string
);
13670 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
13671 staticpro (&echo_buffer
[0]);
13672 staticpro (&echo_buffer
[1]);
13674 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
13675 staticpro (&echo_area_buffer
[0]);
13676 staticpro (&echo_area_buffer
[1]);
13678 Vmessages_buffer_name
= build_string ("*Messages*");
13679 staticpro (&Vmessages_buffer_name
);
13681 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
13682 "Non-nil means highlight trailing whitespace.\n\
13683 The face used for trailing whitespace is `trailing-whitespace'.");
13684 Vshow_trailing_whitespace
= Qnil
;
13686 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
13687 "Non-nil means don't actually do any redisplay.\n\
13688 This is used for internal purposes.");
13689 Vinhibit_redisplay
= Qnil
;
13691 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
13692 "String (or mode line construct) included (normally) in `mode-line-format'.");
13693 Vglobal_mode_string
= Qnil
;
13695 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
13696 "Marker for where to display an arrow on top of the buffer text.\n\
13697 This must be the beginning of a line in order to work.\n\
13698 See also `overlay-arrow-string'.");
13699 Voverlay_arrow_position
= Qnil
;
13701 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
13702 "String to display as an arrow. See also `overlay-arrow-position'.");
13703 Voverlay_arrow_string
= Qnil
;
13705 DEFVAR_INT ("scroll-step", &scroll_step
,
13706 "*The number of lines to try scrolling a window by when point moves out.\n\
13707 If that fails to bring point back on frame, point is centered instead.\n\
13708 If this is zero, point is always centered after it moves off frame.");
13710 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
13711 "*Scroll up to this many lines, to bring point back on screen.\n\
13712 A value of zero means to scroll the text to center point vertically\n\
13714 scroll_conservatively
= 0;
13716 DEFVAR_INT ("scroll-margin", &scroll_margin
,
13717 "*Number of lines of margin at the top and bottom of a window.\n\
13718 Recenter the window whenever point gets within this many lines\n\
13719 of the top or bottom of the window.");
13723 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
13726 DEFVAR_BOOL ("truncate-partial-width-windows",
13727 &truncate_partial_width_windows
,
13728 "*Non-nil means truncate lines in all windows less than full frame wide.");
13729 truncate_partial_width_windows
= 1;
13731 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
13732 "*Non-nil means use inverse video for the mode line.");
13733 mode_line_inverse_video
= 1;
13735 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
13736 "*Maximum buffer size for which line number should be displayed.\n\
13737 If the buffer is bigger than this, the line number does not appear\n\
13738 in the mode line. A value of nil means no limit.");
13739 Vline_number_display_limit
= Qnil
;
13741 DEFVAR_INT ("line-number-display-limit-width",
13742 &line_number_display_limit_width
,
13743 "*Maximum line width (in characters) for line number display.\n\
13744 If the average length of the lines near point is bigger than this, then the\n\
13745 line number may be omitted from the mode line.");
13746 line_number_display_limit_width
= 200;
13748 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
13749 "*Non-nil means highlight region even in nonselected windows.");
13750 highlight_nonselected_windows
= 0;
13752 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
13753 "Non-nil if more than one frame is visible on this display.\n\
13754 Minibuffer-only frames don't count, but iconified frames do.\n\
13755 This variable is not guaranteed to be accurate except while processing\n\
13756 `frame-title-format' and `icon-title-format'.");
13758 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
13759 "Template for displaying the title bar of visible frames.\n\
13760 \(Assuming the window manager supports this feature.)\n\
13761 This variable has the same structure as `mode-line-format' (which see),\n\
13762 and is used only on frames for which no explicit name has been set\n\
13763 \(see `modify-frame-parameters').");
13764 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
13765 "Template for displaying the title bar of an iconified frame.\n\
13766 \(Assuming the window manager supports this feature.)\n\
13767 This variable has the same structure as `mode-line-format' (which see),\n\
13768 and is used only on frames for which no explicit name has been set\n\
13769 \(see `modify-frame-parameters').");
13771 = Vframe_title_format
13772 = Fcons (intern ("multiple-frames"),
13773 Fcons (build_string ("%b"),
13774 Fcons (Fcons (build_string (""),
13775 Fcons (intern ("invocation-name"),
13776 Fcons (build_string ("@"),
13777 Fcons (intern ("system-name"),
13781 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
13782 "Maximum number of lines to keep in the message log buffer.\n\
13783 If nil, disable message logging. If t, log messages but don't truncate\n\
13784 the buffer when it becomes large.");
13785 XSETFASTINT (Vmessage_log_max
, 50);
13787 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
13788 "Functions called before redisplay, if window sizes have changed.\n\
13789 The value should be a list of functions that take one argument.\n\
13790 Just before redisplay, for each frame, if any of its windows have changed\n\
13791 size since the last redisplay, or have been split or deleted,\n\
13792 all the functions in the list are called, with the frame as argument.");
13793 Vwindow_size_change_functions
= Qnil
;
13795 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
13796 "List of Functions to call before redisplaying a window with scrolling.\n\
13797 Each function is called with two arguments, the window\n\
13798 and its new display-start position. Note that the value of `window-end'\n\
13799 is not valid when these functions are called.");
13800 Vwindow_scroll_functions
= Qnil
;
13802 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
13803 "*Non-nil means automatically resize tool-bars.\n\
13804 This increases a tool-bar's height if not all tool-bar items are visible.\n\
13805 It decreases a tool-bar's height when it would display blank lines\n\
13807 auto_resize_tool_bars_p
= 1;
13809 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
13810 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
13811 auto_raise_tool_bar_buttons_p
= 1;
13813 DEFVAR_INT ("tool-bar-button-margin", &tool_bar_button_margin
,
13814 "*Margin around tool-bar buttons in pixels.");
13815 tool_bar_button_margin
= 1;
13817 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
13818 "Relief thickness of tool-bar buttons.");
13819 tool_bar_button_relief
= 3;
13821 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
13822 "List of functions to call to fontify regions of text.\n\
13823 Each function is called with one argument POS. Functions must\n\
13824 fontify a region starting at POS in the current buffer, and give\n\
13825 fontified regions the property `fontified'.\n\
13826 This variable automatically becomes buffer-local when set.");
13827 Vfontification_functions
= Qnil
;
13828 Fmake_local_variable (Qfontification_functions
);
13830 DEFVAR_BOOL ("unibyte-display-via-language-environment",
13831 &unibyte_display_via_language_environment
,
13832 "*Non-nil means display unibyte text according to language environment.\n\
13833 Specifically this means that unibyte non-ASCII characters\n\
13834 are displayed by converting them to the equivalent multibyte characters\n\
13835 according to the current language environment. As a result, they are\n\
13836 displayed according to the current fontset.");
13837 unibyte_display_via_language_environment
= 0;
13839 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
13840 "*Maximum height for resizing mini-windows.\n\
13841 If a float, it specifies a fraction of the mini-window frame's height.\n\
13842 If an integer, it specifies a number of lines.\n\
13843 If nil, don't resize.");
13844 Vmax_mini_window_height
= make_float (0.25);
13846 DEFVAR_BOOL ("cursor-in-non-selected-windows",
13847 &cursor_in_non_selected_windows
,
13848 "*Non-nil means display a hollow cursor in non-selected windows.\n\
13849 Nil means don't display a cursor there.");
13850 cursor_in_non_selected_windows
= 1;
13852 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
13853 "*Non-nil means scroll the display automatically to make point visible.");
13854 automatic_hscrolling_p
= 1;
13856 DEFVAR_LISP ("image-types", &Vimage_types
,
13857 "List of supported image types.\n\
13858 Each element of the list is a symbol for a supported image type.");
13859 Vimage_types
= Qnil
;
13861 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
13862 "If non-nil, messages are truncated instead of resizing the echo area.\n\
13863 Bind this around calls to `message' to let it take effect.");
13864 message_truncate_lines
= 0;
13866 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
13867 "Normal hook run for clicks on menu bar, before displaying a submenu.\n\
13868 Can be used to update submenus whose contents should vary.");
13873 /* Initialize this module when Emacs starts. */
13878 Lisp_Object root_window
;
13879 struct window
*mini_w
;
13881 CHARPOS (this_line_start_pos
) = 0;
13883 mini_w
= XWINDOW (minibuf_window
);
13884 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
13886 if (!noninteractive
)
13888 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
13891 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
13892 set_window_height (root_window
,
13893 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
13895 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
13896 set_window_height (minibuf_window
, 1, 0);
13898 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
13899 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
13901 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
13902 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
13903 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
13905 /* The default ellipsis glyphs `...'. */
13906 for (i
= 0; i
< 3; ++i
)
13907 XSETFASTINT (default_invis_vector
[i
], '.');
13910 #ifdef HAVE_WINDOW_SYSTEM
13912 /* Allocate the buffer for frame titles. */
13914 frame_title_buf
= (char *) xmalloc (size
);
13915 frame_title_buf_end
= frame_title_buf
+ size
;
13916 frame_title_ptr
= NULL
;
13918 #endif /* HAVE_WINDOW_SYSTEM */
13920 help_echo_showing_p
= 0;