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. */
178 #include "termchar.h"
179 #include "dispextern.h"
183 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
188 #include "keyboard.h"
191 #include "region-cache.h"
193 #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
, QCwhen
;
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 toolbar buttons raised when the mouse moves
233 int auto_raise_toolbar_buttons_p
;
235 /* Margin around toolbar buttons in pixels. */
237 int toolbar_button_margin
;
239 /* Thickness of shadow to draw around toolbar buttons. */
241 int toolbar_button_relief
;
243 /* Non-zero means automatically resize toolbars so that all toolbar
244 items are visible, and no blank lines remain. */
246 int auto_resize_toolbars_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
, Qwidth
, Qalign_to
;
255 extern Lisp_Object Qface
, Qinvisible
, Qimage
;
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
, Qheight
, Qraise
;
262 /* Non-nil means highlight trailing whitespace. */
264 Lisp_Object Vshow_trailing_whitespace
;
266 /* Name of the face used to highlight trailing whitespace. */
268 Lisp_Object Qtrailing_whitespace
;
270 /* The symbol `image' which is the car of the lists used to represent
275 /* Non-zero means print newline to stdout before next mini-buffer
278 int noninteractive_need_newline
;
280 /* Non-zero means print newline to message log before next message. */
282 static int message_log_need_newline
;
285 /* The buffer position of the first character appearing entirely or
286 partially on the line of the selected window which contains the
287 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
288 redisplay optimization in redisplay_internal. */
290 static struct text_pos this_line_start_pos
;
292 /* Number of characters past the end of the line above, including the
293 terminating newline. */
295 static struct text_pos this_line_end_pos
;
297 /* The vertical positions and the height of this line. */
299 static int this_line_vpos
;
300 static int this_line_y
;
301 static int this_line_pixel_height
;
303 /* X position at which this display line starts. Usually zero;
304 negative if first character is partially visible. */
306 static int this_line_start_x
;
308 /* Buffer that this_line_.* variables are referring to. */
310 static struct buffer
*this_line_buffer
;
312 /* Nonzero means truncate lines in all windows less wide than the
315 int truncate_partial_width_windows
;
317 /* A flag to control how to display unibyte 8-bit character. */
319 int unibyte_display_via_language_environment
;
321 /* Nonzero means we have more than one non-mini-buffer-only frame.
322 Not guaranteed to be accurate except while parsing
323 frame-title-format. */
327 Lisp_Object Vglobal_mode_string
;
329 /* Marker for where to display an arrow on top of the buffer text. */
331 Lisp_Object Voverlay_arrow_position
;
333 /* String to display for the arrow. Only used on terminal frames. */
335 Lisp_Object Voverlay_arrow_string
;
337 /* Values of those variables at last redisplay. However, if
338 Voverlay_arrow_position is a marker, last_arrow_position is its
339 numerical position. */
341 static Lisp_Object last_arrow_position
, last_arrow_string
;
343 /* Like mode-line-format, but for the title bar on a visible frame. */
345 Lisp_Object Vframe_title_format
;
347 /* Like mode-line-format, but for the title bar on an iconified frame. */
349 Lisp_Object Vicon_title_format
;
351 /* List of functions to call when a window's size changes. These
352 functions get one arg, a frame on which one or more windows' sizes
355 static Lisp_Object Vwindow_size_change_functions
;
357 Lisp_Object Qmenu_bar_update_hook
;
359 /* Nonzero if overlay arrow has been displayed once in this window. */
361 static int overlay_arrow_seen
;
363 /* Nonzero means highlight the region even in nonselected windows. */
365 int highlight_nonselected_windows
;
367 /* If cursor motion alone moves point off frame, try scrolling this
368 many lines up or down if that will bring it back. */
370 static int scroll_step
;
372 /* Non-0 means scroll just far enough to bring point back on the
373 screen, when appropriate. */
375 static int scroll_conservatively
;
377 /* Recenter the window whenever point gets within this many lines of
378 the top or bottom of the window. This value is translated into a
379 pixel value by multiplying it with CANON_Y_UNIT, which means that
380 there is really a fixed pixel height scroll margin. */
384 /* Number of windows showing the buffer of the selected window (or
385 another buffer with the same base buffer). keyboard.c refers to
390 /* Vector containing glyphs for an ellipsis `...'. */
392 static Lisp_Object default_invis_vector
[3];
394 /* Nonzero means display mode line highlighted. */
396 int mode_line_inverse_video
;
398 /* Prompt to display in front of the mini-buffer contents. */
400 Lisp_Object minibuf_prompt
;
402 /* Width of current mini-buffer prompt. Only set after display_line
403 of the line that contains the prompt. */
405 int minibuf_prompt_width
;
406 int minibuf_prompt_pixel_width
;
408 /* This is the window where the echo area message was displayed. It
409 is always a mini-buffer window, but it may not be the same window
410 currently active as a mini-buffer. */
412 Lisp_Object echo_area_window
;
414 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
415 pushes the current message and the value of
416 message_enable_multibyte on the stack, the function restore_message
417 pops the stack and displays MESSAGE again. */
419 Lisp_Object Vmessage_stack
;
421 /* Nonzero means multibyte characters were enabled when the echo area
422 message was specified. */
424 int message_enable_multibyte
;
426 /* True if we should redraw the mode lines on the next redisplay. */
428 int update_mode_lines
;
430 /* Nonzero if window sizes or contents have changed since last
431 redisplay that finished */
433 int windows_or_buffers_changed
;
435 /* Nonzero after display_mode_line if %l was used and it displayed a
438 int line_number_displayed
;
440 /* Maximum buffer size for which to display line numbers. */
442 static int line_number_display_limit
;
444 /* line width to consider when repostioning for line number display */
446 static int line_number_display_limit_width
;
448 /* Number of lines to keep in the message log buffer. t means
449 infinite. nil means don't log at all. */
451 Lisp_Object Vmessage_log_max
;
453 /* Current, index 0, and last displayed echo area message. Either
454 buffers from echo_buffers, or nil to indicate no message. */
456 Lisp_Object echo_area_buffer
[2];
458 /* The buffers referenced from echo_area_buffer. */
460 static Lisp_Object echo_buffer
[2];
462 /* A vector saved used in with_area_buffer to reduce consing. */
464 static Lisp_Object Vwith_echo_area_save_vector
;
466 /* Non-zero means display_echo_area should display the last echo area
467 message again. Set by redisplay_preserve_echo_area. */
469 static int display_last_displayed_message_p
;
471 /* Nonzero if echo area is being used by print; zero if being used by
474 int message_buf_print
;
476 /* Maximum height for resizing mini-windows. Either a float
477 specifying a fraction of the available height, or an integer
478 specifying a number of lines. */
480 static Lisp_Object Vmax_mini_window_height
;
482 /* Window configuration saved in resize_mini_window. */
484 Lisp_Object Vresize_mini_config
;
486 /* Frmae of the mini-window being resized by resize_mini_window. */
488 struct frame
*resize_mini_frame
;
490 /* Initial height of the mini-window having been resized
491 by resize_mini_window. */
493 int resize_mini_initial_height
;
495 /* A scratch glyph row with contents used for generating truncation
496 glyphs. Also used in direct_output_for_insert. */
498 #define MAX_SCRATCH_GLYPHS 100
499 struct glyph_row scratch_glyph_row
;
500 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
502 /* Ascent and height of the last line processed by move_it_to. */
504 static int last_max_ascent
, last_height
;
506 /* The maximum distance to look ahead for text properties. Values
507 that are too small let us call compute_char_face and similar
508 functions too often which is expensive. Values that are too large
509 let us call compute_char_face and alike too often because we
510 might not be interested in text properties that far away. */
512 #define TEXT_PROP_DISTANCE_LIMIT 100
514 /* Non-zero means print traces of redisplay if compiled with
518 int trace_redisplay_p
;
521 /* Value returned from text property handlers (see below). */
526 HANDLED_RECOMPUTE_PROPS
,
527 HANDLED_OVERLAY_STRING_CONSUMED
,
531 /* A description of text properties that redisplay is interested
536 /* The name of the property. */
539 /* A unique index for the property. */
542 /* A handler function called to set up iterator IT from the property
543 at IT's current position. Value is used to steer handle_stop. */
544 enum prop_handled (*handler
) P_ ((struct it
*it
));
547 static enum prop_handled handle_face_prop
P_ ((struct it
*));
548 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
549 static enum prop_handled handle_display_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
},
566 /* Value is the position described by X. If X is a marker, value is
567 the marker_position of X. Otherwise, value is X. */
569 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
571 /* Enumeration returned by some move_it_.* functions internally. */
575 /* Not used. Undefined value. */
578 /* Move ended at the requested buffer position or ZV. */
579 MOVE_POS_MATCH_OR_ZV
,
581 /* Move ended at the requested X pixel position. */
584 /* Move within a line ended at the end of a line that must be
588 /* Move within a line ended at the end of a line that would
589 be displayed truncated. */
592 /* Move within a line ended at a line end. */
598 /* Function prototypes. */
600 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
601 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
602 static int resize_mini_window
P_ ((struct window
*));
603 static void clear_garbaged_frames
P_ ((void));
604 static int current_message_1
P_ ((Lisp_Object
*));
605 static int truncate_message_1
P_ ((int));
606 static int set_message_1
P_ ((char *s
, Lisp_Object
, int, int));
607 static int display_echo_area
P_ ((struct window
*));
608 static int display_echo_area_1
P_ ((struct window
*));
609 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
610 static int string_char_and_length
P_ ((unsigned char *, int, int *));
611 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
613 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
614 static Lisp_Object eval_handler
P_ ((Lisp_Object
));
615 static Lisp_Object eval_form
P_ ((Lisp_Object
));
616 static void insert_left_trunc_glyphs
P_ ((struct it
*));
617 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
618 static void extend_face_to_end_of_line
P_ ((struct it
*));
619 static void append_space
P_ ((struct it
*, int));
620 static void make_cursor_line_fully_visible
P_ ((struct window
*));
621 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
622 static int trailing_whitespace_p
P_ ((int));
623 static int message_log_check_duplicate
P_ ((int, int, int, int));
624 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
625 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
626 static void push_it
P_ ((struct it
*));
627 static void pop_it
P_ ((struct it
*));
628 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
629 static void redisplay_internal
P_ ((int));
630 static int echo_area_display
P_ ((int));
631 static void redisplay_windows
P_ ((Lisp_Object
));
632 static void redisplay_window
P_ ((Lisp_Object
, int));
633 static void update_menu_bar
P_ ((struct frame
*, int));
634 static int try_window_reusing_current_matrix
P_ ((struct window
*));
635 static int try_window_id
P_ ((struct window
*));
636 static int display_line
P_ ((struct it
*));
637 static void display_mode_lines
P_ ((struct window
*));
638 static void display_mode_line
P_ ((struct window
*, enum face_id
,
640 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
641 static char *decode_mode_spec
P_ ((struct window
*, char, int, int));
642 static void display_menu_bar
P_ ((struct window
*));
643 static int display_count_lines
P_ ((int, int, int, int, int *));
644 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
645 int, int, struct it
*, int, int, int, int));
646 static void compute_line_metrics
P_ ((struct it
*));
647 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
648 static int get_overlay_strings
P_ ((struct it
*));
649 static void next_overlay_string
P_ ((struct it
*));
650 void set_iterator_to_next
P_ ((struct it
*));
651 static void reseat
P_ ((struct it
*, struct text_pos
, int));
652 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
653 static void back_to_previous_visible_line_start
P_ ((struct it
*));
654 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
655 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
656 static int next_element_from_display_vector
P_ ((struct it
*));
657 static int next_element_from_string
P_ ((struct it
*));
658 static int next_element_from_c_string
P_ ((struct it
*));
659 static int next_element_from_buffer
P_ ((struct it
*));
660 static int next_element_from_image
P_ ((struct it
*));
661 static int next_element_from_stretch
P_ ((struct it
*));
662 static void load_overlay_strings
P_ ((struct it
*));
663 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
664 struct display_pos
*));
665 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
666 Lisp_Object
, int, int, int, int));
667 static int charset_at_position
P_ ((struct text_pos
));
668 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
670 void move_it_vertically_backward
P_ ((struct it
*, int));
671 static void init_to_row_start
P_ ((struct it
*, struct window
*,
672 struct glyph_row
*));
673 static void init_to_row_end
P_ ((struct it
*, struct window
*,
674 struct glyph_row
*));
675 static void back_to_previous_line_start
P_ ((struct it
*));
676 static void forward_to_next_line_start
P_ ((struct it
*));
677 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
679 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
680 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
681 static int number_of_chars
P_ ((unsigned char *, int));
682 static void compute_stop_pos
P_ ((struct it
*));
683 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
685 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
686 static int next_overlay_change
P_ ((int));
687 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
688 Lisp_Object
, struct text_pos
*));
690 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
691 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
693 #ifdef HAVE_WINDOW_SYSTEM
695 static void update_toolbar
P_ ((struct frame
*, int));
696 static void build_desired_toolbar_string
P_ ((struct frame
*f
));
697 static int redisplay_toolbar
P_ ((struct frame
*));
698 static void display_toolbar_line
P_ ((struct it
*));
700 #endif /* HAVE_WINDOW_SYSTEM */
703 /***********************************************************************
704 Window display dimensions
705 ***********************************************************************/
707 /* Return the window-relative maximum y + 1 for glyph rows displaying
708 text in window W. This is the height of W minus the height of a
709 mode line, if any. */
712 window_text_bottom_y (w
)
715 struct frame
*f
= XFRAME (w
->frame
);
716 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
718 if (WINDOW_WANTS_MODELINE_P (w
))
719 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
724 /* Return the pixel width of display area AREA of window W. AREA < 0
725 means return the total width of W, not including bitmap areas to
726 the left and right of the window. */
729 window_box_width (w
, area
)
733 struct frame
*f
= XFRAME (w
->frame
);
734 int width
= XFASTINT (w
->width
);
736 if (!w
->pseudo_window_p
)
738 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
740 if (area
== TEXT_AREA
)
742 if (INTEGERP (w
->left_margin_width
))
743 width
-= XFASTINT (w
->left_margin_width
);
744 if (INTEGERP (w
->right_margin_width
))
745 width
-= XFASTINT (w
->right_margin_width
);
747 else if (area
== LEFT_MARGIN_AREA
)
748 width
= (INTEGERP (w
->left_margin_width
)
749 ? XFASTINT (w
->left_margin_width
) : 0);
750 else if (area
== RIGHT_MARGIN_AREA
)
751 width
= (INTEGERP (w
->right_margin_width
)
752 ? XFASTINT (w
->right_margin_width
) : 0);
755 return width
* CANON_X_UNIT (f
);
759 /* Return the pixel height of the display area of window W, not
760 including mode lines of W, if any.. */
763 window_box_height (w
)
766 struct frame
*f
= XFRAME (w
->frame
);
767 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
769 if (WINDOW_WANTS_MODELINE_P (w
))
770 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
772 if (WINDOW_WANTS_TOP_LINE_P (w
))
773 height
-= CURRENT_TOP_LINE_HEIGHT (w
);
779 /* Return the frame-relative coordinate of the left edge of display
780 area AREA of window W. AREA < 0 means return the left edge of the
781 whole window, to the right of any bitmap area at the left side of
785 window_box_left (w
, area
)
789 struct frame
*f
= XFRAME (w
->frame
);
790 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
792 if (!w
->pseudo_window_p
)
794 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
795 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
797 if (area
== TEXT_AREA
)
798 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
799 else if (area
== RIGHT_MARGIN_AREA
)
800 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
801 + window_box_width (w
, TEXT_AREA
));
808 /* Return the frame-relative coordinate of the right edge of display
809 area AREA of window W. AREA < 0 means return the left edge of the
810 whole window, to the left of any bitmap area at the right side of
814 window_box_right (w
, area
)
818 return window_box_left (w
, area
) + window_box_width (w
, area
);
822 /* Get the bounding box of the display area AREA of window W, without
823 mode lines, in frame-relative coordinates. AREA < 0 means the
824 whole window, not including bitmap areas to the left and right of
825 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
826 coordinates of the upper-left corner of the box. Return in
827 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
830 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
833 int *box_x
, *box_y
, *box_width
, *box_height
;
835 struct frame
*f
= XFRAME (w
->frame
);
837 *box_width
= window_box_width (w
, area
);
838 *box_height
= window_box_height (w
);
839 *box_x
= window_box_left (w
, area
);
840 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
841 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
842 if (WINDOW_WANTS_TOP_LINE_P (w
))
843 *box_y
+= CURRENT_TOP_LINE_HEIGHT (w
);
847 /* Get the bounding box of the display area AREA of window W, without
848 mode lines. AREA < 0 means the whole window, not including bitmap
849 areas to the left and right of the window. Return in *TOP_LEFT_X
850 and TOP_LEFT_Y the frame-relative pixel coordinates of the
851 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
852 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
856 window_box_edges (w
, area
, top_left_x
, top_left_y
,
857 bottom_right_x
, bottom_right_y
)
860 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
862 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
864 *bottom_right_x
+= *top_left_x
;
865 *bottom_right_y
+= *top_left_y
;
870 /***********************************************************************
872 ***********************************************************************/
874 /* Return the next character from STR which is MAXLEN bytes long.
875 Return in *LEN the length of the character. This is like
876 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
877 we find one, we return a `?', but with the length of the illegal
881 string_char_and_length (str
, maxlen
, len
)
887 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
888 if (!CHAR_VALID_P (c
, 1))
889 /* We may not change the length here because other places in Emacs
890 don't use this function, i.e. they silently accept illegal
899 /* Given a position POS containing a valid character and byte position
900 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
902 static struct text_pos
903 string_pos_nchars_ahead (pos
, string
, nchars
)
908 xassert (STRINGP (string
) && nchars
>= 0);
910 if (STRING_MULTIBYTE (string
))
912 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
913 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
918 string_char_and_length (p
, rest
, &len
);
919 p
+= len
, rest
-= len
;
922 BYTEPOS (pos
) += len
;
926 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
932 /* Value is the text position, i.e. character and byte position,
933 for character position CHARPOS in STRING. */
935 static INLINE
struct text_pos
936 string_pos (charpos
, string
)
941 xassert (STRINGP (string
));
942 xassert (charpos
>= 0);
943 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
948 /* Value is a text position, i.e. character and byte position, for
949 character position CHARPOS in C string S. MULTIBYTE_P non-zero
950 means recognize multibyte characters. */
952 static struct text_pos
953 c_string_pos (charpos
, s
, multibyte_p
)
961 xassert (charpos
>= 0);
965 int rest
= strlen (s
), len
;
967 SET_TEXT_POS (pos
, 0, 0);
970 string_char_and_length (s
, rest
, &len
);
971 s
+= len
, rest
-= len
;
974 BYTEPOS (pos
) += len
;
978 SET_TEXT_POS (pos
, charpos
, charpos
);
984 /* Value is the number of characters in C string S. MULTIBYTE_P
985 non-zero means recognize multibyte characters. */
988 number_of_chars (s
, multibyte_p
)
996 int rest
= strlen (s
), len
;
997 unsigned char *p
= (unsigned char *) s
;
999 for (nchars
= 0; rest
> 0; ++nchars
)
1001 string_char_and_length (p
, rest
, &len
);
1002 rest
-= len
, p
+= len
;
1006 nchars
= strlen (s
);
1012 /* Compute byte position NEWPOS->bytepos corresponding to
1013 NEWPOS->charpos. POS is a known position in string STRING.
1014 NEWPOS->charpos must be >= POS.charpos. */
1017 compute_string_pos (newpos
, pos
, string
)
1018 struct text_pos
*newpos
, pos
;
1021 xassert (STRINGP (string
));
1022 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1024 if (STRING_MULTIBYTE (string
))
1025 *newpos
= string_pos_nchars_ahead (pos
, CHARPOS (*newpos
) - CHARPOS (pos
),
1028 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1032 /* Return the charset of the character at position POS in
1036 charset_at_position (pos
)
1037 struct text_pos pos
;
1040 unsigned char *p
= BYTE_POS_ADDR (BYTEPOS (pos
));
1042 multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1045 int maxlen
= ((BYTEPOS (pos
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
1048 c
= string_char_and_length (p
, maxlen
, &len
);
1053 return CHAR_CHARSET (c
);
1058 /***********************************************************************
1059 Lisp form evaluation
1060 ***********************************************************************/
1062 /* Error handler for eval_form. */
1072 /* Evaluate SEXPR and return the result, or nil if something went
1079 int count
= specpdl_ptr
- specpdl
;
1081 specbind (Qinhibit_redisplay
, Qt
);
1082 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, eval_handler
);
1083 return unbind_to (count
, val
);
1088 /***********************************************************************
1090 ***********************************************************************/
1094 /* Define CHECK_IT to perform sanity checks on iterators.
1095 This is for debugging. It is too slow to do unconditionally. */
1101 if (it
->method
== next_element_from_string
)
1103 xassert (STRINGP (it
->string
));
1104 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1106 else if (it
->method
== next_element_from_buffer
)
1108 /* Check that character and byte positions agree. */
1109 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1113 xassert (it
->current
.dpvec_index
>= 0);
1115 xassert (it
->current
.dpvec_index
< 0);
1118 #define CHECK_IT(IT) check_it ((IT))
1122 #define CHECK_IT(IT) (void) 0
1129 /* Check that the window end of window W is what we expect it
1130 to be---the last row in the current matrix displaying text. */
1133 check_window_end (w
)
1136 if (!MINI_WINDOW_P (w
)
1137 && !NILP (w
->window_end_valid
))
1139 struct glyph_row
*row
;
1140 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1141 XFASTINT (w
->window_end_vpos
)),
1143 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1144 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1148 #define CHECK_WINDOW_END(W) check_window_end ((W))
1150 #else /* not GLYPH_DEBUG */
1152 #define CHECK_WINDOW_END(W) (void) 0
1154 #endif /* not GLYPH_DEBUG */
1158 /***********************************************************************
1159 Iterator initialization
1160 ***********************************************************************/
1162 /* Initialize IT for displaying current_buffer in window W, starting
1163 at character position CHARPOS. CHARPOS < 0 means that no buffer
1164 position is specified which is useful when the iterator is assigned
1165 a position later. BYTEPOS is the byte position corresponding to
1166 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1168 If ROW is not null, calls to produce_glyphs with IT as parameter
1169 will produce glyphs in that row.
1171 BASE_FACE_ID is the id of a base face to use. It must be one of
1172 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1173 TOP_LINE_FACE_ID for displaying mode lines, or TOOLBAR_FACE_ID for
1174 displaying the toolbar.
1176 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1177 TOP_LINE_FACE_ID, the iterator will be initialized to use the
1178 corresponding mode line glyph row of the desired matrix of W. */
1181 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1184 int charpos
, bytepos
;
1185 struct glyph_row
*row
;
1186 enum face_id base_face_id
;
1188 int highlight_region_p
;
1190 /* Some precondition checks. */
1191 xassert (w
!= NULL
&& it
!= NULL
);
1192 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1194 /* If face attributes have been changed since the last redisplay,
1195 free realized faces now because they depend on face definitions
1196 that might have changed. */
1197 if (face_change_count
)
1199 face_change_count
= 0;
1200 free_all_realized_faces (Qnil
);
1203 /* Use one of the mode line rows of W's desired matrix if
1207 if (base_face_id
== MODE_LINE_FACE_ID
)
1208 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1209 else if (base_face_id
== TOP_LINE_FACE_ID
)
1210 row
= MATRIX_TOP_LINE_ROW (w
->desired_matrix
);
1214 bzero (it
, sizeof *it
);
1215 it
->current
.overlay_string_index
= -1;
1216 it
->current
.dpvec_index
= -1;
1217 it
->charset
= CHARSET_ASCII
;
1218 it
->base_face_id
= base_face_id
;
1220 /* The window in which we iterate over current_buffer: */
1221 XSETWINDOW (it
->window
, w
);
1223 it
->f
= XFRAME (w
->frame
);
1225 /* If realized faces have been removed, e.g. because of face
1226 attribute changes of named faces, recompute them. */
1227 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1228 recompute_basic_faces (it
->f
);
1230 /* Current value of the `space-width', and 'height' properties. */
1231 it
->space_width
= Qnil
;
1232 it
->font_height
= Qnil
;
1234 /* Are control characters displayed as `^C'? */
1235 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1237 /* -1 means everything between a CR and the following line end
1238 is invisible. >0 means lines indented more than this value are
1240 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1241 ? XFASTINT (current_buffer
->selective_display
)
1242 : (!NILP (current_buffer
->selective_display
)
1244 it
->selective_display_ellipsis_p
1245 = !NILP (current_buffer
->selective_display_ellipses
);
1247 /* Display table to use. */
1248 it
->dp
= window_display_table (w
);
1250 /* Are multibyte characters enabled in current_buffer? */
1251 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1253 /* Non-zero if we should highlight the region. */
1255 = (!NILP (Vtransient_mark_mode
)
1256 && !NILP (current_buffer
->mark_active
)
1257 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1259 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1260 start and end of a visible region in window IT->w. Set both to
1261 -1 to indicate no region. */
1262 if (highlight_region_p
1263 /* Maybe highlight only in selected window. */
1264 && (/* Either show region everywhere. */
1265 highlight_nonselected_windows
1266 /* Or show region in the selected window. */
1267 || w
== XWINDOW (selected_window
)
1268 /* Or show the region if we are in the mini-buffer and W is
1269 the window the mini-buffer refers to. */
1270 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1271 && w
== XWINDOW (Vminibuf_scroll_window
))))
1273 int charpos
= marker_position (current_buffer
->mark
);
1274 it
->region_beg_charpos
= min (PT
, charpos
);
1275 it
->region_end_charpos
= max (PT
, charpos
);
1278 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1280 /* Get the position at which the redisplay_end_trigger hook should
1281 be run, if it is to be run at all. */
1282 if (MARKERP (w
->redisplay_end_trigger
)
1283 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1284 it
->redisplay_end_trigger_charpos
1285 = marker_position (w
->redisplay_end_trigger
);
1286 else if (INTEGERP (w
->redisplay_end_trigger
))
1287 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1289 /* Correct bogus values of tab_width. */
1290 it
->tab_width
= XINT (current_buffer
->tab_width
);
1291 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1294 /* Are lines in the display truncated? */
1295 it
->truncate_lines_p
1296 = (base_face_id
!= DEFAULT_FACE_ID
1297 || XINT (it
->w
->hscroll
)
1298 || (truncate_partial_width_windows
1299 && !WINDOW_FULL_WIDTH_P (it
->w
))
1300 || !NILP (current_buffer
->truncate_lines
));
1302 /* Get dimensions of truncation and continuation glyphs. These are
1303 displayed as bitmaps under X, so we don't need them for such
1305 if (!FRAME_WINDOW_P (it
->f
))
1307 if (it
->truncate_lines_p
)
1309 /* We will need the truncation glyph. */
1310 xassert (it
->glyph_row
== NULL
);
1311 produce_special_glyphs (it
, IT_TRUNCATION
);
1312 it
->truncation_pixel_width
= it
->pixel_width
;
1316 /* We will need the continuation glyph. */
1317 xassert (it
->glyph_row
== NULL
);
1318 produce_special_glyphs (it
, IT_CONTINUATION
);
1319 it
->continuation_pixel_width
= it
->pixel_width
;
1322 /* Reset these values to zero becaue the produce_special_glyphs
1323 above has changed them. */
1324 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1325 it
->phys_ascent
= it
->phys_descent
= 0;
1328 /* Set this after getting the dimensions of truncation and
1329 continuation glyphs, so that we don't produce glyphs when calling
1330 produce_special_glyphs, above. */
1331 it
->glyph_row
= row
;
1332 it
->area
= TEXT_AREA
;
1334 /* Get the dimensions of the display area. The display area
1335 consists of the visible window area plus a horizontally scrolled
1336 part to the left of the window. All x-values are relative to the
1337 start of this total display area. */
1338 if (base_face_id
!= DEFAULT_FACE_ID
)
1340 /* Mode lines, menu bar in terminal frames. */
1341 it
->first_visible_x
= 0;
1342 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1347 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1348 it
->last_visible_x
= (it
->first_visible_x
1349 + window_box_width (w
, TEXT_AREA
));
1351 /* If we truncate lines, leave room for the truncator glyph(s) at
1352 the right margin. Otherwise, leave room for the continuation
1353 glyph(s). Truncation and continuation glyphs are not inserted
1354 for window-based redisplay. */
1355 if (!FRAME_WINDOW_P (it
->f
))
1357 if (it
->truncate_lines_p
)
1358 it
->last_visible_x
-= it
->truncation_pixel_width
;
1360 it
->last_visible_x
-= it
->continuation_pixel_width
;
1363 it
->top_line_p
= WINDOW_WANTS_TOP_LINE_P (w
);
1364 it
->current_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
) + w
->vscroll
;
1367 /* Leave room for a border glyph. */
1368 if (!FRAME_WINDOW_P (it
->f
)
1369 && !WINDOW_RIGHTMOST_P (it
->w
))
1370 it
->last_visible_x
-= 1;
1372 it
->last_visible_y
= window_text_bottom_y (w
);
1374 /* For mode lines and alike, arrange for the first glyph having a
1375 left box line if the face specifies a box. */
1376 if (base_face_id
!= DEFAULT_FACE_ID
)
1380 it
->face_id
= base_face_id
;
1382 /* If we have a boxed mode line, make the first character appear
1383 with a left box line. */
1384 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1385 if (face
->box
!= FACE_NO_BOX
)
1386 it
->start_of_box_run_p
= 1;
1389 /* If a buffer position was specified, set the iterator there,
1390 getting overlays and face properties from that position. */
1393 it
->end_charpos
= ZV
;
1395 IT_CHARPOS (*it
) = charpos
;
1397 /* Compute byte position if not specified. */
1399 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1401 IT_BYTEPOS (*it
) = bytepos
;
1403 /* Compute faces etc. */
1404 reseat (it
, it
->current
.pos
, 1);
1411 /* Initialize IT for the display of window W with window start POS. */
1414 start_display (it
, w
, pos
)
1417 struct text_pos pos
;
1419 int start_at_line_beg_p
;
1420 struct glyph_row
*row
;
1421 int first_vpos
= WINDOW_WANTS_TOP_LINE_P (w
) ? 1 : 0;
1424 row
= w
->desired_matrix
->rows
+ first_vpos
;
1425 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1426 first_y
= it
->current_y
;
1428 /* If window start is not at a line start, move back to the line
1429 start. This makes sure that we take continuation lines into
1431 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1432 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1433 if (!start_at_line_beg_p
)
1434 reseat_at_previous_visible_line_start (it
);
1436 /* If window start is not at a line start, skip forward to POS to
1437 get the correct continuation_lines_width and current_x. */
1438 if (!start_at_line_beg_p
)
1440 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1442 /* If lines are continued, this line may end in the middle of a
1443 multi-glyph character (e.g. a control character displayed as
1444 \003, or in the middle of an overlay string). In this case
1445 move_it_to above will not have taken us to the start of
1446 the continuation line but to the end of the continued line. */
1447 if (!it
->truncate_lines_p
&& it
->current_x
> 0)
1449 if (it
->current
.dpvec_index
>= 0
1450 || it
->current
.overlay_string_index
>= 0)
1452 set_iterator_to_next (it
);
1453 move_it_in_display_line_to (it
, -1, -1, 0);
1455 it
->continuation_lines_width
+= it
->current_x
;
1458 it
->current_y
= first_y
;
1460 it
->current_x
= it
->hpos
= 0;
1463 #if 0 /* Don't assert the following because start_display is sometimes
1464 called intentionally with a window start that is not at a
1465 line start. Please leave this code in as a comment. */
1467 /* Window start should be on a line start, now. */
1468 xassert (it
->continuation_lines_width
1469 || IT_CHARPOS (it
) == BEGV
1470 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1475 /* Initialize IT for stepping through current_buffer in window W,
1476 starting at position POS that includes overlay string and display
1477 vector/ control character translation position information. */
1480 init_from_display_pos (it
, w
, pos
)
1483 struct display_pos
*pos
;
1485 /* Keep in mind: the call to reseat in init_iterator skips invisible
1486 text, so we might end up at a position different from POS. This
1487 is only a problem when POS is a row start after a newline and an
1488 overlay starts there with an after-string, and the overlay has an
1489 invisible property. Since we don't skip invisible text in
1490 display_line and elsewhere immediately after consuming the
1491 newline before the row start, such a POS will not be in a string,
1492 but the call to init_iterator below will move us to the
1494 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1495 NULL
, DEFAULT_FACE_ID
);
1497 /* If position is within an overlay string, set up IT to
1498 the right overlay string. */
1499 if (pos
->overlay_string_index
>= 0)
1503 /* We already have the first chunk of overlay strings in
1504 IT->overlay_strings. Load more until the one for
1505 pos->overlay_string_index is in IT->overlay_strings. */
1506 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1508 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1509 it
->current
.overlay_string_index
= 0;
1512 load_overlay_strings (it
);
1513 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1517 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1518 relative_index
= (it
->current
.overlay_string_index
1519 % OVERLAY_STRING_CHUNK_SIZE
);
1520 it
->string
= it
->overlay_strings
[relative_index
];
1521 it
->current
.string_pos
= pos
->string_pos
;
1522 it
->method
= next_element_from_string
;
1524 else if (CHARPOS (pos
->string_pos
) >= 0)
1526 /* Recorded position is not in an overlay string, but in another
1527 string. This can only be a string from a `display' property.
1528 IT should already be filled with that string. */
1529 it
->current
.string_pos
= pos
->string_pos
;
1530 xassert (STRINGP (it
->string
));
1533 /* Restore position in display vector translations or control
1534 character translations. */
1535 if (pos
->dpvec_index
>= 0)
1537 /* This fills IT->dpvec. */
1538 get_next_display_element (it
);
1539 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1540 it
->current
.dpvec_index
= pos
->dpvec_index
;
1547 /* Initialize IT for stepping through current_buffer in window W
1548 starting at ROW->start. */
1551 init_to_row_start (it
, w
, row
)
1554 struct glyph_row
*row
;
1556 init_from_display_pos (it
, w
, &row
->start
);
1557 it
->continuation_lines_width
= row
->continuation_lines_width
;
1562 /* Initialize IT for stepping through current_buffer in window W
1563 starting in the line following ROW, i.e. starting at ROW->end. */
1566 init_to_row_end (it
, w
, row
)
1569 struct glyph_row
*row
;
1571 init_from_display_pos (it
, w
, &row
->end
);
1573 if (row
->continued_p
)
1574 it
->continuation_lines_width
= (row
->continuation_lines_width
1575 + row
->pixel_width
);
1582 /***********************************************************************
1584 ***********************************************************************/
1586 /* Called when IT reaches IT->stop_charpos. Handle text property and
1587 overlay changes. Set IT->stop_charpos to the next position where
1594 enum prop_handled handled
;
1595 int handle_overlay_change_p
= 1;
1599 it
->current
.dpvec_index
= -1;
1603 handled
= HANDLED_NORMALLY
;
1605 /* Call text property handlers. */
1606 for (p
= it_props
; p
->handler
; ++p
)
1608 handled
= p
->handler (it
);
1610 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1612 else if (handled
== HANDLED_RETURN
)
1614 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1615 handle_overlay_change_p
= 0;
1618 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1620 /* Don't check for overlay strings below when set to deliver
1621 characters from a display vector. */
1622 if (it
->method
== next_element_from_display_vector
)
1623 handle_overlay_change_p
= 0;
1625 /* Handle overlay changes. */
1626 if (handle_overlay_change_p
)
1627 handled
= handle_overlay_change (it
);
1629 /* Determine where to stop next. */
1630 if (handled
== HANDLED_NORMALLY
)
1631 compute_stop_pos (it
);
1634 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1638 /* Compute IT->stop_charpos from text property and overlay change
1639 information for IT's current position. */
1642 compute_stop_pos (it
)
1645 register INTERVAL iv
, next_iv
;
1646 Lisp_Object object
, limit
, position
;
1648 /* If nowhere else, stop at the end. */
1649 it
->stop_charpos
= it
->end_charpos
;
1651 if (STRINGP (it
->string
))
1653 /* Strings are usually short, so don't limit the search for
1655 object
= it
->string
;
1657 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1663 /* If next overlay change is in front of the current stop pos
1664 (which is IT->end_charpos), stop there. Note: value of
1665 next_overlay_change is point-max if no overlay change
1667 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1668 if (charpos
< it
->stop_charpos
)
1669 it
->stop_charpos
= charpos
;
1671 /* If showing the region, we have to stop at the region
1672 start or end because the face might change there. */
1673 if (it
->region_beg_charpos
> 0)
1675 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1676 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1677 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1678 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1681 /* Set up variables for computing the stop position from text
1682 property changes. */
1683 XSETBUFFER (object
, current_buffer
);
1684 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1685 XSETFASTINT (position
, IT_CHARPOS (*it
));
1689 /* Get the interval containing IT's position. Value is a null
1690 interval if there isn't such an interval. */
1691 iv
= validate_interval_range (object
, &position
, &position
, 0);
1692 if (!NULL_INTERVAL_P (iv
))
1694 Lisp_Object values_here
[LAST_PROP_IDX
];
1697 /* Get properties here. */
1698 for (p
= it_props
; p
->handler
; ++p
)
1699 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1701 /* Look for an interval following iv that has different
1703 for (next_iv
= next_interval (iv
);
1704 (!NULL_INTERVAL_P (next_iv
)
1706 || XFASTINT (limit
) > next_iv
->position
));
1707 next_iv
= next_interval (next_iv
))
1709 for (p
= it_props
; p
->handler
; ++p
)
1711 Lisp_Object new_value
;
1713 new_value
= textget (next_iv
->plist
, *p
->name
);
1714 if (!EQ (values_here
[p
->idx
], new_value
))
1722 if (!NULL_INTERVAL_P (next_iv
))
1724 if (INTEGERP (limit
)
1725 && next_iv
->position
>= XFASTINT (limit
))
1726 /* No text property change up to limit. */
1727 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1729 /* Text properties change in next_iv. */
1730 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1734 xassert (STRINGP (it
->string
)
1735 || (it
->stop_charpos
>= BEGV
1736 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1740 /* Return the position of the next overlay change after POS in
1741 current_buffer. Value is point-max if no overlay change
1742 follows. This is like `next-overlay-change' but doesn't use
1746 next_overlay_change (pos
)
1751 Lisp_Object
*overlays
;
1755 /* Get all overlays at the given position. */
1757 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1758 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1759 if (noverlays
> len
)
1762 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1763 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1766 /* If any of these overlays ends before endpos,
1767 use its ending point instead. */
1768 for (i
= 0; i
< noverlays
; ++i
)
1773 oend
= OVERLAY_END (overlays
[i
]);
1774 oendpos
= OVERLAY_POSITION (oend
);
1775 endpos
= min (endpos
, oendpos
);
1783 /***********************************************************************
1785 ***********************************************************************/
1787 /* Handle changes in the `fontified' property of the current buffer by
1788 calling hook functions from Qfontification_functions to fontify
1791 static enum prop_handled
1792 handle_fontified_prop (it
)
1795 Lisp_Object prop
, pos
;
1796 enum prop_handled handled
= HANDLED_NORMALLY
;
1798 /* Get the value of the `fontified' property at IT's current buffer
1799 position. (The `fontified' property doesn't have a special
1800 meaning in strings.) If the value is nil, call functions from
1801 Qfontification_functions. */
1802 if (!STRINGP (it
->string
)
1804 && !NILP (Vfontification_functions
)
1805 && (pos
= make_number (IT_CHARPOS (*it
)),
1806 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1809 Lisp_Object args
[2];
1811 /* Run the hook functions. */
1812 args
[0] = Qfontification_functions
;
1814 Frun_hook_with_args (make_number (2), args
);
1816 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
1817 something. This avoids an endless loop if they failed to
1818 fontify the text for which reason ever. */
1819 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
1820 handled
= HANDLED_RECOMPUTE_PROPS
;
1828 /***********************************************************************
1830 ***********************************************************************/
1832 /* Set up iterator IT from face properties at its current position.
1833 Called from handle_stop. */
1835 static enum prop_handled
1836 handle_face_prop (it
)
1839 int new_face_id
, next_stop
;
1841 if (!STRINGP (it
->string
))
1844 = face_at_buffer_position (it
->w
,
1846 it
->region_beg_charpos
,
1847 it
->region_end_charpos
,
1850 + TEXT_PROP_DISTANCE_LIMIT
),
1853 /* Is this a start of a run of characters with box face?
1854 Caveat: this can be called for a freshly initialized
1855 iterator; face_id is -1 is this case. We know that the new
1856 face will not change until limit, i.e. if the new face has a
1857 box, all characters up to limit will have one. But, as
1858 usual, we don't know whether limit is really the end. */
1859 if (new_face_id
!= it
->face_id
)
1861 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1863 /* If new face has a box but old face has not, this is
1864 the start of a run of characters with box, i.e. it has
1865 a shadow on the left side. The value of face_id of the
1866 iterator will be -1 if this is the initial call that gets
1867 the face. In this case, we have to look in front of IT's
1868 position and see whether there is a face != new_face_id. */
1869 it
->start_of_box_run_p
1870 = (new_face
->box
!= FACE_NO_BOX
1871 && (it
->face_id
>= 0
1872 || IT_CHARPOS (*it
) == BEG
1873 || new_face_id
!= face_before_it_pos (it
)));
1874 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1880 = face_at_string_position (it
->w
,
1882 IT_STRING_CHARPOS (*it
),
1883 (it
->current
.overlay_string_index
>= 0
1886 it
->region_beg_charpos
,
1887 it
->region_end_charpos
,
1891 #if 0 /* This shouldn't be neccessary. Let's check it. */
1892 /* If IT is used to display a mode line we would really like to
1893 use the mode line face instead of the frame's default face. */
1894 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
1895 && new_face_id
== DEFAULT_FACE_ID
)
1896 new_face_id
= MODE_LINE_FACE_ID
;
1899 /* Is this a start of a run of characters with box? Caveat:
1900 this can be called for a freshly allocated iterator; face_id
1901 is -1 is this case. We know that the new face will not
1902 change until the next check pos, i.e. if the new face has a
1903 box, all characters up to that position will have a
1904 box. But, as usual, we don't know whether that position
1905 is really the end. */
1906 if (new_face_id
!= it
->face_id
)
1908 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1909 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1911 /* If new face has a box but old face hasn't, this is the
1912 start of a run of characters with box, i.e. it has a
1913 shadow on the left side. */
1914 it
->start_of_box_run_p
1915 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
1916 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1920 it
->face_id
= new_face_id
;
1921 it
->charset
= CHARSET_ASCII
;
1922 return HANDLED_NORMALLY
;
1926 /* Compute the face one character before or after the current position
1927 of IT. BEFORE_P non-zero means get the face in front of IT's
1928 position. Value is the id of the face. */
1931 face_before_or_after_it_pos (it
, before_p
)
1936 int next_check_charpos
;
1937 struct text_pos pos
;
1939 xassert (it
->s
== NULL
);
1941 if (STRINGP (it
->string
))
1943 /* No face change past the end of the string (for the case
1944 we are padding with spaces). No face change before the
1946 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
1947 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
1950 /* Set pos to the position before or after IT's current position. */
1952 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
1954 pos
= string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
);
1956 /* Get the face for ASCII, or unibyte. */
1958 = face_at_string_position (it
->w
,
1961 (it
->current
.overlay_string_index
>= 0
1964 it
->region_beg_charpos
,
1965 it
->region_end_charpos
,
1966 &next_check_charpos
,
1969 /* Correct the face for charsets different from ASCII. Do it
1970 for the multibyte case only. The face returned above is
1971 suitable for unibyte text if IT->string is unibyte. */
1972 if (STRING_MULTIBYTE (it
->string
))
1974 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
1975 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
1976 int c
, len
, charset
;
1978 c
= string_char_and_length (p
, rest
, &len
);
1979 charset
= CHAR_CHARSET (c
);
1980 if (charset
!= CHARSET_ASCII
)
1981 face_id
= FACE_FOR_CHARSET (it
->f
, face_id
, charset
);
1986 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
1987 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
1990 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
1991 pos
= it
->current
.pos
;
1998 /* Determine face for CHARSET_ASCII, or unibyte. */
1999 face_id
= face_at_buffer_position (it
->w
,
2001 it
->region_beg_charpos
,
2002 it
->region_end_charpos
,
2003 &next_check_charpos
,
2006 /* Correct the face for charsets different from ASCII. Do it
2007 for the multibyte case only. The face returned above is
2008 suitable for unibyte text if current_buffer is unibyte. */
2009 if (it
->multibyte_p
)
2011 int charset
= charset_at_position (pos
);
2012 if (charset
!= CHARSET_ASCII
)
2013 face_id
= FACE_FOR_CHARSET (it
->f
, face_id
, charset
);
2022 /***********************************************************************
2024 ***********************************************************************/
2026 /* Set up iterator IT from invisible properties at its current
2027 position. Called from handle_stop. */
2029 static enum prop_handled
2030 handle_invisible_prop (it
)
2033 enum prop_handled handled
= HANDLED_NORMALLY
;
2035 if (STRINGP (it
->string
))
2037 extern Lisp_Object Qinvisible
;
2038 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2040 /* Get the value of the invisible text property at the
2041 current position. Value will be nil if there is no such
2043 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2044 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2048 handled
= HANDLED_RECOMPUTE_PROPS
;
2050 /* Get the position at which the next change of the
2051 invisible text property can be found in IT->string.
2052 Value will be nil if the property value is the same for
2053 all the rest of IT->string. */
2054 XSETINT (limit
, XSTRING (it
->string
)->size
);
2055 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2058 /* Text at current position is invisible. The next
2059 change in the property is at position end_charpos.
2060 Move IT's current position to that position. */
2061 if (INTEGERP (end_charpos
)
2062 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2064 struct text_pos old
;
2065 old
= it
->current
.string_pos
;
2066 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2067 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2071 /* The rest of the string is invisible. If this is an
2072 overlay string, proceed with the next overlay string
2073 or whatever comes and return a character from there. */
2074 if (it
->current
.overlay_string_index
>= 0)
2076 next_overlay_string (it
);
2077 /* Don't check for overlay strings when we just
2078 finished processing them. */
2079 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2083 struct Lisp_String
*s
= XSTRING (it
->string
);
2084 IT_STRING_CHARPOS (*it
) = s
->size
;
2085 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2092 int visible_p
, newpos
, next_stop
;
2093 Lisp_Object pos
, prop
;
2095 /* First of all, is there invisible text at this position? */
2096 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2097 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2099 /* If we are on invisible text, skip over it. */
2100 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
2102 /* Record whether we have to display an ellipsis for the
2104 int display_ellipsis_p
2105 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2107 handled
= HANDLED_RECOMPUTE_PROPS
;
2109 /* Loop skipping over invisible text. The loop is left at
2110 ZV or with IT on the first char being visible again. */
2113 /* Try to skip some invisible text. Return value is the
2114 position reached which can be equal to IT's position
2115 if there is nothing invisible here. This skips both
2116 over invisible text properties and overlays with
2117 invisible property. */
2118 newpos
= skip_invisible (IT_CHARPOS (*it
),
2119 &next_stop
, ZV
, it
->window
);
2121 /* If we skipped nothing at all we weren't at invisible
2122 text in the first place. If everything to the end of
2123 the buffer was skipped, end the loop. */
2124 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2128 /* We skipped some characters but not necessarily
2129 all there are. Check if we ended up on visible
2130 text. Fget_char_property returns the property of
2131 the char before the given position, i.e. if we
2132 get visible_p = 1, this means that the char at
2133 newpos is visible. */
2134 XSETFASTINT (pos
, newpos
);
2135 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2136 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2139 /* If we ended up on invisible text, proceed to
2140 skip starting with next_stop. */
2142 IT_CHARPOS (*it
) = next_stop
;
2146 /* The position newpos is now either ZV or on visible text. */
2147 IT_CHARPOS (*it
) = newpos
;
2148 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2150 /* Maybe return `...' next for the end of the invisible text. */
2151 if (display_ellipsis_p
)
2154 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2156 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2157 it
->dpvec
= v
->contents
;
2158 it
->dpend
= v
->contents
+ v
->size
;
2162 /* Default `...'. */
2163 it
->dpvec
= default_invis_vector
;
2164 it
->dpend
= default_invis_vector
+ 3;
2167 /* The ellipsis display does not replace the display of
2168 the character at the new position. Indicate this by
2169 setting IT->dpvec_char_len to zero. */
2170 it
->dpvec_char_len
= 0;
2172 it
->current
.dpvec_index
= 0;
2173 it
->method
= next_element_from_display_vector
;
2183 /***********************************************************************
2185 ***********************************************************************/
2187 /* Set up iterator IT from `display' property at its current position.
2188 Called from handle_stop. */
2190 static enum prop_handled
2191 handle_display_prop (it
)
2194 Lisp_Object prop
, object
;
2195 struct text_pos
*position
;
2196 int space_or_image_found_p
;
2198 if (STRINGP (it
->string
))
2200 object
= it
->string
;
2201 position
= &it
->current
.string_pos
;
2206 position
= &it
->current
.pos
;
2209 /* Reset those iterator values set from display property values. */
2210 it
->font_height
= Qnil
;
2211 it
->space_width
= Qnil
;
2214 /* We don't support recursive `display' properties, i.e. string
2215 values that have a string `display' property, that have a string
2216 `display' property etc. */
2217 if (!it
->string_from_display_prop_p
)
2218 it
->area
= TEXT_AREA
;
2220 prop
= Fget_char_property (make_number (position
->charpos
),
2223 return HANDLED_NORMALLY
;
2225 space_or_image_found_p
= 0;
2226 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2228 while (CONSP (prop
))
2230 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2231 space_or_image_found_p
= 1;
2235 else if (VECTORP (prop
))
2238 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2239 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2241 space_or_image_found_p
= 1;
2245 if (handle_single_display_prop (it
, prop
, object
, position
))
2246 space_or_image_found_p
= 1;
2249 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2253 /* Value is the position of the end of the `display' property stating
2254 at START_POS in OBJECT. */
2256 static struct text_pos
2257 display_prop_end (it
, object
, start_pos
)
2260 struct text_pos start_pos
;
2263 struct text_pos end_pos
;
2265 /* Characters having this form of property are not displayed, so
2266 we have to find the end of the property. */
2267 end
= Fnext_single_property_change (make_number (start_pos
.charpos
),
2268 Qdisplay
, object
, Qnil
);
2271 /* A nil value of `end' means there are no changes of the
2272 property to the end of the buffer or string. */
2273 if (it
->current
.overlay_string_index
>= 0)
2274 end_pos
.charpos
= XSTRING (it
->string
)->size
;
2276 end_pos
.charpos
= it
->end_charpos
;
2279 end_pos
.charpos
= XFASTINT (end
);
2281 if (STRINGP (it
->string
))
2282 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2284 end_pos
.bytepos
= CHAR_TO_BYTE (end_pos
.charpos
);
2290 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2291 is the object in which the `display' property was found. *POSITION
2292 is the position at which it was found.
2294 If PROP is a `space' or `image' sub-property, set *POSITION to the
2295 end position of the `display' property.
2297 Value is non-zero if a `space' or `image' property value was found. */
2300 handle_single_display_prop (it
, prop
, object
, position
)
2304 struct text_pos
*position
;
2307 int space_or_image_found_p
= 0;
2311 /* If PROP is a list of the form `(:when FORM VALUE)', FORM is
2312 evaluated. If the result is nil, VALUE is ignored. */
2314 if (CONSP (prop
) && EQ (XCAR (prop
), QCwhen
))
2326 if (!NILP (form
) && !EQ (form
, Qt
))
2328 struct gcpro gcpro1
;
2329 struct text_pos end_pos
, pt
;
2331 end_pos
= display_prop_end (it
, object
, *position
);
2334 /* Temporarily set point to the end position, and then evaluate
2335 the form. This makes `(eolp)' work as FORM. */
2337 BYTEPOS (pt
) = PT_BYTE
;
2338 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2339 form
= eval_form (form
);
2340 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2348 && EQ (XCAR (prop
), Qheight
)
2349 && CONSP (XCDR (prop
)))
2351 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2354 /* `(height HEIGHT)'. */
2355 it
->font_height
= XCAR (XCDR (prop
));
2356 if (!NILP (it
->font_height
))
2358 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2359 int new_height
= -1;
2361 if (CONSP (it
->font_height
)
2362 && (EQ (XCAR (it
->font_height
), Qplus
)
2363 || EQ (XCAR (it
->font_height
), Qminus
))
2364 && CONSP (XCDR (it
->font_height
))
2365 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2367 /* `(+ N)' or `(- N)' where N is an integer. */
2368 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2369 if (EQ (XCAR (it
->font_height
), Qplus
))
2371 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2373 else if (SYMBOLP (it
->font_height
))
2375 /* Call function with current height as argument.
2376 Value is the new height. */
2377 Lisp_Object form
, height
;
2378 struct gcpro gcpro1
;
2380 height
= face
->lface
[LFACE_HEIGHT_INDEX
];
2381 form
= Fcons (it
->font_height
, Fcons (height
, Qnil
));
2383 height
= eval_form (form
);
2384 if (NUMBERP (height
))
2385 new_height
= XFLOATINT (height
);
2388 else if (NUMBERP (it
->font_height
))
2390 /* Value is a multiple of the canonical char height. */
2393 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2394 new_height
= (XFLOATINT (it
->font_height
)
2395 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2399 /* Evaluate IT->font_height with `height' bound to the
2400 current specified height to get the new height. */
2402 int count
= specpdl_ptr
- specpdl
;
2404 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2405 value
= eval_form (it
->font_height
);
2406 unbind_to (count
, Qnil
);
2408 if (NUMBERP (value
))
2409 new_height
= XFLOATINT (value
);
2413 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2416 else if (CONSP (prop
)
2417 && EQ (XCAR (prop
), Qspace_width
)
2418 && CONSP (XCDR (prop
)))
2420 /* `(space_width WIDTH)'. */
2421 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2424 value
= XCAR (XCDR (prop
));
2425 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2426 it
->space_width
= value
;
2428 else if (CONSP (prop
)
2429 && EQ (XCAR (prop
), Qraise
)
2430 && CONSP (XCDR (prop
)))
2432 #ifdef HAVE_WINDOW_SYSTEM
2433 /* `(raise FACTOR)'. */
2434 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2437 value
= XCAR (XCDR (prop
));
2438 if (NUMBERP (value
))
2440 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2441 it
->voffset
= - (XFLOATINT (value
)
2442 * (face
->font
->ascent
+ face
->font
->descent
));
2444 #endif /* HAVE_WINDOW_SYSTEM */
2446 else if (!it
->string_from_display_prop_p
)
2448 /* `(left-margin VALUE)' or `(right-margin VALUE)
2449 or `(nil VALUE)' or VALUE. */
2450 Lisp_Object location
, value
;
2451 struct text_pos start_pos
;
2454 /* Characters having this form of property are not displayed, so
2455 we have to find the end of the property. */
2456 space_or_image_found_p
= 1;
2457 start_pos
= *position
;
2458 *position
= display_prop_end (it
, object
, start_pos
);
2460 /* Let's stop at the new position and assume that all
2461 text properties change there. */
2462 it
->stop_charpos
= position
->charpos
;
2465 && !EQ (XCAR (prop
), Qspace
)
2466 && !EQ (XCAR (prop
), Qimage
))
2468 location
= XCAR (prop
);
2469 value
= XCDR (prop
);
2477 #ifdef HAVE_WINDOW_SYSTEM
2478 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2479 valid_p
= STRINGP (value
);
2481 valid_p
= (STRINGP (value
)
2482 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2483 || valid_image_p (value
));
2484 #else /* not HAVE_WINDOW_SYSTEM */
2485 valid_p
= STRINGP (value
);
2486 #endif /* not HAVE_WINDOW_SYSTEM */
2488 if ((EQ (location
, Qleft_margin
)
2489 || EQ (location
, Qright_margin
)
2493 /* Save current settings of IT so that we can restore them
2494 when we are finished with the glyph property value. */
2497 if (NILP (location
))
2498 it
->area
= TEXT_AREA
;
2499 else if (EQ (location
, Qleft_margin
))
2500 it
->area
= LEFT_MARGIN_AREA
;
2502 it
->area
= RIGHT_MARGIN_AREA
;
2504 if (STRINGP (value
))
2507 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2508 it
->current
.overlay_string_index
= -1;
2509 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2510 it
->end_charpos
= it
->string_nchars
2511 = XSTRING (it
->string
)->size
;
2512 it
->method
= next_element_from_string
;
2513 it
->stop_charpos
= 0;
2514 it
->string_from_display_prop_p
= 1;
2516 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2518 it
->method
= next_element_from_stretch
;
2520 it
->current
.pos
= it
->position
= start_pos
;
2522 #ifdef HAVE_WINDOW_SYSTEM
2525 it
->what
= IT_IMAGE
;
2526 it
->image_id
= lookup_image (it
->f
, value
);
2527 it
->position
= start_pos
;
2528 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2529 it
->method
= next_element_from_image
;
2531 /* Say that we don't have consumed the characters with
2532 `display' property yet. The call to pop_it in
2533 set_iterator_to_next will clean this up. */
2534 *position
= start_pos
;
2536 #endif /* HAVE_WINDOW_SYSTEM */
2540 return space_or_image_found_p
;
2545 /***********************************************************************
2547 ***********************************************************************/
2549 /* The following structure is used to record overlay strings for
2550 later sorting in load_overlay_strings. */
2552 struct overlay_entry
2560 /* Set up iterator IT from overlay strings at its current position.
2561 Called from handle_stop. */
2563 static enum prop_handled
2564 handle_overlay_change (it
)
2567 /* Overlays are handled in current_buffer only. */
2568 if (STRINGP (it
->string
))
2569 return HANDLED_NORMALLY
;
2571 return (get_overlay_strings (it
)
2572 ? HANDLED_RECOMPUTE_PROPS
2573 : HANDLED_NORMALLY
);
2577 /* Set up the next overlay string for delivery by IT, if there is an
2578 overlay string to deliver. Called by set_iterator_to_next when the
2579 end of the current overlay string is reached. If there are more
2580 overlay strings to display, IT->string and
2581 IT->current.overlay_string_index are set appropriately here.
2582 Otherwise IT->string is set to nil. */
2585 next_overlay_string (it
)
2588 ++it
->current
.overlay_string_index
;
2589 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2591 /* No more overlay strings. Restore IT's settings to what
2592 they were before overlay strings were processed, and
2593 continue to deliver from current_buffer. */
2595 xassert (it
->stop_charpos
>= BEGV
2596 && it
->stop_charpos
<= it
->end_charpos
);
2598 it
->current
.overlay_string_index
= -1;
2599 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2600 it
->n_overlay_strings
= 0;
2601 it
->method
= next_element_from_buffer
;
2605 /* There are more overlay strings to process. If
2606 IT->current.overlay_string_index has advanced to a position
2607 where we must load IT->overlay_strings with more strings, do
2609 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2611 if (it
->current
.overlay_string_index
&& i
== 0)
2612 load_overlay_strings (it
);
2614 /* Initialize IT to deliver display elements from the overlay
2616 it
->string
= it
->overlay_strings
[i
];
2617 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2618 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2619 it
->method
= next_element_from_string
;
2620 it
->stop_charpos
= 0;
2627 /* Compare two overlay_entry structures E1 and E2. Used as a
2628 comparison function for qsort in load_overlay_strings. Overlay
2629 strings for the same position are sorted so that
2631 1. All after-strings come in front of before-strings.
2633 2. Within after-strings, strings are sorted so that overlay strings
2634 from overlays with higher priorities come first.
2636 2. Within before-strings, strings are sorted so that overlay
2637 strings from overlays with higher priorities come last.
2639 Value is analogous to strcmp. */
2643 compare_overlay_entries (e1
, e2
)
2646 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
2647 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
2650 if (entry1
->after_string_p
!= entry2
->after_string_p
)
2651 /* Let after-strings appear in front of before-strings. */
2652 result
= entry1
->after_string_p
? -1 : 1;
2653 else if (entry1
->after_string_p
)
2654 /* After-strings sorted in order of decreasing priority. */
2655 result
= entry2
->priority
- entry1
->priority
;
2657 /* Before-strings sorted in order of increasing priority. */
2658 result
= entry1
->priority
- entry2
->priority
;
2664 /* Load the vector IT->overlay_strings with overlay strings from IT's
2665 current buffer position. Set IT->n_overlays to the total number of
2666 overlay strings found.
2668 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
2669 a time. On entry into load_overlay_strings,
2670 IT->current.overlay_string_index gives the number of overlay
2671 strings that have already been loaded by previous calls to this
2674 Overlay strings are sorted so that after-string strings come in
2675 front of before-string strings. Within before and after-strings,
2676 strings are sorted by overlay priority. See also function
2677 compare_overlay_entries. */
2680 load_overlay_strings (it
)
2683 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
2684 Lisp_Object ov
, overlay
, window
, str
;
2688 struct overlay_entry
*entries
2689 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
2691 /* Append the overlay string STRING of overlay OVERLAY to vector
2692 `entries' which has size `size' and currently contains `n'
2693 elements. AFTER_P non-zero means STRING is an after-string of
2695 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
2698 Lisp_Object priority; \
2702 int new_size = 2 * size; \
2703 struct overlay_entry *old = entries; \
2705 (struct overlay_entry *) alloca (new_size \
2706 * sizeof *entries); \
2707 bcopy (old, entries, size * sizeof *entries); \
2711 entries[n].string = (STRING); \
2712 priority = Foverlay_get ((OVERLAY), Qpriority); \
2713 entries[n].priority \
2714 = INTEGERP (priority) ? XFASTINT (priority) : 0; \
2715 entries[n].after_string_p = (AFTER_P); \
2720 /* Process overlay before the overlay center. */
2721 for (ov
= current_buffer
->overlays_before
;
2723 ov
= XCONS (ov
)->cdr
)
2725 overlay
= XCONS (ov
)->car
;
2726 xassert (OVERLAYP (overlay
));
2727 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2728 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2730 if (end
< IT_CHARPOS (*it
))
2733 /* Skip this overlay if it doesn't start or end at IT's current
2735 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2738 /* Skip this overlay if it doesn't apply to IT->w. */
2739 window
= Foverlay_get (overlay
, Qwindow
);
2740 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2743 /* If overlay has a non-empty before-string, record it. */
2744 if (start
== IT_CHARPOS (*it
)
2745 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2746 && XSTRING (str
)->size
)
2747 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2749 /* If overlay has a non-empty after-string, record it. */
2750 if (end
== IT_CHARPOS (*it
)
2751 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2752 && XSTRING (str
)->size
)
2753 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2756 /* Process overlays after the overlay center. */
2757 for (ov
= current_buffer
->overlays_after
;
2759 ov
= XCONS (ov
)->cdr
)
2761 overlay
= XCONS (ov
)->car
;
2762 xassert (OVERLAYP (overlay
));
2763 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2764 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2766 if (start
> IT_CHARPOS (*it
))
2769 /* Skip this overlay if it doesn't start or end at IT's current
2771 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2774 /* Skip this overlay if it doesn't apply to IT->w. */
2775 window
= Foverlay_get (overlay
, Qwindow
);
2776 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2779 /* If overlay has a non-empty before-string, record it. */
2780 if (start
== IT_CHARPOS (*it
)
2781 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2782 && XSTRING (str
)->size
)
2783 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2785 /* If overlay has a non-empty after-string, record it. */
2786 if (end
== IT_CHARPOS (*it
)
2787 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2788 && XSTRING (str
)->size
)
2789 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2792 #undef RECORD_OVERLAY_STRING
2795 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
2797 /* Record the total number of strings to process. */
2798 it
->n_overlay_strings
= n
;
2800 /* IT->current.overlay_string_index is the number of overlay strings
2801 that have already been consumed by IT. Copy some of the
2802 remaining overlay strings to IT->overlay_strings. */
2804 j
= it
->current
.overlay_string_index
;
2805 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
2806 it
->overlay_strings
[i
++] = entries
[j
++].string
;
2812 /* Get the first chunk of overlay strings at IT's current buffer
2813 position. Value is non-zero if at least one overlay string was
2817 get_overlay_strings (it
)
2820 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
2821 process. This fills IT->overlay_strings with strings, and sets
2822 IT->n_overlay_strings to the total number of strings to process.
2823 IT->pos.overlay_string_index has to be set temporarily to zero
2824 because load_overlay_strings needs this; it must be set to -1
2825 when no overlay strings are found because a zero value would
2826 indicate a position in the first overlay string. */
2827 it
->current
.overlay_string_index
= 0;
2828 load_overlay_strings (it
);
2830 /* If we found overlay strings, set up IT to deliver display
2831 elements from the first one. Otherwise set up IT to deliver
2832 from current_buffer. */
2833 if (it
->n_overlay_strings
)
2835 /* Make sure we know settings in current_buffer, so that we can
2836 restore meaningful values when we're done with the overlay
2838 compute_stop_pos (it
);
2839 xassert (it
->face_id
>= 0);
2841 /* Save IT's settings. They are restored after all overlay
2842 strings have been processed. */
2843 xassert (it
->sp
== 0);
2846 /* Set up IT to deliver display elements from the first overlay
2848 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2849 it
->stop_charpos
= 0;
2850 it
->string
= it
->overlay_strings
[0];
2851 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2852 xassert (STRINGP (it
->string
));
2853 it
->method
= next_element_from_string
;
2858 it
->current
.overlay_string_index
= -1;
2859 it
->method
= next_element_from_buffer
;
2864 /* Value is non-zero if we found at least one overlay string. */
2865 return STRINGP (it
->string
);
2870 /***********************************************************************
2871 Saving and restoring state
2872 ***********************************************************************/
2874 /* Save current settings of IT on IT->stack. Called, for example,
2875 before setting up IT for an overlay string, to be able to restore
2876 IT's settings to what they were after the overlay string has been
2883 struct iterator_stack_entry
*p
;
2885 xassert (it
->sp
< 2);
2886 p
= it
->stack
+ it
->sp
;
2888 p
->stop_charpos
= it
->stop_charpos
;
2889 xassert (it
->face_id
>= 0);
2890 p
->face_id
= it
->face_id
;
2891 p
->string
= it
->string
;
2892 p
->pos
= it
->current
;
2893 p
->end_charpos
= it
->end_charpos
;
2894 p
->string_nchars
= it
->string_nchars
;
2896 p
->multibyte_p
= it
->multibyte_p
;
2897 p
->space_width
= it
->space_width
;
2898 p
->font_height
= it
->font_height
;
2899 p
->voffset
= it
->voffset
;
2900 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
2905 /* Restore IT's settings from IT->stack. Called, for example, when no
2906 more overlay strings must be processed, and we return to delivering
2907 display elements from a buffer, or when the end of a string from a
2908 `display' property is reached and we return to delivering display
2909 elements from an overlay string, or from a buffer. */
2915 struct iterator_stack_entry
*p
;
2917 xassert (it
->sp
> 0);
2919 p
= it
->stack
+ it
->sp
;
2920 it
->stop_charpos
= p
->stop_charpos
;
2921 it
->face_id
= p
->face_id
;
2922 it
->string
= p
->string
;
2923 it
->current
= p
->pos
;
2924 it
->end_charpos
= p
->end_charpos
;
2925 it
->string_nchars
= p
->string_nchars
;
2927 it
->multibyte_p
= p
->multibyte_p
;
2928 it
->space_width
= p
->space_width
;
2929 it
->font_height
= p
->font_height
;
2930 it
->voffset
= p
->voffset
;
2931 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
2936 /***********************************************************************
2938 ***********************************************************************/
2940 /* Set IT's current position to the previous line start. */
2943 back_to_previous_line_start (it
)
2946 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
2947 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
2951 /* Set IT's current position to the next line start. */
2954 forward_to_next_line_start (it
)
2957 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), 1);
2958 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
2962 /* Set IT's current position to the previous visible line start. Skip
2963 invisible text that is so either due to text properties or due to
2964 selective display. Caution: this does not change IT->current_x and
2968 back_to_previous_visible_line_start (it
)
2973 /* Go back one newline if not on BEGV already. */
2974 if (IT_CHARPOS (*it
) > BEGV
)
2975 back_to_previous_line_start (it
);
2977 /* Move over lines that are invisible because of selective display
2978 or text properties. */
2979 while (IT_CHARPOS (*it
) > BEGV
2984 /* If selective > 0, then lines indented more than that values
2986 if (it
->selective
> 0
2987 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
2990 #ifdef USE_TEXT_PROPERTIES
2995 prop
= Fget_char_property (IT_CHARPOS (*it
), Qinvisible
, it
->window
);
2996 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
2999 #endif /* USE_TEXT_PROPERTIES */
3001 /* Back one more newline if the current one is invisible. */
3003 back_to_previous_line_start (it
);
3006 xassert (IT_CHARPOS (*it
) >= BEGV
);
3007 xassert (IT_CHARPOS (*it
) == BEGV
3008 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3013 /* Reseat iterator IT at the previous visible line start. Skip
3014 invisible text that is so either due to text properties or due to
3015 selective display. At the end, update IT's overlay information,
3016 face information etc. */
3019 reseat_at_previous_visible_line_start (it
)
3022 back_to_previous_visible_line_start (it
);
3023 reseat (it
, it
->current
.pos
, 1);
3028 /* Reseat iterator IT on the next visible line start in the current
3029 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3030 preceding the line start. Skip over invisible text that is so
3031 because of selective display. Compute faces, overlays etc at the
3032 new position. Note that this function does not skip over text that
3033 is invisible because of text properties. */
3036 reseat_at_next_visible_line_start (it
, on_newline_p
)
3040 /* Restore the buffer position when currently not delivering display
3041 elements from the current buffer. This is the case, for example,
3042 when called at the end of a truncated overlay string. */
3045 it
->method
= next_element_from_buffer
;
3047 /* Otherwise, scan_buffer would not work. */
3048 if (IT_CHARPOS (*it
) < ZV
)
3050 /* If on a newline, advance past it. Otherwise, find the next
3051 newline which automatically gives us the position following
3053 if (FETCH_BYTE (IT_BYTEPOS (*it
)) == '\n')
3059 forward_to_next_line_start (it
);
3061 /* We must either have reached the end of the buffer or end up
3063 xassert (IT_CHARPOS (*it
) == ZV
3064 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3066 /* Skip over lines that are invisible because they are indented
3067 more than the value of IT->selective. */
3068 if (it
->selective
> 0)
3069 while (IT_CHARPOS (*it
) < ZV
3070 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3072 forward_to_next_line_start (it
);
3074 /* Position on the newline if we should. */
3075 if (on_newline_p
&& IT_CHARPOS (*it
) > BEGV
)
3078 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3081 /* Set the iterator there. The 0 as the last parameter of
3082 reseat means don't force a text property lookup. The lookup
3083 is then only done if we've skipped past the iterator's
3084 check_charpos'es. This optimization is important because
3085 text property lookups tend to be expensive. */
3086 reseat (it
, it
->current
.pos
, 0);
3094 /***********************************************************************
3095 Changing an iterator's position
3096 ***********************************************************************/
3098 /* Change IT's current position to POS in current_buffer. If FORCE_P
3099 is non-zero, always check for text properties at the new position.
3100 Otherwise, text properties are only looked up if POS >=
3101 IT->check_charpos of a property. */
3104 reseat (it
, pos
, force_p
)
3106 struct text_pos pos
;
3109 int original_pos
= IT_CHARPOS (*it
);
3111 reseat_1 (it
, pos
, 0);
3113 /* Determine where to check text properties. Avoid doing it
3114 where possible because text property lookup is very expensive. */
3116 || CHARPOS (pos
) > it
->stop_charpos
3117 || CHARPOS (pos
) < original_pos
)
3124 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3125 IT->stop_pos to POS, also. */
3128 reseat_1 (it
, pos
, set_stop_p
)
3130 struct text_pos pos
;
3133 /* Don't call this function when scanning a C string. */
3134 xassert (it
->s
== NULL
);
3136 /* POS must be a reasonable value. */
3137 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3139 it
->current
.pos
= it
->position
= pos
;
3140 XSETBUFFER (it
->object
, current_buffer
);
3142 it
->current
.dpvec_index
= -1;
3143 it
->current
.overlay_string_index
= -1;
3144 IT_STRING_CHARPOS (*it
) = -1;
3145 IT_STRING_BYTEPOS (*it
) = -1;
3147 it
->method
= next_element_from_buffer
;
3151 it
->stop_charpos
= CHARPOS (pos
);
3155 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3156 If S is non-null, it is a C string to iterate over. Otherwise,
3157 STRING gives a Lisp string to iterate over.
3159 If PRECISION > 0, don't return more then PRECISION number of
3160 characters from the string.
3162 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3163 characters have been returned. FIELD_WIDTH < 0 means an infinite
3166 MULTIBYTE = 0 means disable processing of multibyte characters,
3167 MULTIBYTE > 0 means enable it,
3168 MULTIBYTE < 0 means use IT->multibyte_p.
3170 IT must be initialized via a prior call to init_iterator before
3171 calling this function. */
3174 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3179 int precision
, field_width
, multibyte
;
3181 /* No region in strings. */
3182 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3184 /* No text property checks performed by default, but see below. */
3185 it
->stop_charpos
= -1;
3187 /* Set iterator position and end position. */
3188 bzero (&it
->current
, sizeof it
->current
);
3189 it
->current
.overlay_string_index
= -1;
3190 it
->current
.dpvec_index
= -1;
3191 it
->charset
= CHARSET_ASCII
;
3192 xassert (charpos
>= 0);
3194 /* Use the setting of MULTIBYTE if specified. */
3196 it
->multibyte_p
= multibyte
> 0;
3200 xassert (STRINGP (string
));
3201 it
->string
= string
;
3203 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3204 it
->method
= next_element_from_string
;
3205 it
->current
.string_pos
= string_pos (charpos
, string
);
3212 /* Note that we use IT->current.pos, not it->current.string_pos,
3213 for displaying C strings. */
3214 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3215 if (it
->multibyte_p
)
3217 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3218 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3222 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3223 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3226 it
->method
= next_element_from_c_string
;
3229 /* PRECISION > 0 means don't return more than PRECISION characters
3231 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3232 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3234 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3235 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3236 FIELD_WIDTH < 0 means infinite field width. This is useful for
3237 padding with `-' at the end of a mode line. */
3238 if (field_width
< 0)
3239 field_width
= INFINITY
;
3240 if (field_width
> it
->end_charpos
- charpos
)
3241 it
->end_charpos
= charpos
+ field_width
;
3243 /* Use the standard display table for displaying strings. */
3244 if (DISP_TABLE_P (Vstandard_display_table
))
3245 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3247 it
->stop_charpos
= charpos
;
3253 /***********************************************************************
3255 ***********************************************************************/
3257 /* Load IT's display element fields with information about the next
3258 display element from the current position of IT. Value is zero if
3259 end of buffer (or C string) is reached. */
3262 get_next_display_element (it
)
3265 /* Non-zero means that we found an display element. Zero means that
3266 we hit the end of what we iterate over. Performance note: the
3267 function pointer `method' used here turns out to be faster than
3268 using a sequence of if-statements. */
3269 int success_p
= (*it
->method
) (it
);
3272 if (it
->what
== IT_CHARACTER
)
3274 /* Map via display table or translate control characters.
3275 IT->c, IT->len etc. have been set to the next character by
3276 the function call above. If we have a display table, and it
3277 contains an entry for IT->c, translate it. Don't do this if
3278 IT->c itself comes from a display table, otherwise we could
3279 end up in an infinite recursion. (An alternative could be to
3280 count the recursion depth of this function and signal an
3281 error when a certain maximum depth is reached.) Is it worth
3283 if (success_p
&& it
->dpvec
== NULL
)
3288 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3291 struct Lisp_Vector
*v
= XVECTOR (dv
);
3293 /* Return the first character from the display table
3294 entry, if not empty. If empty, don't display the
3295 current character. */
3298 it
->dpvec_char_len
= it
->len
;
3299 it
->dpvec
= v
->contents
;
3300 it
->dpend
= v
->contents
+ v
->size
;
3301 it
->current
.dpvec_index
= 0;
3302 it
->method
= next_element_from_display_vector
;
3305 success_p
= get_next_display_element (it
);
3308 /* Translate control characters into `\003' or `^C' form.
3309 Control characters coming from a display table entry are
3310 currently not translated because we use IT->dpvec to hold
3311 the translation. This could easily be changed but I
3312 don't believe that it is worth doing. */
3313 else if ((it
->c
< ' '
3314 && (it
->area
!= TEXT_AREA
3315 || (it
->c
!= '\n' && it
->c
!= '\t')))
3319 /* IT->c is a control character which must be displayed
3320 either as '\003' or as `^C' where the '\\' and '^'
3321 can be defined in the display table. Fill
3322 IT->ctl_chars with glyphs for what we have to
3323 display. Then, set IT->dpvec to these glyphs. */
3326 if (it
->c
< 128 && it
->ctl_arrow_p
)
3328 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3330 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3331 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3332 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3334 g
= FAST_MAKE_GLYPH ('^', 0);
3335 XSETINT (it
->ctl_chars
[0], g
);
3337 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3338 XSETINT (it
->ctl_chars
[1], g
);
3340 /* Set up IT->dpvec and return first character from it. */
3341 it
->dpvec_char_len
= it
->len
;
3342 it
->dpvec
= it
->ctl_chars
;
3343 it
->dpend
= it
->dpvec
+ 2;
3344 it
->current
.dpvec_index
= 0;
3345 it
->method
= next_element_from_display_vector
;
3346 get_next_display_element (it
);
3350 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3352 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3353 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3354 g
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3356 g
= FAST_MAKE_GLYPH ('\\', 0);
3357 XSETINT (it
->ctl_chars
[0], g
);
3359 /* Insert three more glyphs into IT->ctl_chars for
3360 the octal display of the character. */
3361 g
= FAST_MAKE_GLYPH (((it
->c
>> 6) & 7) + '0', 0);
3362 XSETINT (it
->ctl_chars
[1], g
);
3363 g
= FAST_MAKE_GLYPH (((it
->c
>> 3) & 7) + '0', 0);
3364 XSETINT (it
->ctl_chars
[2], g
);
3365 g
= FAST_MAKE_GLYPH ((it
->c
& 7) + '0', 0);
3366 XSETINT (it
->ctl_chars
[3], g
);
3368 /* Set up IT->dpvec and return the first character
3370 it
->dpvec_char_len
= it
->len
;
3371 it
->dpvec
= it
->ctl_chars
;
3372 it
->dpend
= it
->dpvec
+ 4;
3373 it
->current
.dpvec_index
= 0;
3374 it
->method
= next_element_from_display_vector
;
3375 get_next_display_element (it
);
3380 /* Adjust face id if charset changes. There are no charset
3381 changes in unibyte text because Emacs' charsets are not
3382 applicable there. */
3385 && (charset
= CHAR_CHARSET (it
->c
),
3386 charset
!= it
->charset
))
3388 it
->charset
= charset
;
3389 it
->face_id
= FACE_FOR_CHARSET (it
->f
, it
->face_id
, charset
);
3393 /* Is this character the last one of a run of characters with
3394 box? If yes, set IT->end_of_box_run_p to 1. */
3401 it
->end_of_box_run_p
3402 = ((face_id
= face_after_it_pos (it
),
3403 face_id
!= it
->face_id
)
3404 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3405 face
->box
== FACE_NO_BOX
));
3408 /* Value is 0 if end of buffer or string reached. */
3413 /* Move IT to the next display element.
3415 Functions get_next_display_element and set_iterator_to_next are
3416 separate because I find this arrangement easier to handle than a
3417 get_next_display_element function that also increments IT's
3418 position. The way it is we can first look at an iterator's current
3419 display element, decide whether it fits on a line, and if it does,
3420 increment the iterator position. The other way around we probably
3421 would either need a flag indicating whether the iterator has to be
3422 incremented the next time, or we would have to implement a
3423 decrement position function which would not be easy to write. */
3426 set_iterator_to_next (it
)
3429 if (it
->method
== next_element_from_buffer
)
3431 /* The current display element of IT is a character from
3432 current_buffer. Advance in the buffer, and maybe skip over
3433 invisible lines that are so because of selective display. */
3434 if (ITERATOR_AT_END_OF_LINE_P (it
))
3435 reseat_at_next_visible_line_start (it
, 0);
3438 xassert (it
->len
!= 0);
3439 IT_BYTEPOS (*it
) += it
->len
;
3440 IT_CHARPOS (*it
) += 1;
3441 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3444 else if (it
->method
== next_element_from_c_string
)
3446 /* Current display element of IT is from a C string. */
3447 IT_BYTEPOS (*it
) += it
->len
;
3448 IT_CHARPOS (*it
) += 1;
3450 else if (it
->method
== next_element_from_display_vector
)
3452 /* Current display element of IT is from a display table entry.
3453 Advance in the display table definition. Reset it to null if
3454 end reached, and continue with characters from buffers/
3456 ++it
->current
.dpvec_index
;
3458 /* Restore face and charset of the iterator to what they were
3459 before the display vector entry (these entries may contain
3460 faces, and of course characters of different charsets). */
3461 it
->face_id
= it
->saved_face_id
;
3462 it
->charset
= FACE_FROM_ID (it
->f
, it
->face_id
)->charset
;
3464 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3467 it
->method
= next_element_from_c_string
;
3468 else if (STRINGP (it
->string
))
3469 it
->method
= next_element_from_string
;
3471 it
->method
= next_element_from_buffer
;
3474 it
->current
.dpvec_index
= -1;
3476 /* Skip over characters which were displayed via IT->dpvec. */
3477 if (it
->dpvec_char_len
< 0)
3478 reseat_at_next_visible_line_start (it
, 1);
3479 else if (it
->dpvec_char_len
> 0)
3481 it
->len
= it
->dpvec_char_len
;
3482 set_iterator_to_next (it
);
3486 else if (it
->method
== next_element_from_string
)
3488 /* Current display element is a character from a Lisp string. */
3489 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3490 IT_STRING_BYTEPOS (*it
) += it
->len
;
3491 IT_STRING_CHARPOS (*it
) += 1;
3493 consider_string_end
:
3495 if (it
->current
.overlay_string_index
>= 0)
3497 /* IT->string is an overlay string. Advance to the
3498 next, if there is one. */
3499 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3500 next_overlay_string (it
);
3504 /* IT->string is not an overlay string. If we reached
3505 its end, and there is something on IT->stack, proceed
3506 with what is on the stack. This can be either another
3507 string, this time an overlay string, or a buffer. */
3508 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3512 if (!STRINGP (it
->string
))
3513 it
->method
= next_element_from_buffer
;
3517 else if (it
->method
== next_element_from_image
3518 || it
->method
== next_element_from_stretch
)
3520 /* The position etc with which we have to proceed are on
3521 the stack. The position may be at the end of a string,
3522 if the `display' property takes up the whole string. */
3525 if (STRINGP (it
->string
))
3527 it
->method
= next_element_from_string
;
3528 goto consider_string_end
;
3531 it
->method
= next_element_from_buffer
;
3534 /* There are no other methods defined, so this should be a bug. */
3537 /* Reset flags indicating start and end of a sequence of
3538 characters with box. */
3539 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3541 xassert (it
->method
!= next_element_from_string
3542 || (STRINGP (it
->string
)
3543 && IT_STRING_CHARPOS (*it
) >= 0));
3547 /* Load IT's display element fields with information about the next
3548 display element which comes from a display table entry or from the
3549 result of translating a control character to one of the forms `^C'
3550 or `\003'. IT->dpvec holds the glyphs to return as characters. */
3553 next_element_from_display_vector (it
)
3557 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
3559 /* Remember the current face id in case glyphs specify faces.
3560 IT's face is restored in set_iterator_to_next. */
3561 it
->saved_face_id
= it
->face_id
;
3563 if (INTEGERP (*it
->dpvec
)
3564 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
3569 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
3570 it
->c
= FAST_GLYPH_CHAR (g
);
3571 it
->len
= CHAR_LEN (it
->c
);
3573 /* The entry may contain a face id to use. Such a face id is
3574 the id of a Lisp face, not a realized face. A face id of
3575 zero means no face. */
3576 lface_id
= FAST_GLYPH_FACE (g
);
3579 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
3582 it
->face_id
= face_id
;
3583 it
->charset
= CHARSET_ASCII
;
3588 /* Display table entry is invalid. Return a space. */
3589 it
->c
= ' ', it
->len
= 1;
3591 /* Don't change position and object of the iterator here. They are
3592 still the values of the character that had this display table
3593 entry or was translated, and that's what we want. */
3594 it
->what
= IT_CHARACTER
;
3599 /* Load IT with the next display element from Lisp string IT->string.
3600 IT->current.string_pos is the current position within the string.
3601 If IT->current.overlay_string_index >= 0, the Lisp string is an
3605 next_element_from_string (it
)
3608 struct text_pos position
;
3610 xassert (STRINGP (it
->string
));
3611 xassert (IT_STRING_CHARPOS (*it
) >= 0);
3612 position
= it
->current
.string_pos
;
3614 /* Time to check for invisible text? */
3615 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
3616 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
3620 /* Since a handler may have changed IT->method, we must
3622 return get_next_display_element (it
);
3625 if (it
->current
.overlay_string_index
>= 0)
3627 /* Get the next character from an overlay string. In overlay
3628 strings, There is no field width or padding with spaces to
3630 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3635 else if (STRING_MULTIBYTE (it
->string
))
3637 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
3638 - IT_STRING_BYTEPOS (*it
));
3639 unsigned char *s
= (XSTRING (it
->string
)->data
3640 + IT_STRING_BYTEPOS (*it
));
3641 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
3645 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3651 /* Get the next character from a Lisp string that is not an
3652 overlay string. Such strings come from the mode line, for
3653 example. We may have to pad with spaces, or truncate the
3654 string. See also next_element_from_c_string. */
3655 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
3660 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
3662 /* Pad with spaces. */
3663 it
->c
= ' ', it
->len
= 1;
3664 CHARPOS (position
) = BYTEPOS (position
) = -1;
3666 else if (STRING_MULTIBYTE (it
->string
))
3668 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
3669 - IT_STRING_BYTEPOS (*it
));
3670 unsigned char *s
= (XSTRING (it
->string
)->data
3671 + IT_STRING_BYTEPOS (*it
));
3672 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
3676 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3681 /* Record what we have and where it came from. Note that we store a
3682 buffer position in IT->position although it could arguably be a
3684 it
->what
= IT_CHARACTER
;
3685 it
->object
= it
->string
;
3686 it
->position
= position
;
3691 /* Load IT with next display element from C string IT->s.
3692 IT->string_nchars is the maximum number of characters to return
3693 from the string. IT->end_charpos may be greater than
3694 IT->string_nchars when this function is called, in which case we
3695 may have to return padding spaces. Value is zero if end of string
3696 reached, including padding spaces. */
3699 next_element_from_c_string (it
)
3705 it
->what
= IT_CHARACTER
;
3706 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
3709 /* IT's position can be greater IT->string_nchars in case a field
3710 width or precision has been specified when the iterator was
3712 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3714 /* End of the game. */
3718 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
3720 /* Pad with spaces. */
3721 it
->c
= ' ', it
->len
= 1;
3722 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
3724 else if (it
->multibyte_p
)
3726 /* Implementation note: The calls to strlen apparently aren't a
3727 performance problem because there is no noticeable performance
3728 difference between Emacs running in unibyte or multibyte mode. */
3729 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
3730 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
3734 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
3740 /* Set up IT to return characters from an ellipsis, if appropriate.
3741 The definition of the ellipsis glyphs may come from a display table
3742 entry. This function Fills IT with the first glyph from the
3743 ellipsis if an ellipsis is to be displayed. */
3746 next_element_from_ellipsis (it
)
3749 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3751 /* Use the display table definition for `...'. Invalid glyphs
3752 will be handled by the method returning elements from dpvec. */
3753 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3754 it
->dpvec_char_len
= it
->len
;
3755 it
->dpvec
= v
->contents
;
3756 it
->dpend
= v
->contents
+ v
->size
;
3757 it
->current
.dpvec_index
= 0;
3758 it
->method
= next_element_from_display_vector
;
3759 get_next_display_element (it
);
3761 else if (it
->selective_display_ellipsis_p
)
3763 /* Use default `...' which is stored in default_invis_vector. */
3764 it
->dpvec_char_len
= it
->len
;
3765 it
->dpvec
= default_invis_vector
;
3766 it
->dpend
= default_invis_vector
+ 3;
3767 it
->current
.dpvec_index
= 0;
3768 it
->method
= next_element_from_display_vector
;
3769 get_next_display_element (it
);
3774 /* Deliver an image display element. The iterator IT is already
3775 filled with image information (done in handle_display_prop). Value
3780 next_element_from_image (it
)
3783 it
->what
= IT_IMAGE
;
3788 /* Fill iterator IT with next display element from a stretch glyph
3789 property. IT->object is the value of the text property. Value is
3793 next_element_from_stretch (it
)
3796 it
->what
= IT_STRETCH
;
3801 /* Load IT with the next display element from current_buffer. Value
3802 is zero if end of buffer reached. IT->stop_charpos is the next
3803 position at which to stop and check for text properties or buffer
3807 next_element_from_buffer (it
)
3812 /* Check this assumption, otherwise, we would never enter the
3813 if-statement, below. */
3814 xassert (IT_CHARPOS (*it
) >= BEGV
3815 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
3817 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
3819 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3821 int overlay_strings_follow_p
;
3823 /* End of the game, except when overlay strings follow that
3824 haven't been returned yet. */
3825 if (it
->overlay_strings_at_end_processed_p
)
3826 overlay_strings_follow_p
= 0;
3829 it
->overlay_strings_at_end_processed_p
= 1;
3830 overlay_strings_follow_p
3831 = get_overlay_strings (it
);
3834 if (overlay_strings_follow_p
)
3835 success_p
= get_next_display_element (it
);
3839 it
->position
= it
->current
.pos
;
3846 return get_next_display_element (it
);
3851 /* No face changes, overlays etc. in sight, so just return a
3852 character from current_buffer. */
3855 /* Maybe run the redisplay end trigger hook. Performance note:
3856 This doesn't seem to cost measurable time. */
3857 if (it
->redisplay_end_trigger_charpos
3859 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
3860 run_redisplay_end_trigger_hook (it
);
3862 /* Get the next character, maybe multibyte. */
3863 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
3864 if (it
->multibyte_p
)
3866 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
3867 - IT_BYTEPOS (*it
));
3868 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
3871 it
->c
= *p
, it
->len
= 1;
3873 /* Record what we have and where it came from. */
3874 it
->what
= IT_CHARACTER
;;
3875 it
->object
= it
->w
->buffer
;
3876 it
->position
= it
->current
.pos
;
3878 /* Normally we return the character found above, except when we
3879 really want to return an ellipsis for selective display. */
3884 /* A value of selective > 0 means hide lines indented more
3885 than that number of columns. */
3886 if (it
->selective
> 0
3887 && IT_CHARPOS (*it
) + 1 < ZV
3888 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
3889 IT_BYTEPOS (*it
) + 1,
3892 next_element_from_ellipsis (it
);
3893 it
->dpvec_char_len
= -1;
3896 else if (it
->c
== '\r' && it
->selective
== -1)
3898 /* A value of selective == -1 means that everything from the
3899 CR to the end of the line is invisible, with maybe an
3900 ellipsis displayed for it. */
3901 next_element_from_ellipsis (it
);
3902 it
->dpvec_char_len
= -1;
3907 /* Value is zero if end of buffer reached. */
3908 xassert (!success_p
|| it
->len
> 0);
3913 /* Run the redisplay end trigger hook for IT. */
3916 run_redisplay_end_trigger_hook (it
)
3919 Lisp_Object args
[3];
3921 /* IT->glyph_row should be non-null, i.e. we should be actually
3922 displaying something, or otherwise we should not run the hook. */
3923 xassert (it
->glyph_row
);
3925 /* Set up hook arguments. */
3926 args
[0] = Qredisplay_end_trigger_functions
;
3927 args
[1] = it
->window
;
3928 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
3929 it
->redisplay_end_trigger_charpos
= 0;
3931 /* Since we are *trying* to run these functions, don't try to run
3932 them again, even if they get an error. */
3933 it
->w
->redisplay_end_trigger
= Qnil
;
3934 Frun_hook_with_args (3, args
);
3936 /* Notice if it changed the face of the character we are on. */
3937 handle_face_prop (it
);
3942 /***********************************************************************
3943 Moving an iterator without producing glyphs
3944 ***********************************************************************/
3946 /* Move iterator IT to a specified buffer or X position within one
3947 line on the display without producing glyphs.
3949 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
3950 whichever is reached first.
3952 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
3954 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
3955 0 <= TO_X <= IT->last_visible_x. This means in particular, that
3956 TO_X includes the amount by which a window is horizontally
3961 MOVE_POS_MATCH_OR_ZV
3962 - when TO_POS or ZV was reached.
3965 -when TO_X was reached before TO_POS or ZV were reached.
3968 - when we reached the end of the display area and the line must
3972 - when we reached the end of the display area and the line is
3976 - when we stopped at a line end, i.e. a newline or a CR and selective
3980 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
3982 int to_charpos
, to_x
, op
;
3984 enum move_it_result result
= MOVE_UNDEFINED
;
3985 struct glyph_row
*saved_glyph_row
;
3987 /* Don't produce glyphs in produce_glyphs. */
3988 saved_glyph_row
= it
->glyph_row
;
3989 it
->glyph_row
= NULL
;
3995 /* Stop when ZV or TO_CHARPOS reached. */
3996 if (!get_next_display_element (it
)
3997 || ((op
& MOVE_TO_POS
) != 0
3998 && BUFFERP (it
->object
)
3999 && IT_CHARPOS (*it
) >= to_charpos
))
4001 result
= MOVE_POS_MATCH_OR_ZV
;
4005 /* The call to produce_glyphs will get the metrics of the
4006 display element IT is loaded with. We record in x the
4007 x-position before this display element in case it does not
4010 PRODUCE_GLYPHS (it
);
4012 if (it
->area
!= TEXT_AREA
)
4014 set_iterator_to_next (it
);
4018 /* The number of glyphs we get back in IT->nglyphs will normally
4019 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4020 character on a terminal frame, or (iii) a line end. For the
4021 second case, IT->nglyphs - 1 padding glyphs will be present
4022 (on X frames, there is only one glyph produced for a
4023 composite character.
4025 The behavior implemented below means, for continuation lines,
4026 that as many spaces of a TAB as fit on the current line are
4027 displayed there. For terminal frames, as many glyphs of a
4028 multi-glyph character are displayed in the current line, too.
4029 This is what the old redisplay code did, and we keep it that
4030 way. Under X, the whole shape of a complex character must
4031 fit on the line or it will be completely displayed in the
4034 Note that both for tabs and padding glyphs, all glyphs have
4038 /* More than one glyph or glyph doesn't fit on line. All
4039 glyphs have the same width. */
4040 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4043 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4045 new_x
= x
+ single_glyph_width
;
4047 /* We want to leave anything reaching TO_X to the caller. */
4048 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4051 result
= MOVE_X_REACHED
;
4054 else if (/* Lines are continued. */
4055 !it
->truncate_lines_p
4056 && (/* And glyph doesn't fit on the line. */
4057 new_x
> it
->last_visible_x
4058 /* Or it fits exactly and we're on a window
4060 || (new_x
== it
->last_visible_x
4061 && FRAME_WINDOW_P (it
->f
))))
4063 if (/* IT->hpos == 0 means the very first glyph
4064 doesn't fit on the line, e.g. a wide image. */
4066 || (new_x
== it
->last_visible_x
4067 && FRAME_WINDOW_P (it
->f
)))
4070 it
->current_x
= new_x
;
4071 if (i
== it
->nglyphs
- 1)
4072 set_iterator_to_next (it
);
4077 result
= MOVE_LINE_CONTINUED
;
4080 else if (new_x
> it
->first_visible_x
)
4082 /* Glyph is visible. Increment number of glyphs that
4083 would be displayed. */
4088 /* Glyph is completely off the left margin of the display
4089 area. Nothing to do. */
4093 if (result
!= MOVE_UNDEFINED
)
4096 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4098 /* Stop when TO_X specified and reached. This check is
4099 necessary here because of lines consisting of a line end,
4100 only. The line end will not produce any glyphs and we
4101 would never get MOVE_X_REACHED. */
4102 xassert (it
->nglyphs
== 0);
4103 result
= MOVE_X_REACHED
;
4107 /* Is this a line end? If yes, we're done. */
4108 if (ITERATOR_AT_END_OF_LINE_P (it
))
4110 result
= MOVE_NEWLINE_OR_CR
;
4114 /* The current display element has been consumed. Advance
4116 set_iterator_to_next (it
);
4118 /* Stop if lines are truncated and IT's current x-position is
4119 past the right edge of the window now. */
4120 if (it
->truncate_lines_p
4121 && it
->current_x
>= it
->last_visible_x
)
4123 result
= MOVE_LINE_TRUNCATED
;
4128 /* Restore the iterator settings altered at the beginning of this
4130 it
->glyph_row
= saved_glyph_row
;
4135 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4136 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4137 the description of enum move_operation_enum.
4139 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4140 screen line, this function will set IT to the next position >
4144 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4146 int to_charpos
, to_x
, to_y
, to_vpos
;
4149 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4154 if (op
& MOVE_TO_VPOS
)
4156 /* If no TO_CHARPOS and no TO_X specified, stop at the
4157 start of the line TO_VPOS. */
4158 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4160 if (it
->vpos
== to_vpos
)
4162 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4166 /* TO_VPOS >= 0 means stop at TO_X in the line at
4167 TO_VPOS, or at TO_POS, whichever comes first. */
4168 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4170 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4172 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4174 /* We have reached TO_X but not in the line we want. */
4175 skip
= move_it_in_display_line_to (it
, to_charpos
,
4177 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4182 else if (op
& MOVE_TO_Y
)
4184 struct it it_backup
;
4187 /* TO_Y specified means stop at TO_X in the line containing
4188 TO_Y---or at TO_CHARPOS if this is reached first. The
4189 problem is that we can't really tell whether the line
4190 contains TO_Y before we have completely scanned it, and
4191 this may skip past TO_X. What we do is to first scan to
4194 If TO_X is not specified, use a TO_X of zero. The reason
4195 is to make the outcome of this function more predictable.
4196 If we didn't use TO_X == 0, we would stop at the end of
4197 the line which is probably not what a caller would expect
4199 skip
= move_it_in_display_line_to (it
, to_charpos
,
4203 | (op
& MOVE_TO_POS
)));
4205 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4206 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4209 /* If TO_X was reached, we would like to know whether TO_Y
4210 is in the line. This can only be said if we know the
4211 total line height which requires us to scan the rest of
4214 if (skip
== MOVE_X_REACHED
)
4217 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4221 /* Now, decide whether TO_Y is in this line. */
4222 line_height
= it
->max_ascent
+ it
->max_descent
;
4224 if (to_y
>= it
->current_y
4225 && to_y
< it
->current_y
+ line_height
)
4227 if (skip
== MOVE_X_REACHED
)
4228 /* If TO_Y is in this line and TO_X was reached above,
4229 we scanned too far. We have to restore IT's settings
4230 to the ones before skipping. */
4234 else if (skip
== MOVE_X_REACHED
)
4237 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4245 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4249 case MOVE_POS_MATCH_OR_ZV
:
4252 case MOVE_NEWLINE_OR_CR
:
4253 set_iterator_to_next (it
);
4254 it
->continuation_lines_width
= 0;
4257 case MOVE_LINE_TRUNCATED
:
4258 it
->continuation_lines_width
= 0;
4259 reseat_at_next_visible_line_start (it
, 0);
4260 if ((op
& MOVE_TO_POS
) != 0
4261 && IT_CHARPOS (*it
) > to_charpos
)
4265 case MOVE_LINE_CONTINUED
:
4266 it
->continuation_lines_width
+= it
->current_x
;
4273 /* Reset/increment for the next run. */
4274 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4275 it
->current_x
= it
->hpos
= 0;
4276 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4278 last_height
= it
->max_ascent
+ it
->max_descent
;
4279 last_max_ascent
= it
->max_ascent
;
4280 it
->max_ascent
= it
->max_descent
= 0;
4286 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4288 If DY > 0, move IT backward at least that many pixels. DY = 0
4289 means move IT backward to the preceding line start or BEGV. This
4290 function may move over more than DY pixels if IT->current_y - DY
4291 ends up in the middle of a line; in this case IT->current_y will be
4292 set to the top of the line moved to. */
4295 move_it_vertically_backward (it
, dy
)
4299 int nlines
, h
, line_height
;
4301 int start_pos
= IT_CHARPOS (*it
);
4305 /* Estimate how many newlines we must move back. */
4306 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4308 /* Set the iterator's position that many lines back. */
4309 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4310 back_to_previous_visible_line_start (it
);
4312 /* Reseat the iterator here. When moving backward, we don't want
4313 reseat to skip forward over invisible text, set up the iterator
4314 to deliver from overlay strings at the new position etc. So,
4315 use reseat_1 here. */
4316 reseat_1 (it
, it
->current
.pos
, 1);
4318 /* We are now surely at a line start. */
4319 it
->current_x
= it
->hpos
= 0;
4321 /* Move forward and see what y-distance we moved. First move to the
4322 start of the next line so that we get its height. We need this
4323 height to be able to tell whether we reached the specified
4326 it2
.max_ascent
= it2
.max_descent
= 0;
4327 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4328 MOVE_TO_POS
| MOVE_TO_VPOS
);
4329 xassert (IT_CHARPOS (*it
) >= BEGV
);
4330 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4331 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4332 xassert (IT_CHARPOS (*it
) >= BEGV
);
4333 h
= it2
.current_y
- it
->current_y
;
4334 nlines
= it2
.vpos
- it
->vpos
;
4336 /* Correct IT's y and vpos position. */
4342 /* DY == 0 means move to the start of the screen line. The
4343 value of nlines is > 0 if continuation lines were involved. */
4345 move_it_by_lines (it
, nlines
, 1);
4346 xassert (IT_CHARPOS (*it
) <= start_pos
);
4350 /* The y-position we try to reach. Note that h has been
4351 subtracted in front of the if-statement. */
4352 int target_y
= it
->current_y
+ h
- dy
;
4354 /* If we did not reach target_y, try to move further backward if
4355 we can. If we moved too far backward, try to move forward. */
4356 if (target_y
< it
->current_y
4357 && IT_CHARPOS (*it
) > BEGV
)
4359 move_it_vertically (it
, target_y
- it
->current_y
);
4360 xassert (IT_CHARPOS (*it
) >= BEGV
);
4362 else if (target_y
>= it
->current_y
+ line_height
4363 && IT_CHARPOS (*it
) < ZV
)
4365 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4366 xassert (IT_CHARPOS (*it
) >= BEGV
);
4372 /* Move IT by a specified amount of pixel lines DY. DY negative means
4373 move backwards. DY = 0 means move to start of screen line. At the
4374 end, IT will be on the start of a screen line. */
4377 move_it_vertically (it
, dy
)
4382 move_it_vertically_backward (it
, -dy
);
4385 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4386 MOVE_TO_POS
| MOVE_TO_Y
);
4388 /* If buffer ends in ZV without a newline, move to the start of
4389 the line to satisfy the post-condition. */
4390 if (IT_CHARPOS (*it
) == ZV
4391 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4392 move_it_by_lines (it
, 0, 0);
4397 /* Return non-zero if some text between buffer positions START_CHARPOS
4398 and END_CHARPOS is invisible. IT->window is the window for text
4402 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4404 int start_charpos
, end_charpos
;
4406 #ifdef USE_TEXT_PROPERTIES
4407 Lisp_Object prop
, limit
;
4408 int invisible_found_p
;
4410 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4412 /* Is text at START invisible? */
4413 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4415 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4416 invisible_found_p
= 1;
4419 limit
= Fnext_single_property_change (make_number (start_charpos
),
4422 make_number (end_charpos
));
4423 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4426 return invisible_found_p
;
4428 #else /* not USE_TEXT_PROPERTIES */
4430 #endif /* not USE_TEXT_PROPERTIES */
4434 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4435 negative means move up. DVPOS == 0 means move to the start of the
4436 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4437 NEED_Y_P is zero, IT->current_y will be left unchanged.
4439 Further optimization ideas: If we would know that IT->f doesn't use
4440 a face with proportional font, we could be faster for
4441 truncate-lines nil. */
4444 move_it_by_lines (it
, dvpos
, need_y_p
)
4446 int dvpos
, need_y_p
;
4448 struct position pos
;
4450 if (!FRAME_WINDOW_P (it
->f
))
4452 struct text_pos textpos
;
4454 /* We can use vmotion on frames without proportional fonts. */
4455 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4456 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4457 reseat (it
, textpos
, 1);
4458 it
->vpos
+= pos
.vpos
;
4459 it
->current_y
+= pos
.vpos
;
4461 else if (dvpos
== 0)
4463 /* DVPOS == 0 means move to the start of the screen line. */
4464 move_it_vertically_backward (it
, 0);
4465 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4469 /* If there are no continuation lines, and if there is no
4470 selective display, try the simple method of moving forward
4471 DVPOS newlines, then see where we are. */
4472 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4474 int shortage
= 0, charpos
;
4476 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
4477 charpos
= IT_CHARPOS (*it
) + 1;
4479 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
4482 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
4484 struct text_pos pos
;
4485 CHARPOS (pos
) = charpos
;
4486 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4487 reseat (it
, pos
, 1);
4488 it
->vpos
+= dvpos
- shortage
;
4489 it
->hpos
= it
->current_x
= 0;
4494 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
4499 int start_charpos
, i
;
4501 /* If there are no continuation lines, and if there is no
4502 selective display, try the simple method of moving backward
4504 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4507 int charpos
= IT_CHARPOS (*it
);
4508 int bytepos
= IT_BYTEPOS (*it
);
4510 /* If in the middle of a line, go to its start. */
4511 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
4513 charpos
= find_next_newline_no_quit (charpos
, -1);
4514 bytepos
= CHAR_TO_BYTE (charpos
);
4517 if (charpos
== BEGV
)
4519 struct text_pos pos
;
4520 CHARPOS (pos
) = charpos
;
4521 BYTEPOS (pos
) = bytepos
;
4522 reseat (it
, pos
, 1);
4523 it
->hpos
= it
->current_x
= 0;
4528 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
4529 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
4531 struct text_pos pos
;
4532 CHARPOS (pos
) = charpos
;
4533 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4534 reseat (it
, pos
, 1);
4535 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
4536 it
->hpos
= it
->current_x
= 0;
4542 /* Go back -DVPOS visible lines and reseat the iterator there. */
4543 start_charpos
= IT_CHARPOS (*it
);
4544 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
4545 back_to_previous_visible_line_start (it
);
4546 reseat (it
, it
->current
.pos
, 1);
4547 it
->current_x
= it
->hpos
= 0;
4549 /* Above call may have moved too far if continuation lines
4550 are involved. Scan forward and see if it did. */
4552 it2
.vpos
= it2
.current_y
= 0;
4553 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
4554 it
->vpos
-= it2
.vpos
;
4555 it
->current_y
-= it2
.current_y
;
4556 it
->current_x
= it
->hpos
= 0;
4558 /* If we moved too far, move IT some lines forward. */
4559 if (it2
.vpos
> -dvpos
)
4561 int delta
= it2
.vpos
+ dvpos
;
4562 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
4569 /***********************************************************************
4571 ***********************************************************************/
4574 /* Output a newline in the *Messages* buffer if "needs" one. */
4577 message_log_maybe_newline ()
4579 if (message_log_need_newline
)
4580 message_dolog ("", 0, 1, 0);
4584 /* Add a string M of length LEN to the message log, optionally
4585 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
4586 nonzero, means interpret the contents of M as multibyte. This
4587 function calls low-level routines in order to bypass text property
4588 hooks, etc. which might not be safe to run. */
4591 message_dolog (m
, len
, nlflag
, multibyte
)
4593 int len
, nlflag
, multibyte
;
4595 if (!NILP (Vmessage_log_max
))
4597 struct buffer
*oldbuf
;
4598 Lisp_Object oldpoint
, oldbegv
, oldzv
;
4599 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4600 int point_at_end
= 0;
4602 Lisp_Object old_deactivate_mark
, tem
;
4603 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4605 old_deactivate_mark
= Vdeactivate_mark
;
4606 oldbuf
= current_buffer
;
4607 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
4608 current_buffer
->undo_list
= Qt
;
4610 oldpoint
= Fpoint_marker ();
4611 oldbegv
= Fpoint_min_marker ();
4612 oldzv
= Fpoint_max_marker ();
4613 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
4621 BEGV_BYTE
= BEG_BYTE
;
4624 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4626 /* Insert the string--maybe converting multibyte to single byte
4627 or vice versa, so that all the text fits the buffer. */
4629 && NILP (current_buffer
->enable_multibyte_characters
))
4632 unsigned char work
[1];
4634 /* Convert a multibyte string to single-byte
4635 for the *Message* buffer. */
4636 for (i
= 0; i
< len
; i
+= nbytes
)
4638 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
4639 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
4641 : multibyte_char_to_unibyte (c
, Qnil
));
4642 insert_1_both (work
, 1, 1, 1, 0, 0);
4645 else if (! multibyte
4646 && ! NILP (current_buffer
->enable_multibyte_characters
))
4649 unsigned char *msg
= (unsigned char *) m
;
4650 unsigned char *str
, work
[4];
4651 /* Convert a single-byte string to multibyte
4652 for the *Message* buffer. */
4653 for (i
= 0; i
< len
; i
++)
4655 c
= unibyte_char_to_multibyte (msg
[i
]);
4656 nbytes
= CHAR_STRING (c
, work
, str
);
4657 insert_1_both (work
, 1, nbytes
, 1, 0, 0);
4661 insert_1 (m
, len
, 1, 0, 0);
4665 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
4666 insert_1 ("\n", 1, 1, 0, 0);
4668 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4670 this_bol_byte
= PT_BYTE
;
4674 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4676 prev_bol_byte
= PT_BYTE
;
4678 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
4679 this_bol
, this_bol_byte
);
4682 del_range_both (prev_bol
, prev_bol_byte
,
4683 this_bol
, this_bol_byte
, 0);
4689 /* If you change this format, don't forget to also
4690 change message_log_check_duplicate. */
4691 sprintf (dupstr
, " [%d times]", dup
);
4692 duplen
= strlen (dupstr
);
4693 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
4694 insert_1 (dupstr
, duplen
, 1, 0, 1);
4699 if (NATNUMP (Vmessage_log_max
))
4701 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
4702 -XFASTINT (Vmessage_log_max
) - 1, 0);
4703 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
4706 BEGV
= XMARKER (oldbegv
)->charpos
;
4707 BEGV_BYTE
= marker_byte_position (oldbegv
);
4716 ZV
= XMARKER (oldzv
)->charpos
;
4717 ZV_BYTE
= marker_byte_position (oldzv
);
4721 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4723 /* We can't do Fgoto_char (oldpoint) because it will run some
4725 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
4726 XMARKER (oldpoint
)->bytepos
);
4729 free_marker (oldpoint
);
4730 free_marker (oldbegv
);
4731 free_marker (oldzv
);
4733 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
4734 set_buffer_internal (oldbuf
);
4736 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
4737 message_log_need_newline
= !nlflag
;
4738 Vdeactivate_mark
= old_deactivate_mark
;
4743 /* We are at the end of the buffer after just having inserted a newline.
4744 (Note: We depend on the fact we won't be crossing the gap.)
4745 Check to see if the most recent message looks a lot like the previous one.
4746 Return 0 if different, 1 if the new one should just replace it, or a
4747 value N > 1 if we should also append " [N times]". */
4750 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
4751 int prev_bol
, this_bol
;
4752 int prev_bol_byte
, this_bol_byte
;
4755 int len
= Z_BYTE
- 1 - this_bol_byte
;
4757 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
4758 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
4760 for (i
= 0; i
< len
; i
++)
4762 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
4771 if (*p1
++ == ' ' && *p1
++ == '[')
4774 while (*p1
>= '0' && *p1
<= '9')
4775 n
= n
* 10 + *p1
++ - '0';
4776 if (strncmp (p1
, " times]\n", 8) == 0)
4783 /* Display an echo area message M with a specified length of LEN
4784 chars. The string may include null characters. If M is 0, clear
4785 out any existing message, and let the mini-buffer text show through.
4787 The buffer M must continue to exist until after the echo area gets
4788 cleared or some other message gets displayed there. This means do
4789 not pass text that is stored in a Lisp string; do not pass text in
4790 a buffer that was alloca'd. */
4793 message2 (m
, len
, multibyte
)
4798 /* First flush out any partial line written with print. */
4799 message_log_maybe_newline ();
4801 message_dolog (m
, len
, 1, multibyte
);
4802 message2_nolog (m
, len
, multibyte
);
4806 /* The non-logging counterpart of message2. */
4809 message2_nolog (m
, len
, multibyte
)
4813 message_enable_multibyte
= multibyte
;
4817 if (noninteractive_need_newline
)
4818 putc ('\n', stderr
);
4819 noninteractive_need_newline
= 0;
4821 fwrite (m
, len
, 1, stderr
);
4822 if (cursor_in_echo_area
== 0)
4823 fprintf (stderr
, "\n");
4826 /* A null message buffer means that the frame hasn't really been
4827 initialized yet. Error messages get reported properly by
4828 cmd_error, so this must be just an informative message; toss it. */
4829 else if (INTERACTIVE
4830 && selected_frame
->glyphs_initialized_p
4831 && FRAME_MESSAGE_BUF (selected_frame
))
4833 Lisp_Object mini_window
;
4836 /* Get the frame containing the mini-buffer
4837 that the selected frame is using. */
4838 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
4839 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4841 FRAME_SAMPLE_VISIBILITY (f
);
4842 if (FRAME_VISIBLE_P (selected_frame
)
4843 && ! FRAME_VISIBLE_P (f
))
4844 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
4848 set_message (m
, Qnil
, len
, multibyte
);
4849 if (minibuffer_auto_raise
)
4850 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
4853 clear_message (1, 1);
4855 do_pending_window_change (0);
4856 echo_area_display (1);
4857 do_pending_window_change (0);
4858 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
4859 (*frame_up_to_date_hook
) (f
);
4864 /* Display an echo area message M with a specified length of NBYTES
4865 bytes. The string may include null characters. If M is not a
4866 string, clear out any existing message, and let the mini-buffer
4867 text show through. */
4870 message3 (m
, nbytes
, multibyte
)
4875 struct gcpro gcpro1
;
4879 /* First flush out any partial line written with print. */
4880 message_log_maybe_newline ();
4882 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
4883 message3_nolog (m
, nbytes
, multibyte
);
4889 /* The non-logging version of message3. */
4892 message3_nolog (m
, nbytes
, multibyte
)
4894 int nbytes
, multibyte
;
4896 message_enable_multibyte
= multibyte
;
4900 if (noninteractive_need_newline
)
4901 putc ('\n', stderr
);
4902 noninteractive_need_newline
= 0;
4904 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
4905 if (cursor_in_echo_area
== 0)
4906 fprintf (stderr
, "\n");
4909 /* A null message buffer means that the frame hasn't really been
4910 initialized yet. Error messages get reported properly by
4911 cmd_error, so this must be just an informative message; toss it. */
4912 else if (INTERACTIVE
4913 && selected_frame
->glyphs_initialized_p
4914 && FRAME_MESSAGE_BUF (selected_frame
))
4916 Lisp_Object mini_window
;
4920 /* Get the frame containing the mini-buffer
4921 that the selected frame is using. */
4922 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
4923 frame
= XWINDOW (mini_window
)->frame
;
4926 FRAME_SAMPLE_VISIBILITY (f
);
4927 if (FRAME_VISIBLE_P (selected_frame
)
4928 && !FRAME_VISIBLE_P (f
))
4929 Fmake_frame_visible (frame
);
4931 if (STRINGP (m
) && XSTRING (m
)->size
)
4933 set_message (NULL
, m
, nbytes
, multibyte
);
4934 if (minibuffer_auto_raise
)
4935 Fraise_frame (frame
);
4938 clear_message (1, 1);
4940 do_pending_window_change (0);
4941 echo_area_display (1);
4942 do_pending_window_change (0);
4943 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
4944 (*frame_up_to_date_hook
) (f
);
4949 /* Display a null-terminated echo area message M. If M is 0, clear
4950 out any existing message, and let the mini-buffer text show through.
4952 The buffer M must continue to exist until after the echo area gets
4953 cleared or some other message gets displayed there. Do not pass
4954 text that is stored in a Lisp string. Do not pass text in a buffer
4955 that was alloca'd. */
4961 message2 (m
, (m
? strlen (m
) : 0), 0);
4965 /* The non-logging counterpart of message1. */
4971 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
4974 /* Display a message M which contains a single %s
4975 which gets replaced with STRING. */
4978 message_with_string (m
, string
, log
)
4987 if (noninteractive_need_newline
)
4988 putc ('\n', stderr
);
4989 noninteractive_need_newline
= 0;
4990 fprintf (stderr
, m
, XSTRING (string
)->data
);
4991 if (cursor_in_echo_area
== 0)
4992 fprintf (stderr
, "\n");
4996 else if (INTERACTIVE
)
4998 /* The frame whose minibuffer we're going to display the message on.
4999 It may be larger than the selected frame, so we need
5000 to use its buffer, not the selected frame's buffer. */
5001 Lisp_Object mini_window
;
5004 /* Get the frame containing the minibuffer
5005 that the selected frame is using. */
5006 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
5007 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5009 /* A null message buffer means that the frame hasn't really been
5010 initialized yet. Error messages get reported properly by
5011 cmd_error, so this must be just an informative message; toss it. */
5012 if (FRAME_MESSAGE_BUF (f
))
5016 a
[0] = (char *) XSTRING (string
)->data
;
5018 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5019 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5022 message2 (FRAME_MESSAGE_BUF (f
), len
,
5023 STRING_MULTIBYTE (string
));
5025 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5026 STRING_MULTIBYTE (string
));
5028 /* Print should start at the beginning of the message
5029 buffer next time. */
5030 message_buf_print
= 0;
5036 /* Dump an informative message to the minibuf. If M is 0, clear out
5037 any existing message, and let the mini-buffer text show through. */
5041 message (m
, a1
, a2
, a3
)
5043 EMACS_INT a1
, a2
, a3
;
5049 if (noninteractive_need_newline
)
5050 putc ('\n', stderr
);
5051 noninteractive_need_newline
= 0;
5052 fprintf (stderr
, m
, a1
, a2
, a3
);
5053 if (cursor_in_echo_area
== 0)
5054 fprintf (stderr
, "\n");
5058 else if (INTERACTIVE
)
5060 /* The frame whose mini-buffer we're going to display the message
5061 on. It may be larger than the selected frame, so we need to
5062 use its buffer, not the selected frame's buffer. */
5063 Lisp_Object mini_window
;
5066 /* Get the frame containing the mini-buffer
5067 that the selected frame is using. */
5068 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
5069 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5071 /* A null message buffer means that the frame hasn't really been
5072 initialized yet. Error messages get reported properly by
5073 cmd_error, so this must be just an informative message; toss
5075 if (FRAME_MESSAGE_BUF (f
))
5086 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5087 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5089 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5090 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5092 #endif /* NO_ARG_ARRAY */
5094 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5099 /* Print should start at the beginning of the message
5100 buffer next time. */
5101 message_buf_print
= 0;
5107 /* The non-logging version of message. */
5110 message_nolog (m
, a1
, a2
, a3
)
5112 EMACS_INT a1
, a2
, a3
;
5114 Lisp_Object old_log_max
;
5115 old_log_max
= Vmessage_log_max
;
5116 Vmessage_log_max
= Qnil
;
5117 message (m
, a1
, a2
, a3
);
5118 Vmessage_log_max
= old_log_max
;
5122 /* Display the current message in the current mini-buffer. This is
5123 only called from error handlers in process.c, and is not time
5129 if (!NILP (echo_area_buffer
[0]))
5132 string
= Fcurrent_message ();
5133 message3 (string
, XSTRING (string
)->size
,
5134 !NILP (current_buffer
->enable_multibyte_characters
));
5139 /* Call FN with args A1..A5 with either the current or last displayed
5140 echo_area_buffer as current buffer.
5142 WHICH zero means use the current message buffer
5143 echo_area_buffer[0]. If that is nil, choose a suitable buffer
5144 from echo_buffer[] and clear it.
5146 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
5147 suitable buffer from echo_buffer[] and clear it.
5149 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
5150 that the current message becomes the last displayed one, make
5151 choose a suitable buffer for echo_area_buffer[0], and clear it.
5153 Value is what FN returns. */
5156 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
, a5
)
5160 int a1
, a2
, a3
, a4
, a5
;
5163 int i
, this_one
, the_other
, clear_buffer_p
, rc
;
5164 int count
= specpdl_ptr
- specpdl
;
5166 /* If buffers aren't life, make new ones. */
5167 for (i
= 0; i
< 2; ++i
)
5168 if (!BUFFERP (echo_buffer
[i
])
5169 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5172 sprintf (name
, " *Echo Area %d*", i
);
5173 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5179 this_one
= 0, the_other
= 1;
5181 this_one
= 1, the_other
= 0;
5184 this_one
= 0, the_other
= 1;
5187 /* We need a fresh one in case the current echo buffer equals
5188 the one containing the last displayed echo area message. */
5189 if (!NILP (echo_area_buffer
[this_one
])
5190 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
5191 echo_area_buffer
[this_one
] = Qnil
;
5195 /* Choose a suitable buffer from echo_buffer[] is we don't
5197 if (NILP (echo_area_buffer
[this_one
]))
5199 echo_area_buffer
[this_one
]
5200 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
5201 ? echo_buffer
[the_other
]
5202 : echo_buffer
[this_one
]);
5206 buffer
= echo_area_buffer
[this_one
];
5208 record_unwind_protect (unwind_with_echo_area_buffer
,
5209 with_echo_area_buffer_unwind_data (w
));
5211 /* Make the echo area buffer current. Note that for display
5212 purposes, it is not necessary that the displayed window's buffer
5213 == current_buffer, except for text property lookup. So, let's
5214 only set that buffer temporarily here without doing a full
5215 Fset_window_buffer. We must also change w->pointm, though,
5216 because otherwise an assertions in unshow_buffer fails, and Emacs
5218 set_buffer_internal_1 (XBUFFER (buffer
));
5222 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
5224 current_buffer
->truncate_lines
= Qnil
;
5225 current_buffer
->undo_list
= Qt
;
5226 current_buffer
->read_only
= Qnil
;
5228 if (clear_buffer_p
&& Z
> BEG
)
5231 xassert (BEGV
>= BEG
);
5232 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5234 rc
= fn (a1
, a2
, a3
, a4
, a5
);
5236 xassert (BEGV
>= BEG
);
5237 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5239 unbind_to (count
, Qnil
);
5244 /* Save state that should be preserved around the call to the function
5245 FN called in with_echo_area_buffer. */
5248 with_echo_area_buffer_unwind_data (w
)
5254 /* Reduce consing by keeping one vector in
5255 Vwith_echo_area_save_vector. */
5256 vector
= Vwith_echo_area_save_vector
;
5257 Vwith_echo_area_save_vector
= Qnil
;
5260 vector
= Fmake_vector (make_number (7), Qnil
);
5262 XSETBUFFER (XVECTOR (vector
)->contents
[i
], current_buffer
); ++i
;
5263 XVECTOR (vector
)->contents
[i
++] = Vdeactivate_mark
;
5264 XVECTOR (vector
)->contents
[i
++] = make_number (windows_or_buffers_changed
);
5268 XSETWINDOW (XVECTOR (vector
)->contents
[i
], w
); ++i
;
5269 XVECTOR (vector
)->contents
[i
++] = w
->buffer
;
5270 XVECTOR (vector
)->contents
[i
++]
5271 = make_number (XMARKER (w
->pointm
)->charpos
);
5272 XVECTOR (vector
)->contents
[i
++]
5273 = make_number (XMARKER (w
->pointm
)->bytepos
);
5279 XVECTOR (vector
)->contents
[i
++] = Qnil
;
5282 xassert (i
== XVECTOR (vector
)->size
);
5287 /* Restore global state from VECTOR which was created by
5288 with_echo_area_buffer_unwind_data. */
5291 unwind_with_echo_area_buffer (vector
)
5296 set_buffer_internal_1 (XBUFFER (XVECTOR (vector
)->contents
[i
])); ++i
;
5297 Vdeactivate_mark
= XVECTOR (vector
)->contents
[i
]; ++i
;
5298 windows_or_buffers_changed
= XFASTINT (XVECTOR (vector
)->contents
[i
]); ++i
;
5300 if (WINDOWP (XVECTOR (vector
)->contents
[i
]))
5303 Lisp_Object buffer
, charpos
, bytepos
;
5305 w
= XWINDOW (XVECTOR (vector
)->contents
[i
]); ++i
;
5306 buffer
= XVECTOR (vector
)->contents
[i
]; ++i
;
5307 charpos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5308 bytepos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5311 set_marker_both (w
->pointm
, buffer
,
5312 XFASTINT (charpos
), XFASTINT (bytepos
));
5315 Vwith_echo_area_save_vector
= vector
;
5320 /* Set up the echo area for use by print functions. MULTIBYTE_P
5321 non-zero means we will print multibyte. */
5324 setup_echo_area_for_printing (multibyte_p
)
5327 if (!message_buf_print
)
5329 /* A message has been output since the last time we printed.
5330 Choose a fresh echo area buffer. */
5331 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5332 echo_area_buffer
[0] = echo_buffer
[1];
5334 echo_area_buffer
[0] = echo_buffer
[0];
5336 /* Switch to that buffer and clear it. */
5337 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5340 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5342 /* Set up the buffer for the multibyteness we need. */
5344 != !NILP (current_buffer
->enable_multibyte_characters
))
5345 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
5347 /* Raise the frame containing the echo area. */
5348 if (minibuffer_auto_raise
)
5350 Lisp_Object mini_window
;
5351 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
5352 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5355 message_buf_print
= 1;
5357 else if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
5358 /* Someone switched buffers between print requests. */
5359 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5363 /* Display an echo area message in window W. Value is non-zero if W's
5364 height is changed. If display_last_displayed_message_p is
5365 non-zero, display the message that was last displayed, otherwise
5366 display the current message. */
5369 display_echo_area (w
)
5372 int i
, no_message_p
, window_height_changed_p
;
5374 /* If there is no message, we must call display_echo_area_1
5375 nevertheless because it resizes the window. But we will have to
5376 reset the echo_area_buffer in question to nil at the end because
5377 with_echo_area_buffer will sets it to an empty buffer. */
5378 i
= display_last_displayed_message_p
? 1 : 0;
5379 no_message_p
= NILP (echo_area_buffer
[i
]);
5381 window_height_changed_p
5382 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
5383 (int (*) ()) display_echo_area_1
, w
);
5386 echo_area_buffer
[i
] = Qnil
;
5388 return window_height_changed_p
;
5392 /* Helper for display_echo_area. Display the current buffer which
5393 contains the current echo area message in window W, a mini-window.
5394 Change the height of W so that all of the message is displayed.
5395 Value is non-zero if height of W was changed. */
5398 display_echo_area_1 (w
)
5402 struct frame
*f
= XFRAME (w
->frame
);
5403 struct text_pos start
;
5404 int window_height_changed_p
= 0;
5406 /* Do this before displaying, so that we have a large enough glyph
5407 matrix for the display. */
5408 window_height_changed_p
= resize_mini_window (w
);
5411 clear_glyph_matrix (w
->desired_matrix
);
5412 XSETWINDOW (window
, w
);
5413 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
5414 try_window (window
, start
);
5416 return window_height_changed_p
;
5420 /* Resize mini-window W to fit the size of its contents. Value is
5421 non-zero if the window height has been changed. */
5424 resize_mini_window (w
)
5427 struct frame
*f
= XFRAME (w
->frame
);
5428 int window_height_changed_p
= 0;
5430 xassert (MINI_WINDOW_P (w
));
5432 /* Nil means don't try to resize. */
5433 if (NILP (Vmax_mini_window_height
))
5436 if (!FRAME_MINIBUF_ONLY_P (f
))
5439 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5440 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
5441 int height
, max_height
;
5442 int unit
= CANON_Y_UNIT (f
);
5443 struct text_pos start
;
5445 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
5447 /* Compute the max. number of lines specified by the user. */
5448 if (FLOATP (Vmax_mini_window_height
))
5449 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
5450 else if (INTEGERP (Vmax_mini_window_height
))
5451 max_height
= XINT (Vmax_mini_window_height
);
5453 max_height
= total_height
/ 4;
5455 /* Correct that max. height if it's bogus. */
5456 max_height
= max (1, max_height
);
5457 max_height
= min (total_height
, max_height
);
5459 /* Find out the height of the text in the window. */
5460 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
5461 height
= (unit
- 1 + it
.current_y
+ last_height
) / unit
;
5462 height
= max (1, height
);
5464 /* Compute a suitable window start. */
5465 if (height
> max_height
)
5467 height
= max_height
;
5468 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
5469 move_it_vertically_backward (&it
, (height
- 1) * unit
);
5470 start
= it
.current
.pos
;
5473 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5474 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
5476 if (NILP (Vresize_mini_config
))
5478 if (height
!= XFASTINT (w
->height
))
5480 Lisp_Object old_selected_window
;
5482 struct gcpro gcpro1
;
5484 resize_mini_initial_height
= XFASTINT (w
->height
);
5485 config
= Fcurrent_window_configuration (Qnil
);
5488 old_selected_window
= selected_window
;
5489 XSETWINDOW (selected_window
, w
);
5490 change_window_height (height
- XFASTINT (w
->height
), 0);
5491 selected_window
= old_selected_window
;
5493 window_height_changed_p
= 1;
5495 /* Set this after changing window sizes, or else
5496 Vresize_mini_config would be reset in
5497 adjust_frame_glyphs. */
5498 resize_mini_frame
= XFRAME (w
->frame
);
5499 Vresize_mini_config
= config
;
5503 else if (height
!= XFASTINT (w
->height
))
5505 if (height
== resize_mini_initial_height
)
5507 Fset_window_configuration (Vresize_mini_config
);
5508 Vresize_mini_config
= Qnil
;
5509 resize_mini_frame
= NULL
;
5513 Lisp_Object old_selected_window
;
5514 old_selected_window
= selected_window
;
5515 XSETWINDOW (selected_window
, w
);
5516 change_window_height (height
- XFASTINT (w
->height
), 0);
5517 selected_window
= old_selected_window
;
5520 window_height_changed_p
= 1;
5524 return window_height_changed_p
;
5528 /* Value is the current message, a string, or nil if there is no
5536 if (NILP (echo_area_buffer
[0]))
5540 with_echo_area_buffer (0, 0, (int (*) ()) current_message_1
, &msg
);
5542 echo_area_buffer
[0] = Qnil
;
5550 current_message_1 (msg
)
5554 *msg
= make_buffer_string (BEG
, Z
, 1);
5561 /* Push the current message on Vmessage_stack for later restauration
5562 by restore_message. Value is non-zero if the current message isn't
5563 empty. This is a relatively infrequent operation, so it's not
5564 worth optimizing. */
5570 msg
= current_message ();
5571 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
5572 return STRINGP (msg
);
5576 /* Restore message display from the top of Vmessage_stack. */
5583 xassert (CONSP (Vmessage_stack
));
5584 msg
= XCAR (Vmessage_stack
);
5586 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
5588 message3_nolog (msg
, 0, 0);
5592 /* Pop the top-most entry off Vmessage_stack. */
5597 xassert (CONSP (Vmessage_stack
));
5598 Vmessage_stack
= XCDR (Vmessage_stack
);
5602 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
5603 exits. If the stack is not empty, we have a missing pop_message
5607 check_message_stack ()
5609 if (!NILP (Vmessage_stack
))
5614 /* Truncate to NCHARS what will be displayed in the echo area the next
5615 time we display it---but don't redisplay it now. */
5618 truncate_echo_area (nchars
)
5622 echo_area_buffer
[0] = Qnil
;
5623 /* A null message buffer means that the frame hasn't really been
5624 initialized yet. Error messages get reported properly by
5625 cmd_error, so this must be just an informative message; toss it. */
5626 else if (!noninteractive
5628 && FRAME_MESSAGE_BUF (selected_frame
)
5629 && !NILP (echo_area_buffer
[0]))
5630 with_echo_area_buffer (0, 0, (int (*) ()) truncate_message_1
, nchars
);
5634 /* Helper function for truncate_echo_area. Truncate the current
5635 message to at most NCHARS characters. */
5638 truncate_message_1 (nchars
)
5641 if (BEG
+ nchars
< Z
)
5642 del_range (BEG
+ nchars
, Z
);
5644 echo_area_buffer
[0] = Qnil
;
5649 /* Set the current message to a substring of S or STRING.
5651 If STRING is a Lisp string, set the message to the first NBYTES
5652 bytes from STRING. NBYTES zero means use the whole string. If
5653 STRING is multibyte, the message will be displayed multibyte.
5655 If S is not null, set the message to the first LEN bytes of S. LEN
5656 zero means use the whole string. MULTIBYTE_P non-zero means S is
5657 multibyte. Display the message multibyte in that case. */
5660 set_message (s
, string
, nbytes
, multibyte_p
)
5665 message_enable_multibyte
5666 = ((s
&& multibyte_p
)
5667 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
5669 with_echo_area_buffer (0, -1, (int (*) ()) set_message_1
,
5670 s
, string
, nbytes
, multibyte_p
);
5671 message_buf_print
= 0;
5675 /* Helper function for set_message. Arguments have the same meaning
5676 as there. This function is called with the echo area buffer being
5680 set_message_1 (s
, string
, nbytes
, multibyte_p
)
5683 int nbytes
, multibyte_p
;
5687 /* Change multibyteness of the echo buffer appropriately. */
5688 if (message_enable_multibyte
5689 != !NILP (current_buffer
->enable_multibyte_characters
))
5690 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
5692 /* Insert new message at BEG. */
5693 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5695 if (STRINGP (string
))
5700 nbytes
= XSTRING (string
)->size_byte
;
5701 nchars
= string_byte_to_char (string
, nbytes
);
5703 /* This function takes care of single/multibyte conversion. We
5704 just have to ensure that the echo area buffer has the right
5705 setting of enable_multibyte_characters. */
5706 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
5711 nbytes
= strlen (s
);
5713 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
5715 /* Convert from multi-byte to single-byte. */
5717 unsigned char work
[1];
5719 /* Convert a multibyte string to single-byte. */
5720 for (i
= 0; i
< nbytes
; i
+= n
)
5722 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
5723 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5725 : multibyte_char_to_unibyte (c
, Qnil
));
5726 insert_1_both (work
, 1, 1, 1, 0, 0);
5729 else if (!multibyte_p
5730 && !NILP (current_buffer
->enable_multibyte_characters
))
5732 /* Convert from single-byte to multi-byte. */
5734 unsigned char *msg
= (unsigned char *) s
;
5735 unsigned char *str
, work
[4];
5737 /* Convert a single-byte string to multibyte. */
5738 for (i
= 0; i
< nbytes
; i
++)
5740 c
= unibyte_char_to_multibyte (msg
[i
]);
5741 n
= CHAR_STRING (c
, work
, str
);
5742 insert_1_both (work
, 1, n
, 1, 0, 0);
5746 insert_1 (s
, nbytes
, 1, 0, 0);
5753 /* Clear messages. CURRENT_P non-zero means clear the current
5754 message. LAST_DISPLAYED_P non-zero means clear the message
5758 clear_message (current_p
, last_displayed_p
)
5759 int current_p
, last_displayed_p
;
5762 echo_area_buffer
[0] = Qnil
;
5764 if (last_displayed_p
)
5765 echo_area_buffer
[1] = Qnil
;
5767 message_buf_print
= 0;
5770 /* Clear garbaged frames.
5772 This function is used where the old redisplay called
5773 redraw_garbaged_frames which in turn called redraw_frame which in
5774 turn called clear_frame. The call to clear_frame was a source of
5775 flickering. I believe a clear_frame is not necessary. It should
5776 suffice in the new redisplay to invalidate all current matrices,
5777 and ensure a complete redisplay of all windows. */
5780 clear_garbaged_frames ()
5784 Lisp_Object tail
, frame
;
5786 FOR_EACH_FRAME (tail
, frame
)
5788 struct frame
*f
= XFRAME (frame
);
5790 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
5792 clear_current_matrices (f
);
5798 ++windows_or_buffers_changed
;
5803 /* Redisplay the echo area of selected_frame. If UPDATE_FRAME_P is
5804 non-zero update selected_frame. Value is non-zero if the
5805 mini-windows height has been changed. */
5808 echo_area_display (update_frame_p
)
5811 Lisp_Object mini_window
;
5814 int window_height_changed_p
= 0;
5816 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
5817 w
= XWINDOW (mini_window
);
5818 f
= XFRAME (WINDOW_FRAME (w
));
5820 /* Don't display if frame is invisible or not yet initialized. */
5821 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
5824 /* When Emacs starts, selected_frame may be a visible terminal
5825 frame, even if we run under a window system. If we let this
5826 through, a message would be displayed on the terminal. */
5827 #ifdef HAVE_WINDOW_SYSTEM
5828 if (!inhibit_window_system
&& !FRAME_WINDOW_P (selected_frame
))
5830 #endif /* HAVE_WINDOW_SYSTEM */
5832 /* Redraw garbaged frames. */
5834 clear_garbaged_frames ();
5836 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
5838 echo_area_window
= mini_window
;
5839 window_height_changed_p
= display_echo_area (w
);
5840 w
->must_be_updated_p
= 1;
5844 /* Not called from redisplay_internal. If we changed
5845 window configuration, we must redisplay thoroughly.
5846 Otherwise, we can do with updating what we displayed
5848 if (window_height_changed_p
)
5850 ++windows_or_buffers_changed
;
5851 ++update_mode_lines
;
5852 redisplay_internal (0);
5854 else if (FRAME_WINDOW_P (f
))
5856 update_single_window (w
, 1);
5857 rif
->flush_display (f
);
5860 update_frame (f
, 1, 1);
5863 else if (!EQ (mini_window
, selected_window
))
5864 windows_or_buffers_changed
++;
5866 /* Last displayed message is now the current message. */
5867 echo_area_buffer
[1] = echo_area_buffer
[0];
5869 /* Prevent redisplay optimization in redisplay_internal by resetting
5870 this_line_start_pos. This is done because the mini-buffer now
5871 displays the message instead of its buffer text. */
5872 if (EQ (mini_window
, selected_window
))
5873 CHARPOS (this_line_start_pos
) = 0;
5875 return window_height_changed_p
;
5880 /***********************************************************************
5882 ***********************************************************************/
5885 #ifdef HAVE_WINDOW_SYSTEM
5887 /* A buffer for constructing frame titles in it; allocated from the
5888 heap in init_xdisp and resized as needed in store_frame_title_char. */
5890 static char *frame_title_buf
;
5892 /* The buffer's end, and a current output position in it. */
5894 static char *frame_title_buf_end
;
5895 static char *frame_title_ptr
;
5898 /* Store a single character C for the frame title in frame_title_buf.
5899 Re-allocate frame_title_buf if necessary. */
5902 store_frame_title_char (c
)
5905 /* If output position has reached the end of the allocated buffer,
5906 double the buffer's size. */
5907 if (frame_title_ptr
== frame_title_buf_end
)
5909 int len
= frame_title_ptr
- frame_title_buf
;
5910 int new_size
= 2 * len
* sizeof *frame_title_buf
;
5911 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
5912 frame_title_buf_end
= frame_title_buf
+ new_size
;
5913 frame_title_ptr
= frame_title_buf
+ len
;
5916 *frame_title_ptr
++ = c
;
5920 /* Store part of a frame title in frame_title_buf, beginning at
5921 frame_title_ptr. STR is the string to store. Do not copy more
5922 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
5923 the whole string. Pad with spaces until FIELD_WIDTH number of
5924 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
5925 Called from display_mode_element when it is used to build a frame
5929 store_frame_title (str
, field_width
, precision
)
5931 int field_width
, precision
;
5935 /* Copy at most PRECISION chars from STR. */
5936 while ((precision
<= 0 || n
< precision
)
5939 store_frame_title_char (*str
++);
5943 /* Fill up with spaces until FIELD_WIDTH reached. */
5944 while (field_width
> 0
5947 store_frame_title_char (' ');
5955 /* Set the title of FRAME, if it has changed. The title format is
5956 Vicon_title_format if FRAME is iconified, otherwise it is
5957 frame_title_format. */
5960 x_consider_frame_title (frame
)
5963 struct frame
*f
= XFRAME (frame
);
5965 if (FRAME_WINDOW_P (f
)
5966 || FRAME_MINIBUF_ONLY_P (f
)
5967 || f
->explicit_name
)
5969 /* Do we have more than one visible frame on this X display? */
5972 struct buffer
*obuf
;
5976 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5978 struct frame
*tf
= XFRAME (XCONS (tail
)->car
);
5981 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
5982 && !FRAME_MINIBUF_ONLY_P (tf
)
5983 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
5987 /* Set global variable indicating that multiple frames exist. */
5988 multiple_frames
= CONSP (tail
);
5990 /* Switch to the buffer of selected window of the frame. Set up
5991 frame_title_ptr so that display_mode_element will output into it;
5992 then display the title. */
5993 obuf
= current_buffer
;
5994 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
5995 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
5996 frame_title_ptr
= frame_title_buf
;
5997 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
5998 NULL
, DEFAULT_FACE_ID
);
5999 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
6000 frame_title_ptr
= NULL
;
6001 set_buffer_internal (obuf
);
6003 /* Set the title only if it's changed. This avoids consing in
6004 the common case where it hasn't. (If it turns out that we've
6005 already wasted too much time by walking through the list with
6006 display_mode_element, then we might need to optimize at a
6007 higher level than this.) */
6008 if (! STRINGP (f
->name
)
6009 || STRING_BYTES (XSTRING (f
->name
)) != len
6010 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
6011 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
6015 #else /* not HAVE_WINDOW_SYSTEM */
6017 #define frame_title_ptr ((char *)0)
6018 #define store_frame_title(str, mincol, maxcol) 0
6020 #endif /* not HAVE_WINDOW_SYSTEM */
6025 /***********************************************************************
6027 ***********************************************************************/
6030 /* Prepare for redisplay by updating menu-bar item lists when
6031 appropriate. This can call eval. */
6034 prepare_menu_bars ()
6037 struct gcpro gcpro1
, gcpro2
;
6039 struct frame
*tooltip_frame
;
6041 #ifdef HAVE_X_WINDOWS
6042 tooltip_frame
= tip_frame
;
6044 tooltip_frame
= NULL
;
6047 /* Update all frame titles based on their buffer names, etc. We do
6048 this before the menu bars so that the buffer-menu will show the
6049 up-to-date frame titles. */
6050 #ifdef HAVE_WINDOW_SYSTEM
6051 if (windows_or_buffers_changed
|| update_mode_lines
)
6053 Lisp_Object tail
, frame
;
6055 FOR_EACH_FRAME (tail
, frame
)
6058 if (f
!= tooltip_frame
6059 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
6060 x_consider_frame_title (frame
);
6063 #endif /* HAVE_WINDOW_SYSTEM */
6065 /* Update the menu bar item lists, if appropriate. This has to be
6066 done before any actual redisplay or generation of display lines. */
6067 all_windows
= (update_mode_lines
6068 || buffer_shared
> 1
6069 || windows_or_buffers_changed
);
6072 Lisp_Object tail
, frame
;
6073 int count
= specpdl_ptr
- specpdl
;
6075 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6077 FOR_EACH_FRAME (tail
, frame
)
6081 /* Ignore tooltip frame. */
6082 if (f
== tooltip_frame
)
6085 /* If a window on this frame changed size, report that to
6086 the user and clear the size-change flag. */
6087 if (FRAME_WINDOW_SIZES_CHANGED (f
))
6089 Lisp_Object functions
;
6091 /* Clear flag first in case we get an error below. */
6092 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
6093 functions
= Vwindow_size_change_functions
;
6094 GCPRO2 (tail
, functions
);
6096 while (CONSP (functions
))
6098 call1 (XCAR (functions
), frame
);
6099 functions
= XCDR (functions
);
6105 update_menu_bar (f
, 0);
6106 #ifdef HAVE_WINDOW_SYSTEM
6107 update_toolbar (f
, 0);
6112 unbind_to (count
, Qnil
);
6116 update_menu_bar (selected_frame
, 1);
6117 #ifdef HAVE_WINDOW_SYSTEM
6118 update_toolbar (selected_frame
, 1);
6122 /* Motif needs this. See comment in xmenu.c. Turn it off when
6123 pending_menu_activation is not defined. */
6124 #ifdef USE_X_TOOLKIT
6125 pending_menu_activation
= 0;
6130 /* Update the menu bar item list for frame F. This has to be done
6131 before we start to fill in any display lines, because it can call
6134 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
6137 update_menu_bar (f
, save_match_data
)
6139 int save_match_data
;
6142 register struct window
*w
;
6144 window
= FRAME_SELECTED_WINDOW (f
);
6145 w
= XWINDOW (window
);
6147 if (update_mode_lines
)
6148 w
->update_mode_line
= Qt
;
6150 if (FRAME_WINDOW_P (f
)
6152 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6153 FRAME_EXTERNAL_MENU_BAR (f
)
6155 FRAME_MENU_BAR_LINES (f
) > 0
6157 : FRAME_MENU_BAR_LINES (f
) > 0)
6159 /* If the user has switched buffers or windows, we need to
6160 recompute to reflect the new bindings. But we'll
6161 recompute when update_mode_lines is set too; that means
6162 that people can use force-mode-line-update to request
6163 that the menu bar be recomputed. The adverse effect on
6164 the rest of the redisplay algorithm is about the same as
6165 windows_or_buffers_changed anyway. */
6166 if (windows_or_buffers_changed
6167 || !NILP (w
->update_mode_line
)
6168 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6169 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6170 != !NILP (w
->last_had_star
))
6171 || ((!NILP (Vtransient_mark_mode
)
6172 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6173 != !NILP (w
->region_showing
)))
6175 struct buffer
*prev
= current_buffer
;
6176 int count
= specpdl_ptr
- specpdl
;
6178 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6179 if (save_match_data
)
6180 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6181 if (NILP (Voverriding_local_map_menu_flag
))
6183 specbind (Qoverriding_terminal_local_map
, Qnil
);
6184 specbind (Qoverriding_local_map
, Qnil
);
6187 /* Run the Lucid hook. */
6188 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
6190 /* If it has changed current-menubar from previous value,
6191 really recompute the menu-bar from the value. */
6192 if (! NILP (Vlucid_menu_bar_dirty_flag
))
6193 call0 (Qrecompute_lucid_menubar
);
6195 safe_run_hooks (Qmenu_bar_update_hook
);
6196 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
6198 /* Redisplay the menu bar in case we changed it. */
6199 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6200 if (FRAME_WINDOW_P (f
))
6201 set_frame_menubar (f
, 0, 0);
6203 /* On a terminal screen, the menu bar is an ordinary screen
6204 line, and this makes it get updated. */
6205 w
->update_mode_line
= Qt
;
6206 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6207 /* In the non-toolkit version, the menu bar is an ordinary screen
6208 line, and this makes it get updated. */
6209 w
->update_mode_line
= Qt
;
6210 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6212 unbind_to (count
, Qnil
);
6213 set_buffer_internal_1 (prev
);
6220 /***********************************************************************
6222 ***********************************************************************/
6224 #ifdef HAVE_WINDOW_SYSTEM
6226 /* Update the toolbar item list for frame F. This has to be done
6227 before we start to fill in any display lines. Called from
6228 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
6229 and restore it here. */
6232 update_toolbar (f
, save_match_data
)
6234 int save_match_data
;
6236 if (WINDOWP (f
->toolbar_window
)
6237 && XFASTINT (XWINDOW (f
->toolbar_window
)->height
) > 0)
6242 window
= FRAME_SELECTED_WINDOW (f
);
6243 w
= XWINDOW (window
);
6245 /* If the user has switched buffers or windows, we need to
6246 recompute to reflect the new bindings. But we'll
6247 recompute when update_mode_lines is set too; that means
6248 that people can use force-mode-line-update to request
6249 that the menu bar be recomputed. The adverse effect on
6250 the rest of the redisplay algorithm is about the same as
6251 windows_or_buffers_changed anyway. */
6252 if (windows_or_buffers_changed
6253 || !NILP (w
->update_mode_line
)
6254 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6255 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6256 != !NILP (w
->last_had_star
))
6257 || ((!NILP (Vtransient_mark_mode
)
6258 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6259 != !NILP (w
->region_showing
)))
6261 struct buffer
*prev
= current_buffer
;
6262 int count
= specpdl_ptr
- specpdl
;
6264 /* Set current_buffer to the buffer of the selected
6265 window of the frame, so that we get the right local
6267 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6269 /* Save match data, if we must. */
6270 if (save_match_data
)
6271 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6273 /* Make sure that we don't accidentally use bogus keymaps. */
6274 if (NILP (Voverriding_local_map_menu_flag
))
6276 specbind (Qoverriding_terminal_local_map
, Qnil
);
6277 specbind (Qoverriding_local_map
, Qnil
);
6280 /* Build desired toolbar items from keymaps. */
6281 f
->desired_toolbar_items
6282 = toolbar_items (f
->desired_toolbar_items
,
6283 &f
->n_desired_toolbar_items
);
6285 /* Redisplay the toolbar in case we changed it. */
6286 w
->update_mode_line
= Qt
;
6288 unbind_to (count
, Qnil
);
6289 set_buffer_internal_1 (prev
);
6295 /* Set F->desired_toolbar_string to a Lisp string representing frame
6296 F's desired toolbar contents. F->desired_toolbar_items must have
6297 been set up previously by calling prepare_menu_bars. */
6300 build_desired_toolbar_string (f
)
6303 int i
, size
, size_needed
, string_idx
;
6304 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6305 Lisp_Object image
, plist
, props
;
6307 image
= plist
= props
= Qnil
;
6308 GCPRO3 (image
, plist
, props
);
6310 /* Prepare F->desired_toolbar_string. If we can reuse it, do so.
6311 Otherwise, make a new string. */
6313 /* The size of the string we might be able to reuse. */
6314 size
= (STRINGP (f
->desired_toolbar_string
)
6315 ? XSTRING (f
->desired_toolbar_string
)->size
6318 /* Each image in the string we build is preceded by a space,
6319 and there is a space at the end. */
6320 size_needed
= f
->n_desired_toolbar_items
+ 1;
6322 /* Reuse f->desired_toolbar_string, if possible. */
6323 if (size
< size_needed
)
6324 f
->desired_toolbar_string
= Fmake_string (make_number (size_needed
), ' ');
6327 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
6328 Fremove_text_properties (make_number (0), make_number (size
),
6329 props
, f
->desired_toolbar_string
);
6332 /* Put a `display' property on the string for the images to display,
6333 put a `menu_item' property on toolbar items with a value that
6334 is the index of the item in F's toolbar item vector. */
6335 for (i
= 0, string_idx
= 0;
6336 i
< f
->n_desired_toolbar_items
;
6337 ++i
, string_idx
+= 1)
6340 (XVECTOR (f->desired_toolbar_items) \
6341 ->contents[i * TOOLBAR_ITEM_NSLOTS + (IDX)])
6343 int enabled_p
= !NILP (PROP (TOOLBAR_ITEM_ENABLED_P
));
6344 int selected_p
= !NILP (PROP (TOOLBAR_ITEM_SELECTED_P
));
6346 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
6347 extern Lisp_Object Qlaplace
;
6349 /* If image is a vector, choose the image according to the
6351 image
= PROP (TOOLBAR_ITEM_IMAGES
);
6352 if (VECTORP (image
))
6354 enum toolbar_item_image idx
;
6358 ? TOOLBAR_IMAGE_ENABLED_SELECTED
6359 : TOOLBAR_IMAGE_ENABLED_DESELECTED
);
6362 ? TOOLBAR_IMAGE_DISABLED_SELECTED
6363 : TOOLBAR_IMAGE_DISABLED_DESELECTED
);
6365 xassert (XVECTOR (image
)->size
>= idx
);
6366 image
= XVECTOR (image
)->contents
[idx
];
6369 /* Ignore invalid image specifications. */
6370 if (!valid_image_p (image
))
6373 /* Display the toolbar button pressed, or depressed. */
6374 plist
= Fcopy_sequence (XCDR (image
));
6376 /* Compute margin and relief to draw. */
6377 relief
= toolbar_button_relief
> 0 ? toolbar_button_relief
: 3;
6378 margin
= relief
+ max (0, toolbar_button_margin
);
6380 if (auto_raise_toolbar_buttons_p
)
6382 /* Add a `:relief' property to the image spec if the item is
6386 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
6392 /* If image is selected, display it pressed, i.e. with a
6393 negative relief. If it's not selected, display it with a
6395 plist
= Fplist_put (plist
, QCrelief
,
6397 ? make_number (-relief
)
6398 : make_number (relief
)));
6402 /* Put a margin around the image. */
6404 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
6406 /* If button is not enabled, make the image appear disabled by
6407 applying an appropriate algorithm to it. */
6409 plist
= Fplist_put (plist
, QCalgorithm
, Qlaplace
);
6411 /* Put a `display' text property on the string for the image to
6412 display. Put a `menu-item' property on the string that gives
6413 the start of this item's properties in the toolbar items
6415 image
= Fcons (Qimage
, plist
);
6416 props
= list4 (Qdisplay
, image
,
6417 Qmenu_item
, make_number (i
* TOOLBAR_ITEM_NSLOTS
)),
6418 Fadd_text_properties (make_number (string_idx
),
6419 make_number (string_idx
+ 1),
6420 props
, f
->desired_toolbar_string
);
6428 /* Display one line of the toolbar of frame IT->f. */
6431 display_toolbar_line (it
)
6434 struct glyph_row
*row
= it
->glyph_row
;
6435 int max_x
= it
->last_visible_x
;
6438 prepare_desired_row (row
);
6439 row
->y
= it
->current_y
;
6441 while (it
->current_x
< max_x
)
6443 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
6445 /* Get the next display element. */
6446 if (!get_next_display_element (it
))
6449 /* Produce glyphs. */
6450 x_before
= it
->current_x
;
6451 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
6452 PRODUCE_GLYPHS (it
);
6454 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
6459 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
6461 if (x
+ glyph
->pixel_width
> max_x
)
6463 /* Glyph doesn't fit on line. */
6464 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
6470 x
+= glyph
->pixel_width
;
6474 /* Stop at line ends. */
6475 if (ITERATOR_AT_END_OF_LINE_P (it
))
6478 set_iterator_to_next (it
);
6483 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
6484 extend_face_to_end_of_line (it
);
6485 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
6486 last
->right_box_line_p
= 1;
6487 compute_line_metrics (it
);
6489 /* If line is empty, make it occupy the rest of the toolbar. */
6490 if (!row
->displays_text_p
)
6492 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
6493 row
->ascent
= row
->phys_ascent
= 0;
6496 row
->full_width_p
= 1;
6497 row
->continued_p
= 0;
6498 row
->truncated_on_left_p
= 0;
6499 row
->truncated_on_right_p
= 0;
6501 it
->current_x
= it
->hpos
= 0;
6502 it
->current_y
+= row
->height
;
6508 /* Value is the number of screen lines needed to make all toolbar
6509 items of frame F visible. */
6512 toolbar_lines_needed (f
)
6515 struct window
*w
= XWINDOW (f
->toolbar_window
);
6518 /* Initialize an iterator for iteration over F->desired_toolbar_string
6519 in the toolbar window of frame F. */
6520 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOLBAR_FACE_ID
);
6521 it
.first_visible_x
= 0;
6522 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6523 reseat_to_string (&it
, NULL
, f
->desired_toolbar_string
, 0, 0, 0, -1);
6525 while (!ITERATOR_AT_END_P (&it
))
6527 it
.glyph_row
= w
->desired_matrix
->rows
;
6528 clear_glyph_row (it
.glyph_row
);
6529 display_toolbar_line (&it
);
6532 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
6536 /* Display the toolbar of frame F. Value is non-zero if toolbar's
6537 height should be changed. */
6540 redisplay_toolbar (f
)
6545 struct glyph_row
*row
;
6546 int change_height_p
= 0;
6548 /* If frame hasn't a toolbar window or if it is zero-height, don't
6549 do anything. This means you must start with toolbar-lines
6550 non-zero to get the auto-sizing effect. Or in other words, you
6551 can turn off toolbars by specifying toolbar-lines zero. */
6552 if (!WINDOWP (f
->toolbar_window
)
6553 || (w
= XWINDOW (f
->toolbar_window
),
6554 XFASTINT (w
->height
) == 0))
6557 /* Set up an iterator for the toolbar window. */
6558 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOLBAR_FACE_ID
);
6559 it
.first_visible_x
= 0;
6560 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6563 /* Build a string that represents the contents of the toolbar. */
6564 build_desired_toolbar_string (f
);
6565 reseat_to_string (&it
, NULL
, f
->desired_toolbar_string
, 0, 0, 0, -1);
6567 /* Display as many lines as needed to display all toolbar items. */
6568 while (it
.current_y
< it
.last_visible_y
)
6569 display_toolbar_line (&it
);
6571 /* It doesn't make much sense to try scrolling in the toolbar
6572 window, so don't do it. */
6573 w
->desired_matrix
->no_scrolling_p
= 1;
6574 w
->must_be_updated_p
= 1;
6576 if (auto_resize_toolbars_p
)
6580 /* If there are blank lines at the end, except for a partially
6581 visible blank line at the end that is smaller than
6582 CANON_Y_UNIT, change the toolbar's height. */
6583 row
= it
.glyph_row
- 1;
6584 if (!row
->displays_text_p
6585 && row
->height
>= CANON_Y_UNIT (f
))
6586 change_height_p
= 1;
6588 /* If row displays toolbar items, but is partially visible,
6589 change the toolbar's height. */
6590 if (row
->displays_text_p
6591 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
6592 change_height_p
= 1;
6594 /* Resize windows as needed by changing the `toolbar-lines'
6597 && (nlines
= toolbar_lines_needed (f
),
6598 nlines
!= XFASTINT (w
->height
)))
6600 extern Lisp_Object Qtoolbar_lines
;
6603 XSETFRAME (frame
, f
);
6604 clear_glyph_matrix (w
->desired_matrix
);
6605 Fmodify_frame_parameters (frame
,
6606 Fcons (Fcons (Qtoolbar_lines
,
6607 make_number (nlines
)),
6609 fonts_changed_p
= 1;
6613 return change_height_p
;
6617 /* Get information about the toolbar item which is displayed in GLYPH
6618 on frame F. Return in *PROP_IDX the index where toolbar item
6619 properties start in F->current_toolbar_items. Value is zero if
6620 GLYPH doesn't display a toolbar item. */
6623 toolbar_item_info (f
, glyph
, prop_idx
)
6625 struct glyph
*glyph
;
6631 /* Get the text property `menu-item' at pos. The value of that
6632 property is the start index of this item's properties in
6633 F->current_toolbar_items. */
6634 prop
= Fget_text_property (make_number (glyph
->charpos
),
6635 Qmenu_item
, f
->current_toolbar_string
);
6636 if (INTEGERP (prop
))
6638 *prop_idx
= XINT (prop
);
6647 #endif /* HAVE_WINDOW_SYSTEM */
6651 /************************************************************************
6652 Horizontal scrolling
6653 ************************************************************************/
6655 static int hscroll_window_tree
P_ ((Lisp_Object
));
6656 static int hscroll_windows
P_ ((Lisp_Object
));
6658 /* For all leaf windows in the window tree rooted at WINDOW, set their
6659 hscroll value so that PT is (i) visible in the window, and (ii) so
6660 that it is not within a certain margin at the window's left and
6661 right border. Value is non-zero if any window's hscroll has been
6665 hscroll_window_tree (window
)
6668 int hscrolled_p
= 0;
6670 while (WINDOWP (window
))
6672 struct window
*w
= XWINDOW (window
);
6674 if (WINDOWP (w
->hchild
))
6675 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
6676 else if (WINDOWP (w
->vchild
))
6677 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
6678 else if (w
->cursor
.vpos
>= 0)
6680 int hscroll_margin
, text_area_x
, text_area_y
;
6681 int text_area_width
, text_area_height
;
6682 struct glyph_row
*cursor_row
= MATRIX_ROW (w
->current_matrix
,
6685 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
6686 &text_area_width
, &text_area_height
);
6688 /* Scroll when cursor is inside this scroll margin. */
6689 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
6691 if ((XFASTINT (w
->hscroll
)
6692 && w
->cursor
.x
< hscroll_margin
)
6693 || (cursor_row
->truncated_on_right_p
6694 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
6698 struct buffer
*saved_current_buffer
;
6701 /* Find point in a display of infinite width. */
6702 saved_current_buffer
= current_buffer
;
6703 current_buffer
= XBUFFER (w
->buffer
);
6705 if (w
== XWINDOW (selected_window
))
6706 pt
= BUF_PT (current_buffer
);
6709 pt
= marker_position (w
->pointm
);
6710 pt
= max (BEGV
, pt
);
6714 /* Move iterator to pt starting at cursor_row->start in
6715 a line with infinite width. */
6716 init_to_row_start (&it
, w
, cursor_row
);
6717 it
.last_visible_x
= INFINITY
;
6718 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
6719 current_buffer
= saved_current_buffer
;
6721 /* Center cursor in window. */
6722 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
6723 / CANON_X_UNIT (it
.f
));
6725 /* Don't call Fset_window_hscroll if value hasn't
6726 changed because it will prevent redisplay
6728 if (XFASTINT (w
->hscroll
) != hscroll
)
6730 Fset_window_hscroll (window
, make_number (hscroll
));
6739 /* Value is non-zero if hscroll of any leaf window has been changed. */
6744 /* Set hscroll so that cursor is visible and not inside horizontal
6745 scroll margins for all windows in the tree rooted at WINDOW. See
6746 also hscroll_window_tree above. Value is non-zero if any window's
6747 hscroll has been changed. If it has, desired matrices on the frame
6748 of WINDOW are cleared. */
6751 hscroll_windows (window
)
6754 int hscrolled_p
= hscroll_window_tree (window
);
6756 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
6762 /************************************************************************
6764 ************************************************************************/
6766 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
6767 to a non-zero value. This is sometimes handy to have in a debugger
6772 /* First and last unchanged row for try_window_id. */
6774 int debug_first_unchanged_at_end_vpos
;
6775 int debug_last_unchanged_at_beg_vpos
;
6777 /* Delta vpos and y. */
6779 int debug_dvpos
, debug_dy
;
6781 /* Delta in characters and bytes for try_window_id. */
6783 int debug_delta
, debug_delta_bytes
;
6785 /* Values of window_end_pos and window_end_vpos at the end of
6788 int debug_end_pos
, debug_end_vpos
;
6790 /* Append a string to W->desired_matrix->method. FMT is a printf
6791 format string. A1...A9 are a supplement for a variable-length
6792 argument list. If trace_redisplay_p is non-zero also printf the
6793 resulting string to stderr. */
6796 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
6799 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
6802 char *method
= w
->desired_matrix
->method
;
6803 int len
= strlen (method
);
6804 int size
= sizeof w
->desired_matrix
->method
;
6805 int remaining
= size
- len
- 1;
6807 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
6808 if (len
&& remaining
)
6814 strncpy (method
+ len
, buffer
, remaining
);
6816 if (trace_redisplay_p
)
6817 fprintf (stderr
, "%p (%s): %s\n",
6819 ((BUFFERP (w
->buffer
)
6820 && STRINGP (XBUFFER (w
->buffer
)->name
))
6821 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
6826 #endif /* GLYPH_DEBUG */
6829 /* This counter is used to clear the face cache every once in a while
6830 in redisplay_internal. It is incremented for each redisplay.
6831 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
6834 #define CLEAR_FACE_CACHE_COUNT 10000
6835 static int clear_face_cache_count
;
6837 /* Record the previous terminal frame we displayed. */
6839 static struct frame
*previous_terminal_frame
;
6841 /* Non-zero while redisplay_internal is in progress. */
6846 /* Value is non-zero if all changes in window W, which displays
6847 current_buffer, are in the text between START and END. START is a
6848 buffer position, END is given as a distance from Z. Used in
6849 redisplay_internal for display optimization. */
6852 text_outside_line_unchanged_p (w
, start
, end
)
6856 int unchanged_p
= 1;
6858 /* If text or overlays have changed, see where. */
6859 if (XFASTINT (w
->last_modified
) < MODIFF
6860 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
6862 /* Gap in the line? */
6863 if (GPT
< start
|| Z
- GPT
< end
)
6866 /* Changes start in front of the line, or end after it? */
6868 && (BEG_UNCHANGED
< start
- 1
6869 || END_UNCHANGED
< end
))
6872 /* If selective display, can't optimize if changes start at the
6873 beginning of the line. */
6875 && INTEGERP (current_buffer
->selective_display
)
6876 && XINT (current_buffer
->selective_display
) > 0
6877 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
6885 /* Do a frame update, taking possible shortcuts into account. This is
6886 the main external entry point for redisplay.
6888 If the last redisplay displayed an echo area message and that message
6889 is no longer requested, we clear the echo area or bring back the
6890 mini-buffer if that is in use. */
6895 redisplay_internal (0);
6899 /* Reconsider the setting of B->clip_changed which is displayed
6903 reconsider_clip_changes (w
, b
)
6907 if (b
->prevent_redisplay_optimizations_p
)
6908 b
->clip_changed
= 1;
6909 else if (b
->clip_changed
6910 && !NILP (w
->window_end_valid
)
6911 && w
->current_matrix
->buffer
== b
6912 && w
->current_matrix
->zv
== BUF_ZV (b
)
6913 && w
->current_matrix
->begv
== BUF_BEGV (b
))
6914 b
->clip_changed
= 0;
6918 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
6919 response to any user action; therefore, we should preserve the echo
6920 area. (Actually, our caller does that job.) Perhaps in the future
6921 avoid recentering windows if it is not necessary; currently that
6922 causes some problems. */
6925 redisplay_internal (preserve_echo_area
)
6926 int preserve_echo_area
;
6928 struct window
*w
= XWINDOW (selected_window
);
6929 struct frame
*f
= XFRAME (w
->frame
);
6931 int must_finish
= 0;
6932 struct text_pos tlbufpos
, tlendpos
;
6933 int number_of_visible_frames
;
6936 /* Non-zero means redisplay has to consider all windows on all
6937 frames. Zero means, only selected_window is considered. */
6938 int consider_all_windows_p
;
6940 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
6942 /* No redisplay if running in batch mode or frame is not yet fully
6943 initialized, or redisplay is explicitly turned off by setting
6944 Vinhibit_redisplay. */
6946 || !NILP (Vinhibit_redisplay
)
6947 || !f
->glyphs_initialized_p
)
6950 /* The flag redisplay_performed_directly_p is set by
6951 direct_output_for_insert when it already did the whole screen
6952 update necessary. */
6953 if (redisplay_performed_directly_p
)
6955 redisplay_performed_directly_p
= 0;
6956 if (!hscroll_windows (selected_window
))
6960 #ifdef USE_X_TOOLKIT
6961 if (popup_activated ())
6965 /* I don't think this happens but let's be paranoid. */
6969 /* Record a function that resets redisplaying_p to its old value
6970 when we leave this function. */
6971 count
= specpdl_ptr
- specpdl
;
6972 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
6977 reconsider_clip_changes (w
, current_buffer
);
6979 /* If new fonts have been loaded that make a glyph matrix adjustment
6980 necessary, do it. */
6981 if (fonts_changed_p
)
6983 adjust_glyphs (NULL
);
6984 ++windows_or_buffers_changed
;
6985 fonts_changed_p
= 0;
6988 if (! FRAME_WINDOW_P (selected_frame
)
6989 && previous_terminal_frame
!= selected_frame
)
6991 /* Since frames on an ASCII terminal share the same display
6992 area, displaying a different frame means redisplay the whole
6994 windows_or_buffers_changed
++;
6995 SET_FRAME_GARBAGED (selected_frame
);
6996 XSETFRAME (Vterminal_frame
, selected_frame
);
6998 previous_terminal_frame
= selected_frame
;
7000 /* Set the visible flags for all frames. Do this before checking
7001 for resized or garbaged frames; they want to know if their frames
7002 are visible. See the comment in frame.h for
7003 FRAME_SAMPLE_VISIBILITY. */
7005 Lisp_Object tail
, frame
;
7007 number_of_visible_frames
= 0;
7009 FOR_EACH_FRAME (tail
, frame
)
7011 struct frame
*f
= XFRAME (frame
);
7013 FRAME_SAMPLE_VISIBILITY (f
);
7014 if (FRAME_VISIBLE_P (f
))
7015 ++number_of_visible_frames
;
7016 clear_desired_matrices (f
);
7020 /* Notice any pending interrupt request to change frame size. */
7021 do_pending_window_change (1);
7023 /* Clear frames marked as garbaged. */
7025 clear_garbaged_frames ();
7027 /* Build menubar and toolbar items. */
7028 prepare_menu_bars ();
7030 if (windows_or_buffers_changed
)
7031 update_mode_lines
++;
7033 /* Detect case that we need to write or remove a star in the mode line. */
7034 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
7036 w
->update_mode_line
= Qt
;
7037 if (buffer_shared
> 1)
7038 update_mode_lines
++;
7041 /* If %c is in the mode line, update it if needed. */
7042 if (!NILP (w
->column_number_displayed
)
7043 /* This alternative quickly identifies a common case
7044 where no change is needed. */
7045 && !(PT
== XFASTINT (w
->last_point
)
7046 && XFASTINT (w
->last_modified
) >= MODIFF
7047 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7048 && XFASTINT (w
->column_number_displayed
) != current_column ())
7049 w
->update_mode_line
= Qt
;
7051 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
7053 /* The variable buffer_shared is set in redisplay_window and
7054 indicates that we redisplay a buffer in different windows. See
7056 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
7058 /* If specs for an arrow have changed, do thorough redisplay
7059 to ensure we remove any arrow that should no longer exist. */
7060 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
7061 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
7062 consider_all_windows_p
= windows_or_buffers_changed
= 1;
7064 /* Normally the message* functions will have already displayed and
7065 updated the echo area, but the frame may have been trashed, or
7066 the update may have been preempted, so display the echo area
7067 again here. Checking both message buffers captures the case that
7068 the echo area should be cleared. */
7069 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
7071 int window_height_changed_p
= echo_area_display (0);
7074 if (fonts_changed_p
)
7076 else if (window_height_changed_p
)
7078 consider_all_windows_p
= 1;
7079 ++update_mode_lines
;
7080 ++windows_or_buffers_changed
;
7082 /* If window configuration was changed, frames may have been
7083 marked garbaged. Clear them or we will experience
7084 surprises wrt scrolling. */
7086 clear_garbaged_frames ();
7089 else if (w
== XWINDOW (minibuf_window
)
7090 && (current_buffer
->clip_changed
7091 || XFASTINT (w
->last_modified
) < MODIFF
7092 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7093 && resize_mini_window (w
))
7095 /* Resized active mini-window to fit the size of what it is
7096 showing if its contents might have changed. */
7098 consider_all_windows_p
= 1;
7099 ++windows_or_buffers_changed
;
7100 ++update_mode_lines
;
7102 /* If window configuration was changed, frames may have been
7103 marked garbaged. Clear them or we will experience
7104 surprises wrt scrolling. */
7106 clear_garbaged_frames ();
7110 /* If showing the region, and mark has changed, we must redisplay
7111 the whole window. The assignment to this_line_start_pos prevents
7112 the optimization directly below this if-statement. */
7113 if (((!NILP (Vtransient_mark_mode
)
7114 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7115 != !NILP (w
->region_showing
))
7116 || (!NILP (w
->region_showing
)
7117 && !EQ (w
->region_showing
,
7118 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
7119 CHARPOS (this_line_start_pos
) = 0;
7121 /* Optimize the case that only the line containing the cursor in the
7122 selected window has changed. Variables starting with this_ are
7123 set in display_line and record information about the line
7124 containing the cursor. */
7125 tlbufpos
= this_line_start_pos
;
7126 tlendpos
= this_line_end_pos
;
7127 if (!consider_all_windows_p
7128 && CHARPOS (tlbufpos
) > 0
7129 && NILP (w
->update_mode_line
)
7130 && !current_buffer
->clip_changed
7131 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
7132 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
7133 /* Make sure recorded data applies to current buffer, etc. */
7134 && this_line_buffer
== current_buffer
7135 && current_buffer
== XBUFFER (w
->buffer
)
7136 && NILP (w
->force_start
)
7137 /* Point must be on the line that we have info recorded about. */
7138 && PT
>= CHARPOS (tlbufpos
)
7139 && PT
<= Z
- CHARPOS (tlendpos
)
7140 /* All text outside that line, including its final newline,
7141 must be unchanged */
7142 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
7143 CHARPOS (tlendpos
)))
7145 if (CHARPOS (tlbufpos
) > BEGV
7146 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
7147 && (CHARPOS (tlbufpos
) == ZV
7148 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
7149 /* Former continuation line has disappeared by becoming empty */
7151 else if (XFASTINT (w
->last_modified
) < MODIFF
7152 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
7153 || MINI_WINDOW_P (w
))
7155 /* We have to handle the case of continuation around a
7156 wide-column character (See the comment in indent.c around
7159 For instance, in the following case:
7161 -------- Insert --------
7162 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
7163 J_I_ ==> J_I_ `^^' are cursors.
7167 As we have to redraw the line above, we should goto cancel. */
7170 int line_height_before
= this_line_pixel_height
;
7172 /* Note that start_display will handle the case that the
7173 line starting at tlbufpos is a continuation lines. */
7174 start_display (&it
, w
, tlbufpos
);
7176 /* Implementation note: It this still necessary? */
7177 if (it
.current_x
!= this_line_start_x
)
7180 TRACE ((stderr
, "trying display optimization 1\n"));
7181 w
->cursor
.vpos
= -1;
7182 overlay_arrow_seen
= 0;
7183 it
.vpos
= this_line_vpos
;
7184 it
.current_y
= this_line_y
;
7185 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
7188 /* If line contains point, is not continued,
7189 and ends at same distance from eob as before, we win */
7190 if (w
->cursor
.vpos
>= 0
7191 /* Line is not continued, otherwise this_line_start_pos
7192 would have been set to 0 in display_line. */
7193 && CHARPOS (this_line_start_pos
)
7194 /* Line ends as before. */
7195 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
7196 /* Line has same height as before. Otherwise other lines
7197 would have to be shifted up or down. */
7198 && this_line_pixel_height
== line_height_before
)
7200 /* If this is not the window's last line, we must adjust
7201 the charstarts of the lines below. */
7202 if (it
.current_y
< it
.last_visible_y
)
7204 struct glyph_row
*row
7205 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
7206 int delta
, delta_bytes
;
7208 if (Z
- CHARPOS (tlendpos
) == ZV
)
7210 /* This line ends at end of (accessible part of)
7211 buffer. There is no newline to count. */
7213 - CHARPOS (tlendpos
)
7214 - MATRIX_ROW_START_CHARPOS (row
));
7215 delta_bytes
= (Z_BYTE
7216 - BYTEPOS (tlendpos
)
7217 - MATRIX_ROW_START_BYTEPOS (row
));
7221 /* This line ends in a newline. Must take
7222 account of the newline and the rest of the
7223 text that follows. */
7225 - CHARPOS (tlendpos
)
7226 - MATRIX_ROW_START_CHARPOS (row
));
7227 delta_bytes
= (Z_BYTE
7228 - BYTEPOS (tlendpos
)
7229 - MATRIX_ROW_START_BYTEPOS (row
));
7232 increment_glyph_matrix_buffer_positions (w
->current_matrix
,
7234 w
->current_matrix
->nrows
,
7235 delta
, delta_bytes
);
7238 /* If this row displays text now but previously didn't,
7239 or vice versa, w->window_end_vpos may have to be
7241 if ((it
.glyph_row
- 1)->displays_text_p
)
7243 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
7244 XSETINT (w
->window_end_vpos
, this_line_vpos
);
7246 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
7247 && this_line_vpos
> 0)
7248 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
7249 w
->window_end_valid
= Qnil
;
7251 /* Update hint: No need to try to scroll in update_window. */
7252 w
->desired_matrix
->no_scrolling_p
= 1;
7255 *w
->desired_matrix
->method
= 0;
7256 debug_method_add (w
, "optimization 1");
7263 else if (/* Cursor position hasn't changed. */
7264 PT
== XFASTINT (w
->last_point
)
7265 /* Make sure the cursor was last displayed
7266 in this window. Otherwise we have to reposition it. */
7267 && 0 <= w
->cursor
.vpos
7268 && XINT (w
->height
) > w
->cursor
.vpos
)
7272 do_pending_window_change (1);
7274 /* We used to always goto end_of_redisplay here, but this
7275 isn't enough if we have a blinking cursor. */
7276 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
7277 goto end_of_redisplay
;
7281 /* If highlighting the region, or if the cursor is in the echo area,
7282 then we can't just move the cursor. */
7283 else if (! (!NILP (Vtransient_mark_mode
)
7284 && !NILP (current_buffer
->mark_active
))
7285 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7286 || highlight_nonselected_windows
)
7287 && NILP (w
->region_showing
)
7288 && NILP (Vshow_trailing_whitespace
)
7289 && !cursor_in_echo_area
)
7292 struct glyph_row
*row
;
7294 /* Skip from tlbufpos to PT and see where it is. Note that
7295 PT may be in invisible text. If so, we will end at the
7296 next visible position. */
7297 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
7298 NULL
, DEFAULT_FACE_ID
);
7299 it
.current_x
= this_line_start_x
;
7300 it
.current_y
= this_line_y
;
7301 it
.vpos
= this_line_vpos
;
7303 /* The call to move_it_to stops in front of PT, but
7304 moves over before-strings. */
7305 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
7307 if (it
.vpos
== this_line_vpos
7308 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
7311 xassert (this_line_vpos
== it
.vpos
);
7312 xassert (this_line_y
== it
.current_y
);
7313 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
7321 /* Text changed drastically or point moved off of line. */
7322 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
7325 CHARPOS (this_line_start_pos
) = 0;
7326 consider_all_windows_p
|= buffer_shared
> 1;
7327 ++clear_face_cache_count
;
7330 /* Build desired matrices. If consider_all_windows_p is non-zero,
7331 do it for all windows on all frames. Otherwise do it for
7332 selected_window, only. */
7334 if (consider_all_windows_p
)
7336 Lisp_Object tail
, frame
;
7338 /* Clear the face cache eventually. */
7339 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
7341 clear_face_cache (0);
7342 clear_face_cache_count
= 0;
7345 /* Recompute # windows showing selected buffer. This will be
7346 incremented each time such a window is displayed. */
7349 FOR_EACH_FRAME (tail
, frame
)
7351 struct frame
*f
= XFRAME (frame
);
7352 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
7354 /* Mark all the scroll bars to be removed; we'll redeem
7355 the ones we want when we redisplay their windows. */
7356 if (condemn_scroll_bars_hook
)
7357 (*condemn_scroll_bars_hook
) (f
);
7359 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7360 redisplay_windows (FRAME_ROOT_WINDOW (f
));
7362 /* Any scroll bars which redisplay_windows should have
7363 nuked should now go away. */
7364 if (judge_scroll_bars_hook
)
7365 (*judge_scroll_bars_hook
) (f
);
7369 else if (FRAME_VISIBLE_P (selected_frame
)
7370 && !FRAME_OBSCURED_P (selected_frame
))
7371 redisplay_window (selected_window
, 1);
7374 /* Compare desired and current matrices, perform output. */
7378 /* If fonts changed, display again. */
7379 if (fonts_changed_p
)
7382 /* Prevent various kinds of signals during display update.
7383 stdio is not robust about handling signals,
7384 which can cause an apparent I/O error. */
7385 if (interrupt_input
)
7389 if (consider_all_windows_p
)
7395 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
7399 if (!FRAMEP (XCONS (tail
)->car
))
7402 f
= XFRAME (XCONS (tail
)->car
);
7404 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
7405 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7407 /* Mark all windows as to be updated. */
7408 set_window_update_flags (XWINDOW (f
->root_window
), 1);
7409 pause
|= update_frame (f
, 0, 0);
7412 if (hscroll_windows (f
->root_window
))
7415 mark_window_display_accurate (f
->root_window
, 1);
7416 if (frame_up_to_date_hook
!= 0)
7417 (*frame_up_to_date_hook
) (f
);
7424 if (FRAME_VISIBLE_P (selected_frame
)
7425 && !FRAME_OBSCURED_P (selected_frame
))
7427 XWINDOW (selected_window
)->must_be_updated_p
= 1;
7428 pause
= update_frame (selected_frame
, 0, 0);
7429 if (!pause
&& hscroll_windows (selected_window
))
7435 /* We may have called echo_area_display at the top of this
7436 function. If the echo area is on another frame, that may
7437 have put text on a frame other than the selected one, so the
7438 above call to update_frame would not have caught it. Catch
7441 Lisp_Object mini_window
;
7442 struct frame
*mini_frame
;
7444 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
7445 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7447 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
7449 XWINDOW (mini_window
)->must_be_updated_p
= 1;
7450 pause
|= update_frame (mini_frame
, 0, 0);
7451 if (!pause
&& hscroll_windows (mini_window
))
7457 /* If display was paused because of pending input, make sure we do a
7458 thorough update the next time. */
7461 /* Prevent the optimization at the beginning of
7462 redisplay_internal that tries a single-line update of the
7463 line containing the cursor in the selected window. */
7464 CHARPOS (this_line_start_pos
) = 0;
7466 /* Let the overlay arrow be updated the next time. */
7467 if (!NILP (last_arrow_position
))
7469 last_arrow_position
= Qt
;
7470 last_arrow_string
= Qt
;
7473 /* If we pause after scrolling, some rows in the current
7474 matrices of some windows are not valid. */
7475 if (!WINDOW_FULL_WIDTH_P (w
)
7476 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
7477 update_mode_lines
= 1;
7480 /* Now text on frame agrees with windows, so put info into the
7481 windows for partial redisplay to follow. */
7484 register struct buffer
*b
= XBUFFER (w
->buffer
);
7486 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
7487 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
7488 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
7489 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
7491 if (consider_all_windows_p
)
7492 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
7495 XSETFASTINT (w
->last_point
, BUF_PT (b
));
7496 w
->last_cursor
= w
->cursor
;
7497 w
->last_cursor_off_p
= w
->cursor_off_p
;
7499 b
->clip_changed
= 0;
7500 b
->prevent_redisplay_optimizations_p
= 0;
7501 w
->update_mode_line
= Qnil
;
7502 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
7503 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
7505 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7508 /* Record if we are showing a region, so can make sure to
7509 update it fully at next redisplay. */
7510 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
7511 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7512 || highlight_nonselected_windows
)
7513 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
7514 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
7517 w
->window_end_valid
= w
->buffer
;
7518 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7519 last_arrow_string
= Voverlay_arrow_string
;
7520 if (frame_up_to_date_hook
!= 0)
7521 (*frame_up_to_date_hook
) (selected_frame
);
7523 w
->current_matrix
->buffer
= b
;
7524 w
->current_matrix
->begv
= BUF_BEGV (b
);
7525 w
->current_matrix
->zv
= BUF_ZV (b
);
7528 update_mode_lines
= 0;
7529 windows_or_buffers_changed
= 0;
7532 /* Start SIGIO interrupts coming again. Having them off during the
7533 code above makes it less likely one will discard output, but not
7534 impossible, since there might be stuff in the system buffer here.
7535 But it is much hairier to try to do anything about that. */
7536 if (interrupt_input
)
7540 /* If a frame has become visible which was not before, redisplay
7541 again, so that we display it. Expose events for such a frame
7542 (which it gets when becoming visible) don't call the parts of
7543 redisplay constructing glyphs, so simply exposing a frame won't
7544 display anything in this case. So, we have to display these
7545 frames here explicitly. */
7548 Lisp_Object tail
, frame
;
7551 FOR_EACH_FRAME (tail
, frame
)
7553 int this_is_visible
= 0;
7555 if (XFRAME (frame
)->visible
)
7556 this_is_visible
= 1;
7557 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
7558 if (XFRAME (frame
)->visible
)
7559 this_is_visible
= 1;
7561 if (this_is_visible
)
7565 if (new_count
!= number_of_visible_frames
)
7566 windows_or_buffers_changed
++;
7569 /* Change frame size now if a change is pending. */
7570 do_pending_window_change (1);
7572 /* If we just did a pending size change, or have additional
7573 visible frames, redisplay again. */
7574 if (windows_or_buffers_changed
&& !pause
)
7579 unbind_to (count
, Qnil
);
7583 /* Redisplay, but leave alone any recent echo area message unless
7584 another message has been requested in its place.
7586 This is useful in situations where you need to redisplay but no
7587 user action has occurred, making it inappropriate for the message
7588 area to be cleared. See tracking_off and
7589 wait_reading_process_input for examples of these situations. */
7592 redisplay_preserve_echo_area ()
7594 if (!NILP (echo_area_buffer
[1]))
7596 /* We have a previously displayed message, but no current
7597 message. Redisplay the previous message. */
7598 display_last_displayed_message_p
= 1;
7599 redisplay_internal (1);
7600 display_last_displayed_message_p
= 0;
7603 redisplay_internal (1);
7607 /* Function registered with record_unwind_protect in
7608 redisplay_internal. Clears the flag indicating that a redisplay is
7612 unwind_redisplay (old_redisplaying_p
)
7613 Lisp_Object old_redisplaying_p
;
7615 redisplaying_p
= XFASTINT (old_redisplaying_p
);
7620 /* Mark the display of windows in the window tree rooted at WINDOW as
7621 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
7622 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
7623 the next time redisplay_internal is called. */
7626 mark_window_display_accurate (window
, accurate_p
)
7632 for (; !NILP (window
); window
= w
->next
)
7634 w
= XWINDOW (window
);
7636 if (BUFFERP (w
->buffer
))
7638 struct buffer
*b
= XBUFFER (w
->buffer
);
7640 XSETFASTINT (w
->last_modified
,
7641 accurate_p
? BUF_MODIFF (b
) : 0);
7642 XSETFASTINT (w
->last_overlay_modified
,
7643 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
7644 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
7647 #if 0 /* I don't think this is necessary because display_line does it.
7649 /* Record if we are showing a region, so can make sure to
7650 update it fully at next redisplay. */
7652 = (!NILP (Vtransient_mark_mode
)
7653 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7654 || highlight_nonselected_windows
)
7655 && (!NILP (b
->mark_active
)
7656 ? Fmarker_position (b
->mark
)
7662 b
->clip_changed
= 0;
7663 b
->prevent_redisplay_optimizations_p
= 0;
7664 w
->current_matrix
->buffer
= b
;
7665 w
->current_matrix
->begv
= BUF_BEGV (b
);
7666 w
->current_matrix
->zv
= BUF_ZV (b
);
7667 w
->last_cursor
= w
->cursor
;
7668 w
->last_cursor_off_p
= w
->cursor_off_p
;
7669 if (w
== XWINDOW (selected_window
))
7670 w
->last_point
= BUF_PT (b
);
7672 w
->last_point
= XMARKER (w
->pointm
)->charpos
;
7676 w
->window_end_valid
= w
->buffer
;
7677 w
->update_mode_line
= Qnil
;
7679 if (!NILP (w
->vchild
))
7680 mark_window_display_accurate (w
->vchild
, accurate_p
);
7681 if (!NILP (w
->hchild
))
7682 mark_window_display_accurate (w
->hchild
, accurate_p
);
7687 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7688 last_arrow_string
= Voverlay_arrow_string
;
7692 /* Force a thorough redisplay the next time by setting
7693 last_arrow_position and last_arrow_string to t, which is
7694 unequal to any useful value of Voverlay_arrow_... */
7695 last_arrow_position
= Qt
;
7696 last_arrow_string
= Qt
;
7701 /* Return value in display table DP (Lisp_Char_Table *) for character
7702 C. Since a display table doesn't have any parent, we don't have to
7703 follow parent. Do not call this function directly but use the
7704 macro DISP_CHAR_VECTOR. */
7707 disp_char_vector (dp
, c
)
7708 struct Lisp_Char_Table
*dp
;
7714 if (SINGLE_BYTE_CHAR_P (c
))
7715 return (dp
->contents
[c
]);
7717 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
7718 if (code
[0] != CHARSET_COMPOSITION
)
7722 else if (code
[2] < 32)
7726 /* Here, the possible range of code[0] (== charset ID) is
7727 128..max_charset. Since the top level char table contains data
7728 for multibyte characters after 256th element, we must increment
7729 code[0] by 128 to get a correct index. */
7731 code
[3] = -1; /* anchor */
7733 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
7735 val
= dp
->contents
[code
[i
]];
7736 if (!SUB_CHAR_TABLE_P (val
))
7737 return (NILP (val
) ? dp
->defalt
: val
);
7740 /* Here, val is a sub char table. We return the default value of
7742 return (dp
->defalt
);
7747 /***********************************************************************
7749 ***********************************************************************/
7751 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
7754 redisplay_windows (window
)
7757 while (!NILP (window
))
7759 struct window
*w
= XWINDOW (window
);
7761 if (!NILP (w
->hchild
))
7762 redisplay_windows (w
->hchild
);
7763 else if (!NILP (w
->vchild
))
7764 redisplay_windows (w
->vchild
);
7766 redisplay_window (window
, 0);
7773 /* Set cursor position of W. PT is assumed to be displayed in ROW.
7774 DELTA is the number of bytes by which positions recorded in ROW
7775 differ from current buffer positions. */
7778 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
7780 struct glyph_row
*row
;
7781 struct glyph_matrix
*matrix
;
7782 int delta
, delta_bytes
, dy
, dvpos
;
7784 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
7785 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
7787 int pt_old
= PT
- delta
;
7789 /* Skip over glyphs not having an object at the start of the row.
7790 These are special glyphs like truncation marks on terminal
7792 if (row
->displays_text_p
)
7795 && glyph
->charpos
< 0)
7797 x
+= glyph
->pixel_width
;
7803 && (!BUFFERP (glyph
->object
)
7804 || glyph
->charpos
< pt_old
))
7806 x
+= glyph
->pixel_width
;
7810 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7812 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
7813 w
->cursor
.y
= row
->y
+ dy
;
7815 if (w
== XWINDOW (selected_window
))
7817 if (!row
->continued_p
7818 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
7821 this_line_buffer
= XBUFFER (w
->buffer
);
7823 CHARPOS (this_line_start_pos
)
7824 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
7825 BYTEPOS (this_line_start_pos
)
7826 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
7828 CHARPOS (this_line_end_pos
)
7829 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
7830 BYTEPOS (this_line_end_pos
)
7831 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
7833 this_line_y
= w
->cursor
.y
;
7834 this_line_pixel_height
= row
->height
;
7835 this_line_vpos
= w
->cursor
.vpos
;
7836 this_line_start_x
= row
->x
;
7839 CHARPOS (this_line_start_pos
) = 0;
7844 /* Run window scroll functions, if any, for WINDOW with new window
7845 start STARTP. Sets the window start of WINDOW to that position. */
7847 static INLINE
struct text_pos
7848 run_window_scroll_functions (window
, startp
)
7850 struct text_pos startp
;
7852 struct window
*w
= XWINDOW (window
);
7853 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
7855 if (!NILP (Vwindow_scroll_functions
))
7857 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
7858 make_number (CHARPOS (startp
)));
7859 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
7866 /* Modify the desired matrix of window W and W->vscroll so that the
7867 line containing the cursor is fully visible. */
7870 make_cursor_line_fully_visible (w
)
7873 struct glyph_matrix
*matrix
;
7874 struct glyph_row
*row
;
7875 int top_line_height
;
7877 /* It's not always possible to find the cursor, e.g, when a window
7878 is full of overlay strings. Don't do anything in that case. */
7879 if (w
->cursor
.vpos
< 0)
7882 matrix
= w
->desired_matrix
;
7883 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
7885 /* If row->y == top y of window display area, the window isn't tall
7886 enough to display a single line. There is nothing we can do
7888 top_line_height
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
7889 if (row
->y
== top_line_height
)
7892 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
7894 int dy
= row
->height
- row
->visible_height
;
7897 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
7899 else if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w
, row
))
7901 int dy
= - (row
->height
- row
->visible_height
);
7904 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
7907 /* When we change the cursor y-position of the selected window,
7908 change this_line_y as well so that the display optimization for
7909 the cursor line of the selected window in redisplay_internal uses
7910 the correct y-position. */
7911 if (w
== XWINDOW (selected_window
))
7912 this_line_y
= w
->cursor
.y
;
7916 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
7917 non-zero means only WINDOW is redisplayed in redisplay_internal.
7918 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
7919 in redisplay_window to bring a partially visible line into view in
7920 the case that only the cursor has moved.
7924 1 if scrolling succeeded
7926 0 if scrolling didn't find point.
7928 -1 if new fonts have been loaded so that we must interrupt
7929 redisplay, adjust glyph matrices, and try again. */
7932 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
7933 scroll_step
, temp_scroll_step
)
7935 int just_this_one_p
;
7936 int scroll_conservatively
, scroll_step
;
7937 int temp_scroll_step
;
7939 struct window
*w
= XWINDOW (window
);
7940 struct frame
*f
= XFRAME (w
->frame
);
7941 struct text_pos scroll_margin_pos
;
7942 struct text_pos pos
;
7943 struct text_pos startp
;
7945 Lisp_Object window_end
;
7946 int this_scroll_margin
;
7949 int line_height
, rc
;
7950 int amount_to_scroll
= 0;
7951 Lisp_Object aggressive
;
7955 debug_method_add (w
, "try_scrolling");
7958 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
7960 /* Compute scroll margin height in pixels. We scroll when point is
7961 within this distance from the top or bottom of the window. */
7962 if (scroll_margin
> 0)
7964 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
7965 this_scroll_margin
*= CANON_Y_UNIT (f
);
7968 this_scroll_margin
= 0;
7970 /* Compute how much we should try to scroll maximally to bring point
7973 scroll_max
= scroll_step
;
7974 else if (scroll_conservatively
)
7975 scroll_max
= scroll_conservatively
;
7976 else if (temp_scroll_step
)
7977 scroll_max
= temp_scroll_step
;
7978 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
7979 || NUMBERP (current_buffer
->scroll_up_aggressively
))
7980 /* We're trying to scroll because of aggressive scrolling
7981 but no scroll_step is set. Choose an arbitrary one. Maybe
7982 there should be a variable for this. */
7986 scroll_max
*= CANON_Y_UNIT (f
);
7988 /* Decide whether we have to scroll down. Start at the window end
7989 and move this_scroll_margin up to find the position of the scroll
7991 window_end
= Fwindow_end (window
, Qt
);
7992 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
7993 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
7994 if (this_scroll_margin
)
7996 start_display (&it
, w
, scroll_margin_pos
);
7997 move_it_vertically (&it
, - this_scroll_margin
);
7998 scroll_margin_pos
= it
.current
.pos
;
8001 if (PT
>= CHARPOS (scroll_margin_pos
))
8005 /* Point is in the scroll margin at the bottom of the window, or
8006 below. Compute a new window start that makes point visible. */
8008 /* Compute the distance from the scroll margin to PT.
8009 Give up if the distance is greater than scroll_max. */
8010 start_display (&it
, w
, scroll_margin_pos
);
8012 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8013 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8014 line_height
= (it
.max_ascent
+ it
.max_descent
8015 ? it
.max_ascent
+ it
.max_descent
8017 dy
= it
.current_y
+ line_height
- y0
;
8018 if (dy
> scroll_max
)
8021 /* Move the window start down. If scrolling conservatively,
8022 move it just enough down to make point visible. If
8023 scroll_step is set, move it down by scroll_step. */
8024 start_display (&it
, w
, startp
);
8026 if (scroll_conservatively
)
8027 amount_to_scroll
= dy
;
8028 else if (scroll_step
|| temp_scroll_step
)
8029 amount_to_scroll
= scroll_max
;
8032 aggressive
= current_buffer
->scroll_down_aggressively
;
8033 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8034 - WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
));
8035 if (NUMBERP (aggressive
))
8036 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8039 if (amount_to_scroll
<= 0)
8042 move_it_vertically (&it
, amount_to_scroll
);
8043 startp
= it
.current
.pos
;
8047 /* See if point is inside the scroll margin at the top of the
8049 scroll_margin_pos
= startp
;
8050 if (this_scroll_margin
)
8052 start_display (&it
, w
, startp
);
8053 move_it_vertically (&it
, this_scroll_margin
);
8054 scroll_margin_pos
= it
.current
.pos
;
8057 if (PT
< CHARPOS (scroll_margin_pos
))
8059 /* Point is in the scroll margin at the top of the window or
8060 above what is displayed in the window. */
8063 /* Compute the vertical distance from PT to the scroll
8064 margin position. Give up if distance is greater than
8066 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
8067 start_display (&it
, w
, pos
);
8069 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
8070 it
.last_visible_y
, -1,
8071 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8072 dy
= it
.current_y
- y0
;
8073 if (dy
> scroll_max
)
8076 /* Compute new window start. */
8077 start_display (&it
, w
, startp
);
8079 if (scroll_conservatively
)
8080 amount_to_scroll
= dy
;
8081 else if (scroll_step
|| temp_scroll_step
)
8082 amount_to_scroll
= scroll_max
;
8085 aggressive
= current_buffer
->scroll_up_aggressively
;
8086 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8087 - WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
));
8088 if (NUMBERP (aggressive
))
8089 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8092 if (amount_to_scroll
<= 0)
8095 move_it_vertically (&it
, - amount_to_scroll
);
8096 startp
= it
.current
.pos
;
8100 /* Run window scroll functions. */
8101 startp
= run_window_scroll_functions (window
, startp
);
8103 /* Display the window. Give up if new fonts are loaded, or if point
8105 if (!try_window (window
, startp
))
8107 else if (w
->cursor
.vpos
< 0)
8109 clear_glyph_matrix (w
->desired_matrix
);
8114 /* Maybe forget recorded base line for line number display. */
8115 if (!just_this_one_p
8116 || current_buffer
->clip_changed
8117 || BEG_UNCHANGED
< CHARPOS (startp
))
8118 w
->base_line_number
= Qnil
;
8120 /* If cursor ends up on a partially visible line, shift display
8121 lines up or down. */
8122 make_cursor_line_fully_visible (w
);
8130 /* Compute a suitable window start for window W if display of W starts
8131 on a continuation line. Value is non-zero if a new window start
8134 The new window start will be computed, based on W's width, starting
8135 from the start of the continued line. It is the start of the
8136 screen line with the minimum distance from the old start W->start. */
8139 compute_window_start_on_continuation_line (w
)
8142 struct text_pos pos
, start_pos
;
8143 int window_start_changed_p
= 0;
8145 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
8147 /* If window start is on a continuation line... Window start may be
8148 < BEGV in case there's invisible text at the start of the
8149 buffer (M-x rmail, for example). */
8150 if (CHARPOS (start_pos
) > BEGV
8151 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
8154 struct glyph_row
*row
;
8156 /* Find the start of the continued line. This should be fast
8157 because scan_buffer is fast (newline cache). */
8158 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_TOP_LINE_P (w
) ? 1 : 0);
8159 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
8160 row
, DEFAULT_FACE_ID
);
8161 reseat_at_previous_visible_line_start (&it
);
8163 /* If the line start is "too far" away from the window start,
8164 say it takes too much time to compute a new window start. */
8165 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
8166 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
8168 int min_distance
, distance
;
8170 /* Move forward by display lines to find the new window
8171 start. If window width was enlarged, the new start can
8172 be expected to be > the old start. If window width was
8173 decreased, the new window start will be < the old start.
8174 So, we're looking for the display line start with the
8175 minimum distance from the old window start. */
8176 pos
= it
.current
.pos
;
8177 min_distance
= INFINITY
;
8178 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
8179 distance
< min_distance
)
8181 min_distance
= distance
;
8182 pos
= it
.current
.pos
;
8183 move_it_by_lines (&it
, 1, 0);
8186 /* Set the window start there. */
8187 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
8188 window_start_changed_p
= 1;
8192 return window_start_changed_p
;
8196 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
8197 selected_window is redisplayed. */
8200 redisplay_window (window
, just_this_one_p
)
8202 int just_this_one_p
;
8204 struct window
*w
= XWINDOW (window
);
8205 struct frame
*f
= XFRAME (w
->frame
);
8206 struct buffer
*buffer
= XBUFFER (w
->buffer
);
8207 struct buffer
*old
= current_buffer
;
8208 struct text_pos lpoint
, opoint
, startp
;
8209 int update_mode_line
;
8212 /* Record it now because it's overwritten. */
8213 int current_matrix_up_to_date_p
= 0;
8214 int really_switched_buffer
= 0;
8215 int temp_scroll_step
= 0;
8216 int count
= specpdl_ptr
- specpdl
;
8218 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8221 /* W must be a leaf window here. */
8222 xassert (!NILP (w
->buffer
));
8224 *w
->desired_matrix
->method
= 0;
8227 specbind (Qinhibit_point_motion_hooks
, Qt
);
8229 reconsider_clip_changes (w
, buffer
);
8231 /* Has the mode line to be updated? */
8232 update_mode_line
= (!NILP (w
->update_mode_line
)
8233 || update_mode_lines
8234 || buffer
->clip_changed
);
8236 if (MINI_WINDOW_P (w
))
8238 if (w
== XWINDOW (echo_area_window
)
8239 && !NILP (echo_area_buffer
[0]))
8241 if (update_mode_line
)
8242 /* We may have to update a tty frame's menu bar or a
8243 toolbar. Example `M-x C-h C-h C-g'. */
8244 goto finish_menu_bars
;
8246 /* We've already displayed the echo area glyphs in this window. */
8247 goto finish_scroll_bars
;
8249 else if (w
!= XWINDOW (minibuf_window
))
8251 /* W is a mini-buffer window, but it's not the currently
8252 active one, so clear it. */
8253 int yb
= window_text_bottom_y (w
);
8254 struct glyph_row
*row
;
8257 for (y
= 0, row
= w
->desired_matrix
->rows
;
8259 y
+= row
->height
, ++row
)
8260 blank_row (w
, row
, y
);
8261 goto finish_scroll_bars
;
8265 /* Otherwise set up data on this window; select its buffer and point
8267 if (update_mode_line
)
8269 /* Really select the buffer, for the sake of buffer-local
8271 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8272 really_switched_buffer
= 1;
8275 set_buffer_temp (XBUFFER (w
->buffer
));
8276 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
8278 current_matrix_up_to_date_p
8279 = (!NILP (w
->window_end_valid
)
8280 && !current_buffer
->clip_changed
8281 && XFASTINT (w
->last_modified
) >= MODIFF
8282 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
8284 /* When windows_or_buffers_changed is non-zero, we can't rely on
8285 the window end being valid, so set it to nil there. */
8286 if (windows_or_buffers_changed
)
8288 /* If window starts on a continuation line, maybe adjust the
8289 window start in case the window's width changed. */
8290 if (XMARKER (w
->start
)->buffer
== current_buffer
)
8291 compute_window_start_on_continuation_line (w
);
8293 w
->window_end_valid
= Qnil
;
8296 /* Some sanity checks. */
8297 CHECK_WINDOW_END (w
);
8298 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
8300 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
8303 /* If %c is in mode line, update it if needed. */
8304 if (!NILP (w
->column_number_displayed
)
8305 /* This alternative quickly identifies a common case
8306 where no change is needed. */
8307 && !(PT
== XFASTINT (w
->last_point
)
8308 && XFASTINT (w
->last_modified
) >= MODIFF
8309 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8310 && XFASTINT (w
->column_number_displayed
) != current_column ())
8311 update_mode_line
= 1;
8313 /* Count number of windows showing the selected buffer. An indirect
8314 buffer counts as its base buffer. */
8315 if (!just_this_one_p
)
8317 struct buffer
*current_base
, *window_base
;
8318 current_base
= current_buffer
;
8319 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
8320 if (current_base
->base_buffer
)
8321 current_base
= current_base
->base_buffer
;
8322 if (window_base
->base_buffer
)
8323 window_base
= window_base
->base_buffer
;
8324 if (current_base
== window_base
)
8328 /* Point refers normally to the selected window. For any other
8329 window, set up appropriate value. */
8330 if (!EQ (window
, selected_window
))
8332 int new_pt
= XMARKER (w
->pointm
)->charpos
;
8333 int new_pt_byte
= marker_byte_position (w
->pointm
);
8337 new_pt_byte
= BEGV_BYTE
;
8338 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
8340 else if (new_pt
> (ZV
- 1))
8343 new_pt_byte
= ZV_BYTE
;
8344 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
8347 /* We don't use SET_PT so that the point-motion hooks don't run. */
8348 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
8351 /* If any of the character widths specified in the display table
8352 have changed, invalidate the width run cache. It's true that
8353 this may be a bit late to catch such changes, but the rest of
8354 redisplay goes (non-fatally) haywire when the display table is
8355 changed, so why should we worry about doing any better? */
8356 if (current_buffer
->width_run_cache
)
8358 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
8360 if (! disptab_matches_widthtab (disptab
,
8361 XVECTOR (current_buffer
->width_table
)))
8363 invalidate_region_cache (current_buffer
,
8364 current_buffer
->width_run_cache
,
8366 recompute_width_table (current_buffer
, disptab
);
8370 /* If window-start is screwed up, choose a new one. */
8371 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
8374 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8376 /* If someone specified a new starting point but did not insist,
8377 check whether it can be used. */
8378 if (!NILP (w
->optional_new_start
))
8380 w
->optional_new_start
= Qnil
;
8381 /* This takes a mini-buffer prompt into account. */
8382 start_display (&it
, w
, startp
);
8383 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8384 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8385 if (IT_CHARPOS (it
) == PT
)
8386 w
->force_start
= Qt
;
8389 /* Handle case where place to start displaying has been specified,
8390 unless the specified location is outside the accessible range. */
8391 if (!NILP (w
->force_start
))
8393 w
->force_start
= Qnil
;
8395 w
->window_end_valid
= Qnil
;
8397 /* Forget any recorded base line for line number display. */
8398 if (!current_matrix_up_to_date_p
8399 || current_buffer
->clip_changed
)
8400 w
->base_line_number
= Qnil
;
8402 /* Redisplay the mode line. Select the buffer properly for that.
8403 Also, run the hook window-scroll-functions
8404 because we have scrolled. */
8405 /* Note, we do this after clearing force_start because
8406 if there's an error, it is better to forget about force_start
8407 than to get into an infinite loop calling the hook functions
8408 and having them get more errors. */
8409 if (!update_mode_line
8410 || ! NILP (Vwindow_scroll_functions
))
8412 if (!really_switched_buffer
)
8414 set_buffer_temp (old
);
8415 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8416 really_switched_buffer
= 1;
8419 update_mode_line
= 1;
8420 w
->update_mode_line
= Qt
;
8421 startp
= run_window_scroll_functions (window
, startp
);
8424 XSETFASTINT (w
->last_modified
, 0);
8425 XSETFASTINT (w
->last_overlay_modified
, 0);
8426 if (CHARPOS (startp
) < BEGV
)
8427 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
8428 else if (CHARPOS (startp
) > ZV
)
8429 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
8431 /* Redisplay, then check if cursor has been set during the
8432 redisplay. Give up if new fonts were loaded. */
8433 if (!try_window (window
, startp
))
8435 w
->force_start
= Qt
;
8436 clear_glyph_matrix (w
->desired_matrix
);
8437 goto restore_buffers
;
8440 if (w
->cursor
.vpos
< 0)
8442 /* If point does not appear, or on a line that is not fully
8443 visible, move point so it does appear. The desired
8444 matrix has been built above, so we can use it. */
8445 int height
= window_box_height (w
) / 2;
8446 struct glyph_row
*row
= MATRIX_ROW (w
->desired_matrix
, 0);
8448 while (row
->y
< height
)
8451 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
8452 MATRIX_ROW_START_BYTEPOS (row
));
8454 if (w
!= XWINDOW (selected_window
))
8455 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
8456 else if (current_buffer
== old
)
8457 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8459 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
8461 /* If we are highlighting the region, then we just changed
8462 the region, so redisplay to show it. */
8463 if (!NILP (Vtransient_mark_mode
)
8464 && !NILP (current_buffer
->mark_active
))
8466 clear_glyph_matrix (w
->desired_matrix
);
8467 if (!try_window (window
, startp
))
8468 goto restore_buffers
;
8472 make_cursor_line_fully_visible (w
);
8474 debug_method_add (w
, "forced window start");
8479 /* Handle case where text has not changed, only point, and it has
8480 not moved off the frame. */
8481 if (current_matrix_up_to_date_p
8482 /* Point may be in this window. */
8483 && PT
>= CHARPOS (startp
)
8484 /* If we don't check this, we are called to move the cursor in a
8485 horizontally split window with a current matrix that doesn't
8487 && !windows_or_buffers_changed
8488 /* Selective display hasn't changed. */
8489 && !current_buffer
->clip_changed
8490 /* If force-mode-line-update was called, really redisplay;
8491 that's how redisplay is forced after e.g. changing
8492 buffer-invisibility-spec. */
8493 && NILP (w
->update_mode_line
)
8494 /* Can't use this case if highlighting a region. When a
8495 region exists, cursor movement has to do more than just
8497 && !(!NILP (Vtransient_mark_mode
)
8498 && !NILP (current_buffer
->mark_active
))
8499 && NILP (w
->region_showing
)
8500 && NILP (Vshow_trailing_whitespace
)
8501 /* Right after splitting windows, last_point may be nil. */
8502 && INTEGERP (w
->last_point
)
8503 /* This code is not used for mini-buffer for the sake of the case
8504 of redisplaying to replace an echo area message; since in
8505 that case the mini-buffer contents per se are usually
8506 unchanged. This code is of no real use in the mini-buffer
8507 since the handling of this_line_start_pos, etc., in redisplay
8508 handles the same cases. */
8509 && !EQ (window
, minibuf_window
)
8510 /* When splitting windows or for new windows, it happens that
8511 redisplay is called with a nil window_end_vpos or one being
8512 larger than the window. This should really be fixed in
8513 window.c. I don't have this on my list, now, so we do
8514 approximately the same as the old redisplay code. --gerd. */
8515 && INTEGERP (w
->window_end_vpos
)
8516 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
8517 && (FRAME_WINDOW_P (f
)
8518 || !MARKERP (Voverlay_arrow_position
)
8519 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
8521 int this_scroll_margin
;
8522 struct glyph_row
*row
;
8526 debug_method_add (w
, "cursor movement");
8529 /* Scroll if point within this distance from the top or bottom
8530 of the window. This is a pixel value. */
8531 this_scroll_margin
= max (0, scroll_margin
);
8532 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
8533 this_scroll_margin
*= CANON_Y_UNIT (f
);
8535 /* Start with the row the cursor was displayed during the last
8536 not paused redisplay. Give up if that row is not valid. */
8537 if (w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
8539 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
8540 if (row
->mode_line_p
)
8542 if (!row
->enabled_p
)
8546 if (PT
> XFASTINT (w
->last_point
))
8548 /* Point has moved forward. */
8549 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
8551 while ((MATRIX_ROW_END_CHARPOS (row
) < PT
8552 /* The end position of a row equals the start
8553 position of the next row. If PT is there, we
8554 would rather display it in the next line, except
8555 when this line ends in ZV. */
8556 || (MATRIX_ROW_END_CHARPOS (row
) == PT
8557 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
8558 || !row
->ends_at_zv_p
)))
8559 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
8561 xassert (row
->enabled_p
);
8565 /* If within the scroll margin, scroll. Note that
8566 MATRIX_ROW_BOTTOM_Y gives the pixel position at which the
8567 next line would be drawn, and that this_scroll_margin can
8569 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
8570 || PT
> MATRIX_ROW_END_CHARPOS (row
)
8571 /* Line is completely visible last line in window and PT
8572 is to be set in the next line. */
8573 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
8574 && PT
== MATRIX_ROW_END_CHARPOS (row
)
8575 && !row
->ends_at_zv_p
8576 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
8579 else if (PT
< XFASTINT (w
->last_point
))
8581 /* Cursor has to be moved backward. Note that PT >=
8582 CHARPOS (startp) because of the outer if-statement. */
8583 while (!row
->mode_line_p
8584 && (MATRIX_ROW_START_CHARPOS (row
) > PT
8585 || (MATRIX_ROW_START_CHARPOS (row
) == PT
8586 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
8587 && (row
->y
> this_scroll_margin
8588 || CHARPOS (startp
) == BEGV
))
8590 xassert (row
->enabled_p
);
8594 /* Consider the following case: Window starts at BEGV, there
8595 is invisible, intangible text at BEGV, so that display
8596 starts at some point START > BEGV. It can happen that
8597 we are called with PT somewhere between BEGV and START.
8598 Try to handle that case. */
8599 if (row
< w
->current_matrix
->rows
8600 || row
->mode_line_p
)
8602 row
= w
->current_matrix
->rows
;
8603 if (row
->mode_line_p
)
8607 /* Due to newlines in overlay strings, we may have to skip
8608 forward over overlay strings. */
8609 while (MATRIX_ROW_END_CHARPOS (row
) == PT
8610 && MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P (row
)
8611 && !row
->ends_at_zv_p
)
8614 /* If within the scroll margin, scroll. */
8615 if (row
->y
< this_scroll_margin
8616 && CHARPOS (startp
) != BEGV
)
8620 /* if PT is not in the glyph row, give up. */
8621 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
8622 || PT
> MATRIX_ROW_END_CHARPOS (row
))
8625 /* If we end up in a partially visible line, let's make it fully
8626 visible. This can be done most easily by using the existing
8628 if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8630 temp_scroll_step
= 1;
8636 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8640 /* If current starting point was originally the beginning of a line
8641 but no longer is, find a new starting point. */
8642 else if (!NILP (w
->start_at_line_beg
)
8643 && !(CHARPOS (startp
) <= BEGV
8644 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
8647 debug_method_add (w
, "recenter 1");
8652 /* Try scrolling with try_window_id. */
8653 else if (/* Windows and buffers haven't changed. */
8654 !windows_or_buffers_changed
8655 /* Window must be either use window-based redisplay or
8657 && (FRAME_WINDOW_P (f
)
8658 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
8659 && !MINI_WINDOW_P (w
)
8660 /* Point is not known NOT to appear in window. */
8661 && PT
>= CHARPOS (startp
)
8662 && XFASTINT (w
->last_modified
)
8663 /* Window is not hscrolled. */
8664 && XFASTINT (w
->hscroll
) == 0
8665 /* Selective display has not changed. */
8666 && !current_buffer
->clip_changed
8667 /* Current matrix is up to date. */
8668 && !NILP (w
->window_end_valid
)
8669 /* Can't use this case if highlighting a region because
8670 a cursor movement will do more than just set the cursor. */
8671 && !(!NILP (Vtransient_mark_mode
)
8672 && !NILP (current_buffer
->mark_active
))
8673 && NILP (w
->region_showing
)
8674 && NILP (Vshow_trailing_whitespace
)
8675 /* Overlay arrow position and string not changed. */
8676 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
8677 && EQ (last_arrow_string
, Voverlay_arrow_string
)
8678 /* Value is > 0 if update has been done, it is -1 if we
8679 know that the same window start will not work. It is 0
8680 if unsuccessful for some other reason. */
8681 && (tem
= try_window_id (w
)) != 0)
8684 debug_method_add (w
, "try_window_id");
8687 if (fonts_changed_p
)
8688 goto restore_buffers
;
8691 /* Otherwise try_window_id has returned -1 which means that we
8692 don't want the alternative below this comment to execute. */
8694 else if (CHARPOS (startp
) >= BEGV
8695 && CHARPOS (startp
) <= ZV
8696 && PT
>= CHARPOS (startp
)
8697 && (CHARPOS (startp
) < ZV
8698 /* Avoid starting at end of buffer. */
8699 || CHARPOS (startp
) == BEGV
8700 || (XFASTINT (w
->last_modified
) >= MODIFF
8701 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
8704 debug_method_add (w
, "same window start");
8707 /* Try to redisplay starting at same place as before.
8708 If point has not moved off frame, accept the results. */
8709 if (!current_matrix_up_to_date_p
8710 /* Don't use try_window_reusing_current_matrix in this case
8711 because it can have changed the buffer. */
8712 || !NILP (Vwindow_scroll_functions
)
8713 || MINI_WINDOW_P (w
)
8714 || !try_window_reusing_current_matrix (w
))
8716 IF_DEBUG (debug_method_add (w
, "1"));
8717 try_window (window
, startp
);
8720 if (fonts_changed_p
)
8721 goto restore_buffers
;
8723 if (w
->cursor
.vpos
>= 0)
8725 if (!just_this_one_p
8726 || current_buffer
->clip_changed
8727 || BEG_UNCHANGED
< CHARPOS (startp
))
8728 /* Forget any recorded base line for line number display. */
8729 w
->base_line_number
= Qnil
;
8731 make_cursor_line_fully_visible (w
);
8735 clear_glyph_matrix (w
->desired_matrix
);
8740 XSETFASTINT (w
->last_modified
, 0);
8741 XSETFASTINT (w
->last_overlay_modified
, 0);
8743 /* Redisplay the mode line. Select the buffer properly for that. */
8744 if (!update_mode_line
)
8746 if (!really_switched_buffer
)
8748 set_buffer_temp (old
);
8749 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8750 really_switched_buffer
= 1;
8752 update_mode_line
= 1;
8753 w
->update_mode_line
= Qt
;
8756 /* Try to scroll by specified few lines. */
8757 if ((scroll_conservatively
8760 || NUMBERP (current_buffer
->scroll_up_aggressively
)
8761 || NUMBERP (current_buffer
->scroll_down_aggressively
))
8762 && !current_buffer
->clip_changed
8763 && CHARPOS (startp
) >= BEGV
8764 && CHARPOS (startp
) <= ZV
)
8766 /* The function returns -1 if new fonts were loaded, 1 if
8767 successful, 0 if not successful. */
8768 int rc
= try_scrolling (window
, just_this_one_p
,
8769 scroll_conservatively
,
8775 goto restore_buffers
;
8778 /* Finally, just choose place to start which centers point */
8783 debug_method_add (w
, "recenter");
8786 /* w->vscroll = 0; */
8788 /* Forget any previously recorded base line for line number display. */
8789 if (!current_matrix_up_to_date_p
8790 || current_buffer
->clip_changed
)
8791 w
->base_line_number
= Qnil
;
8793 /* Move backward half the height of the window. */
8794 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
8795 it
.current_y
= it
.last_visible_y
;
8796 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
8797 xassert (IT_CHARPOS (it
) >= BEGV
);
8799 /* The function move_it_vertically_backward may move over more
8800 than the specified y-distance. If it->w is small, e.g. a
8801 mini-buffer window, we may end up in front of the window's
8802 display area. Start displaying at the start of the line
8803 containing PT in this case. */
8804 if (it
.current_y
<= 0)
8806 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
8807 move_it_vertically (&it
, 0);
8808 xassert (IT_CHARPOS (it
) <= PT
);
8812 it
.current_x
= it
.hpos
= 0;
8814 /* Set startp here explicitly in case that helps avoid an infinite loop
8815 in case the window-scroll-functions functions get errors. */
8816 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
8818 /* Run scroll hooks. */
8819 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
8821 /* Redisplay the window. */
8822 if (!current_matrix_up_to_date_p
8823 || windows_or_buffers_changed
8824 /* Don't use try_window_reusing_current_matrix in this case
8825 because it can have changed the buffer. */
8826 || !NILP (Vwindow_scroll_functions
)
8828 || MINI_WINDOW_P (w
)
8829 || !try_window_reusing_current_matrix (w
))
8830 try_window (window
, startp
);
8832 /* If new fonts have been loaded (due to fontsets), give up. We
8833 have to start a new redisplay since we need to re-adjust glyph
8835 if (fonts_changed_p
)
8836 goto restore_buffers
;
8838 /* If cursor did not appear assume that the middle of the window is
8839 in the first line of the window. Do it again with the next line.
8840 (Imagine a window of height 100, displaying two lines of height
8841 60. Moving back 50 from it->last_visible_y will end in the first
8843 if (w
->cursor
.vpos
< 0)
8845 if (!NILP (w
->window_end_valid
)
8846 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
8848 clear_glyph_matrix (w
->desired_matrix
);
8849 move_it_by_lines (&it
, 1, 0);
8850 try_window (window
, it
.current
.pos
);
8852 else if (PT
< IT_CHARPOS (it
))
8854 clear_glyph_matrix (w
->desired_matrix
);
8855 move_it_by_lines (&it
, -1, 0);
8856 try_window (window
, it
.current
.pos
);
8860 /* Not much we can do about it. */
8864 /* Consider the following case: Window starts at BEGV, there is
8865 invisible, intangible text at BEGV, so that display starts at
8866 some point START > BEGV. It can happen that we are called with
8867 PT somewhere between BEGV and START. Try to handle that case. */
8868 if (w
->cursor
.vpos
< 0)
8870 struct glyph_row
*row
= w
->current_matrix
->rows
;
8871 if (row
->mode_line_p
)
8873 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8876 make_cursor_line_fully_visible (w
);
8878 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8879 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
8880 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
8885 /* Display the mode line, if we must. */
8886 if ((update_mode_line
8887 /* If window not full width, must redo its mode line
8888 if (a) the window to its side is being redone and
8889 (b) we do a frame-based redisplay. This is a consequence
8890 of how inverted lines are drawn in frame-based redisplay. */
8891 || (!just_this_one_p
8892 && !FRAME_WINDOW_P (f
)
8893 && !WINDOW_FULL_WIDTH_P (w
))
8894 /* Line number to display. */
8895 || INTEGERP (w
->base_line_pos
)
8896 /* Column number is displayed and different from the one displayed. */
8897 || (!NILP (w
->column_number_displayed
)
8898 && XFASTINT (w
->column_number_displayed
) != current_column ()))
8899 /* This means that the window has a mode line. */
8900 && (WINDOW_WANTS_MODELINE_P (w
)
8901 || WINDOW_WANTS_TOP_LINE_P (w
)))
8903 display_mode_lines (w
);
8905 /* If mode line height has changed, arrange for a thorough
8906 immediate redisplay using the correct mode line height. */
8907 if (WINDOW_WANTS_MODELINE_P (w
)
8908 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
8910 fonts_changed_p
= 1;
8911 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
8912 = DESIRED_MODE_LINE_HEIGHT (w
);
8915 /* If top line height has changed, arrange for a thorough
8916 immediate redisplay using the correct mode line height. */
8917 if (WINDOW_WANTS_TOP_LINE_P (w
)
8918 && CURRENT_TOP_LINE_HEIGHT (w
) != DESIRED_TOP_LINE_HEIGHT (w
))
8920 fonts_changed_p
= 1;
8921 MATRIX_TOP_LINE_ROW (w
->current_matrix
)->height
8922 = DESIRED_TOP_LINE_HEIGHT (w
);
8925 if (fonts_changed_p
)
8926 goto restore_buffers
;
8929 if (!line_number_displayed
8930 && !BUFFERP (w
->base_line_pos
))
8932 w
->base_line_pos
= Qnil
;
8933 w
->base_line_number
= Qnil
;
8938 /* When we reach a frame's selected window, redo the frame's menu bar. */
8939 if (update_mode_line
8940 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
8942 int redisplay_menu_p
= 0;
8944 if (FRAME_WINDOW_P (f
))
8946 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
8947 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
8949 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
8953 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
8955 if (redisplay_menu_p
)
8956 display_menu_bar (w
);
8958 #ifdef HAVE_WINDOW_SYSTEM
8959 if (WINDOWP (f
->toolbar_window
)
8960 && (FRAME_TOOLBAR_LINES (f
) > 0
8961 || auto_resize_toolbars_p
))
8962 redisplay_toolbar (f
);
8968 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8970 int start
, end
, whole
;
8972 /* Calculate the start and end positions for the current window.
8973 At some point, it would be nice to choose between scrollbars
8974 which reflect the whole buffer size, with special markers
8975 indicating narrowing, and scrollbars which reflect only the
8978 Note that mini-buffers sometimes aren't displaying any text. */
8979 if (!MINI_WINDOW_P (w
)
8980 || (w
== XWINDOW (minibuf_window
)
8981 && NILP (echo_area_buffer
[0])))
8984 start
= marker_position (w
->start
) - BEGV
;
8985 /* I don't think this is guaranteed to be right. For the
8986 moment, we'll pretend it is. */
8987 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
8991 if (whole
< (end
- start
))
8992 whole
= end
- start
;
8995 start
= end
= whole
= 0;
8997 /* Indicate what this scroll bar ought to be displaying now. */
8998 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
9000 /* Note that we actually used the scroll bar attached to this
9001 window, so it shouldn't be deleted at the end of redisplay. */
9002 (*redeem_scroll_bar_hook
) (w
);
9007 /* Restore current_buffer and value of point in it. */
9008 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
9009 if (really_switched_buffer
)
9010 set_buffer_internal_1 (old
);
9012 set_buffer_temp (old
);
9013 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
9015 unbind_to (count
, Qnil
);
9019 /* Build the complete desired matrix of WINDOW with a window start
9020 buffer position POS. Value is non-zero if successful. It is zero
9021 if fonts were loaded during redisplay which makes re-adjusting
9022 glyph matrices necessary. */
9025 try_window (window
, pos
)
9027 struct text_pos pos
;
9029 struct window
*w
= XWINDOW (window
);
9031 struct glyph_row
*last_text_row
= NULL
;
9033 /* Make POS the new window start. */
9034 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
9036 /* Mark cursor position as unknown. No overlay arrow seen. */
9037 w
->cursor
.vpos
= -1;
9038 overlay_arrow_seen
= 0;
9040 /* Initialize iterator and info to start at POS. */
9041 start_display (&it
, w
, pos
);
9043 /* Display all lines of W. */
9044 while (it
.current_y
< it
.last_visible_y
)
9046 if (display_line (&it
))
9047 last_text_row
= it
.glyph_row
- 1;
9048 if (fonts_changed_p
)
9052 /* If bottom moved off end of frame, change mode line percentage. */
9053 if (XFASTINT (w
->window_end_pos
) <= 0
9054 && Z
!= IT_CHARPOS (it
))
9055 w
->update_mode_line
= Qt
;
9057 /* Set window_end_pos to the offset of the last character displayed
9058 on the window from the end of current_buffer. Set
9059 window_end_vpos to its row number. */
9062 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
9063 w
->window_end_bytepos
9064 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9065 XSETFASTINT (w
->window_end_pos
,
9066 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9067 XSETFASTINT (w
->window_end_vpos
,
9068 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9069 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
9074 w
->window_end_bytepos
= 0;
9075 XSETFASTINT (w
->window_end_pos
, 0);
9076 XSETFASTINT (w
->window_end_vpos
, 0);
9079 /* But that is not valid info until redisplay finishes. */
9080 w
->window_end_valid
= Qnil
;
9086 /************************************************************************
9087 Window redisplay reusing current matrix when buffer has not changed
9088 ************************************************************************/
9090 /* Try redisplay of window W showing an unchanged buffer with a
9091 different window start than the last time it was displayed by
9092 reusing its current matrix. Value is non-zero if successful.
9093 W->start is the new window start. */
9096 try_window_reusing_current_matrix (w
)
9099 struct frame
*f
= XFRAME (w
->frame
);
9100 struct glyph_row
*row
, *bottom_row
;
9103 struct text_pos start
, new_start
;
9104 int nrows_scrolled
, i
;
9105 struct glyph_row
*last_text_row
;
9106 struct glyph_row
*last_reused_text_row
;
9107 struct glyph_row
*start_row
;
9108 int start_vpos
, min_y
, max_y
;
9110 /* Right now this function doesn't handle terminal frames. */
9111 if (!FRAME_WINDOW_P (f
))
9114 /* Can't do this if region may have changed. */
9115 if ((!NILP (Vtransient_mark_mode
)
9116 && !NILP (current_buffer
->mark_active
))
9117 || !NILP (w
->region_showing
)
9118 || !NILP (Vshow_trailing_whitespace
))
9121 /* If top-line visibility has changed, give up. */
9122 if (WINDOW_WANTS_TOP_LINE_P (w
)
9123 != MATRIX_TOP_LINE_ROW (w
->current_matrix
)->mode_line_p
)
9126 /* Give up if old or new display is scrolled vertically. We could
9127 make this function handle this, but right now it doesn't. */
9128 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9129 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
9132 /* The variable new_start now holds the new window start. The old
9133 start `start' can be determined from the current matrix. */
9134 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
9135 start
= start_row
->start
.pos
;
9136 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
9138 /* Clear the desired matrix for the display below. */
9139 clear_glyph_matrix (w
->desired_matrix
);
9141 if (CHARPOS (new_start
) <= CHARPOS (start
))
9145 IF_DEBUG (debug_method_add (w
, "twu1"));
9147 /* Display up to a row that can be reused. The variable
9148 last_text_row is set to the last row displayed that displays
9150 start_display (&it
, w
, new_start
);
9151 first_row_y
= it
.current_y
;
9152 w
->cursor
.vpos
= -1;
9153 last_text_row
= last_reused_text_row
= NULL
;
9154 while (it
.current_y
< it
.last_visible_y
9155 && IT_CHARPOS (it
) < CHARPOS (start
)
9156 && !fonts_changed_p
)
9157 if (display_line (&it
))
9158 last_text_row
= it
.glyph_row
- 1;
9160 /* A value of current_y < last_visible_y means that we stopped
9161 at the previous window start, which in turn means that we
9162 have at least one reusable row. */
9163 if (it
.current_y
< it
.last_visible_y
)
9165 nrows_scrolled
= it
.vpos
;
9167 /* Find PT if not already found in the lines displayed. */
9168 if (w
->cursor
.vpos
< 0)
9170 int dy
= it
.current_y
- first_row_y
;
9172 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9173 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9175 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
9176 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9178 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
9179 dy
, nrows_scrolled
);
9183 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
9189 /* Give up if point was not found. This shouldn't
9190 happen often; not more often than with try_window
9192 if (w
->cursor
.vpos
< 0)
9194 clear_glyph_matrix (w
->desired_matrix
);
9199 /* Scroll the display. Do it before the current matrix is
9200 changed. The problem here is that update has not yet
9201 run, i.e. part of the current matrix is not up to date.
9202 scroll_run_hook will clear the cursor, and use the
9203 current matrix to get the height of the row the cursor is
9205 run
.current_y
= first_row_y
;
9206 run
.desired_y
= it
.current_y
;
9207 run
.height
= it
.last_visible_y
- it
.current_y
;
9211 rif
->update_window_begin_hook (w
);
9212 rif
->scroll_run_hook (w
, &run
);
9213 rif
->update_window_end_hook (w
, 0);
9217 /* Shift current matrix down by nrows_scrolled lines. */
9218 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9219 rotate_matrix (w
->current_matrix
,
9221 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9224 /* Disable lines not reused. */
9225 for (i
= 0; i
< it
.vpos
; ++i
)
9226 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
9228 /* Re-compute Y positions. */
9229 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
) + nrows_scrolled
;
9230 min_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
9231 max_y
= it
.last_visible_y
;
9232 while (row
< bottom_row
)
9234 row
->y
= it
.current_y
;
9237 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9238 else if (row
->y
+ row
->height
> max_y
)
9240 = row
->height
- (row
->y
+ row
->height
- max_y
);
9242 row
->visible_height
= row
->height
;
9244 it
.current_y
+= row
->height
;
9247 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9248 last_reused_text_row
= row
;
9249 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
9255 /* Update window_end_pos etc.; last_reused_text_row is the last
9256 reused row from the current matrix containing text, if any.
9257 The value of last_text_row is the last displayed line
9259 if (last_reused_text_row
)
9261 w
->window_end_bytepos
9262 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
9263 XSETFASTINT (w
->window_end_pos
,
9264 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
9265 XSETFASTINT (w
->window_end_vpos
,
9266 MATRIX_ROW_VPOS (last_reused_text_row
,
9267 w
->current_matrix
));
9269 else if (last_text_row
)
9271 w
->window_end_bytepos
9272 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9273 XSETFASTINT (w
->window_end_pos
,
9274 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9275 XSETFASTINT (w
->window_end_vpos
,
9276 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9280 /* This window must be completely empty. */
9281 w
->window_end_bytepos
= 0;
9282 XSETFASTINT (w
->window_end_pos
, 0);
9283 XSETFASTINT (w
->window_end_vpos
, 0);
9285 w
->window_end_valid
= Qnil
;
9287 /* Update hint: don't try scrolling again in update_window. */
9288 w
->desired_matrix
->no_scrolling_p
= 1;
9291 debug_method_add (w
, "try_window_reusing_current_matrix 1");
9295 else if (CHARPOS (new_start
) > CHARPOS (start
))
9297 struct glyph_row
*pt_row
, *row
;
9298 struct glyph_row
*first_reusable_row
;
9299 struct glyph_row
*first_row_to_display
;
9301 int yb
= window_text_bottom_y (w
);
9303 IF_DEBUG (debug_method_add (w
, "twu2"));
9305 /* Find the row starting at new_start, if there is one. Don't
9306 reuse a partially visible line at the end. */
9307 first_reusable_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9308 while (first_reusable_row
->enabled_p
9309 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
9310 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9311 < CHARPOS (new_start
)))
9312 ++first_reusable_row
;
9314 /* Give up if there is no row to reuse. */
9315 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
9316 || !first_reusable_row
->enabled_p
9317 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9318 != CHARPOS (new_start
)))
9321 /* We can reuse fully visible rows beginning with
9322 first_reusable_row to the end of the window. Set
9323 first_row_to_display to the first row that cannot be reused.
9324 Set pt_row to the row containing point, if there is any. */
9325 first_row_to_display
= first_reusable_row
;
9327 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
9329 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
9330 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
9331 pt_row
= first_row_to_display
;
9333 ++first_row_to_display
;
9336 /* Start displaying at the start of first_row_to_display. */
9337 xassert (first_row_to_display
->y
< yb
);
9338 init_to_row_start (&it
, w
, first_row_to_display
);
9339 nrows_scrolled
= MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
);
9340 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
9342 it
.current_y
= first_row_to_display
->y
- first_reusable_row
->y
;
9344 /* Display lines beginning with first_row_to_display in the
9345 desired matrix. Set last_text_row to the last row displayed
9346 that displays text. */
9347 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
9349 w
->cursor
.vpos
= -1;
9350 last_text_row
= NULL
;
9351 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
9352 if (display_line (&it
))
9353 last_text_row
= it
.glyph_row
- 1;
9355 /* Give up If point isn't in a row displayed or reused. */
9356 if (w
->cursor
.vpos
< 0)
9358 clear_glyph_matrix (w
->desired_matrix
);
9362 /* If point is in a reused row, adjust y and vpos of the cursor
9366 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
9368 w
->cursor
.y
-= first_reusable_row
->y
;
9371 /* Scroll the display. */
9372 run
.current_y
= first_reusable_row
->y
;
9373 run
.desired_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
9374 run
.height
= it
.last_visible_y
- run
.current_y
;
9377 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9379 rif
->update_window_begin_hook (w
);
9380 rif
->scroll_run_hook (w
, &run
);
9381 rif
->update_window_end_hook (w
, 0);
9385 /* Adjust Y positions of reused rows. */
9386 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9387 row
= first_reusable_row
;
9388 dy
= first_reusable_row
->y
;
9389 min_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
9390 max_y
= it
.last_visible_y
;
9391 while (row
< first_row_to_display
)
9395 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9396 else if (row
->y
+ row
->height
> max_y
)
9398 = row
->height
- (row
->y
+ row
->height
- max_y
);
9400 row
->visible_height
= row
->height
;
9404 /* Disable rows not reused. */
9405 while (row
< bottom_row
)
9411 /* Scroll the current matrix. */
9412 xassert (nrows_scrolled
> 0);
9413 rotate_matrix (w
->current_matrix
,
9415 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9418 /* Adjust window end. A null value of last_text_row means that
9419 the window end is in reused rows which in turn means that
9420 only its vpos can have changed. */
9423 w
->window_end_bytepos
9424 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9425 XSETFASTINT (w
->window_end_pos
,
9426 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9427 XSETFASTINT (w
->window_end_vpos
,
9428 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9432 XSETFASTINT (w
->window_end_vpos
,
9433 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
9436 w
->window_end_valid
= Qnil
;
9437 w
->desired_matrix
->no_scrolling_p
= 1;
9440 debug_method_add (w
, "try_window_reusing_current_matrix 2");
9450 /************************************************************************
9451 Window redisplay reusing current matrix when buffer has changed
9452 ************************************************************************/
9454 static struct glyph_row
*get_last_unchanged_at_beg_row
P_ ((struct window
*));
9455 static struct glyph_row
*get_first_unchanged_at_end_row
P_ ((struct window
*,
9457 static struct glyph_row
*
9458 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
9459 struct glyph_row
*));
9462 /* Return the last row in MATRIX displaying text. If row START is
9463 non-null, start searching with that row. IT gives the dimensions
9464 of the display. Value is null if matrix is empty; otherwise it is
9465 a pointer to the row found. */
9467 static struct glyph_row
*
9468 find_last_row_displaying_text (matrix
, it
, start
)
9469 struct glyph_matrix
*matrix
;
9471 struct glyph_row
*start
;
9473 struct glyph_row
*row
, *row_found
;
9475 /* Set row_found to the last row in IT->w's current matrix
9476 displaying text. The loop looks funny but think of partially
9479 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
9480 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9482 xassert (row
->enabled_p
);
9484 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
9493 /* Return the last row in the current matrix of W that is not affected
9494 by changes at the start of current_buffer that occurred since the
9495 last time W was redisplayed. Value is null if no such row exists.
9497 The global variable beg_unchanged has to contain the number of
9498 bytes unchanged at the start of current_buffer. BEG +
9499 beg_unchanged is the buffer position of the first changed byte in
9500 current_buffer. Characters at positions < BEG + beg_unchanged are
9501 at the same buffer positions as they were when the current matrix
9504 static struct glyph_row
*
9505 get_last_unchanged_at_beg_row (w
)
9508 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
9509 struct glyph_row
*row
;
9510 struct glyph_row
*row_found
= NULL
;
9511 int yb
= window_text_bottom_y (w
);
9513 /* Find the last row displaying unchanged text. */
9514 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9515 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
9516 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
9518 if (/* If row ends before first_changed_pos, it is unchanged,
9519 except in some case. */
9520 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
9521 /* When row ends in ZV and we write at ZV it is not
9523 && !row
->ends_at_zv_p
9524 /* When first_changed_pos is the end of a continued line,
9525 row is not unchanged because it may be no longer
9527 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
9528 && row
->continued_p
))
9531 /* Stop if last visible row. */
9532 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
9542 /* Find the first glyph row in the current matrix of W that is not
9543 affected by changes at the end of current_buffer since the last
9544 time the window was redisplayed. Return in *DELTA the number of
9545 chars by which buffer positions in unchanged text at the end of
9546 current_buffer must be adjusted. Return in *DELTA_BYTES the
9547 corresponding number of bytes. Value is null if no such row
9548 exists, i.e. all rows are affected by changes. */
9550 static struct glyph_row
*
9551 get_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
9553 int *delta
, *delta_bytes
;
9555 struct glyph_row
*row
;
9556 struct glyph_row
*row_found
= NULL
;
9558 *delta
= *delta_bytes
= 0;
9560 /* A value of window_end_pos >= end_unchanged means that the window
9561 end is in the range of changed text. If so, there is no
9562 unchanged row at the end of W's current matrix. */
9563 xassert (!NILP (w
->window_end_valid
));
9564 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
9567 /* Set row to the last row in W's current matrix displaying text. */
9568 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
9570 /* If matrix is entirely empty, no unchanged row exists. */
9571 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9573 /* The value of row is the last glyph row in the matrix having a
9574 meaningful buffer position in it. The end position of row
9575 corresponds to window_end_pos. This allows us to translate
9576 buffer positions in the current matrix to current buffer
9577 positions for characters not in changed text. */
9578 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
9579 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
9580 int last_unchanged_pos
, last_unchanged_pos_old
;
9581 struct glyph_row
*first_text_row
9582 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9585 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
9587 /* Set last_unchanged_pos to the buffer position of the last
9588 character in the buffer that has not been changed. Z is the
9589 index + 1 of the last byte in current_buffer, i.e. by
9590 subtracting end_unchanged we get the index of the last
9591 unchanged character, and we have to add BEG to get its buffer
9593 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
9594 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
9596 /* Search backward from ROW for a row displaying a line that
9597 starts at a minimum position >= last_unchanged_pos_old. */
9598 while (row
>= first_text_row
)
9600 xassert (row
->enabled_p
);
9601 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
));
9603 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
9609 xassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
9614 /* Make sure that glyph rows in the current matrix of window W
9615 reference the same glyph memory as corresponding rows in the
9616 frame's frame matrix. This function is called after scrolling W's
9617 current matrix on a terminal frame in try_window_id and
9618 try_window_reusing_current_matrix. */
9621 sync_frame_with_window_matrix_rows (w
)
9624 struct frame
*f
= XFRAME (w
->frame
);
9625 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
9627 /* Preconditions: W must be a leaf window and full-width. Its frame
9628 must have a frame matrix. */
9629 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
9630 xassert (WINDOW_FULL_WIDTH_P (w
));
9631 xassert (!FRAME_WINDOW_P (f
));
9633 /* If W is a full-width window, glyph pointers in W's current matrix
9634 have, by definition, to be the same as glyph pointers in the
9635 corresponding frame matrix. */
9636 window_row
= w
->current_matrix
->rows
;
9637 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
9638 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
9639 while (window_row
< window_row_end
)
9642 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
9643 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
9644 ++window_row
, ++frame_row
;
9649 /* Try to redisplay window W by reusing its existing display. W's
9650 current matrix must be up to date when this function is called,
9651 i.e. window_end_valid must not be nil.
9655 1 if display has been updated
9656 0 if otherwise unsuccessful
9657 -1 if redisplay with same window start is known not to succeed
9659 The following steps are performed:
9661 1. Find the last row in the current matrix of W that is not
9662 affected by changes at the start of current_buffer. If no such row
9665 2. Find the first row in W's current matrix that is not affected by
9666 changes at the end of current_buffer. Maybe there is no such row.
9668 3. Display lines beginning with the row + 1 found in step 1 to the
9669 row found in step 2 or, if step 2 didn't find a row, to the end of
9672 4. If cursor is not known to appear on the window, give up.
9674 5. If display stopped at the row found in step 2, scroll the
9675 display and current matrix as needed.
9677 6. Maybe display some lines at the end of W, if we must. This can
9678 happen under various circumstances, like a partially visible line
9679 becoming fully visible, or because newly displayed lines are displayed
9680 in smaller font sizes.
9682 7. Update W's window end information. */
9684 /* Check that window end is what we expect it to be. */
9690 struct frame
*f
= XFRAME (w
->frame
);
9691 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
9692 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
9693 struct glyph_row
*last_unchanged_at_beg_row
;
9694 struct glyph_row
*first_unchanged_at_end_row
;
9695 struct glyph_row
*row
;
9696 struct glyph_row
*bottom_row
;
9699 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
9700 struct text_pos start_pos
;
9702 int first_unchanged_at_end_vpos
= 0;
9703 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
9704 struct text_pos start
;
9706 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
9708 /* Check pre-conditions. Window end must be valid, otherwise
9709 the current matrix would not be up to date. */
9710 xassert (!NILP (w
->window_end_valid
));
9711 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
9712 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
9714 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
9715 only if buffer has really changed. The reason is that the gap is
9716 initially at Z for freshly visited files. The code below would
9717 set end_unchanged to 0 in that case. */
9718 if (MODIFF
> SAVE_MODIFF
)
9720 if (GPT
- BEG
< BEG_UNCHANGED
)
9721 BEG_UNCHANGED
= GPT
- BEG
;
9722 if (Z
- GPT
< END_UNCHANGED
)
9723 END_UNCHANGED
= Z
- GPT
;
9726 /* If window starts after a line end, and the last change is in
9727 front of that newline, then changes don't affect the display.
9728 This case happens with stealth-fontification. */
9729 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
9730 if (CHARPOS (start
) > BEGV
9731 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
9732 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
9733 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9735 /* We have to update window end positions because the buffer's
9736 size has changed. */
9738 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
9739 w
->window_end_bytepos
9740 = make_number (Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
));
9744 /* Return quickly if changes are all below what is displayed in the
9745 window, and if PT is in the window. */
9746 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
9747 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9749 /* We have to update window end positions because the buffer's
9750 size has changed. */
9752 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
9753 w
->window_end_bytepos
9754 = make_number (Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
));
9758 /* Check that window start agrees with the start of the first glyph
9759 row in its current matrix. Check this after we know the window
9760 start is not in changed text, otherwise positions would not be
9762 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9763 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
9766 /* Compute the position at which we have to start displaying new
9767 lines. Some of the lines at the top of the window might be
9768 reusable because they are not displaying changed text. Find the
9769 last row in W's current matrix not affected by changes at the
9770 start of current_buffer. Value is null if changes start in the
9771 first line of window. */
9772 last_unchanged_at_beg_row
= get_last_unchanged_at_beg_row (w
);
9773 if (last_unchanged_at_beg_row
)
9775 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
9776 start_pos
= it
.current
.pos
;
9778 /* Start displaying new lines in the desired matrix at the same
9779 vpos we would use in the current matrix, i.e. below
9780 last_unchanged_at_beg_row. */
9781 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
9783 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
9784 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
9786 xassert (it
.hpos
== 0 && it
.current_x
== 0);
9790 /* There are no reusable lines at the start of the window.
9791 Start displaying in the first line. */
9792 start_display (&it
, w
, start
);
9793 start_pos
= it
.current
.pos
;
9796 /* Find the first row that is not affected by changes at the end of
9797 the buffer. Value will be null if there is no unchanged row, in
9798 which case we must redisplay to the end of the window. delta
9799 will be set to the value by which buffer positions beginning with
9800 first_unchanged_at_end_row have to be adjusted due to text
9802 first_unchanged_at_end_row
9803 = get_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
9804 IF_DEBUG (debug_delta
= delta
);
9805 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
9807 /* Set stop_pos to the buffer position up to which we will have to
9808 display new lines. If first_unchanged_at_end_row != NULL, this
9809 is the buffer position of the start of the line displayed in that
9810 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
9811 that we don't stop at a buffer position. */
9813 if (first_unchanged_at_end_row
)
9815 xassert (last_unchanged_at_beg_row
== NULL
9816 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
9818 /* If this is a continuation line, move forward to the next one
9819 that isn't. Changes in lines above affect this line.
9820 Caution: this may move first_unchanged_at_end_row to a row
9821 not displaying text. */
9822 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
9823 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
9824 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
9825 < it
.last_visible_y
))
9826 ++first_unchanged_at_end_row
;
9828 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
9829 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
9830 >= it
.last_visible_y
))
9831 first_unchanged_at_end_row
= NULL
;
9834 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
9836 first_unchanged_at_end_vpos
9837 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
9838 xassert (stop_pos
>= Z
- END_UNCHANGED
);
9841 else if (last_unchanged_at_beg_row
== NULL
)
9847 /* Either there is no unchanged row at the end, or the one we have
9848 now displays text. This is a necessary condition for the window
9849 end pos calculation at the end of this function. */
9850 xassert (first_unchanged_at_end_row
== NULL
9851 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
9853 debug_last_unchanged_at_beg_vpos
9854 = (last_unchanged_at_beg_row
9855 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
9857 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
9859 #endif /* GLYPH_DEBUG != 0 */
9862 /* Display new lines. Set last_text_row to the last new line
9863 displayed which has text on it, i.e. might end up as being the
9864 line where the window_end_vpos is. */
9865 w
->cursor
.vpos
= -1;
9866 last_text_row
= NULL
;
9867 overlay_arrow_seen
= 0;
9868 while (it
.current_y
< it
.last_visible_y
9870 && (first_unchanged_at_end_row
== NULL
9871 || IT_CHARPOS (it
) < stop_pos
))
9873 if (display_line (&it
))
9874 last_text_row
= it
.glyph_row
- 1;
9877 if (fonts_changed_p
)
9881 /* Compute differences in buffer positions, y-positions etc. for
9882 lines reused at the bottom of the window. Compute what we can
9884 if (first_unchanged_at_end_row
9885 /* No lines reused because we displayed everything up to the
9886 bottom of the window. */
9887 && it
.current_y
< it
.last_visible_y
)
9890 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
9892 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
9893 run
.current_y
= first_unchanged_at_end_row
->y
;
9894 run
.desired_y
= run
.current_y
+ dy
;
9895 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
9899 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
9900 first_unchanged_at_end_row
= NULL
;
9902 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
9905 /* Find the cursor if not already found. We have to decide whether
9906 PT will appear on this window (it sometimes doesn't, but this is
9907 not a very frequent case.) This decision has to be made before
9908 the current matrix is altered. A value of cursor.vpos < 0 means
9909 that PT is either in one of the lines beginning at
9910 first_unchanged_at_end_row or below the window. Don't care for
9911 lines that might be displayed later at the window end; as
9912 mentioned, this is not a frequent case. */
9913 if (w
->cursor
.vpos
< 0)
9915 int last_y
= min (it
.last_visible_y
, it
.last_visible_y
+ dy
);
9917 /* Cursor in unchanged rows at the top? */
9918 if (PT
< CHARPOS (start_pos
)
9919 && last_unchanged_at_beg_row
)
9921 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9922 while (row
<= last_unchanged_at_beg_row
9923 && MATRIX_ROW_END_CHARPOS (row
) <= PT
)
9925 xassert (row
<= last_unchanged_at_beg_row
);
9926 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9929 /* Start from first_unchanged_at_end_row looking for PT. */
9930 else if (first_unchanged_at_end_row
)
9932 row
= first_unchanged_at_end_row
;
9934 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9936 if (PT
- delta
>= MATRIX_ROW_START_CHARPOS (row
)
9937 && PT
- delta
< MATRIX_ROW_END_CHARPOS (row
))
9939 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
9940 delta_bytes
, dy
, dvpos
);
9943 else if (MATRIX_ROW_BOTTOM_Y (row
) >= last_y
)
9948 /* If PT is at ZV, this is not in a line displaying text.
9950 if (w
->cursor
.vpos
< 0
9951 && PT
- delta
== MATRIX_ROW_START_CHARPOS (row
)
9952 && row
->ends_at_zv_p
)
9953 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
9954 delta_bytes
, dy
, dvpos
);
9957 /* Give up if cursor was not found. */
9958 if (w
->cursor
.vpos
< 0)
9960 clear_glyph_matrix (w
->desired_matrix
);
9965 /* Don't let the cursor end in the scroll margins. */
9967 int this_scroll_margin
, cursor_height
;
9969 this_scroll_margin
= max (0, scroll_margin
);
9970 this_scroll_margin
= min (this_scroll_margin
,
9971 XFASTINT (w
->height
) / 4);
9972 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
9973 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
9975 if ((w
->cursor
.y
< this_scroll_margin
9976 && CHARPOS (start
) > BEGV
)
9977 /* Don't take scroll margin into account at the bottom because
9978 old redisplay didn't do it either. */
9979 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
9981 w
->cursor
.vpos
= -1;
9982 clear_glyph_matrix (w
->desired_matrix
);
9987 /* Scroll the display. Do it before changing the current matrix so
9988 that xterm.c doesn't get confused about where the cursor glyph is
9994 if (FRAME_WINDOW_P (f
))
9996 rif
->update_window_begin_hook (w
);
9997 rif
->scroll_run_hook (w
, &run
);
9998 rif
->update_window_end_hook (w
, 0);
10002 /* Terminal frame. In this case, dvpos gives the number of
10003 lines to scroll by; dvpos < 0 means scroll up. */
10004 int first_unchanged_at_end_vpos
10005 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
10006 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
10007 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
10009 /* Perform the operation on the screen. */
10012 /* Scroll last_unchanged_at_beg_row to the end of the
10013 window down dvpos lines. */
10014 set_terminal_window (end
);
10016 /* On dumb terminals delete dvpos lines at the end
10017 before inserting dvpos empty lines. */
10018 if (!scroll_region_ok
)
10019 ins_del_lines (end
- dvpos
, -dvpos
);
10021 /* Insert dvpos empty lines in front of
10022 last_unchanged_at_beg_row. */
10023 ins_del_lines (from
, dvpos
);
10025 else if (dvpos
< 0)
10027 /* Scroll up last_unchanged_at_beg_vpos to the end of
10028 the window to last_unchanged_at_beg_vpos - |dvpos|. */
10029 set_terminal_window (end
);
10031 /* Delete dvpos lines in front of
10032 last_unchanged_at_beg_vpos. ins_del_lines will set
10033 the cursor to the given vpos and emit |dvpos| delete
10035 ins_del_lines (from
+ dvpos
, dvpos
);
10037 /* On a dumb terminal insert dvpos empty lines at the
10039 if (!scroll_region_ok
)
10040 ins_del_lines (end
+ dvpos
, -dvpos
);
10043 set_terminal_window (0);
10049 /* Shift reused rows of the current matrix to the right position.
10050 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
10052 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10053 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
10056 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
10057 bottom_vpos
, dvpos
);
10058 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
10061 else if (dvpos
> 0)
10063 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
10064 bottom_vpos
, dvpos
);
10065 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
10066 first_unchanged_at_end_vpos
+ dvpos
, 0);
10069 /* For frame-based redisplay, make sure that current frame and window
10070 matrix are in sync with respect to glyph memory. */
10071 if (!FRAME_WINDOW_P (f
))
10072 sync_frame_with_window_matrix_rows (w
);
10074 /* Adjust buffer positions in reused rows. */
10076 increment_glyph_matrix_buffer_positions (current_matrix
,
10077 first_unchanged_at_end_vpos
+ dvpos
,
10078 bottom_vpos
, delta
, delta_bytes
);
10080 /* Adjust Y positions. */
10082 shift_glyph_matrix (w
, current_matrix
,
10083 first_unchanged_at_end_vpos
+ dvpos
,
10086 if (first_unchanged_at_end_row
)
10087 first_unchanged_at_end_row
+= dvpos
;
10089 /* If scrolling up, there may be some lines to display at the end of
10091 last_text_row_at_end
= NULL
;
10094 /* Set last_row to the glyph row in the current matrix where the
10095 window end line is found. It has been moved up or down in
10096 the matrix by dvpos. */
10097 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
10098 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
10100 /* If last_row is the window end line, it should display text. */
10101 xassert (last_row
->displays_text_p
);
10103 /* If window end line was partially visible before, begin
10104 displaying at that line. Otherwise begin displaying with the
10105 line following it. */
10106 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
10108 init_to_row_start (&it
, w
, last_row
);
10109 it
.vpos
= last_vpos
;
10110 it
.current_y
= last_row
->y
;
10114 init_to_row_end (&it
, w
, last_row
);
10115 it
.vpos
= 1 + last_vpos
;
10116 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
10120 /* We may start in a continuation line. If so, we have to get
10121 the right continuation_lines_width and current_x. */
10122 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
10123 it
.hpos
= it
.current_x
= 0;
10125 /* Display the rest of the lines at the window end. */
10126 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10127 while (it
.current_y
< it
.last_visible_y
10128 && !fonts_changed_p
)
10130 /* Is it always sure that the display agrees with lines in
10131 the current matrix? I don't think so, so we mark rows
10132 displayed invalid in the current matrix by setting their
10133 enabled_p flag to zero. */
10134 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
10135 if (display_line (&it
))
10136 last_text_row_at_end
= it
.glyph_row
- 1;
10140 /* Update window_end_pos and window_end_vpos. */
10141 if (first_unchanged_at_end_row
10142 && first_unchanged_at_end_row
->y
< it
.last_visible_y
10143 && !last_text_row_at_end
)
10145 /* Window end line if one of the preserved rows from the current
10146 matrix. Set row to the last row displaying text in current
10147 matrix starting at first_unchanged_at_end_row, after
10149 xassert (first_unchanged_at_end_row
->displays_text_p
);
10150 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
10151 first_unchanged_at_end_row
);
10152 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
10154 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
10155 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10156 XSETFASTINT (w
->window_end_vpos
,
10157 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
10159 else if (last_text_row_at_end
)
10161 XSETFASTINT (w
->window_end_pos
,
10162 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
10163 w
->window_end_bytepos
10164 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
10165 XSETFASTINT (w
->window_end_vpos
,
10166 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
10168 else if (last_text_row
)
10170 /* We have displayed either to the end of the window or at the
10171 end of the window, i.e. the last row with text is to be found
10172 in the desired matrix. */
10173 XSETFASTINT (w
->window_end_pos
,
10174 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10175 w
->window_end_bytepos
10176 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10177 XSETFASTINT (w
->window_end_vpos
,
10178 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
10180 else if (first_unchanged_at_end_row
== NULL
10181 && last_text_row
== NULL
10182 && last_text_row_at_end
== NULL
)
10184 /* Displayed to end of window, but no line containing text was
10185 displayed. Lines were deleted at the end of the window. */
10187 int top_line_p
= WINDOW_WANTS_TOP_LINE_P (w
) ? 1 : 0;
10189 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
10190 if ((w
->desired_matrix
->rows
[vpos
+ top_line_p
].enabled_p
10191 && w
->desired_matrix
->rows
[vpos
+ top_line_p
].displays_text_p
)
10192 || (!w
->desired_matrix
->rows
[vpos
+ top_line_p
].enabled_p
10193 && w
->current_matrix
->rows
[vpos
+ top_line_p
].displays_text_p
))
10196 w
->window_end_vpos
= make_number (vpos
);
10201 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
10202 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
10204 /* Record that display has not been completed. */
10205 w
->window_end_valid
= Qnil
;
10206 w
->desired_matrix
->no_scrolling_p
= 1;
10212 /***********************************************************************
10213 More debugging support
10214 ***********************************************************************/
10218 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
10219 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
10222 /* Dump the contents of glyph matrix MATRIX on stderr. If
10223 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
10226 dump_glyph_matrix (matrix
, with_glyphs_p
)
10227 struct glyph_matrix
*matrix
;
10231 for (i
= 0; i
< matrix
->nrows
; ++i
)
10232 dump_glyph_row (matrix
, i
, with_glyphs_p
);
10236 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
10237 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
10240 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
10241 struct glyph_matrix
*matrix
;
10242 int vpos
, with_glyphs_p
;
10244 struct glyph_row
*row
;
10246 if (vpos
< 0 || vpos
>= matrix
->nrows
)
10249 row
= MATRIX_ROW (matrix
, vpos
);
10251 fprintf (stderr
, "Row Start End Used oEI><O\\CTZF X Y W\n");
10252 fprintf (stderr
, "=============================================\n");
10254 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",
10255 row
- matrix
->rows
,
10256 MATRIX_ROW_START_CHARPOS (row
),
10257 MATRIX_ROW_END_CHARPOS (row
),
10258 row
->used
[TEXT_AREA
],
10259 row
->contains_overlapping_glyphs_p
,
10262 row
->truncated_on_left_p
,
10263 row
->truncated_on_right_p
,
10264 row
->overlay_arrow_p
,
10266 MATRIX_ROW_CONTINUATION_LINE_P (row
),
10267 row
->displays_text_p
,
10273 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
10274 row
->end
.overlay_string_index
);
10275 fprintf (stderr
, "%9d %5d\n",
10276 CHARPOS (row
->start
.string_pos
),
10277 CHARPOS (row
->end
.string_pos
));
10278 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
10279 row
->end
.dpvec_index
);
10283 struct glyph
*glyph
, *glyph_end
;
10284 int prev_had_glyphs_p
;
10286 glyph
= row
->glyphs
[TEXT_AREA
];
10287 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
10289 /* Glyph for a line end in text. */
10290 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
10293 if (glyph
< glyph_end
)
10295 fprintf (stderr
, " Glyph Type Pos W Code C Face LR\n");
10296 prev_had_glyphs_p
= 1;
10299 prev_had_glyphs_p
= 0;
10301 while (glyph
< glyph_end
)
10303 if (glyph
->type
== CHAR_GLYPH
)
10306 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10307 glyph
- row
->glyphs
[TEXT_AREA
],
10310 glyph
->pixel_width
,
10312 (glyph
->u
.ch
.code
< 0x80 && glyph
->u
.ch
.code
>= ' '
10315 glyph
->u
.ch
.face_id
,
10316 glyph
->left_box_line_p
,
10317 glyph
->right_box_line_p
);
10319 else if (glyph
->type
== STRETCH_GLYPH
)
10322 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10323 glyph
- row
->glyphs
[TEXT_AREA
],
10326 glyph
->pixel_width
,
10329 glyph
->u
.stretch
.face_id
,
10330 glyph
->left_box_line_p
,
10331 glyph
->right_box_line_p
);
10333 else if (glyph
->type
== IMAGE_GLYPH
)
10336 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10337 glyph
- row
->glyphs
[TEXT_AREA
],
10340 glyph
->pixel_width
,
10343 glyph
->u
.img
.face_id
,
10344 glyph
->left_box_line_p
,
10345 glyph
->right_box_line_p
);
10353 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
10354 Sdump_glyph_matrix
, 0, 1, "p",
10355 "Dump the current matrix of the selected window to stderr.\n\
10356 Shows contents of glyph row structures. With non-nil optional\n\
10357 parameter WITH-GLYPHS-P, dump glyphs as well.")
10360 struct window
*w
= XWINDOW (selected_window
);
10361 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10363 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
10364 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
10365 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
10366 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
10367 fprintf (stderr
, "=============================================\n");
10368 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
10373 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
10374 "Dump glyph row ROW to stderr.")
10378 CHECK_NUMBER (row
, 0);
10379 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
10384 DEFUN ("dump-toolbar-row", Fdump_toolbar_row
, Sdump_toolbar_row
,
10388 struct glyph_matrix
*m
= (XWINDOW (selected_frame
->toolbar_window
)
10390 dump_glyph_row (m
, 0, 1);
10395 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
10396 Strace_redisplay_toggle
, 0, 0, "",
10397 "Toggle tracing of redisplay.")
10400 trace_redisplay_p
= !trace_redisplay_p
;
10405 #endif /* GLYPH_DEBUG */
10409 /***********************************************************************
10410 Building Desired Matrix Rows
10411 ***********************************************************************/
10413 /* Return a temporary glyph row holding the glyphs of an overlay
10414 arrow. Only used for non-window-redisplay windows. */
10416 static struct glyph_row
*
10417 get_overlay_arrow_glyph_row (w
)
10420 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10421 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10422 struct buffer
*old
= current_buffer
;
10423 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
10424 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
10425 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
10429 int n_glyphs_before
;
10431 set_buffer_temp (buffer
);
10432 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
10433 it
.glyph_row
->used
[TEXT_AREA
] = 0;
10434 SET_TEXT_POS (it
.position
, 0, 0);
10436 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
10438 while (p
< arrow_end
)
10440 Lisp_Object face
, ilisp
;
10442 /* Get the next character. */
10444 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
10446 it
.c
= *p
, it
.len
= 1;
10449 /* Get its face. */
10450 XSETFASTINT (ilisp
, p
- arrow_string
);
10451 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
10452 it
.face_id
= compute_char_face (f
, it
.c
, face
);
10454 /* Compute its width, get its glyphs. */
10455 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
10456 SET_TEXT_POS (it
.position
, -1, -1);
10457 PRODUCE_GLYPHS (&it
);
10459 /* If this character doesn't fit any more in the line, we have
10460 to remove some glyphs. */
10461 if (it
.current_x
> it
.last_visible_x
)
10463 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
10468 set_buffer_temp (old
);
10469 return it
.glyph_row
;
10473 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
10474 glyphs are only inserted for terminal frames since we can't really
10475 win with truncation glyphs when partially visible glyphs are
10476 involved. Which glyphs to insert is determined by
10477 produce_special_glyphs. */
10480 insert_left_trunc_glyphs (it
)
10483 struct it truncate_it
;
10484 struct glyph
*from
, *end
, *to
, *toend
;
10486 xassert (!FRAME_WINDOW_P (it
->f
));
10488 /* Get the truncation glyphs. */
10490 truncate_it
.charset
= -1;
10491 truncate_it
.current_x
= 0;
10492 truncate_it
.face_id
= DEFAULT_FACE_ID
;
10493 truncate_it
.glyph_row
= &scratch_glyph_row
;
10494 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
10495 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
10496 truncate_it
.object
= 0;
10497 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
10499 /* Overwrite glyphs from IT with truncation glyphs. */
10500 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
10501 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
10502 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
10503 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
10508 /* There may be padding glyphs left over. Remove them. */
10510 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
10512 while (from
< toend
)
10515 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
10519 /* Compute the pixel height and width of IT->glyph_row.
10521 Most of the time, ascent and height of a display line will be equal
10522 to the max_ascent and max_height values of the display iterator
10523 structure. This is not the case if
10525 1. We hit ZV without displaying anything. In this case, max_ascent
10526 and max_height will be zero.
10528 2. We have some glyphs that don't contribute to the line height.
10529 (The glyph row flag contributes_to_line_height_p is for future
10530 pixmap extensions).
10532 The first case is easily covered by using default values because in
10533 these cases, the line height does not really matter, except that it
10534 must not be zero. */
10537 compute_line_metrics (it
)
10540 struct glyph_row
*row
= it
->glyph_row
;
10543 if (FRAME_WINDOW_P (it
->f
))
10545 int i
, top_line_height
;
10547 /* The line may consist of one space only, that was added to
10548 place the cursor on it. If so, the row's height hasn't been
10550 if (row
->height
== 0)
10552 if (it
->max_ascent
+ it
->max_descent
== 0)
10553 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
10554 row
->ascent
= it
->max_ascent
;
10555 row
->height
= it
->max_ascent
+ it
->max_descent
;
10556 row
->phys_ascent
= it
->max_phys_ascent
;
10557 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
10560 /* Compute the width of this line. */
10561 row
->pixel_width
= row
->x
;
10562 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
10563 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10565 xassert (row
->pixel_width
>= 0);
10566 xassert (row
->ascent
>= 0 && row
->height
> 0);
10568 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
10569 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
10571 /* If first line's physical ascent is larger than its logical
10572 ascent, use the physical ascent, and make the row taller.
10573 This makes accented characters fully visible. */
10574 if (row
== it
->w
->desired_matrix
->rows
10575 && row
->phys_ascent
> row
->ascent
)
10577 row
->height
+= row
->phys_ascent
- row
->ascent
;
10578 row
->ascent
= row
->phys_ascent
;
10581 /* Compute how much of the line is visible. */
10582 row
->visible_height
= row
->height
;
10584 top_line_height
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (it
->w
);
10585 if (row
->y
< top_line_height
)
10586 row
->visible_height
-= top_line_height
- row
->y
;
10589 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
10590 if (row
->y
+ row
->height
> max_y
)
10591 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10596 row
->pixel_width
= row
->used
[TEXT_AREA
];
10597 row
->ascent
= row
->phys_ascent
= 0;
10598 row
->height
= row
->phys_height
= row
->visible_height
= 1;
10601 /* Compute a hash code for this row. */
10603 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
10604 for (i
= 0; i
< row
->used
[area
]; ++i
)
10605 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
10606 + row
->glyphs
[area
][i
].u
.val
10607 + (row
->glyphs
[area
][i
].type
<< 2));
10609 it
->max_ascent
= it
->max_descent
= 0;
10610 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
10614 /* Append one space to the glyph row of iterator IT if doing a
10615 window-based redisplay. DEFAULT_FACE_P non-zero means let the
10616 space have the default face, otherwise let it have the same face as
10619 This function is called to make sure that there is always one glyph
10620 at the end of a glyph row that the cursor can be set on under
10621 window-systems. (If there weren't such a glyph we would not know
10622 how wide and tall a box cursor should be displayed).
10624 At the same time this space let's a nicely handle clearing to the
10625 end of the line if the row ends in italic text. */
10628 append_space (it
, default_face_p
)
10630 int default_face_p
;
10632 if (FRAME_WINDOW_P (it
->f
))
10634 int n
= it
->glyph_row
->used
[TEXT_AREA
];
10636 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
10637 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
10639 /* Save some values that must not be changed. */
10640 int saved_x
= it
->current_x
;
10641 struct text_pos saved_pos
;
10642 int saved_what
= it
->what
;
10643 int saved_face_id
= it
->face_id
;
10644 int saved_charset
= it
->charset
;
10645 Lisp_Object saved_object
;
10647 saved_object
= it
->object
;
10648 saved_pos
= it
->position
;
10650 it
->what
= IT_CHARACTER
;
10651 bzero (&it
->position
, sizeof it
->position
);
10655 it
->charset
= CHARSET_ASCII
;
10657 if (default_face_p
)
10658 it
->face_id
= DEFAULT_FACE_ID
;
10659 if (it
->multibyte_p
)
10660 it
->face_id
= FACE_FOR_CHARSET (it
->f
, it
->face_id
, CHARSET_ASCII
);
10662 it
->face_id
= FACE_FOR_CHARSET (it
->f
, it
->face_id
, -1);
10664 PRODUCE_GLYPHS (it
);
10666 it
->current_x
= saved_x
;
10667 it
->object
= saved_object
;
10668 it
->position
= saved_pos
;
10669 it
->what
= saved_what
;
10670 it
->face_id
= saved_face_id
;
10671 it
->charset
= saved_charset
;
10677 /* Extend the face of the last glyph in the text area of IT->glyph_row
10678 to the end of the display line. Called from display_line.
10679 If the glyph row is empty, add a space glyph to it so that we
10680 know the face to draw. Set the glyph row flag fill_line_p. */
10683 extend_face_to_end_of_line (it
)
10687 struct frame
*f
= it
->f
;
10689 /* If line is already filled, do nothing. */
10690 if (it
->current_x
>= it
->last_visible_x
)
10693 /* Face extension extends the background and box of IT->face_id
10694 to the end of the line. If the background equals the background
10695 of the frame, we haven't to do anything. */
10696 face
= FACE_FROM_ID (f
, it
->face_id
);
10697 if (FRAME_WINDOW_P (f
)
10698 && face
->box
== FACE_NO_BOX
10699 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
10703 /* Set the glyph row flag indicating that the face of the last glyph
10704 in the text area has to be drawn to the end of the text area. */
10705 it
->glyph_row
->fill_line_p
= 1;
10707 /* If current charset of IT is not ASCII, make sure we have the
10708 ASCII face. This will be automatically undone the next time
10709 get_next_display_element returns a character from a different
10710 charset. Note that the charset will always be ASCII in unibyte
10712 if (it
->charset
!= CHARSET_ASCII
)
10714 it
->charset
= CHARSET_ASCII
;
10715 it
->face_id
= FACE_FOR_CHARSET (f
, it
->face_id
, CHARSET_ASCII
);
10718 if (FRAME_WINDOW_P (f
))
10720 /* If the row is empty, add a space with the current face of IT,
10721 so that we know which face to draw. */
10722 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
10724 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
10725 it
->glyph_row
->glyphs
[TEXT_AREA
][0].u
.ch
.face_id
= it
->face_id
;
10726 it
->glyph_row
->used
[TEXT_AREA
] = 1;
10731 /* Save some values that must not be changed. */
10732 int saved_x
= it
->current_x
;
10733 struct text_pos saved_pos
;
10734 Lisp_Object saved_object
;
10735 int saved_what
= it
->what
;
10737 saved_object
= it
->object
;
10738 saved_pos
= it
->position
;
10740 it
->what
= IT_CHARACTER
;
10741 bzero (&it
->position
, sizeof it
->position
);
10746 PRODUCE_GLYPHS (it
);
10748 while (it
->current_x
<= it
->last_visible_x
)
10749 PRODUCE_GLYPHS (it
);
10751 /* Don't count these blanks really. It would let us insert a left
10752 truncation glyph below and make us set the cursor on them, maybe. */
10753 it
->current_x
= saved_x
;
10754 it
->object
= saved_object
;
10755 it
->position
= saved_pos
;
10756 it
->what
= saved_what
;
10761 /* Value is non-zero if text starting at CHARPOS in current_buffer is
10762 trailing whitespace. */
10765 trailing_whitespace_p (charpos
)
10768 int bytepos
= CHAR_TO_BYTE (charpos
);
10771 while (bytepos
< ZV_BYTE
10772 && (c
= FETCH_CHAR (bytepos
),
10773 c
== ' ' || c
== '\t'))
10776 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
10778 if (bytepos
!= PT_BYTE
)
10785 /* Highlight trailing whitespace, if any, in ROW. */
10788 highlight_trailing_whitespace (f
, row
)
10790 struct glyph_row
*row
;
10792 int used
= row
->used
[TEXT_AREA
];
10796 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
10797 struct glyph
*glyph
= start
+ used
- 1;
10799 /* Skip over the space glyph inserted to display the
10800 cursor at the end of a line. */
10801 if (glyph
->type
== CHAR_GLYPH
10802 && glyph
->u
.ch
.code
== ' '
10803 && glyph
->object
== 0)
10806 /* If last glyph is a space or stretch, and it's trailing
10807 whitespace, set the face of all trailing whitespace glyphs in
10808 IT->glyph_row to `trailing-whitespace'. */
10810 && BUFFERP (glyph
->object
)
10811 && (glyph
->type
== STRETCH_GLYPH
10812 || (glyph
->type
== CHAR_GLYPH
10813 && glyph
->u
.ch
.code
== ' '))
10814 && trailing_whitespace_p (glyph
->charpos
))
10816 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
,
10819 while (glyph
>= start
10820 && BUFFERP (glyph
->object
)
10821 && (glyph
->type
== STRETCH_GLYPH
10822 || (glyph
->type
== CHAR_GLYPH
10823 && glyph
->u
.ch
.code
== ' ')))
10825 if (glyph
->type
== STRETCH_GLYPH
)
10826 glyph
->u
.stretch
.face_id
= face_id
;
10828 glyph
->u
.ch
.face_id
= face_id
;
10836 /* Construct the glyph row IT->glyph_row in the desired matrix of
10837 IT->w from text at the current position of IT. See dispextern.h
10838 for an overview of struct it. Value is non-zero if
10839 IT->glyph_row displays text, as opposed to a line displaying ZV
10846 struct glyph_row
*row
= it
->glyph_row
;
10848 /* We always start displaying at hpos zero even if hscrolled. */
10849 xassert (it
->hpos
== 0 && it
->current_x
== 0);
10851 /* We must not display in a row that's not a text row. */
10852 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
10853 < it
->w
->desired_matrix
->nrows
);
10855 /* Is IT->w showing the region? */
10856 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
10858 /* Clear the result glyph row and enable it. */
10859 prepare_desired_row (row
);
10861 row
->y
= it
->current_y
;
10862 row
->start
= it
->current
;
10863 row
->continuation_lines_width
= it
->continuation_lines_width
;
10864 row
->displays_text_p
= 1;
10866 /* Arrange the overlays nicely for our purposes. Usually, we call
10867 display_line on only one line at a time, in which case this
10868 can't really hurt too much, or we call it on lines which appear
10869 one after another in the buffer, in which case all calls to
10870 recenter_overlay_lists but the first will be pretty cheap. */
10871 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
10873 /* Move over display elements that are not visible because we are
10874 hscrolled. This may stop at an x-position < IT->first_visible_x
10875 if the first glyph is partially visible or if we hit a line end. */
10876 if (it
->current_x
< it
->first_visible_x
)
10877 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
10878 MOVE_TO_POS
| MOVE_TO_X
);
10880 /* Get the initial row height. This is either the height of the
10881 text hscrolled, if there is any, or zero. */
10882 row
->ascent
= it
->max_ascent
;
10883 row
->height
= it
->max_ascent
+ it
->max_descent
;
10884 row
->phys_ascent
= it
->max_phys_ascent
;
10885 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
10887 /* Loop generating characters. The loop is left with IT on the next
10888 character to display. */
10891 int n_glyphs_before
, hpos_before
, x_before
;
10894 /* Retrieve the next thing to display. Value is zero if end of
10896 if (!get_next_display_element (it
))
10898 /* Maybe add a space at the end of this line that is used to
10899 display the cursor there under X. */
10900 append_space (it
, 1);
10902 /* The position -1 below indicates a blank line not
10903 corresponding to any text, as opposed to an empty line
10904 corresponding to a line end. */
10905 if (row
->used
[TEXT_AREA
] <= 1)
10907 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
10908 row
->displays_text_p
= 0;
10910 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
10911 row
->indicate_empty_line_p
= 1;
10914 it
->continuation_lines_width
= 0;
10915 row
->ends_at_zv_p
= 1;
10919 /* Now, get the metrics of what we want to display. This also
10920 generates glyphs in `row' (which is IT->glyph_row). */
10921 n_glyphs_before
= row
->used
[TEXT_AREA
];
10923 PRODUCE_GLYPHS (it
);
10925 /* If this display element was in marginal areas, continue with
10927 if (it
->area
!= TEXT_AREA
)
10929 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
10930 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
10931 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
10932 row
->phys_height
= max (row
->phys_height
,
10933 it
->max_phys_ascent
+ it
->max_phys_descent
);
10934 set_iterator_to_next (it
);
10938 /* Does the display element fit on the line? If we truncate
10939 lines, we should draw past the right edge of the window. If
10940 we don't truncate, we want to stop so that we can display the
10941 continuation glyph before the right margin. If lines are
10942 continued, there are two possible strategies for characters
10943 resulting in more than 1 glyph (e.g. tabs): Display as many
10944 glyphs as possible in this line and leave the rest for the
10945 continuation line, or display the whole element in the next
10946 line. Original redisplay did the former, so we do it also. */
10947 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10948 hpos_before
= it
->hpos
;
10952 && it
->current_x
< it
->last_visible_x
)
10955 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
10956 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
10957 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
10958 row
->phys_height
= max (row
->phys_height
,
10959 it
->max_phys_ascent
+ it
->max_phys_descent
);
10960 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
10961 row
->x
= x
- it
->first_visible_x
;
10966 struct glyph
*glyph
;
10968 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
10970 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10971 new_x
= x
+ glyph
->pixel_width
;
10973 if (/* Lines are continued. */
10974 !it
->truncate_lines_p
10975 && (/* Glyph doesn't fit on the line. */
10976 new_x
> it
->last_visible_x
10977 /* Or it fits exactly on a window system frame. */
10978 || (new_x
== it
->last_visible_x
10979 && FRAME_WINDOW_P (it
->f
))))
10981 /* End of a continued line. */
10984 || (new_x
== it
->last_visible_x
10985 && FRAME_WINDOW_P (it
->f
)))
10987 /* Current glyph fits exactly on the line. We
10988 must continue the line because we can't draw
10989 the cursor after the glyph. */
10990 row
->continued_p
= 1;
10991 it
->current_x
= new_x
;
10992 it
->continuation_lines_width
+= new_x
;
10994 if (i
== nglyphs
- 1)
10995 set_iterator_to_next (it
);
10999 /* Display element draws past the right edge of
11000 the window. Restore positions to values
11001 before the element. The next line starts
11002 with current_x before the glyph that could
11003 not be displayed, so that TAB works right. */
11004 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11006 /* Display continuation glyphs. */
11007 if (!FRAME_WINDOW_P (it
->f
))
11008 produce_special_glyphs (it
, IT_CONTINUATION
);
11009 row
->continued_p
= 1;
11012 it
->continuation_lines_width
+= x
;
11016 else if (new_x
> it
->first_visible_x
)
11018 /* Increment number of glyphs actually displayed. */
11021 if (x
< it
->first_visible_x
)
11022 /* Glyph is partially visible, i.e. row starts at
11023 negative X position. */
11024 row
->x
= x
- it
->first_visible_x
;
11028 /* Glyph is completely off the left margin of the
11029 window. This should not happen because of the
11030 move_it_in_display_line at the start of
11036 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11037 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11038 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11039 row
->phys_height
= max (row
->phys_height
,
11040 it
->max_phys_ascent
+ it
->max_phys_descent
);
11042 /* End of this display line if row is continued. */
11043 if (row
->continued_p
)
11047 /* Is this a line end? If yes, we're also done, after making
11048 sure that a non-default face is extended up to the right
11049 margin of the window. */
11050 if (ITERATOR_AT_END_OF_LINE_P (it
))
11052 int used_before
= row
->used
[TEXT_AREA
];
11054 /* Add a space at the end of the line that is used to
11055 display the cursor there. */
11056 append_space (it
, 0);
11058 /* Extend the face to the end of the line. */
11059 extend_face_to_end_of_line (it
);
11061 /* Make sure we have the position. */
11062 if (used_before
== 0)
11063 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
11065 /* Consume the line end. This skips over invisible lines. */
11066 set_iterator_to_next (it
);
11067 it
->continuation_lines_width
= 0;
11071 /* Proceed with next display element. Note that this skips
11072 over lines invisible because of selective display. */
11073 set_iterator_to_next (it
);
11075 /* If we truncate lines, we are done when the last displayed
11076 glyphs reach past the right margin of the window. */
11077 if (it
->truncate_lines_p
11078 && (FRAME_WINDOW_P (it
->f
)
11079 ? (it
->current_x
>= it
->last_visible_x
)
11080 : (it
->current_x
> it
->last_visible_x
)))
11082 /* Maybe add truncation glyphs. */
11083 if (!FRAME_WINDOW_P (it
->f
))
11085 --it
->glyph_row
->used
[TEXT_AREA
];
11086 produce_special_glyphs (it
, IT_TRUNCATION
);
11089 row
->truncated_on_right_p
= 1;
11090 it
->continuation_lines_width
= 0;
11091 reseat_at_next_visible_line_start (it
, 0);
11092 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
11093 it
->hpos
= hpos_before
;
11094 it
->current_x
= x_before
;
11099 /* If line is not empty and hscrolled, maybe insert truncation glyphs
11100 at the left window margin. */
11101 if (it
->first_visible_x
11102 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
11104 if (!FRAME_WINDOW_P (it
->f
))
11105 insert_left_trunc_glyphs (it
);
11106 row
->truncated_on_left_p
= 1;
11109 /* If the start of this line is the overlay arrow-position, then
11110 mark this glyph row as the one containing the overlay arrow.
11111 This is clearly a mess with variable size fonts. It would be
11112 better to let it be displayed like cursors under X. */
11113 if (MARKERP (Voverlay_arrow_position
)
11114 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
11115 && (MATRIX_ROW_START_CHARPOS (row
)
11116 == marker_position (Voverlay_arrow_position
))
11117 && STRINGP (Voverlay_arrow_string
)
11118 && ! overlay_arrow_seen
)
11120 /* Overlay arrow in window redisplay is a bitmap. */
11121 if (!FRAME_WINDOW_P (it
->f
))
11123 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
11124 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
11125 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
11126 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
11127 struct glyph
*p2
, *end
;
11129 /* Copy the arrow glyphs. */
11130 while (glyph
< arrow_end
)
11133 /* Throw away padding glyphs. */
11135 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
11136 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
11142 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
11146 overlay_arrow_seen
= 1;
11147 row
->overlay_arrow_p
= 1;
11150 /* Compute pixel dimensions of this line. */
11151 compute_line_metrics (it
);
11153 /* Remember the position at which this line ends. */
11154 row
->end
= it
->current
;
11156 /* Maybe set the cursor. If you change this, it's probably a good
11157 idea to also change the code in redisplay_window for cursor
11158 movement in an unchanged window. */
11159 if (it
->w
->cursor
.vpos
< 0
11160 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
11161 && MATRIX_ROW_END_CHARPOS (row
) >= PT
11162 && !(MATRIX_ROW_END_CHARPOS (row
) == PT
11163 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11164 || !row
->ends_at_zv_p
)))
11165 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
11167 /* Highlight trailing whitespace. */
11168 if (!NILP (Vshow_trailing_whitespace
))
11169 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
11171 /* Prepare for the next line. This line starts horizontally at (X
11172 HPOS) = (0 0). Vertical positions are incremented. As a
11173 convenience for the caller, IT->glyph_row is set to the next
11175 it
->current_x
= it
->hpos
= 0;
11176 it
->current_y
+= row
->height
;
11179 return row
->displays_text_p
;
11184 /***********************************************************************
11186 ***********************************************************************/
11188 /* Redisplay the menu bar in the frame for window W.
11190 The menu bar of X frames that don't have X toolkit support is
11191 displayed in a special window W->frame->menu_bar_window.
11193 The menu bar of terminal frames is treated specially as far as
11194 glyph matrices are concerned. Menu bar lines are not part of
11195 windows, so the update is done directly on the frame matrix rows
11196 for the menu bar. */
11199 display_menu_bar (w
)
11202 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11207 /* Don't do all this for graphical frames. */
11209 if (!NILP (Vwindow_system
))
11212 #ifdef USE_X_TOOLKIT
11217 #ifdef USE_X_TOOLKIT
11218 xassert (!FRAME_WINDOW_P (f
));
11219 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MODE_LINE_FACE_ID
);
11220 it
.first_visible_x
= 0;
11221 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11222 #else /* not USE_X_TOOLKIT */
11223 if (FRAME_WINDOW_P (f
))
11225 /* Menu bar lines are displayed in the desired matrix of the
11226 dummy window menu_bar_window. */
11227 struct window
*menu_w
;
11228 xassert (WINDOWP (f
->menu_bar_window
));
11229 menu_w
= XWINDOW (f
->menu_bar_window
);
11230 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
11231 MODE_LINE_FACE_ID
);
11232 it
.first_visible_x
= 0;
11233 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11237 /* This is a TTY frame, i.e. character hpos/vpos are used as
11239 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
11240 MODE_LINE_FACE_ID
);
11241 it
.first_visible_x
= 0;
11242 it
.last_visible_x
= FRAME_WIDTH (f
);
11244 #endif /* not USE_X_TOOLKIT */
11246 /* Clear all rows of the menu bar. */
11247 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
11249 struct glyph_row
*row
= it
.glyph_row
+ i
;
11250 clear_glyph_row (row
);
11251 row
->enabled_p
= 1;
11252 row
->full_width_p
= 1;
11255 /* Make the first line of the menu bar appear in reverse video. */
11256 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11258 /* Display all items of the menu bar. */
11259 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
11260 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
11262 Lisp_Object string
;
11264 /* Stop at nil string. */
11265 string
= XVECTOR (items
)->contents
[i
+ 1];
11269 /* Remember where item was displayed. */
11270 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
11272 /* Display the item, pad with one space. */
11273 if (it
.current_x
< it
.last_visible_x
)
11274 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
11275 XSTRING (string
)->size
+ 1, 0, 0, -1);
11278 /* Fill out the line with spaces. */
11279 if (it
.current_x
< it
.last_visible_x
)
11280 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
11282 /* Compute the total height of the lines. */
11283 compute_line_metrics (&it
);
11288 /***********************************************************************
11290 ***********************************************************************/
11292 /* Display the mode and/or top line of window W. */
11295 display_mode_lines (w
)
11298 /* These will be set while the mode line specs are processed. */
11299 line_number_displayed
= 0;
11300 w
->column_number_displayed
= Qnil
;
11302 if (WINDOW_WANTS_MODELINE_P (w
))
11303 display_mode_line (w
, MODE_LINE_FACE_ID
, current_buffer
->mode_line_format
);
11305 if (WINDOW_WANTS_TOP_LINE_P (w
))
11306 display_mode_line (w
, TOP_LINE_FACE_ID
, current_buffer
->top_line_format
);
11310 /* Display mode or top line of window W. FACE_ID specifies which line
11311 to display; it is either MODE_LINE_FACE_ID or TOP_LINE_FACE_ID.
11312 FORMAT is the mode line format to display. */
11315 display_mode_line (w
, face_id
, format
)
11317 enum face_id face_id
;
11318 Lisp_Object format
;
11323 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
11324 prepare_desired_row (it
.glyph_row
);
11326 /* Temporarily make frame's keyboard the current kboard so that
11327 kboard-local variables in the mode_line_format will get the right
11329 push_frame_kboard (it
.f
);
11330 display_mode_element (&it
, 0, 0, 0, format
);
11331 pop_frame_kboard ();
11333 /* Fill up with spaces. */
11334 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
11336 compute_line_metrics (&it
);
11337 it
.glyph_row
->full_width_p
= 1;
11338 it
.glyph_row
->mode_line_p
= 1;
11339 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11340 it
.glyph_row
->continued_p
= 0;
11341 it
.glyph_row
->truncated_on_left_p
= 0;
11342 it
.glyph_row
->truncated_on_right_p
= 0;
11344 /* Make a 3D mode-line have a shadow at its right end. */
11345 face
= FACE_FROM_ID (it
.f
, face_id
);
11346 extend_face_to_end_of_line (&it
);
11347 if (face
->box
!= FACE_NO_BOX
)
11349 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
11350 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
11351 last
->right_box_line_p
= 1;
11356 /* Contribute ELT to the mode line for window IT->w. How it
11357 translates into text depends on its data type.
11359 IT describes the display environment in which we display, as usual.
11361 DEPTH is the depth in recursion. It is used to prevent
11362 infinite recursion here.
11364 FIELD_WIDTH is the number of characters the display of ELT should
11365 occupy in the mode line, and PRECISION is the maximum number of
11366 characters to display from ELT's representation. See
11367 display_string for details. *
11369 Returns the hpos of the end of the text generated by ELT. */
11372 display_mode_element (it
, depth
, field_width
, precision
, elt
)
11375 int field_width
, precision
;
11378 int n
= 0, field
, prec
;
11386 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
11390 /* A string: output it and check for %-constructs within it. */
11392 unsigned char *this = XSTRING (elt
)->data
;
11393 unsigned char *lisp_string
= this;
11395 while ((precision
<= 0 || n
< precision
)
11397 && (frame_title_ptr
11398 || it
->current_x
< it
->last_visible_x
))
11400 unsigned char *last
= this;
11402 /* Advance to end of string or next format specifier. */
11403 while ((c
= *this++) != '\0' && c
!= '%')
11406 if (this - 1 != last
)
11408 /* Output to end of string or up to '%'. Field width
11409 is length of string. Don't output more than
11410 PRECISION allows us. */
11411 prec
= --this - last
;
11412 if (precision
> 0 && prec
> precision
- n
)
11413 prec
= precision
- n
;
11415 if (frame_title_ptr
)
11416 n
+= store_frame_title (last
, prec
, prec
);
11418 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
11419 it
, 0, prec
, 0, -1);
11421 else /* c == '%' */
11423 unsigned char *percent_position
= this;
11425 /* Get the specified minimum width. Zero means
11428 while ((c
= *this++) >= '0' && c
<= '9')
11429 field
= field
* 10 + c
- '0';
11431 /* Don't pad beyond the total padding allowed. */
11432 if (field_width
- n
> 0 && field
> field_width
- n
)
11433 field
= field_width
- n
;
11435 /* Note that either PRECISION <= 0 or N < PRECISION. */
11436 prec
= precision
- n
;
11439 n
+= display_mode_element (it
, depth
, field
, prec
,
11440 Vglobal_mode_string
);
11443 unsigned char *spec
11444 = decode_mode_spec (it
->w
, c
, field
, prec
);
11446 if (frame_title_ptr
)
11447 n
+= store_frame_title (spec
, field
, prec
);
11451 = it
->glyph_row
->used
[TEXT_AREA
];
11453 = percent_position
- XSTRING (elt
)->data
;
11455 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
11456 field
, prec
, 0, -1);
11458 /* Assign to the glyphs written above the
11459 string where the `%x' came from, position
11463 struct glyph
*glyph
11464 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
11468 for (i
= 0; i
< nwritten
; ++i
)
11470 glyph
[i
].object
= elt
;
11471 glyph
[i
].charpos
= charpos
;
11484 /* A symbol: process the value of the symbol recursively
11485 as if it appeared here directly. Avoid error if symbol void.
11486 Special case: if value of symbol is a string, output the string
11489 register Lisp_Object tem
;
11490 tem
= Fboundp (elt
);
11493 tem
= Fsymbol_value (elt
);
11494 /* If value is a string, output that string literally:
11495 don't check for % within it. */
11498 prec
= XSTRING (tem
)->size
;
11499 if (precision
> 0 && prec
> precision
- n
)
11500 prec
= precision
- n
;
11501 if (frame_title_ptr
)
11502 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
11504 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
11507 else if (!EQ (tem
, elt
))
11509 /* Give up right away for nil or t. */
11519 register Lisp_Object car
, tem
;
11521 /* A cons cell: three distinct cases.
11522 If first element is a string or a cons, process all the elements
11523 and effectively concatenate them.
11524 If first element is a negative number, truncate displaying cdr to
11525 at most that many characters. If positive, pad (with spaces)
11526 to at least that many characters.
11527 If first element is a symbol, process the cadr or caddr recursively
11528 according to whether the symbol's value is non-nil or nil. */
11529 car
= XCONS (elt
)->car
;
11530 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
11532 /* An element of the form (:eval FORM) means evaluate FORM
11533 and use the result as mode line elements. */
11534 struct gcpro gcpro1
;
11537 spec
= eval_form (XCAR (XCDR (elt
)));
11539 n
+= display_mode_element (it
, depth
, field_width
- n
,
11540 precision
- n
, spec
);
11543 else if (SYMBOLP (car
))
11545 tem
= Fboundp (car
);
11546 elt
= XCONS (elt
)->cdr
;
11549 /* elt is now the cdr, and we know it is a cons cell.
11550 Use its car if CAR has a non-nil value. */
11553 tem
= Fsymbol_value (car
);
11555 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
11557 /* Symbol's value is nil (or symbol is unbound)
11558 Get the cddr of the original list
11559 and if possible find the caddr and use that. */
11560 elt
= XCONS (elt
)->cdr
;
11563 else if (!CONSP (elt
))
11565 elt
= XCONS (elt
)->car
;
11568 else if (INTEGERP (car
))
11570 register int lim
= XINT (car
);
11571 elt
= XCONS (elt
)->cdr
;
11574 /* Negative int means reduce maximum width. */
11575 if (precision
<= 0)
11578 precision
= min (precision
, -lim
);
11582 /* Padding specified. Don't let it be more than
11583 current maximum. */
11585 lim
= min (precision
, lim
);
11587 /* If that's more padding than already wanted, queue it.
11588 But don't reduce padding already specified even if
11589 that is beyond the current truncation point. */
11590 field_width
= max (lim
, field_width
);
11594 else if (STRINGP (car
) || CONSP (car
))
11596 register int limit
= 50;
11597 /* Limit is to protect against circular lists. */
11600 && (precision
<= 0 || n
< precision
))
11602 n
+= display_mode_element (it
, depth
, field_width
- n
,
11603 precision
- n
, XCONS (elt
)->car
);
11604 elt
= XCONS (elt
)->cdr
;
11612 if (frame_title_ptr
)
11613 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
11615 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
11616 precision
- n
, 0, 0);
11620 /* Pad to FIELD_WIDTH. */
11621 if (field_width
> 0 && n
< field_width
)
11623 if (frame_title_ptr
)
11624 n
+= store_frame_title ("", field_width
- n
, 0);
11626 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
11634 /* Write a null-terminated, right justified decimal representation of
11635 the positive integer D to BUF using a minimal field width WIDTH. */
11638 pint2str (buf
, width
, d
)
11639 register char *buf
;
11640 register int width
;
11643 register char *p
= buf
;
11651 *p
++ = d
% 10 + '0';
11656 for (width
-= (int) (p
- buf
); width
> 0; --width
)
11667 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
11668 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
11669 type of CODING_SYSTEM. Return updated pointer into BUF. */
11671 static unsigned char invalid_eol_type
[] = "(*invalid*)";
11674 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
11675 Lisp_Object coding_system
;
11676 register char *buf
;
11680 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
11681 unsigned char *eol_str
;
11683 /* The EOL conversion we are using. */
11684 Lisp_Object eoltype
;
11686 val
= coding_system
;
11688 if (NILP (val
)) /* Not yet decided. */
11693 eoltype
= eol_mnemonic_undecided
;
11694 /* Don't mention EOL conversion if it isn't decided. */
11698 Lisp_Object eolvalue
;
11700 eolvalue
= Fget (coding_system
, Qeol_type
);
11702 while (!NILP (val
) && SYMBOLP (val
))
11704 val
= Fget (val
, Qcoding_system
);
11705 if (NILP (eolvalue
))
11706 eolvalue
= Fget (val
, Qeol_type
);
11710 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
11714 /* The EOL conversion that is normal on this system. */
11716 if (NILP (eolvalue
)) /* Not yet decided. */
11717 eoltype
= eol_mnemonic_undecided
;
11718 else if (VECTORP (eolvalue
)) /* Not yet decided. */
11719 eoltype
= eol_mnemonic_undecided
;
11720 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
11721 eoltype
= (XFASTINT (eolvalue
) == 0
11722 ? eol_mnemonic_unix
11723 : (XFASTINT (eolvalue
) == 1
11724 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
11730 /* Mention the EOL conversion if it is not the usual one. */
11731 if (STRINGP (eoltype
))
11733 eol_str
= XSTRING (eoltype
)->data
;
11734 eol_str_len
= XSTRING (eoltype
)->size
;
11736 else if (INTEGERP (eoltype
)
11737 && CHAR_VALID_P (XINT (eoltype
), 0))
11739 unsigned char work
[4];
11741 eol_str_len
= CHAR_STRING (XINT (eoltype
), work
, eol_str
);
11745 eol_str
= invalid_eol_type
;
11746 eol_str_len
= sizeof (invalid_eol_type
) - 1;
11748 bcopy (eol_str
, buf
, eol_str_len
);
11749 buf
+= eol_str_len
;
11755 /* Return a string for the output of a mode line %-spec for window W,
11756 generated by character C. PRECISION >= 0 means don't return a
11757 string longer than that value. FIELD_WIDTH > 0 means pad the
11758 string returned with spaces to that value. */
11760 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
11763 decode_mode_spec (w
, c
, field_width
, precision
)
11766 int field_width
, precision
;
11769 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11770 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
11771 struct buffer
*b
= XBUFFER (w
->buffer
);
11778 if (!NILP (b
->read_only
))
11780 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
11785 /* This differs from %* only for a modified read-only buffer. */
11786 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
11788 if (!NILP (b
->read_only
))
11793 /* This differs from %* in ignoring read-only-ness. */
11794 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
11806 if (command_loop_level
> 5)
11808 p
= decode_mode_spec_buf
;
11809 for (i
= 0; i
< command_loop_level
; i
++)
11812 return decode_mode_spec_buf
;
11820 if (command_loop_level
> 5)
11822 p
= decode_mode_spec_buf
;
11823 for (i
= 0; i
< command_loop_level
; i
++)
11826 return decode_mode_spec_buf
;
11833 /* Let lots_of_dashes be a string of infinite length. */
11834 if (field_width
<= 0
11835 || field_width
> sizeof (lots_of_dashes
))
11837 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
11838 decode_mode_spec_buf
[i
] = '-';
11839 decode_mode_spec_buf
[i
] = '\0';
11840 return decode_mode_spec_buf
;
11843 return lots_of_dashes
;
11852 int col
= current_column ();
11853 XSETFASTINT (w
->column_number_displayed
, col
);
11854 pint2str (decode_mode_spec_buf
, field_width
, col
);
11855 return decode_mode_spec_buf
;
11859 /* %F displays the frame name. */
11860 if (!NILP (f
->title
))
11861 return (char *) XSTRING (f
->title
)->data
;
11862 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
11863 return (char *) XSTRING (f
->name
)->data
;
11872 int startpos
= XMARKER (w
->start
)->charpos
;
11873 int startpos_byte
= marker_byte_position (w
->start
);
11874 int line
, linepos
, linepos_byte
, topline
;
11876 int height
= XFASTINT (w
->height
);
11878 /* If we decided that this buffer isn't suitable for line numbers,
11879 don't forget that too fast. */
11880 if (EQ (w
->base_line_pos
, w
->buffer
))
11882 /* But do forget it, if the window shows a different buffer now. */
11883 else if (BUFFERP (w
->base_line_pos
))
11884 w
->base_line_pos
= Qnil
;
11886 /* If the buffer is very big, don't waste time. */
11887 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
11889 w
->base_line_pos
= Qnil
;
11890 w
->base_line_number
= Qnil
;
11894 if (!NILP (w
->base_line_number
)
11895 && !NILP (w
->base_line_pos
)
11896 && XFASTINT (w
->base_line_pos
) <= startpos
)
11898 line
= XFASTINT (w
->base_line_number
);
11899 linepos
= XFASTINT (w
->base_line_pos
);
11900 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
11905 linepos
= BUF_BEGV (b
);
11906 linepos_byte
= BUF_BEGV_BYTE (b
);
11909 /* Count lines from base line to window start position. */
11910 nlines
= display_count_lines (linepos
, linepos_byte
,
11914 topline
= nlines
+ line
;
11916 /* Determine a new base line, if the old one is too close
11917 or too far away, or if we did not have one.
11918 "Too close" means it's plausible a scroll-down would
11919 go back past it. */
11920 if (startpos
== BUF_BEGV (b
))
11922 XSETFASTINT (w
->base_line_number
, topline
);
11923 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
11925 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
11926 || linepos
== BUF_BEGV (b
))
11928 int limit
= BUF_BEGV (b
);
11929 int limit_byte
= BUF_BEGV_BYTE (b
);
11931 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
11933 if (startpos
- distance
> limit
)
11935 limit
= startpos
- distance
;
11936 limit_byte
= CHAR_TO_BYTE (limit
);
11939 nlines
= display_count_lines (startpos
, startpos_byte
,
11941 - (height
* 2 + 30),
11943 /* If we couldn't find the lines we wanted within
11944 line_number_display_limit_width chars per line,
11945 give up on line numbers for this window. */
11946 if (position
== limit_byte
&& limit
== startpos
- distance
)
11948 w
->base_line_pos
= w
->buffer
;
11949 w
->base_line_number
= Qnil
;
11953 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
11954 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
11957 /* Now count lines from the start pos to point. */
11958 nlines
= display_count_lines (startpos
, startpos_byte
,
11959 PT_BYTE
, PT
, &junk
);
11961 /* Record that we did display the line number. */
11962 line_number_displayed
= 1;
11964 /* Make the string to show. */
11965 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
11966 return decode_mode_spec_buf
;
11969 char* p
= decode_mode_spec_buf
;
11970 int pad
= field_width
- 2;
11975 return decode_mode_spec_buf
;
11981 obj
= b
->mode_name
;
11985 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
11991 int pos
= marker_position (w
->start
);
11992 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
11994 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
11996 if (pos
<= BUF_BEGV (b
))
12001 else if (pos
<= BUF_BEGV (b
))
12005 if (total
> 1000000)
12006 /* Do it differently for a large value, to avoid overflow. */
12007 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12009 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12010 /* We can't normally display a 3-digit number,
12011 so get us a 2-digit number that is close. */
12014 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12015 return decode_mode_spec_buf
;
12019 /* Display percentage of size above the bottom of the screen. */
12022 int toppos
= marker_position (w
->start
);
12023 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
12024 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12026 if (botpos
>= BUF_ZV (b
))
12028 if (toppos
<= BUF_BEGV (b
))
12035 if (total
> 1000000)
12036 /* Do it differently for a large value, to avoid overflow. */
12037 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12039 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12040 /* We can't normally display a 3-digit number,
12041 so get us a 2-digit number that is close. */
12044 if (toppos
<= BUF_BEGV (b
))
12045 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
12047 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12048 return decode_mode_spec_buf
;
12053 /* status of process */
12054 obj
= Fget_buffer_process (w
->buffer
);
12056 return "no process";
12057 #ifdef subprocesses
12058 obj
= Fsymbol_name (Fprocess_status (obj
));
12062 case 't': /* indicate TEXT or BINARY */
12063 #ifdef MODE_LINE_BINARY_TEXT
12064 return MODE_LINE_BINARY_TEXT (b
);
12070 /* coding-system (not including end-of-line format) */
12072 /* coding-system (including end-of-line type) */
12074 int eol_flag
= (c
== 'Z');
12075 char *p
= decode_mode_spec_buf
;
12077 if (! FRAME_WINDOW_P (f
))
12079 /* No need to mention EOL here--the terminal never needs
12080 to do EOL conversion. */
12081 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
12082 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
12084 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
12087 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
12088 #ifdef subprocesses
12089 obj
= Fget_buffer_process (Fcurrent_buffer ());
12090 if (PROCESSP (obj
))
12092 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
12094 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
12097 #endif /* subprocesses */
12100 return decode_mode_spec_buf
;
12105 return (char *) XSTRING (obj
)->data
;
12111 /* Count up to COUNT lines starting from START / START_BYTE.
12112 But don't go beyond LIMIT_BYTE.
12113 Return the number of lines thus found (always nonnegative).
12115 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
12118 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
12119 int start
, start_byte
, limit_byte
, count
;
12122 register unsigned char *cursor
;
12123 unsigned char *base
;
12125 register int ceiling
;
12126 register unsigned char *ceiling_addr
;
12127 int orig_count
= count
;
12129 /* If we are not in selective display mode,
12130 check only for newlines. */
12131 int selective_display
= (!NILP (current_buffer
->selective_display
)
12132 && !INTEGERP (current_buffer
->selective_display
));
12136 while (start_byte
< limit_byte
)
12138 ceiling
= BUFFER_CEILING_OF (start_byte
);
12139 ceiling
= min (limit_byte
- 1, ceiling
);
12140 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
12141 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
12144 if (selective_display
)
12145 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
12148 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
12151 if (cursor
!= ceiling_addr
)
12155 start_byte
+= cursor
- base
+ 1;
12156 *byte_pos_ptr
= start_byte
;
12160 if (++cursor
== ceiling_addr
)
12166 start_byte
+= cursor
- base
;
12171 while (start_byte
> limit_byte
)
12173 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
12174 ceiling
= max (limit_byte
, ceiling
);
12175 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
12176 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
12179 if (selective_display
)
12180 while (--cursor
!= ceiling_addr
12181 && *cursor
!= '\n' && *cursor
!= 015)
12184 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
12187 if (cursor
!= ceiling_addr
)
12191 start_byte
+= cursor
- base
+ 1;
12192 *byte_pos_ptr
= start_byte
;
12193 /* When scanning backwards, we should
12194 not count the newline posterior to which we stop. */
12195 return - orig_count
- 1;
12201 /* Here we add 1 to compensate for the last decrement
12202 of CURSOR, which took it past the valid range. */
12203 start_byte
+= cursor
- base
+ 1;
12207 *byte_pos_ptr
= limit_byte
;
12210 return - orig_count
+ count
;
12211 return orig_count
- count
;
12217 /***********************************************************************
12219 ***********************************************************************/
12221 /* Display a NUL-terminated string, starting with index START.
12223 If STRING is non-null, display that C string. Otherwise, the Lisp
12224 string LISP_STRING is displayed.
12226 If FACE_STRING is not nil, FACE_STRING_POS is a position in
12227 FACE_STRING. Display STRING or LISP_STRING with the face at
12228 FACE_STRING_POS in FACE_STRING:
12230 Display the string in the environment given by IT, but use the
12231 standard display table, temporarily.
12233 FIELD_WIDTH is the minimum number of output glyphs to produce.
12234 If STRING has fewer characters than FIELD_WIDTH, pad to the right
12235 with spaces. If STRING has more characters, more than FIELD_WIDTH
12236 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
12238 PRECISION is the maximum number of characters to output from
12239 STRING. PRECISION < 0 means don't truncate the string.
12241 This is roughly equivalent to printf format specifiers:
12243 FIELD_WIDTH PRECISION PRINTF
12244 ----------------------------------------
12250 MULTIBYTE zero means do not display multibyte chars, > 0 means do
12251 display them, and < 0 means obey the current buffer's value of
12252 enable_multibyte_characters.
12254 Value is the number of glyphs produced. */
12257 display_string (string
, lisp_string
, face_string
, face_string_pos
,
12258 start
, it
, field_width
, precision
, max_x
, multibyte
)
12259 unsigned char *string
;
12260 Lisp_Object lisp_string
;
12263 int field_width
, precision
, max_x
;
12266 int hpos_at_start
= it
->hpos
;
12267 int saved_face_id
= it
->face_id
;
12268 struct glyph_row
*row
= it
->glyph_row
;
12270 /* Initialize the iterator IT for iteration over STRING beginning
12271 with index START. We assume that IT may be modified here (which
12272 means that display_line has to do something when displaying a
12273 mini-buffer prompt, which it does). */
12274 reseat_to_string (it
, string
, lisp_string
, start
,
12275 precision
, field_width
, multibyte
);
12277 /* If displaying STRING, set up the face of the iterator
12278 from LISP_STRING, if that's given. */
12279 if (STRINGP (face_string
))
12285 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
12286 0, it
->region_beg_charpos
,
12287 it
->region_end_charpos
,
12288 &endptr
, it
->base_face_id
);
12289 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12290 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
12293 /* Set max_x to the maximum allowed X position. Don't let it go
12294 beyond the right edge of the window. */
12296 max_x
= it
->last_visible_x
;
12298 max_x
= min (max_x
, it
->last_visible_x
);
12300 /* Skip over display elements that are not visible. because IT->w is
12302 if (it
->current_x
< it
->first_visible_x
)
12303 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
12304 MOVE_TO_POS
| MOVE_TO_X
);
12306 row
->ascent
= it
->max_ascent
;
12307 row
->height
= it
->max_ascent
+ it
->max_descent
;
12308 row
->phys_ascent
= it
->max_phys_ascent
;
12309 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12311 /* This condition is for the case that we are called with current_x
12312 past last_visible_x. */
12313 while (it
->current_x
< max_x
)
12315 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
12317 /* Get the next display element. */
12318 if (!get_next_display_element (it
))
12321 /* Produce glyphs. */
12322 x_before
= it
->current_x
;
12323 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
12324 PRODUCE_GLYPHS (it
);
12326 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
12329 while (i
< nglyphs
)
12331 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12333 if (!it
->truncate_lines_p
12334 && x
+ glyph
->pixel_width
> max_x
)
12336 /* End of continued line or max_x reached. */
12337 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12341 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
12343 /* Glyph is at least partially visible. */
12345 if (x
< it
->first_visible_x
)
12346 it
->glyph_row
->x
= x
- it
->first_visible_x
;
12350 /* Glyph is off the left margin of the display area.
12351 Should not happen. */
12355 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12356 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12357 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12358 row
->phys_height
= max (row
->phys_height
,
12359 it
->max_phys_ascent
+ it
->max_phys_descent
);
12360 x
+= glyph
->pixel_width
;
12364 /* Stop if max_x reached. */
12368 /* Stop at line ends. */
12369 if (ITERATOR_AT_END_OF_LINE_P (it
))
12371 it
->continuation_lines_width
= 0;
12375 set_iterator_to_next (it
);
12377 /* Stop if truncating at the right edge. */
12378 if (it
->truncate_lines_p
12379 && it
->current_x
>= it
->last_visible_x
)
12381 /* Add truncation mark, but don't do it if the line is
12382 truncated at a padding space. */
12383 if (IT_CHARPOS (*it
) < it
->string_nchars
)
12385 if (!FRAME_WINDOW_P (it
->f
))
12386 produce_special_glyphs (it
, IT_TRUNCATION
);
12387 it
->glyph_row
->truncated_on_right_p
= 1;
12393 /* Maybe insert a truncation at the left. */
12394 if (it
->first_visible_x
12395 && IT_CHARPOS (*it
) > 0)
12397 if (!FRAME_WINDOW_P (it
->f
))
12398 insert_left_trunc_glyphs (it
);
12399 it
->glyph_row
->truncated_on_left_p
= 1;
12402 it
->face_id
= saved_face_id
;
12404 /* Value is number of columns displayed. */
12405 return it
->hpos
- hpos_at_start
;
12410 /* This is like a combination of memq and assq. Return 1 if PROPVAL
12411 appears as an element of LIST or as the car of an element of LIST.
12412 If PROPVAL is a list, compare each element against LIST in that
12413 way, and return 1 if any element of PROPVAL is found in LIST.
12414 Otherwise return 0. This function cannot quit. */
12417 invisible_p (propval
, list
)
12418 register Lisp_Object propval
;
12421 register Lisp_Object tail
, proptail
;
12422 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
12424 register Lisp_Object tem
;
12425 tem
= XCONS (tail
)->car
;
12426 if (EQ (propval
, tem
))
12428 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
12431 if (CONSP (propval
))
12432 for (proptail
= propval
; CONSP (proptail
);
12433 proptail
= XCONS (proptail
)->cdr
)
12435 Lisp_Object propelt
;
12436 propelt
= XCONS (proptail
)->car
;
12437 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
12439 register Lisp_Object tem
;
12440 tem
= XCONS (tail
)->car
;
12441 if (EQ (propelt
, tem
))
12443 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
12451 /* Return 1 if PROPVAL appears as the car of an element of LIST and
12452 the cdr of that element is non-nil. If PROPVAL is a list, check
12453 each element of PROPVAL in that way, and the first time some
12454 element is found, return 1 if the cdr of that element is non-nil.
12455 Otherwise return 0. This function cannot quit. */
12458 invisible_ellipsis_p (propval
, list
)
12459 register Lisp_Object propval
;
12462 register Lisp_Object tail
, proptail
;
12463 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
12465 register Lisp_Object tem
;
12466 tem
= XCONS (tail
)->car
;
12467 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
12468 return ! NILP (XCONS (tem
)->cdr
);
12470 if (CONSP (propval
))
12471 for (proptail
= propval
; CONSP (proptail
);
12472 proptail
= XCONS (proptail
)->cdr
)
12474 Lisp_Object propelt
;
12475 propelt
= XCONS (proptail
)->car
;
12476 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
12478 register Lisp_Object tem
;
12479 tem
= XCONS (tail
)->car
;
12480 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
12481 return ! NILP (XCONS (tem
)->cdr
);
12489 /***********************************************************************
12491 ***********************************************************************/
12496 Vresize_mini_config
= Qnil
;
12497 staticpro (&Vresize_mini_config
);
12499 Vwith_echo_area_save_vector
= Qnil
;
12500 staticpro (&Vwith_echo_area_save_vector
);
12502 Vmessage_stack
= Qnil
;
12503 staticpro (&Vmessage_stack
);
12505 Qinhibit_redisplay
= intern ("inhibit-redisplay");
12506 staticpro (&Qinhibit_redisplay
);
12509 defsubr (&Sdump_glyph_matrix
);
12510 defsubr (&Sdump_glyph_row
);
12511 defsubr (&Sdump_toolbar_row
);
12512 defsubr (&Strace_redisplay_toggle
);
12515 staticpro (&Qmenu_bar_update_hook
);
12516 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
12518 staticpro (&Qoverriding_terminal_local_map
);
12519 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
12521 staticpro (&Qoverriding_local_map
);
12522 Qoverriding_local_map
= intern ("overriding-local-map");
12524 staticpro (&Qwindow_scroll_functions
);
12525 Qwindow_scroll_functions
= intern ("window-scroll-functions");
12527 staticpro (&Qredisplay_end_trigger_functions
);
12528 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
12530 staticpro (&Qinhibit_point_motion_hooks
);
12531 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
12533 staticpro (&Qdisplay
);
12534 Qdisplay
= intern ("display");
12535 staticpro (&Qleft_margin
);
12536 Qspace_width
= intern ("space-width");
12537 staticpro (&Qspace_width
);
12538 Qheight
= intern ("height");
12539 staticpro (&Qheight
);
12540 Qraise
= intern ("raise");
12541 staticpro (&Qraise
);
12542 Qspace
= intern ("space");
12543 staticpro (&Qspace
);
12544 Qleft_margin
= intern ("left-margin");
12545 staticpro (&Qright_margin
);
12546 Qright_margin
= intern ("right-margin");
12547 Qalign_to
= intern ("align-to");
12548 staticpro (&Qalign_to
);
12549 QCalign_to
= intern (":align-to");
12550 staticpro (&QCalign_to
);
12551 Qwidth
= intern ("width");
12552 staticpro (&Qwidth
);
12553 Qrelative_width
= intern ("relative-width");
12554 staticpro (&Qrelative_width
);
12555 QCrelative_width
= intern (":relative-width");
12556 staticpro (&QCrelative_width
);
12557 QCrelative_height
= intern (":relative-height");
12558 staticpro (&QCrelative_height
);
12559 QCeval
= intern (":eval");
12560 staticpro (&QCeval
);
12561 QCwhen
= intern (":when");
12562 staticpro (&QCwhen
);
12563 Qfontified
= intern ("fontified");
12564 staticpro (&Qfontified
);
12565 Qfontification_functions
= intern ("fontification-functions");
12566 staticpro (&Qfontification_functions
);
12567 Qtrailing_whitespace
= intern ("trailing-whitespace");
12568 staticpro (&Qtrailing_whitespace
);
12569 Qimage
= intern ("image");
12570 staticpro (&Qimage
);
12572 staticpro (&last_arrow_position
);
12573 staticpro (&last_arrow_string
);
12574 last_arrow_position
= Qnil
;
12575 last_arrow_string
= Qnil
;
12577 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
12578 staticpro (&echo_buffer
[0]);
12579 staticpro (&echo_buffer
[1]);
12581 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
12582 staticpro (&echo_area_buffer
[0]);
12583 staticpro (&echo_area_buffer
[1]);
12585 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
12586 "Non-nil means highlight trailing whitespace.\n\
12587 The face used for trailing whitespace is `trailing-whitespace'.");
12588 Vshow_trailing_whitespace
= Qnil
;
12590 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
12591 "Non-nil means don't actually do any redisplay.\n\
12592 This is used for internal purposes.");
12593 Vinhibit_redisplay
= Qnil
;
12595 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
12596 "String (or mode line construct) included (normally) in `mode-line-format'.");
12597 Vglobal_mode_string
= Qnil
;
12599 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
12600 "Marker for where to display an arrow on top of the buffer text.\n\
12601 This must be the beginning of a line in order to work.\n\
12602 See also `overlay-arrow-string'.");
12603 Voverlay_arrow_position
= Qnil
;
12605 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
12606 "String to display as an arrow. See also `overlay-arrow-position'.");
12607 Voverlay_arrow_string
= Qnil
;
12609 DEFVAR_INT ("scroll-step", &scroll_step
,
12610 "*The number of lines to try scrolling a window by when point moves out.\n\
12611 If that fails to bring point back on frame, point is centered instead.\n\
12612 If this is zero, point is always centered after it moves off frame.");
12614 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
12615 "*Scroll up to this many lines, to bring point back on screen.");
12616 scroll_conservatively
= 0;
12618 DEFVAR_INT ("scroll-margin", &scroll_margin
,
12619 "*Number of lines of margin at the top and bottom of a window.\n\
12620 Recenter the window whenever point gets within this many lines\n\
12621 of the top or bottom of the window.");
12625 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
12628 DEFVAR_BOOL ("truncate-partial-width-windows",
12629 &truncate_partial_width_windows
,
12630 "*Non-nil means truncate lines in all windows less than full frame wide.");
12631 truncate_partial_width_windows
= 1;
12633 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
12634 "*Non-nil means use inverse video for the mode line.");
12635 mode_line_inverse_video
= 1;
12637 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
12638 "*Maximum buffer size for which line number should be displayed.\n\
12639 If the buffer is bigger than this, the line number does not appear\n\
12640 in the mode line.");
12641 line_number_display_limit
= 1000000;
12643 DEFVAR_INT ("line-number-display-limit-width", &line_number_display_limit_width
,
12644 "*Maximum line width (in characters) for line number display.\n\
12645 If the average length of the lines near point is bigger than this, then the\n\
12646 line number may be omitted from the mode line.");
12647 line_number_display_limit_width
= 200;
12649 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
12650 "*Non-nil means highlight region even in nonselected windows.");
12651 highlight_nonselected_windows
= 0;
12653 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
12654 "Non-nil if more than one frame is visible on this display.\n\
12655 Minibuffer-only frames don't count, but iconified frames do.\n\
12656 This variable is not guaranteed to be accurate except while processing\n\
12657 `frame-title-format' and `icon-title-format'.");
12659 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
12660 "Template for displaying the title bar of visible frames.\n\
12661 \(Assuming the window manager supports this feature.)\n\
12662 This variable has the same structure as `mode-line-format' (which see),\n\
12663 and is used only on frames for which no explicit name has been set\n\
12664 \(see `modify-frame-parameters').");
12665 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
12666 "Template for displaying the title bar of an iconified frame.\n\
12667 \(Assuming the window manager supports this feature.)\n\
12668 This variable has the same structure as `mode-line-format' (which see),\n\
12669 and is used only on frames for which no explicit name has been set\n\
12670 \(see `modify-frame-parameters').");
12672 = Vframe_title_format
12673 = Fcons (intern ("multiple-frames"),
12674 Fcons (build_string ("%b"),
12675 Fcons (Fcons (build_string (""),
12676 Fcons (intern ("invocation-name"),
12677 Fcons (build_string ("@"),
12678 Fcons (intern ("system-name"),
12682 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
12683 "Maximum number of lines to keep in the message log buffer.\n\
12684 If nil, disable message logging. If t, log messages but don't truncate\n\
12685 the buffer when it becomes large.");
12686 XSETFASTINT (Vmessage_log_max
, 50);
12688 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
12689 "Functions called before redisplay, if window sizes have changed.\n\
12690 The value should be a list of functions that take one argument.\n\
12691 Just before redisplay, for each frame, if any of its windows have changed\n\
12692 size since the last redisplay, or have been split or deleted,\n\
12693 all the functions in the list are called, with the frame as argument.");
12694 Vwindow_size_change_functions
= Qnil
;
12696 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
12697 "List of Functions to call before redisplaying a window with scrolling.\n\
12698 Each function is called with two arguments, the window\n\
12699 and its new display-start position. Note that the value of `window-end'\n\
12700 is not valid when these functions are called.");
12701 Vwindow_scroll_functions
= Qnil
;
12703 DEFVAR_BOOL ("auto-resize-toolbars", &auto_resize_toolbars_p
,
12704 "*Non-nil means automatically resize toolbars.\n\
12705 This increases a toolbar's height if not all toolbar items are visible.\n\
12706 It decreases a toolbar's height when it would display blank lines\n\
12708 auto_resize_toolbars_p
= 1;
12710 DEFVAR_BOOL ("auto-raise-toolbar-buttons", &auto_raise_toolbar_buttons_p
,
12711 "*Non-nil means raise toolbar buttons when the mouse moves over them.");
12712 auto_raise_toolbar_buttons_p
= 1;
12714 DEFVAR_INT ("toolbar-button-margin", &toolbar_button_margin
,
12715 "*Margin around toolbar buttons in pixels.");
12716 toolbar_button_margin
= 1;
12718 DEFVAR_INT ("toolbar-button-relief", &toolbar_button_relief
,
12719 "Relief thickness of toolbar buttons.");
12720 toolbar_button_relief
= 3;
12722 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
12723 "List of functions to call to fontify regions of text.\n\
12724 Each function is called with one argument POS. Functions must\n\
12725 fontify a region starting at POS in the current buffer, and give\n\
12726 fontified regions the property `fontified'.\n\
12727 This variable automatically becomes buffer-local when set.");
12728 Vfontification_functions
= Qnil
;
12729 Fmake_local_variable (Qfontification_functions
);
12731 DEFVAR_BOOL ("unibyte-display-via-language-environment",
12732 &unibyte_display_via_language_environment
,
12733 "*Non-nil means display unibyte text according to language environment.\n\
12734 Specifically this means that unibyte non-ASCII characters\n\
12735 are displayed by converting them to the equivalent multibyte characters\n\
12736 according to the current language environment. As a result, they are\n\
12737 displayed according to the current fontset.");
12738 unibyte_display_via_language_environment
= 0;
12740 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
12741 "*Maximum height for resizing mini-windows.\n\
12742 If a float, it specifies a fraction of the mini-window frame's height.\n\
12743 If an integer, it specifies a number of lines.\n\
12744 If nil, don't resize.");
12745 Vmax_mini_window_height
= make_float (0.25);
12749 /* Initialize this module when Emacs starts. */
12754 Lisp_Object root_window
;
12755 struct window
*mini_w
;
12757 CHARPOS (this_line_start_pos
) = 0;
12759 mini_w
= XWINDOW (minibuf_window
);
12760 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
12762 if (!noninteractive
)
12764 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
12767 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
12768 set_window_height (root_window
,
12769 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
12771 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
12772 set_window_height (minibuf_window
, 1, 0);
12774 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
12775 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
12777 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
12778 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
12779 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
12781 /* The default ellipsis glyphs `...'. */
12782 for (i
= 0; i
< 3; ++i
)
12783 XSETFASTINT (default_invis_vector
[i
], '.');
12786 #ifdef HAVE_WINDOW_SYSTEM
12788 /* Allocate the buffer for frame titles. */
12790 frame_title_buf
= (char *) xmalloc (size
);
12791 frame_title_buf_end
= frame_title_buf
+ size
;
12792 frame_title_ptr
= NULL
;
12794 #endif /* HAVE_WINDOW_SYSTEM */