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
198 #define min(a, b) ((a) < (b) ? (a) : (b))
199 #define max(a, b) ((a) > (b) ? (a) : (b))
201 #define INFINITY 10000000
203 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
204 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
205 extern int pending_menu_activation
;
208 extern int interrupt_input
;
209 extern int command_loop_level
;
211 extern int minibuffer_auto_raise
;
213 extern Lisp_Object Qface
;
215 extern Lisp_Object Voverriding_local_map
;
216 extern Lisp_Object Voverriding_local_map_menu_flag
;
217 extern Lisp_Object Qmenu_item
;
219 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
220 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
221 Lisp_Object Qredisplay_end_trigger_functions
;
222 Lisp_Object Qinhibit_point_motion_hooks
;
223 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
;
224 Lisp_Object Qfontified
;
226 /* Functions called to fontify regions of text. */
228 Lisp_Object Vfontification_functions
;
229 Lisp_Object Qfontification_functions
;
231 /* Non-zero means draw tool bar buttons raised when the mouse moves
234 int auto_raise_tool_bar_buttons_p
;
236 /* Margin around tool bar buttons in pixels. */
238 int tool_bar_button_margin
;
240 /* Thickness of shadow to draw around tool bar buttons. */
242 int tool_bar_button_relief
;
244 /* Non-zero means automatically resize tool-bars so that all tool-bar
245 items are visible, and no blank lines remain. */
247 int auto_resize_tool_bars_p
;
249 /* Non-nil means don't actually do any redisplay. */
251 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
253 /* Names of text properties relevant for redisplay. */
255 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
256 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
258 /* Symbols used in text property values. */
260 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
261 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
263 extern Lisp_Object Qheight
;
265 /* Non-nil means highlight trailing whitespace. */
267 Lisp_Object Vshow_trailing_whitespace
;
269 /* Name of the face used to highlight trailing whitespace. */
271 Lisp_Object Qtrailing_whitespace
;
273 /* The symbol `image' which is the car of the lists used to represent
278 /* Non-zero means print newline to stdout before next mini-buffer
281 int noninteractive_need_newline
;
283 /* Non-zero means print newline to message log before next message. */
285 static int message_log_need_newline
;
288 /* The buffer position of the first character appearing entirely or
289 partially on the line of the selected window which contains the
290 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
291 redisplay optimization in redisplay_internal. */
293 static struct text_pos this_line_start_pos
;
295 /* Number of characters past the end of the line above, including the
296 terminating newline. */
298 static struct text_pos this_line_end_pos
;
300 /* The vertical positions and the height of this line. */
302 static int this_line_vpos
;
303 static int this_line_y
;
304 static int this_line_pixel_height
;
306 /* X position at which this display line starts. Usually zero;
307 negative if first character is partially visible. */
309 static int this_line_start_x
;
311 /* Buffer that this_line_.* variables are referring to. */
313 static struct buffer
*this_line_buffer
;
315 /* Nonzero means truncate lines in all windows less wide than the
318 int truncate_partial_width_windows
;
320 /* A flag to control how to display unibyte 8-bit character. */
322 int unibyte_display_via_language_environment
;
324 /* Nonzero means we have more than one non-mini-buffer-only frame.
325 Not guaranteed to be accurate except while parsing
326 frame-title-format. */
330 Lisp_Object Vglobal_mode_string
;
332 /* Marker for where to display an arrow on top of the buffer text. */
334 Lisp_Object Voverlay_arrow_position
;
336 /* String to display for the arrow. Only used on terminal frames. */
338 Lisp_Object Voverlay_arrow_string
;
340 /* Values of those variables at last redisplay. However, if
341 Voverlay_arrow_position is a marker, last_arrow_position is its
342 numerical position. */
344 static Lisp_Object last_arrow_position
, last_arrow_string
;
346 /* Like mode-line-format, but for the title bar on a visible frame. */
348 Lisp_Object Vframe_title_format
;
350 /* Like mode-line-format, but for the title bar on an iconified frame. */
352 Lisp_Object Vicon_title_format
;
354 /* List of functions to call when a window's size changes. These
355 functions get one arg, a frame on which one or more windows' sizes
358 static Lisp_Object Vwindow_size_change_functions
;
360 Lisp_Object Qmenu_bar_update_hook
;
362 /* Nonzero if overlay arrow has been displayed once in this window. */
364 static int overlay_arrow_seen
;
366 /* Nonzero means highlight the region even in nonselected windows. */
368 int highlight_nonselected_windows
;
370 /* If cursor motion alone moves point off frame, try scrolling this
371 many lines up or down if that will bring it back. */
373 static int scroll_step
;
375 /* Non-0 means scroll just far enough to bring point back on the
376 screen, when appropriate. */
378 static int scroll_conservatively
;
380 /* Recenter the window whenever point gets within this many lines of
381 the top or bottom of the window. This value is translated into a
382 pixel value by multiplying it with CANON_Y_UNIT, which means that
383 there is really a fixed pixel height scroll margin. */
387 /* Number of windows showing the buffer of the selected window (or
388 another buffer with the same base buffer). keyboard.c refers to
393 /* Vector containing glyphs for an ellipsis `...'. */
395 static Lisp_Object default_invis_vector
[3];
397 /* Nonzero means display mode line highlighted. */
399 int mode_line_inverse_video
;
401 /* Prompt to display in front of the mini-buffer contents. */
403 Lisp_Object minibuf_prompt
;
405 /* Width of current mini-buffer prompt. Only set after display_line
406 of the line that contains the prompt. */
408 int minibuf_prompt_width
;
409 int minibuf_prompt_pixel_width
;
411 /* This is the window where the echo area message was displayed. It
412 is always a mini-buffer window, but it may not be the same window
413 currently active as a mini-buffer. */
415 Lisp_Object echo_area_window
;
417 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
418 pushes the current message and the value of
419 message_enable_multibyte on the stack, the function restore_message
420 pops the stack and displays MESSAGE again. */
422 Lisp_Object Vmessage_stack
;
424 /* Nonzero means multibyte characters were enabled when the echo area
425 message was specified. */
427 int message_enable_multibyte
;
429 /* True if we should redraw the mode lines on the next redisplay. */
431 int update_mode_lines
;
433 /* Nonzero if window sizes or contents have changed since last
434 redisplay that finished */
436 int windows_or_buffers_changed
;
438 /* Nonzero after display_mode_line if %l was used and it displayed a
441 int line_number_displayed
;
443 /* Maximum buffer size for which to display line numbers. */
445 Lisp_Object Vline_number_display_limit
;
447 /* line width to consider when repostioning for line number display */
449 static int line_number_display_limit_width
;
451 /* Number of lines to keep in the message log buffer. t means
452 infinite. nil means don't log at all. */
454 Lisp_Object Vmessage_log_max
;
456 /* The name of the *Messages* buffer, a string. */
458 static Lisp_Object Vmessages_buffer_name
;
460 /* Current, index 0, and last displayed echo area message. Either
461 buffers from echo_buffers, or nil to indicate no message. */
463 Lisp_Object echo_area_buffer
[2];
465 /* The buffers referenced from echo_area_buffer. */
467 static Lisp_Object echo_buffer
[2];
469 /* A vector saved used in with_area_buffer to reduce consing. */
471 static Lisp_Object Vwith_echo_area_save_vector
;
473 /* Non-zero means display_echo_area should display the last echo area
474 message again. Set by redisplay_preserve_echo_area. */
476 static int display_last_displayed_message_p
;
478 /* Nonzero if echo area is being used by print; zero if being used by
481 int message_buf_print
;
483 /* Maximum height for resizing mini-windows. Either a float
484 specifying a fraction of the available height, or an integer
485 specifying a number of lines. */
487 Lisp_Object Vmax_mini_window_height
;
489 /* Non-zero means messages should be displayed with truncated
490 lines instead of being continued. */
492 int message_truncate_lines
;
493 Lisp_Object Qmessage_truncate_lines
;
495 /* Non-zero means we want a hollow cursor in windows that are not
496 selected. Zero means there's no cursor in such windows. */
498 int cursor_in_non_selected_windows
;
500 /* A scratch glyph row with contents used for generating truncation
501 glyphs. Also used in direct_output_for_insert. */
503 #define MAX_SCRATCH_GLYPHS 100
504 struct glyph_row scratch_glyph_row
;
505 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
507 /* Ascent and height of the last line processed by move_it_to. */
509 static int last_max_ascent
, last_height
;
511 /* The maximum distance to look ahead for text properties. Values
512 that are too small let us call compute_char_face and similar
513 functions too often which is expensive. Values that are too large
514 let us call compute_char_face and alike too often because we
515 might not be interested in text properties that far away. */
517 #define TEXT_PROP_DISTANCE_LIMIT 100
521 /* Non-zero means print traces of redisplay if compiled with
524 int trace_redisplay_p
;
526 #endif /* GLYPH_DEBUG */
528 #ifdef DEBUG_TRACE_MOVE
529 /* Non-zero means trace with TRACE_MOVE to stderr. */
532 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
534 #define TRACE_MOVE(x) (void) 0
537 /* Non-zero means automatically scroll windows horizontally to make
540 int automatic_hscrolling_p
;
542 /* A list of symbols, one for each supported image type. */
544 Lisp_Object Vimage_types
;
546 /* Value returned from text property handlers (see below). */
551 HANDLED_RECOMPUTE_PROPS
,
552 HANDLED_OVERLAY_STRING_CONSUMED
,
556 /* A description of text properties that redisplay is interested
561 /* The name of the property. */
564 /* A unique index for the property. */
567 /* A handler function called to set up iterator IT from the property
568 at IT's current position. Value is used to steer handle_stop. */
569 enum prop_handled (*handler
) P_ ((struct it
*it
));
572 static enum prop_handled handle_face_prop
P_ ((struct it
*));
573 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
574 static enum prop_handled handle_display_prop
P_ ((struct it
*));
575 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
576 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
577 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
579 /* Properties handled by iterators. */
581 static struct props it_props
[] =
583 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
584 /* Handle `face' before `display' because some sub-properties of
585 `display' need to know the face. */
586 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
587 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
588 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
589 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
593 /* Value is the position described by X. If X is a marker, value is
594 the marker_position of X. Otherwise, value is X. */
596 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
598 /* Enumeration returned by some move_it_.* functions internally. */
602 /* Not used. Undefined value. */
605 /* Move ended at the requested buffer position or ZV. */
606 MOVE_POS_MATCH_OR_ZV
,
608 /* Move ended at the requested X pixel position. */
611 /* Move within a line ended at the end of a line that must be
615 /* Move within a line ended at the end of a line that would
616 be displayed truncated. */
619 /* Move within a line ended at a line end. */
625 /* Function prototypes. */
627 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
628 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
629 static int invisible_text_between_p
P_ ((struct it
*, int, int));
630 static int next_element_from_ellipsis
P_ ((struct it
*));
631 static void pint2str
P_ ((char *, int, int));
632 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
634 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
635 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
636 static void store_frame_title_char
P_ ((char));
637 static int store_frame_title
P_ ((unsigned char *, int, int));
638 static void x_consider_frame_title
P_ ((Lisp_Object
));
639 static void handle_stop
P_ ((struct it
*));
640 static int tool_bar_lines_needed
P_ ((struct frame
*));
641 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
642 static void ensure_echo_area_buffers
P_ ((void));
643 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
645 struct glyph_row
*));
646 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
647 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
648 static int with_echo_area_buffer
P_ ((struct window
*, int,
649 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
650 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
651 static void clear_garbaged_frames
P_ ((void));
652 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
653 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
654 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
655 static int display_echo_area
P_ ((struct window
*));
656 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
657 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
658 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
659 static int string_char_and_length
P_ ((unsigned char *, int, int *));
660 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
662 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
663 static Lisp_Object eval_handler
P_ ((Lisp_Object
));
664 static void insert_left_trunc_glyphs
P_ ((struct it
*));
665 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
666 static void extend_face_to_end_of_line
P_ ((struct it
*));
667 static int append_space
P_ ((struct it
*, int));
668 static void make_cursor_line_fully_visible
P_ ((struct window
*));
669 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
670 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
671 static int trailing_whitespace_p
P_ ((int));
672 static int message_log_check_duplicate
P_ ((int, int, int, int));
673 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
674 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
675 static void push_it
P_ ((struct it
*));
676 static void pop_it
P_ ((struct it
*));
677 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
678 static void redisplay_internal
P_ ((int));
679 static int echo_area_display
P_ ((int));
680 static void redisplay_windows
P_ ((Lisp_Object
));
681 static void redisplay_window
P_ ((Lisp_Object
, int));
682 static void update_menu_bar
P_ ((struct frame
*, int));
683 static int try_window_reusing_current_matrix
P_ ((struct window
*));
684 static int try_window_id
P_ ((struct window
*));
685 static int display_line
P_ ((struct it
*));
686 static int display_mode_lines
P_ ((struct window
*));
687 static void display_mode_line
P_ ((struct window
*, enum face_id
,
689 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
690 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
691 static void display_menu_bar
P_ ((struct window
*));
692 static int display_count_lines
P_ ((int, int, int, int, int *));
693 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
694 int, int, struct it
*, int, int, int, int));
695 static void compute_line_metrics
P_ ((struct it
*));
696 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
697 static int get_overlay_strings
P_ ((struct it
*));
698 static void next_overlay_string
P_ ((struct it
*));
699 void set_iterator_to_next
P_ ((struct it
*));
700 static void reseat
P_ ((struct it
*, struct text_pos
, int));
701 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
702 static void back_to_previous_visible_line_start
P_ ((struct it
*));
703 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
704 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
705 static int next_element_from_display_vector
P_ ((struct it
*));
706 static int next_element_from_string
P_ ((struct it
*));
707 static int next_element_from_c_string
P_ ((struct it
*));
708 static int next_element_from_buffer
P_ ((struct it
*));
709 static int next_element_from_composition
P_ ((struct it
*));
710 static int next_element_from_image
P_ ((struct it
*));
711 static int next_element_from_stretch
P_ ((struct it
*));
712 static void load_overlay_strings
P_ ((struct it
*));
713 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
714 struct display_pos
*));
715 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
716 Lisp_Object
, int, int, int, int));
717 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
719 void move_it_vertically_backward
P_ ((struct it
*, int));
720 static void init_to_row_start
P_ ((struct it
*, struct window
*,
721 struct glyph_row
*));
722 static void init_to_row_end
P_ ((struct it
*, struct window
*,
723 struct glyph_row
*));
724 static void back_to_previous_line_start
P_ ((struct it
*));
725 static void forward_to_next_line_start
P_ ((struct it
*));
726 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
728 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
729 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
730 static int number_of_chars
P_ ((unsigned char *, int));
731 static void compute_stop_pos
P_ ((struct it
*));
732 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
734 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
735 static int next_overlay_change
P_ ((int));
736 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
737 Lisp_Object
, struct text_pos
*));
739 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
740 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
742 #ifdef HAVE_WINDOW_SYSTEM
744 static void update_tool_bar
P_ ((struct frame
*, int));
745 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
746 static int redisplay_tool_bar
P_ ((struct frame
*));
747 static void display_tool_bar_line
P_ ((struct it
*));
749 #endif /* HAVE_WINDOW_SYSTEM */
752 /***********************************************************************
753 Window display dimensions
754 ***********************************************************************/
756 /* Return the window-relative maximum y + 1 for glyph rows displaying
757 text in window W. This is the height of W minus the height of a
758 mode line, if any. */
761 window_text_bottom_y (w
)
764 struct frame
*f
= XFRAME (w
->frame
);
765 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
767 if (WINDOW_WANTS_MODELINE_P (w
))
768 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
773 /* Return the pixel width of display area AREA of window W. AREA < 0
774 means return the total width of W, not including bitmap areas to
775 the left and right of the window. */
778 window_box_width (w
, area
)
782 struct frame
*f
= XFRAME (w
->frame
);
783 int width
= XFASTINT (w
->width
);
785 if (!w
->pseudo_window_p
)
787 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
789 if (area
== TEXT_AREA
)
791 if (INTEGERP (w
->left_margin_width
))
792 width
-= XFASTINT (w
->left_margin_width
);
793 if (INTEGERP (w
->right_margin_width
))
794 width
-= XFASTINT (w
->right_margin_width
);
796 else if (area
== LEFT_MARGIN_AREA
)
797 width
= (INTEGERP (w
->left_margin_width
)
798 ? XFASTINT (w
->left_margin_width
) : 0);
799 else if (area
== RIGHT_MARGIN_AREA
)
800 width
= (INTEGERP (w
->right_margin_width
)
801 ? XFASTINT (w
->right_margin_width
) : 0);
804 return width
* CANON_X_UNIT (f
);
808 /* Return the pixel height of the display area of window W, not
809 including mode lines of W, if any.. */
812 window_box_height (w
)
815 struct frame
*f
= XFRAME (w
->frame
);
816 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
818 if (WINDOW_WANTS_MODELINE_P (w
))
819 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
821 if (WINDOW_WANTS_HEADER_LINE_P (w
))
822 height
-= CURRENT_HEADER_LINE_HEIGHT (w
);
828 /* Return the frame-relative coordinate of the left edge of display
829 area AREA of window W. AREA < 0 means return the left edge of the
830 whole window, to the right of any bitmap area at the left side of
834 window_box_left (w
, area
)
838 struct frame
*f
= XFRAME (w
->frame
);
839 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
841 if (!w
->pseudo_window_p
)
843 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
844 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
846 if (area
== TEXT_AREA
)
847 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
848 else if (area
== RIGHT_MARGIN_AREA
)
849 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
850 + window_box_width (w
, TEXT_AREA
));
857 /* Return the frame-relative coordinate of the right edge of display
858 area AREA of window W. AREA < 0 means return the left edge of the
859 whole window, to the left of any bitmap area at the right side of
863 window_box_right (w
, area
)
867 return window_box_left (w
, area
) + window_box_width (w
, area
);
871 /* Get the bounding box of the display area AREA of window W, without
872 mode lines, in frame-relative coordinates. AREA < 0 means the
873 whole window, not including bitmap areas to the left and right of
874 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
875 coordinates of the upper-left corner of the box. Return in
876 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
879 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
882 int *box_x
, *box_y
, *box_width
, *box_height
;
884 struct frame
*f
= XFRAME (w
->frame
);
886 *box_width
= window_box_width (w
, area
);
887 *box_height
= window_box_height (w
);
888 *box_x
= window_box_left (w
, area
);
889 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
890 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
891 if (WINDOW_WANTS_HEADER_LINE_P (w
))
892 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
896 /* Get the bounding box of the display area AREA of window W, without
897 mode lines. AREA < 0 means the whole window, not including bitmap
898 areas to the left and right of the window. Return in *TOP_LEFT_X
899 and TOP_LEFT_Y the frame-relative pixel coordinates of the
900 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
901 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
905 window_box_edges (w
, area
, top_left_x
, top_left_y
,
906 bottom_right_x
, bottom_right_y
)
909 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
911 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
913 *bottom_right_x
+= *top_left_x
;
914 *bottom_right_y
+= *top_left_y
;
919 /***********************************************************************
921 ***********************************************************************/
923 /* Return the next character from STR which is MAXLEN bytes long.
924 Return in *LEN the length of the character. This is like
925 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
926 we find one, we return a `?', but with the length of the invalid
930 string_char_and_length (str
, maxlen
, len
)
936 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
937 if (!CHAR_VALID_P (c
, 1))
938 /* We may not change the length here because other places in Emacs
939 don't use this function, i.e. they silently accept invalid
948 /* Given a position POS containing a valid character and byte position
949 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
951 static struct text_pos
952 string_pos_nchars_ahead (pos
, string
, nchars
)
957 xassert (STRINGP (string
) && nchars
>= 0);
959 if (STRING_MULTIBYTE (string
))
961 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
962 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
967 string_char_and_length (p
, rest
, &len
);
968 p
+= len
, rest
-= len
;
971 BYTEPOS (pos
) += len
;
975 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
981 /* Value is the text position, i.e. character and byte position,
982 for character position CHARPOS in STRING. */
984 static INLINE
struct text_pos
985 string_pos (charpos
, string
)
990 xassert (STRINGP (string
));
991 xassert (charpos
>= 0);
992 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
997 /* Value is a text position, i.e. character and byte position, for
998 character position CHARPOS in C string S. MULTIBYTE_P non-zero
999 means recognize multibyte characters. */
1001 static struct text_pos
1002 c_string_pos (charpos
, s
, multibyte_p
)
1007 struct text_pos pos
;
1009 xassert (s
!= NULL
);
1010 xassert (charpos
>= 0);
1014 int rest
= strlen (s
), len
;
1016 SET_TEXT_POS (pos
, 0, 0);
1019 string_char_and_length (s
, rest
, &len
);
1020 s
+= len
, rest
-= len
;
1021 xassert (rest
>= 0);
1023 BYTEPOS (pos
) += len
;
1027 SET_TEXT_POS (pos
, charpos
, charpos
);
1033 /* Value is the number of characters in C string S. MULTIBYTE_P
1034 non-zero means recognize multibyte characters. */
1037 number_of_chars (s
, multibyte_p
)
1045 int rest
= strlen (s
), len
;
1046 unsigned char *p
= (unsigned char *) s
;
1048 for (nchars
= 0; rest
> 0; ++nchars
)
1050 string_char_and_length (p
, rest
, &len
);
1051 rest
-= len
, p
+= len
;
1055 nchars
= strlen (s
);
1061 /* Compute byte position NEWPOS->bytepos corresponding to
1062 NEWPOS->charpos. POS is a known position in string STRING.
1063 NEWPOS->charpos must be >= POS.charpos. */
1066 compute_string_pos (newpos
, pos
, string
)
1067 struct text_pos
*newpos
, pos
;
1070 xassert (STRINGP (string
));
1071 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1073 if (STRING_MULTIBYTE (string
))
1074 *newpos
= string_pos_nchars_ahead (pos
, string
,
1075 CHARPOS (*newpos
) - CHARPOS (pos
));
1077 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1082 /***********************************************************************
1083 Lisp form evaluation
1084 ***********************************************************************/
1086 /* Error handler for eval_form and call_function. */
1096 /* Evaluate SEXPR and return the result, or nil if something went
1103 int count
= specpdl_ptr
- specpdl
;
1104 struct gcpro gcpro1
;
1108 specbind (Qinhibit_redisplay
, Qt
);
1109 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, eval_handler
);
1111 return unbind_to (count
, val
);
1115 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1116 Return the result, or nil if something went wrong. */
1119 call_function (nargs
, args
)
1123 int count
= specpdl_ptr
- specpdl
;
1125 struct gcpro gcpro1
;
1128 gcpro1
.nvars
= nargs
;
1129 specbind (Qinhibit_redisplay
, Qt
);
1130 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1133 return unbind_to (count
, val
);
1138 /***********************************************************************
1140 ***********************************************************************/
1144 /* Define CHECK_IT to perform sanity checks on iterators.
1145 This is for debugging. It is too slow to do unconditionally. */
1151 if (it
->method
== next_element_from_string
)
1153 xassert (STRINGP (it
->string
));
1154 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1156 else if (it
->method
== next_element_from_buffer
)
1158 /* Check that character and byte positions agree. */
1159 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1163 xassert (it
->current
.dpvec_index
>= 0);
1165 xassert (it
->current
.dpvec_index
< 0);
1168 #define CHECK_IT(IT) check_it ((IT))
1172 #define CHECK_IT(IT) (void) 0
1179 /* Check that the window end of window W is what we expect it
1180 to be---the last row in the current matrix displaying text. */
1183 check_window_end (w
)
1186 if (!MINI_WINDOW_P (w
)
1187 && !NILP (w
->window_end_valid
))
1189 struct glyph_row
*row
;
1190 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1191 XFASTINT (w
->window_end_vpos
)),
1193 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1194 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1198 #define CHECK_WINDOW_END(W) check_window_end ((W))
1200 #else /* not GLYPH_DEBUG */
1202 #define CHECK_WINDOW_END(W) (void) 0
1204 #endif /* not GLYPH_DEBUG */
1208 /***********************************************************************
1209 Iterator initialization
1210 ***********************************************************************/
1212 /* Initialize IT for displaying current_buffer in window W, starting
1213 at character position CHARPOS. CHARPOS < 0 means that no buffer
1214 position is specified which is useful when the iterator is assigned
1215 a position later. BYTEPOS is the byte position corresponding to
1216 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1218 If ROW is not null, calls to produce_glyphs with IT as parameter
1219 will produce glyphs in that row.
1221 BASE_FACE_ID is the id of a base face to use. It must be one of
1222 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1223 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1224 displaying the tool-bar.
1226 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1227 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1228 corresponding mode line glyph row of the desired matrix of W. */
1231 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1234 int charpos
, bytepos
;
1235 struct glyph_row
*row
;
1236 enum face_id base_face_id
;
1238 int highlight_region_p
;
1240 /* Some precondition checks. */
1241 xassert (w
!= NULL
&& it
!= NULL
);
1242 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1244 /* If face attributes have been changed since the last redisplay,
1245 free realized faces now because they depend on face definitions
1246 that might have changed. */
1247 if (face_change_count
)
1249 face_change_count
= 0;
1250 free_all_realized_faces (Qnil
);
1253 /* Use one of the mode line rows of W's desired matrix if
1257 if (base_face_id
== MODE_LINE_FACE_ID
)
1258 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1259 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1260 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1264 bzero (it
, sizeof *it
);
1265 it
->current
.overlay_string_index
= -1;
1266 it
->current
.dpvec_index
= -1;
1267 it
->base_face_id
= base_face_id
;
1269 /* The window in which we iterate over current_buffer: */
1270 XSETWINDOW (it
->window
, w
);
1272 it
->f
= XFRAME (w
->frame
);
1274 /* Extra space between lines (on window systems only). */
1275 if (base_face_id
== DEFAULT_FACE_ID
1276 && FRAME_WINDOW_P (it
->f
))
1278 if (NATNUMP (current_buffer
->extra_line_spacing
))
1279 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1280 else if (it
->f
->extra_line_spacing
> 0)
1281 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1284 /* If realized faces have been removed, e.g. because of face
1285 attribute changes of named faces, recompute them. */
1286 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1287 recompute_basic_faces (it
->f
);
1289 /* Current value of the `space-width', and 'height' properties. */
1290 it
->space_width
= Qnil
;
1291 it
->font_height
= Qnil
;
1293 /* Are control characters displayed as `^C'? */
1294 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1296 /* -1 means everything between a CR and the following line end
1297 is invisible. >0 means lines indented more than this value are
1299 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1300 ? XFASTINT (current_buffer
->selective_display
)
1301 : (!NILP (current_buffer
->selective_display
)
1303 it
->selective_display_ellipsis_p
1304 = !NILP (current_buffer
->selective_display_ellipses
);
1306 /* Display table to use. */
1307 it
->dp
= window_display_table (w
);
1309 /* Are multibyte characters enabled in current_buffer? */
1310 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1312 /* Non-zero if we should highlight the region. */
1314 = (!NILP (Vtransient_mark_mode
)
1315 && !NILP (current_buffer
->mark_active
)
1316 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1318 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1319 start and end of a visible region in window IT->w. Set both to
1320 -1 to indicate no region. */
1321 if (highlight_region_p
1322 /* Maybe highlight only in selected window. */
1323 && (/* Either show region everywhere. */
1324 highlight_nonselected_windows
1325 /* Or show region in the selected window. */
1326 || w
== XWINDOW (selected_window
)
1327 /* Or show the region if we are in the mini-buffer and W is
1328 the window the mini-buffer refers to. */
1329 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1330 && w
== XWINDOW (Vminibuf_scroll_window
))))
1332 int charpos
= marker_position (current_buffer
->mark
);
1333 it
->region_beg_charpos
= min (PT
, charpos
);
1334 it
->region_end_charpos
= max (PT
, charpos
);
1337 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1339 /* Get the position at which the redisplay_end_trigger hook should
1340 be run, if it is to be run at all. */
1341 if (MARKERP (w
->redisplay_end_trigger
)
1342 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1343 it
->redisplay_end_trigger_charpos
1344 = marker_position (w
->redisplay_end_trigger
);
1345 else if (INTEGERP (w
->redisplay_end_trigger
))
1346 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1348 /* Correct bogus values of tab_width. */
1349 it
->tab_width
= XINT (current_buffer
->tab_width
);
1350 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1353 /* Are lines in the display truncated? */
1354 it
->truncate_lines_p
1355 = (base_face_id
!= DEFAULT_FACE_ID
1356 || XINT (it
->w
->hscroll
)
1357 || (truncate_partial_width_windows
1358 && !WINDOW_FULL_WIDTH_P (it
->w
))
1359 || !NILP (current_buffer
->truncate_lines
));
1361 /* Get dimensions of truncation and continuation glyphs. These are
1362 displayed as bitmaps under X, so we don't need them for such
1364 if (!FRAME_WINDOW_P (it
->f
))
1366 if (it
->truncate_lines_p
)
1368 /* We will need the truncation glyph. */
1369 xassert (it
->glyph_row
== NULL
);
1370 produce_special_glyphs (it
, IT_TRUNCATION
);
1371 it
->truncation_pixel_width
= it
->pixel_width
;
1375 /* We will need the continuation glyph. */
1376 xassert (it
->glyph_row
== NULL
);
1377 produce_special_glyphs (it
, IT_CONTINUATION
);
1378 it
->continuation_pixel_width
= it
->pixel_width
;
1381 /* Reset these values to zero becaue the produce_special_glyphs
1382 above has changed them. */
1383 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1384 it
->phys_ascent
= it
->phys_descent
= 0;
1387 /* Set this after getting the dimensions of truncation and
1388 continuation glyphs, so that we don't produce glyphs when calling
1389 produce_special_glyphs, above. */
1390 it
->glyph_row
= row
;
1391 it
->area
= TEXT_AREA
;
1393 /* Get the dimensions of the display area. The display area
1394 consists of the visible window area plus a horizontally scrolled
1395 part to the left of the window. All x-values are relative to the
1396 start of this total display area. */
1397 if (base_face_id
!= DEFAULT_FACE_ID
)
1399 /* Mode lines, menu bar in terminal frames. */
1400 it
->first_visible_x
= 0;
1401 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1406 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1407 it
->last_visible_x
= (it
->first_visible_x
1408 + window_box_width (w
, TEXT_AREA
));
1410 /* If we truncate lines, leave room for the truncator glyph(s) at
1411 the right margin. Otherwise, leave room for the continuation
1412 glyph(s). Truncation and continuation glyphs are not inserted
1413 for window-based redisplay. */
1414 if (!FRAME_WINDOW_P (it
->f
))
1416 if (it
->truncate_lines_p
)
1417 it
->last_visible_x
-= it
->truncation_pixel_width
;
1419 it
->last_visible_x
-= it
->continuation_pixel_width
;
1422 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1423 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1426 /* Leave room for a border glyph. */
1427 if (!FRAME_WINDOW_P (it
->f
)
1428 && !WINDOW_RIGHTMOST_P (it
->w
))
1429 it
->last_visible_x
-= 1;
1431 it
->last_visible_y
= window_text_bottom_y (w
);
1433 /* For mode lines and alike, arrange for the first glyph having a
1434 left box line if the face specifies a box. */
1435 if (base_face_id
!= DEFAULT_FACE_ID
)
1439 it
->face_id
= base_face_id
;
1441 /* If we have a boxed mode line, make the first character appear
1442 with a left box line. */
1443 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1444 if (face
->box
!= FACE_NO_BOX
)
1445 it
->start_of_box_run_p
= 1;
1448 /* If a buffer position was specified, set the iterator there,
1449 getting overlays and face properties from that position. */
1452 it
->end_charpos
= ZV
;
1454 IT_CHARPOS (*it
) = charpos
;
1456 /* Compute byte position if not specified. */
1458 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1460 IT_BYTEPOS (*it
) = bytepos
;
1462 /* Compute faces etc. */
1463 reseat (it
, it
->current
.pos
, 1);
1470 /* Initialize IT for the display of window W with window start POS. */
1473 start_display (it
, w
, pos
)
1476 struct text_pos pos
;
1478 int start_at_line_beg_p
;
1479 struct glyph_row
*row
;
1480 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1483 row
= w
->desired_matrix
->rows
+ first_vpos
;
1484 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1485 first_y
= it
->current_y
;
1487 /* If window start is not at a line start, move back to the line
1488 start. This makes sure that we take continuation lines into
1490 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1491 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1492 if (!start_at_line_beg_p
)
1493 reseat_at_previous_visible_line_start (it
);
1495 /* If window start is not at a line start, skip forward to POS to
1496 get the correct continuation_lines_width and current_x. */
1497 if (!start_at_line_beg_p
)
1499 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1501 /* If lines are continued, this line may end in the middle of a
1502 multi-glyph character (e.g. a control character displayed as
1503 \003, or in the middle of an overlay string). In this case
1504 move_it_to above will not have taken us to the start of
1505 the continuation line but to the end of the continued line. */
1506 if (!it
->truncate_lines_p
)
1508 if (it
->current_x
> 0)
1510 if (it
->current
.dpvec_index
>= 0
1511 || it
->current
.overlay_string_index
>= 0)
1513 set_iterator_to_next (it
);
1514 move_it_in_display_line_to (it
, -1, -1, 0);
1517 it
->continuation_lines_width
+= it
->current_x
;
1520 /* We're starting a new display line, not affected by the
1521 height of the continued line, so clear the appropriate
1522 fields in the iterator structure. */
1523 it
->max_ascent
= it
->max_descent
= 0;
1524 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1527 it
->current_y
= first_y
;
1529 it
->current_x
= it
->hpos
= 0;
1532 #if 0 /* Don't assert the following because start_display is sometimes
1533 called intentionally with a window start that is not at a
1534 line start. Please leave this code in as a comment. */
1536 /* Window start should be on a line start, now. */
1537 xassert (it
->continuation_lines_width
1538 || IT_CHARPOS (it
) == BEGV
1539 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1544 /* Initialize IT for stepping through current_buffer in window W,
1545 starting at position POS that includes overlay string and display
1546 vector/ control character translation position information. */
1549 init_from_display_pos (it
, w
, pos
)
1552 struct display_pos
*pos
;
1554 /* Keep in mind: the call to reseat in init_iterator skips invisible
1555 text, so we might end up at a position different from POS. This
1556 is only a problem when POS is a row start after a newline and an
1557 overlay starts there with an after-string, and the overlay has an
1558 invisible property. Since we don't skip invisible text in
1559 display_line and elsewhere immediately after consuming the
1560 newline before the row start, such a POS will not be in a string,
1561 but the call to init_iterator below will move us to the
1563 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1564 NULL
, DEFAULT_FACE_ID
);
1566 /* If position is within an overlay string, set up IT to
1567 the right overlay string. */
1568 if (pos
->overlay_string_index
>= 0)
1572 /* We already have the first chunk of overlay strings in
1573 IT->overlay_strings. Load more until the one for
1574 pos->overlay_string_index is in IT->overlay_strings. */
1575 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1577 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1578 it
->current
.overlay_string_index
= 0;
1581 load_overlay_strings (it
);
1582 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1586 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1587 relative_index
= (it
->current
.overlay_string_index
1588 % OVERLAY_STRING_CHUNK_SIZE
);
1589 it
->string
= it
->overlay_strings
[relative_index
];
1590 it
->current
.string_pos
= pos
->string_pos
;
1591 it
->method
= next_element_from_string
;
1593 else if (CHARPOS (pos
->string_pos
) >= 0)
1595 /* Recorded position is not in an overlay string, but in another
1596 string. This can only be a string from a `display' property.
1597 IT should already be filled with that string. */
1598 it
->current
.string_pos
= pos
->string_pos
;
1599 xassert (STRINGP (it
->string
));
1602 /* Restore position in display vector translations or control
1603 character translations. */
1604 if (pos
->dpvec_index
>= 0)
1606 /* This fills IT->dpvec. */
1607 get_next_display_element (it
);
1608 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1609 it
->current
.dpvec_index
= pos
->dpvec_index
;
1616 /* Initialize IT for stepping through current_buffer in window W
1617 starting at ROW->start. */
1620 init_to_row_start (it
, w
, row
)
1623 struct glyph_row
*row
;
1625 init_from_display_pos (it
, w
, &row
->start
);
1626 it
->continuation_lines_width
= row
->continuation_lines_width
;
1631 /* Initialize IT for stepping through current_buffer in window W
1632 starting in the line following ROW, i.e. starting at ROW->end. */
1635 init_to_row_end (it
, w
, row
)
1638 struct glyph_row
*row
;
1640 init_from_display_pos (it
, w
, &row
->end
);
1642 if (row
->continued_p
)
1643 it
->continuation_lines_width
= (row
->continuation_lines_width
1644 + row
->pixel_width
);
1651 /***********************************************************************
1653 ***********************************************************************/
1655 /* Called when IT reaches IT->stop_charpos. Handle text property and
1656 overlay changes. Set IT->stop_charpos to the next position where
1663 enum prop_handled handled
;
1664 int handle_overlay_change_p
= 1;
1668 it
->current
.dpvec_index
= -1;
1669 it
->add_overlay_start
= 0;
1673 handled
= HANDLED_NORMALLY
;
1675 /* Call text property handlers. */
1676 for (p
= it_props
; p
->handler
; ++p
)
1678 handled
= p
->handler (it
);
1680 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1682 else if (handled
== HANDLED_RETURN
)
1684 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1685 handle_overlay_change_p
= 0;
1688 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1690 /* Don't check for overlay strings below when set to deliver
1691 characters from a display vector. */
1692 if (it
->method
== next_element_from_display_vector
)
1693 handle_overlay_change_p
= 0;
1695 /* Handle overlay changes. */
1696 if (handle_overlay_change_p
)
1697 handled
= handle_overlay_change (it
);
1699 /* Determine where to stop next. */
1700 if (handled
== HANDLED_NORMALLY
)
1701 compute_stop_pos (it
);
1704 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1708 /* Compute IT->stop_charpos from text property and overlay change
1709 information for IT's current position. */
1712 compute_stop_pos (it
)
1715 register INTERVAL iv
, next_iv
;
1716 Lisp_Object object
, limit
, position
;
1718 /* If nowhere else, stop at the end. */
1719 it
->stop_charpos
= it
->end_charpos
;
1721 if (STRINGP (it
->string
))
1723 /* Strings are usually short, so don't limit the search for
1725 object
= it
->string
;
1727 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1733 /* If next overlay change is in front of the current stop pos
1734 (which is IT->end_charpos), stop there. Note: value of
1735 next_overlay_change is point-max if no overlay change
1737 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1738 if (charpos
< it
->stop_charpos
)
1739 it
->stop_charpos
= charpos
;
1741 /* If showing the region, we have to stop at the region
1742 start or end because the face might change there. */
1743 if (it
->region_beg_charpos
> 0)
1745 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1746 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1747 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1748 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1751 /* Set up variables for computing the stop position from text
1752 property changes. */
1753 XSETBUFFER (object
, current_buffer
);
1754 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1755 XSETFASTINT (position
, IT_CHARPOS (*it
));
1759 /* Get the interval containing IT's position. Value is a null
1760 interval if there isn't such an interval. */
1761 iv
= validate_interval_range (object
, &position
, &position
, 0);
1762 if (!NULL_INTERVAL_P (iv
))
1764 Lisp_Object values_here
[LAST_PROP_IDX
];
1767 /* Get properties here. */
1768 for (p
= it_props
; p
->handler
; ++p
)
1769 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1771 /* Look for an interval following iv that has different
1773 for (next_iv
= next_interval (iv
);
1774 (!NULL_INTERVAL_P (next_iv
)
1776 || XFASTINT (limit
) > next_iv
->position
));
1777 next_iv
= next_interval (next_iv
))
1779 for (p
= it_props
; p
->handler
; ++p
)
1781 Lisp_Object new_value
;
1783 new_value
= textget (next_iv
->plist
, *p
->name
);
1784 if (!EQ (values_here
[p
->idx
], new_value
))
1792 if (!NULL_INTERVAL_P (next_iv
))
1794 if (INTEGERP (limit
)
1795 && next_iv
->position
>= XFASTINT (limit
))
1796 /* No text property change up to limit. */
1797 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1799 /* Text properties change in next_iv. */
1800 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1804 xassert (STRINGP (it
->string
)
1805 || (it
->stop_charpos
>= BEGV
1806 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1810 /* Return the position of the next overlay change after POS in
1811 current_buffer. Value is point-max if no overlay change
1812 follows. This is like `next-overlay-change' but doesn't use
1816 next_overlay_change (pos
)
1821 Lisp_Object
*overlays
;
1825 /* Get all overlays at the given position. */
1827 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1828 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
1829 if (noverlays
> len
)
1832 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1833 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
1836 /* If any of these overlays ends before endpos,
1837 use its ending point instead. */
1838 for (i
= 0; i
< noverlays
; ++i
)
1843 oend
= OVERLAY_END (overlays
[i
]);
1844 oendpos
= OVERLAY_POSITION (oend
);
1845 endpos
= min (endpos
, oendpos
);
1853 /***********************************************************************
1855 ***********************************************************************/
1857 /* Handle changes in the `fontified' property of the current buffer by
1858 calling hook functions from Qfontification_functions to fontify
1861 static enum prop_handled
1862 handle_fontified_prop (it
)
1865 Lisp_Object prop
, pos
;
1866 enum prop_handled handled
= HANDLED_NORMALLY
;
1868 /* Get the value of the `fontified' property at IT's current buffer
1869 position. (The `fontified' property doesn't have a special
1870 meaning in strings.) If the value is nil, call functions from
1871 Qfontification_functions. */
1872 if (!STRINGP (it
->string
)
1874 && !NILP (Vfontification_functions
)
1875 && !NILP (Vrun_hooks
)
1876 && (pos
= make_number (IT_CHARPOS (*it
)),
1877 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1880 int count
= specpdl_ptr
- specpdl
;
1883 val
= Vfontification_functions
;
1884 specbind (Qfontification_functions
, Qnil
);
1885 specbind (Qafter_change_functions
, Qnil
);
1887 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
1891 Lisp_Object globals
, fn
;
1892 struct gcpro gcpro1
, gcpro2
;
1895 GCPRO2 (val
, globals
);
1897 for (; CONSP (val
); val
= XCDR (val
))
1903 /* A value of t indicates this hook has a local
1904 binding; it means to run the global binding too.
1905 In a global value, t should not occur. If it
1906 does, we must ignore it to avoid an endless
1908 for (globals
= Fdefault_value (Qfontification_functions
);
1910 globals
= XCDR (globals
))
1912 fn
= XCAR (globals
);
1924 unbind_to (count
, Qnil
);
1926 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
1927 something. This avoids an endless loop if they failed to
1928 fontify the text for which reason ever. */
1929 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
1930 handled
= HANDLED_RECOMPUTE_PROPS
;
1938 /***********************************************************************
1940 ***********************************************************************/
1942 /* Set up iterator IT from face properties at its current position.
1943 Called from handle_stop. */
1945 static enum prop_handled
1946 handle_face_prop (it
)
1949 int new_face_id
, next_stop
;
1951 if (!STRINGP (it
->string
))
1954 = face_at_buffer_position (it
->w
,
1956 it
->region_beg_charpos
,
1957 it
->region_end_charpos
,
1960 + TEXT_PROP_DISTANCE_LIMIT
),
1963 /* Is this a start of a run of characters with box face?
1964 Caveat: this can be called for a freshly initialized
1965 iterator; face_id is -1 is this case. We know that the new
1966 face will not change until limit, i.e. if the new face has a
1967 box, all characters up to limit will have one. But, as
1968 usual, we don't know whether limit is really the end. */
1969 if (new_face_id
!= it
->face_id
)
1971 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1973 /* If new face has a box but old face has not, this is
1974 the start of a run of characters with box, i.e. it has
1975 a shadow on the left side. The value of face_id of the
1976 iterator will be -1 if this is the initial call that gets
1977 the face. In this case, we have to look in front of IT's
1978 position and see whether there is a face != new_face_id. */
1979 it
->start_of_box_run_p
1980 = (new_face
->box
!= FACE_NO_BOX
1981 && (it
->face_id
>= 0
1982 || IT_CHARPOS (*it
) == BEG
1983 || new_face_id
!= face_before_it_pos (it
)));
1984 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1990 = face_at_string_position (it
->w
,
1992 IT_STRING_CHARPOS (*it
),
1993 (it
->current
.overlay_string_index
>= 0
1996 it
->region_beg_charpos
,
1997 it
->region_end_charpos
,
2001 #if 0 /* This shouldn't be neccessary. Let's check it. */
2002 /* If IT is used to display a mode line we would really like to
2003 use the mode line face instead of the frame's default face. */
2004 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2005 && new_face_id
== DEFAULT_FACE_ID
)
2006 new_face_id
= MODE_LINE_FACE_ID
;
2009 /* Is this a start of a run of characters with box? Caveat:
2010 this can be called for a freshly allocated iterator; face_id
2011 is -1 is this case. We know that the new face will not
2012 change until the next check pos, i.e. if the new face has a
2013 box, all characters up to that position will have a
2014 box. But, as usual, we don't know whether that position
2015 is really the end. */
2016 if (new_face_id
!= it
->face_id
)
2018 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2019 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2021 /* If new face has a box but old face hasn't, this is the
2022 start of a run of characters with box, i.e. it has a
2023 shadow on the left side. */
2024 it
->start_of_box_run_p
2025 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2026 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2030 it
->face_id
= new_face_id
;
2031 return HANDLED_NORMALLY
;
2035 /* Compute the face one character before or after the current position
2036 of IT. BEFORE_P non-zero means get the face in front of IT's
2037 position. Value is the id of the face. */
2040 face_before_or_after_it_pos (it
, before_p
)
2045 int next_check_charpos
;
2046 struct text_pos pos
;
2048 xassert (it
->s
== NULL
);
2050 if (STRINGP (it
->string
))
2052 /* No face change past the end of the string (for the case
2053 we are padding with spaces). No face change before the
2055 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2056 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2059 /* Set pos to the position before or after IT's current position. */
2061 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2063 /* For composition, we must check the character after the
2065 pos
= (it
->what
== IT_COMPOSITION
2066 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2067 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2069 /* Get the face for ASCII, or unibyte. */
2071 = face_at_string_position (it
->w
,
2074 (it
->current
.overlay_string_index
>= 0
2077 it
->region_beg_charpos
,
2078 it
->region_end_charpos
,
2079 &next_check_charpos
,
2082 /* Correct the face for charsets different from ASCII. Do it
2083 for the multibyte case only. The face returned above is
2084 suitable for unibyte text if IT->string is unibyte. */
2085 if (STRING_MULTIBYTE (it
->string
))
2087 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2088 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2090 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2092 c
= string_char_and_length (p
, rest
, &len
);
2093 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2098 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2099 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2102 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2103 pos
= it
->current
.pos
;
2106 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2109 if (it
->what
== IT_COMPOSITION
)
2110 /* For composition, we must check the position after the
2112 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2114 INC_TEXT_POS (pos
, it
->multibyte_p
);
2116 /* Determine face for CHARSET_ASCII, or unibyte. */
2117 face_id
= face_at_buffer_position (it
->w
,
2119 it
->region_beg_charpos
,
2120 it
->region_end_charpos
,
2121 &next_check_charpos
,
2124 /* Correct the face for charsets different from ASCII. Do it
2125 for the multibyte case only. The face returned above is
2126 suitable for unibyte text if current_buffer is unibyte. */
2127 if (it
->multibyte_p
)
2129 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2130 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2131 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2140 /***********************************************************************
2142 ***********************************************************************/
2144 /* Set up iterator IT from invisible properties at its current
2145 position. Called from handle_stop. */
2147 static enum prop_handled
2148 handle_invisible_prop (it
)
2151 enum prop_handled handled
= HANDLED_NORMALLY
;
2153 if (STRINGP (it
->string
))
2155 extern Lisp_Object Qinvisible
;
2156 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2158 /* Get the value of the invisible text property at the
2159 current position. Value will be nil if there is no such
2161 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2162 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2165 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2167 handled
= HANDLED_RECOMPUTE_PROPS
;
2169 /* Get the position at which the next change of the
2170 invisible text property can be found in IT->string.
2171 Value will be nil if the property value is the same for
2172 all the rest of IT->string. */
2173 XSETINT (limit
, XSTRING (it
->string
)->size
);
2174 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2177 /* Text at current position is invisible. The next
2178 change in the property is at position end_charpos.
2179 Move IT's current position to that position. */
2180 if (INTEGERP (end_charpos
)
2181 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2183 struct text_pos old
;
2184 old
= it
->current
.string_pos
;
2185 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2186 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2190 /* The rest of the string is invisible. If this is an
2191 overlay string, proceed with the next overlay string
2192 or whatever comes and return a character from there. */
2193 if (it
->current
.overlay_string_index
>= 0)
2195 next_overlay_string (it
);
2196 /* Don't check for overlay strings when we just
2197 finished processing them. */
2198 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2202 struct Lisp_String
*s
= XSTRING (it
->string
);
2203 IT_STRING_CHARPOS (*it
) = s
->size
;
2204 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2211 int visible_p
, newpos
, next_stop
;
2212 Lisp_Object pos
, prop
;
2214 /* First of all, is there invisible text at this position? */
2215 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2216 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2218 /* If we are on invisible text, skip over it. */
2219 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2220 && IT_CHARPOS (*it
) < it
->end_charpos
)
2222 /* Record whether we have to display an ellipsis for the
2224 int display_ellipsis_p
2225 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2227 handled
= HANDLED_RECOMPUTE_PROPS
;
2228 it
->add_overlay_start
= IT_CHARPOS (*it
);
2230 /* Loop skipping over invisible text. The loop is left at
2231 ZV or with IT on the first char being visible again. */
2234 /* Try to skip some invisible text. Return value is the
2235 position reached which can be equal to IT's position
2236 if there is nothing invisible here. This skips both
2237 over invisible text properties and overlays with
2238 invisible property. */
2239 newpos
= skip_invisible (IT_CHARPOS (*it
),
2240 &next_stop
, ZV
, it
->window
);
2242 /* If we skipped nothing at all we weren't at invisible
2243 text in the first place. If everything to the end of
2244 the buffer was skipped, end the loop. */
2245 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2249 /* We skipped some characters but not necessarily
2250 all there are. Check if we ended up on visible
2251 text. Fget_char_property returns the property of
2252 the char before the given position, i.e. if we
2253 get visible_p = 1, this means that the char at
2254 newpos is visible. */
2255 XSETFASTINT (pos
, newpos
);
2256 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2257 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2260 /* If we ended up on invisible text, proceed to
2261 skip starting with next_stop. */
2263 IT_CHARPOS (*it
) = next_stop
;
2267 /* The position newpos is now either ZV or on visible text. */
2268 IT_CHARPOS (*it
) = newpos
;
2269 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2271 /* Maybe return `...' next for the end of the invisible text. */
2272 if (display_ellipsis_p
)
2275 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2277 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2278 it
->dpvec
= v
->contents
;
2279 it
->dpend
= v
->contents
+ v
->size
;
2283 /* Default `...'. */
2284 it
->dpvec
= default_invis_vector
;
2285 it
->dpend
= default_invis_vector
+ 3;
2288 /* The ellipsis display does not replace the display of
2289 the character at the new position. Indicate this by
2290 setting IT->dpvec_char_len to zero. */
2291 it
->dpvec_char_len
= 0;
2293 it
->current
.dpvec_index
= 0;
2294 it
->method
= next_element_from_display_vector
;
2304 /***********************************************************************
2306 ***********************************************************************/
2308 /* Set up iterator IT from `display' property at its current position.
2309 Called from handle_stop. */
2311 static enum prop_handled
2312 handle_display_prop (it
)
2315 Lisp_Object prop
, object
;
2316 struct text_pos
*position
;
2317 int space_or_image_found_p
;
2319 if (STRINGP (it
->string
))
2321 object
= it
->string
;
2322 position
= &it
->current
.string_pos
;
2327 position
= &it
->current
.pos
;
2330 /* Reset those iterator values set from display property values. */
2331 it
->font_height
= Qnil
;
2332 it
->space_width
= Qnil
;
2335 /* We don't support recursive `display' properties, i.e. string
2336 values that have a string `display' property, that have a string
2337 `display' property etc. */
2338 if (!it
->string_from_display_prop_p
)
2339 it
->area
= TEXT_AREA
;
2341 prop
= Fget_char_property (make_number (position
->charpos
),
2344 return HANDLED_NORMALLY
;
2346 space_or_image_found_p
= 0;
2348 && CONSP (XCAR (prop
))
2349 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2351 /* A list of sub-properties. */
2352 while (CONSP (prop
))
2354 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2355 space_or_image_found_p
= 1;
2359 else if (VECTORP (prop
))
2362 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2363 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2365 space_or_image_found_p
= 1;
2369 if (handle_single_display_prop (it
, prop
, object
, position
))
2370 space_or_image_found_p
= 1;
2373 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2377 /* Value is the position of the end of the `display' property starting
2378 at START_POS in OBJECT. */
2380 static struct text_pos
2381 display_prop_end (it
, object
, start_pos
)
2384 struct text_pos start_pos
;
2387 struct text_pos end_pos
;
2389 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2390 Qdisplay
, object
, Qnil
);
2391 CHARPOS (end_pos
) = XFASTINT (end
);
2392 if (STRINGP (object
))
2393 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2395 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2401 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2402 is the object in which the `display' property was found. *POSITION
2403 is the position at which it was found.
2405 If PROP is a `space' or `image' sub-property, set *POSITION to the
2406 end position of the `display' property.
2408 Value is non-zero if a `space' or `image' property value was found. */
2411 handle_single_display_prop (it
, prop
, object
, position
)
2415 struct text_pos
*position
;
2418 int space_or_image_found_p
= 0;
2421 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2422 evaluated. If the result is nil, VALUE is ignored. */
2424 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2433 if (!NILP (form
) && !EQ (form
, Qt
))
2435 struct gcpro gcpro1
;
2436 struct text_pos end_pos
, pt
;
2439 end_pos
= display_prop_end (it
, object
, *position
);
2441 /* Temporarily set point to the end position, and then evaluate
2442 the form. This makes `(eolp)' work as FORM. */
2443 if (BUFFERP (object
))
2446 BYTEPOS (pt
) = PT_BYTE
;
2447 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2450 form
= eval_form (form
);
2452 if (BUFFERP (object
))
2453 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2461 && EQ (XCAR (prop
), Qheight
)
2462 && CONSP (XCDR (prop
)))
2464 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2467 /* `(height HEIGHT)'. */
2468 it
->font_height
= XCAR (XCDR (prop
));
2469 if (!NILP (it
->font_height
))
2471 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2472 int new_height
= -1;
2474 if (CONSP (it
->font_height
)
2475 && (EQ (XCAR (it
->font_height
), Qplus
)
2476 || EQ (XCAR (it
->font_height
), Qminus
))
2477 && CONSP (XCDR (it
->font_height
))
2478 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2480 /* `(+ N)' or `(- N)' where N is an integer. */
2481 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2482 if (EQ (XCAR (it
->font_height
), Qplus
))
2484 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2486 else if (FUNCTIONP (it
->font_height
))
2488 /* Call function with current height as argument.
2489 Value is the new height. */
2490 Lisp_Object args
[2], height
;
2492 args
[0] = it
->font_height
;
2493 args
[1] = face
->lface
[LFACE_HEIGHT_INDEX
];
2494 height
= call_function (2, args
);
2496 if (NUMBERP (height
))
2497 new_height
= XFLOATINT (height
);
2499 else if (NUMBERP (it
->font_height
))
2501 /* Value is a multiple of the canonical char height. */
2504 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2505 new_height
= (XFLOATINT (it
->font_height
)
2506 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2510 /* Evaluate IT->font_height with `height' bound to the
2511 current specified height to get the new height. */
2513 int count
= specpdl_ptr
- specpdl
;
2515 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2516 value
= eval_form (it
->font_height
);
2517 unbind_to (count
, Qnil
);
2519 if (NUMBERP (value
))
2520 new_height
= XFLOATINT (value
);
2524 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2527 else if (CONSP (prop
)
2528 && EQ (XCAR (prop
), Qspace_width
)
2529 && CONSP (XCDR (prop
)))
2531 /* `(space_width WIDTH)'. */
2532 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2535 value
= XCAR (XCDR (prop
));
2536 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2537 it
->space_width
= value
;
2539 else if (CONSP (prop
)
2540 && EQ (XCAR (prop
), Qraise
)
2541 && CONSP (XCDR (prop
)))
2543 /* `(raise FACTOR)'. */
2544 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2547 #ifdef HAVE_WINDOW_SYSTEM
2548 value
= XCAR (XCDR (prop
));
2549 if (NUMBERP (value
))
2551 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2552 it
->voffset
= - (XFLOATINT (value
)
2553 * (FONT_HEIGHT (face
->font
)));
2555 #endif /* HAVE_WINDOW_SYSTEM */
2557 else if (!it
->string_from_display_prop_p
)
2559 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2560 VALUE) or `((margin nil) VALUE)' or VALUE. */
2561 Lisp_Object location
, value
;
2562 struct text_pos start_pos
;
2565 /* Characters having this form of property are not displayed, so
2566 we have to find the end of the property. */
2567 start_pos
= *position
;
2568 *position
= display_prop_end (it
, object
, start_pos
);
2571 /* Let's stop at the new position and assume that all
2572 text properties change there. */
2573 it
->stop_charpos
= position
->charpos
;
2575 location
= Qunbound
;
2576 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2580 value
= XCDR (prop
);
2582 value
= XCAR (value
);
2585 if (EQ (XCAR (tem
), Qmargin
)
2586 && (tem
= XCDR (tem
),
2587 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2589 || EQ (tem
, Qleft_margin
)
2590 || EQ (tem
, Qright_margin
))))
2594 if (EQ (location
, Qunbound
))
2600 #ifdef HAVE_WINDOW_SYSTEM
2601 if (FRAME_TERMCAP_P (it
->f
))
2602 valid_p
= STRINGP (value
);
2604 valid_p
= (STRINGP (value
)
2605 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2606 || valid_image_p (value
));
2607 #else /* not HAVE_WINDOW_SYSTEM */
2608 valid_p
= STRINGP (value
);
2609 #endif /* not HAVE_WINDOW_SYSTEM */
2611 if ((EQ (location
, Qleft_margin
)
2612 || EQ (location
, Qright_margin
)
2616 space_or_image_found_p
= 1;
2618 /* Save current settings of IT so that we can restore them
2619 when we are finished with the glyph property value. */
2622 if (NILP (location
))
2623 it
->area
= TEXT_AREA
;
2624 else if (EQ (location
, Qleft_margin
))
2625 it
->area
= LEFT_MARGIN_AREA
;
2627 it
->area
= RIGHT_MARGIN_AREA
;
2629 if (STRINGP (value
))
2632 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2633 it
->current
.overlay_string_index
= -1;
2634 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2635 it
->end_charpos
= it
->string_nchars
2636 = XSTRING (it
->string
)->size
;
2637 it
->method
= next_element_from_string
;
2638 it
->stop_charpos
= 0;
2639 it
->string_from_display_prop_p
= 1;
2641 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2643 it
->method
= next_element_from_stretch
;
2645 it
->current
.pos
= it
->position
= start_pos
;
2647 #ifdef HAVE_WINDOW_SYSTEM
2650 it
->what
= IT_IMAGE
;
2651 it
->image_id
= lookup_image (it
->f
, value
);
2652 it
->position
= start_pos
;
2653 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2654 it
->method
= next_element_from_image
;
2656 /* Say that we haven't consumed the characters with
2657 `display' property yet. The call to pop_it in
2658 set_iterator_to_next will clean this up. */
2659 *position
= start_pos
;
2661 #endif /* HAVE_WINDOW_SYSTEM */
2664 /* Invalid property or property not supported. Restore
2665 the position to what it was before. */
2666 *position
= start_pos
;
2669 return space_or_image_found_p
;
2673 /* Check if PROP is a display sub-property value whose text should be
2674 treated as intangible. */
2677 single_display_prop_intangible_p (prop
)
2680 /* Skip over `when FORM'. */
2681 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2692 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
2693 we don't need to treat text as intangible. */
2694 if (EQ (XCAR (prop
), Qmargin
))
2702 || EQ (XCAR (prop
), Qleft_margin
)
2703 || EQ (XCAR (prop
), Qright_margin
))
2707 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
2711 /* Check if PROP is a display property value whose text should be
2712 treated as intangible. */
2715 display_prop_intangible_p (prop
)
2719 && CONSP (XCAR (prop
))
2720 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2722 /* A list of sub-properties. */
2723 while (CONSP (prop
))
2725 if (single_display_prop_intangible_p (XCAR (prop
)))
2730 else if (VECTORP (prop
))
2732 /* A vector of sub-properties. */
2734 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2735 if (single_display_prop_intangible_p (XVECTOR (prop
)->contents
[i
]))
2739 return single_display_prop_intangible_p (prop
);
2745 /***********************************************************************
2746 `composition' property
2747 ***********************************************************************/
2749 /* Set up iterator IT from `composition' property at its current
2750 position. Called from handle_stop. */
2752 static enum prop_handled
2753 handle_composition_prop (it
)
2756 Lisp_Object prop
, string
;
2757 int pos
, pos_byte
, end
;
2758 enum prop_handled handled
= HANDLED_NORMALLY
;
2760 if (STRINGP (it
->string
))
2762 pos
= IT_STRING_CHARPOS (*it
);
2763 pos_byte
= IT_STRING_BYTEPOS (*it
);
2764 string
= it
->string
;
2768 pos
= IT_CHARPOS (*it
);
2769 pos_byte
= IT_BYTEPOS (*it
);
2773 /* If there's a valid composition and point is not inside of the
2774 composition (in the case that the composition is from the current
2775 buffer), draw a glyph composed from the composition components. */
2776 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
2777 && COMPOSITION_VALID_P (pos
, end
, prop
)
2778 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
2780 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
2784 it
->method
= next_element_from_composition
;
2786 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
2787 /* For a terminal, draw only the first character of the
2789 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
2790 it
->len
= (STRINGP (it
->string
)
2791 ? string_char_to_byte (it
->string
, end
)
2792 : CHAR_TO_BYTE (end
)) - pos_byte
;
2793 it
->stop_charpos
= end
;
2794 handled
= HANDLED_RETURN
;
2803 /***********************************************************************
2805 ***********************************************************************/
2807 /* The following structure is used to record overlay strings for
2808 later sorting in load_overlay_strings. */
2810 struct overlay_entry
2812 Lisp_Object overlay
;
2819 /* Set up iterator IT from overlay strings at its current position.
2820 Called from handle_stop. */
2822 static enum prop_handled
2823 handle_overlay_change (it
)
2826 if (!STRINGP (it
->string
) && get_overlay_strings (it
))
2827 return HANDLED_RECOMPUTE_PROPS
;
2829 return HANDLED_NORMALLY
;
2833 /* Set up the next overlay string for delivery by IT, if there is an
2834 overlay string to deliver. Called by set_iterator_to_next when the
2835 end of the current overlay string is reached. If there are more
2836 overlay strings to display, IT->string and
2837 IT->current.overlay_string_index are set appropriately here.
2838 Otherwise IT->string is set to nil. */
2841 next_overlay_string (it
)
2844 ++it
->current
.overlay_string_index
;
2845 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2847 /* No more overlay strings. Restore IT's settings to what
2848 they were before overlay strings were processed, and
2849 continue to deliver from current_buffer. */
2851 xassert (it
->stop_charpos
>= BEGV
2852 && it
->stop_charpos
<= it
->end_charpos
);
2854 it
->current
.overlay_string_index
= -1;
2855 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2856 it
->n_overlay_strings
= 0;
2857 it
->method
= next_element_from_buffer
;
2859 /* If we're at the end of the buffer, record that we have
2860 processed the overlay strings there already, so that
2861 next_element_from_buffer doesn't try it again. */
2862 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
2863 it
->overlay_strings_at_end_processed_p
= 1;
2867 /* There are more overlay strings to process. If
2868 IT->current.overlay_string_index has advanced to a position
2869 where we must load IT->overlay_strings with more strings, do
2871 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2873 if (it
->current
.overlay_string_index
&& i
== 0)
2874 load_overlay_strings (it
);
2876 /* Initialize IT to deliver display elements from the overlay
2878 it
->string
= it
->overlay_strings
[i
];
2879 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2880 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2881 it
->method
= next_element_from_string
;
2882 it
->stop_charpos
= 0;
2889 /* Compare two overlay_entry structures E1 and E2. Used as a
2890 comparison function for qsort in load_overlay_strings. Overlay
2891 strings for the same position are sorted so that
2893 1. All after-strings come in front of before-strings, except
2894 when they come from the same overlay.
2896 2. Within after-strings, strings are sorted so that overlay strings
2897 from overlays with higher priorities come first.
2899 2. Within before-strings, strings are sorted so that overlay
2900 strings from overlays with higher priorities come last.
2902 Value is analogous to strcmp. */
2906 compare_overlay_entries (e1
, e2
)
2909 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
2910 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
2913 if (entry1
->after_string_p
!= entry2
->after_string_p
)
2915 /* Let after-strings appear in front of before-strings if
2916 they come from different overlays. */
2917 if (EQ (entry1
->overlay
, entry2
->overlay
))
2918 result
= entry1
->after_string_p
? 1 : -1;
2920 result
= entry1
->after_string_p
? -1 : 1;
2922 else if (entry1
->after_string_p
)
2923 /* After-strings sorted in order of decreasing priority. */
2924 result
= entry2
->priority
- entry1
->priority
;
2926 /* Before-strings sorted in order of increasing priority. */
2927 result
= entry1
->priority
- entry2
->priority
;
2933 /* Load the vector IT->overlay_strings with overlay strings from IT's
2934 current buffer position. Set IT->n_overlays to the total number of
2935 overlay strings found.
2937 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
2938 a time. On entry into load_overlay_strings,
2939 IT->current.overlay_string_index gives the number of overlay
2940 strings that have already been loaded by previous calls to this
2943 IT->add_overlay_start contains an additional overlay start
2944 position to consider for taking overlay strings from, if non-zero.
2945 This position comes into play when the overlay has an `invisible'
2946 property, and both before and after-strings. When we've skipped to
2947 the end of the overlay, because of its `invisible' property, we
2948 nevertheless want its before-string to appear.
2949 IT->add_overlay_start will contain the overlay start position
2952 Overlay strings are sorted so that after-string strings come in
2953 front of before-string strings. Within before and after-strings,
2954 strings are sorted by overlay priority. See also function
2955 compare_overlay_entries. */
2958 load_overlay_strings (it
)
2961 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
2962 Lisp_Object ov
, overlay
, window
, str
;
2966 struct overlay_entry
*entries
2967 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
2969 /* Append the overlay string STRING of overlay OVERLAY to vector
2970 `entries' which has size `size' and currently contains `n'
2971 elements. AFTER_P non-zero means STRING is an after-string of
2973 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
2976 Lisp_Object priority; \
2980 int new_size = 2 * size; \
2981 struct overlay_entry *old = entries; \
2983 (struct overlay_entry *) alloca (new_size \
2984 * sizeof *entries); \
2985 bcopy (old, entries, size * sizeof *entries); \
2989 entries[n].string = (STRING); \
2990 entries[n].overlay = (OVERLAY); \
2991 priority = Foverlay_get ((OVERLAY), Qpriority); \
2992 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
2993 entries[n].after_string_p = (AFTER_P); \
2998 /* Process overlay before the overlay center. */
2999 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3001 overlay
= XCAR (ov
);
3002 xassert (OVERLAYP (overlay
));
3003 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3004 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3006 if (end
< IT_CHARPOS (*it
))
3009 /* Skip this overlay if it doesn't start or end at IT's current
3011 if (end
!= IT_CHARPOS (*it
)
3012 && start
!= IT_CHARPOS (*it
)
3013 && it
->add_overlay_start
!= IT_CHARPOS (*it
))
3016 /* Skip this overlay if it doesn't apply to IT->w. */
3017 window
= Foverlay_get (overlay
, Qwindow
);
3018 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3021 /* If overlay has a non-empty before-string, record it. */
3022 if ((start
== IT_CHARPOS (*it
)
3023 || start
== it
->add_overlay_start
)
3024 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3025 && XSTRING (str
)->size
)
3026 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3028 /* If overlay has a non-empty after-string, record it. */
3029 if (end
== IT_CHARPOS (*it
)
3030 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3031 && XSTRING (str
)->size
)
3032 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3035 /* Process overlays after the overlay center. */
3036 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3038 overlay
= XCAR (ov
);
3039 xassert (OVERLAYP (overlay
));
3040 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3041 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3043 if (start
> IT_CHARPOS (*it
))
3046 /* Skip this overlay if it doesn't start or end at IT's current
3048 if (end
!= IT_CHARPOS (*it
)
3049 && start
!= IT_CHARPOS (*it
)
3050 && it
->add_overlay_start
!= IT_CHARPOS (*it
))
3053 /* Skip this overlay if it doesn't apply to IT->w. */
3054 window
= Foverlay_get (overlay
, Qwindow
);
3055 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3058 /* If overlay has a non-empty before-string, record it. */
3059 if ((start
== IT_CHARPOS (*it
)
3060 || start
== it
->add_overlay_start
)
3061 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3062 && XSTRING (str
)->size
)
3063 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3065 /* If overlay has a non-empty after-string, record it. */
3066 if (end
== IT_CHARPOS (*it
)
3067 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3068 && XSTRING (str
)->size
)
3069 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3072 #undef RECORD_OVERLAY_STRING
3076 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3078 /* Record the total number of strings to process. */
3079 it
->n_overlay_strings
= n
;
3081 /* IT->current.overlay_string_index is the number of overlay strings
3082 that have already been consumed by IT. Copy some of the
3083 remaining overlay strings to IT->overlay_strings. */
3085 j
= it
->current
.overlay_string_index
;
3086 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3087 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3093 /* Get the first chunk of overlay strings at IT's current buffer
3094 position. Value is non-zero if at least one overlay string was
3098 get_overlay_strings (it
)
3101 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3102 process. This fills IT->overlay_strings with strings, and sets
3103 IT->n_overlay_strings to the total number of strings to process.
3104 IT->pos.overlay_string_index has to be set temporarily to zero
3105 because load_overlay_strings needs this; it must be set to -1
3106 when no overlay strings are found because a zero value would
3107 indicate a position in the first overlay string. */
3108 it
->current
.overlay_string_index
= 0;
3109 load_overlay_strings (it
);
3111 /* If we found overlay strings, set up IT to deliver display
3112 elements from the first one. Otherwise set up IT to deliver
3113 from current_buffer. */
3114 if (it
->n_overlay_strings
)
3116 /* Make sure we know settings in current_buffer, so that we can
3117 restore meaningful values when we're done with the overlay
3119 compute_stop_pos (it
);
3120 xassert (it
->face_id
>= 0);
3122 /* Save IT's settings. They are restored after all overlay
3123 strings have been processed. */
3124 xassert (it
->sp
== 0);
3127 /* Set up IT to deliver display elements from the first overlay
3129 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3130 it
->stop_charpos
= 0;
3131 it
->string
= it
->overlay_strings
[0];
3132 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3133 xassert (STRINGP (it
->string
));
3134 it
->method
= next_element_from_string
;
3139 it
->current
.overlay_string_index
= -1;
3140 it
->method
= next_element_from_buffer
;
3145 /* Value is non-zero if we found at least one overlay string. */
3146 return STRINGP (it
->string
);
3151 /***********************************************************************
3152 Saving and restoring state
3153 ***********************************************************************/
3155 /* Save current settings of IT on IT->stack. Called, for example,
3156 before setting up IT for an overlay string, to be able to restore
3157 IT's settings to what they were after the overlay string has been
3164 struct iterator_stack_entry
*p
;
3166 xassert (it
->sp
< 2);
3167 p
= it
->stack
+ it
->sp
;
3169 p
->stop_charpos
= it
->stop_charpos
;
3170 xassert (it
->face_id
>= 0);
3171 p
->face_id
= it
->face_id
;
3172 p
->string
= it
->string
;
3173 p
->pos
= it
->current
;
3174 p
->end_charpos
= it
->end_charpos
;
3175 p
->string_nchars
= it
->string_nchars
;
3177 p
->multibyte_p
= it
->multibyte_p
;
3178 p
->space_width
= it
->space_width
;
3179 p
->font_height
= it
->font_height
;
3180 p
->voffset
= it
->voffset
;
3181 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3186 /* Restore IT's settings from IT->stack. Called, for example, when no
3187 more overlay strings must be processed, and we return to delivering
3188 display elements from a buffer, or when the end of a string from a
3189 `display' property is reached and we return to delivering display
3190 elements from an overlay string, or from a buffer. */
3196 struct iterator_stack_entry
*p
;
3198 xassert (it
->sp
> 0);
3200 p
= it
->stack
+ it
->sp
;
3201 it
->stop_charpos
= p
->stop_charpos
;
3202 it
->face_id
= p
->face_id
;
3203 it
->string
= p
->string
;
3204 it
->current
= p
->pos
;
3205 it
->end_charpos
= p
->end_charpos
;
3206 it
->string_nchars
= p
->string_nchars
;
3208 it
->multibyte_p
= p
->multibyte_p
;
3209 it
->space_width
= p
->space_width
;
3210 it
->font_height
= p
->font_height
;
3211 it
->voffset
= p
->voffset
;
3212 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3217 /***********************************************************************
3219 ***********************************************************************/
3221 /* Set IT's current position to the previous line start. */
3224 back_to_previous_line_start (it
)
3227 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3228 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3232 /* Set IT's current position to the next line start. */
3235 forward_to_next_line_start (it
)
3238 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), 1);
3239 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3243 /* Set IT's current position to the previous visible line start. Skip
3244 invisible text that is so either due to text properties or due to
3245 selective display. Caution: this does not change IT->current_x and
3249 back_to_previous_visible_line_start (it
)
3254 /* Go back one newline if not on BEGV already. */
3255 if (IT_CHARPOS (*it
) > BEGV
)
3256 back_to_previous_line_start (it
);
3258 /* Move over lines that are invisible because of selective display
3259 or text properties. */
3260 while (IT_CHARPOS (*it
) > BEGV
3265 /* If selective > 0, then lines indented more than that values
3267 if (it
->selective
> 0
3268 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3275 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3276 Qinvisible
, it
->window
);
3277 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3281 /* Back one more newline if the current one is invisible. */
3283 back_to_previous_line_start (it
);
3286 xassert (IT_CHARPOS (*it
) >= BEGV
);
3287 xassert (IT_CHARPOS (*it
) == BEGV
3288 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3293 /* Reseat iterator IT at the previous visible line start. Skip
3294 invisible text that is so either due to text properties or due to
3295 selective display. At the end, update IT's overlay information,
3296 face information etc. */
3299 reseat_at_previous_visible_line_start (it
)
3302 back_to_previous_visible_line_start (it
);
3303 reseat (it
, it
->current
.pos
, 1);
3308 /* Reseat iterator IT on the next visible line start in the current
3309 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3310 preceding the line start. Skip over invisible text that is so
3311 because of selective display. Compute faces, overlays etc at the
3312 new position. Note that this function does not skip over text that
3313 is invisible because of text properties. */
3316 reseat_at_next_visible_line_start (it
, on_newline_p
)
3320 /* Restore the buffer position when currently not delivering display
3321 elements from the current buffer. This is the case, for example,
3322 when called at the end of a truncated overlay string. */
3325 it
->method
= next_element_from_buffer
;
3327 /* Otherwise, scan_buffer would not work. */
3328 if (IT_CHARPOS (*it
) < ZV
)
3330 /* If on a newline, advance past it. Otherwise, find the next
3331 newline which automatically gives us the position following
3333 if (FETCH_BYTE (IT_BYTEPOS (*it
)) == '\n')
3339 forward_to_next_line_start (it
);
3341 /* We must either have reached the end of the buffer or end up
3343 xassert (IT_CHARPOS (*it
) == ZV
3344 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3346 /* Skip over lines that are invisible because they are indented
3347 more than the value of IT->selective. */
3348 if (it
->selective
> 0)
3349 while (IT_CHARPOS (*it
) < ZV
3350 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3352 forward_to_next_line_start (it
);
3354 /* Position on the newline if we should. */
3356 && IT_CHARPOS (*it
) > BEGV
3357 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n')
3360 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3363 /* Set the iterator there. The 0 as the last parameter of
3364 reseat means don't force a text property lookup. The lookup
3365 is then only done if we've skipped past the iterator's
3366 check_charpos'es. This optimization is important because
3367 text property lookups tend to be expensive. */
3368 reseat (it
, it
->current
.pos
, 0);
3376 /***********************************************************************
3377 Changing an iterator's position
3378 ***********************************************************************/
3380 /* Change IT's current position to POS in current_buffer. If FORCE_P
3381 is non-zero, always check for text properties at the new position.
3382 Otherwise, text properties are only looked up if POS >=
3383 IT->check_charpos of a property. */
3386 reseat (it
, pos
, force_p
)
3388 struct text_pos pos
;
3391 int original_pos
= IT_CHARPOS (*it
);
3393 reseat_1 (it
, pos
, 0);
3395 /* Determine where to check text properties. Avoid doing it
3396 where possible because text property lookup is very expensive. */
3398 || CHARPOS (pos
) > it
->stop_charpos
3399 || CHARPOS (pos
) < original_pos
)
3406 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3407 IT->stop_pos to POS, also. */
3410 reseat_1 (it
, pos
, set_stop_p
)
3412 struct text_pos pos
;
3415 /* Don't call this function when scanning a C string. */
3416 xassert (it
->s
== NULL
);
3418 /* POS must be a reasonable value. */
3419 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3421 it
->current
.pos
= it
->position
= pos
;
3422 XSETBUFFER (it
->object
, current_buffer
);
3424 it
->current
.dpvec_index
= -1;
3425 it
->current
.overlay_string_index
= -1;
3426 IT_STRING_CHARPOS (*it
) = -1;
3427 IT_STRING_BYTEPOS (*it
) = -1;
3429 it
->method
= next_element_from_buffer
;
3433 it
->stop_charpos
= CHARPOS (pos
);
3437 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3438 If S is non-null, it is a C string to iterate over. Otherwise,
3439 STRING gives a Lisp string to iterate over.
3441 If PRECISION > 0, don't return more then PRECISION number of
3442 characters from the string.
3444 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3445 characters have been returned. FIELD_WIDTH < 0 means an infinite
3448 MULTIBYTE = 0 means disable processing of multibyte characters,
3449 MULTIBYTE > 0 means enable it,
3450 MULTIBYTE < 0 means use IT->multibyte_p.
3452 IT must be initialized via a prior call to init_iterator before
3453 calling this function. */
3456 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3461 int precision
, field_width
, multibyte
;
3463 /* No region in strings. */
3464 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3466 /* No text property checks performed by default, but see below. */
3467 it
->stop_charpos
= -1;
3469 /* Set iterator position and end position. */
3470 bzero (&it
->current
, sizeof it
->current
);
3471 it
->current
.overlay_string_index
= -1;
3472 it
->current
.dpvec_index
= -1;
3473 xassert (charpos
>= 0);
3475 /* Use the setting of MULTIBYTE if specified. */
3477 it
->multibyte_p
= multibyte
> 0;
3481 xassert (STRINGP (string
));
3482 it
->string
= string
;
3484 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3485 it
->method
= next_element_from_string
;
3486 it
->current
.string_pos
= string_pos (charpos
, string
);
3493 /* Note that we use IT->current.pos, not it->current.string_pos,
3494 for displaying C strings. */
3495 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3496 if (it
->multibyte_p
)
3498 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3499 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3503 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3504 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3507 it
->method
= next_element_from_c_string
;
3510 /* PRECISION > 0 means don't return more than PRECISION characters
3512 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3513 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3515 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3516 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3517 FIELD_WIDTH < 0 means infinite field width. This is useful for
3518 padding with `-' at the end of a mode line. */
3519 if (field_width
< 0)
3520 field_width
= INFINITY
;
3521 if (field_width
> it
->end_charpos
- charpos
)
3522 it
->end_charpos
= charpos
+ field_width
;
3524 /* Use the standard display table for displaying strings. */
3525 if (DISP_TABLE_P (Vstandard_display_table
))
3526 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3528 it
->stop_charpos
= charpos
;
3534 /***********************************************************************
3536 ***********************************************************************/
3538 /* Load IT's display element fields with information about the next
3539 display element from the current position of IT. Value is zero if
3540 end of buffer (or C string) is reached. */
3543 get_next_display_element (it
)
3546 /* Non-zero means that we found an display element. Zero means that
3547 we hit the end of what we iterate over. Performance note: the
3548 function pointer `method' used here turns out to be faster than
3549 using a sequence of if-statements. */
3550 int success_p
= (*it
->method
) (it
);
3552 if (it
->what
== IT_CHARACTER
)
3554 /* Map via display table or translate control characters.
3555 IT->c, IT->len etc. have been set to the next character by
3556 the function call above. If we have a display table, and it
3557 contains an entry for IT->c, translate it. Don't do this if
3558 IT->c itself comes from a display table, otherwise we could
3559 end up in an infinite recursion. (An alternative could be to
3560 count the recursion depth of this function and signal an
3561 error when a certain maximum depth is reached.) Is it worth
3563 if (success_p
&& it
->dpvec
== NULL
)
3568 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3571 struct Lisp_Vector
*v
= XVECTOR (dv
);
3573 /* Return the first character from the display table
3574 entry, if not empty. If empty, don't display the
3575 current character. */
3578 it
->dpvec_char_len
= it
->len
;
3579 it
->dpvec
= v
->contents
;
3580 it
->dpend
= v
->contents
+ v
->size
;
3581 it
->current
.dpvec_index
= 0;
3582 it
->method
= next_element_from_display_vector
;
3585 success_p
= get_next_display_element (it
);
3588 /* Translate control characters into `\003' or `^C' form.
3589 Control characters coming from a display table entry are
3590 currently not translated because we use IT->dpvec to hold
3591 the translation. This could easily be changed but I
3592 don't believe that it is worth doing.
3594 Non-printable multibyte characters are also translated
3596 else if ((it
->c
< ' '
3597 && (it
->area
!= TEXT_AREA
3598 || (it
->c
!= '\n' && it
->c
!= '\t')))
3601 || !CHAR_PRINTABLE_P (it
->c
))
3603 /* IT->c is a control character which must be displayed
3604 either as '\003' or as `^C' where the '\\' and '^'
3605 can be defined in the display table. Fill
3606 IT->ctl_chars with glyphs for what we have to
3607 display. Then, set IT->dpvec to these glyphs. */
3610 if (it
->c
< 128 && it
->ctl_arrow_p
)
3612 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3614 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3615 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3616 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3618 g
= FAST_MAKE_GLYPH ('^', 0);
3619 XSETINT (it
->ctl_chars
[0], g
);
3621 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3622 XSETINT (it
->ctl_chars
[1], g
);
3624 /* Set up IT->dpvec and return first character from it. */
3625 it
->dpvec_char_len
= it
->len
;
3626 it
->dpvec
= it
->ctl_chars
;
3627 it
->dpend
= it
->dpvec
+ 2;
3628 it
->current
.dpvec_index
= 0;
3629 it
->method
= next_element_from_display_vector
;
3630 get_next_display_element (it
);
3634 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
3639 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3641 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3642 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3643 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3645 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
3647 if (SINGLE_BYTE_CHAR_P (it
->c
))
3648 str
[0] = it
->c
, len
= 1;
3650 len
= CHAR_STRING (it
->c
, str
);
3652 for (i
= 0; i
< len
; i
++)
3654 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
3655 /* Insert three more glyphs into IT->ctl_chars for
3656 the octal display of the character. */
3657 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
3658 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
3659 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
3660 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
3661 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
3662 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
3665 /* Set up IT->dpvec and return the first character
3667 it
->dpvec_char_len
= it
->len
;
3668 it
->dpvec
= it
->ctl_chars
;
3669 it
->dpend
= it
->dpvec
+ len
* 4;
3670 it
->current
.dpvec_index
= 0;
3671 it
->method
= next_element_from_display_vector
;
3672 get_next_display_element (it
);
3677 /* Adjust face id for a multibyte character. There are no
3678 multibyte character in unibyte text. */
3681 && FRAME_WINDOW_P (it
->f
))
3683 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3684 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
3688 /* Is this character the last one of a run of characters with
3689 box? If yes, set IT->end_of_box_run_p to 1. */
3696 it
->end_of_box_run_p
3697 = ((face_id
= face_after_it_pos (it
),
3698 face_id
!= it
->face_id
)
3699 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3700 face
->box
== FACE_NO_BOX
));
3703 /* Value is 0 if end of buffer or string reached. */
3708 /* Move IT to the next display element.
3710 Functions get_next_display_element and set_iterator_to_next are
3711 separate because I find this arrangement easier to handle than a
3712 get_next_display_element function that also increments IT's
3713 position. The way it is we can first look at an iterator's current
3714 display element, decide whether it fits on a line, and if it does,
3715 increment the iterator position. The other way around we probably
3716 would either need a flag indicating whether the iterator has to be
3717 incremented the next time, or we would have to implement a
3718 decrement position function which would not be easy to write. */
3721 set_iterator_to_next (it
)
3724 if (it
->method
== next_element_from_buffer
)
3726 /* The current display element of IT is a character from
3727 current_buffer. Advance in the buffer, and maybe skip over
3728 invisible lines that are so because of selective display. */
3729 if (ITERATOR_AT_END_OF_LINE_P (it
))
3730 reseat_at_next_visible_line_start (it
, 0);
3733 xassert (it
->len
!= 0);
3734 IT_BYTEPOS (*it
) += it
->len
;
3735 IT_CHARPOS (*it
) += 1;
3736 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3739 else if (it
->method
== next_element_from_composition
)
3741 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
3742 if (STRINGP (it
->string
))
3744 IT_STRING_BYTEPOS (*it
) += it
->len
;
3745 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
3746 it
->method
= next_element_from_string
;
3747 goto consider_string_end
;
3751 IT_BYTEPOS (*it
) += it
->len
;
3752 IT_CHARPOS (*it
) += it
->cmp_len
;
3753 it
->method
= next_element_from_buffer
;
3756 else if (it
->method
== next_element_from_c_string
)
3758 /* Current display element of IT is from a C string. */
3759 IT_BYTEPOS (*it
) += it
->len
;
3760 IT_CHARPOS (*it
) += 1;
3762 else if (it
->method
== next_element_from_display_vector
)
3764 /* Current display element of IT is from a display table entry.
3765 Advance in the display table definition. Reset it to null if
3766 end reached, and continue with characters from buffers/
3768 ++it
->current
.dpvec_index
;
3770 /* Restore face of the iterator to what they were before the
3771 display vector entry (these entries may contain faces). */
3772 it
->face_id
= it
->saved_face_id
;
3774 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3777 it
->method
= next_element_from_c_string
;
3778 else if (STRINGP (it
->string
))
3779 it
->method
= next_element_from_string
;
3781 it
->method
= next_element_from_buffer
;
3784 it
->current
.dpvec_index
= -1;
3786 /* Skip over characters which were displayed via IT->dpvec. */
3787 if (it
->dpvec_char_len
< 0)
3788 reseat_at_next_visible_line_start (it
, 1);
3789 else if (it
->dpvec_char_len
> 0)
3791 it
->len
= it
->dpvec_char_len
;
3792 set_iterator_to_next (it
);
3796 else if (it
->method
== next_element_from_string
)
3798 /* Current display element is a character from a Lisp string. */
3799 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3800 IT_STRING_BYTEPOS (*it
) += it
->len
;
3801 IT_STRING_CHARPOS (*it
) += 1;
3803 consider_string_end
:
3805 if (it
->current
.overlay_string_index
>= 0)
3807 /* IT->string is an overlay string. Advance to the
3808 next, if there is one. */
3809 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3810 next_overlay_string (it
);
3814 /* IT->string is not an overlay string. If we reached
3815 its end, and there is something on IT->stack, proceed
3816 with what is on the stack. This can be either another
3817 string, this time an overlay string, or a buffer. */
3818 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3822 if (!STRINGP (it
->string
))
3823 it
->method
= next_element_from_buffer
;
3827 else if (it
->method
== next_element_from_image
3828 || it
->method
== next_element_from_stretch
)
3830 /* The position etc with which we have to proceed are on
3831 the stack. The position may be at the end of a string,
3832 if the `display' property takes up the whole string. */
3835 if (STRINGP (it
->string
))
3837 it
->method
= next_element_from_string
;
3838 goto consider_string_end
;
3841 it
->method
= next_element_from_buffer
;
3844 /* There are no other methods defined, so this should be a bug. */
3847 /* Reset flags indicating start and end of a sequence of
3848 characters with box. */
3849 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3851 xassert (it
->method
!= next_element_from_string
3852 || (STRINGP (it
->string
)
3853 && IT_STRING_CHARPOS (*it
) >= 0));
3857 /* Load IT's display element fields with information about the next
3858 display element which comes from a display table entry or from the
3859 result of translating a control character to one of the forms `^C'
3860 or `\003'. IT->dpvec holds the glyphs to return as characters. */
3863 next_element_from_display_vector (it
)
3867 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
3869 /* Remember the current face id in case glyphs specify faces.
3870 IT's face is restored in set_iterator_to_next. */
3871 it
->saved_face_id
= it
->face_id
;
3873 if (INTEGERP (*it
->dpvec
)
3874 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
3879 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
3880 it
->c
= FAST_GLYPH_CHAR (g
);
3881 it
->len
= CHAR_BYTES (it
->c
);
3883 /* The entry may contain a face id to use. Such a face id is
3884 the id of a Lisp face, not a realized face. A face id of
3885 zero means no face is specified. */
3886 lface_id
= FAST_GLYPH_FACE (g
);
3889 /* The function returns -1 if lface_id is invalid. */
3890 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
3892 it
->face_id
= face_id
;
3896 /* Display table entry is invalid. Return a space. */
3897 it
->c
= ' ', it
->len
= 1;
3899 /* Don't change position and object of the iterator here. They are
3900 still the values of the character that had this display table
3901 entry or was translated, and that's what we want. */
3902 it
->what
= IT_CHARACTER
;
3907 /* Load IT with the next display element from Lisp string IT->string.
3908 IT->current.string_pos is the current position within the string.
3909 If IT->current.overlay_string_index >= 0, the Lisp string is an
3913 next_element_from_string (it
)
3916 struct text_pos position
;
3918 xassert (STRINGP (it
->string
));
3919 xassert (IT_STRING_CHARPOS (*it
) >= 0);
3920 position
= it
->current
.string_pos
;
3922 /* Time to check for invisible text? */
3923 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
3924 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
3928 /* Since a handler may have changed IT->method, we must
3930 return get_next_display_element (it
);
3933 if (it
->current
.overlay_string_index
>= 0)
3935 /* Get the next character from an overlay string. In overlay
3936 strings, There is no field width or padding with spaces to
3938 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3943 else if (STRING_MULTIBYTE (it
->string
))
3945 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
3946 - IT_STRING_BYTEPOS (*it
));
3947 unsigned char *s
= (XSTRING (it
->string
)->data
3948 + IT_STRING_BYTEPOS (*it
));
3949 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
3953 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3959 /* Get the next character from a Lisp string that is not an
3960 overlay string. Such strings come from the mode line, for
3961 example. We may have to pad with spaces, or truncate the
3962 string. See also next_element_from_c_string. */
3963 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
3968 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
3970 /* Pad with spaces. */
3971 it
->c
= ' ', it
->len
= 1;
3972 CHARPOS (position
) = BYTEPOS (position
) = -1;
3974 else if (STRING_MULTIBYTE (it
->string
))
3976 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
3977 - IT_STRING_BYTEPOS (*it
));
3978 unsigned char *s
= (XSTRING (it
->string
)->data
3979 + IT_STRING_BYTEPOS (*it
));
3980 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
3984 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3989 /* Record what we have and where it came from. Note that we store a
3990 buffer position in IT->position although it could arguably be a
3992 it
->what
= IT_CHARACTER
;
3993 it
->object
= it
->string
;
3994 it
->position
= position
;
3999 /* Load IT with next display element from C string IT->s.
4000 IT->string_nchars is the maximum number of characters to return
4001 from the string. IT->end_charpos may be greater than
4002 IT->string_nchars when this function is called, in which case we
4003 may have to return padding spaces. Value is zero if end of string
4004 reached, including padding spaces. */
4007 next_element_from_c_string (it
)
4013 it
->what
= IT_CHARACTER
;
4014 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4017 /* IT's position can be greater IT->string_nchars in case a field
4018 width or precision has been specified when the iterator was
4020 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4022 /* End of the game. */
4026 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4028 /* Pad with spaces. */
4029 it
->c
= ' ', it
->len
= 1;
4030 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4032 else if (it
->multibyte_p
)
4034 /* Implementation note: The calls to strlen apparently aren't a
4035 performance problem because there is no noticeable performance
4036 difference between Emacs running in unibyte or multibyte mode. */
4037 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4038 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4042 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4048 /* Set up IT to return characters from an ellipsis, if appropriate.
4049 The definition of the ellipsis glyphs may come from a display table
4050 entry. This function Fills IT with the first glyph from the
4051 ellipsis if an ellipsis is to be displayed. */
4054 next_element_from_ellipsis (it
)
4057 if (it
->selective_display_ellipsis_p
)
4059 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4061 /* Use the display table definition for `...'. Invalid glyphs
4062 will be handled by the method returning elements from dpvec. */
4063 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4064 it
->dpvec_char_len
= it
->len
;
4065 it
->dpvec
= v
->contents
;
4066 it
->dpend
= v
->contents
+ v
->size
;
4067 it
->current
.dpvec_index
= 0;
4068 it
->method
= next_element_from_display_vector
;
4072 /* Use default `...' which is stored in default_invis_vector. */
4073 it
->dpvec_char_len
= it
->len
;
4074 it
->dpvec
= default_invis_vector
;
4075 it
->dpend
= default_invis_vector
+ 3;
4076 it
->current
.dpvec_index
= 0;
4077 it
->method
= next_element_from_display_vector
;
4081 reseat_at_next_visible_line_start (it
, 1);
4083 return get_next_display_element (it
);
4087 /* Deliver an image display element. The iterator IT is already
4088 filled with image information (done in handle_display_prop). Value
4093 next_element_from_image (it
)
4096 it
->what
= IT_IMAGE
;
4101 /* Fill iterator IT with next display element from a stretch glyph
4102 property. IT->object is the value of the text property. Value is
4106 next_element_from_stretch (it
)
4109 it
->what
= IT_STRETCH
;
4114 /* Load IT with the next display element from current_buffer. Value
4115 is zero if end of buffer reached. IT->stop_charpos is the next
4116 position at which to stop and check for text properties or buffer
4120 next_element_from_buffer (it
)
4125 /* Check this assumption, otherwise, we would never enter the
4126 if-statement, below. */
4127 xassert (IT_CHARPOS (*it
) >= BEGV
4128 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4130 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4132 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4134 int overlay_strings_follow_p
;
4136 /* End of the game, except when overlay strings follow that
4137 haven't been returned yet. */
4138 if (it
->overlay_strings_at_end_processed_p
)
4139 overlay_strings_follow_p
= 0;
4142 it
->overlay_strings_at_end_processed_p
= 1;
4143 overlay_strings_follow_p
= get_overlay_strings (it
);
4146 if (overlay_strings_follow_p
)
4147 success_p
= get_next_display_element (it
);
4151 it
->position
= it
->current
.pos
;
4158 return get_next_display_element (it
);
4163 /* No face changes, overlays etc. in sight, so just return a
4164 character from current_buffer. */
4167 /* Maybe run the redisplay end trigger hook. Performance note:
4168 This doesn't seem to cost measurable time. */
4169 if (it
->redisplay_end_trigger_charpos
4171 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4172 run_redisplay_end_trigger_hook (it
);
4174 /* Get the next character, maybe multibyte. */
4175 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4176 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4178 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4179 - IT_BYTEPOS (*it
));
4180 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4183 it
->c
= *p
, it
->len
= 1;
4185 /* Record what we have and where it came from. */
4186 it
->what
= IT_CHARACTER
;;
4187 it
->object
= it
->w
->buffer
;
4188 it
->position
= it
->current
.pos
;
4190 /* Normally we return the character found above, except when we
4191 really want to return an ellipsis for selective display. */
4196 /* A value of selective > 0 means hide lines indented more
4197 than that number of columns. */
4198 if (it
->selective
> 0
4199 && IT_CHARPOS (*it
) + 1 < ZV
4200 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4201 IT_BYTEPOS (*it
) + 1,
4204 success_p
= next_element_from_ellipsis (it
);
4205 it
->dpvec_char_len
= -1;
4208 else if (it
->c
== '\r' && it
->selective
== -1)
4210 /* A value of selective == -1 means that everything from the
4211 CR to the end of the line is invisible, with maybe an
4212 ellipsis displayed for it. */
4213 success_p
= next_element_from_ellipsis (it
);
4214 it
->dpvec_char_len
= -1;
4219 /* Value is zero if end of buffer reached. */
4220 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4225 /* Run the redisplay end trigger hook for IT. */
4228 run_redisplay_end_trigger_hook (it
)
4231 Lisp_Object args
[3];
4233 /* IT->glyph_row should be non-null, i.e. we should be actually
4234 displaying something, or otherwise we should not run the hook. */
4235 xassert (it
->glyph_row
);
4237 /* Set up hook arguments. */
4238 args
[0] = Qredisplay_end_trigger_functions
;
4239 args
[1] = it
->window
;
4240 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4241 it
->redisplay_end_trigger_charpos
= 0;
4243 /* Since we are *trying* to run these functions, don't try to run
4244 them again, even if they get an error. */
4245 it
->w
->redisplay_end_trigger
= Qnil
;
4246 Frun_hook_with_args (3, args
);
4248 /* Notice if it changed the face of the character we are on. */
4249 handle_face_prop (it
);
4253 /* Deliver a composition display element. The iterator IT is already
4254 filled with composition information (done in
4255 handle_composition_prop). Value is always 1. */
4258 next_element_from_composition (it
)
4261 it
->what
= IT_COMPOSITION
;
4262 it
->position
= (STRINGP (it
->string
)
4263 ? it
->current
.string_pos
4270 /***********************************************************************
4271 Moving an iterator without producing glyphs
4272 ***********************************************************************/
4274 /* Move iterator IT to a specified buffer or X position within one
4275 line on the display without producing glyphs.
4277 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4278 whichever is reached first.
4280 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4282 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4283 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4284 TO_X includes the amount by which a window is horizontally
4289 MOVE_POS_MATCH_OR_ZV
4290 - when TO_POS or ZV was reached.
4293 -when TO_X was reached before TO_POS or ZV were reached.
4296 - when we reached the end of the display area and the line must
4300 - when we reached the end of the display area and the line is
4304 - when we stopped at a line end, i.e. a newline or a CR and selective
4307 static enum move_it_result
4308 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4310 int to_charpos
, to_x
, op
;
4312 enum move_it_result result
= MOVE_UNDEFINED
;
4313 struct glyph_row
*saved_glyph_row
;
4315 /* Don't produce glyphs in produce_glyphs. */
4316 saved_glyph_row
= it
->glyph_row
;
4317 it
->glyph_row
= NULL
;
4321 int x
, i
, ascent
= 0, descent
= 0;
4323 /* Stop when ZV or TO_CHARPOS reached. */
4324 if (!get_next_display_element (it
)
4325 || ((op
& MOVE_TO_POS
) != 0
4326 && BUFFERP (it
->object
)
4327 && IT_CHARPOS (*it
) >= to_charpos
))
4329 result
= MOVE_POS_MATCH_OR_ZV
;
4333 /* The call to produce_glyphs will get the metrics of the
4334 display element IT is loaded with. We record in x the
4335 x-position before this display element in case it does not
4339 /* Remember the line height so far in case the next element doesn't
4341 if (!it
->truncate_lines_p
)
4343 ascent
= it
->max_ascent
;
4344 descent
= it
->max_descent
;
4347 PRODUCE_GLYPHS (it
);
4349 if (it
->area
!= TEXT_AREA
)
4351 set_iterator_to_next (it
);
4355 /* The number of glyphs we get back in IT->nglyphs will normally
4356 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4357 character on a terminal frame, or (iii) a line end. For the
4358 second case, IT->nglyphs - 1 padding glyphs will be present
4359 (on X frames, there is only one glyph produced for a
4360 composite character.
4362 The behavior implemented below means, for continuation lines,
4363 that as many spaces of a TAB as fit on the current line are
4364 displayed there. For terminal frames, as many glyphs of a
4365 multi-glyph character are displayed in the current line, too.
4366 This is what the old redisplay code did, and we keep it that
4367 way. Under X, the whole shape of a complex character must
4368 fit on the line or it will be completely displayed in the
4371 Note that both for tabs and padding glyphs, all glyphs have
4375 /* More than one glyph or glyph doesn't fit on line. All
4376 glyphs have the same width. */
4377 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4380 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4382 new_x
= x
+ single_glyph_width
;
4384 /* We want to leave anything reaching TO_X to the caller. */
4385 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4388 result
= MOVE_X_REACHED
;
4391 else if (/* Lines are continued. */
4392 !it
->truncate_lines_p
4393 && (/* And glyph doesn't fit on the line. */
4394 new_x
> it
->last_visible_x
4395 /* Or it fits exactly and we're on a window
4397 || (new_x
== it
->last_visible_x
4398 && FRAME_WINDOW_P (it
->f
))))
4400 if (/* IT->hpos == 0 means the very first glyph
4401 doesn't fit on the line, e.g. a wide image. */
4403 || (new_x
== it
->last_visible_x
4404 && FRAME_WINDOW_P (it
->f
)))
4407 it
->current_x
= new_x
;
4408 if (i
== it
->nglyphs
- 1)
4409 set_iterator_to_next (it
);
4414 it
->max_ascent
= ascent
;
4415 it
->max_descent
= descent
;
4418 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
4420 result
= MOVE_LINE_CONTINUED
;
4423 else if (new_x
> it
->first_visible_x
)
4425 /* Glyph is visible. Increment number of glyphs that
4426 would be displayed. */
4431 /* Glyph is completely off the left margin of the display
4432 area. Nothing to do. */
4436 if (result
!= MOVE_UNDEFINED
)
4439 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4441 /* Stop when TO_X specified and reached. This check is
4442 necessary here because of lines consisting of a line end,
4443 only. The line end will not produce any glyphs and we
4444 would never get MOVE_X_REACHED. */
4445 xassert (it
->nglyphs
== 0);
4446 result
= MOVE_X_REACHED
;
4450 /* Is this a line end? If yes, we're done. */
4451 if (ITERATOR_AT_END_OF_LINE_P (it
))
4453 result
= MOVE_NEWLINE_OR_CR
;
4457 /* The current display element has been consumed. Advance
4459 set_iterator_to_next (it
);
4461 /* Stop if lines are truncated and IT's current x-position is
4462 past the right edge of the window now. */
4463 if (it
->truncate_lines_p
4464 && it
->current_x
>= it
->last_visible_x
)
4466 result
= MOVE_LINE_TRUNCATED
;
4471 /* Restore the iterator settings altered at the beginning of this
4473 it
->glyph_row
= saved_glyph_row
;
4478 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4479 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4480 the description of enum move_operation_enum.
4482 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4483 screen line, this function will set IT to the next position >
4487 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4489 int to_charpos
, to_x
, to_y
, to_vpos
;
4492 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4498 if (op
& MOVE_TO_VPOS
)
4500 /* If no TO_CHARPOS and no TO_X specified, stop at the
4501 start of the line TO_VPOS. */
4502 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4504 if (it
->vpos
== to_vpos
)
4510 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4514 /* TO_VPOS >= 0 means stop at TO_X in the line at
4515 TO_VPOS, or at TO_POS, whichever comes first. */
4516 if (it
->vpos
== to_vpos
)
4522 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4524 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4529 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4531 /* We have reached TO_X but not in the line we want. */
4532 skip
= move_it_in_display_line_to (it
, to_charpos
,
4534 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4542 else if (op
& MOVE_TO_Y
)
4544 struct it it_backup
;
4546 /* TO_Y specified means stop at TO_X in the line containing
4547 TO_Y---or at TO_CHARPOS if this is reached first. The
4548 problem is that we can't really tell whether the line
4549 contains TO_Y before we have completely scanned it, and
4550 this may skip past TO_X. What we do is to first scan to
4553 If TO_X is not specified, use a TO_X of zero. The reason
4554 is to make the outcome of this function more predictable.
4555 If we didn't use TO_X == 0, we would stop at the end of
4556 the line which is probably not what a caller would expect
4558 skip
= move_it_in_display_line_to (it
, to_charpos
,
4562 | (op
& MOVE_TO_POS
)));
4564 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4565 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4571 /* If TO_X was reached, we would like to know whether TO_Y
4572 is in the line. This can only be said if we know the
4573 total line height which requires us to scan the rest of
4575 if (skip
== MOVE_X_REACHED
)
4578 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
4579 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4581 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
4584 /* Now, decide whether TO_Y is in this line. */
4585 line_height
= it
->max_ascent
+ it
->max_descent
;
4586 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
4588 if (to_y
>= it
->current_y
4589 && to_y
< it
->current_y
+ line_height
)
4591 if (skip
== MOVE_X_REACHED
)
4592 /* If TO_Y is in this line and TO_X was reached above,
4593 we scanned too far. We have to restore IT's settings
4594 to the ones before skipping. */
4598 else if (skip
== MOVE_X_REACHED
)
4601 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4609 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4613 case MOVE_POS_MATCH_OR_ZV
:
4617 case MOVE_NEWLINE_OR_CR
:
4618 set_iterator_to_next (it
);
4619 it
->continuation_lines_width
= 0;
4622 case MOVE_LINE_TRUNCATED
:
4623 it
->continuation_lines_width
= 0;
4624 reseat_at_next_visible_line_start (it
, 0);
4625 if ((op
& MOVE_TO_POS
) != 0
4626 && IT_CHARPOS (*it
) > to_charpos
)
4633 case MOVE_LINE_CONTINUED
:
4634 it
->continuation_lines_width
+= it
->current_x
;
4641 /* Reset/increment for the next run. */
4642 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4643 it
->current_x
= it
->hpos
= 0;
4644 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4646 last_height
= it
->max_ascent
+ it
->max_descent
;
4647 last_max_ascent
= it
->max_ascent
;
4648 it
->max_ascent
= it
->max_descent
= 0;
4653 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
4657 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4659 If DY > 0, move IT backward at least that many pixels. DY = 0
4660 means move IT backward to the preceding line start or BEGV. This
4661 function may move over more than DY pixels if IT->current_y - DY
4662 ends up in the middle of a line; in this case IT->current_y will be
4663 set to the top of the line moved to. */
4666 move_it_vertically_backward (it
, dy
)
4670 int nlines
, h
, line_height
;
4672 int start_pos
= IT_CHARPOS (*it
);
4676 /* Estimate how many newlines we must move back. */
4677 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4679 /* Set the iterator's position that many lines back. */
4680 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4681 back_to_previous_visible_line_start (it
);
4683 /* Reseat the iterator here. When moving backward, we don't want
4684 reseat to skip forward over invisible text, set up the iterator
4685 to deliver from overlay strings at the new position etc. So,
4686 use reseat_1 here. */
4687 reseat_1 (it
, it
->current
.pos
, 1);
4689 /* We are now surely at a line start. */
4690 it
->current_x
= it
->hpos
= 0;
4692 /* Move forward and see what y-distance we moved. First move to the
4693 start of the next line so that we get its height. We need this
4694 height to be able to tell whether we reached the specified
4697 it2
.max_ascent
= it2
.max_descent
= 0;
4698 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4699 MOVE_TO_POS
| MOVE_TO_VPOS
);
4700 xassert (IT_CHARPOS (*it
) >= BEGV
);
4701 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4703 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4704 xassert (IT_CHARPOS (*it
) >= BEGV
);
4705 h
= it2
.current_y
- it
->current_y
;
4706 nlines
= it2
.vpos
- it
->vpos
;
4708 /* Correct IT's y and vpos position. */
4714 /* DY == 0 means move to the start of the screen line. The
4715 value of nlines is > 0 if continuation lines were involved. */
4717 move_it_by_lines (it
, nlines
, 1);
4718 xassert (IT_CHARPOS (*it
) <= start_pos
);
4722 /* The y-position we try to reach. Note that h has been
4723 subtracted in front of the if-statement. */
4724 int target_y
= it
->current_y
+ h
- dy
;
4726 /* If we did not reach target_y, try to move further backward if
4727 we can. If we moved too far backward, try to move forward. */
4728 if (target_y
< it
->current_y
4729 && IT_CHARPOS (*it
) > BEGV
)
4731 move_it_vertically (it
, target_y
- it
->current_y
);
4732 xassert (IT_CHARPOS (*it
) >= BEGV
);
4734 else if (target_y
>= it
->current_y
+ line_height
4735 && IT_CHARPOS (*it
) < ZV
)
4737 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4738 xassert (IT_CHARPOS (*it
) >= BEGV
);
4744 /* Move IT by a specified amount of pixel lines DY. DY negative means
4745 move backwards. DY = 0 means move to start of screen line. At the
4746 end, IT will be on the start of a screen line. */
4749 move_it_vertically (it
, dy
)
4754 move_it_vertically_backward (it
, -dy
);
4757 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
4758 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4759 MOVE_TO_POS
| MOVE_TO_Y
);
4760 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
4762 /* If buffer ends in ZV without a newline, move to the start of
4763 the line to satisfy the post-condition. */
4764 if (IT_CHARPOS (*it
) == ZV
4765 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4766 move_it_by_lines (it
, 0, 0);
4771 /* Return non-zero if some text between buffer positions START_CHARPOS
4772 and END_CHARPOS is invisible. IT->window is the window for text
4776 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4778 int start_charpos
, end_charpos
;
4780 Lisp_Object prop
, limit
;
4781 int invisible_found_p
;
4783 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4785 /* Is text at START invisible? */
4786 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4788 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4789 invisible_found_p
= 1;
4792 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
4794 make_number (end_charpos
));
4795 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4798 return invisible_found_p
;
4802 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4803 negative means move up. DVPOS == 0 means move to the start of the
4804 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4805 NEED_Y_P is zero, IT->current_y will be left unchanged.
4807 Further optimization ideas: If we would know that IT->f doesn't use
4808 a face with proportional font, we could be faster for
4809 truncate-lines nil. */
4812 move_it_by_lines (it
, dvpos
, need_y_p
)
4814 int dvpos
, need_y_p
;
4816 struct position pos
;
4818 if (!FRAME_WINDOW_P (it
->f
))
4820 struct text_pos textpos
;
4822 /* We can use vmotion on frames without proportional fonts. */
4823 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4824 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4825 reseat (it
, textpos
, 1);
4826 it
->vpos
+= pos
.vpos
;
4827 it
->current_y
+= pos
.vpos
;
4829 else if (dvpos
== 0)
4831 /* DVPOS == 0 means move to the start of the screen line. */
4832 move_it_vertically_backward (it
, 0);
4833 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4837 /* If there are no continuation lines, and if there is no
4838 selective display, try the simple method of moving forward
4839 DVPOS newlines, then see where we are. */
4840 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4842 int shortage
= 0, charpos
;
4844 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
4845 charpos
= IT_CHARPOS (*it
) + 1;
4847 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
4850 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
4852 struct text_pos pos
;
4853 CHARPOS (pos
) = charpos
;
4854 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4855 reseat (it
, pos
, 1);
4856 it
->vpos
+= dvpos
- shortage
;
4857 it
->hpos
= it
->current_x
= 0;
4862 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
4867 int start_charpos
, i
;
4869 /* If there are no continuation lines, and if there is no
4870 selective display, try the simple method of moving backward
4872 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4875 int charpos
= IT_CHARPOS (*it
);
4876 int bytepos
= IT_BYTEPOS (*it
);
4878 /* If in the middle of a line, go to its start. */
4879 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
4881 charpos
= find_next_newline_no_quit (charpos
, -1);
4882 bytepos
= CHAR_TO_BYTE (charpos
);
4885 if (charpos
== BEGV
)
4887 struct text_pos pos
;
4888 CHARPOS (pos
) = charpos
;
4889 BYTEPOS (pos
) = bytepos
;
4890 reseat (it
, pos
, 1);
4891 it
->hpos
= it
->current_x
= 0;
4896 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
4897 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
4899 struct text_pos pos
;
4900 CHARPOS (pos
) = charpos
;
4901 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4902 reseat (it
, pos
, 1);
4903 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
4904 it
->hpos
= it
->current_x
= 0;
4910 /* Go back -DVPOS visible lines and reseat the iterator there. */
4911 start_charpos
= IT_CHARPOS (*it
);
4912 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
4913 back_to_previous_visible_line_start (it
);
4914 reseat (it
, it
->current
.pos
, 1);
4915 it
->current_x
= it
->hpos
= 0;
4917 /* Above call may have moved too far if continuation lines
4918 are involved. Scan forward and see if it did. */
4920 it2
.vpos
= it2
.current_y
= 0;
4921 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
4922 it
->vpos
-= it2
.vpos
;
4923 it
->current_y
-= it2
.current_y
;
4924 it
->current_x
= it
->hpos
= 0;
4926 /* If we moved too far, move IT some lines forward. */
4927 if (it2
.vpos
> -dvpos
)
4929 int delta
= it2
.vpos
+ dvpos
;
4930 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
4937 /***********************************************************************
4939 ***********************************************************************/
4942 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
4946 add_to_log (format
, arg1
, arg2
)
4948 Lisp_Object arg1
, arg2
;
4950 Lisp_Object args
[3];
4951 Lisp_Object msg
, fmt
;
4954 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4957 GCPRO4 (fmt
, msg
, arg1
, arg2
);
4959 args
[0] = fmt
= build_string (format
);
4962 msg
= Fformat (3, args
);
4964 len
= STRING_BYTES (XSTRING (msg
)) + 1;
4965 buffer
= (char *) alloca (len
);
4966 strcpy (buffer
, XSTRING (msg
)->data
);
4968 message_dolog (buffer
, len
- 1, 1, 0);
4973 /* Output a newline in the *Messages* buffer if "needs" one. */
4976 message_log_maybe_newline ()
4978 if (message_log_need_newline
)
4979 message_dolog ("", 0, 1, 0);
4983 /* Add a string M of length LEN to the message log, optionally
4984 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
4985 nonzero, means interpret the contents of M as multibyte. This
4986 function calls low-level routines in order to bypass text property
4987 hooks, etc. which might not be safe to run. */
4990 message_dolog (m
, len
, nlflag
, multibyte
)
4992 int len
, nlflag
, multibyte
;
4994 if (!NILP (Vmessage_log_max
))
4996 struct buffer
*oldbuf
;
4997 Lisp_Object oldpoint
, oldbegv
, oldzv
;
4998 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4999 int point_at_end
= 0;
5001 Lisp_Object old_deactivate_mark
, tem
;
5002 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5004 old_deactivate_mark
= Vdeactivate_mark
;
5005 oldbuf
= current_buffer
;
5006 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5007 current_buffer
->undo_list
= Qt
;
5009 oldpoint
= Fpoint_marker ();
5010 oldbegv
= Fpoint_min_marker ();
5011 oldzv
= Fpoint_max_marker ();
5012 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5020 BEGV_BYTE
= BEG_BYTE
;
5023 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5025 /* Insert the string--maybe converting multibyte to single byte
5026 or vice versa, so that all the text fits the buffer. */
5028 && NILP (current_buffer
->enable_multibyte_characters
))
5031 unsigned char work
[1];
5033 /* Convert a multibyte string to single-byte
5034 for the *Message* buffer. */
5035 for (i
= 0; i
< len
; i
+= nbytes
)
5037 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
5038 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5040 : multibyte_char_to_unibyte (c
, Qnil
));
5041 insert_1_both (work
, 1, 1, 1, 0, 0);
5044 else if (! multibyte
5045 && ! NILP (current_buffer
->enable_multibyte_characters
))
5048 unsigned char *msg
= (unsigned char *) m
;
5049 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5050 /* Convert a single-byte string to multibyte
5051 for the *Message* buffer. */
5052 for (i
= 0; i
< len
; i
++)
5054 c
= unibyte_char_to_multibyte (msg
[i
]);
5055 nbytes
= CHAR_STRING (c
, str
);
5056 insert_1_both (str
, 1, nbytes
, 1, 0, 0);
5060 insert_1 (m
, len
, 1, 0, 0);
5064 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5065 insert_1 ("\n", 1, 1, 0, 0);
5067 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5069 this_bol_byte
= PT_BYTE
;
5073 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5075 prev_bol_byte
= PT_BYTE
;
5077 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5078 this_bol
, this_bol_byte
);
5081 del_range_both (prev_bol
, prev_bol_byte
,
5082 this_bol
, this_bol_byte
, 0);
5088 /* If you change this format, don't forget to also
5089 change message_log_check_duplicate. */
5090 sprintf (dupstr
, " [%d times]", dup
);
5091 duplen
= strlen (dupstr
);
5092 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5093 insert_1 (dupstr
, duplen
, 1, 0, 1);
5098 if (NATNUMP (Vmessage_log_max
))
5100 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5101 -XFASTINT (Vmessage_log_max
) - 1, 0);
5102 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5105 BEGV
= XMARKER (oldbegv
)->charpos
;
5106 BEGV_BYTE
= marker_byte_position (oldbegv
);
5115 ZV
= XMARKER (oldzv
)->charpos
;
5116 ZV_BYTE
= marker_byte_position (oldzv
);
5120 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5122 /* We can't do Fgoto_char (oldpoint) because it will run some
5124 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5125 XMARKER (oldpoint
)->bytepos
);
5128 free_marker (oldpoint
);
5129 free_marker (oldbegv
);
5130 free_marker (oldzv
);
5132 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5133 set_buffer_internal (oldbuf
);
5135 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5136 message_log_need_newline
= !nlflag
;
5137 Vdeactivate_mark
= old_deactivate_mark
;
5142 /* We are at the end of the buffer after just having inserted a newline.
5143 (Note: We depend on the fact we won't be crossing the gap.)
5144 Check to see if the most recent message looks a lot like the previous one.
5145 Return 0 if different, 1 if the new one should just replace it, or a
5146 value N > 1 if we should also append " [N times]". */
5149 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5150 int prev_bol
, this_bol
;
5151 int prev_bol_byte
, this_bol_byte
;
5154 int len
= Z_BYTE
- 1 - this_bol_byte
;
5156 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5157 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5159 for (i
= 0; i
< len
; i
++)
5161 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
5170 if (*p1
++ == ' ' && *p1
++ == '[')
5173 while (*p1
>= '0' && *p1
<= '9')
5174 n
= n
* 10 + *p1
++ - '0';
5175 if (strncmp (p1
, " times]\n", 8) == 0)
5182 /* Display an echo area message M with a specified length of LEN
5183 chars. The string may include null characters. If M is 0, clear
5184 out any existing message, and let the mini-buffer text show through.
5186 The buffer M must continue to exist until after the echo area gets
5187 cleared or some other message gets displayed there. This means do
5188 not pass text that is stored in a Lisp string; do not pass text in
5189 a buffer that was alloca'd. */
5192 message2 (m
, len
, multibyte
)
5197 /* First flush out any partial line written with print. */
5198 message_log_maybe_newline ();
5200 message_dolog (m
, len
, 1, multibyte
);
5201 message2_nolog (m
, len
, multibyte
);
5205 /* The non-logging counterpart of message2. */
5208 message2_nolog (m
, len
, multibyte
)
5212 struct frame
*sf
= SELECTED_FRAME ();
5213 message_enable_multibyte
= multibyte
;
5217 if (noninteractive_need_newline
)
5218 putc ('\n', stderr
);
5219 noninteractive_need_newline
= 0;
5221 fwrite (m
, len
, 1, stderr
);
5222 if (cursor_in_echo_area
== 0)
5223 fprintf (stderr
, "\n");
5226 /* A null message buffer means that the frame hasn't really been
5227 initialized yet. Error messages get reported properly by
5228 cmd_error, so this must be just an informative message; toss it. */
5229 else if (INTERACTIVE
5230 && sf
->glyphs_initialized_p
5231 && FRAME_MESSAGE_BUF (sf
))
5233 Lisp_Object mini_window
;
5236 /* Get the frame containing the mini-buffer
5237 that the selected frame is using. */
5238 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5239 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5241 FRAME_SAMPLE_VISIBILITY (f
);
5242 if (FRAME_VISIBLE_P (sf
)
5243 && ! FRAME_VISIBLE_P (f
))
5244 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5248 set_message (m
, Qnil
, len
, multibyte
);
5249 if (minibuffer_auto_raise
)
5250 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5253 clear_message (1, 1);
5255 do_pending_window_change (0);
5256 echo_area_display (1);
5257 do_pending_window_change (0);
5258 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5259 (*frame_up_to_date_hook
) (f
);
5264 /* Display an echo area message M with a specified length of NBYTES
5265 bytes. The string may include null characters. If M is not a
5266 string, clear out any existing message, and let the mini-buffer
5267 text show through. */
5270 message3 (m
, nbytes
, multibyte
)
5275 struct gcpro gcpro1
;
5279 /* First flush out any partial line written with print. */
5280 message_log_maybe_newline ();
5282 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5283 message3_nolog (m
, nbytes
, multibyte
);
5289 /* The non-logging version of message3. */
5292 message3_nolog (m
, nbytes
, multibyte
)
5294 int nbytes
, multibyte
;
5296 struct frame
*sf
= SELECTED_FRAME ();
5297 message_enable_multibyte
= multibyte
;
5301 if (noninteractive_need_newline
)
5302 putc ('\n', stderr
);
5303 noninteractive_need_newline
= 0;
5305 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5306 if (cursor_in_echo_area
== 0)
5307 fprintf (stderr
, "\n");
5310 /* A null message buffer means that the frame hasn't really been
5311 initialized yet. Error messages get reported properly by
5312 cmd_error, so this must be just an informative message; toss it. */
5313 else if (INTERACTIVE
5314 && sf
->glyphs_initialized_p
5315 && FRAME_MESSAGE_BUF (sf
))
5317 Lisp_Object mini_window
;
5321 /* Get the frame containing the mini-buffer
5322 that the selected frame is using. */
5323 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5324 frame
= XWINDOW (mini_window
)->frame
;
5327 FRAME_SAMPLE_VISIBILITY (f
);
5328 if (FRAME_VISIBLE_P (sf
)
5329 && !FRAME_VISIBLE_P (f
))
5330 Fmake_frame_visible (frame
);
5332 if (STRINGP (m
) && XSTRING (m
)->size
)
5334 set_message (NULL
, m
, nbytes
, multibyte
);
5335 if (minibuffer_auto_raise
)
5336 Fraise_frame (frame
);
5339 clear_message (1, 1);
5341 do_pending_window_change (0);
5342 echo_area_display (1);
5343 do_pending_window_change (0);
5344 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5345 (*frame_up_to_date_hook
) (f
);
5350 /* Display a null-terminated echo area message M. If M is 0, clear
5351 out any existing message, and let the mini-buffer text show through.
5353 The buffer M must continue to exist until after the echo area gets
5354 cleared or some other message gets displayed there. Do not pass
5355 text that is stored in a Lisp string. Do not pass text in a buffer
5356 that was alloca'd. */
5362 message2 (m
, (m
? strlen (m
) : 0), 0);
5366 /* The non-logging counterpart of message1. */
5372 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5375 /* Display a message M which contains a single %s
5376 which gets replaced with STRING. */
5379 message_with_string (m
, string
, log
)
5388 if (noninteractive_need_newline
)
5389 putc ('\n', stderr
);
5390 noninteractive_need_newline
= 0;
5391 fprintf (stderr
, m
, XSTRING (string
)->data
);
5392 if (cursor_in_echo_area
== 0)
5393 fprintf (stderr
, "\n");
5397 else if (INTERACTIVE
)
5399 /* The frame whose minibuffer we're going to display the message on.
5400 It may be larger than the selected frame, so we need
5401 to use its buffer, not the selected frame's buffer. */
5402 Lisp_Object mini_window
;
5403 struct frame
*f
, *sf
= SELECTED_FRAME ();
5405 /* Get the frame containing the minibuffer
5406 that the selected frame is using. */
5407 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5408 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5410 /* A null message buffer means that the frame hasn't really been
5411 initialized yet. Error messages get reported properly by
5412 cmd_error, so this must be just an informative message; toss it. */
5413 if (FRAME_MESSAGE_BUF (f
))
5417 a
[0] = (char *) XSTRING (string
)->data
;
5419 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5420 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5423 message2 (FRAME_MESSAGE_BUF (f
), len
,
5424 STRING_MULTIBYTE (string
));
5426 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5427 STRING_MULTIBYTE (string
));
5429 /* Print should start at the beginning of the message
5430 buffer next time. */
5431 message_buf_print
= 0;
5437 /* Dump an informative message to the minibuf. If M is 0, clear out
5438 any existing message, and let the mini-buffer text show through. */
5442 message (m
, a1
, a2
, a3
)
5444 EMACS_INT a1
, a2
, a3
;
5450 if (noninteractive_need_newline
)
5451 putc ('\n', stderr
);
5452 noninteractive_need_newline
= 0;
5453 fprintf (stderr
, m
, a1
, a2
, a3
);
5454 if (cursor_in_echo_area
== 0)
5455 fprintf (stderr
, "\n");
5459 else if (INTERACTIVE
)
5461 /* The frame whose mini-buffer we're going to display the message
5462 on. It may be larger than the selected frame, so we need to
5463 use its buffer, not the selected frame's buffer. */
5464 Lisp_Object mini_window
;
5465 struct frame
*f
, *sf
= SELECTED_FRAME ();
5467 /* Get the frame containing the mini-buffer
5468 that the selected frame is using. */
5469 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5470 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5472 /* A null message buffer means that the frame hasn't really been
5473 initialized yet. Error messages get reported properly by
5474 cmd_error, so this must be just an informative message; toss
5476 if (FRAME_MESSAGE_BUF (f
))
5487 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5488 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5490 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5491 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5493 #endif /* NO_ARG_ARRAY */
5495 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5500 /* Print should start at the beginning of the message
5501 buffer next time. */
5502 message_buf_print
= 0;
5508 /* The non-logging version of message. */
5511 message_nolog (m
, a1
, a2
, a3
)
5513 EMACS_INT a1
, a2
, a3
;
5515 Lisp_Object old_log_max
;
5516 old_log_max
= Vmessage_log_max
;
5517 Vmessage_log_max
= Qnil
;
5518 message (m
, a1
, a2
, a3
);
5519 Vmessage_log_max
= old_log_max
;
5523 /* Display the current message in the current mini-buffer. This is
5524 only called from error handlers in process.c, and is not time
5530 if (!NILP (echo_area_buffer
[0]))
5533 string
= Fcurrent_message ();
5534 message3 (string
, XSTRING (string
)->size
,
5535 !NILP (current_buffer
->enable_multibyte_characters
));
5540 /* Make sure echo area buffers in echo_buffers[] are life. If they
5541 aren't, make new ones. */
5544 ensure_echo_area_buffers ()
5548 for (i
= 0; i
< 2; ++i
)
5549 if (!BUFFERP (echo_buffer
[i
])
5550 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5553 Lisp_Object old_buffer
;
5556 old_buffer
= echo_buffer
[i
];
5557 sprintf (name
, " *Echo Area %d*", i
);
5558 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5559 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
5561 for (j
= 0; j
< 2; ++j
)
5562 if (EQ (old_buffer
, echo_area_buffer
[j
]))
5563 echo_area_buffer
[j
] = echo_buffer
[i
];
5568 /* Call FN with args A1..A4 with either the current or last displayed
5569 echo_area_buffer as current buffer.
5571 WHICH zero means use the current message buffer
5572 echo_area_buffer[0]. If that is nil, choose a suitable buffer
5573 from echo_buffer[] and clear it.
5575 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
5576 suitable buffer from echo_buffer[] and clear it.
5578 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
5579 that the current message becomes the last displayed one, make
5580 choose a suitable buffer for echo_area_buffer[0], and clear it.
5582 Value is what FN returns. */
5585 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
5588 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
5594 int this_one
, the_other
, clear_buffer_p
, rc
;
5595 int count
= specpdl_ptr
- specpdl
;
5597 /* If buffers aren't life, make new ones. */
5598 ensure_echo_area_buffers ();
5603 this_one
= 0, the_other
= 1;
5605 this_one
= 1, the_other
= 0;
5608 this_one
= 0, the_other
= 1;
5611 /* We need a fresh one in case the current echo buffer equals
5612 the one containing the last displayed echo area message. */
5613 if (!NILP (echo_area_buffer
[this_one
])
5614 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
5615 echo_area_buffer
[this_one
] = Qnil
;
5618 /* Choose a suitable buffer from echo_buffer[] is we don't
5620 if (NILP (echo_area_buffer
[this_one
]))
5622 echo_area_buffer
[this_one
]
5623 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
5624 ? echo_buffer
[the_other
]
5625 : echo_buffer
[this_one
]);
5629 buffer
= echo_area_buffer
[this_one
];
5631 record_unwind_protect (unwind_with_echo_area_buffer
,
5632 with_echo_area_buffer_unwind_data (w
));
5634 /* Make the echo area buffer current. Note that for display
5635 purposes, it is not necessary that the displayed window's buffer
5636 == current_buffer, except for text property lookup. So, let's
5637 only set that buffer temporarily here without doing a full
5638 Fset_window_buffer. We must also change w->pointm, though,
5639 because otherwise an assertions in unshow_buffer fails, and Emacs
5641 set_buffer_internal_1 (XBUFFER (buffer
));
5645 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
5648 current_buffer
->undo_list
= Qt
;
5649 current_buffer
->read_only
= Qnil
;
5651 if (clear_buffer_p
&& Z
> BEG
)
5654 xassert (BEGV
>= BEG
);
5655 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5657 rc
= fn (a1
, a2
, a3
, a4
);
5659 xassert (BEGV
>= BEG
);
5660 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5662 unbind_to (count
, Qnil
);
5667 /* Save state that should be preserved around the call to the function
5668 FN called in with_echo_area_buffer. */
5671 with_echo_area_buffer_unwind_data (w
)
5677 /* Reduce consing by keeping one vector in
5678 Vwith_echo_area_save_vector. */
5679 vector
= Vwith_echo_area_save_vector
;
5680 Vwith_echo_area_save_vector
= Qnil
;
5683 vector
= Fmake_vector (make_number (7), Qnil
);
5685 XSETBUFFER (XVECTOR (vector
)->contents
[i
], current_buffer
); ++i
;
5686 XVECTOR (vector
)->contents
[i
++] = Vdeactivate_mark
;
5687 XVECTOR (vector
)->contents
[i
++] = make_number (windows_or_buffers_changed
);
5691 XSETWINDOW (XVECTOR (vector
)->contents
[i
], w
); ++i
;
5692 XVECTOR (vector
)->contents
[i
++] = w
->buffer
;
5693 XVECTOR (vector
)->contents
[i
++]
5694 = make_number (XMARKER (w
->pointm
)->charpos
);
5695 XVECTOR (vector
)->contents
[i
++]
5696 = make_number (XMARKER (w
->pointm
)->bytepos
);
5702 XVECTOR (vector
)->contents
[i
++] = Qnil
;
5705 xassert (i
== XVECTOR (vector
)->size
);
5710 /* Restore global state from VECTOR which was created by
5711 with_echo_area_buffer_unwind_data. */
5714 unwind_with_echo_area_buffer (vector
)
5719 set_buffer_internal_1 (XBUFFER (XVECTOR (vector
)->contents
[i
])); ++i
;
5720 Vdeactivate_mark
= XVECTOR (vector
)->contents
[i
]; ++i
;
5721 windows_or_buffers_changed
= XFASTINT (XVECTOR (vector
)->contents
[i
]); ++i
;
5723 if (WINDOWP (XVECTOR (vector
)->contents
[i
]))
5726 Lisp_Object buffer
, charpos
, bytepos
;
5728 w
= XWINDOW (XVECTOR (vector
)->contents
[i
]); ++i
;
5729 buffer
= XVECTOR (vector
)->contents
[i
]; ++i
;
5730 charpos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5731 bytepos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5734 set_marker_both (w
->pointm
, buffer
,
5735 XFASTINT (charpos
), XFASTINT (bytepos
));
5738 Vwith_echo_area_save_vector
= vector
;
5743 /* Set up the echo area for use by print functions. MULTIBYTE_P
5744 non-zero means we will print multibyte. */
5747 setup_echo_area_for_printing (multibyte_p
)
5750 ensure_echo_area_buffers ();
5752 if (!message_buf_print
)
5754 /* A message has been output since the last time we printed.
5755 Choose a fresh echo area buffer. */
5756 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5757 echo_area_buffer
[0] = echo_buffer
[1];
5759 echo_area_buffer
[0] = echo_buffer
[0];
5761 /* Switch to that buffer and clear it. */
5762 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5765 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5767 /* Set up the buffer for the multibyteness we need. */
5769 != !NILP (current_buffer
->enable_multibyte_characters
))
5770 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
5772 /* Raise the frame containing the echo area. */
5773 if (minibuffer_auto_raise
)
5775 struct frame
*sf
= SELECTED_FRAME ();
5776 Lisp_Object mini_window
;
5777 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5778 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5781 message_log_maybe_newline ();
5782 message_buf_print
= 1;
5786 if (NILP (echo_area_buffer
[0]))
5788 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5789 echo_area_buffer
[0] = echo_buffer
[1];
5791 echo_area_buffer
[0] = echo_buffer
[0];
5794 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
5795 /* Someone switched buffers between print requests. */
5796 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5801 /* Display an echo area message in window W. Value is non-zero if W's
5802 height is changed. If display_last_displayed_message_p is
5803 non-zero, display the message that was last displayed, otherwise
5804 display the current message. */
5807 display_echo_area (w
)
5810 int i
, no_message_p
, window_height_changed_p
, count
;
5812 /* Temporarily disable garbage collections while displaying the echo
5813 area. This is done because a GC can print a message itself.
5814 That message would modify the echo area buffer's contents while a
5815 redisplay of the buffer is going on, and seriously confuse
5817 count
= inhibit_garbage_collection ();
5819 /* If there is no message, we must call display_echo_area_1
5820 nevertheless because it resizes the window. But we will have to
5821 reset the echo_area_buffer in question to nil at the end because
5822 with_echo_area_buffer will sets it to an empty buffer. */
5823 i
= display_last_displayed_message_p
? 1 : 0;
5824 no_message_p
= NILP (echo_area_buffer
[i
]);
5826 window_height_changed_p
5827 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
5828 display_echo_area_1
,
5829 (EMACS_INT
) w
, Qnil
, 0, 0);
5832 echo_area_buffer
[i
] = Qnil
;
5834 unbind_to (count
, Qnil
);
5835 return window_height_changed_p
;
5839 /* Helper for display_echo_area. Display the current buffer which
5840 contains the current echo area message in window W, a mini-window,
5841 a pointer to which is passed in A1. A2..A4 are currently not used.
5842 Change the height of W so that all of the message is displayed.
5843 Value is non-zero if height of W was changed. */
5846 display_echo_area_1 (a1
, a2
, a3
, a4
)
5851 struct window
*w
= (struct window
*) a1
;
5853 struct text_pos start
;
5854 int window_height_changed_p
= 0;
5856 /* Do this before displaying, so that we have a large enough glyph
5857 matrix for the display. */
5858 window_height_changed_p
= resize_mini_window (w
, 0);
5861 clear_glyph_matrix (w
->desired_matrix
);
5862 XSETWINDOW (window
, w
);
5863 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
5864 try_window (window
, start
);
5866 return window_height_changed_p
;
5870 /* Resize the echo area window to exactly the size needed for the
5871 currently displayed message, if there is one. */
5874 resize_echo_area_axactly ()
5876 if (BUFFERP (echo_area_buffer
[0])
5877 && WINDOWP (echo_area_window
))
5879 struct window
*w
= XWINDOW (echo_area_window
);
5882 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
5883 (EMACS_INT
) w
, Qnil
, 0, 0);
5886 ++windows_or_buffers_changed
;
5887 ++update_mode_lines
;
5888 redisplay_internal (0);
5894 /* Callback function for with_echo_area_buffer, when used from
5895 resize_echo_area_axactly. A1 contains a pointer to the window to
5896 resize, A2 to A4 are not used. Value is what resize_mini_window
5900 resize_mini_window_1 (a1
, a2
, a3
, a4
)
5905 return resize_mini_window ((struct window
*) a1
, 1);
5909 /* Resize mini-window W to fit the size of its contents. EXACT:P
5910 means size the window exactly to the size needed. Otherwise, it's
5911 only enlarged until W's buffer is empty. Value is non-zero if
5912 the window height has been changed. */
5915 resize_mini_window (w
, exact_p
)
5919 struct frame
*f
= XFRAME (w
->frame
);
5920 int window_height_changed_p
= 0;
5922 xassert (MINI_WINDOW_P (w
));
5924 /* Nil means don't try to resize. */
5925 if (NILP (Vmax_mini_window_height
)
5926 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
5929 if (!FRAME_MINIBUF_ONLY_P (f
))
5932 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5933 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
5934 int height
, max_height
;
5935 int unit
= CANON_Y_UNIT (f
);
5936 struct text_pos start
;
5938 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
5940 /* Compute the max. number of lines specified by the user. */
5941 if (FLOATP (Vmax_mini_window_height
))
5942 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
5943 else if (INTEGERP (Vmax_mini_window_height
))
5944 max_height
= XINT (Vmax_mini_window_height
);
5946 max_height
= total_height
/ 4;
5948 /* Correct that max. height if it's bogus. */
5949 max_height
= max (1, max_height
);
5950 max_height
= min (total_height
, max_height
);
5952 /* Find out the height of the text in the window. */
5953 if (it
.truncate_lines_p
)
5958 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
5959 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
5960 height
= it
.current_y
+ last_height
;
5962 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
5963 height
-= it
.extra_line_spacing
;
5964 height
= (height
+ unit
- 1) / unit
;
5967 /* Compute a suitable window start. */
5968 if (height
> max_height
)
5970 height
= max_height
;
5971 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
5972 move_it_vertically_backward (&it
, (height
- 1) * unit
);
5973 start
= it
.current
.pos
;
5976 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5977 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
5979 /* Let it grow only, until we display an empty message, in which
5980 case the window shrinks again. */
5981 if (height
> XFASTINT (w
->height
))
5983 int old_height
= XFASTINT (w
->height
);
5984 freeze_window_starts (f
, 1);
5985 grow_mini_window (w
, height
- XFASTINT (w
->height
));
5986 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5988 else if (height
< XFASTINT (w
->height
)
5989 && (exact_p
|| BEGV
== ZV
))
5991 int old_height
= XFASTINT (w
->height
);
5992 freeze_window_starts (f
, 0);
5993 shrink_mini_window (w
);
5994 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5998 return window_height_changed_p
;
6002 /* Value is the current message, a string, or nil if there is no
6010 if (NILP (echo_area_buffer
[0]))
6014 with_echo_area_buffer (0, 0, current_message_1
,
6015 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6017 echo_area_buffer
[0] = Qnil
;
6025 current_message_1 (a1
, a2
, a3
, a4
)
6030 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6033 *msg
= make_buffer_string (BEG
, Z
, 1);
6040 /* Push the current message on Vmessage_stack for later restauration
6041 by restore_message. Value is non-zero if the current message isn't
6042 empty. This is a relatively infrequent operation, so it's not
6043 worth optimizing. */
6049 msg
= current_message ();
6050 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6051 return STRINGP (msg
);
6055 /* Restore message display from the top of Vmessage_stack. */
6062 xassert (CONSP (Vmessage_stack
));
6063 msg
= XCAR (Vmessage_stack
);
6065 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6067 message3_nolog (msg
, 0, 0);
6071 /* Pop the top-most entry off Vmessage_stack. */
6076 xassert (CONSP (Vmessage_stack
));
6077 Vmessage_stack
= XCDR (Vmessage_stack
);
6081 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6082 exits. If the stack is not empty, we have a missing pop_message
6086 check_message_stack ()
6088 if (!NILP (Vmessage_stack
))
6093 /* Truncate to NCHARS what will be displayed in the echo area the next
6094 time we display it---but don't redisplay it now. */
6097 truncate_echo_area (nchars
)
6101 echo_area_buffer
[0] = Qnil
;
6102 /* A null message buffer means that the frame hasn't really been
6103 initialized yet. Error messages get reported properly by
6104 cmd_error, so this must be just an informative message; toss it. */
6105 else if (!noninteractive
6107 && !NILP (echo_area_buffer
[0]))
6109 struct frame
*sf
= SELECTED_FRAME ();
6110 if (FRAME_MESSAGE_BUF (sf
))
6111 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6116 /* Helper function for truncate_echo_area. Truncate the current
6117 message to at most NCHARS characters. */
6120 truncate_message_1 (nchars
, a2
, a3
, a4
)
6125 if (BEG
+ nchars
< Z
)
6126 del_range (BEG
+ nchars
, Z
);
6128 echo_area_buffer
[0] = Qnil
;
6133 /* Set the current message to a substring of S or STRING.
6135 If STRING is a Lisp string, set the message to the first NBYTES
6136 bytes from STRING. NBYTES zero means use the whole string. If
6137 STRING is multibyte, the message will be displayed multibyte.
6139 If S is not null, set the message to the first LEN bytes of S. LEN
6140 zero means use the whole string. MULTIBYTE_P non-zero means S is
6141 multibyte. Display the message multibyte in that case. */
6144 set_message (s
, string
, nbytes
, multibyte_p
)
6149 message_enable_multibyte
6150 = ((s
&& multibyte_p
)
6151 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6153 with_echo_area_buffer (0, -1, set_message_1
,
6154 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6155 message_buf_print
= 0;
6159 /* Helper function for set_message. Arguments have the same meaning
6160 as there, with A1 corresponding to S and A2 corresponding to STRING
6161 This function is called with the echo area buffer being
6165 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6168 EMACS_INT nbytes
, multibyte_p
;
6170 char *s
= (char *) a1
;
6171 Lisp_Object string
= a2
;
6175 /* Change multibyteness of the echo buffer appropriately. */
6176 if (message_enable_multibyte
6177 != !NILP (current_buffer
->enable_multibyte_characters
))
6178 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6180 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6182 /* Insert new message at BEG. */
6183 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6185 if (STRINGP (string
))
6190 nbytes
= XSTRING (string
)->size_byte
;
6191 nchars
= string_byte_to_char (string
, nbytes
);
6193 /* This function takes care of single/multibyte conversion. We
6194 just have to ensure that the echo area buffer has the right
6195 setting of enable_multibyte_characters. */
6196 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6201 nbytes
= strlen (s
);
6203 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6205 /* Convert from multi-byte to single-byte. */
6207 unsigned char work
[1];
6209 /* Convert a multibyte string to single-byte. */
6210 for (i
= 0; i
< nbytes
; i
+= n
)
6212 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6213 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6215 : multibyte_char_to_unibyte (c
, Qnil
));
6216 insert_1_both (work
, 1, 1, 1, 0, 0);
6219 else if (!multibyte_p
6220 && !NILP (current_buffer
->enable_multibyte_characters
))
6222 /* Convert from single-byte to multi-byte. */
6224 unsigned char *msg
= (unsigned char *) s
;
6225 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6227 /* Convert a single-byte string to multibyte. */
6228 for (i
= 0; i
< nbytes
; i
++)
6230 c
= unibyte_char_to_multibyte (msg
[i
]);
6231 n
= CHAR_STRING (c
, str
);
6232 insert_1_both (str
, 1, n
, 1, 0, 0);
6236 insert_1 (s
, nbytes
, 1, 0, 0);
6243 /* Clear messages. CURRENT_P non-zero means clear the current
6244 message. LAST_DISPLAYED_P non-zero means clear the message
6248 clear_message (current_p
, last_displayed_p
)
6249 int current_p
, last_displayed_p
;
6252 echo_area_buffer
[0] = Qnil
;
6254 if (last_displayed_p
)
6255 echo_area_buffer
[1] = Qnil
;
6257 message_buf_print
= 0;
6260 /* Clear garbaged frames.
6262 This function is used where the old redisplay called
6263 redraw_garbaged_frames which in turn called redraw_frame which in
6264 turn called clear_frame. The call to clear_frame was a source of
6265 flickering. I believe a clear_frame is not necessary. It should
6266 suffice in the new redisplay to invalidate all current matrices,
6267 and ensure a complete redisplay of all windows. */
6270 clear_garbaged_frames ()
6274 Lisp_Object tail
, frame
;
6276 FOR_EACH_FRAME (tail
, frame
)
6278 struct frame
*f
= XFRAME (frame
);
6280 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6282 clear_current_matrices (f
);
6288 ++windows_or_buffers_changed
;
6293 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6294 is non-zero update selected_frame. Value is non-zero if the
6295 mini-windows height has been changed. */
6298 echo_area_display (update_frame_p
)
6301 Lisp_Object mini_window
;
6304 int window_height_changed_p
= 0;
6305 struct frame
*sf
= SELECTED_FRAME ();
6307 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6308 w
= XWINDOW (mini_window
);
6309 f
= XFRAME (WINDOW_FRAME (w
));
6311 /* Don't display if frame is invisible or not yet initialized. */
6312 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6315 #ifdef HAVE_WINDOW_SYSTEM
6316 /* When Emacs starts, selected_frame may be a visible terminal
6317 frame, even if we run under a window system. If we let this
6318 through, a message would be displayed on the terminal. */
6319 if (EQ (selected_frame
, Vterminal_frame
)
6320 && !NILP (Vwindow_system
))
6322 #endif /* HAVE_WINDOW_SYSTEM */
6324 /* Redraw garbaged frames. */
6326 clear_garbaged_frames ();
6328 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6330 echo_area_window
= mini_window
;
6331 window_height_changed_p
= display_echo_area (w
);
6332 w
->must_be_updated_p
= 1;
6334 /* Update the display, unless called from redisplay_internal. */
6339 /* If the display update has been interrupted by pending
6340 input, update mode lines in the frame. Due to the
6341 pending input, it might have been that redisplay hasn't
6342 been called, so that mode lines above the echo area are
6343 garbaged. This looks odd, so we prevent it here. */
6344 if (!display_completed
)
6345 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
6347 if (window_height_changed_p
)
6349 /* Must update other windows. */
6350 windows_or_buffers_changed
= 1;
6351 redisplay_internal (0);
6353 else if (FRAME_WINDOW_P (f
) && n
== 0)
6355 /* Window configuration is the same as before.
6356 Can do with a display update of the echo area,
6357 unless we displayed some mode lines. */
6358 update_single_window (w
, 1);
6359 rif
->flush_display (f
);
6362 update_frame (f
, 1, 1);
6365 else if (!EQ (mini_window
, selected_window
))
6366 windows_or_buffers_changed
++;
6368 /* Last displayed message is now the current message. */
6369 echo_area_buffer
[1] = echo_area_buffer
[0];
6371 /* Prevent redisplay optimization in redisplay_internal by resetting
6372 this_line_start_pos. This is done because the mini-buffer now
6373 displays the message instead of its buffer text. */
6374 if (EQ (mini_window
, selected_window
))
6375 CHARPOS (this_line_start_pos
) = 0;
6377 return window_height_changed_p
;
6382 /***********************************************************************
6384 ***********************************************************************/
6387 #ifdef HAVE_WINDOW_SYSTEM
6389 /* A buffer for constructing frame titles in it; allocated from the
6390 heap in init_xdisp and resized as needed in store_frame_title_char. */
6392 static char *frame_title_buf
;
6394 /* The buffer's end, and a current output position in it. */
6396 static char *frame_title_buf_end
;
6397 static char *frame_title_ptr
;
6400 /* Store a single character C for the frame title in frame_title_buf.
6401 Re-allocate frame_title_buf if necessary. */
6404 store_frame_title_char (c
)
6407 /* If output position has reached the end of the allocated buffer,
6408 double the buffer's size. */
6409 if (frame_title_ptr
== frame_title_buf_end
)
6411 int len
= frame_title_ptr
- frame_title_buf
;
6412 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6413 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6414 frame_title_buf_end
= frame_title_buf
+ new_size
;
6415 frame_title_ptr
= frame_title_buf
+ len
;
6418 *frame_title_ptr
++ = c
;
6422 /* Store part of a frame title in frame_title_buf, beginning at
6423 frame_title_ptr. STR is the string to store. Do not copy more
6424 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
6425 the whole string. Pad with spaces until FIELD_WIDTH number of
6426 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
6427 Called from display_mode_element when it is used to build a frame
6431 store_frame_title (str
, field_width
, precision
)
6433 int field_width
, precision
;
6437 /* Copy at most PRECISION chars from STR. */
6438 while ((precision
<= 0 || n
< precision
)
6441 store_frame_title_char (*str
++);
6445 /* Fill up with spaces until FIELD_WIDTH reached. */
6446 while (field_width
> 0
6449 store_frame_title_char (' ');
6457 /* Set the title of FRAME, if it has changed. The title format is
6458 Vicon_title_format if FRAME is iconified, otherwise it is
6459 frame_title_format. */
6462 x_consider_frame_title (frame
)
6465 struct frame
*f
= XFRAME (frame
);
6467 if (FRAME_WINDOW_P (f
)
6468 || FRAME_MINIBUF_ONLY_P (f
)
6469 || f
->explicit_name
)
6471 /* Do we have more than one visible frame on this X display? */
6474 struct buffer
*obuf
;
6478 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
6480 struct frame
*tf
= XFRAME (XCAR (tail
));
6483 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
6484 && !FRAME_MINIBUF_ONLY_P (tf
)
6485 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
6489 /* Set global variable indicating that multiple frames exist. */
6490 multiple_frames
= CONSP (tail
);
6492 /* Switch to the buffer of selected window of the frame. Set up
6493 frame_title_ptr so that display_mode_element will output into it;
6494 then display the title. */
6495 obuf
= current_buffer
;
6496 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
6497 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
6498 frame_title_ptr
= frame_title_buf
;
6499 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
6500 NULL
, DEFAULT_FACE_ID
);
6501 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
6502 frame_title_ptr
= NULL
;
6503 set_buffer_internal (obuf
);
6505 /* Set the title only if it's changed. This avoids consing in
6506 the common case where it hasn't. (If it turns out that we've
6507 already wasted too much time by walking through the list with
6508 display_mode_element, then we might need to optimize at a
6509 higher level than this.) */
6510 if (! STRINGP (f
->name
)
6511 || STRING_BYTES (XSTRING (f
->name
)) != len
6512 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
6513 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
6517 #else /* not HAVE_WINDOW_SYSTEM */
6519 #define frame_title_ptr ((char *)0)
6520 #define store_frame_title(str, mincol, maxcol) 0
6522 #endif /* not HAVE_WINDOW_SYSTEM */
6527 /***********************************************************************
6529 ***********************************************************************/
6532 /* Prepare for redisplay by updating menu-bar item lists when
6533 appropriate. This can call eval. */
6536 prepare_menu_bars ()
6539 struct gcpro gcpro1
, gcpro2
;
6541 struct frame
*tooltip_frame
;
6543 #ifdef HAVE_X_WINDOWS
6544 tooltip_frame
= tip_frame
;
6546 tooltip_frame
= NULL
;
6549 /* Update all frame titles based on their buffer names, etc. We do
6550 this before the menu bars so that the buffer-menu will show the
6551 up-to-date frame titles. */
6552 #ifdef HAVE_WINDOW_SYSTEM
6553 if (windows_or_buffers_changed
|| update_mode_lines
)
6555 Lisp_Object tail
, frame
;
6557 FOR_EACH_FRAME (tail
, frame
)
6560 if (f
!= tooltip_frame
6561 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
6562 x_consider_frame_title (frame
);
6565 #endif /* HAVE_WINDOW_SYSTEM */
6567 /* Update the menu bar item lists, if appropriate. This has to be
6568 done before any actual redisplay or generation of display lines. */
6569 all_windows
= (update_mode_lines
6570 || buffer_shared
> 1
6571 || windows_or_buffers_changed
);
6574 Lisp_Object tail
, frame
;
6575 int count
= specpdl_ptr
- specpdl
;
6577 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6579 FOR_EACH_FRAME (tail
, frame
)
6583 /* Ignore tooltip frame. */
6584 if (f
== tooltip_frame
)
6587 /* If a window on this frame changed size, report that to
6588 the user and clear the size-change flag. */
6589 if (FRAME_WINDOW_SIZES_CHANGED (f
))
6591 Lisp_Object functions
;
6593 /* Clear flag first in case we get an error below. */
6594 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
6595 functions
= Vwindow_size_change_functions
;
6596 GCPRO2 (tail
, functions
);
6598 while (CONSP (functions
))
6600 call1 (XCAR (functions
), frame
);
6601 functions
= XCDR (functions
);
6607 update_menu_bar (f
, 0);
6608 #ifdef HAVE_WINDOW_SYSTEM
6609 update_tool_bar (f
, 0);
6614 unbind_to (count
, Qnil
);
6618 struct frame
*sf
= SELECTED_FRAME ();
6619 update_menu_bar (sf
, 1);
6620 #ifdef HAVE_WINDOW_SYSTEM
6621 update_tool_bar (sf
, 1);
6625 /* Motif needs this. See comment in xmenu.c. Turn it off when
6626 pending_menu_activation is not defined. */
6627 #ifdef USE_X_TOOLKIT
6628 pending_menu_activation
= 0;
6633 /* Update the menu bar item list for frame F. This has to be done
6634 before we start to fill in any display lines, because it can call
6637 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
6640 update_menu_bar (f
, save_match_data
)
6642 int save_match_data
;
6645 register struct window
*w
;
6647 window
= FRAME_SELECTED_WINDOW (f
);
6648 w
= XWINDOW (window
);
6650 if (update_mode_lines
)
6651 w
->update_mode_line
= Qt
;
6653 if (FRAME_WINDOW_P (f
)
6655 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6656 FRAME_EXTERNAL_MENU_BAR (f
)
6658 FRAME_MENU_BAR_LINES (f
) > 0
6660 : FRAME_MENU_BAR_LINES (f
) > 0)
6662 /* If the user has switched buffers or windows, we need to
6663 recompute to reflect the new bindings. But we'll
6664 recompute when update_mode_lines is set too; that means
6665 that people can use force-mode-line-update to request
6666 that the menu bar be recomputed. The adverse effect on
6667 the rest of the redisplay algorithm is about the same as
6668 windows_or_buffers_changed anyway. */
6669 if (windows_or_buffers_changed
6670 || !NILP (w
->update_mode_line
)
6671 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6672 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6673 != !NILP (w
->last_had_star
))
6674 || ((!NILP (Vtransient_mark_mode
)
6675 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6676 != !NILP (w
->region_showing
)))
6678 struct buffer
*prev
= current_buffer
;
6679 int count
= specpdl_ptr
- specpdl
;
6681 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6682 if (save_match_data
)
6683 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6684 if (NILP (Voverriding_local_map_menu_flag
))
6686 specbind (Qoverriding_terminal_local_map
, Qnil
);
6687 specbind (Qoverriding_local_map
, Qnil
);
6690 /* Run the Lucid hook. */
6691 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
6693 /* If it has changed current-menubar from previous value,
6694 really recompute the menu-bar from the value. */
6695 if (! NILP (Vlucid_menu_bar_dirty_flag
))
6696 call0 (Qrecompute_lucid_menubar
);
6698 safe_run_hooks (Qmenu_bar_update_hook
);
6699 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
6701 /* Redisplay the menu bar in case we changed it. */
6702 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6703 if (FRAME_WINDOW_P (f
))
6704 set_frame_menubar (f
, 0, 0);
6706 /* On a terminal screen, the menu bar is an ordinary screen
6707 line, and this makes it get updated. */
6708 w
->update_mode_line
= Qt
;
6709 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6710 /* In the non-toolkit version, the menu bar is an ordinary screen
6711 line, and this makes it get updated. */
6712 w
->update_mode_line
= Qt
;
6713 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6715 unbind_to (count
, Qnil
);
6716 set_buffer_internal_1 (prev
);
6723 /***********************************************************************
6725 ***********************************************************************/
6727 #ifdef HAVE_WINDOW_SYSTEM
6729 /* Update the tool-bar item list for frame F. This has to be done
6730 before we start to fill in any display lines. Called from
6731 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
6732 and restore it here. */
6735 update_tool_bar (f
, save_match_data
)
6737 int save_match_data
;
6739 if (WINDOWP (f
->tool_bar_window
)
6740 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
6745 window
= FRAME_SELECTED_WINDOW (f
);
6746 w
= XWINDOW (window
);
6748 /* If the user has switched buffers or windows, we need to
6749 recompute to reflect the new bindings. But we'll
6750 recompute when update_mode_lines is set too; that means
6751 that people can use force-mode-line-update to request
6752 that the menu bar be recomputed. The adverse effect on
6753 the rest of the redisplay algorithm is about the same as
6754 windows_or_buffers_changed anyway. */
6755 if (windows_or_buffers_changed
6756 || !NILP (w
->update_mode_line
)
6757 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6758 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6759 != !NILP (w
->last_had_star
))
6760 || ((!NILP (Vtransient_mark_mode
)
6761 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6762 != !NILP (w
->region_showing
)))
6764 struct buffer
*prev
= current_buffer
;
6765 int count
= specpdl_ptr
- specpdl
;
6767 /* Set current_buffer to the buffer of the selected
6768 window of the frame, so that we get the right local
6770 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6772 /* Save match data, if we must. */
6773 if (save_match_data
)
6774 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6776 /* Make sure that we don't accidentally use bogus keymaps. */
6777 if (NILP (Voverriding_local_map_menu_flag
))
6779 specbind (Qoverriding_terminal_local_map
, Qnil
);
6780 specbind (Qoverriding_local_map
, Qnil
);
6783 /* Build desired tool-bar items from keymaps. */
6784 f
->desired_tool_bar_items
6785 = tool_bar_items (f
->desired_tool_bar_items
,
6786 &f
->n_desired_tool_bar_items
);
6788 /* Redisplay the tool-bar in case we changed it. */
6789 w
->update_mode_line
= Qt
;
6791 unbind_to (count
, Qnil
);
6792 set_buffer_internal_1 (prev
);
6798 /* Set F->desired_tool_bar_string to a Lisp string representing frame
6799 F's desired tool-bar contents. F->desired_tool_bar_items must have
6800 been set up previously by calling prepare_menu_bars. */
6803 build_desired_tool_bar_string (f
)
6806 int i
, size
, size_needed
, string_idx
;
6807 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6808 Lisp_Object image
, plist
, props
;
6810 image
= plist
= props
= Qnil
;
6811 GCPRO3 (image
, plist
, props
);
6813 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
6814 Otherwise, make a new string. */
6816 /* The size of the string we might be able to reuse. */
6817 size
= (STRINGP (f
->desired_tool_bar_string
)
6818 ? XSTRING (f
->desired_tool_bar_string
)->size
6821 /* Each image in the string we build is preceded by a space,
6822 and there is a space at the end. */
6823 size_needed
= f
->n_desired_tool_bar_items
+ 1;
6825 /* Reuse f->desired_tool_bar_string, if possible. */
6826 if (size
< size_needed
)
6827 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
6831 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
6832 Fremove_text_properties (make_number (0), make_number (size
),
6833 props
, f
->desired_tool_bar_string
);
6836 /* Put a `display' property on the string for the images to display,
6837 put a `menu_item' property on tool-bar items with a value that
6838 is the index of the item in F's tool-bar item vector. */
6839 for (i
= 0, string_idx
= 0;
6840 i
< f
->n_desired_tool_bar_items
;
6841 ++i
, string_idx
+= 1)
6844 (XVECTOR (f->desired_tool_bar_items) \
6845 ->contents[i * TOOL_BAR_ITEM_NSLOTS + (IDX)])
6847 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
6848 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
6850 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
6851 extern Lisp_Object Qlaplace
;
6853 /* If image is a vector, choose the image according to the
6855 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
6856 if (VECTORP (image
))
6858 enum tool_bar_item_image idx
;
6862 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
6863 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
6866 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
6867 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
6869 xassert (XVECTOR (image
)->size
>= idx
);
6870 image
= XVECTOR (image
)->contents
[idx
];
6873 /* Ignore invalid image specifications. */
6874 if (!valid_image_p (image
))
6877 /* Display the tool-bar button pressed, or depressed. */
6878 plist
= Fcopy_sequence (XCDR (image
));
6880 /* Compute margin and relief to draw. */
6881 relief
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
6882 margin
= relief
+ max (0, tool_bar_button_margin
);
6884 if (auto_raise_tool_bar_buttons_p
)
6886 /* Add a `:relief' property to the image spec if the item is
6890 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
6896 /* If image is selected, display it pressed, i.e. with a
6897 negative relief. If it's not selected, display it with a
6899 plist
= Fplist_put (plist
, QCrelief
,
6901 ? make_number (-relief
)
6902 : make_number (relief
)));
6906 /* Put a margin around the image. */
6908 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
6910 /* If button is not enabled, make the image appear disabled by
6911 applying an appropriate algorithm to it. */
6913 plist
= Fplist_put (plist
, QCalgorithm
, Qlaplace
);
6915 /* Put a `display' text property on the string for the image to
6916 display. Put a `menu-item' property on the string that gives
6917 the start of this item's properties in the tool-bar items
6919 image
= Fcons (Qimage
, plist
);
6920 props
= list4 (Qdisplay
, image
,
6921 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
)),
6922 Fadd_text_properties (make_number (string_idx
),
6923 make_number (string_idx
+ 1),
6924 props
, f
->desired_tool_bar_string
);
6932 /* Display one line of the tool-bar of frame IT->f. */
6935 display_tool_bar_line (it
)
6938 struct glyph_row
*row
= it
->glyph_row
;
6939 int max_x
= it
->last_visible_x
;
6942 prepare_desired_row (row
);
6943 row
->y
= it
->current_y
;
6945 while (it
->current_x
< max_x
)
6947 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
6949 /* Get the next display element. */
6950 if (!get_next_display_element (it
))
6953 /* Produce glyphs. */
6954 x_before
= it
->current_x
;
6955 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
6956 PRODUCE_GLYPHS (it
);
6958 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
6963 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
6965 if (x
+ glyph
->pixel_width
> max_x
)
6967 /* Glyph doesn't fit on line. */
6968 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
6974 x
+= glyph
->pixel_width
;
6978 /* Stop at line ends. */
6979 if (ITERATOR_AT_END_OF_LINE_P (it
))
6982 set_iterator_to_next (it
);
6987 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
6988 extend_face_to_end_of_line (it
);
6989 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
6990 last
->right_box_line_p
= 1;
6991 compute_line_metrics (it
);
6993 /* If line is empty, make it occupy the rest of the tool-bar. */
6994 if (!row
->displays_text_p
)
6996 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
6997 row
->ascent
= row
->phys_ascent
= 0;
7000 row
->full_width_p
= 1;
7001 row
->continued_p
= 0;
7002 row
->truncated_on_left_p
= 0;
7003 row
->truncated_on_right_p
= 0;
7005 it
->current_x
= it
->hpos
= 0;
7006 it
->current_y
+= row
->height
;
7012 /* Value is the number of screen lines needed to make all tool-bar
7013 items of frame F visible. */
7016 tool_bar_lines_needed (f
)
7019 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7022 /* Initialize an iterator for iteration over
7023 F->desired_tool_bar_string in the tool-bar window of frame F. */
7024 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7025 it
.first_visible_x
= 0;
7026 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7027 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7029 while (!ITERATOR_AT_END_P (&it
))
7031 it
.glyph_row
= w
->desired_matrix
->rows
;
7032 clear_glyph_row (it
.glyph_row
);
7033 display_tool_bar_line (&it
);
7036 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7040 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7041 height should be changed. */
7044 redisplay_tool_bar (f
)
7049 struct glyph_row
*row
;
7050 int change_height_p
= 0;
7052 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7053 do anything. This means you must start with tool-bar-lines
7054 non-zero to get the auto-sizing effect. Or in other words, you
7055 can turn off tool-bars by specifying tool-bar-lines zero. */
7056 if (!WINDOWP (f
->tool_bar_window
)
7057 || (w
= XWINDOW (f
->tool_bar_window
),
7058 XFASTINT (w
->height
) == 0))
7061 /* Set up an iterator for the tool-bar window. */
7062 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7063 it
.first_visible_x
= 0;
7064 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7067 /* Build a string that represents the contents of the tool-bar. */
7068 build_desired_tool_bar_string (f
);
7069 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7071 /* Display as many lines as needed to display all tool-bar items. */
7072 while (it
.current_y
< it
.last_visible_y
)
7073 display_tool_bar_line (&it
);
7075 /* It doesn't make much sense to try scrolling in the tool-bar
7076 window, so don't do it. */
7077 w
->desired_matrix
->no_scrolling_p
= 1;
7078 w
->must_be_updated_p
= 1;
7080 if (auto_resize_tool_bars_p
)
7084 /* If there are blank lines at the end, except for a partially
7085 visible blank line at the end that is smaller than
7086 CANON_Y_UNIT, change the tool-bar's height. */
7087 row
= it
.glyph_row
- 1;
7088 if (!row
->displays_text_p
7089 && row
->height
>= CANON_Y_UNIT (f
))
7090 change_height_p
= 1;
7092 /* If row displays tool-bar items, but is partially visible,
7093 change the tool-bar's height. */
7094 if (row
->displays_text_p
7095 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7096 change_height_p
= 1;
7098 /* Resize windows as needed by changing the `tool-bar-lines'
7101 && (nlines
= tool_bar_lines_needed (f
),
7102 nlines
!= XFASTINT (w
->height
)))
7104 extern Lisp_Object Qtool_bar_lines
;
7107 XSETFRAME (frame
, f
);
7108 clear_glyph_matrix (w
->desired_matrix
);
7109 Fmodify_frame_parameters (frame
,
7110 Fcons (Fcons (Qtool_bar_lines
,
7111 make_number (nlines
)),
7113 fonts_changed_p
= 1;
7117 return change_height_p
;
7121 /* Get information about the tool-bar item which is displayed in GLYPH
7122 on frame F. Return in *PROP_IDX the index where tool-bar item
7123 properties start in F->current_tool_bar_items. Value is zero if
7124 GLYPH doesn't display a tool-bar item. */
7127 tool_bar_item_info (f
, glyph
, prop_idx
)
7129 struct glyph
*glyph
;
7135 /* Get the text property `menu-item' at pos. The value of that
7136 property is the start index of this item's properties in
7137 F->current_tool_bar_items. */
7138 prop
= Fget_text_property (make_number (glyph
->charpos
),
7139 Qmenu_item
, f
->current_tool_bar_string
);
7140 if (INTEGERP (prop
))
7142 *prop_idx
= XINT (prop
);
7151 #endif /* HAVE_WINDOW_SYSTEM */
7155 /************************************************************************
7156 Horizontal scrolling
7157 ************************************************************************/
7159 static int hscroll_window_tree
P_ ((Lisp_Object
));
7160 static int hscroll_windows
P_ ((Lisp_Object
));
7162 /* For all leaf windows in the window tree rooted at WINDOW, set their
7163 hscroll value so that PT is (i) visible in the window, and (ii) so
7164 that it is not within a certain margin at the window's left and
7165 right border. Value is non-zero if any window's hscroll has been
7169 hscroll_window_tree (window
)
7172 int hscrolled_p
= 0;
7174 while (WINDOWP (window
))
7176 struct window
*w
= XWINDOW (window
);
7178 if (WINDOWP (w
->hchild
))
7179 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7180 else if (WINDOWP (w
->vchild
))
7181 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7182 else if (w
->cursor
.vpos
>= 0)
7184 int hscroll_margin
, text_area_x
, text_area_y
;
7185 int text_area_width
, text_area_height
;
7186 struct glyph_row
*current_cursor_row
7187 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7188 struct glyph_row
*desired_cursor_row
7189 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7190 struct glyph_row
*cursor_row
7191 = (desired_cursor_row
->enabled_p
7192 ? desired_cursor_row
7193 : current_cursor_row
);
7195 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7196 &text_area_width
, &text_area_height
);
7198 /* Scroll when cursor is inside this scroll margin. */
7199 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
7201 if ((XFASTINT (w
->hscroll
)
7202 && w
->cursor
.x
< hscroll_margin
)
7203 || (cursor_row
->enabled_p
7204 && cursor_row
->truncated_on_right_p
7205 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
7209 struct buffer
*saved_current_buffer
;
7212 /* Find point in a display of infinite width. */
7213 saved_current_buffer
= current_buffer
;
7214 current_buffer
= XBUFFER (w
->buffer
);
7216 if (w
== XWINDOW (selected_window
))
7217 pt
= BUF_PT (current_buffer
);
7220 pt
= marker_position (w
->pointm
);
7221 pt
= max (BEGV
, pt
);
7225 /* Move iterator to pt starting at cursor_row->start in
7226 a line with infinite width. */
7227 init_to_row_start (&it
, w
, cursor_row
);
7228 it
.last_visible_x
= INFINITY
;
7229 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
7230 current_buffer
= saved_current_buffer
;
7232 /* Center cursor in window. */
7233 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
7234 / CANON_X_UNIT (it
.f
));
7236 /* Don't call Fset_window_hscroll if value hasn't
7237 changed because it will prevent redisplay
7239 if (XFASTINT (w
->hscroll
) != hscroll
)
7241 Fset_window_hscroll (window
, make_number (hscroll
));
7250 /* Value is non-zero if hscroll of any leaf window has been changed. */
7255 /* Set hscroll so that cursor is visible and not inside horizontal
7256 scroll margins for all windows in the tree rooted at WINDOW. See
7257 also hscroll_window_tree above. Value is non-zero if any window's
7258 hscroll has been changed. If it has, desired matrices on the frame
7259 of WINDOW are cleared. */
7262 hscroll_windows (window
)
7267 if (automatic_hscrolling_p
)
7269 hscrolled_p
= hscroll_window_tree (window
);
7271 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
7280 /************************************************************************
7282 ************************************************************************/
7284 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
7285 to a non-zero value. This is sometimes handy to have in a debugger
7290 /* First and last unchanged row for try_window_id. */
7292 int debug_first_unchanged_at_end_vpos
;
7293 int debug_last_unchanged_at_beg_vpos
;
7295 /* Delta vpos and y. */
7297 int debug_dvpos
, debug_dy
;
7299 /* Delta in characters and bytes for try_window_id. */
7301 int debug_delta
, debug_delta_bytes
;
7303 /* Values of window_end_pos and window_end_vpos at the end of
7306 int debug_end_pos
, debug_end_vpos
;
7308 /* Append a string to W->desired_matrix->method. FMT is a printf
7309 format string. A1...A9 are a supplement for a variable-length
7310 argument list. If trace_redisplay_p is non-zero also printf the
7311 resulting string to stderr. */
7314 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
7317 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
7320 char *method
= w
->desired_matrix
->method
;
7321 int len
= strlen (method
);
7322 int size
= sizeof w
->desired_matrix
->method
;
7323 int remaining
= size
- len
- 1;
7325 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
7326 if (len
&& remaining
)
7332 strncpy (method
+ len
, buffer
, remaining
);
7334 if (trace_redisplay_p
)
7335 fprintf (stderr
, "%p (%s): %s\n",
7337 ((BUFFERP (w
->buffer
)
7338 && STRINGP (XBUFFER (w
->buffer
)->name
))
7339 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
7344 #endif /* GLYPH_DEBUG */
7347 /* This counter is used to clear the face cache every once in a while
7348 in redisplay_internal. It is incremented for each redisplay.
7349 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
7352 #define CLEAR_FACE_CACHE_COUNT 10000
7353 static int clear_face_cache_count
;
7355 /* Record the previous terminal frame we displayed. */
7357 static struct frame
*previous_terminal_frame
;
7359 /* Non-zero while redisplay_internal is in progress. */
7364 /* Value is non-zero if all changes in window W, which displays
7365 current_buffer, are in the text between START and END. START is a
7366 buffer position, END is given as a distance from Z. Used in
7367 redisplay_internal for display optimization. */
7370 text_outside_line_unchanged_p (w
, start
, end
)
7374 int unchanged_p
= 1;
7376 /* If text or overlays have changed, see where. */
7377 if (XFASTINT (w
->last_modified
) < MODIFF
7378 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7380 /* Gap in the line? */
7381 if (GPT
< start
|| Z
- GPT
< end
)
7384 /* Changes start in front of the line, or end after it? */
7386 && (BEG_UNCHANGED
< start
- 1
7387 || END_UNCHANGED
< end
))
7390 /* If selective display, can't optimize if changes start at the
7391 beginning of the line. */
7393 && INTEGERP (current_buffer
->selective_display
)
7394 && XINT (current_buffer
->selective_display
) > 0
7395 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
7403 /* Do a frame update, taking possible shortcuts into account. This is
7404 the main external entry point for redisplay.
7406 If the last redisplay displayed an echo area message and that message
7407 is no longer requested, we clear the echo area or bring back the
7408 mini-buffer if that is in use. */
7413 redisplay_internal (0);
7416 /* Return 1 if point moved out of or into a composition. Otherwise
7417 return 0. PREV_BUF and PREV_PT are the last point buffer and
7418 position. BUF and PT are the current point buffer and position. */
7421 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
7422 struct buffer
*prev_buf
, *buf
;
7429 XSETBUFFER (buffer
, buf
);
7430 /* Check a composition at the last point if point moved within the
7432 if (prev_buf
== buf
)
7435 /* Point didn't move. */
7438 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
7439 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
7440 && COMPOSITION_VALID_P (start
, end
, prop
)
7441 && start
< prev_pt
&& end
> prev_pt
)
7442 /* The last point was within the composition. Return 1 iff
7443 point moved out of the composition. */
7444 return (pt
<= start
|| pt
>= end
);
7447 /* Check a composition at the current point. */
7448 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
7449 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
7450 && COMPOSITION_VALID_P (start
, end
, prop
)
7451 && start
< pt
&& end
> pt
);
7454 /* Reconsider the setting of B->clip_changed which is displayed
7458 reconsider_clip_changes (w
, b
)
7462 if (b
->prevent_redisplay_optimizations_p
)
7463 b
->clip_changed
= 1;
7464 else if (b
->clip_changed
7465 && !NILP (w
->window_end_valid
)
7466 && w
->current_matrix
->buffer
== b
7467 && w
->current_matrix
->zv
== BUF_ZV (b
)
7468 && w
->current_matrix
->begv
== BUF_BEGV (b
))
7469 b
->clip_changed
= 0;
7471 /* If display wasn't paused, and W is not a tool bar window, see if
7472 point has been moved into or out of a composition. In that case,
7473 we set b->clip_changed to 1 to force updating the screen. If
7474 b->clip_changed has already been set to 1, we can skip this
7476 if (!b
->clip_changed
7477 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
7481 if (w
== XWINDOW (selected_window
))
7482 pt
= BUF_PT (current_buffer
);
7484 pt
= marker_position (w
->pointm
);
7486 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
7487 || pt
!= XINT (w
->last_point
))
7488 && check_point_in_composition (w
->current_matrix
->buffer
,
7489 XINT (w
->last_point
),
7490 XBUFFER (w
->buffer
), pt
))
7491 b
->clip_changed
= 1;
7496 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
7497 response to any user action; therefore, we should preserve the echo
7498 area. (Actually, our caller does that job.) Perhaps in the future
7499 avoid recentering windows if it is not necessary; currently that
7500 causes some problems. */
7503 redisplay_internal (preserve_echo_area
)
7504 int preserve_echo_area
;
7506 struct window
*w
= XWINDOW (selected_window
);
7507 struct frame
*f
= XFRAME (w
->frame
);
7509 int must_finish
= 0;
7510 struct text_pos tlbufpos
, tlendpos
;
7511 int number_of_visible_frames
;
7513 struct frame
*sf
= SELECTED_FRAME ();
7515 /* Non-zero means redisplay has to consider all windows on all
7516 frames. Zero means, only selected_window is considered. */
7517 int consider_all_windows_p
;
7519 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
7521 /* No redisplay if running in batch mode or frame is not yet fully
7522 initialized, or redisplay is explicitly turned off by setting
7523 Vinhibit_redisplay. */
7525 || !NILP (Vinhibit_redisplay
)
7526 || !f
->glyphs_initialized_p
)
7529 /* The flag redisplay_performed_directly_p is set by
7530 direct_output_for_insert when it already did the whole screen
7531 update necessary. */
7532 if (redisplay_performed_directly_p
)
7534 redisplay_performed_directly_p
= 0;
7535 if (!hscroll_windows (selected_window
))
7539 #ifdef USE_X_TOOLKIT
7540 if (popup_activated ())
7544 /* I don't think this happens but let's be paranoid. */
7548 /* Record a function that resets redisplaying_p to its old value
7549 when we leave this function. */
7550 count
= specpdl_ptr
- specpdl
;
7551 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
7556 reconsider_clip_changes (w
, current_buffer
);
7558 /* If new fonts have been loaded that make a glyph matrix adjustment
7559 necessary, do it. */
7560 if (fonts_changed_p
)
7562 adjust_glyphs (NULL
);
7563 ++windows_or_buffers_changed
;
7564 fonts_changed_p
= 0;
7567 if (! FRAME_WINDOW_P (sf
)
7568 && previous_terminal_frame
!= sf
)
7570 /* Since frames on an ASCII terminal share the same display
7571 area, displaying a different frame means redisplay the whole
7573 windows_or_buffers_changed
++;
7574 SET_FRAME_GARBAGED (sf
);
7575 XSETFRAME (Vterminal_frame
, sf
);
7577 previous_terminal_frame
= sf
;
7579 /* Set the visible flags for all frames. Do this before checking
7580 for resized or garbaged frames; they want to know if their frames
7581 are visible. See the comment in frame.h for
7582 FRAME_SAMPLE_VISIBILITY. */
7584 Lisp_Object tail
, frame
;
7586 number_of_visible_frames
= 0;
7588 FOR_EACH_FRAME (tail
, frame
)
7590 struct frame
*f
= XFRAME (frame
);
7592 FRAME_SAMPLE_VISIBILITY (f
);
7593 if (FRAME_VISIBLE_P (f
))
7594 ++number_of_visible_frames
;
7595 clear_desired_matrices (f
);
7599 /* Notice any pending interrupt request to change frame size. */
7600 do_pending_window_change (1);
7602 /* Clear frames marked as garbaged. */
7604 clear_garbaged_frames ();
7606 /* Build menubar and tool-bar items. */
7607 prepare_menu_bars ();
7609 if (windows_or_buffers_changed
)
7610 update_mode_lines
++;
7612 /* Detect case that we need to write or remove a star in the mode line. */
7613 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
7615 w
->update_mode_line
= Qt
;
7616 if (buffer_shared
> 1)
7617 update_mode_lines
++;
7620 /* If %c is in the mode line, update it if needed. */
7621 if (!NILP (w
->column_number_displayed
)
7622 /* This alternative quickly identifies a common case
7623 where no change is needed. */
7624 && !(PT
== XFASTINT (w
->last_point
)
7625 && XFASTINT (w
->last_modified
) >= MODIFF
7626 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7627 && XFASTINT (w
->column_number_displayed
) != current_column ())
7628 w
->update_mode_line
= Qt
;
7630 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
7632 /* The variable buffer_shared is set in redisplay_window and
7633 indicates that we redisplay a buffer in different windows. See
7635 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
7637 /* If specs for an arrow have changed, do thorough redisplay
7638 to ensure we remove any arrow that should no longer exist. */
7639 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
7640 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
7641 consider_all_windows_p
= windows_or_buffers_changed
= 1;
7643 /* Normally the message* functions will have already displayed and
7644 updated the echo area, but the frame may have been trashed, or
7645 the update may have been preempted, so display the echo area
7646 again here. Checking both message buffers captures the case that
7647 the echo area should be cleared. */
7648 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
7650 int window_height_changed_p
= echo_area_display (0);
7653 if (fonts_changed_p
)
7655 else if (window_height_changed_p
)
7657 consider_all_windows_p
= 1;
7658 ++update_mode_lines
;
7659 ++windows_or_buffers_changed
;
7661 /* If window configuration was changed, frames may have been
7662 marked garbaged. Clear them or we will experience
7663 surprises wrt scrolling. */
7665 clear_garbaged_frames ();
7668 else if (EQ (selected_window
, minibuf_window
)
7669 && (current_buffer
->clip_changed
7670 || XFASTINT (w
->last_modified
) < MODIFF
7671 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7672 && resize_mini_window (w
, 0))
7674 /* Resized active mini-window to fit the size of what it is
7675 showing if its contents might have changed. */
7677 consider_all_windows_p
= 1;
7678 ++windows_or_buffers_changed
;
7679 ++update_mode_lines
;
7681 /* If window configuration was changed, frames may have been
7682 marked garbaged. Clear them or we will experience
7683 surprises wrt scrolling. */
7685 clear_garbaged_frames ();
7689 /* If showing the region, and mark has changed, we must redisplay
7690 the whole window. The assignment to this_line_start_pos prevents
7691 the optimization directly below this if-statement. */
7692 if (((!NILP (Vtransient_mark_mode
)
7693 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7694 != !NILP (w
->region_showing
))
7695 || (!NILP (w
->region_showing
)
7696 && !EQ (w
->region_showing
,
7697 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
7698 CHARPOS (this_line_start_pos
) = 0;
7700 /* Optimize the case that only the line containing the cursor in the
7701 selected window has changed. Variables starting with this_ are
7702 set in display_line and record information about the line
7703 containing the cursor. */
7704 tlbufpos
= this_line_start_pos
;
7705 tlendpos
= this_line_end_pos
;
7706 if (!consider_all_windows_p
7707 && CHARPOS (tlbufpos
) > 0
7708 && NILP (w
->update_mode_line
)
7709 && !current_buffer
->clip_changed
7710 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
7711 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
7712 /* Make sure recorded data applies to current buffer, etc. */
7713 && this_line_buffer
== current_buffer
7714 && current_buffer
== XBUFFER (w
->buffer
)
7715 && NILP (w
->force_start
)
7716 /* Point must be on the line that we have info recorded about. */
7717 && PT
>= CHARPOS (tlbufpos
)
7718 && PT
<= Z
- CHARPOS (tlendpos
)
7719 /* All text outside that line, including its final newline,
7720 must be unchanged */
7721 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
7722 CHARPOS (tlendpos
)))
7724 if (CHARPOS (tlbufpos
) > BEGV
7725 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
7726 && (CHARPOS (tlbufpos
) == ZV
7727 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
7728 /* Former continuation line has disappeared by becoming empty */
7730 else if (XFASTINT (w
->last_modified
) < MODIFF
7731 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
7732 || MINI_WINDOW_P (w
))
7734 /* We have to handle the case of continuation around a
7735 wide-column character (See the comment in indent.c around
7738 For instance, in the following case:
7740 -------- Insert --------
7741 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
7742 J_I_ ==> J_I_ `^^' are cursors.
7746 As we have to redraw the line above, we should goto cancel. */
7749 int line_height_before
= this_line_pixel_height
;
7751 /* Note that start_display will handle the case that the
7752 line starting at tlbufpos is a continuation lines. */
7753 start_display (&it
, w
, tlbufpos
);
7755 /* Implementation note: It this still necessary? */
7756 if (it
.current_x
!= this_line_start_x
)
7759 TRACE ((stderr
, "trying display optimization 1\n"));
7760 w
->cursor
.vpos
= -1;
7761 overlay_arrow_seen
= 0;
7762 it
.vpos
= this_line_vpos
;
7763 it
.current_y
= this_line_y
;
7764 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
7767 /* If line contains point, is not continued,
7768 and ends at same distance from eob as before, we win */
7769 if (w
->cursor
.vpos
>= 0
7770 /* Line is not continued, otherwise this_line_start_pos
7771 would have been set to 0 in display_line. */
7772 && CHARPOS (this_line_start_pos
)
7773 /* Line ends as before. */
7774 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
7775 /* Line has same height as before. Otherwise other lines
7776 would have to be shifted up or down. */
7777 && this_line_pixel_height
== line_height_before
)
7779 /* If this is not the window's last line, we must adjust
7780 the charstarts of the lines below. */
7781 if (it
.current_y
< it
.last_visible_y
)
7783 struct glyph_row
*row
7784 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
7785 int delta
, delta_bytes
;
7787 if (Z
- CHARPOS (tlendpos
) == ZV
)
7789 /* This line ends at end of (accessible part of)
7790 buffer. There is no newline to count. */
7792 - CHARPOS (tlendpos
)
7793 - MATRIX_ROW_START_CHARPOS (row
));
7794 delta_bytes
= (Z_BYTE
7795 - BYTEPOS (tlendpos
)
7796 - MATRIX_ROW_START_BYTEPOS (row
));
7800 /* This line ends in a newline. Must take
7801 account of the newline and the rest of the
7802 text that follows. */
7804 - CHARPOS (tlendpos
)
7805 - MATRIX_ROW_START_CHARPOS (row
));
7806 delta_bytes
= (Z_BYTE
7807 - BYTEPOS (tlendpos
)
7808 - MATRIX_ROW_START_BYTEPOS (row
));
7811 increment_matrix_positions (w
->current_matrix
,
7813 w
->current_matrix
->nrows
,
7814 delta
, delta_bytes
);
7817 /* If this row displays text now but previously didn't,
7818 or vice versa, w->window_end_vpos may have to be
7820 if ((it
.glyph_row
- 1)->displays_text_p
)
7822 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
7823 XSETINT (w
->window_end_vpos
, this_line_vpos
);
7825 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
7826 && this_line_vpos
> 0)
7827 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
7828 w
->window_end_valid
= Qnil
;
7830 /* Update hint: No need to try to scroll in update_window. */
7831 w
->desired_matrix
->no_scrolling_p
= 1;
7834 *w
->desired_matrix
->method
= 0;
7835 debug_method_add (w
, "optimization 1");
7842 else if (/* Cursor position hasn't changed. */
7843 PT
== XFASTINT (w
->last_point
)
7844 /* Make sure the cursor was last displayed
7845 in this window. Otherwise we have to reposition it. */
7846 && 0 <= w
->cursor
.vpos
7847 && XINT (w
->height
) > w
->cursor
.vpos
)
7851 do_pending_window_change (1);
7853 /* We used to always goto end_of_redisplay here, but this
7854 isn't enough if we have a blinking cursor. */
7855 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
7856 goto end_of_redisplay
;
7860 /* If highlighting the region, or if the cursor is in the echo area,
7861 then we can't just move the cursor. */
7862 else if (! (!NILP (Vtransient_mark_mode
)
7863 && !NILP (current_buffer
->mark_active
))
7864 && (EQ (selected_window
, current_buffer
->last_selected_window
)
7865 || highlight_nonselected_windows
)
7866 && NILP (w
->region_showing
)
7867 && NILP (Vshow_trailing_whitespace
)
7868 && !cursor_in_echo_area
)
7871 struct glyph_row
*row
;
7873 /* Skip from tlbufpos to PT and see where it is. Note that
7874 PT may be in invisible text. If so, we will end at the
7875 next visible position. */
7876 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
7877 NULL
, DEFAULT_FACE_ID
);
7878 it
.current_x
= this_line_start_x
;
7879 it
.current_y
= this_line_y
;
7880 it
.vpos
= this_line_vpos
;
7882 /* The call to move_it_to stops in front of PT, but
7883 moves over before-strings. */
7884 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
7886 if (it
.vpos
== this_line_vpos
7887 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
7890 xassert (this_line_vpos
== it
.vpos
);
7891 xassert (this_line_y
== it
.current_y
);
7892 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
7900 /* Text changed drastically or point moved off of line. */
7901 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
7904 CHARPOS (this_line_start_pos
) = 0;
7905 consider_all_windows_p
|= buffer_shared
> 1;
7906 ++clear_face_cache_count
;
7909 /* Build desired matrices, and update the display. If
7910 consider_all_windows_p is non-zero, do it for all windows on all
7911 frames. Otherwise do it for selected_window, only. */
7913 if (consider_all_windows_p
)
7915 Lisp_Object tail
, frame
;
7917 /* Clear the face cache eventually. */
7918 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
7920 clear_face_cache (0);
7921 clear_face_cache_count
= 0;
7924 /* Recompute # windows showing selected buffer. This will be
7925 incremented each time such a window is displayed. */
7928 FOR_EACH_FRAME (tail
, frame
)
7930 struct frame
*f
= XFRAME (frame
);
7932 if (FRAME_WINDOW_P (f
) || f
== sf
)
7934 /* Mark all the scroll bars to be removed; we'll redeem
7935 the ones we want when we redisplay their windows. */
7936 if (condemn_scroll_bars_hook
)
7937 (*condemn_scroll_bars_hook
) (f
);
7939 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7940 redisplay_windows (FRAME_ROOT_WINDOW (f
));
7942 /* Any scroll bars which redisplay_windows should have
7943 nuked should now go away. */
7944 if (judge_scroll_bars_hook
)
7945 (*judge_scroll_bars_hook
) (f
);
7947 /* If fonts changed, display again. */
7948 if (fonts_changed_p
)
7951 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7953 /* See if we have to hscroll. */
7954 if (hscroll_windows (f
->root_window
))
7957 /* Prevent various kinds of signals during display
7958 update. stdio is not robust about handling
7959 signals, which can cause an apparent I/O
7961 if (interrupt_input
)
7965 /* Update the display. */
7966 set_window_update_flags (XWINDOW (f
->root_window
), 1);
7967 pause
|= update_frame (f
, 0, 0);
7971 mark_window_display_accurate (f
->root_window
, 1);
7972 if (frame_up_to_date_hook
)
7973 frame_up_to_date_hook (f
);
7978 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
7980 Lisp_Object mini_window
;
7981 struct frame
*mini_frame
;
7983 redisplay_window (selected_window
, 1);
7985 /* Compare desired and current matrices, perform output. */
7988 /* If fonts changed, display again. */
7989 if (fonts_changed_p
)
7992 /* Prevent various kinds of signals during display update.
7993 stdio is not robust about handling signals,
7994 which can cause an apparent I/O error. */
7995 if (interrupt_input
)
7999 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8001 if (hscroll_windows (selected_window
))
8004 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8005 pause
= update_frame (sf
, 0, 0);
8008 /* We may have called echo_area_display at the top of this
8009 function. If the echo area is on another frame, that may
8010 have put text on a frame other than the selected one, so the
8011 above call to update_frame would not have caught it. Catch
8013 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8014 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8016 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8018 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8019 pause
|= update_frame (mini_frame
, 0, 0);
8020 if (!pause
&& hscroll_windows (mini_window
))
8025 /* If display was paused because of pending input, make sure we do a
8026 thorough update the next time. */
8029 /* Prevent the optimization at the beginning of
8030 redisplay_internal that tries a single-line update of the
8031 line containing the cursor in the selected window. */
8032 CHARPOS (this_line_start_pos
) = 0;
8034 /* Let the overlay arrow be updated the next time. */
8035 if (!NILP (last_arrow_position
))
8037 last_arrow_position
= Qt
;
8038 last_arrow_string
= Qt
;
8041 /* If we pause after scrolling, some rows in the current
8042 matrices of some windows are not valid. */
8043 if (!WINDOW_FULL_WIDTH_P (w
)
8044 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8045 update_mode_lines
= 1;
8048 /* Now text on frame agrees with windows, so put info into the
8049 windows for partial redisplay to follow. */
8052 register struct buffer
*b
= XBUFFER (w
->buffer
);
8054 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
8055 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
8056 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
8057 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
8059 if (consider_all_windows_p
)
8060 mark_window_display_accurate (FRAME_ROOT_WINDOW (sf
), 1);
8063 XSETFASTINT (w
->last_point
, BUF_PT (b
));
8064 w
->last_cursor
= w
->cursor
;
8065 w
->last_cursor_off_p
= w
->cursor_off_p
;
8067 b
->clip_changed
= 0;
8068 b
->prevent_redisplay_optimizations_p
= 0;
8069 w
->update_mode_line
= Qnil
;
8070 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
8071 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
8073 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8076 /* Record if we are showing a region, so can make sure to
8077 update it fully at next redisplay. */
8078 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
8079 && (EQ (selected_window
,
8080 current_buffer
->last_selected_window
)
8081 || highlight_nonselected_windows
)
8082 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
8083 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
8086 w
->window_end_valid
= w
->buffer
;
8087 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8088 last_arrow_string
= Voverlay_arrow_string
;
8089 if (frame_up_to_date_hook
!= 0)
8090 (*frame_up_to_date_hook
) (sf
);
8092 w
->current_matrix
->buffer
= b
;
8093 w
->current_matrix
->begv
= BUF_BEGV (b
);
8094 w
->current_matrix
->zv
= BUF_ZV (b
);
8097 update_mode_lines
= 0;
8098 windows_or_buffers_changed
= 0;
8101 /* Start SIGIO interrupts coming again. Having them off during the
8102 code above makes it less likely one will discard output, but not
8103 impossible, since there might be stuff in the system buffer here.
8104 But it is much hairier to try to do anything about that. */
8105 if (interrupt_input
)
8109 /* If a frame has become visible which was not before, redisplay
8110 again, so that we display it. Expose events for such a frame
8111 (which it gets when becoming visible) don't call the parts of
8112 redisplay constructing glyphs, so simply exposing a frame won't
8113 display anything in this case. So, we have to display these
8114 frames here explicitly. */
8117 Lisp_Object tail
, frame
;
8120 FOR_EACH_FRAME (tail
, frame
)
8122 int this_is_visible
= 0;
8124 if (XFRAME (frame
)->visible
)
8125 this_is_visible
= 1;
8126 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8127 if (XFRAME (frame
)->visible
)
8128 this_is_visible
= 1;
8130 if (this_is_visible
)
8134 if (new_count
!= number_of_visible_frames
)
8135 windows_or_buffers_changed
++;
8138 /* Change frame size now if a change is pending. */
8139 do_pending_window_change (1);
8141 /* If we just did a pending size change, or have additional
8142 visible frames, redisplay again. */
8143 if (windows_or_buffers_changed
&& !pause
)
8148 unbind_to (count
, Qnil
);
8152 /* Redisplay, but leave alone any recent echo area message unless
8153 another message has been requested in its place.
8155 This is useful in situations where you need to redisplay but no
8156 user action has occurred, making it inappropriate for the message
8157 area to be cleared. See tracking_off and
8158 wait_reading_process_input for examples of these situations. */
8161 redisplay_preserve_echo_area ()
8163 if (!NILP (echo_area_buffer
[1]))
8165 /* We have a previously displayed message, but no current
8166 message. Redisplay the previous message. */
8167 display_last_displayed_message_p
= 1;
8168 redisplay_internal (1);
8169 display_last_displayed_message_p
= 0;
8172 redisplay_internal (1);
8176 /* Function registered with record_unwind_protect in
8177 redisplay_internal. Clears the flag indicating that a redisplay is
8181 unwind_redisplay (old_redisplaying_p
)
8182 Lisp_Object old_redisplaying_p
;
8184 redisplaying_p
= XFASTINT (old_redisplaying_p
);
8189 /* Mark the display of windows in the window tree rooted at WINDOW as
8190 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
8191 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
8192 the next time redisplay_internal is called. */
8195 mark_window_display_accurate (window
, accurate_p
)
8201 for (; !NILP (window
); window
= w
->next
)
8203 w
= XWINDOW (window
);
8205 if (BUFFERP (w
->buffer
))
8207 struct buffer
*b
= XBUFFER (w
->buffer
);
8209 XSETFASTINT (w
->last_modified
,
8210 accurate_p
? BUF_MODIFF (b
) : 0);
8211 XSETFASTINT (w
->last_overlay_modified
,
8212 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
8213 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
8216 #if 0 /* I don't think this is necessary because display_line does it.
8218 /* Record if we are showing a region, so can make sure to
8219 update it fully at next redisplay. */
8221 = (!NILP (Vtransient_mark_mode
)
8222 && (w
== XWINDOW (current_buffer
->last_selected_window
)
8223 || highlight_nonselected_windows
)
8224 && (!NILP (b
->mark_active
)
8225 ? Fmarker_position (b
->mark
)
8231 b
->clip_changed
= 0;
8232 b
->prevent_redisplay_optimizations_p
= 0;
8233 w
->current_matrix
->buffer
= b
;
8234 w
->current_matrix
->begv
= BUF_BEGV (b
);
8235 w
->current_matrix
->zv
= BUF_ZV (b
);
8236 w
->last_cursor
= w
->cursor
;
8237 w
->last_cursor_off_p
= w
->cursor_off_p
;
8238 if (w
== XWINDOW (selected_window
))
8239 w
->last_point
= make_number (BUF_PT (b
));
8241 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
8245 w
->window_end_valid
= w
->buffer
;
8246 w
->update_mode_line
= Qnil
;
8248 if (!NILP (w
->vchild
))
8249 mark_window_display_accurate (w
->vchild
, accurate_p
);
8250 if (!NILP (w
->hchild
))
8251 mark_window_display_accurate (w
->hchild
, accurate_p
);
8256 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8257 last_arrow_string
= Voverlay_arrow_string
;
8261 /* Force a thorough redisplay the next time by setting
8262 last_arrow_position and last_arrow_string to t, which is
8263 unequal to any useful value of Voverlay_arrow_... */
8264 last_arrow_position
= Qt
;
8265 last_arrow_string
= Qt
;
8270 /* Return value in display table DP (Lisp_Char_Table *) for character
8271 C. Since a display table doesn't have any parent, we don't have to
8272 follow parent. Do not call this function directly but use the
8273 macro DISP_CHAR_VECTOR. */
8276 disp_char_vector (dp
, c
)
8277 struct Lisp_Char_Table
*dp
;
8283 if (SINGLE_BYTE_CHAR_P (c
))
8284 return (dp
->contents
[c
]);
8286 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
8289 else if (code
[2] < 32)
8292 /* Here, the possible range of code[0] (== charset ID) is
8293 128..max_charset. Since the top level char table contains data
8294 for multibyte characters after 256th element, we must increment
8295 code[0] by 128 to get a correct index. */
8297 code
[3] = -1; /* anchor */
8299 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
8301 val
= dp
->contents
[code
[i
]];
8302 if (!SUB_CHAR_TABLE_P (val
))
8303 return (NILP (val
) ? dp
->defalt
: val
);
8306 /* Here, val is a sub char table. We return the default value of
8308 return (dp
->defalt
);
8313 /***********************************************************************
8315 ***********************************************************************/
8317 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
8320 redisplay_windows (window
)
8323 while (!NILP (window
))
8325 struct window
*w
= XWINDOW (window
);
8327 if (!NILP (w
->hchild
))
8328 redisplay_windows (w
->hchild
);
8329 else if (!NILP (w
->vchild
))
8330 redisplay_windows (w
->vchild
);
8332 redisplay_window (window
, 0);
8339 /* Set cursor position of W. PT is assumed to be displayed in ROW.
8340 DELTA is the number of bytes by which positions recorded in ROW
8341 differ from current buffer positions. */
8344 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
8346 struct glyph_row
*row
;
8347 struct glyph_matrix
*matrix
;
8348 int delta
, delta_bytes
, dy
, dvpos
;
8350 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
8351 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
8353 int pt_old
= PT
- delta
;
8355 /* Skip over glyphs not having an object at the start of the row.
8356 These are special glyphs like truncation marks on terminal
8358 if (row
->displays_text_p
)
8360 && INTEGERP (glyph
->object
)
8361 && glyph
->charpos
< 0)
8363 x
+= glyph
->pixel_width
;
8368 && !INTEGERP (glyph
->object
)
8369 && (!BUFFERP (glyph
->object
)
8370 || glyph
->charpos
< pt_old
))
8372 x
+= glyph
->pixel_width
;
8376 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
8378 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
8379 w
->cursor
.y
= row
->y
+ dy
;
8381 if (w
== XWINDOW (selected_window
))
8383 if (!row
->continued_p
8384 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
8387 this_line_buffer
= XBUFFER (w
->buffer
);
8389 CHARPOS (this_line_start_pos
)
8390 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
8391 BYTEPOS (this_line_start_pos
)
8392 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
8394 CHARPOS (this_line_end_pos
)
8395 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
8396 BYTEPOS (this_line_end_pos
)
8397 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
8399 this_line_y
= w
->cursor
.y
;
8400 this_line_pixel_height
= row
->height
;
8401 this_line_vpos
= w
->cursor
.vpos
;
8402 this_line_start_x
= row
->x
;
8405 CHARPOS (this_line_start_pos
) = 0;
8410 /* Run window scroll functions, if any, for WINDOW with new window
8411 start STARTP. Sets the window start of WINDOW to that position.
8413 We assume that the window's buffer is really current. */
8415 static INLINE
struct text_pos
8416 run_window_scroll_functions (window
, startp
)
8418 struct text_pos startp
;
8420 struct window
*w
= XWINDOW (window
);
8421 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
8423 if (current_buffer
!= XBUFFER (w
->buffer
))
8426 if (!NILP (Vwindow_scroll_functions
))
8428 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
8429 make_number (CHARPOS (startp
)));
8430 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8431 /* In case the hook functions switch buffers. */
8432 if (current_buffer
!= XBUFFER (w
->buffer
))
8433 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8440 /* Modify the desired matrix of window W and W->vscroll so that the
8441 line containing the cursor is fully visible. */
8444 make_cursor_line_fully_visible (w
)
8447 struct glyph_matrix
*matrix
;
8448 struct glyph_row
*row
;
8449 int window_height
, header_line_height
;
8451 /* It's not always possible to find the cursor, e.g, when a window
8452 is full of overlay strings. Don't do anything in that case. */
8453 if (w
->cursor
.vpos
< 0)
8456 matrix
= w
->desired_matrix
;
8457 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
8459 /* If the cursor row is not partially visible, there's nothing
8461 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8464 /* If the row the cursor is in is taller than the window's height,
8465 it's not clear what to do, so do nothing. */
8466 window_height
= window_box_height (w
);
8467 if (row
->height
>= window_height
)
8470 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
8472 int dy
= row
->height
- row
->visible_height
;
8475 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8477 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
8479 int dy
= - (row
->height
- row
->visible_height
);
8482 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8485 /* When we change the cursor y-position of the selected window,
8486 change this_line_y as well so that the display optimization for
8487 the cursor line of the selected window in redisplay_internal uses
8488 the correct y-position. */
8489 if (w
== XWINDOW (selected_window
))
8490 this_line_y
= w
->cursor
.y
;
8494 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
8495 non-zero means only WINDOW is redisplayed in redisplay_internal.
8496 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
8497 in redisplay_window to bring a partially visible line into view in
8498 the case that only the cursor has moved.
8502 1 if scrolling succeeded
8504 0 if scrolling didn't find point.
8506 -1 if new fonts have been loaded so that we must interrupt
8507 redisplay, adjust glyph matrices, and try again. */
8510 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
8511 scroll_step
, temp_scroll_step
)
8513 int just_this_one_p
;
8514 int scroll_conservatively
, scroll_step
;
8515 int temp_scroll_step
;
8517 struct window
*w
= XWINDOW (window
);
8518 struct frame
*f
= XFRAME (w
->frame
);
8519 struct text_pos scroll_margin_pos
;
8520 struct text_pos pos
;
8521 struct text_pos startp
;
8523 Lisp_Object window_end
;
8524 int this_scroll_margin
;
8527 int line_height
, rc
;
8528 int amount_to_scroll
= 0;
8529 Lisp_Object aggressive
;
8533 debug_method_add (w
, "try_scrolling");
8536 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8538 /* Compute scroll margin height in pixels. We scroll when point is
8539 within this distance from the top or bottom of the window. */
8540 if (scroll_margin
> 0)
8542 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
8543 this_scroll_margin
*= CANON_Y_UNIT (f
);
8546 this_scroll_margin
= 0;
8548 /* Compute how much we should try to scroll maximally to bring point
8551 scroll_max
= scroll_step
;
8552 else if (scroll_conservatively
)
8553 scroll_max
= scroll_conservatively
;
8554 else if (temp_scroll_step
)
8555 scroll_max
= temp_scroll_step
;
8556 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
8557 || NUMBERP (current_buffer
->scroll_up_aggressively
))
8558 /* We're trying to scroll because of aggressive scrolling
8559 but no scroll_step is set. Choose an arbitrary one. Maybe
8560 there should be a variable for this. */
8564 scroll_max
*= CANON_Y_UNIT (f
);
8566 /* Decide whether we have to scroll down. Start at the window end
8567 and move this_scroll_margin up to find the position of the scroll
8569 window_end
= Fwindow_end (window
, Qt
);
8570 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
8571 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
8572 if (this_scroll_margin
)
8574 start_display (&it
, w
, scroll_margin_pos
);
8575 move_it_vertically (&it
, - this_scroll_margin
);
8576 scroll_margin_pos
= it
.current
.pos
;
8579 if (PT
>= CHARPOS (scroll_margin_pos
))
8583 /* Point is in the scroll margin at the bottom of the window, or
8584 below. Compute a new window start that makes point visible. */
8586 /* Compute the distance from the scroll margin to PT.
8587 Give up if the distance is greater than scroll_max. */
8588 start_display (&it
, w
, scroll_margin_pos
);
8590 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8591 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8592 line_height
= (it
.max_ascent
+ it
.max_descent
8593 ? it
.max_ascent
+ it
.max_descent
8595 dy
= it
.current_y
+ line_height
- y0
;
8597 if (dy
> scroll_max
)
8600 /* Move the window start down. If scrolling conservatively,
8601 move it just enough down to make point visible. If
8602 scroll_step is set, move it down by scroll_step. */
8603 start_display (&it
, w
, startp
);
8605 if (scroll_conservatively
)
8606 amount_to_scroll
= dy
;
8607 else if (scroll_step
|| temp_scroll_step
)
8608 amount_to_scroll
= scroll_max
;
8611 aggressive
= current_buffer
->scroll_down_aggressively
;
8612 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8613 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8614 if (NUMBERP (aggressive
))
8615 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8618 if (amount_to_scroll
<= 0)
8621 move_it_vertically (&it
, amount_to_scroll
);
8622 startp
= it
.current
.pos
;
8626 /* See if point is inside the scroll margin at the top of the
8628 scroll_margin_pos
= startp
;
8629 if (this_scroll_margin
)
8631 start_display (&it
, w
, startp
);
8632 move_it_vertically (&it
, this_scroll_margin
);
8633 scroll_margin_pos
= it
.current
.pos
;
8636 if (PT
< CHARPOS (scroll_margin_pos
))
8638 /* Point is in the scroll margin at the top of the window or
8639 above what is displayed in the window. */
8642 /* Compute the vertical distance from PT to the scroll
8643 margin position. Give up if distance is greater than
8645 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
8646 start_display (&it
, w
, pos
);
8648 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
8649 it
.last_visible_y
, -1,
8650 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8651 dy
= it
.current_y
- y0
;
8652 if (dy
> scroll_max
)
8655 /* Compute new window start. */
8656 start_display (&it
, w
, startp
);
8658 if (scroll_conservatively
)
8659 amount_to_scroll
= dy
;
8660 else if (scroll_step
|| temp_scroll_step
)
8661 amount_to_scroll
= scroll_max
;
8664 aggressive
= current_buffer
->scroll_up_aggressively
;
8665 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8666 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8667 if (NUMBERP (aggressive
))
8668 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8671 if (amount_to_scroll
<= 0)
8674 move_it_vertically (&it
, - amount_to_scroll
);
8675 startp
= it
.current
.pos
;
8679 /* Run window scroll functions. */
8680 startp
= run_window_scroll_functions (window
, startp
);
8682 /* Display the window. Give up if new fonts are loaded, or if point
8684 if (!try_window (window
, startp
))
8686 else if (w
->cursor
.vpos
< 0)
8688 clear_glyph_matrix (w
->desired_matrix
);
8693 /* Maybe forget recorded base line for line number display. */
8694 if (!just_this_one_p
8695 || current_buffer
->clip_changed
8696 || BEG_UNCHANGED
< CHARPOS (startp
))
8697 w
->base_line_number
= Qnil
;
8699 /* If cursor ends up on a partially visible line, shift display
8700 lines up or down. */
8701 make_cursor_line_fully_visible (w
);
8709 /* Compute a suitable window start for window W if display of W starts
8710 on a continuation line. Value is non-zero if a new window start
8713 The new window start will be computed, based on W's width, starting
8714 from the start of the continued line. It is the start of the
8715 screen line with the minimum distance from the old start W->start. */
8718 compute_window_start_on_continuation_line (w
)
8721 struct text_pos pos
, start_pos
;
8722 int window_start_changed_p
= 0;
8724 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
8726 /* If window start is on a continuation line... Window start may be
8727 < BEGV in case there's invisible text at the start of the
8728 buffer (M-x rmail, for example). */
8729 if (CHARPOS (start_pos
) > BEGV
8730 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
8733 struct glyph_row
*row
;
8735 /* Handle the case that the window start is out of range. */
8736 if (CHARPOS (start_pos
) < BEGV
)
8737 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
8738 else if (CHARPOS (start_pos
) > ZV
)
8739 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
8741 /* Find the start of the continued line. This should be fast
8742 because scan_buffer is fast (newline cache). */
8743 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
8744 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
8745 row
, DEFAULT_FACE_ID
);
8746 reseat_at_previous_visible_line_start (&it
);
8748 /* If the line start is "too far" away from the window start,
8749 say it takes too much time to compute a new window start. */
8750 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
8751 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
8753 int min_distance
, distance
;
8755 /* Move forward by display lines to find the new window
8756 start. If window width was enlarged, the new start can
8757 be expected to be > the old start. If window width was
8758 decreased, the new window start will be < the old start.
8759 So, we're looking for the display line start with the
8760 minimum distance from the old window start. */
8761 pos
= it
.current
.pos
;
8762 min_distance
= INFINITY
;
8763 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
8764 distance
< min_distance
)
8766 min_distance
= distance
;
8767 pos
= it
.current
.pos
;
8768 move_it_by_lines (&it
, 1, 0);
8771 /* Set the window start there. */
8772 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
8773 window_start_changed_p
= 1;
8777 return window_start_changed_p
;
8781 /* Try cursor movement in case text has not changes in window WINDOW,
8782 with window start STARTP. Value is
8786 0 if this method cannot be used
8788 -1 if we know we have to scroll the display. *SCROLL_STEP is
8789 set to 1, under certain circumstances, if we want to scroll as
8790 if scroll-step were set to 1. See the code. */
8793 try_cursor_movement (window
, startp
, scroll_step
)
8795 struct text_pos startp
;
8798 struct window
*w
= XWINDOW (window
);
8799 struct frame
*f
= XFRAME (w
->frame
);
8802 /* Handle case where text has not changed, only point, and it has
8803 not moved off the frame. */
8804 if (/* Point may be in this window. */
8805 PT
>= CHARPOS (startp
)
8806 /* If we don't check this, we are called to move the cursor in a
8807 horizontally split window with a current matrix that doesn't
8809 && !windows_or_buffers_changed
8810 /* Selective display hasn't changed. */
8811 && !current_buffer
->clip_changed
8812 /* If force-mode-line-update was called, really redisplay;
8813 that's how redisplay is forced after e.g. changing
8814 buffer-invisibility-spec. */
8815 && NILP (w
->update_mode_line
)
8816 /* Can't use this case if highlighting a region. When a
8817 region exists, cursor movement has to do more than just
8819 && !(!NILP (Vtransient_mark_mode
)
8820 && !NILP (current_buffer
->mark_active
))
8821 && NILP (w
->region_showing
)
8822 && NILP (Vshow_trailing_whitespace
)
8823 /* Right after splitting windows, last_point may be nil. */
8824 && INTEGERP (w
->last_point
)
8825 /* This code is not used for mini-buffer for the sake of the case
8826 of redisplaying to replace an echo area message; since in
8827 that case the mini-buffer contents per se are usually
8828 unchanged. This code is of no real use in the mini-buffer
8829 since the handling of this_line_start_pos, etc., in redisplay
8830 handles the same cases. */
8831 && !EQ (window
, minibuf_window
)
8832 /* When splitting windows or for new windows, it happens that
8833 redisplay is called with a nil window_end_vpos or one being
8834 larger than the window. This should really be fixed in
8835 window.c. I don't have this on my list, now, so we do
8836 approximately the same as the old redisplay code. --gerd. */
8837 && INTEGERP (w
->window_end_vpos
)
8838 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
8839 && (FRAME_WINDOW_P (f
)
8840 || !MARKERP (Voverlay_arrow_position
)
8841 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
8843 int this_scroll_margin
;
8844 struct glyph_row
*row
;
8847 debug_method_add (w
, "cursor movement");
8850 /* Scroll if point within this distance from the top or bottom
8851 of the window. This is a pixel value. */
8852 this_scroll_margin
= max (0, scroll_margin
);
8853 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
8854 this_scroll_margin
*= CANON_Y_UNIT (f
);
8856 /* Start with the row the cursor was displayed during the last
8857 not paused redisplay. Give up if that row is not valid. */
8858 if (w
->last_cursor
.vpos
< 0
8859 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
8863 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
8864 if (row
->mode_line_p
)
8866 if (!row
->enabled_p
)
8874 if (PT
> XFASTINT (w
->last_point
))
8876 /* Point has moved forward. */
8877 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
8879 while (MATRIX_ROW_END_CHARPOS (row
) < PT
8880 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
8882 xassert (row
->enabled_p
);
8886 /* The end position of a row equals the start position
8887 of the next row. If PT is there, we would rather
8888 display it in the next line. Exceptions are when the
8889 row ends in the middle of a character, or ends in
8891 if (MATRIX_ROW_BOTTOM_Y (row
) < last_y
8892 && MATRIX_ROW_END_CHARPOS (row
) == PT
8893 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
8894 && !row
->ends_at_zv_p
)
8896 xassert (row
->enabled_p
);
8900 /* If within the scroll margin, scroll. Note that
8901 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
8902 the next line would be drawn, and that
8903 this_scroll_margin can be zero. */
8904 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
8905 || PT
> MATRIX_ROW_END_CHARPOS (row
)
8906 /* Line is completely visible last line in window
8907 and PT is to be set in the next line. */
8908 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
8909 && PT
== MATRIX_ROW_END_CHARPOS (row
)
8910 && !row
->ends_at_zv_p
8911 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
8914 else if (PT
< XFASTINT (w
->last_point
))
8916 /* Cursor has to be moved backward. Note that PT >=
8917 CHARPOS (startp) because of the outer
8919 while (!row
->mode_line_p
8920 && (MATRIX_ROW_START_CHARPOS (row
) > PT
8921 || (MATRIX_ROW_START_CHARPOS (row
) == PT
8922 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
8923 && (row
->y
> this_scroll_margin
8924 || CHARPOS (startp
) == BEGV
))
8926 xassert (row
->enabled_p
);
8930 /* Consider the following case: Window starts at BEGV,
8931 there is invisible, intangible text at BEGV, so that
8932 display starts at some point START > BEGV. It can
8933 happen that we are called with PT somewhere between
8934 BEGV and START. Try to handle that case. */
8935 if (row
< w
->current_matrix
->rows
8936 || row
->mode_line_p
)
8938 row
= w
->current_matrix
->rows
;
8939 if (row
->mode_line_p
)
8943 /* Due to newlines in overlay strings, we may have to
8944 skip forward over overlay strings. */
8945 while (MATRIX_ROW_END_CHARPOS (row
) == PT
8946 && MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P (row
)
8947 && !row
->ends_at_zv_p
)
8950 /* If within the scroll margin, scroll. */
8951 if (row
->y
< this_scroll_margin
8952 && CHARPOS (startp
) != BEGV
)
8956 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
8957 || PT
> MATRIX_ROW_END_CHARPOS (row
))
8959 /* if PT is not in the glyph row, give up. */
8962 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8964 /* If we end up in a partially visible line, let's make it
8965 fully visible, except when it's taller than the window,
8966 in which case we can't do much about it. */
8967 if (row
->height
> window_box_height (w
))
8974 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8975 try_window (window
, startp
);
8976 make_cursor_line_fully_visible (w
);
8984 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8994 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
8995 selected_window is redisplayed. */
8998 redisplay_window (window
, just_this_one_p
)
9000 int just_this_one_p
;
9002 struct window
*w
= XWINDOW (window
);
9003 struct frame
*f
= XFRAME (w
->frame
);
9004 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9005 struct buffer
*old
= current_buffer
;
9006 struct text_pos lpoint
, opoint
, startp
;
9007 int update_mode_line
;
9010 /* Record it now because it's overwritten. */
9011 int current_matrix_up_to_date_p
= 0;
9012 int temp_scroll_step
= 0;
9013 int count
= specpdl_ptr
- specpdl
;
9016 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9019 /* W must be a leaf window here. */
9020 xassert (!NILP (w
->buffer
));
9022 *w
->desired_matrix
->method
= 0;
9025 specbind (Qinhibit_point_motion_hooks
, Qt
);
9027 reconsider_clip_changes (w
, buffer
);
9029 /* Has the mode line to be updated? */
9030 update_mode_line
= (!NILP (w
->update_mode_line
)
9031 || update_mode_lines
9032 || buffer
->clip_changed
);
9034 if (MINI_WINDOW_P (w
))
9036 if (w
== XWINDOW (echo_area_window
)
9037 && !NILP (echo_area_buffer
[0]))
9039 if (update_mode_line
)
9040 /* We may have to update a tty frame's menu bar or a
9041 tool-bar. Example `M-x C-h C-h C-g'. */
9042 goto finish_menu_bars
;
9044 /* We've already displayed the echo area glyphs in this window. */
9045 goto finish_scroll_bars
;
9047 else if (w
!= XWINDOW (minibuf_window
))
9049 /* W is a mini-buffer window, but it's not the currently
9050 active one, so clear it. */
9051 int yb
= window_text_bottom_y (w
);
9052 struct glyph_row
*row
;
9055 for (y
= 0, row
= w
->desired_matrix
->rows
;
9057 y
+= row
->height
, ++row
)
9058 blank_row (w
, row
, y
);
9059 goto finish_scroll_bars
;
9063 /* Otherwise set up data on this window; select its buffer and point
9065 /* Really select the buffer, for the sake of buffer-local
9067 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9068 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9070 current_matrix_up_to_date_p
9071 = (!NILP (w
->window_end_valid
)
9072 && !current_buffer
->clip_changed
9073 && XFASTINT (w
->last_modified
) >= MODIFF
9074 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9076 /* When windows_or_buffers_changed is non-zero, we can't rely on
9077 the window end being valid, so set it to nil there. */
9078 if (windows_or_buffers_changed
)
9080 /* If window starts on a continuation line, maybe adjust the
9081 window start in case the window's width changed. */
9082 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9083 compute_window_start_on_continuation_line (w
);
9085 w
->window_end_valid
= Qnil
;
9088 /* Some sanity checks. */
9089 CHECK_WINDOW_END (w
);
9090 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9092 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9095 /* If %c is in mode line, update it if needed. */
9096 if (!NILP (w
->column_number_displayed
)
9097 /* This alternative quickly identifies a common case
9098 where no change is needed. */
9099 && !(PT
== XFASTINT (w
->last_point
)
9100 && XFASTINT (w
->last_modified
) >= MODIFF
9101 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9102 && XFASTINT (w
->column_number_displayed
) != current_column ())
9103 update_mode_line
= 1;
9105 /* Count number of windows showing the selected buffer. An indirect
9106 buffer counts as its base buffer. */
9107 if (!just_this_one_p
)
9109 struct buffer
*current_base
, *window_base
;
9110 current_base
= current_buffer
;
9111 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9112 if (current_base
->base_buffer
)
9113 current_base
= current_base
->base_buffer
;
9114 if (window_base
->base_buffer
)
9115 window_base
= window_base
->base_buffer
;
9116 if (current_base
== window_base
)
9120 /* Point refers normally to the selected window. For any other
9121 window, set up appropriate value. */
9122 if (!EQ (window
, selected_window
))
9124 int new_pt
= XMARKER (w
->pointm
)->charpos
;
9125 int new_pt_byte
= marker_byte_position (w
->pointm
);
9129 new_pt_byte
= BEGV_BYTE
;
9130 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
9132 else if (new_pt
> (ZV
- 1))
9135 new_pt_byte
= ZV_BYTE
;
9136 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
9139 /* We don't use SET_PT so that the point-motion hooks don't run. */
9140 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
9143 /* If any of the character widths specified in the display table
9144 have changed, invalidate the width run cache. It's true that
9145 this may be a bit late to catch such changes, but the rest of
9146 redisplay goes (non-fatally) haywire when the display table is
9147 changed, so why should we worry about doing any better? */
9148 if (current_buffer
->width_run_cache
)
9150 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
9152 if (! disptab_matches_widthtab (disptab
,
9153 XVECTOR (current_buffer
->width_table
)))
9155 invalidate_region_cache (current_buffer
,
9156 current_buffer
->width_run_cache
,
9158 recompute_width_table (current_buffer
, disptab
);
9162 /* If window-start is screwed up, choose a new one. */
9163 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
9166 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9168 /* If someone specified a new starting point but did not insist,
9169 check whether it can be used. */
9170 if (!NILP (w
->optional_new_start
)
9171 && CHARPOS (startp
) >= BEGV
9172 && CHARPOS (startp
) <= ZV
)
9174 w
->optional_new_start
= Qnil
;
9175 start_display (&it
, w
, startp
);
9176 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9177 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9178 if (IT_CHARPOS (it
) == PT
)
9179 w
->force_start
= Qt
;
9182 /* Handle case where place to start displaying has been specified,
9183 unless the specified location is outside the accessible range. */
9184 if (!NILP (w
->force_start
)
9185 || w
->frozen_window_start_p
)
9187 w
->force_start
= Qnil
;
9189 w
->window_end_valid
= Qnil
;
9191 /* Forget any recorded base line for line number display. */
9192 if (!current_matrix_up_to_date_p
9193 || current_buffer
->clip_changed
)
9194 w
->base_line_number
= Qnil
;
9196 /* Redisplay the mode line. Select the buffer properly for that.
9197 Also, run the hook window-scroll-functions
9198 because we have scrolled. */
9199 /* Note, we do this after clearing force_start because
9200 if there's an error, it is better to forget about force_start
9201 than to get into an infinite loop calling the hook functions
9202 and having them get more errors. */
9203 if (!update_mode_line
9204 || ! NILP (Vwindow_scroll_functions
))
9206 update_mode_line
= 1;
9207 w
->update_mode_line
= Qt
;
9208 startp
= run_window_scroll_functions (window
, startp
);
9211 XSETFASTINT (w
->last_modified
, 0);
9212 XSETFASTINT (w
->last_overlay_modified
, 0);
9213 if (CHARPOS (startp
) < BEGV
)
9214 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
9215 else if (CHARPOS (startp
) > ZV
)
9216 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
9218 /* Redisplay, then check if cursor has been set during the
9219 redisplay. Give up if new fonts were loaded. */
9220 if (!try_window (window
, startp
))
9222 w
->force_start
= Qt
;
9223 clear_glyph_matrix (w
->desired_matrix
);
9224 goto restore_buffers
;
9227 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
9229 /* If point does not appear, try to move point so it does
9230 appear. The desired matrix has been built above, so we
9233 struct glyph_row
*row
;
9235 window_height
= window_box_height (w
) / 2;
9236 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
9237 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
9240 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
9241 MATRIX_ROW_START_BYTEPOS (row
));
9243 if (w
!= XWINDOW (selected_window
))
9244 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
9245 else if (current_buffer
== old
)
9246 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9248 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
9250 /* If we are highlighting the region, then we just changed
9251 the region, so redisplay to show it. */
9252 if (!NILP (Vtransient_mark_mode
)
9253 && !NILP (current_buffer
->mark_active
))
9255 clear_glyph_matrix (w
->desired_matrix
);
9256 if (!try_window (window
, startp
))
9257 goto restore_buffers
;
9261 make_cursor_line_fully_visible (w
);
9263 debug_method_add (w
, "forced window start");
9268 /* Handle case where text has not changed, only point, and it has
9269 not moved off the frame. */
9270 if (current_matrix_up_to_date_p
9271 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
9279 /* If current starting point was originally the beginning of a line
9280 but no longer is, find a new starting point. */
9281 else if (!NILP (w
->start_at_line_beg
)
9282 && !(CHARPOS (startp
) <= BEGV
9283 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
9286 debug_method_add (w
, "recenter 1");
9291 /* Try scrolling with try_window_id. */
9292 else if (/* Windows and buffers haven't changed. */
9293 !windows_or_buffers_changed
9294 /* Window must be either use window-based redisplay or
9296 && (FRAME_WINDOW_P (f
)
9297 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
9298 && !MINI_WINDOW_P (w
)
9299 /* Point is not known NOT to appear in window. */
9300 && PT
>= CHARPOS (startp
)
9301 && XFASTINT (w
->last_modified
)
9302 /* Window is not hscrolled. */
9303 && XFASTINT (w
->hscroll
) == 0
9304 /* Selective display has not changed. */
9305 && !current_buffer
->clip_changed
9306 /* Current matrix is up to date. */
9307 && !NILP (w
->window_end_valid
)
9308 /* Can't use this case if highlighting a region because
9309 a cursor movement will do more than just set the cursor. */
9310 && !(!NILP (Vtransient_mark_mode
)
9311 && !NILP (current_buffer
->mark_active
))
9312 && NILP (w
->region_showing
)
9313 && NILP (Vshow_trailing_whitespace
)
9314 /* Overlay arrow position and string not changed. */
9315 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
9316 && EQ (last_arrow_string
, Voverlay_arrow_string
)
9317 /* Value is > 0 if update has been done, it is -1 if we
9318 know that the same window start will not work. It is 0
9319 if unsuccessful for some other reason. */
9320 && (tem
= try_window_id (w
)) != 0)
9323 debug_method_add (w
, "try_window_id %d", tem
);
9326 if (fonts_changed_p
)
9327 goto restore_buffers
;
9331 /* Otherwise try_window_id has returned -1 which means that we
9332 don't want the alternative below this comment to execute. */
9334 else if (CHARPOS (startp
) >= BEGV
9335 && CHARPOS (startp
) <= ZV
9336 && PT
>= CHARPOS (startp
)
9337 && (CHARPOS (startp
) < ZV
9338 /* Avoid starting at end of buffer. */
9339 || CHARPOS (startp
) == BEGV
9340 || (XFASTINT (w
->last_modified
) >= MODIFF
9341 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
9344 debug_method_add (w
, "same window start");
9347 /* Try to redisplay starting at same place as before.
9348 If point has not moved off frame, accept the results. */
9349 if (!current_matrix_up_to_date_p
9350 /* Don't use try_window_reusing_current_matrix in this case
9351 because a window scroll function can have changed the
9353 || !NILP (Vwindow_scroll_functions
)
9354 || MINI_WINDOW_P (w
)
9355 || !try_window_reusing_current_matrix (w
))
9357 IF_DEBUG (debug_method_add (w
, "1"));
9358 try_window (window
, startp
);
9361 if (fonts_changed_p
)
9362 goto restore_buffers
;
9364 if (w
->cursor
.vpos
>= 0)
9366 if (!just_this_one_p
9367 || current_buffer
->clip_changed
9368 || BEG_UNCHANGED
< CHARPOS (startp
))
9369 /* Forget any recorded base line for line number display. */
9370 w
->base_line_number
= Qnil
;
9372 make_cursor_line_fully_visible (w
);
9376 clear_glyph_matrix (w
->desired_matrix
);
9381 XSETFASTINT (w
->last_modified
, 0);
9382 XSETFASTINT (w
->last_overlay_modified
, 0);
9384 /* Redisplay the mode line. Select the buffer properly for that. */
9385 if (!update_mode_line
)
9387 update_mode_line
= 1;
9388 w
->update_mode_line
= Qt
;
9391 /* Try to scroll by specified few lines. */
9392 if ((scroll_conservatively
9395 || NUMBERP (current_buffer
->scroll_up_aggressively
)
9396 || NUMBERP (current_buffer
->scroll_down_aggressively
))
9397 && !current_buffer
->clip_changed
9398 && CHARPOS (startp
) >= BEGV
9399 && CHARPOS (startp
) <= ZV
)
9401 /* The function returns -1 if new fonts were loaded, 1 if
9402 successful, 0 if not successful. */
9403 int rc
= try_scrolling (window
, just_this_one_p
,
9404 scroll_conservatively
,
9410 goto restore_buffers
;
9413 /* Finally, just choose place to start which centers point */
9418 debug_method_add (w
, "recenter");
9421 /* w->vscroll = 0; */
9423 /* Forget any previously recorded base line for line number display. */
9424 if (!current_matrix_up_to_date_p
9425 || current_buffer
->clip_changed
)
9426 w
->base_line_number
= Qnil
;
9428 /* Move backward half the height of the window. */
9429 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9430 it
.current_y
= it
.last_visible_y
;
9431 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
9432 xassert (IT_CHARPOS (it
) >= BEGV
);
9434 /* The function move_it_vertically_backward may move over more
9435 than the specified y-distance. If it->w is small, e.g. a
9436 mini-buffer window, we may end up in front of the window's
9437 display area. Start displaying at the start of the line
9438 containing PT in this case. */
9439 if (it
.current_y
<= 0)
9441 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9442 move_it_vertically (&it
, 0);
9443 xassert (IT_CHARPOS (it
) <= PT
);
9447 it
.current_x
= it
.hpos
= 0;
9449 /* Set startp here explicitly in case that helps avoid an infinite loop
9450 in case the window-scroll-functions functions get errors. */
9451 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
9453 /* Run scroll hooks. */
9454 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
9456 /* Redisplay the window. */
9457 if (!current_matrix_up_to_date_p
9458 || windows_or_buffers_changed
9459 /* Don't use try_window_reusing_current_matrix in this case
9460 because it can have changed the buffer. */
9461 || !NILP (Vwindow_scroll_functions
)
9463 || MINI_WINDOW_P (w
)
9464 || !try_window_reusing_current_matrix (w
))
9465 try_window (window
, startp
);
9467 /* If new fonts have been loaded (due to fontsets), give up. We
9468 have to start a new redisplay since we need to re-adjust glyph
9470 if (fonts_changed_p
)
9471 goto restore_buffers
;
9473 /* If cursor did not appear assume that the middle of the window is
9474 in the first line of the window. Do it again with the next line.
9475 (Imagine a window of height 100, displaying two lines of height
9476 60. Moving back 50 from it->last_visible_y will end in the first
9478 if (w
->cursor
.vpos
< 0)
9480 if (!NILP (w
->window_end_valid
)
9481 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
9483 clear_glyph_matrix (w
->desired_matrix
);
9484 move_it_by_lines (&it
, 1, 0);
9485 try_window (window
, it
.current
.pos
);
9487 else if (PT
< IT_CHARPOS (it
))
9489 clear_glyph_matrix (w
->desired_matrix
);
9490 move_it_by_lines (&it
, -1, 0);
9491 try_window (window
, it
.current
.pos
);
9495 /* Not much we can do about it. */
9499 /* Consider the following case: Window starts at BEGV, there is
9500 invisible, intangible text at BEGV, so that display starts at
9501 some point START > BEGV. It can happen that we are called with
9502 PT somewhere between BEGV and START. Try to handle that case. */
9503 if (w
->cursor
.vpos
< 0)
9505 struct glyph_row
*row
= w
->current_matrix
->rows
;
9506 if (row
->mode_line_p
)
9508 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9511 make_cursor_line_fully_visible (w
);
9515 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9516 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
9517 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
9520 /* Display the mode line, if we must. */
9521 if ((update_mode_line
9522 /* If window not full width, must redo its mode line
9523 if (a) the window to its side is being redone and
9524 (b) we do a frame-based redisplay. This is a consequence
9525 of how inverted lines are drawn in frame-based redisplay. */
9526 || (!just_this_one_p
9527 && !FRAME_WINDOW_P (f
)
9528 && !WINDOW_FULL_WIDTH_P (w
))
9529 /* Line number to display. */
9530 || INTEGERP (w
->base_line_pos
)
9531 /* Column number is displayed and different from the one displayed. */
9532 || (!NILP (w
->column_number_displayed
)
9533 && XFASTINT (w
->column_number_displayed
) != current_column ()))
9534 /* This means that the window has a mode line. */
9535 && (WINDOW_WANTS_MODELINE_P (w
)
9536 || WINDOW_WANTS_HEADER_LINE_P (w
)))
9538 Lisp_Object old_selected_frame
;
9540 old_selected_frame
= selected_frame
;
9542 XSETFRAME (selected_frame
, f
);
9543 display_mode_lines (w
);
9544 selected_frame
= old_selected_frame
;
9546 /* If mode line height has changed, arrange for a thorough
9547 immediate redisplay using the correct mode line height. */
9548 if (WINDOW_WANTS_MODELINE_P (w
)
9549 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
9551 fonts_changed_p
= 1;
9552 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
9553 = DESIRED_MODE_LINE_HEIGHT (w
);
9556 /* If top line height has changed, arrange for a thorough
9557 immediate redisplay using the correct mode line height. */
9558 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9559 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
9561 fonts_changed_p
= 1;
9562 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
9563 = DESIRED_HEADER_LINE_HEIGHT (w
);
9566 if (fonts_changed_p
)
9567 goto restore_buffers
;
9570 if (!line_number_displayed
9571 && !BUFFERP (w
->base_line_pos
))
9573 w
->base_line_pos
= Qnil
;
9574 w
->base_line_number
= Qnil
;
9579 /* When we reach a frame's selected window, redo the frame's menu bar. */
9580 if (update_mode_line
9581 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
9583 int redisplay_menu_p
= 0;
9585 if (FRAME_WINDOW_P (f
))
9587 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
9588 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
9590 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9594 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9596 if (redisplay_menu_p
)
9597 display_menu_bar (w
);
9599 #ifdef HAVE_WINDOW_SYSTEM
9600 if (WINDOWP (f
->tool_bar_window
)
9601 && (FRAME_TOOL_BAR_LINES (f
) > 0
9602 || auto_resize_tool_bars_p
))
9603 redisplay_tool_bar (f
);
9609 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9611 int start
, end
, whole
;
9613 /* Calculate the start and end positions for the current window.
9614 At some point, it would be nice to choose between scrollbars
9615 which reflect the whole buffer size, with special markers
9616 indicating narrowing, and scrollbars which reflect only the
9619 Note that mini-buffers sometimes aren't displaying any text. */
9620 if (!MINI_WINDOW_P (w
)
9621 || (w
== XWINDOW (minibuf_window
)
9622 && NILP (echo_area_buffer
[0])))
9625 start
= marker_position (w
->start
) - BEGV
;
9626 /* I don't think this is guaranteed to be right. For the
9627 moment, we'll pretend it is. */
9628 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
9632 if (whole
< (end
- start
))
9633 whole
= end
- start
;
9636 start
= end
= whole
= 0;
9638 /* Indicate what this scroll bar ought to be displaying now. */
9639 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
9641 /* Note that we actually used the scroll bar attached to this
9642 window, so it shouldn't be deleted at the end of redisplay. */
9643 (*redeem_scroll_bar_hook
) (w
);
9648 /* Restore current_buffer and value of point in it. */
9649 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
9650 set_buffer_internal_1 (old
);
9651 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
9653 unbind_to (count
, Qnil
);
9657 /* Build the complete desired matrix of WINDOW with a window start
9658 buffer position POS. Value is non-zero if successful. It is zero
9659 if fonts were loaded during redisplay which makes re-adjusting
9660 glyph matrices necessary. */
9663 try_window (window
, pos
)
9665 struct text_pos pos
;
9667 struct window
*w
= XWINDOW (window
);
9669 struct glyph_row
*last_text_row
= NULL
;
9671 /* Make POS the new window start. */
9672 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
9674 /* Mark cursor position as unknown. No overlay arrow seen. */
9675 w
->cursor
.vpos
= -1;
9676 overlay_arrow_seen
= 0;
9678 /* Initialize iterator and info to start at POS. */
9679 start_display (&it
, w
, pos
);
9681 /* Display all lines of W. */
9682 while (it
.current_y
< it
.last_visible_y
)
9684 if (display_line (&it
))
9685 last_text_row
= it
.glyph_row
- 1;
9686 if (fonts_changed_p
)
9690 /* If bottom moved off end of frame, change mode line percentage. */
9691 if (XFASTINT (w
->window_end_pos
) <= 0
9692 && Z
!= IT_CHARPOS (it
))
9693 w
->update_mode_line
= Qt
;
9695 /* Set window_end_pos to the offset of the last character displayed
9696 on the window from the end of current_buffer. Set
9697 window_end_vpos to its row number. */
9700 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
9701 w
->window_end_bytepos
9702 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9703 XSETFASTINT (w
->window_end_pos
,
9704 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9705 XSETFASTINT (w
->window_end_vpos
,
9706 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9707 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
9712 w
->window_end_bytepos
= 0;
9713 XSETFASTINT (w
->window_end_pos
, 0);
9714 XSETFASTINT (w
->window_end_vpos
, 0);
9717 /* But that is not valid info until redisplay finishes. */
9718 w
->window_end_valid
= Qnil
;
9724 /************************************************************************
9725 Window redisplay reusing current matrix when buffer has not changed
9726 ************************************************************************/
9728 /* Try redisplay of window W showing an unchanged buffer with a
9729 different window start than the last time it was displayed by
9730 reusing its current matrix. Value is non-zero if successful.
9731 W->start is the new window start. */
9734 try_window_reusing_current_matrix (w
)
9737 struct frame
*f
= XFRAME (w
->frame
);
9738 struct glyph_row
*row
, *bottom_row
;
9741 struct text_pos start
, new_start
;
9742 int nrows_scrolled
, i
;
9743 struct glyph_row
*last_text_row
;
9744 struct glyph_row
*last_reused_text_row
;
9745 struct glyph_row
*start_row
;
9746 int start_vpos
, min_y
, max_y
;
9749 if (/* This function doesn't handle terminal frames. */
9751 /* Don't try to reuse the display if windows have been split
9753 || windows_or_buffers_changed
)
9756 /* Can't do this if region may have changed. */
9757 if ((!NILP (Vtransient_mark_mode
)
9758 && !NILP (current_buffer
->mark_active
))
9759 || !NILP (w
->region_showing
)
9760 || !NILP (Vshow_trailing_whitespace
))
9763 /* If top-line visibility has changed, give up. */
9764 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9765 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
9768 /* Give up if old or new display is scrolled vertically. We could
9769 make this function handle this, but right now it doesn't. */
9770 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9771 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
9774 /* The variable new_start now holds the new window start. The old
9775 start `start' can be determined from the current matrix. */
9776 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
9777 start
= start_row
->start
.pos
;
9778 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
9780 /* Clear the desired matrix for the display below. */
9781 clear_glyph_matrix (w
->desired_matrix
);
9783 if (CHARPOS (new_start
) <= CHARPOS (start
))
9787 IF_DEBUG (debug_method_add (w
, "twu1"));
9789 /* Display up to a row that can be reused. The variable
9790 last_text_row is set to the last row displayed that displays
9792 start_display (&it
, w
, new_start
);
9793 first_row_y
= it
.current_y
;
9794 w
->cursor
.vpos
= -1;
9795 last_text_row
= last_reused_text_row
= NULL
;
9796 while (it
.current_y
< it
.last_visible_y
9797 && IT_CHARPOS (it
) < CHARPOS (start
)
9798 && !fonts_changed_p
)
9799 if (display_line (&it
))
9800 last_text_row
= it
.glyph_row
- 1;
9802 /* A value of current_y < last_visible_y means that we stopped
9803 at the previous window start, which in turn means that we
9804 have at least one reusable row. */
9805 if (it
.current_y
< it
.last_visible_y
)
9807 nrows_scrolled
= it
.vpos
;
9809 /* Find PT if not already found in the lines displayed. */
9810 if (w
->cursor
.vpos
< 0)
9812 int dy
= it
.current_y
- first_row_y
;
9814 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9815 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9817 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
9818 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9820 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
9821 dy
, nrows_scrolled
);
9825 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
9831 /* Give up if point was not found. This shouldn't
9832 happen often; not more often than with try_window
9834 if (w
->cursor
.vpos
< 0)
9836 clear_glyph_matrix (w
->desired_matrix
);
9841 /* Scroll the display. Do it before the current matrix is
9842 changed. The problem here is that update has not yet
9843 run, i.e. part of the current matrix is not up to date.
9844 scroll_run_hook will clear the cursor, and use the
9845 current matrix to get the height of the row the cursor is
9847 run
.current_y
= first_row_y
;
9848 run
.desired_y
= it
.current_y
;
9849 run
.height
= it
.last_visible_y
- it
.current_y
;
9851 && run
.current_y
!= run
.desired_y
)
9854 rif
->update_window_begin_hook (w
);
9855 rif
->clear_mouse_face (w
);
9856 rif
->scroll_run_hook (w
, &run
);
9857 rif
->update_window_end_hook (w
, 0, 0);
9861 /* Shift current matrix down by nrows_scrolled lines. */
9862 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9863 rotate_matrix (w
->current_matrix
,
9865 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9868 /* Disable lines not reused. */
9869 for (i
= 0; i
< it
.vpos
; ++i
)
9870 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
9872 /* Re-compute Y positions. */
9873 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
) + nrows_scrolled
;
9874 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9875 max_y
= it
.last_visible_y
;
9876 while (row
< bottom_row
)
9878 row
->y
= it
.current_y
;
9881 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9882 else if (row
->y
+ row
->height
> max_y
)
9884 = row
->height
- (row
->y
+ row
->height
- max_y
);
9886 row
->visible_height
= row
->height
;
9888 it
.current_y
+= row
->height
;
9891 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9892 last_reused_text_row
= row
;
9893 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
9899 /* Update window_end_pos etc.; last_reused_text_row is the last
9900 reused row from the current matrix containing text, if any.
9901 The value of last_text_row is the last displayed line
9903 if (last_reused_text_row
)
9905 w
->window_end_bytepos
9906 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
9907 XSETFASTINT (w
->window_end_pos
,
9908 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
9909 XSETFASTINT (w
->window_end_vpos
,
9910 MATRIX_ROW_VPOS (last_reused_text_row
,
9911 w
->current_matrix
));
9913 else if (last_text_row
)
9915 w
->window_end_bytepos
9916 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9917 XSETFASTINT (w
->window_end_pos
,
9918 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9919 XSETFASTINT (w
->window_end_vpos
,
9920 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9924 /* This window must be completely empty. */
9925 w
->window_end_bytepos
= 0;
9926 XSETFASTINT (w
->window_end_pos
, 0);
9927 XSETFASTINT (w
->window_end_vpos
, 0);
9929 w
->window_end_valid
= Qnil
;
9931 /* Update hint: don't try scrolling again in update_window. */
9932 w
->desired_matrix
->no_scrolling_p
= 1;
9935 debug_method_add (w
, "try_window_reusing_current_matrix 1");
9939 else if (CHARPOS (new_start
) > CHARPOS (start
))
9941 struct glyph_row
*pt_row
, *row
;
9942 struct glyph_row
*first_reusable_row
;
9943 struct glyph_row
*first_row_to_display
;
9945 int yb
= window_text_bottom_y (w
);
9947 IF_DEBUG (debug_method_add (w
, "twu2"));
9949 /* Find the row starting at new_start, if there is one. Don't
9950 reuse a partially visible line at the end. */
9951 first_reusable_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9952 while (first_reusable_row
->enabled_p
9953 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
9954 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9955 < CHARPOS (new_start
)))
9956 ++first_reusable_row
;
9958 /* Give up if there is no row to reuse. */
9959 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
9960 || !first_reusable_row
->enabled_p
9961 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9962 != CHARPOS (new_start
)))
9965 /* We can reuse fully visible rows beginning with
9966 first_reusable_row to the end of the window. Set
9967 first_row_to_display to the first row that cannot be reused.
9968 Set pt_row to the row containing point, if there is any. */
9969 first_row_to_display
= first_reusable_row
;
9971 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
9973 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
9974 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
9975 pt_row
= first_row_to_display
;
9977 ++first_row_to_display
;
9980 /* Start displaying at the start of first_row_to_display. */
9981 xassert (first_row_to_display
->y
< yb
);
9982 init_to_row_start (&it
, w
, first_row_to_display
);
9983 nrows_scrolled
= MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
);
9984 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
9986 it
.current_y
= first_row_to_display
->y
- first_reusable_row
->y
;
9988 /* Display lines beginning with first_row_to_display in the
9989 desired matrix. Set last_text_row to the last row displayed
9990 that displays text. */
9991 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
9993 w
->cursor
.vpos
= -1;
9994 last_text_row
= NULL
;
9995 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
9996 if (display_line (&it
))
9997 last_text_row
= it
.glyph_row
- 1;
9999 /* Give up If point isn't in a row displayed or reused. */
10000 if (w
->cursor
.vpos
< 0)
10002 clear_glyph_matrix (w
->desired_matrix
);
10006 /* If point is in a reused row, adjust y and vpos of the cursor
10010 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10011 w
->current_matrix
);
10012 w
->cursor
.y
-= first_reusable_row
->y
;
10015 /* Scroll the display. */
10016 run
.current_y
= first_reusable_row
->y
;
10017 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10018 run
.height
= it
.last_visible_y
- run
.current_y
;
10021 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10023 rif
->update_window_begin_hook (w
);
10024 rif
->clear_mouse_face (w
);
10025 rif
->scroll_run_hook (w
, &run
);
10026 rif
->update_window_end_hook (w
, 0, 0);
10030 /* Adjust Y positions of reused rows. */
10031 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10032 row
= first_reusable_row
;
10033 dy
= first_reusable_row
->y
;
10034 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10035 max_y
= it
.last_visible_y
;
10036 while (row
< first_row_to_display
)
10039 if (row
->y
< min_y
)
10040 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10041 else if (row
->y
+ row
->height
> max_y
)
10042 row
->visible_height
10043 = row
->height
- (row
->y
+ row
->height
- max_y
);
10045 row
->visible_height
= row
->height
;
10049 /* Disable rows not reused. */
10050 while (row
< bottom_row
)
10052 row
->enabled_p
= 0;
10056 /* Scroll the current matrix. */
10057 xassert (nrows_scrolled
> 0);
10058 rotate_matrix (w
->current_matrix
,
10060 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10063 /* Adjust window end. A null value of last_text_row means that
10064 the window end is in reused rows which in turn means that
10065 only its vpos can have changed. */
10068 w
->window_end_bytepos
10069 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10070 XSETFASTINT (w
->window_end_pos
,
10071 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10072 XSETFASTINT (w
->window_end_vpos
,
10073 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10077 XSETFASTINT (w
->window_end_vpos
,
10078 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10081 w
->window_end_valid
= Qnil
;
10082 w
->desired_matrix
->no_scrolling_p
= 1;
10085 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10095 /************************************************************************
10096 Window redisplay reusing current matrix when buffer has changed
10097 ************************************************************************/
10099 static struct glyph_row
*get_last_unchanged_at_beg_row
P_ ((struct window
*));
10100 static struct glyph_row
*get_first_unchanged_at_end_row
P_ ((struct window
*,
10102 static struct glyph_row
*
10103 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10104 struct glyph_row
*));
10107 /* Return the last row in MATRIX displaying text. If row START is
10108 non-null, start searching with that row. IT gives the dimensions
10109 of the display. Value is null if matrix is empty; otherwise it is
10110 a pointer to the row found. */
10112 static struct glyph_row
*
10113 find_last_row_displaying_text (matrix
, it
, start
)
10114 struct glyph_matrix
*matrix
;
10116 struct glyph_row
*start
;
10118 struct glyph_row
*row
, *row_found
;
10120 /* Set row_found to the last row in IT->w's current matrix
10121 displaying text. The loop looks funny but think of partially
10124 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
10125 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10127 xassert (row
->enabled_p
);
10129 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
10138 /* Return the last row in the current matrix of W that is not affected
10139 by changes at the start of current_buffer that occurred since the
10140 last time W was redisplayed. Value is null if no such row exists.
10142 The global variable beg_unchanged has to contain the number of
10143 bytes unchanged at the start of current_buffer. BEG +
10144 beg_unchanged is the buffer position of the first changed byte in
10145 current_buffer. Characters at positions < BEG + beg_unchanged are
10146 at the same buffer positions as they were when the current matrix
10149 static struct glyph_row
*
10150 get_last_unchanged_at_beg_row (w
)
10153 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
10154 struct glyph_row
*row
;
10155 struct glyph_row
*row_found
= NULL
;
10156 int yb
= window_text_bottom_y (w
);
10158 /* Find the last row displaying unchanged text. */
10159 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10160 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
10161 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
10163 if (/* If row ends before first_changed_pos, it is unchanged,
10164 except in some case. */
10165 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
10166 /* When row ends in ZV and we write at ZV it is not
10168 && !row
->ends_at_zv_p
10169 /* When first_changed_pos is the end of a continued line,
10170 row is not unchanged because it may be no longer
10172 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
10173 && row
->continued_p
))
10176 /* Stop if last visible row. */
10177 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
10187 /* Find the first glyph row in the current matrix of W that is not
10188 affected by changes at the end of current_buffer since the last
10189 time the window was redisplayed. Return in *DELTA the number of
10190 chars by which buffer positions in unchanged text at the end of
10191 current_buffer must be adjusted. Return in *DELTA_BYTES the
10192 corresponding number of bytes. Value is null if no such row
10193 exists, i.e. all rows are affected by changes. */
10195 static struct glyph_row
*
10196 get_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
10198 int *delta
, *delta_bytes
;
10200 struct glyph_row
*row
;
10201 struct glyph_row
*row_found
= NULL
;
10203 *delta
= *delta_bytes
= 0;
10205 /* A value of window_end_pos >= end_unchanged means that the window
10206 end is in the range of changed text. If so, there is no
10207 unchanged row at the end of W's current matrix. */
10208 xassert (!NILP (w
->window_end_valid
));
10209 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
10212 /* Set row to the last row in W's current matrix displaying text. */
10213 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10215 /* If matrix is entirely empty, no unchanged row exists. */
10216 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10218 /* The value of row is the last glyph row in the matrix having a
10219 meaningful buffer position in it. The end position of row
10220 corresponds to window_end_pos. This allows us to translate
10221 buffer positions in the current matrix to current buffer
10222 positions for characters not in changed text. */
10223 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
10224 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
10225 int last_unchanged_pos
, last_unchanged_pos_old
;
10226 struct glyph_row
*first_text_row
10227 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10229 *delta
= Z
- Z_old
;
10230 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
10232 /* Set last_unchanged_pos to the buffer position of the last
10233 character in the buffer that has not been changed. Z is the
10234 index + 1 of the last byte in current_buffer, i.e. by
10235 subtracting end_unchanged we get the index of the last
10236 unchanged character, and we have to add BEG to get its buffer
10238 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
10239 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
10241 /* Search backward from ROW for a row displaying a line that
10242 starts at a minimum position >= last_unchanged_pos_old. */
10243 while (row
>= first_text_row
)
10245 xassert (row
->enabled_p
);
10246 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
));
10248 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
10254 xassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
10259 /* Make sure that glyph rows in the current matrix of window W
10260 reference the same glyph memory as corresponding rows in the
10261 frame's frame matrix. This function is called after scrolling W's
10262 current matrix on a terminal frame in try_window_id and
10263 try_window_reusing_current_matrix. */
10266 sync_frame_with_window_matrix_rows (w
)
10269 struct frame
*f
= XFRAME (w
->frame
);
10270 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
10272 /* Preconditions: W must be a leaf window and full-width. Its frame
10273 must have a frame matrix. */
10274 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
10275 xassert (WINDOW_FULL_WIDTH_P (w
));
10276 xassert (!FRAME_WINDOW_P (f
));
10278 /* If W is a full-width window, glyph pointers in W's current matrix
10279 have, by definition, to be the same as glyph pointers in the
10280 corresponding frame matrix. */
10281 window_row
= w
->current_matrix
->rows
;
10282 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
10283 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
10284 while (window_row
< window_row_end
)
10288 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
10289 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
10291 /* Disable frame rows whose corresponding window rows have
10292 been disabled in try_window_id. */
10293 if (!window_row
->enabled_p
)
10294 frame_row
->enabled_p
= 0;
10296 ++window_row
, ++frame_row
;
10301 /* Find the glyph row in window W containing CHARPOS. Consider all
10302 rows between START and END (not inclusive). END null means search
10303 all rows to the end of the display area of W. Value is the row
10304 containing CHARPOS or null. */
10306 static struct glyph_row
*
10307 row_containing_pos (w
, charpos
, start
, end
)
10310 struct glyph_row
*start
, *end
;
10312 struct glyph_row
*row
= start
;
10315 /* If we happen to start on a header-line, skip that. */
10316 if (row
->mode_line_p
)
10319 if ((end
&& row
>= end
) || !row
->enabled_p
)
10322 last_y
= window_text_bottom_y (w
);
10324 while ((end
== NULL
|| row
< end
)
10325 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
10326 /* The end position of a row equals the start
10327 position of the next row. If CHARPOS is there, we
10328 would rather display it in the next line, except
10329 when this line ends in ZV. */
10330 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
10331 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
10332 || !row
->ends_at_zv_p
)))
10333 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
10336 /* Give up if CHARPOS not found. */
10337 if ((end
&& row
>= end
)
10338 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
10339 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
10346 /* Try to redisplay window W by reusing its existing display. W's
10347 current matrix must be up to date when this function is called,
10348 i.e. window_end_valid must not be nil.
10352 1 if display has been updated
10353 0 if otherwise unsuccessful
10354 -1 if redisplay with same window start is known not to succeed
10356 The following steps are performed:
10358 1. Find the last row in the current matrix of W that is not
10359 affected by changes at the start of current_buffer. If no such row
10362 2. Find the first row in W's current matrix that is not affected by
10363 changes at the end of current_buffer. Maybe there is no such row.
10365 3. Display lines beginning with the row + 1 found in step 1 to the
10366 row found in step 2 or, if step 2 didn't find a row, to the end of
10369 4. If cursor is not known to appear on the window, give up.
10371 5. If display stopped at the row found in step 2, scroll the
10372 display and current matrix as needed.
10374 6. Maybe display some lines at the end of W, if we must. This can
10375 happen under various circumstances, like a partially visible line
10376 becoming fully visible, or because newly displayed lines are displayed
10377 in smaller font sizes.
10379 7. Update W's window end information. */
10381 /* Check that window end is what we expect it to be. */
10387 struct frame
*f
= XFRAME (w
->frame
);
10388 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
10389 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
10390 struct glyph_row
*last_unchanged_at_beg_row
;
10391 struct glyph_row
*first_unchanged_at_end_row
;
10392 struct glyph_row
*row
;
10393 struct glyph_row
*bottom_row
;
10396 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
10397 struct text_pos start_pos
;
10399 int first_unchanged_at_end_vpos
= 0;
10400 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
10401 struct text_pos start
;
10403 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10405 /* Check pre-conditions. Window end must be valid, otherwise
10406 the current matrix would not be up to date. */
10407 xassert (!NILP (w
->window_end_valid
));
10408 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
10409 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
10411 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
10412 only if buffer has really changed. The reason is that the gap is
10413 initially at Z for freshly visited files. The code below would
10414 set end_unchanged to 0 in that case. */
10415 if (MODIFF
> SAVE_MODIFF
10416 /* This seems to happen sometimes after saving a buffer. */
10417 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
10419 if (GPT
- BEG
< BEG_UNCHANGED
)
10420 BEG_UNCHANGED
= GPT
- BEG
;
10421 if (Z
- GPT
< END_UNCHANGED
)
10422 END_UNCHANGED
= Z
- GPT
;
10425 /* If window starts after a line end, and the last change is in
10426 front of that newline, then changes don't affect the display.
10427 This case happens with stealth-fontification. Note that although
10428 the display is unchanged, glyph positions in the matrix have to
10429 be adjusted, of course. */
10430 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10431 if (CHARPOS (start
) > BEGV
10432 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
10433 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
10434 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10436 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
10437 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
10441 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10442 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
10444 increment_matrix_positions (w
->current_matrix
,
10445 MATRIX_ROW_VPOS (r0
, current_matrix
),
10446 MATRIX_ROW_VPOS (r1
, current_matrix
),
10447 delta
, delta_bytes
);
10450 #if 0 /* If changes are all in front of the window start, the
10451 distance of the last displayed glyph from Z hasn't
10454 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10455 w
->window_end_bytepos
10456 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10462 /* Return quickly if changes are all below what is displayed in the
10463 window, and if PT is in the window. */
10464 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
10465 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10467 /* We have to update window end positions because the buffer's
10468 size has changed. */
10470 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10471 w
->window_end_bytepos
10472 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10474 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10475 row
= row_containing_pos (w
, PT
, row
, NULL
);
10476 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10480 /* Check that window start agrees with the start of the first glyph
10481 row in its current matrix. Check this after we know the window
10482 start is not in changed text, otherwise positions would not be
10484 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10485 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
10488 /* Compute the position at which we have to start displaying new
10489 lines. Some of the lines at the top of the window might be
10490 reusable because they are not displaying changed text. Find the
10491 last row in W's current matrix not affected by changes at the
10492 start of current_buffer. Value is null if changes start in the
10493 first line of window. */
10494 last_unchanged_at_beg_row
= get_last_unchanged_at_beg_row (w
);
10495 if (last_unchanged_at_beg_row
)
10497 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
10498 start_pos
= it
.current
.pos
;
10500 /* Start displaying new lines in the desired matrix at the same
10501 vpos we would use in the current matrix, i.e. below
10502 last_unchanged_at_beg_row. */
10503 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
10505 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10506 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
10508 xassert (it
.hpos
== 0 && it
.current_x
== 0);
10512 /* There are no reusable lines at the start of the window.
10513 Start displaying in the first line. */
10514 start_display (&it
, w
, start
);
10515 start_pos
= it
.current
.pos
;
10518 /* Find the first row that is not affected by changes at the end of
10519 the buffer. Value will be null if there is no unchanged row, in
10520 which case we must redisplay to the end of the window. delta
10521 will be set to the value by which buffer positions beginning with
10522 first_unchanged_at_end_row have to be adjusted due to text
10524 first_unchanged_at_end_row
10525 = get_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
10526 IF_DEBUG (debug_delta
= delta
);
10527 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
10529 /* Set stop_pos to the buffer position up to which we will have to
10530 display new lines. If first_unchanged_at_end_row != NULL, this
10531 is the buffer position of the start of the line displayed in that
10532 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
10533 that we don't stop at a buffer position. */
10535 if (first_unchanged_at_end_row
)
10537 xassert (last_unchanged_at_beg_row
== NULL
10538 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
10540 /* If this is a continuation line, move forward to the next one
10541 that isn't. Changes in lines above affect this line.
10542 Caution: this may move first_unchanged_at_end_row to a row
10543 not displaying text. */
10544 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
10545 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10546 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10547 < it
.last_visible_y
))
10548 ++first_unchanged_at_end_row
;
10550 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10551 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10552 >= it
.last_visible_y
))
10553 first_unchanged_at_end_row
= NULL
;
10556 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
10558 first_unchanged_at_end_vpos
10559 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
10560 xassert (stop_pos
>= Z
- END_UNCHANGED
);
10563 else if (last_unchanged_at_beg_row
== NULL
)
10569 /* Either there is no unchanged row at the end, or the one we have
10570 now displays text. This is a necessary condition for the window
10571 end pos calculation at the end of this function. */
10572 xassert (first_unchanged_at_end_row
== NULL
10573 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
10575 debug_last_unchanged_at_beg_vpos
10576 = (last_unchanged_at_beg_row
10577 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
10579 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
10581 #endif /* GLYPH_DEBUG != 0 */
10584 /* Display new lines. Set last_text_row to the last new line
10585 displayed which has text on it, i.e. might end up as being the
10586 line where the window_end_vpos is. */
10587 w
->cursor
.vpos
= -1;
10588 last_text_row
= NULL
;
10589 overlay_arrow_seen
= 0;
10590 while (it
.current_y
< it
.last_visible_y
10591 && !fonts_changed_p
10592 && (first_unchanged_at_end_row
== NULL
10593 || IT_CHARPOS (it
) < stop_pos
))
10595 if (display_line (&it
))
10596 last_text_row
= it
.glyph_row
- 1;
10599 if (fonts_changed_p
)
10603 /* Compute differences in buffer positions, y-positions etc. for
10604 lines reused at the bottom of the window. Compute what we can
10606 if (first_unchanged_at_end_row
10607 /* No lines reused because we displayed everything up to the
10608 bottom of the window. */
10609 && it
.current_y
< it
.last_visible_y
)
10612 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
10614 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
10615 run
.current_y
= first_unchanged_at_end_row
->y
;
10616 run
.desired_y
= run
.current_y
+ dy
;
10617 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
10621 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
10622 first_unchanged_at_end_row
= NULL
;
10624 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
10627 /* Find the cursor if not already found. We have to decide whether
10628 PT will appear on this window (it sometimes doesn't, but this is
10629 not a very frequent case.) This decision has to be made before
10630 the current matrix is altered. A value of cursor.vpos < 0 means
10631 that PT is either in one of the lines beginning at
10632 first_unchanged_at_end_row or below the window. Don't care for
10633 lines that might be displayed later at the window end; as
10634 mentioned, this is not a frequent case. */
10635 if (w
->cursor
.vpos
< 0)
10637 /* Cursor in unchanged rows at the top? */
10638 if (PT
< CHARPOS (start_pos
)
10639 && last_unchanged_at_beg_row
)
10641 row
= row_containing_pos (w
, PT
,
10642 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
10643 last_unchanged_at_beg_row
+ 1);
10645 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10648 /* Start from first_unchanged_at_end_row looking for PT. */
10649 else if (first_unchanged_at_end_row
)
10651 row
= row_containing_pos (w
, PT
- delta
,
10652 first_unchanged_at_end_row
, NULL
);
10654 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
10655 delta_bytes
, dy
, dvpos
);
10658 /* Give up if cursor was not found. */
10659 if (w
->cursor
.vpos
< 0)
10661 clear_glyph_matrix (w
->desired_matrix
);
10666 /* Don't let the cursor end in the scroll margins. */
10668 int this_scroll_margin
, cursor_height
;
10670 this_scroll_margin
= max (0, scroll_margin
);
10671 this_scroll_margin
= min (this_scroll_margin
,
10672 XFASTINT (w
->height
) / 4);
10673 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
10674 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
10676 if ((w
->cursor
.y
< this_scroll_margin
10677 && CHARPOS (start
) > BEGV
)
10678 /* Don't take scroll margin into account at the bottom because
10679 old redisplay didn't do it either. */
10680 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
10682 w
->cursor
.vpos
= -1;
10683 clear_glyph_matrix (w
->desired_matrix
);
10688 /* Scroll the display. Do it before changing the current matrix so
10689 that xterm.c doesn't get confused about where the cursor glyph is
10691 if (dy
&& run
.height
)
10695 if (FRAME_WINDOW_P (f
))
10697 rif
->update_window_begin_hook (w
);
10698 rif
->clear_mouse_face (w
);
10699 rif
->scroll_run_hook (w
, &run
);
10700 rif
->update_window_end_hook (w
, 0, 0);
10704 /* Terminal frame. In this case, dvpos gives the number of
10705 lines to scroll by; dvpos < 0 means scroll up. */
10706 int first_unchanged_at_end_vpos
10707 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
10708 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
10709 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
10711 /* Perform the operation on the screen. */
10714 /* Scroll last_unchanged_at_beg_row to the end of the
10715 window down dvpos lines. */
10716 set_terminal_window (end
);
10718 /* On dumb terminals delete dvpos lines at the end
10719 before inserting dvpos empty lines. */
10720 if (!scroll_region_ok
)
10721 ins_del_lines (end
- dvpos
, -dvpos
);
10723 /* Insert dvpos empty lines in front of
10724 last_unchanged_at_beg_row. */
10725 ins_del_lines (from
, dvpos
);
10727 else if (dvpos
< 0)
10729 /* Scroll up last_unchanged_at_beg_vpos to the end of
10730 the window to last_unchanged_at_beg_vpos - |dvpos|. */
10731 set_terminal_window (end
);
10733 /* Delete dvpos lines in front of
10734 last_unchanged_at_beg_vpos. ins_del_lines will set
10735 the cursor to the given vpos and emit |dvpos| delete
10737 ins_del_lines (from
+ dvpos
, dvpos
);
10739 /* On a dumb terminal insert dvpos empty lines at the
10741 if (!scroll_region_ok
)
10742 ins_del_lines (end
+ dvpos
, -dvpos
);
10745 set_terminal_window (0);
10751 /* Shift reused rows of the current matrix to the right position.
10752 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
10754 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10755 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
10758 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
10759 bottom_vpos
, dvpos
);
10760 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
10763 else if (dvpos
> 0)
10765 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
10766 bottom_vpos
, dvpos
);
10767 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
10768 first_unchanged_at_end_vpos
+ dvpos
, 0);
10771 /* For frame-based redisplay, make sure that current frame and window
10772 matrix are in sync with respect to glyph memory. */
10773 if (!FRAME_WINDOW_P (f
))
10774 sync_frame_with_window_matrix_rows (w
);
10776 /* Adjust buffer positions in reused rows. */
10778 increment_matrix_positions (current_matrix
,
10779 first_unchanged_at_end_vpos
+ dvpos
,
10780 bottom_vpos
, delta
, delta_bytes
);
10782 /* Adjust Y positions. */
10784 shift_glyph_matrix (w
, current_matrix
,
10785 first_unchanged_at_end_vpos
+ dvpos
,
10788 if (first_unchanged_at_end_row
)
10789 first_unchanged_at_end_row
+= dvpos
;
10791 /* If scrolling up, there may be some lines to display at the end of
10793 last_text_row_at_end
= NULL
;
10796 /* Set last_row to the glyph row in the current matrix where the
10797 window end line is found. It has been moved up or down in
10798 the matrix by dvpos. */
10799 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
10800 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
10802 /* If last_row is the window end line, it should display text. */
10803 xassert (last_row
->displays_text_p
);
10805 /* If window end line was partially visible before, begin
10806 displaying at that line. Otherwise begin displaying with the
10807 line following it. */
10808 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
10810 init_to_row_start (&it
, w
, last_row
);
10811 it
.vpos
= last_vpos
;
10812 it
.current_y
= last_row
->y
;
10816 init_to_row_end (&it
, w
, last_row
);
10817 it
.vpos
= 1 + last_vpos
;
10818 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
10822 /* We may start in a continuation line. If so, we have to get
10823 the right continuation_lines_width and current_x. */
10824 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
10825 it
.hpos
= it
.current_x
= 0;
10827 /* Display the rest of the lines at the window end. */
10828 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10829 while (it
.current_y
< it
.last_visible_y
10830 && !fonts_changed_p
)
10832 /* Is it always sure that the display agrees with lines in
10833 the current matrix? I don't think so, so we mark rows
10834 displayed invalid in the current matrix by setting their
10835 enabled_p flag to zero. */
10836 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
10837 if (display_line (&it
))
10838 last_text_row_at_end
= it
.glyph_row
- 1;
10842 /* Update window_end_pos and window_end_vpos. */
10843 if (first_unchanged_at_end_row
10844 && first_unchanged_at_end_row
->y
< it
.last_visible_y
10845 && !last_text_row_at_end
)
10847 /* Window end line if one of the preserved rows from the current
10848 matrix. Set row to the last row displaying text in current
10849 matrix starting at first_unchanged_at_end_row, after
10851 xassert (first_unchanged_at_end_row
->displays_text_p
);
10852 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
10853 first_unchanged_at_end_row
);
10854 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
10856 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
10857 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10858 XSETFASTINT (w
->window_end_vpos
,
10859 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
10861 else if (last_text_row_at_end
)
10863 XSETFASTINT (w
->window_end_pos
,
10864 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
10865 w
->window_end_bytepos
10866 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
10867 XSETFASTINT (w
->window_end_vpos
,
10868 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
10870 else if (last_text_row
)
10872 /* We have displayed either to the end of the window or at the
10873 end of the window, i.e. the last row with text is to be found
10874 in the desired matrix. */
10875 XSETFASTINT (w
->window_end_pos
,
10876 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10877 w
->window_end_bytepos
10878 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10879 XSETFASTINT (w
->window_end_vpos
,
10880 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
10882 else if (first_unchanged_at_end_row
== NULL
10883 && last_text_row
== NULL
10884 && last_text_row_at_end
== NULL
)
10886 /* Displayed to end of window, but no line containing text was
10887 displayed. Lines were deleted at the end of the window. */
10889 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
10891 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
10892 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10893 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
10894 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10895 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
10898 w
->window_end_vpos
= make_number (vpos
);
10903 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
10904 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
10906 /* Record that display has not been completed. */
10907 w
->window_end_valid
= Qnil
;
10908 w
->desired_matrix
->no_scrolling_p
= 1;
10914 /***********************************************************************
10915 More debugging support
10916 ***********************************************************************/
10920 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
10921 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
10924 /* Dump the contents of glyph matrix MATRIX on stderr. If
10925 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
10928 dump_glyph_matrix (matrix
, with_glyphs_p
)
10929 struct glyph_matrix
*matrix
;
10933 for (i
= 0; i
< matrix
->nrows
; ++i
)
10934 dump_glyph_row (matrix
, i
, with_glyphs_p
);
10938 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
10939 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
10942 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
10943 struct glyph_matrix
*matrix
;
10944 int vpos
, with_glyphs_p
;
10946 struct glyph_row
*row
;
10948 if (vpos
< 0 || vpos
>= matrix
->nrows
)
10951 row
= MATRIX_ROW (matrix
, vpos
);
10953 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFes X Y W H V A P\n");
10954 fprintf (stderr
, "=======================================================================\n");
10956 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d\
10957 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
10958 row
- matrix
->rows
,
10959 MATRIX_ROW_START_CHARPOS (row
),
10960 MATRIX_ROW_END_CHARPOS (row
),
10961 row
->used
[TEXT_AREA
],
10962 row
->contains_overlapping_glyphs_p
,
10965 row
->truncated_on_left_p
,
10966 row
->truncated_on_right_p
,
10967 row
->overlay_arrow_p
,
10969 MATRIX_ROW_CONTINUATION_LINE_P (row
),
10970 row
->displays_text_p
,
10973 row
->ends_in_middle_of_char_p
,
10974 row
->starts_in_middle_of_char_p
,
10979 row
->visible_height
,
10982 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
10983 row
->end
.overlay_string_index
);
10984 fprintf (stderr
, "%9d %5d\n",
10985 CHARPOS (row
->start
.string_pos
),
10986 CHARPOS (row
->end
.string_pos
));
10987 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
10988 row
->end
.dpvec_index
);
10992 struct glyph
*glyph
, *glyph_end
;
10993 int prev_had_glyphs_p
;
10995 glyph
= row
->glyphs
[TEXT_AREA
];
10996 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
10998 /* Glyph for a line end in text. */
10999 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
11002 if (glyph
< glyph_end
)
11004 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
11005 prev_had_glyphs_p
= 1;
11008 prev_had_glyphs_p
= 0;
11010 while (glyph
< glyph_end
)
11012 if (glyph
->type
== CHAR_GLYPH
)
11015 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11016 glyph
- row
->glyphs
[TEXT_AREA
],
11019 (BUFFERP (glyph
->object
)
11021 : (STRINGP (glyph
->object
)
11024 glyph
->pixel_width
,
11026 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
11030 glyph
->left_box_line_p
,
11031 glyph
->right_box_line_p
);
11033 else if (glyph
->type
== STRETCH_GLYPH
)
11036 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11037 glyph
- row
->glyphs
[TEXT_AREA
],
11040 (BUFFERP (glyph
->object
)
11042 : (STRINGP (glyph
->object
)
11045 glyph
->pixel_width
,
11049 glyph
->left_box_line_p
,
11050 glyph
->right_box_line_p
);
11052 else if (glyph
->type
== IMAGE_GLYPH
)
11055 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11056 glyph
- row
->glyphs
[TEXT_AREA
],
11059 (BUFFERP (glyph
->object
)
11061 : (STRINGP (glyph
->object
)
11064 glyph
->pixel_width
,
11068 glyph
->left_box_line_p
,
11069 glyph
->right_box_line_p
);
11077 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
11078 Sdump_glyph_matrix
, 0, 1, "p",
11079 "Dump the current matrix of the selected window to stderr.\n\
11080 Shows contents of glyph row structures. With non-nil optional\n\
11081 parameter WITH-GLYPHS-P, dump glyphs as well.")
11083 Lisp_Object with_glyphs_p
;
11085 struct window
*w
= XWINDOW (selected_window
);
11086 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11088 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
11089 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
11090 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
11091 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
11092 fprintf (stderr
, "=============================================\n");
11093 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
11098 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
11099 "Dump glyph row ROW to stderr.")
11103 CHECK_NUMBER (row
, 0);
11104 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
11109 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
,
11113 struct frame
*sf
= SELECTED_FRAME ();
11114 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)
11116 dump_glyph_row (m
, 0, 1);
11121 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
11122 Strace_redisplay_toggle
, 0, 0, "",
11123 "Toggle tracing of redisplay.")
11126 trace_redisplay_p
= !trace_redisplay_p
;
11131 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
11132 "Print STRING to stderr.")
11134 Lisp_Object string
;
11136 CHECK_STRING (string
, 0);
11137 fprintf (stderr
, "%s", XSTRING (string
)->data
);
11141 #endif /* GLYPH_DEBUG */
11145 /***********************************************************************
11146 Building Desired Matrix Rows
11147 ***********************************************************************/
11149 /* Return a temporary glyph row holding the glyphs of an overlay
11150 arrow. Only used for non-window-redisplay windows. */
11152 static struct glyph_row
*
11153 get_overlay_arrow_glyph_row (w
)
11156 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11157 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11158 struct buffer
*old
= current_buffer
;
11159 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
11160 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
11161 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
11165 int n_glyphs_before
;
11167 set_buffer_temp (buffer
);
11168 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
11169 it
.glyph_row
->used
[TEXT_AREA
] = 0;
11170 SET_TEXT_POS (it
.position
, 0, 0);
11172 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
11174 while (p
< arrow_end
)
11176 Lisp_Object face
, ilisp
;
11178 /* Get the next character. */
11180 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
11182 it
.c
= *p
, it
.len
= 1;
11185 /* Get its face. */
11186 XSETFASTINT (ilisp
, p
- arrow_string
);
11187 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
11188 it
.face_id
= compute_char_face (f
, it
.c
, face
);
11190 /* Compute its width, get its glyphs. */
11191 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
11192 SET_TEXT_POS (it
.position
, -1, -1);
11193 PRODUCE_GLYPHS (&it
);
11195 /* If this character doesn't fit any more in the line, we have
11196 to remove some glyphs. */
11197 if (it
.current_x
> it
.last_visible_x
)
11199 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
11204 set_buffer_temp (old
);
11205 return it
.glyph_row
;
11209 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
11210 glyphs are only inserted for terminal frames since we can't really
11211 win with truncation glyphs when partially visible glyphs are
11212 involved. Which glyphs to insert is determined by
11213 produce_special_glyphs. */
11216 insert_left_trunc_glyphs (it
)
11219 struct it truncate_it
;
11220 struct glyph
*from
, *end
, *to
, *toend
;
11222 xassert (!FRAME_WINDOW_P (it
->f
));
11224 /* Get the truncation glyphs. */
11226 truncate_it
.current_x
= 0;
11227 truncate_it
.face_id
= DEFAULT_FACE_ID
;
11228 truncate_it
.glyph_row
= &scratch_glyph_row
;
11229 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
11230 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
11231 truncate_it
.object
= make_number (0);
11232 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
11234 /* Overwrite glyphs from IT with truncation glyphs. */
11235 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
11236 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
11237 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
11238 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
11243 /* There may be padding glyphs left over. Remove them. */
11245 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
11247 while (from
< toend
)
11250 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
11254 /* Compute the pixel height and width of IT->glyph_row.
11256 Most of the time, ascent and height of a display line will be equal
11257 to the max_ascent and max_height values of the display iterator
11258 structure. This is not the case if
11260 1. We hit ZV without displaying anything. In this case, max_ascent
11261 and max_height will be zero.
11263 2. We have some glyphs that don't contribute to the line height.
11264 (The glyph row flag contributes_to_line_height_p is for future
11265 pixmap extensions).
11267 The first case is easily covered by using default values because in
11268 these cases, the line height does not really matter, except that it
11269 must not be zero. */
11272 compute_line_metrics (it
)
11275 struct glyph_row
*row
= it
->glyph_row
;
11278 if (FRAME_WINDOW_P (it
->f
))
11280 int i
, header_line_height
;
11282 /* The line may consist of one space only, that was added to
11283 place the cursor on it. If so, the row's height hasn't been
11285 if (row
->height
== 0)
11287 if (it
->max_ascent
+ it
->max_descent
== 0)
11288 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
11289 row
->ascent
= it
->max_ascent
;
11290 row
->height
= it
->max_ascent
+ it
->max_descent
;
11291 row
->phys_ascent
= it
->max_phys_ascent
;
11292 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11295 /* Compute the width of this line. */
11296 row
->pixel_width
= row
->x
;
11297 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
11298 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11300 xassert (row
->pixel_width
>= 0);
11301 xassert (row
->ascent
>= 0 && row
->height
> 0);
11303 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
11304 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
11306 /* If first line's physical ascent is larger than its logical
11307 ascent, use the physical ascent, and make the row taller.
11308 This makes accented characters fully visible. */
11309 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
11310 && row
->phys_ascent
> row
->ascent
)
11312 row
->height
+= row
->phys_ascent
- row
->ascent
;
11313 row
->ascent
= row
->phys_ascent
;
11316 /* Compute how much of the line is visible. */
11317 row
->visible_height
= row
->height
;
11319 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
11320 if (row
->y
< header_line_height
)
11321 row
->visible_height
-= header_line_height
- row
->y
;
11324 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
11325 if (row
->y
+ row
->height
> max_y
)
11326 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11331 row
->pixel_width
= row
->used
[TEXT_AREA
];
11332 row
->ascent
= row
->phys_ascent
= 0;
11333 row
->height
= row
->phys_height
= row
->visible_height
= 1;
11336 /* Compute a hash code for this row. */
11338 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11339 for (i
= 0; i
< row
->used
[area
]; ++i
)
11340 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
11341 + row
->glyphs
[area
][i
].u
.val
11342 + row
->glyphs
[area
][i
].face_id
11343 + row
->glyphs
[area
][i
].padding_p
11344 + (row
->glyphs
[area
][i
].type
<< 2));
11346 it
->max_ascent
= it
->max_descent
= 0;
11347 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
11351 /* Append one space to the glyph row of iterator IT if doing a
11352 window-based redisplay. DEFAULT_FACE_P non-zero means let the
11353 space have the default face, otherwise let it have the same face as
11354 IT->face_id. Value is non-zero if a space was added.
11356 This function is called to make sure that there is always one glyph
11357 at the end of a glyph row that the cursor can be set on under
11358 window-systems. (If there weren't such a glyph we would not know
11359 how wide and tall a box cursor should be displayed).
11361 At the same time this space let's a nicely handle clearing to the
11362 end of the line if the row ends in italic text. */
11365 append_space (it
, default_face_p
)
11367 int default_face_p
;
11369 if (FRAME_WINDOW_P (it
->f
))
11371 int n
= it
->glyph_row
->used
[TEXT_AREA
];
11373 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
11374 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
11376 /* Save some values that must not be changed. */
11377 int saved_x
= it
->current_x
;
11378 struct text_pos saved_pos
;
11379 int saved_what
= it
->what
;
11380 int saved_face_id
= it
->face_id
;
11381 Lisp_Object saved_object
;
11384 saved_object
= it
->object
;
11385 saved_pos
= it
->position
;
11387 it
->what
= IT_CHARACTER
;
11388 bzero (&it
->position
, sizeof it
->position
);
11389 it
->object
= make_number (0);
11393 if (default_face_p
)
11394 it
->face_id
= DEFAULT_FACE_ID
;
11395 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11396 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
11398 PRODUCE_GLYPHS (it
);
11400 it
->current_x
= saved_x
;
11401 it
->object
= saved_object
;
11402 it
->position
= saved_pos
;
11403 it
->what
= saved_what
;
11404 it
->face_id
= saved_face_id
;
11413 /* Extend the face of the last glyph in the text area of IT->glyph_row
11414 to the end of the display line. Called from display_line.
11415 If the glyph row is empty, add a space glyph to it so that we
11416 know the face to draw. Set the glyph row flag fill_line_p. */
11419 extend_face_to_end_of_line (it
)
11423 struct frame
*f
= it
->f
;
11425 /* If line is already filled, do nothing. */
11426 if (it
->current_x
>= it
->last_visible_x
)
11429 /* Face extension extends the background and box of IT->face_id
11430 to the end of the line. If the background equals the background
11431 of the frame, we haven't to do anything. */
11432 face
= FACE_FROM_ID (f
, it
->face_id
);
11433 if (FRAME_WINDOW_P (f
)
11434 && face
->box
== FACE_NO_BOX
11435 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
11439 /* Set the glyph row flag indicating that the face of the last glyph
11440 in the text area has to be drawn to the end of the text area. */
11441 it
->glyph_row
->fill_line_p
= 1;
11443 /* If current character of IT is not ASCII, make sure we have the
11444 ASCII face. This will be automatically undone the next time
11445 get_next_display_element returns a multibyte character. Note
11446 that the character will always be single byte in unibyte text. */
11447 if (!SINGLE_BYTE_CHAR_P (it
->c
))
11449 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
11452 if (FRAME_WINDOW_P (f
))
11454 /* If the row is empty, add a space with the current face of IT,
11455 so that we know which face to draw. */
11456 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
11458 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
11459 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
11460 it
->glyph_row
->used
[TEXT_AREA
] = 1;
11465 /* Save some values that must not be changed. */
11466 int saved_x
= it
->current_x
;
11467 struct text_pos saved_pos
;
11468 Lisp_Object saved_object
;
11469 int saved_what
= it
->what
;
11471 saved_object
= it
->object
;
11472 saved_pos
= it
->position
;
11474 it
->what
= IT_CHARACTER
;
11475 bzero (&it
->position
, sizeof it
->position
);
11476 it
->object
= make_number (0);
11480 PRODUCE_GLYPHS (it
);
11482 while (it
->current_x
<= it
->last_visible_x
)
11483 PRODUCE_GLYPHS (it
);
11485 /* Don't count these blanks really. It would let us insert a left
11486 truncation glyph below and make us set the cursor on them, maybe. */
11487 it
->current_x
= saved_x
;
11488 it
->object
= saved_object
;
11489 it
->position
= saved_pos
;
11490 it
->what
= saved_what
;
11495 /* Value is non-zero if text starting at CHARPOS in current_buffer is
11496 trailing whitespace. */
11499 trailing_whitespace_p (charpos
)
11502 int bytepos
= CHAR_TO_BYTE (charpos
);
11505 while (bytepos
< ZV_BYTE
11506 && (c
= FETCH_CHAR (bytepos
),
11507 c
== ' ' || c
== '\t'))
11510 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
11512 if (bytepos
!= PT_BYTE
)
11519 /* Highlight trailing whitespace, if any, in ROW. */
11522 highlight_trailing_whitespace (f
, row
)
11524 struct glyph_row
*row
;
11526 int used
= row
->used
[TEXT_AREA
];
11530 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
11531 struct glyph
*glyph
= start
+ used
- 1;
11533 /* Skip over the space glyph inserted to display the
11534 cursor at the end of a line. */
11535 if (glyph
->type
== CHAR_GLYPH
11536 && glyph
->u
.ch
== ' '
11537 && INTEGERP (glyph
->object
))
11540 /* If last glyph is a space or stretch, and it's trailing
11541 whitespace, set the face of all trailing whitespace glyphs in
11542 IT->glyph_row to `trailing-whitespace'. */
11544 && BUFFERP (glyph
->object
)
11545 && (glyph
->type
== STRETCH_GLYPH
11546 || (glyph
->type
== CHAR_GLYPH
11547 && glyph
->u
.ch
== ' '))
11548 && trailing_whitespace_p (glyph
->charpos
))
11550 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
11552 while (glyph
>= start
11553 && BUFFERP (glyph
->object
)
11554 && (glyph
->type
== STRETCH_GLYPH
11555 || (glyph
->type
== CHAR_GLYPH
11556 && glyph
->u
.ch
== ' ')))
11557 (glyph
--)->face_id
= face_id
;
11563 /* Construct the glyph row IT->glyph_row in the desired matrix of
11564 IT->w from text at the current position of IT. See dispextern.h
11565 for an overview of struct it. Value is non-zero if
11566 IT->glyph_row displays text, as opposed to a line displaying ZV
11573 struct glyph_row
*row
= it
->glyph_row
;
11575 /* We always start displaying at hpos zero even if hscrolled. */
11576 xassert (it
->hpos
== 0 && it
->current_x
== 0);
11578 /* We must not display in a row that's not a text row. */
11579 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
11580 < it
->w
->desired_matrix
->nrows
);
11582 /* Is IT->w showing the region? */
11583 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
11585 /* Clear the result glyph row and enable it. */
11586 prepare_desired_row (row
);
11588 row
->y
= it
->current_y
;
11589 row
->start
= it
->current
;
11590 row
->continuation_lines_width
= it
->continuation_lines_width
;
11591 row
->displays_text_p
= 1;
11592 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
11593 it
->starts_in_middle_of_char_p
= 0;
11595 /* Arrange the overlays nicely for our purposes. Usually, we call
11596 display_line on only one line at a time, in which case this
11597 can't really hurt too much, or we call it on lines which appear
11598 one after another in the buffer, in which case all calls to
11599 recenter_overlay_lists but the first will be pretty cheap. */
11600 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
11602 /* Move over display elements that are not visible because we are
11603 hscrolled. This may stop at an x-position < IT->first_visible_x
11604 if the first glyph is partially visible or if we hit a line end. */
11605 if (it
->current_x
< it
->first_visible_x
)
11606 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
11607 MOVE_TO_POS
| MOVE_TO_X
);
11609 /* Get the initial row height. This is either the height of the
11610 text hscrolled, if there is any, or zero. */
11611 row
->ascent
= it
->max_ascent
;
11612 row
->height
= it
->max_ascent
+ it
->max_descent
;
11613 row
->phys_ascent
= it
->max_phys_ascent
;
11614 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11616 /* Loop generating characters. The loop is left with IT on the next
11617 character to display. */
11620 int n_glyphs_before
, hpos_before
, x_before
;
11622 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
11624 /* Retrieve the next thing to display. Value is zero if end of
11626 if (!get_next_display_element (it
))
11628 /* Maybe add a space at the end of this line that is used to
11629 display the cursor there under X. Set the charpos of the
11630 first glyph of blank lines not corresponding to any text
11632 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
11633 || row
->used
[TEXT_AREA
] == 0)
11635 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
11636 row
->displays_text_p
= 0;
11638 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
11639 row
->indicate_empty_line_p
= 1;
11642 it
->continuation_lines_width
= 0;
11643 row
->ends_at_zv_p
= 1;
11647 /* Now, get the metrics of what we want to display. This also
11648 generates glyphs in `row' (which is IT->glyph_row). */
11649 n_glyphs_before
= row
->used
[TEXT_AREA
];
11652 /* Remember the line height so far in case the next element doesn't
11653 fit on the line. */
11654 if (!it
->truncate_lines_p
)
11656 ascent
= it
->max_ascent
;
11657 descent
= it
->max_descent
;
11658 phys_ascent
= it
->max_phys_ascent
;
11659 phys_descent
= it
->max_phys_descent
;
11662 PRODUCE_GLYPHS (it
);
11664 /* If this display element was in marginal areas, continue with
11666 if (it
->area
!= TEXT_AREA
)
11668 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11669 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11670 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11671 row
->phys_height
= max (row
->phys_height
,
11672 it
->max_phys_ascent
+ it
->max_phys_descent
);
11673 set_iterator_to_next (it
);
11677 /* Does the display element fit on the line? If we truncate
11678 lines, we should draw past the right edge of the window. If
11679 we don't truncate, we want to stop so that we can display the
11680 continuation glyph before the right margin. If lines are
11681 continued, there are two possible strategies for characters
11682 resulting in more than 1 glyph (e.g. tabs): Display as many
11683 glyphs as possible in this line and leave the rest for the
11684 continuation line, or display the whole element in the next
11685 line. Original redisplay did the former, so we do it also. */
11686 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11687 hpos_before
= it
->hpos
;
11691 && it
->current_x
< it
->last_visible_x
)
11694 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11695 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11696 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11697 row
->phys_height
= max (row
->phys_height
,
11698 it
->max_phys_ascent
+ it
->max_phys_descent
);
11699 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
11700 row
->x
= x
- it
->first_visible_x
;
11705 struct glyph
*glyph
;
11707 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
11709 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11710 new_x
= x
+ glyph
->pixel_width
;
11712 if (/* Lines are continued. */
11713 !it
->truncate_lines_p
11714 && (/* Glyph doesn't fit on the line. */
11715 new_x
> it
->last_visible_x
11716 /* Or it fits exactly on a window system frame. */
11717 || (new_x
== it
->last_visible_x
11718 && FRAME_WINDOW_P (it
->f
))))
11720 /* End of a continued line. */
11723 || (new_x
== it
->last_visible_x
11724 && FRAME_WINDOW_P (it
->f
)))
11726 /* Current glyph is the only one on the line or
11727 fits exactly on the line. We must continue
11728 the line because we can't draw the cursor
11729 after the glyph. */
11730 row
->continued_p
= 1;
11731 it
->current_x
= new_x
;
11732 it
->continuation_lines_width
+= new_x
;
11734 if (i
== nglyphs
- 1)
11735 set_iterator_to_next (it
);
11737 else if (CHAR_GLYPH_PADDING_P (*glyph
)
11738 && !FRAME_WINDOW_P (it
->f
))
11740 /* A padding glyph that doesn't fit on this line.
11741 This means the whole character doesn't fit
11743 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11745 /* Fill the rest of the row with continuation
11746 glyphs like in 20.x. */
11747 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
11748 < row
->glyphs
[1 + TEXT_AREA
])
11749 produce_special_glyphs (it
, IT_CONTINUATION
);
11751 row
->continued_p
= 1;
11752 it
->current_x
= x_before
;
11753 it
->continuation_lines_width
+= x_before
;
11755 /* Restore the height to what it was before the
11756 element not fitting on the line. */
11757 it
->max_ascent
= ascent
;
11758 it
->max_descent
= descent
;
11759 it
->max_phys_ascent
= phys_ascent
;
11760 it
->max_phys_descent
= phys_descent
;
11764 /* Display element draws past the right edge of
11765 the window. Restore positions to values
11766 before the element. The next line starts
11767 with current_x before the glyph that could
11768 not be displayed, so that TAB works right. */
11769 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11771 /* Display continuation glyphs. */
11772 if (!FRAME_WINDOW_P (it
->f
))
11773 produce_special_glyphs (it
, IT_CONTINUATION
);
11774 row
->continued_p
= 1;
11777 it
->continuation_lines_width
+= x
;
11778 if (nglyphs
> 1 && i
> 0)
11780 row
->ends_in_middle_of_char_p
= 1;
11781 it
->starts_in_middle_of_char_p
= 1;
11784 /* Restore the height to what it was before the
11785 element not fitting on the line. */
11786 it
->max_ascent
= ascent
;
11787 it
->max_descent
= descent
;
11788 it
->max_phys_ascent
= phys_ascent
;
11789 it
->max_phys_descent
= phys_descent
;
11794 else if (new_x
> it
->first_visible_x
)
11796 /* Increment number of glyphs actually displayed. */
11799 if (x
< it
->first_visible_x
)
11800 /* Glyph is partially visible, i.e. row starts at
11801 negative X position. */
11802 row
->x
= x
- it
->first_visible_x
;
11806 /* Glyph is completely off the left margin of the
11807 window. This should not happen because of the
11808 move_it_in_display_line at the start of
11814 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11815 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11816 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11817 row
->phys_height
= max (row
->phys_height
,
11818 it
->max_phys_ascent
+ it
->max_phys_descent
);
11820 /* End of this display line if row is continued. */
11821 if (row
->continued_p
)
11825 /* Is this a line end? If yes, we're also done, after making
11826 sure that a non-default face is extended up to the right
11827 margin of the window. */
11828 if (ITERATOR_AT_END_OF_LINE_P (it
))
11830 int used_before
= row
->used
[TEXT_AREA
];
11832 /* Add a space at the end of the line that is used to
11833 display the cursor there. */
11834 append_space (it
, 0);
11836 /* Extend the face to the end of the line. */
11837 extend_face_to_end_of_line (it
);
11839 /* Make sure we have the position. */
11840 if (used_before
== 0)
11841 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
11843 /* Consume the line end. This skips over invisible lines. */
11844 set_iterator_to_next (it
);
11845 it
->continuation_lines_width
= 0;
11849 /* Proceed with next display element. Note that this skips
11850 over lines invisible because of selective display. */
11851 set_iterator_to_next (it
);
11853 /* If we truncate lines, we are done when the last displayed
11854 glyphs reach past the right margin of the window. */
11855 if (it
->truncate_lines_p
11856 && (FRAME_WINDOW_P (it
->f
)
11857 ? (it
->current_x
>= it
->last_visible_x
)
11858 : (it
->current_x
> it
->last_visible_x
)))
11860 /* Maybe add truncation glyphs. */
11861 if (!FRAME_WINDOW_P (it
->f
))
11863 --it
->glyph_row
->used
[TEXT_AREA
];
11864 produce_special_glyphs (it
, IT_TRUNCATION
);
11867 row
->truncated_on_right_p
= 1;
11868 it
->continuation_lines_width
= 0;
11869 reseat_at_next_visible_line_start (it
, 0);
11870 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
11871 it
->hpos
= hpos_before
;
11872 it
->current_x
= x_before
;
11877 /* If line is not empty and hscrolled, maybe insert truncation glyphs
11878 at the left window margin. */
11879 if (it
->first_visible_x
11880 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
11882 if (!FRAME_WINDOW_P (it
->f
))
11883 insert_left_trunc_glyphs (it
);
11884 row
->truncated_on_left_p
= 1;
11887 /* If the start of this line is the overlay arrow-position, then
11888 mark this glyph row as the one containing the overlay arrow.
11889 This is clearly a mess with variable size fonts. It would be
11890 better to let it be displayed like cursors under X. */
11891 if (MARKERP (Voverlay_arrow_position
)
11892 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
11893 && (MATRIX_ROW_START_CHARPOS (row
)
11894 == marker_position (Voverlay_arrow_position
))
11895 && STRINGP (Voverlay_arrow_string
)
11896 && ! overlay_arrow_seen
)
11898 /* Overlay arrow in window redisplay is a bitmap. */
11899 if (!FRAME_WINDOW_P (it
->f
))
11901 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
11902 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
11903 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
11904 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
11905 struct glyph
*p2
, *end
;
11907 /* Copy the arrow glyphs. */
11908 while (glyph
< arrow_end
)
11911 /* Throw away padding glyphs. */
11913 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
11914 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
11920 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
11924 overlay_arrow_seen
= 1;
11925 row
->overlay_arrow_p
= 1;
11928 /* Compute pixel dimensions of this line. */
11929 compute_line_metrics (it
);
11931 /* Remember the position at which this line ends. */
11932 row
->end
= it
->current
;
11934 /* Maybe set the cursor. */
11935 if (it
->w
->cursor
.vpos
< 0
11936 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
11937 && PT
<= MATRIX_ROW_END_CHARPOS (row
))
11939 /* Also see redisplay_window, case cursor movement in unchanged
11941 if (MATRIX_ROW_END_CHARPOS (row
) == PT
11942 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11943 && !row
->ends_at_zv_p
)
11946 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
11949 /* Highlight trailing whitespace. */
11950 if (!NILP (Vshow_trailing_whitespace
))
11951 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
11953 /* Prepare for the next line. This line starts horizontally at (X
11954 HPOS) = (0 0). Vertical positions are incremented. As a
11955 convenience for the caller, IT->glyph_row is set to the next
11957 it
->current_x
= it
->hpos
= 0;
11958 it
->current_y
+= row
->height
;
11961 return row
->displays_text_p
;
11966 /***********************************************************************
11968 ***********************************************************************/
11970 /* Redisplay the menu bar in the frame for window W.
11972 The menu bar of X frames that don't have X toolkit support is
11973 displayed in a special window W->frame->menu_bar_window.
11975 The menu bar of terminal frames is treated specially as far as
11976 glyph matrices are concerned. Menu bar lines are not part of
11977 windows, so the update is done directly on the frame matrix rows
11978 for the menu bar. */
11981 display_menu_bar (w
)
11984 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11989 /* Don't do all this for graphical frames. */
11991 if (!NILP (Vwindow_system
))
11994 #ifdef USE_X_TOOLKIT
11999 #ifdef USE_X_TOOLKIT
12000 xassert (!FRAME_WINDOW_P (f
));
12001 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
12002 it
.first_visible_x
= 0;
12003 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12004 #else /* not USE_X_TOOLKIT */
12005 if (FRAME_WINDOW_P (f
))
12007 /* Menu bar lines are displayed in the desired matrix of the
12008 dummy window menu_bar_window. */
12009 struct window
*menu_w
;
12010 xassert (WINDOWP (f
->menu_bar_window
));
12011 menu_w
= XWINDOW (f
->menu_bar_window
);
12012 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
12014 it
.first_visible_x
= 0;
12015 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12019 /* This is a TTY frame, i.e. character hpos/vpos are used as
12021 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
12023 it
.first_visible_x
= 0;
12024 it
.last_visible_x
= FRAME_WIDTH (f
);
12026 #endif /* not USE_X_TOOLKIT */
12028 /* Clear all rows of the menu bar. */
12029 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
12031 struct glyph_row
*row
= it
.glyph_row
+ i
;
12032 clear_glyph_row (row
);
12033 row
->enabled_p
= 1;
12034 row
->full_width_p
= 1;
12037 /* Make the first line of the menu bar appear in reverse video. */
12038 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
12040 /* Display all items of the menu bar. */
12041 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
12042 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
12044 Lisp_Object string
;
12046 /* Stop at nil string. */
12047 string
= XVECTOR (items
)->contents
[i
+ 1];
12051 /* Remember where item was displayed. */
12052 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
12054 /* Display the item, pad with one space. */
12055 if (it
.current_x
< it
.last_visible_x
)
12056 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
12057 XSTRING (string
)->size
+ 1, 0, 0, -1);
12060 /* Fill out the line with spaces. */
12061 if (it
.current_x
< it
.last_visible_x
)
12062 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
12064 /* Compute the total height of the lines. */
12065 compute_line_metrics (&it
);
12070 /***********************************************************************
12072 ***********************************************************************/
12074 /* Redisplay mode lines in the window tree whose root is WINDOW. If
12075 FORCE is non-zero, redisplay mode lines unconditionally.
12076 Otherwise, redisplay only mode lines that are garbaged. Value is
12077 the number of windows whose mode lines were redisplayed. */
12080 redisplay_mode_lines (window
, force
)
12081 Lisp_Object window
;
12086 while (!NILP (window
))
12088 struct window
*w
= XWINDOW (window
);
12090 if (WINDOWP (w
->hchild
))
12091 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
12092 else if (WINDOWP (w
->vchild
))
12093 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
12095 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
12096 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
12098 Lisp_Object old_selected_frame
;
12099 struct text_pos lpoint
;
12100 struct buffer
*old
= current_buffer
;
12102 /* Set the window's buffer for the mode line display. */
12103 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12104 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12106 /* Point refers normally to the selected window. For any
12107 other window, set up appropriate value. */
12108 if (!EQ (window
, selected_window
))
12110 struct text_pos pt
;
12112 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
12113 if (CHARPOS (pt
) < BEGV
)
12114 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
12115 else if (CHARPOS (pt
) > (ZV
- 1))
12116 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
12118 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
12121 /* Temporarily set up the selected frame. */
12122 old_selected_frame
= selected_frame
;
12123 selected_frame
= w
->frame
;
12125 /* Display mode lines. */
12126 clear_glyph_matrix (w
->desired_matrix
);
12127 if (display_mode_lines (w
))
12130 w
->must_be_updated_p
= 1;
12133 /* Restore old settings. */
12134 selected_frame
= old_selected_frame
;
12135 set_buffer_internal_1 (old
);
12136 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12146 /* Display the mode and/or top line of window W. Value is the number
12147 of mode lines displayed. */
12150 display_mode_lines (w
)
12155 /* These will be set while the mode line specs are processed. */
12156 line_number_displayed
= 0;
12157 w
->column_number_displayed
= Qnil
;
12159 if (WINDOW_WANTS_MODELINE_P (w
))
12161 display_mode_line (w
, MODE_LINE_FACE_ID
,
12162 current_buffer
->mode_line_format
);
12166 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12168 display_mode_line (w
, HEADER_LINE_FACE_ID
,
12169 current_buffer
->header_line_format
);
12177 /* Display mode or top line of window W. FACE_ID specifies which line
12178 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
12179 FORMAT is the mode line format to display. */
12182 display_mode_line (w
, face_id
, format
)
12184 enum face_id face_id
;
12185 Lisp_Object format
;
12190 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
12191 prepare_desired_row (it
.glyph_row
);
12193 /* Temporarily make frame's keyboard the current kboard so that
12194 kboard-local variables in the mode_line_format will get the right
12196 push_frame_kboard (it
.f
);
12197 display_mode_element (&it
, 0, 0, 0, format
);
12198 pop_frame_kboard ();
12200 /* Fill up with spaces. */
12201 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
12203 compute_line_metrics (&it
);
12204 it
.glyph_row
->full_width_p
= 1;
12205 it
.glyph_row
->mode_line_p
= 1;
12206 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
12207 it
.glyph_row
->continued_p
= 0;
12208 it
.glyph_row
->truncated_on_left_p
= 0;
12209 it
.glyph_row
->truncated_on_right_p
= 0;
12211 /* Make a 3D mode-line have a shadow at its right end. */
12212 face
= FACE_FROM_ID (it
.f
, face_id
);
12213 extend_face_to_end_of_line (&it
);
12214 if (face
->box
!= FACE_NO_BOX
)
12216 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
12217 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
12218 last
->right_box_line_p
= 1;
12223 /* Contribute ELT to the mode line for window IT->w. How it
12224 translates into text depends on its data type.
12226 IT describes the display environment in which we display, as usual.
12228 DEPTH is the depth in recursion. It is used to prevent
12229 infinite recursion here.
12231 FIELD_WIDTH is the number of characters the display of ELT should
12232 occupy in the mode line, and PRECISION is the maximum number of
12233 characters to display from ELT's representation. See
12234 display_string for details. *
12236 Returns the hpos of the end of the text generated by ELT. */
12239 display_mode_element (it
, depth
, field_width
, precision
, elt
)
12242 int field_width
, precision
;
12245 int n
= 0, field
, prec
;
12253 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
12257 /* A string: output it and check for %-constructs within it. */
12259 unsigned char *this = XSTRING (elt
)->data
;
12260 unsigned char *lisp_string
= this;
12262 while ((precision
<= 0 || n
< precision
)
12264 && (frame_title_ptr
12265 || it
->current_x
< it
->last_visible_x
))
12267 unsigned char *last
= this;
12269 /* Advance to end of string or next format specifier. */
12270 while ((c
= *this++) != '\0' && c
!= '%')
12273 if (this - 1 != last
)
12275 /* Output to end of string or up to '%'. Field width
12276 is length of string. Don't output more than
12277 PRECISION allows us. */
12278 prec
= --this - last
;
12279 if (precision
> 0 && prec
> precision
- n
)
12280 prec
= precision
- n
;
12282 if (frame_title_ptr
)
12283 n
+= store_frame_title (last
, prec
, prec
);
12285 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
12286 it
, 0, prec
, 0, -1);
12288 else /* c == '%' */
12290 unsigned char *percent_position
= this;
12292 /* Get the specified minimum width. Zero means
12295 while ((c
= *this++) >= '0' && c
<= '9')
12296 field
= field
* 10 + c
- '0';
12298 /* Don't pad beyond the total padding allowed. */
12299 if (field_width
- n
> 0 && field
> field_width
- n
)
12300 field
= field_width
- n
;
12302 /* Note that either PRECISION <= 0 or N < PRECISION. */
12303 prec
= precision
- n
;
12306 n
+= display_mode_element (it
, depth
, field
, prec
,
12307 Vglobal_mode_string
);
12310 unsigned char *spec
12311 = decode_mode_spec (it
->w
, c
, field
, prec
);
12313 if (frame_title_ptr
)
12314 n
+= store_frame_title (spec
, field
, prec
);
12318 = it
->glyph_row
->used
[TEXT_AREA
];
12320 = percent_position
- XSTRING (elt
)->data
;
12322 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
12323 field
, prec
, 0, -1);
12325 /* Assign to the glyphs written above the
12326 string where the `%x' came from, position
12330 struct glyph
*glyph
12331 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
12335 for (i
= 0; i
< nwritten
; ++i
)
12337 glyph
[i
].object
= elt
;
12338 glyph
[i
].charpos
= charpos
;
12351 /* A symbol: process the value of the symbol recursively
12352 as if it appeared here directly. Avoid error if symbol void.
12353 Special case: if value of symbol is a string, output the string
12356 register Lisp_Object tem
;
12357 tem
= Fboundp (elt
);
12360 tem
= Fsymbol_value (elt
);
12361 /* If value is a string, output that string literally:
12362 don't check for % within it. */
12365 prec
= XSTRING (tem
)->size
;
12366 if (precision
> 0 && prec
> precision
- n
)
12367 prec
= precision
- n
;
12368 if (frame_title_ptr
)
12369 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
12371 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
12374 else if (!EQ (tem
, elt
))
12376 /* Give up right away for nil or t. */
12386 register Lisp_Object car
, tem
;
12388 /* A cons cell: three distinct cases.
12389 If first element is a string or a cons, process all the elements
12390 and effectively concatenate them.
12391 If first element is a negative number, truncate displaying cdr to
12392 at most that many characters. If positive, pad (with spaces)
12393 to at least that many characters.
12394 If first element is a symbol, process the cadr or caddr recursively
12395 according to whether the symbol's value is non-nil or nil. */
12397 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
12399 /* An element of the form (:eval FORM) means evaluate FORM
12400 and use the result as mode line elements. */
12401 struct gcpro gcpro1
;
12404 spec
= eval_form (XCAR (XCDR (elt
)));
12406 n
+= display_mode_element (it
, depth
, field_width
- n
,
12407 precision
- n
, spec
);
12410 else if (SYMBOLP (car
))
12412 tem
= Fboundp (car
);
12416 /* elt is now the cdr, and we know it is a cons cell.
12417 Use its car if CAR has a non-nil value. */
12420 tem
= Fsymbol_value (car
);
12427 /* Symbol's value is nil (or symbol is unbound)
12428 Get the cddr of the original list
12429 and if possible find the caddr and use that. */
12433 else if (!CONSP (elt
))
12438 else if (INTEGERP (car
))
12440 register int lim
= XINT (car
);
12444 /* Negative int means reduce maximum width. */
12445 if (precision
<= 0)
12448 precision
= min (precision
, -lim
);
12452 /* Padding specified. Don't let it be more than
12453 current maximum. */
12455 lim
= min (precision
, lim
);
12457 /* If that's more padding than already wanted, queue it.
12458 But don't reduce padding already specified even if
12459 that is beyond the current truncation point. */
12460 field_width
= max (lim
, field_width
);
12464 else if (STRINGP (car
) || CONSP (car
))
12466 register int limit
= 50;
12467 /* Limit is to protect against circular lists. */
12470 && (precision
<= 0 || n
< precision
))
12472 n
+= display_mode_element (it
, depth
, field_width
- n
,
12473 precision
- n
, XCAR (elt
));
12482 if (frame_title_ptr
)
12483 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
12485 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
12486 precision
- n
, 0, 0);
12490 /* Pad to FIELD_WIDTH. */
12491 if (field_width
> 0 && n
< field_width
)
12493 if (frame_title_ptr
)
12494 n
+= store_frame_title ("", field_width
- n
, 0);
12496 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
12504 /* Write a null-terminated, right justified decimal representation of
12505 the positive integer D to BUF using a minimal field width WIDTH. */
12508 pint2str (buf
, width
, d
)
12509 register char *buf
;
12510 register int width
;
12513 register char *p
= buf
;
12521 *p
++ = d
% 10 + '0';
12526 for (width
-= (int) (p
- buf
); width
> 0; --width
)
12537 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
12538 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
12539 type of CODING_SYSTEM. Return updated pointer into BUF. */
12541 static unsigned char invalid_eol_type
[] = "(*invalid*)";
12544 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
12545 Lisp_Object coding_system
;
12546 register char *buf
;
12550 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
12551 unsigned char *eol_str
;
12553 /* The EOL conversion we are using. */
12554 Lisp_Object eoltype
;
12556 val
= Fget (coding_system
, Qcoding_system
);
12559 if (!VECTORP (val
)) /* Not yet decided. */
12564 eoltype
= eol_mnemonic_undecided
;
12565 /* Don't mention EOL conversion if it isn't decided. */
12569 Lisp_Object eolvalue
;
12571 eolvalue
= Fget (coding_system
, Qeol_type
);
12574 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
12578 /* The EOL conversion that is normal on this system. */
12580 if (NILP (eolvalue
)) /* Not yet decided. */
12581 eoltype
= eol_mnemonic_undecided
;
12582 else if (VECTORP (eolvalue
)) /* Not yet decided. */
12583 eoltype
= eol_mnemonic_undecided
;
12584 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
12585 eoltype
= (XFASTINT (eolvalue
) == 0
12586 ? eol_mnemonic_unix
12587 : (XFASTINT (eolvalue
) == 1
12588 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
12594 /* Mention the EOL conversion if it is not the usual one. */
12595 if (STRINGP (eoltype
))
12597 eol_str
= XSTRING (eoltype
)->data
;
12598 eol_str_len
= XSTRING (eoltype
)->size
;
12600 else if (INTEGERP (eoltype
)
12601 && CHAR_VALID_P (XINT (eoltype
), 0))
12603 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
12604 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
12608 eol_str
= invalid_eol_type
;
12609 eol_str_len
= sizeof (invalid_eol_type
) - 1;
12611 bcopy (eol_str
, buf
, eol_str_len
);
12612 buf
+= eol_str_len
;
12618 /* Return a string for the output of a mode line %-spec for window W,
12619 generated by character C. PRECISION >= 0 means don't return a
12620 string longer than that value. FIELD_WIDTH > 0 means pad the
12621 string returned with spaces to that value. */
12623 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
12626 decode_mode_spec (w
, c
, field_width
, precision
)
12629 int field_width
, precision
;
12632 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12633 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
12634 struct buffer
*b
= XBUFFER (w
->buffer
);
12641 if (!NILP (b
->read_only
))
12643 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12648 /* This differs from %* only for a modified read-only buffer. */
12649 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12651 if (!NILP (b
->read_only
))
12656 /* This differs from %* in ignoring read-only-ness. */
12657 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12669 if (command_loop_level
> 5)
12671 p
= decode_mode_spec_buf
;
12672 for (i
= 0; i
< command_loop_level
; i
++)
12675 return decode_mode_spec_buf
;
12683 if (command_loop_level
> 5)
12685 p
= decode_mode_spec_buf
;
12686 for (i
= 0; i
< command_loop_level
; i
++)
12689 return decode_mode_spec_buf
;
12696 /* Let lots_of_dashes be a string of infinite length. */
12697 if (field_width
<= 0
12698 || field_width
> sizeof (lots_of_dashes
))
12700 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
12701 decode_mode_spec_buf
[i
] = '-';
12702 decode_mode_spec_buf
[i
] = '\0';
12703 return decode_mode_spec_buf
;
12706 return lots_of_dashes
;
12715 int col
= current_column ();
12716 XSETFASTINT (w
->column_number_displayed
, col
);
12717 pint2str (decode_mode_spec_buf
, field_width
, col
);
12718 return decode_mode_spec_buf
;
12722 /* %F displays the frame name. */
12723 if (!NILP (f
->title
))
12724 return (char *) XSTRING (f
->title
)->data
;
12725 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
12726 return (char *) XSTRING (f
->name
)->data
;
12735 int startpos
= XMARKER (w
->start
)->charpos
;
12736 int startpos_byte
= marker_byte_position (w
->start
);
12737 int line
, linepos
, linepos_byte
, topline
;
12739 int height
= XFASTINT (w
->height
);
12741 /* If we decided that this buffer isn't suitable for line numbers,
12742 don't forget that too fast. */
12743 if (EQ (w
->base_line_pos
, w
->buffer
))
12745 /* But do forget it, if the window shows a different buffer now. */
12746 else if (BUFFERP (w
->base_line_pos
))
12747 w
->base_line_pos
= Qnil
;
12749 /* If the buffer is very big, don't waste time. */
12750 if (INTEGERP (Vline_number_display_limit
)
12751 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
12753 w
->base_line_pos
= Qnil
;
12754 w
->base_line_number
= Qnil
;
12758 if (!NILP (w
->base_line_number
)
12759 && !NILP (w
->base_line_pos
)
12760 && XFASTINT (w
->base_line_pos
) <= startpos
)
12762 line
= XFASTINT (w
->base_line_number
);
12763 linepos
= XFASTINT (w
->base_line_pos
);
12764 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
12769 linepos
= BUF_BEGV (b
);
12770 linepos_byte
= BUF_BEGV_BYTE (b
);
12773 /* Count lines from base line to window start position. */
12774 nlines
= display_count_lines (linepos
, linepos_byte
,
12778 topline
= nlines
+ line
;
12780 /* Determine a new base line, if the old one is too close
12781 or too far away, or if we did not have one.
12782 "Too close" means it's plausible a scroll-down would
12783 go back past it. */
12784 if (startpos
== BUF_BEGV (b
))
12786 XSETFASTINT (w
->base_line_number
, topline
);
12787 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
12789 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
12790 || linepos
== BUF_BEGV (b
))
12792 int limit
= BUF_BEGV (b
);
12793 int limit_byte
= BUF_BEGV_BYTE (b
);
12795 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
12797 if (startpos
- distance
> limit
)
12799 limit
= startpos
- distance
;
12800 limit_byte
= CHAR_TO_BYTE (limit
);
12803 nlines
= display_count_lines (startpos
, startpos_byte
,
12805 - (height
* 2 + 30),
12807 /* If we couldn't find the lines we wanted within
12808 line_number_display_limit_width chars per line,
12809 give up on line numbers for this window. */
12810 if (position
== limit_byte
&& limit
== startpos
- distance
)
12812 w
->base_line_pos
= w
->buffer
;
12813 w
->base_line_number
= Qnil
;
12817 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
12818 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
12821 /* Now count lines from the start pos to point. */
12822 nlines
= display_count_lines (startpos
, startpos_byte
,
12823 PT_BYTE
, PT
, &junk
);
12825 /* Record that we did display the line number. */
12826 line_number_displayed
= 1;
12828 /* Make the string to show. */
12829 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
12830 return decode_mode_spec_buf
;
12833 char* p
= decode_mode_spec_buf
;
12834 int pad
= field_width
- 2;
12840 return decode_mode_spec_buf
;
12846 obj
= b
->mode_name
;
12850 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
12856 int pos
= marker_position (w
->start
);
12857 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12859 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
12861 if (pos
<= BUF_BEGV (b
))
12866 else if (pos
<= BUF_BEGV (b
))
12870 if (total
> 1000000)
12871 /* Do it differently for a large value, to avoid overflow. */
12872 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12874 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12875 /* We can't normally display a 3-digit number,
12876 so get us a 2-digit number that is close. */
12879 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12880 return decode_mode_spec_buf
;
12884 /* Display percentage of size above the bottom of the screen. */
12887 int toppos
= marker_position (w
->start
);
12888 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
12889 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12891 if (botpos
>= BUF_ZV (b
))
12893 if (toppos
<= BUF_BEGV (b
))
12900 if (total
> 1000000)
12901 /* Do it differently for a large value, to avoid overflow. */
12902 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12904 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12905 /* We can't normally display a 3-digit number,
12906 so get us a 2-digit number that is close. */
12909 if (toppos
<= BUF_BEGV (b
))
12910 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
12912 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12913 return decode_mode_spec_buf
;
12918 /* status of process */
12919 obj
= Fget_buffer_process (w
->buffer
);
12921 return "no process";
12922 #ifdef subprocesses
12923 obj
= Fsymbol_name (Fprocess_status (obj
));
12927 case 't': /* indicate TEXT or BINARY */
12928 #ifdef MODE_LINE_BINARY_TEXT
12929 return MODE_LINE_BINARY_TEXT (b
);
12935 /* coding-system (not including end-of-line format) */
12937 /* coding-system (including end-of-line type) */
12939 int eol_flag
= (c
== 'Z');
12940 char *p
= decode_mode_spec_buf
;
12942 if (! FRAME_WINDOW_P (f
))
12944 /* No need to mention EOL here--the terminal never needs
12945 to do EOL conversion. */
12946 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
12947 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
12949 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
12952 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
12953 #ifdef subprocesses
12954 obj
= Fget_buffer_process (Fcurrent_buffer ());
12955 if (PROCESSP (obj
))
12957 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
12959 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
12962 #endif /* subprocesses */
12965 return decode_mode_spec_buf
;
12970 return (char *) XSTRING (obj
)->data
;
12976 /* Count up to COUNT lines starting from START / START_BYTE.
12977 But don't go beyond LIMIT_BYTE.
12978 Return the number of lines thus found (always nonnegative).
12980 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
12983 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
12984 int start
, start_byte
, limit_byte
, count
;
12987 register unsigned char *cursor
;
12988 unsigned char *base
;
12990 register int ceiling
;
12991 register unsigned char *ceiling_addr
;
12992 int orig_count
= count
;
12994 /* If we are not in selective display mode,
12995 check only for newlines. */
12996 int selective_display
= (!NILP (current_buffer
->selective_display
)
12997 && !INTEGERP (current_buffer
->selective_display
));
13001 while (start_byte
< limit_byte
)
13003 ceiling
= BUFFER_CEILING_OF (start_byte
);
13004 ceiling
= min (limit_byte
- 1, ceiling
);
13005 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
13006 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
13009 if (selective_display
)
13010 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
13013 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
13016 if (cursor
!= ceiling_addr
)
13020 start_byte
+= cursor
- base
+ 1;
13021 *byte_pos_ptr
= start_byte
;
13025 if (++cursor
== ceiling_addr
)
13031 start_byte
+= cursor
- base
;
13036 while (start_byte
> limit_byte
)
13038 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
13039 ceiling
= max (limit_byte
, ceiling
);
13040 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
13041 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
13044 if (selective_display
)
13045 while (--cursor
!= ceiling_addr
13046 && *cursor
!= '\n' && *cursor
!= 015)
13049 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
13052 if (cursor
!= ceiling_addr
)
13056 start_byte
+= cursor
- base
+ 1;
13057 *byte_pos_ptr
= start_byte
;
13058 /* When scanning backwards, we should
13059 not count the newline posterior to which we stop. */
13060 return - orig_count
- 1;
13066 /* Here we add 1 to compensate for the last decrement
13067 of CURSOR, which took it past the valid range. */
13068 start_byte
+= cursor
- base
+ 1;
13072 *byte_pos_ptr
= limit_byte
;
13075 return - orig_count
+ count
;
13076 return orig_count
- count
;
13082 /***********************************************************************
13084 ***********************************************************************/
13086 /* Display a NUL-terminated string, starting with index START.
13088 If STRING is non-null, display that C string. Otherwise, the Lisp
13089 string LISP_STRING is displayed.
13091 If FACE_STRING is not nil, FACE_STRING_POS is a position in
13092 FACE_STRING. Display STRING or LISP_STRING with the face at
13093 FACE_STRING_POS in FACE_STRING:
13095 Display the string in the environment given by IT, but use the
13096 standard display table, temporarily.
13098 FIELD_WIDTH is the minimum number of output glyphs to produce.
13099 If STRING has fewer characters than FIELD_WIDTH, pad to the right
13100 with spaces. If STRING has more characters, more than FIELD_WIDTH
13101 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
13103 PRECISION is the maximum number of characters to output from
13104 STRING. PRECISION < 0 means don't truncate the string.
13106 This is roughly equivalent to printf format specifiers:
13108 FIELD_WIDTH PRECISION PRINTF
13109 ----------------------------------------
13115 MULTIBYTE zero means do not display multibyte chars, > 0 means do
13116 display them, and < 0 means obey the current buffer's value of
13117 enable_multibyte_characters.
13119 Value is the number of glyphs produced. */
13122 display_string (string
, lisp_string
, face_string
, face_string_pos
,
13123 start
, it
, field_width
, precision
, max_x
, multibyte
)
13124 unsigned char *string
;
13125 Lisp_Object lisp_string
;
13126 Lisp_Object face_string
;
13127 int face_string_pos
;
13130 int field_width
, precision
, max_x
;
13133 int hpos_at_start
= it
->hpos
;
13134 int saved_face_id
= it
->face_id
;
13135 struct glyph_row
*row
= it
->glyph_row
;
13137 /* Initialize the iterator IT for iteration over STRING beginning
13138 with index START. We assume that IT may be modified here (which
13139 means that display_line has to do something when displaying a
13140 mini-buffer prompt, which it does). */
13141 reseat_to_string (it
, string
, lisp_string
, start
,
13142 precision
, field_width
, multibyte
);
13144 /* If displaying STRING, set up the face of the iterator
13145 from LISP_STRING, if that's given. */
13146 if (STRINGP (face_string
))
13152 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
13153 0, it
->region_beg_charpos
,
13154 it
->region_end_charpos
,
13155 &endptr
, it
->base_face_id
);
13156 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
13157 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
13160 /* Set max_x to the maximum allowed X position. Don't let it go
13161 beyond the right edge of the window. */
13163 max_x
= it
->last_visible_x
;
13165 max_x
= min (max_x
, it
->last_visible_x
);
13167 /* Skip over display elements that are not visible. because IT->w is
13169 if (it
->current_x
< it
->first_visible_x
)
13170 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
13171 MOVE_TO_POS
| MOVE_TO_X
);
13173 row
->ascent
= it
->max_ascent
;
13174 row
->height
= it
->max_ascent
+ it
->max_descent
;
13175 row
->phys_ascent
= it
->max_phys_ascent
;
13176 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13178 /* This condition is for the case that we are called with current_x
13179 past last_visible_x. */
13180 while (it
->current_x
< max_x
)
13182 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
13184 /* Get the next display element. */
13185 if (!get_next_display_element (it
))
13188 /* Produce glyphs. */
13189 x_before
= it
->current_x
;
13190 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13191 PRODUCE_GLYPHS (it
);
13193 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
13196 while (i
< nglyphs
)
13198 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13200 if (!it
->truncate_lines_p
13201 && x
+ glyph
->pixel_width
> max_x
)
13203 /* End of continued line or max_x reached. */
13204 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13208 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
13210 /* Glyph is at least partially visible. */
13212 if (x
< it
->first_visible_x
)
13213 it
->glyph_row
->x
= x
- it
->first_visible_x
;
13217 /* Glyph is off the left margin of the display area.
13218 Should not happen. */
13222 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13223 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13224 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13225 row
->phys_height
= max (row
->phys_height
,
13226 it
->max_phys_ascent
+ it
->max_phys_descent
);
13227 x
+= glyph
->pixel_width
;
13231 /* Stop if max_x reached. */
13235 /* Stop at line ends. */
13236 if (ITERATOR_AT_END_OF_LINE_P (it
))
13238 it
->continuation_lines_width
= 0;
13242 set_iterator_to_next (it
);
13244 /* Stop if truncating at the right edge. */
13245 if (it
->truncate_lines_p
13246 && it
->current_x
>= it
->last_visible_x
)
13248 /* Add truncation mark, but don't do it if the line is
13249 truncated at a padding space. */
13250 if (IT_CHARPOS (*it
) < it
->string_nchars
)
13252 if (!FRAME_WINDOW_P (it
->f
))
13253 produce_special_glyphs (it
, IT_TRUNCATION
);
13254 it
->glyph_row
->truncated_on_right_p
= 1;
13260 /* Maybe insert a truncation at the left. */
13261 if (it
->first_visible_x
13262 && IT_CHARPOS (*it
) > 0)
13264 if (!FRAME_WINDOW_P (it
->f
))
13265 insert_left_trunc_glyphs (it
);
13266 it
->glyph_row
->truncated_on_left_p
= 1;
13269 it
->face_id
= saved_face_id
;
13271 /* Value is number of columns displayed. */
13272 return it
->hpos
- hpos_at_start
;
13277 /* This is like a combination of memq and assq. Return 1 if PROPVAL
13278 appears as an element of LIST or as the car of an element of LIST.
13279 If PROPVAL is a list, compare each element against LIST in that
13280 way, and return 1 if any element of PROPVAL is found in LIST.
13281 Otherwise return 0. This function cannot quit. */
13284 invisible_p (propval
, list
)
13285 register Lisp_Object propval
;
13288 register Lisp_Object tail
, proptail
;
13290 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13292 register Lisp_Object tem
;
13294 if (EQ (propval
, tem
))
13296 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
13300 if (CONSP (propval
))
13302 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
13304 Lisp_Object propelt
;
13305 propelt
= XCAR (proptail
);
13306 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13308 register Lisp_Object tem
;
13310 if (EQ (propelt
, tem
))
13312 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
13322 /* Return 1 if PROPVAL appears as the car of an element of LIST and
13323 the cdr of that element is non-nil. If PROPVAL is a list, check
13324 each element of PROPVAL in that way, and the first time some
13325 element is found, return 1 if the cdr of that element is non-nil.
13326 Otherwise return 0. This function cannot quit. */
13329 invisible_ellipsis_p (propval
, list
)
13330 register Lisp_Object propval
;
13333 register Lisp_Object tail
, proptail
;
13335 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13337 register Lisp_Object tem
;
13339 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
13340 return ! NILP (XCDR (tem
));
13343 if (CONSP (propval
))
13344 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
13346 Lisp_Object propelt
;
13347 propelt
= XCAR (proptail
);
13348 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13350 register Lisp_Object tem
;
13352 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
13353 return ! NILP (XCDR (tem
));
13362 /***********************************************************************
13364 ***********************************************************************/
13369 Vwith_echo_area_save_vector
= Qnil
;
13370 staticpro (&Vwith_echo_area_save_vector
);
13372 Vmessage_stack
= Qnil
;
13373 staticpro (&Vmessage_stack
);
13375 Qinhibit_redisplay
= intern ("inhibit-redisplay");
13376 staticpro (&Qinhibit_redisplay
);
13379 defsubr (&Sdump_glyph_matrix
);
13380 defsubr (&Sdump_glyph_row
);
13381 defsubr (&Sdump_tool_bar_row
);
13382 defsubr (&Strace_redisplay_toggle
);
13383 defsubr (&Strace_to_stderr
);
13386 staticpro (&Qmenu_bar_update_hook
);
13387 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
13389 staticpro (&Qoverriding_terminal_local_map
);
13390 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
13392 staticpro (&Qoverriding_local_map
);
13393 Qoverriding_local_map
= intern ("overriding-local-map");
13395 staticpro (&Qwindow_scroll_functions
);
13396 Qwindow_scroll_functions
= intern ("window-scroll-functions");
13398 staticpro (&Qredisplay_end_trigger_functions
);
13399 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
13401 staticpro (&Qinhibit_point_motion_hooks
);
13402 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
13404 QCdata
= intern (":data");
13405 staticpro (&QCdata
);
13406 Qdisplay
= intern ("display");
13407 staticpro (&Qdisplay
);
13408 Qspace_width
= intern ("space-width");
13409 staticpro (&Qspace_width
);
13410 Qraise
= intern ("raise");
13411 staticpro (&Qraise
);
13412 Qspace
= intern ("space");
13413 staticpro (&Qspace
);
13414 Qmargin
= intern ("margin");
13415 staticpro (&Qmargin
);
13416 Qleft_margin
= intern ("left-margin");
13417 staticpro (&Qleft_margin
);
13418 Qright_margin
= intern ("right-margin");
13419 staticpro (&Qright_margin
);
13420 Qalign_to
= intern ("align-to");
13421 staticpro (&Qalign_to
);
13422 QCalign_to
= intern (":align-to");
13423 staticpro (&QCalign_to
);
13424 Qrelative_width
= intern ("relative-width");
13425 staticpro (&Qrelative_width
);
13426 QCrelative_width
= intern (":relative-width");
13427 staticpro (&QCrelative_width
);
13428 QCrelative_height
= intern (":relative-height");
13429 staticpro (&QCrelative_height
);
13430 QCeval
= intern (":eval");
13431 staticpro (&QCeval
);
13432 Qwhen
= intern ("when");
13433 staticpro (&Qwhen
);
13434 QCfile
= intern (":file");
13435 staticpro (&QCfile
);
13436 Qfontified
= intern ("fontified");
13437 staticpro (&Qfontified
);
13438 Qfontification_functions
= intern ("fontification-functions");
13439 staticpro (&Qfontification_functions
);
13440 Qtrailing_whitespace
= intern ("trailing-whitespace");
13441 staticpro (&Qtrailing_whitespace
);
13442 Qimage
= intern ("image");
13443 staticpro (&Qimage
);
13444 Qmessage_truncate_lines
= intern ("message-truncate-lines");
13445 staticpro (&Qmessage_truncate_lines
);
13447 last_arrow_position
= Qnil
;
13448 last_arrow_string
= Qnil
;
13449 staticpro (&last_arrow_position
);
13450 staticpro (&last_arrow_string
);
13452 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
13453 staticpro (&echo_buffer
[0]);
13454 staticpro (&echo_buffer
[1]);
13456 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
13457 staticpro (&echo_area_buffer
[0]);
13458 staticpro (&echo_area_buffer
[1]);
13460 Vmessages_buffer_name
= build_string ("*Messages*");
13461 staticpro (&Vmessages_buffer_name
);
13463 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
13464 "Non-nil means highlight trailing whitespace.\n\
13465 The face used for trailing whitespace is `trailing-whitespace'.");
13466 Vshow_trailing_whitespace
= Qnil
;
13468 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
13469 "Non-nil means don't actually do any redisplay.\n\
13470 This is used for internal purposes.");
13471 Vinhibit_redisplay
= Qnil
;
13473 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
13474 "String (or mode line construct) included (normally) in `mode-line-format'.");
13475 Vglobal_mode_string
= Qnil
;
13477 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
13478 "Marker for where to display an arrow on top of the buffer text.\n\
13479 This must be the beginning of a line in order to work.\n\
13480 See also `overlay-arrow-string'.");
13481 Voverlay_arrow_position
= Qnil
;
13483 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
13484 "String to display as an arrow. See also `overlay-arrow-position'.");
13485 Voverlay_arrow_string
= Qnil
;
13487 DEFVAR_INT ("scroll-step", &scroll_step
,
13488 "*The number of lines to try scrolling a window by when point moves out.\n\
13489 If that fails to bring point back on frame, point is centered instead.\n\
13490 If this is zero, point is always centered after it moves off frame.");
13492 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
13493 "*Scroll up to this many lines, to bring point back on screen.\n\
13494 A value of zero means to scroll the text to center point vertically\n\
13496 scroll_conservatively
= 0;
13498 DEFVAR_INT ("scroll-margin", &scroll_margin
,
13499 "*Number of lines of margin at the top and bottom of a window.\n\
13500 Recenter the window whenever point gets within this many lines\n\
13501 of the top or bottom of the window.");
13505 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
13508 DEFVAR_BOOL ("truncate-partial-width-windows",
13509 &truncate_partial_width_windows
,
13510 "*Non-nil means truncate lines in all windows less than full frame wide.");
13511 truncate_partial_width_windows
= 1;
13513 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
13514 "*Non-nil means use inverse video for the mode line.");
13515 mode_line_inverse_video
= 1;
13517 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
13518 "*Maximum buffer size for which line number should be displayed.\n\
13519 If the buffer is bigger than this, the line number does not appear\n\
13520 in the mode line. A value of nil means no limit.");
13521 Vline_number_display_limit
= Qnil
;
13523 DEFVAR_INT ("line-number-display-limit-width",
13524 &line_number_display_limit_width
,
13525 "*Maximum line width (in characters) for line number display.\n\
13526 If the average length of the lines near point is bigger than this, then the\n\
13527 line number may be omitted from the mode line.");
13528 line_number_display_limit_width
= 200;
13530 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
13531 "*Non-nil means highlight region even in nonselected windows.");
13532 highlight_nonselected_windows
= 0;
13534 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
13535 "Non-nil if more than one frame is visible on this display.\n\
13536 Minibuffer-only frames don't count, but iconified frames do.\n\
13537 This variable is not guaranteed to be accurate except while processing\n\
13538 `frame-title-format' and `icon-title-format'.");
13540 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
13541 "Template for displaying the title bar of visible frames.\n\
13542 \(Assuming the window manager supports this feature.)\n\
13543 This variable has the same structure as `mode-line-format' (which see),\n\
13544 and is used only on frames for which no explicit name has been set\n\
13545 \(see `modify-frame-parameters').");
13546 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
13547 "Template for displaying the title bar of an iconified frame.\n\
13548 \(Assuming the window manager supports this feature.)\n\
13549 This variable has the same structure as `mode-line-format' (which see),\n\
13550 and is used only on frames for which no explicit name has been set\n\
13551 \(see `modify-frame-parameters').");
13553 = Vframe_title_format
13554 = Fcons (intern ("multiple-frames"),
13555 Fcons (build_string ("%b"),
13556 Fcons (Fcons (build_string (""),
13557 Fcons (intern ("invocation-name"),
13558 Fcons (build_string ("@"),
13559 Fcons (intern ("system-name"),
13563 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
13564 "Maximum number of lines to keep in the message log buffer.\n\
13565 If nil, disable message logging. If t, log messages but don't truncate\n\
13566 the buffer when it becomes large.");
13567 XSETFASTINT (Vmessage_log_max
, 50);
13569 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
13570 "Functions called before redisplay, if window sizes have changed.\n\
13571 The value should be a list of functions that take one argument.\n\
13572 Just before redisplay, for each frame, if any of its windows have changed\n\
13573 size since the last redisplay, or have been split or deleted,\n\
13574 all the functions in the list are called, with the frame as argument.");
13575 Vwindow_size_change_functions
= Qnil
;
13577 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
13578 "List of Functions to call before redisplaying a window with scrolling.\n\
13579 Each function is called with two arguments, the window\n\
13580 and its new display-start position. Note that the value of `window-end'\n\
13581 is not valid when these functions are called.");
13582 Vwindow_scroll_functions
= Qnil
;
13584 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
13585 "*Non-nil means automatically resize tool-bars.\n\
13586 This increases a tool-bar's height if not all tool-bar items are visible.\n\
13587 It decreases a tool-bar's height when it would display blank lines\n\
13589 auto_resize_tool_bars_p
= 1;
13591 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
13592 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
13593 auto_raise_tool_bar_buttons_p
= 1;
13595 DEFVAR_INT ("tool-bar-button-margin", &tool_bar_button_margin
,
13596 "*Margin around tool-bar buttons in pixels.");
13597 tool_bar_button_margin
= 1;
13599 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
13600 "Relief thickness of tool-bar buttons.");
13601 tool_bar_button_relief
= 3;
13603 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
13604 "List of functions to call to fontify regions of text.\n\
13605 Each function is called with one argument POS. Functions must\n\
13606 fontify a region starting at POS in the current buffer, and give\n\
13607 fontified regions the property `fontified'.\n\
13608 This variable automatically becomes buffer-local when set.");
13609 Vfontification_functions
= Qnil
;
13610 Fmake_local_variable (Qfontification_functions
);
13612 DEFVAR_BOOL ("unibyte-display-via-language-environment",
13613 &unibyte_display_via_language_environment
,
13614 "*Non-nil means display unibyte text according to language environment.\n\
13615 Specifically this means that unibyte non-ASCII characters\n\
13616 are displayed by converting them to the equivalent multibyte characters\n\
13617 according to the current language environment. As a result, they are\n\
13618 displayed according to the current fontset.");
13619 unibyte_display_via_language_environment
= 0;
13621 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
13622 "*Maximum height for resizing mini-windows.\n\
13623 If a float, it specifies a fraction of the mini-window frame's height.\n\
13624 If an integer, it specifies a number of lines.\n\
13625 If nil, don't resize.");
13626 Vmax_mini_window_height
= make_float (0.25);
13628 DEFVAR_BOOL ("cursor-in-non-selected-windows",
13629 &cursor_in_non_selected_windows
,
13630 "*Non-nil means display a hollow cursor in non-selected windows.\n\
13631 Nil means don't display a cursor there.");
13632 cursor_in_non_selected_windows
= 1;
13634 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
13635 "*Non-nil means scroll the display automatically to make point visible.");
13636 automatic_hscrolling_p
= 1;
13638 DEFVAR_LISP ("image-types", &Vimage_types
,
13639 "List of supported image types.\n\
13640 Each element of the list is a symbol for a supported image type.");
13641 Vimage_types
= Qnil
;
13643 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
13644 "If non-nil, messages are truncated instead of resizing the echo area.\n\
13645 Bind this around calls to `message' to let it take effect.");
13646 message_truncate_lines
= 0;
13650 /* Initialize this module when Emacs starts. */
13655 Lisp_Object root_window
;
13656 struct window
*mini_w
;
13658 CHARPOS (this_line_start_pos
) = 0;
13660 mini_w
= XWINDOW (minibuf_window
);
13661 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
13663 if (!noninteractive
)
13665 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
13668 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
13669 set_window_height (root_window
,
13670 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
13672 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
13673 set_window_height (minibuf_window
, 1, 0);
13675 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
13676 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
13678 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
13679 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
13680 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
13682 /* The default ellipsis glyphs `...'. */
13683 for (i
= 0; i
< 3; ++i
)
13684 XSETFASTINT (default_invis_vector
[i
], '.');
13687 #ifdef HAVE_WINDOW_SYSTEM
13689 /* Allocate the buffer for frame titles. */
13691 frame_title_buf
= (char *) xmalloc (size
);
13692 frame_title_buf_end
= frame_title_buf
+ size
;
13693 frame_title_ptr
= NULL
;
13695 #endif /* HAVE_WINDOW_SYSTEM */