1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99
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. */
175 #include "termchar.h"
176 #include "dispextern.h"
180 #include "commands.h"
183 #include "termhooks.h"
184 #include "intervals.h"
185 #include "keyboard.h"
188 #include "region-cache.h"
190 #ifdef HAVE_X_WINDOWS
197 #define min(a, b) ((a) < (b) ? (a) : (b))
198 #define max(a, b) ((a) > (b) ? (a) : (b))
200 #define INFINITY 10000000
202 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
203 extern void set_frame_menubar ();
204 extern int pending_menu_activation
;
207 extern int interrupt_input
;
208 extern int command_loop_level
;
210 extern int minibuffer_auto_raise
;
212 extern Lisp_Object Qface
;
214 extern Lisp_Object Voverriding_local_map
;
215 extern Lisp_Object Voverriding_local_map_menu_flag
;
216 extern Lisp_Object Qmenu_item
;
218 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
219 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
220 Lisp_Object Qredisplay_end_trigger_functions
;
221 Lisp_Object Qinhibit_point_motion_hooks
;
222 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
;
223 Lisp_Object Qfontified
;
225 /* Functions called to fontify regions of text. */
227 Lisp_Object Vfontification_functions
;
228 Lisp_Object Qfontification_functions
;
230 /* Non-zero means draw tool bar buttons raised when the mouse moves
233 int auto_raise_tool_bar_buttons_p
;
235 /* Margin around tool bar buttons in pixels. */
237 int tool_bar_button_margin
;
239 /* Thickness of shadow to draw around tool bar buttons. */
241 int tool_bar_button_relief
;
243 /* Non-zero means automatically resize tool-bars so that all tool-bar
244 items are visible, and no blank lines remain. */
246 int auto_resize_tool_bars_p
;
248 /* Non-nil means don't actually do any redisplay. */
250 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
252 /* Names of text properties relevant for redisplay. */
254 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
255 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
257 /* Symbols used in text property values. */
259 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
260 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
262 extern Lisp_Object Qheight
;
264 /* Non-nil means highlight trailing whitespace. */
266 Lisp_Object Vshow_trailing_whitespace
;
268 /* Name of the face used to highlight trailing whitespace. */
270 Lisp_Object Qtrailing_whitespace
;
272 /* The symbol `image' which is the car of the lists used to represent
277 /* Non-zero means print newline to stdout before next mini-buffer
280 int noninteractive_need_newline
;
282 /* Non-zero means print newline to message log before next message. */
284 static int message_log_need_newline
;
287 /* The buffer position of the first character appearing entirely or
288 partially on the line of the selected window which contains the
289 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
290 redisplay optimization in redisplay_internal. */
292 static struct text_pos this_line_start_pos
;
294 /* Number of characters past the end of the line above, including the
295 terminating newline. */
297 static struct text_pos this_line_end_pos
;
299 /* The vertical positions and the height of this line. */
301 static int this_line_vpos
;
302 static int this_line_y
;
303 static int this_line_pixel_height
;
305 /* X position at which this display line starts. Usually zero;
306 negative if first character is partially visible. */
308 static int this_line_start_x
;
310 /* Buffer that this_line_.* variables are referring to. */
312 static struct buffer
*this_line_buffer
;
314 /* Nonzero means truncate lines in all windows less wide than the
317 int truncate_partial_width_windows
;
319 /* A flag to control how to display unibyte 8-bit character. */
321 int unibyte_display_via_language_environment
;
323 /* Nonzero means we have more than one non-mini-buffer-only frame.
324 Not guaranteed to be accurate except while parsing
325 frame-title-format. */
329 Lisp_Object Vglobal_mode_string
;
331 /* Marker for where to display an arrow on top of the buffer text. */
333 Lisp_Object Voverlay_arrow_position
;
335 /* String to display for the arrow. Only used on terminal frames. */
337 Lisp_Object Voverlay_arrow_string
;
339 /* Values of those variables at last redisplay. However, if
340 Voverlay_arrow_position is a marker, last_arrow_position is its
341 numerical position. */
343 static Lisp_Object last_arrow_position
, last_arrow_string
;
345 /* Like mode-line-format, but for the title bar on a visible frame. */
347 Lisp_Object Vframe_title_format
;
349 /* Like mode-line-format, but for the title bar on an iconified frame. */
351 Lisp_Object Vicon_title_format
;
353 /* List of functions to call when a window's size changes. These
354 functions get one arg, a frame on which one or more windows' sizes
357 static Lisp_Object Vwindow_size_change_functions
;
359 Lisp_Object Qmenu_bar_update_hook
;
361 /* Nonzero if overlay arrow has been displayed once in this window. */
363 static int overlay_arrow_seen
;
365 /* Nonzero means highlight the region even in nonselected windows. */
367 int highlight_nonselected_windows
;
369 /* If cursor motion alone moves point off frame, try scrolling this
370 many lines up or down if that will bring it back. */
372 static int scroll_step
;
374 /* Non-0 means scroll just far enough to bring point back on the
375 screen, when appropriate. */
377 static int scroll_conservatively
;
379 /* Recenter the window whenever point gets within this many lines of
380 the top or bottom of the window. This value is translated into a
381 pixel value by multiplying it with CANON_Y_UNIT, which means that
382 there is really a fixed pixel height scroll margin. */
386 /* Number of windows showing the buffer of the selected window (or
387 another buffer with the same base buffer). keyboard.c refers to
392 /* Vector containing glyphs for an ellipsis `...'. */
394 static Lisp_Object default_invis_vector
[3];
396 /* Nonzero means display mode line highlighted. */
398 int mode_line_inverse_video
;
400 /* Prompt to display in front of the mini-buffer contents. */
402 Lisp_Object minibuf_prompt
;
404 /* Width of current mini-buffer prompt. Only set after display_line
405 of the line that contains the prompt. */
407 int minibuf_prompt_width
;
408 int minibuf_prompt_pixel_width
;
410 /* This is the window where the echo area message was displayed. It
411 is always a mini-buffer window, but it may not be the same window
412 currently active as a mini-buffer. */
414 Lisp_Object echo_area_window
;
416 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
417 pushes the current message and the value of
418 message_enable_multibyte on the stack, the function restore_message
419 pops the stack and displays MESSAGE again. */
421 Lisp_Object Vmessage_stack
;
423 /* Nonzero means multibyte characters were enabled when the echo area
424 message was specified. */
426 int message_enable_multibyte
;
428 /* True if we should redraw the mode lines on the next redisplay. */
430 int update_mode_lines
;
432 /* Nonzero if window sizes or contents have changed since last
433 redisplay that finished */
435 int windows_or_buffers_changed
;
437 /* Nonzero after display_mode_line if %l was used and it displayed a
440 int line_number_displayed
;
442 /* Maximum buffer size for which to display line numbers. */
444 static int line_number_display_limit
;
446 /* line width to consider when repostioning for line number display */
448 static int line_number_display_limit_width
;
450 /* Number of lines to keep in the message log buffer. t means
451 infinite. nil means don't log at all. */
453 Lisp_Object Vmessage_log_max
;
455 /* Current, index 0, and last displayed echo area message. Either
456 buffers from echo_buffers, or nil to indicate no message. */
458 Lisp_Object echo_area_buffer
[2];
460 /* The buffers referenced from echo_area_buffer. */
462 static Lisp_Object echo_buffer
[2];
464 /* A vector saved used in with_area_buffer to reduce consing. */
466 static Lisp_Object Vwith_echo_area_save_vector
;
468 /* Non-zero means display_echo_area should display the last echo area
469 message again. Set by redisplay_preserve_echo_area. */
471 static int display_last_displayed_message_p
;
473 /* Nonzero if echo area is being used by print; zero if being used by
476 int message_buf_print
;
478 /* Maximum height for resizing mini-windows. Either a float
479 specifying a fraction of the available height, or an integer
480 specifying a number of lines. */
482 static Lisp_Object Vmax_mini_window_height
;
484 /* Non-zero means we want a hollow cursor in windows that are not
485 selected. Zero means there's no cursor in such windows. */
487 int cursor_in_non_selected_windows
;
489 /* A scratch glyph row with contents used for generating truncation
490 glyphs. Also used in direct_output_for_insert. */
492 #define MAX_SCRATCH_GLYPHS 100
493 struct glyph_row scratch_glyph_row
;
494 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
496 /* Ascent and height of the last line processed by move_it_to. */
498 static int last_max_ascent
, last_height
;
500 /* The maximum distance to look ahead for text properties. Values
501 that are too small let us call compute_char_face and similar
502 functions too often which is expensive. Values that are too large
503 let us call compute_char_face and alike too often because we
504 might not be interested in text properties that far away. */
506 #define TEXT_PROP_DISTANCE_LIMIT 100
508 /* Non-zero means print traces of redisplay if compiled with
512 int trace_redisplay_p
;
515 /* Non-zero means automatically scroll windows horizontally to make
518 int automatic_hscrolling_p
;
520 /* A list of symbols, one for each supported image type. */
522 Lisp_Object Vimage_types
;
524 /* Value returned from text property handlers (see below). */
529 HANDLED_RECOMPUTE_PROPS
,
530 HANDLED_OVERLAY_STRING_CONSUMED
,
534 /* A description of text properties that redisplay is interested
539 /* The name of the property. */
542 /* A unique index for the property. */
545 /* A handler function called to set up iterator IT from the property
546 at IT's current position. Value is used to steer handle_stop. */
547 enum prop_handled (*handler
) P_ ((struct it
*it
));
550 static enum prop_handled handle_face_prop
P_ ((struct it
*));
551 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
552 static enum prop_handled handle_display_prop
P_ ((struct it
*));
553 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
554 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
555 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
557 /* Properties handled by iterators. */
559 static struct props it_props
[] =
561 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
562 /* Handle `face' before `display' because some sub-properties of
563 `display' need to know the face. */
564 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
565 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
566 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
567 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
571 /* Value is the position described by X. If X is a marker, value is
572 the marker_position of X. Otherwise, value is X. */
574 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
576 /* Enumeration returned by some move_it_.* functions internally. */
580 /* Not used. Undefined value. */
583 /* Move ended at the requested buffer position or ZV. */
584 MOVE_POS_MATCH_OR_ZV
,
586 /* Move ended at the requested X pixel position. */
589 /* Move within a line ended at the end of a line that must be
593 /* Move within a line ended at the end of a line that would
594 be displayed truncated. */
597 /* Move within a line ended at a line end. */
603 /* Function prototypes. */
605 static void ensure_echo_area_buffers
P_ ((void));
606 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
608 struct glyph_row
*));
609 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
610 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
611 static void clear_garbaged_frames
P_ ((void));
612 static int current_message_1
P_ ((Lisp_Object
*));
613 static int truncate_message_1
P_ ((int));
614 static int set_message_1
P_ ((char *s
, Lisp_Object
, int, int));
615 static int display_echo_area
P_ ((struct window
*));
616 static int display_echo_area_1
P_ ((struct window
*));
617 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
618 static int string_char_and_length
P_ ((unsigned char *, int, int *));
619 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
621 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
622 static Lisp_Object eval_handler
P_ ((Lisp_Object
));
623 static Lisp_Object eval_form
P_ ((Lisp_Object
));
624 static void insert_left_trunc_glyphs
P_ ((struct it
*));
625 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
626 static void extend_face_to_end_of_line
P_ ((struct it
*));
627 static int append_space
P_ ((struct it
*, int));
628 static void make_cursor_line_fully_visible
P_ ((struct window
*));
629 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
630 static int trailing_whitespace_p
P_ ((int));
631 static int message_log_check_duplicate
P_ ((int, int, int, int));
632 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
633 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
634 static void push_it
P_ ((struct it
*));
635 static void pop_it
P_ ((struct it
*));
636 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
637 static void redisplay_internal
P_ ((int));
638 static int echo_area_display
P_ ((int));
639 static void redisplay_windows
P_ ((Lisp_Object
));
640 static void redisplay_window
P_ ((Lisp_Object
, int));
641 static void update_menu_bar
P_ ((struct frame
*, int));
642 static int try_window_reusing_current_matrix
P_ ((struct window
*));
643 static int try_window_id
P_ ((struct window
*));
644 static int display_line
P_ ((struct it
*));
645 static void display_mode_lines
P_ ((struct window
*));
646 static void display_mode_line
P_ ((struct window
*, enum face_id
,
648 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
649 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
650 static void display_menu_bar
P_ ((struct window
*));
651 static int display_count_lines
P_ ((int, int, int, int, int *));
652 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
653 int, int, struct it
*, int, int, int, int));
654 static void compute_line_metrics
P_ ((struct it
*));
655 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
656 static int get_overlay_strings
P_ ((struct it
*));
657 static void next_overlay_string
P_ ((struct it
*));
658 void set_iterator_to_next
P_ ((struct it
*));
659 static void reseat
P_ ((struct it
*, struct text_pos
, int));
660 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
661 static void back_to_previous_visible_line_start
P_ ((struct it
*));
662 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
663 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
664 static int next_element_from_display_vector
P_ ((struct it
*));
665 static int next_element_from_string
P_ ((struct it
*));
666 static int next_element_from_c_string
P_ ((struct it
*));
667 static int next_element_from_buffer
P_ ((struct it
*));
668 static int next_element_from_composition
P_ ((struct it
*));
669 static int next_element_from_image
P_ ((struct it
*));
670 static int next_element_from_stretch
P_ ((struct it
*));
671 static void load_overlay_strings
P_ ((struct it
*));
672 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
673 struct display_pos
*));
674 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
675 Lisp_Object
, int, int, int, int));
676 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
678 void move_it_vertically_backward
P_ ((struct it
*, int));
679 static void init_to_row_start
P_ ((struct it
*, struct window
*,
680 struct glyph_row
*));
681 static void init_to_row_end
P_ ((struct it
*, struct window
*,
682 struct glyph_row
*));
683 static void back_to_previous_line_start
P_ ((struct it
*));
684 static void forward_to_next_line_start
P_ ((struct it
*));
685 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
687 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
688 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
689 static int number_of_chars
P_ ((unsigned char *, int));
690 static void compute_stop_pos
P_ ((struct it
*));
691 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
693 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
694 static int next_overlay_change
P_ ((int));
695 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
696 Lisp_Object
, struct text_pos
*));
698 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
699 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
701 #ifdef HAVE_WINDOW_SYSTEM
703 static void update_tool_bar
P_ ((struct frame
*, int));
704 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
705 static int redisplay_tool_bar
P_ ((struct frame
*));
706 static void display_tool_bar_line
P_ ((struct it
*));
708 #endif /* HAVE_WINDOW_SYSTEM */
711 /***********************************************************************
712 Window display dimensions
713 ***********************************************************************/
715 /* Return the window-relative maximum y + 1 for glyph rows displaying
716 text in window W. This is the height of W minus the height of a
717 mode line, if any. */
720 window_text_bottom_y (w
)
723 struct frame
*f
= XFRAME (w
->frame
);
724 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
726 if (WINDOW_WANTS_MODELINE_P (w
))
727 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
732 /* Return the pixel width of display area AREA of window W. AREA < 0
733 means return the total width of W, not including bitmap areas to
734 the left and right of the window. */
737 window_box_width (w
, area
)
741 struct frame
*f
= XFRAME (w
->frame
);
742 int width
= XFASTINT (w
->width
);
744 if (!w
->pseudo_window_p
)
746 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
748 if (area
== TEXT_AREA
)
750 if (INTEGERP (w
->left_margin_width
))
751 width
-= XFASTINT (w
->left_margin_width
);
752 if (INTEGERP (w
->right_margin_width
))
753 width
-= XFASTINT (w
->right_margin_width
);
755 else if (area
== LEFT_MARGIN_AREA
)
756 width
= (INTEGERP (w
->left_margin_width
)
757 ? XFASTINT (w
->left_margin_width
) : 0);
758 else if (area
== RIGHT_MARGIN_AREA
)
759 width
= (INTEGERP (w
->right_margin_width
)
760 ? XFASTINT (w
->right_margin_width
) : 0);
763 return width
* CANON_X_UNIT (f
);
767 /* Return the pixel height of the display area of window W, not
768 including mode lines of W, if any.. */
771 window_box_height (w
)
774 struct frame
*f
= XFRAME (w
->frame
);
775 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
777 if (WINDOW_WANTS_MODELINE_P (w
))
778 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
780 if (WINDOW_WANTS_HEADER_LINE_P (w
))
781 height
-= CURRENT_HEADER_LINE_HEIGHT (w
);
787 /* Return the frame-relative coordinate of the left edge of display
788 area AREA of window W. AREA < 0 means return the left edge of the
789 whole window, to the right of any bitmap area at the left side of
793 window_box_left (w
, area
)
797 struct frame
*f
= XFRAME (w
->frame
);
798 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
800 if (!w
->pseudo_window_p
)
802 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
803 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
805 if (area
== TEXT_AREA
)
806 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
807 else if (area
== RIGHT_MARGIN_AREA
)
808 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
809 + window_box_width (w
, TEXT_AREA
));
816 /* Return the frame-relative coordinate of the right edge of display
817 area AREA of window W. AREA < 0 means return the left edge of the
818 whole window, to the left of any bitmap area at the right side of
822 window_box_right (w
, area
)
826 return window_box_left (w
, area
) + window_box_width (w
, area
);
830 /* Get the bounding box of the display area AREA of window W, without
831 mode lines, in frame-relative coordinates. AREA < 0 means the
832 whole window, not including bitmap areas to the left and right of
833 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
834 coordinates of the upper-left corner of the box. Return in
835 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
838 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
841 int *box_x
, *box_y
, *box_width
, *box_height
;
843 struct frame
*f
= XFRAME (w
->frame
);
845 *box_width
= window_box_width (w
, area
);
846 *box_height
= window_box_height (w
);
847 *box_x
= window_box_left (w
, area
);
848 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
849 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
850 if (WINDOW_WANTS_HEADER_LINE_P (w
))
851 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
855 /* Get the bounding box of the display area AREA of window W, without
856 mode lines. AREA < 0 means the whole window, not including bitmap
857 areas to the left and right of the window. Return in *TOP_LEFT_X
858 and TOP_LEFT_Y the frame-relative pixel coordinates of the
859 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
860 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
864 window_box_edges (w
, area
, top_left_x
, top_left_y
,
865 bottom_right_x
, bottom_right_y
)
868 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
870 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
872 *bottom_right_x
+= *top_left_x
;
873 *bottom_right_y
+= *top_left_y
;
878 /***********************************************************************
880 ***********************************************************************/
882 /* Return the next character from STR which is MAXLEN bytes long.
883 Return in *LEN the length of the character. This is like
884 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
885 we find one, we return a `?', but with the length of the invalid
889 string_char_and_length (str
, maxlen
, len
)
895 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
896 if (!CHAR_VALID_P (c
, 1))
897 /* We may not change the length here because other places in Emacs
898 don't use this function, i.e. they silently accept invalid
907 /* Given a position POS containing a valid character and byte position
908 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
910 static struct text_pos
911 string_pos_nchars_ahead (pos
, string
, nchars
)
916 xassert (STRINGP (string
) && nchars
>= 0);
918 if (STRING_MULTIBYTE (string
))
920 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
921 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
926 string_char_and_length (p
, rest
, &len
);
927 p
+= len
, rest
-= len
;
930 BYTEPOS (pos
) += len
;
934 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
940 /* Value is the text position, i.e. character and byte position,
941 for character position CHARPOS in STRING. */
943 static INLINE
struct text_pos
944 string_pos (charpos
, string
)
949 xassert (STRINGP (string
));
950 xassert (charpos
>= 0);
951 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
956 /* Value is a text position, i.e. character and byte position, for
957 character position CHARPOS in C string S. MULTIBYTE_P non-zero
958 means recognize multibyte characters. */
960 static struct text_pos
961 c_string_pos (charpos
, s
, multibyte_p
)
969 xassert (charpos
>= 0);
973 int rest
= strlen (s
), len
;
975 SET_TEXT_POS (pos
, 0, 0);
978 string_char_and_length (s
, rest
, &len
);
979 s
+= len
, rest
-= len
;
982 BYTEPOS (pos
) += len
;
986 SET_TEXT_POS (pos
, charpos
, charpos
);
992 /* Value is the number of characters in C string S. MULTIBYTE_P
993 non-zero means recognize multibyte characters. */
996 number_of_chars (s
, multibyte_p
)
1004 int rest
= strlen (s
), len
;
1005 unsigned char *p
= (unsigned char *) s
;
1007 for (nchars
= 0; rest
> 0; ++nchars
)
1009 string_char_and_length (p
, rest
, &len
);
1010 rest
-= len
, p
+= len
;
1014 nchars
= strlen (s
);
1020 /* Compute byte position NEWPOS->bytepos corresponding to
1021 NEWPOS->charpos. POS is a known position in string STRING.
1022 NEWPOS->charpos must be >= POS.charpos. */
1025 compute_string_pos (newpos
, pos
, string
)
1026 struct text_pos
*newpos
, pos
;
1029 xassert (STRINGP (string
));
1030 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1032 if (STRING_MULTIBYTE (string
))
1033 *newpos
= string_pos_nchars_ahead (pos
, string
,
1034 CHARPOS (*newpos
) - CHARPOS (pos
));
1036 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1041 /***********************************************************************
1042 Lisp form evaluation
1043 ***********************************************************************/
1045 /* Error handler for eval_form. */
1055 /* Evaluate SEXPR and return the result, or nil if something went
1062 int count
= specpdl_ptr
- specpdl
;
1064 specbind (Qinhibit_redisplay
, Qt
);
1065 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, eval_handler
);
1066 return unbind_to (count
, val
);
1071 /***********************************************************************
1073 ***********************************************************************/
1077 /* Define CHECK_IT to perform sanity checks on iterators.
1078 This is for debugging. It is too slow to do unconditionally. */
1084 if (it
->method
== next_element_from_string
)
1086 xassert (STRINGP (it
->string
));
1087 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1089 else if (it
->method
== next_element_from_buffer
)
1091 /* Check that character and byte positions agree. */
1092 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1096 xassert (it
->current
.dpvec_index
>= 0);
1098 xassert (it
->current
.dpvec_index
< 0);
1101 #define CHECK_IT(IT) check_it ((IT))
1105 #define CHECK_IT(IT) (void) 0
1112 /* Check that the window end of window W is what we expect it
1113 to be---the last row in the current matrix displaying text. */
1116 check_window_end (w
)
1119 if (!MINI_WINDOW_P (w
)
1120 && !NILP (w
->window_end_valid
))
1122 struct glyph_row
*row
;
1123 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1124 XFASTINT (w
->window_end_vpos
)),
1126 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1127 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1131 #define CHECK_WINDOW_END(W) check_window_end ((W))
1133 #else /* not GLYPH_DEBUG */
1135 #define CHECK_WINDOW_END(W) (void) 0
1137 #endif /* not GLYPH_DEBUG */
1141 /***********************************************************************
1142 Iterator initialization
1143 ***********************************************************************/
1145 /* Initialize IT for displaying current_buffer in window W, starting
1146 at character position CHARPOS. CHARPOS < 0 means that no buffer
1147 position is specified which is useful when the iterator is assigned
1148 a position later. BYTEPOS is the byte position corresponding to
1149 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1151 If ROW is not null, calls to produce_glyphs with IT as parameter
1152 will produce glyphs in that row.
1154 BASE_FACE_ID is the id of a base face to use. It must be one of
1155 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1156 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1157 displaying the tool-bar.
1159 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1160 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1161 corresponding mode line glyph row of the desired matrix of W. */
1164 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1167 int charpos
, bytepos
;
1168 struct glyph_row
*row
;
1169 enum face_id base_face_id
;
1171 int highlight_region_p
;
1173 /* Some precondition checks. */
1174 xassert (w
!= NULL
&& it
!= NULL
);
1175 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1177 /* If face attributes have been changed since the last redisplay,
1178 free realized faces now because they depend on face definitions
1179 that might have changed. */
1180 if (face_change_count
)
1182 face_change_count
= 0;
1183 free_all_realized_faces (Qnil
);
1186 /* Use one of the mode line rows of W's desired matrix if
1190 if (base_face_id
== MODE_LINE_FACE_ID
)
1191 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1192 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1193 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1197 bzero (it
, sizeof *it
);
1198 it
->current
.overlay_string_index
= -1;
1199 it
->current
.dpvec_index
= -1;
1200 it
->base_face_id
= base_face_id
;
1202 /* The window in which we iterate over current_buffer: */
1203 XSETWINDOW (it
->window
, w
);
1205 it
->f
= XFRAME (w
->frame
);
1207 /* Extra space between lines (on window systems only). */
1208 if (base_face_id
== DEFAULT_FACE_ID
1209 && FRAME_WINDOW_P (it
->f
))
1211 if (NATNUMP (current_buffer
->extra_line_spacing
))
1212 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1213 else if (it
->f
->extra_line_spacing
> 0)
1214 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1217 /* If realized faces have been removed, e.g. because of face
1218 attribute changes of named faces, recompute them. */
1219 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1220 recompute_basic_faces (it
->f
);
1222 /* Current value of the `space-width', and 'height' properties. */
1223 it
->space_width
= Qnil
;
1224 it
->font_height
= Qnil
;
1226 /* Are control characters displayed as `^C'? */
1227 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1229 /* -1 means everything between a CR and the following line end
1230 is invisible. >0 means lines indented more than this value are
1232 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1233 ? XFASTINT (current_buffer
->selective_display
)
1234 : (!NILP (current_buffer
->selective_display
)
1236 it
->selective_display_ellipsis_p
1237 = !NILP (current_buffer
->selective_display_ellipses
);
1239 /* Display table to use. */
1240 it
->dp
= window_display_table (w
);
1242 /* Are multibyte characters enabled in current_buffer? */
1243 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1245 /* Non-zero if we should highlight the region. */
1247 = (!NILP (Vtransient_mark_mode
)
1248 && !NILP (current_buffer
->mark_active
)
1249 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1251 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1252 start and end of a visible region in window IT->w. Set both to
1253 -1 to indicate no region. */
1254 if (highlight_region_p
1255 /* Maybe highlight only in selected window. */
1256 && (/* Either show region everywhere. */
1257 highlight_nonselected_windows
1258 /* Or show region in the selected window. */
1259 || w
== XWINDOW (selected_window
)
1260 /* Or show the region if we are in the mini-buffer and W is
1261 the window the mini-buffer refers to. */
1262 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1263 && w
== XWINDOW (Vminibuf_scroll_window
))))
1265 int charpos
= marker_position (current_buffer
->mark
);
1266 it
->region_beg_charpos
= min (PT
, charpos
);
1267 it
->region_end_charpos
= max (PT
, charpos
);
1270 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1272 /* Get the position at which the redisplay_end_trigger hook should
1273 be run, if it is to be run at all. */
1274 if (MARKERP (w
->redisplay_end_trigger
)
1275 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1276 it
->redisplay_end_trigger_charpos
1277 = marker_position (w
->redisplay_end_trigger
);
1278 else if (INTEGERP (w
->redisplay_end_trigger
))
1279 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1281 /* Correct bogus values of tab_width. */
1282 it
->tab_width
= XINT (current_buffer
->tab_width
);
1283 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1286 /* Are lines in the display truncated? */
1287 it
->truncate_lines_p
1288 = (base_face_id
!= DEFAULT_FACE_ID
1289 || XINT (it
->w
->hscroll
)
1290 || (truncate_partial_width_windows
1291 && !WINDOW_FULL_WIDTH_P (it
->w
))
1292 || !NILP (current_buffer
->truncate_lines
));
1294 /* Get dimensions of truncation and continuation glyphs. These are
1295 displayed as bitmaps under X, so we don't need them for such
1297 if (!FRAME_WINDOW_P (it
->f
))
1299 if (it
->truncate_lines_p
)
1301 /* We will need the truncation glyph. */
1302 xassert (it
->glyph_row
== NULL
);
1303 produce_special_glyphs (it
, IT_TRUNCATION
);
1304 it
->truncation_pixel_width
= it
->pixel_width
;
1308 /* We will need the continuation glyph. */
1309 xassert (it
->glyph_row
== NULL
);
1310 produce_special_glyphs (it
, IT_CONTINUATION
);
1311 it
->continuation_pixel_width
= it
->pixel_width
;
1314 /* Reset these values to zero becaue the produce_special_glyphs
1315 above has changed them. */
1316 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1317 it
->phys_ascent
= it
->phys_descent
= 0;
1320 /* Set this after getting the dimensions of truncation and
1321 continuation glyphs, so that we don't produce glyphs when calling
1322 produce_special_glyphs, above. */
1323 it
->glyph_row
= row
;
1324 it
->area
= TEXT_AREA
;
1326 /* Get the dimensions of the display area. The display area
1327 consists of the visible window area plus a horizontally scrolled
1328 part to the left of the window. All x-values are relative to the
1329 start of this total display area. */
1330 if (base_face_id
!= DEFAULT_FACE_ID
)
1332 /* Mode lines, menu bar in terminal frames. */
1333 it
->first_visible_x
= 0;
1334 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1339 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1340 it
->last_visible_x
= (it
->first_visible_x
1341 + window_box_width (w
, TEXT_AREA
));
1343 /* If we truncate lines, leave room for the truncator glyph(s) at
1344 the right margin. Otherwise, leave room for the continuation
1345 glyph(s). Truncation and continuation glyphs are not inserted
1346 for window-based redisplay. */
1347 if (!FRAME_WINDOW_P (it
->f
))
1349 if (it
->truncate_lines_p
)
1350 it
->last_visible_x
-= it
->truncation_pixel_width
;
1352 it
->last_visible_x
-= it
->continuation_pixel_width
;
1355 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1356 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1359 /* Leave room for a border glyph. */
1360 if (!FRAME_WINDOW_P (it
->f
)
1361 && !WINDOW_RIGHTMOST_P (it
->w
))
1362 it
->last_visible_x
-= 1;
1364 it
->last_visible_y
= window_text_bottom_y (w
);
1366 /* For mode lines and alike, arrange for the first glyph having a
1367 left box line if the face specifies a box. */
1368 if (base_face_id
!= DEFAULT_FACE_ID
)
1372 it
->face_id
= base_face_id
;
1374 /* If we have a boxed mode line, make the first character appear
1375 with a left box line. */
1376 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1377 if (face
->box
!= FACE_NO_BOX
)
1378 it
->start_of_box_run_p
= 1;
1381 /* If a buffer position was specified, set the iterator there,
1382 getting overlays and face properties from that position. */
1385 it
->end_charpos
= ZV
;
1387 IT_CHARPOS (*it
) = charpos
;
1389 /* Compute byte position if not specified. */
1391 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1393 IT_BYTEPOS (*it
) = bytepos
;
1395 /* Compute faces etc. */
1396 reseat (it
, it
->current
.pos
, 1);
1403 /* Initialize IT for the display of window W with window start POS. */
1406 start_display (it
, w
, pos
)
1409 struct text_pos pos
;
1411 int start_at_line_beg_p
;
1412 struct glyph_row
*row
;
1413 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1416 row
= w
->desired_matrix
->rows
+ first_vpos
;
1417 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1418 first_y
= it
->current_y
;
1420 /* If window start is not at a line start, move back to the line
1421 start. This makes sure that we take continuation lines into
1423 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1424 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1425 if (!start_at_line_beg_p
)
1426 reseat_at_previous_visible_line_start (it
);
1428 /* If window start is not at a line start, skip forward to POS to
1429 get the correct continuation_lines_width and current_x. */
1430 if (!start_at_line_beg_p
)
1432 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1434 /* If lines are continued, this line may end in the middle of a
1435 multi-glyph character (e.g. a control character displayed as
1436 \003, or in the middle of an overlay string). In this case
1437 move_it_to above will not have taken us to the start of
1438 the continuation line but to the end of the continued line. */
1439 if (!it
->truncate_lines_p
&& it
->current_x
> 0)
1441 if (it
->current
.dpvec_index
>= 0
1442 || it
->current
.overlay_string_index
>= 0)
1444 set_iterator_to_next (it
);
1445 move_it_in_display_line_to (it
, -1, -1, 0);
1447 it
->continuation_lines_width
+= it
->current_x
;
1450 it
->current_y
= first_y
;
1452 it
->current_x
= it
->hpos
= 0;
1455 #if 0 /* Don't assert the following because start_display is sometimes
1456 called intentionally with a window start that is not at a
1457 line start. Please leave this code in as a comment. */
1459 /* Window start should be on a line start, now. */
1460 xassert (it
->continuation_lines_width
1461 || IT_CHARPOS (it
) == BEGV
1462 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1467 /* Initialize IT for stepping through current_buffer in window W,
1468 starting at position POS that includes overlay string and display
1469 vector/ control character translation position information. */
1472 init_from_display_pos (it
, w
, pos
)
1475 struct display_pos
*pos
;
1477 /* Keep in mind: the call to reseat in init_iterator skips invisible
1478 text, so we might end up at a position different from POS. This
1479 is only a problem when POS is a row start after a newline and an
1480 overlay starts there with an after-string, and the overlay has an
1481 invisible property. Since we don't skip invisible text in
1482 display_line and elsewhere immediately after consuming the
1483 newline before the row start, such a POS will not be in a string,
1484 but the call to init_iterator below will move us to the
1486 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1487 NULL
, DEFAULT_FACE_ID
);
1489 /* If position is within an overlay string, set up IT to
1490 the right overlay string. */
1491 if (pos
->overlay_string_index
>= 0)
1495 /* We already have the first chunk of overlay strings in
1496 IT->overlay_strings. Load more until the one for
1497 pos->overlay_string_index is in IT->overlay_strings. */
1498 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1500 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1501 it
->current
.overlay_string_index
= 0;
1504 load_overlay_strings (it
);
1505 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1509 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1510 relative_index
= (it
->current
.overlay_string_index
1511 % OVERLAY_STRING_CHUNK_SIZE
);
1512 it
->string
= it
->overlay_strings
[relative_index
];
1513 it
->current
.string_pos
= pos
->string_pos
;
1514 it
->method
= next_element_from_string
;
1516 else if (CHARPOS (pos
->string_pos
) >= 0)
1518 /* Recorded position is not in an overlay string, but in another
1519 string. This can only be a string from a `display' property.
1520 IT should already be filled with that string. */
1521 it
->current
.string_pos
= pos
->string_pos
;
1522 xassert (STRINGP (it
->string
));
1525 /* Restore position in display vector translations or control
1526 character translations. */
1527 if (pos
->dpvec_index
>= 0)
1529 /* This fills IT->dpvec. */
1530 get_next_display_element (it
);
1531 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1532 it
->current
.dpvec_index
= pos
->dpvec_index
;
1539 /* Initialize IT for stepping through current_buffer in window W
1540 starting at ROW->start. */
1543 init_to_row_start (it
, w
, row
)
1546 struct glyph_row
*row
;
1548 init_from_display_pos (it
, w
, &row
->start
);
1549 it
->continuation_lines_width
= row
->continuation_lines_width
;
1554 /* Initialize IT for stepping through current_buffer in window W
1555 starting in the line following ROW, i.e. starting at ROW->end. */
1558 init_to_row_end (it
, w
, row
)
1561 struct glyph_row
*row
;
1563 init_from_display_pos (it
, w
, &row
->end
);
1565 if (row
->continued_p
)
1566 it
->continuation_lines_width
= (row
->continuation_lines_width
1567 + row
->pixel_width
);
1574 /***********************************************************************
1576 ***********************************************************************/
1578 /* Called when IT reaches IT->stop_charpos. Handle text property and
1579 overlay changes. Set IT->stop_charpos to the next position where
1586 enum prop_handled handled
;
1587 int handle_overlay_change_p
= 1;
1591 it
->current
.dpvec_index
= -1;
1595 handled
= HANDLED_NORMALLY
;
1597 /* Call text property handlers. */
1598 for (p
= it_props
; p
->handler
; ++p
)
1600 handled
= p
->handler (it
);
1602 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1604 else if (handled
== HANDLED_RETURN
)
1606 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1607 handle_overlay_change_p
= 0;
1610 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1612 /* Don't check for overlay strings below when set to deliver
1613 characters from a display vector. */
1614 if (it
->method
== next_element_from_display_vector
)
1615 handle_overlay_change_p
= 0;
1617 /* Handle overlay changes. */
1618 if (handle_overlay_change_p
)
1619 handled
= handle_overlay_change (it
);
1621 /* Determine where to stop next. */
1622 if (handled
== HANDLED_NORMALLY
)
1623 compute_stop_pos (it
);
1626 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1630 /* Compute IT->stop_charpos from text property and overlay change
1631 information for IT's current position. */
1634 compute_stop_pos (it
)
1637 register INTERVAL iv
, next_iv
;
1638 Lisp_Object object
, limit
, position
;
1640 /* If nowhere else, stop at the end. */
1641 it
->stop_charpos
= it
->end_charpos
;
1643 if (STRINGP (it
->string
))
1645 /* Strings are usually short, so don't limit the search for
1647 object
= it
->string
;
1649 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1655 /* If next overlay change is in front of the current stop pos
1656 (which is IT->end_charpos), stop there. Note: value of
1657 next_overlay_change is point-max if no overlay change
1659 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1660 if (charpos
< it
->stop_charpos
)
1661 it
->stop_charpos
= charpos
;
1663 /* If showing the region, we have to stop at the region
1664 start or end because the face might change there. */
1665 if (it
->region_beg_charpos
> 0)
1667 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1668 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1669 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1670 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1673 /* Set up variables for computing the stop position from text
1674 property changes. */
1675 XSETBUFFER (object
, current_buffer
);
1676 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1677 XSETFASTINT (position
, IT_CHARPOS (*it
));
1681 /* Get the interval containing IT's position. Value is a null
1682 interval if there isn't such an interval. */
1683 iv
= validate_interval_range (object
, &position
, &position
, 0);
1684 if (!NULL_INTERVAL_P (iv
))
1686 Lisp_Object values_here
[LAST_PROP_IDX
];
1689 /* Get properties here. */
1690 for (p
= it_props
; p
->handler
; ++p
)
1691 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1693 /* Look for an interval following iv that has different
1695 for (next_iv
= next_interval (iv
);
1696 (!NULL_INTERVAL_P (next_iv
)
1698 || XFASTINT (limit
) > next_iv
->position
));
1699 next_iv
= next_interval (next_iv
))
1701 for (p
= it_props
; p
->handler
; ++p
)
1703 Lisp_Object new_value
;
1705 new_value
= textget (next_iv
->plist
, *p
->name
);
1706 if (!EQ (values_here
[p
->idx
], new_value
))
1714 if (!NULL_INTERVAL_P (next_iv
))
1716 if (INTEGERP (limit
)
1717 && next_iv
->position
>= XFASTINT (limit
))
1718 /* No text property change up to limit. */
1719 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1721 /* Text properties change in next_iv. */
1722 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1726 xassert (STRINGP (it
->string
)
1727 || (it
->stop_charpos
>= BEGV
1728 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1732 /* Return the position of the next overlay change after POS in
1733 current_buffer. Value is point-max if no overlay change
1734 follows. This is like `next-overlay-change' but doesn't use
1738 next_overlay_change (pos
)
1743 Lisp_Object
*overlays
;
1747 /* Get all overlays at the given position. */
1749 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1750 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1751 if (noverlays
> len
)
1754 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1755 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1758 /* If any of these overlays ends before endpos,
1759 use its ending point instead. */
1760 for (i
= 0; i
< noverlays
; ++i
)
1765 oend
= OVERLAY_END (overlays
[i
]);
1766 oendpos
= OVERLAY_POSITION (oend
);
1767 endpos
= min (endpos
, oendpos
);
1775 /***********************************************************************
1777 ***********************************************************************/
1779 /* Handle changes in the `fontified' property of the current buffer by
1780 calling hook functions from Qfontification_functions to fontify
1783 static enum prop_handled
1784 handle_fontified_prop (it
)
1787 Lisp_Object prop
, pos
;
1788 enum prop_handled handled
= HANDLED_NORMALLY
;
1789 struct gcpro gcpro1
;
1791 /* Get the value of the `fontified' property at IT's current buffer
1792 position. (The `fontified' property doesn't have a special
1793 meaning in strings.) If the value is nil, call functions from
1794 Qfontification_functions. */
1795 if (!STRINGP (it
->string
)
1797 && !NILP (Vfontification_functions
)
1798 && (pos
= make_number (IT_CHARPOS (*it
)),
1799 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1802 Lisp_Object args
[2];
1805 /* Run the hook functions. */
1806 args
[0] = Qfontification_functions
;
1808 Frun_hook_with_args (2, args
);
1810 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
1811 something. This avoids an endless loop if they failed to
1812 fontify the text for which reason ever. */
1813 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
1814 handled
= HANDLED_RECOMPUTE_PROPS
;
1823 /***********************************************************************
1825 ***********************************************************************/
1827 /* Set up iterator IT from face properties at its current position.
1828 Called from handle_stop. */
1830 static enum prop_handled
1831 handle_face_prop (it
)
1834 int new_face_id
, next_stop
;
1836 if (!STRINGP (it
->string
))
1839 = face_at_buffer_position (it
->w
,
1841 it
->region_beg_charpos
,
1842 it
->region_end_charpos
,
1845 + TEXT_PROP_DISTANCE_LIMIT
),
1848 /* Is this a start of a run of characters with box face?
1849 Caveat: this can be called for a freshly initialized
1850 iterator; face_id is -1 is this case. We know that the new
1851 face will not change until limit, i.e. if the new face has a
1852 box, all characters up to limit will have one. But, as
1853 usual, we don't know whether limit is really the end. */
1854 if (new_face_id
!= it
->face_id
)
1856 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1858 /* If new face has a box but old face has not, this is
1859 the start of a run of characters with box, i.e. it has
1860 a shadow on the left side. The value of face_id of the
1861 iterator will be -1 if this is the initial call that gets
1862 the face. In this case, we have to look in front of IT's
1863 position and see whether there is a face != new_face_id. */
1864 it
->start_of_box_run_p
1865 = (new_face
->box
!= FACE_NO_BOX
1866 && (it
->face_id
>= 0
1867 || IT_CHARPOS (*it
) == BEG
1868 || new_face_id
!= face_before_it_pos (it
)));
1869 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1875 = face_at_string_position (it
->w
,
1877 IT_STRING_CHARPOS (*it
),
1878 (it
->current
.overlay_string_index
>= 0
1881 it
->region_beg_charpos
,
1882 it
->region_end_charpos
,
1886 #if 0 /* This shouldn't be neccessary. Let's check it. */
1887 /* If IT is used to display a mode line we would really like to
1888 use the mode line face instead of the frame's default face. */
1889 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
1890 && new_face_id
== DEFAULT_FACE_ID
)
1891 new_face_id
= MODE_LINE_FACE_ID
;
1894 /* Is this a start of a run of characters with box? Caveat:
1895 this can be called for a freshly allocated iterator; face_id
1896 is -1 is this case. We know that the new face will not
1897 change until the next check pos, i.e. if the new face has a
1898 box, all characters up to that position will have a
1899 box. But, as usual, we don't know whether that position
1900 is really the end. */
1901 if (new_face_id
!= it
->face_id
)
1903 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1904 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1906 /* If new face has a box but old face hasn't, this is the
1907 start of a run of characters with box, i.e. it has a
1908 shadow on the left side. */
1909 it
->start_of_box_run_p
1910 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
1911 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1915 it
->face_id
= new_face_id
;
1916 return HANDLED_NORMALLY
;
1920 /* Compute the face one character before or after the current position
1921 of IT. BEFORE_P non-zero means get the face in front of IT's
1922 position. Value is the id of the face. */
1925 face_before_or_after_it_pos (it
, before_p
)
1930 int next_check_charpos
;
1931 struct text_pos pos
;
1933 xassert (it
->s
== NULL
);
1935 if (STRINGP (it
->string
))
1937 /* No face change past the end of the string (for the case
1938 we are padding with spaces). No face change before the
1940 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
1941 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
1944 /* Set pos to the position before or after IT's current position. */
1946 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
1948 /* For composition, we must check the character after the
1950 pos
= (it
->what
== IT_COMPOSITION
1951 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
1952 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
1954 /* Get the face for ASCII, or unibyte. */
1956 = face_at_string_position (it
->w
,
1959 (it
->current
.overlay_string_index
>= 0
1962 it
->region_beg_charpos
,
1963 it
->region_end_charpos
,
1964 &next_check_charpos
,
1967 /* Correct the face for charsets different from ASCII. Do it
1968 for the multibyte case only. The face returned above is
1969 suitable for unibyte text if IT->string is unibyte. */
1970 if (STRING_MULTIBYTE (it
->string
))
1972 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
1973 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
1975 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
1977 c
= string_char_and_length (p
, rest
, &len
);
1978 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
1983 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
1984 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
1987 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
1988 pos
= it
->current
.pos
;
1991 DEC_TEXT_POS (pos
, it
->multibyte_p
);
1994 if (it
->what
== IT_COMPOSITION
)
1995 /* For composition, we must check the position after the
1997 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
1999 INC_TEXT_POS (pos
, it
->multibyte_p
);
2001 /* Determine face for CHARSET_ASCII, or unibyte. */
2002 face_id
= face_at_buffer_position (it
->w
,
2004 it
->region_beg_charpos
,
2005 it
->region_end_charpos
,
2006 &next_check_charpos
,
2009 /* Correct the face for charsets different from ASCII. Do it
2010 for the multibyte case only. The face returned above is
2011 suitable for unibyte text if current_buffer is unibyte. */
2012 if (it
->multibyte_p
)
2014 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2015 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2016 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2025 /***********************************************************************
2027 ***********************************************************************/
2029 /* Set up iterator IT from invisible properties at its current
2030 position. Called from handle_stop. */
2032 static enum prop_handled
2033 handle_invisible_prop (it
)
2036 enum prop_handled handled
= HANDLED_NORMALLY
;
2038 if (STRINGP (it
->string
))
2040 extern Lisp_Object Qinvisible
;
2041 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2043 /* Get the value of the invisible text property at the
2044 current position. Value will be nil if there is no such
2046 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2047 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2050 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2052 handled
= HANDLED_RECOMPUTE_PROPS
;
2054 /* Get the position at which the next change of the
2055 invisible text property can be found in IT->string.
2056 Value will be nil if the property value is the same for
2057 all the rest of IT->string. */
2058 XSETINT (limit
, XSTRING (it
->string
)->size
);
2059 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2062 /* Text at current position is invisible. The next
2063 change in the property is at position end_charpos.
2064 Move IT's current position to that position. */
2065 if (INTEGERP (end_charpos
)
2066 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2068 struct text_pos old
;
2069 old
= it
->current
.string_pos
;
2070 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2071 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2075 /* The rest of the string is invisible. If this is an
2076 overlay string, proceed with the next overlay string
2077 or whatever comes and return a character from there. */
2078 if (it
->current
.overlay_string_index
>= 0)
2080 next_overlay_string (it
);
2081 /* Don't check for overlay strings when we just
2082 finished processing them. */
2083 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2087 struct Lisp_String
*s
= XSTRING (it
->string
);
2088 IT_STRING_CHARPOS (*it
) = s
->size
;
2089 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2096 int visible_p
, newpos
, next_stop
;
2097 Lisp_Object pos
, prop
;
2099 /* First of all, is there invisible text at this position? */
2100 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2101 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2103 /* If we are on invisible text, skip over it. */
2104 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2105 && IT_CHARPOS (*it
) < it
->end_charpos
)
2107 /* Record whether we have to display an ellipsis for the
2109 int display_ellipsis_p
2110 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2112 handled
= HANDLED_RECOMPUTE_PROPS
;
2114 /* Loop skipping over invisible text. The loop is left at
2115 ZV or with IT on the first char being visible again. */
2118 /* Try to skip some invisible text. Return value is the
2119 position reached which can be equal to IT's position
2120 if there is nothing invisible here. This skips both
2121 over invisible text properties and overlays with
2122 invisible property. */
2123 newpos
= skip_invisible (IT_CHARPOS (*it
),
2124 &next_stop
, ZV
, it
->window
);
2126 /* If we skipped nothing at all we weren't at invisible
2127 text in the first place. If everything to the end of
2128 the buffer was skipped, end the loop. */
2129 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2133 /* We skipped some characters but not necessarily
2134 all there are. Check if we ended up on visible
2135 text. Fget_char_property returns the property of
2136 the char before the given position, i.e. if we
2137 get visible_p = 1, this means that the char at
2138 newpos is visible. */
2139 XSETFASTINT (pos
, newpos
);
2140 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2141 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2144 /* If we ended up on invisible text, proceed to
2145 skip starting with next_stop. */
2147 IT_CHARPOS (*it
) = next_stop
;
2151 /* The position newpos is now either ZV or on visible text. */
2152 IT_CHARPOS (*it
) = newpos
;
2153 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2155 /* Maybe return `...' next for the end of the invisible text. */
2156 if (display_ellipsis_p
)
2159 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2161 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2162 it
->dpvec
= v
->contents
;
2163 it
->dpend
= v
->contents
+ v
->size
;
2167 /* Default `...'. */
2168 it
->dpvec
= default_invis_vector
;
2169 it
->dpend
= default_invis_vector
+ 3;
2172 /* The ellipsis display does not replace the display of
2173 the character at the new position. Indicate this by
2174 setting IT->dpvec_char_len to zero. */
2175 it
->dpvec_char_len
= 0;
2177 it
->current
.dpvec_index
= 0;
2178 it
->method
= next_element_from_display_vector
;
2188 /***********************************************************************
2190 ***********************************************************************/
2192 /* Set up iterator IT from `display' property at its current position.
2193 Called from handle_stop. */
2195 static enum prop_handled
2196 handle_display_prop (it
)
2199 Lisp_Object prop
, object
;
2200 struct text_pos
*position
;
2201 int space_or_image_found_p
;
2203 if (STRINGP (it
->string
))
2205 object
= it
->string
;
2206 position
= &it
->current
.string_pos
;
2211 position
= &it
->current
.pos
;
2214 /* Reset those iterator values set from display property values. */
2215 it
->font_height
= Qnil
;
2216 it
->space_width
= Qnil
;
2219 /* We don't support recursive `display' properties, i.e. string
2220 values that have a string `display' property, that have a string
2221 `display' property etc. */
2222 if (!it
->string_from_display_prop_p
)
2223 it
->area
= TEXT_AREA
;
2225 prop
= Fget_char_property (make_number (position
->charpos
),
2228 return HANDLED_NORMALLY
;
2230 space_or_image_found_p
= 0;
2232 && CONSP (XCAR (prop
))
2233 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2235 /* A list of sub-properties. */
2236 while (CONSP (prop
))
2238 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2239 space_or_image_found_p
= 1;
2243 else if (VECTORP (prop
))
2246 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2247 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2249 space_or_image_found_p
= 1;
2253 if (handle_single_display_prop (it
, prop
, object
, position
))
2254 space_or_image_found_p
= 1;
2257 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2261 /* Value is the position of the end of the `display' property starting
2262 at START_POS in OBJECT. */
2264 static struct text_pos
2265 display_prop_end (it
, object
, start_pos
)
2268 struct text_pos start_pos
;
2271 struct text_pos end_pos
;
2273 end
= next_single_char_property_change (make_number (CHARPOS (start_pos
)),
2274 Qdisplay
, object
, Qnil
);
2275 CHARPOS (end_pos
) = XFASTINT (end
);
2276 if (STRINGP (object
))
2277 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2279 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2285 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2286 is the object in which the `display' property was found. *POSITION
2287 is the position at which it was found.
2289 If PROP is a `space' or `image' sub-property, set *POSITION to the
2290 end position of the `display' property.
2292 Value is non-zero if a `space' or `image' property value was found. */
2295 handle_single_display_prop (it
, prop
, object
, position
)
2299 struct text_pos
*position
;
2302 int space_or_image_found_p
= 0;
2306 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2307 evaluated. If the result is nil, VALUE is ignored. */
2309 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2318 if (!NILP (form
) && !EQ (form
, Qt
))
2320 struct gcpro gcpro1
;
2321 struct text_pos end_pos
, pt
;
2324 end_pos
= display_prop_end (it
, object
, *position
);
2326 /* Temporarily set point to the end position, and then evaluate
2327 the form. This makes `(eolp)' work as FORM. */
2328 if (BUFFERP (object
))
2331 BYTEPOS (pt
) = PT_BYTE
;
2332 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2335 form
= eval_form (form
);
2337 if (BUFFERP (object
))
2338 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2346 && EQ (XCAR (prop
), Qheight
)
2347 && CONSP (XCDR (prop
)))
2349 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2352 /* `(height HEIGHT)'. */
2353 it
->font_height
= XCAR (XCDR (prop
));
2354 if (!NILP (it
->font_height
))
2356 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2357 int new_height
= -1;
2359 if (CONSP (it
->font_height
)
2360 && (EQ (XCAR (it
->font_height
), Qplus
)
2361 || EQ (XCAR (it
->font_height
), Qminus
))
2362 && CONSP (XCDR (it
->font_height
))
2363 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2365 /* `(+ N)' or `(- N)' where N is an integer. */
2366 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2367 if (EQ (XCAR (it
->font_height
), Qplus
))
2369 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2371 else if (SYMBOLP (it
->font_height
))
2373 /* Call function with current height as argument.
2374 Value is the new height. */
2375 Lisp_Object form
, height
;
2376 struct gcpro gcpro1
;
2378 height
= face
->lface
[LFACE_HEIGHT_INDEX
];
2379 form
= Fcons (it
->font_height
, Fcons (height
, Qnil
));
2381 height
= eval_form (form
);
2382 if (NUMBERP (height
))
2383 new_height
= XFLOATINT (height
);
2386 else if (NUMBERP (it
->font_height
))
2388 /* Value is a multiple of the canonical char height. */
2391 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2392 new_height
= (XFLOATINT (it
->font_height
)
2393 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2397 /* Evaluate IT->font_height with `height' bound to the
2398 current specified height to get the new height. */
2400 int count
= specpdl_ptr
- specpdl
;
2402 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2403 value
= eval_form (it
->font_height
);
2404 unbind_to (count
, Qnil
);
2406 if (NUMBERP (value
))
2407 new_height
= XFLOATINT (value
);
2411 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2414 else if (CONSP (prop
)
2415 && EQ (XCAR (prop
), Qspace_width
)
2416 && CONSP (XCDR (prop
)))
2418 /* `(space_width WIDTH)'. */
2419 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2422 value
= XCAR (XCDR (prop
));
2423 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2424 it
->space_width
= value
;
2426 else if (CONSP (prop
)
2427 && EQ (XCAR (prop
), Qraise
)
2428 && CONSP (XCDR (prop
)))
2430 /* `(raise FACTOR)'. */
2431 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2434 #ifdef HAVE_WINDOW_SYSTEM
2435 value
= XCAR (XCDR (prop
));
2436 if (NUMBERP (value
))
2438 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2439 it
->voffset
= - (XFLOATINT (value
)
2440 * (FONT_HEIGHT (face
->font
)));
2442 #endif /* HAVE_WINDOW_SYSTEM */
2444 else if (!it
->string_from_display_prop_p
)
2446 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2447 VALUE) or `((margin nil) VALUE)' or VALUE. */
2448 Lisp_Object location
, value
;
2449 struct text_pos start_pos
;
2452 /* Characters having this form of property are not displayed, so
2453 we have to find the end of the property. */
2454 start_pos
= *position
;
2455 *position
= display_prop_end (it
, object
, start_pos
);
2458 /* Let's stop at the new position and assume that all
2459 text properties change there. */
2460 it
->stop_charpos
= position
->charpos
;
2462 location
= Qunbound
;
2463 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2467 value
= XCDR (prop
);
2469 value
= XCAR (value
);
2472 if (EQ (XCAR (tem
), Qmargin
)
2473 && (tem
= XCDR (tem
),
2474 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2476 || EQ (tem
, Qleft_margin
)
2477 || EQ (tem
, Qright_margin
))))
2481 if (EQ (location
, Qunbound
))
2487 #ifdef HAVE_WINDOW_SYSTEM
2488 if (FRAME_TERMCAP_P (it
->f
))
2489 valid_p
= STRINGP (value
);
2491 valid_p
= (STRINGP (value
)
2492 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2493 || valid_image_p (value
));
2494 #else /* not HAVE_WINDOW_SYSTEM */
2495 valid_p
= STRINGP (value
);
2496 #endif /* not HAVE_WINDOW_SYSTEM */
2498 if ((EQ (location
, Qleft_margin
)
2499 || EQ (location
, Qright_margin
)
2503 space_or_image_found_p
= 1;
2505 /* Save current settings of IT so that we can restore them
2506 when we are finished with the glyph property value. */
2509 if (NILP (location
))
2510 it
->area
= TEXT_AREA
;
2511 else if (EQ (location
, Qleft_margin
))
2512 it
->area
= LEFT_MARGIN_AREA
;
2514 it
->area
= RIGHT_MARGIN_AREA
;
2516 if (STRINGP (value
))
2519 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2520 it
->current
.overlay_string_index
= -1;
2521 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2522 it
->end_charpos
= it
->string_nchars
2523 = XSTRING (it
->string
)->size
;
2524 it
->method
= next_element_from_string
;
2525 it
->stop_charpos
= 0;
2526 it
->string_from_display_prop_p
= 1;
2528 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2530 it
->method
= next_element_from_stretch
;
2532 it
->current
.pos
= it
->position
= start_pos
;
2534 #ifdef HAVE_WINDOW_SYSTEM
2537 it
->what
= IT_IMAGE
;
2538 it
->image_id
= lookup_image (it
->f
, value
);
2539 it
->position
= start_pos
;
2540 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2541 it
->method
= next_element_from_image
;
2543 /* Say that we haven't consumed the characters with
2544 `display' property yet. The call to pop_it in
2545 set_iterator_to_next will clean this up. */
2546 *position
= start_pos
;
2548 #endif /* HAVE_WINDOW_SYSTEM */
2551 /* Invalid property or property not supported. Restore
2552 the position to what it was before. */
2553 *position
= start_pos
;
2556 return space_or_image_found_p
;
2561 /***********************************************************************
2562 `composition' property
2563 ***********************************************************************/
2565 /* Set up iterator IT from `composition' property at its current
2566 position. Called from handle_stop. */
2568 static enum prop_handled
2569 handle_composition_prop (it
)
2572 Lisp_Object prop
, string
;
2573 int pos
, pos_byte
, end
;
2574 enum prop_handled handled
= HANDLED_NORMALLY
;
2576 if (STRINGP (it
->string
))
2578 pos
= IT_STRING_CHARPOS (*it
);
2579 pos_byte
= IT_STRING_BYTEPOS (*it
);
2580 string
= it
->string
;
2584 pos
= IT_CHARPOS (*it
);
2585 pos_byte
= IT_BYTEPOS (*it
);
2589 /* If there's a valid composition and point is not inside of the
2590 composition (in the case that the composition is from the current
2591 buffer), draw a glyph composed from the composition components. */
2592 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
2593 && COMPOSITION_VALID_P (pos
, end
, prop
)
2594 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
2596 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
2600 it
->method
= next_element_from_composition
;
2602 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
2603 /* For a terminal, draw only the first character of the
2605 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
2606 it
->len
= (STRINGP (it
->string
)
2607 ? string_char_to_byte (it
->string
, end
)
2608 : CHAR_TO_BYTE (end
)) - pos_byte
;
2609 it
->stop_charpos
= end
;
2610 handled
= HANDLED_RETURN
;
2619 /***********************************************************************
2621 ***********************************************************************/
2623 /* The following structure is used to record overlay strings for
2624 later sorting in load_overlay_strings. */
2626 struct overlay_entry
2634 /* Set up iterator IT from overlay strings at its current position.
2635 Called from handle_stop. */
2637 static enum prop_handled
2638 handle_overlay_change (it
)
2641 /* Overlays are handled in current_buffer only. */
2642 if (STRINGP (it
->string
))
2643 return HANDLED_NORMALLY
;
2645 return (get_overlay_strings (it
)
2646 ? HANDLED_RECOMPUTE_PROPS
2647 : HANDLED_NORMALLY
);
2651 /* Set up the next overlay string for delivery by IT, if there is an
2652 overlay string to deliver. Called by set_iterator_to_next when the
2653 end of the current overlay string is reached. If there are more
2654 overlay strings to display, IT->string and
2655 IT->current.overlay_string_index are set appropriately here.
2656 Otherwise IT->string is set to nil. */
2659 next_overlay_string (it
)
2662 ++it
->current
.overlay_string_index
;
2663 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2665 /* No more overlay strings. Restore IT's settings to what
2666 they were before overlay strings were processed, and
2667 continue to deliver from current_buffer. */
2669 xassert (it
->stop_charpos
>= BEGV
2670 && it
->stop_charpos
<= it
->end_charpos
);
2672 it
->current
.overlay_string_index
= -1;
2673 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2674 it
->n_overlay_strings
= 0;
2675 it
->method
= next_element_from_buffer
;
2679 /* There are more overlay strings to process. If
2680 IT->current.overlay_string_index has advanced to a position
2681 where we must load IT->overlay_strings with more strings, do
2683 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2685 if (it
->current
.overlay_string_index
&& i
== 0)
2686 load_overlay_strings (it
);
2688 /* Initialize IT to deliver display elements from the overlay
2690 it
->string
= it
->overlay_strings
[i
];
2691 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2692 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2693 it
->method
= next_element_from_string
;
2694 it
->stop_charpos
= 0;
2701 /* Compare two overlay_entry structures E1 and E2. Used as a
2702 comparison function for qsort in load_overlay_strings. Overlay
2703 strings for the same position are sorted so that
2705 1. All after-strings come in front of before-strings.
2707 2. Within after-strings, strings are sorted so that overlay strings
2708 from overlays with higher priorities come first.
2710 2. Within before-strings, strings are sorted so that overlay
2711 strings from overlays with higher priorities come last.
2713 Value is analogous to strcmp. */
2717 compare_overlay_entries (e1
, e2
)
2720 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
2721 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
2724 if (entry1
->after_string_p
!= entry2
->after_string_p
)
2725 /* Let after-strings appear in front of before-strings. */
2726 result
= entry1
->after_string_p
? -1 : 1;
2727 else if (entry1
->after_string_p
)
2728 /* After-strings sorted in order of decreasing priority. */
2729 result
= entry2
->priority
- entry1
->priority
;
2731 /* Before-strings sorted in order of increasing priority. */
2732 result
= entry1
->priority
- entry2
->priority
;
2738 /* Load the vector IT->overlay_strings with overlay strings from IT's
2739 current buffer position. Set IT->n_overlays to the total number of
2740 overlay strings found.
2742 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
2743 a time. On entry into load_overlay_strings,
2744 IT->current.overlay_string_index gives the number of overlay
2745 strings that have already been loaded by previous calls to this
2748 Overlay strings are sorted so that after-string strings come in
2749 front of before-string strings. Within before and after-strings,
2750 strings are sorted by overlay priority. See also function
2751 compare_overlay_entries. */
2754 load_overlay_strings (it
)
2757 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
2758 Lisp_Object ov
, overlay
, window
, str
;
2762 struct overlay_entry
*entries
2763 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
2765 /* Append the overlay string STRING of overlay OVERLAY to vector
2766 `entries' which has size `size' and currently contains `n'
2767 elements. AFTER_P non-zero means STRING is an after-string of
2769 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
2772 Lisp_Object priority; \
2776 int new_size = 2 * size; \
2777 struct overlay_entry *old = entries; \
2779 (struct overlay_entry *) alloca (new_size \
2780 * sizeof *entries); \
2781 bcopy (old, entries, size * sizeof *entries); \
2785 entries[n].string = (STRING); \
2786 priority = Foverlay_get ((OVERLAY), Qpriority); \
2787 entries[n].priority \
2788 = INTEGERP (priority) ? XFASTINT (priority) : 0; \
2789 entries[n].after_string_p = (AFTER_P); \
2794 /* Process overlay before the overlay center. */
2795 for (ov
= current_buffer
->overlays_before
;
2799 overlay
= XCAR (ov
);
2800 xassert (OVERLAYP (overlay
));
2801 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2802 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2804 if (end
< IT_CHARPOS (*it
))
2807 /* Skip this overlay if it doesn't start or end at IT's current
2809 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2812 /* Skip this overlay if it doesn't apply to IT->w. */
2813 window
= Foverlay_get (overlay
, Qwindow
);
2814 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2817 /* If overlay has a non-empty before-string, record it. */
2818 if (start
== IT_CHARPOS (*it
)
2819 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2820 && XSTRING (str
)->size
)
2821 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2823 /* If overlay has a non-empty after-string, record it. */
2824 if (end
== IT_CHARPOS (*it
)
2825 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2826 && XSTRING (str
)->size
)
2827 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2830 /* Process overlays after the overlay center. */
2831 for (ov
= current_buffer
->overlays_after
;
2835 overlay
= XCAR (ov
);
2836 xassert (OVERLAYP (overlay
));
2837 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2838 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2840 if (start
> IT_CHARPOS (*it
))
2843 /* Skip this overlay if it doesn't start or end at IT's current
2845 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2848 /* Skip this overlay if it doesn't apply to IT->w. */
2849 window
= Foverlay_get (overlay
, Qwindow
);
2850 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2853 /* If overlay has a non-empty before-string, record it. */
2854 if (start
== IT_CHARPOS (*it
)
2855 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2856 && XSTRING (str
)->size
)
2857 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2859 /* If overlay has a non-empty after-string, record it. */
2860 if (end
== IT_CHARPOS (*it
)
2861 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2862 && XSTRING (str
)->size
)
2863 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2866 #undef RECORD_OVERLAY_STRING
2869 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
2871 /* Record the total number of strings to process. */
2872 it
->n_overlay_strings
= n
;
2874 /* IT->current.overlay_string_index is the number of overlay strings
2875 that have already been consumed by IT. Copy some of the
2876 remaining overlay strings to IT->overlay_strings. */
2878 j
= it
->current
.overlay_string_index
;
2879 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
2880 it
->overlay_strings
[i
++] = entries
[j
++].string
;
2886 /* Get the first chunk of overlay strings at IT's current buffer
2887 position. Value is non-zero if at least one overlay string was
2891 get_overlay_strings (it
)
2894 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
2895 process. This fills IT->overlay_strings with strings, and sets
2896 IT->n_overlay_strings to the total number of strings to process.
2897 IT->pos.overlay_string_index has to be set temporarily to zero
2898 because load_overlay_strings needs this; it must be set to -1
2899 when no overlay strings are found because a zero value would
2900 indicate a position in the first overlay string. */
2901 it
->current
.overlay_string_index
= 0;
2902 load_overlay_strings (it
);
2904 /* If we found overlay strings, set up IT to deliver display
2905 elements from the first one. Otherwise set up IT to deliver
2906 from current_buffer. */
2907 if (it
->n_overlay_strings
)
2909 /* Make sure we know settings in current_buffer, so that we can
2910 restore meaningful values when we're done with the overlay
2912 compute_stop_pos (it
);
2913 xassert (it
->face_id
>= 0);
2915 /* Save IT's settings. They are restored after all overlay
2916 strings have been processed. */
2917 xassert (it
->sp
== 0);
2920 /* Set up IT to deliver display elements from the first overlay
2922 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2923 it
->stop_charpos
= 0;
2924 it
->string
= it
->overlay_strings
[0];
2925 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2926 xassert (STRINGP (it
->string
));
2927 it
->method
= next_element_from_string
;
2932 it
->current
.overlay_string_index
= -1;
2933 it
->method
= next_element_from_buffer
;
2938 /* Value is non-zero if we found at least one overlay string. */
2939 return STRINGP (it
->string
);
2944 /***********************************************************************
2945 Saving and restoring state
2946 ***********************************************************************/
2948 /* Save current settings of IT on IT->stack. Called, for example,
2949 before setting up IT for an overlay string, to be able to restore
2950 IT's settings to what they were after the overlay string has been
2957 struct iterator_stack_entry
*p
;
2959 xassert (it
->sp
< 2);
2960 p
= it
->stack
+ it
->sp
;
2962 p
->stop_charpos
= it
->stop_charpos
;
2963 xassert (it
->face_id
>= 0);
2964 p
->face_id
= it
->face_id
;
2965 p
->string
= it
->string
;
2966 p
->pos
= it
->current
;
2967 p
->end_charpos
= it
->end_charpos
;
2968 p
->string_nchars
= it
->string_nchars
;
2970 p
->multibyte_p
= it
->multibyte_p
;
2971 p
->space_width
= it
->space_width
;
2972 p
->font_height
= it
->font_height
;
2973 p
->voffset
= it
->voffset
;
2974 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
2979 /* Restore IT's settings from IT->stack. Called, for example, when no
2980 more overlay strings must be processed, and we return to delivering
2981 display elements from a buffer, or when the end of a string from a
2982 `display' property is reached and we return to delivering display
2983 elements from an overlay string, or from a buffer. */
2989 struct iterator_stack_entry
*p
;
2991 xassert (it
->sp
> 0);
2993 p
= it
->stack
+ it
->sp
;
2994 it
->stop_charpos
= p
->stop_charpos
;
2995 it
->face_id
= p
->face_id
;
2996 it
->string
= p
->string
;
2997 it
->current
= p
->pos
;
2998 it
->end_charpos
= p
->end_charpos
;
2999 it
->string_nchars
= p
->string_nchars
;
3001 it
->multibyte_p
= p
->multibyte_p
;
3002 it
->space_width
= p
->space_width
;
3003 it
->font_height
= p
->font_height
;
3004 it
->voffset
= p
->voffset
;
3005 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3010 /***********************************************************************
3012 ***********************************************************************/
3014 /* Set IT's current position to the previous line start. */
3017 back_to_previous_line_start (it
)
3020 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3021 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3025 /* Set IT's current position to the next line start. */
3028 forward_to_next_line_start (it
)
3031 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), 1);
3032 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3036 /* Set IT's current position to the previous visible line start. Skip
3037 invisible text that is so either due to text properties or due to
3038 selective display. Caution: this does not change IT->current_x and
3042 back_to_previous_visible_line_start (it
)
3047 /* Go back one newline if not on BEGV already. */
3048 if (IT_CHARPOS (*it
) > BEGV
)
3049 back_to_previous_line_start (it
);
3051 /* Move over lines that are invisible because of selective display
3052 or text properties. */
3053 while (IT_CHARPOS (*it
) > BEGV
3058 /* If selective > 0, then lines indented more than that values
3060 if (it
->selective
> 0
3061 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3068 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3069 Qinvisible
, it
->window
);
3070 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3074 /* Back one more newline if the current one is invisible. */
3076 back_to_previous_line_start (it
);
3079 xassert (IT_CHARPOS (*it
) >= BEGV
);
3080 xassert (IT_CHARPOS (*it
) == BEGV
3081 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3086 /* Reseat iterator IT at the previous visible line start. Skip
3087 invisible text that is so either due to text properties or due to
3088 selective display. At the end, update IT's overlay information,
3089 face information etc. */
3092 reseat_at_previous_visible_line_start (it
)
3095 back_to_previous_visible_line_start (it
);
3096 reseat (it
, it
->current
.pos
, 1);
3101 /* Reseat iterator IT on the next visible line start in the current
3102 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3103 preceding the line start. Skip over invisible text that is so
3104 because of selective display. Compute faces, overlays etc at the
3105 new position. Note that this function does not skip over text that
3106 is invisible because of text properties. */
3109 reseat_at_next_visible_line_start (it
, on_newline_p
)
3113 /* Restore the buffer position when currently not delivering display
3114 elements from the current buffer. This is the case, for example,
3115 when called at the end of a truncated overlay string. */
3118 it
->method
= next_element_from_buffer
;
3120 /* Otherwise, scan_buffer would not work. */
3121 if (IT_CHARPOS (*it
) < ZV
)
3123 /* If on a newline, advance past it. Otherwise, find the next
3124 newline which automatically gives us the position following
3126 if (FETCH_BYTE (IT_BYTEPOS (*it
)) == '\n')
3132 forward_to_next_line_start (it
);
3134 /* We must either have reached the end of the buffer or end up
3136 xassert (IT_CHARPOS (*it
) == ZV
3137 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3139 /* Skip over lines that are invisible because they are indented
3140 more than the value of IT->selective. */
3141 if (it
->selective
> 0)
3142 while (IT_CHARPOS (*it
) < ZV
3143 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3145 forward_to_next_line_start (it
);
3147 /* Position on the newline if we should. */
3149 && IT_CHARPOS (*it
) > BEGV
3150 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n')
3153 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3156 /* Set the iterator there. The 0 as the last parameter of
3157 reseat means don't force a text property lookup. The lookup
3158 is then only done if we've skipped past the iterator's
3159 check_charpos'es. This optimization is important because
3160 text property lookups tend to be expensive. */
3161 reseat (it
, it
->current
.pos
, 0);
3169 /***********************************************************************
3170 Changing an iterator's position
3171 ***********************************************************************/
3173 /* Change IT's current position to POS in current_buffer. If FORCE_P
3174 is non-zero, always check for text properties at the new position.
3175 Otherwise, text properties are only looked up if POS >=
3176 IT->check_charpos of a property. */
3179 reseat (it
, pos
, force_p
)
3181 struct text_pos pos
;
3184 int original_pos
= IT_CHARPOS (*it
);
3186 reseat_1 (it
, pos
, 0);
3188 /* Determine where to check text properties. Avoid doing it
3189 where possible because text property lookup is very expensive. */
3191 || CHARPOS (pos
) > it
->stop_charpos
3192 || CHARPOS (pos
) < original_pos
)
3199 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3200 IT->stop_pos to POS, also. */
3203 reseat_1 (it
, pos
, set_stop_p
)
3205 struct text_pos pos
;
3208 /* Don't call this function when scanning a C string. */
3209 xassert (it
->s
== NULL
);
3211 /* POS must be a reasonable value. */
3212 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3214 it
->current
.pos
= it
->position
= pos
;
3215 XSETBUFFER (it
->object
, current_buffer
);
3217 it
->current
.dpvec_index
= -1;
3218 it
->current
.overlay_string_index
= -1;
3219 IT_STRING_CHARPOS (*it
) = -1;
3220 IT_STRING_BYTEPOS (*it
) = -1;
3222 it
->method
= next_element_from_buffer
;
3226 it
->stop_charpos
= CHARPOS (pos
);
3230 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3231 If S is non-null, it is a C string to iterate over. Otherwise,
3232 STRING gives a Lisp string to iterate over.
3234 If PRECISION > 0, don't return more then PRECISION number of
3235 characters from the string.
3237 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3238 characters have been returned. FIELD_WIDTH < 0 means an infinite
3241 MULTIBYTE = 0 means disable processing of multibyte characters,
3242 MULTIBYTE > 0 means enable it,
3243 MULTIBYTE < 0 means use IT->multibyte_p.
3245 IT must be initialized via a prior call to init_iterator before
3246 calling this function. */
3249 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3254 int precision
, field_width
, multibyte
;
3256 /* No region in strings. */
3257 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3259 /* No text property checks performed by default, but see below. */
3260 it
->stop_charpos
= -1;
3262 /* Set iterator position and end position. */
3263 bzero (&it
->current
, sizeof it
->current
);
3264 it
->current
.overlay_string_index
= -1;
3265 it
->current
.dpvec_index
= -1;
3266 xassert (charpos
>= 0);
3268 /* Use the setting of MULTIBYTE if specified. */
3270 it
->multibyte_p
= multibyte
> 0;
3274 xassert (STRINGP (string
));
3275 it
->string
= string
;
3277 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3278 it
->method
= next_element_from_string
;
3279 it
->current
.string_pos
= string_pos (charpos
, string
);
3286 /* Note that we use IT->current.pos, not it->current.string_pos,
3287 for displaying C strings. */
3288 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3289 if (it
->multibyte_p
)
3291 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3292 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3296 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3297 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3300 it
->method
= next_element_from_c_string
;
3303 /* PRECISION > 0 means don't return more than PRECISION characters
3305 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3306 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3308 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3309 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3310 FIELD_WIDTH < 0 means infinite field width. This is useful for
3311 padding with `-' at the end of a mode line. */
3312 if (field_width
< 0)
3313 field_width
= INFINITY
;
3314 if (field_width
> it
->end_charpos
- charpos
)
3315 it
->end_charpos
= charpos
+ field_width
;
3317 /* Use the standard display table for displaying strings. */
3318 if (DISP_TABLE_P (Vstandard_display_table
))
3319 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3321 it
->stop_charpos
= charpos
;
3327 /***********************************************************************
3329 ***********************************************************************/
3331 /* Load IT's display element fields with information about the next
3332 display element from the current position of IT. Value is zero if
3333 end of buffer (or C string) is reached. */
3336 get_next_display_element (it
)
3339 /* Non-zero means that we found an display element. Zero means that
3340 we hit the end of what we iterate over. Performance note: the
3341 function pointer `method' used here turns out to be faster than
3342 using a sequence of if-statements. */
3343 int success_p
= (*it
->method
) (it
);
3345 if (it
->what
== IT_CHARACTER
)
3347 /* Map via display table or translate control characters.
3348 IT->c, IT->len etc. have been set to the next character by
3349 the function call above. If we have a display table, and it
3350 contains an entry for IT->c, translate it. Don't do this if
3351 IT->c itself comes from a display table, otherwise we could
3352 end up in an infinite recursion. (An alternative could be to
3353 count the recursion depth of this function and signal an
3354 error when a certain maximum depth is reached.) Is it worth
3356 if (success_p
&& it
->dpvec
== NULL
)
3361 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3364 struct Lisp_Vector
*v
= XVECTOR (dv
);
3366 /* Return the first character from the display table
3367 entry, if not empty. If empty, don't display the
3368 current character. */
3371 it
->dpvec_char_len
= it
->len
;
3372 it
->dpvec
= v
->contents
;
3373 it
->dpend
= v
->contents
+ v
->size
;
3374 it
->current
.dpvec_index
= 0;
3375 it
->method
= next_element_from_display_vector
;
3378 success_p
= get_next_display_element (it
);
3381 /* Translate control characters into `\003' or `^C' form.
3382 Control characters coming from a display table entry are
3383 currently not translated because we use IT->dpvec to hold
3384 the translation. This could easily be changed but I
3385 don't believe that it is worth doing.
3387 Non-printable multibyte characters are also translated
3389 else if ((it
->c
< ' '
3390 && (it
->area
!= TEXT_AREA
3391 || (it
->c
!= '\n' && it
->c
!= '\t')))
3394 || !CHAR_PRINTABLE_P (it
->c
))
3396 /* IT->c is a control character which must be displayed
3397 either as '\003' or as `^C' where the '\\' and '^'
3398 can be defined in the display table. Fill
3399 IT->ctl_chars with glyphs for what we have to
3400 display. Then, set IT->dpvec to these glyphs. */
3403 if (it
->c
< 128 && it
->ctl_arrow_p
)
3405 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3407 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3408 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3409 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3411 g
= FAST_MAKE_GLYPH ('^', 0);
3412 XSETINT (it
->ctl_chars
[0], g
);
3414 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3415 XSETINT (it
->ctl_chars
[1], g
);
3417 /* Set up IT->dpvec and return first character from it. */
3418 it
->dpvec_char_len
= it
->len
;
3419 it
->dpvec
= it
->ctl_chars
;
3420 it
->dpend
= it
->dpvec
+ 2;
3421 it
->current
.dpvec_index
= 0;
3422 it
->method
= next_element_from_display_vector
;
3423 get_next_display_element (it
);
3427 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
3432 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3434 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3435 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3436 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3438 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
3440 if (SINGLE_BYTE_CHAR_P (it
->c
))
3441 str
[0] = it
->c
, len
= 1;
3443 len
= CHAR_STRING (it
->c
, str
);
3445 for (i
= 0; i
< len
; i
++)
3447 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
3448 /* Insert three more glyphs into IT->ctl_chars for
3449 the octal display of the character. */
3450 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
3451 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
3452 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
3453 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
3454 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
3455 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
3458 /* Set up IT->dpvec and return the first character
3460 it
->dpvec_char_len
= it
->len
;
3461 it
->dpvec
= it
->ctl_chars
;
3462 it
->dpend
= it
->dpvec
+ len
* 4;
3463 it
->current
.dpvec_index
= 0;
3464 it
->method
= next_element_from_display_vector
;
3465 get_next_display_element (it
);
3470 /* Adjust face id for a multibyte character. There are no
3471 multibyte character in unibyte text. */
3474 && FRAME_WINDOW_P (it
->f
))
3476 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3477 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
3481 /* Is this character the last one of a run of characters with
3482 box? If yes, set IT->end_of_box_run_p to 1. */
3489 it
->end_of_box_run_p
3490 = ((face_id
= face_after_it_pos (it
),
3491 face_id
!= it
->face_id
)
3492 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3493 face
->box
== FACE_NO_BOX
));
3496 /* Value is 0 if end of buffer or string reached. */
3501 /* Move IT to the next display element.
3503 Functions get_next_display_element and set_iterator_to_next are
3504 separate because I find this arrangement easier to handle than a
3505 get_next_display_element function that also increments IT's
3506 position. The way it is we can first look at an iterator's current
3507 display element, decide whether it fits on a line, and if it does,
3508 increment the iterator position. The other way around we probably
3509 would either need a flag indicating whether the iterator has to be
3510 incremented the next time, or we would have to implement a
3511 decrement position function which would not be easy to write. */
3514 set_iterator_to_next (it
)
3517 if (it
->method
== next_element_from_buffer
)
3519 /* The current display element of IT is a character from
3520 current_buffer. Advance in the buffer, and maybe skip over
3521 invisible lines that are so because of selective display. */
3522 if (ITERATOR_AT_END_OF_LINE_P (it
))
3523 reseat_at_next_visible_line_start (it
, 0);
3526 xassert (it
->len
!= 0);
3527 IT_BYTEPOS (*it
) += it
->len
;
3528 IT_CHARPOS (*it
) += 1;
3529 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3532 else if (it
->method
== next_element_from_composition
)
3534 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
3535 if (STRINGP (it
->string
))
3537 IT_STRING_BYTEPOS (*it
) += it
->len
;
3538 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
3539 it
->method
= next_element_from_string
;
3540 goto consider_string_end
;
3544 IT_BYTEPOS (*it
) += it
->len
;
3545 IT_CHARPOS (*it
) += it
->cmp_len
;
3546 it
->method
= next_element_from_buffer
;
3549 else if (it
->method
== next_element_from_c_string
)
3551 /* Current display element of IT is from a C string. */
3552 IT_BYTEPOS (*it
) += it
->len
;
3553 IT_CHARPOS (*it
) += 1;
3555 else if (it
->method
== next_element_from_display_vector
)
3557 /* Current display element of IT is from a display table entry.
3558 Advance in the display table definition. Reset it to null if
3559 end reached, and continue with characters from buffers/
3561 ++it
->current
.dpvec_index
;
3563 /* Restore face of the iterator to what they were before the
3564 display vector entry (these entries may contain faces). */
3565 it
->face_id
= it
->saved_face_id
;
3567 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3570 it
->method
= next_element_from_c_string
;
3571 else if (STRINGP (it
->string
))
3572 it
->method
= next_element_from_string
;
3574 it
->method
= next_element_from_buffer
;
3577 it
->current
.dpvec_index
= -1;
3579 /* Skip over characters which were displayed via IT->dpvec. */
3580 if (it
->dpvec_char_len
< 0)
3581 reseat_at_next_visible_line_start (it
, 1);
3582 else if (it
->dpvec_char_len
> 0)
3584 it
->len
= it
->dpvec_char_len
;
3585 set_iterator_to_next (it
);
3589 else if (it
->method
== next_element_from_string
)
3591 /* Current display element is a character from a Lisp string. */
3592 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3593 IT_STRING_BYTEPOS (*it
) += it
->len
;
3594 IT_STRING_CHARPOS (*it
) += 1;
3596 consider_string_end
:
3598 if (it
->current
.overlay_string_index
>= 0)
3600 /* IT->string is an overlay string. Advance to the
3601 next, if there is one. */
3602 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3603 next_overlay_string (it
);
3607 /* IT->string is not an overlay string. If we reached
3608 its end, and there is something on IT->stack, proceed
3609 with what is on the stack. This can be either another
3610 string, this time an overlay string, or a buffer. */
3611 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3615 if (!STRINGP (it
->string
))
3616 it
->method
= next_element_from_buffer
;
3620 else if (it
->method
== next_element_from_image
3621 || it
->method
== next_element_from_stretch
)
3623 /* The position etc with which we have to proceed are on
3624 the stack. The position may be at the end of a string,
3625 if the `display' property takes up the whole string. */
3628 if (STRINGP (it
->string
))
3630 it
->method
= next_element_from_string
;
3631 goto consider_string_end
;
3634 it
->method
= next_element_from_buffer
;
3637 /* There are no other methods defined, so this should be a bug. */
3640 /* Reset flags indicating start and end of a sequence of
3641 characters with box. */
3642 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3644 xassert (it
->method
!= next_element_from_string
3645 || (STRINGP (it
->string
)
3646 && IT_STRING_CHARPOS (*it
) >= 0));
3650 /* Load IT's display element fields with information about the next
3651 display element which comes from a display table entry or from the
3652 result of translating a control character to one of the forms `^C'
3653 or `\003'. IT->dpvec holds the glyphs to return as characters. */
3656 next_element_from_display_vector (it
)
3660 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
3662 /* Remember the current face id in case glyphs specify faces.
3663 IT's face is restored in set_iterator_to_next. */
3664 it
->saved_face_id
= it
->face_id
;
3666 if (INTEGERP (*it
->dpvec
)
3667 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
3672 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
3673 it
->c
= FAST_GLYPH_CHAR (g
);
3674 it
->len
= CHAR_BYTES (it
->c
);
3676 /* The entry may contain a face id to use. Such a face id is
3677 the id of a Lisp face, not a realized face. A face id of
3678 zero means no face. */
3679 lface_id
= FAST_GLYPH_FACE (g
);
3682 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
3685 it
->face_id
= face_id
;
3690 /* Display table entry is invalid. Return a space. */
3691 it
->c
= ' ', it
->len
= 1;
3693 /* Don't change position and object of the iterator here. They are
3694 still the values of the character that had this display table
3695 entry or was translated, and that's what we want. */
3696 it
->what
= IT_CHARACTER
;
3701 /* Load IT with the next display element from Lisp string IT->string.
3702 IT->current.string_pos is the current position within the string.
3703 If IT->current.overlay_string_index >= 0, the Lisp string is an
3707 next_element_from_string (it
)
3710 struct text_pos position
;
3712 xassert (STRINGP (it
->string
));
3713 xassert (IT_STRING_CHARPOS (*it
) >= 0);
3714 position
= it
->current
.string_pos
;
3716 /* Time to check for invisible text? */
3717 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
3718 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
3722 /* Since a handler may have changed IT->method, we must
3724 return get_next_display_element (it
);
3727 if (it
->current
.overlay_string_index
>= 0)
3729 /* Get the next character from an overlay string. In overlay
3730 strings, There is no field width or padding with spaces to
3732 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3737 else if (STRING_MULTIBYTE (it
->string
))
3739 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
3740 - IT_STRING_BYTEPOS (*it
));
3741 unsigned char *s
= (XSTRING (it
->string
)->data
3742 + IT_STRING_BYTEPOS (*it
));
3743 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
3747 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3753 /* Get the next character from a Lisp string that is not an
3754 overlay string. Such strings come from the mode line, for
3755 example. We may have to pad with spaces, or truncate the
3756 string. See also next_element_from_c_string. */
3757 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
3762 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
3764 /* Pad with spaces. */
3765 it
->c
= ' ', it
->len
= 1;
3766 CHARPOS (position
) = BYTEPOS (position
) = -1;
3768 else if (STRING_MULTIBYTE (it
->string
))
3770 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
3771 - IT_STRING_BYTEPOS (*it
));
3772 unsigned char *s
= (XSTRING (it
->string
)->data
3773 + IT_STRING_BYTEPOS (*it
));
3774 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
3778 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3783 /* Record what we have and where it came from. Note that we store a
3784 buffer position in IT->position although it could arguably be a
3786 it
->what
= IT_CHARACTER
;
3787 it
->object
= it
->string
;
3788 it
->position
= position
;
3793 /* Load IT with next display element from C string IT->s.
3794 IT->string_nchars is the maximum number of characters to return
3795 from the string. IT->end_charpos may be greater than
3796 IT->string_nchars when this function is called, in which case we
3797 may have to return padding spaces. Value is zero if end of string
3798 reached, including padding spaces. */
3801 next_element_from_c_string (it
)
3807 it
->what
= IT_CHARACTER
;
3808 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
3811 /* IT's position can be greater IT->string_nchars in case a field
3812 width or precision has been specified when the iterator was
3814 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3816 /* End of the game. */
3820 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
3822 /* Pad with spaces. */
3823 it
->c
= ' ', it
->len
= 1;
3824 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
3826 else if (it
->multibyte_p
)
3828 /* Implementation note: The calls to strlen apparently aren't a
3829 performance problem because there is no noticeable performance
3830 difference between Emacs running in unibyte or multibyte mode. */
3831 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
3832 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
3836 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
3842 /* Set up IT to return characters from an ellipsis, if appropriate.
3843 The definition of the ellipsis glyphs may come from a display table
3844 entry. This function Fills IT with the first glyph from the
3845 ellipsis if an ellipsis is to be displayed. */
3848 next_element_from_ellipsis (it
)
3851 if (it
->selective_display_ellipsis_p
)
3853 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3855 /* Use the display table definition for `...'. Invalid glyphs
3856 will be handled by the method returning elements from dpvec. */
3857 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3858 it
->dpvec_char_len
= it
->len
;
3859 it
->dpvec
= v
->contents
;
3860 it
->dpend
= v
->contents
+ v
->size
;
3861 it
->current
.dpvec_index
= 0;
3862 it
->method
= next_element_from_display_vector
;
3866 /* Use default `...' which is stored in default_invis_vector. */
3867 it
->dpvec_char_len
= it
->len
;
3868 it
->dpvec
= default_invis_vector
;
3869 it
->dpend
= default_invis_vector
+ 3;
3870 it
->current
.dpvec_index
= 0;
3871 it
->method
= next_element_from_display_vector
;
3875 reseat_at_next_visible_line_start (it
, 1);
3877 return get_next_display_element (it
);
3881 /* Deliver an image display element. The iterator IT is already
3882 filled with image information (done in handle_display_prop). Value
3887 next_element_from_image (it
)
3890 it
->what
= IT_IMAGE
;
3895 /* Fill iterator IT with next display element from a stretch glyph
3896 property. IT->object is the value of the text property. Value is
3900 next_element_from_stretch (it
)
3903 it
->what
= IT_STRETCH
;
3908 /* Load IT with the next display element from current_buffer. Value
3909 is zero if end of buffer reached. IT->stop_charpos is the next
3910 position at which to stop and check for text properties or buffer
3914 next_element_from_buffer (it
)
3919 /* Check this assumption, otherwise, we would never enter the
3920 if-statement, below. */
3921 xassert (IT_CHARPOS (*it
) >= BEGV
3922 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
3924 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
3926 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3928 int overlay_strings_follow_p
;
3930 /* End of the game, except when overlay strings follow that
3931 haven't been returned yet. */
3932 if (it
->overlay_strings_at_end_processed_p
)
3933 overlay_strings_follow_p
= 0;
3936 it
->overlay_strings_at_end_processed_p
= 1;
3937 overlay_strings_follow_p
= get_overlay_strings (it
);
3940 if (overlay_strings_follow_p
)
3941 success_p
= get_next_display_element (it
);
3945 it
->position
= it
->current
.pos
;
3952 return get_next_display_element (it
);
3957 /* No face changes, overlays etc. in sight, so just return a
3958 character from current_buffer. */
3961 /* Maybe run the redisplay end trigger hook. Performance note:
3962 This doesn't seem to cost measurable time. */
3963 if (it
->redisplay_end_trigger_charpos
3965 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
3966 run_redisplay_end_trigger_hook (it
);
3968 /* Get the next character, maybe multibyte. */
3969 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
3970 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
3972 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
3973 - IT_BYTEPOS (*it
));
3974 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
3977 it
->c
= *p
, it
->len
= 1;
3979 /* Record what we have and where it came from. */
3980 it
->what
= IT_CHARACTER
;;
3981 it
->object
= it
->w
->buffer
;
3982 it
->position
= it
->current
.pos
;
3984 /* Normally we return the character found above, except when we
3985 really want to return an ellipsis for selective display. */
3990 /* A value of selective > 0 means hide lines indented more
3991 than that number of columns. */
3992 if (it
->selective
> 0
3993 && IT_CHARPOS (*it
) + 1 < ZV
3994 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
3995 IT_BYTEPOS (*it
) + 1,
3998 success_p
= next_element_from_ellipsis (it
);
3999 it
->dpvec_char_len
= -1;
4002 else if (it
->c
== '\r' && it
->selective
== -1)
4004 /* A value of selective == -1 means that everything from the
4005 CR to the end of the line is invisible, with maybe an
4006 ellipsis displayed for it. */
4007 success_p
= next_element_from_ellipsis (it
);
4008 it
->dpvec_char_len
= -1;
4013 /* Value is zero if end of buffer reached. */
4014 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4019 /* Run the redisplay end trigger hook for IT. */
4022 run_redisplay_end_trigger_hook (it
)
4025 Lisp_Object args
[3];
4027 /* IT->glyph_row should be non-null, i.e. we should be actually
4028 displaying something, or otherwise we should not run the hook. */
4029 xassert (it
->glyph_row
);
4031 /* Set up hook arguments. */
4032 args
[0] = Qredisplay_end_trigger_functions
;
4033 args
[1] = it
->window
;
4034 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4035 it
->redisplay_end_trigger_charpos
= 0;
4037 /* Since we are *trying* to run these functions, don't try to run
4038 them again, even if they get an error. */
4039 it
->w
->redisplay_end_trigger
= Qnil
;
4040 Frun_hook_with_args (3, args
);
4042 /* Notice if it changed the face of the character we are on. */
4043 handle_face_prop (it
);
4047 /* Deliver a composition display element. The iterator IT is already
4048 filled with composition information (done in
4049 handle_composition_prop). Value is always 1. */
4052 next_element_from_composition (it
)
4055 it
->what
= IT_COMPOSITION
;
4056 it
->position
= (STRINGP (it
->string
)
4057 ? it
->current
.string_pos
4064 /***********************************************************************
4065 Moving an iterator without producing glyphs
4066 ***********************************************************************/
4068 /* Move iterator IT to a specified buffer or X position within one
4069 line on the display without producing glyphs.
4071 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4072 whichever is reached first.
4074 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4076 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4077 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4078 TO_X includes the amount by which a window is horizontally
4083 MOVE_POS_MATCH_OR_ZV
4084 - when TO_POS or ZV was reached.
4087 -when TO_X was reached before TO_POS or ZV were reached.
4090 - when we reached the end of the display area and the line must
4094 - when we reached the end of the display area and the line is
4098 - when we stopped at a line end, i.e. a newline or a CR and selective
4101 static enum move_it_result
4102 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4104 int to_charpos
, to_x
, op
;
4106 enum move_it_result result
= MOVE_UNDEFINED
;
4107 struct glyph_row
*saved_glyph_row
;
4109 /* Don't produce glyphs in produce_glyphs. */
4110 saved_glyph_row
= it
->glyph_row
;
4111 it
->glyph_row
= NULL
;
4117 /* Stop when ZV or TO_CHARPOS reached. */
4118 if (!get_next_display_element (it
)
4119 || ((op
& MOVE_TO_POS
) != 0
4120 && BUFFERP (it
->object
)
4121 && IT_CHARPOS (*it
) >= to_charpos
))
4123 result
= MOVE_POS_MATCH_OR_ZV
;
4127 /* The call to produce_glyphs will get the metrics of the
4128 display element IT is loaded with. We record in x the
4129 x-position before this display element in case it does not
4132 PRODUCE_GLYPHS (it
);
4134 if (it
->area
!= TEXT_AREA
)
4136 set_iterator_to_next (it
);
4140 /* The number of glyphs we get back in IT->nglyphs will normally
4141 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4142 character on a terminal frame, or (iii) a line end. For the
4143 second case, IT->nglyphs - 1 padding glyphs will be present
4144 (on X frames, there is only one glyph produced for a
4145 composite character.
4147 The behavior implemented below means, for continuation lines,
4148 that as many spaces of a TAB as fit on the current line are
4149 displayed there. For terminal frames, as many glyphs of a
4150 multi-glyph character are displayed in the current line, too.
4151 This is what the old redisplay code did, and we keep it that
4152 way. Under X, the whole shape of a complex character must
4153 fit on the line or it will be completely displayed in the
4156 Note that both for tabs and padding glyphs, all glyphs have
4160 /* More than one glyph or glyph doesn't fit on line. All
4161 glyphs have the same width. */
4162 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4165 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4167 new_x
= x
+ single_glyph_width
;
4169 /* We want to leave anything reaching TO_X to the caller. */
4170 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4173 result
= MOVE_X_REACHED
;
4176 else if (/* Lines are continued. */
4177 !it
->truncate_lines_p
4178 && (/* And glyph doesn't fit on the line. */
4179 new_x
> it
->last_visible_x
4180 /* Or it fits exactly and we're on a window
4182 || (new_x
== it
->last_visible_x
4183 && FRAME_WINDOW_P (it
->f
))))
4185 if (/* IT->hpos == 0 means the very first glyph
4186 doesn't fit on the line, e.g. a wide image. */
4188 || (new_x
== it
->last_visible_x
4189 && FRAME_WINDOW_P (it
->f
)))
4192 it
->current_x
= new_x
;
4193 if (i
== it
->nglyphs
- 1)
4194 set_iterator_to_next (it
);
4199 result
= MOVE_LINE_CONTINUED
;
4202 else if (new_x
> it
->first_visible_x
)
4204 /* Glyph is visible. Increment number of glyphs that
4205 would be displayed. */
4210 /* Glyph is completely off the left margin of the display
4211 area. Nothing to do. */
4215 if (result
!= MOVE_UNDEFINED
)
4218 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4220 /* Stop when TO_X specified and reached. This check is
4221 necessary here because of lines consisting of a line end,
4222 only. The line end will not produce any glyphs and we
4223 would never get MOVE_X_REACHED. */
4224 xassert (it
->nglyphs
== 0);
4225 result
= MOVE_X_REACHED
;
4229 /* Is this a line end? If yes, we're done. */
4230 if (ITERATOR_AT_END_OF_LINE_P (it
))
4232 result
= MOVE_NEWLINE_OR_CR
;
4236 /* The current display element has been consumed. Advance
4238 set_iterator_to_next (it
);
4240 /* Stop if lines are truncated and IT's current x-position is
4241 past the right edge of the window now. */
4242 if (it
->truncate_lines_p
4243 && it
->current_x
>= it
->last_visible_x
)
4245 result
= MOVE_LINE_TRUNCATED
;
4250 /* Restore the iterator settings altered at the beginning of this
4252 it
->glyph_row
= saved_glyph_row
;
4257 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4258 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4259 the description of enum move_operation_enum.
4261 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4262 screen line, this function will set IT to the next position >
4266 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4268 int to_charpos
, to_x
, to_y
, to_vpos
;
4271 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4276 if (op
& MOVE_TO_VPOS
)
4278 /* If no TO_CHARPOS and no TO_X specified, stop at the
4279 start of the line TO_VPOS. */
4280 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4282 if (it
->vpos
== to_vpos
)
4284 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4288 /* TO_VPOS >= 0 means stop at TO_X in the line at
4289 TO_VPOS, or at TO_POS, whichever comes first. */
4290 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4292 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4294 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4296 /* We have reached TO_X but not in the line we want. */
4297 skip
= move_it_in_display_line_to (it
, to_charpos
,
4299 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4304 else if (op
& MOVE_TO_Y
)
4306 struct it it_backup
;
4309 /* TO_Y specified means stop at TO_X in the line containing
4310 TO_Y---or at TO_CHARPOS if this is reached first. The
4311 problem is that we can't really tell whether the line
4312 contains TO_Y before we have completely scanned it, and
4313 this may skip past TO_X. What we do is to first scan to
4316 If TO_X is not specified, use a TO_X of zero. The reason
4317 is to make the outcome of this function more predictable.
4318 If we didn't use TO_X == 0, we would stop at the end of
4319 the line which is probably not what a caller would expect
4321 skip
= move_it_in_display_line_to (it
, to_charpos
,
4325 | (op
& MOVE_TO_POS
)));
4327 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4328 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4331 /* If TO_X was reached, we would like to know whether TO_Y
4332 is in the line. This can only be said if we know the
4333 total line height which requires us to scan the rest of
4336 if (skip
== MOVE_X_REACHED
)
4339 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4343 /* Now, decide whether TO_Y is in this line. */
4344 line_height
= it
->max_ascent
+ it
->max_descent
;
4346 if (to_y
>= it
->current_y
4347 && to_y
< it
->current_y
+ line_height
)
4349 if (skip
== MOVE_X_REACHED
)
4350 /* If TO_Y is in this line and TO_X was reached above,
4351 we scanned too far. We have to restore IT's settings
4352 to the ones before skipping. */
4356 else if (skip
== MOVE_X_REACHED
)
4359 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4367 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4371 case MOVE_POS_MATCH_OR_ZV
:
4374 case MOVE_NEWLINE_OR_CR
:
4375 set_iterator_to_next (it
);
4376 it
->continuation_lines_width
= 0;
4379 case MOVE_LINE_TRUNCATED
:
4380 it
->continuation_lines_width
= 0;
4381 reseat_at_next_visible_line_start (it
, 0);
4382 if ((op
& MOVE_TO_POS
) != 0
4383 && IT_CHARPOS (*it
) > to_charpos
)
4387 case MOVE_LINE_CONTINUED
:
4388 it
->continuation_lines_width
+= it
->current_x
;
4395 /* Reset/increment for the next run. */
4396 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4397 it
->current_x
= it
->hpos
= 0;
4398 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4400 last_height
= it
->max_ascent
+ it
->max_descent
;
4401 last_max_ascent
= it
->max_ascent
;
4402 it
->max_ascent
= it
->max_descent
= 0;
4408 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4410 If DY > 0, move IT backward at least that many pixels. DY = 0
4411 means move IT backward to the preceding line start or BEGV. This
4412 function may move over more than DY pixels if IT->current_y - DY
4413 ends up in the middle of a line; in this case IT->current_y will be
4414 set to the top of the line moved to. */
4417 move_it_vertically_backward (it
, dy
)
4421 int nlines
, h
, line_height
;
4423 int start_pos
= IT_CHARPOS (*it
);
4427 /* Estimate how many newlines we must move back. */
4428 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4430 /* Set the iterator's position that many lines back. */
4431 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4432 back_to_previous_visible_line_start (it
);
4434 /* Reseat the iterator here. When moving backward, we don't want
4435 reseat to skip forward over invisible text, set up the iterator
4436 to deliver from overlay strings at the new position etc. So,
4437 use reseat_1 here. */
4438 reseat_1 (it
, it
->current
.pos
, 1);
4440 /* We are now surely at a line start. */
4441 it
->current_x
= it
->hpos
= 0;
4443 /* Move forward and see what y-distance we moved. First move to the
4444 start of the next line so that we get its height. We need this
4445 height to be able to tell whether we reached the specified
4448 it2
.max_ascent
= it2
.max_descent
= 0;
4449 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4450 MOVE_TO_POS
| MOVE_TO_VPOS
);
4451 xassert (IT_CHARPOS (*it
) >= BEGV
);
4452 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4453 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4454 xassert (IT_CHARPOS (*it
) >= BEGV
);
4455 h
= it2
.current_y
- it
->current_y
;
4456 nlines
= it2
.vpos
- it
->vpos
;
4458 /* Correct IT's y and vpos position. */
4464 /* DY == 0 means move to the start of the screen line. The
4465 value of nlines is > 0 if continuation lines were involved. */
4467 move_it_by_lines (it
, nlines
, 1);
4468 xassert (IT_CHARPOS (*it
) <= start_pos
);
4472 /* The y-position we try to reach. Note that h has been
4473 subtracted in front of the if-statement. */
4474 int target_y
= it
->current_y
+ h
- dy
;
4476 /* If we did not reach target_y, try to move further backward if
4477 we can. If we moved too far backward, try to move forward. */
4478 if (target_y
< it
->current_y
4479 && IT_CHARPOS (*it
) > BEGV
)
4481 move_it_vertically (it
, target_y
- it
->current_y
);
4482 xassert (IT_CHARPOS (*it
) >= BEGV
);
4484 else if (target_y
>= it
->current_y
+ line_height
4485 && IT_CHARPOS (*it
) < ZV
)
4487 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4488 xassert (IT_CHARPOS (*it
) >= BEGV
);
4494 /* Move IT by a specified amount of pixel lines DY. DY negative means
4495 move backwards. DY = 0 means move to start of screen line. At the
4496 end, IT will be on the start of a screen line. */
4499 move_it_vertically (it
, dy
)
4504 move_it_vertically_backward (it
, -dy
);
4507 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4508 MOVE_TO_POS
| MOVE_TO_Y
);
4510 /* If buffer ends in ZV without a newline, move to the start of
4511 the line to satisfy the post-condition. */
4512 if (IT_CHARPOS (*it
) == ZV
4513 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4514 move_it_by_lines (it
, 0, 0);
4519 /* Return non-zero if some text between buffer positions START_CHARPOS
4520 and END_CHARPOS is invisible. IT->window is the window for text
4524 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4526 int start_charpos
, end_charpos
;
4528 Lisp_Object prop
, limit
;
4529 int invisible_found_p
;
4531 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4533 /* Is text at START invisible? */
4534 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4536 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4537 invisible_found_p
= 1;
4540 limit
= next_single_char_property_change (make_number (start_charpos
),
4542 make_number (end_charpos
));
4543 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4546 return invisible_found_p
;
4550 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4551 negative means move up. DVPOS == 0 means move to the start of the
4552 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4553 NEED_Y_P is zero, IT->current_y will be left unchanged.
4555 Further optimization ideas: If we would know that IT->f doesn't use
4556 a face with proportional font, we could be faster for
4557 truncate-lines nil. */
4560 move_it_by_lines (it
, dvpos
, need_y_p
)
4562 int dvpos
, need_y_p
;
4564 struct position pos
;
4566 if (!FRAME_WINDOW_P (it
->f
))
4568 struct text_pos textpos
;
4570 /* We can use vmotion on frames without proportional fonts. */
4571 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4572 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4573 reseat (it
, textpos
, 1);
4574 it
->vpos
+= pos
.vpos
;
4575 it
->current_y
+= pos
.vpos
;
4577 else if (dvpos
== 0)
4579 /* DVPOS == 0 means move to the start of the screen line. */
4580 move_it_vertically_backward (it
, 0);
4581 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4585 /* If there are no continuation lines, and if there is no
4586 selective display, try the simple method of moving forward
4587 DVPOS newlines, then see where we are. */
4588 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4590 int shortage
= 0, charpos
;
4592 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
4593 charpos
= IT_CHARPOS (*it
) + 1;
4595 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
4598 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
4600 struct text_pos pos
;
4601 CHARPOS (pos
) = charpos
;
4602 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4603 reseat (it
, pos
, 1);
4604 it
->vpos
+= dvpos
- shortage
;
4605 it
->hpos
= it
->current_x
= 0;
4610 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
4615 int start_charpos
, i
;
4617 /* If there are no continuation lines, and if there is no
4618 selective display, try the simple method of moving backward
4620 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4623 int charpos
= IT_CHARPOS (*it
);
4624 int bytepos
= IT_BYTEPOS (*it
);
4626 /* If in the middle of a line, go to its start. */
4627 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
4629 charpos
= find_next_newline_no_quit (charpos
, -1);
4630 bytepos
= CHAR_TO_BYTE (charpos
);
4633 if (charpos
== BEGV
)
4635 struct text_pos pos
;
4636 CHARPOS (pos
) = charpos
;
4637 BYTEPOS (pos
) = bytepos
;
4638 reseat (it
, pos
, 1);
4639 it
->hpos
= it
->current_x
= 0;
4644 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
4645 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
4647 struct text_pos pos
;
4648 CHARPOS (pos
) = charpos
;
4649 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4650 reseat (it
, pos
, 1);
4651 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
4652 it
->hpos
= it
->current_x
= 0;
4658 /* Go back -DVPOS visible lines and reseat the iterator there. */
4659 start_charpos
= IT_CHARPOS (*it
);
4660 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
4661 back_to_previous_visible_line_start (it
);
4662 reseat (it
, it
->current
.pos
, 1);
4663 it
->current_x
= it
->hpos
= 0;
4665 /* Above call may have moved too far if continuation lines
4666 are involved. Scan forward and see if it did. */
4668 it2
.vpos
= it2
.current_y
= 0;
4669 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
4670 it
->vpos
-= it2
.vpos
;
4671 it
->current_y
-= it2
.current_y
;
4672 it
->current_x
= it
->hpos
= 0;
4674 /* If we moved too far, move IT some lines forward. */
4675 if (it2
.vpos
> -dvpos
)
4677 int delta
= it2
.vpos
+ dvpos
;
4678 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
4685 /***********************************************************************
4687 ***********************************************************************/
4690 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
4694 add_to_log (format
, arg1
, arg2
)
4696 Lisp_Object arg1
, arg2
;
4698 Lisp_Object args
[3];
4699 Lisp_Object msg
, fmt
;
4702 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4705 GCPRO4 (fmt
, msg
, arg1
, arg2
);
4707 args
[0] = fmt
= build_string (format
);
4710 msg
= Fformat (3, args
);
4712 len
= STRING_BYTES (XSTRING (msg
)) + 1;
4713 buffer
= (char *) alloca (len
);
4714 strcpy (buffer
, XSTRING (msg
)->data
);
4716 message_dolog (buffer
, len
- 1, 1, 0);
4721 /* Output a newline in the *Messages* buffer if "needs" one. */
4724 message_log_maybe_newline ()
4726 if (message_log_need_newline
)
4727 message_dolog ("", 0, 1, 0);
4731 /* Add a string M of length LEN to the message log, optionally
4732 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
4733 nonzero, means interpret the contents of M as multibyte. This
4734 function calls low-level routines in order to bypass text property
4735 hooks, etc. which might not be safe to run. */
4738 message_dolog (m
, len
, nlflag
, multibyte
)
4740 int len
, nlflag
, multibyte
;
4742 if (!NILP (Vmessage_log_max
))
4744 struct buffer
*oldbuf
;
4745 Lisp_Object oldpoint
, oldbegv
, oldzv
;
4746 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4747 int point_at_end
= 0;
4749 Lisp_Object old_deactivate_mark
, tem
;
4750 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4752 old_deactivate_mark
= Vdeactivate_mark
;
4753 oldbuf
= current_buffer
;
4754 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
4755 current_buffer
->undo_list
= Qt
;
4757 oldpoint
= Fpoint_marker ();
4758 oldbegv
= Fpoint_min_marker ();
4759 oldzv
= Fpoint_max_marker ();
4760 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
4768 BEGV_BYTE
= BEG_BYTE
;
4771 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4773 /* Insert the string--maybe converting multibyte to single byte
4774 or vice versa, so that all the text fits the buffer. */
4776 && NILP (current_buffer
->enable_multibyte_characters
))
4779 unsigned char work
[1];
4781 /* Convert a multibyte string to single-byte
4782 for the *Message* buffer. */
4783 for (i
= 0; i
< len
; i
+= nbytes
)
4785 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
4786 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
4788 : multibyte_char_to_unibyte (c
, Qnil
));
4789 insert_1_both (work
, 1, 1, 1, 0, 0);
4792 else if (! multibyte
4793 && ! NILP (current_buffer
->enable_multibyte_characters
))
4796 unsigned char *msg
= (unsigned char *) m
;
4797 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4798 /* Convert a single-byte string to multibyte
4799 for the *Message* buffer. */
4800 for (i
= 0; i
< len
; i
++)
4802 c
= unibyte_char_to_multibyte (msg
[i
]);
4803 nbytes
= CHAR_STRING (c
, str
);
4804 insert_1_both (str
, 1, nbytes
, 1, 0, 0);
4808 insert_1 (m
, len
, 1, 0, 0);
4812 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
4813 insert_1 ("\n", 1, 1, 0, 0);
4815 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4817 this_bol_byte
= PT_BYTE
;
4821 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4823 prev_bol_byte
= PT_BYTE
;
4825 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
4826 this_bol
, this_bol_byte
);
4829 del_range_both (prev_bol
, prev_bol_byte
,
4830 this_bol
, this_bol_byte
, 0);
4836 /* If you change this format, don't forget to also
4837 change message_log_check_duplicate. */
4838 sprintf (dupstr
, " [%d times]", dup
);
4839 duplen
= strlen (dupstr
);
4840 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
4841 insert_1 (dupstr
, duplen
, 1, 0, 1);
4846 if (NATNUMP (Vmessage_log_max
))
4848 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
4849 -XFASTINT (Vmessage_log_max
) - 1, 0);
4850 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
4853 BEGV
= XMARKER (oldbegv
)->charpos
;
4854 BEGV_BYTE
= marker_byte_position (oldbegv
);
4863 ZV
= XMARKER (oldzv
)->charpos
;
4864 ZV_BYTE
= marker_byte_position (oldzv
);
4868 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4870 /* We can't do Fgoto_char (oldpoint) because it will run some
4872 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
4873 XMARKER (oldpoint
)->bytepos
);
4876 free_marker (oldpoint
);
4877 free_marker (oldbegv
);
4878 free_marker (oldzv
);
4880 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
4881 set_buffer_internal (oldbuf
);
4883 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
4884 message_log_need_newline
= !nlflag
;
4885 Vdeactivate_mark
= old_deactivate_mark
;
4890 /* We are at the end of the buffer after just having inserted a newline.
4891 (Note: We depend on the fact we won't be crossing the gap.)
4892 Check to see if the most recent message looks a lot like the previous one.
4893 Return 0 if different, 1 if the new one should just replace it, or a
4894 value N > 1 if we should also append " [N times]". */
4897 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
4898 int prev_bol
, this_bol
;
4899 int prev_bol_byte
, this_bol_byte
;
4902 int len
= Z_BYTE
- 1 - this_bol_byte
;
4904 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
4905 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
4907 for (i
= 0; i
< len
; i
++)
4909 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
4918 if (*p1
++ == ' ' && *p1
++ == '[')
4921 while (*p1
>= '0' && *p1
<= '9')
4922 n
= n
* 10 + *p1
++ - '0';
4923 if (strncmp (p1
, " times]\n", 8) == 0)
4930 /* Display an echo area message M with a specified length of LEN
4931 chars. The string may include null characters. If M is 0, clear
4932 out any existing message, and let the mini-buffer text show through.
4934 The buffer M must continue to exist until after the echo area gets
4935 cleared or some other message gets displayed there. This means do
4936 not pass text that is stored in a Lisp string; do not pass text in
4937 a buffer that was alloca'd. */
4940 message2 (m
, len
, multibyte
)
4945 /* First flush out any partial line written with print. */
4946 message_log_maybe_newline ();
4948 message_dolog (m
, len
, 1, multibyte
);
4949 message2_nolog (m
, len
, multibyte
);
4953 /* The non-logging counterpart of message2. */
4956 message2_nolog (m
, len
, multibyte
)
4960 struct frame
*sf
= SELECTED_FRAME ();
4961 message_enable_multibyte
= multibyte
;
4965 if (noninteractive_need_newline
)
4966 putc ('\n', stderr
);
4967 noninteractive_need_newline
= 0;
4969 fwrite (m
, len
, 1, stderr
);
4970 if (cursor_in_echo_area
== 0)
4971 fprintf (stderr
, "\n");
4974 /* A null message buffer means that the frame hasn't really been
4975 initialized yet. Error messages get reported properly by
4976 cmd_error, so this must be just an informative message; toss it. */
4977 else if (INTERACTIVE
4978 && sf
->glyphs_initialized_p
4979 && FRAME_MESSAGE_BUF (sf
))
4981 Lisp_Object mini_window
;
4984 /* Get the frame containing the mini-buffer
4985 that the selected frame is using. */
4986 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
4987 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4989 FRAME_SAMPLE_VISIBILITY (f
);
4990 if (FRAME_VISIBLE_P (sf
)
4991 && ! FRAME_VISIBLE_P (f
))
4992 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
4996 set_message (m
, Qnil
, len
, multibyte
);
4997 if (minibuffer_auto_raise
)
4998 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5001 clear_message (1, 1);
5003 do_pending_window_change (0);
5004 echo_area_display (1);
5005 do_pending_window_change (0);
5006 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5007 (*frame_up_to_date_hook
) (f
);
5012 /* Display an echo area message M with a specified length of NBYTES
5013 bytes. The string may include null characters. If M is not a
5014 string, clear out any existing message, and let the mini-buffer
5015 text show through. */
5018 message3 (m
, nbytes
, multibyte
)
5023 struct gcpro gcpro1
;
5027 /* First flush out any partial line written with print. */
5028 message_log_maybe_newline ();
5030 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5031 message3_nolog (m
, nbytes
, multibyte
);
5037 /* The non-logging version of message3. */
5040 message3_nolog (m
, nbytes
, multibyte
)
5042 int nbytes
, multibyte
;
5044 struct frame
*sf
= SELECTED_FRAME ();
5045 message_enable_multibyte
= multibyte
;
5049 if (noninteractive_need_newline
)
5050 putc ('\n', stderr
);
5051 noninteractive_need_newline
= 0;
5053 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5054 if (cursor_in_echo_area
== 0)
5055 fprintf (stderr
, "\n");
5058 /* A null message buffer means that the frame hasn't really been
5059 initialized yet. Error messages get reported properly by
5060 cmd_error, so this must be just an informative message; toss it. */
5061 else if (INTERACTIVE
5062 && sf
->glyphs_initialized_p
5063 && FRAME_MESSAGE_BUF (sf
))
5065 Lisp_Object mini_window
;
5069 /* Get the frame containing the mini-buffer
5070 that the selected frame is using. */
5071 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5072 frame
= XWINDOW (mini_window
)->frame
;
5075 FRAME_SAMPLE_VISIBILITY (f
);
5076 if (FRAME_VISIBLE_P (sf
)
5077 && !FRAME_VISIBLE_P (f
))
5078 Fmake_frame_visible (frame
);
5080 if (STRINGP (m
) && XSTRING (m
)->size
)
5082 set_message (NULL
, m
, nbytes
, multibyte
);
5083 if (minibuffer_auto_raise
)
5084 Fraise_frame (frame
);
5087 clear_message (1, 1);
5089 do_pending_window_change (0);
5090 echo_area_display (1);
5091 do_pending_window_change (0);
5092 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5093 (*frame_up_to_date_hook
) (f
);
5098 /* Display a null-terminated echo area message M. If M is 0, clear
5099 out any existing message, and let the mini-buffer text show through.
5101 The buffer M must continue to exist until after the echo area gets
5102 cleared or some other message gets displayed there. Do not pass
5103 text that is stored in a Lisp string. Do not pass text in a buffer
5104 that was alloca'd. */
5110 message2 (m
, (m
? strlen (m
) : 0), 0);
5114 /* The non-logging counterpart of message1. */
5120 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5123 /* Display a message M which contains a single %s
5124 which gets replaced with STRING. */
5127 message_with_string (m
, string
, log
)
5136 if (noninteractive_need_newline
)
5137 putc ('\n', stderr
);
5138 noninteractive_need_newline
= 0;
5139 fprintf (stderr
, m
, XSTRING (string
)->data
);
5140 if (cursor_in_echo_area
== 0)
5141 fprintf (stderr
, "\n");
5145 else if (INTERACTIVE
)
5147 /* The frame whose minibuffer we're going to display the message on.
5148 It may be larger than the selected frame, so we need
5149 to use its buffer, not the selected frame's buffer. */
5150 Lisp_Object mini_window
;
5151 struct frame
*f
, *sf
= SELECTED_FRAME ();
5153 /* Get the frame containing the minibuffer
5154 that the selected frame is using. */
5155 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5156 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5158 /* A null message buffer means that the frame hasn't really been
5159 initialized yet. Error messages get reported properly by
5160 cmd_error, so this must be just an informative message; toss it. */
5161 if (FRAME_MESSAGE_BUF (f
))
5165 a
[0] = (char *) XSTRING (string
)->data
;
5167 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5168 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5171 message2 (FRAME_MESSAGE_BUF (f
), len
,
5172 STRING_MULTIBYTE (string
));
5174 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5175 STRING_MULTIBYTE (string
));
5177 /* Print should start at the beginning of the message
5178 buffer next time. */
5179 message_buf_print
= 0;
5185 /* Dump an informative message to the minibuf. If M is 0, clear out
5186 any existing message, and let the mini-buffer text show through. */
5190 message (m
, a1
, a2
, a3
)
5192 EMACS_INT a1
, a2
, a3
;
5198 if (noninteractive_need_newline
)
5199 putc ('\n', stderr
);
5200 noninteractive_need_newline
= 0;
5201 fprintf (stderr
, m
, a1
, a2
, a3
);
5202 if (cursor_in_echo_area
== 0)
5203 fprintf (stderr
, "\n");
5207 else if (INTERACTIVE
)
5209 /* The frame whose mini-buffer we're going to display the message
5210 on. It may be larger than the selected frame, so we need to
5211 use its buffer, not the selected frame's buffer. */
5212 Lisp_Object mini_window
;
5213 struct frame
*f
, *sf
= SELECTED_FRAME ();
5215 /* Get the frame containing the mini-buffer
5216 that the selected frame is using. */
5217 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5218 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5220 /* A null message buffer means that the frame hasn't really been
5221 initialized yet. Error messages get reported properly by
5222 cmd_error, so this must be just an informative message; toss
5224 if (FRAME_MESSAGE_BUF (f
))
5235 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5236 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5238 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5239 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5241 #endif /* NO_ARG_ARRAY */
5243 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5248 /* Print should start at the beginning of the message
5249 buffer next time. */
5250 message_buf_print
= 0;
5256 /* The non-logging version of message. */
5259 message_nolog (m
, a1
, a2
, a3
)
5261 EMACS_INT a1
, a2
, a3
;
5263 Lisp_Object old_log_max
;
5264 old_log_max
= Vmessage_log_max
;
5265 Vmessage_log_max
= Qnil
;
5266 message (m
, a1
, a2
, a3
);
5267 Vmessage_log_max
= old_log_max
;
5271 /* Display the current message in the current mini-buffer. This is
5272 only called from error handlers in process.c, and is not time
5278 if (!NILP (echo_area_buffer
[0]))
5281 string
= Fcurrent_message ();
5282 message3 (string
, XSTRING (string
)->size
,
5283 !NILP (current_buffer
->enable_multibyte_characters
));
5288 /* Make sure echo area buffers in echo_buffers[] are life. If they
5289 aren't, make new ones. */
5292 ensure_echo_area_buffers ()
5296 for (i
= 0; i
< 2; ++i
)
5297 if (!BUFFERP (echo_buffer
[i
])
5298 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5301 sprintf (name
, " *Echo Area %d*", i
);
5302 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5307 /* Call FN with args A1..A5 with either the current or last displayed
5308 echo_area_buffer as current buffer.
5310 WHICH zero means use the current message buffer
5311 echo_area_buffer[0]. If that is nil, choose a suitable buffer
5312 from echo_buffer[] and clear it.
5314 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
5315 suitable buffer from echo_buffer[] and clear it.
5317 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
5318 that the current message becomes the last displayed one, make
5319 choose a suitable buffer for echo_area_buffer[0], and clear it.
5321 Value is what FN returns. */
5324 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
)
5328 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
;
5331 int this_one
, the_other
, clear_buffer_p
, rc
;
5332 int count
= specpdl_ptr
- specpdl
;
5334 /* If buffers aren't life, make new ones. */
5335 ensure_echo_area_buffers ();
5340 this_one
= 0, the_other
= 1;
5342 this_one
= 1, the_other
= 0;
5345 this_one
= 0, the_other
= 1;
5348 /* We need a fresh one in case the current echo buffer equals
5349 the one containing the last displayed echo area message. */
5350 if (!NILP (echo_area_buffer
[this_one
])
5351 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
5352 echo_area_buffer
[this_one
] = Qnil
;
5355 /* Choose a suitable buffer from echo_buffer[] is we don't
5357 if (NILP (echo_area_buffer
[this_one
]))
5359 echo_area_buffer
[this_one
]
5360 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
5361 ? echo_buffer
[the_other
]
5362 : echo_buffer
[this_one
]);
5366 buffer
= echo_area_buffer
[this_one
];
5368 record_unwind_protect (unwind_with_echo_area_buffer
,
5369 with_echo_area_buffer_unwind_data (w
));
5371 /* Make the echo area buffer current. Note that for display
5372 purposes, it is not necessary that the displayed window's buffer
5373 == current_buffer, except for text property lookup. So, let's
5374 only set that buffer temporarily here without doing a full
5375 Fset_window_buffer. We must also change w->pointm, though,
5376 because otherwise an assertions in unshow_buffer fails, and Emacs
5378 set_buffer_internal_1 (XBUFFER (buffer
));
5382 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
5384 current_buffer
->truncate_lines
= Qnil
;
5385 current_buffer
->undo_list
= Qt
;
5386 current_buffer
->read_only
= Qnil
;
5388 if (clear_buffer_p
&& Z
> BEG
)
5391 xassert (BEGV
>= BEG
);
5392 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5394 rc
= fn (a1
, a2
, a3
, a4
, a5
);
5396 xassert (BEGV
>= BEG
);
5397 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5399 unbind_to (count
, Qnil
);
5404 /* Save state that should be preserved around the call to the function
5405 FN called in with_echo_area_buffer. */
5408 with_echo_area_buffer_unwind_data (w
)
5414 /* Reduce consing by keeping one vector in
5415 Vwith_echo_area_save_vector. */
5416 vector
= Vwith_echo_area_save_vector
;
5417 Vwith_echo_area_save_vector
= Qnil
;
5420 vector
= Fmake_vector (make_number (7), Qnil
);
5422 XSETBUFFER (XVECTOR (vector
)->contents
[i
], current_buffer
); ++i
;
5423 XVECTOR (vector
)->contents
[i
++] = Vdeactivate_mark
;
5424 XVECTOR (vector
)->contents
[i
++] = make_number (windows_or_buffers_changed
);
5428 XSETWINDOW (XVECTOR (vector
)->contents
[i
], w
); ++i
;
5429 XVECTOR (vector
)->contents
[i
++] = w
->buffer
;
5430 XVECTOR (vector
)->contents
[i
++]
5431 = make_number (XMARKER (w
->pointm
)->charpos
);
5432 XVECTOR (vector
)->contents
[i
++]
5433 = make_number (XMARKER (w
->pointm
)->bytepos
);
5439 XVECTOR (vector
)->contents
[i
++] = Qnil
;
5442 xassert (i
== XVECTOR (vector
)->size
);
5447 /* Restore global state from VECTOR which was created by
5448 with_echo_area_buffer_unwind_data. */
5451 unwind_with_echo_area_buffer (vector
)
5456 set_buffer_internal_1 (XBUFFER (XVECTOR (vector
)->contents
[i
])); ++i
;
5457 Vdeactivate_mark
= XVECTOR (vector
)->contents
[i
]; ++i
;
5458 windows_or_buffers_changed
= XFASTINT (XVECTOR (vector
)->contents
[i
]); ++i
;
5460 if (WINDOWP (XVECTOR (vector
)->contents
[i
]))
5463 Lisp_Object buffer
, charpos
, bytepos
;
5465 w
= XWINDOW (XVECTOR (vector
)->contents
[i
]); ++i
;
5466 buffer
= XVECTOR (vector
)->contents
[i
]; ++i
;
5467 charpos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5468 bytepos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5471 set_marker_both (w
->pointm
, buffer
,
5472 XFASTINT (charpos
), XFASTINT (bytepos
));
5475 Vwith_echo_area_save_vector
= vector
;
5480 /* Set up the echo area for use by print functions. MULTIBYTE_P
5481 non-zero means we will print multibyte. */
5484 setup_echo_area_for_printing (multibyte_p
)
5487 ensure_echo_area_buffers ();
5489 if (!message_buf_print
)
5491 /* A message has been output since the last time we printed.
5492 Choose a fresh echo area buffer. */
5493 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5494 echo_area_buffer
[0] = echo_buffer
[1];
5496 echo_area_buffer
[0] = echo_buffer
[0];
5498 /* Switch to that buffer and clear it. */
5499 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5502 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5504 /* Set up the buffer for the multibyteness we need. */
5506 != !NILP (current_buffer
->enable_multibyte_characters
))
5507 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
5509 /* Raise the frame containing the echo area. */
5510 if (minibuffer_auto_raise
)
5512 struct frame
*sf
= SELECTED_FRAME ();
5513 Lisp_Object mini_window
;
5514 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5515 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5518 message_buf_print
= 1;
5522 if (NILP (echo_area_buffer
[0]))
5524 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5525 echo_area_buffer
[0] = echo_buffer
[1];
5527 echo_area_buffer
[0] = echo_buffer
[0];
5530 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
5531 /* Someone switched buffers between print requests. */
5532 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5537 /* Display an echo area message in window W. Value is non-zero if W's
5538 height is changed. If display_last_displayed_message_p is
5539 non-zero, display the message that was last displayed, otherwise
5540 display the current message. */
5543 display_echo_area (w
)
5546 int i
, no_message_p
, window_height_changed_p
, count
;
5548 /* Temporarily disable garbage collections while displaying the echo
5549 area. This is done because a GC can print a message itself.
5550 That message would modify the echo area buffer's contents while a
5551 redisplay of the buffer is going on, and seriously confuse
5553 count
= inhibit_garbage_collection ();
5555 /* If there is no message, we must call display_echo_area_1
5556 nevertheless because it resizes the window. But we will have to
5557 reset the echo_area_buffer in question to nil at the end because
5558 with_echo_area_buffer will sets it to an empty buffer. */
5559 i
= display_last_displayed_message_p
? 1 : 0;
5560 no_message_p
= NILP (echo_area_buffer
[i
]);
5562 window_height_changed_p
5563 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
5564 (int (*) ()) display_echo_area_1
, w
);
5567 echo_area_buffer
[i
] = Qnil
;
5569 unbind_to (count
, Qnil
);
5570 return window_height_changed_p
;
5574 /* Helper for display_echo_area. Display the current buffer which
5575 contains the current echo area message in window W, a mini-window.
5576 Change the height of W so that all of the message is displayed.
5577 Value is non-zero if height of W was changed. */
5580 display_echo_area_1 (w
)
5584 struct text_pos start
;
5585 int window_height_changed_p
= 0;
5587 /* Do this before displaying, so that we have a large enough glyph
5588 matrix for the display. */
5589 window_height_changed_p
= resize_mini_window (w
, 0);
5592 clear_glyph_matrix (w
->desired_matrix
);
5593 XSETWINDOW (window
, w
);
5594 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
5595 try_window (window
, start
);
5597 return window_height_changed_p
;
5601 /* Resize the echo area window to exactly the size needed for the
5602 currently displayed message, if there is one. */
5605 resize_echo_area_axactly ()
5607 if (BUFFERP (echo_area_buffer
[0])
5608 && WINDOWP (echo_area_window
))
5610 struct window
*w
= XWINDOW (echo_area_window
);
5613 resized_p
= with_echo_area_buffer (w
, 0,
5614 (int (*) ()) resize_mini_window
,
5618 ++windows_or_buffers_changed
;
5619 ++update_mode_lines
;
5620 redisplay_internal (0);
5626 /* Resize mini-window W to fit the size of its contents. EXACT:P
5627 means size the window exactly to the size needed. Otherwise, it's
5628 only enlarged until W's buffer is empty. Value is non-zero if
5629 the window height has been changed. */
5632 resize_mini_window (w
, exact_p
)
5636 struct frame
*f
= XFRAME (w
->frame
);
5637 int window_height_changed_p
= 0;
5639 xassert (MINI_WINDOW_P (w
));
5641 /* Nil means don't try to resize. */
5642 if (NILP (Vmax_mini_window_height
)
5643 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
5646 if (!FRAME_MINIBUF_ONLY_P (f
))
5649 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5650 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
5651 int height
, max_height
;
5652 int unit
= CANON_Y_UNIT (f
);
5653 struct text_pos start
;
5655 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
5657 /* Compute the max. number of lines specified by the user. */
5658 if (FLOATP (Vmax_mini_window_height
))
5659 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
5660 else if (INTEGERP (Vmax_mini_window_height
))
5661 max_height
= XINT (Vmax_mini_window_height
);
5663 max_height
= total_height
/ 4;
5665 /* Correct that max. height if it's bogus. */
5666 max_height
= max (1, max_height
);
5667 max_height
= min (total_height
, max_height
);
5669 /* Find out the height of the text in the window. */
5671 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
5672 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
5673 height
= it
.current_y
+ last_height
;
5675 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
5676 height
= (height
+ unit
- 1) / unit
;
5678 /* Compute a suitable window start. */
5679 if (height
> max_height
)
5681 height
= max_height
;
5682 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
5683 move_it_vertically_backward (&it
, (height
- 1) * unit
);
5684 start
= it
.current
.pos
;
5687 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5688 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
5690 /* Let it grow only, until we display an empty message, in which
5691 case the window shrinks again. */
5692 if (height
> XFASTINT (w
->height
))
5694 int old_height
= XFASTINT (w
->height
);
5695 freeze_window_starts (f
, 1);
5696 grow_mini_window (w
, height
- XFASTINT (w
->height
));
5697 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5699 else if (height
< XFASTINT (w
->height
)
5700 && (exact_p
|| BEGV
== ZV
))
5702 int old_height
= XFASTINT (w
->height
);
5703 freeze_window_starts (f
, 0);
5704 shrink_mini_window (w
);
5705 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5709 return window_height_changed_p
;
5713 /* Value is the current message, a string, or nil if there is no
5721 if (NILP (echo_area_buffer
[0]))
5725 with_echo_area_buffer (0, 0, (int (*) ()) current_message_1
, &msg
);
5727 echo_area_buffer
[0] = Qnil
;
5735 current_message_1 (msg
)
5739 *msg
= make_buffer_string (BEG
, Z
, 1);
5746 /* Push the current message on Vmessage_stack for later restauration
5747 by restore_message. Value is non-zero if the current message isn't
5748 empty. This is a relatively infrequent operation, so it's not
5749 worth optimizing. */
5755 msg
= current_message ();
5756 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
5757 return STRINGP (msg
);
5761 /* Restore message display from the top of Vmessage_stack. */
5768 xassert (CONSP (Vmessage_stack
));
5769 msg
= XCAR (Vmessage_stack
);
5771 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
5773 message3_nolog (msg
, 0, 0);
5777 /* Pop the top-most entry off Vmessage_stack. */
5782 xassert (CONSP (Vmessage_stack
));
5783 Vmessage_stack
= XCDR (Vmessage_stack
);
5787 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
5788 exits. If the stack is not empty, we have a missing pop_message
5792 check_message_stack ()
5794 if (!NILP (Vmessage_stack
))
5799 /* Truncate to NCHARS what will be displayed in the echo area the next
5800 time we display it---but don't redisplay it now. */
5803 truncate_echo_area (nchars
)
5807 echo_area_buffer
[0] = Qnil
;
5808 /* A null message buffer means that the frame hasn't really been
5809 initialized yet. Error messages get reported properly by
5810 cmd_error, so this must be just an informative message; toss it. */
5811 else if (!noninteractive
5813 && !NILP (echo_area_buffer
[0]))
5815 struct frame
*sf
= SELECTED_FRAME ();
5816 if (FRAME_MESSAGE_BUF (sf
))
5817 with_echo_area_buffer (0, 0, (int (*) ()) truncate_message_1
, nchars
);
5822 /* Helper function for truncate_echo_area. Truncate the current
5823 message to at most NCHARS characters. */
5826 truncate_message_1 (nchars
)
5829 if (BEG
+ nchars
< Z
)
5830 del_range (BEG
+ nchars
, Z
);
5832 echo_area_buffer
[0] = Qnil
;
5837 /* Set the current message to a substring of S or STRING.
5839 If STRING is a Lisp string, set the message to the first NBYTES
5840 bytes from STRING. NBYTES zero means use the whole string. If
5841 STRING is multibyte, the message will be displayed multibyte.
5843 If S is not null, set the message to the first LEN bytes of S. LEN
5844 zero means use the whole string. MULTIBYTE_P non-zero means S is
5845 multibyte. Display the message multibyte in that case. */
5848 set_message (s
, string
, nbytes
, multibyte_p
)
5853 message_enable_multibyte
5854 = ((s
&& multibyte_p
)
5855 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
5857 with_echo_area_buffer (0, -1, (int (*) ()) set_message_1
,
5858 s
, string
, nbytes
, multibyte_p
);
5859 message_buf_print
= 0;
5863 /* Helper function for set_message. Arguments have the same meaning
5864 as there. This function is called with the echo area buffer being
5868 set_message_1 (s
, string
, nbytes
, multibyte_p
)
5871 int nbytes
, multibyte_p
;
5875 /* Change multibyteness of the echo buffer appropriately. */
5876 if (message_enable_multibyte
5877 != !NILP (current_buffer
->enable_multibyte_characters
))
5878 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
5880 /* Insert new message at BEG. */
5881 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5883 if (STRINGP (string
))
5888 nbytes
= XSTRING (string
)->size_byte
;
5889 nchars
= string_byte_to_char (string
, nbytes
);
5891 /* This function takes care of single/multibyte conversion. We
5892 just have to ensure that the echo area buffer has the right
5893 setting of enable_multibyte_characters. */
5894 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
5899 nbytes
= strlen (s
);
5901 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
5903 /* Convert from multi-byte to single-byte. */
5905 unsigned char work
[1];
5907 /* Convert a multibyte string to single-byte. */
5908 for (i
= 0; i
< nbytes
; i
+= n
)
5910 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
5911 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5913 : multibyte_char_to_unibyte (c
, Qnil
));
5914 insert_1_both (work
, 1, 1, 1, 0, 0);
5917 else if (!multibyte_p
5918 && !NILP (current_buffer
->enable_multibyte_characters
))
5920 /* Convert from single-byte to multi-byte. */
5922 unsigned char *msg
= (unsigned char *) s
;
5923 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5925 /* Convert a single-byte string to multibyte. */
5926 for (i
= 0; i
< nbytes
; i
++)
5928 c
= unibyte_char_to_multibyte (msg
[i
]);
5929 n
= CHAR_STRING (c
, str
);
5930 insert_1_both (str
, 1, n
, 1, 0, 0);
5934 insert_1 (s
, nbytes
, 1, 0, 0);
5941 /* Clear messages. CURRENT_P non-zero means clear the current
5942 message. LAST_DISPLAYED_P non-zero means clear the message
5946 clear_message (current_p
, last_displayed_p
)
5947 int current_p
, last_displayed_p
;
5950 echo_area_buffer
[0] = Qnil
;
5952 if (last_displayed_p
)
5953 echo_area_buffer
[1] = Qnil
;
5955 message_buf_print
= 0;
5958 /* Clear garbaged frames.
5960 This function is used where the old redisplay called
5961 redraw_garbaged_frames which in turn called redraw_frame which in
5962 turn called clear_frame. The call to clear_frame was a source of
5963 flickering. I believe a clear_frame is not necessary. It should
5964 suffice in the new redisplay to invalidate all current matrices,
5965 and ensure a complete redisplay of all windows. */
5968 clear_garbaged_frames ()
5972 Lisp_Object tail
, frame
;
5974 FOR_EACH_FRAME (tail
, frame
)
5976 struct frame
*f
= XFRAME (frame
);
5978 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
5980 clear_current_matrices (f
);
5986 ++windows_or_buffers_changed
;
5991 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
5992 is non-zero update selected_frame. Value is non-zero if the
5993 mini-windows height has been changed. */
5996 echo_area_display (update_frame_p
)
5999 Lisp_Object mini_window
;
6002 int window_height_changed_p
= 0;
6003 struct frame
*sf
= SELECTED_FRAME ();
6005 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6006 w
= XWINDOW (mini_window
);
6007 f
= XFRAME (WINDOW_FRAME (w
));
6009 /* Don't display if frame is invisible or not yet initialized. */
6010 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6013 #ifdef HAVE_WINDOW_SYSTEM
6014 /* When Emacs starts, selected_frame may be a visible terminal
6015 frame, even if we run under a window system. If we let this
6016 through, a message would be displayed on the terminal. */
6017 if (EQ (selected_frame
, Vterminal_frame
)
6018 && !NILP (Vwindow_system
))
6020 #endif /* HAVE_WINDOW_SYSTEM */
6022 /* Redraw garbaged frames. */
6024 clear_garbaged_frames ();
6026 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6028 echo_area_window
= mini_window
;
6029 window_height_changed_p
= display_echo_area (w
);
6030 w
->must_be_updated_p
= 1;
6034 /* Not called from redisplay_internal. If we changed
6035 window configuration, we must redisplay thoroughly.
6036 Otherwise, we can do with updating what we displayed
6038 if (window_height_changed_p
)
6040 ++windows_or_buffers_changed
;
6041 ++update_mode_lines
;
6042 redisplay_internal (0);
6044 else if (FRAME_WINDOW_P (f
))
6046 update_single_window (w
, 1);
6047 rif
->flush_display (f
);
6050 update_frame (f
, 1, 1);
6053 else if (!EQ (mini_window
, selected_window
))
6054 windows_or_buffers_changed
++;
6056 /* Last displayed message is now the current message. */
6057 echo_area_buffer
[1] = echo_area_buffer
[0];
6059 /* Prevent redisplay optimization in redisplay_internal by resetting
6060 this_line_start_pos. This is done because the mini-buffer now
6061 displays the message instead of its buffer text. */
6062 if (EQ (mini_window
, selected_window
))
6063 CHARPOS (this_line_start_pos
) = 0;
6065 return window_height_changed_p
;
6070 /***********************************************************************
6072 ***********************************************************************/
6075 #ifdef HAVE_WINDOW_SYSTEM
6077 /* A buffer for constructing frame titles in it; allocated from the
6078 heap in init_xdisp and resized as needed in store_frame_title_char. */
6080 static char *frame_title_buf
;
6082 /* The buffer's end, and a current output position in it. */
6084 static char *frame_title_buf_end
;
6085 static char *frame_title_ptr
;
6088 /* Store a single character C for the frame title in frame_title_buf.
6089 Re-allocate frame_title_buf if necessary. */
6092 store_frame_title_char (c
)
6095 /* If output position has reached the end of the allocated buffer,
6096 double the buffer's size. */
6097 if (frame_title_ptr
== frame_title_buf_end
)
6099 int len
= frame_title_ptr
- frame_title_buf
;
6100 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6101 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6102 frame_title_buf_end
= frame_title_buf
+ new_size
;
6103 frame_title_ptr
= frame_title_buf
+ len
;
6106 *frame_title_ptr
++ = c
;
6110 /* Store part of a frame title in frame_title_buf, beginning at
6111 frame_title_ptr. STR is the string to store. Do not copy more
6112 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
6113 the whole string. Pad with spaces until FIELD_WIDTH number of
6114 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
6115 Called from display_mode_element when it is used to build a frame
6119 store_frame_title (str
, field_width
, precision
)
6121 int field_width
, precision
;
6125 /* Copy at most PRECISION chars from STR. */
6126 while ((precision
<= 0 || n
< precision
)
6129 store_frame_title_char (*str
++);
6133 /* Fill up with spaces until FIELD_WIDTH reached. */
6134 while (field_width
> 0
6137 store_frame_title_char (' ');
6145 /* Set the title of FRAME, if it has changed. The title format is
6146 Vicon_title_format if FRAME is iconified, otherwise it is
6147 frame_title_format. */
6150 x_consider_frame_title (frame
)
6153 struct frame
*f
= XFRAME (frame
);
6155 if (FRAME_WINDOW_P (f
)
6156 || FRAME_MINIBUF_ONLY_P (f
)
6157 || f
->explicit_name
)
6159 /* Do we have more than one visible frame on this X display? */
6162 struct buffer
*obuf
;
6166 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
6168 struct frame
*tf
= XFRAME (XCAR (tail
));
6171 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
6172 && !FRAME_MINIBUF_ONLY_P (tf
)
6173 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
6177 /* Set global variable indicating that multiple frames exist. */
6178 multiple_frames
= CONSP (tail
);
6180 /* Switch to the buffer of selected window of the frame. Set up
6181 frame_title_ptr so that display_mode_element will output into it;
6182 then display the title. */
6183 obuf
= current_buffer
;
6184 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
6185 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
6186 frame_title_ptr
= frame_title_buf
;
6187 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
6188 NULL
, DEFAULT_FACE_ID
);
6189 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
6190 frame_title_ptr
= NULL
;
6191 set_buffer_internal (obuf
);
6193 /* Set the title only if it's changed. This avoids consing in
6194 the common case where it hasn't. (If it turns out that we've
6195 already wasted too much time by walking through the list with
6196 display_mode_element, then we might need to optimize at a
6197 higher level than this.) */
6198 if (! STRINGP (f
->name
)
6199 || STRING_BYTES (XSTRING (f
->name
)) != len
6200 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
6201 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
6205 #else /* not HAVE_WINDOW_SYSTEM */
6207 #define frame_title_ptr ((char *)0)
6208 #define store_frame_title(str, mincol, maxcol) 0
6210 #endif /* not HAVE_WINDOW_SYSTEM */
6215 /***********************************************************************
6217 ***********************************************************************/
6220 /* Prepare for redisplay by updating menu-bar item lists when
6221 appropriate. This can call eval. */
6224 prepare_menu_bars ()
6227 struct gcpro gcpro1
, gcpro2
;
6229 struct frame
*tooltip_frame
;
6231 #ifdef HAVE_X_WINDOWS
6232 tooltip_frame
= tip_frame
;
6234 tooltip_frame
= NULL
;
6237 /* Update all frame titles based on their buffer names, etc. We do
6238 this before the menu bars so that the buffer-menu will show the
6239 up-to-date frame titles. */
6240 #ifdef HAVE_WINDOW_SYSTEM
6241 if (windows_or_buffers_changed
|| update_mode_lines
)
6243 Lisp_Object tail
, frame
;
6245 FOR_EACH_FRAME (tail
, frame
)
6248 if (f
!= tooltip_frame
6249 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
6250 x_consider_frame_title (frame
);
6253 #endif /* HAVE_WINDOW_SYSTEM */
6255 /* Update the menu bar item lists, if appropriate. This has to be
6256 done before any actual redisplay or generation of display lines. */
6257 all_windows
= (update_mode_lines
6258 || buffer_shared
> 1
6259 || windows_or_buffers_changed
);
6262 Lisp_Object tail
, frame
;
6263 int count
= specpdl_ptr
- specpdl
;
6265 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6267 FOR_EACH_FRAME (tail
, frame
)
6271 /* Ignore tooltip frame. */
6272 if (f
== tooltip_frame
)
6275 /* If a window on this frame changed size, report that to
6276 the user and clear the size-change flag. */
6277 if (FRAME_WINDOW_SIZES_CHANGED (f
))
6279 Lisp_Object functions
;
6281 /* Clear flag first in case we get an error below. */
6282 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
6283 functions
= Vwindow_size_change_functions
;
6284 GCPRO2 (tail
, functions
);
6286 while (CONSP (functions
))
6288 call1 (XCAR (functions
), frame
);
6289 functions
= XCDR (functions
);
6295 update_menu_bar (f
, 0);
6296 #ifdef HAVE_WINDOW_SYSTEM
6297 update_tool_bar (f
, 0);
6302 unbind_to (count
, Qnil
);
6306 struct frame
*sf
= SELECTED_FRAME ();
6307 update_menu_bar (sf
, 1);
6308 #ifdef HAVE_WINDOW_SYSTEM
6309 update_tool_bar (sf
, 1);
6313 /* Motif needs this. See comment in xmenu.c. Turn it off when
6314 pending_menu_activation is not defined. */
6315 #ifdef USE_X_TOOLKIT
6316 pending_menu_activation
= 0;
6321 /* Update the menu bar item list for frame F. This has to be done
6322 before we start to fill in any display lines, because it can call
6325 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
6328 update_menu_bar (f
, save_match_data
)
6330 int save_match_data
;
6333 register struct window
*w
;
6335 window
= FRAME_SELECTED_WINDOW (f
);
6336 w
= XWINDOW (window
);
6338 if (update_mode_lines
)
6339 w
->update_mode_line
= Qt
;
6341 if (FRAME_WINDOW_P (f
)
6343 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6344 FRAME_EXTERNAL_MENU_BAR (f
)
6346 FRAME_MENU_BAR_LINES (f
) > 0
6348 : FRAME_MENU_BAR_LINES (f
) > 0)
6350 /* If the user has switched buffers or windows, we need to
6351 recompute to reflect the new bindings. But we'll
6352 recompute when update_mode_lines is set too; that means
6353 that people can use force-mode-line-update to request
6354 that the menu bar be recomputed. The adverse effect on
6355 the rest of the redisplay algorithm is about the same as
6356 windows_or_buffers_changed anyway. */
6357 if (windows_or_buffers_changed
6358 || !NILP (w
->update_mode_line
)
6359 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6360 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6361 != !NILP (w
->last_had_star
))
6362 || ((!NILP (Vtransient_mark_mode
)
6363 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6364 != !NILP (w
->region_showing
)))
6366 struct buffer
*prev
= current_buffer
;
6367 int count
= specpdl_ptr
- specpdl
;
6369 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6370 if (save_match_data
)
6371 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6372 if (NILP (Voverriding_local_map_menu_flag
))
6374 specbind (Qoverriding_terminal_local_map
, Qnil
);
6375 specbind (Qoverriding_local_map
, Qnil
);
6378 /* Run the Lucid hook. */
6379 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
6381 /* If it has changed current-menubar from previous value,
6382 really recompute the menu-bar from the value. */
6383 if (! NILP (Vlucid_menu_bar_dirty_flag
))
6384 call0 (Qrecompute_lucid_menubar
);
6386 safe_run_hooks (Qmenu_bar_update_hook
);
6387 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
6389 /* Redisplay the menu bar in case we changed it. */
6390 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6391 if (FRAME_WINDOW_P (f
))
6392 set_frame_menubar (f
, 0, 0);
6394 /* On a terminal screen, the menu bar is an ordinary screen
6395 line, and this makes it get updated. */
6396 w
->update_mode_line
= Qt
;
6397 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6398 /* In the non-toolkit version, the menu bar is an ordinary screen
6399 line, and this makes it get updated. */
6400 w
->update_mode_line
= Qt
;
6401 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6403 unbind_to (count
, Qnil
);
6404 set_buffer_internal_1 (prev
);
6411 /***********************************************************************
6413 ***********************************************************************/
6415 #ifdef HAVE_WINDOW_SYSTEM
6417 /* Update the tool-bar item list for frame F. This has to be done
6418 before we start to fill in any display lines. Called from
6419 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
6420 and restore it here. */
6423 update_tool_bar (f
, save_match_data
)
6425 int save_match_data
;
6427 if (WINDOWP (f
->tool_bar_window
)
6428 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
6433 window
= FRAME_SELECTED_WINDOW (f
);
6434 w
= XWINDOW (window
);
6436 /* If the user has switched buffers or windows, we need to
6437 recompute to reflect the new bindings. But we'll
6438 recompute when update_mode_lines is set too; that means
6439 that people can use force-mode-line-update to request
6440 that the menu bar be recomputed. The adverse effect on
6441 the rest of the redisplay algorithm is about the same as
6442 windows_or_buffers_changed anyway. */
6443 if (windows_or_buffers_changed
6444 || !NILP (w
->update_mode_line
)
6445 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6446 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6447 != !NILP (w
->last_had_star
))
6448 || ((!NILP (Vtransient_mark_mode
)
6449 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6450 != !NILP (w
->region_showing
)))
6452 struct buffer
*prev
= current_buffer
;
6453 int count
= specpdl_ptr
- specpdl
;
6455 /* Set current_buffer to the buffer of the selected
6456 window of the frame, so that we get the right local
6458 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6460 /* Save match data, if we must. */
6461 if (save_match_data
)
6462 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6464 /* Make sure that we don't accidentally use bogus keymaps. */
6465 if (NILP (Voverriding_local_map_menu_flag
))
6467 specbind (Qoverriding_terminal_local_map
, Qnil
);
6468 specbind (Qoverriding_local_map
, Qnil
);
6471 /* Build desired tool-bar items from keymaps. */
6472 f
->desired_tool_bar_items
6473 = tool_bar_items (f
->desired_tool_bar_items
,
6474 &f
->n_desired_tool_bar_items
);
6476 /* Redisplay the tool-bar in case we changed it. */
6477 w
->update_mode_line
= Qt
;
6479 unbind_to (count
, Qnil
);
6480 set_buffer_internal_1 (prev
);
6486 /* Set F->desired_tool_bar_string to a Lisp string representing frame
6487 F's desired tool-bar contents. F->desired_tool_bar_items must have
6488 been set up previously by calling prepare_menu_bars. */
6491 build_desired_tool_bar_string (f
)
6494 int i
, size
, size_needed
, string_idx
;
6495 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6496 Lisp_Object image
, plist
, props
;
6498 image
= plist
= props
= Qnil
;
6499 GCPRO3 (image
, plist
, props
);
6501 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
6502 Otherwise, make a new string. */
6504 /* The size of the string we might be able to reuse. */
6505 size
= (STRINGP (f
->desired_tool_bar_string
)
6506 ? XSTRING (f
->desired_tool_bar_string
)->size
6509 /* Each image in the string we build is preceded by a space,
6510 and there is a space at the end. */
6511 size_needed
= f
->n_desired_tool_bar_items
+ 1;
6513 /* Reuse f->desired_tool_bar_string, if possible. */
6514 if (size
< size_needed
)
6515 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
6519 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
6520 Fremove_text_properties (make_number (0), make_number (size
),
6521 props
, f
->desired_tool_bar_string
);
6524 /* Put a `display' property on the string for the images to display,
6525 put a `menu_item' property on tool-bar items with a value that
6526 is the index of the item in F's tool-bar item vector. */
6527 for (i
= 0, string_idx
= 0;
6528 i
< f
->n_desired_tool_bar_items
;
6529 ++i
, string_idx
+= 1)
6532 (XVECTOR (f->desired_tool_bar_items) \
6533 ->contents[i * TOOL_BAR_ITEM_NSLOTS + (IDX)])
6535 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
6536 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
6538 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
6539 extern Lisp_Object Qlaplace
;
6541 /* If image is a vector, choose the image according to the
6543 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
6544 if (VECTORP (image
))
6546 enum tool_bar_item_image idx
;
6550 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
6551 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
6554 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
6555 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
6557 xassert (XVECTOR (image
)->size
>= idx
);
6558 image
= XVECTOR (image
)->contents
[idx
];
6561 /* Ignore invalid image specifications. */
6562 if (!valid_image_p (image
))
6565 /* Display the tool-bar button pressed, or depressed. */
6566 plist
= Fcopy_sequence (XCDR (image
));
6568 /* Compute margin and relief to draw. */
6569 relief
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
6570 margin
= relief
+ max (0, tool_bar_button_margin
);
6572 if (auto_raise_tool_bar_buttons_p
)
6574 /* Add a `:relief' property to the image spec if the item is
6578 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
6584 /* If image is selected, display it pressed, i.e. with a
6585 negative relief. If it's not selected, display it with a
6587 plist
= Fplist_put (plist
, QCrelief
,
6589 ? make_number (-relief
)
6590 : make_number (relief
)));
6594 /* Put a margin around the image. */
6596 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
6598 /* If button is not enabled, make the image appear disabled by
6599 applying an appropriate algorithm to it. */
6601 plist
= Fplist_put (plist
, QCalgorithm
, Qlaplace
);
6603 /* Put a `display' text property on the string for the image to
6604 display. Put a `menu-item' property on the string that gives
6605 the start of this item's properties in the tool-bar items
6607 image
= Fcons (Qimage
, plist
);
6608 props
= list4 (Qdisplay
, image
,
6609 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
)),
6610 Fadd_text_properties (make_number (string_idx
),
6611 make_number (string_idx
+ 1),
6612 props
, f
->desired_tool_bar_string
);
6620 /* Display one line of the tool-bar of frame IT->f. */
6623 display_tool_bar_line (it
)
6626 struct glyph_row
*row
= it
->glyph_row
;
6627 int max_x
= it
->last_visible_x
;
6630 prepare_desired_row (row
);
6631 row
->y
= it
->current_y
;
6633 while (it
->current_x
< max_x
)
6635 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
6637 /* Get the next display element. */
6638 if (!get_next_display_element (it
))
6641 /* Produce glyphs. */
6642 x_before
= it
->current_x
;
6643 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
6644 PRODUCE_GLYPHS (it
);
6646 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
6651 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
6653 if (x
+ glyph
->pixel_width
> max_x
)
6655 /* Glyph doesn't fit on line. */
6656 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
6662 x
+= glyph
->pixel_width
;
6666 /* Stop at line ends. */
6667 if (ITERATOR_AT_END_OF_LINE_P (it
))
6670 set_iterator_to_next (it
);
6675 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
6676 extend_face_to_end_of_line (it
);
6677 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
6678 last
->right_box_line_p
= 1;
6679 compute_line_metrics (it
);
6681 /* If line is empty, make it occupy the rest of the tool-bar. */
6682 if (!row
->displays_text_p
)
6684 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
6685 row
->ascent
= row
->phys_ascent
= 0;
6688 row
->full_width_p
= 1;
6689 row
->continued_p
= 0;
6690 row
->truncated_on_left_p
= 0;
6691 row
->truncated_on_right_p
= 0;
6693 it
->current_x
= it
->hpos
= 0;
6694 it
->current_y
+= row
->height
;
6700 /* Value is the number of screen lines needed to make all tool-bar
6701 items of frame F visible. */
6704 tool_bar_lines_needed (f
)
6707 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6710 /* Initialize an iterator for iteration over
6711 F->desired_tool_bar_string in the tool-bar window of frame F. */
6712 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
6713 it
.first_visible_x
= 0;
6714 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6715 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
6717 while (!ITERATOR_AT_END_P (&it
))
6719 it
.glyph_row
= w
->desired_matrix
->rows
;
6720 clear_glyph_row (it
.glyph_row
);
6721 display_tool_bar_line (&it
);
6724 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
6728 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
6729 height should be changed. */
6732 redisplay_tool_bar (f
)
6737 struct glyph_row
*row
;
6738 int change_height_p
= 0;
6740 /* If frame hasn't a tool-bar window or if it is zero-height, don't
6741 do anything. This means you must start with tool-bar-lines
6742 non-zero to get the auto-sizing effect. Or in other words, you
6743 can turn off tool-bars by specifying tool-bar-lines zero. */
6744 if (!WINDOWP (f
->tool_bar_window
)
6745 || (w
= XWINDOW (f
->tool_bar_window
),
6746 XFASTINT (w
->height
) == 0))
6749 /* Set up an iterator for the tool-bar window. */
6750 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
6751 it
.first_visible_x
= 0;
6752 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6755 /* Build a string that represents the contents of the tool-bar. */
6756 build_desired_tool_bar_string (f
);
6757 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
6759 /* Display as many lines as needed to display all tool-bar items. */
6760 while (it
.current_y
< it
.last_visible_y
)
6761 display_tool_bar_line (&it
);
6763 /* It doesn't make much sense to try scrolling in the tool-bar
6764 window, so don't do it. */
6765 w
->desired_matrix
->no_scrolling_p
= 1;
6766 w
->must_be_updated_p
= 1;
6768 if (auto_resize_tool_bars_p
)
6772 /* If there are blank lines at the end, except for a partially
6773 visible blank line at the end that is smaller than
6774 CANON_Y_UNIT, change the tool-bar's height. */
6775 row
= it
.glyph_row
- 1;
6776 if (!row
->displays_text_p
6777 && row
->height
>= CANON_Y_UNIT (f
))
6778 change_height_p
= 1;
6780 /* If row displays tool-bar items, but is partially visible,
6781 change the tool-bar's height. */
6782 if (row
->displays_text_p
6783 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
6784 change_height_p
= 1;
6786 /* Resize windows as needed by changing the `tool-bar-lines'
6789 && (nlines
= tool_bar_lines_needed (f
),
6790 nlines
!= XFASTINT (w
->height
)))
6792 extern Lisp_Object Qtool_bar_lines
;
6795 XSETFRAME (frame
, f
);
6796 clear_glyph_matrix (w
->desired_matrix
);
6797 Fmodify_frame_parameters (frame
,
6798 Fcons (Fcons (Qtool_bar_lines
,
6799 make_number (nlines
)),
6801 fonts_changed_p
= 1;
6805 return change_height_p
;
6809 /* Get information about the tool-bar item which is displayed in GLYPH
6810 on frame F. Return in *PROP_IDX the index where tool-bar item
6811 properties start in F->current_tool_bar_items. Value is zero if
6812 GLYPH doesn't display a tool-bar item. */
6815 tool_bar_item_info (f
, glyph
, prop_idx
)
6817 struct glyph
*glyph
;
6823 /* Get the text property `menu-item' at pos. The value of that
6824 property is the start index of this item's properties in
6825 F->current_tool_bar_items. */
6826 prop
= Fget_text_property (make_number (glyph
->charpos
),
6827 Qmenu_item
, f
->current_tool_bar_string
);
6828 if (INTEGERP (prop
))
6830 *prop_idx
= XINT (prop
);
6839 #endif /* HAVE_WINDOW_SYSTEM */
6843 /************************************************************************
6844 Horizontal scrolling
6845 ************************************************************************/
6847 static int hscroll_window_tree
P_ ((Lisp_Object
));
6848 static int hscroll_windows
P_ ((Lisp_Object
));
6850 /* For all leaf windows in the window tree rooted at WINDOW, set their
6851 hscroll value so that PT is (i) visible in the window, and (ii) so
6852 that it is not within a certain margin at the window's left and
6853 right border. Value is non-zero if any window's hscroll has been
6857 hscroll_window_tree (window
)
6860 int hscrolled_p
= 0;
6862 while (WINDOWP (window
))
6864 struct window
*w
= XWINDOW (window
);
6866 if (WINDOWP (w
->hchild
))
6867 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
6868 else if (WINDOWP (w
->vchild
))
6869 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
6870 else if (w
->cursor
.vpos
>= 0)
6872 int hscroll_margin
, text_area_x
, text_area_y
;
6873 int text_area_width
, text_area_height
;
6874 struct glyph_row
*current_cursor_row
6875 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
6876 struct glyph_row
*desired_cursor_row
6877 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
6878 struct glyph_row
*cursor_row
6879 = (desired_cursor_row
->enabled_p
6880 ? desired_cursor_row
6881 : current_cursor_row
);
6883 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
6884 &text_area_width
, &text_area_height
);
6886 /* Scroll when cursor is inside this scroll margin. */
6887 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
6889 if ((XFASTINT (w
->hscroll
)
6890 && w
->cursor
.x
< hscroll_margin
)
6891 || (cursor_row
->enabled_p
6892 && cursor_row
->truncated_on_right_p
6893 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
6897 struct buffer
*saved_current_buffer
;
6900 /* Find point in a display of infinite width. */
6901 saved_current_buffer
= current_buffer
;
6902 current_buffer
= XBUFFER (w
->buffer
);
6904 if (w
== XWINDOW (selected_window
))
6905 pt
= BUF_PT (current_buffer
);
6908 pt
= marker_position (w
->pointm
);
6909 pt
= max (BEGV
, pt
);
6913 /* Move iterator to pt starting at cursor_row->start in
6914 a line with infinite width. */
6915 init_to_row_start (&it
, w
, cursor_row
);
6916 it
.last_visible_x
= INFINITY
;
6917 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
6918 current_buffer
= saved_current_buffer
;
6920 /* Center cursor in window. */
6921 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
6922 / CANON_X_UNIT (it
.f
));
6924 /* Don't call Fset_window_hscroll if value hasn't
6925 changed because it will prevent redisplay
6927 if (XFASTINT (w
->hscroll
) != hscroll
)
6929 Fset_window_hscroll (window
, make_number (hscroll
));
6938 /* Value is non-zero if hscroll of any leaf window has been changed. */
6943 /* Set hscroll so that cursor is visible and not inside horizontal
6944 scroll margins for all windows in the tree rooted at WINDOW. See
6945 also hscroll_window_tree above. Value is non-zero if any window's
6946 hscroll has been changed. If it has, desired matrices on the frame
6947 of WINDOW are cleared. */
6950 hscroll_windows (window
)
6955 if (automatic_hscrolling_p
)
6957 hscrolled_p
= hscroll_window_tree (window
);
6959 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
6968 /************************************************************************
6970 ************************************************************************/
6972 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
6973 to a non-zero value. This is sometimes handy to have in a debugger
6978 /* First and last unchanged row for try_window_id. */
6980 int debug_first_unchanged_at_end_vpos
;
6981 int debug_last_unchanged_at_beg_vpos
;
6983 /* Delta vpos and y. */
6985 int debug_dvpos
, debug_dy
;
6987 /* Delta in characters and bytes for try_window_id. */
6989 int debug_delta
, debug_delta_bytes
;
6991 /* Values of window_end_pos and window_end_vpos at the end of
6994 int debug_end_pos
, debug_end_vpos
;
6996 /* Append a string to W->desired_matrix->method. FMT is a printf
6997 format string. A1...A9 are a supplement for a variable-length
6998 argument list. If trace_redisplay_p is non-zero also printf the
6999 resulting string to stderr. */
7002 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
7005 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
7008 char *method
= w
->desired_matrix
->method
;
7009 int len
= strlen (method
);
7010 int size
= sizeof w
->desired_matrix
->method
;
7011 int remaining
= size
- len
- 1;
7013 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
7014 if (len
&& remaining
)
7020 strncpy (method
+ len
, buffer
, remaining
);
7022 if (trace_redisplay_p
)
7023 fprintf (stderr
, "%p (%s): %s\n",
7025 ((BUFFERP (w
->buffer
)
7026 && STRINGP (XBUFFER (w
->buffer
)->name
))
7027 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
7032 #endif /* GLYPH_DEBUG */
7035 /* This counter is used to clear the face cache every once in a while
7036 in redisplay_internal. It is incremented for each redisplay.
7037 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
7040 #define CLEAR_FACE_CACHE_COUNT 10000
7041 static int clear_face_cache_count
;
7043 /* Record the previous terminal frame we displayed. */
7045 static struct frame
*previous_terminal_frame
;
7047 /* Non-zero while redisplay_internal is in progress. */
7052 /* Value is non-zero if all changes in window W, which displays
7053 current_buffer, are in the text between START and END. START is a
7054 buffer position, END is given as a distance from Z. Used in
7055 redisplay_internal for display optimization. */
7058 text_outside_line_unchanged_p (w
, start
, end
)
7062 int unchanged_p
= 1;
7064 /* If text or overlays have changed, see where. */
7065 if (XFASTINT (w
->last_modified
) < MODIFF
7066 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7068 /* Gap in the line? */
7069 if (GPT
< start
|| Z
- GPT
< end
)
7072 /* Changes start in front of the line, or end after it? */
7074 && (BEG_UNCHANGED
< start
- 1
7075 || END_UNCHANGED
< end
))
7078 /* If selective display, can't optimize if changes start at the
7079 beginning of the line. */
7081 && INTEGERP (current_buffer
->selective_display
)
7082 && XINT (current_buffer
->selective_display
) > 0
7083 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
7091 /* Do a frame update, taking possible shortcuts into account. This is
7092 the main external entry point for redisplay.
7094 If the last redisplay displayed an echo area message and that message
7095 is no longer requested, we clear the echo area or bring back the
7096 mini-buffer if that is in use. */
7101 redisplay_internal (0);
7104 /* Return 1 if point moved out of or into a composition. Otherwise
7105 return 0. PREV_BUF and PREV_PT are the last point buffer and
7106 position. BUF and PT are the current point buffer and position. */
7109 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
7110 struct buffer
*prev_buf
, *buf
;
7117 XSETBUFFER (buffer
, buf
);
7118 /* Check a composition at the last point if point moved within the
7120 if (prev_buf
== buf
)
7123 /* Point didn't move. */
7126 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
7127 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
7128 && COMPOSITION_VALID_P (start
, end
, prop
)
7129 && start
< prev_pt
&& end
> prev_pt
)
7130 /* The last point was within the composition. Return 1 iff
7131 point moved out of the composition. */
7132 return (pt
<= start
|| pt
>= end
);
7135 /* Check a composition at the current point. */
7136 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
7137 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
7138 && COMPOSITION_VALID_P (start
, end
, prop
)
7139 && start
< pt
&& end
> pt
);
7142 /* Reconsider the setting of B->clip_changed which is displayed
7146 reconsider_clip_changes (w
, b
)
7150 if (b
->prevent_redisplay_optimizations_p
)
7151 b
->clip_changed
= 1;
7152 else if (b
->clip_changed
7153 && !NILP (w
->window_end_valid
)
7154 && w
->current_matrix
->buffer
== b
7155 && w
->current_matrix
->zv
== BUF_ZV (b
)
7156 && w
->current_matrix
->begv
== BUF_BEGV (b
))
7157 b
->clip_changed
= 0;
7159 /* If display wasn't paused, and W is not a tool bar window, see if
7160 point has been moved into or out of a composition. In that case,
7161 we set b->clip_changed to 1 to force updating the screen. If
7162 b->clip_changed has already been set to 1, we can skip this
7164 if (!b
->clip_changed
7165 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
7169 if (w
== XWINDOW (selected_window
))
7170 pt
= BUF_PT (current_buffer
);
7172 pt
= marker_position (w
->pointm
);
7174 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
7175 || pt
!= XINT (w
->last_point
))
7176 && check_point_in_composition (w
->current_matrix
->buffer
,
7177 XINT (w
->last_point
),
7178 XBUFFER (w
->buffer
), pt
))
7179 b
->clip_changed
= 1;
7184 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
7185 response to any user action; therefore, we should preserve the echo
7186 area. (Actually, our caller does that job.) Perhaps in the future
7187 avoid recentering windows if it is not necessary; currently that
7188 causes some problems. */
7191 redisplay_internal (preserve_echo_area
)
7192 int preserve_echo_area
;
7194 struct window
*w
= XWINDOW (selected_window
);
7195 struct frame
*f
= XFRAME (w
->frame
);
7197 int must_finish
= 0;
7198 struct text_pos tlbufpos
, tlendpos
;
7199 int number_of_visible_frames
;
7201 struct frame
*sf
= SELECTED_FRAME ();
7203 /* Non-zero means redisplay has to consider all windows on all
7204 frames. Zero means, only selected_window is considered. */
7205 int consider_all_windows_p
;
7207 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
7209 /* No redisplay if running in batch mode or frame is not yet fully
7210 initialized, or redisplay is explicitly turned off by setting
7211 Vinhibit_redisplay. */
7213 || !NILP (Vinhibit_redisplay
)
7214 || !f
->glyphs_initialized_p
)
7217 /* The flag redisplay_performed_directly_p is set by
7218 direct_output_for_insert when it already did the whole screen
7219 update necessary. */
7220 if (redisplay_performed_directly_p
)
7222 redisplay_performed_directly_p
= 0;
7223 if (!hscroll_windows (selected_window
))
7227 #ifdef USE_X_TOOLKIT
7228 if (popup_activated ())
7232 /* I don't think this happens but let's be paranoid. */
7236 /* Record a function that resets redisplaying_p to its old value
7237 when we leave this function. */
7238 count
= specpdl_ptr
- specpdl
;
7239 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
7244 reconsider_clip_changes (w
, current_buffer
);
7246 /* If new fonts have been loaded that make a glyph matrix adjustment
7247 necessary, do it. */
7248 if (fonts_changed_p
)
7250 adjust_glyphs (NULL
);
7251 ++windows_or_buffers_changed
;
7252 fonts_changed_p
= 0;
7255 if (! FRAME_WINDOW_P (sf
)
7256 && previous_terminal_frame
!= sf
)
7258 /* Since frames on an ASCII terminal share the same display
7259 area, displaying a different frame means redisplay the whole
7261 windows_or_buffers_changed
++;
7262 SET_FRAME_GARBAGED (sf
);
7263 XSETFRAME (Vterminal_frame
, sf
);
7265 previous_terminal_frame
= sf
;
7267 /* Set the visible flags for all frames. Do this before checking
7268 for resized or garbaged frames; they want to know if their frames
7269 are visible. See the comment in frame.h for
7270 FRAME_SAMPLE_VISIBILITY. */
7272 Lisp_Object tail
, frame
;
7274 number_of_visible_frames
= 0;
7276 FOR_EACH_FRAME (tail
, frame
)
7278 struct frame
*f
= XFRAME (frame
);
7280 FRAME_SAMPLE_VISIBILITY (f
);
7281 if (FRAME_VISIBLE_P (f
))
7282 ++number_of_visible_frames
;
7283 clear_desired_matrices (f
);
7287 /* Notice any pending interrupt request to change frame size. */
7288 do_pending_window_change (1);
7290 /* Clear frames marked as garbaged. */
7292 clear_garbaged_frames ();
7294 /* Build menubar and tool-bar items. */
7295 prepare_menu_bars ();
7297 if (windows_or_buffers_changed
)
7298 update_mode_lines
++;
7300 /* Detect case that we need to write or remove a star in the mode line. */
7301 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
7303 w
->update_mode_line
= Qt
;
7304 if (buffer_shared
> 1)
7305 update_mode_lines
++;
7308 /* If %c is in the mode line, update it if needed. */
7309 if (!NILP (w
->column_number_displayed
)
7310 /* This alternative quickly identifies a common case
7311 where no change is needed. */
7312 && !(PT
== XFASTINT (w
->last_point
)
7313 && XFASTINT (w
->last_modified
) >= MODIFF
7314 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7315 && XFASTINT (w
->column_number_displayed
) != current_column ())
7316 w
->update_mode_line
= Qt
;
7318 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
7320 /* The variable buffer_shared is set in redisplay_window and
7321 indicates that we redisplay a buffer in different windows. See
7323 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
7325 /* If specs for an arrow have changed, do thorough redisplay
7326 to ensure we remove any arrow that should no longer exist. */
7327 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
7328 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
7329 consider_all_windows_p
= windows_or_buffers_changed
= 1;
7331 /* Normally the message* functions will have already displayed and
7332 updated the echo area, but the frame may have been trashed, or
7333 the update may have been preempted, so display the echo area
7334 again here. Checking both message buffers captures the case that
7335 the echo area should be cleared. */
7336 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
7338 int window_height_changed_p
= echo_area_display (0);
7341 if (fonts_changed_p
)
7343 else if (window_height_changed_p
)
7345 consider_all_windows_p
= 1;
7346 ++update_mode_lines
;
7347 ++windows_or_buffers_changed
;
7349 /* If window configuration was changed, frames may have been
7350 marked garbaged. Clear them or we will experience
7351 surprises wrt scrolling. */
7353 clear_garbaged_frames ();
7356 else if (w
== XWINDOW (minibuf_window
)
7357 && (current_buffer
->clip_changed
7358 || XFASTINT (w
->last_modified
) < MODIFF
7359 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7360 && resize_mini_window (w
, 0))
7362 /* Resized active mini-window to fit the size of what it is
7363 showing if its contents might have changed. */
7365 consider_all_windows_p
= 1;
7366 ++windows_or_buffers_changed
;
7367 ++update_mode_lines
;
7369 /* If window configuration was changed, frames may have been
7370 marked garbaged. Clear them or we will experience
7371 surprises wrt scrolling. */
7373 clear_garbaged_frames ();
7377 /* If showing the region, and mark has changed, we must redisplay
7378 the whole window. The assignment to this_line_start_pos prevents
7379 the optimization directly below this if-statement. */
7380 if (((!NILP (Vtransient_mark_mode
)
7381 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7382 != !NILP (w
->region_showing
))
7383 || (!NILP (w
->region_showing
)
7384 && !EQ (w
->region_showing
,
7385 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
7386 CHARPOS (this_line_start_pos
) = 0;
7388 /* Optimize the case that only the line containing the cursor in the
7389 selected window has changed. Variables starting with this_ are
7390 set in display_line and record information about the line
7391 containing the cursor. */
7392 tlbufpos
= this_line_start_pos
;
7393 tlendpos
= this_line_end_pos
;
7394 if (!consider_all_windows_p
7395 && CHARPOS (tlbufpos
) > 0
7396 && NILP (w
->update_mode_line
)
7397 && !current_buffer
->clip_changed
7398 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
7399 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
7400 /* Make sure recorded data applies to current buffer, etc. */
7401 && this_line_buffer
== current_buffer
7402 && current_buffer
== XBUFFER (w
->buffer
)
7403 && NILP (w
->force_start
)
7404 /* Point must be on the line that we have info recorded about. */
7405 && PT
>= CHARPOS (tlbufpos
)
7406 && PT
<= Z
- CHARPOS (tlendpos
)
7407 /* All text outside that line, including its final newline,
7408 must be unchanged */
7409 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
7410 CHARPOS (tlendpos
)))
7412 if (CHARPOS (tlbufpos
) > BEGV
7413 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
7414 && (CHARPOS (tlbufpos
) == ZV
7415 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
7416 /* Former continuation line has disappeared by becoming empty */
7418 else if (XFASTINT (w
->last_modified
) < MODIFF
7419 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
7420 || MINI_WINDOW_P (w
))
7422 /* We have to handle the case of continuation around a
7423 wide-column character (See the comment in indent.c around
7426 For instance, in the following case:
7428 -------- Insert --------
7429 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
7430 J_I_ ==> J_I_ `^^' are cursors.
7434 As we have to redraw the line above, we should goto cancel. */
7437 int line_height_before
= this_line_pixel_height
;
7439 /* Note that start_display will handle the case that the
7440 line starting at tlbufpos is a continuation lines. */
7441 start_display (&it
, w
, tlbufpos
);
7443 /* Implementation note: It this still necessary? */
7444 if (it
.current_x
!= this_line_start_x
)
7447 TRACE ((stderr
, "trying display optimization 1\n"));
7448 w
->cursor
.vpos
= -1;
7449 overlay_arrow_seen
= 0;
7450 it
.vpos
= this_line_vpos
;
7451 it
.current_y
= this_line_y
;
7452 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
7455 /* If line contains point, is not continued,
7456 and ends at same distance from eob as before, we win */
7457 if (w
->cursor
.vpos
>= 0
7458 /* Line is not continued, otherwise this_line_start_pos
7459 would have been set to 0 in display_line. */
7460 && CHARPOS (this_line_start_pos
)
7461 /* Line ends as before. */
7462 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
7463 /* Line has same height as before. Otherwise other lines
7464 would have to be shifted up or down. */
7465 && this_line_pixel_height
== line_height_before
)
7467 /* If this is not the window's last line, we must adjust
7468 the charstarts of the lines below. */
7469 if (it
.current_y
< it
.last_visible_y
)
7471 struct glyph_row
*row
7472 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
7473 int delta
, delta_bytes
;
7475 if (Z
- CHARPOS (tlendpos
) == ZV
)
7477 /* This line ends at end of (accessible part of)
7478 buffer. There is no newline to count. */
7480 - CHARPOS (tlendpos
)
7481 - MATRIX_ROW_START_CHARPOS (row
));
7482 delta_bytes
= (Z_BYTE
7483 - BYTEPOS (tlendpos
)
7484 - MATRIX_ROW_START_BYTEPOS (row
));
7488 /* This line ends in a newline. Must take
7489 account of the newline and the rest of the
7490 text that follows. */
7492 - CHARPOS (tlendpos
)
7493 - MATRIX_ROW_START_CHARPOS (row
));
7494 delta_bytes
= (Z_BYTE
7495 - BYTEPOS (tlendpos
)
7496 - MATRIX_ROW_START_BYTEPOS (row
));
7499 increment_matrix_positions (w
->current_matrix
,
7501 w
->current_matrix
->nrows
,
7502 delta
, delta_bytes
);
7505 /* If this row displays text now but previously didn't,
7506 or vice versa, w->window_end_vpos may have to be
7508 if ((it
.glyph_row
- 1)->displays_text_p
)
7510 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
7511 XSETINT (w
->window_end_vpos
, this_line_vpos
);
7513 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
7514 && this_line_vpos
> 0)
7515 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
7516 w
->window_end_valid
= Qnil
;
7518 /* Update hint: No need to try to scroll in update_window. */
7519 w
->desired_matrix
->no_scrolling_p
= 1;
7522 *w
->desired_matrix
->method
= 0;
7523 debug_method_add (w
, "optimization 1");
7530 else if (/* Cursor position hasn't changed. */
7531 PT
== XFASTINT (w
->last_point
)
7532 /* Make sure the cursor was last displayed
7533 in this window. Otherwise we have to reposition it. */
7534 && 0 <= w
->cursor
.vpos
7535 && XINT (w
->height
) > w
->cursor
.vpos
)
7539 do_pending_window_change (1);
7541 /* We used to always goto end_of_redisplay here, but this
7542 isn't enough if we have a blinking cursor. */
7543 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
7544 goto end_of_redisplay
;
7548 /* If highlighting the region, or if the cursor is in the echo area,
7549 then we can't just move the cursor. */
7550 else if (! (!NILP (Vtransient_mark_mode
)
7551 && !NILP (current_buffer
->mark_active
))
7552 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7553 || highlight_nonselected_windows
)
7554 && NILP (w
->region_showing
)
7555 && NILP (Vshow_trailing_whitespace
)
7556 && !cursor_in_echo_area
)
7559 struct glyph_row
*row
;
7561 /* Skip from tlbufpos to PT and see where it is. Note that
7562 PT may be in invisible text. If so, we will end at the
7563 next visible position. */
7564 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
7565 NULL
, DEFAULT_FACE_ID
);
7566 it
.current_x
= this_line_start_x
;
7567 it
.current_y
= this_line_y
;
7568 it
.vpos
= this_line_vpos
;
7570 /* The call to move_it_to stops in front of PT, but
7571 moves over before-strings. */
7572 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
7574 if (it
.vpos
== this_line_vpos
7575 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
7578 xassert (this_line_vpos
== it
.vpos
);
7579 xassert (this_line_y
== it
.current_y
);
7580 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
7588 /* Text changed drastically or point moved off of line. */
7589 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
7592 CHARPOS (this_line_start_pos
) = 0;
7593 consider_all_windows_p
|= buffer_shared
> 1;
7594 ++clear_face_cache_count
;
7597 /* Build desired matrices. If consider_all_windows_p is non-zero,
7598 do it for all windows on all frames. Otherwise do it for
7599 selected_window, only. */
7601 if (consider_all_windows_p
)
7603 Lisp_Object tail
, frame
;
7605 /* Clear the face cache eventually. */
7606 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
7608 clear_face_cache (0);
7609 clear_face_cache_count
= 0;
7612 /* Recompute # windows showing selected buffer. This will be
7613 incremented each time such a window is displayed. */
7616 FOR_EACH_FRAME (tail
, frame
)
7618 struct frame
*f
= XFRAME (frame
);
7619 if (FRAME_WINDOW_P (f
) || f
== sf
)
7621 /* Mark all the scroll bars to be removed; we'll redeem
7622 the ones we want when we redisplay their windows. */
7623 if (condemn_scroll_bars_hook
)
7624 (*condemn_scroll_bars_hook
) (f
);
7626 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7627 redisplay_windows (FRAME_ROOT_WINDOW (f
));
7629 /* Any scroll bars which redisplay_windows should have
7630 nuked should now go away. */
7631 if (judge_scroll_bars_hook
)
7632 (*judge_scroll_bars_hook
) (f
);
7636 else if (FRAME_VISIBLE_P (sf
)
7637 && !FRAME_OBSCURED_P (sf
))
7638 redisplay_window (selected_window
, 1);
7641 /* Compare desired and current matrices, perform output. */
7645 /* If fonts changed, display again. */
7646 if (fonts_changed_p
)
7649 /* Prevent various kinds of signals during display update.
7650 stdio is not robust about handling signals,
7651 which can cause an apparent I/O error. */
7652 if (interrupt_input
)
7656 if (consider_all_windows_p
)
7665 /* See if we have to hscroll. */
7666 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7667 if (FRAMEP (XCAR (tail
)))
7669 f
= XFRAME (XCAR (tail
));
7671 if ((FRAME_WINDOW_P (f
)
7673 && FRAME_VISIBLE_P (f
)
7674 && !FRAME_OBSCURED_P (f
)
7675 && hscroll_windows (f
->root_window
))
7682 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7684 if (!FRAMEP (XCAR (tail
)))
7687 f
= XFRAME (XCAR (tail
));
7689 if ((FRAME_WINDOW_P (f
) || f
== sf
)
7690 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7692 /* Mark all windows as to be updated. */
7693 set_window_update_flags (XWINDOW (f
->root_window
), 1);
7694 pause
|= update_frame (f
, 0, 0);
7697 mark_window_display_accurate (f
->root_window
, 1);
7698 if (frame_up_to_date_hook
!= 0)
7699 (*frame_up_to_date_hook
) (f
);
7706 if (FRAME_VISIBLE_P (sf
)
7707 && !FRAME_OBSCURED_P (sf
))
7709 if (hscroll_windows (selected_window
))
7712 XWINDOW (selected_window
)->must_be_updated_p
= 1;
7713 pause
= update_frame (sf
, 0, 0);
7718 /* We may have called echo_area_display at the top of this
7719 function. If the echo area is on another frame, that may
7720 have put text on a frame other than the selected one, so the
7721 above call to update_frame would not have caught it. Catch
7724 Lisp_Object mini_window
;
7725 struct frame
*mini_frame
;
7727 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7728 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7730 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
7732 XWINDOW (mini_window
)->must_be_updated_p
= 1;
7733 pause
|= update_frame (mini_frame
, 0, 0);
7734 if (!pause
&& hscroll_windows (mini_window
))
7740 /* If display was paused because of pending input, make sure we do a
7741 thorough update the next time. */
7744 /* Prevent the optimization at the beginning of
7745 redisplay_internal that tries a single-line update of the
7746 line containing the cursor in the selected window. */
7747 CHARPOS (this_line_start_pos
) = 0;
7749 /* Let the overlay arrow be updated the next time. */
7750 if (!NILP (last_arrow_position
))
7752 last_arrow_position
= Qt
;
7753 last_arrow_string
= Qt
;
7756 /* If we pause after scrolling, some rows in the current
7757 matrices of some windows are not valid. */
7758 if (!WINDOW_FULL_WIDTH_P (w
)
7759 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
7760 update_mode_lines
= 1;
7763 /* Now text on frame agrees with windows, so put info into the
7764 windows for partial redisplay to follow. */
7767 register struct buffer
*b
= XBUFFER (w
->buffer
);
7769 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
7770 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
7771 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
7772 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
7774 if (consider_all_windows_p
)
7775 mark_window_display_accurate (FRAME_ROOT_WINDOW (sf
), 1);
7778 XSETFASTINT (w
->last_point
, BUF_PT (b
));
7779 w
->last_cursor
= w
->cursor
;
7780 w
->last_cursor_off_p
= w
->cursor_off_p
;
7782 b
->clip_changed
= 0;
7783 b
->prevent_redisplay_optimizations_p
= 0;
7784 w
->update_mode_line
= Qnil
;
7785 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
7786 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
7788 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7791 /* Record if we are showing a region, so can make sure to
7792 update it fully at next redisplay. */
7793 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
7794 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7795 || highlight_nonselected_windows
)
7796 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
7797 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
7800 w
->window_end_valid
= w
->buffer
;
7801 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7802 last_arrow_string
= Voverlay_arrow_string
;
7803 if (frame_up_to_date_hook
!= 0)
7804 (*frame_up_to_date_hook
) (sf
);
7806 w
->current_matrix
->buffer
= b
;
7807 w
->current_matrix
->begv
= BUF_BEGV (b
);
7808 w
->current_matrix
->zv
= BUF_ZV (b
);
7811 update_mode_lines
= 0;
7812 windows_or_buffers_changed
= 0;
7815 /* Start SIGIO interrupts coming again. Having them off during the
7816 code above makes it less likely one will discard output, but not
7817 impossible, since there might be stuff in the system buffer here.
7818 But it is much hairier to try to do anything about that. */
7819 if (interrupt_input
)
7823 /* If a frame has become visible which was not before, redisplay
7824 again, so that we display it. Expose events for such a frame
7825 (which it gets when becoming visible) don't call the parts of
7826 redisplay constructing glyphs, so simply exposing a frame won't
7827 display anything in this case. So, we have to display these
7828 frames here explicitly. */
7831 Lisp_Object tail
, frame
;
7834 FOR_EACH_FRAME (tail
, frame
)
7836 int this_is_visible
= 0;
7838 if (XFRAME (frame
)->visible
)
7839 this_is_visible
= 1;
7840 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
7841 if (XFRAME (frame
)->visible
)
7842 this_is_visible
= 1;
7844 if (this_is_visible
)
7848 if (new_count
!= number_of_visible_frames
)
7849 windows_or_buffers_changed
++;
7852 /* Change frame size now if a change is pending. */
7853 do_pending_window_change (1);
7855 /* If we just did a pending size change, or have additional
7856 visible frames, redisplay again. */
7857 if (windows_or_buffers_changed
&& !pause
)
7862 unbind_to (count
, Qnil
);
7866 /* Redisplay, but leave alone any recent echo area message unless
7867 another message has been requested in its place.
7869 This is useful in situations where you need to redisplay but no
7870 user action has occurred, making it inappropriate for the message
7871 area to be cleared. See tracking_off and
7872 wait_reading_process_input for examples of these situations. */
7875 redisplay_preserve_echo_area ()
7877 if (!NILP (echo_area_buffer
[1]))
7879 /* We have a previously displayed message, but no current
7880 message. Redisplay the previous message. */
7881 display_last_displayed_message_p
= 1;
7882 redisplay_internal (1);
7883 display_last_displayed_message_p
= 0;
7886 redisplay_internal (1);
7890 /* Function registered with record_unwind_protect in
7891 redisplay_internal. Clears the flag indicating that a redisplay is
7895 unwind_redisplay (old_redisplaying_p
)
7896 Lisp_Object old_redisplaying_p
;
7898 redisplaying_p
= XFASTINT (old_redisplaying_p
);
7903 /* Mark the display of windows in the window tree rooted at WINDOW as
7904 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
7905 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
7906 the next time redisplay_internal is called. */
7909 mark_window_display_accurate (window
, accurate_p
)
7915 for (; !NILP (window
); window
= w
->next
)
7917 w
= XWINDOW (window
);
7919 if (BUFFERP (w
->buffer
))
7921 struct buffer
*b
= XBUFFER (w
->buffer
);
7923 XSETFASTINT (w
->last_modified
,
7924 accurate_p
? BUF_MODIFF (b
) : 0);
7925 XSETFASTINT (w
->last_overlay_modified
,
7926 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
7927 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
7930 #if 0 /* I don't think this is necessary because display_line does it.
7932 /* Record if we are showing a region, so can make sure to
7933 update it fully at next redisplay. */
7935 = (!NILP (Vtransient_mark_mode
)
7936 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7937 || highlight_nonselected_windows
)
7938 && (!NILP (b
->mark_active
)
7939 ? Fmarker_position (b
->mark
)
7945 b
->clip_changed
= 0;
7946 b
->prevent_redisplay_optimizations_p
= 0;
7947 w
->current_matrix
->buffer
= b
;
7948 w
->current_matrix
->begv
= BUF_BEGV (b
);
7949 w
->current_matrix
->zv
= BUF_ZV (b
);
7950 w
->last_cursor
= w
->cursor
;
7951 w
->last_cursor_off_p
= w
->cursor_off_p
;
7952 if (w
== XWINDOW (selected_window
))
7953 w
->last_point
= make_number (BUF_PT (b
));
7955 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
7959 w
->window_end_valid
= w
->buffer
;
7960 w
->update_mode_line
= Qnil
;
7962 if (!NILP (w
->vchild
))
7963 mark_window_display_accurate (w
->vchild
, accurate_p
);
7964 if (!NILP (w
->hchild
))
7965 mark_window_display_accurate (w
->hchild
, accurate_p
);
7970 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7971 last_arrow_string
= Voverlay_arrow_string
;
7975 /* Force a thorough redisplay the next time by setting
7976 last_arrow_position and last_arrow_string to t, which is
7977 unequal to any useful value of Voverlay_arrow_... */
7978 last_arrow_position
= Qt
;
7979 last_arrow_string
= Qt
;
7984 /* Return value in display table DP (Lisp_Char_Table *) for character
7985 C. Since a display table doesn't have any parent, we don't have to
7986 follow parent. Do not call this function directly but use the
7987 macro DISP_CHAR_VECTOR. */
7990 disp_char_vector (dp
, c
)
7991 struct Lisp_Char_Table
*dp
;
7997 if (SINGLE_BYTE_CHAR_P (c
))
7998 return (dp
->contents
[c
]);
8000 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
8003 else if (code
[2] < 32)
8006 /* Here, the possible range of code[0] (== charset ID) is
8007 128..max_charset. Since the top level char table contains data
8008 for multibyte characters after 256th element, we must increment
8009 code[0] by 128 to get a correct index. */
8011 code
[3] = -1; /* anchor */
8013 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
8015 val
= dp
->contents
[code
[i
]];
8016 if (!SUB_CHAR_TABLE_P (val
))
8017 return (NILP (val
) ? dp
->defalt
: val
);
8020 /* Here, val is a sub char table. We return the default value of
8022 return (dp
->defalt
);
8027 /***********************************************************************
8029 ***********************************************************************/
8031 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
8034 redisplay_windows (window
)
8037 while (!NILP (window
))
8039 struct window
*w
= XWINDOW (window
);
8041 if (!NILP (w
->hchild
))
8042 redisplay_windows (w
->hchild
);
8043 else if (!NILP (w
->vchild
))
8044 redisplay_windows (w
->vchild
);
8046 redisplay_window (window
, 0);
8053 /* Set cursor position of W. PT is assumed to be displayed in ROW.
8054 DELTA is the number of bytes by which positions recorded in ROW
8055 differ from current buffer positions. */
8058 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
8060 struct glyph_row
*row
;
8061 struct glyph_matrix
*matrix
;
8062 int delta
, delta_bytes
, dy
, dvpos
;
8064 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
8065 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
8067 int pt_old
= PT
- delta
;
8069 /* Skip over glyphs not having an object at the start of the row.
8070 These are special glyphs like truncation marks on terminal
8072 if (row
->displays_text_p
)
8074 && INTEGERP (glyph
->object
)
8075 && glyph
->charpos
< 0)
8077 x
+= glyph
->pixel_width
;
8082 && !INTEGERP (glyph
->object
)
8083 && (!BUFFERP (glyph
->object
)
8084 || glyph
->charpos
< pt_old
))
8086 x
+= glyph
->pixel_width
;
8090 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
8092 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
8093 w
->cursor
.y
= row
->y
+ dy
;
8095 if (w
== XWINDOW (selected_window
))
8097 if (!row
->continued_p
8098 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
8101 this_line_buffer
= XBUFFER (w
->buffer
);
8103 CHARPOS (this_line_start_pos
)
8104 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
8105 BYTEPOS (this_line_start_pos
)
8106 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
8108 CHARPOS (this_line_end_pos
)
8109 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
8110 BYTEPOS (this_line_end_pos
)
8111 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
8113 this_line_y
= w
->cursor
.y
;
8114 this_line_pixel_height
= row
->height
;
8115 this_line_vpos
= w
->cursor
.vpos
;
8116 this_line_start_x
= row
->x
;
8119 CHARPOS (this_line_start_pos
) = 0;
8124 /* Run window scroll functions, if any, for WINDOW with new window
8125 start STARTP. Sets the window start of WINDOW to that position.
8127 We assume that the window's buffer is really current. */
8129 static INLINE
struct text_pos
8130 run_window_scroll_functions (window
, startp
)
8132 struct text_pos startp
;
8134 struct window
*w
= XWINDOW (window
);
8135 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
8137 if (current_buffer
!= XBUFFER (w
->buffer
))
8140 if (!NILP (Vwindow_scroll_functions
))
8142 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
8143 make_number (CHARPOS (startp
)));
8144 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8145 /* In case the hook functions switch buffers. */
8146 if (current_buffer
!= XBUFFER (w
->buffer
))
8147 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8154 /* Modify the desired matrix of window W and W->vscroll so that the
8155 line containing the cursor is fully visible. */
8158 make_cursor_line_fully_visible (w
)
8161 struct glyph_matrix
*matrix
;
8162 struct glyph_row
*row
;
8163 int header_line_height
;
8165 /* It's not always possible to find the cursor, e.g, when a window
8166 is full of overlay strings. Don't do anything in that case. */
8167 if (w
->cursor
.vpos
< 0)
8170 matrix
= w
->desired_matrix
;
8171 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
8173 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
)
8174 /* The row may be partially visible at the top because we
8175 already have chosen a vscroll to align the bottom of the
8176 row with the bottom of the window. This happens for rows
8177 taller than the window. */
8178 && row
->y
+ row
->height
< window_box_height (w
))
8180 int dy
= row
->height
- row
->visible_height
;
8183 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8185 else if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w
, row
)
8186 /* The row may be partially visible at the bottom because
8187 we chose a vscroll to align the row's top with the
8188 window's top. This happens for rows taller than the
8190 && row
->y
> WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
))
8192 int dy
= - (row
->height
- row
->visible_height
);
8195 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8198 /* When we change the cursor y-position of the selected window,
8199 change this_line_y as well so that the display optimization for
8200 the cursor line of the selected window in redisplay_internal uses
8201 the correct y-position. */
8202 if (w
== XWINDOW (selected_window
))
8203 this_line_y
= w
->cursor
.y
;
8207 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
8208 non-zero means only WINDOW is redisplayed in redisplay_internal.
8209 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
8210 in redisplay_window to bring a partially visible line into view in
8211 the case that only the cursor has moved.
8215 1 if scrolling succeeded
8217 0 if scrolling didn't find point.
8219 -1 if new fonts have been loaded so that we must interrupt
8220 redisplay, adjust glyph matrices, and try again. */
8223 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
8224 scroll_step
, temp_scroll_step
)
8226 int just_this_one_p
;
8227 int scroll_conservatively
, scroll_step
;
8228 int temp_scroll_step
;
8230 struct window
*w
= XWINDOW (window
);
8231 struct frame
*f
= XFRAME (w
->frame
);
8232 struct text_pos scroll_margin_pos
;
8233 struct text_pos pos
;
8234 struct text_pos startp
;
8236 Lisp_Object window_end
;
8237 int this_scroll_margin
;
8240 int line_height
, rc
;
8241 int amount_to_scroll
= 0;
8242 Lisp_Object aggressive
;
8246 debug_method_add (w
, "try_scrolling");
8249 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8251 /* Compute scroll margin height in pixels. We scroll when point is
8252 within this distance from the top or bottom of the window. */
8253 if (scroll_margin
> 0)
8255 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
8256 this_scroll_margin
*= CANON_Y_UNIT (f
);
8259 this_scroll_margin
= 0;
8261 /* Compute how much we should try to scroll maximally to bring point
8264 scroll_max
= scroll_step
;
8265 else if (scroll_conservatively
)
8266 scroll_max
= scroll_conservatively
;
8267 else if (temp_scroll_step
)
8268 scroll_max
= temp_scroll_step
;
8269 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
8270 || NUMBERP (current_buffer
->scroll_up_aggressively
))
8271 /* We're trying to scroll because of aggressive scrolling
8272 but no scroll_step is set. Choose an arbitrary one. Maybe
8273 there should be a variable for this. */
8277 scroll_max
*= CANON_Y_UNIT (f
);
8279 /* Decide whether we have to scroll down. Start at the window end
8280 and move this_scroll_margin up to find the position of the scroll
8282 window_end
= Fwindow_end (window
, Qt
);
8283 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
8284 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
8285 if (this_scroll_margin
)
8287 start_display (&it
, w
, scroll_margin_pos
);
8288 move_it_vertically (&it
, - this_scroll_margin
);
8289 scroll_margin_pos
= it
.current
.pos
;
8292 if (PT
>= CHARPOS (scroll_margin_pos
))
8296 /* Point is in the scroll margin at the bottom of the window, or
8297 below. Compute a new window start that makes point visible. */
8299 /* Compute the distance from the scroll margin to PT.
8300 Give up if the distance is greater than scroll_max. */
8301 start_display (&it
, w
, scroll_margin_pos
);
8303 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8304 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8305 line_height
= (it
.max_ascent
+ it
.max_descent
8306 ? it
.max_ascent
+ it
.max_descent
8308 dy
= it
.current_y
+ line_height
- y0
;
8309 if (dy
> scroll_max
)
8312 /* Move the window start down. If scrolling conservatively,
8313 move it just enough down to make point visible. If
8314 scroll_step is set, move it down by scroll_step. */
8315 start_display (&it
, w
, startp
);
8317 if (scroll_conservatively
)
8318 amount_to_scroll
= dy
;
8319 else if (scroll_step
|| temp_scroll_step
)
8320 amount_to_scroll
= scroll_max
;
8323 aggressive
= current_buffer
->scroll_down_aggressively
;
8324 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8325 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8326 if (NUMBERP (aggressive
))
8327 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8330 if (amount_to_scroll
<= 0)
8333 move_it_vertically (&it
, amount_to_scroll
);
8334 startp
= it
.current
.pos
;
8338 /* See if point is inside the scroll margin at the top of the
8340 scroll_margin_pos
= startp
;
8341 if (this_scroll_margin
)
8343 start_display (&it
, w
, startp
);
8344 move_it_vertically (&it
, this_scroll_margin
);
8345 scroll_margin_pos
= it
.current
.pos
;
8348 if (PT
< CHARPOS (scroll_margin_pos
))
8350 /* Point is in the scroll margin at the top of the window or
8351 above what is displayed in the window. */
8354 /* Compute the vertical distance from PT to the scroll
8355 margin position. Give up if distance is greater than
8357 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
8358 start_display (&it
, w
, pos
);
8360 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
8361 it
.last_visible_y
, -1,
8362 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8363 dy
= it
.current_y
- y0
;
8364 if (dy
> scroll_max
)
8367 /* Compute new window start. */
8368 start_display (&it
, w
, startp
);
8370 if (scroll_conservatively
)
8371 amount_to_scroll
= dy
;
8372 else if (scroll_step
|| temp_scroll_step
)
8373 amount_to_scroll
= scroll_max
;
8376 aggressive
= current_buffer
->scroll_up_aggressively
;
8377 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8378 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8379 if (NUMBERP (aggressive
))
8380 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8383 if (amount_to_scroll
<= 0)
8386 move_it_vertically (&it
, - amount_to_scroll
);
8387 startp
= it
.current
.pos
;
8391 /* Run window scroll functions. */
8392 startp
= run_window_scroll_functions (window
, startp
);
8394 /* Display the window. Give up if new fonts are loaded, or if point
8396 if (!try_window (window
, startp
))
8398 else if (w
->cursor
.vpos
< 0)
8400 clear_glyph_matrix (w
->desired_matrix
);
8405 /* Maybe forget recorded base line for line number display. */
8406 if (!just_this_one_p
8407 || current_buffer
->clip_changed
8408 || BEG_UNCHANGED
< CHARPOS (startp
))
8409 w
->base_line_number
= Qnil
;
8411 /* If cursor ends up on a partially visible line, shift display
8412 lines up or down. */
8413 make_cursor_line_fully_visible (w
);
8421 /* Compute a suitable window start for window W if display of W starts
8422 on a continuation line. Value is non-zero if a new window start
8425 The new window start will be computed, based on W's width, starting
8426 from the start of the continued line. It is the start of the
8427 screen line with the minimum distance from the old start W->start. */
8430 compute_window_start_on_continuation_line (w
)
8433 struct text_pos pos
, start_pos
;
8434 int window_start_changed_p
= 0;
8436 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
8438 /* If window start is on a continuation line... Window start may be
8439 < BEGV in case there's invisible text at the start of the
8440 buffer (M-x rmail, for example). */
8441 if (CHARPOS (start_pos
) > BEGV
8442 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
8445 struct glyph_row
*row
;
8447 /* Handle the case that the window start is out of range. */
8448 if (CHARPOS (start_pos
) < BEGV
)
8449 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
8450 else if (CHARPOS (start_pos
) > ZV
)
8451 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
8453 /* Find the start of the continued line. This should be fast
8454 because scan_buffer is fast (newline cache). */
8455 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
8456 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
8457 row
, DEFAULT_FACE_ID
);
8458 reseat_at_previous_visible_line_start (&it
);
8460 /* If the line start is "too far" away from the window start,
8461 say it takes too much time to compute a new window start. */
8462 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
8463 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
8465 int min_distance
, distance
;
8467 /* Move forward by display lines to find the new window
8468 start. If window width was enlarged, the new start can
8469 be expected to be > the old start. If window width was
8470 decreased, the new window start will be < the old start.
8471 So, we're looking for the display line start with the
8472 minimum distance from the old window start. */
8473 pos
= it
.current
.pos
;
8474 min_distance
= INFINITY
;
8475 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
8476 distance
< min_distance
)
8478 min_distance
= distance
;
8479 pos
= it
.current
.pos
;
8480 move_it_by_lines (&it
, 1, 0);
8483 /* Set the window start there. */
8484 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
8485 window_start_changed_p
= 1;
8489 return window_start_changed_p
;
8493 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
8494 selected_window is redisplayed. */
8497 redisplay_window (window
, just_this_one_p
)
8499 int just_this_one_p
;
8501 struct window
*w
= XWINDOW (window
);
8502 struct frame
*f
= XFRAME (w
->frame
);
8503 struct buffer
*buffer
= XBUFFER (w
->buffer
);
8504 struct buffer
*old
= current_buffer
;
8505 struct text_pos lpoint
, opoint
, startp
;
8506 int update_mode_line
;
8509 /* Record it now because it's overwritten. */
8510 int current_matrix_up_to_date_p
= 0;
8511 int really_switched_buffer
= 0;
8512 int temp_scroll_step
= 0;
8513 int count
= specpdl_ptr
- specpdl
;
8515 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8518 /* W must be a leaf window here. */
8519 xassert (!NILP (w
->buffer
));
8521 *w
->desired_matrix
->method
= 0;
8524 specbind (Qinhibit_point_motion_hooks
, Qt
);
8526 reconsider_clip_changes (w
, buffer
);
8528 /* Has the mode line to be updated? */
8529 update_mode_line
= (!NILP (w
->update_mode_line
)
8530 || update_mode_lines
8531 || buffer
->clip_changed
);
8533 if (MINI_WINDOW_P (w
))
8535 if (w
== XWINDOW (echo_area_window
)
8536 && !NILP (echo_area_buffer
[0]))
8538 if (update_mode_line
)
8539 /* We may have to update a tty frame's menu bar or a
8540 tool-bar. Example `M-x C-h C-h C-g'. */
8541 goto finish_menu_bars
;
8543 /* We've already displayed the echo area glyphs in this window. */
8544 goto finish_scroll_bars
;
8546 else if (w
!= XWINDOW (minibuf_window
))
8548 /* W is a mini-buffer window, but it's not the currently
8549 active one, so clear it. */
8550 int yb
= window_text_bottom_y (w
);
8551 struct glyph_row
*row
;
8554 for (y
= 0, row
= w
->desired_matrix
->rows
;
8556 y
+= row
->height
, ++row
)
8557 blank_row (w
, row
, y
);
8558 goto finish_scroll_bars
;
8562 /* Otherwise set up data on this window; select its buffer and point
8564 if (update_mode_line
)
8566 /* Really select the buffer, for the sake of buffer-local
8568 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8569 really_switched_buffer
= 1;
8572 set_buffer_temp (XBUFFER (w
->buffer
));
8573 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
8575 current_matrix_up_to_date_p
8576 = (!NILP (w
->window_end_valid
)
8577 && !current_buffer
->clip_changed
8578 && XFASTINT (w
->last_modified
) >= MODIFF
8579 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
8581 /* When windows_or_buffers_changed is non-zero, we can't rely on
8582 the window end being valid, so set it to nil there. */
8583 if (windows_or_buffers_changed
)
8585 /* If window starts on a continuation line, maybe adjust the
8586 window start in case the window's width changed. */
8587 if (XMARKER (w
->start
)->buffer
== current_buffer
)
8588 compute_window_start_on_continuation_line (w
);
8590 w
->window_end_valid
= Qnil
;
8593 /* Some sanity checks. */
8594 CHECK_WINDOW_END (w
);
8595 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
8597 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
8600 /* If %c is in mode line, update it if needed. */
8601 if (!NILP (w
->column_number_displayed
)
8602 /* This alternative quickly identifies a common case
8603 where no change is needed. */
8604 && !(PT
== XFASTINT (w
->last_point
)
8605 && XFASTINT (w
->last_modified
) >= MODIFF
8606 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8607 && XFASTINT (w
->column_number_displayed
) != current_column ())
8608 update_mode_line
= 1;
8610 /* Count number of windows showing the selected buffer. An indirect
8611 buffer counts as its base buffer. */
8612 if (!just_this_one_p
)
8614 struct buffer
*current_base
, *window_base
;
8615 current_base
= current_buffer
;
8616 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
8617 if (current_base
->base_buffer
)
8618 current_base
= current_base
->base_buffer
;
8619 if (window_base
->base_buffer
)
8620 window_base
= window_base
->base_buffer
;
8621 if (current_base
== window_base
)
8625 /* Point refers normally to the selected window. For any other
8626 window, set up appropriate value. */
8627 if (!EQ (window
, selected_window
))
8629 int new_pt
= XMARKER (w
->pointm
)->charpos
;
8630 int new_pt_byte
= marker_byte_position (w
->pointm
);
8634 new_pt_byte
= BEGV_BYTE
;
8635 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
8637 else if (new_pt
> (ZV
- 1))
8640 new_pt_byte
= ZV_BYTE
;
8641 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
8644 /* We don't use SET_PT so that the point-motion hooks don't run. */
8645 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
8648 /* If any of the character widths specified in the display table
8649 have changed, invalidate the width run cache. It's true that
8650 this may be a bit late to catch such changes, but the rest of
8651 redisplay goes (non-fatally) haywire when the display table is
8652 changed, so why should we worry about doing any better? */
8653 if (current_buffer
->width_run_cache
)
8655 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
8657 if (! disptab_matches_widthtab (disptab
,
8658 XVECTOR (current_buffer
->width_table
)))
8660 invalidate_region_cache (current_buffer
,
8661 current_buffer
->width_run_cache
,
8663 recompute_width_table (current_buffer
, disptab
);
8667 /* If window-start is screwed up, choose a new one. */
8668 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
8671 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8673 /* If someone specified a new starting point but did not insist,
8674 check whether it can be used. */
8675 if (!NILP (w
->optional_new_start
)
8676 && CHARPOS (startp
) >= BEGV
8677 && CHARPOS (startp
) <= ZV
)
8679 w
->optional_new_start
= Qnil
;
8680 /* This takes a mini-buffer prompt into account. */
8681 start_display (&it
, w
, startp
);
8682 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8683 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8684 if (IT_CHARPOS (it
) == PT
)
8685 w
->force_start
= Qt
;
8688 /* Handle case where place to start displaying has been specified,
8689 unless the specified location is outside the accessible range. */
8690 if (!NILP (w
->force_start
)
8691 || w
->frozen_window_start_p
)
8693 w
->force_start
= Qnil
;
8695 w
->window_end_valid
= Qnil
;
8697 /* Forget any recorded base line for line number display. */
8698 if (!current_matrix_up_to_date_p
8699 || current_buffer
->clip_changed
)
8700 w
->base_line_number
= Qnil
;
8702 /* Redisplay the mode line. Select the buffer properly for that.
8703 Also, run the hook window-scroll-functions
8704 because we have scrolled. */
8705 /* Note, we do this after clearing force_start because
8706 if there's an error, it is better to forget about force_start
8707 than to get into an infinite loop calling the hook functions
8708 and having them get more errors. */
8709 if (!update_mode_line
8710 || ! NILP (Vwindow_scroll_functions
))
8712 if (!really_switched_buffer
)
8714 set_buffer_temp (old
);
8715 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8716 really_switched_buffer
= 1;
8719 update_mode_line
= 1;
8720 w
->update_mode_line
= Qt
;
8721 startp
= run_window_scroll_functions (window
, startp
);
8724 XSETFASTINT (w
->last_modified
, 0);
8725 XSETFASTINT (w
->last_overlay_modified
, 0);
8726 if (CHARPOS (startp
) < BEGV
)
8727 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
8728 else if (CHARPOS (startp
) > ZV
)
8729 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
8731 /* Redisplay, then check if cursor has been set during the
8732 redisplay. Give up if new fonts were loaded. */
8733 if (!try_window (window
, startp
))
8735 w
->force_start
= Qt
;
8736 clear_glyph_matrix (w
->desired_matrix
);
8737 goto restore_buffers
;
8740 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
8742 /* If point does not appear, or on a line that is not fully
8743 visible, move point so it does appear. The desired
8744 matrix has been built above, so we can use it. */
8745 int height
= window_box_height (w
) / 2;
8746 struct glyph_row
*row
= MATRIX_ROW (w
->desired_matrix
, 0);
8748 while (row
->y
< height
)
8751 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
8752 MATRIX_ROW_START_BYTEPOS (row
));
8754 if (w
!= XWINDOW (selected_window
))
8755 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
8756 else if (current_buffer
== old
)
8757 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8759 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
8761 /* If we are highlighting the region, then we just changed
8762 the region, so redisplay to show it. */
8763 if (!NILP (Vtransient_mark_mode
)
8764 && !NILP (current_buffer
->mark_active
))
8766 clear_glyph_matrix (w
->desired_matrix
);
8767 if (!try_window (window
, startp
))
8768 goto restore_buffers
;
8772 make_cursor_line_fully_visible (w
);
8774 debug_method_add (w
, "forced window start");
8779 /* Handle case where text has not changed, only point, and it has
8780 not moved off the frame. */
8781 if (current_matrix_up_to_date_p
8782 /* Point may be in this window. */
8783 && PT
>= CHARPOS (startp
)
8784 /* If we don't check this, we are called to move the cursor in a
8785 horizontally split window with a current matrix that doesn't
8787 && !windows_or_buffers_changed
8788 /* Selective display hasn't changed. */
8789 && !current_buffer
->clip_changed
8790 /* If force-mode-line-update was called, really redisplay;
8791 that's how redisplay is forced after e.g. changing
8792 buffer-invisibility-spec. */
8793 && NILP (w
->update_mode_line
)
8794 /* Can't use this case if highlighting a region. When a
8795 region exists, cursor movement has to do more than just
8797 && !(!NILP (Vtransient_mark_mode
)
8798 && !NILP (current_buffer
->mark_active
))
8799 && NILP (w
->region_showing
)
8800 && NILP (Vshow_trailing_whitespace
)
8801 /* Right after splitting windows, last_point may be nil. */
8802 && INTEGERP (w
->last_point
)
8803 /* This code is not used for mini-buffer for the sake of the case
8804 of redisplaying to replace an echo area message; since in
8805 that case the mini-buffer contents per se are usually
8806 unchanged. This code is of no real use in the mini-buffer
8807 since the handling of this_line_start_pos, etc., in redisplay
8808 handles the same cases. */
8809 && !EQ (window
, minibuf_window
)
8810 /* When splitting windows or for new windows, it happens that
8811 redisplay is called with a nil window_end_vpos or one being
8812 larger than the window. This should really be fixed in
8813 window.c. I don't have this on my list, now, so we do
8814 approximately the same as the old redisplay code. --gerd. */
8815 && INTEGERP (w
->window_end_vpos
)
8816 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
8817 && (FRAME_WINDOW_P (f
)
8818 || !MARKERP (Voverlay_arrow_position
)
8819 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
8821 int this_scroll_margin
;
8822 struct glyph_row
*row
;
8826 debug_method_add (w
, "cursor movement");
8829 /* Scroll if point within this distance from the top or bottom
8830 of the window. This is a pixel value. */
8831 this_scroll_margin
= max (0, scroll_margin
);
8832 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
8833 this_scroll_margin
*= CANON_Y_UNIT (f
);
8835 /* Start with the row the cursor was displayed during the last
8836 not paused redisplay. Give up if that row is not valid. */
8837 if (w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
8839 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
8840 if (row
->mode_line_p
)
8842 if (!row
->enabled_p
)
8846 if (PT
> XFASTINT (w
->last_point
))
8848 /* Point has moved forward. */
8849 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
8851 while ((MATRIX_ROW_END_CHARPOS (row
) < PT
8852 /* The end position of a row equals the start
8853 position of the next row. If PT is there, we
8854 would rather display it in the next line, except
8855 when this line ends in ZV. */
8856 || (MATRIX_ROW_END_CHARPOS (row
) == PT
8857 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
8858 || !row
->ends_at_zv_p
)))
8859 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
8861 xassert (row
->enabled_p
);
8865 /* If within the scroll margin, scroll. Note that
8866 MATRIX_ROW_BOTTOM_Y gives the pixel position at which the
8867 next line would be drawn, and that this_scroll_margin can
8869 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
8870 || PT
> MATRIX_ROW_END_CHARPOS (row
)
8871 /* Line is completely visible last line in window and PT
8872 is to be set in the next line. */
8873 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
8874 && PT
== MATRIX_ROW_END_CHARPOS (row
)
8875 && !row
->ends_at_zv_p
8876 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
8879 else if (PT
< XFASTINT (w
->last_point
))
8881 /* Cursor has to be moved backward. Note that PT >=
8882 CHARPOS (startp) because of the outer if-statement. */
8883 while (!row
->mode_line_p
8884 && (MATRIX_ROW_START_CHARPOS (row
) > PT
8885 || (MATRIX_ROW_START_CHARPOS (row
) == PT
8886 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
8887 && (row
->y
> this_scroll_margin
8888 || CHARPOS (startp
) == BEGV
))
8890 xassert (row
->enabled_p
);
8894 /* Consider the following case: Window starts at BEGV, there
8895 is invisible, intangible text at BEGV, so that display
8896 starts at some point START > BEGV. It can happen that
8897 we are called with PT somewhere between BEGV and START.
8898 Try to handle that case. */
8899 if (row
< w
->current_matrix
->rows
8900 || row
->mode_line_p
)
8902 row
= w
->current_matrix
->rows
;
8903 if (row
->mode_line_p
)
8907 /* Due to newlines in overlay strings, we may have to skip
8908 forward over overlay strings. */
8909 while (MATRIX_ROW_END_CHARPOS (row
) == PT
8910 && MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P (row
)
8911 && !row
->ends_at_zv_p
)
8914 /* If within the scroll margin, scroll. */
8915 if (row
->y
< this_scroll_margin
8916 && CHARPOS (startp
) != BEGV
)
8920 /* if PT is not in the glyph row, give up. */
8921 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
8922 || PT
> MATRIX_ROW_END_CHARPOS (row
))
8925 /* If we end up in a partially visible line, let's make it fully
8926 visible. This can be done most easily by using the existing
8928 if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8930 temp_scroll_step
= 1;
8936 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8940 /* If current starting point was originally the beginning of a line
8941 but no longer is, find a new starting point. */
8942 else if (!NILP (w
->start_at_line_beg
)
8943 && !(CHARPOS (startp
) <= BEGV
8944 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
8947 debug_method_add (w
, "recenter 1");
8952 /* Try scrolling with try_window_id. */
8953 else if (/* Windows and buffers haven't changed. */
8954 !windows_or_buffers_changed
8955 /* Window must be either use window-based redisplay or
8957 && (FRAME_WINDOW_P (f
)
8958 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
8959 && !MINI_WINDOW_P (w
)
8960 /* Point is not known NOT to appear in window. */
8961 && PT
>= CHARPOS (startp
)
8962 && XFASTINT (w
->last_modified
)
8963 /* Window is not hscrolled. */
8964 && XFASTINT (w
->hscroll
) == 0
8965 /* Selective display has not changed. */
8966 && !current_buffer
->clip_changed
8967 /* Current matrix is up to date. */
8968 && !NILP (w
->window_end_valid
)
8969 /* Can't use this case if highlighting a region because
8970 a cursor movement will do more than just set the cursor. */
8971 && !(!NILP (Vtransient_mark_mode
)
8972 && !NILP (current_buffer
->mark_active
))
8973 && NILP (w
->region_showing
)
8974 && NILP (Vshow_trailing_whitespace
)
8975 /* Overlay arrow position and string not changed. */
8976 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
8977 && EQ (last_arrow_string
, Voverlay_arrow_string
)
8978 /* Value is > 0 if update has been done, it is -1 if we
8979 know that the same window start will not work. It is 0
8980 if unsuccessful for some other reason. */
8981 && (tem
= try_window_id (w
)) != 0)
8984 debug_method_add (w
, "try_window_id");
8987 if (fonts_changed_p
)
8988 goto restore_buffers
;
8991 /* Otherwise try_window_id has returned -1 which means that we
8992 don't want the alternative below this comment to execute. */
8994 else if (CHARPOS (startp
) >= BEGV
8995 && CHARPOS (startp
) <= ZV
8996 && PT
>= CHARPOS (startp
)
8997 && (CHARPOS (startp
) < ZV
8998 /* Avoid starting at end of buffer. */
8999 || CHARPOS (startp
) == BEGV
9000 || (XFASTINT (w
->last_modified
) >= MODIFF
9001 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
9004 debug_method_add (w
, "same window start");
9007 /* Try to redisplay starting at same place as before.
9008 If point has not moved off frame, accept the results. */
9009 if (!current_matrix_up_to_date_p
9010 /* Don't use try_window_reusing_current_matrix in this case
9011 because a window scroll function can have changed the
9013 || !NILP (Vwindow_scroll_functions
)
9014 || MINI_WINDOW_P (w
)
9015 || !try_window_reusing_current_matrix (w
))
9017 IF_DEBUG (debug_method_add (w
, "1"));
9018 try_window (window
, startp
);
9021 if (fonts_changed_p
)
9022 goto restore_buffers
;
9024 if (w
->cursor
.vpos
>= 0)
9026 if (!just_this_one_p
9027 || current_buffer
->clip_changed
9028 || BEG_UNCHANGED
< CHARPOS (startp
))
9029 /* Forget any recorded base line for line number display. */
9030 w
->base_line_number
= Qnil
;
9032 make_cursor_line_fully_visible (w
);
9036 clear_glyph_matrix (w
->desired_matrix
);
9041 XSETFASTINT (w
->last_modified
, 0);
9042 XSETFASTINT (w
->last_overlay_modified
, 0);
9044 /* Redisplay the mode line. Select the buffer properly for that. */
9045 if (!update_mode_line
)
9047 if (!really_switched_buffer
)
9049 set_buffer_temp (old
);
9050 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9051 really_switched_buffer
= 1;
9053 update_mode_line
= 1;
9054 w
->update_mode_line
= Qt
;
9057 /* Try to scroll by specified few lines. */
9058 if ((scroll_conservatively
9061 || NUMBERP (current_buffer
->scroll_up_aggressively
)
9062 || NUMBERP (current_buffer
->scroll_down_aggressively
))
9063 && !current_buffer
->clip_changed
9064 && CHARPOS (startp
) >= BEGV
9065 && CHARPOS (startp
) <= ZV
)
9067 /* The function returns -1 if new fonts were loaded, 1 if
9068 successful, 0 if not successful. */
9069 int rc
= try_scrolling (window
, just_this_one_p
,
9070 scroll_conservatively
,
9076 goto restore_buffers
;
9079 /* Finally, just choose place to start which centers point */
9084 debug_method_add (w
, "recenter");
9087 /* w->vscroll = 0; */
9089 /* Forget any previously recorded base line for line number display. */
9090 if (!current_matrix_up_to_date_p
9091 || current_buffer
->clip_changed
)
9092 w
->base_line_number
= Qnil
;
9094 /* Move backward half the height of the window. */
9095 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9096 it
.current_y
= it
.last_visible_y
;
9097 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
9098 xassert (IT_CHARPOS (it
) >= BEGV
);
9100 /* The function move_it_vertically_backward may move over more
9101 than the specified y-distance. If it->w is small, e.g. a
9102 mini-buffer window, we may end up in front of the window's
9103 display area. Start displaying at the start of the line
9104 containing PT in this case. */
9105 if (it
.current_y
<= 0)
9107 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9108 move_it_vertically (&it
, 0);
9109 xassert (IT_CHARPOS (it
) <= PT
);
9113 it
.current_x
= it
.hpos
= 0;
9115 /* Set startp here explicitly in case that helps avoid an infinite loop
9116 in case the window-scroll-functions functions get errors. */
9117 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
9119 /* Run scroll hooks. */
9120 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
9122 /* Redisplay the window. */
9123 if (!current_matrix_up_to_date_p
9124 || windows_or_buffers_changed
9125 /* Don't use try_window_reusing_current_matrix in this case
9126 because it can have changed the buffer. */
9127 || !NILP (Vwindow_scroll_functions
)
9129 || MINI_WINDOW_P (w
)
9130 || !try_window_reusing_current_matrix (w
))
9131 try_window (window
, startp
);
9133 /* If new fonts have been loaded (due to fontsets), give up. We
9134 have to start a new redisplay since we need to re-adjust glyph
9136 if (fonts_changed_p
)
9137 goto restore_buffers
;
9139 /* If cursor did not appear assume that the middle of the window is
9140 in the first line of the window. Do it again with the next line.
9141 (Imagine a window of height 100, displaying two lines of height
9142 60. Moving back 50 from it->last_visible_y will end in the first
9144 if (w
->cursor
.vpos
< 0)
9146 if (!NILP (w
->window_end_valid
)
9147 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
9149 clear_glyph_matrix (w
->desired_matrix
);
9150 move_it_by_lines (&it
, 1, 0);
9151 try_window (window
, it
.current
.pos
);
9153 else if (PT
< IT_CHARPOS (it
))
9155 clear_glyph_matrix (w
->desired_matrix
);
9156 move_it_by_lines (&it
, -1, 0);
9157 try_window (window
, it
.current
.pos
);
9161 /* Not much we can do about it. */
9165 /* Consider the following case: Window starts at BEGV, there is
9166 invisible, intangible text at BEGV, so that display starts at
9167 some point START > BEGV. It can happen that we are called with
9168 PT somewhere between BEGV and START. Try to handle that case. */
9169 if (w
->cursor
.vpos
< 0)
9171 struct glyph_row
*row
= w
->current_matrix
->rows
;
9172 if (row
->mode_line_p
)
9174 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9177 make_cursor_line_fully_visible (w
);
9181 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9182 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
9183 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
9186 /* Display the mode line, if we must. */
9187 if ((update_mode_line
9188 /* If window not full width, must redo its mode line
9189 if (a) the window to its side is being redone and
9190 (b) we do a frame-based redisplay. This is a consequence
9191 of how inverted lines are drawn in frame-based redisplay. */
9192 || (!just_this_one_p
9193 && !FRAME_WINDOW_P (f
)
9194 && !WINDOW_FULL_WIDTH_P (w
))
9195 /* Line number to display. */
9196 || INTEGERP (w
->base_line_pos
)
9197 /* Column number is displayed and different from the one displayed. */
9198 || (!NILP (w
->column_number_displayed
)
9199 && XFASTINT (w
->column_number_displayed
) != current_column ()))
9200 /* This means that the window has a mode line. */
9201 && (WINDOW_WANTS_MODELINE_P (w
)
9202 || WINDOW_WANTS_HEADER_LINE_P (w
)))
9204 Lisp_Object old_selected_frame
;
9206 old_selected_frame
= selected_frame
;
9208 if (!really_switched_buffer
)
9210 set_buffer_temp (old
);
9211 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9212 really_switched_buffer
= 1;
9215 XSETFRAME (selected_frame
, f
);
9216 display_mode_lines (w
);
9217 selected_frame
= old_selected_frame
;
9219 /* If mode line height has changed, arrange for a thorough
9220 immediate redisplay using the correct mode line height. */
9221 if (WINDOW_WANTS_MODELINE_P (w
)
9222 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
9224 fonts_changed_p
= 1;
9225 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
9226 = DESIRED_MODE_LINE_HEIGHT (w
);
9229 /* If top line height has changed, arrange for a thorough
9230 immediate redisplay using the correct mode line height. */
9231 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9232 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
9234 fonts_changed_p
= 1;
9235 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
9236 = DESIRED_HEADER_LINE_HEIGHT (w
);
9239 if (fonts_changed_p
)
9240 goto restore_buffers
;
9243 if (!line_number_displayed
9244 && !BUFFERP (w
->base_line_pos
))
9246 w
->base_line_pos
= Qnil
;
9247 w
->base_line_number
= Qnil
;
9252 /* When we reach a frame's selected window, redo the frame's menu bar. */
9253 if (update_mode_line
9254 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
9256 int redisplay_menu_p
= 0;
9258 if (FRAME_WINDOW_P (f
))
9260 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
9261 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
9263 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9267 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9269 if (redisplay_menu_p
)
9270 display_menu_bar (w
);
9272 #ifdef HAVE_WINDOW_SYSTEM
9273 if (WINDOWP (f
->tool_bar_window
)
9274 && (FRAME_TOOL_BAR_LINES (f
) > 0
9275 || auto_resize_tool_bars_p
))
9276 redisplay_tool_bar (f
);
9282 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9284 int start
, end
, whole
;
9286 /* Calculate the start and end positions for the current window.
9287 At some point, it would be nice to choose between scrollbars
9288 which reflect the whole buffer size, with special markers
9289 indicating narrowing, and scrollbars which reflect only the
9292 Note that mini-buffers sometimes aren't displaying any text. */
9293 if (!MINI_WINDOW_P (w
)
9294 || (w
== XWINDOW (minibuf_window
)
9295 && NILP (echo_area_buffer
[0])))
9298 start
= marker_position (w
->start
) - BEGV
;
9299 /* I don't think this is guaranteed to be right. For the
9300 moment, we'll pretend it is. */
9301 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
9305 if (whole
< (end
- start
))
9306 whole
= end
- start
;
9309 start
= end
= whole
= 0;
9311 /* Indicate what this scroll bar ought to be displaying now. */
9312 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
9314 /* Note that we actually used the scroll bar attached to this
9315 window, so it shouldn't be deleted at the end of redisplay. */
9316 (*redeem_scroll_bar_hook
) (w
);
9321 /* Restore current_buffer and value of point in it. */
9322 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
9323 if (really_switched_buffer
)
9324 set_buffer_internal_1 (old
);
9326 set_buffer_temp (old
);
9327 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
9329 unbind_to (count
, Qnil
);
9333 /* Build the complete desired matrix of WINDOW with a window start
9334 buffer position POS. Value is non-zero if successful. It is zero
9335 if fonts were loaded during redisplay which makes re-adjusting
9336 glyph matrices necessary. */
9339 try_window (window
, pos
)
9341 struct text_pos pos
;
9343 struct window
*w
= XWINDOW (window
);
9345 struct glyph_row
*last_text_row
= NULL
;
9347 /* Make POS the new window start. */
9348 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
9350 /* Mark cursor position as unknown. No overlay arrow seen. */
9351 w
->cursor
.vpos
= -1;
9352 overlay_arrow_seen
= 0;
9354 /* Initialize iterator and info to start at POS. */
9355 start_display (&it
, w
, pos
);
9357 /* Display all lines of W. */
9358 while (it
.current_y
< it
.last_visible_y
)
9360 if (display_line (&it
))
9361 last_text_row
= it
.glyph_row
- 1;
9362 if (fonts_changed_p
)
9366 /* If bottom moved off end of frame, change mode line percentage. */
9367 if (XFASTINT (w
->window_end_pos
) <= 0
9368 && Z
!= IT_CHARPOS (it
))
9369 w
->update_mode_line
= Qt
;
9371 /* Set window_end_pos to the offset of the last character displayed
9372 on the window from the end of current_buffer. Set
9373 window_end_vpos to its row number. */
9376 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
9377 w
->window_end_bytepos
9378 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9379 XSETFASTINT (w
->window_end_pos
,
9380 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9381 XSETFASTINT (w
->window_end_vpos
,
9382 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9383 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
9388 w
->window_end_bytepos
= 0;
9389 XSETFASTINT (w
->window_end_pos
, 0);
9390 XSETFASTINT (w
->window_end_vpos
, 0);
9393 /* But that is not valid info until redisplay finishes. */
9394 w
->window_end_valid
= Qnil
;
9400 /************************************************************************
9401 Window redisplay reusing current matrix when buffer has not changed
9402 ************************************************************************/
9404 /* Try redisplay of window W showing an unchanged buffer with a
9405 different window start than the last time it was displayed by
9406 reusing its current matrix. Value is non-zero if successful.
9407 W->start is the new window start. */
9410 try_window_reusing_current_matrix (w
)
9413 struct frame
*f
= XFRAME (w
->frame
);
9414 struct glyph_row
*row
, *bottom_row
;
9417 struct text_pos start
, new_start
;
9418 int nrows_scrolled
, i
;
9419 struct glyph_row
*last_text_row
;
9420 struct glyph_row
*last_reused_text_row
;
9421 struct glyph_row
*start_row
;
9422 int start_vpos
, min_y
, max_y
;
9424 /* Right now this function doesn't handle terminal frames. */
9425 if (!FRAME_WINDOW_P (f
))
9428 /* Can't do this if region may have changed. */
9429 if ((!NILP (Vtransient_mark_mode
)
9430 && !NILP (current_buffer
->mark_active
))
9431 || !NILP (w
->region_showing
)
9432 || !NILP (Vshow_trailing_whitespace
))
9435 /* If top-line visibility has changed, give up. */
9436 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9437 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
9440 /* Give up if old or new display is scrolled vertically. We could
9441 make this function handle this, but right now it doesn't. */
9442 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9443 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
9446 /* The variable new_start now holds the new window start. The old
9447 start `start' can be determined from the current matrix. */
9448 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
9449 start
= start_row
->start
.pos
;
9450 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
9452 /* Clear the desired matrix for the display below. */
9453 clear_glyph_matrix (w
->desired_matrix
);
9455 if (CHARPOS (new_start
) <= CHARPOS (start
))
9459 IF_DEBUG (debug_method_add (w
, "twu1"));
9461 /* Display up to a row that can be reused. The variable
9462 last_text_row is set to the last row displayed that displays
9464 start_display (&it
, w
, new_start
);
9465 first_row_y
= it
.current_y
;
9466 w
->cursor
.vpos
= -1;
9467 last_text_row
= last_reused_text_row
= NULL
;
9468 while (it
.current_y
< it
.last_visible_y
9469 && IT_CHARPOS (it
) < CHARPOS (start
)
9470 && !fonts_changed_p
)
9471 if (display_line (&it
))
9472 last_text_row
= it
.glyph_row
- 1;
9474 /* A value of current_y < last_visible_y means that we stopped
9475 at the previous window start, which in turn means that we
9476 have at least one reusable row. */
9477 if (it
.current_y
< it
.last_visible_y
)
9479 nrows_scrolled
= it
.vpos
;
9481 /* Find PT if not already found in the lines displayed. */
9482 if (w
->cursor
.vpos
< 0)
9484 int dy
= it
.current_y
- first_row_y
;
9486 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9487 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9489 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
9490 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9492 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
9493 dy
, nrows_scrolled
);
9497 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
9503 /* Give up if point was not found. This shouldn't
9504 happen often; not more often than with try_window
9506 if (w
->cursor
.vpos
< 0)
9508 clear_glyph_matrix (w
->desired_matrix
);
9513 /* Scroll the display. Do it before the current matrix is
9514 changed. The problem here is that update has not yet
9515 run, i.e. part of the current matrix is not up to date.
9516 scroll_run_hook will clear the cursor, and use the
9517 current matrix to get the height of the row the cursor is
9519 run
.current_y
= first_row_y
;
9520 run
.desired_y
= it
.current_y
;
9521 run
.height
= it
.last_visible_y
- it
.current_y
;
9523 && run
.current_y
!= run
.desired_y
)
9526 rif
->update_window_begin_hook (w
);
9527 rif
->scroll_run_hook (w
, &run
);
9528 rif
->update_window_end_hook (w
, 0);
9532 /* Shift current matrix down by nrows_scrolled lines. */
9533 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9534 rotate_matrix (w
->current_matrix
,
9536 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9539 /* Disable lines not reused. */
9540 for (i
= 0; i
< it
.vpos
; ++i
)
9541 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
9543 /* Re-compute Y positions. */
9544 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
) + nrows_scrolled
;
9545 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9546 max_y
= it
.last_visible_y
;
9547 while (row
< bottom_row
)
9549 row
->y
= it
.current_y
;
9552 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9553 else if (row
->y
+ row
->height
> max_y
)
9555 = row
->height
- (row
->y
+ row
->height
- max_y
);
9557 row
->visible_height
= row
->height
;
9559 it
.current_y
+= row
->height
;
9562 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9563 last_reused_text_row
= row
;
9564 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
9570 /* Update window_end_pos etc.; last_reused_text_row is the last
9571 reused row from the current matrix containing text, if any.
9572 The value of last_text_row is the last displayed line
9574 if (last_reused_text_row
)
9576 w
->window_end_bytepos
9577 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
9578 XSETFASTINT (w
->window_end_pos
,
9579 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
9580 XSETFASTINT (w
->window_end_vpos
,
9581 MATRIX_ROW_VPOS (last_reused_text_row
,
9582 w
->current_matrix
));
9584 else if (last_text_row
)
9586 w
->window_end_bytepos
9587 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9588 XSETFASTINT (w
->window_end_pos
,
9589 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9590 XSETFASTINT (w
->window_end_vpos
,
9591 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9595 /* This window must be completely empty. */
9596 w
->window_end_bytepos
= 0;
9597 XSETFASTINT (w
->window_end_pos
, 0);
9598 XSETFASTINT (w
->window_end_vpos
, 0);
9600 w
->window_end_valid
= Qnil
;
9602 /* Update hint: don't try scrolling again in update_window. */
9603 w
->desired_matrix
->no_scrolling_p
= 1;
9606 debug_method_add (w
, "try_window_reusing_current_matrix 1");
9610 else if (CHARPOS (new_start
) > CHARPOS (start
))
9612 struct glyph_row
*pt_row
, *row
;
9613 struct glyph_row
*first_reusable_row
;
9614 struct glyph_row
*first_row_to_display
;
9616 int yb
= window_text_bottom_y (w
);
9618 IF_DEBUG (debug_method_add (w
, "twu2"));
9620 /* Find the row starting at new_start, if there is one. Don't
9621 reuse a partially visible line at the end. */
9622 first_reusable_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9623 while (first_reusable_row
->enabled_p
9624 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
9625 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9626 < CHARPOS (new_start
)))
9627 ++first_reusable_row
;
9629 /* Give up if there is no row to reuse. */
9630 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
9631 || !first_reusable_row
->enabled_p
9632 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9633 != CHARPOS (new_start
)))
9636 /* We can reuse fully visible rows beginning with
9637 first_reusable_row to the end of the window. Set
9638 first_row_to_display to the first row that cannot be reused.
9639 Set pt_row to the row containing point, if there is any. */
9640 first_row_to_display
= first_reusable_row
;
9642 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
9644 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
9645 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
9646 pt_row
= first_row_to_display
;
9648 ++first_row_to_display
;
9651 /* Start displaying at the start of first_row_to_display. */
9652 xassert (first_row_to_display
->y
< yb
);
9653 init_to_row_start (&it
, w
, first_row_to_display
);
9654 nrows_scrolled
= MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
);
9655 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
9657 it
.current_y
= first_row_to_display
->y
- first_reusable_row
->y
;
9659 /* Display lines beginning with first_row_to_display in the
9660 desired matrix. Set last_text_row to the last row displayed
9661 that displays text. */
9662 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
9664 w
->cursor
.vpos
= -1;
9665 last_text_row
= NULL
;
9666 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
9667 if (display_line (&it
))
9668 last_text_row
= it
.glyph_row
- 1;
9670 /* Give up If point isn't in a row displayed or reused. */
9671 if (w
->cursor
.vpos
< 0)
9673 clear_glyph_matrix (w
->desired_matrix
);
9677 /* If point is in a reused row, adjust y and vpos of the cursor
9681 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
9683 w
->cursor
.y
-= first_reusable_row
->y
;
9686 /* Scroll the display. */
9687 run
.current_y
= first_reusable_row
->y
;
9688 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9689 run
.height
= it
.last_visible_y
- run
.current_y
;
9692 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9694 rif
->update_window_begin_hook (w
);
9695 rif
->scroll_run_hook (w
, &run
);
9696 rif
->update_window_end_hook (w
, 0);
9700 /* Adjust Y positions of reused rows. */
9701 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9702 row
= first_reusable_row
;
9703 dy
= first_reusable_row
->y
;
9704 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9705 max_y
= it
.last_visible_y
;
9706 while (row
< first_row_to_display
)
9710 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9711 else if (row
->y
+ row
->height
> max_y
)
9713 = row
->height
- (row
->y
+ row
->height
- max_y
);
9715 row
->visible_height
= row
->height
;
9719 /* Disable rows not reused. */
9720 while (row
< bottom_row
)
9726 /* Scroll the current matrix. */
9727 xassert (nrows_scrolled
> 0);
9728 rotate_matrix (w
->current_matrix
,
9730 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9733 /* Adjust window end. A null value of last_text_row means that
9734 the window end is in reused rows which in turn means that
9735 only its vpos can have changed. */
9738 w
->window_end_bytepos
9739 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9740 XSETFASTINT (w
->window_end_pos
,
9741 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9742 XSETFASTINT (w
->window_end_vpos
,
9743 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9747 XSETFASTINT (w
->window_end_vpos
,
9748 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
9751 w
->window_end_valid
= Qnil
;
9752 w
->desired_matrix
->no_scrolling_p
= 1;
9755 debug_method_add (w
, "try_window_reusing_current_matrix 2");
9765 /************************************************************************
9766 Window redisplay reusing current matrix when buffer has changed
9767 ************************************************************************/
9769 static struct glyph_row
*get_last_unchanged_at_beg_row
P_ ((struct window
*));
9770 static struct glyph_row
*get_first_unchanged_at_end_row
P_ ((struct window
*,
9772 static struct glyph_row
*
9773 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
9774 struct glyph_row
*));
9777 /* Return the last row in MATRIX displaying text. If row START is
9778 non-null, start searching with that row. IT gives the dimensions
9779 of the display. Value is null if matrix is empty; otherwise it is
9780 a pointer to the row found. */
9782 static struct glyph_row
*
9783 find_last_row_displaying_text (matrix
, it
, start
)
9784 struct glyph_matrix
*matrix
;
9786 struct glyph_row
*start
;
9788 struct glyph_row
*row
, *row_found
;
9790 /* Set row_found to the last row in IT->w's current matrix
9791 displaying text. The loop looks funny but think of partially
9794 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
9795 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9797 xassert (row
->enabled_p
);
9799 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
9808 /* Return the last row in the current matrix of W that is not affected
9809 by changes at the start of current_buffer that occurred since the
9810 last time W was redisplayed. Value is null if no such row exists.
9812 The global variable beg_unchanged has to contain the number of
9813 bytes unchanged at the start of current_buffer. BEG +
9814 beg_unchanged is the buffer position of the first changed byte in
9815 current_buffer. Characters at positions < BEG + beg_unchanged are
9816 at the same buffer positions as they were when the current matrix
9819 static struct glyph_row
*
9820 get_last_unchanged_at_beg_row (w
)
9823 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
9824 struct glyph_row
*row
;
9825 struct glyph_row
*row_found
= NULL
;
9826 int yb
= window_text_bottom_y (w
);
9828 /* Find the last row displaying unchanged text. */
9829 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9830 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
9831 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
9833 if (/* If row ends before first_changed_pos, it is unchanged,
9834 except in some case. */
9835 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
9836 /* When row ends in ZV and we write at ZV it is not
9838 && !row
->ends_at_zv_p
9839 /* When first_changed_pos is the end of a continued line,
9840 row is not unchanged because it may be no longer
9842 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
9843 && row
->continued_p
))
9846 /* Stop if last visible row. */
9847 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
9857 /* Find the first glyph row in the current matrix of W that is not
9858 affected by changes at the end of current_buffer since the last
9859 time the window was redisplayed. Return in *DELTA the number of
9860 chars by which buffer positions in unchanged text at the end of
9861 current_buffer must be adjusted. Return in *DELTA_BYTES the
9862 corresponding number of bytes. Value is null if no such row
9863 exists, i.e. all rows are affected by changes. */
9865 static struct glyph_row
*
9866 get_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
9868 int *delta
, *delta_bytes
;
9870 struct glyph_row
*row
;
9871 struct glyph_row
*row_found
= NULL
;
9873 *delta
= *delta_bytes
= 0;
9875 /* A value of window_end_pos >= end_unchanged means that the window
9876 end is in the range of changed text. If so, there is no
9877 unchanged row at the end of W's current matrix. */
9878 xassert (!NILP (w
->window_end_valid
));
9879 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
9882 /* Set row to the last row in W's current matrix displaying text. */
9883 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
9885 /* If matrix is entirely empty, no unchanged row exists. */
9886 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9888 /* The value of row is the last glyph row in the matrix having a
9889 meaningful buffer position in it. The end position of row
9890 corresponds to window_end_pos. This allows us to translate
9891 buffer positions in the current matrix to current buffer
9892 positions for characters not in changed text. */
9893 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
9894 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
9895 int last_unchanged_pos
, last_unchanged_pos_old
;
9896 struct glyph_row
*first_text_row
9897 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9900 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
9902 /* Set last_unchanged_pos to the buffer position of the last
9903 character in the buffer that has not been changed. Z is the
9904 index + 1 of the last byte in current_buffer, i.e. by
9905 subtracting end_unchanged we get the index of the last
9906 unchanged character, and we have to add BEG to get its buffer
9908 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
9909 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
9911 /* Search backward from ROW for a row displaying a line that
9912 starts at a minimum position >= last_unchanged_pos_old. */
9913 while (row
>= first_text_row
)
9915 xassert (row
->enabled_p
);
9916 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
));
9918 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
9924 xassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
9929 /* Make sure that glyph rows in the current matrix of window W
9930 reference the same glyph memory as corresponding rows in the
9931 frame's frame matrix. This function is called after scrolling W's
9932 current matrix on a terminal frame in try_window_id and
9933 try_window_reusing_current_matrix. */
9936 sync_frame_with_window_matrix_rows (w
)
9939 struct frame
*f
= XFRAME (w
->frame
);
9940 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
9942 /* Preconditions: W must be a leaf window and full-width. Its frame
9943 must have a frame matrix. */
9944 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
9945 xassert (WINDOW_FULL_WIDTH_P (w
));
9946 xassert (!FRAME_WINDOW_P (f
));
9948 /* If W is a full-width window, glyph pointers in W's current matrix
9949 have, by definition, to be the same as glyph pointers in the
9950 corresponding frame matrix. */
9951 window_row
= w
->current_matrix
->rows
;
9952 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
9953 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
9954 while (window_row
< window_row_end
)
9958 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
9959 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
9961 /* Disable frame rows whose corresponding window rows have
9962 been disabled in try_window_id. */
9963 if (!window_row
->enabled_p
)
9964 frame_row
->enabled_p
= 0;
9966 ++window_row
, ++frame_row
;
9971 /* Find the glyph row in window W containing CHARPOS. Consider all
9972 rows between START and END (not inclusive). END null means search
9973 all rows to the end of the display area of W. Value is the row
9974 containing CHARPOS or null. */
9976 static struct glyph_row
*
9977 row_containing_pos (w
, charpos
, start
, end
)
9980 struct glyph_row
*start
, *end
;
9982 struct glyph_row
*row
= start
;
9985 /* If we happen to start on a header-line, skip that. */
9986 if (row
->mode_line_p
)
9989 if ((end
&& row
>= end
) || !row
->enabled_p
)
9992 last_y
= window_text_bottom_y (w
);
9994 while ((end
== NULL
|| row
< end
)
9995 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
9996 /* The end position of a row equals the start
9997 position of the next row. If CHARPOS is there, we
9998 would rather display it in the next line, except
9999 when this line ends in ZV. */
10000 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
10001 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
10002 || !row
->ends_at_zv_p
)))
10003 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
10006 /* Give up if CHARPOS not found. */
10007 if ((end
&& row
>= end
)
10008 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
10009 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
10016 /* Try to redisplay window W by reusing its existing display. W's
10017 current matrix must be up to date when this function is called,
10018 i.e. window_end_valid must not be nil.
10022 1 if display has been updated
10023 0 if otherwise unsuccessful
10024 -1 if redisplay with same window start is known not to succeed
10026 The following steps are performed:
10028 1. Find the last row in the current matrix of W that is not
10029 affected by changes at the start of current_buffer. If no such row
10032 2. Find the first row in W's current matrix that is not affected by
10033 changes at the end of current_buffer. Maybe there is no such row.
10035 3. Display lines beginning with the row + 1 found in step 1 to the
10036 row found in step 2 or, if step 2 didn't find a row, to the end of
10039 4. If cursor is not known to appear on the window, give up.
10041 5. If display stopped at the row found in step 2, scroll the
10042 display and current matrix as needed.
10044 6. Maybe display some lines at the end of W, if we must. This can
10045 happen under various circumstances, like a partially visible line
10046 becoming fully visible, or because newly displayed lines are displayed
10047 in smaller font sizes.
10049 7. Update W's window end information. */
10051 /* Check that window end is what we expect it to be. */
10057 struct frame
*f
= XFRAME (w
->frame
);
10058 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
10059 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
10060 struct glyph_row
*last_unchanged_at_beg_row
;
10061 struct glyph_row
*first_unchanged_at_end_row
;
10062 struct glyph_row
*row
;
10063 struct glyph_row
*bottom_row
;
10066 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
10067 struct text_pos start_pos
;
10069 int first_unchanged_at_end_vpos
= 0;
10070 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
10071 struct text_pos start
;
10073 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10075 /* Check pre-conditions. Window end must be valid, otherwise
10076 the current matrix would not be up to date. */
10077 xassert (!NILP (w
->window_end_valid
));
10078 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
10079 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
10081 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
10082 only if buffer has really changed. The reason is that the gap is
10083 initially at Z for freshly visited files. The code below would
10084 set end_unchanged to 0 in that case. */
10085 if (MODIFF
> SAVE_MODIFF
10086 /* This seems to happen sometimes after saving a buffer. */
10087 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
10089 if (GPT
- BEG
< BEG_UNCHANGED
)
10090 BEG_UNCHANGED
= GPT
- BEG
;
10091 if (Z
- GPT
< END_UNCHANGED
)
10092 END_UNCHANGED
= Z
- GPT
;
10095 /* If window starts after a line end, and the last change is in
10096 front of that newline, then changes don't affect the display.
10097 This case happens with stealth-fontification. Note that although
10098 the display is unchanged, glyph positions in the matrix have to
10099 be adjusted, of course. */
10100 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10101 if (CHARPOS (start
) > BEGV
10102 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
10103 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
10104 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10106 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
10107 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
10111 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10112 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
10114 increment_matrix_positions (w
->current_matrix
,
10115 MATRIX_ROW_VPOS (r0
, current_matrix
),
10116 MATRIX_ROW_VPOS (r1
, current_matrix
),
10117 delta
, delta_bytes
);
10120 #if 0 /* If changes are all in front of the window start, the
10121 distance of the last displayed glyph from Z hasn't
10124 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10125 w
->window_end_bytepos
10126 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10132 /* Return quickly if changes are all below what is displayed in the
10133 window, and if PT is in the window. */
10134 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
10135 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10137 /* We have to update window end positions because the buffer's
10138 size has changed. */
10140 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10141 w
->window_end_bytepos
10142 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10146 /* Check that window start agrees with the start of the first glyph
10147 row in its current matrix. Check this after we know the window
10148 start is not in changed text, otherwise positions would not be
10150 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10151 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
10154 /* Compute the position at which we have to start displaying new
10155 lines. Some of the lines at the top of the window might be
10156 reusable because they are not displaying changed text. Find the
10157 last row in W's current matrix not affected by changes at the
10158 start of current_buffer. Value is null if changes start in the
10159 first line of window. */
10160 last_unchanged_at_beg_row
= get_last_unchanged_at_beg_row (w
);
10161 if (last_unchanged_at_beg_row
)
10163 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
10164 start_pos
= it
.current
.pos
;
10166 /* Start displaying new lines in the desired matrix at the same
10167 vpos we would use in the current matrix, i.e. below
10168 last_unchanged_at_beg_row. */
10169 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
10171 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10172 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
10174 xassert (it
.hpos
== 0 && it
.current_x
== 0);
10178 /* There are no reusable lines at the start of the window.
10179 Start displaying in the first line. */
10180 start_display (&it
, w
, start
);
10181 start_pos
= it
.current
.pos
;
10184 /* Find the first row that is not affected by changes at the end of
10185 the buffer. Value will be null if there is no unchanged row, in
10186 which case we must redisplay to the end of the window. delta
10187 will be set to the value by which buffer positions beginning with
10188 first_unchanged_at_end_row have to be adjusted due to text
10190 first_unchanged_at_end_row
10191 = get_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
10192 IF_DEBUG (debug_delta
= delta
);
10193 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
10195 /* Set stop_pos to the buffer position up to which we will have to
10196 display new lines. If first_unchanged_at_end_row != NULL, this
10197 is the buffer position of the start of the line displayed in that
10198 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
10199 that we don't stop at a buffer position. */
10201 if (first_unchanged_at_end_row
)
10203 xassert (last_unchanged_at_beg_row
== NULL
10204 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
10206 /* If this is a continuation line, move forward to the next one
10207 that isn't. Changes in lines above affect this line.
10208 Caution: this may move first_unchanged_at_end_row to a row
10209 not displaying text. */
10210 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
10211 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10212 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10213 < it
.last_visible_y
))
10214 ++first_unchanged_at_end_row
;
10216 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10217 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10218 >= it
.last_visible_y
))
10219 first_unchanged_at_end_row
= NULL
;
10222 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
10224 first_unchanged_at_end_vpos
10225 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
10226 xassert (stop_pos
>= Z
- END_UNCHANGED
);
10229 else if (last_unchanged_at_beg_row
== NULL
)
10235 /* Either there is no unchanged row at the end, or the one we have
10236 now displays text. This is a necessary condition for the window
10237 end pos calculation at the end of this function. */
10238 xassert (first_unchanged_at_end_row
== NULL
10239 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
10241 debug_last_unchanged_at_beg_vpos
10242 = (last_unchanged_at_beg_row
10243 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
10245 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
10247 #endif /* GLYPH_DEBUG != 0 */
10250 /* Display new lines. Set last_text_row to the last new line
10251 displayed which has text on it, i.e. might end up as being the
10252 line where the window_end_vpos is. */
10253 w
->cursor
.vpos
= -1;
10254 last_text_row
= NULL
;
10255 overlay_arrow_seen
= 0;
10256 while (it
.current_y
< it
.last_visible_y
10257 && !fonts_changed_p
10258 && (first_unchanged_at_end_row
== NULL
10259 || IT_CHARPOS (it
) < stop_pos
))
10261 if (display_line (&it
))
10262 last_text_row
= it
.glyph_row
- 1;
10265 if (fonts_changed_p
)
10269 /* Compute differences in buffer positions, y-positions etc. for
10270 lines reused at the bottom of the window. Compute what we can
10272 if (first_unchanged_at_end_row
10273 /* No lines reused because we displayed everything up to the
10274 bottom of the window. */
10275 && it
.current_y
< it
.last_visible_y
)
10278 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
10280 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
10281 run
.current_y
= first_unchanged_at_end_row
->y
;
10282 run
.desired_y
= run
.current_y
+ dy
;
10283 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
10287 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
10288 first_unchanged_at_end_row
= NULL
;
10290 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
10293 /* Find the cursor if not already found. We have to decide whether
10294 PT will appear on this window (it sometimes doesn't, but this is
10295 not a very frequent case.) This decision has to be made before
10296 the current matrix is altered. A value of cursor.vpos < 0 means
10297 that PT is either in one of the lines beginning at
10298 first_unchanged_at_end_row or below the window. Don't care for
10299 lines that might be displayed later at the window end; as
10300 mentioned, this is not a frequent case. */
10301 if (w
->cursor
.vpos
< 0)
10303 /* Cursor in unchanged rows at the top? */
10304 if (PT
< CHARPOS (start_pos
)
10305 && last_unchanged_at_beg_row
)
10307 row
= row_containing_pos (w
, PT
,
10308 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
10309 last_unchanged_at_beg_row
+ 1);
10310 xassert (row
&& row
<= last_unchanged_at_beg_row
);
10311 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10314 /* Start from first_unchanged_at_end_row looking for PT. */
10315 else if (first_unchanged_at_end_row
)
10317 row
= row_containing_pos (w
, PT
- delta
,
10318 first_unchanged_at_end_row
, NULL
);
10320 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
10321 delta_bytes
, dy
, dvpos
);
10324 /* Give up if cursor was not found. */
10325 if (w
->cursor
.vpos
< 0)
10327 clear_glyph_matrix (w
->desired_matrix
);
10332 /* Don't let the cursor end in the scroll margins. */
10334 int this_scroll_margin
, cursor_height
;
10336 this_scroll_margin
= max (0, scroll_margin
);
10337 this_scroll_margin
= min (this_scroll_margin
,
10338 XFASTINT (w
->height
) / 4);
10339 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
10340 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
10342 if ((w
->cursor
.y
< this_scroll_margin
10343 && CHARPOS (start
) > BEGV
)
10344 /* Don't take scroll margin into account at the bottom because
10345 old redisplay didn't do it either. */
10346 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
10348 w
->cursor
.vpos
= -1;
10349 clear_glyph_matrix (w
->desired_matrix
);
10354 /* Scroll the display. Do it before changing the current matrix so
10355 that xterm.c doesn't get confused about where the cursor glyph is
10357 if (dy
&& run
.height
)
10361 if (FRAME_WINDOW_P (f
))
10363 rif
->update_window_begin_hook (w
);
10364 rif
->scroll_run_hook (w
, &run
);
10365 rif
->update_window_end_hook (w
, 0);
10369 /* Terminal frame. In this case, dvpos gives the number of
10370 lines to scroll by; dvpos < 0 means scroll up. */
10371 int first_unchanged_at_end_vpos
10372 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
10373 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
10374 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
10376 /* Perform the operation on the screen. */
10379 /* Scroll last_unchanged_at_beg_row to the end of the
10380 window down dvpos lines. */
10381 set_terminal_window (end
);
10383 /* On dumb terminals delete dvpos lines at the end
10384 before inserting dvpos empty lines. */
10385 if (!scroll_region_ok
)
10386 ins_del_lines (end
- dvpos
, -dvpos
);
10388 /* Insert dvpos empty lines in front of
10389 last_unchanged_at_beg_row. */
10390 ins_del_lines (from
, dvpos
);
10392 else if (dvpos
< 0)
10394 /* Scroll up last_unchanged_at_beg_vpos to the end of
10395 the window to last_unchanged_at_beg_vpos - |dvpos|. */
10396 set_terminal_window (end
);
10398 /* Delete dvpos lines in front of
10399 last_unchanged_at_beg_vpos. ins_del_lines will set
10400 the cursor to the given vpos and emit |dvpos| delete
10402 ins_del_lines (from
+ dvpos
, dvpos
);
10404 /* On a dumb terminal insert dvpos empty lines at the
10406 if (!scroll_region_ok
)
10407 ins_del_lines (end
+ dvpos
, -dvpos
);
10410 set_terminal_window (0);
10416 /* Shift reused rows of the current matrix to the right position.
10417 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
10419 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10420 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
10423 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
10424 bottom_vpos
, dvpos
);
10425 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
10428 else if (dvpos
> 0)
10430 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
10431 bottom_vpos
, dvpos
);
10432 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
10433 first_unchanged_at_end_vpos
+ dvpos
, 0);
10436 /* For frame-based redisplay, make sure that current frame and window
10437 matrix are in sync with respect to glyph memory. */
10438 if (!FRAME_WINDOW_P (f
))
10439 sync_frame_with_window_matrix_rows (w
);
10441 /* Adjust buffer positions in reused rows. */
10443 increment_matrix_positions (current_matrix
,
10444 first_unchanged_at_end_vpos
+ dvpos
,
10445 bottom_vpos
, delta
, delta_bytes
);
10447 /* Adjust Y positions. */
10449 shift_glyph_matrix (w
, current_matrix
,
10450 first_unchanged_at_end_vpos
+ dvpos
,
10453 if (first_unchanged_at_end_row
)
10454 first_unchanged_at_end_row
+= dvpos
;
10456 /* If scrolling up, there may be some lines to display at the end of
10458 last_text_row_at_end
= NULL
;
10461 /* Set last_row to the glyph row in the current matrix where the
10462 window end line is found. It has been moved up or down in
10463 the matrix by dvpos. */
10464 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
10465 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
10467 /* If last_row is the window end line, it should display text. */
10468 xassert (last_row
->displays_text_p
);
10470 /* If window end line was partially visible before, begin
10471 displaying at that line. Otherwise begin displaying with the
10472 line following it. */
10473 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
10475 init_to_row_start (&it
, w
, last_row
);
10476 it
.vpos
= last_vpos
;
10477 it
.current_y
= last_row
->y
;
10481 init_to_row_end (&it
, w
, last_row
);
10482 it
.vpos
= 1 + last_vpos
;
10483 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
10487 /* We may start in a continuation line. If so, we have to get
10488 the right continuation_lines_width and current_x. */
10489 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
10490 it
.hpos
= it
.current_x
= 0;
10492 /* Display the rest of the lines at the window end. */
10493 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10494 while (it
.current_y
< it
.last_visible_y
10495 && !fonts_changed_p
)
10497 /* Is it always sure that the display agrees with lines in
10498 the current matrix? I don't think so, so we mark rows
10499 displayed invalid in the current matrix by setting their
10500 enabled_p flag to zero. */
10501 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
10502 if (display_line (&it
))
10503 last_text_row_at_end
= it
.glyph_row
- 1;
10507 /* Update window_end_pos and window_end_vpos. */
10508 if (first_unchanged_at_end_row
10509 && first_unchanged_at_end_row
->y
< it
.last_visible_y
10510 && !last_text_row_at_end
)
10512 /* Window end line if one of the preserved rows from the current
10513 matrix. Set row to the last row displaying text in current
10514 matrix starting at first_unchanged_at_end_row, after
10516 xassert (first_unchanged_at_end_row
->displays_text_p
);
10517 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
10518 first_unchanged_at_end_row
);
10519 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
10521 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
10522 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10523 XSETFASTINT (w
->window_end_vpos
,
10524 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
10526 else if (last_text_row_at_end
)
10528 XSETFASTINT (w
->window_end_pos
,
10529 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
10530 w
->window_end_bytepos
10531 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
10532 XSETFASTINT (w
->window_end_vpos
,
10533 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
10535 else if (last_text_row
)
10537 /* We have displayed either to the end of the window or at the
10538 end of the window, i.e. the last row with text is to be found
10539 in the desired matrix. */
10540 XSETFASTINT (w
->window_end_pos
,
10541 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10542 w
->window_end_bytepos
10543 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10544 XSETFASTINT (w
->window_end_vpos
,
10545 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
10547 else if (first_unchanged_at_end_row
== NULL
10548 && last_text_row
== NULL
10549 && last_text_row_at_end
== NULL
)
10551 /* Displayed to end of window, but no line containing text was
10552 displayed. Lines were deleted at the end of the window. */
10554 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
10556 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
10557 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10558 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
10559 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10560 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
10563 w
->window_end_vpos
= make_number (vpos
);
10568 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
10569 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
10571 /* Record that display has not been completed. */
10572 w
->window_end_valid
= Qnil
;
10573 w
->desired_matrix
->no_scrolling_p
= 1;
10579 /***********************************************************************
10580 More debugging support
10581 ***********************************************************************/
10585 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
10586 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
10589 /* Dump the contents of glyph matrix MATRIX on stderr. If
10590 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
10593 dump_glyph_matrix (matrix
, with_glyphs_p
)
10594 struct glyph_matrix
*matrix
;
10598 for (i
= 0; i
< matrix
->nrows
; ++i
)
10599 dump_glyph_row (matrix
, i
, with_glyphs_p
);
10603 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
10604 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
10607 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
10608 struct glyph_matrix
*matrix
;
10609 int vpos
, with_glyphs_p
;
10611 struct glyph_row
*row
;
10613 if (vpos
< 0 || vpos
>= matrix
->nrows
)
10616 row
= MATRIX_ROW (matrix
, vpos
);
10618 fprintf (stderr
, "Row Start End Used oEI><O\\CTZF X Y W\n");
10619 fprintf (stderr
, "=============================================\n");
10621 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d\n",
10622 row
- matrix
->rows
,
10623 MATRIX_ROW_START_CHARPOS (row
),
10624 MATRIX_ROW_END_CHARPOS (row
),
10625 row
->used
[TEXT_AREA
],
10626 row
->contains_overlapping_glyphs_p
,
10629 row
->truncated_on_left_p
,
10630 row
->truncated_on_right_p
,
10631 row
->overlay_arrow_p
,
10633 MATRIX_ROW_CONTINUATION_LINE_P (row
),
10634 row
->displays_text_p
,
10640 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
10641 row
->end
.overlay_string_index
);
10642 fprintf (stderr
, "%9d %5d\n",
10643 CHARPOS (row
->start
.string_pos
),
10644 CHARPOS (row
->end
.string_pos
));
10645 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
10646 row
->end
.dpvec_index
);
10650 struct glyph
*glyph
, *glyph_end
;
10651 int prev_had_glyphs_p
;
10653 glyph
= row
->glyphs
[TEXT_AREA
];
10654 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
10656 /* Glyph for a line end in text. */
10657 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
10660 if (glyph
< glyph_end
)
10662 fprintf (stderr
, " Glyph Type Pos W Code C Face LR\n");
10663 prev_had_glyphs_p
= 1;
10666 prev_had_glyphs_p
= 0;
10668 while (glyph
< glyph_end
)
10670 if (glyph
->type
== CHAR_GLYPH
)
10673 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10674 glyph
- row
->glyphs
[TEXT_AREA
],
10677 glyph
->pixel_width
,
10679 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
10683 glyph
->left_box_line_p
,
10684 glyph
->right_box_line_p
);
10686 else if (glyph
->type
== STRETCH_GLYPH
)
10689 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10690 glyph
- row
->glyphs
[TEXT_AREA
],
10693 glyph
->pixel_width
,
10697 glyph
->left_box_line_p
,
10698 glyph
->right_box_line_p
);
10700 else if (glyph
->type
== IMAGE_GLYPH
)
10703 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10704 glyph
- row
->glyphs
[TEXT_AREA
],
10707 glyph
->pixel_width
,
10711 glyph
->left_box_line_p
,
10712 glyph
->right_box_line_p
);
10720 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
10721 Sdump_glyph_matrix
, 0, 1, "p",
10722 "Dump the current matrix of the selected window to stderr.\n\
10723 Shows contents of glyph row structures. With non-nil optional\n\
10724 parameter WITH-GLYPHS-P, dump glyphs as well.")
10726 Lisp_Object with_glyphs_p
;
10728 struct window
*w
= XWINDOW (selected_window
);
10729 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10731 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
10732 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
10733 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
10734 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
10735 fprintf (stderr
, "=============================================\n");
10736 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
10741 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
10742 "Dump glyph row ROW to stderr.")
10746 CHECK_NUMBER (row
, 0);
10747 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
10752 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
,
10756 struct frame
*sf
= SELECTED_FRAME ();
10757 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)
10759 dump_glyph_row (m
, 0, 1);
10764 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
10765 Strace_redisplay_toggle
, 0, 0, "",
10766 "Toggle tracing of redisplay.")
10769 trace_redisplay_p
= !trace_redisplay_p
;
10774 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
10775 "Print STRING to stderr.")
10777 Lisp_Object string
;
10779 CHECK_STRING (string
, 0);
10780 fprintf (stderr
, "%s", XSTRING (string
)->data
);
10784 #endif /* GLYPH_DEBUG */
10788 /***********************************************************************
10789 Building Desired Matrix Rows
10790 ***********************************************************************/
10792 /* Return a temporary glyph row holding the glyphs of an overlay
10793 arrow. Only used for non-window-redisplay windows. */
10795 static struct glyph_row
*
10796 get_overlay_arrow_glyph_row (w
)
10799 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10800 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10801 struct buffer
*old
= current_buffer
;
10802 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
10803 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
10804 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
10808 int n_glyphs_before
;
10810 set_buffer_temp (buffer
);
10811 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
10812 it
.glyph_row
->used
[TEXT_AREA
] = 0;
10813 SET_TEXT_POS (it
.position
, 0, 0);
10815 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
10817 while (p
< arrow_end
)
10819 Lisp_Object face
, ilisp
;
10821 /* Get the next character. */
10823 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
10825 it
.c
= *p
, it
.len
= 1;
10828 /* Get its face. */
10829 XSETFASTINT (ilisp
, p
- arrow_string
);
10830 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
10831 it
.face_id
= compute_char_face (f
, it
.c
, face
);
10833 /* Compute its width, get its glyphs. */
10834 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
10835 SET_TEXT_POS (it
.position
, -1, -1);
10836 PRODUCE_GLYPHS (&it
);
10838 /* If this character doesn't fit any more in the line, we have
10839 to remove some glyphs. */
10840 if (it
.current_x
> it
.last_visible_x
)
10842 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
10847 set_buffer_temp (old
);
10848 return it
.glyph_row
;
10852 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
10853 glyphs are only inserted for terminal frames since we can't really
10854 win with truncation glyphs when partially visible glyphs are
10855 involved. Which glyphs to insert is determined by
10856 produce_special_glyphs. */
10859 insert_left_trunc_glyphs (it
)
10862 struct it truncate_it
;
10863 struct glyph
*from
, *end
, *to
, *toend
;
10865 xassert (!FRAME_WINDOW_P (it
->f
));
10867 /* Get the truncation glyphs. */
10869 truncate_it
.current_x
= 0;
10870 truncate_it
.face_id
= DEFAULT_FACE_ID
;
10871 truncate_it
.glyph_row
= &scratch_glyph_row
;
10872 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
10873 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
10874 truncate_it
.object
= make_number (0);
10875 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
10877 /* Overwrite glyphs from IT with truncation glyphs. */
10878 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
10879 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
10880 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
10881 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
10886 /* There may be padding glyphs left over. Remove them. */
10888 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
10890 while (from
< toend
)
10893 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
10897 /* Compute the pixel height and width of IT->glyph_row.
10899 Most of the time, ascent and height of a display line will be equal
10900 to the max_ascent and max_height values of the display iterator
10901 structure. This is not the case if
10903 1. We hit ZV without displaying anything. In this case, max_ascent
10904 and max_height will be zero.
10906 2. We have some glyphs that don't contribute to the line height.
10907 (The glyph row flag contributes_to_line_height_p is for future
10908 pixmap extensions).
10910 The first case is easily covered by using default values because in
10911 these cases, the line height does not really matter, except that it
10912 must not be zero. */
10915 compute_line_metrics (it
)
10918 struct glyph_row
*row
= it
->glyph_row
;
10921 if (FRAME_WINDOW_P (it
->f
))
10923 int i
, header_line_height
;
10925 /* The line may consist of one space only, that was added to
10926 place the cursor on it. If so, the row's height hasn't been
10928 if (row
->height
== 0)
10930 if (it
->max_ascent
+ it
->max_descent
== 0)
10931 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
10932 row
->ascent
= it
->max_ascent
;
10933 row
->height
= it
->max_ascent
+ it
->max_descent
;
10934 row
->phys_ascent
= it
->max_phys_ascent
;
10935 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
10938 /* Compute the width of this line. */
10939 row
->pixel_width
= row
->x
;
10940 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
10941 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10943 xassert (row
->pixel_width
>= 0);
10944 xassert (row
->ascent
>= 0 && row
->height
> 0);
10946 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
10947 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
10949 /* If first line's physical ascent is larger than its logical
10950 ascent, use the physical ascent, and make the row taller.
10951 This makes accented characters fully visible. */
10952 if (row
== it
->w
->desired_matrix
->rows
10953 && row
->phys_ascent
> row
->ascent
)
10955 row
->height
+= row
->phys_ascent
- row
->ascent
;
10956 row
->ascent
= row
->phys_ascent
;
10959 /* Compute how much of the line is visible. */
10960 row
->visible_height
= row
->height
;
10962 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
10963 if (row
->y
< header_line_height
)
10964 row
->visible_height
-= header_line_height
- row
->y
;
10967 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
10968 if (row
->y
+ row
->height
> max_y
)
10969 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10974 row
->pixel_width
= row
->used
[TEXT_AREA
];
10975 row
->ascent
= row
->phys_ascent
= 0;
10976 row
->height
= row
->phys_height
= row
->visible_height
= 1;
10979 /* Compute a hash code for this row. */
10981 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
10982 for (i
= 0; i
< row
->used
[area
]; ++i
)
10983 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
10984 + row
->glyphs
[area
][i
].u
.val
10985 + row
->glyphs
[area
][i
].face_id
10986 + row
->glyphs
[area
][i
].padding_p
10987 + (row
->glyphs
[area
][i
].type
<< 2));
10989 it
->max_ascent
= it
->max_descent
= 0;
10990 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
10994 /* Append one space to the glyph row of iterator IT if doing a
10995 window-based redisplay. DEFAULT_FACE_P non-zero means let the
10996 space have the default face, otherwise let it have the same face as
10997 IT->face_id. Value is non-zero if a space was added.
10999 This function is called to make sure that there is always one glyph
11000 at the end of a glyph row that the cursor can be set on under
11001 window-systems. (If there weren't such a glyph we would not know
11002 how wide and tall a box cursor should be displayed).
11004 At the same time this space let's a nicely handle clearing to the
11005 end of the line if the row ends in italic text. */
11008 append_space (it
, default_face_p
)
11010 int default_face_p
;
11012 if (FRAME_WINDOW_P (it
->f
))
11014 int n
= it
->glyph_row
->used
[TEXT_AREA
];
11016 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
11017 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
11019 /* Save some values that must not be changed. */
11020 int saved_x
= it
->current_x
;
11021 struct text_pos saved_pos
;
11022 int saved_what
= it
->what
;
11023 int saved_face_id
= it
->face_id
;
11024 Lisp_Object saved_object
;
11027 saved_object
= it
->object
;
11028 saved_pos
= it
->position
;
11030 it
->what
= IT_CHARACTER
;
11031 bzero (&it
->position
, sizeof it
->position
);
11032 it
->object
= make_number (0);
11036 if (default_face_p
)
11037 it
->face_id
= DEFAULT_FACE_ID
;
11038 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11039 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
11041 PRODUCE_GLYPHS (it
);
11043 it
->current_x
= saved_x
;
11044 it
->object
= saved_object
;
11045 it
->position
= saved_pos
;
11046 it
->what
= saved_what
;
11047 it
->face_id
= saved_face_id
;
11056 /* Extend the face of the last glyph in the text area of IT->glyph_row
11057 to the end of the display line. Called from display_line.
11058 If the glyph row is empty, add a space glyph to it so that we
11059 know the face to draw. Set the glyph row flag fill_line_p. */
11062 extend_face_to_end_of_line (it
)
11066 struct frame
*f
= it
->f
;
11068 /* If line is already filled, do nothing. */
11069 if (it
->current_x
>= it
->last_visible_x
)
11072 /* Face extension extends the background and box of IT->face_id
11073 to the end of the line. If the background equals the background
11074 of the frame, we haven't to do anything. */
11075 face
= FACE_FROM_ID (f
, it
->face_id
);
11076 if (FRAME_WINDOW_P (f
)
11077 && face
->box
== FACE_NO_BOX
11078 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
11082 /* Set the glyph row flag indicating that the face of the last glyph
11083 in the text area has to be drawn to the end of the text area. */
11084 it
->glyph_row
->fill_line_p
= 1;
11086 /* If current character of IT is not ASCII, make sure we have the
11087 ASCII face. This will be automatically undone the next time
11088 get_next_display_element returns a multibyte character. Note
11089 that the character will always be single byte in unibyte text. */
11090 if (!SINGLE_BYTE_CHAR_P (it
->c
))
11092 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
11095 if (FRAME_WINDOW_P (f
))
11097 /* If the row is empty, add a space with the current face of IT,
11098 so that we know which face to draw. */
11099 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
11101 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
11102 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
11103 it
->glyph_row
->used
[TEXT_AREA
] = 1;
11108 /* Save some values that must not be changed. */
11109 int saved_x
= it
->current_x
;
11110 struct text_pos saved_pos
;
11111 Lisp_Object saved_object
;
11112 int saved_what
= it
->what
;
11114 saved_object
= it
->object
;
11115 saved_pos
= it
->position
;
11117 it
->what
= IT_CHARACTER
;
11118 bzero (&it
->position
, sizeof it
->position
);
11119 it
->object
= make_number (0);
11123 PRODUCE_GLYPHS (it
);
11125 while (it
->current_x
<= it
->last_visible_x
)
11126 PRODUCE_GLYPHS (it
);
11128 /* Don't count these blanks really. It would let us insert a left
11129 truncation glyph below and make us set the cursor on them, maybe. */
11130 it
->current_x
= saved_x
;
11131 it
->object
= saved_object
;
11132 it
->position
= saved_pos
;
11133 it
->what
= saved_what
;
11138 /* Value is non-zero if text starting at CHARPOS in current_buffer is
11139 trailing whitespace. */
11142 trailing_whitespace_p (charpos
)
11145 int bytepos
= CHAR_TO_BYTE (charpos
);
11148 while (bytepos
< ZV_BYTE
11149 && (c
= FETCH_CHAR (bytepos
),
11150 c
== ' ' || c
== '\t'))
11153 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
11155 if (bytepos
!= PT_BYTE
)
11162 /* Highlight trailing whitespace, if any, in ROW. */
11165 highlight_trailing_whitespace (f
, row
)
11167 struct glyph_row
*row
;
11169 int used
= row
->used
[TEXT_AREA
];
11173 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
11174 struct glyph
*glyph
= start
+ used
- 1;
11176 /* Skip over the space glyph inserted to display the
11177 cursor at the end of a line. */
11178 if (glyph
->type
== CHAR_GLYPH
11179 && glyph
->u
.ch
== ' '
11180 && INTEGERP (glyph
->object
))
11183 /* If last glyph is a space or stretch, and it's trailing
11184 whitespace, set the face of all trailing whitespace glyphs in
11185 IT->glyph_row to `trailing-whitespace'. */
11187 && BUFFERP (glyph
->object
)
11188 && (glyph
->type
== STRETCH_GLYPH
11189 || (glyph
->type
== CHAR_GLYPH
11190 && glyph
->u
.ch
== ' '))
11191 && trailing_whitespace_p (glyph
->charpos
))
11193 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
11195 while (glyph
>= start
11196 && BUFFERP (glyph
->object
)
11197 && (glyph
->type
== STRETCH_GLYPH
11198 || (glyph
->type
== CHAR_GLYPH
11199 && glyph
->u
.ch
== ' ')))
11200 (glyph
--)->face_id
= face_id
;
11206 /* Construct the glyph row IT->glyph_row in the desired matrix of
11207 IT->w from text at the current position of IT. See dispextern.h
11208 for an overview of struct it. Value is non-zero if
11209 IT->glyph_row displays text, as opposed to a line displaying ZV
11216 struct glyph_row
*row
= it
->glyph_row
;
11218 /* We always start displaying at hpos zero even if hscrolled. */
11219 xassert (it
->hpos
== 0 && it
->current_x
== 0);
11221 /* We must not display in a row that's not a text row. */
11222 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
11223 < it
->w
->desired_matrix
->nrows
);
11225 /* Is IT->w showing the region? */
11226 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
11228 /* Clear the result glyph row and enable it. */
11229 prepare_desired_row (row
);
11231 row
->y
= it
->current_y
;
11232 row
->start
= it
->current
;
11233 row
->continuation_lines_width
= it
->continuation_lines_width
;
11234 row
->displays_text_p
= 1;
11236 /* Arrange the overlays nicely for our purposes. Usually, we call
11237 display_line on only one line at a time, in which case this
11238 can't really hurt too much, or we call it on lines which appear
11239 one after another in the buffer, in which case all calls to
11240 recenter_overlay_lists but the first will be pretty cheap. */
11241 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
11243 /* Move over display elements that are not visible because we are
11244 hscrolled. This may stop at an x-position < IT->first_visible_x
11245 if the first glyph is partially visible or if we hit a line end. */
11246 if (it
->current_x
< it
->first_visible_x
)
11247 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
11248 MOVE_TO_POS
| MOVE_TO_X
);
11250 /* Get the initial row height. This is either the height of the
11251 text hscrolled, if there is any, or zero. */
11252 row
->ascent
= it
->max_ascent
;
11253 row
->height
= it
->max_ascent
+ it
->max_descent
;
11254 row
->phys_ascent
= it
->max_phys_ascent
;
11255 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11257 /* Loop generating characters. The loop is left with IT on the next
11258 character to display. */
11261 int n_glyphs_before
, hpos_before
, x_before
;
11263 int ascent
, descent
, phys_ascent
, phys_descent
;
11265 /* Retrieve the next thing to display. Value is zero if end of
11267 if (!get_next_display_element (it
))
11269 /* Maybe add a space at the end of this line that is used to
11270 display the cursor there under X. Set the charpos of the
11271 first glyph of blank lines not corresponding to any text
11273 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
11274 || row
->used
[TEXT_AREA
] == 0)
11276 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
11277 row
->displays_text_p
= 0;
11279 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
11280 row
->indicate_empty_line_p
= 1;
11283 it
->continuation_lines_width
= 0;
11284 row
->ends_at_zv_p
= 1;
11288 /* Now, get the metrics of what we want to display. This also
11289 generates glyphs in `row' (which is IT->glyph_row). */
11290 n_glyphs_before
= row
->used
[TEXT_AREA
];
11293 /* Remember the line height so far in case the next element doesn't
11294 fit on the line. */
11295 if (!it
->truncate_lines_p
)
11297 ascent
= it
->max_ascent
;
11298 descent
= it
->max_descent
;
11299 phys_ascent
= it
->max_phys_ascent
;
11300 phys_descent
= it
->max_phys_descent
;
11303 PRODUCE_GLYPHS (it
);
11305 /* If this display element was in marginal areas, continue with
11307 if (it
->area
!= TEXT_AREA
)
11309 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11310 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11311 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11312 row
->phys_height
= max (row
->phys_height
,
11313 it
->max_phys_ascent
+ it
->max_phys_descent
);
11314 set_iterator_to_next (it
);
11318 /* Does the display element fit on the line? If we truncate
11319 lines, we should draw past the right edge of the window. If
11320 we don't truncate, we want to stop so that we can display the
11321 continuation glyph before the right margin. If lines are
11322 continued, there are two possible strategies for characters
11323 resulting in more than 1 glyph (e.g. tabs): Display as many
11324 glyphs as possible in this line and leave the rest for the
11325 continuation line, or display the whole element in the next
11326 line. Original redisplay did the former, so we do it also. */
11327 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11328 hpos_before
= it
->hpos
;
11332 && it
->current_x
< it
->last_visible_x
)
11335 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11336 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11337 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11338 row
->phys_height
= max (row
->phys_height
,
11339 it
->max_phys_ascent
+ it
->max_phys_descent
);
11340 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
11341 row
->x
= x
- it
->first_visible_x
;
11346 struct glyph
*glyph
;
11348 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
11350 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11351 new_x
= x
+ glyph
->pixel_width
;
11353 if (/* Lines are continued. */
11354 !it
->truncate_lines_p
11355 && (/* Glyph doesn't fit on the line. */
11356 new_x
> it
->last_visible_x
11357 /* Or it fits exactly on a window system frame. */
11358 || (new_x
== it
->last_visible_x
11359 && FRAME_WINDOW_P (it
->f
))))
11361 /* End of a continued line. */
11364 || (new_x
== it
->last_visible_x
11365 && FRAME_WINDOW_P (it
->f
)))
11367 /* Current glyph is the only one on the line or
11368 fits exactly on the line. We must continue
11369 the line because we can't draw the cursor
11370 after the glyph. */
11371 row
->continued_p
= 1;
11372 it
->current_x
= new_x
;
11373 it
->continuation_lines_width
+= new_x
;
11375 if (i
== nglyphs
- 1)
11376 set_iterator_to_next (it
);
11380 /* Display element draws past the right edge of
11381 the window. Restore positions to values
11382 before the element. The next line starts
11383 with current_x before the glyph that could
11384 not be displayed, so that TAB works right. */
11385 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11387 /* Display continuation glyphs. */
11388 if (!FRAME_WINDOW_P (it
->f
))
11389 produce_special_glyphs (it
, IT_CONTINUATION
);
11390 row
->continued_p
= 1;
11393 it
->continuation_lines_width
+= x
;
11395 /* Restore the height to what it was before the
11396 element not fitting on the line. */
11397 it
->max_ascent
= ascent
;
11398 it
->max_descent
= descent
;
11399 it
->max_phys_ascent
= phys_ascent
;
11400 it
->max_phys_descent
= phys_descent
;
11405 else if (new_x
> it
->first_visible_x
)
11407 /* Increment number of glyphs actually displayed. */
11410 if (x
< it
->first_visible_x
)
11411 /* Glyph is partially visible, i.e. row starts at
11412 negative X position. */
11413 row
->x
= x
- it
->first_visible_x
;
11417 /* Glyph is completely off the left margin of the
11418 window. This should not happen because of the
11419 move_it_in_display_line at the start of
11425 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11426 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11427 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11428 row
->phys_height
= max (row
->phys_height
,
11429 it
->max_phys_ascent
+ it
->max_phys_descent
);
11431 /* End of this display line if row is continued. */
11432 if (row
->continued_p
)
11436 /* Is this a line end? If yes, we're also done, after making
11437 sure that a non-default face is extended up to the right
11438 margin of the window. */
11439 if (ITERATOR_AT_END_OF_LINE_P (it
))
11441 int used_before
= row
->used
[TEXT_AREA
];
11443 /* Add a space at the end of the line that is used to
11444 display the cursor there. */
11445 append_space (it
, 0);
11447 /* Extend the face to the end of the line. */
11448 extend_face_to_end_of_line (it
);
11450 /* Make sure we have the position. */
11451 if (used_before
== 0)
11452 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
11454 /* Consume the line end. This skips over invisible lines. */
11455 set_iterator_to_next (it
);
11456 it
->continuation_lines_width
= 0;
11460 /* Proceed with next display element. Note that this skips
11461 over lines invisible because of selective display. */
11462 set_iterator_to_next (it
);
11464 /* If we truncate lines, we are done when the last displayed
11465 glyphs reach past the right margin of the window. */
11466 if (it
->truncate_lines_p
11467 && (FRAME_WINDOW_P (it
->f
)
11468 ? (it
->current_x
>= it
->last_visible_x
)
11469 : (it
->current_x
> it
->last_visible_x
)))
11471 /* Maybe add truncation glyphs. */
11472 if (!FRAME_WINDOW_P (it
->f
))
11474 --it
->glyph_row
->used
[TEXT_AREA
];
11475 produce_special_glyphs (it
, IT_TRUNCATION
);
11478 row
->truncated_on_right_p
= 1;
11479 it
->continuation_lines_width
= 0;
11480 reseat_at_next_visible_line_start (it
, 0);
11481 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
11482 it
->hpos
= hpos_before
;
11483 it
->current_x
= x_before
;
11488 /* If line is not empty and hscrolled, maybe insert truncation glyphs
11489 at the left window margin. */
11490 if (it
->first_visible_x
11491 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
11493 if (!FRAME_WINDOW_P (it
->f
))
11494 insert_left_trunc_glyphs (it
);
11495 row
->truncated_on_left_p
= 1;
11498 /* If the start of this line is the overlay arrow-position, then
11499 mark this glyph row as the one containing the overlay arrow.
11500 This is clearly a mess with variable size fonts. It would be
11501 better to let it be displayed like cursors under X. */
11502 if (MARKERP (Voverlay_arrow_position
)
11503 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
11504 && (MATRIX_ROW_START_CHARPOS (row
)
11505 == marker_position (Voverlay_arrow_position
))
11506 && STRINGP (Voverlay_arrow_string
)
11507 && ! overlay_arrow_seen
)
11509 /* Overlay arrow in window redisplay is a bitmap. */
11510 if (!FRAME_WINDOW_P (it
->f
))
11512 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
11513 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
11514 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
11515 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
11516 struct glyph
*p2
, *end
;
11518 /* Copy the arrow glyphs. */
11519 while (glyph
< arrow_end
)
11522 /* Throw away padding glyphs. */
11524 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
11525 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
11531 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
11535 overlay_arrow_seen
= 1;
11536 row
->overlay_arrow_p
= 1;
11539 /* Compute pixel dimensions of this line. */
11540 compute_line_metrics (it
);
11542 /* Remember the position at which this line ends. */
11543 row
->end
= it
->current
;
11545 /* Maybe set the cursor. If you change this, it's probably a good
11546 idea to also change the code in redisplay_window for cursor
11547 movement in an unchanged window. */
11548 if (it
->w
->cursor
.vpos
< 0
11549 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
11550 && MATRIX_ROW_END_CHARPOS (row
) >= PT
11551 && !(MATRIX_ROW_END_CHARPOS (row
) == PT
11552 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11553 || !row
->ends_at_zv_p
)))
11554 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
11556 /* Highlight trailing whitespace. */
11557 if (!NILP (Vshow_trailing_whitespace
))
11558 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
11560 /* Prepare for the next line. This line starts horizontally at (X
11561 HPOS) = (0 0). Vertical positions are incremented. As a
11562 convenience for the caller, IT->glyph_row is set to the next
11564 it
->current_x
= it
->hpos
= 0;
11565 it
->current_y
+= row
->height
;
11568 return row
->displays_text_p
;
11573 /***********************************************************************
11575 ***********************************************************************/
11577 /* Redisplay the menu bar in the frame for window W.
11579 The menu bar of X frames that don't have X toolkit support is
11580 displayed in a special window W->frame->menu_bar_window.
11582 The menu bar of terminal frames is treated specially as far as
11583 glyph matrices are concerned. Menu bar lines are not part of
11584 windows, so the update is done directly on the frame matrix rows
11585 for the menu bar. */
11588 display_menu_bar (w
)
11591 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11596 /* Don't do all this for graphical frames. */
11598 if (!NILP (Vwindow_system
))
11601 #ifdef USE_X_TOOLKIT
11606 #ifdef USE_X_TOOLKIT
11607 xassert (!FRAME_WINDOW_P (f
));
11608 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
11609 it
.first_visible_x
= 0;
11610 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11611 #else /* not USE_X_TOOLKIT */
11612 if (FRAME_WINDOW_P (f
))
11614 /* Menu bar lines are displayed in the desired matrix of the
11615 dummy window menu_bar_window. */
11616 struct window
*menu_w
;
11617 xassert (WINDOWP (f
->menu_bar_window
));
11618 menu_w
= XWINDOW (f
->menu_bar_window
);
11619 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
11621 it
.first_visible_x
= 0;
11622 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11626 /* This is a TTY frame, i.e. character hpos/vpos are used as
11628 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
11630 it
.first_visible_x
= 0;
11631 it
.last_visible_x
= FRAME_WIDTH (f
);
11633 #endif /* not USE_X_TOOLKIT */
11635 /* Clear all rows of the menu bar. */
11636 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
11638 struct glyph_row
*row
= it
.glyph_row
+ i
;
11639 clear_glyph_row (row
);
11640 row
->enabled_p
= 1;
11641 row
->full_width_p
= 1;
11644 /* Make the first line of the menu bar appear in reverse video. */
11645 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11647 /* Display all items of the menu bar. */
11648 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
11649 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
11651 Lisp_Object string
;
11653 /* Stop at nil string. */
11654 string
= XVECTOR (items
)->contents
[i
+ 1];
11658 /* Remember where item was displayed. */
11659 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
11661 /* Display the item, pad with one space. */
11662 if (it
.current_x
< it
.last_visible_x
)
11663 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
11664 XSTRING (string
)->size
+ 1, 0, 0, -1);
11667 /* Fill out the line with spaces. */
11668 if (it
.current_x
< it
.last_visible_x
)
11669 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
11671 /* Compute the total height of the lines. */
11672 compute_line_metrics (&it
);
11677 /***********************************************************************
11679 ***********************************************************************/
11681 /* Display the mode and/or top line of window W. */
11684 display_mode_lines (w
)
11687 /* These will be set while the mode line specs are processed. */
11688 line_number_displayed
= 0;
11689 w
->column_number_displayed
= Qnil
;
11691 if (WINDOW_WANTS_MODELINE_P (w
))
11692 display_mode_line (w
, MODE_LINE_FACE_ID
,
11693 current_buffer
->mode_line_format
);
11695 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11696 display_mode_line (w
, HEADER_LINE_FACE_ID
,
11697 current_buffer
->header_line_format
);
11701 /* Display mode or top line of window W. FACE_ID specifies which line
11702 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
11703 FORMAT is the mode line format to display. */
11706 display_mode_line (w
, face_id
, format
)
11708 enum face_id face_id
;
11709 Lisp_Object format
;
11714 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
11715 prepare_desired_row (it
.glyph_row
);
11717 /* Temporarily make frame's keyboard the current kboard so that
11718 kboard-local variables in the mode_line_format will get the right
11720 push_frame_kboard (it
.f
);
11721 display_mode_element (&it
, 0, 0, 0, format
);
11722 pop_frame_kboard ();
11724 /* Fill up with spaces. */
11725 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
11727 compute_line_metrics (&it
);
11728 it
.glyph_row
->full_width_p
= 1;
11729 it
.glyph_row
->mode_line_p
= 1;
11730 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11731 it
.glyph_row
->continued_p
= 0;
11732 it
.glyph_row
->truncated_on_left_p
= 0;
11733 it
.glyph_row
->truncated_on_right_p
= 0;
11735 /* Make a 3D mode-line have a shadow at its right end. */
11736 face
= FACE_FROM_ID (it
.f
, face_id
);
11737 extend_face_to_end_of_line (&it
);
11738 if (face
->box
!= FACE_NO_BOX
)
11740 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
11741 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
11742 last
->right_box_line_p
= 1;
11747 /* Contribute ELT to the mode line for window IT->w. How it
11748 translates into text depends on its data type.
11750 IT describes the display environment in which we display, as usual.
11752 DEPTH is the depth in recursion. It is used to prevent
11753 infinite recursion here.
11755 FIELD_WIDTH is the number of characters the display of ELT should
11756 occupy in the mode line, and PRECISION is the maximum number of
11757 characters to display from ELT's representation. See
11758 display_string for details. *
11760 Returns the hpos of the end of the text generated by ELT. */
11763 display_mode_element (it
, depth
, field_width
, precision
, elt
)
11766 int field_width
, precision
;
11769 int n
= 0, field
, prec
;
11777 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
11781 /* A string: output it and check for %-constructs within it. */
11783 unsigned char *this = XSTRING (elt
)->data
;
11784 unsigned char *lisp_string
= this;
11786 while ((precision
<= 0 || n
< precision
)
11788 && (frame_title_ptr
11789 || it
->current_x
< it
->last_visible_x
))
11791 unsigned char *last
= this;
11793 /* Advance to end of string or next format specifier. */
11794 while ((c
= *this++) != '\0' && c
!= '%')
11797 if (this - 1 != last
)
11799 /* Output to end of string or up to '%'. Field width
11800 is length of string. Don't output more than
11801 PRECISION allows us. */
11802 prec
= --this - last
;
11803 if (precision
> 0 && prec
> precision
- n
)
11804 prec
= precision
- n
;
11806 if (frame_title_ptr
)
11807 n
+= store_frame_title (last
, prec
, prec
);
11809 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
11810 it
, 0, prec
, 0, -1);
11812 else /* c == '%' */
11814 unsigned char *percent_position
= this;
11816 /* Get the specified minimum width. Zero means
11819 while ((c
= *this++) >= '0' && c
<= '9')
11820 field
= field
* 10 + c
- '0';
11822 /* Don't pad beyond the total padding allowed. */
11823 if (field_width
- n
> 0 && field
> field_width
- n
)
11824 field
= field_width
- n
;
11826 /* Note that either PRECISION <= 0 or N < PRECISION. */
11827 prec
= precision
- n
;
11830 n
+= display_mode_element (it
, depth
, field
, prec
,
11831 Vglobal_mode_string
);
11834 unsigned char *spec
11835 = decode_mode_spec (it
->w
, c
, field
, prec
);
11837 if (frame_title_ptr
)
11838 n
+= store_frame_title (spec
, field
, prec
);
11842 = it
->glyph_row
->used
[TEXT_AREA
];
11844 = percent_position
- XSTRING (elt
)->data
;
11846 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
11847 field
, prec
, 0, -1);
11849 /* Assign to the glyphs written above the
11850 string where the `%x' came from, position
11854 struct glyph
*glyph
11855 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
11859 for (i
= 0; i
< nwritten
; ++i
)
11861 glyph
[i
].object
= elt
;
11862 glyph
[i
].charpos
= charpos
;
11875 /* A symbol: process the value of the symbol recursively
11876 as if it appeared here directly. Avoid error if symbol void.
11877 Special case: if value of symbol is a string, output the string
11880 register Lisp_Object tem
;
11881 tem
= Fboundp (elt
);
11884 tem
= Fsymbol_value (elt
);
11885 /* If value is a string, output that string literally:
11886 don't check for % within it. */
11889 prec
= XSTRING (tem
)->size
;
11890 if (precision
> 0 && prec
> precision
- n
)
11891 prec
= precision
- n
;
11892 if (frame_title_ptr
)
11893 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
11895 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
11898 else if (!EQ (tem
, elt
))
11900 /* Give up right away for nil or t. */
11910 register Lisp_Object car
, tem
;
11912 /* A cons cell: three distinct cases.
11913 If first element is a string or a cons, process all the elements
11914 and effectively concatenate them.
11915 If first element is a negative number, truncate displaying cdr to
11916 at most that many characters. If positive, pad (with spaces)
11917 to at least that many characters.
11918 If first element is a symbol, process the cadr or caddr recursively
11919 according to whether the symbol's value is non-nil or nil. */
11921 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
11923 /* An element of the form (:eval FORM) means evaluate FORM
11924 and use the result as mode line elements. */
11925 struct gcpro gcpro1
;
11928 spec
= eval_form (XCAR (XCDR (elt
)));
11930 n
+= display_mode_element (it
, depth
, field_width
- n
,
11931 precision
- n
, spec
);
11934 else if (SYMBOLP (car
))
11936 tem
= Fboundp (car
);
11940 /* elt is now the cdr, and we know it is a cons cell.
11941 Use its car if CAR has a non-nil value. */
11944 tem
= Fsymbol_value (car
);
11951 /* Symbol's value is nil (or symbol is unbound)
11952 Get the cddr of the original list
11953 and if possible find the caddr and use that. */
11957 else if (!CONSP (elt
))
11962 else if (INTEGERP (car
))
11964 register int lim
= XINT (car
);
11968 /* Negative int means reduce maximum width. */
11969 if (precision
<= 0)
11972 precision
= min (precision
, -lim
);
11976 /* Padding specified. Don't let it be more than
11977 current maximum. */
11979 lim
= min (precision
, lim
);
11981 /* If that's more padding than already wanted, queue it.
11982 But don't reduce padding already specified even if
11983 that is beyond the current truncation point. */
11984 field_width
= max (lim
, field_width
);
11988 else if (STRINGP (car
) || CONSP (car
))
11990 register int limit
= 50;
11991 /* Limit is to protect against circular lists. */
11994 && (precision
<= 0 || n
< precision
))
11996 n
+= display_mode_element (it
, depth
, field_width
- n
,
11997 precision
- n
, XCAR (elt
));
12006 if (frame_title_ptr
)
12007 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
12009 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
12010 precision
- n
, 0, 0);
12014 /* Pad to FIELD_WIDTH. */
12015 if (field_width
> 0 && n
< field_width
)
12017 if (frame_title_ptr
)
12018 n
+= store_frame_title ("", field_width
- n
, 0);
12020 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
12028 /* Write a null-terminated, right justified decimal representation of
12029 the positive integer D to BUF using a minimal field width WIDTH. */
12032 pint2str (buf
, width
, d
)
12033 register char *buf
;
12034 register int width
;
12037 register char *p
= buf
;
12045 *p
++ = d
% 10 + '0';
12050 for (width
-= (int) (p
- buf
); width
> 0; --width
)
12061 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
12062 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
12063 type of CODING_SYSTEM. Return updated pointer into BUF. */
12065 static unsigned char invalid_eol_type
[] = "(*invalid*)";
12068 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
12069 Lisp_Object coding_system
;
12070 register char *buf
;
12074 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
12075 unsigned char *eol_str
;
12077 /* The EOL conversion we are using. */
12078 Lisp_Object eoltype
;
12080 val
= Fget (coding_system
, Qcoding_system
);
12082 if (!VECTORP (val
)) /* Not yet decided. */
12087 eoltype
= eol_mnemonic_undecided
;
12088 /* Don't mention EOL conversion if it isn't decided. */
12092 Lisp_Object eolvalue
;
12094 eolvalue
= Fget (coding_system
, Qeol_type
);
12097 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
12101 /* The EOL conversion that is normal on this system. */
12103 if (NILP (eolvalue
)) /* Not yet decided. */
12104 eoltype
= eol_mnemonic_undecided
;
12105 else if (VECTORP (eolvalue
)) /* Not yet decided. */
12106 eoltype
= eol_mnemonic_undecided
;
12107 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
12108 eoltype
= (XFASTINT (eolvalue
) == 0
12109 ? eol_mnemonic_unix
12110 : (XFASTINT (eolvalue
) == 1
12111 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
12117 /* Mention the EOL conversion if it is not the usual one. */
12118 if (STRINGP (eoltype
))
12120 eol_str
= XSTRING (eoltype
)->data
;
12121 eol_str_len
= XSTRING (eoltype
)->size
;
12123 else if (INTEGERP (eoltype
)
12124 && CHAR_VALID_P (XINT (eoltype
), 0))
12126 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
12127 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
12131 eol_str
= invalid_eol_type
;
12132 eol_str_len
= sizeof (invalid_eol_type
) - 1;
12134 bcopy (eol_str
, buf
, eol_str_len
);
12135 buf
+= eol_str_len
;
12141 /* Return a string for the output of a mode line %-spec for window W,
12142 generated by character C. PRECISION >= 0 means don't return a
12143 string longer than that value. FIELD_WIDTH > 0 means pad the
12144 string returned with spaces to that value. */
12146 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
12149 decode_mode_spec (w
, c
, field_width
, precision
)
12152 int field_width
, precision
;
12155 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12156 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
12157 struct buffer
*b
= XBUFFER (w
->buffer
);
12164 if (!NILP (b
->read_only
))
12166 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12171 /* This differs from %* only for a modified read-only buffer. */
12172 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12174 if (!NILP (b
->read_only
))
12179 /* This differs from %* in ignoring read-only-ness. */
12180 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12192 if (command_loop_level
> 5)
12194 p
= decode_mode_spec_buf
;
12195 for (i
= 0; i
< command_loop_level
; i
++)
12198 return decode_mode_spec_buf
;
12206 if (command_loop_level
> 5)
12208 p
= decode_mode_spec_buf
;
12209 for (i
= 0; i
< command_loop_level
; i
++)
12212 return decode_mode_spec_buf
;
12219 /* Let lots_of_dashes be a string of infinite length. */
12220 if (field_width
<= 0
12221 || field_width
> sizeof (lots_of_dashes
))
12223 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
12224 decode_mode_spec_buf
[i
] = '-';
12225 decode_mode_spec_buf
[i
] = '\0';
12226 return decode_mode_spec_buf
;
12229 return lots_of_dashes
;
12238 int col
= current_column ();
12239 XSETFASTINT (w
->column_number_displayed
, col
);
12240 pint2str (decode_mode_spec_buf
, field_width
, col
);
12241 return decode_mode_spec_buf
;
12245 /* %F displays the frame name. */
12246 if (!NILP (f
->title
))
12247 return (char *) XSTRING (f
->title
)->data
;
12248 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
12249 return (char *) XSTRING (f
->name
)->data
;
12258 int startpos
= XMARKER (w
->start
)->charpos
;
12259 int startpos_byte
= marker_byte_position (w
->start
);
12260 int line
, linepos
, linepos_byte
, topline
;
12262 int height
= XFASTINT (w
->height
);
12264 /* If we decided that this buffer isn't suitable for line numbers,
12265 don't forget that too fast. */
12266 if (EQ (w
->base_line_pos
, w
->buffer
))
12268 /* But do forget it, if the window shows a different buffer now. */
12269 else if (BUFFERP (w
->base_line_pos
))
12270 w
->base_line_pos
= Qnil
;
12272 /* If the buffer is very big, don't waste time. */
12273 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
12275 w
->base_line_pos
= Qnil
;
12276 w
->base_line_number
= Qnil
;
12280 if (!NILP (w
->base_line_number
)
12281 && !NILP (w
->base_line_pos
)
12282 && XFASTINT (w
->base_line_pos
) <= startpos
)
12284 line
= XFASTINT (w
->base_line_number
);
12285 linepos
= XFASTINT (w
->base_line_pos
);
12286 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
12291 linepos
= BUF_BEGV (b
);
12292 linepos_byte
= BUF_BEGV_BYTE (b
);
12295 /* Count lines from base line to window start position. */
12296 nlines
= display_count_lines (linepos
, linepos_byte
,
12300 topline
= nlines
+ line
;
12302 /* Determine a new base line, if the old one is too close
12303 or too far away, or if we did not have one.
12304 "Too close" means it's plausible a scroll-down would
12305 go back past it. */
12306 if (startpos
== BUF_BEGV (b
))
12308 XSETFASTINT (w
->base_line_number
, topline
);
12309 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
12311 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
12312 || linepos
== BUF_BEGV (b
))
12314 int limit
= BUF_BEGV (b
);
12315 int limit_byte
= BUF_BEGV_BYTE (b
);
12317 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
12319 if (startpos
- distance
> limit
)
12321 limit
= startpos
- distance
;
12322 limit_byte
= CHAR_TO_BYTE (limit
);
12325 nlines
= display_count_lines (startpos
, startpos_byte
,
12327 - (height
* 2 + 30),
12329 /* If we couldn't find the lines we wanted within
12330 line_number_display_limit_width chars per line,
12331 give up on line numbers for this window. */
12332 if (position
== limit_byte
&& limit
== startpos
- distance
)
12334 w
->base_line_pos
= w
->buffer
;
12335 w
->base_line_number
= Qnil
;
12339 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
12340 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
12343 /* Now count lines from the start pos to point. */
12344 nlines
= display_count_lines (startpos
, startpos_byte
,
12345 PT_BYTE
, PT
, &junk
);
12347 /* Record that we did display the line number. */
12348 line_number_displayed
= 1;
12350 /* Make the string to show. */
12351 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
12352 return decode_mode_spec_buf
;
12355 char* p
= decode_mode_spec_buf
;
12356 int pad
= field_width
- 2;
12361 return decode_mode_spec_buf
;
12367 obj
= b
->mode_name
;
12371 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
12377 int pos
= marker_position (w
->start
);
12378 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12380 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
12382 if (pos
<= BUF_BEGV (b
))
12387 else if (pos
<= BUF_BEGV (b
))
12391 if (total
> 1000000)
12392 /* Do it differently for a large value, to avoid overflow. */
12393 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12395 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12396 /* We can't normally display a 3-digit number,
12397 so get us a 2-digit number that is close. */
12400 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12401 return decode_mode_spec_buf
;
12405 /* Display percentage of size above the bottom of the screen. */
12408 int toppos
= marker_position (w
->start
);
12409 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
12410 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12412 if (botpos
>= BUF_ZV (b
))
12414 if (toppos
<= BUF_BEGV (b
))
12421 if (total
> 1000000)
12422 /* Do it differently for a large value, to avoid overflow. */
12423 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12425 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12426 /* We can't normally display a 3-digit number,
12427 so get us a 2-digit number that is close. */
12430 if (toppos
<= BUF_BEGV (b
))
12431 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
12433 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12434 return decode_mode_spec_buf
;
12439 /* status of process */
12440 obj
= Fget_buffer_process (w
->buffer
);
12442 return "no process";
12443 #ifdef subprocesses
12444 obj
= Fsymbol_name (Fprocess_status (obj
));
12448 case 't': /* indicate TEXT or BINARY */
12449 #ifdef MODE_LINE_BINARY_TEXT
12450 return MODE_LINE_BINARY_TEXT (b
);
12456 /* coding-system (not including end-of-line format) */
12458 /* coding-system (including end-of-line type) */
12460 int eol_flag
= (c
== 'Z');
12461 char *p
= decode_mode_spec_buf
;
12463 if (! FRAME_WINDOW_P (f
))
12465 /* No need to mention EOL here--the terminal never needs
12466 to do EOL conversion. */
12467 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
12468 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
12470 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
12473 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
12474 #ifdef subprocesses
12475 obj
= Fget_buffer_process (Fcurrent_buffer ());
12476 if (PROCESSP (obj
))
12478 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
12480 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
12483 #endif /* subprocesses */
12486 return decode_mode_spec_buf
;
12491 return (char *) XSTRING (obj
)->data
;
12497 /* Count up to COUNT lines starting from START / START_BYTE.
12498 But don't go beyond LIMIT_BYTE.
12499 Return the number of lines thus found (always nonnegative).
12501 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
12504 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
12505 int start
, start_byte
, limit_byte
, count
;
12508 register unsigned char *cursor
;
12509 unsigned char *base
;
12511 register int ceiling
;
12512 register unsigned char *ceiling_addr
;
12513 int orig_count
= count
;
12515 /* If we are not in selective display mode,
12516 check only for newlines. */
12517 int selective_display
= (!NILP (current_buffer
->selective_display
)
12518 && !INTEGERP (current_buffer
->selective_display
));
12522 while (start_byte
< limit_byte
)
12524 ceiling
= BUFFER_CEILING_OF (start_byte
);
12525 ceiling
= min (limit_byte
- 1, ceiling
);
12526 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
12527 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
12530 if (selective_display
)
12531 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
12534 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
12537 if (cursor
!= ceiling_addr
)
12541 start_byte
+= cursor
- base
+ 1;
12542 *byte_pos_ptr
= start_byte
;
12546 if (++cursor
== ceiling_addr
)
12552 start_byte
+= cursor
- base
;
12557 while (start_byte
> limit_byte
)
12559 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
12560 ceiling
= max (limit_byte
, ceiling
);
12561 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
12562 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
12565 if (selective_display
)
12566 while (--cursor
!= ceiling_addr
12567 && *cursor
!= '\n' && *cursor
!= 015)
12570 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
12573 if (cursor
!= ceiling_addr
)
12577 start_byte
+= cursor
- base
+ 1;
12578 *byte_pos_ptr
= start_byte
;
12579 /* When scanning backwards, we should
12580 not count the newline posterior to which we stop. */
12581 return - orig_count
- 1;
12587 /* Here we add 1 to compensate for the last decrement
12588 of CURSOR, which took it past the valid range. */
12589 start_byte
+= cursor
- base
+ 1;
12593 *byte_pos_ptr
= limit_byte
;
12596 return - orig_count
+ count
;
12597 return orig_count
- count
;
12603 /***********************************************************************
12605 ***********************************************************************/
12607 /* Display a NUL-terminated string, starting with index START.
12609 If STRING is non-null, display that C string. Otherwise, the Lisp
12610 string LISP_STRING is displayed.
12612 If FACE_STRING is not nil, FACE_STRING_POS is a position in
12613 FACE_STRING. Display STRING or LISP_STRING with the face at
12614 FACE_STRING_POS in FACE_STRING:
12616 Display the string in the environment given by IT, but use the
12617 standard display table, temporarily.
12619 FIELD_WIDTH is the minimum number of output glyphs to produce.
12620 If STRING has fewer characters than FIELD_WIDTH, pad to the right
12621 with spaces. If STRING has more characters, more than FIELD_WIDTH
12622 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
12624 PRECISION is the maximum number of characters to output from
12625 STRING. PRECISION < 0 means don't truncate the string.
12627 This is roughly equivalent to printf format specifiers:
12629 FIELD_WIDTH PRECISION PRINTF
12630 ----------------------------------------
12636 MULTIBYTE zero means do not display multibyte chars, > 0 means do
12637 display them, and < 0 means obey the current buffer's value of
12638 enable_multibyte_characters.
12640 Value is the number of glyphs produced. */
12643 display_string (string
, lisp_string
, face_string
, face_string_pos
,
12644 start
, it
, field_width
, precision
, max_x
, multibyte
)
12645 unsigned char *string
;
12646 Lisp_Object lisp_string
;
12647 Lisp_Object face_string
;
12648 int face_string_pos
;
12651 int field_width
, precision
, max_x
;
12654 int hpos_at_start
= it
->hpos
;
12655 int saved_face_id
= it
->face_id
;
12656 struct glyph_row
*row
= it
->glyph_row
;
12658 /* Initialize the iterator IT for iteration over STRING beginning
12659 with index START. We assume that IT may be modified here (which
12660 means that display_line has to do something when displaying a
12661 mini-buffer prompt, which it does). */
12662 reseat_to_string (it
, string
, lisp_string
, start
,
12663 precision
, field_width
, multibyte
);
12665 /* If displaying STRING, set up the face of the iterator
12666 from LISP_STRING, if that's given. */
12667 if (STRINGP (face_string
))
12673 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
12674 0, it
->region_beg_charpos
,
12675 it
->region_end_charpos
,
12676 &endptr
, it
->base_face_id
);
12677 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12678 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
12681 /* Set max_x to the maximum allowed X position. Don't let it go
12682 beyond the right edge of the window. */
12684 max_x
= it
->last_visible_x
;
12686 max_x
= min (max_x
, it
->last_visible_x
);
12688 /* Skip over display elements that are not visible. because IT->w is
12690 if (it
->current_x
< it
->first_visible_x
)
12691 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
12692 MOVE_TO_POS
| MOVE_TO_X
);
12694 row
->ascent
= it
->max_ascent
;
12695 row
->height
= it
->max_ascent
+ it
->max_descent
;
12696 row
->phys_ascent
= it
->max_phys_ascent
;
12697 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12699 /* This condition is for the case that we are called with current_x
12700 past last_visible_x. */
12701 while (it
->current_x
< max_x
)
12703 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
12705 /* Get the next display element. */
12706 if (!get_next_display_element (it
))
12709 /* Produce glyphs. */
12710 x_before
= it
->current_x
;
12711 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
12712 PRODUCE_GLYPHS (it
);
12714 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
12717 while (i
< nglyphs
)
12719 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12721 if (!it
->truncate_lines_p
12722 && x
+ glyph
->pixel_width
> max_x
)
12724 /* End of continued line or max_x reached. */
12725 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12729 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
12731 /* Glyph is at least partially visible. */
12733 if (x
< it
->first_visible_x
)
12734 it
->glyph_row
->x
= x
- it
->first_visible_x
;
12738 /* Glyph is off the left margin of the display area.
12739 Should not happen. */
12743 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12744 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12745 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12746 row
->phys_height
= max (row
->phys_height
,
12747 it
->max_phys_ascent
+ it
->max_phys_descent
);
12748 x
+= glyph
->pixel_width
;
12752 /* Stop if max_x reached. */
12756 /* Stop at line ends. */
12757 if (ITERATOR_AT_END_OF_LINE_P (it
))
12759 it
->continuation_lines_width
= 0;
12763 set_iterator_to_next (it
);
12765 /* Stop if truncating at the right edge. */
12766 if (it
->truncate_lines_p
12767 && it
->current_x
>= it
->last_visible_x
)
12769 /* Add truncation mark, but don't do it if the line is
12770 truncated at a padding space. */
12771 if (IT_CHARPOS (*it
) < it
->string_nchars
)
12773 if (!FRAME_WINDOW_P (it
->f
))
12774 produce_special_glyphs (it
, IT_TRUNCATION
);
12775 it
->glyph_row
->truncated_on_right_p
= 1;
12781 /* Maybe insert a truncation at the left. */
12782 if (it
->first_visible_x
12783 && IT_CHARPOS (*it
) > 0)
12785 if (!FRAME_WINDOW_P (it
->f
))
12786 insert_left_trunc_glyphs (it
);
12787 it
->glyph_row
->truncated_on_left_p
= 1;
12790 it
->face_id
= saved_face_id
;
12792 /* Value is number of columns displayed. */
12793 return it
->hpos
- hpos_at_start
;
12798 /* This is like a combination of memq and assq. Return 1 if PROPVAL
12799 appears as an element of LIST or as the car of an element of LIST.
12800 If PROPVAL is a list, compare each element against LIST in that
12801 way, and return 1 if any element of PROPVAL is found in LIST.
12802 Otherwise return 0. This function cannot quit. */
12805 invisible_p (propval
, list
)
12806 register Lisp_Object propval
;
12809 register Lisp_Object tail
, proptail
;
12810 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12812 register Lisp_Object tem
;
12814 if (EQ (propval
, tem
))
12816 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
12819 if (CONSP (propval
))
12820 for (proptail
= propval
; CONSP (proptail
);
12821 proptail
= XCDR (proptail
))
12823 Lisp_Object propelt
;
12824 propelt
= XCAR (proptail
);
12825 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12827 register Lisp_Object tem
;
12829 if (EQ (propelt
, tem
))
12831 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
12839 /* Return 1 if PROPVAL appears as the car of an element of LIST and
12840 the cdr of that element is non-nil. If PROPVAL is a list, check
12841 each element of PROPVAL in that way, and the first time some
12842 element is found, return 1 if the cdr of that element is non-nil.
12843 Otherwise return 0. This function cannot quit. */
12846 invisible_ellipsis_p (propval
, list
)
12847 register Lisp_Object propval
;
12850 register Lisp_Object tail
, proptail
;
12852 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12854 register Lisp_Object tem
;
12856 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
12857 return ! NILP (XCDR (tem
));
12860 if (CONSP (propval
))
12861 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
12863 Lisp_Object propelt
;
12864 propelt
= XCAR (proptail
);
12865 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12867 register Lisp_Object tem
;
12869 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
12870 return ! NILP (XCDR (tem
));
12879 /***********************************************************************
12881 ***********************************************************************/
12886 Vwith_echo_area_save_vector
= Qnil
;
12887 staticpro (&Vwith_echo_area_save_vector
);
12889 Vmessage_stack
= Qnil
;
12890 staticpro (&Vmessage_stack
);
12892 Qinhibit_redisplay
= intern ("inhibit-redisplay");
12893 staticpro (&Qinhibit_redisplay
);
12896 defsubr (&Sdump_glyph_matrix
);
12897 defsubr (&Sdump_glyph_row
);
12898 defsubr (&Sdump_tool_bar_row
);
12899 defsubr (&Strace_redisplay_toggle
);
12900 defsubr (&Strace_to_stderr
);
12903 staticpro (&Qmenu_bar_update_hook
);
12904 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
12906 staticpro (&Qoverriding_terminal_local_map
);
12907 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
12909 staticpro (&Qoverriding_local_map
);
12910 Qoverriding_local_map
= intern ("overriding-local-map");
12912 staticpro (&Qwindow_scroll_functions
);
12913 Qwindow_scroll_functions
= intern ("window-scroll-functions");
12915 staticpro (&Qredisplay_end_trigger_functions
);
12916 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
12918 staticpro (&Qinhibit_point_motion_hooks
);
12919 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
12921 QCdata
= intern (":data");
12922 staticpro (&QCdata
);
12923 Qdisplay
= intern ("display");
12924 staticpro (&Qdisplay
);
12925 Qspace_width
= intern ("space-width");
12926 staticpro (&Qspace_width
);
12927 Qraise
= intern ("raise");
12928 staticpro (&Qraise
);
12929 Qspace
= intern ("space");
12930 staticpro (&Qspace
);
12931 Qmargin
= intern ("margin");
12932 staticpro (&Qmargin
);
12933 Qleft_margin
= intern ("left-margin");
12934 staticpro (&Qleft_margin
);
12935 Qright_margin
= intern ("right-margin");
12936 staticpro (&Qright_margin
);
12937 Qalign_to
= intern ("align-to");
12938 staticpro (&Qalign_to
);
12939 QCalign_to
= intern (":align-to");
12940 staticpro (&QCalign_to
);
12941 Qrelative_width
= intern ("relative-width");
12942 staticpro (&Qrelative_width
);
12943 QCrelative_width
= intern (":relative-width");
12944 staticpro (&QCrelative_width
);
12945 QCrelative_height
= intern (":relative-height");
12946 staticpro (&QCrelative_height
);
12947 QCeval
= intern (":eval");
12948 staticpro (&QCeval
);
12949 Qwhen
= intern ("when");
12950 staticpro (&Qwhen
);
12951 QCfile
= intern (":file");
12952 staticpro (&QCfile
);
12953 Qfontified
= intern ("fontified");
12954 staticpro (&Qfontified
);
12955 Qfontification_functions
= intern ("fontification-functions");
12956 staticpro (&Qfontification_functions
);
12957 Qtrailing_whitespace
= intern ("trailing-whitespace");
12958 staticpro (&Qtrailing_whitespace
);
12959 Qimage
= intern ("image");
12960 staticpro (&Qimage
);
12962 last_arrow_position
= Qnil
;
12963 last_arrow_string
= Qnil
;
12964 staticpro (&last_arrow_position
);
12965 staticpro (&last_arrow_string
);
12967 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
12968 staticpro (&echo_buffer
[0]);
12969 staticpro (&echo_buffer
[1]);
12971 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
12972 staticpro (&echo_area_buffer
[0]);
12973 staticpro (&echo_area_buffer
[1]);
12975 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
12976 "Non-nil means highlight trailing whitespace.\n\
12977 The face used for trailing whitespace is `trailing-whitespace'.");
12978 Vshow_trailing_whitespace
= Qnil
;
12980 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
12981 "Non-nil means don't actually do any redisplay.\n\
12982 This is used for internal purposes.");
12983 Vinhibit_redisplay
= Qnil
;
12985 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
12986 "String (or mode line construct) included (normally) in `mode-line-format'.");
12987 Vglobal_mode_string
= Qnil
;
12989 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
12990 "Marker for where to display an arrow on top of the buffer text.\n\
12991 This must be the beginning of a line in order to work.\n\
12992 See also `overlay-arrow-string'.");
12993 Voverlay_arrow_position
= Qnil
;
12995 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
12996 "String to display as an arrow. See also `overlay-arrow-position'.");
12997 Voverlay_arrow_string
= Qnil
;
12999 DEFVAR_INT ("scroll-step", &scroll_step
,
13000 "*The number of lines to try scrolling a window by when point moves out.\n\
13001 If that fails to bring point back on frame, point is centered instead.\n\
13002 If this is zero, point is always centered after it moves off frame.");
13004 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
13005 "*Scroll up to this many lines, to bring point back on screen.\n\
13006 A value of zero means to scroll the text to center point vertically\n\
13008 scroll_conservatively
= 0;
13010 DEFVAR_INT ("scroll-margin", &scroll_margin
,
13011 "*Number of lines of margin at the top and bottom of a window.\n\
13012 Recenter the window whenever point gets within this many lines\n\
13013 of the top or bottom of the window.");
13017 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
13020 DEFVAR_BOOL ("truncate-partial-width-windows",
13021 &truncate_partial_width_windows
,
13022 "*Non-nil means truncate lines in all windows less than full frame wide.");
13023 truncate_partial_width_windows
= 1;
13025 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
13026 "*Non-nil means use inverse video for the mode line.");
13027 mode_line_inverse_video
= 1;
13029 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
13030 "*Maximum buffer size for which line number should be displayed.\n\
13031 If the buffer is bigger than this, the line number does not appear\n\
13032 in the mode line.");
13033 line_number_display_limit
= 1000000;
13035 DEFVAR_INT ("line-number-display-limit-width", &line_number_display_limit_width
,
13036 "*Maximum line width (in characters) for line number display.\n\
13037 If the average length of the lines near point is bigger than this, then the\n\
13038 line number may be omitted from the mode line.");
13039 line_number_display_limit_width
= 200;
13041 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
13042 "*Non-nil means highlight region even in nonselected windows.");
13043 highlight_nonselected_windows
= 0;
13045 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
13046 "Non-nil if more than one frame is visible on this display.\n\
13047 Minibuffer-only frames don't count, but iconified frames do.\n\
13048 This variable is not guaranteed to be accurate except while processing\n\
13049 `frame-title-format' and `icon-title-format'.");
13051 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
13052 "Template for displaying the title bar of visible frames.\n\
13053 \(Assuming the window manager supports this feature.)\n\
13054 This variable has the same structure as `mode-line-format' (which see),\n\
13055 and is used only on frames for which no explicit name has been set\n\
13056 \(see `modify-frame-parameters').");
13057 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
13058 "Template for displaying the title bar of an iconified frame.\n\
13059 \(Assuming the window manager supports this feature.)\n\
13060 This variable has the same structure as `mode-line-format' (which see),\n\
13061 and is used only on frames for which no explicit name has been set\n\
13062 \(see `modify-frame-parameters').");
13064 = Vframe_title_format
13065 = Fcons (intern ("multiple-frames"),
13066 Fcons (build_string ("%b"),
13067 Fcons (Fcons (build_string (""),
13068 Fcons (intern ("invocation-name"),
13069 Fcons (build_string ("@"),
13070 Fcons (intern ("system-name"),
13074 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
13075 "Maximum number of lines to keep in the message log buffer.\n\
13076 If nil, disable message logging. If t, log messages but don't truncate\n\
13077 the buffer when it becomes large.");
13078 XSETFASTINT (Vmessage_log_max
, 50);
13080 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
13081 "Functions called before redisplay, if window sizes have changed.\n\
13082 The value should be a list of functions that take one argument.\n\
13083 Just before redisplay, for each frame, if any of its windows have changed\n\
13084 size since the last redisplay, or have been split or deleted,\n\
13085 all the functions in the list are called, with the frame as argument.");
13086 Vwindow_size_change_functions
= Qnil
;
13088 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
13089 "List of Functions to call before redisplaying a window with scrolling.\n\
13090 Each function is called with two arguments, the window\n\
13091 and its new display-start position. Note that the value of `window-end'\n\
13092 is not valid when these functions are called.");
13093 Vwindow_scroll_functions
= Qnil
;
13095 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
13096 "*Non-nil means automatically resize tool-bars.\n\
13097 This increases a tool-bar's height if not all tool-bar items are visible.\n\
13098 It decreases a tool-bar's height when it would display blank lines\n\
13100 auto_resize_tool_bars_p
= 1;
13102 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
13103 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
13104 auto_raise_tool_bar_buttons_p
= 1;
13106 DEFVAR_INT ("tool-bar-button-margin", &tool_bar_button_margin
,
13107 "*Margin around tool-bar buttons in pixels.");
13108 tool_bar_button_margin
= 1;
13110 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
13111 "Relief thickness of tool-bar buttons.");
13112 tool_bar_button_relief
= 3;
13114 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
13115 "List of functions to call to fontify regions of text.\n\
13116 Each function is called with one argument POS. Functions must\n\
13117 fontify a region starting at POS in the current buffer, and give\n\
13118 fontified regions the property `fontified'.\n\
13119 This variable automatically becomes buffer-local when set.");
13120 Vfontification_functions
= Qnil
;
13121 Fmake_local_variable (Qfontification_functions
);
13123 DEFVAR_BOOL ("unibyte-display-via-language-environment",
13124 &unibyte_display_via_language_environment
,
13125 "*Non-nil means display unibyte text according to language environment.\n\
13126 Specifically this means that unibyte non-ASCII characters\n\
13127 are displayed by converting them to the equivalent multibyte characters\n\
13128 according to the current language environment. As a result, they are\n\
13129 displayed according to the current fontset.");
13130 unibyte_display_via_language_environment
= 0;
13132 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
13133 "*Maximum height for resizing mini-windows.\n\
13134 If a float, it specifies a fraction of the mini-window frame's height.\n\
13135 If an integer, it specifies a number of lines.\n\
13136 If nil, don't resize.");
13137 Vmax_mini_window_height
= make_float (0.25);
13139 DEFVAR_BOOL ("cursor-in-non-selected-windows",
13140 &cursor_in_non_selected_windows
,
13141 "*Non-nil means display a hollow cursor in non-selected windows.\n\
13142 Nil means don't display a cursor there.");
13143 cursor_in_non_selected_windows
= 1;
13145 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
13146 "*Non-nil means scroll the display automatically to make point visible.");
13147 automatic_hscrolling_p
= 1;
13149 DEFVAR_LISP ("image-types", &Vimage_types
,
13150 "List of supported image types.\n\
13151 Each element of the list is a symbol for a supported image type.");
13152 Vimage_types
= Qnil
;
13156 /* Initialize this module when Emacs starts. */
13161 Lisp_Object root_window
;
13162 struct window
*mini_w
;
13164 CHARPOS (this_line_start_pos
) = 0;
13166 mini_w
= XWINDOW (minibuf_window
);
13167 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
13169 if (!noninteractive
)
13171 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
13174 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
13175 set_window_height (root_window
,
13176 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
13178 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
13179 set_window_height (minibuf_window
, 1, 0);
13181 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
13182 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
13184 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
13185 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
13186 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
13188 /* The default ellipsis glyphs `...'. */
13189 for (i
= 0; i
< 3; ++i
)
13190 XSETFASTINT (default_invis_vector
[i
], '.');
13193 #ifdef HAVE_WINDOW_SYSTEM
13195 /* Allocate the buffer for frame titles. */
13197 frame_title_buf
= (char *) xmalloc (size
);
13198 frame_title_buf_end
= frame_title_buf
+ size
;
13199 frame_title_ptr
= NULL
;
13201 #endif /* HAVE_WINDOW_SYSTEM */