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 /* Value returned from text property handlers (see below). */
525 HANDLED_RECOMPUTE_PROPS
,
526 HANDLED_OVERLAY_STRING_CONSUMED
,
530 /* A description of text properties that redisplay is interested
535 /* The name of the property. */
538 /* A unique index for the property. */
541 /* A handler function called to set up iterator IT from the property
542 at IT's current position. Value is used to steer handle_stop. */
543 enum prop_handled (*handler
) P_ ((struct it
*it
));
546 static enum prop_handled handle_face_prop
P_ ((struct it
*));
547 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
548 static enum prop_handled handle_display_prop
P_ ((struct it
*));
549 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
550 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
551 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
553 /* Properties handled by iterators. */
555 static struct props it_props
[] =
557 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
558 /* Handle `face' before `display' because some sub-properties of
559 `display' need to know the face. */
560 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
561 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
562 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
563 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
567 /* Value is the position described by X. If X is a marker, value is
568 the marker_position of X. Otherwise, value is X. */
570 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
572 /* Enumeration returned by some move_it_.* functions internally. */
576 /* Not used. Undefined value. */
579 /* Move ended at the requested buffer position or ZV. */
580 MOVE_POS_MATCH_OR_ZV
,
582 /* Move ended at the requested X pixel position. */
585 /* Move within a line ended at the end of a line that must be
589 /* Move within a line ended at the end of a line that would
590 be displayed truncated. */
593 /* Move within a line ended at a line end. */
599 /* Function prototypes. */
601 static void ensure_echo_area_buffers
P_ ((void));
602 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
604 struct glyph_row
*));
605 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
606 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
607 static void clear_garbaged_frames
P_ ((void));
608 static int current_message_1
P_ ((Lisp_Object
*));
609 static int truncate_message_1
P_ ((int));
610 static int set_message_1
P_ ((char *s
, Lisp_Object
, int, int));
611 static int display_echo_area
P_ ((struct window
*));
612 static int display_echo_area_1
P_ ((struct window
*));
613 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
614 static int string_char_and_length
P_ ((unsigned char *, int, int *));
615 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
617 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
618 static Lisp_Object eval_handler
P_ ((Lisp_Object
));
619 static Lisp_Object eval_form
P_ ((Lisp_Object
));
620 static void insert_left_trunc_glyphs
P_ ((struct it
*));
621 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
622 static void extend_face_to_end_of_line
P_ ((struct it
*));
623 static int append_space
P_ ((struct it
*, int));
624 static void make_cursor_line_fully_visible
P_ ((struct window
*));
625 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
626 static int trailing_whitespace_p
P_ ((int));
627 static int message_log_check_duplicate
P_ ((int, int, int, int));
628 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
629 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
630 static void push_it
P_ ((struct it
*));
631 static void pop_it
P_ ((struct it
*));
632 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
633 static void redisplay_internal
P_ ((int));
634 static int echo_area_display
P_ ((int));
635 static void redisplay_windows
P_ ((Lisp_Object
));
636 static void redisplay_window
P_ ((Lisp_Object
, int));
637 static void update_menu_bar
P_ ((struct frame
*, int));
638 static int try_window_reusing_current_matrix
P_ ((struct window
*));
639 static int try_window_id
P_ ((struct window
*));
640 static int display_line
P_ ((struct it
*));
641 static void display_mode_lines
P_ ((struct window
*));
642 static void display_mode_line
P_ ((struct window
*, enum face_id
,
644 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
645 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
646 static void display_menu_bar
P_ ((struct window
*));
647 static int display_count_lines
P_ ((int, int, int, int, int *));
648 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
649 int, int, struct it
*, int, int, int, int));
650 static void compute_line_metrics
P_ ((struct it
*));
651 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
652 static int get_overlay_strings
P_ ((struct it
*));
653 static void next_overlay_string
P_ ((struct it
*));
654 void set_iterator_to_next
P_ ((struct it
*));
655 static void reseat
P_ ((struct it
*, struct text_pos
, int));
656 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
657 static void back_to_previous_visible_line_start
P_ ((struct it
*));
658 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
659 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
660 static int next_element_from_display_vector
P_ ((struct it
*));
661 static int next_element_from_string
P_ ((struct it
*));
662 static int next_element_from_c_string
P_ ((struct it
*));
663 static int next_element_from_buffer
P_ ((struct it
*));
664 static int next_element_from_composition
P_ ((struct it
*));
665 static int next_element_from_image
P_ ((struct it
*));
666 static int next_element_from_stretch
P_ ((struct it
*));
667 static void load_overlay_strings
P_ ((struct it
*));
668 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
669 struct display_pos
*));
670 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
671 Lisp_Object
, int, int, int, int));
672 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
674 void move_it_vertically_backward
P_ ((struct it
*, int));
675 static void init_to_row_start
P_ ((struct it
*, struct window
*,
676 struct glyph_row
*));
677 static void init_to_row_end
P_ ((struct it
*, struct window
*,
678 struct glyph_row
*));
679 static void back_to_previous_line_start
P_ ((struct it
*));
680 static void forward_to_next_line_start
P_ ((struct it
*));
681 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
683 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
684 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
685 static int number_of_chars
P_ ((unsigned char *, int));
686 static void compute_stop_pos
P_ ((struct it
*));
687 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
689 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
690 static int next_overlay_change
P_ ((int));
691 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
692 Lisp_Object
, struct text_pos
*));
694 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
695 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
697 #ifdef HAVE_WINDOW_SYSTEM
699 static void update_tool_bar
P_ ((struct frame
*, int));
700 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
701 static int redisplay_tool_bar
P_ ((struct frame
*));
702 static void display_tool_bar_line
P_ ((struct it
*));
704 #endif /* HAVE_WINDOW_SYSTEM */
707 /***********************************************************************
708 Window display dimensions
709 ***********************************************************************/
711 /* Return the window-relative maximum y + 1 for glyph rows displaying
712 text in window W. This is the height of W minus the height of a
713 mode line, if any. */
716 window_text_bottom_y (w
)
719 struct frame
*f
= XFRAME (w
->frame
);
720 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
722 if (WINDOW_WANTS_MODELINE_P (w
))
723 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
728 /* Return the pixel width of display area AREA of window W. AREA < 0
729 means return the total width of W, not including bitmap areas to
730 the left and right of the window. */
733 window_box_width (w
, area
)
737 struct frame
*f
= XFRAME (w
->frame
);
738 int width
= XFASTINT (w
->width
);
740 if (!w
->pseudo_window_p
)
742 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
744 if (area
== TEXT_AREA
)
746 if (INTEGERP (w
->left_margin_width
))
747 width
-= XFASTINT (w
->left_margin_width
);
748 if (INTEGERP (w
->right_margin_width
))
749 width
-= XFASTINT (w
->right_margin_width
);
751 else if (area
== LEFT_MARGIN_AREA
)
752 width
= (INTEGERP (w
->left_margin_width
)
753 ? XFASTINT (w
->left_margin_width
) : 0);
754 else if (area
== RIGHT_MARGIN_AREA
)
755 width
= (INTEGERP (w
->right_margin_width
)
756 ? XFASTINT (w
->right_margin_width
) : 0);
759 return width
* CANON_X_UNIT (f
);
763 /* Return the pixel height of the display area of window W, not
764 including mode lines of W, if any.. */
767 window_box_height (w
)
770 struct frame
*f
= XFRAME (w
->frame
);
771 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
773 if (WINDOW_WANTS_MODELINE_P (w
))
774 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
776 if (WINDOW_WANTS_HEADER_LINE_P (w
))
777 height
-= CURRENT_HEADER_LINE_HEIGHT (w
);
783 /* Return the frame-relative coordinate of the left edge of display
784 area AREA of window W. AREA < 0 means return the left edge of the
785 whole window, to the right of any bitmap area at the left side of
789 window_box_left (w
, area
)
793 struct frame
*f
= XFRAME (w
->frame
);
794 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
796 if (!w
->pseudo_window_p
)
798 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
799 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
801 if (area
== TEXT_AREA
)
802 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
803 else if (area
== RIGHT_MARGIN_AREA
)
804 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
805 + window_box_width (w
, TEXT_AREA
));
812 /* Return the frame-relative coordinate of the right edge of display
813 area AREA of window W. AREA < 0 means return the left edge of the
814 whole window, to the left of any bitmap area at the right side of
818 window_box_right (w
, area
)
822 return window_box_left (w
, area
) + window_box_width (w
, area
);
826 /* Get the bounding box of the display area AREA of window W, without
827 mode lines, in frame-relative coordinates. AREA < 0 means the
828 whole window, not including bitmap areas to the left and right of
829 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
830 coordinates of the upper-left corner of the box. Return in
831 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
834 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
837 int *box_x
, *box_y
, *box_width
, *box_height
;
839 struct frame
*f
= XFRAME (w
->frame
);
841 *box_width
= window_box_width (w
, area
);
842 *box_height
= window_box_height (w
);
843 *box_x
= window_box_left (w
, area
);
844 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
845 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
846 if (WINDOW_WANTS_HEADER_LINE_P (w
))
847 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
851 /* Get the bounding box of the display area AREA of window W, without
852 mode lines. AREA < 0 means the whole window, not including bitmap
853 areas to the left and right of the window. Return in *TOP_LEFT_X
854 and TOP_LEFT_Y the frame-relative pixel coordinates of the
855 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
856 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
860 window_box_edges (w
, area
, top_left_x
, top_left_y
,
861 bottom_right_x
, bottom_right_y
)
864 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
866 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
868 *bottom_right_x
+= *top_left_x
;
869 *bottom_right_y
+= *top_left_y
;
874 /***********************************************************************
876 ***********************************************************************/
878 /* Return the next character from STR which is MAXLEN bytes long.
879 Return in *LEN the length of the character. This is like
880 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
881 we find one, we return a `?', but with the length of the illegal
885 string_char_and_length (str
, maxlen
, len
)
891 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
892 if (!CHAR_VALID_P (c
, 1))
893 /* We may not change the length here because other places in Emacs
894 don't use this function, i.e. they silently accept illegal
903 /* Given a position POS containing a valid character and byte position
904 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
906 static struct text_pos
907 string_pos_nchars_ahead (pos
, string
, nchars
)
912 xassert (STRINGP (string
) && nchars
>= 0);
914 if (STRING_MULTIBYTE (string
))
916 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
917 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
922 string_char_and_length (p
, rest
, &len
);
923 p
+= len
, rest
-= len
;
926 BYTEPOS (pos
) += len
;
930 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
936 /* Value is the text position, i.e. character and byte position,
937 for character position CHARPOS in STRING. */
939 static INLINE
struct text_pos
940 string_pos (charpos
, string
)
945 xassert (STRINGP (string
));
946 xassert (charpos
>= 0);
947 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
952 /* Value is a text position, i.e. character and byte position, for
953 character position CHARPOS in C string S. MULTIBYTE_P non-zero
954 means recognize multibyte characters. */
956 static struct text_pos
957 c_string_pos (charpos
, s
, multibyte_p
)
965 xassert (charpos
>= 0);
969 int rest
= strlen (s
), len
;
971 SET_TEXT_POS (pos
, 0, 0);
974 string_char_and_length (s
, rest
, &len
);
975 s
+= len
, rest
-= len
;
978 BYTEPOS (pos
) += len
;
982 SET_TEXT_POS (pos
, charpos
, charpos
);
988 /* Value is the number of characters in C string S. MULTIBYTE_P
989 non-zero means recognize multibyte characters. */
992 number_of_chars (s
, multibyte_p
)
1000 int rest
= strlen (s
), len
;
1001 unsigned char *p
= (unsigned char *) s
;
1003 for (nchars
= 0; rest
> 0; ++nchars
)
1005 string_char_and_length (p
, rest
, &len
);
1006 rest
-= len
, p
+= len
;
1010 nchars
= strlen (s
);
1016 /* Compute byte position NEWPOS->bytepos corresponding to
1017 NEWPOS->charpos. POS is a known position in string STRING.
1018 NEWPOS->charpos must be >= POS.charpos. */
1021 compute_string_pos (newpos
, pos
, string
)
1022 struct text_pos
*newpos
, pos
;
1025 xassert (STRINGP (string
));
1026 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1028 if (STRING_MULTIBYTE (string
))
1029 *newpos
= string_pos_nchars_ahead (pos
, string
,
1030 CHARPOS (*newpos
) - CHARPOS (pos
));
1032 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1037 /***********************************************************************
1038 Lisp form evaluation
1039 ***********************************************************************/
1041 /* Error handler for eval_form. */
1051 /* Evaluate SEXPR and return the result, or nil if something went
1058 int count
= specpdl_ptr
- specpdl
;
1060 specbind (Qinhibit_redisplay
, Qt
);
1061 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, eval_handler
);
1062 return unbind_to (count
, val
);
1067 /***********************************************************************
1069 ***********************************************************************/
1073 /* Define CHECK_IT to perform sanity checks on iterators.
1074 This is for debugging. It is too slow to do unconditionally. */
1080 if (it
->method
== next_element_from_string
)
1082 xassert (STRINGP (it
->string
));
1083 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1085 else if (it
->method
== next_element_from_buffer
)
1087 /* Check that character and byte positions agree. */
1088 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1092 xassert (it
->current
.dpvec_index
>= 0);
1094 xassert (it
->current
.dpvec_index
< 0);
1097 #define CHECK_IT(IT) check_it ((IT))
1101 #define CHECK_IT(IT) (void) 0
1108 /* Check that the window end of window W is what we expect it
1109 to be---the last row in the current matrix displaying text. */
1112 check_window_end (w
)
1115 if (!MINI_WINDOW_P (w
)
1116 && !NILP (w
->window_end_valid
))
1118 struct glyph_row
*row
;
1119 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1120 XFASTINT (w
->window_end_vpos
)),
1122 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1123 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1127 #define CHECK_WINDOW_END(W) check_window_end ((W))
1129 #else /* not GLYPH_DEBUG */
1131 #define CHECK_WINDOW_END(W) (void) 0
1133 #endif /* not GLYPH_DEBUG */
1137 /***********************************************************************
1138 Iterator initialization
1139 ***********************************************************************/
1141 /* Initialize IT for displaying current_buffer in window W, starting
1142 at character position CHARPOS. CHARPOS < 0 means that no buffer
1143 position is specified which is useful when the iterator is assigned
1144 a position later. BYTEPOS is the byte position corresponding to
1145 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1147 If ROW is not null, calls to produce_glyphs with IT as parameter
1148 will produce glyphs in that row.
1150 BASE_FACE_ID is the id of a base face to use. It must be one of
1151 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1152 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1153 displaying the tool-bar.
1155 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1156 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1157 corresponding mode line glyph row of the desired matrix of W. */
1160 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1163 int charpos
, bytepos
;
1164 struct glyph_row
*row
;
1165 enum face_id base_face_id
;
1167 int highlight_region_p
;
1169 /* Some precondition checks. */
1170 xassert (w
!= NULL
&& it
!= NULL
);
1171 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1173 /* If face attributes have been changed since the last redisplay,
1174 free realized faces now because they depend on face definitions
1175 that might have changed. */
1176 if (face_change_count
)
1178 face_change_count
= 0;
1179 free_all_realized_faces (Qnil
);
1182 /* Use one of the mode line rows of W's desired matrix if
1186 if (base_face_id
== MODE_LINE_FACE_ID
)
1187 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1188 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1189 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1193 bzero (it
, sizeof *it
);
1194 it
->current
.overlay_string_index
= -1;
1195 it
->current
.dpvec_index
= -1;
1196 it
->base_face_id
= base_face_id
;
1198 /* The window in which we iterate over current_buffer: */
1199 XSETWINDOW (it
->window
, w
);
1201 it
->f
= XFRAME (w
->frame
);
1203 /* Extra space between lines (on window systems only). */
1204 if (base_face_id
== DEFAULT_FACE_ID
1205 && FRAME_WINDOW_P (it
->f
))
1207 if (NATNUMP (current_buffer
->extra_line_spacing
))
1208 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1209 else if (it
->f
->extra_line_spacing
> 0)
1210 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1213 /* If realized faces have been removed, e.g. because of face
1214 attribute changes of named faces, recompute them. */
1215 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1216 recompute_basic_faces (it
->f
);
1218 /* Current value of the `space-width', and 'height' properties. */
1219 it
->space_width
= Qnil
;
1220 it
->font_height
= Qnil
;
1222 /* Are control characters displayed as `^C'? */
1223 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1225 /* -1 means everything between a CR and the following line end
1226 is invisible. >0 means lines indented more than this value are
1228 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1229 ? XFASTINT (current_buffer
->selective_display
)
1230 : (!NILP (current_buffer
->selective_display
)
1232 it
->selective_display_ellipsis_p
1233 = !NILP (current_buffer
->selective_display_ellipses
);
1235 /* Display table to use. */
1236 it
->dp
= window_display_table (w
);
1238 /* Are multibyte characters enabled in current_buffer? */
1239 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1241 /* Non-zero if we should highlight the region. */
1243 = (!NILP (Vtransient_mark_mode
)
1244 && !NILP (current_buffer
->mark_active
)
1245 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1247 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1248 start and end of a visible region in window IT->w. Set both to
1249 -1 to indicate no region. */
1250 if (highlight_region_p
1251 /* Maybe highlight only in selected window. */
1252 && (/* Either show region everywhere. */
1253 highlight_nonselected_windows
1254 /* Or show region in the selected window. */
1255 || w
== XWINDOW (selected_window
)
1256 /* Or show the region if we are in the mini-buffer and W is
1257 the window the mini-buffer refers to. */
1258 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1259 && w
== XWINDOW (Vminibuf_scroll_window
))))
1261 int charpos
= marker_position (current_buffer
->mark
);
1262 it
->region_beg_charpos
= min (PT
, charpos
);
1263 it
->region_end_charpos
= max (PT
, charpos
);
1266 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1268 /* Get the position at which the redisplay_end_trigger hook should
1269 be run, if it is to be run at all. */
1270 if (MARKERP (w
->redisplay_end_trigger
)
1271 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1272 it
->redisplay_end_trigger_charpos
1273 = marker_position (w
->redisplay_end_trigger
);
1274 else if (INTEGERP (w
->redisplay_end_trigger
))
1275 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1277 /* Correct bogus values of tab_width. */
1278 it
->tab_width
= XINT (current_buffer
->tab_width
);
1279 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1282 /* Are lines in the display truncated? */
1283 it
->truncate_lines_p
1284 = (base_face_id
!= DEFAULT_FACE_ID
1285 || XINT (it
->w
->hscroll
)
1286 || (truncate_partial_width_windows
1287 && !WINDOW_FULL_WIDTH_P (it
->w
))
1288 || !NILP (current_buffer
->truncate_lines
));
1290 /* Get dimensions of truncation and continuation glyphs. These are
1291 displayed as bitmaps under X, so we don't need them for such
1293 if (!FRAME_WINDOW_P (it
->f
))
1295 if (it
->truncate_lines_p
)
1297 /* We will need the truncation glyph. */
1298 xassert (it
->glyph_row
== NULL
);
1299 produce_special_glyphs (it
, IT_TRUNCATION
);
1300 it
->truncation_pixel_width
= it
->pixel_width
;
1304 /* We will need the continuation glyph. */
1305 xassert (it
->glyph_row
== NULL
);
1306 produce_special_glyphs (it
, IT_CONTINUATION
);
1307 it
->continuation_pixel_width
= it
->pixel_width
;
1310 /* Reset these values to zero becaue the produce_special_glyphs
1311 above has changed them. */
1312 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1313 it
->phys_ascent
= it
->phys_descent
= 0;
1316 /* Set this after getting the dimensions of truncation and
1317 continuation glyphs, so that we don't produce glyphs when calling
1318 produce_special_glyphs, above. */
1319 it
->glyph_row
= row
;
1320 it
->area
= TEXT_AREA
;
1322 /* Get the dimensions of the display area. The display area
1323 consists of the visible window area plus a horizontally scrolled
1324 part to the left of the window. All x-values are relative to the
1325 start of this total display area. */
1326 if (base_face_id
!= DEFAULT_FACE_ID
)
1328 /* Mode lines, menu bar in terminal frames. */
1329 it
->first_visible_x
= 0;
1330 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1335 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1336 it
->last_visible_x
= (it
->first_visible_x
1337 + window_box_width (w
, TEXT_AREA
));
1339 /* If we truncate lines, leave room for the truncator glyph(s) at
1340 the right margin. Otherwise, leave room for the continuation
1341 glyph(s). Truncation and continuation glyphs are not inserted
1342 for window-based redisplay. */
1343 if (!FRAME_WINDOW_P (it
->f
))
1345 if (it
->truncate_lines_p
)
1346 it
->last_visible_x
-= it
->truncation_pixel_width
;
1348 it
->last_visible_x
-= it
->continuation_pixel_width
;
1351 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1352 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1355 /* Leave room for a border glyph. */
1356 if (!FRAME_WINDOW_P (it
->f
)
1357 && !WINDOW_RIGHTMOST_P (it
->w
))
1358 it
->last_visible_x
-= 1;
1360 it
->last_visible_y
= window_text_bottom_y (w
);
1362 /* For mode lines and alike, arrange for the first glyph having a
1363 left box line if the face specifies a box. */
1364 if (base_face_id
!= DEFAULT_FACE_ID
)
1368 it
->face_id
= base_face_id
;
1370 /* If we have a boxed mode line, make the first character appear
1371 with a left box line. */
1372 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1373 if (face
->box
!= FACE_NO_BOX
)
1374 it
->start_of_box_run_p
= 1;
1377 /* If a buffer position was specified, set the iterator there,
1378 getting overlays and face properties from that position. */
1381 it
->end_charpos
= ZV
;
1383 IT_CHARPOS (*it
) = charpos
;
1385 /* Compute byte position if not specified. */
1387 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1389 IT_BYTEPOS (*it
) = bytepos
;
1391 /* Compute faces etc. */
1392 reseat (it
, it
->current
.pos
, 1);
1399 /* Initialize IT for the display of window W with window start POS. */
1402 start_display (it
, w
, pos
)
1405 struct text_pos pos
;
1407 int start_at_line_beg_p
;
1408 struct glyph_row
*row
;
1409 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1412 row
= w
->desired_matrix
->rows
+ first_vpos
;
1413 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1414 first_y
= it
->current_y
;
1416 /* If window start is not at a line start, move back to the line
1417 start. This makes sure that we take continuation lines into
1419 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1420 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1421 if (!start_at_line_beg_p
)
1422 reseat_at_previous_visible_line_start (it
);
1424 /* If window start is not at a line start, skip forward to POS to
1425 get the correct continuation_lines_width and current_x. */
1426 if (!start_at_line_beg_p
)
1428 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1430 /* If lines are continued, this line may end in the middle of a
1431 multi-glyph character (e.g. a control character displayed as
1432 \003, or in the middle of an overlay string). In this case
1433 move_it_to above will not have taken us to the start of
1434 the continuation line but to the end of the continued line. */
1435 if (!it
->truncate_lines_p
&& it
->current_x
> 0)
1437 if (it
->current
.dpvec_index
>= 0
1438 || it
->current
.overlay_string_index
>= 0)
1440 set_iterator_to_next (it
);
1441 move_it_in_display_line_to (it
, -1, -1, 0);
1443 it
->continuation_lines_width
+= it
->current_x
;
1446 it
->current_y
= first_y
;
1448 it
->current_x
= it
->hpos
= 0;
1451 #if 0 /* Don't assert the following because start_display is sometimes
1452 called intentionally with a window start that is not at a
1453 line start. Please leave this code in as a comment. */
1455 /* Window start should be on a line start, now. */
1456 xassert (it
->continuation_lines_width
1457 || IT_CHARPOS (it
) == BEGV
1458 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1463 /* Initialize IT for stepping through current_buffer in window W,
1464 starting at position POS that includes overlay string and display
1465 vector/ control character translation position information. */
1468 init_from_display_pos (it
, w
, pos
)
1471 struct display_pos
*pos
;
1473 /* Keep in mind: the call to reseat in init_iterator skips invisible
1474 text, so we might end up at a position different from POS. This
1475 is only a problem when POS is a row start after a newline and an
1476 overlay starts there with an after-string, and the overlay has an
1477 invisible property. Since we don't skip invisible text in
1478 display_line and elsewhere immediately after consuming the
1479 newline before the row start, such a POS will not be in a string,
1480 but the call to init_iterator below will move us to the
1482 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1483 NULL
, DEFAULT_FACE_ID
);
1485 /* If position is within an overlay string, set up IT to
1486 the right overlay string. */
1487 if (pos
->overlay_string_index
>= 0)
1491 /* We already have the first chunk of overlay strings in
1492 IT->overlay_strings. Load more until the one for
1493 pos->overlay_string_index is in IT->overlay_strings. */
1494 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1496 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1497 it
->current
.overlay_string_index
= 0;
1500 load_overlay_strings (it
);
1501 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1505 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1506 relative_index
= (it
->current
.overlay_string_index
1507 % OVERLAY_STRING_CHUNK_SIZE
);
1508 it
->string
= it
->overlay_strings
[relative_index
];
1509 it
->current
.string_pos
= pos
->string_pos
;
1510 it
->method
= next_element_from_string
;
1512 else if (CHARPOS (pos
->string_pos
) >= 0)
1514 /* Recorded position is not in an overlay string, but in another
1515 string. This can only be a string from a `display' property.
1516 IT should already be filled with that string. */
1517 it
->current
.string_pos
= pos
->string_pos
;
1518 xassert (STRINGP (it
->string
));
1521 /* Restore position in display vector translations or control
1522 character translations. */
1523 if (pos
->dpvec_index
>= 0)
1525 /* This fills IT->dpvec. */
1526 get_next_display_element (it
);
1527 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1528 it
->current
.dpvec_index
= pos
->dpvec_index
;
1535 /* Initialize IT for stepping through current_buffer in window W
1536 starting at ROW->start. */
1539 init_to_row_start (it
, w
, row
)
1542 struct glyph_row
*row
;
1544 init_from_display_pos (it
, w
, &row
->start
);
1545 it
->continuation_lines_width
= row
->continuation_lines_width
;
1550 /* Initialize IT for stepping through current_buffer in window W
1551 starting in the line following ROW, i.e. starting at ROW->end. */
1554 init_to_row_end (it
, w
, row
)
1557 struct glyph_row
*row
;
1559 init_from_display_pos (it
, w
, &row
->end
);
1561 if (row
->continued_p
)
1562 it
->continuation_lines_width
= (row
->continuation_lines_width
1563 + row
->pixel_width
);
1570 /***********************************************************************
1572 ***********************************************************************/
1574 /* Called when IT reaches IT->stop_charpos. Handle text property and
1575 overlay changes. Set IT->stop_charpos to the next position where
1582 enum prop_handled handled
;
1583 int handle_overlay_change_p
= 1;
1587 it
->current
.dpvec_index
= -1;
1591 handled
= HANDLED_NORMALLY
;
1593 /* Call text property handlers. */
1594 for (p
= it_props
; p
->handler
; ++p
)
1596 handled
= p
->handler (it
);
1598 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1600 else if (handled
== HANDLED_RETURN
)
1602 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1603 handle_overlay_change_p
= 0;
1606 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1608 /* Don't check for overlay strings below when set to deliver
1609 characters from a display vector. */
1610 if (it
->method
== next_element_from_display_vector
)
1611 handle_overlay_change_p
= 0;
1613 /* Handle overlay changes. */
1614 if (handle_overlay_change_p
)
1615 handled
= handle_overlay_change (it
);
1617 /* Determine where to stop next. */
1618 if (handled
== HANDLED_NORMALLY
)
1619 compute_stop_pos (it
);
1622 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1626 /* Compute IT->stop_charpos from text property and overlay change
1627 information for IT's current position. */
1630 compute_stop_pos (it
)
1633 register INTERVAL iv
, next_iv
;
1634 Lisp_Object object
, limit
, position
;
1636 /* If nowhere else, stop at the end. */
1637 it
->stop_charpos
= it
->end_charpos
;
1639 if (STRINGP (it
->string
))
1641 /* Strings are usually short, so don't limit the search for
1643 object
= it
->string
;
1645 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1651 /* If next overlay change is in front of the current stop pos
1652 (which is IT->end_charpos), stop there. Note: value of
1653 next_overlay_change is point-max if no overlay change
1655 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1656 if (charpos
< it
->stop_charpos
)
1657 it
->stop_charpos
= charpos
;
1659 /* If showing the region, we have to stop at the region
1660 start or end because the face might change there. */
1661 if (it
->region_beg_charpos
> 0)
1663 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1664 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1665 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1666 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1669 /* Set up variables for computing the stop position from text
1670 property changes. */
1671 XSETBUFFER (object
, current_buffer
);
1672 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1673 XSETFASTINT (position
, IT_CHARPOS (*it
));
1677 /* Get the interval containing IT's position. Value is a null
1678 interval if there isn't such an interval. */
1679 iv
= validate_interval_range (object
, &position
, &position
, 0);
1680 if (!NULL_INTERVAL_P (iv
))
1682 Lisp_Object values_here
[LAST_PROP_IDX
];
1685 /* Get properties here. */
1686 for (p
= it_props
; p
->handler
; ++p
)
1687 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1689 /* Look for an interval following iv that has different
1691 for (next_iv
= next_interval (iv
);
1692 (!NULL_INTERVAL_P (next_iv
)
1694 || XFASTINT (limit
) > next_iv
->position
));
1695 next_iv
= next_interval (next_iv
))
1697 for (p
= it_props
; p
->handler
; ++p
)
1699 Lisp_Object new_value
;
1701 new_value
= textget (next_iv
->plist
, *p
->name
);
1702 if (!EQ (values_here
[p
->idx
], new_value
))
1710 if (!NULL_INTERVAL_P (next_iv
))
1712 if (INTEGERP (limit
)
1713 && next_iv
->position
>= XFASTINT (limit
))
1714 /* No text property change up to limit. */
1715 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1717 /* Text properties change in next_iv. */
1718 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1722 xassert (STRINGP (it
->string
)
1723 || (it
->stop_charpos
>= BEGV
1724 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1728 /* Return the position of the next overlay change after POS in
1729 current_buffer. Value is point-max if no overlay change
1730 follows. This is like `next-overlay-change' but doesn't use
1734 next_overlay_change (pos
)
1739 Lisp_Object
*overlays
;
1743 /* Get all overlays at the given position. */
1745 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1746 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1747 if (noverlays
> len
)
1750 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1751 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1754 /* If any of these overlays ends before endpos,
1755 use its ending point instead. */
1756 for (i
= 0; i
< noverlays
; ++i
)
1761 oend
= OVERLAY_END (overlays
[i
]);
1762 oendpos
= OVERLAY_POSITION (oend
);
1763 endpos
= min (endpos
, oendpos
);
1771 /***********************************************************************
1773 ***********************************************************************/
1775 /* Handle changes in the `fontified' property of the current buffer by
1776 calling hook functions from Qfontification_functions to fontify
1779 static enum prop_handled
1780 handle_fontified_prop (it
)
1783 Lisp_Object prop
, pos
;
1784 enum prop_handled handled
= HANDLED_NORMALLY
;
1785 struct gcpro gcpro1
;
1787 /* Get the value of the `fontified' property at IT's current buffer
1788 position. (The `fontified' property doesn't have a special
1789 meaning in strings.) If the value is nil, call functions from
1790 Qfontification_functions. */
1791 if (!STRINGP (it
->string
)
1793 && !NILP (Vfontification_functions
)
1794 && (pos
= make_number (IT_CHARPOS (*it
)),
1795 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1798 Lisp_Object args
[2];
1801 /* Run the hook functions. */
1802 args
[0] = Qfontification_functions
;
1804 Frun_hook_with_args (2, args
);
1806 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
1807 something. This avoids an endless loop if they failed to
1808 fontify the text for which reason ever. */
1809 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
1810 handled
= HANDLED_RECOMPUTE_PROPS
;
1819 /***********************************************************************
1821 ***********************************************************************/
1823 /* Set up iterator IT from face properties at its current position.
1824 Called from handle_stop. */
1826 static enum prop_handled
1827 handle_face_prop (it
)
1830 int new_face_id
, next_stop
;
1832 if (!STRINGP (it
->string
))
1835 = face_at_buffer_position (it
->w
,
1837 it
->region_beg_charpos
,
1838 it
->region_end_charpos
,
1841 + TEXT_PROP_DISTANCE_LIMIT
),
1844 /* Is this a start of a run of characters with box face?
1845 Caveat: this can be called for a freshly initialized
1846 iterator; face_id is -1 is this case. We know that the new
1847 face will not change until limit, i.e. if the new face has a
1848 box, all characters up to limit will have one. But, as
1849 usual, we don't know whether limit is really the end. */
1850 if (new_face_id
!= it
->face_id
)
1852 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1854 /* If new face has a box but old face has not, this is
1855 the start of a run of characters with box, i.e. it has
1856 a shadow on the left side. The value of face_id of the
1857 iterator will be -1 if this is the initial call that gets
1858 the face. In this case, we have to look in front of IT's
1859 position and see whether there is a face != new_face_id. */
1860 it
->start_of_box_run_p
1861 = (new_face
->box
!= FACE_NO_BOX
1862 && (it
->face_id
>= 0
1863 || IT_CHARPOS (*it
) == BEG
1864 || new_face_id
!= face_before_it_pos (it
)));
1865 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1871 = face_at_string_position (it
->w
,
1873 IT_STRING_CHARPOS (*it
),
1874 (it
->current
.overlay_string_index
>= 0
1877 it
->region_beg_charpos
,
1878 it
->region_end_charpos
,
1882 #if 0 /* This shouldn't be neccessary. Let's check it. */
1883 /* If IT is used to display a mode line we would really like to
1884 use the mode line face instead of the frame's default face. */
1885 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
1886 && new_face_id
== DEFAULT_FACE_ID
)
1887 new_face_id
= MODE_LINE_FACE_ID
;
1890 /* Is this a start of a run of characters with box? Caveat:
1891 this can be called for a freshly allocated iterator; face_id
1892 is -1 is this case. We know that the new face will not
1893 change until the next check pos, i.e. if the new face has a
1894 box, all characters up to that position will have a
1895 box. But, as usual, we don't know whether that position
1896 is really the end. */
1897 if (new_face_id
!= it
->face_id
)
1899 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1900 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1902 /* If new face has a box but old face hasn't, this is the
1903 start of a run of characters with box, i.e. it has a
1904 shadow on the left side. */
1905 it
->start_of_box_run_p
1906 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
1907 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1911 it
->face_id
= new_face_id
;
1912 return HANDLED_NORMALLY
;
1916 /* Compute the face one character before or after the current position
1917 of IT. BEFORE_P non-zero means get the face in front of IT's
1918 position. Value is the id of the face. */
1921 face_before_or_after_it_pos (it
, before_p
)
1926 int next_check_charpos
;
1927 struct text_pos pos
;
1929 xassert (it
->s
== NULL
);
1931 if (STRINGP (it
->string
))
1933 /* No face change past the end of the string (for the case
1934 we are padding with spaces). No face change before the
1936 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
1937 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
1940 /* Set pos to the position before or after IT's current position. */
1942 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
1944 /* For composition, we must check the character after the
1946 pos
= (it
->what
== IT_COMPOSITION
1947 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
1948 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
1950 /* Get the face for ASCII, or unibyte. */
1952 = face_at_string_position (it
->w
,
1955 (it
->current
.overlay_string_index
>= 0
1958 it
->region_beg_charpos
,
1959 it
->region_end_charpos
,
1960 &next_check_charpos
,
1963 /* Correct the face for charsets different from ASCII. Do it
1964 for the multibyte case only. The face returned above is
1965 suitable for unibyte text if IT->string is unibyte. */
1966 if (STRING_MULTIBYTE (it
->string
))
1968 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
1969 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
1971 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
1973 c
= string_char_and_length (p
, rest
, &len
);
1974 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
1979 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
1980 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
1983 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
1984 pos
= it
->current
.pos
;
1987 DEC_TEXT_POS (pos
, it
->multibyte_p
);
1990 if (it
->what
== IT_COMPOSITION
)
1991 /* For composition, we must check the position after the
1993 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
1995 INC_TEXT_POS (pos
, it
->multibyte_p
);
1997 /* Determine face for CHARSET_ASCII, or unibyte. */
1998 face_id
= face_at_buffer_position (it
->w
,
2000 it
->region_beg_charpos
,
2001 it
->region_end_charpos
,
2002 &next_check_charpos
,
2005 /* Correct the face for charsets different from ASCII. Do it
2006 for the multibyte case only. The face returned above is
2007 suitable for unibyte text if current_buffer is unibyte. */
2008 if (it
->multibyte_p
)
2010 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2011 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2012 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2021 /***********************************************************************
2023 ***********************************************************************/
2025 /* Set up iterator IT from invisible properties at its current
2026 position. Called from handle_stop. */
2028 static enum prop_handled
2029 handle_invisible_prop (it
)
2032 enum prop_handled handled
= HANDLED_NORMALLY
;
2034 if (STRINGP (it
->string
))
2036 extern Lisp_Object Qinvisible
;
2037 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2039 /* Get the value of the invisible text property at the
2040 current position. Value will be nil if there is no such
2042 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2043 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2047 handled
= HANDLED_RECOMPUTE_PROPS
;
2049 /* Get the position at which the next change of the
2050 invisible text property can be found in IT->string.
2051 Value will be nil if the property value is the same for
2052 all the rest of IT->string. */
2053 XSETINT (limit
, XSTRING (it
->string
)->size
);
2054 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2057 /* Text at current position is invisible. The next
2058 change in the property is at position end_charpos.
2059 Move IT's current position to that position. */
2060 if (INTEGERP (end_charpos
)
2061 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2063 struct text_pos old
;
2064 old
= it
->current
.string_pos
;
2065 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2066 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2070 /* The rest of the string is invisible. If this is an
2071 overlay string, proceed with the next overlay string
2072 or whatever comes and return a character from there. */
2073 if (it
->current
.overlay_string_index
>= 0)
2075 next_overlay_string (it
);
2076 /* Don't check for overlay strings when we just
2077 finished processing them. */
2078 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2082 struct Lisp_String
*s
= XSTRING (it
->string
);
2083 IT_STRING_CHARPOS (*it
) = s
->size
;
2084 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2091 int visible_p
, newpos
, next_stop
;
2092 Lisp_Object pos
, prop
;
2094 /* First of all, is there invisible text at this position? */
2095 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2096 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2098 /* If we are on invisible text, skip over it. */
2099 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
2101 /* Record whether we have to display an ellipsis for the
2103 int display_ellipsis_p
2104 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2106 handled
= HANDLED_RECOMPUTE_PROPS
;
2108 /* Loop skipping over invisible text. The loop is left at
2109 ZV or with IT on the first char being visible again. */
2112 /* Try to skip some invisible text. Return value is the
2113 position reached which can be equal to IT's position
2114 if there is nothing invisible here. This skips both
2115 over invisible text properties and overlays with
2116 invisible property. */
2117 newpos
= skip_invisible (IT_CHARPOS (*it
),
2118 &next_stop
, ZV
, it
->window
);
2120 /* If we skipped nothing at all we weren't at invisible
2121 text in the first place. If everything to the end of
2122 the buffer was skipped, end the loop. */
2123 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2127 /* We skipped some characters but not necessarily
2128 all there are. Check if we ended up on visible
2129 text. Fget_char_property returns the property of
2130 the char before the given position, i.e. if we
2131 get visible_p = 1, this means that the char at
2132 newpos is visible. */
2133 XSETFASTINT (pos
, newpos
);
2134 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2135 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2138 /* If we ended up on invisible text, proceed to
2139 skip starting with next_stop. */
2141 IT_CHARPOS (*it
) = next_stop
;
2145 /* The position newpos is now either ZV or on visible text. */
2146 IT_CHARPOS (*it
) = newpos
;
2147 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2149 /* Maybe return `...' next for the end of the invisible text. */
2150 if (display_ellipsis_p
)
2153 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2155 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2156 it
->dpvec
= v
->contents
;
2157 it
->dpend
= v
->contents
+ v
->size
;
2161 /* Default `...'. */
2162 it
->dpvec
= default_invis_vector
;
2163 it
->dpend
= default_invis_vector
+ 3;
2166 /* The ellipsis display does not replace the display of
2167 the character at the new position. Indicate this by
2168 setting IT->dpvec_char_len to zero. */
2169 it
->dpvec_char_len
= 0;
2171 it
->current
.dpvec_index
= 0;
2172 it
->method
= next_element_from_display_vector
;
2182 /***********************************************************************
2184 ***********************************************************************/
2186 /* Set up iterator IT from `display' property at its current position.
2187 Called from handle_stop. */
2189 static enum prop_handled
2190 handle_display_prop (it
)
2193 Lisp_Object prop
, object
;
2194 struct text_pos
*position
;
2195 int space_or_image_found_p
;
2197 if (STRINGP (it
->string
))
2199 object
= it
->string
;
2200 position
= &it
->current
.string_pos
;
2205 position
= &it
->current
.pos
;
2208 /* Reset those iterator values set from display property values. */
2209 it
->font_height
= Qnil
;
2210 it
->space_width
= Qnil
;
2213 /* We don't support recursive `display' properties, i.e. string
2214 values that have a string `display' property, that have a string
2215 `display' property etc. */
2216 if (!it
->string_from_display_prop_p
)
2217 it
->area
= TEXT_AREA
;
2219 prop
= Fget_char_property (make_number (position
->charpos
),
2222 return HANDLED_NORMALLY
;
2224 space_or_image_found_p
= 0;
2226 && CONSP (XCAR (prop
))
2227 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2229 /* A list of sub-properties. */
2230 while (CONSP (prop
))
2232 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2233 space_or_image_found_p
= 1;
2237 else if (VECTORP (prop
))
2240 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2241 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2243 space_or_image_found_p
= 1;
2247 if (handle_single_display_prop (it
, prop
, object
, position
))
2248 space_or_image_found_p
= 1;
2251 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2255 /* Value is the position of the end of the `display' property starting
2256 at START_POS in OBJECT. */
2258 static struct text_pos
2259 display_prop_end (it
, object
, start_pos
)
2262 struct text_pos start_pos
;
2265 struct text_pos end_pos
;
2267 end
= next_single_char_property_change (make_number (CHARPOS (start_pos
)),
2268 Qdisplay
, object
, Qnil
);
2269 CHARPOS (end_pos
) = XFASTINT (end
);
2270 if (STRINGP (object
))
2271 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2273 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2279 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2280 is the object in which the `display' property was found. *POSITION
2281 is the position at which it was found.
2283 If PROP is a `space' or `image' sub-property, set *POSITION to the
2284 end position of the `display' property.
2286 Value is non-zero if a `space' or `image' property value was found. */
2289 handle_single_display_prop (it
, prop
, object
, position
)
2293 struct text_pos
*position
;
2296 int space_or_image_found_p
= 0;
2300 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2301 evaluated. If the result is nil, VALUE is ignored. */
2303 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2312 if (!NILP (form
) && !EQ (form
, Qt
))
2314 struct gcpro gcpro1
;
2315 struct text_pos end_pos
, pt
;
2317 end_pos
= display_prop_end (it
, object
, *position
);
2320 /* Temporarily set point to the end position, and then evaluate
2321 the form. This makes `(eolp)' work as FORM. */
2323 BYTEPOS (pt
) = PT_BYTE
;
2324 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2325 form
= eval_form (form
);
2326 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2334 && EQ (XCAR (prop
), Qheight
)
2335 && CONSP (XCDR (prop
)))
2337 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2340 /* `(height HEIGHT)'. */
2341 it
->font_height
= XCAR (XCDR (prop
));
2342 if (!NILP (it
->font_height
))
2344 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2345 int new_height
= -1;
2347 if (CONSP (it
->font_height
)
2348 && (EQ (XCAR (it
->font_height
), Qplus
)
2349 || EQ (XCAR (it
->font_height
), Qminus
))
2350 && CONSP (XCDR (it
->font_height
))
2351 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2353 /* `(+ N)' or `(- N)' where N is an integer. */
2354 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2355 if (EQ (XCAR (it
->font_height
), Qplus
))
2357 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2359 else if (SYMBOLP (it
->font_height
))
2361 /* Call function with current height as argument.
2362 Value is the new height. */
2363 Lisp_Object form
, height
;
2364 struct gcpro gcpro1
;
2366 height
= face
->lface
[LFACE_HEIGHT_INDEX
];
2367 form
= Fcons (it
->font_height
, Fcons (height
, Qnil
));
2369 height
= eval_form (form
);
2370 if (NUMBERP (height
))
2371 new_height
= XFLOATINT (height
);
2374 else if (NUMBERP (it
->font_height
))
2376 /* Value is a multiple of the canonical char height. */
2379 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2380 new_height
= (XFLOATINT (it
->font_height
)
2381 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2385 /* Evaluate IT->font_height with `height' bound to the
2386 current specified height to get the new height. */
2388 int count
= specpdl_ptr
- specpdl
;
2390 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2391 value
= eval_form (it
->font_height
);
2392 unbind_to (count
, Qnil
);
2394 if (NUMBERP (value
))
2395 new_height
= XFLOATINT (value
);
2399 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2402 else if (CONSP (prop
)
2403 && EQ (XCAR (prop
), Qspace_width
)
2404 && CONSP (XCDR (prop
)))
2406 /* `(space_width WIDTH)'. */
2407 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2410 value
= XCAR (XCDR (prop
));
2411 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2412 it
->space_width
= value
;
2414 else if (CONSP (prop
)
2415 && EQ (XCAR (prop
), Qraise
)
2416 && CONSP (XCDR (prop
)))
2418 /* `(raise FACTOR)'. */
2419 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2422 #ifdef HAVE_WINDOW_SYSTEM
2423 value
= XCAR (XCDR (prop
));
2424 if (NUMBERP (value
))
2426 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2427 it
->voffset
= - (XFLOATINT (value
)
2428 * (FONT_HEIGHT (face
->font
)));
2430 #endif /* HAVE_WINDOW_SYSTEM */
2432 else if (!it
->string_from_display_prop_p
)
2434 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2435 VALUE) or `((margin nil) VALUE)' or VALUE. */
2436 Lisp_Object location
, value
;
2437 struct text_pos start_pos
;
2440 /* Characters having this form of property are not displayed, so
2441 we have to find the end of the property. */
2442 space_or_image_found_p
= 1;
2443 start_pos
= *position
;
2444 *position
= display_prop_end (it
, object
, start_pos
);
2447 /* Let's stop at the new position and assume that all
2448 text properties change there. */
2449 it
->stop_charpos
= position
->charpos
;
2451 location
= Qunbound
;
2452 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2456 value
= XCDR (prop
);
2458 value
= XCAR (value
);
2461 if (EQ (XCAR (tem
), Qmargin
)
2462 && (tem
= XCDR (tem
),
2463 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2465 || EQ (tem
, Qleft_margin
)
2466 || EQ (tem
, Qright_margin
))))
2470 if (EQ (location
, Qunbound
))
2476 #ifdef HAVE_WINDOW_SYSTEM
2477 if (FRAME_TERMCAP_P (it
->f
))
2478 valid_p
= STRINGP (value
);
2480 valid_p
= (STRINGP (value
)
2481 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2482 || valid_image_p (value
));
2483 #else /* not HAVE_WINDOW_SYSTEM */
2484 valid_p
= STRINGP (value
);
2485 #endif /* not HAVE_WINDOW_SYSTEM */
2487 if ((EQ (location
, Qleft_margin
)
2488 || EQ (location
, Qright_margin
)
2492 /* Save current settings of IT so that we can restore them
2493 when we are finished with the glyph property value. */
2496 if (NILP (location
))
2497 it
->area
= TEXT_AREA
;
2498 else if (EQ (location
, Qleft_margin
))
2499 it
->area
= LEFT_MARGIN_AREA
;
2501 it
->area
= RIGHT_MARGIN_AREA
;
2503 if (STRINGP (value
))
2506 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2507 it
->current
.overlay_string_index
= -1;
2508 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2509 it
->end_charpos
= it
->string_nchars
2510 = XSTRING (it
->string
)->size
;
2511 it
->method
= next_element_from_string
;
2512 it
->stop_charpos
= 0;
2513 it
->string_from_display_prop_p
= 1;
2515 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2517 it
->method
= next_element_from_stretch
;
2519 it
->current
.pos
= it
->position
= start_pos
;
2521 #ifdef HAVE_WINDOW_SYSTEM
2524 it
->what
= IT_IMAGE
;
2525 it
->image_id
= lookup_image (it
->f
, value
);
2526 it
->position
= start_pos
;
2527 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2528 it
->method
= next_element_from_image
;
2530 /* Say that we don't have consumed the characters with
2531 `display' property yet. The call to pop_it in
2532 set_iterator_to_next will clean this up. */
2533 *position
= start_pos
;
2535 #endif /* HAVE_WINDOW_SYSTEM */
2539 return space_or_image_found_p
;
2544 /***********************************************************************
2545 `composition' property
2546 ***********************************************************************/
2548 /* Set up iterator IT from `composition' property at its current
2549 position. Called from handle_stop. */
2551 static enum prop_handled
2552 handle_composition_prop (it
)
2555 Lisp_Object prop
, string
;
2556 int pos
, pos_byte
, end
;
2557 enum prop_handled handled
= HANDLED_NORMALLY
;
2559 if (STRINGP (it
->string
))
2561 pos
= IT_STRING_CHARPOS (*it
);
2562 pos_byte
= IT_STRING_BYTEPOS (*it
);
2563 string
= it
->string
;
2567 pos
= IT_CHARPOS (*it
);
2568 pos_byte
= IT_BYTEPOS (*it
);
2572 /* If there's a valid composition and point is not inside of the
2573 composition (in the case that the composition is from the current
2574 buffer), draw a glyph composed from the composition components. */
2575 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
2576 && COMPOSITION_VALID_P (pos
, end
, prop
)
2577 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
2579 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
2583 it
->method
= next_element_from_composition
;
2585 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
2586 /* For a terminal, draw only the first character of the
2588 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
2589 it
->len
= (STRINGP (it
->string
)
2590 ? string_char_to_byte (it
->string
, end
)
2591 : CHAR_TO_BYTE (end
)) - pos_byte
;
2592 it
->stop_charpos
= end
;
2593 handled
= HANDLED_RETURN
;
2602 /***********************************************************************
2604 ***********************************************************************/
2606 /* The following structure is used to record overlay strings for
2607 later sorting in load_overlay_strings. */
2609 struct overlay_entry
2617 /* Set up iterator IT from overlay strings at its current position.
2618 Called from handle_stop. */
2620 static enum prop_handled
2621 handle_overlay_change (it
)
2624 /* Overlays are handled in current_buffer only. */
2625 if (STRINGP (it
->string
))
2626 return HANDLED_NORMALLY
;
2628 return (get_overlay_strings (it
)
2629 ? HANDLED_RECOMPUTE_PROPS
2630 : HANDLED_NORMALLY
);
2634 /* Set up the next overlay string for delivery by IT, if there is an
2635 overlay string to deliver. Called by set_iterator_to_next when the
2636 end of the current overlay string is reached. If there are more
2637 overlay strings to display, IT->string and
2638 IT->current.overlay_string_index are set appropriately here.
2639 Otherwise IT->string is set to nil. */
2642 next_overlay_string (it
)
2645 ++it
->current
.overlay_string_index
;
2646 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2648 /* No more overlay strings. Restore IT's settings to what
2649 they were before overlay strings were processed, and
2650 continue to deliver from current_buffer. */
2652 xassert (it
->stop_charpos
>= BEGV
2653 && it
->stop_charpos
<= it
->end_charpos
);
2655 it
->current
.overlay_string_index
= -1;
2656 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2657 it
->n_overlay_strings
= 0;
2658 it
->method
= next_element_from_buffer
;
2662 /* There are more overlay strings to process. If
2663 IT->current.overlay_string_index has advanced to a position
2664 where we must load IT->overlay_strings with more strings, do
2666 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2668 if (it
->current
.overlay_string_index
&& i
== 0)
2669 load_overlay_strings (it
);
2671 /* Initialize IT to deliver display elements from the overlay
2673 it
->string
= it
->overlay_strings
[i
];
2674 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2675 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2676 it
->method
= next_element_from_string
;
2677 it
->stop_charpos
= 0;
2684 /* Compare two overlay_entry structures E1 and E2. Used as a
2685 comparison function for qsort in load_overlay_strings. Overlay
2686 strings for the same position are sorted so that
2688 1. All after-strings come in front of before-strings.
2690 2. Within after-strings, strings are sorted so that overlay strings
2691 from overlays with higher priorities come first.
2693 2. Within before-strings, strings are sorted so that overlay
2694 strings from overlays with higher priorities come last.
2696 Value is analogous to strcmp. */
2700 compare_overlay_entries (e1
, e2
)
2703 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
2704 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
2707 if (entry1
->after_string_p
!= entry2
->after_string_p
)
2708 /* Let after-strings appear in front of before-strings. */
2709 result
= entry1
->after_string_p
? -1 : 1;
2710 else if (entry1
->after_string_p
)
2711 /* After-strings sorted in order of decreasing priority. */
2712 result
= entry2
->priority
- entry1
->priority
;
2714 /* Before-strings sorted in order of increasing priority. */
2715 result
= entry1
->priority
- entry2
->priority
;
2721 /* Load the vector IT->overlay_strings with overlay strings from IT's
2722 current buffer position. Set IT->n_overlays to the total number of
2723 overlay strings found.
2725 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
2726 a time. On entry into load_overlay_strings,
2727 IT->current.overlay_string_index gives the number of overlay
2728 strings that have already been loaded by previous calls to this
2731 Overlay strings are sorted so that after-string strings come in
2732 front of before-string strings. Within before and after-strings,
2733 strings are sorted by overlay priority. See also function
2734 compare_overlay_entries. */
2737 load_overlay_strings (it
)
2740 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
2741 Lisp_Object ov
, overlay
, window
, str
;
2745 struct overlay_entry
*entries
2746 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
2748 /* Append the overlay string STRING of overlay OVERLAY to vector
2749 `entries' which has size `size' and currently contains `n'
2750 elements. AFTER_P non-zero means STRING is an after-string of
2752 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
2755 Lisp_Object priority; \
2759 int new_size = 2 * size; \
2760 struct overlay_entry *old = entries; \
2762 (struct overlay_entry *) alloca (new_size \
2763 * sizeof *entries); \
2764 bcopy (old, entries, size * sizeof *entries); \
2768 entries[n].string = (STRING); \
2769 priority = Foverlay_get ((OVERLAY), Qpriority); \
2770 entries[n].priority \
2771 = INTEGERP (priority) ? XFASTINT (priority) : 0; \
2772 entries[n].after_string_p = (AFTER_P); \
2777 /* Process overlay before the overlay center. */
2778 for (ov
= current_buffer
->overlays_before
;
2782 overlay
= XCAR (ov
);
2783 xassert (OVERLAYP (overlay
));
2784 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2785 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2787 if (end
< IT_CHARPOS (*it
))
2790 /* Skip this overlay if it doesn't start or end at IT's current
2792 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2795 /* Skip this overlay if it doesn't apply to IT->w. */
2796 window
= Foverlay_get (overlay
, Qwindow
);
2797 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2800 /* If overlay has a non-empty before-string, record it. */
2801 if (start
== IT_CHARPOS (*it
)
2802 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2803 && XSTRING (str
)->size
)
2804 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2806 /* If overlay has a non-empty after-string, record it. */
2807 if (end
== IT_CHARPOS (*it
)
2808 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2809 && XSTRING (str
)->size
)
2810 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2813 /* Process overlays after the overlay center. */
2814 for (ov
= current_buffer
->overlays_after
;
2818 overlay
= XCAR (ov
);
2819 xassert (OVERLAYP (overlay
));
2820 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2821 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2823 if (start
> IT_CHARPOS (*it
))
2826 /* Skip this overlay if it doesn't start or end at IT's current
2828 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2831 /* Skip this overlay if it doesn't apply to IT->w. */
2832 window
= Foverlay_get (overlay
, Qwindow
);
2833 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2836 /* If overlay has a non-empty before-string, record it. */
2837 if (start
== IT_CHARPOS (*it
)
2838 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2839 && XSTRING (str
)->size
)
2840 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2842 /* If overlay has a non-empty after-string, record it. */
2843 if (end
== IT_CHARPOS (*it
)
2844 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2845 && XSTRING (str
)->size
)
2846 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2849 #undef RECORD_OVERLAY_STRING
2852 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
2854 /* Record the total number of strings to process. */
2855 it
->n_overlay_strings
= n
;
2857 /* IT->current.overlay_string_index is the number of overlay strings
2858 that have already been consumed by IT. Copy some of the
2859 remaining overlay strings to IT->overlay_strings. */
2861 j
= it
->current
.overlay_string_index
;
2862 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
2863 it
->overlay_strings
[i
++] = entries
[j
++].string
;
2869 /* Get the first chunk of overlay strings at IT's current buffer
2870 position. Value is non-zero if at least one overlay string was
2874 get_overlay_strings (it
)
2877 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
2878 process. This fills IT->overlay_strings with strings, and sets
2879 IT->n_overlay_strings to the total number of strings to process.
2880 IT->pos.overlay_string_index has to be set temporarily to zero
2881 because load_overlay_strings needs this; it must be set to -1
2882 when no overlay strings are found because a zero value would
2883 indicate a position in the first overlay string. */
2884 it
->current
.overlay_string_index
= 0;
2885 load_overlay_strings (it
);
2887 /* If we found overlay strings, set up IT to deliver display
2888 elements from the first one. Otherwise set up IT to deliver
2889 from current_buffer. */
2890 if (it
->n_overlay_strings
)
2892 /* Make sure we know settings in current_buffer, so that we can
2893 restore meaningful values when we're done with the overlay
2895 compute_stop_pos (it
);
2896 xassert (it
->face_id
>= 0);
2898 /* Save IT's settings. They are restored after all overlay
2899 strings have been processed. */
2900 xassert (it
->sp
== 0);
2903 /* Set up IT to deliver display elements from the first overlay
2905 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2906 it
->stop_charpos
= 0;
2907 it
->string
= it
->overlay_strings
[0];
2908 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2909 xassert (STRINGP (it
->string
));
2910 it
->method
= next_element_from_string
;
2915 it
->current
.overlay_string_index
= -1;
2916 it
->method
= next_element_from_buffer
;
2921 /* Value is non-zero if we found at least one overlay string. */
2922 return STRINGP (it
->string
);
2927 /***********************************************************************
2928 Saving and restoring state
2929 ***********************************************************************/
2931 /* Save current settings of IT on IT->stack. Called, for example,
2932 before setting up IT for an overlay string, to be able to restore
2933 IT's settings to what they were after the overlay string has been
2940 struct iterator_stack_entry
*p
;
2942 xassert (it
->sp
< 2);
2943 p
= it
->stack
+ it
->sp
;
2945 p
->stop_charpos
= it
->stop_charpos
;
2946 xassert (it
->face_id
>= 0);
2947 p
->face_id
= it
->face_id
;
2948 p
->string
= it
->string
;
2949 p
->pos
= it
->current
;
2950 p
->end_charpos
= it
->end_charpos
;
2951 p
->string_nchars
= it
->string_nchars
;
2953 p
->multibyte_p
= it
->multibyte_p
;
2954 p
->space_width
= it
->space_width
;
2955 p
->font_height
= it
->font_height
;
2956 p
->voffset
= it
->voffset
;
2957 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
2962 /* Restore IT's settings from IT->stack. Called, for example, when no
2963 more overlay strings must be processed, and we return to delivering
2964 display elements from a buffer, or when the end of a string from a
2965 `display' property is reached and we return to delivering display
2966 elements from an overlay string, or from a buffer. */
2972 struct iterator_stack_entry
*p
;
2974 xassert (it
->sp
> 0);
2976 p
= it
->stack
+ it
->sp
;
2977 it
->stop_charpos
= p
->stop_charpos
;
2978 it
->face_id
= p
->face_id
;
2979 it
->string
= p
->string
;
2980 it
->current
= p
->pos
;
2981 it
->end_charpos
= p
->end_charpos
;
2982 it
->string_nchars
= p
->string_nchars
;
2984 it
->multibyte_p
= p
->multibyte_p
;
2985 it
->space_width
= p
->space_width
;
2986 it
->font_height
= p
->font_height
;
2987 it
->voffset
= p
->voffset
;
2988 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
2993 /***********************************************************************
2995 ***********************************************************************/
2997 /* Set IT's current position to the previous line start. */
3000 back_to_previous_line_start (it
)
3003 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3004 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3008 /* Set IT's current position to the next line start. */
3011 forward_to_next_line_start (it
)
3014 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), 1);
3015 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3019 /* Set IT's current position to the previous visible line start. Skip
3020 invisible text that is so either due to text properties or due to
3021 selective display. Caution: this does not change IT->current_x and
3025 back_to_previous_visible_line_start (it
)
3030 /* Go back one newline if not on BEGV already. */
3031 if (IT_CHARPOS (*it
) > BEGV
)
3032 back_to_previous_line_start (it
);
3034 /* Move over lines that are invisible because of selective display
3035 or text properties. */
3036 while (IT_CHARPOS (*it
) > BEGV
3041 /* If selective > 0, then lines indented more than that values
3043 if (it
->selective
> 0
3044 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3051 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3052 Qinvisible
, it
->window
);
3053 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3057 /* Back one more newline if the current one is invisible. */
3059 back_to_previous_line_start (it
);
3062 xassert (IT_CHARPOS (*it
) >= BEGV
);
3063 xassert (IT_CHARPOS (*it
) == BEGV
3064 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3069 /* Reseat iterator IT at the previous visible line start. Skip
3070 invisible text that is so either due to text properties or due to
3071 selective display. At the end, update IT's overlay information,
3072 face information etc. */
3075 reseat_at_previous_visible_line_start (it
)
3078 back_to_previous_visible_line_start (it
);
3079 reseat (it
, it
->current
.pos
, 1);
3084 /* Reseat iterator IT on the next visible line start in the current
3085 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3086 preceding the line start. Skip over invisible text that is so
3087 because of selective display. Compute faces, overlays etc at the
3088 new position. Note that this function does not skip over text that
3089 is invisible because of text properties. */
3092 reseat_at_next_visible_line_start (it
, on_newline_p
)
3096 /* Restore the buffer position when currently not delivering display
3097 elements from the current buffer. This is the case, for example,
3098 when called at the end of a truncated overlay string. */
3101 it
->method
= next_element_from_buffer
;
3103 /* Otherwise, scan_buffer would not work. */
3104 if (IT_CHARPOS (*it
) < ZV
)
3106 /* If on a newline, advance past it. Otherwise, find the next
3107 newline which automatically gives us the position following
3109 if (FETCH_BYTE (IT_BYTEPOS (*it
)) == '\n')
3115 forward_to_next_line_start (it
);
3117 /* We must either have reached the end of the buffer or end up
3119 xassert (IT_CHARPOS (*it
) == ZV
3120 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3122 /* Skip over lines that are invisible because they are indented
3123 more than the value of IT->selective. */
3124 if (it
->selective
> 0)
3125 while (IT_CHARPOS (*it
) < ZV
3126 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3128 forward_to_next_line_start (it
);
3130 /* Position on the newline if we should. */
3132 && IT_CHARPOS (*it
) > BEGV
3133 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n')
3136 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3139 /* Set the iterator there. The 0 as the last parameter of
3140 reseat means don't force a text property lookup. The lookup
3141 is then only done if we've skipped past the iterator's
3142 check_charpos'es. This optimization is important because
3143 text property lookups tend to be expensive. */
3144 reseat (it
, it
->current
.pos
, 0);
3152 /***********************************************************************
3153 Changing an iterator's position
3154 ***********************************************************************/
3156 /* Change IT's current position to POS in current_buffer. If FORCE_P
3157 is non-zero, always check for text properties at the new position.
3158 Otherwise, text properties are only looked up if POS >=
3159 IT->check_charpos of a property. */
3162 reseat (it
, pos
, force_p
)
3164 struct text_pos pos
;
3167 int original_pos
= IT_CHARPOS (*it
);
3169 reseat_1 (it
, pos
, 0);
3171 /* Determine where to check text properties. Avoid doing it
3172 where possible because text property lookup is very expensive. */
3174 || CHARPOS (pos
) > it
->stop_charpos
3175 || CHARPOS (pos
) < original_pos
)
3182 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3183 IT->stop_pos to POS, also. */
3186 reseat_1 (it
, pos
, set_stop_p
)
3188 struct text_pos pos
;
3191 /* Don't call this function when scanning a C string. */
3192 xassert (it
->s
== NULL
);
3194 /* POS must be a reasonable value. */
3195 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3197 it
->current
.pos
= it
->position
= pos
;
3198 XSETBUFFER (it
->object
, current_buffer
);
3200 it
->current
.dpvec_index
= -1;
3201 it
->current
.overlay_string_index
= -1;
3202 IT_STRING_CHARPOS (*it
) = -1;
3203 IT_STRING_BYTEPOS (*it
) = -1;
3205 it
->method
= next_element_from_buffer
;
3209 it
->stop_charpos
= CHARPOS (pos
);
3213 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3214 If S is non-null, it is a C string to iterate over. Otherwise,
3215 STRING gives a Lisp string to iterate over.
3217 If PRECISION > 0, don't return more then PRECISION number of
3218 characters from the string.
3220 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3221 characters have been returned. FIELD_WIDTH < 0 means an infinite
3224 MULTIBYTE = 0 means disable processing of multibyte characters,
3225 MULTIBYTE > 0 means enable it,
3226 MULTIBYTE < 0 means use IT->multibyte_p.
3228 IT must be initialized via a prior call to init_iterator before
3229 calling this function. */
3232 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3237 int precision
, field_width
, multibyte
;
3239 /* No region in strings. */
3240 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3242 /* No text property checks performed by default, but see below. */
3243 it
->stop_charpos
= -1;
3245 /* Set iterator position and end position. */
3246 bzero (&it
->current
, sizeof it
->current
);
3247 it
->current
.overlay_string_index
= -1;
3248 it
->current
.dpvec_index
= -1;
3249 xassert (charpos
>= 0);
3251 /* Use the setting of MULTIBYTE if specified. */
3253 it
->multibyte_p
= multibyte
> 0;
3257 xassert (STRINGP (string
));
3258 it
->string
= string
;
3260 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3261 it
->method
= next_element_from_string
;
3262 it
->current
.string_pos
= string_pos (charpos
, string
);
3269 /* Note that we use IT->current.pos, not it->current.string_pos,
3270 for displaying C strings. */
3271 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3272 if (it
->multibyte_p
)
3274 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3275 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3279 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3280 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3283 it
->method
= next_element_from_c_string
;
3286 /* PRECISION > 0 means don't return more than PRECISION characters
3288 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3289 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3291 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3292 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3293 FIELD_WIDTH < 0 means infinite field width. This is useful for
3294 padding with `-' at the end of a mode line. */
3295 if (field_width
< 0)
3296 field_width
= INFINITY
;
3297 if (field_width
> it
->end_charpos
- charpos
)
3298 it
->end_charpos
= charpos
+ field_width
;
3300 /* Use the standard display table for displaying strings. */
3301 if (DISP_TABLE_P (Vstandard_display_table
))
3302 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3304 it
->stop_charpos
= charpos
;
3310 /***********************************************************************
3312 ***********************************************************************/
3314 /* Load IT's display element fields with information about the next
3315 display element from the current position of IT. Value is zero if
3316 end of buffer (or C string) is reached. */
3319 get_next_display_element (it
)
3322 /* Non-zero means that we found an display element. Zero means that
3323 we hit the end of what we iterate over. Performance note: the
3324 function pointer `method' used here turns out to be faster than
3325 using a sequence of if-statements. */
3326 int success_p
= (*it
->method
) (it
);
3328 if (it
->what
== IT_CHARACTER
)
3330 /* Map via display table or translate control characters.
3331 IT->c, IT->len etc. have been set to the next character by
3332 the function call above. If we have a display table, and it
3333 contains an entry for IT->c, translate it. Don't do this if
3334 IT->c itself comes from a display table, otherwise we could
3335 end up in an infinite recursion. (An alternative could be to
3336 count the recursion depth of this function and signal an
3337 error when a certain maximum depth is reached.) Is it worth
3339 if (success_p
&& it
->dpvec
== NULL
)
3344 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3347 struct Lisp_Vector
*v
= XVECTOR (dv
);
3349 /* Return the first character from the display table
3350 entry, if not empty. If empty, don't display the
3351 current character. */
3354 it
->dpvec_char_len
= it
->len
;
3355 it
->dpvec
= v
->contents
;
3356 it
->dpend
= v
->contents
+ v
->size
;
3357 it
->current
.dpvec_index
= 0;
3358 it
->method
= next_element_from_display_vector
;
3361 success_p
= get_next_display_element (it
);
3364 /* Translate control characters into `\003' or `^C' form.
3365 Control characters coming from a display table entry are
3366 currently not translated because we use IT->dpvec to hold
3367 the translation. This could easily be changed but I
3368 don't believe that it is worth doing.
3370 Non-printable multibyte characters are also translated
3372 else if ((it
->c
< ' '
3373 && (it
->area
!= TEXT_AREA
3374 || (it
->c
!= '\n' && it
->c
!= '\t')))
3377 || !CHAR_PRINTABLE_P (it
->c
))
3379 /* IT->c is a control character which must be displayed
3380 either as '\003' or as `^C' where the '\\' and '^'
3381 can be defined in the display table. Fill
3382 IT->ctl_chars with glyphs for what we have to
3383 display. Then, set IT->dpvec to these glyphs. */
3386 if (it
->c
< 128 && it
->ctl_arrow_p
)
3388 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3390 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3391 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3392 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3394 g
= FAST_MAKE_GLYPH ('^', 0);
3395 XSETINT (it
->ctl_chars
[0], g
);
3397 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3398 XSETINT (it
->ctl_chars
[1], g
);
3400 /* Set up IT->dpvec and return first character from it. */
3401 it
->dpvec_char_len
= it
->len
;
3402 it
->dpvec
= it
->ctl_chars
;
3403 it
->dpend
= it
->dpvec
+ 2;
3404 it
->current
.dpvec_index
= 0;
3405 it
->method
= next_element_from_display_vector
;
3406 get_next_display_element (it
);
3410 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
3411 int len
= CHAR_STRING (it
->c
, str
);
3415 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3417 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3418 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3419 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3421 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
3423 for (i
= 0; i
< len
; i
++)
3425 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
3426 /* Insert three more glyphs into IT->ctl_chars for
3427 the octal display of the character. */
3428 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
3429 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
3430 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
3431 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
3432 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
3433 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
3436 /* Set up IT->dpvec and return the first character
3438 it
->dpvec_char_len
= it
->len
;
3439 it
->dpvec
= it
->ctl_chars
;
3440 it
->dpend
= it
->dpvec
+ len
* 4;
3441 it
->current
.dpvec_index
= 0;
3442 it
->method
= next_element_from_display_vector
;
3443 get_next_display_element (it
);
3448 /* Adjust face id for a multibyte character. There are no
3449 multibyte character in unibyte text. */
3452 && FRAME_WINDOW_P (it
->f
))
3454 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3455 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
3459 /* Is this character the last one of a run of characters with
3460 box? If yes, set IT->end_of_box_run_p to 1. */
3467 it
->end_of_box_run_p
3468 = ((face_id
= face_after_it_pos (it
),
3469 face_id
!= it
->face_id
)
3470 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3471 face
->box
== FACE_NO_BOX
));
3474 /* Value is 0 if end of buffer or string reached. */
3479 /* Move IT to the next display element.
3481 Functions get_next_display_element and set_iterator_to_next are
3482 separate because I find this arrangement easier to handle than a
3483 get_next_display_element function that also increments IT's
3484 position. The way it is we can first look at an iterator's current
3485 display element, decide whether it fits on a line, and if it does,
3486 increment the iterator position. The other way around we probably
3487 would either need a flag indicating whether the iterator has to be
3488 incremented the next time, or we would have to implement a
3489 decrement position function which would not be easy to write. */
3492 set_iterator_to_next (it
)
3495 if (it
->method
== next_element_from_buffer
)
3497 /* The current display element of IT is a character from
3498 current_buffer. Advance in the buffer, and maybe skip over
3499 invisible lines that are so because of selective display. */
3500 if (ITERATOR_AT_END_OF_LINE_P (it
))
3501 reseat_at_next_visible_line_start (it
, 0);
3504 xassert (it
->len
!= 0);
3505 IT_BYTEPOS (*it
) += it
->len
;
3506 IT_CHARPOS (*it
) += 1;
3507 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3510 else if (it
->method
== next_element_from_composition
)
3512 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
3513 if (STRINGP (it
->string
))
3515 IT_STRING_BYTEPOS (*it
) += it
->len
;
3516 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
3517 it
->method
= next_element_from_string
;
3518 goto consider_string_end
;
3522 IT_BYTEPOS (*it
) += it
->len
;
3523 IT_CHARPOS (*it
) += it
->cmp_len
;
3524 it
->method
= next_element_from_buffer
;
3527 else if (it
->method
== next_element_from_c_string
)
3529 /* Current display element of IT is from a C string. */
3530 IT_BYTEPOS (*it
) += it
->len
;
3531 IT_CHARPOS (*it
) += 1;
3533 else if (it
->method
== next_element_from_display_vector
)
3535 /* Current display element of IT is from a display table entry.
3536 Advance in the display table definition. Reset it to null if
3537 end reached, and continue with characters from buffers/
3539 ++it
->current
.dpvec_index
;
3541 /* Restore face of the iterator to what they were before the
3542 display vector entry (these entries may contain faces). */
3543 it
->face_id
= it
->saved_face_id
;
3545 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3548 it
->method
= next_element_from_c_string
;
3549 else if (STRINGP (it
->string
))
3550 it
->method
= next_element_from_string
;
3552 it
->method
= next_element_from_buffer
;
3555 it
->current
.dpvec_index
= -1;
3557 /* Skip over characters which were displayed via IT->dpvec. */
3558 if (it
->dpvec_char_len
< 0)
3559 reseat_at_next_visible_line_start (it
, 1);
3560 else if (it
->dpvec_char_len
> 0)
3562 it
->len
= it
->dpvec_char_len
;
3563 set_iterator_to_next (it
);
3567 else if (it
->method
== next_element_from_string
)
3569 /* Current display element is a character from a Lisp string. */
3570 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3571 IT_STRING_BYTEPOS (*it
) += it
->len
;
3572 IT_STRING_CHARPOS (*it
) += 1;
3574 consider_string_end
:
3576 if (it
->current
.overlay_string_index
>= 0)
3578 /* IT->string is an overlay string. Advance to the
3579 next, if there is one. */
3580 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3581 next_overlay_string (it
);
3585 /* IT->string is not an overlay string. If we reached
3586 its end, and there is something on IT->stack, proceed
3587 with what is on the stack. This can be either another
3588 string, this time an overlay string, or a buffer. */
3589 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3593 if (!STRINGP (it
->string
))
3594 it
->method
= next_element_from_buffer
;
3598 else if (it
->method
== next_element_from_image
3599 || it
->method
== next_element_from_stretch
)
3601 /* The position etc with which we have to proceed are on
3602 the stack. The position may be at the end of a string,
3603 if the `display' property takes up the whole string. */
3606 if (STRINGP (it
->string
))
3608 it
->method
= next_element_from_string
;
3609 goto consider_string_end
;
3612 it
->method
= next_element_from_buffer
;
3615 /* There are no other methods defined, so this should be a bug. */
3618 /* Reset flags indicating start and end of a sequence of
3619 characters with box. */
3620 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3622 xassert (it
->method
!= next_element_from_string
3623 || (STRINGP (it
->string
)
3624 && IT_STRING_CHARPOS (*it
) >= 0));
3628 /* Load IT's display element fields with information about the next
3629 display element which comes from a display table entry or from the
3630 result of translating a control character to one of the forms `^C'
3631 or `\003'. IT->dpvec holds the glyphs to return as characters. */
3634 next_element_from_display_vector (it
)
3638 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
3640 /* Remember the current face id in case glyphs specify faces.
3641 IT's face is restored in set_iterator_to_next. */
3642 it
->saved_face_id
= it
->face_id
;
3644 if (INTEGERP (*it
->dpvec
)
3645 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
3650 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
3651 it
->c
= FAST_GLYPH_CHAR (g
);
3652 it
->len
= CHAR_LEN (it
->c
);
3654 /* The entry may contain a face id to use. Such a face id is
3655 the id of a Lisp face, not a realized face. A face id of
3656 zero means no face. */
3657 lface_id
= FAST_GLYPH_FACE (g
);
3660 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
3663 it
->face_id
= face_id
;
3668 /* Display table entry is invalid. Return a space. */
3669 it
->c
= ' ', it
->len
= 1;
3671 /* Don't change position and object of the iterator here. They are
3672 still the values of the character that had this display table
3673 entry or was translated, and that's what we want. */
3674 it
->what
= IT_CHARACTER
;
3679 /* Load IT with the next display element from Lisp string IT->string.
3680 IT->current.string_pos is the current position within the string.
3681 If IT->current.overlay_string_index >= 0, the Lisp string is an
3685 next_element_from_string (it
)
3688 struct text_pos position
;
3690 xassert (STRINGP (it
->string
));
3691 xassert (IT_STRING_CHARPOS (*it
) >= 0);
3692 position
= it
->current
.string_pos
;
3694 /* Time to check for invisible text? */
3695 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
3696 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
3700 /* Since a handler may have changed IT->method, we must
3702 return get_next_display_element (it
);
3705 if (it
->current
.overlay_string_index
>= 0)
3707 /* Get the next character from an overlay string. In overlay
3708 strings, There is no field width or padding with spaces to
3710 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3715 else if (STRING_MULTIBYTE (it
->string
))
3717 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
3718 - IT_STRING_BYTEPOS (*it
));
3719 unsigned char *s
= (XSTRING (it
->string
)->data
3720 + IT_STRING_BYTEPOS (*it
));
3721 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
3725 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3731 /* Get the next character from a Lisp string that is not an
3732 overlay string. Such strings come from the mode line, for
3733 example. We may have to pad with spaces, or truncate the
3734 string. See also next_element_from_c_string. */
3735 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
3740 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
3742 /* Pad with spaces. */
3743 it
->c
= ' ', it
->len
= 1;
3744 CHARPOS (position
) = BYTEPOS (position
) = -1;
3746 else if (STRING_MULTIBYTE (it
->string
))
3748 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
3749 - IT_STRING_BYTEPOS (*it
));
3750 unsigned char *s
= (XSTRING (it
->string
)->data
3751 + IT_STRING_BYTEPOS (*it
));
3752 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
3756 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3761 /* Record what we have and where it came from. Note that we store a
3762 buffer position in IT->position although it could arguably be a
3764 it
->what
= IT_CHARACTER
;
3765 it
->object
= it
->string
;
3766 it
->position
= position
;
3771 /* Load IT with next display element from C string IT->s.
3772 IT->string_nchars is the maximum number of characters to return
3773 from the string. IT->end_charpos may be greater than
3774 IT->string_nchars when this function is called, in which case we
3775 may have to return padding spaces. Value is zero if end of string
3776 reached, including padding spaces. */
3779 next_element_from_c_string (it
)
3785 it
->what
= IT_CHARACTER
;
3786 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
3789 /* IT's position can be greater IT->string_nchars in case a field
3790 width or precision has been specified when the iterator was
3792 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3794 /* End of the game. */
3798 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
3800 /* Pad with spaces. */
3801 it
->c
= ' ', it
->len
= 1;
3802 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
3804 else if (it
->multibyte_p
)
3806 /* Implementation note: The calls to strlen apparently aren't a
3807 performance problem because there is no noticeable performance
3808 difference between Emacs running in unibyte or multibyte mode. */
3809 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
3810 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
3814 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
3820 /* Set up IT to return characters from an ellipsis, if appropriate.
3821 The definition of the ellipsis glyphs may come from a display table
3822 entry. This function Fills IT with the first glyph from the
3823 ellipsis if an ellipsis is to be displayed. */
3826 next_element_from_ellipsis (it
)
3829 if (it
->selective_display_ellipsis_p
)
3831 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3833 /* Use the display table definition for `...'. Invalid glyphs
3834 will be handled by the method returning elements from dpvec. */
3835 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3836 it
->dpvec_char_len
= it
->len
;
3837 it
->dpvec
= v
->contents
;
3838 it
->dpend
= v
->contents
+ v
->size
;
3839 it
->current
.dpvec_index
= 0;
3840 it
->method
= next_element_from_display_vector
;
3844 /* Use default `...' which is stored in default_invis_vector. */
3845 it
->dpvec_char_len
= it
->len
;
3846 it
->dpvec
= default_invis_vector
;
3847 it
->dpend
= default_invis_vector
+ 3;
3848 it
->current
.dpvec_index
= 0;
3849 it
->method
= next_element_from_display_vector
;
3853 reseat_at_next_visible_line_start (it
, 1);
3855 return get_next_display_element (it
);
3859 /* Deliver an image display element. The iterator IT is already
3860 filled with image information (done in handle_display_prop). Value
3865 next_element_from_image (it
)
3868 it
->what
= IT_IMAGE
;
3873 /* Fill iterator IT with next display element from a stretch glyph
3874 property. IT->object is the value of the text property. Value is
3878 next_element_from_stretch (it
)
3881 it
->what
= IT_STRETCH
;
3886 /* Load IT with the next display element from current_buffer. Value
3887 is zero if end of buffer reached. IT->stop_charpos is the next
3888 position at which to stop and check for text properties or buffer
3892 next_element_from_buffer (it
)
3897 /* Check this assumption, otherwise, we would never enter the
3898 if-statement, below. */
3899 xassert (IT_CHARPOS (*it
) >= BEGV
3900 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
3902 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
3904 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3906 int overlay_strings_follow_p
;
3908 /* End of the game, except when overlay strings follow that
3909 haven't been returned yet. */
3910 if (it
->overlay_strings_at_end_processed_p
)
3911 overlay_strings_follow_p
= 0;
3914 it
->overlay_strings_at_end_processed_p
= 1;
3915 overlay_strings_follow_p
= get_overlay_strings (it
);
3918 if (overlay_strings_follow_p
)
3919 success_p
= get_next_display_element (it
);
3923 it
->position
= it
->current
.pos
;
3930 return get_next_display_element (it
);
3935 /* No face changes, overlays etc. in sight, so just return a
3936 character from current_buffer. */
3939 /* Maybe run the redisplay end trigger hook. Performance note:
3940 This doesn't seem to cost measurable time. */
3941 if (it
->redisplay_end_trigger_charpos
3943 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
3944 run_redisplay_end_trigger_hook (it
);
3946 /* Get the next character, maybe multibyte. */
3947 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
3948 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
3950 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
3951 - IT_BYTEPOS (*it
));
3952 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
3955 it
->c
= *p
, it
->len
= 1;
3957 /* Record what we have and where it came from. */
3958 it
->what
= IT_CHARACTER
;;
3959 it
->object
= it
->w
->buffer
;
3960 it
->position
= it
->current
.pos
;
3962 /* Normally we return the character found above, except when we
3963 really want to return an ellipsis for selective display. */
3968 /* A value of selective > 0 means hide lines indented more
3969 than that number of columns. */
3970 if (it
->selective
> 0
3971 && IT_CHARPOS (*it
) + 1 < ZV
3972 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
3973 IT_BYTEPOS (*it
) + 1,
3976 success_p
= next_element_from_ellipsis (it
);
3977 it
->dpvec_char_len
= -1;
3980 else if (it
->c
== '\r' && it
->selective
== -1)
3982 /* A value of selective == -1 means that everything from the
3983 CR to the end of the line is invisible, with maybe an
3984 ellipsis displayed for it. */
3985 success_p
= next_element_from_ellipsis (it
);
3986 it
->dpvec_char_len
= -1;
3991 /* Value is zero if end of buffer reached. */
3992 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
3997 /* Run the redisplay end trigger hook for IT. */
4000 run_redisplay_end_trigger_hook (it
)
4003 Lisp_Object args
[3];
4005 /* IT->glyph_row should be non-null, i.e. we should be actually
4006 displaying something, or otherwise we should not run the hook. */
4007 xassert (it
->glyph_row
);
4009 /* Set up hook arguments. */
4010 args
[0] = Qredisplay_end_trigger_functions
;
4011 args
[1] = it
->window
;
4012 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4013 it
->redisplay_end_trigger_charpos
= 0;
4015 /* Since we are *trying* to run these functions, don't try to run
4016 them again, even if they get an error. */
4017 it
->w
->redisplay_end_trigger
= Qnil
;
4018 Frun_hook_with_args (3, args
);
4020 /* Notice if it changed the face of the character we are on. */
4021 handle_face_prop (it
);
4025 /* Deliver a composition display element. The iterator IT is already
4026 filled with composition information (done in
4027 handle_composition_prop). Value is always 1. */
4030 next_element_from_composition (it
)
4033 it
->what
= IT_COMPOSITION
;
4034 it
->position
= (STRINGP (it
->string
)
4035 ? it
->current
.string_pos
4042 /***********************************************************************
4043 Moving an iterator without producing glyphs
4044 ***********************************************************************/
4046 /* Move iterator IT to a specified buffer or X position within one
4047 line on the display without producing glyphs.
4049 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4050 whichever is reached first.
4052 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4054 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4055 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4056 TO_X includes the amount by which a window is horizontally
4061 MOVE_POS_MATCH_OR_ZV
4062 - when TO_POS or ZV was reached.
4065 -when TO_X was reached before TO_POS or ZV were reached.
4068 - when we reached the end of the display area and the line must
4072 - when we reached the end of the display area and the line is
4076 - when we stopped at a line end, i.e. a newline or a CR and selective
4079 static enum move_it_result
4080 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4082 int to_charpos
, to_x
, op
;
4084 enum move_it_result result
= MOVE_UNDEFINED
;
4085 struct glyph_row
*saved_glyph_row
;
4087 /* Don't produce glyphs in produce_glyphs. */
4088 saved_glyph_row
= it
->glyph_row
;
4089 it
->glyph_row
= NULL
;
4095 /* Stop when ZV or TO_CHARPOS reached. */
4096 if (!get_next_display_element (it
)
4097 || ((op
& MOVE_TO_POS
) != 0
4098 && BUFFERP (it
->object
)
4099 && IT_CHARPOS (*it
) >= to_charpos
))
4101 result
= MOVE_POS_MATCH_OR_ZV
;
4105 /* The call to produce_glyphs will get the metrics of the
4106 display element IT is loaded with. We record in x the
4107 x-position before this display element in case it does not
4110 PRODUCE_GLYPHS (it
);
4112 if (it
->area
!= TEXT_AREA
)
4114 set_iterator_to_next (it
);
4118 /* The number of glyphs we get back in IT->nglyphs will normally
4119 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4120 character on a terminal frame, or (iii) a line end. For the
4121 second case, IT->nglyphs - 1 padding glyphs will be present
4122 (on X frames, there is only one glyph produced for a
4123 composite character.
4125 The behavior implemented below means, for continuation lines,
4126 that as many spaces of a TAB as fit on the current line are
4127 displayed there. For terminal frames, as many glyphs of a
4128 multi-glyph character are displayed in the current line, too.
4129 This is what the old redisplay code did, and we keep it that
4130 way. Under X, the whole shape of a complex character must
4131 fit on the line or it will be completely displayed in the
4134 Note that both for tabs and padding glyphs, all glyphs have
4138 /* More than one glyph or glyph doesn't fit on line. All
4139 glyphs have the same width. */
4140 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4143 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4145 new_x
= x
+ single_glyph_width
;
4147 /* We want to leave anything reaching TO_X to the caller. */
4148 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4151 result
= MOVE_X_REACHED
;
4154 else if (/* Lines are continued. */
4155 !it
->truncate_lines_p
4156 && (/* And glyph doesn't fit on the line. */
4157 new_x
> it
->last_visible_x
4158 /* Or it fits exactly and we're on a window
4160 || (new_x
== it
->last_visible_x
4161 && FRAME_WINDOW_P (it
->f
))))
4163 if (/* IT->hpos == 0 means the very first glyph
4164 doesn't fit on the line, e.g. a wide image. */
4166 || (new_x
== it
->last_visible_x
4167 && FRAME_WINDOW_P (it
->f
)))
4170 it
->current_x
= new_x
;
4171 if (i
== it
->nglyphs
- 1)
4172 set_iterator_to_next (it
);
4177 result
= MOVE_LINE_CONTINUED
;
4180 else if (new_x
> it
->first_visible_x
)
4182 /* Glyph is visible. Increment number of glyphs that
4183 would be displayed. */
4188 /* Glyph is completely off the left margin of the display
4189 area. Nothing to do. */
4193 if (result
!= MOVE_UNDEFINED
)
4196 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4198 /* Stop when TO_X specified and reached. This check is
4199 necessary here because of lines consisting of a line end,
4200 only. The line end will not produce any glyphs and we
4201 would never get MOVE_X_REACHED. */
4202 xassert (it
->nglyphs
== 0);
4203 result
= MOVE_X_REACHED
;
4207 /* Is this a line end? If yes, we're done. */
4208 if (ITERATOR_AT_END_OF_LINE_P (it
))
4210 result
= MOVE_NEWLINE_OR_CR
;
4214 /* The current display element has been consumed. Advance
4216 set_iterator_to_next (it
);
4218 /* Stop if lines are truncated and IT's current x-position is
4219 past the right edge of the window now. */
4220 if (it
->truncate_lines_p
4221 && it
->current_x
>= it
->last_visible_x
)
4223 result
= MOVE_LINE_TRUNCATED
;
4228 /* Restore the iterator settings altered at the beginning of this
4230 it
->glyph_row
= saved_glyph_row
;
4235 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4236 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4237 the description of enum move_operation_enum.
4239 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4240 screen line, this function will set IT to the next position >
4244 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4246 int to_charpos
, to_x
, to_y
, to_vpos
;
4249 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4254 if (op
& MOVE_TO_VPOS
)
4256 /* If no TO_CHARPOS and no TO_X specified, stop at the
4257 start of the line TO_VPOS. */
4258 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4260 if (it
->vpos
== to_vpos
)
4262 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4266 /* TO_VPOS >= 0 means stop at TO_X in the line at
4267 TO_VPOS, or at TO_POS, whichever comes first. */
4268 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4270 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4272 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4274 /* We have reached TO_X but not in the line we want. */
4275 skip
= move_it_in_display_line_to (it
, to_charpos
,
4277 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4282 else if (op
& MOVE_TO_Y
)
4284 struct it it_backup
;
4287 /* TO_Y specified means stop at TO_X in the line containing
4288 TO_Y---or at TO_CHARPOS if this is reached first. The
4289 problem is that we can't really tell whether the line
4290 contains TO_Y before we have completely scanned it, and
4291 this may skip past TO_X. What we do is to first scan to
4294 If TO_X is not specified, use a TO_X of zero. The reason
4295 is to make the outcome of this function more predictable.
4296 If we didn't use TO_X == 0, we would stop at the end of
4297 the line which is probably not what a caller would expect
4299 skip
= move_it_in_display_line_to (it
, to_charpos
,
4303 | (op
& MOVE_TO_POS
)));
4305 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4306 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4309 /* If TO_X was reached, we would like to know whether TO_Y
4310 is in the line. This can only be said if we know the
4311 total line height which requires us to scan the rest of
4314 if (skip
== MOVE_X_REACHED
)
4317 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4321 /* Now, decide whether TO_Y is in this line. */
4322 line_height
= it
->max_ascent
+ it
->max_descent
;
4324 if (to_y
>= it
->current_y
4325 && to_y
< it
->current_y
+ line_height
)
4327 if (skip
== MOVE_X_REACHED
)
4328 /* If TO_Y is in this line and TO_X was reached above,
4329 we scanned too far. We have to restore IT's settings
4330 to the ones before skipping. */
4334 else if (skip
== MOVE_X_REACHED
)
4337 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4345 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4349 case MOVE_POS_MATCH_OR_ZV
:
4352 case MOVE_NEWLINE_OR_CR
:
4353 set_iterator_to_next (it
);
4354 it
->continuation_lines_width
= 0;
4357 case MOVE_LINE_TRUNCATED
:
4358 it
->continuation_lines_width
= 0;
4359 reseat_at_next_visible_line_start (it
, 0);
4360 if ((op
& MOVE_TO_POS
) != 0
4361 && IT_CHARPOS (*it
) > to_charpos
)
4365 case MOVE_LINE_CONTINUED
:
4366 it
->continuation_lines_width
+= it
->current_x
;
4373 /* Reset/increment for the next run. */
4374 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4375 it
->current_x
= it
->hpos
= 0;
4376 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4378 last_height
= it
->max_ascent
+ it
->max_descent
;
4379 last_max_ascent
= it
->max_ascent
;
4380 it
->max_ascent
= it
->max_descent
= 0;
4386 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4388 If DY > 0, move IT backward at least that many pixels. DY = 0
4389 means move IT backward to the preceding line start or BEGV. This
4390 function may move over more than DY pixels if IT->current_y - DY
4391 ends up in the middle of a line; in this case IT->current_y will be
4392 set to the top of the line moved to. */
4395 move_it_vertically_backward (it
, dy
)
4399 int nlines
, h
, line_height
;
4401 int start_pos
= IT_CHARPOS (*it
);
4405 /* Estimate how many newlines we must move back. */
4406 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4408 /* Set the iterator's position that many lines back. */
4409 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4410 back_to_previous_visible_line_start (it
);
4412 /* Reseat the iterator here. When moving backward, we don't want
4413 reseat to skip forward over invisible text, set up the iterator
4414 to deliver from overlay strings at the new position etc. So,
4415 use reseat_1 here. */
4416 reseat_1 (it
, it
->current
.pos
, 1);
4418 /* We are now surely at a line start. */
4419 it
->current_x
= it
->hpos
= 0;
4421 /* Move forward and see what y-distance we moved. First move to the
4422 start of the next line so that we get its height. We need this
4423 height to be able to tell whether we reached the specified
4426 it2
.max_ascent
= it2
.max_descent
= 0;
4427 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4428 MOVE_TO_POS
| MOVE_TO_VPOS
);
4429 xassert (IT_CHARPOS (*it
) >= BEGV
);
4430 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4431 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4432 xassert (IT_CHARPOS (*it
) >= BEGV
);
4433 h
= it2
.current_y
- it
->current_y
;
4434 nlines
= it2
.vpos
- it
->vpos
;
4436 /* Correct IT's y and vpos position. */
4442 /* DY == 0 means move to the start of the screen line. The
4443 value of nlines is > 0 if continuation lines were involved. */
4445 move_it_by_lines (it
, nlines
, 1);
4446 xassert (IT_CHARPOS (*it
) <= start_pos
);
4450 /* The y-position we try to reach. Note that h has been
4451 subtracted in front of the if-statement. */
4452 int target_y
= it
->current_y
+ h
- dy
;
4454 /* If we did not reach target_y, try to move further backward if
4455 we can. If we moved too far backward, try to move forward. */
4456 if (target_y
< it
->current_y
4457 && IT_CHARPOS (*it
) > BEGV
)
4459 move_it_vertically (it
, target_y
- it
->current_y
);
4460 xassert (IT_CHARPOS (*it
) >= BEGV
);
4462 else if (target_y
>= it
->current_y
+ line_height
4463 && IT_CHARPOS (*it
) < ZV
)
4465 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4466 xassert (IT_CHARPOS (*it
) >= BEGV
);
4472 /* Move IT by a specified amount of pixel lines DY. DY negative means
4473 move backwards. DY = 0 means move to start of screen line. At the
4474 end, IT will be on the start of a screen line. */
4477 move_it_vertically (it
, dy
)
4482 move_it_vertically_backward (it
, -dy
);
4485 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4486 MOVE_TO_POS
| MOVE_TO_Y
);
4488 /* If buffer ends in ZV without a newline, move to the start of
4489 the line to satisfy the post-condition. */
4490 if (IT_CHARPOS (*it
) == ZV
4491 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4492 move_it_by_lines (it
, 0, 0);
4497 /* Return non-zero if some text between buffer positions START_CHARPOS
4498 and END_CHARPOS is invisible. IT->window is the window for text
4502 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4504 int start_charpos
, end_charpos
;
4506 Lisp_Object prop
, limit
;
4507 int invisible_found_p
;
4509 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4511 /* Is text at START invisible? */
4512 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4514 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4515 invisible_found_p
= 1;
4518 limit
= next_single_char_property_change (make_number (start_charpos
),
4520 make_number (end_charpos
));
4521 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4524 return invisible_found_p
;
4528 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4529 negative means move up. DVPOS == 0 means move to the start of the
4530 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4531 NEED_Y_P is zero, IT->current_y will be left unchanged.
4533 Further optimization ideas: If we would know that IT->f doesn't use
4534 a face with proportional font, we could be faster for
4535 truncate-lines nil. */
4538 move_it_by_lines (it
, dvpos
, need_y_p
)
4540 int dvpos
, need_y_p
;
4542 struct position pos
;
4544 if (!FRAME_WINDOW_P (it
->f
))
4546 struct text_pos textpos
;
4548 /* We can use vmotion on frames without proportional fonts. */
4549 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4550 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4551 reseat (it
, textpos
, 1);
4552 it
->vpos
+= pos
.vpos
;
4553 it
->current_y
+= pos
.vpos
;
4555 else if (dvpos
== 0)
4557 /* DVPOS == 0 means move to the start of the screen line. */
4558 move_it_vertically_backward (it
, 0);
4559 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4563 /* If there are no continuation lines, and if there is no
4564 selective display, try the simple method of moving forward
4565 DVPOS newlines, then see where we are. */
4566 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4568 int shortage
= 0, charpos
;
4570 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
4571 charpos
= IT_CHARPOS (*it
) + 1;
4573 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
4576 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
4578 struct text_pos pos
;
4579 CHARPOS (pos
) = charpos
;
4580 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4581 reseat (it
, pos
, 1);
4582 it
->vpos
+= dvpos
- shortage
;
4583 it
->hpos
= it
->current_x
= 0;
4588 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
4593 int start_charpos
, i
;
4595 /* If there are no continuation lines, and if there is no
4596 selective display, try the simple method of moving backward
4598 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4601 int charpos
= IT_CHARPOS (*it
);
4602 int bytepos
= IT_BYTEPOS (*it
);
4604 /* If in the middle of a line, go to its start. */
4605 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
4607 charpos
= find_next_newline_no_quit (charpos
, -1);
4608 bytepos
= CHAR_TO_BYTE (charpos
);
4611 if (charpos
== BEGV
)
4613 struct text_pos pos
;
4614 CHARPOS (pos
) = charpos
;
4615 BYTEPOS (pos
) = bytepos
;
4616 reseat (it
, pos
, 1);
4617 it
->hpos
= it
->current_x
= 0;
4622 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
4623 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
4625 struct text_pos pos
;
4626 CHARPOS (pos
) = charpos
;
4627 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4628 reseat (it
, pos
, 1);
4629 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
4630 it
->hpos
= it
->current_x
= 0;
4636 /* Go back -DVPOS visible lines and reseat the iterator there. */
4637 start_charpos
= IT_CHARPOS (*it
);
4638 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
4639 back_to_previous_visible_line_start (it
);
4640 reseat (it
, it
->current
.pos
, 1);
4641 it
->current_x
= it
->hpos
= 0;
4643 /* Above call may have moved too far if continuation lines
4644 are involved. Scan forward and see if it did. */
4646 it2
.vpos
= it2
.current_y
= 0;
4647 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
4648 it
->vpos
-= it2
.vpos
;
4649 it
->current_y
-= it2
.current_y
;
4650 it
->current_x
= it
->hpos
= 0;
4652 /* If we moved too far, move IT some lines forward. */
4653 if (it2
.vpos
> -dvpos
)
4655 int delta
= it2
.vpos
+ dvpos
;
4656 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
4663 /***********************************************************************
4665 ***********************************************************************/
4668 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
4672 add_to_log (format
, arg1
, arg2
)
4674 Lisp_Object arg1
, arg2
;
4676 Lisp_Object args
[3];
4677 Lisp_Object msg
, fmt
;
4680 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4683 GCPRO4 (fmt
, msg
, arg1
, arg2
);
4685 args
[0] = fmt
= build_string (format
);
4688 msg
= Fformat (3, args
);
4690 len
= STRING_BYTES (XSTRING (msg
)) + 1;
4691 buffer
= (char *) alloca (len
);
4692 strcpy (buffer
, XSTRING (msg
)->data
);
4694 message_dolog (buffer
, len
, 1, 0);
4699 /* Output a newline in the *Messages* buffer if "needs" one. */
4702 message_log_maybe_newline ()
4704 if (message_log_need_newline
)
4705 message_dolog ("", 0, 1, 0);
4709 /* Add a string M of length LEN to the message log, optionally
4710 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
4711 nonzero, means interpret the contents of M as multibyte. This
4712 function calls low-level routines in order to bypass text property
4713 hooks, etc. which might not be safe to run. */
4716 message_dolog (m
, len
, nlflag
, multibyte
)
4718 int len
, nlflag
, multibyte
;
4720 if (!NILP (Vmessage_log_max
))
4722 struct buffer
*oldbuf
;
4723 Lisp_Object oldpoint
, oldbegv
, oldzv
;
4724 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4725 int point_at_end
= 0;
4727 Lisp_Object old_deactivate_mark
, tem
;
4728 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4730 old_deactivate_mark
= Vdeactivate_mark
;
4731 oldbuf
= current_buffer
;
4732 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
4733 current_buffer
->undo_list
= Qt
;
4735 oldpoint
= Fpoint_marker ();
4736 oldbegv
= Fpoint_min_marker ();
4737 oldzv
= Fpoint_max_marker ();
4738 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
4746 BEGV_BYTE
= BEG_BYTE
;
4749 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4751 /* Insert the string--maybe converting multibyte to single byte
4752 or vice versa, so that all the text fits the buffer. */
4754 && NILP (current_buffer
->enable_multibyte_characters
))
4757 unsigned char work
[1];
4759 /* Convert a multibyte string to single-byte
4760 for the *Message* buffer. */
4761 for (i
= 0; i
< len
; i
+= nbytes
)
4763 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
4764 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
4766 : multibyte_char_to_unibyte (c
, Qnil
));
4767 insert_1_both (work
, 1, 1, 1, 0, 0);
4770 else if (! multibyte
4771 && ! NILP (current_buffer
->enable_multibyte_characters
))
4774 unsigned char *msg
= (unsigned char *) m
;
4775 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4776 /* Convert a single-byte string to multibyte
4777 for the *Message* buffer. */
4778 for (i
= 0; i
< len
; i
++)
4780 c
= unibyte_char_to_multibyte (msg
[i
]);
4781 nbytes
= CHAR_STRING (c
, str
);
4782 insert_1_both (str
, 1, nbytes
, 1, 0, 0);
4786 insert_1 (m
, len
, 1, 0, 0);
4790 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
4791 insert_1 ("\n", 1, 1, 0, 0);
4793 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4795 this_bol_byte
= PT_BYTE
;
4799 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4801 prev_bol_byte
= PT_BYTE
;
4803 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
4804 this_bol
, this_bol_byte
);
4807 del_range_both (prev_bol
, prev_bol_byte
,
4808 this_bol
, this_bol_byte
, 0);
4814 /* If you change this format, don't forget to also
4815 change message_log_check_duplicate. */
4816 sprintf (dupstr
, " [%d times]", dup
);
4817 duplen
= strlen (dupstr
);
4818 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
4819 insert_1 (dupstr
, duplen
, 1, 0, 1);
4824 if (NATNUMP (Vmessage_log_max
))
4826 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
4827 -XFASTINT (Vmessage_log_max
) - 1, 0);
4828 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
4831 BEGV
= XMARKER (oldbegv
)->charpos
;
4832 BEGV_BYTE
= marker_byte_position (oldbegv
);
4841 ZV
= XMARKER (oldzv
)->charpos
;
4842 ZV_BYTE
= marker_byte_position (oldzv
);
4846 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4848 /* We can't do Fgoto_char (oldpoint) because it will run some
4850 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
4851 XMARKER (oldpoint
)->bytepos
);
4854 free_marker (oldpoint
);
4855 free_marker (oldbegv
);
4856 free_marker (oldzv
);
4858 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
4859 set_buffer_internal (oldbuf
);
4861 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
4862 message_log_need_newline
= !nlflag
;
4863 Vdeactivate_mark
= old_deactivate_mark
;
4868 /* We are at the end of the buffer after just having inserted a newline.
4869 (Note: We depend on the fact we won't be crossing the gap.)
4870 Check to see if the most recent message looks a lot like the previous one.
4871 Return 0 if different, 1 if the new one should just replace it, or a
4872 value N > 1 if we should also append " [N times]". */
4875 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
4876 int prev_bol
, this_bol
;
4877 int prev_bol_byte
, this_bol_byte
;
4880 int len
= Z_BYTE
- 1 - this_bol_byte
;
4882 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
4883 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
4885 for (i
= 0; i
< len
; i
++)
4887 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
4896 if (*p1
++ == ' ' && *p1
++ == '[')
4899 while (*p1
>= '0' && *p1
<= '9')
4900 n
= n
* 10 + *p1
++ - '0';
4901 if (strncmp (p1
, " times]\n", 8) == 0)
4908 /* Display an echo area message M with a specified length of LEN
4909 chars. The string may include null characters. If M is 0, clear
4910 out any existing message, and let the mini-buffer text show through.
4912 The buffer M must continue to exist until after the echo area gets
4913 cleared or some other message gets displayed there. This means do
4914 not pass text that is stored in a Lisp string; do not pass text in
4915 a buffer that was alloca'd. */
4918 message2 (m
, len
, multibyte
)
4923 /* First flush out any partial line written with print. */
4924 message_log_maybe_newline ();
4926 message_dolog (m
, len
, 1, multibyte
);
4927 message2_nolog (m
, len
, multibyte
);
4931 /* The non-logging counterpart of message2. */
4934 message2_nolog (m
, len
, multibyte
)
4938 struct frame
*sf
= SELECTED_FRAME ();
4939 message_enable_multibyte
= multibyte
;
4943 if (noninteractive_need_newline
)
4944 putc ('\n', stderr
);
4945 noninteractive_need_newline
= 0;
4947 fwrite (m
, len
, 1, stderr
);
4948 if (cursor_in_echo_area
== 0)
4949 fprintf (stderr
, "\n");
4952 /* A null message buffer means that the frame hasn't really been
4953 initialized yet. Error messages get reported properly by
4954 cmd_error, so this must be just an informative message; toss it. */
4955 else if (INTERACTIVE
4956 && sf
->glyphs_initialized_p
4957 && FRAME_MESSAGE_BUF (sf
))
4959 Lisp_Object mini_window
;
4962 /* Get the frame containing the mini-buffer
4963 that the selected frame is using. */
4964 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
4965 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4967 FRAME_SAMPLE_VISIBILITY (f
);
4968 if (FRAME_VISIBLE_P (sf
)
4969 && ! FRAME_VISIBLE_P (f
))
4970 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
4974 set_message (m
, Qnil
, len
, multibyte
);
4975 if (minibuffer_auto_raise
)
4976 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
4979 clear_message (1, 1);
4981 do_pending_window_change (0);
4982 echo_area_display (1);
4983 do_pending_window_change (0);
4984 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
4985 (*frame_up_to_date_hook
) (f
);
4990 /* Display an echo area message M with a specified length of NBYTES
4991 bytes. The string may include null characters. If M is not a
4992 string, clear out any existing message, and let the mini-buffer
4993 text show through. */
4996 message3 (m
, nbytes
, multibyte
)
5001 struct gcpro gcpro1
;
5005 /* First flush out any partial line written with print. */
5006 message_log_maybe_newline ();
5008 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5009 message3_nolog (m
, nbytes
, multibyte
);
5015 /* The non-logging version of message3. */
5018 message3_nolog (m
, nbytes
, multibyte
)
5020 int nbytes
, multibyte
;
5022 struct frame
*sf
= SELECTED_FRAME ();
5023 message_enable_multibyte
= multibyte
;
5027 if (noninteractive_need_newline
)
5028 putc ('\n', stderr
);
5029 noninteractive_need_newline
= 0;
5031 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5032 if (cursor_in_echo_area
== 0)
5033 fprintf (stderr
, "\n");
5036 /* A null message buffer means that the frame hasn't really been
5037 initialized yet. Error messages get reported properly by
5038 cmd_error, so this must be just an informative message; toss it. */
5039 else if (INTERACTIVE
5040 && sf
->glyphs_initialized_p
5041 && FRAME_MESSAGE_BUF (sf
))
5043 Lisp_Object mini_window
;
5047 /* Get the frame containing the mini-buffer
5048 that the selected frame is using. */
5049 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5050 frame
= XWINDOW (mini_window
)->frame
;
5053 FRAME_SAMPLE_VISIBILITY (f
);
5054 if (FRAME_VISIBLE_P (sf
)
5055 && !FRAME_VISIBLE_P (f
))
5056 Fmake_frame_visible (frame
);
5058 if (STRINGP (m
) && XSTRING (m
)->size
)
5060 set_message (NULL
, m
, nbytes
, multibyte
);
5061 if (minibuffer_auto_raise
)
5062 Fraise_frame (frame
);
5065 clear_message (1, 1);
5067 do_pending_window_change (0);
5068 echo_area_display (1);
5069 do_pending_window_change (0);
5070 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5071 (*frame_up_to_date_hook
) (f
);
5076 /* Display a null-terminated echo area message M. If M is 0, clear
5077 out any existing message, and let the mini-buffer text show through.
5079 The buffer M must continue to exist until after the echo area gets
5080 cleared or some other message gets displayed there. Do not pass
5081 text that is stored in a Lisp string. Do not pass text in a buffer
5082 that was alloca'd. */
5088 message2 (m
, (m
? strlen (m
) : 0), 0);
5092 /* The non-logging counterpart of message1. */
5098 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5101 /* Display a message M which contains a single %s
5102 which gets replaced with STRING. */
5105 message_with_string (m
, string
, log
)
5114 if (noninteractive_need_newline
)
5115 putc ('\n', stderr
);
5116 noninteractive_need_newline
= 0;
5117 fprintf (stderr
, m
, XSTRING (string
)->data
);
5118 if (cursor_in_echo_area
== 0)
5119 fprintf (stderr
, "\n");
5123 else if (INTERACTIVE
)
5125 /* The frame whose minibuffer we're going to display the message on.
5126 It may be larger than the selected frame, so we need
5127 to use its buffer, not the selected frame's buffer. */
5128 Lisp_Object mini_window
;
5129 struct frame
*f
, *sf
= SELECTED_FRAME ();
5131 /* Get the frame containing the minibuffer
5132 that the selected frame is using. */
5133 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5134 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5136 /* A null message buffer means that the frame hasn't really been
5137 initialized yet. Error messages get reported properly by
5138 cmd_error, so this must be just an informative message; toss it. */
5139 if (FRAME_MESSAGE_BUF (f
))
5143 a
[0] = (char *) XSTRING (string
)->data
;
5145 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5146 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5149 message2 (FRAME_MESSAGE_BUF (f
), len
,
5150 STRING_MULTIBYTE (string
));
5152 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5153 STRING_MULTIBYTE (string
));
5155 /* Print should start at the beginning of the message
5156 buffer next time. */
5157 message_buf_print
= 0;
5163 /* Dump an informative message to the minibuf. If M is 0, clear out
5164 any existing message, and let the mini-buffer text show through. */
5168 message (m
, a1
, a2
, a3
)
5170 EMACS_INT a1
, a2
, a3
;
5176 if (noninteractive_need_newline
)
5177 putc ('\n', stderr
);
5178 noninteractive_need_newline
= 0;
5179 fprintf (stderr
, m
, a1
, a2
, a3
);
5180 if (cursor_in_echo_area
== 0)
5181 fprintf (stderr
, "\n");
5185 else if (INTERACTIVE
)
5187 /* The frame whose mini-buffer we're going to display the message
5188 on. It may be larger than the selected frame, so we need to
5189 use its buffer, not the selected frame's buffer. */
5190 Lisp_Object mini_window
;
5191 struct frame
*f
, *sf
= SELECTED_FRAME ();
5193 /* Get the frame containing the mini-buffer
5194 that the selected frame is using. */
5195 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5196 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5198 /* A null message buffer means that the frame hasn't really been
5199 initialized yet. Error messages get reported properly by
5200 cmd_error, so this must be just an informative message; toss
5202 if (FRAME_MESSAGE_BUF (f
))
5213 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5214 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5216 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5217 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5219 #endif /* NO_ARG_ARRAY */
5221 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5226 /* Print should start at the beginning of the message
5227 buffer next time. */
5228 message_buf_print
= 0;
5234 /* The non-logging version of message. */
5237 message_nolog (m
, a1
, a2
, a3
)
5239 EMACS_INT a1
, a2
, a3
;
5241 Lisp_Object old_log_max
;
5242 old_log_max
= Vmessage_log_max
;
5243 Vmessage_log_max
= Qnil
;
5244 message (m
, a1
, a2
, a3
);
5245 Vmessage_log_max
= old_log_max
;
5249 /* Display the current message in the current mini-buffer. This is
5250 only called from error handlers in process.c, and is not time
5256 if (!NILP (echo_area_buffer
[0]))
5259 string
= Fcurrent_message ();
5260 message3 (string
, XSTRING (string
)->size
,
5261 !NILP (current_buffer
->enable_multibyte_characters
));
5266 /* Make sure echo area buffers in echo_buffers[] are life. If they
5267 aren't, make new ones. */
5270 ensure_echo_area_buffers ()
5274 for (i
= 0; i
< 2; ++i
)
5275 if (!BUFFERP (echo_buffer
[i
])
5276 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5279 sprintf (name
, " *Echo Area %d*", i
);
5280 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5285 /* Call FN with args A1..A5 with either the current or last displayed
5286 echo_area_buffer as current buffer.
5288 WHICH zero means use the current message buffer
5289 echo_area_buffer[0]. If that is nil, choose a suitable buffer
5290 from echo_buffer[] and clear it.
5292 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
5293 suitable buffer from echo_buffer[] and clear it.
5295 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
5296 that the current message becomes the last displayed one, make
5297 choose a suitable buffer for echo_area_buffer[0], and clear it.
5299 Value is what FN returns. */
5302 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
)
5306 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
;
5309 int this_one
, the_other
, clear_buffer_p
, rc
;
5310 int count
= specpdl_ptr
- specpdl
;
5312 /* If buffers aren't life, make new ones. */
5313 ensure_echo_area_buffers ();
5318 this_one
= 0, the_other
= 1;
5320 this_one
= 1, the_other
= 0;
5323 this_one
= 0, the_other
= 1;
5326 /* We need a fresh one in case the current echo buffer equals
5327 the one containing the last displayed echo area message. */
5328 if (!NILP (echo_area_buffer
[this_one
])
5329 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
5330 echo_area_buffer
[this_one
] = Qnil
;
5333 /* Choose a suitable buffer from echo_buffer[] is we don't
5335 if (NILP (echo_area_buffer
[this_one
]))
5337 echo_area_buffer
[this_one
]
5338 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
5339 ? echo_buffer
[the_other
]
5340 : echo_buffer
[this_one
]);
5344 buffer
= echo_area_buffer
[this_one
];
5346 record_unwind_protect (unwind_with_echo_area_buffer
,
5347 with_echo_area_buffer_unwind_data (w
));
5349 /* Make the echo area buffer current. Note that for display
5350 purposes, it is not necessary that the displayed window's buffer
5351 == current_buffer, except for text property lookup. So, let's
5352 only set that buffer temporarily here without doing a full
5353 Fset_window_buffer. We must also change w->pointm, though,
5354 because otherwise an assertions in unshow_buffer fails, and Emacs
5356 set_buffer_internal_1 (XBUFFER (buffer
));
5360 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
5362 current_buffer
->truncate_lines
= Qnil
;
5363 current_buffer
->undo_list
= Qt
;
5364 current_buffer
->read_only
= Qnil
;
5366 if (clear_buffer_p
&& Z
> BEG
)
5369 xassert (BEGV
>= BEG
);
5370 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5372 rc
= fn (a1
, a2
, a3
, a4
, a5
);
5374 xassert (BEGV
>= BEG
);
5375 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5377 unbind_to (count
, Qnil
);
5382 /* Save state that should be preserved around the call to the function
5383 FN called in with_echo_area_buffer. */
5386 with_echo_area_buffer_unwind_data (w
)
5392 /* Reduce consing by keeping one vector in
5393 Vwith_echo_area_save_vector. */
5394 vector
= Vwith_echo_area_save_vector
;
5395 Vwith_echo_area_save_vector
= Qnil
;
5398 vector
= Fmake_vector (make_number (7), Qnil
);
5400 XSETBUFFER (XVECTOR (vector
)->contents
[i
], current_buffer
); ++i
;
5401 XVECTOR (vector
)->contents
[i
++] = Vdeactivate_mark
;
5402 XVECTOR (vector
)->contents
[i
++] = make_number (windows_or_buffers_changed
);
5406 XSETWINDOW (XVECTOR (vector
)->contents
[i
], w
); ++i
;
5407 XVECTOR (vector
)->contents
[i
++] = w
->buffer
;
5408 XVECTOR (vector
)->contents
[i
++]
5409 = make_number (XMARKER (w
->pointm
)->charpos
);
5410 XVECTOR (vector
)->contents
[i
++]
5411 = make_number (XMARKER (w
->pointm
)->bytepos
);
5417 XVECTOR (vector
)->contents
[i
++] = Qnil
;
5420 xassert (i
== XVECTOR (vector
)->size
);
5425 /* Restore global state from VECTOR which was created by
5426 with_echo_area_buffer_unwind_data. */
5429 unwind_with_echo_area_buffer (vector
)
5434 set_buffer_internal_1 (XBUFFER (XVECTOR (vector
)->contents
[i
])); ++i
;
5435 Vdeactivate_mark
= XVECTOR (vector
)->contents
[i
]; ++i
;
5436 windows_or_buffers_changed
= XFASTINT (XVECTOR (vector
)->contents
[i
]); ++i
;
5438 if (WINDOWP (XVECTOR (vector
)->contents
[i
]))
5441 Lisp_Object buffer
, charpos
, bytepos
;
5443 w
= XWINDOW (XVECTOR (vector
)->contents
[i
]); ++i
;
5444 buffer
= XVECTOR (vector
)->contents
[i
]; ++i
;
5445 charpos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5446 bytepos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5449 set_marker_both (w
->pointm
, buffer
,
5450 XFASTINT (charpos
), XFASTINT (bytepos
));
5453 Vwith_echo_area_save_vector
= vector
;
5458 /* Set up the echo area for use by print functions. MULTIBYTE_P
5459 non-zero means we will print multibyte. */
5462 setup_echo_area_for_printing (multibyte_p
)
5465 ensure_echo_area_buffers ();
5467 if (!message_buf_print
)
5469 /* A message has been output since the last time we printed.
5470 Choose a fresh echo area buffer. */
5471 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5472 echo_area_buffer
[0] = echo_buffer
[1];
5474 echo_area_buffer
[0] = echo_buffer
[0];
5476 /* Switch to that buffer and clear it. */
5477 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5480 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5482 /* Set up the buffer for the multibyteness we need. */
5484 != !NILP (current_buffer
->enable_multibyte_characters
))
5485 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
5487 /* Raise the frame containing the echo area. */
5488 if (minibuffer_auto_raise
)
5490 struct frame
*sf
= SELECTED_FRAME ();
5491 Lisp_Object mini_window
;
5492 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5493 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5496 message_buf_print
= 1;
5500 if (NILP (echo_area_buffer
[0]))
5502 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5503 echo_area_buffer
[0] = echo_buffer
[1];
5505 echo_area_buffer
[0] = echo_buffer
[0];
5508 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
5509 /* Someone switched buffers between print requests. */
5510 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5515 /* Display an echo area message in window W. Value is non-zero if W's
5516 height is changed. If display_last_displayed_message_p is
5517 non-zero, display the message that was last displayed, otherwise
5518 display the current message. */
5521 display_echo_area (w
)
5524 int i
, no_message_p
, window_height_changed_p
, count
;
5526 /* Temporarily disable garbage collections while displaying the echo
5527 area. This is done because a GC can print a message itself.
5528 That message would modify the echo area buffer's contents while a
5529 redisplay of the buffer is going on, and seriously confuse
5531 count
= inhibit_garbage_collection ();
5533 /* If there is no message, we must call display_echo_area_1
5534 nevertheless because it resizes the window. But we will have to
5535 reset the echo_area_buffer in question to nil at the end because
5536 with_echo_area_buffer will sets it to an empty buffer. */
5537 i
= display_last_displayed_message_p
? 1 : 0;
5538 no_message_p
= NILP (echo_area_buffer
[i
]);
5540 window_height_changed_p
5541 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
5542 (int (*) ()) display_echo_area_1
, w
);
5545 echo_area_buffer
[i
] = Qnil
;
5547 unbind_to (count
, Qnil
);
5548 return window_height_changed_p
;
5552 /* Helper for display_echo_area. Display the current buffer which
5553 contains the current echo area message in window W, a mini-window.
5554 Change the height of W so that all of the message is displayed.
5555 Value is non-zero if height of W was changed. */
5558 display_echo_area_1 (w
)
5562 struct text_pos start
;
5563 int window_height_changed_p
= 0;
5565 /* Do this before displaying, so that we have a large enough glyph
5566 matrix for the display. */
5567 window_height_changed_p
= resize_mini_window (w
, 0);
5570 clear_glyph_matrix (w
->desired_matrix
);
5571 XSETWINDOW (window
, w
);
5572 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
5573 try_window (window
, start
);
5575 return window_height_changed_p
;
5579 /* Resize the echo area window to exactly the size needed for the
5580 currently displayed message, if there is one. */
5583 resize_echo_area_axactly ()
5585 if (BUFFERP (echo_area_buffer
[0])
5586 && WINDOWP (echo_area_window
))
5588 struct window
*w
= XWINDOW (echo_area_window
);
5591 resized_p
= with_echo_area_buffer (w
, 0,
5592 (int (*) ()) resize_mini_window
,
5596 ++windows_or_buffers_changed
;
5597 ++update_mode_lines
;
5598 redisplay_internal (0);
5604 /* Resize mini-window W to fit the size of its contents. EXACT:P
5605 means size the window exactly to the size needed. Otherwise, it's
5606 only enlarged until W's buffer is empty. Value is non-zero if
5607 the window height has been changed. */
5610 resize_mini_window (w
, exact_p
)
5614 struct frame
*f
= XFRAME (w
->frame
);
5615 int window_height_changed_p
= 0;
5617 xassert (MINI_WINDOW_P (w
));
5619 /* Nil means don't try to resize. */
5620 if (NILP (Vmax_mini_window_height
)
5621 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
5624 if (!FRAME_MINIBUF_ONLY_P (f
))
5627 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5628 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
5629 int height
, max_height
;
5630 int unit
= CANON_Y_UNIT (f
);
5631 struct text_pos start
;
5633 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
5635 /* Compute the max. number of lines specified by the user. */
5636 if (FLOATP (Vmax_mini_window_height
))
5637 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
5638 else if (INTEGERP (Vmax_mini_window_height
))
5639 max_height
= XINT (Vmax_mini_window_height
);
5641 max_height
= total_height
/ 4;
5643 /* Correct that max. height if it's bogus. */
5644 max_height
= max (1, max_height
);
5645 max_height
= min (total_height
, max_height
);
5647 /* Find out the height of the text in the window. */
5649 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
5650 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
5651 height
= it
.current_y
+ last_height
;
5653 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
5654 height
= (height
+ unit
- 1) / unit
;
5656 /* Compute a suitable window start. */
5657 if (height
> max_height
)
5659 height
= max_height
;
5660 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
5661 move_it_vertically_backward (&it
, (height
- 1) * unit
);
5662 start
= it
.current
.pos
;
5665 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5666 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
5668 /* Let it grow only, until we display an empty message, in which
5669 case the window shrinks again. */
5670 if (height
> XFASTINT (w
->height
))
5672 int old_height
= XFASTINT (w
->height
);
5673 freeze_window_starts (f
, 1);
5674 grow_mini_window (w
, height
- XFASTINT (w
->height
));
5675 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5677 else if (height
< XFASTINT (w
->height
)
5678 && (exact_p
|| BEGV
== ZV
))
5680 int old_height
= XFASTINT (w
->height
);
5681 freeze_window_starts (f
, 0);
5682 shrink_mini_window (w
);
5683 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5687 return window_height_changed_p
;
5691 /* Value is the current message, a string, or nil if there is no
5699 if (NILP (echo_area_buffer
[0]))
5703 with_echo_area_buffer (0, 0, (int (*) ()) current_message_1
, &msg
);
5705 echo_area_buffer
[0] = Qnil
;
5713 current_message_1 (msg
)
5717 *msg
= make_buffer_string (BEG
, Z
, 1);
5724 /* Push the current message on Vmessage_stack for later restauration
5725 by restore_message. Value is non-zero if the current message isn't
5726 empty. This is a relatively infrequent operation, so it's not
5727 worth optimizing. */
5733 msg
= current_message ();
5734 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
5735 return STRINGP (msg
);
5739 /* Restore message display from the top of Vmessage_stack. */
5746 xassert (CONSP (Vmessage_stack
));
5747 msg
= XCAR (Vmessage_stack
);
5749 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
5751 message3_nolog (msg
, 0, 0);
5755 /* Pop the top-most entry off Vmessage_stack. */
5760 xassert (CONSP (Vmessage_stack
));
5761 Vmessage_stack
= XCDR (Vmessage_stack
);
5765 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
5766 exits. If the stack is not empty, we have a missing pop_message
5770 check_message_stack ()
5772 if (!NILP (Vmessage_stack
))
5777 /* Truncate to NCHARS what will be displayed in the echo area the next
5778 time we display it---but don't redisplay it now. */
5781 truncate_echo_area (nchars
)
5785 echo_area_buffer
[0] = Qnil
;
5786 /* A null message buffer means that the frame hasn't really been
5787 initialized yet. Error messages get reported properly by
5788 cmd_error, so this must be just an informative message; toss it. */
5789 else if (!noninteractive
5791 && !NILP (echo_area_buffer
[0]))
5793 struct frame
*sf
= SELECTED_FRAME ();
5794 if (FRAME_MESSAGE_BUF (sf
))
5795 with_echo_area_buffer (0, 0, (int (*) ()) truncate_message_1
, nchars
);
5800 /* Helper function for truncate_echo_area. Truncate the current
5801 message to at most NCHARS characters. */
5804 truncate_message_1 (nchars
)
5807 if (BEG
+ nchars
< Z
)
5808 del_range (BEG
+ nchars
, Z
);
5810 echo_area_buffer
[0] = Qnil
;
5815 /* Set the current message to a substring of S or STRING.
5817 If STRING is a Lisp string, set the message to the first NBYTES
5818 bytes from STRING. NBYTES zero means use the whole string. If
5819 STRING is multibyte, the message will be displayed multibyte.
5821 If S is not null, set the message to the first LEN bytes of S. LEN
5822 zero means use the whole string. MULTIBYTE_P non-zero means S is
5823 multibyte. Display the message multibyte in that case. */
5826 set_message (s
, string
, nbytes
, multibyte_p
)
5831 message_enable_multibyte
5832 = ((s
&& multibyte_p
)
5833 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
5835 with_echo_area_buffer (0, -1, (int (*) ()) set_message_1
,
5836 s
, string
, nbytes
, multibyte_p
);
5837 message_buf_print
= 0;
5841 /* Helper function for set_message. Arguments have the same meaning
5842 as there. This function is called with the echo area buffer being
5846 set_message_1 (s
, string
, nbytes
, multibyte_p
)
5849 int nbytes
, multibyte_p
;
5853 /* Change multibyteness of the echo buffer appropriately. */
5854 if (message_enable_multibyte
5855 != !NILP (current_buffer
->enable_multibyte_characters
))
5856 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
5858 /* Insert new message at BEG. */
5859 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5861 if (STRINGP (string
))
5866 nbytes
= XSTRING (string
)->size_byte
;
5867 nchars
= string_byte_to_char (string
, nbytes
);
5869 /* This function takes care of single/multibyte conversion. We
5870 just have to ensure that the echo area buffer has the right
5871 setting of enable_multibyte_characters. */
5872 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
5877 nbytes
= strlen (s
);
5879 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
5881 /* Convert from multi-byte to single-byte. */
5883 unsigned char work
[1];
5885 /* Convert a multibyte string to single-byte. */
5886 for (i
= 0; i
< nbytes
; i
+= n
)
5888 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
5889 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5891 : multibyte_char_to_unibyte (c
, Qnil
));
5892 insert_1_both (work
, 1, 1, 1, 0, 0);
5895 else if (!multibyte_p
5896 && !NILP (current_buffer
->enable_multibyte_characters
))
5898 /* Convert from single-byte to multi-byte. */
5900 unsigned char *msg
= (unsigned char *) s
;
5901 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5903 /* Convert a single-byte string to multibyte. */
5904 for (i
= 0; i
< nbytes
; i
++)
5906 c
= unibyte_char_to_multibyte (msg
[i
]);
5907 n
= CHAR_STRING (c
, str
);
5908 insert_1_both (str
, 1, n
, 1, 0, 0);
5912 insert_1 (s
, nbytes
, 1, 0, 0);
5919 /* Clear messages. CURRENT_P non-zero means clear the current
5920 message. LAST_DISPLAYED_P non-zero means clear the message
5924 clear_message (current_p
, last_displayed_p
)
5925 int current_p
, last_displayed_p
;
5928 echo_area_buffer
[0] = Qnil
;
5930 if (last_displayed_p
)
5931 echo_area_buffer
[1] = Qnil
;
5933 message_buf_print
= 0;
5936 /* Clear garbaged frames.
5938 This function is used where the old redisplay called
5939 redraw_garbaged_frames which in turn called redraw_frame which in
5940 turn called clear_frame. The call to clear_frame was a source of
5941 flickering. I believe a clear_frame is not necessary. It should
5942 suffice in the new redisplay to invalidate all current matrices,
5943 and ensure a complete redisplay of all windows. */
5946 clear_garbaged_frames ()
5950 Lisp_Object tail
, frame
;
5952 FOR_EACH_FRAME (tail
, frame
)
5954 struct frame
*f
= XFRAME (frame
);
5956 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
5958 clear_current_matrices (f
);
5964 ++windows_or_buffers_changed
;
5969 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
5970 is non-zero update selected_frame. Value is non-zero if the
5971 mini-windows height has been changed. */
5974 echo_area_display (update_frame_p
)
5977 Lisp_Object mini_window
;
5980 int window_height_changed_p
= 0;
5981 struct frame
*sf
= SELECTED_FRAME ();
5983 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5984 w
= XWINDOW (mini_window
);
5985 f
= XFRAME (WINDOW_FRAME (w
));
5987 /* Don't display if frame is invisible or not yet initialized. */
5988 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
5991 #ifdef HAVE_WINDOW_SYSTEM
5992 /* When Emacs starts, selected_frame may be a visible terminal
5993 frame, even if we run under a window system. If we let this
5994 through, a message would be displayed on the terminal. */
5995 if (EQ (selected_frame
, Vterminal_frame
)
5996 && !NILP (Vwindow_system
))
5998 #endif /* HAVE_WINDOW_SYSTEM */
6000 /* Redraw garbaged frames. */
6002 clear_garbaged_frames ();
6004 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6006 echo_area_window
= mini_window
;
6007 window_height_changed_p
= display_echo_area (w
);
6008 w
->must_be_updated_p
= 1;
6012 /* Not called from redisplay_internal. If we changed
6013 window configuration, we must redisplay thoroughly.
6014 Otherwise, we can do with updating what we displayed
6016 if (window_height_changed_p
)
6018 ++windows_or_buffers_changed
;
6019 ++update_mode_lines
;
6020 redisplay_internal (0);
6022 else if (FRAME_WINDOW_P (f
))
6024 update_single_window (w
, 1);
6025 rif
->flush_display (f
);
6028 update_frame (f
, 1, 1);
6031 else if (!EQ (mini_window
, selected_window
))
6032 windows_or_buffers_changed
++;
6034 /* Last displayed message is now the current message. */
6035 echo_area_buffer
[1] = echo_area_buffer
[0];
6037 /* Prevent redisplay optimization in redisplay_internal by resetting
6038 this_line_start_pos. This is done because the mini-buffer now
6039 displays the message instead of its buffer text. */
6040 if (EQ (mini_window
, selected_window
))
6041 CHARPOS (this_line_start_pos
) = 0;
6043 return window_height_changed_p
;
6048 /***********************************************************************
6050 ***********************************************************************/
6053 #ifdef HAVE_WINDOW_SYSTEM
6055 /* A buffer for constructing frame titles in it; allocated from the
6056 heap in init_xdisp and resized as needed in store_frame_title_char. */
6058 static char *frame_title_buf
;
6060 /* The buffer's end, and a current output position in it. */
6062 static char *frame_title_buf_end
;
6063 static char *frame_title_ptr
;
6066 /* Store a single character C for the frame title in frame_title_buf.
6067 Re-allocate frame_title_buf if necessary. */
6070 store_frame_title_char (c
)
6073 /* If output position has reached the end of the allocated buffer,
6074 double the buffer's size. */
6075 if (frame_title_ptr
== frame_title_buf_end
)
6077 int len
= frame_title_ptr
- frame_title_buf
;
6078 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6079 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6080 frame_title_buf_end
= frame_title_buf
+ new_size
;
6081 frame_title_ptr
= frame_title_buf
+ len
;
6084 *frame_title_ptr
++ = c
;
6088 /* Store part of a frame title in frame_title_buf, beginning at
6089 frame_title_ptr. STR is the string to store. Do not copy more
6090 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
6091 the whole string. Pad with spaces until FIELD_WIDTH number of
6092 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
6093 Called from display_mode_element when it is used to build a frame
6097 store_frame_title (str
, field_width
, precision
)
6099 int field_width
, precision
;
6103 /* Copy at most PRECISION chars from STR. */
6104 while ((precision
<= 0 || n
< precision
)
6107 store_frame_title_char (*str
++);
6111 /* Fill up with spaces until FIELD_WIDTH reached. */
6112 while (field_width
> 0
6115 store_frame_title_char (' ');
6123 /* Set the title of FRAME, if it has changed. The title format is
6124 Vicon_title_format if FRAME is iconified, otherwise it is
6125 frame_title_format. */
6128 x_consider_frame_title (frame
)
6131 struct frame
*f
= XFRAME (frame
);
6133 if (FRAME_WINDOW_P (f
)
6134 || FRAME_MINIBUF_ONLY_P (f
)
6135 || f
->explicit_name
)
6137 /* Do we have more than one visible frame on this X display? */
6140 struct buffer
*obuf
;
6144 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
6146 struct frame
*tf
= XFRAME (XCAR (tail
));
6149 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
6150 && !FRAME_MINIBUF_ONLY_P (tf
)
6151 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
6155 /* Set global variable indicating that multiple frames exist. */
6156 multiple_frames
= CONSP (tail
);
6158 /* Switch to the buffer of selected window of the frame. Set up
6159 frame_title_ptr so that display_mode_element will output into it;
6160 then display the title. */
6161 obuf
= current_buffer
;
6162 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
6163 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
6164 frame_title_ptr
= frame_title_buf
;
6165 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
6166 NULL
, DEFAULT_FACE_ID
);
6167 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
6168 frame_title_ptr
= NULL
;
6169 set_buffer_internal (obuf
);
6171 /* Set the title only if it's changed. This avoids consing in
6172 the common case where it hasn't. (If it turns out that we've
6173 already wasted too much time by walking through the list with
6174 display_mode_element, then we might need to optimize at a
6175 higher level than this.) */
6176 if (! STRINGP (f
->name
)
6177 || STRING_BYTES (XSTRING (f
->name
)) != len
6178 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
6179 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
6183 #else /* not HAVE_WINDOW_SYSTEM */
6185 #define frame_title_ptr ((char *)0)
6186 #define store_frame_title(str, mincol, maxcol) 0
6188 #endif /* not HAVE_WINDOW_SYSTEM */
6193 /***********************************************************************
6195 ***********************************************************************/
6198 /* Prepare for redisplay by updating menu-bar item lists when
6199 appropriate. This can call eval. */
6202 prepare_menu_bars ()
6205 struct gcpro gcpro1
, gcpro2
;
6207 struct frame
*tooltip_frame
;
6209 #ifdef HAVE_X_WINDOWS
6210 tooltip_frame
= tip_frame
;
6212 tooltip_frame
= NULL
;
6215 /* Update all frame titles based on their buffer names, etc. We do
6216 this before the menu bars so that the buffer-menu will show the
6217 up-to-date frame titles. */
6218 #ifdef HAVE_WINDOW_SYSTEM
6219 if (windows_or_buffers_changed
|| update_mode_lines
)
6221 Lisp_Object tail
, frame
;
6223 FOR_EACH_FRAME (tail
, frame
)
6226 if (f
!= tooltip_frame
6227 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
6228 x_consider_frame_title (frame
);
6231 #endif /* HAVE_WINDOW_SYSTEM */
6233 /* Update the menu bar item lists, if appropriate. This has to be
6234 done before any actual redisplay or generation of display lines. */
6235 all_windows
= (update_mode_lines
6236 || buffer_shared
> 1
6237 || windows_or_buffers_changed
);
6240 Lisp_Object tail
, frame
;
6241 int count
= specpdl_ptr
- specpdl
;
6243 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6245 FOR_EACH_FRAME (tail
, frame
)
6249 /* Ignore tooltip frame. */
6250 if (f
== tooltip_frame
)
6253 /* If a window on this frame changed size, report that to
6254 the user and clear the size-change flag. */
6255 if (FRAME_WINDOW_SIZES_CHANGED (f
))
6257 Lisp_Object functions
;
6259 /* Clear flag first in case we get an error below. */
6260 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
6261 functions
= Vwindow_size_change_functions
;
6262 GCPRO2 (tail
, functions
);
6264 while (CONSP (functions
))
6266 call1 (XCAR (functions
), frame
);
6267 functions
= XCDR (functions
);
6273 update_menu_bar (f
, 0);
6274 #ifdef HAVE_WINDOW_SYSTEM
6275 update_tool_bar (f
, 0);
6280 unbind_to (count
, Qnil
);
6284 struct frame
*sf
= SELECTED_FRAME ();
6285 update_menu_bar (sf
, 1);
6286 #ifdef HAVE_WINDOW_SYSTEM
6287 update_tool_bar (sf
, 1);
6291 /* Motif needs this. See comment in xmenu.c. Turn it off when
6292 pending_menu_activation is not defined. */
6293 #ifdef USE_X_TOOLKIT
6294 pending_menu_activation
= 0;
6299 /* Update the menu bar item list for frame F. This has to be done
6300 before we start to fill in any display lines, because it can call
6303 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
6306 update_menu_bar (f
, save_match_data
)
6308 int save_match_data
;
6311 register struct window
*w
;
6313 window
= FRAME_SELECTED_WINDOW (f
);
6314 w
= XWINDOW (window
);
6316 if (update_mode_lines
)
6317 w
->update_mode_line
= Qt
;
6319 if (FRAME_WINDOW_P (f
)
6321 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6322 FRAME_EXTERNAL_MENU_BAR (f
)
6324 FRAME_MENU_BAR_LINES (f
) > 0
6326 : FRAME_MENU_BAR_LINES (f
) > 0)
6328 /* If the user has switched buffers or windows, we need to
6329 recompute to reflect the new bindings. But we'll
6330 recompute when update_mode_lines is set too; that means
6331 that people can use force-mode-line-update to request
6332 that the menu bar be recomputed. The adverse effect on
6333 the rest of the redisplay algorithm is about the same as
6334 windows_or_buffers_changed anyway. */
6335 if (windows_or_buffers_changed
6336 || !NILP (w
->update_mode_line
)
6337 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6338 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6339 != !NILP (w
->last_had_star
))
6340 || ((!NILP (Vtransient_mark_mode
)
6341 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6342 != !NILP (w
->region_showing
)))
6344 struct buffer
*prev
= current_buffer
;
6345 int count
= specpdl_ptr
- specpdl
;
6347 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6348 if (save_match_data
)
6349 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6350 if (NILP (Voverriding_local_map_menu_flag
))
6352 specbind (Qoverriding_terminal_local_map
, Qnil
);
6353 specbind (Qoverriding_local_map
, Qnil
);
6356 /* Run the Lucid hook. */
6357 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
6359 /* If it has changed current-menubar from previous value,
6360 really recompute the menu-bar from the value. */
6361 if (! NILP (Vlucid_menu_bar_dirty_flag
))
6362 call0 (Qrecompute_lucid_menubar
);
6364 safe_run_hooks (Qmenu_bar_update_hook
);
6365 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
6367 /* Redisplay the menu bar in case we changed it. */
6368 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6369 if (FRAME_WINDOW_P (f
))
6370 set_frame_menubar (f
, 0, 0);
6372 /* On a terminal screen, the menu bar is an ordinary screen
6373 line, and this makes it get updated. */
6374 w
->update_mode_line
= Qt
;
6375 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6376 /* In the non-toolkit version, the menu bar is an ordinary screen
6377 line, and this makes it get updated. */
6378 w
->update_mode_line
= Qt
;
6379 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6381 unbind_to (count
, Qnil
);
6382 set_buffer_internal_1 (prev
);
6389 /***********************************************************************
6391 ***********************************************************************/
6393 #ifdef HAVE_WINDOW_SYSTEM
6395 /* Update the tool-bar item list for frame F. This has to be done
6396 before we start to fill in any display lines. Called from
6397 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
6398 and restore it here. */
6401 update_tool_bar (f
, save_match_data
)
6403 int save_match_data
;
6405 if (WINDOWP (f
->tool_bar_window
)
6406 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
6411 window
= FRAME_SELECTED_WINDOW (f
);
6412 w
= XWINDOW (window
);
6414 /* If the user has switched buffers or windows, we need to
6415 recompute to reflect the new bindings. But we'll
6416 recompute when update_mode_lines is set too; that means
6417 that people can use force-mode-line-update to request
6418 that the menu bar be recomputed. The adverse effect on
6419 the rest of the redisplay algorithm is about the same as
6420 windows_or_buffers_changed anyway. */
6421 if (windows_or_buffers_changed
6422 || !NILP (w
->update_mode_line
)
6423 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6424 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6425 != !NILP (w
->last_had_star
))
6426 || ((!NILP (Vtransient_mark_mode
)
6427 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6428 != !NILP (w
->region_showing
)))
6430 struct buffer
*prev
= current_buffer
;
6431 int count
= specpdl_ptr
- specpdl
;
6433 /* Set current_buffer to the buffer of the selected
6434 window of the frame, so that we get the right local
6436 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6438 /* Save match data, if we must. */
6439 if (save_match_data
)
6440 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6442 /* Make sure that we don't accidentally use bogus keymaps. */
6443 if (NILP (Voverriding_local_map_menu_flag
))
6445 specbind (Qoverriding_terminal_local_map
, Qnil
);
6446 specbind (Qoverriding_local_map
, Qnil
);
6449 /* Build desired tool-bar items from keymaps. */
6450 f
->desired_tool_bar_items
6451 = tool_bar_items (f
->desired_tool_bar_items
,
6452 &f
->n_desired_tool_bar_items
);
6454 /* Redisplay the tool-bar in case we changed it. */
6455 w
->update_mode_line
= Qt
;
6457 unbind_to (count
, Qnil
);
6458 set_buffer_internal_1 (prev
);
6464 /* Set F->desired_tool_bar_string to a Lisp string representing frame
6465 F's desired tool-bar contents. F->desired_tool_bar_items must have
6466 been set up previously by calling prepare_menu_bars. */
6469 build_desired_tool_bar_string (f
)
6472 int i
, size
, size_needed
, string_idx
;
6473 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6474 Lisp_Object image
, plist
, props
;
6476 image
= plist
= props
= Qnil
;
6477 GCPRO3 (image
, plist
, props
);
6479 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
6480 Otherwise, make a new string. */
6482 /* The size of the string we might be able to reuse. */
6483 size
= (STRINGP (f
->desired_tool_bar_string
)
6484 ? XSTRING (f
->desired_tool_bar_string
)->size
6487 /* Each image in the string we build is preceded by a space,
6488 and there is a space at the end. */
6489 size_needed
= f
->n_desired_tool_bar_items
+ 1;
6491 /* Reuse f->desired_tool_bar_string, if possible. */
6492 if (size
< size_needed
)
6493 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
6497 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
6498 Fremove_text_properties (make_number (0), make_number (size
),
6499 props
, f
->desired_tool_bar_string
);
6502 /* Put a `display' property on the string for the images to display,
6503 put a `menu_item' property on tool-bar items with a value that
6504 is the index of the item in F's tool-bar item vector. */
6505 for (i
= 0, string_idx
= 0;
6506 i
< f
->n_desired_tool_bar_items
;
6507 ++i
, string_idx
+= 1)
6510 (XVECTOR (f->desired_tool_bar_items) \
6511 ->contents[i * TOOL_BAR_ITEM_NSLOTS + (IDX)])
6513 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
6514 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
6516 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
6517 extern Lisp_Object Qlaplace
;
6519 /* If image is a vector, choose the image according to the
6521 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
6522 if (VECTORP (image
))
6524 enum tool_bar_item_image idx
;
6528 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
6529 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
6532 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
6533 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
6535 xassert (XVECTOR (image
)->size
>= idx
);
6536 image
= XVECTOR (image
)->contents
[idx
];
6539 /* Ignore invalid image specifications. */
6540 if (!valid_image_p (image
))
6543 /* Display the tool-bar button pressed, or depressed. */
6544 plist
= Fcopy_sequence (XCDR (image
));
6546 /* Compute margin and relief to draw. */
6547 relief
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
6548 margin
= relief
+ max (0, tool_bar_button_margin
);
6550 if (auto_raise_tool_bar_buttons_p
)
6552 /* Add a `:relief' property to the image spec if the item is
6556 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
6562 /* If image is selected, display it pressed, i.e. with a
6563 negative relief. If it's not selected, display it with a
6565 plist
= Fplist_put (plist
, QCrelief
,
6567 ? make_number (-relief
)
6568 : make_number (relief
)));
6572 /* Put a margin around the image. */
6574 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
6576 /* If button is not enabled, make the image appear disabled by
6577 applying an appropriate algorithm to it. */
6579 plist
= Fplist_put (plist
, QCalgorithm
, Qlaplace
);
6581 /* Put a `display' text property on the string for the image to
6582 display. Put a `menu-item' property on the string that gives
6583 the start of this item's properties in the tool-bar items
6585 image
= Fcons (Qimage
, plist
);
6586 props
= list4 (Qdisplay
, image
,
6587 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
)),
6588 Fadd_text_properties (make_number (string_idx
),
6589 make_number (string_idx
+ 1),
6590 props
, f
->desired_tool_bar_string
);
6598 /* Display one line of the tool-bar of frame IT->f. */
6601 display_tool_bar_line (it
)
6604 struct glyph_row
*row
= it
->glyph_row
;
6605 int max_x
= it
->last_visible_x
;
6608 prepare_desired_row (row
);
6609 row
->y
= it
->current_y
;
6611 while (it
->current_x
< max_x
)
6613 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
6615 /* Get the next display element. */
6616 if (!get_next_display_element (it
))
6619 /* Produce glyphs. */
6620 x_before
= it
->current_x
;
6621 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
6622 PRODUCE_GLYPHS (it
);
6624 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
6629 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
6631 if (x
+ glyph
->pixel_width
> max_x
)
6633 /* Glyph doesn't fit on line. */
6634 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
6640 x
+= glyph
->pixel_width
;
6644 /* Stop at line ends. */
6645 if (ITERATOR_AT_END_OF_LINE_P (it
))
6648 set_iterator_to_next (it
);
6653 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
6654 extend_face_to_end_of_line (it
);
6655 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
6656 last
->right_box_line_p
= 1;
6657 compute_line_metrics (it
);
6659 /* If line is empty, make it occupy the rest of the tool-bar. */
6660 if (!row
->displays_text_p
)
6662 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
6663 row
->ascent
= row
->phys_ascent
= 0;
6666 row
->full_width_p
= 1;
6667 row
->continued_p
= 0;
6668 row
->truncated_on_left_p
= 0;
6669 row
->truncated_on_right_p
= 0;
6671 it
->current_x
= it
->hpos
= 0;
6672 it
->current_y
+= row
->height
;
6678 /* Value is the number of screen lines needed to make all tool-bar
6679 items of frame F visible. */
6682 tool_bar_lines_needed (f
)
6685 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6688 /* Initialize an iterator for iteration over
6689 F->desired_tool_bar_string in the tool-bar window of frame F. */
6690 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
6691 it
.first_visible_x
= 0;
6692 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6693 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
6695 while (!ITERATOR_AT_END_P (&it
))
6697 it
.glyph_row
= w
->desired_matrix
->rows
;
6698 clear_glyph_row (it
.glyph_row
);
6699 display_tool_bar_line (&it
);
6702 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
6706 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
6707 height should be changed. */
6710 redisplay_tool_bar (f
)
6715 struct glyph_row
*row
;
6716 int change_height_p
= 0;
6718 /* If frame hasn't a tool-bar window or if it is zero-height, don't
6719 do anything. This means you must start with tool-bar-lines
6720 non-zero to get the auto-sizing effect. Or in other words, you
6721 can turn off tool-bars by specifying tool-bar-lines zero. */
6722 if (!WINDOWP (f
->tool_bar_window
)
6723 || (w
= XWINDOW (f
->tool_bar_window
),
6724 XFASTINT (w
->height
) == 0))
6727 /* Set up an iterator for the tool-bar window. */
6728 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
6729 it
.first_visible_x
= 0;
6730 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6733 /* Build a string that represents the contents of the tool-bar. */
6734 build_desired_tool_bar_string (f
);
6735 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
6737 /* Display as many lines as needed to display all tool-bar items. */
6738 while (it
.current_y
< it
.last_visible_y
)
6739 display_tool_bar_line (&it
);
6741 /* It doesn't make much sense to try scrolling in the tool-bar
6742 window, so don't do it. */
6743 w
->desired_matrix
->no_scrolling_p
= 1;
6744 w
->must_be_updated_p
= 1;
6746 if (auto_resize_tool_bars_p
)
6750 /* If there are blank lines at the end, except for a partially
6751 visible blank line at the end that is smaller than
6752 CANON_Y_UNIT, change the tool-bar's height. */
6753 row
= it
.glyph_row
- 1;
6754 if (!row
->displays_text_p
6755 && row
->height
>= CANON_Y_UNIT (f
))
6756 change_height_p
= 1;
6758 /* If row displays tool-bar items, but is partially visible,
6759 change the tool-bar's height. */
6760 if (row
->displays_text_p
6761 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
6762 change_height_p
= 1;
6764 /* Resize windows as needed by changing the `tool-bar-lines'
6767 && (nlines
= tool_bar_lines_needed (f
),
6768 nlines
!= XFASTINT (w
->height
)))
6770 extern Lisp_Object Qtool_bar_lines
;
6773 XSETFRAME (frame
, f
);
6774 clear_glyph_matrix (w
->desired_matrix
);
6775 Fmodify_frame_parameters (frame
,
6776 Fcons (Fcons (Qtool_bar_lines
,
6777 make_number (nlines
)),
6779 fonts_changed_p
= 1;
6783 return change_height_p
;
6787 /* Get information about the tool-bar item which is displayed in GLYPH
6788 on frame F. Return in *PROP_IDX the index where tool-bar item
6789 properties start in F->current_tool_bar_items. Value is zero if
6790 GLYPH doesn't display a tool-bar item. */
6793 tool_bar_item_info (f
, glyph
, prop_idx
)
6795 struct glyph
*glyph
;
6801 /* Get the text property `menu-item' at pos. The value of that
6802 property is the start index of this item's properties in
6803 F->current_tool_bar_items. */
6804 prop
= Fget_text_property (make_number (glyph
->charpos
),
6805 Qmenu_item
, f
->current_tool_bar_string
);
6806 if (INTEGERP (prop
))
6808 *prop_idx
= XINT (prop
);
6817 #endif /* HAVE_WINDOW_SYSTEM */
6821 /************************************************************************
6822 Horizontal scrolling
6823 ************************************************************************/
6825 static int hscroll_window_tree
P_ ((Lisp_Object
));
6826 static int hscroll_windows
P_ ((Lisp_Object
));
6828 /* For all leaf windows in the window tree rooted at WINDOW, set their
6829 hscroll value so that PT is (i) visible in the window, and (ii) so
6830 that it is not within a certain margin at the window's left and
6831 right border. Value is non-zero if any window's hscroll has been
6835 hscroll_window_tree (window
)
6838 int hscrolled_p
= 0;
6840 while (WINDOWP (window
))
6842 struct window
*w
= XWINDOW (window
);
6844 if (WINDOWP (w
->hchild
))
6845 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
6846 else if (WINDOWP (w
->vchild
))
6847 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
6848 else if (w
->cursor
.vpos
>= 0)
6850 int hscroll_margin
, text_area_x
, text_area_y
;
6851 int text_area_width
, text_area_height
;
6852 struct glyph_row
*current_cursor_row
6853 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
6854 struct glyph_row
*desired_cursor_row
6855 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
6856 struct glyph_row
*cursor_row
6857 = (desired_cursor_row
->enabled_p
6858 ? desired_cursor_row
6859 : current_cursor_row
);
6861 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
6862 &text_area_width
, &text_area_height
);
6864 /* Scroll when cursor is inside this scroll margin. */
6865 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
6867 if ((XFASTINT (w
->hscroll
)
6868 && w
->cursor
.x
< hscroll_margin
)
6869 || (cursor_row
->enabled_p
6870 && cursor_row
->truncated_on_right_p
6871 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
6875 struct buffer
*saved_current_buffer
;
6878 /* Find point in a display of infinite width. */
6879 saved_current_buffer
= current_buffer
;
6880 current_buffer
= XBUFFER (w
->buffer
);
6882 if (w
== XWINDOW (selected_window
))
6883 pt
= BUF_PT (current_buffer
);
6886 pt
= marker_position (w
->pointm
);
6887 pt
= max (BEGV
, pt
);
6891 /* Move iterator to pt starting at cursor_row->start in
6892 a line with infinite width. */
6893 init_to_row_start (&it
, w
, cursor_row
);
6894 it
.last_visible_x
= INFINITY
;
6895 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
6896 current_buffer
= saved_current_buffer
;
6898 /* Center cursor in window. */
6899 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
6900 / CANON_X_UNIT (it
.f
));
6902 /* Don't call Fset_window_hscroll if value hasn't
6903 changed because it will prevent redisplay
6905 if (XFASTINT (w
->hscroll
) != hscroll
)
6907 Fset_window_hscroll (window
, make_number (hscroll
));
6916 /* Value is non-zero if hscroll of any leaf window has been changed. */
6921 /* Set hscroll so that cursor is visible and not inside horizontal
6922 scroll margins for all windows in the tree rooted at WINDOW. See
6923 also hscroll_window_tree above. Value is non-zero if any window's
6924 hscroll has been changed. If it has, desired matrices on the frame
6925 of WINDOW are cleared. */
6928 hscroll_windows (window
)
6933 if (automatic_hscrolling_p
)
6935 hscrolled_p
= hscroll_window_tree (window
);
6937 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
6946 /************************************************************************
6948 ************************************************************************/
6950 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
6951 to a non-zero value. This is sometimes handy to have in a debugger
6956 /* First and last unchanged row for try_window_id. */
6958 int debug_first_unchanged_at_end_vpos
;
6959 int debug_last_unchanged_at_beg_vpos
;
6961 /* Delta vpos and y. */
6963 int debug_dvpos
, debug_dy
;
6965 /* Delta in characters and bytes for try_window_id. */
6967 int debug_delta
, debug_delta_bytes
;
6969 /* Values of window_end_pos and window_end_vpos at the end of
6972 int debug_end_pos
, debug_end_vpos
;
6974 /* Append a string to W->desired_matrix->method. FMT is a printf
6975 format string. A1...A9 are a supplement for a variable-length
6976 argument list. If trace_redisplay_p is non-zero also printf the
6977 resulting string to stderr. */
6980 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
6983 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
6986 char *method
= w
->desired_matrix
->method
;
6987 int len
= strlen (method
);
6988 int size
= sizeof w
->desired_matrix
->method
;
6989 int remaining
= size
- len
- 1;
6991 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
6992 if (len
&& remaining
)
6998 strncpy (method
+ len
, buffer
, remaining
);
7000 if (trace_redisplay_p
)
7001 fprintf (stderr
, "%p (%s): %s\n",
7003 ((BUFFERP (w
->buffer
)
7004 && STRINGP (XBUFFER (w
->buffer
)->name
))
7005 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
7010 #endif /* GLYPH_DEBUG */
7013 /* This counter is used to clear the face cache every once in a while
7014 in redisplay_internal. It is incremented for each redisplay.
7015 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
7018 #define CLEAR_FACE_CACHE_COUNT 10000
7019 static int clear_face_cache_count
;
7021 /* Record the previous terminal frame we displayed. */
7023 static struct frame
*previous_terminal_frame
;
7025 /* Non-zero while redisplay_internal is in progress. */
7030 /* Value is non-zero if all changes in window W, which displays
7031 current_buffer, are in the text between START and END. START is a
7032 buffer position, END is given as a distance from Z. Used in
7033 redisplay_internal for display optimization. */
7036 text_outside_line_unchanged_p (w
, start
, end
)
7040 int unchanged_p
= 1;
7042 /* If text or overlays have changed, see where. */
7043 if (XFASTINT (w
->last_modified
) < MODIFF
7044 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7046 /* Gap in the line? */
7047 if (GPT
< start
|| Z
- GPT
< end
)
7050 /* Changes start in front of the line, or end after it? */
7052 && (BEG_UNCHANGED
< start
- 1
7053 || END_UNCHANGED
< end
))
7056 /* If selective display, can't optimize if changes start at the
7057 beginning of the line. */
7059 && INTEGERP (current_buffer
->selective_display
)
7060 && XINT (current_buffer
->selective_display
) > 0
7061 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
7069 /* Do a frame update, taking possible shortcuts into account. This is
7070 the main external entry point for redisplay.
7072 If the last redisplay displayed an echo area message and that message
7073 is no longer requested, we clear the echo area or bring back the
7074 mini-buffer if that is in use. */
7079 redisplay_internal (0);
7082 /* Return 1 if point moved out of or into a composition. Otherwise
7083 return 0. PREV_BUF and PREV_PT are the last point buffer and
7084 position. BUF and PT are the current point buffer and position. */
7087 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
7088 struct buffer
*prev_buf
, *buf
;
7095 XSETBUFFER (buffer
, buf
);
7096 /* Check a composition at the last point if point moved within the
7098 if (prev_buf
== buf
)
7101 /* Point didn't move. */
7104 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
7105 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
7106 && COMPOSITION_VALID_P (start
, end
, prop
)
7107 && start
< prev_pt
&& end
> prev_pt
)
7108 /* The last point was within the composition. Return 1 iff
7109 point moved out of the composition. */
7110 return (pt
<= start
|| pt
>= end
);
7113 /* Check a composition at the current point. */
7114 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
7115 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
7116 && COMPOSITION_VALID_P (start
, end
, prop
)
7117 && start
< pt
&& end
> pt
);
7120 /* Reconsider the setting of B->clip_changed which is displayed
7124 reconsider_clip_changes (w
, b
)
7128 if (b
->prevent_redisplay_optimizations_p
)
7129 b
->clip_changed
= 1;
7130 else if (b
->clip_changed
7131 && !NILP (w
->window_end_valid
)
7132 && w
->current_matrix
->buffer
== b
7133 && w
->current_matrix
->zv
== BUF_ZV (b
)
7134 && w
->current_matrix
->begv
== BUF_BEGV (b
))
7135 b
->clip_changed
= 0;
7137 /* If display wasn't paused, and W is not a tool bar window, see if
7138 point has been moved into or out of a composition. In that case,
7139 we set b->clip_changed to 1 to force updating the screen. If
7140 b->clip_changed has already been set to 1, we can skip this
7142 if (!b
->clip_changed
7143 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
7147 if (w
== XWINDOW (selected_window
))
7148 pt
= BUF_PT (current_buffer
);
7150 pt
= marker_position (w
->pointm
);
7152 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
7153 || pt
!= XINT (w
->last_point
))
7154 && check_point_in_composition (w
->current_matrix
->buffer
,
7155 XINT (w
->last_point
),
7156 XBUFFER (w
->buffer
), pt
))
7157 b
->clip_changed
= 1;
7162 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
7163 response to any user action; therefore, we should preserve the echo
7164 area. (Actually, our caller does that job.) Perhaps in the future
7165 avoid recentering windows if it is not necessary; currently that
7166 causes some problems. */
7169 redisplay_internal (preserve_echo_area
)
7170 int preserve_echo_area
;
7172 struct window
*w
= XWINDOW (selected_window
);
7173 struct frame
*f
= XFRAME (w
->frame
);
7175 int must_finish
= 0;
7176 struct text_pos tlbufpos
, tlendpos
;
7177 int number_of_visible_frames
;
7179 struct frame
*sf
= SELECTED_FRAME ();
7181 /* Non-zero means redisplay has to consider all windows on all
7182 frames. Zero means, only selected_window is considered. */
7183 int consider_all_windows_p
;
7185 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
7187 /* No redisplay if running in batch mode or frame is not yet fully
7188 initialized, or redisplay is explicitly turned off by setting
7189 Vinhibit_redisplay. */
7191 || !NILP (Vinhibit_redisplay
)
7192 || !f
->glyphs_initialized_p
)
7195 /* The flag redisplay_performed_directly_p is set by
7196 direct_output_for_insert when it already did the whole screen
7197 update necessary. */
7198 if (redisplay_performed_directly_p
)
7200 redisplay_performed_directly_p
= 0;
7201 if (!hscroll_windows (selected_window
))
7205 #ifdef USE_X_TOOLKIT
7206 if (popup_activated ())
7210 /* I don't think this happens but let's be paranoid. */
7214 /* Record a function that resets redisplaying_p to its old value
7215 when we leave this function. */
7216 count
= specpdl_ptr
- specpdl
;
7217 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
7222 reconsider_clip_changes (w
, current_buffer
);
7224 /* If new fonts have been loaded that make a glyph matrix adjustment
7225 necessary, do it. */
7226 if (fonts_changed_p
)
7228 adjust_glyphs (NULL
);
7229 ++windows_or_buffers_changed
;
7230 fonts_changed_p
= 0;
7233 if (! FRAME_WINDOW_P (sf
)
7234 && previous_terminal_frame
!= sf
)
7236 /* Since frames on an ASCII terminal share the same display
7237 area, displaying a different frame means redisplay the whole
7239 windows_or_buffers_changed
++;
7240 SET_FRAME_GARBAGED (sf
);
7241 XSETFRAME (Vterminal_frame
, sf
);
7243 previous_terminal_frame
= sf
;
7245 /* Set the visible flags for all frames. Do this before checking
7246 for resized or garbaged frames; they want to know if their frames
7247 are visible. See the comment in frame.h for
7248 FRAME_SAMPLE_VISIBILITY. */
7250 Lisp_Object tail
, frame
;
7252 number_of_visible_frames
= 0;
7254 FOR_EACH_FRAME (tail
, frame
)
7256 struct frame
*f
= XFRAME (frame
);
7258 FRAME_SAMPLE_VISIBILITY (f
);
7259 if (FRAME_VISIBLE_P (f
))
7260 ++number_of_visible_frames
;
7261 clear_desired_matrices (f
);
7265 /* Notice any pending interrupt request to change frame size. */
7266 do_pending_window_change (1);
7268 /* Clear frames marked as garbaged. */
7270 clear_garbaged_frames ();
7272 /* Build menubar and tool-bar items. */
7273 prepare_menu_bars ();
7275 if (windows_or_buffers_changed
)
7276 update_mode_lines
++;
7278 /* Detect case that we need to write or remove a star in the mode line. */
7279 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
7281 w
->update_mode_line
= Qt
;
7282 if (buffer_shared
> 1)
7283 update_mode_lines
++;
7286 /* If %c is in the mode line, update it if needed. */
7287 if (!NILP (w
->column_number_displayed
)
7288 /* This alternative quickly identifies a common case
7289 where no change is needed. */
7290 && !(PT
== XFASTINT (w
->last_point
)
7291 && XFASTINT (w
->last_modified
) >= MODIFF
7292 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7293 && XFASTINT (w
->column_number_displayed
) != current_column ())
7294 w
->update_mode_line
= Qt
;
7296 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
7298 /* The variable buffer_shared is set in redisplay_window and
7299 indicates that we redisplay a buffer in different windows. See
7301 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
7303 /* If specs for an arrow have changed, do thorough redisplay
7304 to ensure we remove any arrow that should no longer exist. */
7305 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
7306 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
7307 consider_all_windows_p
= windows_or_buffers_changed
= 1;
7309 /* Normally the message* functions will have already displayed and
7310 updated the echo area, but the frame may have been trashed, or
7311 the update may have been preempted, so display the echo area
7312 again here. Checking both message buffers captures the case that
7313 the echo area should be cleared. */
7314 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
7316 int window_height_changed_p
= echo_area_display (0);
7319 if (fonts_changed_p
)
7321 else if (window_height_changed_p
)
7323 consider_all_windows_p
= 1;
7324 ++update_mode_lines
;
7325 ++windows_or_buffers_changed
;
7327 /* If window configuration was changed, frames may have been
7328 marked garbaged. Clear them or we will experience
7329 surprises wrt scrolling. */
7331 clear_garbaged_frames ();
7334 else if (w
== XWINDOW (minibuf_window
)
7335 && (current_buffer
->clip_changed
7336 || XFASTINT (w
->last_modified
) < MODIFF
7337 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7338 && resize_mini_window (w
, 0))
7340 /* Resized active mini-window to fit the size of what it is
7341 showing if its contents might have changed. */
7343 consider_all_windows_p
= 1;
7344 ++windows_or_buffers_changed
;
7345 ++update_mode_lines
;
7347 /* If window configuration was changed, frames may have been
7348 marked garbaged. Clear them or we will experience
7349 surprises wrt scrolling. */
7351 clear_garbaged_frames ();
7355 /* If showing the region, and mark has changed, we must redisplay
7356 the whole window. The assignment to this_line_start_pos prevents
7357 the optimization directly below this if-statement. */
7358 if (((!NILP (Vtransient_mark_mode
)
7359 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7360 != !NILP (w
->region_showing
))
7361 || (!NILP (w
->region_showing
)
7362 && !EQ (w
->region_showing
,
7363 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
7364 CHARPOS (this_line_start_pos
) = 0;
7366 /* Optimize the case that only the line containing the cursor in the
7367 selected window has changed. Variables starting with this_ are
7368 set in display_line and record information about the line
7369 containing the cursor. */
7370 tlbufpos
= this_line_start_pos
;
7371 tlendpos
= this_line_end_pos
;
7372 if (!consider_all_windows_p
7373 && CHARPOS (tlbufpos
) > 0
7374 && NILP (w
->update_mode_line
)
7375 && !current_buffer
->clip_changed
7376 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
7377 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
7378 /* Make sure recorded data applies to current buffer, etc. */
7379 && this_line_buffer
== current_buffer
7380 && current_buffer
== XBUFFER (w
->buffer
)
7381 && NILP (w
->force_start
)
7382 /* Point must be on the line that we have info recorded about. */
7383 && PT
>= CHARPOS (tlbufpos
)
7384 && PT
<= Z
- CHARPOS (tlendpos
)
7385 /* All text outside that line, including its final newline,
7386 must be unchanged */
7387 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
7388 CHARPOS (tlendpos
)))
7390 if (CHARPOS (tlbufpos
) > BEGV
7391 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
7392 && (CHARPOS (tlbufpos
) == ZV
7393 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
7394 /* Former continuation line has disappeared by becoming empty */
7396 else if (XFASTINT (w
->last_modified
) < MODIFF
7397 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
7398 || MINI_WINDOW_P (w
))
7400 /* We have to handle the case of continuation around a
7401 wide-column character (See the comment in indent.c around
7404 For instance, in the following case:
7406 -------- Insert --------
7407 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
7408 J_I_ ==> J_I_ `^^' are cursors.
7412 As we have to redraw the line above, we should goto cancel. */
7415 int line_height_before
= this_line_pixel_height
;
7417 /* Note that start_display will handle the case that the
7418 line starting at tlbufpos is a continuation lines. */
7419 start_display (&it
, w
, tlbufpos
);
7421 /* Implementation note: It this still necessary? */
7422 if (it
.current_x
!= this_line_start_x
)
7425 TRACE ((stderr
, "trying display optimization 1\n"));
7426 w
->cursor
.vpos
= -1;
7427 overlay_arrow_seen
= 0;
7428 it
.vpos
= this_line_vpos
;
7429 it
.current_y
= this_line_y
;
7430 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
7433 /* If line contains point, is not continued,
7434 and ends at same distance from eob as before, we win */
7435 if (w
->cursor
.vpos
>= 0
7436 /* Line is not continued, otherwise this_line_start_pos
7437 would have been set to 0 in display_line. */
7438 && CHARPOS (this_line_start_pos
)
7439 /* Line ends as before. */
7440 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
7441 /* Line has same height as before. Otherwise other lines
7442 would have to be shifted up or down. */
7443 && this_line_pixel_height
== line_height_before
)
7445 /* If this is not the window's last line, we must adjust
7446 the charstarts of the lines below. */
7447 if (it
.current_y
< it
.last_visible_y
)
7449 struct glyph_row
*row
7450 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
7451 int delta
, delta_bytes
;
7453 if (Z
- CHARPOS (tlendpos
) == ZV
)
7455 /* This line ends at end of (accessible part of)
7456 buffer. There is no newline to count. */
7458 - CHARPOS (tlendpos
)
7459 - MATRIX_ROW_START_CHARPOS (row
));
7460 delta_bytes
= (Z_BYTE
7461 - BYTEPOS (tlendpos
)
7462 - MATRIX_ROW_START_BYTEPOS (row
));
7466 /* This line ends in a newline. Must take
7467 account of the newline and the rest of the
7468 text that follows. */
7470 - CHARPOS (tlendpos
)
7471 - MATRIX_ROW_START_CHARPOS (row
));
7472 delta_bytes
= (Z_BYTE
7473 - BYTEPOS (tlendpos
)
7474 - MATRIX_ROW_START_BYTEPOS (row
));
7477 increment_matrix_positions (w
->current_matrix
,
7479 w
->current_matrix
->nrows
,
7480 delta
, delta_bytes
);
7483 /* If this row displays text now but previously didn't,
7484 or vice versa, w->window_end_vpos may have to be
7486 if ((it
.glyph_row
- 1)->displays_text_p
)
7488 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
7489 XSETINT (w
->window_end_vpos
, this_line_vpos
);
7491 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
7492 && this_line_vpos
> 0)
7493 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
7494 w
->window_end_valid
= Qnil
;
7496 /* Update hint: No need to try to scroll in update_window. */
7497 w
->desired_matrix
->no_scrolling_p
= 1;
7500 *w
->desired_matrix
->method
= 0;
7501 debug_method_add (w
, "optimization 1");
7508 else if (/* Cursor position hasn't changed. */
7509 PT
== XFASTINT (w
->last_point
)
7510 /* Make sure the cursor was last displayed
7511 in this window. Otherwise we have to reposition it. */
7512 && 0 <= w
->cursor
.vpos
7513 && XINT (w
->height
) > w
->cursor
.vpos
)
7517 do_pending_window_change (1);
7519 /* We used to always goto end_of_redisplay here, but this
7520 isn't enough if we have a blinking cursor. */
7521 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
7522 goto end_of_redisplay
;
7526 /* If highlighting the region, or if the cursor is in the echo area,
7527 then we can't just move the cursor. */
7528 else if (! (!NILP (Vtransient_mark_mode
)
7529 && !NILP (current_buffer
->mark_active
))
7530 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7531 || highlight_nonselected_windows
)
7532 && NILP (w
->region_showing
)
7533 && NILP (Vshow_trailing_whitespace
)
7534 && !cursor_in_echo_area
)
7537 struct glyph_row
*row
;
7539 /* Skip from tlbufpos to PT and see where it is. Note that
7540 PT may be in invisible text. If so, we will end at the
7541 next visible position. */
7542 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
7543 NULL
, DEFAULT_FACE_ID
);
7544 it
.current_x
= this_line_start_x
;
7545 it
.current_y
= this_line_y
;
7546 it
.vpos
= this_line_vpos
;
7548 /* The call to move_it_to stops in front of PT, but
7549 moves over before-strings. */
7550 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
7552 if (it
.vpos
== this_line_vpos
7553 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
7556 xassert (this_line_vpos
== it
.vpos
);
7557 xassert (this_line_y
== it
.current_y
);
7558 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
7566 /* Text changed drastically or point moved off of line. */
7567 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
7570 CHARPOS (this_line_start_pos
) = 0;
7571 consider_all_windows_p
|= buffer_shared
> 1;
7572 ++clear_face_cache_count
;
7575 /* Build desired matrices. If consider_all_windows_p is non-zero,
7576 do it for all windows on all frames. Otherwise do it for
7577 selected_window, only. */
7579 if (consider_all_windows_p
)
7581 Lisp_Object tail
, frame
;
7583 /* Clear the face cache eventually. */
7584 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
7586 clear_face_cache (0);
7587 clear_face_cache_count
= 0;
7590 /* Recompute # windows showing selected buffer. This will be
7591 incremented each time such a window is displayed. */
7594 FOR_EACH_FRAME (tail
, frame
)
7596 struct frame
*f
= XFRAME (frame
);
7597 if (FRAME_WINDOW_P (f
) || f
== sf
)
7599 /* Mark all the scroll bars to be removed; we'll redeem
7600 the ones we want when we redisplay their windows. */
7601 if (condemn_scroll_bars_hook
)
7602 (*condemn_scroll_bars_hook
) (f
);
7604 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7605 redisplay_windows (FRAME_ROOT_WINDOW (f
));
7607 /* Any scroll bars which redisplay_windows should have
7608 nuked should now go away. */
7609 if (judge_scroll_bars_hook
)
7610 (*judge_scroll_bars_hook
) (f
);
7614 else if (FRAME_VISIBLE_P (sf
)
7615 && !FRAME_OBSCURED_P (sf
))
7616 redisplay_window (selected_window
, 1);
7619 /* Compare desired and current matrices, perform output. */
7623 /* If fonts changed, display again. */
7624 if (fonts_changed_p
)
7627 /* Prevent various kinds of signals during display update.
7628 stdio is not robust about handling signals,
7629 which can cause an apparent I/O error. */
7630 if (interrupt_input
)
7634 if (consider_all_windows_p
)
7643 /* See if we have to hscroll. */
7644 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7645 if (FRAMEP (XCAR (tail
)))
7647 f
= XFRAME (XCAR (tail
));
7649 if ((FRAME_WINDOW_P (f
)
7651 && FRAME_VISIBLE_P (f
)
7652 && !FRAME_OBSCURED_P (f
)
7653 && hscroll_windows (f
->root_window
))
7660 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7662 if (!FRAMEP (XCAR (tail
)))
7665 f
= XFRAME (XCAR (tail
));
7667 if ((FRAME_WINDOW_P (f
) || f
== sf
)
7668 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7670 /* Mark all windows as to be updated. */
7671 set_window_update_flags (XWINDOW (f
->root_window
), 1);
7672 pause
|= update_frame (f
, 0, 0);
7675 mark_window_display_accurate (f
->root_window
, 1);
7676 if (frame_up_to_date_hook
!= 0)
7677 (*frame_up_to_date_hook
) (f
);
7684 if (FRAME_VISIBLE_P (sf
)
7685 && !FRAME_OBSCURED_P (sf
))
7687 if (hscroll_windows (selected_window
))
7690 XWINDOW (selected_window
)->must_be_updated_p
= 1;
7691 pause
= update_frame (sf
, 0, 0);
7696 /* We may have called echo_area_display at the top of this
7697 function. If the echo area is on another frame, that may
7698 have put text on a frame other than the selected one, so the
7699 above call to update_frame would not have caught it. Catch
7702 Lisp_Object mini_window
;
7703 struct frame
*mini_frame
;
7705 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7706 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7708 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
7710 XWINDOW (mini_window
)->must_be_updated_p
= 1;
7711 pause
|= update_frame (mini_frame
, 0, 0);
7712 if (!pause
&& hscroll_windows (mini_window
))
7718 /* If display was paused because of pending input, make sure we do a
7719 thorough update the next time. */
7722 /* Prevent the optimization at the beginning of
7723 redisplay_internal that tries a single-line update of the
7724 line containing the cursor in the selected window. */
7725 CHARPOS (this_line_start_pos
) = 0;
7727 /* Let the overlay arrow be updated the next time. */
7728 if (!NILP (last_arrow_position
))
7730 last_arrow_position
= Qt
;
7731 last_arrow_string
= Qt
;
7734 /* If we pause after scrolling, some rows in the current
7735 matrices of some windows are not valid. */
7736 if (!WINDOW_FULL_WIDTH_P (w
)
7737 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
7738 update_mode_lines
= 1;
7741 /* Now text on frame agrees with windows, so put info into the
7742 windows for partial redisplay to follow. */
7745 register struct buffer
*b
= XBUFFER (w
->buffer
);
7747 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
7748 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
7749 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
7750 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
7752 if (consider_all_windows_p
)
7753 mark_window_display_accurate (FRAME_ROOT_WINDOW (sf
), 1);
7756 XSETFASTINT (w
->last_point
, BUF_PT (b
));
7757 w
->last_cursor
= w
->cursor
;
7758 w
->last_cursor_off_p
= w
->cursor_off_p
;
7760 b
->clip_changed
= 0;
7761 b
->prevent_redisplay_optimizations_p
= 0;
7762 w
->update_mode_line
= Qnil
;
7763 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
7764 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
7766 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7769 /* Record if we are showing a region, so can make sure to
7770 update it fully at next redisplay. */
7771 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
7772 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7773 || highlight_nonselected_windows
)
7774 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
7775 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
7778 w
->window_end_valid
= w
->buffer
;
7779 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7780 last_arrow_string
= Voverlay_arrow_string
;
7781 if (frame_up_to_date_hook
!= 0)
7782 (*frame_up_to_date_hook
) (sf
);
7784 w
->current_matrix
->buffer
= b
;
7785 w
->current_matrix
->begv
= BUF_BEGV (b
);
7786 w
->current_matrix
->zv
= BUF_ZV (b
);
7789 update_mode_lines
= 0;
7790 windows_or_buffers_changed
= 0;
7793 /* Start SIGIO interrupts coming again. Having them off during the
7794 code above makes it less likely one will discard output, but not
7795 impossible, since there might be stuff in the system buffer here.
7796 But it is much hairier to try to do anything about that. */
7797 if (interrupt_input
)
7801 /* If a frame has become visible which was not before, redisplay
7802 again, so that we display it. Expose events for such a frame
7803 (which it gets when becoming visible) don't call the parts of
7804 redisplay constructing glyphs, so simply exposing a frame won't
7805 display anything in this case. So, we have to display these
7806 frames here explicitly. */
7809 Lisp_Object tail
, frame
;
7812 FOR_EACH_FRAME (tail
, frame
)
7814 int this_is_visible
= 0;
7816 if (XFRAME (frame
)->visible
)
7817 this_is_visible
= 1;
7818 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
7819 if (XFRAME (frame
)->visible
)
7820 this_is_visible
= 1;
7822 if (this_is_visible
)
7826 if (new_count
!= number_of_visible_frames
)
7827 windows_or_buffers_changed
++;
7830 /* Change frame size now if a change is pending. */
7831 do_pending_window_change (1);
7833 /* If we just did a pending size change, or have additional
7834 visible frames, redisplay again. */
7835 if (windows_or_buffers_changed
&& !pause
)
7840 unbind_to (count
, Qnil
);
7844 /* Redisplay, but leave alone any recent echo area message unless
7845 another message has been requested in its place.
7847 This is useful in situations where you need to redisplay but no
7848 user action has occurred, making it inappropriate for the message
7849 area to be cleared. See tracking_off and
7850 wait_reading_process_input for examples of these situations. */
7853 redisplay_preserve_echo_area ()
7855 if (!NILP (echo_area_buffer
[1]))
7857 /* We have a previously displayed message, but no current
7858 message. Redisplay the previous message. */
7859 display_last_displayed_message_p
= 1;
7860 redisplay_internal (1);
7861 display_last_displayed_message_p
= 0;
7864 redisplay_internal (1);
7868 /* Function registered with record_unwind_protect in
7869 redisplay_internal. Clears the flag indicating that a redisplay is
7873 unwind_redisplay (old_redisplaying_p
)
7874 Lisp_Object old_redisplaying_p
;
7876 redisplaying_p
= XFASTINT (old_redisplaying_p
);
7881 /* Mark the display of windows in the window tree rooted at WINDOW as
7882 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
7883 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
7884 the next time redisplay_internal is called. */
7887 mark_window_display_accurate (window
, accurate_p
)
7893 for (; !NILP (window
); window
= w
->next
)
7895 w
= XWINDOW (window
);
7897 if (BUFFERP (w
->buffer
))
7899 struct buffer
*b
= XBUFFER (w
->buffer
);
7901 XSETFASTINT (w
->last_modified
,
7902 accurate_p
? BUF_MODIFF (b
) : 0);
7903 XSETFASTINT (w
->last_overlay_modified
,
7904 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
7905 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
7908 #if 0 /* I don't think this is necessary because display_line does it.
7910 /* Record if we are showing a region, so can make sure to
7911 update it fully at next redisplay. */
7913 = (!NILP (Vtransient_mark_mode
)
7914 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7915 || highlight_nonselected_windows
)
7916 && (!NILP (b
->mark_active
)
7917 ? Fmarker_position (b
->mark
)
7923 b
->clip_changed
= 0;
7924 b
->prevent_redisplay_optimizations_p
= 0;
7925 w
->current_matrix
->buffer
= b
;
7926 w
->current_matrix
->begv
= BUF_BEGV (b
);
7927 w
->current_matrix
->zv
= BUF_ZV (b
);
7928 w
->last_cursor
= w
->cursor
;
7929 w
->last_cursor_off_p
= w
->cursor_off_p
;
7930 if (w
== XWINDOW (selected_window
))
7931 w
->last_point
= make_number (BUF_PT (b
));
7933 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
7937 w
->window_end_valid
= w
->buffer
;
7938 w
->update_mode_line
= Qnil
;
7940 if (!NILP (w
->vchild
))
7941 mark_window_display_accurate (w
->vchild
, accurate_p
);
7942 if (!NILP (w
->hchild
))
7943 mark_window_display_accurate (w
->hchild
, accurate_p
);
7948 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7949 last_arrow_string
= Voverlay_arrow_string
;
7953 /* Force a thorough redisplay the next time by setting
7954 last_arrow_position and last_arrow_string to t, which is
7955 unequal to any useful value of Voverlay_arrow_... */
7956 last_arrow_position
= Qt
;
7957 last_arrow_string
= Qt
;
7962 /* Return value in display table DP (Lisp_Char_Table *) for character
7963 C. Since a display table doesn't have any parent, we don't have to
7964 follow parent. Do not call this function directly but use the
7965 macro DISP_CHAR_VECTOR. */
7968 disp_char_vector (dp
, c
)
7969 struct Lisp_Char_Table
*dp
;
7975 if (SINGLE_BYTE_CHAR_P (c
))
7976 return (dp
->contents
[c
]);
7978 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
7981 else if (code
[2] < 32)
7984 /* Here, the possible range of code[0] (== charset ID) is
7985 128..max_charset. Since the top level char table contains data
7986 for multibyte characters after 256th element, we must increment
7987 code[0] by 128 to get a correct index. */
7989 code
[3] = -1; /* anchor */
7991 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
7993 val
= dp
->contents
[code
[i
]];
7994 if (!SUB_CHAR_TABLE_P (val
))
7995 return (NILP (val
) ? dp
->defalt
: val
);
7998 /* Here, val is a sub char table. We return the default value of
8000 return (dp
->defalt
);
8005 /***********************************************************************
8007 ***********************************************************************/
8009 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
8012 redisplay_windows (window
)
8015 while (!NILP (window
))
8017 struct window
*w
= XWINDOW (window
);
8019 if (!NILP (w
->hchild
))
8020 redisplay_windows (w
->hchild
);
8021 else if (!NILP (w
->vchild
))
8022 redisplay_windows (w
->vchild
);
8024 redisplay_window (window
, 0);
8031 /* Set cursor position of W. PT is assumed to be displayed in ROW.
8032 DELTA is the number of bytes by which positions recorded in ROW
8033 differ from current buffer positions. */
8036 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
8038 struct glyph_row
*row
;
8039 struct glyph_matrix
*matrix
;
8040 int delta
, delta_bytes
, dy
, dvpos
;
8042 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
8043 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
8045 int pt_old
= PT
- delta
;
8047 /* Skip over glyphs not having an object at the start of the row.
8048 These are special glyphs like truncation marks on terminal
8050 if (row
->displays_text_p
)
8052 && INTEGERP (glyph
->object
)
8053 && glyph
->charpos
< 0)
8055 x
+= glyph
->pixel_width
;
8060 && !INTEGERP (glyph
->object
)
8061 && (!BUFFERP (glyph
->object
)
8062 || glyph
->charpos
< pt_old
))
8064 x
+= glyph
->pixel_width
;
8068 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
8070 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
8071 w
->cursor
.y
= row
->y
+ dy
;
8073 if (w
== XWINDOW (selected_window
))
8075 if (!row
->continued_p
8076 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
8079 this_line_buffer
= XBUFFER (w
->buffer
);
8081 CHARPOS (this_line_start_pos
)
8082 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
8083 BYTEPOS (this_line_start_pos
)
8084 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
8086 CHARPOS (this_line_end_pos
)
8087 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
8088 BYTEPOS (this_line_end_pos
)
8089 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
8091 this_line_y
= w
->cursor
.y
;
8092 this_line_pixel_height
= row
->height
;
8093 this_line_vpos
= w
->cursor
.vpos
;
8094 this_line_start_x
= row
->x
;
8097 CHARPOS (this_line_start_pos
) = 0;
8102 /* Run window scroll functions, if any, for WINDOW with new window
8103 start STARTP. Sets the window start of WINDOW to that position.
8105 We assume that the window's buffer is really current. */
8107 static INLINE
struct text_pos
8108 run_window_scroll_functions (window
, startp
)
8110 struct text_pos startp
;
8112 struct window
*w
= XWINDOW (window
);
8113 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
8115 if (current_buffer
!= XBUFFER (w
->buffer
))
8118 if (!NILP (Vwindow_scroll_functions
))
8120 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
8121 make_number (CHARPOS (startp
)));
8122 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8123 /* In case the hook functions switch buffers. */
8124 if (current_buffer
!= XBUFFER (w
->buffer
))
8125 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8132 /* Modify the desired matrix of window W and W->vscroll so that the
8133 line containing the cursor is fully visible. */
8136 make_cursor_line_fully_visible (w
)
8139 struct glyph_matrix
*matrix
;
8140 struct glyph_row
*row
;
8141 int header_line_height
;
8143 /* It's not always possible to find the cursor, e.g, when a window
8144 is full of overlay strings. Don't do anything in that case. */
8145 if (w
->cursor
.vpos
< 0)
8148 matrix
= w
->desired_matrix
;
8149 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
8151 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
)
8152 /* The row may be partially visible at the top because we
8153 already have chosen a vscroll to align the bottom of the
8154 row with the bottom of the window. This happens for rows
8155 taller than the window. */
8156 && row
->y
+ row
->height
< window_box_height (w
))
8158 int dy
= row
->height
- row
->visible_height
;
8161 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8163 else if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w
, row
)
8164 /* The row may be partially visible at the bottom because
8165 we chose a vscroll to align the row's top with the
8166 window's top. This happens for rows taller than the
8168 && row
->y
> WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
))
8170 int dy
= - (row
->height
- row
->visible_height
);
8173 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8176 /* When we change the cursor y-position of the selected window,
8177 change this_line_y as well so that the display optimization for
8178 the cursor line of the selected window in redisplay_internal uses
8179 the correct y-position. */
8180 if (w
== XWINDOW (selected_window
))
8181 this_line_y
= w
->cursor
.y
;
8185 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
8186 non-zero means only WINDOW is redisplayed in redisplay_internal.
8187 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
8188 in redisplay_window to bring a partially visible line into view in
8189 the case that only the cursor has moved.
8193 1 if scrolling succeeded
8195 0 if scrolling didn't find point.
8197 -1 if new fonts have been loaded so that we must interrupt
8198 redisplay, adjust glyph matrices, and try again. */
8201 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
8202 scroll_step
, temp_scroll_step
)
8204 int just_this_one_p
;
8205 int scroll_conservatively
, scroll_step
;
8206 int temp_scroll_step
;
8208 struct window
*w
= XWINDOW (window
);
8209 struct frame
*f
= XFRAME (w
->frame
);
8210 struct text_pos scroll_margin_pos
;
8211 struct text_pos pos
;
8212 struct text_pos startp
;
8214 Lisp_Object window_end
;
8215 int this_scroll_margin
;
8218 int line_height
, rc
;
8219 int amount_to_scroll
= 0;
8220 Lisp_Object aggressive
;
8224 debug_method_add (w
, "try_scrolling");
8227 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8229 /* Compute scroll margin height in pixels. We scroll when point is
8230 within this distance from the top or bottom of the window. */
8231 if (scroll_margin
> 0)
8233 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
8234 this_scroll_margin
*= CANON_Y_UNIT (f
);
8237 this_scroll_margin
= 0;
8239 /* Compute how much we should try to scroll maximally to bring point
8242 scroll_max
= scroll_step
;
8243 else if (scroll_conservatively
)
8244 scroll_max
= scroll_conservatively
;
8245 else if (temp_scroll_step
)
8246 scroll_max
= temp_scroll_step
;
8247 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
8248 || NUMBERP (current_buffer
->scroll_up_aggressively
))
8249 /* We're trying to scroll because of aggressive scrolling
8250 but no scroll_step is set. Choose an arbitrary one. Maybe
8251 there should be a variable for this. */
8255 scroll_max
*= CANON_Y_UNIT (f
);
8257 /* Decide whether we have to scroll down. Start at the window end
8258 and move this_scroll_margin up to find the position of the scroll
8260 window_end
= Fwindow_end (window
, Qt
);
8261 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
8262 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
8263 if (this_scroll_margin
)
8265 start_display (&it
, w
, scroll_margin_pos
);
8266 move_it_vertically (&it
, - this_scroll_margin
);
8267 scroll_margin_pos
= it
.current
.pos
;
8270 if (PT
>= CHARPOS (scroll_margin_pos
))
8274 /* Point is in the scroll margin at the bottom of the window, or
8275 below. Compute a new window start that makes point visible. */
8277 /* Compute the distance from the scroll margin to PT.
8278 Give up if the distance is greater than scroll_max. */
8279 start_display (&it
, w
, scroll_margin_pos
);
8281 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8282 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8283 line_height
= (it
.max_ascent
+ it
.max_descent
8284 ? it
.max_ascent
+ it
.max_descent
8286 dy
= it
.current_y
+ line_height
- y0
;
8287 if (dy
> scroll_max
)
8290 /* Move the window start down. If scrolling conservatively,
8291 move it just enough down to make point visible. If
8292 scroll_step is set, move it down by scroll_step. */
8293 start_display (&it
, w
, startp
);
8295 if (scroll_conservatively
)
8296 amount_to_scroll
= dy
;
8297 else if (scroll_step
|| temp_scroll_step
)
8298 amount_to_scroll
= scroll_max
;
8301 aggressive
= current_buffer
->scroll_down_aggressively
;
8302 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8303 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8304 if (NUMBERP (aggressive
))
8305 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8308 if (amount_to_scroll
<= 0)
8311 move_it_vertically (&it
, amount_to_scroll
);
8312 startp
= it
.current
.pos
;
8316 /* See if point is inside the scroll margin at the top of the
8318 scroll_margin_pos
= startp
;
8319 if (this_scroll_margin
)
8321 start_display (&it
, w
, startp
);
8322 move_it_vertically (&it
, this_scroll_margin
);
8323 scroll_margin_pos
= it
.current
.pos
;
8326 if (PT
< CHARPOS (scroll_margin_pos
))
8328 /* Point is in the scroll margin at the top of the window or
8329 above what is displayed in the window. */
8332 /* Compute the vertical distance from PT to the scroll
8333 margin position. Give up if distance is greater than
8335 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
8336 start_display (&it
, w
, pos
);
8338 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
8339 it
.last_visible_y
, -1,
8340 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8341 dy
= it
.current_y
- y0
;
8342 if (dy
> scroll_max
)
8345 /* Compute new window start. */
8346 start_display (&it
, w
, startp
);
8348 if (scroll_conservatively
)
8349 amount_to_scroll
= dy
;
8350 else if (scroll_step
|| temp_scroll_step
)
8351 amount_to_scroll
= scroll_max
;
8354 aggressive
= current_buffer
->scroll_up_aggressively
;
8355 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8356 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8357 if (NUMBERP (aggressive
))
8358 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8361 if (amount_to_scroll
<= 0)
8364 move_it_vertically (&it
, - amount_to_scroll
);
8365 startp
= it
.current
.pos
;
8369 /* Run window scroll functions. */
8370 startp
= run_window_scroll_functions (window
, startp
);
8372 /* Display the window. Give up if new fonts are loaded, or if point
8374 if (!try_window (window
, startp
))
8376 else if (w
->cursor
.vpos
< 0)
8378 clear_glyph_matrix (w
->desired_matrix
);
8383 /* Maybe forget recorded base line for line number display. */
8384 if (!just_this_one_p
8385 || current_buffer
->clip_changed
8386 || BEG_UNCHANGED
< CHARPOS (startp
))
8387 w
->base_line_number
= Qnil
;
8389 /* If cursor ends up on a partially visible line, shift display
8390 lines up or down. */
8391 make_cursor_line_fully_visible (w
);
8399 /* Compute a suitable window start for window W if display of W starts
8400 on a continuation line. Value is non-zero if a new window start
8403 The new window start will be computed, based on W's width, starting
8404 from the start of the continued line. It is the start of the
8405 screen line with the minimum distance from the old start W->start. */
8408 compute_window_start_on_continuation_line (w
)
8411 struct text_pos pos
, start_pos
;
8412 int window_start_changed_p
= 0;
8414 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
8416 /* If window start is on a continuation line... Window start may be
8417 < BEGV in case there's invisible text at the start of the
8418 buffer (M-x rmail, for example). */
8419 if (CHARPOS (start_pos
) > BEGV
8420 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
8423 struct glyph_row
*row
;
8425 /* Handle the case that the window start is out of range. */
8426 if (CHARPOS (start_pos
) < BEGV
)
8427 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
8428 else if (CHARPOS (start_pos
) > ZV
)
8429 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
8431 /* Find the start of the continued line. This should be fast
8432 because scan_buffer is fast (newline cache). */
8433 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
8434 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
8435 row
, DEFAULT_FACE_ID
);
8436 reseat_at_previous_visible_line_start (&it
);
8438 /* If the line start is "too far" away from the window start,
8439 say it takes too much time to compute a new window start. */
8440 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
8441 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
8443 int min_distance
, distance
;
8445 /* Move forward by display lines to find the new window
8446 start. If window width was enlarged, the new start can
8447 be expected to be > the old start. If window width was
8448 decreased, the new window start will be < the old start.
8449 So, we're looking for the display line start with the
8450 minimum distance from the old window start. */
8451 pos
= it
.current
.pos
;
8452 min_distance
= INFINITY
;
8453 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
8454 distance
< min_distance
)
8456 min_distance
= distance
;
8457 pos
= it
.current
.pos
;
8458 move_it_by_lines (&it
, 1, 0);
8461 /* Set the window start there. */
8462 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
8463 window_start_changed_p
= 1;
8467 return window_start_changed_p
;
8471 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
8472 selected_window is redisplayed. */
8475 redisplay_window (window
, just_this_one_p
)
8477 int just_this_one_p
;
8479 struct window
*w
= XWINDOW (window
);
8480 struct frame
*f
= XFRAME (w
->frame
);
8481 struct buffer
*buffer
= XBUFFER (w
->buffer
);
8482 struct buffer
*old
= current_buffer
;
8483 struct text_pos lpoint
, opoint
, startp
;
8484 int update_mode_line
;
8487 /* Record it now because it's overwritten. */
8488 int current_matrix_up_to_date_p
= 0;
8489 int really_switched_buffer
= 0;
8490 int temp_scroll_step
= 0;
8491 int count
= specpdl_ptr
- specpdl
;
8493 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8496 /* W must be a leaf window here. */
8497 xassert (!NILP (w
->buffer
));
8499 *w
->desired_matrix
->method
= 0;
8502 specbind (Qinhibit_point_motion_hooks
, Qt
);
8504 reconsider_clip_changes (w
, buffer
);
8506 /* Has the mode line to be updated? */
8507 update_mode_line
= (!NILP (w
->update_mode_line
)
8508 || update_mode_lines
8509 || buffer
->clip_changed
);
8511 if (MINI_WINDOW_P (w
))
8513 if (w
== XWINDOW (echo_area_window
)
8514 && !NILP (echo_area_buffer
[0]))
8516 if (update_mode_line
)
8517 /* We may have to update a tty frame's menu bar or a
8518 tool-bar. Example `M-x C-h C-h C-g'. */
8519 goto finish_menu_bars
;
8521 /* We've already displayed the echo area glyphs in this window. */
8522 goto finish_scroll_bars
;
8524 else if (w
!= XWINDOW (minibuf_window
))
8526 /* W is a mini-buffer window, but it's not the currently
8527 active one, so clear it. */
8528 int yb
= window_text_bottom_y (w
);
8529 struct glyph_row
*row
;
8532 for (y
= 0, row
= w
->desired_matrix
->rows
;
8534 y
+= row
->height
, ++row
)
8535 blank_row (w
, row
, y
);
8536 goto finish_scroll_bars
;
8540 /* Otherwise set up data on this window; select its buffer and point
8542 if (update_mode_line
)
8544 /* Really select the buffer, for the sake of buffer-local
8546 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8547 really_switched_buffer
= 1;
8550 set_buffer_temp (XBUFFER (w
->buffer
));
8551 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
8553 current_matrix_up_to_date_p
8554 = (!NILP (w
->window_end_valid
)
8555 && !current_buffer
->clip_changed
8556 && XFASTINT (w
->last_modified
) >= MODIFF
8557 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
8559 /* When windows_or_buffers_changed is non-zero, we can't rely on
8560 the window end being valid, so set it to nil there. */
8561 if (windows_or_buffers_changed
)
8563 /* If window starts on a continuation line, maybe adjust the
8564 window start in case the window's width changed. */
8565 if (XMARKER (w
->start
)->buffer
== current_buffer
)
8566 compute_window_start_on_continuation_line (w
);
8568 w
->window_end_valid
= Qnil
;
8571 /* Some sanity checks. */
8572 CHECK_WINDOW_END (w
);
8573 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
8575 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
8578 /* If %c is in mode line, update it if needed. */
8579 if (!NILP (w
->column_number_displayed
)
8580 /* This alternative quickly identifies a common case
8581 where no change is needed. */
8582 && !(PT
== XFASTINT (w
->last_point
)
8583 && XFASTINT (w
->last_modified
) >= MODIFF
8584 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8585 && XFASTINT (w
->column_number_displayed
) != current_column ())
8586 update_mode_line
= 1;
8588 /* Count number of windows showing the selected buffer. An indirect
8589 buffer counts as its base buffer. */
8590 if (!just_this_one_p
)
8592 struct buffer
*current_base
, *window_base
;
8593 current_base
= current_buffer
;
8594 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
8595 if (current_base
->base_buffer
)
8596 current_base
= current_base
->base_buffer
;
8597 if (window_base
->base_buffer
)
8598 window_base
= window_base
->base_buffer
;
8599 if (current_base
== window_base
)
8603 /* Point refers normally to the selected window. For any other
8604 window, set up appropriate value. */
8605 if (!EQ (window
, selected_window
))
8607 int new_pt
= XMARKER (w
->pointm
)->charpos
;
8608 int new_pt_byte
= marker_byte_position (w
->pointm
);
8612 new_pt_byte
= BEGV_BYTE
;
8613 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
8615 else if (new_pt
> (ZV
- 1))
8618 new_pt_byte
= ZV_BYTE
;
8619 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
8622 /* We don't use SET_PT so that the point-motion hooks don't run. */
8623 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
8626 /* If any of the character widths specified in the display table
8627 have changed, invalidate the width run cache. It's true that
8628 this may be a bit late to catch such changes, but the rest of
8629 redisplay goes (non-fatally) haywire when the display table is
8630 changed, so why should we worry about doing any better? */
8631 if (current_buffer
->width_run_cache
)
8633 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
8635 if (! disptab_matches_widthtab (disptab
,
8636 XVECTOR (current_buffer
->width_table
)))
8638 invalidate_region_cache (current_buffer
,
8639 current_buffer
->width_run_cache
,
8641 recompute_width_table (current_buffer
, disptab
);
8645 /* If window-start is screwed up, choose a new one. */
8646 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
8649 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8651 /* If someone specified a new starting point but did not insist,
8652 check whether it can be used. */
8653 if (!NILP (w
->optional_new_start
)
8654 && CHARPOS (startp
) >= BEGV
8655 && CHARPOS (startp
) <= ZV
)
8657 w
->optional_new_start
= Qnil
;
8658 /* This takes a mini-buffer prompt into account. */
8659 start_display (&it
, w
, startp
);
8660 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8661 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8662 if (IT_CHARPOS (it
) == PT
)
8663 w
->force_start
= Qt
;
8666 /* Handle case where place to start displaying has been specified,
8667 unless the specified location is outside the accessible range. */
8668 if (!NILP (w
->force_start
)
8669 || w
->frozen_window_start_p
)
8671 w
->force_start
= Qnil
;
8673 w
->window_end_valid
= Qnil
;
8675 /* Forget any recorded base line for line number display. */
8676 if (!current_matrix_up_to_date_p
8677 || current_buffer
->clip_changed
)
8678 w
->base_line_number
= Qnil
;
8680 /* Redisplay the mode line. Select the buffer properly for that.
8681 Also, run the hook window-scroll-functions
8682 because we have scrolled. */
8683 /* Note, we do this after clearing force_start because
8684 if there's an error, it is better to forget about force_start
8685 than to get into an infinite loop calling the hook functions
8686 and having them get more errors. */
8687 if (!update_mode_line
8688 || ! NILP (Vwindow_scroll_functions
))
8690 if (!really_switched_buffer
)
8692 set_buffer_temp (old
);
8693 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8694 really_switched_buffer
= 1;
8697 update_mode_line
= 1;
8698 w
->update_mode_line
= Qt
;
8699 startp
= run_window_scroll_functions (window
, startp
);
8702 XSETFASTINT (w
->last_modified
, 0);
8703 XSETFASTINT (w
->last_overlay_modified
, 0);
8704 if (CHARPOS (startp
) < BEGV
)
8705 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
8706 else if (CHARPOS (startp
) > ZV
)
8707 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
8709 /* Redisplay, then check if cursor has been set during the
8710 redisplay. Give up if new fonts were loaded. */
8711 if (!try_window (window
, startp
))
8713 w
->force_start
= Qt
;
8714 clear_glyph_matrix (w
->desired_matrix
);
8715 goto restore_buffers
;
8718 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
8720 /* If point does not appear, or on a line that is not fully
8721 visible, move point so it does appear. The desired
8722 matrix has been built above, so we can use it. */
8723 int height
= window_box_height (w
) / 2;
8724 struct glyph_row
*row
= MATRIX_ROW (w
->desired_matrix
, 0);
8726 while (row
->y
< height
)
8729 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
8730 MATRIX_ROW_START_BYTEPOS (row
));
8732 if (w
!= XWINDOW (selected_window
))
8733 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
8734 else if (current_buffer
== old
)
8735 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8737 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
8739 /* If we are highlighting the region, then we just changed
8740 the region, so redisplay to show it. */
8741 if (!NILP (Vtransient_mark_mode
)
8742 && !NILP (current_buffer
->mark_active
))
8744 clear_glyph_matrix (w
->desired_matrix
);
8745 if (!try_window (window
, startp
))
8746 goto restore_buffers
;
8750 make_cursor_line_fully_visible (w
);
8752 debug_method_add (w
, "forced window start");
8757 /* Handle case where text has not changed, only point, and it has
8758 not moved off the frame. */
8759 if (current_matrix_up_to_date_p
8760 /* Point may be in this window. */
8761 && PT
>= CHARPOS (startp
)
8762 /* If we don't check this, we are called to move the cursor in a
8763 horizontally split window with a current matrix that doesn't
8765 && !windows_or_buffers_changed
8766 /* Selective display hasn't changed. */
8767 && !current_buffer
->clip_changed
8768 /* If force-mode-line-update was called, really redisplay;
8769 that's how redisplay is forced after e.g. changing
8770 buffer-invisibility-spec. */
8771 && NILP (w
->update_mode_line
)
8772 /* Can't use this case if highlighting a region. When a
8773 region exists, cursor movement has to do more than just
8775 && !(!NILP (Vtransient_mark_mode
)
8776 && !NILP (current_buffer
->mark_active
))
8777 && NILP (w
->region_showing
)
8778 && NILP (Vshow_trailing_whitespace
)
8779 /* Right after splitting windows, last_point may be nil. */
8780 && INTEGERP (w
->last_point
)
8781 /* This code is not used for mini-buffer for the sake of the case
8782 of redisplaying to replace an echo area message; since in
8783 that case the mini-buffer contents per se are usually
8784 unchanged. This code is of no real use in the mini-buffer
8785 since the handling of this_line_start_pos, etc., in redisplay
8786 handles the same cases. */
8787 && !EQ (window
, minibuf_window
)
8788 /* When splitting windows or for new windows, it happens that
8789 redisplay is called with a nil window_end_vpos or one being
8790 larger than the window. This should really be fixed in
8791 window.c. I don't have this on my list, now, so we do
8792 approximately the same as the old redisplay code. --gerd. */
8793 && INTEGERP (w
->window_end_vpos
)
8794 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
8795 && (FRAME_WINDOW_P (f
)
8796 || !MARKERP (Voverlay_arrow_position
)
8797 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
8799 int this_scroll_margin
;
8800 struct glyph_row
*row
;
8804 debug_method_add (w
, "cursor movement");
8807 /* Scroll if point within this distance from the top or bottom
8808 of the window. This is a pixel value. */
8809 this_scroll_margin
= max (0, scroll_margin
);
8810 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
8811 this_scroll_margin
*= CANON_Y_UNIT (f
);
8813 /* Start with the row the cursor was displayed during the last
8814 not paused redisplay. Give up if that row is not valid. */
8815 if (w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
8817 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
8818 if (row
->mode_line_p
)
8820 if (!row
->enabled_p
)
8824 if (PT
> XFASTINT (w
->last_point
))
8826 /* Point has moved forward. */
8827 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
8829 while ((MATRIX_ROW_END_CHARPOS (row
) < PT
8830 /* The end position of a row equals the start
8831 position of the next row. If PT is there, we
8832 would rather display it in the next line, except
8833 when this line ends in ZV. */
8834 || (MATRIX_ROW_END_CHARPOS (row
) == PT
8835 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
8836 || !row
->ends_at_zv_p
)))
8837 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
8839 xassert (row
->enabled_p
);
8843 /* If within the scroll margin, scroll. Note that
8844 MATRIX_ROW_BOTTOM_Y gives the pixel position at which the
8845 next line would be drawn, and that this_scroll_margin can
8847 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
8848 || PT
> MATRIX_ROW_END_CHARPOS (row
)
8849 /* Line is completely visible last line in window and PT
8850 is to be set in the next line. */
8851 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
8852 && PT
== MATRIX_ROW_END_CHARPOS (row
)
8853 && !row
->ends_at_zv_p
8854 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
8857 else if (PT
< XFASTINT (w
->last_point
))
8859 /* Cursor has to be moved backward. Note that PT >=
8860 CHARPOS (startp) because of the outer if-statement. */
8861 while (!row
->mode_line_p
8862 && (MATRIX_ROW_START_CHARPOS (row
) > PT
8863 || (MATRIX_ROW_START_CHARPOS (row
) == PT
8864 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
8865 && (row
->y
> this_scroll_margin
8866 || CHARPOS (startp
) == BEGV
))
8868 xassert (row
->enabled_p
);
8872 /* Consider the following case: Window starts at BEGV, there
8873 is invisible, intangible text at BEGV, so that display
8874 starts at some point START > BEGV. It can happen that
8875 we are called with PT somewhere between BEGV and START.
8876 Try to handle that case. */
8877 if (row
< w
->current_matrix
->rows
8878 || row
->mode_line_p
)
8880 row
= w
->current_matrix
->rows
;
8881 if (row
->mode_line_p
)
8885 /* Due to newlines in overlay strings, we may have to skip
8886 forward over overlay strings. */
8887 while (MATRIX_ROW_END_CHARPOS (row
) == PT
8888 && MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P (row
)
8889 && !row
->ends_at_zv_p
)
8892 /* If within the scroll margin, scroll. */
8893 if (row
->y
< this_scroll_margin
8894 && CHARPOS (startp
) != BEGV
)
8898 /* if PT is not in the glyph row, give up. */
8899 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
8900 || PT
> MATRIX_ROW_END_CHARPOS (row
))
8903 /* If we end up in a partially visible line, let's make it fully
8904 visible. This can be done most easily by using the existing
8906 if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8908 temp_scroll_step
= 1;
8914 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8918 /* If current starting point was originally the beginning of a line
8919 but no longer is, find a new starting point. */
8920 else if (!NILP (w
->start_at_line_beg
)
8921 && !(CHARPOS (startp
) <= BEGV
8922 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
8925 debug_method_add (w
, "recenter 1");
8930 /* Try scrolling with try_window_id. */
8931 else if (/* Windows and buffers haven't changed. */
8932 !windows_or_buffers_changed
8933 /* Window must be either use window-based redisplay or
8935 && (FRAME_WINDOW_P (f
)
8936 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
8937 && !MINI_WINDOW_P (w
)
8938 /* Point is not known NOT to appear in window. */
8939 && PT
>= CHARPOS (startp
)
8940 && XFASTINT (w
->last_modified
)
8941 /* Window is not hscrolled. */
8942 && XFASTINT (w
->hscroll
) == 0
8943 /* Selective display has not changed. */
8944 && !current_buffer
->clip_changed
8945 /* Current matrix is up to date. */
8946 && !NILP (w
->window_end_valid
)
8947 /* Can't use this case if highlighting a region because
8948 a cursor movement will do more than just set the cursor. */
8949 && !(!NILP (Vtransient_mark_mode
)
8950 && !NILP (current_buffer
->mark_active
))
8951 && NILP (w
->region_showing
)
8952 && NILP (Vshow_trailing_whitespace
)
8953 /* Overlay arrow position and string not changed. */
8954 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
8955 && EQ (last_arrow_string
, Voverlay_arrow_string
)
8956 /* Value is > 0 if update has been done, it is -1 if we
8957 know that the same window start will not work. It is 0
8958 if unsuccessful for some other reason. */
8959 && (tem
= try_window_id (w
)) != 0)
8962 debug_method_add (w
, "try_window_id");
8965 if (fonts_changed_p
)
8966 goto restore_buffers
;
8969 /* Otherwise try_window_id has returned -1 which means that we
8970 don't want the alternative below this comment to execute. */
8972 else if (CHARPOS (startp
) >= BEGV
8973 && CHARPOS (startp
) <= ZV
8974 && PT
>= CHARPOS (startp
)
8975 && (CHARPOS (startp
) < ZV
8976 /* Avoid starting at end of buffer. */
8977 || CHARPOS (startp
) == BEGV
8978 || (XFASTINT (w
->last_modified
) >= MODIFF
8979 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
8982 debug_method_add (w
, "same window start");
8985 /* Try to redisplay starting at same place as before.
8986 If point has not moved off frame, accept the results. */
8987 if (!current_matrix_up_to_date_p
8988 /* Don't use try_window_reusing_current_matrix in this case
8989 because a window scroll function can have changed the
8991 || !NILP (Vwindow_scroll_functions
)
8992 || MINI_WINDOW_P (w
)
8993 || !try_window_reusing_current_matrix (w
))
8995 IF_DEBUG (debug_method_add (w
, "1"));
8996 try_window (window
, startp
);
8999 if (fonts_changed_p
)
9000 goto restore_buffers
;
9002 if (w
->cursor
.vpos
>= 0)
9004 if (!just_this_one_p
9005 || current_buffer
->clip_changed
9006 || BEG_UNCHANGED
< CHARPOS (startp
))
9007 /* Forget any recorded base line for line number display. */
9008 w
->base_line_number
= Qnil
;
9010 make_cursor_line_fully_visible (w
);
9014 clear_glyph_matrix (w
->desired_matrix
);
9019 XSETFASTINT (w
->last_modified
, 0);
9020 XSETFASTINT (w
->last_overlay_modified
, 0);
9022 /* Redisplay the mode line. Select the buffer properly for that. */
9023 if (!update_mode_line
)
9025 if (!really_switched_buffer
)
9027 set_buffer_temp (old
);
9028 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9029 really_switched_buffer
= 1;
9031 update_mode_line
= 1;
9032 w
->update_mode_line
= Qt
;
9035 /* Try to scroll by specified few lines. */
9036 if ((scroll_conservatively
9039 || NUMBERP (current_buffer
->scroll_up_aggressively
)
9040 || NUMBERP (current_buffer
->scroll_down_aggressively
))
9041 && !current_buffer
->clip_changed
9042 && CHARPOS (startp
) >= BEGV
9043 && CHARPOS (startp
) <= ZV
)
9045 /* The function returns -1 if new fonts were loaded, 1 if
9046 successful, 0 if not successful. */
9047 int rc
= try_scrolling (window
, just_this_one_p
,
9048 scroll_conservatively
,
9054 goto restore_buffers
;
9057 /* Finally, just choose place to start which centers point */
9062 debug_method_add (w
, "recenter");
9065 /* w->vscroll = 0; */
9067 /* Forget any previously recorded base line for line number display. */
9068 if (!current_matrix_up_to_date_p
9069 || current_buffer
->clip_changed
)
9070 w
->base_line_number
= Qnil
;
9072 /* Move backward half the height of the window. */
9073 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9074 it
.current_y
= it
.last_visible_y
;
9075 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
9076 xassert (IT_CHARPOS (it
) >= BEGV
);
9078 /* The function move_it_vertically_backward may move over more
9079 than the specified y-distance. If it->w is small, e.g. a
9080 mini-buffer window, we may end up in front of the window's
9081 display area. Start displaying at the start of the line
9082 containing PT in this case. */
9083 if (it
.current_y
<= 0)
9085 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9086 move_it_vertically (&it
, 0);
9087 xassert (IT_CHARPOS (it
) <= PT
);
9091 it
.current_x
= it
.hpos
= 0;
9093 /* Set startp here explicitly in case that helps avoid an infinite loop
9094 in case the window-scroll-functions functions get errors. */
9095 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
9097 /* Run scroll hooks. */
9098 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
9100 /* Redisplay the window. */
9101 if (!current_matrix_up_to_date_p
9102 || windows_or_buffers_changed
9103 /* Don't use try_window_reusing_current_matrix in this case
9104 because it can have changed the buffer. */
9105 || !NILP (Vwindow_scroll_functions
)
9107 || MINI_WINDOW_P (w
)
9108 || !try_window_reusing_current_matrix (w
))
9109 try_window (window
, startp
);
9111 /* If new fonts have been loaded (due to fontsets), give up. We
9112 have to start a new redisplay since we need to re-adjust glyph
9114 if (fonts_changed_p
)
9115 goto restore_buffers
;
9117 /* If cursor did not appear assume that the middle of the window is
9118 in the first line of the window. Do it again with the next line.
9119 (Imagine a window of height 100, displaying two lines of height
9120 60. Moving back 50 from it->last_visible_y will end in the first
9122 if (w
->cursor
.vpos
< 0)
9124 if (!NILP (w
->window_end_valid
)
9125 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
9127 clear_glyph_matrix (w
->desired_matrix
);
9128 move_it_by_lines (&it
, 1, 0);
9129 try_window (window
, it
.current
.pos
);
9131 else if (PT
< IT_CHARPOS (it
))
9133 clear_glyph_matrix (w
->desired_matrix
);
9134 move_it_by_lines (&it
, -1, 0);
9135 try_window (window
, it
.current
.pos
);
9139 /* Not much we can do about it. */
9143 /* Consider the following case: Window starts at BEGV, there is
9144 invisible, intangible text at BEGV, so that display starts at
9145 some point START > BEGV. It can happen that we are called with
9146 PT somewhere between BEGV and START. Try to handle that case. */
9147 if (w
->cursor
.vpos
< 0)
9149 struct glyph_row
*row
= w
->current_matrix
->rows
;
9150 if (row
->mode_line_p
)
9152 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9155 make_cursor_line_fully_visible (w
);
9159 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9160 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
9161 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
9164 /* Display the mode line, if we must. */
9165 if ((update_mode_line
9166 /* If window not full width, must redo its mode line
9167 if (a) the window to its side is being redone and
9168 (b) we do a frame-based redisplay. This is a consequence
9169 of how inverted lines are drawn in frame-based redisplay. */
9170 || (!just_this_one_p
9171 && !FRAME_WINDOW_P (f
)
9172 && !WINDOW_FULL_WIDTH_P (w
))
9173 /* Line number to display. */
9174 || INTEGERP (w
->base_line_pos
)
9175 /* Column number is displayed and different from the one displayed. */
9176 || (!NILP (w
->column_number_displayed
)
9177 && XFASTINT (w
->column_number_displayed
) != current_column ()))
9178 /* This means that the window has a mode line. */
9179 && (WINDOW_WANTS_MODELINE_P (w
)
9180 || WINDOW_WANTS_HEADER_LINE_P (w
)))
9182 display_mode_lines (w
);
9184 /* If mode line height has changed, arrange for a thorough
9185 immediate redisplay using the correct mode line height. */
9186 if (WINDOW_WANTS_MODELINE_P (w
)
9187 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
9189 fonts_changed_p
= 1;
9190 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
9191 = DESIRED_MODE_LINE_HEIGHT (w
);
9194 /* If top line height has changed, arrange for a thorough
9195 immediate redisplay using the correct mode line height. */
9196 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9197 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
9199 fonts_changed_p
= 1;
9200 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
9201 = DESIRED_HEADER_LINE_HEIGHT (w
);
9204 if (fonts_changed_p
)
9205 goto restore_buffers
;
9208 if (!line_number_displayed
9209 && !BUFFERP (w
->base_line_pos
))
9211 w
->base_line_pos
= Qnil
;
9212 w
->base_line_number
= Qnil
;
9217 /* When we reach a frame's selected window, redo the frame's menu bar. */
9218 if (update_mode_line
9219 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
9221 int redisplay_menu_p
= 0;
9223 if (FRAME_WINDOW_P (f
))
9225 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
9226 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
9228 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9232 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9234 if (redisplay_menu_p
)
9235 display_menu_bar (w
);
9237 #ifdef HAVE_WINDOW_SYSTEM
9238 if (WINDOWP (f
->tool_bar_window
)
9239 && (FRAME_TOOL_BAR_LINES (f
) > 0
9240 || auto_resize_tool_bars_p
))
9241 redisplay_tool_bar (f
);
9247 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9249 int start
, end
, whole
;
9251 /* Calculate the start and end positions for the current window.
9252 At some point, it would be nice to choose between scrollbars
9253 which reflect the whole buffer size, with special markers
9254 indicating narrowing, and scrollbars which reflect only the
9257 Note that mini-buffers sometimes aren't displaying any text. */
9258 if (!MINI_WINDOW_P (w
)
9259 || (w
== XWINDOW (minibuf_window
)
9260 && NILP (echo_area_buffer
[0])))
9263 start
= marker_position (w
->start
) - BEGV
;
9264 /* I don't think this is guaranteed to be right. For the
9265 moment, we'll pretend it is. */
9266 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
9270 if (whole
< (end
- start
))
9271 whole
= end
- start
;
9274 start
= end
= whole
= 0;
9276 /* Indicate what this scroll bar ought to be displaying now. */
9277 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
9279 /* Note that we actually used the scroll bar attached to this
9280 window, so it shouldn't be deleted at the end of redisplay. */
9281 (*redeem_scroll_bar_hook
) (w
);
9286 /* Restore current_buffer and value of point in it. */
9287 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
9288 if (really_switched_buffer
)
9289 set_buffer_internal_1 (old
);
9291 set_buffer_temp (old
);
9292 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
9294 unbind_to (count
, Qnil
);
9298 /* Build the complete desired matrix of WINDOW with a window start
9299 buffer position POS. Value is non-zero if successful. It is zero
9300 if fonts were loaded during redisplay which makes re-adjusting
9301 glyph matrices necessary. */
9304 try_window (window
, pos
)
9306 struct text_pos pos
;
9308 struct window
*w
= XWINDOW (window
);
9310 struct glyph_row
*last_text_row
= NULL
;
9312 /* Make POS the new window start. */
9313 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
9315 /* Mark cursor position as unknown. No overlay arrow seen. */
9316 w
->cursor
.vpos
= -1;
9317 overlay_arrow_seen
= 0;
9319 /* Initialize iterator and info to start at POS. */
9320 start_display (&it
, w
, pos
);
9322 /* Display all lines of W. */
9323 while (it
.current_y
< it
.last_visible_y
)
9325 if (display_line (&it
))
9326 last_text_row
= it
.glyph_row
- 1;
9327 if (fonts_changed_p
)
9331 /* If bottom moved off end of frame, change mode line percentage. */
9332 if (XFASTINT (w
->window_end_pos
) <= 0
9333 && Z
!= IT_CHARPOS (it
))
9334 w
->update_mode_line
= Qt
;
9336 /* Set window_end_pos to the offset of the last character displayed
9337 on the window from the end of current_buffer. Set
9338 window_end_vpos to its row number. */
9341 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
9342 w
->window_end_bytepos
9343 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9344 XSETFASTINT (w
->window_end_pos
,
9345 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9346 XSETFASTINT (w
->window_end_vpos
,
9347 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9348 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
9353 w
->window_end_bytepos
= 0;
9354 XSETFASTINT (w
->window_end_pos
, 0);
9355 XSETFASTINT (w
->window_end_vpos
, 0);
9358 /* But that is not valid info until redisplay finishes. */
9359 w
->window_end_valid
= Qnil
;
9365 /************************************************************************
9366 Window redisplay reusing current matrix when buffer has not changed
9367 ************************************************************************/
9369 /* Try redisplay of window W showing an unchanged buffer with a
9370 different window start than the last time it was displayed by
9371 reusing its current matrix. Value is non-zero if successful.
9372 W->start is the new window start. */
9375 try_window_reusing_current_matrix (w
)
9378 struct frame
*f
= XFRAME (w
->frame
);
9379 struct glyph_row
*row
, *bottom_row
;
9382 struct text_pos start
, new_start
;
9383 int nrows_scrolled
, i
;
9384 struct glyph_row
*last_text_row
;
9385 struct glyph_row
*last_reused_text_row
;
9386 struct glyph_row
*start_row
;
9387 int start_vpos
, min_y
, max_y
;
9389 /* Right now this function doesn't handle terminal frames. */
9390 if (!FRAME_WINDOW_P (f
))
9393 /* Can't do this if region may have changed. */
9394 if ((!NILP (Vtransient_mark_mode
)
9395 && !NILP (current_buffer
->mark_active
))
9396 || !NILP (w
->region_showing
)
9397 || !NILP (Vshow_trailing_whitespace
))
9400 /* If top-line visibility has changed, give up. */
9401 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9402 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
9405 /* Give up if old or new display is scrolled vertically. We could
9406 make this function handle this, but right now it doesn't. */
9407 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9408 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
9411 /* The variable new_start now holds the new window start. The old
9412 start `start' can be determined from the current matrix. */
9413 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
9414 start
= start_row
->start
.pos
;
9415 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
9417 /* Clear the desired matrix for the display below. */
9418 clear_glyph_matrix (w
->desired_matrix
);
9420 if (CHARPOS (new_start
) <= CHARPOS (start
))
9424 IF_DEBUG (debug_method_add (w
, "twu1"));
9426 /* Display up to a row that can be reused. The variable
9427 last_text_row is set to the last row displayed that displays
9429 start_display (&it
, w
, new_start
);
9430 first_row_y
= it
.current_y
;
9431 w
->cursor
.vpos
= -1;
9432 last_text_row
= last_reused_text_row
= NULL
;
9433 while (it
.current_y
< it
.last_visible_y
9434 && IT_CHARPOS (it
) < CHARPOS (start
)
9435 && !fonts_changed_p
)
9436 if (display_line (&it
))
9437 last_text_row
= it
.glyph_row
- 1;
9439 /* A value of current_y < last_visible_y means that we stopped
9440 at the previous window start, which in turn means that we
9441 have at least one reusable row. */
9442 if (it
.current_y
< it
.last_visible_y
)
9444 nrows_scrolled
= it
.vpos
;
9446 /* Find PT if not already found in the lines displayed. */
9447 if (w
->cursor
.vpos
< 0)
9449 int dy
= it
.current_y
- first_row_y
;
9451 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9452 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9454 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
9455 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9457 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
9458 dy
, nrows_scrolled
);
9462 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
9468 /* Give up if point was not found. This shouldn't
9469 happen often; not more often than with try_window
9471 if (w
->cursor
.vpos
< 0)
9473 clear_glyph_matrix (w
->desired_matrix
);
9478 /* Scroll the display. Do it before the current matrix is
9479 changed. The problem here is that update has not yet
9480 run, i.e. part of the current matrix is not up to date.
9481 scroll_run_hook will clear the cursor, and use the
9482 current matrix to get the height of the row the cursor is
9484 run
.current_y
= first_row_y
;
9485 run
.desired_y
= it
.current_y
;
9486 run
.height
= it
.last_visible_y
- it
.current_y
;
9488 && run
.current_y
!= run
.desired_y
)
9491 rif
->update_window_begin_hook (w
);
9492 rif
->scroll_run_hook (w
, &run
);
9493 rif
->update_window_end_hook (w
, 0);
9497 /* Shift current matrix down by nrows_scrolled lines. */
9498 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9499 rotate_matrix (w
->current_matrix
,
9501 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9504 /* Disable lines not reused. */
9505 for (i
= 0; i
< it
.vpos
; ++i
)
9506 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
9508 /* Re-compute Y positions. */
9509 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
) + nrows_scrolled
;
9510 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9511 max_y
= it
.last_visible_y
;
9512 while (row
< bottom_row
)
9514 row
->y
= it
.current_y
;
9517 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9518 else if (row
->y
+ row
->height
> max_y
)
9520 = row
->height
- (row
->y
+ row
->height
- max_y
);
9522 row
->visible_height
= row
->height
;
9524 it
.current_y
+= row
->height
;
9527 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9528 last_reused_text_row
= row
;
9529 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
9535 /* Update window_end_pos etc.; last_reused_text_row is the last
9536 reused row from the current matrix containing text, if any.
9537 The value of last_text_row is the last displayed line
9539 if (last_reused_text_row
)
9541 w
->window_end_bytepos
9542 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
9543 XSETFASTINT (w
->window_end_pos
,
9544 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
9545 XSETFASTINT (w
->window_end_vpos
,
9546 MATRIX_ROW_VPOS (last_reused_text_row
,
9547 w
->current_matrix
));
9549 else if (last_text_row
)
9551 w
->window_end_bytepos
9552 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9553 XSETFASTINT (w
->window_end_pos
,
9554 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9555 XSETFASTINT (w
->window_end_vpos
,
9556 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9560 /* This window must be completely empty. */
9561 w
->window_end_bytepos
= 0;
9562 XSETFASTINT (w
->window_end_pos
, 0);
9563 XSETFASTINT (w
->window_end_vpos
, 0);
9565 w
->window_end_valid
= Qnil
;
9567 /* Update hint: don't try scrolling again in update_window. */
9568 w
->desired_matrix
->no_scrolling_p
= 1;
9571 debug_method_add (w
, "try_window_reusing_current_matrix 1");
9575 else if (CHARPOS (new_start
) > CHARPOS (start
))
9577 struct glyph_row
*pt_row
, *row
;
9578 struct glyph_row
*first_reusable_row
;
9579 struct glyph_row
*first_row_to_display
;
9581 int yb
= window_text_bottom_y (w
);
9583 IF_DEBUG (debug_method_add (w
, "twu2"));
9585 /* Find the row starting at new_start, if there is one. Don't
9586 reuse a partially visible line at the end. */
9587 first_reusable_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9588 while (first_reusable_row
->enabled_p
9589 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
9590 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9591 < CHARPOS (new_start
)))
9592 ++first_reusable_row
;
9594 /* Give up if there is no row to reuse. */
9595 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
9596 || !first_reusable_row
->enabled_p
9597 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9598 != CHARPOS (new_start
)))
9601 /* We can reuse fully visible rows beginning with
9602 first_reusable_row to the end of the window. Set
9603 first_row_to_display to the first row that cannot be reused.
9604 Set pt_row to the row containing point, if there is any. */
9605 first_row_to_display
= first_reusable_row
;
9607 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
9609 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
9610 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
9611 pt_row
= first_row_to_display
;
9613 ++first_row_to_display
;
9616 /* Start displaying at the start of first_row_to_display. */
9617 xassert (first_row_to_display
->y
< yb
);
9618 init_to_row_start (&it
, w
, first_row_to_display
);
9619 nrows_scrolled
= MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
);
9620 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
9622 it
.current_y
= first_row_to_display
->y
- first_reusable_row
->y
;
9624 /* Display lines beginning with first_row_to_display in the
9625 desired matrix. Set last_text_row to the last row displayed
9626 that displays text. */
9627 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
9629 w
->cursor
.vpos
= -1;
9630 last_text_row
= NULL
;
9631 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
9632 if (display_line (&it
))
9633 last_text_row
= it
.glyph_row
- 1;
9635 /* Give up If point isn't in a row displayed or reused. */
9636 if (w
->cursor
.vpos
< 0)
9638 clear_glyph_matrix (w
->desired_matrix
);
9642 /* If point is in a reused row, adjust y and vpos of the cursor
9646 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
9648 w
->cursor
.y
-= first_reusable_row
->y
;
9651 /* Scroll the display. */
9652 run
.current_y
= first_reusable_row
->y
;
9653 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9654 run
.height
= it
.last_visible_y
- run
.current_y
;
9657 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9659 rif
->update_window_begin_hook (w
);
9660 rif
->scroll_run_hook (w
, &run
);
9661 rif
->update_window_end_hook (w
, 0);
9665 /* Adjust Y positions of reused rows. */
9666 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9667 row
= first_reusable_row
;
9668 dy
= first_reusable_row
->y
;
9669 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9670 max_y
= it
.last_visible_y
;
9671 while (row
< first_row_to_display
)
9675 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9676 else if (row
->y
+ row
->height
> max_y
)
9678 = row
->height
- (row
->y
+ row
->height
- max_y
);
9680 row
->visible_height
= row
->height
;
9684 /* Disable rows not reused. */
9685 while (row
< bottom_row
)
9691 /* Scroll the current matrix. */
9692 xassert (nrows_scrolled
> 0);
9693 rotate_matrix (w
->current_matrix
,
9695 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9698 /* Adjust window end. A null value of last_text_row means that
9699 the window end is in reused rows which in turn means that
9700 only its vpos can have changed. */
9703 w
->window_end_bytepos
9704 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9705 XSETFASTINT (w
->window_end_pos
,
9706 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9707 XSETFASTINT (w
->window_end_vpos
,
9708 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9712 XSETFASTINT (w
->window_end_vpos
,
9713 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
9716 w
->window_end_valid
= Qnil
;
9717 w
->desired_matrix
->no_scrolling_p
= 1;
9720 debug_method_add (w
, "try_window_reusing_current_matrix 2");
9730 /************************************************************************
9731 Window redisplay reusing current matrix when buffer has changed
9732 ************************************************************************/
9734 static struct glyph_row
*get_last_unchanged_at_beg_row
P_ ((struct window
*));
9735 static struct glyph_row
*get_first_unchanged_at_end_row
P_ ((struct window
*,
9737 static struct glyph_row
*
9738 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
9739 struct glyph_row
*));
9742 /* Return the last row in MATRIX displaying text. If row START is
9743 non-null, start searching with that row. IT gives the dimensions
9744 of the display. Value is null if matrix is empty; otherwise it is
9745 a pointer to the row found. */
9747 static struct glyph_row
*
9748 find_last_row_displaying_text (matrix
, it
, start
)
9749 struct glyph_matrix
*matrix
;
9751 struct glyph_row
*start
;
9753 struct glyph_row
*row
, *row_found
;
9755 /* Set row_found to the last row in IT->w's current matrix
9756 displaying text. The loop looks funny but think of partially
9759 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
9760 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9762 xassert (row
->enabled_p
);
9764 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
9773 /* Return the last row in the current matrix of W that is not affected
9774 by changes at the start of current_buffer that occurred since the
9775 last time W was redisplayed. Value is null if no such row exists.
9777 The global variable beg_unchanged has to contain the number of
9778 bytes unchanged at the start of current_buffer. BEG +
9779 beg_unchanged is the buffer position of the first changed byte in
9780 current_buffer. Characters at positions < BEG + beg_unchanged are
9781 at the same buffer positions as they were when the current matrix
9784 static struct glyph_row
*
9785 get_last_unchanged_at_beg_row (w
)
9788 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
9789 struct glyph_row
*row
;
9790 struct glyph_row
*row_found
= NULL
;
9791 int yb
= window_text_bottom_y (w
);
9793 /* Find the last row displaying unchanged text. */
9794 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9795 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
9796 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
9798 if (/* If row ends before first_changed_pos, it is unchanged,
9799 except in some case. */
9800 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
9801 /* When row ends in ZV and we write at ZV it is not
9803 && !row
->ends_at_zv_p
9804 /* When first_changed_pos is the end of a continued line,
9805 row is not unchanged because it may be no longer
9807 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
9808 && row
->continued_p
))
9811 /* Stop if last visible row. */
9812 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
9822 /* Find the first glyph row in the current matrix of W that is not
9823 affected by changes at the end of current_buffer since the last
9824 time the window was redisplayed. Return in *DELTA the number of
9825 chars by which buffer positions in unchanged text at the end of
9826 current_buffer must be adjusted. Return in *DELTA_BYTES the
9827 corresponding number of bytes. Value is null if no such row
9828 exists, i.e. all rows are affected by changes. */
9830 static struct glyph_row
*
9831 get_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
9833 int *delta
, *delta_bytes
;
9835 struct glyph_row
*row
;
9836 struct glyph_row
*row_found
= NULL
;
9838 *delta
= *delta_bytes
= 0;
9840 /* A value of window_end_pos >= end_unchanged means that the window
9841 end is in the range of changed text. If so, there is no
9842 unchanged row at the end of W's current matrix. */
9843 xassert (!NILP (w
->window_end_valid
));
9844 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
9847 /* Set row to the last row in W's current matrix displaying text. */
9848 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
9850 /* If matrix is entirely empty, no unchanged row exists. */
9851 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9853 /* The value of row is the last glyph row in the matrix having a
9854 meaningful buffer position in it. The end position of row
9855 corresponds to window_end_pos. This allows us to translate
9856 buffer positions in the current matrix to current buffer
9857 positions for characters not in changed text. */
9858 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
9859 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
9860 int last_unchanged_pos
, last_unchanged_pos_old
;
9861 struct glyph_row
*first_text_row
9862 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9865 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
9867 /* Set last_unchanged_pos to the buffer position of the last
9868 character in the buffer that has not been changed. Z is the
9869 index + 1 of the last byte in current_buffer, i.e. by
9870 subtracting end_unchanged we get the index of the last
9871 unchanged character, and we have to add BEG to get its buffer
9873 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
9874 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
9876 /* Search backward from ROW for a row displaying a line that
9877 starts at a minimum position >= last_unchanged_pos_old. */
9878 while (row
>= first_text_row
)
9880 xassert (row
->enabled_p
);
9881 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
));
9883 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
9889 xassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
9894 /* Make sure that glyph rows in the current matrix of window W
9895 reference the same glyph memory as corresponding rows in the
9896 frame's frame matrix. This function is called after scrolling W's
9897 current matrix on a terminal frame in try_window_id and
9898 try_window_reusing_current_matrix. */
9901 sync_frame_with_window_matrix_rows (w
)
9904 struct frame
*f
= XFRAME (w
->frame
);
9905 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
9907 /* Preconditions: W must be a leaf window and full-width. Its frame
9908 must have a frame matrix. */
9909 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
9910 xassert (WINDOW_FULL_WIDTH_P (w
));
9911 xassert (!FRAME_WINDOW_P (f
));
9913 /* If W is a full-width window, glyph pointers in W's current matrix
9914 have, by definition, to be the same as glyph pointers in the
9915 corresponding frame matrix. */
9916 window_row
= w
->current_matrix
->rows
;
9917 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
9918 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
9919 while (window_row
< window_row_end
)
9923 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
9924 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
9926 /* Disable frame rows whose corresponding window rows have
9927 been disabled in try_window_id. */
9928 if (!window_row
->enabled_p
)
9929 frame_row
->enabled_p
= 0;
9931 ++window_row
, ++frame_row
;
9936 /* Find the glyph row in window W containing CHARPOS. Consider all
9937 rows between START and END (not inclusive). END null means search
9938 all rows to the end of the display area of W. Value is the row
9939 containing CHARPOS or null. */
9941 static struct glyph_row
*
9942 row_containing_pos (w
, charpos
, start
, end
)
9945 struct glyph_row
*start
, *end
;
9947 struct glyph_row
*row
= start
;
9950 /* If we happen to start on a header-line, skip that. */
9951 if (row
->mode_line_p
)
9954 if ((end
&& row
>= end
) || !row
->enabled_p
)
9957 last_y
= window_text_bottom_y (w
);
9959 while ((end
== NULL
|| row
< end
)
9960 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
9961 /* The end position of a row equals the start
9962 position of the next row. If CHARPOS is there, we
9963 would rather display it in the next line, except
9964 when this line ends in ZV. */
9965 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
9966 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
9967 || !row
->ends_at_zv_p
)))
9968 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9971 /* Give up if CHARPOS not found. */
9972 if ((end
&& row
>= end
)
9973 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
9974 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
9981 /* Try to redisplay window W by reusing its existing display. W's
9982 current matrix must be up to date when this function is called,
9983 i.e. window_end_valid must not be nil.
9987 1 if display has been updated
9988 0 if otherwise unsuccessful
9989 -1 if redisplay with same window start is known not to succeed
9991 The following steps are performed:
9993 1. Find the last row in the current matrix of W that is not
9994 affected by changes at the start of current_buffer. If no such row
9997 2. Find the first row in W's current matrix that is not affected by
9998 changes at the end of current_buffer. Maybe there is no such row.
10000 3. Display lines beginning with the row + 1 found in step 1 to the
10001 row found in step 2 or, if step 2 didn't find a row, to the end of
10004 4. If cursor is not known to appear on the window, give up.
10006 5. If display stopped at the row found in step 2, scroll the
10007 display and current matrix as needed.
10009 6. Maybe display some lines at the end of W, if we must. This can
10010 happen under various circumstances, like a partially visible line
10011 becoming fully visible, or because newly displayed lines are displayed
10012 in smaller font sizes.
10014 7. Update W's window end information. */
10016 /* Check that window end is what we expect it to be. */
10022 struct frame
*f
= XFRAME (w
->frame
);
10023 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
10024 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
10025 struct glyph_row
*last_unchanged_at_beg_row
;
10026 struct glyph_row
*first_unchanged_at_end_row
;
10027 struct glyph_row
*row
;
10028 struct glyph_row
*bottom_row
;
10031 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
10032 struct text_pos start_pos
;
10034 int first_unchanged_at_end_vpos
= 0;
10035 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
10036 struct text_pos start
;
10038 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10040 /* Check pre-conditions. Window end must be valid, otherwise
10041 the current matrix would not be up to date. */
10042 xassert (!NILP (w
->window_end_valid
));
10043 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
10044 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
10046 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
10047 only if buffer has really changed. The reason is that the gap is
10048 initially at Z for freshly visited files. The code below would
10049 set end_unchanged to 0 in that case. */
10050 if (MODIFF
> SAVE_MODIFF
10051 /* This seems to happen sometimes after saving a buffer. */
10052 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
10054 if (GPT
- BEG
< BEG_UNCHANGED
)
10055 BEG_UNCHANGED
= GPT
- BEG
;
10056 if (Z
- GPT
< END_UNCHANGED
)
10057 END_UNCHANGED
= Z
- GPT
;
10060 /* If window starts after a line end, and the last change is in
10061 front of that newline, then changes don't affect the display.
10062 This case happens with stealth-fontification. Note that although
10063 the display is unchanged, glyph positions in the matrix have to
10064 be adjusted, of course. */
10065 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10066 if (CHARPOS (start
) > BEGV
10067 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
10068 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
10069 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10071 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
10072 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
10076 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10077 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
10079 increment_matrix_positions (w
->current_matrix
,
10080 MATRIX_ROW_VPOS (r0
, current_matrix
),
10081 MATRIX_ROW_VPOS (r1
, current_matrix
),
10082 delta
, delta_bytes
);
10085 #if 0 /* If changes are all in front of the window start, the
10086 distance of the last displayed glyph from Z hasn't
10089 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10090 w
->window_end_bytepos
10091 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10097 /* Return quickly if changes are all below what is displayed in the
10098 window, and if PT is in the window. */
10099 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
10100 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10102 /* We have to update window end positions because the buffer's
10103 size has changed. */
10105 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10106 w
->window_end_bytepos
10107 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10111 /* Check that window start agrees with the start of the first glyph
10112 row in its current matrix. Check this after we know the window
10113 start is not in changed text, otherwise positions would not be
10115 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10116 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
10119 /* Compute the position at which we have to start displaying new
10120 lines. Some of the lines at the top of the window might be
10121 reusable because they are not displaying changed text. Find the
10122 last row in W's current matrix not affected by changes at the
10123 start of current_buffer. Value is null if changes start in the
10124 first line of window. */
10125 last_unchanged_at_beg_row
= get_last_unchanged_at_beg_row (w
);
10126 if (last_unchanged_at_beg_row
)
10128 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
10129 start_pos
= it
.current
.pos
;
10131 /* Start displaying new lines in the desired matrix at the same
10132 vpos we would use in the current matrix, i.e. below
10133 last_unchanged_at_beg_row. */
10134 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
10136 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10137 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
10139 xassert (it
.hpos
== 0 && it
.current_x
== 0);
10143 /* There are no reusable lines at the start of the window.
10144 Start displaying in the first line. */
10145 start_display (&it
, w
, start
);
10146 start_pos
= it
.current
.pos
;
10149 /* Find the first row that is not affected by changes at the end of
10150 the buffer. Value will be null if there is no unchanged row, in
10151 which case we must redisplay to the end of the window. delta
10152 will be set to the value by which buffer positions beginning with
10153 first_unchanged_at_end_row have to be adjusted due to text
10155 first_unchanged_at_end_row
10156 = get_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
10157 IF_DEBUG (debug_delta
= delta
);
10158 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
10160 /* Set stop_pos to the buffer position up to which we will have to
10161 display new lines. If first_unchanged_at_end_row != NULL, this
10162 is the buffer position of the start of the line displayed in that
10163 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
10164 that we don't stop at a buffer position. */
10166 if (first_unchanged_at_end_row
)
10168 xassert (last_unchanged_at_beg_row
== NULL
10169 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
10171 /* If this is a continuation line, move forward to the next one
10172 that isn't. Changes in lines above affect this line.
10173 Caution: this may move first_unchanged_at_end_row to a row
10174 not displaying text. */
10175 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
10176 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10177 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10178 < it
.last_visible_y
))
10179 ++first_unchanged_at_end_row
;
10181 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10182 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10183 >= it
.last_visible_y
))
10184 first_unchanged_at_end_row
= NULL
;
10187 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
10189 first_unchanged_at_end_vpos
10190 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
10191 xassert (stop_pos
>= Z
- END_UNCHANGED
);
10194 else if (last_unchanged_at_beg_row
== NULL
)
10200 /* Either there is no unchanged row at the end, or the one we have
10201 now displays text. This is a necessary condition for the window
10202 end pos calculation at the end of this function. */
10203 xassert (first_unchanged_at_end_row
== NULL
10204 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
10206 debug_last_unchanged_at_beg_vpos
10207 = (last_unchanged_at_beg_row
10208 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
10210 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
10212 #endif /* GLYPH_DEBUG != 0 */
10215 /* Display new lines. Set last_text_row to the last new line
10216 displayed which has text on it, i.e. might end up as being the
10217 line where the window_end_vpos is. */
10218 w
->cursor
.vpos
= -1;
10219 last_text_row
= NULL
;
10220 overlay_arrow_seen
= 0;
10221 while (it
.current_y
< it
.last_visible_y
10222 && !fonts_changed_p
10223 && (first_unchanged_at_end_row
== NULL
10224 || IT_CHARPOS (it
) < stop_pos
))
10226 if (display_line (&it
))
10227 last_text_row
= it
.glyph_row
- 1;
10230 if (fonts_changed_p
)
10234 /* Compute differences in buffer positions, y-positions etc. for
10235 lines reused at the bottom of the window. Compute what we can
10237 if (first_unchanged_at_end_row
10238 /* No lines reused because we displayed everything up to the
10239 bottom of the window. */
10240 && it
.current_y
< it
.last_visible_y
)
10243 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
10245 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
10246 run
.current_y
= first_unchanged_at_end_row
->y
;
10247 run
.desired_y
= run
.current_y
+ dy
;
10248 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
10252 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
10253 first_unchanged_at_end_row
= NULL
;
10255 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
10258 /* Find the cursor if not already found. We have to decide whether
10259 PT will appear on this window (it sometimes doesn't, but this is
10260 not a very frequent case.) This decision has to be made before
10261 the current matrix is altered. A value of cursor.vpos < 0 means
10262 that PT is either in one of the lines beginning at
10263 first_unchanged_at_end_row or below the window. Don't care for
10264 lines that might be displayed later at the window end; as
10265 mentioned, this is not a frequent case. */
10266 if (w
->cursor
.vpos
< 0)
10268 /* Cursor in unchanged rows at the top? */
10269 if (PT
< CHARPOS (start_pos
)
10270 && last_unchanged_at_beg_row
)
10272 row
= row_containing_pos (w
, PT
,
10273 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
10274 last_unchanged_at_beg_row
+ 1);
10275 xassert (row
&& row
<= last_unchanged_at_beg_row
);
10276 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10279 /* Start from first_unchanged_at_end_row looking for PT. */
10280 else if (first_unchanged_at_end_row
)
10282 row
= row_containing_pos (w
, PT
- delta
,
10283 first_unchanged_at_end_row
, NULL
);
10285 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
10286 delta_bytes
, dy
, dvpos
);
10289 /* Give up if cursor was not found. */
10290 if (w
->cursor
.vpos
< 0)
10292 clear_glyph_matrix (w
->desired_matrix
);
10297 /* Don't let the cursor end in the scroll margins. */
10299 int this_scroll_margin
, cursor_height
;
10301 this_scroll_margin
= max (0, scroll_margin
);
10302 this_scroll_margin
= min (this_scroll_margin
,
10303 XFASTINT (w
->height
) / 4);
10304 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
10305 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
10307 if ((w
->cursor
.y
< this_scroll_margin
10308 && CHARPOS (start
) > BEGV
)
10309 /* Don't take scroll margin into account at the bottom because
10310 old redisplay didn't do it either. */
10311 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
10313 w
->cursor
.vpos
= -1;
10314 clear_glyph_matrix (w
->desired_matrix
);
10319 /* Scroll the display. Do it before changing the current matrix so
10320 that xterm.c doesn't get confused about where the cursor glyph is
10322 if (dy
&& run
.height
)
10326 if (FRAME_WINDOW_P (f
))
10328 rif
->update_window_begin_hook (w
);
10329 rif
->scroll_run_hook (w
, &run
);
10330 rif
->update_window_end_hook (w
, 0);
10334 /* Terminal frame. In this case, dvpos gives the number of
10335 lines to scroll by; dvpos < 0 means scroll up. */
10336 int first_unchanged_at_end_vpos
10337 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
10338 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
10339 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
10341 /* Perform the operation on the screen. */
10344 /* Scroll last_unchanged_at_beg_row to the end of the
10345 window down dvpos lines. */
10346 set_terminal_window (end
);
10348 /* On dumb terminals delete dvpos lines at the end
10349 before inserting dvpos empty lines. */
10350 if (!scroll_region_ok
)
10351 ins_del_lines (end
- dvpos
, -dvpos
);
10353 /* Insert dvpos empty lines in front of
10354 last_unchanged_at_beg_row. */
10355 ins_del_lines (from
, dvpos
);
10357 else if (dvpos
< 0)
10359 /* Scroll up last_unchanged_at_beg_vpos to the end of
10360 the window to last_unchanged_at_beg_vpos - |dvpos|. */
10361 set_terminal_window (end
);
10363 /* Delete dvpos lines in front of
10364 last_unchanged_at_beg_vpos. ins_del_lines will set
10365 the cursor to the given vpos and emit |dvpos| delete
10367 ins_del_lines (from
+ dvpos
, dvpos
);
10369 /* On a dumb terminal insert dvpos empty lines at the
10371 if (!scroll_region_ok
)
10372 ins_del_lines (end
+ dvpos
, -dvpos
);
10375 set_terminal_window (0);
10381 /* Shift reused rows of the current matrix to the right position.
10382 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
10384 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10385 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
10388 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
10389 bottom_vpos
, dvpos
);
10390 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
10393 else if (dvpos
> 0)
10395 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
10396 bottom_vpos
, dvpos
);
10397 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
10398 first_unchanged_at_end_vpos
+ dvpos
, 0);
10401 /* For frame-based redisplay, make sure that current frame and window
10402 matrix are in sync with respect to glyph memory. */
10403 if (!FRAME_WINDOW_P (f
))
10404 sync_frame_with_window_matrix_rows (w
);
10406 /* Adjust buffer positions in reused rows. */
10408 increment_matrix_positions (current_matrix
,
10409 first_unchanged_at_end_vpos
+ dvpos
,
10410 bottom_vpos
, delta
, delta_bytes
);
10412 /* Adjust Y positions. */
10414 shift_glyph_matrix (w
, current_matrix
,
10415 first_unchanged_at_end_vpos
+ dvpos
,
10418 if (first_unchanged_at_end_row
)
10419 first_unchanged_at_end_row
+= dvpos
;
10421 /* If scrolling up, there may be some lines to display at the end of
10423 last_text_row_at_end
= NULL
;
10426 /* Set last_row to the glyph row in the current matrix where the
10427 window end line is found. It has been moved up or down in
10428 the matrix by dvpos. */
10429 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
10430 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
10432 /* If last_row is the window end line, it should display text. */
10433 xassert (last_row
->displays_text_p
);
10435 /* If window end line was partially visible before, begin
10436 displaying at that line. Otherwise begin displaying with the
10437 line following it. */
10438 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
10440 init_to_row_start (&it
, w
, last_row
);
10441 it
.vpos
= last_vpos
;
10442 it
.current_y
= last_row
->y
;
10446 init_to_row_end (&it
, w
, last_row
);
10447 it
.vpos
= 1 + last_vpos
;
10448 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
10452 /* We may start in a continuation line. If so, we have to get
10453 the right continuation_lines_width and current_x. */
10454 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
10455 it
.hpos
= it
.current_x
= 0;
10457 /* Display the rest of the lines at the window end. */
10458 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10459 while (it
.current_y
< it
.last_visible_y
10460 && !fonts_changed_p
)
10462 /* Is it always sure that the display agrees with lines in
10463 the current matrix? I don't think so, so we mark rows
10464 displayed invalid in the current matrix by setting their
10465 enabled_p flag to zero. */
10466 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
10467 if (display_line (&it
))
10468 last_text_row_at_end
= it
.glyph_row
- 1;
10472 /* Update window_end_pos and window_end_vpos. */
10473 if (first_unchanged_at_end_row
10474 && first_unchanged_at_end_row
->y
< it
.last_visible_y
10475 && !last_text_row_at_end
)
10477 /* Window end line if one of the preserved rows from the current
10478 matrix. Set row to the last row displaying text in current
10479 matrix starting at first_unchanged_at_end_row, after
10481 xassert (first_unchanged_at_end_row
->displays_text_p
);
10482 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
10483 first_unchanged_at_end_row
);
10484 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
10486 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
10487 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10488 XSETFASTINT (w
->window_end_vpos
,
10489 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
10491 else if (last_text_row_at_end
)
10493 XSETFASTINT (w
->window_end_pos
,
10494 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
10495 w
->window_end_bytepos
10496 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
10497 XSETFASTINT (w
->window_end_vpos
,
10498 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
10500 else if (last_text_row
)
10502 /* We have displayed either to the end of the window or at the
10503 end of the window, i.e. the last row with text is to be found
10504 in the desired matrix. */
10505 XSETFASTINT (w
->window_end_pos
,
10506 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10507 w
->window_end_bytepos
10508 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10509 XSETFASTINT (w
->window_end_vpos
,
10510 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
10512 else if (first_unchanged_at_end_row
== NULL
10513 && last_text_row
== NULL
10514 && last_text_row_at_end
== NULL
)
10516 /* Displayed to end of window, but no line containing text was
10517 displayed. Lines were deleted at the end of the window. */
10519 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
10521 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
10522 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10523 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
10524 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10525 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
10528 w
->window_end_vpos
= make_number (vpos
);
10533 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
10534 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
10536 /* Record that display has not been completed. */
10537 w
->window_end_valid
= Qnil
;
10538 w
->desired_matrix
->no_scrolling_p
= 1;
10544 /***********************************************************************
10545 More debugging support
10546 ***********************************************************************/
10550 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
10551 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
10554 /* Dump the contents of glyph matrix MATRIX on stderr. If
10555 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
10558 dump_glyph_matrix (matrix
, with_glyphs_p
)
10559 struct glyph_matrix
*matrix
;
10563 for (i
= 0; i
< matrix
->nrows
; ++i
)
10564 dump_glyph_row (matrix
, i
, with_glyphs_p
);
10568 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
10569 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
10572 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
10573 struct glyph_matrix
*matrix
;
10574 int vpos
, with_glyphs_p
;
10576 struct glyph_row
*row
;
10578 if (vpos
< 0 || vpos
>= matrix
->nrows
)
10581 row
= MATRIX_ROW (matrix
, vpos
);
10583 fprintf (stderr
, "Row Start End Used oEI><O\\CTZF X Y W\n");
10584 fprintf (stderr
, "=============================================\n");
10586 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",
10587 row
- matrix
->rows
,
10588 MATRIX_ROW_START_CHARPOS (row
),
10589 MATRIX_ROW_END_CHARPOS (row
),
10590 row
->used
[TEXT_AREA
],
10591 row
->contains_overlapping_glyphs_p
,
10594 row
->truncated_on_left_p
,
10595 row
->truncated_on_right_p
,
10596 row
->overlay_arrow_p
,
10598 MATRIX_ROW_CONTINUATION_LINE_P (row
),
10599 row
->displays_text_p
,
10605 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
10606 row
->end
.overlay_string_index
);
10607 fprintf (stderr
, "%9d %5d\n",
10608 CHARPOS (row
->start
.string_pos
),
10609 CHARPOS (row
->end
.string_pos
));
10610 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
10611 row
->end
.dpvec_index
);
10615 struct glyph
*glyph
, *glyph_end
;
10616 int prev_had_glyphs_p
;
10618 glyph
= row
->glyphs
[TEXT_AREA
];
10619 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
10621 /* Glyph for a line end in text. */
10622 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
10625 if (glyph
< glyph_end
)
10627 fprintf (stderr
, " Glyph Type Pos W Code C Face LR\n");
10628 prev_had_glyphs_p
= 1;
10631 prev_had_glyphs_p
= 0;
10633 while (glyph
< glyph_end
)
10635 if (glyph
->type
== CHAR_GLYPH
)
10638 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10639 glyph
- row
->glyphs
[TEXT_AREA
],
10642 glyph
->pixel_width
,
10644 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
10648 glyph
->left_box_line_p
,
10649 glyph
->right_box_line_p
);
10651 else if (glyph
->type
== STRETCH_GLYPH
)
10654 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10655 glyph
- row
->glyphs
[TEXT_AREA
],
10658 glyph
->pixel_width
,
10662 glyph
->left_box_line_p
,
10663 glyph
->right_box_line_p
);
10665 else if (glyph
->type
== IMAGE_GLYPH
)
10668 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10669 glyph
- row
->glyphs
[TEXT_AREA
],
10672 glyph
->pixel_width
,
10676 glyph
->left_box_line_p
,
10677 glyph
->right_box_line_p
);
10685 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
10686 Sdump_glyph_matrix
, 0, 1, "p",
10687 "Dump the current matrix of the selected window to stderr.\n\
10688 Shows contents of glyph row structures. With non-nil optional\n\
10689 parameter WITH-GLYPHS-P, dump glyphs as well.")
10692 struct window
*w
= XWINDOW (selected_window
);
10693 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10695 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
10696 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
10697 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
10698 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
10699 fprintf (stderr
, "=============================================\n");
10700 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
10705 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
10706 "Dump glyph row ROW to stderr.")
10710 CHECK_NUMBER (row
, 0);
10711 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
10716 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
,
10720 struct frame
*sf
= SELECTED_FRAME ();
10721 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)
10723 dump_glyph_row (m
, 0, 1);
10728 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
10729 Strace_redisplay_toggle
, 0, 0, "",
10730 "Toggle tracing of redisplay.")
10733 trace_redisplay_p
= !trace_redisplay_p
;
10738 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
10739 "Print STRING to stderr.")
10741 Lisp_Object string
;
10743 CHECK_STRING (string
, 0);
10744 fprintf (stderr
, "%s", XSTRING (string
)->data
);
10748 #endif /* GLYPH_DEBUG */
10752 /***********************************************************************
10753 Building Desired Matrix Rows
10754 ***********************************************************************/
10756 /* Return a temporary glyph row holding the glyphs of an overlay
10757 arrow. Only used for non-window-redisplay windows. */
10759 static struct glyph_row
*
10760 get_overlay_arrow_glyph_row (w
)
10763 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10764 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10765 struct buffer
*old
= current_buffer
;
10766 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
10767 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
10768 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
10772 int n_glyphs_before
;
10774 set_buffer_temp (buffer
);
10775 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
10776 it
.glyph_row
->used
[TEXT_AREA
] = 0;
10777 SET_TEXT_POS (it
.position
, 0, 0);
10779 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
10781 while (p
< arrow_end
)
10783 Lisp_Object face
, ilisp
;
10785 /* Get the next character. */
10787 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
10789 it
.c
= *p
, it
.len
= 1;
10792 /* Get its face. */
10793 XSETFASTINT (ilisp
, p
- arrow_string
);
10794 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
10795 it
.face_id
= compute_char_face (f
, it
.c
, face
);
10797 /* Compute its width, get its glyphs. */
10798 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
10799 SET_TEXT_POS (it
.position
, -1, -1);
10800 PRODUCE_GLYPHS (&it
);
10802 /* If this character doesn't fit any more in the line, we have
10803 to remove some glyphs. */
10804 if (it
.current_x
> it
.last_visible_x
)
10806 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
10811 set_buffer_temp (old
);
10812 return it
.glyph_row
;
10816 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
10817 glyphs are only inserted for terminal frames since we can't really
10818 win with truncation glyphs when partially visible glyphs are
10819 involved. Which glyphs to insert is determined by
10820 produce_special_glyphs. */
10823 insert_left_trunc_glyphs (it
)
10826 struct it truncate_it
;
10827 struct glyph
*from
, *end
, *to
, *toend
;
10829 xassert (!FRAME_WINDOW_P (it
->f
));
10831 /* Get the truncation glyphs. */
10833 truncate_it
.current_x
= 0;
10834 truncate_it
.face_id
= DEFAULT_FACE_ID
;
10835 truncate_it
.glyph_row
= &scratch_glyph_row
;
10836 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
10837 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
10838 truncate_it
.object
= make_number (0);
10839 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
10841 /* Overwrite glyphs from IT with truncation glyphs. */
10842 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
10843 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
10844 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
10845 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
10850 /* There may be padding glyphs left over. Remove them. */
10852 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
10854 while (from
< toend
)
10857 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
10861 /* Compute the pixel height and width of IT->glyph_row.
10863 Most of the time, ascent and height of a display line will be equal
10864 to the max_ascent and max_height values of the display iterator
10865 structure. This is not the case if
10867 1. We hit ZV without displaying anything. In this case, max_ascent
10868 and max_height will be zero.
10870 2. We have some glyphs that don't contribute to the line height.
10871 (The glyph row flag contributes_to_line_height_p is for future
10872 pixmap extensions).
10874 The first case is easily covered by using default values because in
10875 these cases, the line height does not really matter, except that it
10876 must not be zero. */
10879 compute_line_metrics (it
)
10882 struct glyph_row
*row
= it
->glyph_row
;
10885 if (FRAME_WINDOW_P (it
->f
))
10887 int i
, header_line_height
;
10889 /* The line may consist of one space only, that was added to
10890 place the cursor on it. If so, the row's height hasn't been
10892 if (row
->height
== 0)
10894 if (it
->max_ascent
+ it
->max_descent
== 0)
10895 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
10896 row
->ascent
= it
->max_ascent
;
10897 row
->height
= it
->max_ascent
+ it
->max_descent
;
10898 row
->phys_ascent
= it
->max_phys_ascent
;
10899 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
10902 /* Compute the width of this line. */
10903 row
->pixel_width
= row
->x
;
10904 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
10905 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10907 xassert (row
->pixel_width
>= 0);
10908 xassert (row
->ascent
>= 0 && row
->height
> 0);
10910 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
10911 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
10913 /* If first line's physical ascent is larger than its logical
10914 ascent, use the physical ascent, and make the row taller.
10915 This makes accented characters fully visible. */
10916 if (row
== it
->w
->desired_matrix
->rows
10917 && row
->phys_ascent
> row
->ascent
)
10919 row
->height
+= row
->phys_ascent
- row
->ascent
;
10920 row
->ascent
= row
->phys_ascent
;
10923 /* Compute how much of the line is visible. */
10924 row
->visible_height
= row
->height
;
10926 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
10927 if (row
->y
< header_line_height
)
10928 row
->visible_height
-= header_line_height
- row
->y
;
10931 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
10932 if (row
->y
+ row
->height
> max_y
)
10933 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10938 row
->pixel_width
= row
->used
[TEXT_AREA
];
10939 row
->ascent
= row
->phys_ascent
= 0;
10940 row
->height
= row
->phys_height
= row
->visible_height
= 1;
10943 /* Compute a hash code for this row. */
10945 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
10946 for (i
= 0; i
< row
->used
[area
]; ++i
)
10947 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
10948 + row
->glyphs
[area
][i
].u
.val
10949 + row
->glyphs
[area
][i
].face_id
10950 + row
->glyphs
[area
][i
].padding_p
10951 + (row
->glyphs
[area
][i
].type
<< 2));
10953 it
->max_ascent
= it
->max_descent
= 0;
10954 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
10958 /* Append one space to the glyph row of iterator IT if doing a
10959 window-based redisplay. DEFAULT_FACE_P non-zero means let the
10960 space have the default face, otherwise let it have the same face as
10961 IT->face_id. Value is non-zero if a space was added.
10963 This function is called to make sure that there is always one glyph
10964 at the end of a glyph row that the cursor can be set on under
10965 window-systems. (If there weren't such a glyph we would not know
10966 how wide and tall a box cursor should be displayed).
10968 At the same time this space let's a nicely handle clearing to the
10969 end of the line if the row ends in italic text. */
10972 append_space (it
, default_face_p
)
10974 int default_face_p
;
10976 if (FRAME_WINDOW_P (it
->f
))
10978 int n
= it
->glyph_row
->used
[TEXT_AREA
];
10980 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
10981 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
10983 /* Save some values that must not be changed. */
10984 int saved_x
= it
->current_x
;
10985 struct text_pos saved_pos
;
10986 int saved_what
= it
->what
;
10987 int saved_face_id
= it
->face_id
;
10988 Lisp_Object saved_object
;
10991 saved_object
= it
->object
;
10992 saved_pos
= it
->position
;
10994 it
->what
= IT_CHARACTER
;
10995 bzero (&it
->position
, sizeof it
->position
);
10996 it
->object
= make_number (0);
11000 if (default_face_p
)
11001 it
->face_id
= DEFAULT_FACE_ID
;
11002 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11003 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
11005 PRODUCE_GLYPHS (it
);
11007 it
->current_x
= saved_x
;
11008 it
->object
= saved_object
;
11009 it
->position
= saved_pos
;
11010 it
->what
= saved_what
;
11011 it
->face_id
= saved_face_id
;
11020 /* Extend the face of the last glyph in the text area of IT->glyph_row
11021 to the end of the display line. Called from display_line.
11022 If the glyph row is empty, add a space glyph to it so that we
11023 know the face to draw. Set the glyph row flag fill_line_p. */
11026 extend_face_to_end_of_line (it
)
11030 struct frame
*f
= it
->f
;
11032 /* If line is already filled, do nothing. */
11033 if (it
->current_x
>= it
->last_visible_x
)
11036 /* Face extension extends the background and box of IT->face_id
11037 to the end of the line. If the background equals the background
11038 of the frame, we haven't to do anything. */
11039 face
= FACE_FROM_ID (f
, it
->face_id
);
11040 if (FRAME_WINDOW_P (f
)
11041 && face
->box
== FACE_NO_BOX
11042 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
11046 /* Set the glyph row flag indicating that the face of the last glyph
11047 in the text area has to be drawn to the end of the text area. */
11048 it
->glyph_row
->fill_line_p
= 1;
11050 /* If current character of IT is not ASCII, make sure we have the
11051 ASCII face. This will be automatically undone the next time
11052 get_next_display_element returns a multibyte character. Note
11053 that the character will always be single byte in unibyte text. */
11054 if (!SINGLE_BYTE_CHAR_P (it
->c
))
11056 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
11059 if (FRAME_WINDOW_P (f
))
11061 /* If the row is empty, add a space with the current face of IT,
11062 so that we know which face to draw. */
11063 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
11065 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
11066 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
11067 it
->glyph_row
->used
[TEXT_AREA
] = 1;
11072 /* Save some values that must not be changed. */
11073 int saved_x
= it
->current_x
;
11074 struct text_pos saved_pos
;
11075 Lisp_Object saved_object
;
11076 int saved_what
= it
->what
;
11078 saved_object
= it
->object
;
11079 saved_pos
= it
->position
;
11081 it
->what
= IT_CHARACTER
;
11082 bzero (&it
->position
, sizeof it
->position
);
11083 it
->object
= make_number (0);
11087 PRODUCE_GLYPHS (it
);
11089 while (it
->current_x
<= it
->last_visible_x
)
11090 PRODUCE_GLYPHS (it
);
11092 /* Don't count these blanks really. It would let us insert a left
11093 truncation glyph below and make us set the cursor on them, maybe. */
11094 it
->current_x
= saved_x
;
11095 it
->object
= saved_object
;
11096 it
->position
= saved_pos
;
11097 it
->what
= saved_what
;
11102 /* Value is non-zero if text starting at CHARPOS in current_buffer is
11103 trailing whitespace. */
11106 trailing_whitespace_p (charpos
)
11109 int bytepos
= CHAR_TO_BYTE (charpos
);
11112 while (bytepos
< ZV_BYTE
11113 && (c
= FETCH_CHAR (bytepos
),
11114 c
== ' ' || c
== '\t'))
11117 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
11119 if (bytepos
!= PT_BYTE
)
11126 /* Highlight trailing whitespace, if any, in ROW. */
11129 highlight_trailing_whitespace (f
, row
)
11131 struct glyph_row
*row
;
11133 int used
= row
->used
[TEXT_AREA
];
11137 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
11138 struct glyph
*glyph
= start
+ used
- 1;
11140 /* Skip over the space glyph inserted to display the
11141 cursor at the end of a line. */
11142 if (glyph
->type
== CHAR_GLYPH
11143 && glyph
->u
.ch
== ' '
11144 && INTEGERP (glyph
->object
))
11147 /* If last glyph is a space or stretch, and it's trailing
11148 whitespace, set the face of all trailing whitespace glyphs in
11149 IT->glyph_row to `trailing-whitespace'. */
11151 && BUFFERP (glyph
->object
)
11152 && (glyph
->type
== STRETCH_GLYPH
11153 || (glyph
->type
== CHAR_GLYPH
11154 && glyph
->u
.ch
== ' '))
11155 && trailing_whitespace_p (glyph
->charpos
))
11157 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
11159 while (glyph
>= start
11160 && BUFFERP (glyph
->object
)
11161 && (glyph
->type
== STRETCH_GLYPH
11162 || (glyph
->type
== CHAR_GLYPH
11163 && glyph
->u
.ch
== ' ')))
11164 (glyph
--)->face_id
= face_id
;
11170 /* Construct the glyph row IT->glyph_row in the desired matrix of
11171 IT->w from text at the current position of IT. See dispextern.h
11172 for an overview of struct it. Value is non-zero if
11173 IT->glyph_row displays text, as opposed to a line displaying ZV
11180 struct glyph_row
*row
= it
->glyph_row
;
11182 /* We always start displaying at hpos zero even if hscrolled. */
11183 xassert (it
->hpos
== 0 && it
->current_x
== 0);
11185 /* We must not display in a row that's not a text row. */
11186 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
11187 < it
->w
->desired_matrix
->nrows
);
11189 /* Is IT->w showing the region? */
11190 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
11192 /* Clear the result glyph row and enable it. */
11193 prepare_desired_row (row
);
11195 row
->y
= it
->current_y
;
11196 row
->start
= it
->current
;
11197 row
->continuation_lines_width
= it
->continuation_lines_width
;
11198 row
->displays_text_p
= 1;
11200 /* Arrange the overlays nicely for our purposes. Usually, we call
11201 display_line on only one line at a time, in which case this
11202 can't really hurt too much, or we call it on lines which appear
11203 one after another in the buffer, in which case all calls to
11204 recenter_overlay_lists but the first will be pretty cheap. */
11205 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
11207 /* Move over display elements that are not visible because we are
11208 hscrolled. This may stop at an x-position < IT->first_visible_x
11209 if the first glyph is partially visible or if we hit a line end. */
11210 if (it
->current_x
< it
->first_visible_x
)
11211 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
11212 MOVE_TO_POS
| MOVE_TO_X
);
11214 /* Get the initial row height. This is either the height of the
11215 text hscrolled, if there is any, or zero. */
11216 row
->ascent
= it
->max_ascent
;
11217 row
->height
= it
->max_ascent
+ it
->max_descent
;
11218 row
->phys_ascent
= it
->max_phys_ascent
;
11219 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11221 /* Loop generating characters. The loop is left with IT on the next
11222 character to display. */
11225 int n_glyphs_before
, hpos_before
, x_before
;
11227 int ascent
, descent
, phys_ascent
, phys_descent
;
11229 /* Retrieve the next thing to display. Value is zero if end of
11231 if (!get_next_display_element (it
))
11233 /* Maybe add a space at the end of this line that is used to
11234 display the cursor there under X. Set the charpos of the
11235 first glyph of blank lines not corresponding to any text
11237 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
11238 || row
->used
[TEXT_AREA
] == 0)
11240 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
11241 row
->displays_text_p
= 0;
11243 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
11244 row
->indicate_empty_line_p
= 1;
11247 it
->continuation_lines_width
= 0;
11248 row
->ends_at_zv_p
= 1;
11252 /* Now, get the metrics of what we want to display. This also
11253 generates glyphs in `row' (which is IT->glyph_row). */
11254 n_glyphs_before
= row
->used
[TEXT_AREA
];
11257 /* Remember the line height so far in case the next element doesn't
11258 fit on the line. */
11259 if (!it
->truncate_lines_p
)
11261 ascent
= it
->max_ascent
;
11262 descent
= it
->max_descent
;
11263 phys_ascent
= it
->max_phys_ascent
;
11264 phys_descent
= it
->max_phys_descent
;
11267 PRODUCE_GLYPHS (it
);
11269 /* If this display element was in marginal areas, continue with
11271 if (it
->area
!= TEXT_AREA
)
11273 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11274 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11275 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11276 row
->phys_height
= max (row
->phys_height
,
11277 it
->max_phys_ascent
+ it
->max_phys_descent
);
11278 set_iterator_to_next (it
);
11282 /* Does the display element fit on the line? If we truncate
11283 lines, we should draw past the right edge of the window. If
11284 we don't truncate, we want to stop so that we can display the
11285 continuation glyph before the right margin. If lines are
11286 continued, there are two possible strategies for characters
11287 resulting in more than 1 glyph (e.g. tabs): Display as many
11288 glyphs as possible in this line and leave the rest for the
11289 continuation line, or display the whole element in the next
11290 line. Original redisplay did the former, so we do it also. */
11291 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11292 hpos_before
= it
->hpos
;
11296 && it
->current_x
< it
->last_visible_x
)
11299 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11300 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11301 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11302 row
->phys_height
= max (row
->phys_height
,
11303 it
->max_phys_ascent
+ it
->max_phys_descent
);
11304 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
11305 row
->x
= x
- it
->first_visible_x
;
11310 struct glyph
*glyph
;
11312 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
11314 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11315 new_x
= x
+ glyph
->pixel_width
;
11317 if (/* Lines are continued. */
11318 !it
->truncate_lines_p
11319 && (/* Glyph doesn't fit on the line. */
11320 new_x
> it
->last_visible_x
11321 /* Or it fits exactly on a window system frame. */
11322 || (new_x
== it
->last_visible_x
11323 && FRAME_WINDOW_P (it
->f
))))
11325 /* End of a continued line. */
11328 || (new_x
== it
->last_visible_x
11329 && FRAME_WINDOW_P (it
->f
)))
11331 /* Current glyph is the only one on the line or
11332 fits exactly on the line. We must continue
11333 the line because we can't draw the cursor
11334 after the glyph. */
11335 row
->continued_p
= 1;
11336 it
->current_x
= new_x
;
11337 it
->continuation_lines_width
+= new_x
;
11339 if (i
== nglyphs
- 1)
11340 set_iterator_to_next (it
);
11344 /* Display element draws past the right edge of
11345 the window. Restore positions to values
11346 before the element. The next line starts
11347 with current_x before the glyph that could
11348 not be displayed, so that TAB works right. */
11349 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11351 /* Display continuation glyphs. */
11352 if (!FRAME_WINDOW_P (it
->f
))
11353 produce_special_glyphs (it
, IT_CONTINUATION
);
11354 row
->continued_p
= 1;
11357 it
->continuation_lines_width
+= x
;
11359 /* Restore the height to what it was before the
11360 element not fitting on the line. */
11361 it
->max_ascent
= ascent
;
11362 it
->max_descent
= descent
;
11363 it
->max_phys_ascent
= phys_ascent
;
11364 it
->max_phys_descent
= phys_descent
;
11369 else if (new_x
> it
->first_visible_x
)
11371 /* Increment number of glyphs actually displayed. */
11374 if (x
< it
->first_visible_x
)
11375 /* Glyph is partially visible, i.e. row starts at
11376 negative X position. */
11377 row
->x
= x
- it
->first_visible_x
;
11381 /* Glyph is completely off the left margin of the
11382 window. This should not happen because of the
11383 move_it_in_display_line at the start of
11389 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11390 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11391 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11392 row
->phys_height
= max (row
->phys_height
,
11393 it
->max_phys_ascent
+ it
->max_phys_descent
);
11395 /* End of this display line if row is continued. */
11396 if (row
->continued_p
)
11400 /* Is this a line end? If yes, we're also done, after making
11401 sure that a non-default face is extended up to the right
11402 margin of the window. */
11403 if (ITERATOR_AT_END_OF_LINE_P (it
))
11405 int used_before
= row
->used
[TEXT_AREA
];
11407 /* Add a space at the end of the line that is used to
11408 display the cursor there. */
11409 append_space (it
, 0);
11411 /* Extend the face to the end of the line. */
11412 extend_face_to_end_of_line (it
);
11414 /* Make sure we have the position. */
11415 if (used_before
== 0)
11416 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
11418 /* Consume the line end. This skips over invisible lines. */
11419 set_iterator_to_next (it
);
11420 it
->continuation_lines_width
= 0;
11424 /* Proceed with next display element. Note that this skips
11425 over lines invisible because of selective display. */
11426 set_iterator_to_next (it
);
11428 /* If we truncate lines, we are done when the last displayed
11429 glyphs reach past the right margin of the window. */
11430 if (it
->truncate_lines_p
11431 && (FRAME_WINDOW_P (it
->f
)
11432 ? (it
->current_x
>= it
->last_visible_x
)
11433 : (it
->current_x
> it
->last_visible_x
)))
11435 /* Maybe add truncation glyphs. */
11436 if (!FRAME_WINDOW_P (it
->f
))
11438 --it
->glyph_row
->used
[TEXT_AREA
];
11439 produce_special_glyphs (it
, IT_TRUNCATION
);
11442 row
->truncated_on_right_p
= 1;
11443 it
->continuation_lines_width
= 0;
11444 reseat_at_next_visible_line_start (it
, 0);
11445 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
11446 it
->hpos
= hpos_before
;
11447 it
->current_x
= x_before
;
11452 /* If line is not empty and hscrolled, maybe insert truncation glyphs
11453 at the left window margin. */
11454 if (it
->first_visible_x
11455 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
11457 if (!FRAME_WINDOW_P (it
->f
))
11458 insert_left_trunc_glyphs (it
);
11459 row
->truncated_on_left_p
= 1;
11462 /* If the start of this line is the overlay arrow-position, then
11463 mark this glyph row as the one containing the overlay arrow.
11464 This is clearly a mess with variable size fonts. It would be
11465 better to let it be displayed like cursors under X. */
11466 if (MARKERP (Voverlay_arrow_position
)
11467 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
11468 && (MATRIX_ROW_START_CHARPOS (row
)
11469 == marker_position (Voverlay_arrow_position
))
11470 && STRINGP (Voverlay_arrow_string
)
11471 && ! overlay_arrow_seen
)
11473 /* Overlay arrow in window redisplay is a bitmap. */
11474 if (!FRAME_WINDOW_P (it
->f
))
11476 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
11477 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
11478 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
11479 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
11480 struct glyph
*p2
, *end
;
11482 /* Copy the arrow glyphs. */
11483 while (glyph
< arrow_end
)
11486 /* Throw away padding glyphs. */
11488 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
11489 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
11495 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
11499 overlay_arrow_seen
= 1;
11500 row
->overlay_arrow_p
= 1;
11503 /* Compute pixel dimensions of this line. */
11504 compute_line_metrics (it
);
11506 /* Remember the position at which this line ends. */
11507 row
->end
= it
->current
;
11509 /* Maybe set the cursor. If you change this, it's probably a good
11510 idea to also change the code in redisplay_window for cursor
11511 movement in an unchanged window. */
11512 if (it
->w
->cursor
.vpos
< 0
11513 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
11514 && MATRIX_ROW_END_CHARPOS (row
) >= PT
11515 && !(MATRIX_ROW_END_CHARPOS (row
) == PT
11516 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11517 || !row
->ends_at_zv_p
)))
11518 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
11520 /* Highlight trailing whitespace. */
11521 if (!NILP (Vshow_trailing_whitespace
))
11522 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
11524 /* Prepare for the next line. This line starts horizontally at (X
11525 HPOS) = (0 0). Vertical positions are incremented. As a
11526 convenience for the caller, IT->glyph_row is set to the next
11528 it
->current_x
= it
->hpos
= 0;
11529 it
->current_y
+= row
->height
;
11532 return row
->displays_text_p
;
11537 /***********************************************************************
11539 ***********************************************************************/
11541 /* Redisplay the menu bar in the frame for window W.
11543 The menu bar of X frames that don't have X toolkit support is
11544 displayed in a special window W->frame->menu_bar_window.
11546 The menu bar of terminal frames is treated specially as far as
11547 glyph matrices are concerned. Menu bar lines are not part of
11548 windows, so the update is done directly on the frame matrix rows
11549 for the menu bar. */
11552 display_menu_bar (w
)
11555 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11560 /* Don't do all this for graphical frames. */
11562 if (!NILP (Vwindow_system
))
11565 #ifdef USE_X_TOOLKIT
11570 #ifdef USE_X_TOOLKIT
11571 xassert (!FRAME_WINDOW_P (f
));
11572 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
11573 it
.first_visible_x
= 0;
11574 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11575 #else /* not USE_X_TOOLKIT */
11576 if (FRAME_WINDOW_P (f
))
11578 /* Menu bar lines are displayed in the desired matrix of the
11579 dummy window menu_bar_window. */
11580 struct window
*menu_w
;
11581 xassert (WINDOWP (f
->menu_bar_window
));
11582 menu_w
= XWINDOW (f
->menu_bar_window
);
11583 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
11585 it
.first_visible_x
= 0;
11586 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11590 /* This is a TTY frame, i.e. character hpos/vpos are used as
11592 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
11594 it
.first_visible_x
= 0;
11595 it
.last_visible_x
= FRAME_WIDTH (f
);
11597 #endif /* not USE_X_TOOLKIT */
11599 /* Clear all rows of the menu bar. */
11600 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
11602 struct glyph_row
*row
= it
.glyph_row
+ i
;
11603 clear_glyph_row (row
);
11604 row
->enabled_p
= 1;
11605 row
->full_width_p
= 1;
11608 /* Make the first line of the menu bar appear in reverse video. */
11609 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11611 /* Display all items of the menu bar. */
11612 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
11613 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
11615 Lisp_Object string
;
11617 /* Stop at nil string. */
11618 string
= XVECTOR (items
)->contents
[i
+ 1];
11622 /* Remember where item was displayed. */
11623 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
11625 /* Display the item, pad with one space. */
11626 if (it
.current_x
< it
.last_visible_x
)
11627 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
11628 XSTRING (string
)->size
+ 1, 0, 0, -1);
11631 /* Fill out the line with spaces. */
11632 if (it
.current_x
< it
.last_visible_x
)
11633 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
11635 /* Compute the total height of the lines. */
11636 compute_line_metrics (&it
);
11641 /***********************************************************************
11643 ***********************************************************************/
11645 /* Display the mode and/or top line of window W. */
11648 display_mode_lines (w
)
11651 /* These will be set while the mode line specs are processed. */
11652 line_number_displayed
= 0;
11653 w
->column_number_displayed
= Qnil
;
11655 if (WINDOW_WANTS_MODELINE_P (w
))
11656 display_mode_line (w
, MODE_LINE_FACE_ID
,
11657 current_buffer
->mode_line_format
);
11659 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11660 display_mode_line (w
, HEADER_LINE_FACE_ID
,
11661 current_buffer
->header_line_format
);
11665 /* Display mode or top line of window W. FACE_ID specifies which line
11666 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
11667 FORMAT is the mode line format to display. */
11670 display_mode_line (w
, face_id
, format
)
11672 enum face_id face_id
;
11673 Lisp_Object format
;
11678 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
11679 prepare_desired_row (it
.glyph_row
);
11681 /* Temporarily make frame's keyboard the current kboard so that
11682 kboard-local variables in the mode_line_format will get the right
11684 push_frame_kboard (it
.f
);
11685 display_mode_element (&it
, 0, 0, 0, format
);
11686 pop_frame_kboard ();
11688 /* Fill up with spaces. */
11689 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
11691 compute_line_metrics (&it
);
11692 it
.glyph_row
->full_width_p
= 1;
11693 it
.glyph_row
->mode_line_p
= 1;
11694 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11695 it
.glyph_row
->continued_p
= 0;
11696 it
.glyph_row
->truncated_on_left_p
= 0;
11697 it
.glyph_row
->truncated_on_right_p
= 0;
11699 /* Make a 3D mode-line have a shadow at its right end. */
11700 face
= FACE_FROM_ID (it
.f
, face_id
);
11701 extend_face_to_end_of_line (&it
);
11702 if (face
->box
!= FACE_NO_BOX
)
11704 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
11705 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
11706 last
->right_box_line_p
= 1;
11711 /* Contribute ELT to the mode line for window IT->w. How it
11712 translates into text depends on its data type.
11714 IT describes the display environment in which we display, as usual.
11716 DEPTH is the depth in recursion. It is used to prevent
11717 infinite recursion here.
11719 FIELD_WIDTH is the number of characters the display of ELT should
11720 occupy in the mode line, and PRECISION is the maximum number of
11721 characters to display from ELT's representation. See
11722 display_string for details. *
11724 Returns the hpos of the end of the text generated by ELT. */
11727 display_mode_element (it
, depth
, field_width
, precision
, elt
)
11730 int field_width
, precision
;
11733 int n
= 0, field
, prec
;
11741 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
11745 /* A string: output it and check for %-constructs within it. */
11747 unsigned char *this = XSTRING (elt
)->data
;
11748 unsigned char *lisp_string
= this;
11750 while ((precision
<= 0 || n
< precision
)
11752 && (frame_title_ptr
11753 || it
->current_x
< it
->last_visible_x
))
11755 unsigned char *last
= this;
11757 /* Advance to end of string or next format specifier. */
11758 while ((c
= *this++) != '\0' && c
!= '%')
11761 if (this - 1 != last
)
11763 /* Output to end of string or up to '%'. Field width
11764 is length of string. Don't output more than
11765 PRECISION allows us. */
11766 prec
= --this - last
;
11767 if (precision
> 0 && prec
> precision
- n
)
11768 prec
= precision
- n
;
11770 if (frame_title_ptr
)
11771 n
+= store_frame_title (last
, prec
, prec
);
11773 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
11774 it
, 0, prec
, 0, -1);
11776 else /* c == '%' */
11778 unsigned char *percent_position
= this;
11780 /* Get the specified minimum width. Zero means
11783 while ((c
= *this++) >= '0' && c
<= '9')
11784 field
= field
* 10 + c
- '0';
11786 /* Don't pad beyond the total padding allowed. */
11787 if (field_width
- n
> 0 && field
> field_width
- n
)
11788 field
= field_width
- n
;
11790 /* Note that either PRECISION <= 0 or N < PRECISION. */
11791 prec
= precision
- n
;
11794 n
+= display_mode_element (it
, depth
, field
, prec
,
11795 Vglobal_mode_string
);
11798 unsigned char *spec
11799 = decode_mode_spec (it
->w
, c
, field
, prec
);
11801 if (frame_title_ptr
)
11802 n
+= store_frame_title (spec
, field
, prec
);
11806 = it
->glyph_row
->used
[TEXT_AREA
];
11808 = percent_position
- XSTRING (elt
)->data
;
11810 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
11811 field
, prec
, 0, -1);
11813 /* Assign to the glyphs written above the
11814 string where the `%x' came from, position
11818 struct glyph
*glyph
11819 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
11823 for (i
= 0; i
< nwritten
; ++i
)
11825 glyph
[i
].object
= elt
;
11826 glyph
[i
].charpos
= charpos
;
11839 /* A symbol: process the value of the symbol recursively
11840 as if it appeared here directly. Avoid error if symbol void.
11841 Special case: if value of symbol is a string, output the string
11844 register Lisp_Object tem
;
11845 tem
= Fboundp (elt
);
11848 tem
= Fsymbol_value (elt
);
11849 /* If value is a string, output that string literally:
11850 don't check for % within it. */
11853 prec
= XSTRING (tem
)->size
;
11854 if (precision
> 0 && prec
> precision
- n
)
11855 prec
= precision
- n
;
11856 if (frame_title_ptr
)
11857 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
11859 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
11862 else if (!EQ (tem
, elt
))
11864 /* Give up right away for nil or t. */
11874 register Lisp_Object car
, tem
;
11876 /* A cons cell: three distinct cases.
11877 If first element is a string or a cons, process all the elements
11878 and effectively concatenate them.
11879 If first element is a negative number, truncate displaying cdr to
11880 at most that many characters. If positive, pad (with spaces)
11881 to at least that many characters.
11882 If first element is a symbol, process the cadr or caddr recursively
11883 according to whether the symbol's value is non-nil or nil. */
11885 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
11887 /* An element of the form (:eval FORM) means evaluate FORM
11888 and use the result as mode line elements. */
11889 struct gcpro gcpro1
;
11892 spec
= eval_form (XCAR (XCDR (elt
)));
11894 n
+= display_mode_element (it
, depth
, field_width
- n
,
11895 precision
- n
, spec
);
11898 else if (SYMBOLP (car
))
11900 tem
= Fboundp (car
);
11904 /* elt is now the cdr, and we know it is a cons cell.
11905 Use its car if CAR has a non-nil value. */
11908 tem
= Fsymbol_value (car
);
11915 /* Symbol's value is nil (or symbol is unbound)
11916 Get the cddr of the original list
11917 and if possible find the caddr and use that. */
11921 else if (!CONSP (elt
))
11926 else if (INTEGERP (car
))
11928 register int lim
= XINT (car
);
11932 /* Negative int means reduce maximum width. */
11933 if (precision
<= 0)
11936 precision
= min (precision
, -lim
);
11940 /* Padding specified. Don't let it be more than
11941 current maximum. */
11943 lim
= min (precision
, lim
);
11945 /* If that's more padding than already wanted, queue it.
11946 But don't reduce padding already specified even if
11947 that is beyond the current truncation point. */
11948 field_width
= max (lim
, field_width
);
11952 else if (STRINGP (car
) || CONSP (car
))
11954 register int limit
= 50;
11955 /* Limit is to protect against circular lists. */
11958 && (precision
<= 0 || n
< precision
))
11960 n
+= display_mode_element (it
, depth
, field_width
- n
,
11961 precision
- n
, XCAR (elt
));
11970 if (frame_title_ptr
)
11971 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
11973 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
11974 precision
- n
, 0, 0);
11978 /* Pad to FIELD_WIDTH. */
11979 if (field_width
> 0 && n
< field_width
)
11981 if (frame_title_ptr
)
11982 n
+= store_frame_title ("", field_width
- n
, 0);
11984 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
11992 /* Write a null-terminated, right justified decimal representation of
11993 the positive integer D to BUF using a minimal field width WIDTH. */
11996 pint2str (buf
, width
, d
)
11997 register char *buf
;
11998 register int width
;
12001 register char *p
= buf
;
12009 *p
++ = d
% 10 + '0';
12014 for (width
-= (int) (p
- buf
); width
> 0; --width
)
12025 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
12026 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
12027 type of CODING_SYSTEM. Return updated pointer into BUF. */
12029 static unsigned char invalid_eol_type
[] = "(*invalid*)";
12032 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
12033 Lisp_Object coding_system
;
12034 register char *buf
;
12038 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
12039 unsigned char *eol_str
;
12041 /* The EOL conversion we are using. */
12042 Lisp_Object eoltype
;
12044 val
= Fget (coding_system
, Qcoding_system
);
12046 if (!VECTORP (val
)) /* Not yet decided. */
12051 eoltype
= eol_mnemonic_undecided
;
12052 /* Don't mention EOL conversion if it isn't decided. */
12056 Lisp_Object eolvalue
;
12058 eolvalue
= Fget (coding_system
, Qeol_type
);
12061 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
12065 /* The EOL conversion that is normal on this system. */
12067 if (NILP (eolvalue
)) /* Not yet decided. */
12068 eoltype
= eol_mnemonic_undecided
;
12069 else if (VECTORP (eolvalue
)) /* Not yet decided. */
12070 eoltype
= eol_mnemonic_undecided
;
12071 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
12072 eoltype
= (XFASTINT (eolvalue
) == 0
12073 ? eol_mnemonic_unix
12074 : (XFASTINT (eolvalue
) == 1
12075 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
12081 /* Mention the EOL conversion if it is not the usual one. */
12082 if (STRINGP (eoltype
))
12084 eol_str
= XSTRING (eoltype
)->data
;
12085 eol_str_len
= XSTRING (eoltype
)->size
;
12087 else if (INTEGERP (eoltype
)
12088 && CHAR_VALID_P (XINT (eoltype
), 0))
12090 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
12091 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
12095 eol_str
= invalid_eol_type
;
12096 eol_str_len
= sizeof (invalid_eol_type
) - 1;
12098 bcopy (eol_str
, buf
, eol_str_len
);
12099 buf
+= eol_str_len
;
12105 /* Return a string for the output of a mode line %-spec for window W,
12106 generated by character C. PRECISION >= 0 means don't return a
12107 string longer than that value. FIELD_WIDTH > 0 means pad the
12108 string returned with spaces to that value. */
12110 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
12113 decode_mode_spec (w
, c
, field_width
, precision
)
12116 int field_width
, precision
;
12119 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12120 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
12121 struct buffer
*b
= XBUFFER (w
->buffer
);
12128 if (!NILP (b
->read_only
))
12130 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12135 /* This differs from %* only for a modified read-only buffer. */
12136 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12138 if (!NILP (b
->read_only
))
12143 /* This differs from %* in ignoring read-only-ness. */
12144 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12156 if (command_loop_level
> 5)
12158 p
= decode_mode_spec_buf
;
12159 for (i
= 0; i
< command_loop_level
; i
++)
12162 return decode_mode_spec_buf
;
12170 if (command_loop_level
> 5)
12172 p
= decode_mode_spec_buf
;
12173 for (i
= 0; i
< command_loop_level
; i
++)
12176 return decode_mode_spec_buf
;
12183 /* Let lots_of_dashes be a string of infinite length. */
12184 if (field_width
<= 0
12185 || field_width
> sizeof (lots_of_dashes
))
12187 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
12188 decode_mode_spec_buf
[i
] = '-';
12189 decode_mode_spec_buf
[i
] = '\0';
12190 return decode_mode_spec_buf
;
12193 return lots_of_dashes
;
12202 int col
= current_column ();
12203 XSETFASTINT (w
->column_number_displayed
, col
);
12204 pint2str (decode_mode_spec_buf
, field_width
, col
);
12205 return decode_mode_spec_buf
;
12209 /* %F displays the frame name. */
12210 if (!NILP (f
->title
))
12211 return (char *) XSTRING (f
->title
)->data
;
12212 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
12213 return (char *) XSTRING (f
->name
)->data
;
12222 int startpos
= XMARKER (w
->start
)->charpos
;
12223 int startpos_byte
= marker_byte_position (w
->start
);
12224 int line
, linepos
, linepos_byte
, topline
;
12226 int height
= XFASTINT (w
->height
);
12228 /* If we decided that this buffer isn't suitable for line numbers,
12229 don't forget that too fast. */
12230 if (EQ (w
->base_line_pos
, w
->buffer
))
12232 /* But do forget it, if the window shows a different buffer now. */
12233 else if (BUFFERP (w
->base_line_pos
))
12234 w
->base_line_pos
= Qnil
;
12236 /* If the buffer is very big, don't waste time. */
12237 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
12239 w
->base_line_pos
= Qnil
;
12240 w
->base_line_number
= Qnil
;
12244 if (!NILP (w
->base_line_number
)
12245 && !NILP (w
->base_line_pos
)
12246 && XFASTINT (w
->base_line_pos
) <= startpos
)
12248 line
= XFASTINT (w
->base_line_number
);
12249 linepos
= XFASTINT (w
->base_line_pos
);
12250 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
12255 linepos
= BUF_BEGV (b
);
12256 linepos_byte
= BUF_BEGV_BYTE (b
);
12259 /* Count lines from base line to window start position. */
12260 nlines
= display_count_lines (linepos
, linepos_byte
,
12264 topline
= nlines
+ line
;
12266 /* Determine a new base line, if the old one is too close
12267 or too far away, or if we did not have one.
12268 "Too close" means it's plausible a scroll-down would
12269 go back past it. */
12270 if (startpos
== BUF_BEGV (b
))
12272 XSETFASTINT (w
->base_line_number
, topline
);
12273 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
12275 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
12276 || linepos
== BUF_BEGV (b
))
12278 int limit
= BUF_BEGV (b
);
12279 int limit_byte
= BUF_BEGV_BYTE (b
);
12281 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
12283 if (startpos
- distance
> limit
)
12285 limit
= startpos
- distance
;
12286 limit_byte
= CHAR_TO_BYTE (limit
);
12289 nlines
= display_count_lines (startpos
, startpos_byte
,
12291 - (height
* 2 + 30),
12293 /* If we couldn't find the lines we wanted within
12294 line_number_display_limit_width chars per line,
12295 give up on line numbers for this window. */
12296 if (position
== limit_byte
&& limit
== startpos
- distance
)
12298 w
->base_line_pos
= w
->buffer
;
12299 w
->base_line_number
= Qnil
;
12303 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
12304 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
12307 /* Now count lines from the start pos to point. */
12308 nlines
= display_count_lines (startpos
, startpos_byte
,
12309 PT_BYTE
, PT
, &junk
);
12311 /* Record that we did display the line number. */
12312 line_number_displayed
= 1;
12314 /* Make the string to show. */
12315 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
12316 return decode_mode_spec_buf
;
12319 char* p
= decode_mode_spec_buf
;
12320 int pad
= field_width
- 2;
12325 return decode_mode_spec_buf
;
12331 obj
= b
->mode_name
;
12335 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
12341 int pos
= marker_position (w
->start
);
12342 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12344 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
12346 if (pos
<= BUF_BEGV (b
))
12351 else if (pos
<= BUF_BEGV (b
))
12355 if (total
> 1000000)
12356 /* Do it differently for a large value, to avoid overflow. */
12357 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12359 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12360 /* We can't normally display a 3-digit number,
12361 so get us a 2-digit number that is close. */
12364 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12365 return decode_mode_spec_buf
;
12369 /* Display percentage of size above the bottom of the screen. */
12372 int toppos
= marker_position (w
->start
);
12373 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
12374 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12376 if (botpos
>= BUF_ZV (b
))
12378 if (toppos
<= BUF_BEGV (b
))
12385 if (total
> 1000000)
12386 /* Do it differently for a large value, to avoid overflow. */
12387 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12389 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12390 /* We can't normally display a 3-digit number,
12391 so get us a 2-digit number that is close. */
12394 if (toppos
<= BUF_BEGV (b
))
12395 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
12397 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12398 return decode_mode_spec_buf
;
12403 /* status of process */
12404 obj
= Fget_buffer_process (w
->buffer
);
12406 return "no process";
12407 #ifdef subprocesses
12408 obj
= Fsymbol_name (Fprocess_status (obj
));
12412 case 't': /* indicate TEXT or BINARY */
12413 #ifdef MODE_LINE_BINARY_TEXT
12414 return MODE_LINE_BINARY_TEXT (b
);
12420 /* coding-system (not including end-of-line format) */
12422 /* coding-system (including end-of-line type) */
12424 int eol_flag
= (c
== 'Z');
12425 char *p
= decode_mode_spec_buf
;
12427 if (! FRAME_WINDOW_P (f
))
12429 /* No need to mention EOL here--the terminal never needs
12430 to do EOL conversion. */
12431 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
12432 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
12434 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
12437 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
12438 #ifdef subprocesses
12439 obj
= Fget_buffer_process (Fcurrent_buffer ());
12440 if (PROCESSP (obj
))
12442 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
12444 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
12447 #endif /* subprocesses */
12450 return decode_mode_spec_buf
;
12455 return (char *) XSTRING (obj
)->data
;
12461 /* Count up to COUNT lines starting from START / START_BYTE.
12462 But don't go beyond LIMIT_BYTE.
12463 Return the number of lines thus found (always nonnegative).
12465 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
12468 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
12469 int start
, start_byte
, limit_byte
, count
;
12472 register unsigned char *cursor
;
12473 unsigned char *base
;
12475 register int ceiling
;
12476 register unsigned char *ceiling_addr
;
12477 int orig_count
= count
;
12479 /* If we are not in selective display mode,
12480 check only for newlines. */
12481 int selective_display
= (!NILP (current_buffer
->selective_display
)
12482 && !INTEGERP (current_buffer
->selective_display
));
12486 while (start_byte
< limit_byte
)
12488 ceiling
= BUFFER_CEILING_OF (start_byte
);
12489 ceiling
= min (limit_byte
- 1, ceiling
);
12490 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
12491 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
12494 if (selective_display
)
12495 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
12498 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
12501 if (cursor
!= ceiling_addr
)
12505 start_byte
+= cursor
- base
+ 1;
12506 *byte_pos_ptr
= start_byte
;
12510 if (++cursor
== ceiling_addr
)
12516 start_byte
+= cursor
- base
;
12521 while (start_byte
> limit_byte
)
12523 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
12524 ceiling
= max (limit_byte
, ceiling
);
12525 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
12526 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
12529 if (selective_display
)
12530 while (--cursor
!= ceiling_addr
12531 && *cursor
!= '\n' && *cursor
!= 015)
12534 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
12537 if (cursor
!= ceiling_addr
)
12541 start_byte
+= cursor
- base
+ 1;
12542 *byte_pos_ptr
= start_byte
;
12543 /* When scanning backwards, we should
12544 not count the newline posterior to which we stop. */
12545 return - orig_count
- 1;
12551 /* Here we add 1 to compensate for the last decrement
12552 of CURSOR, which took it past the valid range. */
12553 start_byte
+= cursor
- base
+ 1;
12557 *byte_pos_ptr
= limit_byte
;
12560 return - orig_count
+ count
;
12561 return orig_count
- count
;
12567 /***********************************************************************
12569 ***********************************************************************/
12571 /* Display a NUL-terminated string, starting with index START.
12573 If STRING is non-null, display that C string. Otherwise, the Lisp
12574 string LISP_STRING is displayed.
12576 If FACE_STRING is not nil, FACE_STRING_POS is a position in
12577 FACE_STRING. Display STRING or LISP_STRING with the face at
12578 FACE_STRING_POS in FACE_STRING:
12580 Display the string in the environment given by IT, but use the
12581 standard display table, temporarily.
12583 FIELD_WIDTH is the minimum number of output glyphs to produce.
12584 If STRING has fewer characters than FIELD_WIDTH, pad to the right
12585 with spaces. If STRING has more characters, more than FIELD_WIDTH
12586 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
12588 PRECISION is the maximum number of characters to output from
12589 STRING. PRECISION < 0 means don't truncate the string.
12591 This is roughly equivalent to printf format specifiers:
12593 FIELD_WIDTH PRECISION PRINTF
12594 ----------------------------------------
12600 MULTIBYTE zero means do not display multibyte chars, > 0 means do
12601 display them, and < 0 means obey the current buffer's value of
12602 enable_multibyte_characters.
12604 Value is the number of glyphs produced. */
12607 display_string (string
, lisp_string
, face_string
, face_string_pos
,
12608 start
, it
, field_width
, precision
, max_x
, multibyte
)
12609 unsigned char *string
;
12610 Lisp_Object lisp_string
;
12611 Lisp_Object face_string
;
12612 int face_string_pos
;
12615 int field_width
, precision
, max_x
;
12618 int hpos_at_start
= it
->hpos
;
12619 int saved_face_id
= it
->face_id
;
12620 struct glyph_row
*row
= it
->glyph_row
;
12622 /* Initialize the iterator IT for iteration over STRING beginning
12623 with index START. We assume that IT may be modified here (which
12624 means that display_line has to do something when displaying a
12625 mini-buffer prompt, which it does). */
12626 reseat_to_string (it
, string
, lisp_string
, start
,
12627 precision
, field_width
, multibyte
);
12629 /* If displaying STRING, set up the face of the iterator
12630 from LISP_STRING, if that's given. */
12631 if (STRINGP (face_string
))
12637 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
12638 0, it
->region_beg_charpos
,
12639 it
->region_end_charpos
,
12640 &endptr
, it
->base_face_id
);
12641 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12642 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
12645 /* Set max_x to the maximum allowed X position. Don't let it go
12646 beyond the right edge of the window. */
12648 max_x
= it
->last_visible_x
;
12650 max_x
= min (max_x
, it
->last_visible_x
);
12652 /* Skip over display elements that are not visible. because IT->w is
12654 if (it
->current_x
< it
->first_visible_x
)
12655 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
12656 MOVE_TO_POS
| MOVE_TO_X
);
12658 row
->ascent
= it
->max_ascent
;
12659 row
->height
= it
->max_ascent
+ it
->max_descent
;
12660 row
->phys_ascent
= it
->max_phys_ascent
;
12661 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12663 /* This condition is for the case that we are called with current_x
12664 past last_visible_x. */
12665 while (it
->current_x
< max_x
)
12667 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
12669 /* Get the next display element. */
12670 if (!get_next_display_element (it
))
12673 /* Produce glyphs. */
12674 x_before
= it
->current_x
;
12675 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
12676 PRODUCE_GLYPHS (it
);
12678 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
12681 while (i
< nglyphs
)
12683 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12685 if (!it
->truncate_lines_p
12686 && x
+ glyph
->pixel_width
> max_x
)
12688 /* End of continued line or max_x reached. */
12689 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12693 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
12695 /* Glyph is at least partially visible. */
12697 if (x
< it
->first_visible_x
)
12698 it
->glyph_row
->x
= x
- it
->first_visible_x
;
12702 /* Glyph is off the left margin of the display area.
12703 Should not happen. */
12707 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12708 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12709 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12710 row
->phys_height
= max (row
->phys_height
,
12711 it
->max_phys_ascent
+ it
->max_phys_descent
);
12712 x
+= glyph
->pixel_width
;
12716 /* Stop if max_x reached. */
12720 /* Stop at line ends. */
12721 if (ITERATOR_AT_END_OF_LINE_P (it
))
12723 it
->continuation_lines_width
= 0;
12727 set_iterator_to_next (it
);
12729 /* Stop if truncating at the right edge. */
12730 if (it
->truncate_lines_p
12731 && it
->current_x
>= it
->last_visible_x
)
12733 /* Add truncation mark, but don't do it if the line is
12734 truncated at a padding space. */
12735 if (IT_CHARPOS (*it
) < it
->string_nchars
)
12737 if (!FRAME_WINDOW_P (it
->f
))
12738 produce_special_glyphs (it
, IT_TRUNCATION
);
12739 it
->glyph_row
->truncated_on_right_p
= 1;
12745 /* Maybe insert a truncation at the left. */
12746 if (it
->first_visible_x
12747 && IT_CHARPOS (*it
) > 0)
12749 if (!FRAME_WINDOW_P (it
->f
))
12750 insert_left_trunc_glyphs (it
);
12751 it
->glyph_row
->truncated_on_left_p
= 1;
12754 it
->face_id
= saved_face_id
;
12756 /* Value is number of columns displayed. */
12757 return it
->hpos
- hpos_at_start
;
12762 /* This is like a combination of memq and assq. Return 1 if PROPVAL
12763 appears as an element of LIST or as the car of an element of LIST.
12764 If PROPVAL is a list, compare each element against LIST in that
12765 way, and return 1 if any element of PROPVAL is found in LIST.
12766 Otherwise return 0. This function cannot quit. */
12769 invisible_p (propval
, list
)
12770 register Lisp_Object propval
;
12773 register Lisp_Object tail
, proptail
;
12774 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12776 register Lisp_Object tem
;
12778 if (EQ (propval
, tem
))
12780 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
12783 if (CONSP (propval
))
12784 for (proptail
= propval
; CONSP (proptail
);
12785 proptail
= XCDR (proptail
))
12787 Lisp_Object propelt
;
12788 propelt
= XCAR (proptail
);
12789 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12791 register Lisp_Object tem
;
12793 if (EQ (propelt
, tem
))
12795 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
12803 /* Return 1 if PROPVAL appears as the car of an element of LIST and
12804 the cdr of that element is non-nil. If PROPVAL is a list, check
12805 each element of PROPVAL in that way, and the first time some
12806 element is found, return 1 if the cdr of that element is non-nil.
12807 Otherwise return 0. This function cannot quit. */
12810 invisible_ellipsis_p (propval
, list
)
12811 register Lisp_Object propval
;
12814 register Lisp_Object tail
, proptail
;
12816 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12818 register Lisp_Object tem
;
12820 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
12821 return ! NILP (XCDR (tem
));
12824 if (CONSP (propval
))
12825 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
12827 Lisp_Object propelt
;
12828 propelt
= XCAR (proptail
);
12829 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12831 register Lisp_Object tem
;
12833 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
12834 return ! NILP (XCDR (tem
));
12843 /***********************************************************************
12845 ***********************************************************************/
12850 Vwith_echo_area_save_vector
= Qnil
;
12851 staticpro (&Vwith_echo_area_save_vector
);
12853 Vmessage_stack
= Qnil
;
12854 staticpro (&Vmessage_stack
);
12856 Qinhibit_redisplay
= intern ("inhibit-redisplay");
12857 staticpro (&Qinhibit_redisplay
);
12860 defsubr (&Sdump_glyph_matrix
);
12861 defsubr (&Sdump_glyph_row
);
12862 defsubr (&Sdump_tool_bar_row
);
12863 defsubr (&Strace_redisplay_toggle
);
12864 defsubr (&Strace_to_stderr
);
12867 staticpro (&Qmenu_bar_update_hook
);
12868 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
12870 staticpro (&Qoverriding_terminal_local_map
);
12871 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
12873 staticpro (&Qoverriding_local_map
);
12874 Qoverriding_local_map
= intern ("overriding-local-map");
12876 staticpro (&Qwindow_scroll_functions
);
12877 Qwindow_scroll_functions
= intern ("window-scroll-functions");
12879 staticpro (&Qredisplay_end_trigger_functions
);
12880 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
12882 staticpro (&Qinhibit_point_motion_hooks
);
12883 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
12885 QCdata
= intern (":data");
12886 staticpro (&QCdata
);
12887 Qdisplay
= intern ("display");
12888 staticpro (&Qdisplay
);
12889 Qspace_width
= intern ("space-width");
12890 staticpro (&Qspace_width
);
12891 Qraise
= intern ("raise");
12892 staticpro (&Qraise
);
12893 Qspace
= intern ("space");
12894 staticpro (&Qspace
);
12895 Qmargin
= intern ("margin");
12896 staticpro (&Qmargin
);
12897 Qleft_margin
= intern ("left-margin");
12898 staticpro (&Qleft_margin
);
12899 Qright_margin
= intern ("right-margin");
12900 staticpro (&Qright_margin
);
12901 Qalign_to
= intern ("align-to");
12902 staticpro (&Qalign_to
);
12903 QCalign_to
= intern (":align-to");
12904 staticpro (&QCalign_to
);
12905 Qrelative_width
= intern ("relative-width");
12906 staticpro (&Qrelative_width
);
12907 QCrelative_width
= intern (":relative-width");
12908 staticpro (&QCrelative_width
);
12909 QCrelative_height
= intern (":relative-height");
12910 staticpro (&QCrelative_height
);
12911 QCeval
= intern (":eval");
12912 staticpro (&QCeval
);
12913 Qwhen
= intern ("when");
12914 staticpro (&Qwhen
);
12915 QCfile
= intern (":file");
12916 staticpro (&QCfile
);
12917 Qfontified
= intern ("fontified");
12918 staticpro (&Qfontified
);
12919 Qfontification_functions
= intern ("fontification-functions");
12920 staticpro (&Qfontification_functions
);
12921 Qtrailing_whitespace
= intern ("trailing-whitespace");
12922 staticpro (&Qtrailing_whitespace
);
12923 Qimage
= intern ("image");
12924 staticpro (&Qimage
);
12926 last_arrow_position
= Qnil
;
12927 last_arrow_string
= Qnil
;
12928 staticpro (&last_arrow_position
);
12929 staticpro (&last_arrow_string
);
12931 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
12932 staticpro (&echo_buffer
[0]);
12933 staticpro (&echo_buffer
[1]);
12935 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
12936 staticpro (&echo_area_buffer
[0]);
12937 staticpro (&echo_area_buffer
[1]);
12939 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
12940 "Non-nil means highlight trailing whitespace.\n\
12941 The face used for trailing whitespace is `trailing-whitespace'.");
12942 Vshow_trailing_whitespace
= Qnil
;
12944 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
12945 "Non-nil means don't actually do any redisplay.\n\
12946 This is used for internal purposes.");
12947 Vinhibit_redisplay
= Qnil
;
12949 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
12950 "String (or mode line construct) included (normally) in `mode-line-format'.");
12951 Vglobal_mode_string
= Qnil
;
12953 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
12954 "Marker for where to display an arrow on top of the buffer text.\n\
12955 This must be the beginning of a line in order to work.\n\
12956 See also `overlay-arrow-string'.");
12957 Voverlay_arrow_position
= Qnil
;
12959 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
12960 "String to display as an arrow. See also `overlay-arrow-position'.");
12961 Voverlay_arrow_string
= Qnil
;
12963 DEFVAR_INT ("scroll-step", &scroll_step
,
12964 "*The number of lines to try scrolling a window by when point moves out.\n\
12965 If that fails to bring point back on frame, point is centered instead.\n\
12966 If this is zero, point is always centered after it moves off frame.");
12968 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
12969 "*Scroll up to this many lines, to bring point back on screen.\n\
12970 A value of zero means to scroll the text to center point vertically\n\
12972 scroll_conservatively
= 0;
12974 DEFVAR_INT ("scroll-margin", &scroll_margin
,
12975 "*Number of lines of margin at the top and bottom of a window.\n\
12976 Recenter the window whenever point gets within this many lines\n\
12977 of the top or bottom of the window.");
12981 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
12984 DEFVAR_BOOL ("truncate-partial-width-windows",
12985 &truncate_partial_width_windows
,
12986 "*Non-nil means truncate lines in all windows less than full frame wide.");
12987 truncate_partial_width_windows
= 1;
12989 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
12990 "*Non-nil means use inverse video for the mode line.");
12991 mode_line_inverse_video
= 1;
12993 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
12994 "*Maximum buffer size for which line number should be displayed.\n\
12995 If the buffer is bigger than this, the line number does not appear\n\
12996 in the mode line.");
12997 line_number_display_limit
= 1000000;
12999 DEFVAR_INT ("line-number-display-limit-width", &line_number_display_limit_width
,
13000 "*Maximum line width (in characters) for line number display.\n\
13001 If the average length of the lines near point is bigger than this, then the\n\
13002 line number may be omitted from the mode line.");
13003 line_number_display_limit_width
= 200;
13005 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
13006 "*Non-nil means highlight region even in nonselected windows.");
13007 highlight_nonselected_windows
= 0;
13009 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
13010 "Non-nil if more than one frame is visible on this display.\n\
13011 Minibuffer-only frames don't count, but iconified frames do.\n\
13012 This variable is not guaranteed to be accurate except while processing\n\
13013 `frame-title-format' and `icon-title-format'.");
13015 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
13016 "Template for displaying the title bar of visible frames.\n\
13017 \(Assuming the window manager supports this feature.)\n\
13018 This variable has the same structure as `mode-line-format' (which see),\n\
13019 and is used only on frames for which no explicit name has been set\n\
13020 \(see `modify-frame-parameters').");
13021 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
13022 "Template for displaying the title bar of an iconified frame.\n\
13023 \(Assuming the window manager supports this feature.)\n\
13024 This variable has the same structure as `mode-line-format' (which see),\n\
13025 and is used only on frames for which no explicit name has been set\n\
13026 \(see `modify-frame-parameters').");
13028 = Vframe_title_format
13029 = Fcons (intern ("multiple-frames"),
13030 Fcons (build_string ("%b"),
13031 Fcons (Fcons (build_string (""),
13032 Fcons (intern ("invocation-name"),
13033 Fcons (build_string ("@"),
13034 Fcons (intern ("system-name"),
13038 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
13039 "Maximum number of lines to keep in the message log buffer.\n\
13040 If nil, disable message logging. If t, log messages but don't truncate\n\
13041 the buffer when it becomes large.");
13042 XSETFASTINT (Vmessage_log_max
, 50);
13044 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
13045 "Functions called before redisplay, if window sizes have changed.\n\
13046 The value should be a list of functions that take one argument.\n\
13047 Just before redisplay, for each frame, if any of its windows have changed\n\
13048 size since the last redisplay, or have been split or deleted,\n\
13049 all the functions in the list are called, with the frame as argument.");
13050 Vwindow_size_change_functions
= Qnil
;
13052 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
13053 "List of Functions to call before redisplaying a window with scrolling.\n\
13054 Each function is called with two arguments, the window\n\
13055 and its new display-start position. Note that the value of `window-end'\n\
13056 is not valid when these functions are called.");
13057 Vwindow_scroll_functions
= Qnil
;
13059 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
13060 "*Non-nil means automatically resize tool-bars.\n\
13061 This increases a tool-bar's height if not all tool-bar items are visible.\n\
13062 It decreases a tool-bar's height when it would display blank lines\n\
13064 auto_resize_tool_bars_p
= 1;
13066 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
13067 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
13068 auto_raise_tool_bar_buttons_p
= 1;
13070 DEFVAR_INT ("tool-bar-button-margin", &tool_bar_button_margin
,
13071 "*Margin around tool-bar buttons in pixels.");
13072 tool_bar_button_margin
= 1;
13074 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
13075 "Relief thickness of tool-bar buttons.");
13076 tool_bar_button_relief
= 3;
13078 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
13079 "List of functions to call to fontify regions of text.\n\
13080 Each function is called with one argument POS. Functions must\n\
13081 fontify a region starting at POS in the current buffer, and give\n\
13082 fontified regions the property `fontified'.\n\
13083 This variable automatically becomes buffer-local when set.");
13084 Vfontification_functions
= Qnil
;
13085 Fmake_local_variable (Qfontification_functions
);
13087 DEFVAR_BOOL ("unibyte-display-via-language-environment",
13088 &unibyte_display_via_language_environment
,
13089 "*Non-nil means display unibyte text according to language environment.\n\
13090 Specifically this means that unibyte non-ASCII characters\n\
13091 are displayed by converting them to the equivalent multibyte characters\n\
13092 according to the current language environment. As a result, they are\n\
13093 displayed according to the current fontset.");
13094 unibyte_display_via_language_environment
= 0;
13096 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
13097 "*Maximum height for resizing mini-windows.\n\
13098 If a float, it specifies a fraction of the mini-window frame's height.\n\
13099 If an integer, it specifies a number of lines.\n\
13100 If nil, don't resize.");
13101 Vmax_mini_window_height
= make_float (0.25);
13103 DEFVAR_BOOL ("cursor-in-non-selected-windows",
13104 &cursor_in_non_selected_windows
,
13105 "*Non-nil means display a hollow cursor in non-selected windows.\n\
13106 Nil means don't display a cursor there.");
13107 cursor_in_non_selected_windows
= 1;
13109 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
13110 "*Non-nil means scroll the display automatically to make point visible.");
13111 automatic_hscrolling_p
= 1;
13115 /* Initialize this module when Emacs starts. */
13120 Lisp_Object root_window
;
13121 struct window
*mini_w
;
13123 CHARPOS (this_line_start_pos
) = 0;
13125 mini_w
= XWINDOW (minibuf_window
);
13126 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
13128 if (!noninteractive
)
13130 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
13133 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
13134 set_window_height (root_window
,
13135 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
13137 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
13138 set_window_height (minibuf_window
, 1, 0);
13140 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
13141 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
13143 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
13144 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
13145 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
13147 /* The default ellipsis glyphs `...'. */
13148 for (i
= 0; i
< 3; ++i
)
13149 XSETFASTINT (default_invis_vector
[i
], '.');
13152 #ifdef HAVE_WINDOW_SYSTEM
13154 /* Allocate the buffer for frame titles. */
13156 frame_title_buf
= (char *) xmalloc (size
);
13157 frame_title_buf_end
= frame_title_buf
+ size
;
13158 frame_title_ptr
= NULL
;
13160 #endif /* HAVE_WINDOW_SYSTEM */