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 /* Name of the variable controlling the highlighting of trailing
263 whitespace. The implementation uses find_symbol_value to get its
266 Lisp_Object Qshow_trailing_whitespace
;
268 /* Name of the face used to highlight trailing whitespace. */
270 Lisp_Object Qtrailing_whitespace
;
272 /* The symbol `image' which is the car of the lists used to represent
277 /* Non-zero means print newline to stdout before next mini-buffer
280 int noninteractive_need_newline
;
282 /* Non-zero means print newline to message log before next message. */
284 static int message_log_need_newline
;
287 /* The buffer position of the first character appearing entirely or
288 partially on the line of the selected window which contains the
289 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
290 redisplay optimization in redisplay_internal. */
292 static struct text_pos this_line_start_pos
;
294 /* Number of characters past the end of the line above, including the
295 terminating newline. */
297 static struct text_pos this_line_end_pos
;
299 /* The vertical positions and the height of this line. */
301 static int this_line_vpos
;
302 static int this_line_y
;
303 static int this_line_pixel_height
;
305 /* X position at which this display line starts. Usually zero;
306 negative if first character is partially visible. */
308 static int this_line_start_x
;
310 /* Buffer that this_line_.* variables are referring to. */
312 static struct buffer
*this_line_buffer
;
314 /* Nonzero means truncate lines in all windows less wide than the
317 int truncate_partial_width_windows
;
319 /* A flag to control how to display unibyte 8-bit character. */
321 int unibyte_display_via_language_environment
;
323 /* Nonzero means we have more than one non-mini-buffer-only frame.
324 Not guaranteed to be accurate except while parsing
325 frame-title-format. */
329 Lisp_Object Vglobal_mode_string
;
331 /* Marker for where to display an arrow on top of the buffer text. */
333 Lisp_Object Voverlay_arrow_position
;
335 /* String to display for the arrow. Only used on terminal frames. */
337 Lisp_Object Voverlay_arrow_string
;
339 /* Values of those variables at last redisplay. However, if
340 Voverlay_arrow_position is a marker, last_arrow_position is its
341 numerical position. */
343 static Lisp_Object last_arrow_position
, last_arrow_string
;
345 /* Like mode-line-format, but for the title bar on a visible frame. */
347 Lisp_Object Vframe_title_format
;
349 /* Like mode-line-format, but for the title bar on an iconified frame. */
351 Lisp_Object Vicon_title_format
;
353 /* List of functions to call when a window's size changes. These
354 functions get one arg, a frame on which one or more windows' sizes
357 static Lisp_Object Vwindow_size_change_functions
;
359 Lisp_Object Qmenu_bar_update_hook
;
361 /* Nonzero if overlay arrow has been displayed once in this window. */
363 static int overlay_arrow_seen
;
365 /* Nonzero means highlight the region even in nonselected windows. */
367 int highlight_nonselected_windows
;
369 /* If cursor motion alone moves point off frame, try scrolling this
370 many lines up or down if that will bring it back. */
372 static int scroll_step
;
374 /* Non-0 means scroll just far enough to bring point back on the
375 screen, when appropriate. */
377 static int scroll_conservatively
;
379 /* Recenter the window whenever point gets within this many lines of
380 the top or bottom of the window. This value is translated into a
381 pixel value by multiplying it with CANON_Y_UNIT, which means that
382 there is really a fixed pixel height scroll margin. */
386 /* Number of characters of overlap to show, when scrolling a one-line
387 window such as a minibuffer. */
389 static int minibuffer_scroll_overlap
;
391 /* Number of windows showing the buffer of the selected window (or
392 another buffer with the same base buffer). keyboard.c refers to
397 /* Vector containing glyphs for an ellipsis `...'. */
399 static Lisp_Object default_invis_vector
[3];
401 /* Nonzero means display mode line highlighted. */
403 int mode_line_inverse_video
;
405 /* Prompt to display in front of the mini-buffer contents. */
407 Lisp_Object minibuf_prompt
;
409 /* Width of current mini-buffer prompt. Only set after display_line
410 of the line that contains the prompt. */
412 int minibuf_prompt_width
;
413 int minibuf_prompt_pixel_width
;
415 /* Message to display instead of mini-buffer contents. This is what
416 the functions error and message make, and command echoing uses it
417 as well. It overrides the minibuf_prompt as well as the buffer. */
419 char *echo_area_glyphs
;
421 /* A Lisp string to display instead of mini-buffer contents, analogous
422 to echo_area_glyphs. If this is a string, display that string.
423 Otherwise, if echo_area_glyphs is non-null, display that. */
425 Lisp_Object echo_area_message
;
427 /* This is the length of the message in echo_area_glyphs or
428 echo_area_message. */
430 int echo_area_glyphs_length
;
432 /* Value of echo_area_glyphs when it was last acted on. If this is
433 nonzero, there is a message on the frame in the mini-buffer and it
434 should be erased as soon as it is no longer requested to appear. */
436 char *previous_echo_glyphs
;
437 Lisp_Object previous_echo_area_message
;
438 static int previous_echo_glyphs_length
;
440 /* This is the window where the echo area message was displayed. It
441 is always a mini-buffer window, but it may not be the same window
442 currently active as a mini-buffer. */
444 Lisp_Object echo_area_window
;
446 /* Nonzero means multibyte characters were enabled when the echo area
447 message was specified. */
449 int message_enable_multibyte
;
451 /* True if we should redraw the mode lines on the next redisplay. */
453 int update_mode_lines
;
455 /* Smallest number of characters before the gap at any time since last
456 redisplay that finished. Valid for current buffer when
457 try_window_id can be called. */
461 /* Smallest number of characters after the gap at any time since last
462 redisplay that finished. Valid for current buffer when
463 try_window_id can be called. */
467 /* MODIFF as of last redisplay that finished; if it matches MODIFF,
468 and overlay_unchanged_modified matches OVERLAY_MODIFF, that means
469 beg_unchanged and end_unchanged contain no useful information. */
471 int unchanged_modified
;
473 /* OVERLAY_MODIFF as of last redisplay that finished. */
475 int overlay_unchanged_modified
;
477 /* Nonzero if window sizes or contents have changed since last
478 redisplay that finished */
480 int windows_or_buffers_changed
;
482 /* Nonzero after display_mode_line if %l was used and it displayed a
485 int line_number_displayed
;
487 /* Maximum buffer size for which to display line numbers. */
489 static int line_number_display_limit
;
491 /* Number of lines to keep in the message log buffer. t means
492 infinite. nil means don't log at all. */
494 Lisp_Object Vmessage_log_max
;
496 /* A scratch glyph row with contents used for generating truncation
497 glyphs. Also used in direct_output_for_insert. */
499 #define MAX_SCRATCH_GLYPHS 100
500 struct glyph_row scratch_glyph_row
;
501 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
503 /* Ascent and height of the last line processed by move_it_to. */
505 static int last_max_ascent
, last_height
;
507 /* The maximum distance to look ahead for text properties. Values
508 that are too small let us call compute_char_face and similar
509 functions too often which is expensive. Values that are too large
510 let us call compute_char_face and alike too often because we
511 might not be interested in text properties that far away. */
513 #define TEXT_PROP_DISTANCE_LIMIT 100
515 /* Non-zero means print traces of redisplay if compiled with
519 int trace_redisplay_p
;
522 /* Value returned from text property handlers (see below). */
527 HANDLED_RECOMPUTE_PROPS
,
528 HANDLED_OVERLAY_STRING_CONSUMED
,
532 /* A description of text properties that redisplay is interested
537 /* The name of the property. */
540 /* A unique index for the property. */
543 /* A handler function called to set up iterator IT from the property
544 at IT's current position. Value is used to steer handle_stop. */
545 enum prop_handled (*handler
) P_ ((struct it
*it
));
548 static enum prop_handled handle_face_prop
P_ ((struct it
*));
549 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
550 static enum prop_handled handle_display_prop
P_ ((struct it
*));
551 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
552 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
554 /* Properties handled by iterators. */
556 static struct props it_props
[] =
558 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
559 /* Handle `face' before `display' because some sub-properties of
560 `display' need to know the face. */
561 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
562 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
563 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
567 /* Value is the position described by X. If X is a marker, value is
568 the marker_position of X. Otherwise, value is X. */
570 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
572 /* Enumeration returned by some move_it_.* functions internally. */
576 /* Not used. Undefined value. */
579 /* Move ended at the requested buffer position or ZV. */
580 MOVE_POS_MATCH_OR_ZV
,
582 /* Move ended at the requested X pixel position. */
585 /* Move within a line ended at the end of a line that must be
589 /* Move within a line ended at the end of a line that would
590 be displayed truncated. */
593 /* Move within a line ended at a line end. */
599 /* Function prototypes. */
601 static int string_char_and_length
P_ ((unsigned char *, int, int *));
602 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
604 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
605 static Lisp_Object eval_handler
P_ ((Lisp_Object
));
606 static Lisp_Object eval_form
P_ ((Lisp_Object
));
607 static void insert_left_trunc_glyphs
P_ ((struct it
*));
608 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
609 static void extend_face_to_end_of_line
P_ ((struct it
*));
610 static void append_space
P_ ((struct it
*, int));
611 static void make_cursor_line_fully_visible
P_ ((struct window
*));
612 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
613 static int trailing_whitespace_p
P_ ((int));
614 static int message_log_check_duplicate
P_ ((int, int, int, int));
615 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
616 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
617 static void push_it
P_ ((struct it
*));
618 static void pop_it
P_ ((struct it
*));
619 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
620 static void redisplay_internal
P_ ((int));
621 static void echo_area_display
P_ ((int));
622 static void redisplay_windows
P_ ((Lisp_Object
));
623 static void redisplay_window
P_ ((Lisp_Object
, int));
624 static void update_menu_bar
P_ ((struct frame
*, int));
625 static int try_window_reusing_current_matrix
P_ ((struct window
*));
626 static int try_window_id
P_ ((struct window
*));
627 static int display_line
P_ ((struct it
*));
628 static void display_mode_lines
P_ ((struct window
*));
629 static void display_mode_line
P_ ((struct window
*, enum face_id
,
631 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
632 static char *decode_mode_spec
P_ ((struct window
*, char, int, int));
633 static void display_menu_bar
P_ ((struct window
*));
634 static int display_count_lines
P_ ((int, int, int, int, int *));
635 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
636 int, int, struct it
*, int, int, int, int));
637 static void compute_line_metrics
P_ ((struct it
*));
638 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
639 static int get_overlay_strings
P_ ((struct it
*));
640 static void next_overlay_string
P_ ((struct it
*));
641 void set_iterator_to_next
P_ ((struct it
*));
642 static void reseat
P_ ((struct it
*, struct text_pos
, int));
643 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
644 static void back_to_previous_visible_line_start
P_ ((struct it
*));
645 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
646 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
647 static int next_element_from_display_vector
P_ ((struct it
*));
648 static int next_element_from_string
P_ ((struct it
*));
649 static int next_element_from_c_string
P_ ((struct it
*));
650 static int next_element_from_buffer
P_ ((struct it
*));
651 static int next_element_from_image
P_ ((struct it
*));
652 static int next_element_from_stretch
P_ ((struct it
*));
653 static void load_overlay_strings
P_ ((struct it
*));
654 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
655 struct display_pos
*));
656 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
657 Lisp_Object
, int, int, int, int));
658 static int charset_at_position
P_ ((struct text_pos
));
659 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
661 void move_it_vertically_backward
P_ ((struct it
*, int));
662 static void init_to_row_start
P_ ((struct it
*, struct window
*,
663 struct glyph_row
*));
664 static void init_to_row_end
P_ ((struct it
*, struct window
*,
665 struct glyph_row
*));
666 static void back_to_previous_line_start
P_ ((struct it
*));
667 static void forward_to_next_line_start
P_ ((struct it
*));
668 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
670 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
671 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
672 static int number_of_chars
P_ ((unsigned char *, int));
673 static void compute_stop_pos
P_ ((struct it
*));
674 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
676 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
677 static int next_overlay_change
P_ ((int));
678 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
679 Lisp_Object
, struct text_pos
*));
681 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
682 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
684 #ifdef HAVE_WINDOW_SYSTEM
686 static void update_toolbar
P_ ((struct frame
*, int));
687 static void build_desired_toolbar_string
P_ ((struct frame
*f
));
688 static int redisplay_toolbar
P_ ((struct frame
*));
689 static void display_toolbar_line
P_ ((struct it
*));
691 #endif /* HAVE_WINDOW_SYSTEM */
694 /***********************************************************************
695 Window display dimensions
696 ***********************************************************************/
698 /* Return the window-relative maximum y + 1 for glyph rows displaying
699 text in window W. This is the height of W minus the height of a
700 mode line, if any. */
703 window_text_bottom_y (w
)
706 struct frame
*f
= XFRAME (w
->frame
);
707 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
709 if (WINDOW_WANTS_MODELINE_P (w
))
710 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
715 /* Return the pixel width of display area AREA of window W. AREA < 0
716 means return the total width of W, not including bitmap areas to
717 the left and right of the window. */
720 window_box_width (w
, area
)
724 struct frame
*f
= XFRAME (w
->frame
);
725 int width
= XFASTINT (w
->width
);
727 if (!w
->pseudo_window_p
)
729 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + 2 * FRAME_FLAGS_AREA_COLS (f
);
731 if (area
== TEXT_AREA
)
733 if (INTEGERP (w
->left_margin_width
))
734 width
-= XFASTINT (w
->left_margin_width
);
735 if (INTEGERP (w
->right_margin_width
))
736 width
-= XFASTINT (w
->right_margin_width
);
738 else if (area
== LEFT_MARGIN_AREA
)
739 width
= (INTEGERP (w
->left_margin_width
)
740 ? XFASTINT (w
->left_margin_width
) : 0);
741 else if (area
== RIGHT_MARGIN_AREA
)
742 width
= (INTEGERP (w
->right_margin_width
)
743 ? XFASTINT (w
->right_margin_width
) : 0);
746 return width
* CANON_X_UNIT (f
);
750 /* Return the pixel height of the display area of window W, not
751 including mode lines of W, if any.. */
754 window_box_height (w
)
757 struct frame
*f
= XFRAME (w
->frame
);
758 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
760 if (WINDOW_WANTS_MODELINE_P (w
))
761 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
763 if (WINDOW_WANTS_TOP_LINE_P (w
))
764 height
-= CURRENT_TOP_LINE_HEIGHT (w
);
770 /* Return the frame-relative coordinate of the left edge of display
771 area AREA of window W. AREA < 0 means return the left edge of the
772 whole window, to the right of any bitmap area at the left side of
776 window_box_left (w
, area
)
780 struct frame
*f
= XFRAME (w
->frame
);
781 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
783 if (!w
->pseudo_window_p
)
785 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
786 + FRAME_FLAGS_AREA_WIDTH (f
));
788 if (area
== TEXT_AREA
)
789 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
790 else if (area
== RIGHT_MARGIN_AREA
)
791 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
792 + window_box_width (w
, TEXT_AREA
));
799 /* Return the frame-relative coordinate of the right edge of display
800 area AREA of window W. AREA < 0 means return the left edge of the
801 whole window, to the left of any bitmap area at the right side of
805 window_box_right (w
, area
)
809 return window_box_left (w
, area
) + window_box_width (w
, area
);
813 /* Get the bounding box of the display area AREA of window W, without
814 mode lines, in frame-relative coordinates. AREA < 0 means the
815 whole window, not including bitmap areas to the left and right of
816 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
817 coordinates of the upper-left corner of the box. Return in
818 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
821 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
824 int *box_x
, *box_y
, *box_width
, *box_height
;
826 struct frame
*f
= XFRAME (w
->frame
);
828 *box_width
= window_box_width (w
, area
);
829 *box_height
= window_box_height (w
);
830 *box_x
= window_box_left (w
, area
);
831 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
832 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
833 if (WINDOW_WANTS_TOP_LINE_P (w
))
834 *box_y
+= CURRENT_TOP_LINE_HEIGHT (w
);
838 /* Get the bounding box of the display area AREA of window W, without
839 mode lines. AREA < 0 means the whole window, not including bitmap
840 areas to the left and right of the window. Return in *TOP_LEFT_X
841 and TOP_LEFT_Y the frame-relative pixel coordinates of the
842 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
843 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
847 window_box_edges (w
, area
, top_left_x
, top_left_y
,
848 bottom_right_x
, bottom_right_y
)
851 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
853 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
855 *bottom_right_x
+= *top_left_x
;
856 *bottom_right_y
+= *top_left_y
;
861 /***********************************************************************
863 ***********************************************************************/
865 /* Return the next character from STR which is MAXLEN bytes long.
866 Return in *LEN the length of the character. This is like
867 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
868 we find one, we return a `?', but with the length of the illegal
872 string_char_and_length (str
, maxlen
, len
)
878 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
879 if (!CHAR_VALID_P (c
, 1))
880 /* We may not change the length here because other places in Emacs
881 don't use this function, i.e. they silently accept illegal
890 /* Given a position POS containing a valid character and byte position
891 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
893 static struct text_pos
894 string_pos_nchars_ahead (pos
, string
, nchars
)
899 xassert (STRINGP (string
) && nchars
>= 0);
901 if (STRING_MULTIBYTE (string
))
903 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
904 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
909 string_char_and_length (p
, rest
, &len
);
910 p
+= len
, rest
-= len
;
913 BYTEPOS (pos
) += len
;
917 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
923 /* Value is the text position, i.e. character and byte position,
924 for character position CHARPOS in STRING. */
926 static INLINE
struct text_pos
927 string_pos (charpos
, string
)
932 xassert (STRINGP (string
));
933 xassert (charpos
>= 0);
934 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
939 /* Value is a text position, i.e. character and byte position, for
940 character position CHARPOS in C string S. MULTIBYTE_P non-zero
941 means recognize multibyte characters. */
943 static struct text_pos
944 c_string_pos (charpos
, s
, multibyte_p
)
952 xassert (charpos
>= 0);
956 int rest
= strlen (s
), len
;
958 SET_TEXT_POS (pos
, 0, 0);
961 string_char_and_length (s
, rest
, &len
);
962 s
+= len
, rest
-= len
;
965 BYTEPOS (pos
) += len
;
969 SET_TEXT_POS (pos
, charpos
, charpos
);
975 /* Value is the number of characters in C string S. MULTIBYTE_P
976 non-zero means recognize multibyte characters. */
979 number_of_chars (s
, multibyte_p
)
987 int rest
= strlen (s
), len
;
988 unsigned char *p
= (unsigned char *) s
;
990 for (nchars
= 0; rest
> 0; ++nchars
)
992 string_char_and_length (p
, rest
, &len
);
993 rest
-= len
, p
+= len
;
1003 /* Compute byte position NEWPOS->bytepos corresponding to
1004 NEWPOS->charpos. POS is a known position in string STRING.
1005 NEWPOS->charpos must be >= POS.charpos. */
1008 compute_string_pos (newpos
, pos
, string
)
1009 struct text_pos
*newpos
, pos
;
1012 xassert (STRINGP (string
));
1013 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1015 if (STRING_MULTIBYTE (string
))
1016 *newpos
= string_pos_nchars_ahead (pos
, CHARPOS (*newpos
) - CHARPOS (pos
),
1019 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1023 /* Return the charset of the character at position POS in
1027 charset_at_position (pos
)
1028 struct text_pos pos
;
1031 unsigned char *p
= BYTE_POS_ADDR (BYTEPOS (pos
));
1033 multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1036 int maxlen
= ((BYTEPOS (pos
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
1039 c
= string_char_and_length (p
, maxlen
, &len
);
1044 return CHAR_CHARSET (c
);
1049 /***********************************************************************
1050 Lisp form evaluation
1051 ***********************************************************************/
1053 /* Error handler for eval_form. */
1063 /* Evaluate SEXPR and return the result, or nil if something went
1070 int count
= specpdl_ptr
- specpdl
;
1072 specbind (Qinhibit_redisplay
, Qt
);
1073 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, eval_handler
);
1074 return unbind_to (count
, val
);
1079 /***********************************************************************
1081 ***********************************************************************/
1085 /* Define CHECK_IT to perform sanity checks on iterators.
1086 This is for debugging. It is too slow to do unconditionally. */
1092 if (it
->method
== next_element_from_string
)
1094 xassert (STRINGP (it
->string
));
1095 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1097 else if (it
->method
== next_element_from_buffer
)
1099 /* Check that character and byte positions agree. */
1100 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1104 xassert (it
->current
.dpvec_index
>= 0);
1106 xassert (it
->current
.dpvec_index
< 0);
1109 #define CHECK_IT(IT) check_it ((IT))
1113 #define CHECK_IT(IT) (void) 0
1120 /* Check that the window end of window W is what we expect it
1121 to be---the last row in the current matrix displaying text. */
1124 check_window_end (w
)
1127 if (!MINI_WINDOW_P (w
)
1128 && !NILP (w
->window_end_valid
))
1130 struct glyph_row
*row
;
1131 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1132 XFASTINT (w
->window_end_vpos
)),
1134 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1135 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1139 #define CHECK_WINDOW_END(W) check_window_end ((W))
1141 #else /* not GLYPH_DEBUG */
1143 #define CHECK_WINDOW_END(W) (void) 0
1145 #endif /* not GLYPH_DEBUG */
1149 /***********************************************************************
1150 Iterator initialization
1151 ***********************************************************************/
1153 /* Initialize IT for displaying current_buffer in window W, starting
1154 at character position CHARPOS. CHARPOS < 0 means that no buffer
1155 position is specified which is useful when the iterator is assigned
1156 a position later. BYTEPOS is the byte position corresponding to
1157 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1159 If ROW is not null, calls to produce_glyphs with IT as parameter
1160 will produce glyphs in that row.
1162 BASE_FACE_ID is the id of a base face to use. It must be one of
1163 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1164 TOP_LINE_FACE_ID for displaying mode lines, or TOOLBAR_FACE_ID for
1165 displaying the toolbar.
1167 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1168 TOP_LINE_FACE_ID, the iterator will be initialized to use the
1169 corresponding mode line glyph row of the desired matrix of W. */
1172 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1175 int charpos
, bytepos
;
1176 struct glyph_row
*row
;
1177 enum face_id base_face_id
;
1179 int highlight_region_p
;
1182 /* Some precondition checks. */
1183 xassert (w
!= NULL
&& it
!= NULL
);
1184 xassert (charpos
< 0 || current_buffer
== XBUFFER (w
->buffer
));
1185 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1187 /* If face attributes have been changed since the last redisplay,
1188 free realized faces now because they depend on face definitions
1189 that might have changed. */
1190 if (face_change_count
)
1192 face_change_count
= 0;
1193 free_all_realized_faces (Qnil
);
1196 /* Use one of the mode line rows of W's desired matrix if
1200 if (base_face_id
== MODE_LINE_FACE_ID
)
1201 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1202 else if (base_face_id
== TOP_LINE_FACE_ID
)
1203 row
= MATRIX_TOP_LINE_ROW (w
->desired_matrix
);
1207 bzero (it
, sizeof *it
);
1208 it
->current
.overlay_string_index
= -1;
1209 it
->current
.dpvec_index
= -1;
1210 it
->charset
= CHARSET_ASCII
;
1211 it
->base_face_id
= base_face_id
;
1213 /* The window in which we iterate over current_buffer: */
1214 XSETWINDOW (it
->window
, w
);
1216 it
->f
= XFRAME (w
->frame
);
1218 /* If realized faces have been removed, e.g. because of face
1219 attribute changes of named faces, recompute them. */
1220 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1221 recompute_basic_faces (it
->f
);
1223 /* Should we highlight trailing whitespace? */
1224 value
= find_symbol_value (Qshow_trailing_whitespace
);
1225 it
->show_trailing_whitespace_p
1226 = EQ (value
, Qunbound
) ? 0 : !NILP (value
);
1228 /* Current value of the `space-width', and 'height' properties. */
1229 it
->space_width
= Qnil
;
1230 it
->font_height
= Qnil
;
1232 /* Are control characters displayed as `^C'? */
1233 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1235 /* -1 means everything between a CR and the following line end
1236 is invisible. >0 means lines indented more than this value are
1238 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1239 ? XFASTINT (current_buffer
->selective_display
)
1240 : (!NILP (current_buffer
->selective_display
)
1242 it
->selective_display_ellipsis_p
1243 = !NILP (current_buffer
->selective_display_ellipses
);
1245 /* Display table to use. */
1246 it
->dp
= window_display_table (w
);
1248 /* Are multibyte characters enabled in current_buffer? */
1249 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1251 /* Non-zero if we should highlight the region. */
1253 = (!NILP (Vtransient_mark_mode
)
1254 && !NILP (current_buffer
->mark_active
)
1255 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1257 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1258 start and end of a visible region in window IT->w. Set both to
1259 -1 to indicate no region. */
1260 if (highlight_region_p
1261 /* Maybe highlight only in selected window. */
1262 && (/* Either show region everywhere. */
1263 highlight_nonselected_windows
1264 /* Or show region in the selected window. */
1265 || w
== XWINDOW (selected_window
)
1266 /* Or show the region if we are in the mini-buffer and W is
1267 the window the mini-buffer refers to. */
1268 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1269 && w
== XWINDOW (Vminibuf_scroll_window
))))
1271 int charpos
= marker_position (current_buffer
->mark
);
1272 it
->region_beg_charpos
= min (PT
, charpos
);
1273 it
->region_end_charpos
= max (PT
, charpos
);
1276 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1278 /* Get the position at which the redisplay_end_trigger hook should
1279 be run, if it is to be run at all. */
1280 if (MARKERP (w
->redisplay_end_trigger
)
1281 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1282 it
->redisplay_end_trigger_charpos
1283 = marker_position (w
->redisplay_end_trigger
);
1284 else if (INTEGERP (w
->redisplay_end_trigger
))
1285 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1287 /* Correct bogus values of tab_width. */
1288 it
->tab_width
= XINT (current_buffer
->tab_width
);
1289 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1292 /* Are lines in the display truncated? */
1293 it
->truncate_lines_p
1294 = (base_face_id
!= DEFAULT_FACE_ID
1295 || XINT (it
->w
->hscroll
)
1296 || (truncate_partial_width_windows
1297 && !WINDOW_FULL_WIDTH_P (it
->w
))
1298 || !NILP (current_buffer
->truncate_lines
));
1300 /* Get dimensions of truncation and continuation glyphs. These are
1301 displayed as bitmaps under X, so we don't need them for such
1303 if (!FRAME_WINDOW_P (it
->f
))
1305 if (it
->truncate_lines_p
)
1307 /* We will need the truncation glyph. */
1308 xassert (it
->glyph_row
== NULL
);
1309 produce_special_glyphs (it
, IT_TRUNCATION
);
1310 it
->truncation_pixel_width
= it
->pixel_width
;
1314 /* We will need the continuation glyph. */
1315 xassert (it
->glyph_row
== NULL
);
1316 produce_special_glyphs (it
, IT_CONTINUATION
);
1317 it
->continuation_pixel_width
= it
->pixel_width
;
1320 /* Reset these values to zero becaue the produce_special_glyphs
1321 above has changed them. */
1322 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1323 it
->phys_ascent
= it
->phys_descent
= 0;
1326 /* Set this after getting the dimensions of truncation and
1327 continuation glyphs, so that we don't produce glyphs when calling
1328 produce_special_glyphs, above. */
1329 it
->glyph_row
= row
;
1330 it
->area
= TEXT_AREA
;
1332 /* Get the dimensions of the display area. The display area
1333 consists of the visible window area plus a horizontally scrolled
1334 part to the left of the window. All x-values are relative to the
1335 start of this total display area. */
1336 if (base_face_id
!= DEFAULT_FACE_ID
)
1338 /* Mode lines, menu bar in terminal frames. */
1339 it
->first_visible_x
= 0;
1340 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1345 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1346 it
->last_visible_x
= (it
->first_visible_x
1347 + window_box_width (w
, TEXT_AREA
));
1349 /* If we truncate lines, leave room for the truncator glyph(s) at
1350 the right margin. Otherwise, leave room for the continuation
1351 glyph(s). Truncation and continuation glyphs are not inserted
1352 for window-based redisplay. */
1353 if (!FRAME_WINDOW_P (it
->f
))
1355 if (it
->truncate_lines_p
)
1356 it
->last_visible_x
-= it
->truncation_pixel_width
;
1358 it
->last_visible_x
-= it
->continuation_pixel_width
;
1361 it
->top_line_p
= WINDOW_WANTS_TOP_LINE_P (w
);
1362 it
->current_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
) + w
->vscroll
;
1365 /* Leave room for a border glyph. */
1366 if (!FRAME_WINDOW_P (it
->f
)
1367 && !WINDOW_RIGHTMOST_P (it
->w
))
1368 it
->last_visible_x
-= 1;
1370 it
->last_visible_y
= window_text_bottom_y (w
);
1372 /* For mode lines and alike, arrange for the first glyph having a
1373 left box line if the face specifies a box. */
1374 if (base_face_id
!= DEFAULT_FACE_ID
)
1378 it
->face_id
= base_face_id
;
1380 /* If we have a boxed mode line, make the first character appear
1381 with a left box line. */
1382 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1383 if (face
->box
!= FACE_NO_BOX
)
1384 it
->start_of_box_run_p
= 1;
1387 /* If a buffer position was specified, set the iterator there,
1388 getting overlays and face properties from that position. */
1391 it
->end_charpos
= ZV
;
1393 IT_CHARPOS (*it
) = charpos
;
1395 /* Compute byte position if not specified. */
1397 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1399 IT_BYTEPOS (*it
) = bytepos
;
1401 /* Compute faces etc. */
1402 reseat (it
, it
->current
.pos
, 1);
1409 /* Initialize IT for the display of window W with window start POS. */
1412 start_display (it
, w
, pos
)
1415 struct text_pos pos
;
1417 int start_at_line_beg_p
;
1418 struct glyph_row
*row
;
1419 int first_vpos
= WINDOW_WANTS_TOP_LINE_P (w
) ? 1 : 0;
1422 row
= w
->desired_matrix
->rows
+ first_vpos
;
1423 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1424 first_y
= it
->current_y
;
1426 /* If window start is not at a line start, move back to the line
1427 start. This makes sure that we take continuation lines into
1429 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1430 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1431 if (!start_at_line_beg_p
)
1432 reseat_at_previous_visible_line_start (it
);
1434 #if NO_PROMPT_IN_BUFFER
1435 /* Take the mini-buffer prompt width into account for tab
1437 if (MINI_WINDOW_P (w
) && IT_CHARPOS (*it
) == BEGV
)
1439 /* Why is mini-buffer_prompt_width guaranteed to be set here? */
1440 it
->prompt_width
= minibuf_prompt_pixel_width
;
1442 #endif /* NO_PROMPT_IN_BUFFER */
1444 /* If window start is not at a line start, skip forward to POS to
1445 get the correct continuation_lines_width and current_x. */
1446 if (!start_at_line_beg_p
)
1448 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1450 /* If lines are continued, this line may end in the middle of a
1451 multi-glyph character (e.g. a control character displayed as
1452 \003, or in the middle of an overlay string). In this case
1453 move_it_to above will not have taken us to the start of
1454 the continuation line but to the end of the continued line. */
1455 if (!it
->truncate_lines_p
&& it
->current_x
> 0)
1457 if (it
->current
.dpvec_index
>= 0
1458 || it
->current
.overlay_string_index
>= 0)
1460 set_iterator_to_next (it
);
1461 move_it_in_display_line_to (it
, -1, -1, 0);
1463 it
->continuation_lines_width
+= it
->current_x
;
1466 it
->current_y
= first_y
;
1468 it
->current_x
= it
->hpos
= 0;
1471 #if 0 /* Don't assert the following because start_display is sometimes
1472 called intentionally with a window start that is not at a
1473 line start. Please leave this code in as a comment. */
1475 /* Window start should be on a line start, now. */
1476 xassert (it
->continuation_lines_width
1477 || IT_CHARPOS (it
) == BEGV
1478 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1483 /* Initialize IT for stepping through current_buffer in window W,
1484 starting at position POS that includes overlay string and display
1485 vector/ control character translation position information. */
1488 init_from_display_pos (it
, w
, pos
)
1491 struct display_pos
*pos
;
1493 /* Keep in mind: the call to reseat in init_iterator skips invisible
1494 text, so we might end up at a position different from POS. This
1495 is only a problem when POS is a row start after a newline and an
1496 overlay starts there with an after-string, and the overlay has an
1497 invisible property. Since we don't skip invisible text in
1498 display_line and elsewhere immediately after consuming the
1499 newline before the row start, such a POS will not be in a string,
1500 but the call to init_iterator below will move us to the
1502 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1503 NULL
, DEFAULT_FACE_ID
);
1505 /* If position is within an overlay string, set up IT to
1506 the right overlay string. */
1507 if (pos
->overlay_string_index
>= 0)
1511 /* We already have the first chunk of overlay strings in
1512 IT->overlay_strings. Load more until the one for
1513 pos->overlay_string_index is in IT->overlay_strings. */
1514 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1516 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1517 it
->current
.overlay_string_index
= 0;
1520 load_overlay_strings (it
);
1521 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1525 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1526 relative_index
= (it
->current
.overlay_string_index
1527 % OVERLAY_STRING_CHUNK_SIZE
);
1528 it
->string
= it
->overlay_strings
[relative_index
];
1529 it
->current
.string_pos
= pos
->string_pos
;
1530 it
->method
= next_element_from_string
;
1532 else if (CHARPOS (pos
->string_pos
) >= 0)
1534 /* Recorded position is not in an overlay string, but in another
1535 string. This can only be a string from a `display' property.
1536 IT should already be filled with that string. */
1537 it
->current
.string_pos
= pos
->string_pos
;
1538 xassert (STRINGP (it
->string
));
1541 /* Restore position in display vector translations or control
1542 character translations. */
1543 if (pos
->dpvec_index
>= 0)
1545 /* This fills IT->dpvec. */
1546 get_next_display_element (it
);
1547 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1548 it
->current
.dpvec_index
= pos
->dpvec_index
;
1555 /* Initialize IT for stepping through current_buffer in window W
1556 starting at ROW->start. */
1559 init_to_row_start (it
, w
, row
)
1562 struct glyph_row
*row
;
1564 init_from_display_pos (it
, w
, &row
->start
);
1565 it
->continuation_lines_width
= row
->continuation_lines_width
;
1570 /* Initialize IT for stepping through current_buffer in window W
1571 starting in the line following ROW, i.e. starting at ROW->end. */
1574 init_to_row_end (it
, w
, row
)
1577 struct glyph_row
*row
;
1579 init_from_display_pos (it
, w
, &row
->end
);
1581 if (row
->continued_p
)
1582 it
->continuation_lines_width
= (row
->continuation_lines_width
1583 + row
->pixel_width
);
1590 /***********************************************************************
1592 ***********************************************************************/
1594 /* Called when IT reaches IT->stop_charpos. Handle text property and
1595 overlay changes. Set IT->stop_charpos to the next position where
1602 enum prop_handled handled
;
1603 int handle_overlay_change_p
= 1;
1607 it
->current
.dpvec_index
= -1;
1611 handled
= HANDLED_NORMALLY
;
1613 /* Call text property handlers. */
1614 for (p
= it_props
; p
->handler
; ++p
)
1616 handled
= p
->handler (it
);
1618 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1620 else if (handled
== HANDLED_RETURN
)
1622 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1623 handle_overlay_change_p
= 0;
1626 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1628 /* Don't check for overlay strings below when set to deliver
1629 characters from a display vector. */
1630 if (it
->method
== next_element_from_display_vector
)
1631 handle_overlay_change_p
= 0;
1633 /* Handle overlay changes. */
1634 if (handle_overlay_change_p
)
1635 handled
= handle_overlay_change (it
);
1637 /* Determine where to stop next. */
1638 if (handled
== HANDLED_NORMALLY
)
1639 compute_stop_pos (it
);
1642 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1646 /* Compute IT->stop_charpos from text property and overlay change
1647 information for IT's current position. */
1650 compute_stop_pos (it
)
1653 register INTERVAL iv
, next_iv
;
1654 Lisp_Object object
, limit
, position
;
1656 /* If nowhere else, stop at the end. */
1657 it
->stop_charpos
= it
->end_charpos
;
1659 if (STRINGP (it
->string
))
1661 /* Strings are usually short, so don't limit the search for
1663 object
= it
->string
;
1665 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1671 /* If next overlay change is in front of the current stop pos
1672 (which is IT->end_charpos), stop there. Note: value of
1673 next_overlay_change is point-max if no overlay change
1675 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1676 if (charpos
< it
->stop_charpos
)
1677 it
->stop_charpos
= charpos
;
1679 /* If showing the region, we have to stop at the region
1680 start or end because the face might change there. */
1681 if (it
->region_beg_charpos
> 0)
1683 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1684 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1685 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1686 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1689 /* Set up variables for computing the stop position from text
1690 property changes. */
1691 XSETBUFFER (object
, current_buffer
);
1692 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1693 XSETFASTINT (position
, IT_CHARPOS (*it
));
1697 /* Get the interval containing IT's position. Value is a null
1698 interval if there isn't such an interval. */
1699 iv
= validate_interval_range (object
, &position
, &position
, 0);
1700 if (!NULL_INTERVAL_P (iv
))
1702 Lisp_Object values_here
[LAST_PROP_IDX
];
1705 /* Get properties here. */
1706 for (p
= it_props
; p
->handler
; ++p
)
1707 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1709 /* Look for an interval following iv that has different
1711 for (next_iv
= next_interval (iv
);
1712 (!NULL_INTERVAL_P (next_iv
)
1714 || XFASTINT (limit
) > next_iv
->position
));
1715 next_iv
= next_interval (next_iv
))
1717 for (p
= it_props
; p
->handler
; ++p
)
1719 Lisp_Object new_value
;
1721 new_value
= textget (next_iv
->plist
, *p
->name
);
1722 if (!EQ (values_here
[p
->idx
], new_value
))
1730 if (!NULL_INTERVAL_P (next_iv
))
1732 if (INTEGERP (limit
)
1733 && next_iv
->position
>= XFASTINT (limit
))
1734 /* No text property change up to limit. */
1735 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1737 /* Text properties change in next_iv. */
1738 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1742 xassert (STRINGP (it
->string
)
1743 || (it
->stop_charpos
>= BEGV
1744 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1748 /* Return the position of the next overlay change after POS in
1749 current_buffer. Value is point-max if no overlay change
1750 follows. This is like `next-overlay-change' but doesn't use
1754 next_overlay_change (pos
)
1759 Lisp_Object
*overlays
;
1763 /* Get all overlays at the given position. */
1765 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1766 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1767 if (noverlays
> len
)
1770 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1771 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1774 /* If any of these overlays ends before endpos,
1775 use its ending point instead. */
1776 for (i
= 0; i
< noverlays
; ++i
)
1781 oend
= OVERLAY_END (overlays
[i
]);
1782 oendpos
= OVERLAY_POSITION (oend
);
1783 endpos
= min (endpos
, oendpos
);
1791 /***********************************************************************
1793 ***********************************************************************/
1795 /* Handle changes in the `fontified' property of the current buffer by
1796 calling hook functions from Qfontification_functions to fontify
1799 static enum prop_handled
1800 handle_fontified_prop (it
)
1803 Lisp_Object prop
, pos
;
1804 enum prop_handled handled
= HANDLED_NORMALLY
;
1806 /* Get the value of the `fontified' property at IT's current buffer
1807 position. (The `fontified' property doesn't have a special
1808 meaning in strings.) If the value is nil, call functions from
1809 Qfontification_functions. */
1810 if (!STRINGP (it
->string
)
1812 && !NILP (Vfontification_functions
)
1813 && (pos
= make_number (IT_CHARPOS (*it
)),
1814 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1817 Lisp_Object args
[2];
1819 /* Run the hook functions. */
1820 args
[0] = Qfontification_functions
;
1822 Frun_hook_with_args (make_number (2), args
);
1824 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
1825 something. This avoids an endless loop if they failed to
1826 fontify the text for which reason ever. */
1827 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
1828 handled
= HANDLED_RECOMPUTE_PROPS
;
1836 /***********************************************************************
1838 ***********************************************************************/
1840 /* Set up iterator IT from face properties at its current position.
1841 Called from handle_stop. */
1843 static enum prop_handled
1844 handle_face_prop (it
)
1847 int new_face_id
, next_stop
;
1849 if (!STRINGP (it
->string
))
1852 = face_at_buffer_position (it
->w
,
1854 it
->region_beg_charpos
,
1855 it
->region_end_charpos
,
1858 + TEXT_PROP_DISTANCE_LIMIT
),
1861 /* Is this a start of a run of characters with box face?
1862 Caveat: this can be called for a freshly initialized
1863 iterator; face_id is -1 is this case. We know that the new
1864 face will not change until limit, i.e. if the new face has a
1865 box, all characters up to limit will have one. But, as
1866 usual, we don't know whether limit is really the end. */
1867 if (new_face_id
!= it
->face_id
)
1869 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1871 /* If new face has a box but old face has not, this is
1872 the start of a run of characters with box, i.e. it has
1873 a shadow on the left side. The value of face_id of the
1874 iterator will be -1 if this is the initial call that gets
1875 the face. In this case, we have to look in front of IT's
1876 position and see whether there is a face != new_face_id. */
1877 it
->start_of_box_run_p
1878 = (new_face
->box
!= FACE_NO_BOX
1879 && (it
->face_id
>= 0
1880 || IT_CHARPOS (*it
) == BEG
1881 || new_face_id
!= face_before_it_pos (it
)));
1882 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1888 = face_at_string_position (it
->w
,
1890 IT_STRING_CHARPOS (*it
),
1891 (it
->current
.overlay_string_index
>= 0
1894 it
->region_beg_charpos
,
1895 it
->region_end_charpos
,
1899 #if 0 /* This shouldn't be neccessary. Let's check it. */
1900 /* If IT is used to display a mode line we would really like to
1901 use the mode line face instead of the frame's default face. */
1902 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
1903 && new_face_id
== DEFAULT_FACE_ID
)
1904 new_face_id
= MODE_LINE_FACE_ID
;
1907 /* Is this a start of a run of characters with box? Caveat:
1908 this can be called for a freshly allocated iterator; face_id
1909 is -1 is this case. We know that the new face will not
1910 change until the next check pos, i.e. if the new face has a
1911 box, all characters up to that position will have a
1912 box. But, as usual, we don't know whether that position
1913 is really the end. */
1914 if (new_face_id
!= it
->face_id
)
1916 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1917 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1919 /* If new face has a box but old face hasn't, this is the
1920 start of a run of characters with box, i.e. it has a
1921 shadow on the left side. */
1922 it
->start_of_box_run_p
1923 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
1924 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1928 it
->face_id
= new_face_id
;
1929 it
->charset
= CHARSET_ASCII
;
1930 return HANDLED_NORMALLY
;
1934 /* Compute the face one character before or after the current position
1935 of IT. BEFORE_P non-zero means get the face in front of IT's
1936 position. Value is the id of the face. */
1939 face_before_or_after_it_pos (it
, before_p
)
1944 int next_check_charpos
;
1945 struct text_pos pos
;
1947 xassert (it
->s
== NULL
);
1949 if (STRINGP (it
->string
))
1951 /* No face change past the end of the string (for the case
1952 we are padding with spaces). No face change before the
1954 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
1955 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
1958 /* Set pos to the position before or after IT's current position. */
1960 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
1962 pos
= string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
);
1964 /* Get the face for ASCII, or unibyte. */
1966 = face_at_string_position (it
->w
,
1969 (it
->current
.overlay_string_index
>= 0
1972 it
->region_beg_charpos
,
1973 it
->region_end_charpos
,
1974 &next_check_charpos
,
1977 /* Correct the face for charsets different from ASCII. Do it
1978 for the multibyte case only. The face returned above is
1979 suitable for unibyte text if IT->string is unibyte. */
1980 if (STRING_MULTIBYTE (it
->string
))
1982 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
1983 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
1984 int c
, len
, charset
;
1986 c
= string_char_and_length (p
, rest
, &len
);
1987 charset
= CHAR_CHARSET (c
);
1988 if (charset
!= CHARSET_ASCII
)
1989 face_id
= FACE_FOR_CHARSET (it
->f
, face_id
, charset
);
1994 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
1995 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
1998 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
1999 pos
= it
->current
.pos
;
2006 /* Determine face for CHARSET_ASCII, or unibyte. */
2007 face_id
= face_at_buffer_position (it
->w
,
2009 it
->region_beg_charpos
,
2010 it
->region_end_charpos
,
2011 &next_check_charpos
,
2014 /* Correct the face for charsets different from ASCII. Do it
2015 for the multibyte case only. The face returned above is
2016 suitable for unibyte text if current_buffer is unibyte. */
2017 if (it
->multibyte_p
)
2019 int charset
= charset_at_position (pos
);
2020 if (charset
!= CHARSET_ASCII
)
2021 face_id
= FACE_FOR_CHARSET (it
->f
, face_id
, charset
);
2030 /***********************************************************************
2032 ***********************************************************************/
2034 /* Set up iterator IT from invisible properties at its current
2035 position. Called from handle_stop. */
2037 static enum prop_handled
2038 handle_invisible_prop (it
)
2041 enum prop_handled handled
= HANDLED_NORMALLY
;
2043 if (STRINGP (it
->string
))
2045 extern Lisp_Object Qinvisible
;
2046 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2048 /* Get the value of the invisible text property at the
2049 current position. Value will be nil if there is no such
2051 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2052 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2056 handled
= HANDLED_RECOMPUTE_PROPS
;
2058 /* Get the position at which the next change of the
2059 invisible text property can be found in IT->string.
2060 Value will be nil if the property value is the same for
2061 all the rest of IT->string. */
2062 XSETINT (limit
, XSTRING (it
->string
)->size
);
2063 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2066 /* Text at current position is invisible. The next
2067 change in the property is at position end_charpos.
2068 Move IT's current position to that position. */
2069 if (INTEGERP (end_charpos
)
2070 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2072 struct text_pos old
;
2073 old
= it
->current
.string_pos
;
2074 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2075 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2079 /* The rest of the string is invisible. If this is an
2080 overlay string, proceed with the next overlay string
2081 or whatever comes and return a character from there. */
2082 if (it
->current
.overlay_string_index
>= 0)
2084 next_overlay_string (it
);
2085 /* Don't check for overlay strings when we just
2086 finished processing them. */
2087 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2091 struct Lisp_String
*s
= XSTRING (it
->string
);
2092 IT_STRING_CHARPOS (*it
) = s
->size
;
2093 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2100 int visible_p
, newpos
, next_stop
;
2101 Lisp_Object pos
, prop
;
2103 /* First of all, is there invisible text at this position? */
2104 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2105 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2107 /* If we are on invisible text, skip over it. */
2108 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
2110 /* Record whether we have to display an ellipsis for the
2112 int display_ellipsis_p
2113 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2115 handled
= HANDLED_RECOMPUTE_PROPS
;
2117 /* Loop skipping over invisible text. The loop is left at
2118 ZV or with IT on the first char being visible again. */
2121 /* Try to skip some invisible text. Return value is the
2122 position reached which can be equal to IT's position
2123 if there is nothing invisible here. This skips both
2124 over invisible text properties and overlays with
2125 invisible property. */
2126 newpos
= skip_invisible (IT_CHARPOS (*it
),
2127 &next_stop
, ZV
, it
->window
);
2129 /* If we skipped nothing at all we weren't at invisible
2130 text in the first place. If everything to the end of
2131 the buffer was skipped, end the loop. */
2132 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2136 /* We skipped some characters but not necessarily
2137 all there are. Check if we ended up on visible
2138 text. Fget_char_property returns the property of
2139 the char before the given position, i.e. if we
2140 get visible_p = 1, this means that the char at
2141 newpos is visible. */
2142 XSETFASTINT (pos
, newpos
);
2143 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2144 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2147 /* If we ended up on invisible text, proceed to
2148 skip starting with next_stop. */
2150 IT_CHARPOS (*it
) = next_stop
;
2154 /* The position newpos is now either ZV or on visible text. */
2155 IT_CHARPOS (*it
) = newpos
;
2156 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2158 /* Maybe return `...' next for the end of the invisible text. */
2159 if (display_ellipsis_p
)
2162 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2164 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2165 it
->dpvec
= v
->contents
;
2166 it
->dpend
= v
->contents
+ v
->size
;
2170 /* Default `...'. */
2171 it
->dpvec
= default_invis_vector
;
2172 it
->dpend
= default_invis_vector
+ 3;
2175 /* The ellipsis display does not replace the display of
2176 the character at the new position. Indicate this by
2177 setting IT->dpvec_char_len to zero. */
2178 it
->dpvec_char_len
= 0;
2180 it
->current
.dpvec_index
= 0;
2181 it
->method
= next_element_from_display_vector
;
2191 /***********************************************************************
2193 ***********************************************************************/
2195 /* Set up iterator IT from `display' property at its current position.
2196 Called from handle_stop. */
2198 static enum prop_handled
2199 handle_display_prop (it
)
2202 Lisp_Object prop
, object
;
2203 struct text_pos
*position
;
2204 int space_or_image_found_p
;
2206 if (STRINGP (it
->string
))
2208 object
= it
->string
;
2209 position
= &it
->current
.string_pos
;
2214 position
= &it
->current
.pos
;
2217 /* Reset those iterator values set from display property values. */
2218 it
->font_height
= Qnil
;
2219 it
->space_width
= Qnil
;
2222 /* We don't support recursive `display' properties, i.e. string
2223 values that have a string `display' property, that have a string
2224 `display' property etc. */
2225 if (!it
->string_from_display_prop_p
)
2226 it
->area
= TEXT_AREA
;
2228 prop
= Fget_char_property (make_number (position
->charpos
),
2231 return HANDLED_NORMALLY
;
2233 space_or_image_found_p
= 0;
2234 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2236 while (CONSP (prop
))
2238 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2239 space_or_image_found_p
= 1;
2243 else if (VECTORP (prop
))
2246 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2247 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2249 space_or_image_found_p
= 1;
2253 if (handle_single_display_prop (it
, prop
, object
, position
))
2254 space_or_image_found_p
= 1;
2257 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2261 /* Value is the position of the end of the `display' property stating
2262 at START_POS in OBJECT. */
2264 static struct text_pos
2265 display_prop_end (it
, object
, start_pos
)
2268 struct text_pos start_pos
;
2271 struct text_pos end_pos
;
2273 /* Characters having this form of property are not displayed, so
2274 we have to find the end of the property. */
2275 end
= Fnext_single_property_change (make_number (start_pos
.charpos
),
2276 Qdisplay
, object
, Qnil
);
2279 /* A nil value of `end' means there are no changes of the
2280 property to the end of the buffer or string. */
2281 if (it
->current
.overlay_string_index
>= 0)
2282 end_pos
.charpos
= XSTRING (it
->string
)->size
;
2284 end_pos
.charpos
= it
->end_charpos
;
2287 end_pos
.charpos
= XFASTINT (end
);
2289 if (STRINGP (it
->string
))
2290 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2292 end_pos
.bytepos
= CHAR_TO_BYTE (end_pos
.charpos
);
2298 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2299 is the object in which the `display' property was found. *POSITION
2300 is the position at which it was found.
2302 If PROP is a `space' or `image' sub-property, set *POSITION to the
2303 end position of the `display' property.
2305 Value is non-zero if a `space' or `image' property value was found. */
2308 handle_single_display_prop (it
, prop
, object
, position
)
2312 struct text_pos
*position
;
2315 int space_or_image_found_p
= 0;
2319 /* If PROP is a list of the form `(:when FORM VALUE)', FORM is
2320 evaluated. If the result is nil, VALUE is ignored. */
2322 if (CONSP (prop
) && EQ (XCAR (prop
), QCwhen
))
2334 if (!NILP (form
) && !EQ (form
, Qt
))
2336 struct gcpro gcpro1
;
2337 struct text_pos end_pos
, pt
;
2339 end_pos
= display_prop_end (it
, object
, *position
);
2342 /* Temporarily set point to the end position, and then evaluate
2343 the form. This makes `(eolp)' work as FORM. */
2345 BYTEPOS (pt
) = PT_BYTE
;
2346 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2347 form
= eval_form (form
);
2348 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2356 && EQ (XCAR (prop
), Qheight
)
2357 && CONSP (XCDR (prop
)))
2359 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2362 /* `(height HEIGHT)'. */
2363 it
->font_height
= XCAR (XCDR (prop
));
2364 if (!NILP (it
->font_height
))
2366 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2367 int new_height
= -1;
2369 if (CONSP (it
->font_height
)
2370 && (EQ (XCAR (it
->font_height
), Qplus
)
2371 || EQ (XCAR (it
->font_height
), Qminus
))
2372 && CONSP (XCDR (it
->font_height
))
2373 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2375 /* `(+ N)' or `(- N)' where N is an integer. */
2376 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2377 if (EQ (XCAR (it
->font_height
), Qplus
))
2379 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2381 else if (SYMBOLP (it
->font_height
))
2383 /* Call function with current height as argument.
2384 Value is the new height. */
2385 Lisp_Object form
, height
;
2386 struct gcpro gcpro1
;
2388 height
= face
->lface
[LFACE_HEIGHT_INDEX
];
2389 form
= Fcons (it
->font_height
, Fcons (height
, Qnil
));
2391 height
= eval_form (form
);
2392 if (NUMBERP (height
))
2393 new_height
= XFLOATINT (height
);
2396 else if (NUMBERP (it
->font_height
))
2398 /* Value is a multiple of the canonical char height. */
2401 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2402 new_height
= (XFLOATINT (it
->font_height
)
2403 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2407 /* Evaluate IT->font_height with `height' bound to the
2408 current specified height to get the new height. */
2410 int count
= specpdl_ptr
- specpdl
;
2412 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2413 value
= eval_form (it
->font_height
);
2414 unbind_to (count
, Qnil
);
2416 if (NUMBERP (value
))
2417 new_height
= XFLOATINT (value
);
2421 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2424 else if (CONSP (prop
)
2425 && EQ (XCAR (prop
), Qspace_width
)
2426 && CONSP (XCDR (prop
)))
2428 /* `(space_width WIDTH)'. */
2429 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2432 value
= XCAR (XCDR (prop
));
2433 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2434 it
->space_width
= value
;
2436 else if (CONSP (prop
)
2437 && EQ (XCAR (prop
), Qraise
)
2438 && CONSP (XCDR (prop
)))
2440 #ifdef HAVE_WINDOW_SYSTEM
2441 /* `(raise FACTOR)'. */
2442 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2445 value
= XCAR (XCDR (prop
));
2446 if (NUMBERP (value
))
2448 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2449 it
->voffset
= - (XFLOATINT (value
)
2450 * (face
->font
->ascent
+ face
->font
->descent
));
2452 #endif /* HAVE_WINDOW_SYSTEM */
2454 else if (!it
->string_from_display_prop_p
)
2456 /* `(left-margin VALUE)' or `(right-margin VALUE)
2457 or `(nil VALUE)' or VALUE. */
2458 Lisp_Object location
, value
;
2459 struct text_pos start_pos
;
2462 /* Characters having this form of property are not displayed, so
2463 we have to find the end of the property. */
2464 space_or_image_found_p
= 1;
2465 start_pos
= *position
;
2466 *position
= display_prop_end (it
, object
, start_pos
);
2468 /* Let's stop at the new position and assume that all
2469 text properties change there. */
2470 it
->stop_charpos
= position
->charpos
;
2473 && !EQ (XCAR (prop
), Qspace
)
2474 && !EQ (XCAR (prop
), Qimage
))
2476 location
= XCAR (prop
);
2477 value
= XCDR (prop
);
2485 #ifdef HAVE_WINDOW_SYSTEM
2486 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2487 valid_p
= STRINGP (value
);
2489 valid_p
= (STRINGP (value
)
2490 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2491 || valid_image_p (value
));
2492 #else /* not HAVE_WINDOW_SYSTEM */
2493 valid_p
= STRINGP (value
);
2494 #endif /* not HAVE_WINDOW_SYSTEM */
2496 if ((EQ (location
, Qleft_margin
)
2497 || EQ (location
, Qright_margin
)
2501 /* Save current settings of IT so that we can restore them
2502 when we are finished with the glyph property value. */
2505 if (NILP (location
))
2506 it
->area
= TEXT_AREA
;
2507 else if (EQ (location
, Qleft_margin
))
2508 it
->area
= LEFT_MARGIN_AREA
;
2510 it
->area
= RIGHT_MARGIN_AREA
;
2512 if (STRINGP (value
))
2515 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2516 it
->current
.overlay_string_index
= -1;
2517 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2518 it
->end_charpos
= it
->string_nchars
2519 = XSTRING (it
->string
)->size
;
2520 it
->method
= next_element_from_string
;
2521 it
->stop_charpos
= 0;
2522 it
->string_from_display_prop_p
= 1;
2524 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2526 it
->method
= next_element_from_stretch
;
2528 it
->current
.pos
= it
->position
= start_pos
;
2530 #ifdef HAVE_WINDOW_SYSTEM
2533 it
->what
= IT_IMAGE
;
2534 it
->image_id
= lookup_image (it
->f
, value
);
2535 it
->position
= start_pos
;
2536 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2537 it
->method
= next_element_from_image
;
2539 /* Say that we don't have consumed the characters with
2540 `display' property yet. The call to pop_it in
2541 set_iterator_to_next will clean this up. */
2542 *position
= start_pos
;
2544 #endif /* HAVE_WINDOW_SYSTEM */
2548 return space_or_image_found_p
;
2553 /***********************************************************************
2555 ***********************************************************************/
2557 /* The following structure is used to record overlay strings for
2558 later sorting in load_overlay_strings. */
2560 struct overlay_entry
2568 /* Set up iterator IT from overlay strings at its current position.
2569 Called from handle_stop. */
2571 static enum prop_handled
2572 handle_overlay_change (it
)
2575 /* Overlays are handled in current_buffer only. */
2576 if (STRINGP (it
->string
))
2577 return HANDLED_NORMALLY
;
2579 return (get_overlay_strings (it
)
2580 ? HANDLED_RECOMPUTE_PROPS
2581 : HANDLED_NORMALLY
);
2585 /* Set up the next overlay string for delivery by IT, if there is an
2586 overlay string to deliver. Called by set_iterator_to_next when the
2587 end of the current overlay string is reached. If there are more
2588 overlay strings to display, IT->string and
2589 IT->current.overlay_string_index are set appropriately here.
2590 Otherwise IT->string is set to nil. */
2593 next_overlay_string (it
)
2596 ++it
->current
.overlay_string_index
;
2597 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2599 /* No more overlay strings. Restore IT's settings to what
2600 they were before overlay strings were processed, and
2601 continue to deliver from current_buffer. */
2603 xassert (it
->stop_charpos
>= BEGV
2604 && it
->stop_charpos
<= it
->end_charpos
);
2606 it
->current
.overlay_string_index
= -1;
2607 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2608 it
->n_overlay_strings
= 0;
2609 it
->method
= next_element_from_buffer
;
2613 /* There are more overlay strings to process. If
2614 IT->current.overlay_string_index has advanced to a position
2615 where we must load IT->overlay_strings with more strings, do
2617 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2619 if (it
->current
.overlay_string_index
&& i
== 0)
2620 load_overlay_strings (it
);
2622 /* Initialize IT to deliver display elements from the overlay
2624 it
->string
= it
->overlay_strings
[i
];
2625 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2626 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2627 it
->method
= next_element_from_string
;
2628 it
->stop_charpos
= 0;
2635 /* Compare two overlay_entry structures E1 and E2. Used as a
2636 comparison function for qsort in load_overlay_strings. Overlay
2637 strings for the same position are sorted so that
2639 1. All after-strings come in front of before-strings.
2641 2. Within after-strings, strings are sorted so that overlay strings
2642 from overlays with higher priorities come first.
2644 2. Within before-strings, strings are sorted so that overlay
2645 strings from overlays with higher priorities come last.
2647 Value is analogous to strcmp. */
2651 compare_overlay_entries (e1
, e2
)
2654 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
2655 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
2658 if (entry1
->after_string_p
!= entry2
->after_string_p
)
2659 /* Let after-strings appear in front of before-strings. */
2660 result
= entry1
->after_string_p
? -1 : 1;
2661 else if (entry1
->after_string_p
)
2662 /* After-strings sorted in order of decreasing priority. */
2663 result
= entry2
->priority
- entry1
->priority
;
2665 /* Before-strings sorted in order of increasing priority. */
2666 result
= entry1
->priority
- entry2
->priority
;
2672 /* Load the vector IT->overlay_strings with overlay strings from IT's
2673 current buffer position. Set IT->n_overlays to the total number of
2674 overlay strings found.
2676 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
2677 a time. On entry into load_overlay_strings,
2678 IT->current.overlay_string_index gives the number of overlay
2679 strings that have already been loaded by previous calls to this
2682 Overlay strings are sorted so that after-string strings come in
2683 front of before-string strings. Within before and after-strings,
2684 strings are sorted by overlay priority. See also function
2685 compare_overlay_entries. */
2688 load_overlay_strings (it
)
2691 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
2692 Lisp_Object ov
, overlay
, window
, str
;
2696 struct overlay_entry
*entries
2697 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
2699 /* Append the overlay string STRING of overlay OVERLAY to vector
2700 `entries' which has size `size' and currently contains `n'
2701 elements. AFTER_P non-zero means STRING is an after-string of
2703 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
2706 Lisp_Object priority; \
2710 int new_size = 2 * size; \
2711 struct overlay_entry *old = entries; \
2713 (struct overlay_entry *) alloca (new_size \
2714 * sizeof *entries); \
2715 bcopy (old, entries, size * sizeof *entries); \
2719 entries[n].string = (STRING); \
2720 priority = Foverlay_get ((OVERLAY), Qpriority); \
2721 entries[n].priority \
2722 = INTEGERP (priority) ? XFASTINT (priority) : 0; \
2723 entries[n].after_string_p = (AFTER_P); \
2728 /* Process overlay before the overlay center. */
2729 for (ov
= current_buffer
->overlays_before
;
2731 ov
= XCONS (ov
)->cdr
)
2733 overlay
= XCONS (ov
)->car
;
2734 xassert (OVERLAYP (overlay
));
2735 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2736 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2738 if (end
< IT_CHARPOS (*it
))
2741 /* Skip this overlay if it doesn't start or end at IT's current
2743 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2746 /* Skip this overlay if it doesn't apply to IT->w. */
2747 window
= Foverlay_get (overlay
, Qwindow
);
2748 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2751 /* If overlay has a non-empty before-string, record it. */
2752 if (start
== IT_CHARPOS (*it
)
2753 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2754 && XSTRING (str
)->size
)
2755 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2757 /* If overlay has a non-empty after-string, record it. */
2758 if (end
== IT_CHARPOS (*it
)
2759 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2760 && XSTRING (str
)->size
)
2761 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2764 /* Process overlays after the overlay center. */
2765 for (ov
= current_buffer
->overlays_after
;
2767 ov
= XCONS (ov
)->cdr
)
2769 overlay
= XCONS (ov
)->car
;
2770 xassert (OVERLAYP (overlay
));
2771 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2772 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2774 if (start
> IT_CHARPOS (*it
))
2777 /* Skip this overlay if it doesn't start or end at IT's current
2779 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2782 /* Skip this overlay if it doesn't apply to IT->w. */
2783 window
= Foverlay_get (overlay
, Qwindow
);
2784 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2787 /* If overlay has a non-empty before-string, record it. */
2788 if (start
== IT_CHARPOS (*it
)
2789 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2790 && XSTRING (str
)->size
)
2791 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2793 /* If overlay has a non-empty after-string, record it. */
2794 if (end
== IT_CHARPOS (*it
)
2795 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2796 && XSTRING (str
)->size
)
2797 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2800 #undef RECORD_OVERLAY_STRING
2803 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
2805 /* Record the total number of strings to process. */
2806 it
->n_overlay_strings
= n
;
2808 /* IT->current.overlay_string_index is the number of overlay strings
2809 that have already been consumed by IT. Copy some of the
2810 remaining overlay strings to IT->overlay_strings. */
2812 j
= it
->current
.overlay_string_index
;
2813 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
2814 it
->overlay_strings
[i
++] = entries
[j
++].string
;
2820 /* Get the first chunk of overlay strings at IT's current buffer
2821 position. Value is non-zero if at least one overlay string was
2825 get_overlay_strings (it
)
2828 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
2829 process. This fills IT->overlay_strings with strings, and sets
2830 IT->n_overlay_strings to the total number of strings to process.
2831 IT->pos.overlay_string_index has to be set temporarily to zero
2832 because load_overlay_strings needs this; it must be set to -1
2833 when no overlay strings are found because a zero value would
2834 indicate a position in the first overlay string. */
2835 it
->current
.overlay_string_index
= 0;
2836 load_overlay_strings (it
);
2838 /* If we found overlay strings, set up IT to deliver display
2839 elements from the first one. Otherwise set up IT to deliver
2840 from current_buffer. */
2841 if (it
->n_overlay_strings
)
2843 /* Make sure we know settings in current_buffer, so that we can
2844 restore meaningful values when we're done with the overlay
2846 compute_stop_pos (it
);
2847 xassert (it
->face_id
>= 0);
2849 /* Save IT's settings. They are restored after all overlay
2850 strings have been processed. */
2851 xassert (it
->sp
== 0);
2854 /* Set up IT to deliver display elements from the first overlay
2856 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2857 it
->stop_charpos
= 0;
2858 it
->string
= it
->overlay_strings
[0];
2859 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2860 xassert (STRINGP (it
->string
));
2861 it
->method
= next_element_from_string
;
2866 it
->current
.overlay_string_index
= -1;
2867 it
->method
= next_element_from_buffer
;
2872 /* Value is non-zero if we found at least one overlay string. */
2873 return STRINGP (it
->string
);
2878 /***********************************************************************
2879 Saving and restoring state
2880 ***********************************************************************/
2882 /* Save current settings of IT on IT->stack. Called, for example,
2883 before setting up IT for an overlay string, to be able to restore
2884 IT's settings to what they were after the overlay string has been
2891 struct iterator_stack_entry
*p
;
2893 xassert (it
->sp
< 2);
2894 p
= it
->stack
+ it
->sp
;
2896 p
->stop_charpos
= it
->stop_charpos
;
2897 xassert (it
->face_id
>= 0);
2898 p
->face_id
= it
->face_id
;
2899 p
->string
= it
->string
;
2900 p
->pos
= it
->current
;
2901 p
->end_charpos
= it
->end_charpos
;
2902 p
->string_nchars
= it
->string_nchars
;
2904 p
->multibyte_p
= it
->multibyte_p
;
2905 p
->space_width
= it
->space_width
;
2906 p
->font_height
= it
->font_height
;
2907 p
->voffset
= it
->voffset
;
2908 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
2913 /* Restore IT's settings from IT->stack. Called, for example, when no
2914 more overlay strings must be processed, and we return to delivering
2915 display elements from a buffer, or when the end of a string from a
2916 `display' property is reached and we return to delivering display
2917 elements from an overlay string, or from a buffer. */
2923 struct iterator_stack_entry
*p
;
2925 xassert (it
->sp
> 0);
2927 p
= it
->stack
+ it
->sp
;
2928 it
->stop_charpos
= p
->stop_charpos
;
2929 it
->face_id
= p
->face_id
;
2930 it
->string
= p
->string
;
2931 it
->current
= p
->pos
;
2932 it
->end_charpos
= p
->end_charpos
;
2933 it
->string_nchars
= p
->string_nchars
;
2935 it
->multibyte_p
= p
->multibyte_p
;
2936 it
->space_width
= p
->space_width
;
2937 it
->font_height
= p
->font_height
;
2938 it
->voffset
= p
->voffset
;
2939 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
2944 /***********************************************************************
2946 ***********************************************************************/
2948 /* Set IT's current position to the previous line start. */
2951 back_to_previous_line_start (it
)
2954 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
2955 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
2959 /* Set IT's current position to the next line start. */
2962 forward_to_next_line_start (it
)
2965 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), 1);
2966 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
2970 /* Set IT's current position to the previous visible line start. Skip
2971 invisible text that is so either due to text properties or due to
2972 selective display. Caution: this does not change IT->current_x and
2976 back_to_previous_visible_line_start (it
)
2981 /* Go back one newline if not on BEGV already. */
2982 if (IT_CHARPOS (*it
) > BEGV
)
2983 back_to_previous_line_start (it
);
2985 /* Move over lines that are invisible because of selective display
2986 or text properties. */
2987 while (IT_CHARPOS (*it
) > BEGV
2992 /* If selective > 0, then lines indented more than that values
2994 if (it
->selective
> 0
2995 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
2998 #ifdef USE_TEXT_PROPERTIES
3003 prop
= Fget_char_property (IT_CHARPOS (*it
), Qinvisible
, it
->window
);
3004 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3007 #endif /* USE_TEXT_PROPERTIES */
3009 /* Back one more newline if the current one is invisible. */
3011 back_to_previous_line_start (it
);
3014 xassert (IT_CHARPOS (*it
) >= BEGV
);
3015 xassert (IT_CHARPOS (*it
) == BEGV
3016 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3021 /* Reseat iterator IT at the previous visible line start. Skip
3022 invisible text that is so either due to text properties or due to
3023 selective display. At the end, update IT's overlay information,
3024 face information etc. */
3027 reseat_at_previous_visible_line_start (it
)
3030 back_to_previous_visible_line_start (it
);
3031 reseat (it
, it
->current
.pos
, 1);
3036 /* Reseat iterator IT on the next visible line start in the current
3037 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3038 preceding the line start. Skip over invisible text that is so
3039 because of selective display. Compute faces, overlays etc at the
3040 new position. Note that this function does not skip over text that
3041 is invisible because of text properties. */
3044 reseat_at_next_visible_line_start (it
, on_newline_p
)
3048 /* Restore the buffer position when currently not delivering display
3049 elements from the current buffer. This is the case, for example,
3050 when called at the end of a truncated overlay string. */
3053 it
->method
= next_element_from_buffer
;
3055 /* Otherwise, scan_buffer would not work. */
3056 if (IT_CHARPOS (*it
) < ZV
)
3058 /* If on a newline, advance past it. Otherwise, find the next
3059 newline which automatically gives us the position following
3061 if (FETCH_BYTE (IT_BYTEPOS (*it
)) == '\n')
3067 forward_to_next_line_start (it
);
3069 /* We must either have reached the end of the buffer or end up
3071 xassert (IT_CHARPOS (*it
) == ZV
3072 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3074 /* Skip over lines that are invisible because they are indented
3075 more than the value of IT->selective. */
3076 if (it
->selective
> 0)
3077 while (IT_CHARPOS (*it
) < ZV
3078 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3080 forward_to_next_line_start (it
);
3082 /* Position on the newline if we should. */
3083 if (on_newline_p
&& IT_CHARPOS (*it
) > BEGV
)
3086 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3089 /* Set the iterator there. The 0 as the last parameter of
3090 reseat means don't force a text property lookup. The lookup
3091 is then only done if we've skipped past the iterator's
3092 check_charpos'es. This optimization is important because
3093 text property lookups tend to be expensive. */
3094 reseat (it
, it
->current
.pos
, 0);
3102 /***********************************************************************
3103 Changing an iterator's position
3104 ***********************************************************************/
3106 /* Change IT's current position to POS in current_buffer. If FORCE_P
3107 is non-zero, always check for text properties at the new position.
3108 Otherwise, text properties are only looked up if POS >=
3109 IT->check_charpos of a property. */
3112 reseat (it
, pos
, force_p
)
3114 struct text_pos pos
;
3117 int original_pos
= IT_CHARPOS (*it
);
3119 reseat_1 (it
, pos
, 0);
3121 /* Determine where to check text properties. Avoid doing it
3122 where possible because text property lookup is very expensive. */
3124 || CHARPOS (pos
) > it
->stop_charpos
3125 || CHARPOS (pos
) < original_pos
)
3132 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3133 IT->stop_pos to POS, also. */
3136 reseat_1 (it
, pos
, set_stop_p
)
3138 struct text_pos pos
;
3141 /* Don't call this function when scanning a C string. */
3142 xassert (it
->s
== NULL
);
3144 /* POS must be a reasonable value. */
3145 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3147 it
->current
.pos
= it
->position
= pos
;
3148 XSETBUFFER (it
->object
, current_buffer
);
3150 it
->current
.dpvec_index
= -1;
3151 it
->current
.overlay_string_index
= -1;
3152 IT_STRING_CHARPOS (*it
) = -1;
3153 IT_STRING_BYTEPOS (*it
) = -1;
3155 it
->method
= next_element_from_buffer
;
3159 it
->stop_charpos
= CHARPOS (pos
);
3163 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3164 If S is non-null, it is a C string to iterate over. Otherwise,
3165 STRING gives a Lisp string to iterate over.
3167 If PRECISION > 0, don't return more then PRECISION number of
3168 characters from the string.
3170 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3171 characters have been returned. FIELD_WIDTH < 0 means an infinite
3174 MULTIBYTE = 0 means disable processing of multibyte characters,
3175 MULTIBYTE > 0 means enable it,
3176 MULTIBYTE < 0 means use IT->multibyte_p.
3178 IT must be initialized via a prior call to init_iterator before
3179 calling this function. */
3182 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3187 int precision
, field_width
, multibyte
;
3189 /* No region in strings. */
3190 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3192 /* No text property checks performed by default, but see below. */
3193 it
->stop_charpos
= -1;
3195 /* Set iterator position and end position. */
3196 bzero (&it
->current
, sizeof it
->current
);
3197 it
->current
.overlay_string_index
= -1;
3198 it
->current
.dpvec_index
= -1;
3199 it
->charset
= CHARSET_ASCII
;
3200 xassert (charpos
>= 0);
3202 /* Use the setting of MULTIBYTE if specified. */
3204 it
->multibyte_p
= multibyte
> 0;
3208 xassert (STRINGP (string
));
3209 it
->string
= string
;
3211 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3212 it
->method
= next_element_from_string
;
3213 it
->current
.string_pos
= string_pos (charpos
, string
);
3220 /* Note that we use IT->current.pos, not it->current.string_pos,
3221 for displaying C strings. */
3222 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3223 if (it
->multibyte_p
)
3225 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3226 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3230 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3231 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3234 it
->method
= next_element_from_c_string
;
3237 /* PRECISION > 0 means don't return more than PRECISION characters
3239 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3240 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3242 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3243 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3244 FIELD_WIDTH < 0 means infinite field width. This is useful for
3245 padding with `-' at the end of a mode line. */
3246 if (field_width
< 0)
3247 field_width
= INFINITY
;
3248 if (field_width
> it
->end_charpos
- charpos
)
3249 it
->end_charpos
= charpos
+ field_width
;
3251 /* Use the standard display table for displaying strings. */
3252 if (DISP_TABLE_P (Vstandard_display_table
))
3253 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3255 it
->stop_charpos
= charpos
;
3261 /***********************************************************************
3263 ***********************************************************************/
3265 /* Load IT's display element fields with information about the next
3266 display element from the current position of IT. Value is zero if
3267 end of buffer (or C string) is reached. */
3270 get_next_display_element (it
)
3273 /* Non-zero means that we found an display element. Zero means that
3274 we hit the end of what we iterate over. Performance note: the
3275 function pointer `method' used here turns out to be faster than
3276 using a sequence of if-statements. */
3277 int success_p
= (*it
->method
) (it
);
3280 if (it
->what
== IT_CHARACTER
)
3282 /* Map via display table or translate control characters.
3283 IT->c, IT->len etc. have been set to the next character by
3284 the function call above. If we have a display table, and it
3285 contains an entry for IT->c, translate it. Don't do this if
3286 IT->c itself comes from a display table, otherwise we could
3287 end up in an infinite recursion. (An alternative could be to
3288 count the recursion depth of this function and signal an
3289 error when a certain maximum depth is reached.) Is it worth
3291 if (success_p
&& it
->dpvec
== NULL
)
3296 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3299 struct Lisp_Vector
*v
= XVECTOR (dv
);
3301 /* Return the first character from the display table
3302 entry, if not empty. If empty, don't display the
3303 current character. */
3306 it
->dpvec_char_len
= it
->len
;
3307 it
->dpvec
= v
->contents
;
3308 it
->dpend
= v
->contents
+ v
->size
;
3309 it
->current
.dpvec_index
= 0;
3310 it
->method
= next_element_from_display_vector
;
3313 success_p
= get_next_display_element (it
);
3316 /* Translate control characters into `\003' or `^C' form.
3317 Control characters coming from a display table entry are
3318 currently not translated because we use IT->dpvec to hold
3319 the translation. This could easily be changed but I
3320 don't believe that it is worth doing. */
3321 else if ((it
->c
< ' '
3322 && (it
->area
!= TEXT_AREA
3329 /* IT->c is a control character which must be displayed
3330 either as '\003' or as `^C' where the '\\' and '^'
3331 can be defined in the display table. Fill
3332 IT->ctl_chars with glyphs for what we have to
3333 display. Then, set IT->dpvec to these glyphs. */
3336 if (it
->c
< 128 && it
->ctl_arrow_p
)
3338 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3340 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3341 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3342 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3344 g
= FAST_MAKE_GLYPH ('^', 0);
3345 XSETINT (it
->ctl_chars
[0], g
);
3347 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3348 XSETINT (it
->ctl_chars
[1], g
);
3350 /* Set up IT->dpvec and return first character from it. */
3351 it
->dpvec_char_len
= it
->len
;
3352 it
->dpvec
= it
->ctl_chars
;
3353 it
->dpend
= it
->dpvec
+ 2;
3354 it
->current
.dpvec_index
= 0;
3355 it
->method
= next_element_from_display_vector
;
3356 get_next_display_element (it
);
3360 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3362 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3363 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3364 g
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3366 g
= FAST_MAKE_GLYPH ('\\', 0);
3367 XSETINT (it
->ctl_chars
[0], g
);
3369 /* Insert three more glyphs into IT->ctl_chars for
3370 the octal display of the character. */
3371 g
= FAST_MAKE_GLYPH (((it
->c
>> 6) & 7) + '0', 0);
3372 XSETINT (it
->ctl_chars
[1], g
);
3373 g
= FAST_MAKE_GLYPH (((it
->c
>> 3) & 7) + '0', 0);
3374 XSETINT (it
->ctl_chars
[2], g
);
3375 g
= FAST_MAKE_GLYPH ((it
->c
& 7) + '0', 0);
3376 XSETINT (it
->ctl_chars
[3], g
);
3378 /* Set up IT->dpvec and return the first character
3380 it
->dpvec_char_len
= it
->len
;
3381 it
->dpvec
= it
->ctl_chars
;
3382 it
->dpend
= it
->dpvec
+ 4;
3383 it
->current
.dpvec_index
= 0;
3384 it
->method
= next_element_from_display_vector
;
3385 get_next_display_element (it
);
3390 /* Adjust face id if charset changes. There are no charset
3391 changes in unibyte text because Emacs' charsets are not
3392 applicable there. */
3395 && (charset
= CHAR_CHARSET (it
->c
),
3396 charset
!= it
->charset
))
3398 it
->charset
= charset
;
3399 it
->face_id
= FACE_FOR_CHARSET (it
->f
, it
->face_id
, charset
);
3403 /* Is this character the last one of a run of characters with
3404 box? If yes, set IT->end_of_box_run_p to 1. */
3411 it
->end_of_box_run_p
3412 = ((face_id
= face_after_it_pos (it
),
3413 face_id
!= it
->face_id
)
3414 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3415 face
->box
== FACE_NO_BOX
));
3418 /* Value is 0 if end of buffer or string reached. */
3423 /* Move IT to the next display element.
3425 Functions get_next_display_element and set_iterator_to_next are
3426 separate because I find this arrangement easier to handle than a
3427 get_next_display_element function that also increments IT's
3428 position. The way it is we can first look at an iterator's current
3429 display element, decide whether it fits on a line, and if it does,
3430 increment the iterator position. The other way around we probably
3431 would either need a flag indicating whether the iterator has to be
3432 incremented the next time, or we would have to implement a
3433 decrement position function which would not be easy to write. */
3436 set_iterator_to_next (it
)
3439 if (it
->method
== next_element_from_buffer
)
3441 /* The current display element of IT is a character from
3442 current_buffer. Advance in the buffer, and maybe skip over
3443 invisible lines that are so because of selective display. */
3444 if (ITERATOR_AT_END_OF_LINE_P (it
))
3445 reseat_at_next_visible_line_start (it
, 0);
3448 xassert (it
->len
!= 0);
3449 IT_BYTEPOS (*it
) += it
->len
;
3450 IT_CHARPOS (*it
) += 1;
3451 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3454 else if (it
->method
== next_element_from_c_string
)
3456 /* Current display element of IT is from a C string. */
3457 IT_BYTEPOS (*it
) += it
->len
;
3458 IT_CHARPOS (*it
) += 1;
3460 else if (it
->method
== next_element_from_display_vector
)
3462 /* Current display element of IT is from a display table entry.
3463 Advance in the display table definition. Reset it to null if
3464 end reached, and continue with characters from buffers/
3468 ++it
->current
.dpvec_index
;
3470 /* Restore face and charset of the iterator to what they were
3471 before the display vector entry (these entries may contain
3472 faces, and of course characters of different charsets). */
3473 it
->face_id
= it
->saved_face_id
;
3474 it
->charset
= FACE_FROM_ID (it
->f
, it
->face_id
)->charset
;
3476 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3479 it
->method
= next_element_from_c_string
;
3480 else if (STRINGP (it
->string
))
3481 it
->method
= next_element_from_string
;
3483 it
->method
= next_element_from_buffer
;
3486 it
->current
.dpvec_index
= -1;
3488 /* Skip over characters which were displayed via IT->dpvec. */
3489 if (it
->dpvec_char_len
< 0)
3490 reseat_at_next_visible_line_start (it
, 1);
3491 else if (it
->dpvec_char_len
> 0)
3493 it
->len
= it
->dpvec_char_len
;
3494 set_iterator_to_next (it
);
3498 else if (it
->method
== next_element_from_string
)
3500 /* Current display element is a character from a Lisp string. */
3501 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3502 IT_STRING_BYTEPOS (*it
) += it
->len
;
3503 IT_STRING_CHARPOS (*it
) += 1;
3505 consider_string_end
:
3507 if (it
->current
.overlay_string_index
>= 0)
3509 /* IT->string is an overlay string. Advance to the
3510 next, if there is one. */
3511 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3512 next_overlay_string (it
);
3516 /* IT->string is not an overlay string. If we reached
3517 its end, and there is something on IT->stack, proceed
3518 with what is on the stack. This can be either another
3519 string, this time an overlay string, or a buffer. */
3520 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3524 if (!STRINGP (it
->string
))
3525 it
->method
= next_element_from_buffer
;
3529 else if (it
->method
== next_element_from_image
3530 || it
->method
== next_element_from_stretch
)
3532 /* The position etc with which we have to proceed are on
3533 the stack. The position may be at the end of a string,
3534 if the `display' property takes up the whole string. */
3537 if (STRINGP (it
->string
))
3539 it
->method
= next_element_from_string
;
3540 goto consider_string_end
;
3543 it
->method
= next_element_from_buffer
;
3546 /* There are no other methods defined, so this should be a bug. */
3549 /* Reset flags indicating start and end of a sequence of
3550 characters with box. */
3551 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3553 xassert (it
->method
!= next_element_from_string
3554 || (STRINGP (it
->string
)
3555 && IT_STRING_CHARPOS (*it
) >= 0));
3559 /* Load IT's display element fields with information about the next
3560 display element which comes from a display table entry or from the
3561 result of translating a control character to one of the forms `^C'
3562 or `\003'. IT->dpvec holds the glyphs to return as characters. */
3565 next_element_from_display_vector (it
)
3569 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
3571 /* Remember the current face id in case glyphs specify faces.
3572 IT's face is restored in set_iterator_to_next. */
3573 it
->saved_face_id
= it
->face_id
;
3575 if (INTEGERP (*it
->dpvec
)
3576 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
3581 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
3582 it
->c
= FAST_GLYPH_CHAR (g
);
3583 it
->len
= CHAR_LEN (it
->c
);
3585 /* The entry may contain a face id to use. Such a face id is
3586 the id of a Lisp face, not a realized face. A face id of
3587 zero means no face. */
3588 lface_id
= FAST_GLYPH_FACE (g
);
3591 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
3594 it
->face_id
= face_id
;
3595 it
->charset
= CHARSET_ASCII
;
3600 /* Display table entry is invalid. Return a space. */
3601 it
->c
= ' ', it
->len
= 1;
3603 /* Don't change position and object of the iterator here. They are
3604 still the values of the character that had this display table
3605 entry or was translated, and that's what we want. */
3606 it
->what
= IT_CHARACTER
;
3611 /* Load IT with the next display element from Lisp string IT->string.
3612 IT->current.string_pos is the current position within the string.
3613 If IT->current.overlay_string_index >= 0, the Lisp string is an
3617 next_element_from_string (it
)
3620 struct text_pos position
;
3622 xassert (STRINGP (it
->string
));
3623 xassert (IT_STRING_CHARPOS (*it
) >= 0);
3624 position
= it
->current
.string_pos
;
3626 /* Time to check for invisible text? */
3627 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
3628 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
3632 /* Since a handler may have changed IT->method, we must
3634 return get_next_display_element (it
);
3637 if (it
->current
.overlay_string_index
>= 0)
3639 /* Get the next character from an overlay string. In overlay
3640 strings, There is no field width or padding with spaces to
3642 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3647 else if (STRING_MULTIBYTE (it
->string
))
3649 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
3650 - IT_STRING_BYTEPOS (*it
));
3651 unsigned char *s
= (XSTRING (it
->string
)->data
3652 + IT_STRING_BYTEPOS (*it
));
3653 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
3657 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3663 /* Get the next character from a Lisp string that is not an
3664 overlay string. Such strings come from the mode line, for
3665 example. We may have to pad with spaces, or truncate the
3666 string. See also next_element_from_c_string. */
3667 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
3672 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
3674 /* Pad with spaces. */
3675 it
->c
= ' ', it
->len
= 1;
3676 CHARPOS (position
) = BYTEPOS (position
) = -1;
3678 else if (STRING_MULTIBYTE (it
->string
))
3680 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
3681 - IT_STRING_BYTEPOS (*it
));
3682 unsigned char *s
= (XSTRING (it
->string
)->data
3683 + IT_STRING_BYTEPOS (*it
));
3684 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
3688 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3693 /* Record what we have and where it came from. Note that we store a
3694 buffer position in IT->position although it could arguably be a
3696 it
->what
= IT_CHARACTER
;
3697 it
->object
= it
->string
;
3698 it
->position
= position
;
3703 /* Load IT with next display element from C string IT->s.
3704 IT->string_nchars is the maximum number of characters to return
3705 from the string. IT->end_charpos may be greater than
3706 IT->string_nchars when this function is called, in which case we
3707 may have to return padding spaces. Value is zero if end of string
3708 reached, including padding spaces. */
3711 next_element_from_c_string (it
)
3717 it
->what
= IT_CHARACTER
;
3718 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
3721 /* IT's position can be greater IT->string_nchars in case a field
3722 width or precision has been specified when the iterator was
3724 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3726 /* End of the game. */
3730 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
3732 /* Pad with spaces. */
3733 it
->c
= ' ', it
->len
= 1;
3734 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
3736 else if (it
->multibyte_p
)
3738 /* Implementation note: The calls to strlen apparently aren't a
3739 performance problem because there is no noticeable performance
3740 difference between Emacs running in unibyte or multibyte mode. */
3741 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
3742 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
3746 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
3752 /* Set up IT to return characters from an ellipsis, if appropriate.
3753 The definition of the ellipsis glyphs may come from a display table
3754 entry. This function Fills IT with the first glyph from the
3755 ellipsis if an ellipsis is to be displayed. */
3758 next_element_from_ellipsis (it
)
3761 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3763 /* Use the display table definition for `...'. Invalid glyphs
3764 will be handled by the method returning elements from dpvec. */
3765 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3766 it
->dpvec_char_len
= it
->len
;
3767 it
->dpvec
= v
->contents
;
3768 it
->dpend
= v
->contents
+ v
->size
;
3769 it
->current
.dpvec_index
= 0;
3770 it
->method
= next_element_from_display_vector
;
3771 get_next_display_element (it
);
3773 else if (it
->selective_display_ellipsis_p
)
3775 /* Use default `...' which is stored in default_invis_vector. */
3776 it
->dpvec_char_len
= it
->len
;
3777 it
->dpvec
= default_invis_vector
;
3778 it
->dpend
= default_invis_vector
+ 3;
3779 it
->current
.dpvec_index
= 0;
3780 it
->method
= next_element_from_display_vector
;
3781 get_next_display_element (it
);
3786 /* Deliver an image display element. The iterator IT is already
3787 filled with image information (done in handle_display_prop). Value
3792 next_element_from_image (it
)
3795 it
->what
= IT_IMAGE
;
3800 /* Fill iterator IT with next display element from a stretch glyph
3801 property. IT->object is the value of the text property. Value is
3805 next_element_from_stretch (it
)
3808 it
->what
= IT_STRETCH
;
3813 /* Load IT with the next display element from current_buffer. Value
3814 is zero if end of buffer reached. IT->stop_charpos is the next
3815 position at which to stop and check for text properties or buffer
3819 next_element_from_buffer (it
)
3824 /* Check this assumption, otherwise, we would never enter the
3825 if-statement, below. */
3826 xassert (IT_CHARPOS (*it
) >= BEGV
3827 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
3829 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
3831 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3833 int overlay_strings_follow_p
;
3835 /* End of the game, except when overlay strings follow that
3836 haven't been returned yet. */
3837 if (it
->overlay_strings_at_end_processed_p
)
3838 overlay_strings_follow_p
= 0;
3841 it
->overlay_strings_at_end_processed_p
= 1;
3842 overlay_strings_follow_p
3843 = get_overlay_strings (it
);
3846 if (overlay_strings_follow_p
)
3847 success_p
= get_next_display_element (it
);
3851 it
->position
= it
->current
.pos
;
3858 return get_next_display_element (it
);
3863 /* No face changes, overlays etc. in sight, so just return a
3864 character from current_buffer. */
3867 /* Maybe run the redisplay end trigger hook. Performance note:
3868 This doesn't seem to cost measurable time. */
3869 if (it
->redisplay_end_trigger_charpos
3871 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
3872 run_redisplay_end_trigger_hook (it
);
3874 /* Get the next character, maybe multibyte. */
3875 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
3876 if (it
->multibyte_p
)
3878 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
3879 - IT_BYTEPOS (*it
));
3880 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
3883 it
->c
= *p
, it
->len
= 1;
3885 /* Record what we have and where it came from. */
3886 it
->what
= IT_CHARACTER
;;
3887 it
->object
= it
->w
->buffer
;
3888 it
->position
= it
->current
.pos
;
3890 /* Normally we return the character found above, except when we
3891 really want to return an ellipsis for selective display. */
3896 /* A value of selective > 0 means hide lines indented more
3897 than that number of columns. */
3898 if (it
->selective
> 0
3899 && IT_CHARPOS (*it
) + 1 < ZV
3900 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
3901 IT_BYTEPOS (*it
) + 1,
3904 next_element_from_ellipsis (it
);
3905 it
->dpvec_char_len
= -1;
3908 else if (it
->c
== '\r' && it
->selective
== -1)
3910 /* A value of selective == -1 means that everything from the
3911 CR to the end of the line is invisible, with maybe an
3912 ellipsis displayed for it. */
3913 next_element_from_ellipsis (it
);
3914 it
->dpvec_char_len
= -1;
3919 /* Value is zero if end of buffer reached. */
3920 xassert (!success_p
|| it
->len
> 0);
3925 /* Run the redisplay end trigger hook for IT. */
3928 run_redisplay_end_trigger_hook (it
)
3931 Lisp_Object args
[3];
3933 /* IT->glyph_row should be non-null, i.e. we should be actually
3934 displaying something, or otherwise we should not run the hook. */
3935 xassert (it
->glyph_row
);
3937 /* Set up hook arguments. */
3938 args
[0] = Qredisplay_end_trigger_functions
;
3939 args
[1] = it
->window
;
3940 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
3941 it
->redisplay_end_trigger_charpos
= 0;
3943 /* Since we are *trying* to run these functions, don't try to run
3944 them again, even if they get an error. */
3945 it
->w
->redisplay_end_trigger
= Qnil
;
3946 Frun_hook_with_args (3, args
);
3948 /* Notice if it changed the face of the character we are on. */
3949 handle_face_prop (it
);
3954 /***********************************************************************
3955 Moving an iterator without producing glyphs
3956 ***********************************************************************/
3958 /* Move iterator IT to a specified buffer or X position within one
3959 line on the display without producing glyphs.
3961 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
3962 whichever is reached first.
3964 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
3966 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
3967 0 <= TO_X <= IT->last_visible_x. This means in particular, that
3968 TO_X includes the amount by which a window is horizontally
3973 MOVE_POS_MATCH_OR_ZV
3974 - when TO_POS or ZV was reached.
3977 -when TO_X was reached before TO_POS or ZV were reached.
3980 - when we reached the end of the display area and the line must
3984 - when we reached the end of the display area and the line is
3988 - when we stopped at a line end, i.e. a newline or a CR and selective
3992 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
3994 int to_charpos
, to_x
, op
;
3996 enum move_it_result result
= MOVE_UNDEFINED
;
3997 struct glyph_row
*saved_glyph_row
;
3999 /* Don't produce glyphs in produce_glyphs. */
4000 saved_glyph_row
= it
->glyph_row
;
4001 it
->glyph_row
= NULL
;
4003 #if NO_PROMPT_IN_BUFFER
4004 /* Take a mini-buffer prompt into account. */
4005 if (MINI_WINDOW_P (it
->w
)
4006 && IT_CHARPOS (*it
) == BEGV
)
4008 it
->current_x
= minibuf_prompt_pixel_width
;
4009 it
->hpos
= minibuf_prompt_width
;
4017 /* Stop when ZV or TO_CHARPOS reached. */
4018 if (!get_next_display_element (it
)
4019 || ((op
& MOVE_TO_POS
) != 0
4020 && BUFFERP (it
->object
)
4021 && IT_CHARPOS (*it
) >= to_charpos
))
4023 result
= MOVE_POS_MATCH_OR_ZV
;
4027 /* The call to produce_glyphs will get the metrics of the
4028 display element IT is loaded with. We record in x the
4029 x-position before this display element in case it does not
4032 PRODUCE_GLYPHS (it
);
4034 if (it
->area
!= TEXT_AREA
)
4036 set_iterator_to_next (it
);
4040 /* The number of glyphs we get back in IT->nglyphs will normally
4041 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4042 character on a terminal frame, or (iii) a line end. For the
4043 second case, IT->nglyphs - 1 padding glyphs will be present
4044 (on X frames, there is only one glyph produced for a
4045 composite character.
4047 The behavior implemented below means, for continuation lines,
4048 that as many spaces of a TAB as fit on the current line are
4049 displayed there. For terminal frames, as many glyphs of a
4050 multi-glyph character are displayed in the current line, too.
4051 This is what the old redisplay code did, and we keep it that
4052 way. Under X, the whole shape of a complex character must
4053 fit on the line or it will be completely displayed in the
4056 Note that both for tabs and padding glyphs, all glyphs have
4060 /* More than one glyph or glyph doesn't fit on line. All
4061 glyphs have the same width. */
4062 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4065 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4067 new_x
= x
+ single_glyph_width
;
4069 /* We want to leave anything reaching TO_X to the caller. */
4070 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4073 result
= MOVE_X_REACHED
;
4076 else if (/* Lines are continued. */
4077 !it
->truncate_lines_p
4078 && (/* And glyph doesn't fit on the line. */
4079 new_x
> it
->last_visible_x
4080 /* Or it fits exactly and we're on a window
4082 || (new_x
== it
->last_visible_x
4083 && FRAME_WINDOW_P (it
->f
))))
4085 if (/* IT->hpos == 0 means the very first glyph
4086 doesn't fit on the line, e.g. a wide image. */
4088 || (new_x
== it
->last_visible_x
4089 && FRAME_WINDOW_P (it
->f
)))
4092 it
->current_x
= new_x
;
4093 if (i
== it
->nglyphs
- 1)
4094 set_iterator_to_next (it
);
4099 result
= MOVE_LINE_CONTINUED
;
4102 else if (new_x
> it
->first_visible_x
)
4104 /* Glyph is visible. Increment number of glyphs that
4105 would be displayed. */
4110 /* Glyph is completely off the left margin of the display
4111 area. Nothing to do. */
4115 if (result
!= MOVE_UNDEFINED
)
4118 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4120 /* Stop when TO_X specified and reached. This check is
4121 necessary here because of lines consisting of a line end,
4122 only. The line end will not produce any glyphs and we
4123 would never get MOVE_X_REACHED. */
4124 xassert (it
->nglyphs
== 0);
4125 result
= MOVE_X_REACHED
;
4129 /* Is this a line end? If yes, we're done. */
4130 if (ITERATOR_AT_END_OF_LINE_P (it
))
4132 result
= MOVE_NEWLINE_OR_CR
;
4136 /* The current display element has been consumed. Advance
4138 set_iterator_to_next (it
);
4140 /* Stop if lines are truncated and IT's current x-position is
4141 past the right edge of the window now. */
4142 if (it
->truncate_lines_p
4143 && it
->current_x
>= it
->last_visible_x
)
4145 result
= MOVE_LINE_TRUNCATED
;
4150 /* Restore the iterator settings altered at the beginning of this
4152 it
->glyph_row
= saved_glyph_row
;
4157 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4158 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4159 the description of enum move_operation_enum.
4161 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4162 screen line, this function will set IT to the next position >
4166 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4168 int to_charpos
, to_x
, to_y
, to_vpos
;
4171 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4174 xassert (XBUFFER (it
->w
->buffer
) == current_buffer
);
4178 if (op
& MOVE_TO_VPOS
)
4180 /* If no TO_CHARPOS and no TO_X specified, stop at the
4181 start of the line TO_VPOS. */
4182 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4184 if (it
->vpos
== to_vpos
)
4186 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4190 /* TO_VPOS >= 0 means stop at TO_X in the line at
4191 TO_VPOS, or at TO_POS, whichever comes first. */
4192 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4194 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4196 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4198 /* We have reached TO_X but not in the line we want. */
4199 skip
= move_it_in_display_line_to (it
, to_charpos
,
4201 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4206 else if (op
& MOVE_TO_Y
)
4208 struct it it_backup
;
4211 /* TO_Y specified means stop at TO_X in the line containing
4212 TO_Y---or at TO_CHARPOS if this is reached first. The
4213 problem is that we can't really tell whether the line
4214 contains TO_Y before we have completely scanned it, and
4215 this may skip past TO_X. What we do is to first scan to
4218 If TO_X is not specified, use a TO_X of zero. The reason
4219 is to make the outcome of this function more predictable.
4220 If we didn't use TO_X == 0, we would stop at the end of
4221 the line which is probably not what a caller would expect
4223 skip
= move_it_in_display_line_to (it
, to_charpos
,
4227 | (op
& MOVE_TO_POS
)));
4229 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4230 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4233 /* If TO_X was reached, we would like to know whether TO_Y
4234 is in the line. This can only be said if we know the
4235 total line height which requires us to scan the rest of
4238 if (skip
== MOVE_X_REACHED
)
4241 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4245 /* Now, decide whether TO_Y is in this line. */
4246 line_height
= it
->max_ascent
+ it
->max_descent
;
4248 if (to_y
>= it
->current_y
4249 && to_y
< it
->current_y
+ line_height
)
4251 if (skip
== MOVE_X_REACHED
)
4252 /* If TO_Y is in this line and TO_X was reached above,
4253 we scanned too far. We have to restore IT's settings
4254 to the ones before skipping. */
4258 else if (skip
== MOVE_X_REACHED
)
4261 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4269 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4273 case MOVE_POS_MATCH_OR_ZV
:
4276 case MOVE_NEWLINE_OR_CR
:
4277 set_iterator_to_next (it
);
4278 it
->continuation_lines_width
= 0;
4281 case MOVE_LINE_TRUNCATED
:
4282 it
->continuation_lines_width
= 0;
4283 reseat_at_next_visible_line_start (it
, 0);
4284 if ((op
& MOVE_TO_POS
) != 0
4285 && IT_CHARPOS (*it
) > to_charpos
)
4289 case MOVE_LINE_CONTINUED
:
4290 it
->continuation_lines_width
+= it
->current_x
;
4297 /* Reset/increment for the next run. */
4298 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4299 it
->current_x
= it
->hpos
= 0;
4300 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4302 last_height
= it
->max_ascent
+ it
->max_descent
;
4303 last_max_ascent
= it
->max_ascent
;
4304 it
->max_ascent
= it
->max_descent
= 0;
4310 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4312 If DY > 0, move IT backward at least that many pixels. DY = 0
4313 means move IT backward to the preceding line start or BEGV. This
4314 function may move over more than DY pixels if IT->current_y - DY
4315 ends up in the middle of a line; in this case IT->current_y will be
4316 set to the top of the line moved to. */
4319 move_it_vertically_backward (it
, dy
)
4323 int nlines
, h
, line_height
;
4325 int start_pos
= IT_CHARPOS (*it
);
4329 /* Estimate how many newlines we must move back. */
4330 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4332 /* Set the iterator's position that many lines back. */
4333 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4334 back_to_previous_visible_line_start (it
);
4336 /* Reseat the iterator here. When moving backward, we don't want
4337 reseat to skip forward over invisible text, set up the iterator
4338 to deliver from overlay strings at the new position etc. So,
4339 use reseat_1 here. */
4340 reseat_1 (it
, it
->current
.pos
, 1);
4342 /* We are now surely at a line start. */
4343 it
->current_x
= it
->hpos
= 0;
4345 /* Move forward and see what y-distance we moved. First move to the
4346 start of the next line so that we get its height. We need this
4347 height to be able to tell whether we reached the specified
4350 it2
.max_ascent
= it2
.max_descent
= 0;
4351 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4352 MOVE_TO_POS
| MOVE_TO_VPOS
);
4353 xassert (IT_CHARPOS (*it
) >= BEGV
);
4354 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4355 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4356 xassert (IT_CHARPOS (*it
) >= BEGV
);
4357 h
= it2
.current_y
- it
->current_y
;
4358 nlines
= it2
.vpos
- it
->vpos
;
4360 /* Correct IT's y and vpos position. */
4366 /* DY == 0 means move to the start of the screen line. The
4367 value of nlines is > 0 if continuation lines were involved. */
4369 move_it_by_lines (it
, nlines
, 1);
4370 xassert (IT_CHARPOS (*it
) <= start_pos
);
4374 /* The y-position we try to reach. Note that h has been
4375 subtracted in front of the if-statement. */
4376 int target_y
= it
->current_y
+ h
- dy
;
4378 /* If we did not reach target_y, try to move further backward if
4379 we can. If we moved too far backward, try to move forward. */
4380 if (target_y
< it
->current_y
4381 && IT_CHARPOS (*it
) > BEGV
)
4383 move_it_vertically (it
, target_y
- it
->current_y
);
4384 xassert (IT_CHARPOS (*it
) >= BEGV
);
4386 else if (target_y
>= it
->current_y
+ line_height
4387 && IT_CHARPOS (*it
) < ZV
)
4389 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4390 xassert (IT_CHARPOS (*it
) >= BEGV
);
4396 /* Move IT by a specified amount of pixel lines DY. DY negative means
4397 move backwards. DY = 0 means move to start of screen line. At the
4398 end, IT will be on the start of a screen line. */
4401 move_it_vertically (it
, dy
)
4406 move_it_vertically_backward (it
, -dy
);
4409 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4410 MOVE_TO_POS
| MOVE_TO_Y
);
4412 /* If buffer ends in ZV without a newline, move to the start of
4413 the line to satisfy the post-condition. */
4414 if (IT_CHARPOS (*it
) == ZV
4415 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4416 move_it_by_lines (it
, 0, 0);
4421 /* Return non-zero if some text between buffer positions START_CHARPOS
4422 and END_CHARPOS is invisible. IT->window is the window for text
4426 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4428 int start_charpos
, end_charpos
;
4430 #ifdef USE_TEXT_PROPERTIES
4431 Lisp_Object prop
, limit
;
4432 int invisible_found_p
;
4434 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4436 /* Is text at START invisible? */
4437 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4439 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4440 invisible_found_p
= 1;
4443 limit
= Fnext_single_property_change (make_number (start_charpos
),
4446 make_number (end_charpos
));
4447 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4450 return invisible_found_p
;
4452 #else /* not USE_TEXT_PROPERTIES */
4454 #endif /* not USE_TEXT_PROPERTIES */
4458 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4459 negative means move up. DVPOS == 0 means move to the start of the
4460 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4461 NEED_Y_P is zero, IT->current_y will be left unchanged.
4463 Further optimization ideas: If we would know that IT->f doesn't use
4464 a face with proportional font, we could be faster for
4465 truncate-lines nil. */
4468 move_it_by_lines (it
, dvpos
, need_y_p
)
4470 int dvpos
, need_y_p
;
4472 struct position pos
;
4474 if (!FRAME_WINDOW_P (it
->f
))
4476 struct text_pos textpos
;
4478 /* We can use vmotion on frames without proportional fonts. */
4479 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4480 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4481 reseat (it
, textpos
, 1);
4482 it
->vpos
+= pos
.vpos
;
4483 it
->current_y
+= pos
.vpos
;
4485 else if (dvpos
== 0)
4487 /* DVPOS == 0 means move to the start of the screen line. */
4488 move_it_vertically_backward (it
, 0);
4489 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4493 /* If there are no continuation lines, and if there is no
4494 selective display, try the simple method of moving forward
4495 DVPOS newlines, then see where we are. */
4496 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4498 int shortage
= 0, charpos
;
4500 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
4501 charpos
= IT_CHARPOS (*it
) + 1;
4503 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
4506 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
4508 struct text_pos pos
;
4509 CHARPOS (pos
) = charpos
;
4510 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4511 reseat (it
, pos
, 1);
4512 it
->vpos
+= dvpos
- shortage
;
4513 it
->hpos
= it
->current_x
= 0;
4518 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
4523 int start_charpos
, i
;
4525 /* If there are no continuation lines, and if there is no
4526 selective display, try the simple method of moving backward
4528 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4531 int charpos
= IT_CHARPOS (*it
);
4532 int bytepos
= IT_BYTEPOS (*it
);
4534 /* If in the middle of a line, go to its start. */
4535 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
4537 charpos
= find_next_newline_no_quit (charpos
, -1);
4538 bytepos
= CHAR_TO_BYTE (charpos
);
4541 if (charpos
== BEGV
)
4543 struct text_pos pos
;
4544 CHARPOS (pos
) = charpos
;
4545 BYTEPOS (pos
) = bytepos
;
4546 reseat (it
, pos
, 1);
4547 it
->hpos
= it
->current_x
= 0;
4552 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
4553 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
4555 struct text_pos pos
;
4556 CHARPOS (pos
) = charpos
;
4557 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4558 reseat (it
, pos
, 1);
4559 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
4560 it
->hpos
= it
->current_x
= 0;
4566 /* Go back -DVPOS visible lines and reseat the iterator there. */
4567 start_charpos
= IT_CHARPOS (*it
);
4568 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
4569 back_to_previous_visible_line_start (it
);
4570 reseat (it
, it
->current
.pos
, 1);
4571 it
->current_x
= it
->hpos
= 0;
4573 /* Above call may have moved too far if continuation lines
4574 are involved. Scan forward and see if it did. */
4576 it2
.vpos
= it2
.current_y
= 0;
4577 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
4578 it
->vpos
-= it2
.vpos
;
4579 it
->current_y
-= it2
.current_y
;
4580 it
->current_x
= it
->hpos
= 0;
4582 /* If we moved too far, move IT some lines forward. */
4583 if (it2
.vpos
> -dvpos
)
4585 int delta
= it2
.vpos
+ dvpos
;
4586 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
4593 /***********************************************************************
4595 ***********************************************************************/
4598 /* Output a newline in the *Messages* buffer if "needs" one. */
4601 message_log_maybe_newline ()
4603 if (message_log_need_newline
)
4604 message_dolog ("", 0, 1, 0);
4608 /* Add a string M of length LEN to the message log, optionally
4609 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
4610 nonzero, means interpret the contents of M as multibyte. This
4611 function calls low-level routines in order to bypass text property
4612 hooks, etc. which might not be safe to run. */
4615 message_dolog (m
, len
, nlflag
, multibyte
)
4617 int len
, nlflag
, multibyte
;
4619 if (!NILP (Vmessage_log_max
))
4621 struct buffer
*oldbuf
;
4622 Lisp_Object oldpoint
, oldbegv
, oldzv
;
4623 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4624 int point_at_end
= 0;
4626 Lisp_Object old_deactivate_mark
, tem
;
4627 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4629 old_deactivate_mark
= Vdeactivate_mark
;
4630 oldbuf
= current_buffer
;
4631 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
4632 current_buffer
->undo_list
= Qt
;
4634 oldpoint
= Fpoint_marker ();
4635 oldbegv
= Fpoint_min_marker ();
4636 oldzv
= Fpoint_max_marker ();
4637 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
4645 BEGV_BYTE
= BEG_BYTE
;
4648 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4650 /* Insert the string--maybe converting multibyte to single byte
4651 or vice versa, so that all the text fits the buffer. */
4653 && NILP (current_buffer
->enable_multibyte_characters
))
4656 unsigned char work
[1];
4658 /* Convert a multibyte string to single-byte
4659 for the *Message* buffer. */
4660 for (i
= 0; i
< len
; i
+= nbytes
)
4662 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
4663 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
4665 : multibyte_char_to_unibyte (c
, Qnil
));
4666 insert_1_both (work
, 1, 1, 1, 0, 0);
4669 else if (! multibyte
4670 && ! NILP (current_buffer
->enable_multibyte_characters
))
4673 unsigned char *msg
= (unsigned char *) m
;
4674 unsigned char *str
, work
[4];
4675 /* Convert a single-byte string to multibyte
4676 for the *Message* buffer. */
4677 for (i
= 0; i
< len
; i
++)
4679 c
= unibyte_char_to_multibyte (msg
[i
]);
4680 nbytes
= CHAR_STRING (c
, work
, str
);
4681 insert_1_both (work
, 1, nbytes
, 1, 0, 0);
4685 insert_1 (m
, len
, 1, 0, 0);
4689 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
4690 insert_1 ("\n", 1, 1, 0, 0);
4692 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4694 this_bol_byte
= PT_BYTE
;
4698 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4700 prev_bol_byte
= PT_BYTE
;
4702 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
4703 this_bol
, this_bol_byte
);
4706 del_range_both (prev_bol
, prev_bol_byte
,
4707 this_bol
, this_bol_byte
, 0);
4713 /* If you change this format, don't forget to also
4714 change message_log_check_duplicate. */
4715 sprintf (dupstr
, " [%d times]", dup
);
4716 duplen
= strlen (dupstr
);
4717 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
4718 insert_1 (dupstr
, duplen
, 1, 0, 1);
4723 if (NATNUMP (Vmessage_log_max
))
4725 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
4726 -XFASTINT (Vmessage_log_max
) - 1, 0);
4727 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
4730 BEGV
= XMARKER (oldbegv
)->charpos
;
4731 BEGV_BYTE
= marker_byte_position (oldbegv
);
4740 ZV
= XMARKER (oldzv
)->charpos
;
4741 ZV_BYTE
= marker_byte_position (oldzv
);
4745 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4747 /* We can't do Fgoto_char (oldpoint) because it will run some
4749 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
4750 XMARKER (oldpoint
)->bytepos
);
4753 free_marker (oldpoint
);
4754 free_marker (oldbegv
);
4755 free_marker (oldzv
);
4757 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
4758 set_buffer_internal (oldbuf
);
4760 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
4761 message_log_need_newline
= !nlflag
;
4762 Vdeactivate_mark
= old_deactivate_mark
;
4767 /* We are at the end of the buffer after just having inserted a newline.
4768 (Note: We depend on the fact we won't be crossing the gap.)
4769 Check to see if the most recent message looks a lot like the previous one.
4770 Return 0 if different, 1 if the new one should just replace it, or a
4771 value N > 1 if we should also append " [N times]". */
4774 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
4775 int prev_bol
, this_bol
;
4776 int prev_bol_byte
, this_bol_byte
;
4779 int len
= Z_BYTE
- 1 - this_bol_byte
;
4781 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
4782 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
4784 for (i
= 0; i
< len
; i
++)
4786 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
4795 if (*p1
++ == ' ' && *p1
++ == '[')
4798 while (*p1
>= '0' && *p1
<= '9')
4799 n
= n
* 10 + *p1
++ - '0';
4800 if (strncmp (p1
, " times]\n", 8) == 0)
4807 /* Display an echo area message M with a specified length of LEN
4808 chars. The string may include null characters. If M is 0, clear
4809 out any existing message, and let the mini-buffer text show through.
4811 The buffer M must continue to exist until after the echo area gets
4812 cleared or some other message gets displayed there. This means do
4813 not pass text that is stored in a Lisp string; do not pass text in
4814 a buffer that was alloca'd. */
4817 message2 (m
, len
, multibyte
)
4822 /* First flush out any partial line written with print. */
4823 message_log_maybe_newline ();
4825 message_dolog (m
, len
, 1, multibyte
);
4826 message2_nolog (m
, len
, multibyte
);
4830 /* The non-logging counterpart of message2. */
4833 message2_nolog (m
, len
, multibyte
)
4837 message_enable_multibyte
= multibyte
;
4841 if (noninteractive_need_newline
)
4842 putc ('\n', stderr
);
4843 noninteractive_need_newline
= 0;
4845 fwrite (m
, len
, 1, stderr
);
4846 if (cursor_in_echo_area
== 0)
4847 fprintf (stderr
, "\n");
4850 /* A null message buffer means that the frame hasn't really been
4851 initialized yet. Error messages get reported properly by
4852 cmd_error, so this must be just an informative message; toss it. */
4853 else if (INTERACTIVE
4854 && selected_frame
->glyphs_initialized_p
4855 && FRAME_MESSAGE_BUF (selected_frame
))
4857 Lisp_Object mini_window
;
4860 /* Get the frame containing the mini-buffer
4861 that the selected frame is using. */
4862 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
4863 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4865 FRAME_SAMPLE_VISIBILITY (f
);
4866 if (FRAME_VISIBLE_P (selected_frame
)
4867 && ! FRAME_VISIBLE_P (f
))
4868 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
4872 echo_area_glyphs
= m
;
4873 echo_area_glyphs_length
= len
;
4874 echo_area_message
= Qnil
;
4876 if (minibuffer_auto_raise
)
4877 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
4881 echo_area_glyphs
= previous_echo_glyphs
= NULL
;
4882 echo_area_message
= previous_echo_area_message
= Qnil
;
4885 do_pending_window_change ();
4886 echo_area_display (1);
4887 do_pending_window_change ();
4888 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
4889 (*frame_up_to_date_hook
) (f
);
4894 /* Display an echo area message M with a specified length of LEN
4895 chars. The string may include null characters. If M is not a
4896 string, clear out any existing message, and let the mini-buffer
4897 text show through. */
4900 message3 (m
, len
, multibyte
)
4905 struct gcpro gcpro1
;
4909 /* First flush out any partial line written with print. */
4910 message_log_maybe_newline ();
4912 message_dolog (XSTRING (m
)->data
, len
, 1, multibyte
);
4913 message3_nolog (m
, len
, multibyte
);
4919 /* The non-logging version of message3. */
4922 message3_nolog (m
, len
, multibyte
)
4926 message_enable_multibyte
= multibyte
;
4930 if (noninteractive_need_newline
)
4931 putc ('\n', stderr
);
4932 noninteractive_need_newline
= 0;
4934 fwrite (XSTRING (m
)->data
, len
, 1, stderr
);
4935 if (cursor_in_echo_area
== 0)
4936 fprintf (stderr
, "\n");
4939 /* A null message buffer means that the frame hasn't really been
4940 initialized yet. Error messages get reported properly by
4941 cmd_error, so this must be just an informative message; toss it. */
4942 else if (INTERACTIVE
4943 && selected_frame
->glyphs_initialized_p
4944 && FRAME_MESSAGE_BUF (selected_frame
))
4946 Lisp_Object mini_window
;
4949 /* Get the frame containing the mini-buffer
4950 that the selected frame is using. */
4951 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
4952 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4954 FRAME_SAMPLE_VISIBILITY (f
);
4955 if (FRAME_VISIBLE_P (selected_frame
)
4956 && ! FRAME_VISIBLE_P (f
))
4957 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
4961 echo_area_glyphs
= NULL
;
4962 echo_area_message
= m
;
4963 echo_area_glyphs_length
= len
;
4965 if (minibuffer_auto_raise
)
4966 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
4970 echo_area_glyphs
= previous_echo_glyphs
= NULL
;
4971 echo_area_message
= previous_echo_area_message
= Qnil
;
4974 do_pending_window_change ();
4975 echo_area_display (1);
4976 do_pending_window_change ();
4977 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
4978 (*frame_up_to_date_hook
) (f
);
4983 /* Display a null-terminated echo area message M. If M is 0, clear
4984 out any existing message, and let the mini-buffer text show through.
4986 The buffer M must continue to exist until after the echo area gets
4987 cleared or some other message gets displayed there. Do not pass
4988 text that is stored in a Lisp string. Do not pass text in a buffer
4989 that was alloca'd. */
4995 message2 (m
, (m
? strlen (m
) : 0), 0);
4999 /* The non-logging counterpart of message1. */
5005 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5008 /* Display a message M which contains a single %s
5009 which gets replaced with STRING. */
5012 message_with_string (m
, string
, log
)
5021 if (noninteractive_need_newline
)
5022 putc ('\n', stderr
);
5023 noninteractive_need_newline
= 0;
5024 fprintf (stderr
, m
, XSTRING (string
)->data
);
5025 if (cursor_in_echo_area
== 0)
5026 fprintf (stderr
, "\n");
5030 else if (INTERACTIVE
)
5032 /* The frame whose minibuffer we're going to display the message on.
5033 It may be larger than the selected frame, so we need
5034 to use its buffer, not the selected frame's buffer. */
5035 Lisp_Object mini_window
;
5038 /* Get the frame containing the minibuffer
5039 that the selected frame is using. */
5040 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
5041 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5043 /* A null message buffer means that the frame hasn't really been
5044 initialized yet. Error messages get reported properly by
5045 cmd_error, so this must be just an informative message; toss it. */
5046 if (FRAME_MESSAGE_BUF (f
))
5050 a
[0] = (char *) XSTRING (string
)->data
;
5052 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5053 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5056 message2 (FRAME_MESSAGE_BUF (f
), len
,
5057 STRING_MULTIBYTE (string
));
5059 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5060 STRING_MULTIBYTE (string
));
5062 /* Print should start at the beginning of the message
5063 buffer next time. */
5064 message_buf_print
= 0;
5070 /* Truncate what will be displayed in the echo area
5071 the next time we display it--but don't redisplay it now. */
5074 truncate_echo_area (len
)
5077 /* A null message buffer means that the frame hasn't really been
5078 initialized yet. Error messages get reported properly by
5079 cmd_error, so this must be just an informative message; toss it. */
5080 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
5081 echo_area_glyphs_length
= len
;
5085 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by
5086 print; zero if being used by message. */
5088 int message_buf_print
;
5091 /* Dump an informative message to the minibuf. If M is 0, clear out
5092 any existing message, and let the mini-buffer text show through. */
5096 message (m
, a1
, a2
, a3
)
5098 EMACS_INT a1
, a2
, a3
;
5104 if (noninteractive_need_newline
)
5105 putc ('\n', stderr
);
5106 noninteractive_need_newline
= 0;
5107 fprintf (stderr
, m
, a1
, a2
, a3
);
5108 if (cursor_in_echo_area
== 0)
5109 fprintf (stderr
, "\n");
5113 else if (INTERACTIVE
)
5115 /* The frame whose mini-buffer we're going to display the message
5116 on. It may be larger than the selected frame, so we need to
5117 use its buffer, not the selected frame's buffer. */
5118 Lisp_Object mini_window
;
5121 /* Get the frame containing the mini-buffer
5122 that the selected frame is using. */
5123 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
5124 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5126 /* A null message buffer means that the frame hasn't really been
5127 initialized yet. Error messages get reported properly by
5128 cmd_error, so this must be just an informative message; toss
5130 if (FRAME_MESSAGE_BUF (f
))
5141 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5142 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5144 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5145 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5147 #endif /* NO_ARG_ARRAY */
5149 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5154 /* Print should start at the beginning of the message
5155 buffer next time. */
5156 message_buf_print
= 0;
5162 /* The non-logging version of message. */
5165 message_nolog (m
, a1
, a2
, a3
)
5167 EMACS_INT a1
, a2
, a3
;
5169 Lisp_Object old_log_max
;
5170 old_log_max
= Vmessage_log_max
;
5171 Vmessage_log_max
= Qnil
;
5172 message (m
, a1
, a2
, a3
);
5173 Vmessage_log_max
= old_log_max
;
5177 /* Display echo_area_message or echo_area_glyphs in the current
5183 if (STRINGP (echo_area_message
))
5184 message3 (echo_area_message
, echo_area_glyphs_length
,
5185 !NILP (current_buffer
->enable_multibyte_characters
));
5187 message2 (echo_area_glyphs
, echo_area_glyphs_length
,
5188 !NILP (current_buffer
->enable_multibyte_characters
));
5192 /* Redisplay the echo area of selected_frame. If UPDATE_FRAME_P is
5193 non-zero update selected_frame. */
5196 echo_area_display (update_frame_p
)
5199 Lisp_Object mini_window
;
5203 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
5204 w
= XWINDOW (mini_window
);
5205 f
= XFRAME (WINDOW_FRAME (w
));
5207 /* Don't display if frame is invisible or not yet initialized. */
5208 if (!FRAME_VISIBLE_P (f
)
5209 || !f
->glyphs_initialized_p
)
5212 /* When Emacs starts, selected_frame may be a visible terminal
5213 frame, even if we run under a window system. If we let this
5214 through, a message would be displayed on the terminal. */
5215 #ifdef HAVE_WINDOW_SYSTEM
5216 if (!inhibit_window_system
&& !FRAME_WINDOW_P (selected_frame
))
5218 #endif /* HAVE_WINDOW_SYSTEM */
5220 /* Redraw garbaged frames. */
5223 /* Old redisplay called redraw_garbaged_frames here which in
5224 turn called redraw_frame which in turn called clear_frame.
5225 The call to clear_frame is a source of flickering. After
5226 checking the places where SET_FRAME_GARBAGED is called, I
5227 believe a clear_frame is not necessary. It should suffice in
5228 the new redisplay to invalidate all current matrices, and
5229 ensure a complete redisplay of all windows. */
5230 Lisp_Object tail
, frame
;
5232 FOR_EACH_FRAME (tail
, frame
)
5234 struct frame
*f
= XFRAME (frame
);
5236 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
5238 clear_current_matrices (f
);
5244 ++windows_or_buffers_changed
;
5247 if (echo_area_glyphs
5248 || STRINGP (echo_area_message
)
5249 || minibuf_level
== 0)
5253 echo_area_window
= mini_window
;
5254 clear_glyph_matrix (w
->desired_matrix
);
5255 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, DEFAULT_FACE_ID
);
5257 if (STRINGP (echo_area_message
)
5258 && echo_area_glyphs_length
)
5260 prepare_desired_row (it
.glyph_row
);
5261 display_string (NULL
, echo_area_message
, Qnil
, 0, 0,
5262 &it
, -1, echo_area_glyphs_length
, 0,
5263 message_enable_multibyte
);
5264 it
.glyph_row
->truncated_on_right_p
= 0;
5265 compute_line_metrics (&it
);
5267 else if (echo_area_glyphs
5268 && echo_area_glyphs_length
)
5270 prepare_desired_row (it
.glyph_row
);
5271 display_string (echo_area_glyphs
, Qnil
, Qnil
, 0, 0, &it
,
5272 -1, echo_area_glyphs_length
, 0,
5273 message_enable_multibyte
);
5274 it
.glyph_row
->truncated_on_right_p
= 0;
5275 compute_line_metrics (&it
);
5278 blank_row (w
, it
.glyph_row
, 0);
5280 it
.glyph_row
->y
= it
.current_y
;
5281 it
.current_y
+= it
.glyph_row
->height
;
5283 /* Clear the rest of the lines. */
5284 while (it
.current_y
< it
.last_visible_y
)
5287 blank_row (w
, it
.glyph_row
, it
.current_y
);
5288 it
.current_y
+= it
.glyph_row
->height
;
5291 w
->must_be_updated_p
= 1;
5294 /* Calling update_single_window is faster when we can use
5295 window-based redisplay. */
5296 if (FRAME_WINDOW_P (f
))
5298 update_single_window (w
, 1);
5299 rif
->flush_display (f
);
5302 update_frame (f
, 1, 1);
5305 else if (!EQ (mini_window
, selected_window
))
5306 windows_or_buffers_changed
++;
5308 /* Prevent redisplay optimization in redisplay_internal by resetting
5309 this_line_start_pos. This is done because the mini-buffer now
5310 displays the message instead of its buffer text. */
5311 if (EQ (mini_window
, selected_window
))
5312 CHARPOS (this_line_start_pos
) = 0;
5314 previous_echo_glyphs
= echo_area_glyphs
;
5315 previous_echo_area_message
= echo_area_message
;
5316 previous_echo_glyphs_length
= echo_area_glyphs_length
;
5321 /***********************************************************************
5323 ***********************************************************************/
5326 #ifdef HAVE_WINDOW_SYSTEM
5328 /* A buffer for constructing frame titles in it; allocated from the
5329 heap in init_xdisp and resized as needed in store_frame_title_char. */
5331 static char *frame_title_buf
;
5333 /* The buffer's end, and a current output position in it. */
5335 static char *frame_title_buf_end
;
5336 static char *frame_title_ptr
;
5339 /* Store a single character C for the frame title in frame_title_buf.
5340 Re-allocate frame_title_buf if necessary. */
5343 store_frame_title_char (c
)
5346 /* If output position has reached the end of the allocated buffer,
5347 double the buffer's size. */
5348 if (frame_title_ptr
== frame_title_buf_end
)
5350 int len
= frame_title_ptr
- frame_title_buf
;
5351 int new_size
= 2 * len
* sizeof *frame_title_buf
;
5352 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
5353 frame_title_buf_end
= frame_title_buf
+ new_size
;
5354 frame_title_ptr
= frame_title_buf
+ len
;
5357 *frame_title_ptr
++ = c
;
5361 /* Store part of a frame title in frame_title_buf, beginning at
5362 frame_title_ptr. STR is the string to store. Do not copy more
5363 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
5364 the whole string. Pad with spaces until FIELD_WIDTH number of
5365 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
5366 Called from display_mode_element when it is used to build a frame
5370 store_frame_title (str
, field_width
, precision
)
5372 int field_width
, precision
;
5376 /* Copy at most PRECISION chars from STR. */
5377 while ((precision
<= 0 || n
< precision
)
5380 store_frame_title_char (*str
++);
5384 /* Fill up with spaces until FIELD_WIDTH reached. */
5385 while (field_width
> 0
5388 store_frame_title_char (' ');
5396 /* Set the title of FRAME, if it has changed. The title format is
5397 Vicon_title_format if FRAME is iconified, otherwise it is
5398 frame_title_format. */
5401 x_consider_frame_title (frame
)
5404 struct frame
*f
= XFRAME (frame
);
5406 if (FRAME_WINDOW_P (f
)
5407 || FRAME_MINIBUF_ONLY_P (f
)
5408 || f
->explicit_name
)
5410 /* Do we have more than one visible frame on this X display? */
5413 struct buffer
*obuf
;
5417 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5419 struct frame
*tf
= XFRAME (XCONS (tail
)->car
);
5422 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
5423 && !FRAME_MINIBUF_ONLY_P (tf
)
5424 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
5428 /* Set global variable indicating that multiple frames exist. */
5429 multiple_frames
= CONSP (tail
);
5431 /* Switch to the buffer of selected window of the frame. Set up
5432 frame_title_ptr so that display_mode_element will output into it;
5433 then display the title. */
5434 obuf
= current_buffer
;
5435 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
5436 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
5437 frame_title_ptr
= frame_title_buf
;
5438 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
5439 NULL
, DEFAULT_FACE_ID
);
5440 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
5441 frame_title_ptr
= NULL
;
5442 set_buffer_internal (obuf
);
5444 /* Set the title only if it's changed. This avoids consing in
5445 the common case where it hasn't. (If it turns out that we've
5446 already wasted too much time by walking through the list with
5447 display_mode_element, then we might need to optimize at a
5448 higher level than this.) */
5449 if (! STRINGP (f
->name
)
5450 || STRING_BYTES (XSTRING (f
->name
)) != len
5451 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
5452 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
5456 #else /* not HAVE_WINDOW_SYSTEM */
5458 #define frame_title_ptr ((char *)0)
5459 #define store_frame_title(str, mincol, maxcol) 0
5461 #endif /* not HAVE_WINDOW_SYSTEM */
5466 /***********************************************************************
5468 ***********************************************************************/
5471 /* Prepare for redisplay by updating menu-bar item lists when
5472 appropriate. This can call eval. */
5475 prepare_menu_bars ()
5478 struct gcpro gcpro1
, gcpro2
;
5480 struct frame
*tooltip_frame
;
5482 #ifdef HAVE_X_WINDOWS
5483 tooltip_frame
= tip_frame
;
5485 tooltip_frame
= NULL
;
5488 /* Update all frame titles based on their buffer names, etc. We do
5489 this before the menu bars so that the buffer-menu will show the
5490 up-to-date frame titles. */
5491 #ifdef HAVE_WINDOW_SYSTEM
5492 if (windows_or_buffers_changed
|| update_mode_lines
)
5494 Lisp_Object tail
, frame
;
5496 FOR_EACH_FRAME (tail
, frame
)
5499 if (f
!= tooltip_frame
5500 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
5501 x_consider_frame_title (frame
);
5504 #endif /* HAVE_WINDOW_SYSTEM */
5506 /* Update the menu bar item lists, if appropriate. This has to be
5507 done before any actual redisplay or generation of display lines. */
5508 all_windows
= (update_mode_lines
5509 || buffer_shared
> 1
5510 || windows_or_buffers_changed
);
5513 Lisp_Object tail
, frame
;
5514 int count
= specpdl_ptr
- specpdl
;
5516 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
5518 FOR_EACH_FRAME (tail
, frame
)
5522 /* Ignore tooltip frame. */
5523 if (f
== tooltip_frame
)
5526 /* If a window on this frame changed size, report that to
5527 the user and clear the size-change flag. */
5528 if (FRAME_WINDOW_SIZES_CHANGED (f
))
5530 Lisp_Object functions
;
5532 /* Clear flag first in case we get an error below. */
5533 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
5534 functions
= Vwindow_size_change_functions
;
5535 GCPRO2 (tail
, functions
);
5537 while (CONSP (functions
))
5539 call1 (XCAR (functions
), frame
);
5540 functions
= XCDR (functions
);
5546 update_menu_bar (f
, 0);
5547 #ifdef HAVE_WINDOW_SYSTEM
5548 update_toolbar (f
, 0);
5553 unbind_to (count
, Qnil
);
5557 update_menu_bar (selected_frame
, 1);
5558 #ifdef HAVE_WINDOW_SYSTEM
5559 update_toolbar (selected_frame
, 1);
5563 /* Motif needs this. See comment in xmenu.c. Turn it off when
5564 pending_menu_activation is not defined. */
5565 #ifdef USE_X_TOOLKIT
5566 pending_menu_activation
= 0;
5571 /* Update the menu bar item list for frame F. This has to be done
5572 before we start to fill in any display lines, because it can call
5575 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
5578 update_menu_bar (f
, save_match_data
)
5580 int save_match_data
;
5583 register struct window
*w
;
5585 window
= FRAME_SELECTED_WINDOW (f
);
5586 w
= XWINDOW (window
);
5588 if (update_mode_lines
)
5589 w
->update_mode_line
= Qt
;
5591 if (FRAME_WINDOW_P (f
)
5593 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
5594 FRAME_EXTERNAL_MENU_BAR (f
)
5596 FRAME_MENU_BAR_LINES (f
) > 0
5598 : FRAME_MENU_BAR_LINES (f
) > 0)
5600 /* If the user has switched buffers or windows, we need to
5601 recompute to reflect the new bindings. But we'll
5602 recompute when update_mode_lines is set too; that means
5603 that people can use force-mode-line-update to request
5604 that the menu bar be recomputed. The adverse effect on
5605 the rest of the redisplay algorithm is about the same as
5606 windows_or_buffers_changed anyway. */
5607 if (windows_or_buffers_changed
5608 || !NILP (w
->update_mode_line
)
5609 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
5610 < BUF_MODIFF (XBUFFER (w
->buffer
)))
5611 != !NILP (w
->last_had_star
))
5612 || ((!NILP (Vtransient_mark_mode
)
5613 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
5614 != !NILP (w
->region_showing
)))
5616 struct buffer
*prev
= current_buffer
;
5617 int count
= specpdl_ptr
- specpdl
;
5619 set_buffer_internal_1 (XBUFFER (w
->buffer
));
5620 if (save_match_data
)
5621 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
5622 if (NILP (Voverriding_local_map_menu_flag
))
5624 specbind (Qoverriding_terminal_local_map
, Qnil
);
5625 specbind (Qoverriding_local_map
, Qnil
);
5628 /* Run the Lucid hook. */
5629 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
5631 /* If it has changed current-menubar from previous value,
5632 really recompute the menu-bar from the value. */
5633 if (! NILP (Vlucid_menu_bar_dirty_flag
))
5634 call0 (Qrecompute_lucid_menubar
);
5636 safe_run_hooks (Qmenu_bar_update_hook
);
5637 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
5639 /* Redisplay the menu bar in case we changed it. */
5640 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
5641 if (FRAME_WINDOW_P (f
))
5642 set_frame_menubar (f
, 0, 0);
5644 /* On a terminal screen, the menu bar is an ordinary screen
5645 line, and this makes it get updated. */
5646 w
->update_mode_line
= Qt
;
5647 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
5648 /* In the non-toolkit version, the menu bar is an ordinary screen
5649 line, and this makes it get updated. */
5650 w
->update_mode_line
= Qt
;
5651 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
5653 unbind_to (count
, Qnil
);
5654 set_buffer_internal_1 (prev
);
5661 /***********************************************************************
5663 ***********************************************************************/
5665 #ifdef HAVE_WINDOW_SYSTEM
5667 /* Update the toolbar item list for frame F. This has to be done
5668 before we start to fill in any display lines. Called from
5669 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
5670 and restore it here. */
5673 update_toolbar (f
, save_match_data
)
5675 int save_match_data
;
5677 if (WINDOWP (f
->toolbar_window
)
5678 && XFASTINT (XWINDOW (f
->toolbar_window
)->height
) > 0)
5683 window
= FRAME_SELECTED_WINDOW (f
);
5684 w
= XWINDOW (window
);
5686 /* If the user has switched buffers or windows, we need to
5687 recompute to reflect the new bindings. But we'll
5688 recompute when update_mode_lines is set too; that means
5689 that people can use force-mode-line-update to request
5690 that the menu bar be recomputed. The adverse effect on
5691 the rest of the redisplay algorithm is about the same as
5692 windows_or_buffers_changed anyway. */
5693 if (windows_or_buffers_changed
5694 || !NILP (w
->update_mode_line
)
5695 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
5696 < BUF_MODIFF (XBUFFER (w
->buffer
)))
5697 != !NILP (w
->last_had_star
))
5698 || ((!NILP (Vtransient_mark_mode
)
5699 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
5700 != !NILP (w
->region_showing
)))
5702 struct buffer
*prev
= current_buffer
;
5703 int count
= specpdl_ptr
- specpdl
;
5705 /* Set current_buffer to the buffer of the selected
5706 window of the frame, so that we get the right local
5708 set_buffer_internal_1 (XBUFFER (w
->buffer
));
5710 /* Save match data, if we must. */
5711 if (save_match_data
)
5712 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
5714 /* Make sure that we don't accidentally use bogus keymaps. */
5715 if (NILP (Voverriding_local_map_menu_flag
))
5717 specbind (Qoverriding_terminal_local_map
, Qnil
);
5718 specbind (Qoverriding_local_map
, Qnil
);
5721 /* Build desired toolbar items from keymaps. */
5722 f
->desired_toolbar_items
5723 = toolbar_items (f
->desired_toolbar_items
,
5724 &f
->n_desired_toolbar_items
);
5726 /* Redisplay the toolbar in case we changed it. */
5727 w
->update_mode_line
= Qt
;
5729 unbind_to (count
, Qnil
);
5730 set_buffer_internal_1 (prev
);
5736 /* Set F->desired_toolbar_string to a Lisp string representing frame
5737 F's desired toolbar contents. F->desired_toolbar_items must have
5738 been set up previously by calling prepare_menu_bars. */
5741 build_desired_toolbar_string (f
)
5744 int i
, size
, size_needed
, string_idx
;
5745 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5746 Lisp_Object image
, plist
, props
;
5748 image
= plist
= props
= Qnil
;
5749 GCPRO3 (image
, plist
, props
);
5751 /* Prepare F->desired_toolbar_string. If we can reuse it, do so.
5752 Otherwise, make a new string. */
5754 /* The size of the string we might be able to reuse. */
5755 size
= (STRINGP (f
->desired_toolbar_string
)
5756 ? XSTRING (f
->desired_toolbar_string
)->size
5759 /* Each image in the string we build is preceded by a space,
5760 and there is a space at the end. */
5761 size_needed
= f
->n_desired_toolbar_items
+ 1;
5763 /* Reuse f->desired_toolbar_string, if possible. */
5764 if (size
< size_needed
)
5765 f
->desired_toolbar_string
= Fmake_string (make_number (size_needed
), ' ');
5768 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
5769 Fremove_text_properties (make_number (0), make_number (size
),
5770 props
, f
->desired_toolbar_string
);
5773 /* Put a `display' property on the string for the images to display,
5774 put a `menu_item' property on toolbar items with a value that
5775 is the index of the item in F's toolbar item vector. */
5776 for (i
= 0, string_idx
= 0;
5777 i
< f
->n_desired_toolbar_items
;
5778 ++i
, string_idx
+= 1)
5781 (XVECTOR (f->desired_toolbar_items) \
5782 ->contents[i * TOOLBAR_ITEM_NSLOTS + (IDX)])
5784 int enabled_p
= !NILP (PROP (TOOLBAR_ITEM_ENABLED_P
));
5785 int selected_p
= !NILP (PROP (TOOLBAR_ITEM_SELECTED_P
));
5787 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
5788 extern Lisp_Object Qlaplace
;
5790 /* If image is a vector, choose the image according to the
5792 image
= PROP (TOOLBAR_ITEM_IMAGES
);
5793 if (VECTORP (image
))
5795 enum toolbar_item_image idx
;
5799 ? TOOLBAR_IMAGE_ENABLED_SELECTED
5800 : TOOLBAR_IMAGE_ENABLED_DESELECTED
);
5803 ? TOOLBAR_IMAGE_DISABLED_SELECTED
5804 : TOOLBAR_IMAGE_DISABLED_DESELECTED
);
5806 xassert (XVECTOR (image
)->size
>= idx
);
5807 image
= XVECTOR (image
)->contents
[idx
];
5810 /* Ignore invalid image specifications. */
5811 if (!valid_image_p (image
))
5814 /* Display the toolbar button pressed, or depressed. */
5815 plist
= Fcopy_sequence (XCDR (image
));
5817 /* Compute margin and relief to draw. */
5818 relief
= toolbar_button_relief
> 0 ? toolbar_button_relief
: 3;
5819 margin
= relief
+ max (0, toolbar_button_margin
);
5821 if (auto_raise_toolbar_buttons_p
)
5823 /* Add a `:relief' property to the image spec if the item is
5827 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
5833 /* If image is selected, display it pressed, i.e. with a
5834 negative relief. If it's not selected, display it with a
5836 plist
= Fplist_put (plist
, QCrelief
,
5838 ? make_number (-relief
)
5839 : make_number (relief
)));
5843 /* Put a margin around the image. */
5845 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
5847 /* If button is not enabled, make the image appear disabled by
5848 applying an appropriate algorithm to it. */
5850 plist
= Fplist_put (plist
, QCalgorithm
, Qlaplace
);
5852 /* Put a `display' text property on the string for the image to
5853 display. Put a `menu-item' property on the string that gives
5854 the start of this item's properties in the toolbar items
5856 image
= Fcons (Qimage
, plist
);
5857 props
= list4 (Qdisplay
, image
,
5858 Qmenu_item
, make_number (i
* TOOLBAR_ITEM_NSLOTS
)),
5859 Fadd_text_properties (make_number (string_idx
),
5860 make_number (string_idx
+ 1),
5861 props
, f
->desired_toolbar_string
);
5869 /* Display one line of the toolbar of frame IT->f. */
5872 display_toolbar_line (it
)
5875 struct glyph_row
*row
= it
->glyph_row
;
5876 int max_x
= it
->last_visible_x
;
5879 prepare_desired_row (row
);
5880 row
->y
= it
->current_y
;
5882 while (it
->current_x
< max_x
)
5884 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
5886 /* Get the next display element. */
5887 if (!get_next_display_element (it
))
5890 /* Produce glyphs. */
5891 x_before
= it
->current_x
;
5892 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
5893 PRODUCE_GLYPHS (it
);
5895 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
5900 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
5902 if (x
+ glyph
->pixel_width
> max_x
)
5904 /* Glyph doesn't fit on line. */
5905 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
5911 x
+= glyph
->pixel_width
;
5915 /* Stop at line ends. */
5916 if (ITERATOR_AT_END_OF_LINE_P (it
))
5919 set_iterator_to_next (it
);
5924 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
5925 extend_face_to_end_of_line (it
);
5926 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
5927 last
->right_box_line_p
= 1;
5928 compute_line_metrics (it
);
5930 /* If line is empty, make it occupy the rest of the toolbar. */
5931 if (!row
->displays_text_p
)
5933 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
5934 row
->ascent
= row
->phys_ascent
= 0;
5937 row
->full_width_p
= 1;
5938 row
->continued_p
= 0;
5939 row
->truncated_on_left_p
= 0;
5940 row
->truncated_on_right_p
= 0;
5942 it
->current_x
= it
->hpos
= 0;
5943 it
->current_y
+= row
->height
;
5949 /* Value is the number of screen lines needed to make all toolbar
5950 items of frame F visible. */
5953 toolbar_lines_needed (f
)
5956 struct window
*w
= XWINDOW (f
->toolbar_window
);
5959 /* Initialize an iterator for iteration over F->desired_toolbar_string
5960 in the toolbar window of frame F. */
5961 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOLBAR_FACE_ID
);
5962 it
.first_visible_x
= 0;
5963 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
5964 reseat_to_string (&it
, NULL
, f
->desired_toolbar_string
, 0, 0, 0, -1);
5966 while (!ITERATOR_AT_END_P (&it
))
5968 it
.glyph_row
= w
->desired_matrix
->rows
;
5969 clear_glyph_row (it
.glyph_row
);
5970 display_toolbar_line (&it
);
5973 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
5977 /* Display the toolbar of frame F. Value is non-zero if toolbar's
5978 height should be changed. */
5981 redisplay_toolbar (f
)
5986 struct glyph_row
*row
;
5987 int change_height_p
= 0;
5989 /* If frame hasn't a toolbar window or if it is zero-height, don't
5990 do anything. This means you must start with toolbar-lines
5991 non-zero to get the auto-sizing effect. Or in other words, you
5992 can turn off toolbars by specifying toolbar-lines zero. */
5993 if (!WINDOWP (f
->toolbar_window
)
5994 || (w
= XWINDOW (f
->toolbar_window
),
5995 XFASTINT (w
->height
) == 0))
5998 /* Set up an iterator for the toolbar window. */
5999 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOLBAR_FACE_ID
);
6000 it
.first_visible_x
= 0;
6001 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6004 /* Build a string that represents the contents of the toolbar. */
6005 build_desired_toolbar_string (f
);
6006 reseat_to_string (&it
, NULL
, f
->desired_toolbar_string
, 0, 0, 0, -1);
6008 /* Display as many lines as needed to display all toolbar items. */
6009 while (it
.current_y
< it
.last_visible_y
)
6010 display_toolbar_line (&it
);
6012 /* It doesn't make much sense to try scrolling in the toolbar
6013 window, so don't do it. */
6014 w
->desired_matrix
->no_scrolling_p
= 1;
6015 w
->must_be_updated_p
= 1;
6017 if (auto_resize_toolbars_p
)
6021 /* If there are blank lines at the end, except for a partially
6022 visible blank line at the end that is smaller than
6023 CANON_Y_UNIT, change the toolbar's height. */
6024 row
= it
.glyph_row
- 1;
6025 if (!row
->displays_text_p
6026 && row
->height
>= CANON_Y_UNIT (f
))
6027 change_height_p
= 1;
6029 /* If row displays toolbar items, but is partially visible,
6030 change the toolbar's height. */
6031 if (row
->displays_text_p
6032 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
6033 change_height_p
= 1;
6035 /* Resize windows as needed by changing the `toolbar-lines'
6038 && (nlines
= toolbar_lines_needed (f
),
6039 nlines
!= XFASTINT (w
->height
)))
6041 extern Lisp_Object Qtoolbar_lines
;
6044 XSETFRAME (frame
, f
);
6045 clear_glyph_matrix (w
->desired_matrix
);
6046 Fmodify_frame_parameters (frame
,
6047 Fcons (Fcons (Qtoolbar_lines
,
6048 make_number (nlines
)),
6050 fonts_changed_p
= 1;
6054 return change_height_p
;
6058 /* Get information about the toolbar item which is displayed in GLYPH
6059 on frame F. Return in *PROP_IDX the index where toolbar item
6060 properties start in F->current_toolbar_items. Value is zero if
6061 GLYPH doesn't display a toolbar item. */
6064 toolbar_item_info (f
, glyph
, prop_idx
)
6066 struct glyph
*glyph
;
6072 /* Get the text property `menu-item' at pos. The value of that
6073 property is the start index of this item's properties in
6074 F->current_toolbar_items. */
6075 prop
= Fget_text_property (make_number (glyph
->charpos
),
6076 Qmenu_item
, f
->current_toolbar_string
);
6077 if (INTEGERP (prop
))
6079 *prop_idx
= XINT (prop
);
6088 #endif /* HAVE_WINDOW_SYSTEM */
6092 /************************************************************************
6093 Horizontal scrolling
6094 ************************************************************************/
6096 static int hscroll_window_tree
P_ ((Lisp_Object
));
6097 static int hscroll_windows
P_ ((Lisp_Object
));
6099 /* For all leaf windows in the window tree rooted at WINDOW, set their
6100 hscroll value so that PT is (i) visible in the window, and (ii) so
6101 that it is not within a certain margin at the window's left and
6102 right border. Value is non-zero if any window's hscroll has been
6106 hscroll_window_tree (window
)
6109 int hscrolled_p
= 0;
6111 while (WINDOWP (window
))
6113 struct window
*w
= XWINDOW (window
);
6115 if (WINDOWP (w
->hchild
))
6116 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
6117 else if (WINDOWP (w
->vchild
))
6118 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
6119 else if (w
->cursor
.vpos
>= 0)
6121 int hscroll_margin
, text_area_x
, text_area_y
;
6122 int text_area_width
, text_area_height
;
6123 struct glyph_row
*cursor_row
= MATRIX_ROW (w
->current_matrix
,
6126 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
6127 &text_area_width
, &text_area_height
);
6129 /* Scroll when cursor is inside this scroll margin. */
6130 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
6132 if ((XFASTINT (w
->hscroll
)
6133 && w
->cursor
.x
< hscroll_margin
)
6134 || (cursor_row
->truncated_on_right_p
6135 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
6139 struct buffer
*saved_current_buffer
;
6142 /* Find point in a display of infinite width. */
6143 saved_current_buffer
= current_buffer
;
6144 current_buffer
= XBUFFER (w
->buffer
);
6146 if (w
== XWINDOW (selected_window
))
6147 pt
= BUF_PT (current_buffer
);
6150 pt
= marker_position (w
->pointm
);
6151 pt
= max (BEGV
, pt
);
6155 /* Move iterator to pt starting at cursor_row->start in
6156 a line with infinite width. */
6157 init_to_row_start (&it
, w
, cursor_row
);
6158 it
.last_visible_x
= INFINITY
;
6159 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
6160 current_buffer
= saved_current_buffer
;
6162 /* Center cursor in window. */
6163 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
6164 / CANON_X_UNIT (it
.f
));
6166 /* Don't call Fset_window_hscroll if value hasn't
6167 changed because it will prevent redisplay
6169 if (XFASTINT (w
->hscroll
) != hscroll
)
6171 Fset_window_hscroll (window
, make_number (hscroll
));
6180 /* Value is non-zero if hscroll of any leaf window has been changed. */
6185 /* Set hscroll so that cursor is visible and not inside horizontal
6186 scroll margins for all windows in the tree rooted at WINDOW. See
6187 also hscroll_window_tree above. Value is non-zero if any window's
6188 hscroll has been changed. If it has, desired matrices on the frame
6189 of WINDOW are cleared. */
6192 hscroll_windows (window
)
6195 int hscrolled_p
= hscroll_window_tree (window
);
6197 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
6203 /************************************************************************
6205 ************************************************************************/
6207 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
6208 to a non-zero value. This is sometimes handy to have in a debugger
6213 /* Values of beg_unchanged and end_unchanged as of last call to
6216 int debug_beg_unchanged
, debug_end_unchanged
;
6218 /* First and last unchanged row for try_window_id. */
6220 int debug_first_unchanged_at_end_vpos
;
6221 int debug_last_unchanged_at_beg_vpos
;
6223 /* Delta vpos and y. */
6225 int debug_dvpos
, debug_dy
;
6227 /* Delta in characters and bytes for try_window_id. */
6229 int debug_delta
, debug_delta_bytes
;
6231 /* Values of window_end_pos and window_end_vpos at the end of
6234 int debug_end_pos
, debug_end_vpos
;
6236 /* Append a string to W->desired_matrix->method. FMT is a printf
6237 format string. A1...A9 are a supplement for a variable-length
6238 argument list. If trace_redisplay_p is non-zero also printf the
6239 resulting string to stderr. */
6242 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
6245 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
6248 char *method
= w
->desired_matrix
->method
;
6249 int len
= strlen (method
);
6250 int size
= sizeof w
->desired_matrix
->method
;
6251 int remaining
= size
- len
- 1;
6253 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
6254 if (len
&& remaining
)
6260 strncpy (method
+ len
, buffer
, remaining
);
6262 if (trace_redisplay_p
)
6263 fprintf (stderr
, "%p (%s): %s\n",
6265 ((BUFFERP (w
->buffer
)
6266 && STRINGP (XBUFFER (w
->buffer
)->name
))
6267 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
6272 #endif /* GLYPH_DEBUG */
6275 /* This counter is used to clear the face cache every once in a while
6276 in redisplay_internal. It is incremented for each redisplay.
6277 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
6280 #define CLEAR_FACE_CACHE_COUNT 10000
6281 static int clear_face_cache_count
;
6283 /* Record the previous terminal frame we displayed. */
6285 static struct frame
*previous_terminal_frame
;
6287 /* Non-zero while redisplay_internal is in progress. */
6292 /* Value is non-zero if all changes in window W, which displays
6293 current_buffer, are in the text between START and END. START is a
6294 buffer position, END is given as a distance from Z. Used in
6295 redisplay_internal for display optimization. */
6298 text_outside_line_unchanged_p (w
, start
, end
)
6302 int unchanged_p
= 1;
6304 /* If text or overlays have changed, see where. */
6305 if (XFASTINT (w
->last_modified
) < MODIFF
6306 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
6308 /* Gap in the line? */
6309 if (GPT
< start
|| Z
- GPT
< end
)
6312 /* Changes start in front of the line, or end after it? */
6314 && (beg_unchanged
< start
- 1
6315 || end_unchanged
< end
))
6318 /* If selective display, can't optimize if changes start at the
6319 beginning of the line. */
6321 && INTEGERP (current_buffer
->selective_display
)
6322 && XINT (current_buffer
->selective_display
) > 0
6323 && (beg_unchanged
< start
|| GPT
<= start
))
6331 /* Do a frame update, taking possible shortcuts into account. This is
6332 the main external entry point for redisplay.
6334 If the last redisplay displayed an echo area message and that message
6335 is no longer requested, we clear the echo area or bring back the
6336 mini-buffer if that is in use. */
6341 redisplay_internal (0);
6345 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
6346 response to any user action; therefore, we should preserve the echo
6347 area. (Actually, our caller does that job.) Perhaps in the future
6348 avoid recentering windows if it is not necessary; currently that
6349 causes some problems. */
6352 redisplay_internal (preserve_echo_area
)
6353 int preserve_echo_area
;
6355 struct window
*w
= XWINDOW (selected_window
);
6356 struct frame
*f
= XFRAME (w
->frame
);
6358 int must_finish
= 0;
6359 struct text_pos tlbufpos
, tlendpos
;
6360 int number_of_visible_frames
;
6362 /* Non-zero means redisplay has to consider all windows on all
6363 frames. Zero means, only selected_window is considered. */
6364 int consider_all_windows_p
;
6366 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
6368 /* No redisplay if running in batch mode or frame is not yet fully
6369 initialized, or redisplay is explicitly turned off by setting
6370 Vinhibit_redisplay. */
6372 || !NILP (Vinhibit_redisplay
)
6373 || !f
->glyphs_initialized_p
)
6376 /* The flag redisplay_performed_directly_p is set by
6377 direct_output_for_insert when it already did the whole screen
6378 update necessary. */
6379 if (redisplay_performed_directly_p
)
6381 redisplay_performed_directly_p
= 0;
6382 if (!hscroll_windows (selected_window
))
6386 #ifdef USE_X_TOOLKIT
6387 if (popup_activated ())
6397 /* If new fonts have been loaded that make a glyph matrix adjustment
6398 necessary, do it. */
6399 if (fonts_changed_p
)
6401 adjust_glyphs (NULL
);
6402 ++windows_or_buffers_changed
;
6403 fonts_changed_p
= 0;
6406 if (! FRAME_WINDOW_P (selected_frame
)
6407 && previous_terminal_frame
!= selected_frame
)
6409 /* Since frames on an ASCII terminal share the same display
6410 area, displaying a different frame means redisplay the whole
6412 windows_or_buffers_changed
++;
6413 SET_FRAME_GARBAGED (selected_frame
);
6414 XSETFRAME (Vterminal_frame
, selected_frame
);
6416 previous_terminal_frame
= selected_frame
;
6418 /* Set the visible flags for all frames. Do this before checking
6419 for resized or garbaged frames; they want to know if their frames
6420 are visible. See the comment in frame.h for
6421 FRAME_SAMPLE_VISIBILITY. */
6423 Lisp_Object tail
, frame
;
6425 number_of_visible_frames
= 0;
6427 FOR_EACH_FRAME (tail
, frame
)
6429 struct frame
*f
= XFRAME (frame
);
6431 FRAME_SAMPLE_VISIBILITY (f
);
6432 if (FRAME_VISIBLE_P (f
))
6433 ++number_of_visible_frames
;
6434 clear_desired_matrices (f
);
6438 /* Notice any pending interrupt request to change frame size. */
6439 do_pending_window_change ();
6441 /* Clear frames marked as garbaged. */
6444 /* Old redisplay called redraw_garbaged_frames here which in
6445 turn called redraw_frame which in turn called clear_frame.
6446 The call to clear_frame is a source of flickering. After
6447 checking the places where SET_FRAME_GARBAGED is called, I
6448 believe a clear_frame is not necessary. It should suffice in
6449 the new redisplay to invalidate all current matrices, and
6450 ensure a complete redisplay of all windows. */
6451 Lisp_Object tail
, frame
;
6453 FOR_EACH_FRAME (tail
, frame
)
6455 struct frame
*f
= XFRAME (frame
);
6457 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6459 clear_current_matrices (f
);
6465 ++windows_or_buffers_changed
;
6468 /* Build menubar and toolbar items. */
6469 prepare_menu_bars ();
6471 if (windows_or_buffers_changed
)
6472 update_mode_lines
++;
6474 /* Detect case that we need to write or remove a star in the mode line. */
6475 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
6477 w
->update_mode_line
= Qt
;
6478 if (buffer_shared
> 1)
6479 update_mode_lines
++;
6482 /* If %c is in the mode line, update it if needed. */
6483 if (!NILP (w
->column_number_displayed
)
6484 /* This alternative quickly identifies a common case
6485 where no change is needed. */
6486 && !(PT
== XFASTINT (w
->last_point
)
6487 && XFASTINT (w
->last_modified
) >= MODIFF
6488 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
6489 && XFASTINT (w
->column_number_displayed
) != current_column ())
6490 w
->update_mode_line
= Qt
;
6492 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
6494 /* The variable buffer_shared is set in redisplay_window and
6495 indicates that we redisplay a buffer in different windows. See
6497 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
6499 /* If specs for an arrow have changed, do thorough redisplay
6500 to ensure we remove any arrow that should no longer exist. */
6501 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
6502 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
6503 consider_all_windows_p
= windows_or_buffers_changed
= 1;
6505 /* Normally the message* functions will have already displayed and
6506 updated the echo area, but the frame may have been trashed, or
6507 the update may have been preempted, so display the echo area
6509 if (echo_area_glyphs
6510 || STRINGP (echo_area_message
)
6511 || previous_echo_glyphs
6512 || STRINGP (previous_echo_area_message
))
6514 echo_area_display (0);
6518 /* If showing the region, and mark has changed, we must redisplay
6519 the whole window. The assignment to this_line_start_pos prevents
6520 the optimization directly below this if-statement. */
6521 if (((!NILP (Vtransient_mark_mode
)
6522 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6523 != !NILP (w
->region_showing
))
6524 || (!NILP (w
->region_showing
)
6525 && !EQ (w
->region_showing
,
6526 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
6527 CHARPOS (this_line_start_pos
) = 0;
6529 /* Optimize the case that only the line containing the cursor in the
6530 selected window has changed. Variables starting with this_ are
6531 set in display_line and record information about the line
6532 containing the cursor. */
6533 tlbufpos
= this_line_start_pos
;
6534 tlendpos
= this_line_end_pos
;
6535 if (!consider_all_windows_p
6536 && CHARPOS (tlbufpos
) > 0
6537 && NILP (w
->update_mode_line
)
6538 && !current_buffer
->clip_changed
6539 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
6540 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
6541 /* Make sure recorded data applies to current buffer, etc. */
6542 && this_line_buffer
== current_buffer
6543 && current_buffer
== XBUFFER (w
->buffer
)
6544 && NILP (w
->force_start
)
6545 /* Point must be on the line that we have info recorded about. */
6546 && PT
>= CHARPOS (tlbufpos
)
6547 && PT
<= Z
- CHARPOS (tlendpos
)
6548 /* All text outside that line, including its final newline,
6549 must be unchanged */
6550 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
6551 CHARPOS (tlendpos
)))
6553 if (CHARPOS (tlbufpos
) > BEGV
6554 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
6555 && (CHARPOS (tlbufpos
) == ZV
6556 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
6557 /* Former continuation line has disappeared by becoming empty */
6559 else if (XFASTINT (w
->last_modified
) < MODIFF
6560 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
6561 || MINI_WINDOW_P (w
))
6563 /* We have to handle the case of continuation around a
6564 wide-column character (See the comment in indent.c around
6567 For instance, in the following case:
6569 -------- Insert --------
6570 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
6571 J_I_ ==> J_I_ `^^' are cursors.
6575 As we have to redraw the line above, we should goto cancel. */
6578 int line_height_before
= this_line_pixel_height
;
6580 /* Note that start_display will handle the case that the
6581 line starting at tlbufpos is a continuation lines. */
6582 start_display (&it
, w
, tlbufpos
);
6584 /* Implementation note: It this still necessary? */
6585 if (it
.current_x
!= this_line_start_x
)
6588 TRACE ((stderr
, "trying display optimization 1\n"));
6589 w
->cursor
.vpos
= -1;
6590 overlay_arrow_seen
= 0;
6591 it
.vpos
= this_line_vpos
;
6592 it
.current_y
= this_line_y
;
6593 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
6596 /* If line contains point, is not continued,
6597 and ends at same distance from eob as before, we win */
6598 if (w
->cursor
.vpos
>= 0
6599 /* Line is not continued, otherwise this_line_start_pos
6600 would have been set to 0 in display_line. */
6601 && CHARPOS (this_line_start_pos
)
6602 /* Line ends as before. */
6603 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
6604 /* Line has same height as before. Otherwise other lines
6605 would have to be shifted up or down. */
6606 && this_line_pixel_height
== line_height_before
)
6608 /* If this is not the window's last line, we must adjust
6609 the charstarts of the lines below. */
6610 if (it
.current_y
< it
.last_visible_y
)
6612 struct glyph_row
*row
6613 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
6614 int delta
, delta_bytes
;
6616 if (Z
- CHARPOS (tlendpos
) == ZV
)
6618 /* This line ends at end of (accessible part of)
6619 buffer. There is no newline to count. */
6621 - CHARPOS (tlendpos
)
6622 - MATRIX_ROW_START_CHARPOS (row
));
6623 delta_bytes
= (Z_BYTE
6624 - BYTEPOS (tlendpos
)
6625 - MATRIX_ROW_START_BYTEPOS (row
));
6629 /* This line ends in a newline. Must take
6630 account of the newline and the rest of the
6631 text that follows. */
6633 - CHARPOS (tlendpos
)
6634 - MATRIX_ROW_START_CHARPOS (row
));
6635 delta_bytes
= (Z_BYTE
6636 - BYTEPOS (tlendpos
)
6637 - MATRIX_ROW_START_BYTEPOS (row
));
6640 increment_glyph_matrix_buffer_positions (w
->current_matrix
,
6642 w
->current_matrix
->nrows
,
6643 delta
, delta_bytes
);
6646 /* If this row displays text now but previously didn't,
6647 or vice versa, w->window_end_vpos may have to be
6649 if ((it
.glyph_row
- 1)->displays_text_p
)
6651 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
6652 XSETINT (w
->window_end_vpos
, this_line_vpos
);
6654 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
6655 && this_line_vpos
> 0)
6656 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
6657 w
->window_end_valid
= Qnil
;
6659 /* Update hint: No need to try to scroll in update_window. */
6660 w
->desired_matrix
->no_scrolling_p
= 1;
6663 *w
->desired_matrix
->method
= 0;
6664 debug_method_add (w
, "optimization 1");
6671 else if (/* Cursor position hasn't changed. */
6672 PT
== XFASTINT (w
->last_point
)
6673 /* Make sure the cursor was last displayed
6674 in this window. Otherwise we have to reposition it. */
6675 && 0 <= w
->cursor
.vpos
6676 && XINT (w
->height
) > w
->cursor
.vpos
)
6680 do_pending_window_change ();
6682 /* We used to always goto end_of_redisplay here, but this
6683 isn't enough if we have a blinking cursor. */
6684 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
6685 goto end_of_redisplay
;
6689 /* If highlighting the region, or if the cursor is in the echo area,
6690 then we can't just move the cursor. */
6691 else if (! (!NILP (Vtransient_mark_mode
)
6692 && !NILP (current_buffer
->mark_active
))
6693 && (w
== XWINDOW (current_buffer
->last_selected_window
)
6694 || highlight_nonselected_windows
)
6695 && NILP (w
->region_showing
)
6696 && !cursor_in_echo_area
)
6699 struct glyph_row
*row
;
6701 /* Skip from tlbufpos to PT and see where it is. Note that
6702 PT may be in invisible text. If so, we will end at the
6703 next visible position. */
6704 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
6705 NULL
, DEFAULT_FACE_ID
);
6706 it
.current_x
= this_line_start_x
;
6707 it
.current_y
= this_line_y
;
6708 it
.vpos
= this_line_vpos
;
6710 /* The call to move_it_to stops in front of PT, but
6711 moves over before-strings. */
6712 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
6714 if (it
.vpos
== this_line_vpos
6715 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
6718 xassert (this_line_vpos
== it
.vpos
);
6719 xassert (this_line_y
== it
.current_y
);
6720 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
6728 /* Text changed drastically or point moved off of line. */
6729 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
6732 CHARPOS (this_line_start_pos
) = 0;
6733 consider_all_windows_p
|= buffer_shared
> 1;
6734 ++clear_face_cache_count
;
6737 /* Build desired matrices. If consider_all_windows_p is non-zero,
6738 do it for all windows on all frames. Otherwise do it for
6739 selected_window, only. */
6741 if (consider_all_windows_p
)
6743 Lisp_Object tail
, frame
;
6745 /* Clear the face cache eventually. */
6746 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
6748 clear_face_cache (0);
6749 clear_face_cache_count
= 0;
6752 /* Recompute # windows showing selected buffer. This will be
6753 incremented each time such a window is displayed. */
6756 FOR_EACH_FRAME (tail
, frame
)
6758 struct frame
*f
= XFRAME (frame
);
6759 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
6761 /* Mark all the scroll bars to be removed; we'll redeem
6762 the ones we want when we redisplay their windows. */
6763 if (condemn_scroll_bars_hook
)
6764 (*condemn_scroll_bars_hook
) (f
);
6766 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
6767 redisplay_windows (FRAME_ROOT_WINDOW (f
));
6769 /* Any scroll bars which redisplay_windows should have
6770 nuked should now go away. */
6771 if (judge_scroll_bars_hook
)
6772 (*judge_scroll_bars_hook
) (f
);
6776 else if (FRAME_VISIBLE_P (selected_frame
)
6777 && !FRAME_OBSCURED_P (selected_frame
))
6778 redisplay_window (selected_window
, 1);
6781 /* Compare desired and current matrices, perform output. */
6785 /* If fonts changed, display again. */
6786 if (fonts_changed_p
)
6789 /* Prevent various kinds of signals during display update.
6790 stdio is not robust about handling signals,
6791 which can cause an apparent I/O error. */
6792 if (interrupt_input
)
6796 if (consider_all_windows_p
)
6802 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
6806 if (!FRAMEP (XCONS (tail
)->car
))
6809 f
= XFRAME (XCONS (tail
)->car
);
6811 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
6812 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
6814 /* Mark all windows as to be updated. */
6815 set_window_update_flags (XWINDOW (f
->root_window
), 1);
6816 pause
|= update_frame (f
, 0, 0);
6819 if (hscroll_windows (f
->root_window
))
6822 mark_window_display_accurate (f
->root_window
, 1);
6823 if (frame_up_to_date_hook
!= 0)
6824 (*frame_up_to_date_hook
) (f
);
6831 if (FRAME_VISIBLE_P (selected_frame
)
6832 && !FRAME_OBSCURED_P (selected_frame
))
6834 XWINDOW (selected_window
)->must_be_updated_p
= 1;
6835 pause
= update_frame (selected_frame
, 0, 0);
6836 if (!pause
&& hscroll_windows (selected_window
))
6842 /* We may have called echo_area_display at the top of this
6843 function. If the echo area is on another frame, that may
6844 have put text on a frame other than the selected one, so the
6845 above call to update_frame would not have caught it. Catch
6848 Lisp_Object mini_window
;
6849 struct frame
*mini_frame
;
6851 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
6852 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6854 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
6856 XWINDOW (mini_window
)->must_be_updated_p
= 1;
6857 pause
|= update_frame (mini_frame
, 0, 0);
6858 if (!pause
&& hscroll_windows (mini_window
))
6864 /* If display was paused because of pending input, make sure we do a
6865 thorough update the next time. */
6868 /* Prevent the optimization at the beginning of
6869 redisplay_internal that tries a single-line update of the
6870 line containing the cursor in the selected window. */
6871 CHARPOS (this_line_start_pos
) = 0;
6873 /* Let the overlay arrow be updated the next time. */
6874 if (!NILP (last_arrow_position
))
6876 last_arrow_position
= Qt
;
6877 last_arrow_string
= Qt
;
6880 /* If we pause after scrolling, some rows in the current
6881 matrices of some windows are not valid. */
6882 if (!WINDOW_FULL_WIDTH_P (w
)
6883 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
6884 update_mode_lines
= 1;
6887 /* Now text on frame agrees with windows, so put info into the
6888 windows for partial redisplay to follow. */
6891 register struct buffer
*b
= XBUFFER (w
->buffer
);
6893 unchanged_modified
= BUF_MODIFF (b
);
6894 overlay_unchanged_modified
= BUF_OVERLAY_MODIFF (b
);
6895 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
6896 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
6898 if (consider_all_windows_p
)
6899 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
6902 XSETFASTINT (w
->last_point
, BUF_PT (b
));
6903 w
->last_cursor
= w
->cursor
;
6904 w
->last_cursor_off_p
= w
->cursor_off_p
;
6906 b
->clip_changed
= 0;
6907 w
->update_mode_line
= Qnil
;
6908 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
6909 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
6911 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6914 /* Record if we are showing a region, so can make sure to
6915 update it fully at next redisplay. */
6916 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
6917 && (w
== XWINDOW (current_buffer
->last_selected_window
)
6918 || highlight_nonselected_windows
)
6919 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
6920 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
6923 w
->window_end_valid
= w
->buffer
;
6924 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
6925 last_arrow_string
= Voverlay_arrow_string
;
6926 if (frame_up_to_date_hook
!= 0)
6927 (*frame_up_to_date_hook
) (selected_frame
);
6930 update_mode_lines
= 0;
6931 windows_or_buffers_changed
= 0;
6934 /* Start SIGIO interrupts coming again. Having them off during the
6935 code above makes it less likely one will discard output, but not
6936 impossible, since there might be stuff in the system buffer here.
6937 But it is much hairier to try to do anything about that. */
6938 if (interrupt_input
)
6942 /* If a frame has become visible which was not before, redisplay
6943 again, so that we display it. Expose events for such a frame
6944 (which it gets when becoming visible) don't call the parts of
6945 redisplay constructing glyphs, so simply exposing a frame won't
6946 display anything in this case. So, we have to display these
6947 frames here explicitly. */
6950 Lisp_Object tail
, frame
;
6953 FOR_EACH_FRAME (tail
, frame
)
6955 int this_is_visible
= 0;
6957 if (XFRAME (frame
)->visible
)
6958 this_is_visible
= 1;
6959 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
6960 if (XFRAME (frame
)->visible
)
6961 this_is_visible
= 1;
6963 if (this_is_visible
)
6967 if (new_count
!= number_of_visible_frames
)
6968 windows_or_buffers_changed
++;
6971 /* Change frame size now if a change is pending. */
6972 do_pending_window_change ();
6974 /* If we just did a pending size change, or have additional
6975 visible frames, redisplay again. */
6976 if (windows_or_buffers_changed
&& !pause
)
6981 if (--redisplaying_p
< 0)
6986 /* Redisplay, but leave alone any recent echo area message unless
6987 another message has been requested in its place.
6989 This is useful in situations where you need to redisplay but no
6990 user action has occurred, making it inappropriate for the message
6991 area to be cleared. See tracking_off and
6992 wait_reading_process_input for examples of these situations. */
6995 redisplay_preserve_echo_area ()
6997 if (!echo_area_glyphs
6998 && !STRINGP (echo_area_message
)
6999 && (previous_echo_glyphs
7000 || STRINGP (previous_echo_area_message
)))
7002 echo_area_glyphs
= previous_echo_glyphs
;
7003 echo_area_message
= previous_echo_area_message
;
7004 echo_area_glyphs_length
= previous_echo_glyphs_length
;
7005 redisplay_internal (1);
7006 echo_area_glyphs
= NULL
;
7007 echo_area_message
= Qnil
;
7010 redisplay_internal (1);
7014 /* Mark the display of windows in the window tree rooted at WINDOW as
7015 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
7016 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
7017 the next time redisplay_internal is called. */
7020 mark_window_display_accurate (window
, accurate_p
)
7026 for (; !NILP (window
); window
= w
->next
)
7028 w
= XWINDOW (window
);
7030 if (BUFFERP (w
->buffer
))
7032 struct buffer
*b
= XBUFFER (w
->buffer
);
7034 XSETFASTINT (w
->last_modified
,
7035 accurate_p
? BUF_MODIFF (b
) : 0);
7036 XSETFASTINT (w
->last_overlay_modified
,
7037 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
7038 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
7041 #if 0 /* I don't think this is necessary because display_line does it.
7043 /* Record if we are showing a region, so can make sure to
7044 update it fully at next redisplay. */
7046 = (!NILP (Vtransient_mark_mode
)
7047 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7048 || highlight_nonselected_windows
)
7049 && (!NILP (b
->mark_active
)
7050 ? Fmarker_position (b
->mark
)
7056 b
->clip_changed
= 0;
7057 w
->last_cursor
= w
->cursor
;
7058 w
->last_cursor_off_p
= w
->cursor_off_p
;
7059 if (w
== XWINDOW (selected_window
))
7060 w
->last_point
= BUF_PT (b
);
7062 w
->last_point
= XMARKER (w
->pointm
)->charpos
;
7066 w
->window_end_valid
= w
->buffer
;
7067 w
->update_mode_line
= Qnil
;
7069 if (!NILP (w
->vchild
))
7070 mark_window_display_accurate (w
->vchild
, accurate_p
);
7071 if (!NILP (w
->hchild
))
7072 mark_window_display_accurate (w
->hchild
, accurate_p
);
7077 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7078 last_arrow_string
= Voverlay_arrow_string
;
7082 /* Force a thorough redisplay the next time by setting
7083 last_arrow_position and last_arrow_string to t, which is
7084 unequal to any useful value of Voverlay_arrow_... */
7085 last_arrow_position
= Qt
;
7086 last_arrow_string
= Qt
;
7091 /* Return value in display table DP (Lisp_Char_Table *) for character
7092 C. Since a display table doesn't have any parent, we don't have to
7093 follow parent. Do not call this function directly but use the
7094 macro DISP_CHAR_VECTOR. */
7097 disp_char_vector (dp
, c
)
7098 struct Lisp_Char_Table
*dp
;
7104 if (SINGLE_BYTE_CHAR_P (c
))
7105 return (dp
->contents
[c
]);
7107 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
7108 if (code
[0] != CHARSET_COMPOSITION
)
7112 else if (code
[2] < 32)
7116 /* Here, the possible range of code[0] (== charset ID) is
7117 128..max_charset. Since the top level char table contains data
7118 for multibyte characters after 256th element, we must increment
7119 code[0] by 128 to get a correct index. */
7121 code
[3] = -1; /* anchor */
7123 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
7125 val
= dp
->contents
[code
[i
]];
7126 if (!SUB_CHAR_TABLE_P (val
))
7127 return (NILP (val
) ? dp
->defalt
: val
);
7130 /* Here, val is a sub char table. We return the default value of
7132 return (dp
->defalt
);
7137 /***********************************************************************
7139 ***********************************************************************/
7141 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
7144 redisplay_windows (window
)
7147 while (!NILP (window
))
7149 struct window
*w
= XWINDOW (window
);
7151 if (!NILP (w
->hchild
))
7152 redisplay_windows (w
->hchild
);
7153 else if (!NILP (w
->vchild
))
7154 redisplay_windows (w
->vchild
);
7156 redisplay_window (window
, 0);
7163 /* Set cursor position of W. PT is assumed to be displayed in ROW.
7164 DELTA is the number of bytes by which positions recorded in ROW
7165 differ from current buffer positions. */
7168 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
7170 struct glyph_row
*row
;
7171 struct glyph_matrix
*matrix
;
7172 int delta
, delta_bytes
, dy
, dvpos
;
7174 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
7175 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
7177 int pt_old
= PT
- delta
;
7179 /* Skip over glyphs not having an object at the start of the row.
7180 These are special glyphs like truncation marks on terminal
7182 if (row
->displays_text_p
)
7185 && glyph
->charpos
< 0)
7187 x
+= glyph
->pixel_width
;
7193 && (!BUFFERP (glyph
->object
)
7194 || glyph
->charpos
< pt_old
))
7196 x
+= glyph
->pixel_width
;
7200 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7202 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
7203 w
->cursor
.y
= row
->y
+ dy
;
7205 if (w
== XWINDOW (selected_window
))
7207 if (!row
->continued_p
7208 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
7211 this_line_buffer
= XBUFFER (w
->buffer
);
7213 CHARPOS (this_line_start_pos
)
7214 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
7215 BYTEPOS (this_line_start_pos
)
7216 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
7218 CHARPOS (this_line_end_pos
)
7219 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
7220 BYTEPOS (this_line_end_pos
)
7221 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
7223 this_line_y
= w
->cursor
.y
;
7224 this_line_pixel_height
= row
->height
;
7225 this_line_vpos
= w
->cursor
.vpos
;
7226 this_line_start_x
= row
->x
;
7229 CHARPOS (this_line_start_pos
) = 0;
7234 /* Run window scroll functions, if any, for WINDOW with new window
7235 start STARTP. Sets the window start of WINDOW to that position. */
7237 static INLINE
struct text_pos
7238 run_window_scroll_functions (window
, startp
)
7240 struct text_pos startp
;
7242 struct window
*w
= XWINDOW (window
);
7243 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
7245 if (!NILP (Vwindow_scroll_functions
))
7247 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
7248 make_number (CHARPOS (startp
)));
7249 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
7256 /* Modify the desired matrix of window W and W->vscroll so that the
7257 line containing the cursor is fully visible. */
7260 make_cursor_line_fully_visible (w
)
7263 struct glyph_matrix
*matrix
;
7264 struct glyph_row
*row
;
7265 int top_line_height
;
7267 /* It's not always possible to find the cursor, e.g, when a window
7268 is full of overlay strings. Don't do anything in that case. */
7269 if (w
->cursor
.vpos
< 0)
7272 matrix
= w
->desired_matrix
;
7273 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
7275 /* If row->y == top y of window display area, the window isn't tall
7276 enough to display a single line. There is nothing we can do
7278 top_line_height
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
7279 if (row
->y
== top_line_height
)
7282 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
7284 int dy
= row
->height
- row
->visible_height
;
7287 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
7289 else if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w
, row
))
7291 int dy
= - (row
->height
- row
->visible_height
);
7294 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
7297 /* When we change the cursor y-position of the selected window,
7298 change this_line_y as well so that the display optimization for
7299 the cursor line of the selected window in redisplay_internal uses
7300 the correct y-position. */
7301 if (w
== XWINDOW (selected_window
))
7302 this_line_y
= w
->cursor
.y
;
7306 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
7307 non-zero means only WINDOW is redisplayed in redisplay_internal.
7308 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
7309 in redisplay_window to bring a partially visible line into view in
7310 the case that only the cursor has moved.
7314 1 if scrolling succeeded
7316 0 if scrolling didn't find point.
7318 -1 if new fonts have been loaded so that we must interrupt
7319 redisplay, adjust glyph matrices, and try again. */
7322 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
7323 scroll_step
, temp_scroll_step
)
7325 int just_this_one_p
;
7326 int scroll_conservatively
, scroll_step
;
7327 int temp_scroll_step
;
7329 struct window
*w
= XWINDOW (window
);
7330 struct frame
*f
= XFRAME (w
->frame
);
7331 struct text_pos scroll_margin_pos
;
7332 struct text_pos pos
;
7333 struct text_pos startp
;
7335 Lisp_Object window_end
;
7336 int this_scroll_margin
;
7339 int line_height
, rc
;
7340 int amount_to_scroll
= 0;
7341 Lisp_Object aggressive
;
7345 debug_method_add (w
, "try_scrolling");
7348 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
7350 /* Compute scroll margin height in pixels. We scroll when point is
7351 within this distance from the top or bottom of the window. */
7352 if (scroll_margin
> 0)
7354 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
7355 this_scroll_margin
*= CANON_Y_UNIT (f
);
7358 this_scroll_margin
= 0;
7360 /* Compute how much we should try to scroll maximally to bring point
7363 scroll_max
= scroll_step
;
7364 else if (scroll_conservatively
)
7365 scroll_max
= scroll_conservatively
;
7366 else if (temp_scroll_step
)
7367 scroll_max
= temp_scroll_step
;
7368 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
7369 || NUMBERP (current_buffer
->scroll_up_aggressively
))
7370 /* We're trying to scroll because of aggressive scrolling
7371 but no scroll_step is set. Choose an arbitrary one. Maybe
7372 there should be a variable for this. */
7376 scroll_max
*= CANON_Y_UNIT (f
);
7378 /* Decide whether we have to scroll down. Start at the window end
7379 and move this_scroll_margin up to find the position of the scroll
7381 window_end
= Fwindow_end (window
, Qt
);
7382 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
7383 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
7384 if (this_scroll_margin
)
7386 start_display (&it
, w
, scroll_margin_pos
);
7387 move_it_vertically (&it
, - this_scroll_margin
);
7388 scroll_margin_pos
= it
.current
.pos
;
7391 if (PT
>= CHARPOS (scroll_margin_pos
))
7395 /* Point is in the scroll margin at the bottom of the window, or
7396 below. Compute a new window start that makes point visible. */
7398 /* Compute the distance from the scroll margin to PT.
7399 Give up if the distance is greater than scroll_max. */
7400 start_display (&it
, w
, scroll_margin_pos
);
7402 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
7403 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
7404 line_height
= (it
.max_ascent
+ it
.max_descent
7405 ? it
.max_ascent
+ it
.max_descent
7407 dy
= it
.current_y
+ line_height
- y0
;
7408 if (dy
> scroll_max
)
7411 /* Move the window start down. If scrolling conservatively,
7412 move it just enough down to make point visible. If
7413 scroll_step is set, move it down by scroll_step. */
7414 start_display (&it
, w
, startp
);
7416 if (scroll_conservatively
)
7417 amount_to_scroll
= dy
;
7418 else if (scroll_step
|| temp_scroll_step
)
7419 amount_to_scroll
= scroll_max
;
7422 aggressive
= current_buffer
->scroll_down_aggressively
;
7423 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
7424 - WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
));
7425 if (NUMBERP (aggressive
))
7426 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
7429 if (amount_to_scroll
<= 0)
7432 move_it_vertically (&it
, amount_to_scroll
);
7433 startp
= it
.current
.pos
;
7437 /* See if point is inside the scroll margin at the top of the
7439 scroll_margin_pos
= startp
;
7440 if (this_scroll_margin
)
7442 start_display (&it
, w
, startp
);
7443 move_it_vertically (&it
, this_scroll_margin
);
7444 scroll_margin_pos
= it
.current
.pos
;
7447 if (PT
< CHARPOS (scroll_margin_pos
))
7449 /* Point is in the scroll margin at the top of the window or
7450 above what is displayed in the window. */
7453 /* Compute the vertical distance from PT to the scroll
7454 margin position. Give up if distance is greater than
7456 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
7457 start_display (&it
, w
, pos
);
7459 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
7460 it
.last_visible_y
, -1,
7461 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
7462 dy
= it
.current_y
- y0
;
7463 if (dy
> scroll_max
)
7466 /* Compute new window start. */
7467 start_display (&it
, w
, startp
);
7469 if (scroll_conservatively
)
7470 amount_to_scroll
= dy
;
7471 else if (scroll_step
|| temp_scroll_step
)
7472 amount_to_scroll
= scroll_max
;
7475 aggressive
= current_buffer
->scroll_up_aggressively
;
7476 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
7477 - WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
));
7478 if (NUMBERP (aggressive
))
7479 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
7482 if (amount_to_scroll
<= 0)
7485 move_it_vertically (&it
, - amount_to_scroll
);
7486 startp
= it
.current
.pos
;
7490 /* Run window scroll functions. */
7491 startp
= run_window_scroll_functions (window
, startp
);
7493 /* Display the window. Give up if new fonts are loaded, or if point
7495 if (!try_window (window
, startp
))
7497 else if (w
->cursor
.vpos
< 0)
7499 clear_glyph_matrix (w
->desired_matrix
);
7504 /* Maybe forget recorded base line for line number display. */
7505 if (!just_this_one_p
7506 || current_buffer
->clip_changed
7507 || beg_unchanged
< CHARPOS (startp
))
7508 w
->base_line_number
= Qnil
;
7510 /* If cursor ends up on a partially visible line, shift display
7511 lines up or down. */
7512 make_cursor_line_fully_visible (w
);
7520 /* Compute a suitable window start for window W if display of W starts
7521 on a continuation line. Value is non-zero if a new window start
7524 The new window start will be computed, based on W's width, starting
7525 from the start of the continued line. It is the start of the
7526 screen line with the minimum distance from the old start W->start. */
7529 compute_window_start_on_continuation_line (w
)
7532 struct text_pos pos
, start_pos
;
7533 int window_start_changed_p
= 0;
7535 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
7537 /* If window start is on a continuation line... Window start may be
7538 < BEGV in case there's invisible text at the start of the
7539 buffer (M-x rmail, for example). */
7540 if (CHARPOS (start_pos
) > BEGV
7541 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
7544 struct glyph_row
*row
;
7546 /* Find the start of the continued line. This should be fast
7547 because scan_buffer is fast (newline cache). */
7548 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_TOP_LINE_P (w
) ? 1 : 0);
7549 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
7550 row
, DEFAULT_FACE_ID
);
7551 reseat_at_previous_visible_line_start (&it
);
7553 /* If the line start is "too far" away from the window start,
7554 say it takes too much time to compute a new window start. */
7555 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
7556 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
7558 int min_distance
, distance
;
7560 /* Move forward by display lines to find the new window
7561 start. If window width was enlarged, the new start can
7562 be expected to be > the old start. If window width was
7563 decreased, the new window start will be < the old start.
7564 So, we're looking for the display line start with the
7565 minimum distance from the old window start. */
7566 pos
= it
.current
.pos
;
7567 min_distance
= INFINITY
;
7568 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
7569 distance
< min_distance
)
7571 min_distance
= distance
;
7572 pos
= it
.current
.pos
;
7573 move_it_by_lines (&it
, 1, 0);
7576 /* Set the window start there. */
7577 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
7578 window_start_changed_p
= 1;
7582 return window_start_changed_p
;
7586 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
7587 selected_window is redisplayed. */
7590 redisplay_window (window
, just_this_one_p
)
7592 int just_this_one_p
;
7594 struct window
*w
= XWINDOW (window
);
7595 struct frame
*f
= XFRAME (w
->frame
);
7596 struct buffer
*buffer
= XBUFFER (w
->buffer
);
7597 struct buffer
*old
= current_buffer
;
7598 struct text_pos lpoint
, opoint
, startp
;
7599 int update_mode_line
;
7602 /* Record it now because it's overwritten. */
7603 int current_matrix_up_to_date_p
= 0;
7604 int really_switched_buffer
= 0;
7605 int temp_scroll_step
= 0;
7606 int count
= specpdl_ptr
- specpdl
;
7608 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
7611 /* W must be a leaf window here. */
7612 xassert (!NILP (w
->buffer
));
7614 *w
->desired_matrix
->method
= 0;
7617 specbind (Qinhibit_point_motion_hooks
, Qt
);
7619 /* Has the mode line to be updated? */
7620 update_mode_line
= (!NILP (w
->update_mode_line
)
7621 || update_mode_lines
7622 || buffer
->clip_changed
);
7624 if (MINI_WINDOW_P (w
))
7626 if (w
== XWINDOW (echo_area_window
)
7627 && (echo_area_glyphs
7628 || STRINGP (echo_area_message
)))
7630 if (update_mode_line
)
7631 /* We may have to update a tty frame's menu bar or a
7632 toolbar. Example `M-x C-h C-h C-g'. */
7633 goto finish_menu_bars
;
7635 /* We've already displayed the echo area glyphs in this window. */
7636 goto finish_scroll_bars
;
7638 else if (w
!= XWINDOW (minibuf_window
))
7640 /* W is a mini-buffer window, but it's not the currently
7641 active one, so clear it. */
7642 int yb
= window_text_bottom_y (w
);
7643 struct glyph_row
*row
;
7646 for (y
= 0, row
= w
->desired_matrix
->rows
;
7648 y
+= row
->height
, ++row
)
7649 blank_row (w
, row
, y
);
7650 goto finish_scroll_bars
;
7654 /* Otherwise set up data on this window; select its buffer and point
7656 if (update_mode_line
)
7658 /* Really select the buffer, for the sake of buffer-local
7660 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7661 really_switched_buffer
= 1;
7664 set_buffer_temp (XBUFFER (w
->buffer
));
7665 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
7667 current_matrix_up_to_date_p
7668 = (!NILP (w
->window_end_valid
)
7669 && !current_buffer
->clip_changed
7670 && XFASTINT (w
->last_modified
) >= MODIFF
7671 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
7673 /* When windows_or_buffers_changed is non-zero, we can't rely on
7674 the window end being valid, so set it to nil there. */
7675 if (windows_or_buffers_changed
)
7677 /* If window starts on a continuation line, maybe adjust the
7678 window start in case the window's width changed. */
7679 if (XMARKER (w
->start
)->buffer
== current_buffer
)
7680 compute_window_start_on_continuation_line (w
);
7682 w
->window_end_valid
= Qnil
;
7685 /* Some sanity checks. */
7686 CHECK_WINDOW_END (w
);
7687 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
7689 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
7692 /* If %c is in mode line, update it if needed. */
7693 if (!NILP (w
->column_number_displayed
)
7694 /* This alternative quickly identifies a common case
7695 where no change is needed. */
7696 && !(PT
== XFASTINT (w
->last_point
)
7697 && XFASTINT (w
->last_modified
) >= MODIFF
7698 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7699 && XFASTINT (w
->column_number_displayed
) != current_column ())
7700 update_mode_line
= 1;
7702 /* Count number of windows showing the selected buffer. An indirect
7703 buffer counts as its base buffer. */
7704 if (!just_this_one_p
)
7706 struct buffer
*current_base
, *window_base
;
7707 current_base
= current_buffer
;
7708 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
7709 if (current_base
->base_buffer
)
7710 current_base
= current_base
->base_buffer
;
7711 if (window_base
->base_buffer
)
7712 window_base
= window_base
->base_buffer
;
7713 if (current_base
== window_base
)
7717 /* Point refers normally to the selected window. For any other
7718 window, set up appropriate value. */
7719 if (!EQ (window
, selected_window
))
7721 int new_pt
= XMARKER (w
->pointm
)->charpos
;
7722 int new_pt_byte
= marker_byte_position (w
->pointm
);
7726 new_pt_byte
= BEGV_BYTE
;
7727 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
7729 else if (new_pt
> (ZV
- 1))
7732 new_pt_byte
= ZV_BYTE
;
7733 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
7736 /* We don't use SET_PT so that the point-motion hooks don't run. */
7737 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
7740 /* If any of the character widths specified in the display table
7741 have changed, invalidate the width run cache. It's true that
7742 this may be a bit late to catch such changes, but the rest of
7743 redisplay goes (non-fatally) haywire when the display table is
7744 changed, so why should we worry about doing any better? */
7745 if (current_buffer
->width_run_cache
)
7747 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
7749 if (! disptab_matches_widthtab (disptab
,
7750 XVECTOR (current_buffer
->width_table
)))
7752 invalidate_region_cache (current_buffer
,
7753 current_buffer
->width_run_cache
,
7755 recompute_width_table (current_buffer
, disptab
);
7759 /* If window-start is screwed up, choose a new one. */
7760 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
7763 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
7765 /* If someone specified a new starting point but did not insist,
7766 check whether it can be used. */
7767 if (!NILP (w
->optional_new_start
))
7769 w
->optional_new_start
= Qnil
;
7770 /* This takes a mini-buffer prompt into account. */
7771 start_display (&it
, w
, startp
);
7772 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
7773 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
7774 if (IT_CHARPOS (it
) == PT
)
7775 w
->force_start
= Qt
;
7778 /* Handle case where place to start displaying has been specified,
7779 unless the specified location is outside the accessible range. */
7780 if (!NILP (w
->force_start
))
7782 w
->force_start
= Qnil
;
7784 w
->window_end_valid
= Qnil
;
7786 /* Forget any recorded base line for line number display. */
7787 if (!current_matrix_up_to_date_p
7788 || current_buffer
->clip_changed
)
7789 w
->base_line_number
= Qnil
;
7791 /* Redisplay the mode line. Select the buffer properly for that.
7792 Also, run the hook window-scroll-functions
7793 because we have scrolled. */
7794 /* Note, we do this after clearing force_start because
7795 if there's an error, it is better to forget about force_start
7796 than to get into an infinite loop calling the hook functions
7797 and having them get more errors. */
7798 if (!update_mode_line
7799 || ! NILP (Vwindow_scroll_functions
))
7801 if (!really_switched_buffer
)
7803 set_buffer_temp (old
);
7804 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7805 really_switched_buffer
= 1;
7808 update_mode_line
= 1;
7809 w
->update_mode_line
= Qt
;
7810 startp
= run_window_scroll_functions (window
, startp
);
7813 XSETFASTINT (w
->last_modified
, 0);
7814 XSETFASTINT (w
->last_overlay_modified
, 0);
7815 if (CHARPOS (startp
) < BEGV
)
7816 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
7817 else if (CHARPOS (startp
) > ZV
)
7818 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
7820 /* Redisplay, then check if cursor has been set during the
7821 redisplay. Give up if new fonts were loaded. */
7822 if (!try_window (window
, startp
))
7824 w
->force_start
= Qt
;
7825 clear_glyph_matrix (w
->desired_matrix
);
7826 goto restore_buffers
;
7829 if (w
->cursor
.vpos
< 0)
7831 /* If point does not appear, or on a line that is not fully
7832 visible, move point so it does appear. The desired
7833 matrix has been built above, so we can use it. */
7834 int height
= window_box_height (w
) / 2;
7835 struct glyph_row
*row
= MATRIX_ROW (w
->desired_matrix
, 0);
7837 while (row
->y
< height
)
7840 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
7841 MATRIX_ROW_START_BYTEPOS (row
));
7843 if (w
!= XWINDOW (selected_window
))
7844 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
7845 else if (current_buffer
== old
)
7846 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
7848 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
7850 /* If we are highlighting the region, then we just changed
7851 the region, so redisplay to show it. */
7852 if (!NILP (Vtransient_mark_mode
)
7853 && !NILP (current_buffer
->mark_active
))
7855 clear_glyph_matrix (w
->desired_matrix
);
7856 if (!try_window (window
, startp
))
7857 goto restore_buffers
;
7861 make_cursor_line_fully_visible (w
);
7863 debug_method_add (w
, "forced window start");
7868 /* Handle case where text has not changed, only point, and it has
7869 not moved off the frame. */
7870 if (current_matrix_up_to_date_p
7871 /* Point may be in this window. */
7872 && PT
>= CHARPOS (startp
)
7873 /* If we don't check this, we are called to move the cursor in a
7874 horizontally split window with a current matrix that doesn't
7876 && !windows_or_buffers_changed
7877 /* Selective display hasn't changed. */
7878 && !current_buffer
->clip_changed
7879 /* If force-mode-line-update was called, really redisplay;
7880 that's how redisplay is forced after e.g. changing
7881 buffer-invisibility-spec. */
7882 && NILP (w
->update_mode_line
)
7883 /* Can't use this case if highlighting a region. When a
7884 region exists, cursor movement has to do more than just
7886 && !(!NILP (Vtransient_mark_mode
)
7887 && !NILP (current_buffer
->mark_active
))
7888 && NILP (w
->region_showing
)
7889 /* Right after splitting windows, last_point may be nil. */
7890 && INTEGERP (w
->last_point
)
7891 /* This code is not used for mini-buffer for the sake of the case
7892 of redisplaying to replace an echo area message; since in
7893 that case the mini-buffer contents per se are usually
7894 unchanged. This code is of no real use in the mini-buffer
7895 since the handling of this_line_start_pos, etc., in redisplay
7896 handles the same cases. */
7897 && !EQ (window
, minibuf_window
)
7898 /* When splitting windows or for new windows, it happens that
7899 redisplay is called with a nil window_end_vpos or one being
7900 larger than the window. This should really be fixed in
7901 window.c. I don't have this on my list, now, so we do
7902 approximately the same as the old redisplay code. --gerd. */
7903 && INTEGERP (w
->window_end_vpos
)
7904 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
7905 && (FRAME_WINDOW_P (f
)
7906 || !MARKERP (Voverlay_arrow_position
)
7907 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
7909 int this_scroll_margin
;
7910 struct glyph_row
*row
;
7914 debug_method_add (w
, "cursor movement");
7917 /* Scroll if point within this distance from the top or bottom
7918 of the window. This is a pixel value. */
7919 this_scroll_margin
= max (0, scroll_margin
);
7920 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
7921 this_scroll_margin
*= CANON_Y_UNIT (f
);
7923 /* Start with the row the cursor was displayed during the last
7924 not paused redisplay. Give up if that row is not valid. */
7925 if (w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
7927 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
7928 if (row
->mode_line_p
)
7930 if (!row
->enabled_p
)
7934 if (PT
> XFASTINT (w
->last_point
))
7936 /* Point has moved forward. */
7937 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
7939 while ((MATRIX_ROW_END_CHARPOS (row
) < PT
7940 /* The end position of a row equals the start
7941 position of the next row. If PT is there, we
7942 would rather display it in the next line, except
7943 when this line ends in ZV. */
7944 || (MATRIX_ROW_END_CHARPOS (row
) == PT
7945 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
7946 || !row
->ends_at_zv_p
)))
7947 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
7949 xassert (row
->enabled_p
);
7953 /* If within the scroll margin, scroll. Note that
7954 MATRIX_ROW_BOTTOM_Y gives the pixel position at which the
7955 next line would be drawn, and that this_scroll_margin can
7957 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
7958 || PT
> MATRIX_ROW_END_CHARPOS (row
)
7959 /* Line is completely visible last line in window and PT
7960 is to be set in the next line. */
7961 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
7962 && PT
== MATRIX_ROW_END_CHARPOS (row
)
7963 && !row
->ends_at_zv_p
7964 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
7967 else if (PT
< XFASTINT (w
->last_point
))
7969 /* Cursor has to be moved backward. Note that PT >=
7970 CHARPOS (startp) because of the outer if-statement. */
7971 while (!row
->mode_line_p
7972 && (MATRIX_ROW_START_CHARPOS (row
) > PT
7973 || (MATRIX_ROW_START_CHARPOS (row
) == PT
7974 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
7975 && (row
->y
> this_scroll_margin
7976 || CHARPOS (startp
) == BEGV
))
7978 xassert (row
->enabled_p
);
7982 /* Consider the following case: Window starts at BEGV, there
7983 is invisible, intangible text at BEGV, so that display
7984 starts at some point START > BEGV. It can happen that
7985 we are called with PT somewhere between BEGV and START.
7986 Try to handle that case. */
7987 if (row
< w
->current_matrix
->rows
7988 || row
->mode_line_p
)
7990 row
= w
->current_matrix
->rows
;
7991 if (row
->mode_line_p
)
7995 /* Due to newlines in overlay strings, we may have to skip
7996 forward over overlay strings. */
7997 while (MATRIX_ROW_END_CHARPOS (row
) == PT
7998 && MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P (row
)
7999 && !row
->ends_at_zv_p
)
8002 /* If within the scroll margin, scroll. */
8003 if (row
->y
< this_scroll_margin
8004 && CHARPOS (startp
) != BEGV
)
8008 /* if PT is not in the glyph row, give up. */
8009 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
8010 || PT
> MATRIX_ROW_END_CHARPOS (row
))
8013 /* If we end up in a partially visible line, let's make it fully
8014 visible. This can be done most easily by using the existing
8016 if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8018 temp_scroll_step
= 1;
8024 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8028 /* If current starting point was originally the beginning of a line
8029 but no longer is, find a new starting point. */
8030 else if (!NILP (w
->start_at_line_beg
)
8031 && !(CHARPOS (startp
) <= BEGV
8032 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
8035 debug_method_add (w
, "recenter 1");
8040 /* Try scrolling with try_window_id. */
8041 else if (!windows_or_buffers_changed
8042 /* Window must be either use window-based redisplay or
8044 && (FRAME_WINDOW_P (f
)
8045 || ((line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
))
8046 && just_this_one_p
))
8047 && !MINI_WINDOW_P (w
)
8048 /* Point is not known NOT to appear in window. */
8049 && PT
>= CHARPOS (startp
)
8050 && XFASTINT (w
->last_modified
)
8051 /* Window is not hscrolled. */
8052 && XFASTINT (w
->hscroll
) == 0
8053 /* Selective display has not changed. */
8054 && !current_buffer
->clip_changed
8055 /* Current matrix is up to date. */
8056 && !NILP (w
->window_end_valid
)
8057 /* Can't use this case if highlighting a region because
8058 a cursor movement will do more than just set the cursor. */
8059 && !(!NILP (Vtransient_mark_mode
)
8060 && !NILP (current_buffer
->mark_active
))
8061 && NILP (w
->region_showing
)
8062 /* Overlay arrow position and string not changed. */
8063 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
8064 && EQ (last_arrow_string
, Voverlay_arrow_string
)
8065 /* Value is > 0 if update has been done, it is -1 if we
8066 know that the same window start will not work. It is 0
8067 if unsuccessful for some other reason. */
8068 && (tem
= try_window_id (w
)) != 0)
8071 debug_method_add (w
, "try_window_id");
8074 if (fonts_changed_p
)
8075 goto restore_buffers
;
8078 /* Otherwise try_window_id has returned -1 which means that we
8079 don't want the alternative below this comment to execute. */
8081 else if (CHARPOS (startp
) >= BEGV
8082 && CHARPOS (startp
) <= ZV
8083 && PT
>= CHARPOS (startp
)
8084 && (CHARPOS (startp
) < ZV
8085 /* Avoid starting at end of buffer. */
8086 || CHARPOS (startp
) == BEGV
8087 || (XFASTINT (w
->last_modified
) >= MODIFF
8088 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
8091 debug_method_add (w
, "same window start");
8094 /* Try to redisplay starting at same place as before.
8095 If point has not moved off frame, accept the results. */
8096 if (!current_matrix_up_to_date_p
8097 /* Don't use try_window_reusing_current_matrix in this case
8098 because it can have changed the buffer. */
8099 || !NILP (Vwindow_scroll_functions
)
8100 || MINI_WINDOW_P (w
)
8101 || !try_window_reusing_current_matrix (w
))
8103 IF_DEBUG (debug_method_add (w
, "1"));
8104 try_window (window
, startp
);
8107 if (fonts_changed_p
)
8108 goto restore_buffers
;
8110 if (w
->cursor
.vpos
>= 0)
8112 if (!just_this_one_p
8113 || current_buffer
->clip_changed
8114 || beg_unchanged
< CHARPOS (startp
))
8115 /* Forget any recorded base line for line number display. */
8116 w
->base_line_number
= Qnil
;
8118 make_cursor_line_fully_visible (w
);
8122 clear_glyph_matrix (w
->desired_matrix
);
8127 XSETFASTINT (w
->last_modified
, 0);
8128 XSETFASTINT (w
->last_overlay_modified
, 0);
8130 /* Redisplay the mode line. Select the buffer properly for that. */
8131 if (!update_mode_line
)
8133 if (!really_switched_buffer
)
8135 set_buffer_temp (old
);
8136 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8137 really_switched_buffer
= 1;
8139 update_mode_line
= 1;
8140 w
->update_mode_line
= Qt
;
8143 /* Try to scroll by specified few lines. */
8144 if ((scroll_conservatively
8147 || NUMBERP (current_buffer
->scroll_up_aggressively
)
8148 || NUMBERP (current_buffer
->scroll_down_aggressively
))
8149 && !current_buffer
->clip_changed
8150 && CHARPOS (startp
) >= BEGV
8151 && CHARPOS (startp
) <= ZV
)
8153 /* The function returns -1 if new fonts were loaded, 1 if
8154 successful, 0 if not successful. */
8155 int rc
= try_scrolling (window
, just_this_one_p
,
8156 scroll_conservatively
,
8162 goto restore_buffers
;
8165 /* Finally, just choose place to start which centers point */
8170 debug_method_add (w
, "recenter");
8173 /* w->vscroll = 0; */
8175 /* Forget any previously recorded base line for line number display. */
8176 if (!current_matrix_up_to_date_p
8177 || current_buffer
->clip_changed
)
8178 w
->base_line_number
= Qnil
;
8180 /* Move backward half the height of the window. */
8181 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
8182 it
.current_y
= it
.last_visible_y
;
8183 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
8184 xassert (IT_CHARPOS (it
) >= BEGV
);
8186 /* The function move_it_vertically_backward may move over more
8187 than the specified y-distance. If it->w is small, e.g. a
8188 mini-buffer window, we may end up in front of the window's
8189 display area. Start displaying at the start of the line
8190 containing PT in this case. */
8191 if (it
.current_y
<= 0)
8193 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
8194 move_it_vertically (&it
, 0);
8195 xassert (IT_CHARPOS (it
) <= PT
);
8199 it
.current_x
= it
.hpos
= 0;
8201 /* Set startp here explicitly in case that helps avoid an infinite loop
8202 in case the window-scroll-functions functions get errors. */
8203 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
8205 /* Run scroll hooks. */
8206 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
8208 /* Redisplay the window. */
8209 if (!current_matrix_up_to_date_p
8210 || windows_or_buffers_changed
8211 /* Don't use try_window_reusing_current_matrix in this case
8212 because it can have changed the buffer. */
8213 || !NILP (Vwindow_scroll_functions
)
8215 || MINI_WINDOW_P (w
)
8216 || !try_window_reusing_current_matrix (w
))
8217 try_window (window
, startp
);
8219 /* If new fonts have been loaded (due to fontsets), give up. We
8220 have to start a new redisplay since we need to re-adjust glyph
8222 if (fonts_changed_p
)
8223 goto restore_buffers
;
8225 /* If cursor did not appear assume that the middle of the window is
8226 in the first line of the window. Do it again with the next line.
8227 (Imagine a window of height 100, displaying two lines of height
8228 60. Moving back 50 from it->last_visible_y will end in the first
8230 if (w
->cursor
.vpos
< 0)
8232 if (!NILP (w
->window_end_valid
)
8233 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
8235 clear_glyph_matrix (w
->desired_matrix
);
8236 move_it_by_lines (&it
, 1, 0);
8237 try_window (window
, it
.current
.pos
);
8239 else if (PT
< IT_CHARPOS (it
))
8241 clear_glyph_matrix (w
->desired_matrix
);
8242 move_it_by_lines (&it
, -1, 0);
8243 try_window (window
, it
.current
.pos
);
8247 /* Not much we can do about it. */
8251 /* Consider the following case: Window starts at BEGV, there is
8252 invisible, intangible text at BEGV, so that display starts at
8253 some point START > BEGV. It can happen that we are called with
8254 PT somewhere between BEGV and START. Try to handle that case. */
8255 if (w
->cursor
.vpos
< 0)
8257 struct glyph_row
*row
= w
->current_matrix
->rows
;
8258 if (row
->mode_line_p
)
8260 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8263 make_cursor_line_fully_visible (w
);
8265 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8266 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
8267 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
8272 /* Display the mode line, if we must. */
8273 if ((update_mode_line
8274 /* If window not full width, must redo its mode line
8275 if (a) the window to its side is being redone and
8276 (b) we do a frame-based redisplay. This is a consequence
8277 of how inverted lines are drawn in frame-based redisplay. */
8278 || (!just_this_one_p
8279 && !FRAME_WINDOW_P (f
)
8280 && !WINDOW_FULL_WIDTH_P (w
))
8281 /* Line number to display. */
8282 || INTEGERP (w
->base_line_pos
)
8283 /* Column number is displayed and different from the one displayed. */
8284 || (!NILP (w
->column_number_displayed
)
8285 && XFASTINT (w
->column_number_displayed
) != current_column ()))
8286 /* This means that the window has a mode line. */
8287 && (WINDOW_WANTS_MODELINE_P (w
)
8288 || WINDOW_WANTS_TOP_LINE_P (w
)))
8290 display_mode_lines (w
);
8292 /* If mode line height has changed, arrange for a thorough
8293 immediate redisplay using the correct mode line height. */
8294 if (WINDOW_WANTS_MODELINE_P (w
)
8295 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
8297 fonts_changed_p
= 1;
8298 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
8299 = DESIRED_MODE_LINE_HEIGHT (w
);
8302 /* If top line height has changed, arrange for a thorough
8303 immediate redisplay using the correct mode line height. */
8304 if (WINDOW_WANTS_TOP_LINE_P (w
)
8305 && CURRENT_TOP_LINE_HEIGHT (w
) != DESIRED_TOP_LINE_HEIGHT (w
))
8307 fonts_changed_p
= 1;
8308 MATRIX_TOP_LINE_ROW (w
->current_matrix
)->height
8309 = DESIRED_TOP_LINE_HEIGHT (w
);
8312 if (fonts_changed_p
)
8313 goto restore_buffers
;
8316 if (!line_number_displayed
8317 && !BUFFERP (w
->base_line_pos
))
8319 w
->base_line_pos
= Qnil
;
8320 w
->base_line_number
= Qnil
;
8325 /* When we reach a frame's selected window, redo the frame's menu bar. */
8326 if (update_mode_line
8327 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
8329 int redisplay_menu_p
= 0;
8331 if (FRAME_WINDOW_P (f
))
8333 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
8334 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
8336 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
8340 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
8342 if (redisplay_menu_p
)
8343 display_menu_bar (w
);
8345 #ifdef HAVE_WINDOW_SYSTEM
8346 if (WINDOWP (f
->toolbar_window
)
8347 && (FRAME_TOOLBAR_LINES (f
) > 0
8348 || auto_resize_toolbars_p
))
8349 redisplay_toolbar (f
);
8355 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8357 int start
, end
, whole
;
8359 /* Calculate the start and end positions for the current window.
8360 At some point, it would be nice to choose between scrollbars
8361 which reflect the whole buffer size, with special markers
8362 indicating narrowing, and scrollbars which reflect only the
8365 Note that mini-buffers sometimes aren't displaying any text. */
8366 if (! MINI_WINDOW_P (w
)
8367 || (w
== XWINDOW (minibuf_window
)
8368 && !echo_area_glyphs
8369 && !STRINGP (echo_area_message
)))
8372 start
= marker_position (w
->start
) - BEGV
;
8373 /* I don't think this is guaranteed to be right. For the
8374 moment, we'll pretend it is. */
8375 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
8379 if (whole
< (end
- start
))
8380 whole
= end
- start
;
8383 start
= end
= whole
= 0;
8385 /* Indicate what this scroll bar ought to be displaying now. */
8386 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
8388 /* Note that we actually used the scroll bar attached to this
8389 window, so it shouldn't be deleted at the end of redisplay. */
8390 (*redeem_scroll_bar_hook
) (w
);
8395 /* Restore current_buffer and value of point in it. */
8396 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
8397 if (really_switched_buffer
)
8398 set_buffer_internal_1 (old
);
8400 set_buffer_temp (old
);
8401 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
8403 unbind_to (count
, Qnil
);
8407 /* Build the complete desired matrix of WINDOW with a window start
8408 buffer position POS. Value is non-zero if successful. It is zero
8409 if fonts were loaded during redisplay which makes re-adjusting
8410 glyph matrices necessary. */
8413 try_window (window
, pos
)
8415 struct text_pos pos
;
8417 struct window
*w
= XWINDOW (window
);
8419 struct glyph_row
*last_text_row
= NULL
;
8421 /* Make POS the new window start. */
8422 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
8424 /* Mark cursor position as unknown. No overlay arrow seen. */
8425 w
->cursor
.vpos
= -1;
8426 overlay_arrow_seen
= 0;
8428 /* Initialize iterator and info to start at POS. */
8429 start_display (&it
, w
, pos
);
8431 /* Display all lines of W. */
8432 while (it
.current_y
< it
.last_visible_y
)
8434 if (display_line (&it
))
8435 last_text_row
= it
.glyph_row
- 1;
8436 if (fonts_changed_p
)
8440 /* If bottom moved off end of frame, change mode line percentage. */
8441 if (XFASTINT (w
->window_end_pos
) <= 0
8442 && Z
!= IT_CHARPOS (it
))
8443 w
->update_mode_line
= Qt
;
8445 /* Set window_end_pos to the offset of the last character displayed
8446 on the window from the end of current_buffer. Set
8447 window_end_vpos to its row number. */
8450 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
8451 w
->window_end_bytepos
8452 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
8453 XSETFASTINT (w
->window_end_pos
,
8454 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
8455 XSETFASTINT (w
->window_end_vpos
,
8456 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
8457 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
8462 w
->window_end_bytepos
= 0;
8463 XSETFASTINT (w
->window_end_pos
, 0);
8464 XSETFASTINT (w
->window_end_vpos
, 0);
8467 /* But that is not valid info until redisplay finishes. */
8468 w
->window_end_valid
= Qnil
;
8474 /************************************************************************
8475 Window redisplay reusing current matrix when buffer has not changed
8476 ************************************************************************/
8478 /* Try redisplay of window W showing an unchanged buffer with a
8479 different window start than the last time it was displayed by
8480 reusing its current matrix. Value is non-zero if successful.
8481 W->start is the new window start. */
8484 try_window_reusing_current_matrix (w
)
8487 struct frame
*f
= XFRAME (w
->frame
);
8488 struct glyph_row
*row
, *bottom_row
;
8491 struct text_pos start
, new_start
;
8492 int nrows_scrolled
, i
;
8493 struct glyph_row
*last_text_row
;
8494 struct glyph_row
*last_reused_text_row
;
8495 struct glyph_row
*start_row
;
8496 int start_vpos
, min_y
, max_y
;
8498 /* Right now this function doesn't handle terminal frames. */
8499 if (!FRAME_WINDOW_P (f
))
8502 /* Can't do this if region may have changed. */
8503 if ((!NILP (Vtransient_mark_mode
)
8504 && !NILP (current_buffer
->mark_active
))
8505 || !NILP (w
->region_showing
))
8508 /* If top-line visibility has changed, give up. */
8509 if (WINDOW_WANTS_TOP_LINE_P (w
)
8510 != MATRIX_TOP_LINE_ROW (w
->current_matrix
)->mode_line_p
)
8513 /* Give up if old or new display is scrolled vertically. We could
8514 make this function handle this, but right now it doesn't. */
8515 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8516 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
8519 /* The variable new_start now holds the new window start. The old
8520 start `start' can be determined from the current matrix. */
8521 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
8522 start
= start_row
->start
.pos
;
8523 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
8525 /* Clear the desired matrix for the display below. */
8526 clear_glyph_matrix (w
->desired_matrix
);
8528 if (CHARPOS (new_start
) <= CHARPOS (start
))
8532 IF_DEBUG (debug_method_add (w
, "twu1"));
8534 /* Display up to a row that can be reused. The variable
8535 last_text_row is set to the last row displayed that displays
8537 start_display (&it
, w
, new_start
);
8538 first_row_y
= it
.current_y
;
8539 w
->cursor
.vpos
= -1;
8540 last_text_row
= last_reused_text_row
= NULL
;
8541 while (it
.current_y
< it
.last_visible_y
8542 && IT_CHARPOS (it
) < CHARPOS (start
)
8543 && !fonts_changed_p
)
8544 if (display_line (&it
))
8545 last_text_row
= it
.glyph_row
- 1;
8547 /* A value of current_y < last_visible_y means that we stopped
8548 at the previous window start, which in turn means that we
8549 have at least one reusable row. */
8550 if (it
.current_y
< it
.last_visible_y
)
8552 nrows_scrolled
= it
.vpos
;
8554 /* Find PT if not already found in the lines displayed. */
8555 if (w
->cursor
.vpos
< 0)
8557 int dy
= it
.current_y
- first_row_y
;
8559 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8560 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
8562 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
8563 && PT
< MATRIX_ROW_END_CHARPOS (row
))
8565 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
8566 dy
, nrows_scrolled
);
8570 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
8576 /* Give up if point was not found. This shouldn't
8577 happen often; not more often than with try_window
8579 if (w
->cursor
.vpos
< 0)
8581 clear_glyph_matrix (w
->desired_matrix
);
8586 /* Scroll the display. Do it before the current matrix is
8587 changed. The problem here is that update has not yet
8588 run, i.e. part of the current matrix is not up to date.
8589 scroll_run_hook will clear the cursor, and use the
8590 current matrix to get the height of the row the cursor is
8592 run
.current_y
= first_row_y
;
8593 run
.desired_y
= it
.current_y
;
8594 run
.height
= it
.last_visible_y
- it
.current_y
;
8598 rif
->update_window_begin_hook (w
);
8599 rif
->scroll_run_hook (w
, &run
);
8600 rif
->update_window_end_hook (w
, 0);
8604 /* Shift current matrix down by nrows_scrolled lines. */
8605 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
8606 rotate_matrix (w
->current_matrix
,
8608 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
8611 /* Disable lines not reused. */
8612 for (i
= 0; i
< it
.vpos
; ++i
)
8613 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
8615 /* Re-compute Y positions. */
8616 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
) + nrows_scrolled
;
8617 min_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
8618 max_y
= it
.last_visible_y
;
8619 while (row
< bottom_row
)
8621 row
->y
= it
.current_y
;
8624 row
->visible_height
= row
->height
- (min_y
- row
->y
);
8625 else if (row
->y
+ row
->height
> max_y
)
8627 = row
->height
- (row
->y
+ row
->height
- max_y
);
8629 row
->visible_height
= row
->height
;
8631 it
.current_y
+= row
->height
;
8634 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
8635 last_reused_text_row
= row
;
8636 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
8642 /* Update window_end_pos etc.; last_reused_text_row is the last
8643 reused row from the current matrix containing text, if any.
8644 The value of last_text_row is the last displayed line
8646 if (last_reused_text_row
)
8648 w
->window_end_bytepos
8649 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
8650 XSETFASTINT (w
->window_end_pos
,
8651 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
8652 XSETFASTINT (w
->window_end_vpos
,
8653 MATRIX_ROW_VPOS (last_reused_text_row
,
8654 w
->current_matrix
));
8656 else if (last_text_row
)
8658 w
->window_end_bytepos
8659 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
8660 XSETFASTINT (w
->window_end_pos
,
8661 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
8662 XSETFASTINT (w
->window_end_vpos
,
8663 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
8667 /* This window must be completely empty. */
8668 w
->window_end_bytepos
= 0;
8669 XSETFASTINT (w
->window_end_pos
, 0);
8670 XSETFASTINT (w
->window_end_vpos
, 0);
8672 w
->window_end_valid
= Qnil
;
8674 /* Update hint: don't try scrolling again in update_window. */
8675 w
->desired_matrix
->no_scrolling_p
= 1;
8678 debug_method_add (w
, "try_window_reusing_current_matrix 1");
8682 else if (CHARPOS (new_start
) > CHARPOS (start
))
8684 struct glyph_row
*pt_row
, *row
;
8685 struct glyph_row
*first_reusable_row
;
8686 struct glyph_row
*first_row_to_display
;
8688 int yb
= window_text_bottom_y (w
);
8690 IF_DEBUG (debug_method_add (w
, "twu2"));
8692 /* Find the row starting at new_start, if there is one. Don't
8693 reuse a partially visible line at the end. */
8694 first_reusable_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8695 while (first_reusable_row
->enabled_p
8696 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
8697 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
8698 < CHARPOS (new_start
)))
8699 ++first_reusable_row
;
8701 /* Give up if there is no row to reuse. */
8702 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
8703 || !first_reusable_row
->enabled_p
)
8706 /* The row we found must start at new_start, or else something
8708 xassert (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
8709 == CHARPOS (new_start
));
8711 /* We can reuse fully visible rows beginning with
8712 first_reusable_row to the end of the window. Set
8713 first_row_to_display to the first row that cannot be reused.
8714 Set pt_row to the row containing point, if there is any. */
8715 first_row_to_display
= first_reusable_row
;
8717 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
8719 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
8720 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
8721 pt_row
= first_row_to_display
;
8723 ++first_row_to_display
;
8726 /* Start displaying at the start of first_row_to_display. */
8727 xassert (first_row_to_display
->y
< yb
);
8728 init_to_row_start (&it
, w
, first_row_to_display
);
8729 nrows_scrolled
= MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
);
8730 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
8732 it
.current_y
= first_row_to_display
->y
- first_reusable_row
->y
;
8734 /* Display lines beginning with first_row_to_display in the
8735 desired matrix. Set last_text_row to the last row displayed
8736 that displays text. */
8737 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
8739 w
->cursor
.vpos
= -1;
8740 last_text_row
= NULL
;
8741 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
8742 if (display_line (&it
))
8743 last_text_row
= it
.glyph_row
- 1;
8745 /* Give up If point isn't in a row displayed or reused. */
8746 if (w
->cursor
.vpos
< 0)
8748 clear_glyph_matrix (w
->desired_matrix
);
8752 /* If point is in a reused row, adjust y and vpos of the cursor
8756 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
8758 w
->cursor
.y
-= first_reusable_row
->y
;
8761 /* Scroll the display. */
8762 run
.current_y
= first_reusable_row
->y
;
8763 run
.desired_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
8764 run
.height
= it
.last_visible_y
- run
.current_y
;
8767 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8769 rif
->update_window_begin_hook (w
);
8770 rif
->scroll_run_hook (w
, &run
);
8771 rif
->update_window_end_hook (w
, 0);
8775 /* Adjust Y positions of reused rows. */
8776 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
8777 row
= first_reusable_row
;
8778 dy
= first_reusable_row
->y
;
8779 min_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
8780 max_y
= it
.last_visible_y
;
8781 while (row
< first_row_to_display
)
8785 row
->visible_height
= row
->height
- (min_y
- row
->y
);
8786 else if (row
->y
+ row
->height
> max_y
)
8788 = row
->height
- (row
->y
+ row
->height
- max_y
);
8790 row
->visible_height
= row
->height
;
8794 /* Disable rows not reused. */
8795 while (row
< bottom_row
)
8801 /* Scroll the current matrix. */
8802 xassert (nrows_scrolled
> 0);
8803 rotate_matrix (w
->current_matrix
,
8805 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
8808 /* Adjust window end. A null value of last_text_row means that
8809 the window end is in reused rows which in turn means that
8810 only its vpos can have changed. */
8813 w
->window_end_bytepos
8814 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
8815 XSETFASTINT (w
->window_end_pos
,
8816 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
8817 XSETFASTINT (w
->window_end_vpos
,
8818 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
8822 XSETFASTINT (w
->window_end_vpos
,
8823 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
8826 w
->window_end_valid
= Qnil
;
8827 w
->desired_matrix
->no_scrolling_p
= 1;
8830 debug_method_add (w
, "try_window_reusing_current_matrix 2");
8840 /************************************************************************
8841 Window redisplay reusing current matrix when buffer has changed
8842 ************************************************************************/
8844 static struct glyph_row
*get_last_unchanged_at_beg_row
P_ ((struct window
*));
8845 static struct glyph_row
*get_first_unchanged_at_end_row
P_ ((struct window
*,
8847 static struct glyph_row
*
8848 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
8849 struct glyph_row
*));
8852 /* Return the last row in MATRIX displaying text. If row START is
8853 non-null, start searching with that row. IT gives the dimensions
8854 of the display. Value is null if matrix is empty; otherwise it is
8855 a pointer to the row found. */
8857 static struct glyph_row
*
8858 find_last_row_displaying_text (matrix
, it
, start
)
8859 struct glyph_matrix
*matrix
;
8861 struct glyph_row
*start
;
8863 struct glyph_row
*row
, *row_found
;
8865 /* Set row_found to the last row in IT->w's current matrix
8866 displaying text. The loop looks funny but think of partially
8869 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
8870 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
8872 xassert (row
->enabled_p
);
8874 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
8883 /* Return the last row in the current matrix of W that is not affected
8884 by changes at the start of current_buffer that occurred since the
8885 last time W was redisplayed. Value is null if no such row exists.
8887 The global variable beg_unchanged has to contain the number of
8888 bytes unchanged at the start of current_buffer. BEG +
8889 beg_unchanged is the buffer position of the first changed byte in
8890 current_buffer. Characters at positions < BEG + beg_unchanged are
8891 at the same buffer positions as they were when the current matrix
8894 static struct glyph_row
*
8895 get_last_unchanged_at_beg_row (w
)
8898 int first_changed_pos
= BEG
+ beg_unchanged
;
8899 struct glyph_row
*row
;
8900 struct glyph_row
*row_found
= NULL
;
8901 int yb
= window_text_bottom_y (w
);
8903 /* Find the last row displaying unchanged text. */
8904 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8905 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
8906 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
8908 if (/* If row ends before first_changed_pos, it is unchanged,
8909 except in some case. */
8910 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
8911 /* When row ends in ZV and we write at ZV it is not
8913 && !row
->ends_at_zv_p
8914 /* When first_changed_pos is the end of a continued line,
8915 row is not unchanged because it may be no longer
8917 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
8918 && row
->continued_p
))
8921 /* Stop if last visible row. */
8922 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
8932 /* Find the first glyph row in the current matrix of W that is not
8933 affected by changes at the end of current_buffer since the last
8934 time the window was redisplayed. Return in *DELTA the number of
8935 bytes by which buffer positions in unchanged text at the end of
8936 current_buffer must be adjusted. Value is null if no such row
8937 exists, i.e. all rows are affected by changes.
8939 The global variable end_unchanged is assumed to contain the number
8940 of unchanged bytes at the end of current_buffer. The buffer
8941 position of the last changed byte in current_buffer is then Z -
8944 static struct glyph_row
*
8945 get_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
8947 int *delta
, *delta_bytes
;
8949 struct glyph_row
*row
;
8950 struct glyph_row
*row_found
= NULL
;
8952 *delta
= *delta_bytes
= 0;
8954 /* A value of window_end_pos >= end_unchanged means that the window
8955 end is in the range of changed text. If so, there is no
8956 unchanged row at the end of W's current matrix. */
8957 xassert (!NILP (w
->window_end_valid
));
8958 if (XFASTINT (w
->window_end_pos
) >= end_unchanged
)
8961 /* Set row to the last row in W's current matrix displaying text. */
8962 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
8964 /* End vpos should always be on text, except in an entirely empty
8966 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
8967 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0);
8969 /* If matrix is entirely empty, no unchanged row exists. */
8970 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
8972 /* The value of row is the last glyph row in the matrix having a
8973 meaningful buffer position in it. The end position of row
8974 corresponds to window_end_pos. This allows us to translate
8975 buffer positions in the current matrix to current buffer
8976 positions for characters not in changed text. */
8977 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
8978 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
8979 int last_unchanged_pos
, last_unchanged_pos_old
;
8980 struct glyph_row
*first_text_row
8981 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8984 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
8986 /* Set last_unchanged_pos to the buffer position of the last
8987 character in the buffer that has not been changed. Z is the
8988 index + 1 of the last byte in current_buffer, i.e. by
8989 subtracting end_unchanged we get the index of the last
8990 unchanged character, and we have to add BEG to get its buffer
8992 last_unchanged_pos
= Z
- end_unchanged
+ BEG
;
8993 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
8995 /* Search backward from ROW for a row displaying a line that
8996 starts at a minimum position >= last_unchanged_pos_old. */
8997 while (row
>= first_text_row
)
8999 xassert (row
->enabled_p
);
9000 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
));
9002 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
9008 xassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
9013 /* Make sure that glyph rows in the current matrix of window W
9014 reference the same glyph memory as corresponding rows in the
9015 frame's frame matrix. This function is called after scrolling W's
9016 current matrix on a terminal frame in try_window_id and
9017 try_window_reusing_current_matrix. */
9020 sync_frame_with_window_matrix_rows (w
)
9023 struct frame
*f
= XFRAME (w
->frame
);
9024 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
9026 /* Preconditions: W must be a leaf window and full-width. Its frame
9027 must have a frame matrix. */
9028 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
9029 xassert (WINDOW_FULL_WIDTH_P (w
));
9030 xassert (!FRAME_WINDOW_P (f
));
9032 /* If W is a full-width window, glyph pointers in W's current matrix
9033 have, by definition, to be the same as glyph pointers in the
9034 corresponding frame matrix. */
9035 window_row
= w
->current_matrix
->rows
;
9036 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
9037 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
9038 while (window_row
< window_row_end
)
9041 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
9042 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
9043 ++window_row
, ++frame_row
;
9048 /* Try to redisplay window W by reusing its existing display. W's
9049 current matrix must be up to date when this function is called,
9050 i.e. window_end_valid must not be nil.
9054 1 if display has been updated
9055 0 if otherwise unsuccessful
9056 -1 if redisplay with same window start is known not to succeed
9058 The following steps are performed:
9060 1. Find the last row in the current matrix of W that is not
9061 affected by changes at the start of current_buffer. If no such row
9064 2. Find the first row in W's current matrix that is not affected by
9065 changes at the end of current_buffer. Maybe there is no such row.
9067 3. Display lines beginning with the row + 1 found in step 1 to the
9068 row found in step 2 or, if step 2 didn't find a row, to the end of
9071 4. If cursor is not known to appear on the window, give up.
9073 5. If display stopped at the row found in step 2, scroll the
9074 display and current matrix as needed.
9076 6. Maybe display some lines at the end of W, if we must. This can
9077 happen under various circumstances, like a partially visible line
9078 becoming fully visible, or because newly displayed lines are displayed
9079 in smaller font sizes.
9081 7. Update W's window end information. */
9083 /* Check that window end is what we expect it to be. */
9089 struct frame
*f
= XFRAME (w
->frame
);
9090 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
9091 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
9092 struct glyph_row
*last_unchanged_at_beg_row
;
9093 struct glyph_row
*first_unchanged_at_end_row
;
9094 struct glyph_row
*row
;
9095 struct glyph_row
*bottom_row
;
9098 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
9099 struct text_pos start_pos
;
9101 int first_unchanged_at_end_vpos
= 0;
9102 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
9103 struct text_pos start
;
9105 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
9107 /* Check pre-conditions. Window end must be valid, otherwise
9108 the current matrix would not be up to date. */
9109 xassert (!NILP (w
->window_end_valid
));
9110 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
9111 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
9113 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
9114 only if buffer has really changed. The reason is that the gap is
9115 initially at Z for freshly visited files. The code below would
9116 set end_unchanged to 0 in that case. */
9117 if (MODIFF
> SAVE_MODIFF
)
9119 if (GPT
- BEG
< beg_unchanged
)
9120 beg_unchanged
= GPT
- BEG
;
9121 if (Z
- GPT
< end_unchanged
)
9122 end_unchanged
= Z
- GPT
;
9125 /* If window starts after a line end, and the last change is in
9126 front of that newline, then changes don't affect the display.
9127 This case happens with stealth-fontification. */
9128 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
9129 if (CHARPOS (start
) > BEGV
9130 && Z
- end_unchanged
< CHARPOS (start
) - 1
9131 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
9132 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9134 /* We have to update window end positions because the buffer's
9135 size has changed. */
9137 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
9138 w
->window_end_bytepos
9139 = make_number (Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
));
9143 /* Return quickly if changes are all below what is displayed in the
9144 window, and if PT is in the window. */
9145 if (beg_unchanged
> MATRIX_ROW_END_CHARPOS (row
)
9146 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9148 /* We have to update window end positions because the buffer's
9149 size has changed. */
9151 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
9152 w
->window_end_bytepos
9153 = make_number (Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
));
9157 /* Check that window start agrees with the start of the first glyph
9158 row in its current matrix. Check this after we know the window
9159 start is not in changed text, otherwise positions would not be
9161 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9162 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
9165 /* Remember beg_unchanged and end_unchanged for debugging purposes. */
9166 IF_DEBUG (debug_beg_unchanged
= beg_unchanged
;
9167 debug_end_unchanged
= end_unchanged
);
9169 /* Compute the position at which we have to start displaying new
9170 lines. Some of the lines at the top of the window might be
9171 reusable because they are not displaying changed text. Find the
9172 last row in W's current matrix not affected by changes at the
9173 start of current_buffer. Value is null if changes start in the
9174 first line of window. */
9175 last_unchanged_at_beg_row
= get_last_unchanged_at_beg_row (w
);
9176 if (last_unchanged_at_beg_row
)
9178 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
9179 start_pos
= it
.current
.pos
;
9181 /* Start displaying new lines in the desired matrix at the same
9182 vpos we would use in the current matrix, i.e. below
9183 last_unchanged_at_beg_row. */
9184 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
9186 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
9187 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
9189 xassert (it
.hpos
== 0 && it
.current_x
== 0);
9193 /* There are no reusable lines at the start of the window.
9194 Start displaying in the first line. */
9195 start_display (&it
, w
, start
);
9196 start_pos
= it
.current
.pos
;
9199 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
9200 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
9202 /* Find the first row that is not affected by changes at the end of
9203 the buffer. Value will be null if there is no unchanged row, in
9204 which case we must redisplay to the end of the window. delta
9205 will be set to the value by which buffer positions beginning with
9206 first_unchanged_at_end_row have to be adjusted due to text
9208 first_unchanged_at_end_row
9209 = get_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
9210 IF_DEBUG (debug_delta
= delta
);
9211 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
9213 /* Set stop_pos to the buffer position up to which we will have to
9214 display new lines. If first_unchanged_at_end_row != NULL, this
9215 is the buffer position of the start of the line displayed in that
9216 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
9217 that we don't stop at a buffer position. */
9219 if (first_unchanged_at_end_row
)
9221 xassert (last_unchanged_at_beg_row
== NULL
9222 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
9224 /* If this is a continuation line, move forward to the next one
9225 that isn't. Changes in lines above affect this line.
9226 Caution: this may move first_unchanged_at_end_row to a row
9227 not displaying text. */
9228 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
9229 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
9230 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
9231 < it
.last_visible_y
))
9232 ++first_unchanged_at_end_row
;
9234 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
9235 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
9236 >= it
.last_visible_y
))
9237 first_unchanged_at_end_row
= NULL
;
9240 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
9242 first_unchanged_at_end_vpos
9243 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
9244 xassert (stop_pos
>= Z
- end_unchanged
);
9247 else if (last_unchanged_at_beg_row
== NULL
)
9253 /* Either there is no unchanged row at the end, or the one we have
9254 now displays text. This is a necessary condition for the window
9255 end pos calculation at the end of this function. */
9256 xassert (first_unchanged_at_end_row
== NULL
9257 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
9259 debug_last_unchanged_at_beg_vpos
9260 = (last_unchanged_at_beg_row
9261 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
9263 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
9265 #endif /* GLYPH_DEBUG != 0 */
9268 /* Display new lines. Set last_text_row to the last new line
9269 displayed which has text on it, i.e. might end up as being the
9270 line where the window_end_vpos is. */
9271 w
->cursor
.vpos
= -1;
9272 last_text_row
= NULL
;
9273 overlay_arrow_seen
= 0;
9274 while (it
.current_y
< it
.last_visible_y
9276 && (first_unchanged_at_end_row
== NULL
9277 || IT_CHARPOS (it
) < stop_pos
))
9279 if (display_line (&it
))
9280 last_text_row
= it
.glyph_row
- 1;
9283 if (fonts_changed_p
)
9287 /* Compute differences in buffer positions, y-positions etc. for
9288 lines reused at the bottom of the window. Compute what we can
9290 if (first_unchanged_at_end_row
)
9293 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
9295 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
9296 run
.current_y
= first_unchanged_at_end_row
->y
;
9297 run
.desired_y
= run
.current_y
+ dy
;
9298 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
9301 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
9302 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
9305 /* Find the cursor if not already found. We have to decide whether
9306 PT will appear on this window (it sometimes doesn't, but this is
9307 not a very frequent case.) This decision has to be made before
9308 the current matrix is altered. A value of cursor.vpos < 0 means
9309 that PT is either in one of the lines beginning at
9310 first_unchanged_at_end_row or below the window. Don't care for
9311 lines that might be displayed later at the window end; as
9312 mentioned, this is not a frequent case. */
9313 if (w
->cursor
.vpos
< 0)
9315 int last_y
= min (it
.last_visible_y
, it
.last_visible_y
+ dy
);
9317 /* Cursor in unchanged rows at the top? */
9318 if (PT
< CHARPOS (start_pos
)
9319 && last_unchanged_at_beg_row
)
9321 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9322 while (row
<= last_unchanged_at_beg_row
9323 && MATRIX_ROW_END_CHARPOS (row
) <= PT
)
9325 xassert (row
<= last_unchanged_at_beg_row
);
9326 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9329 /* Start from first_unchanged_at_end_row looking for PT. */
9330 else if (first_unchanged_at_end_row
)
9332 row
= first_unchanged_at_end_row
;
9333 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9335 if (PT
- delta
>= MATRIX_ROW_START_CHARPOS (row
)
9336 && PT
- delta
< MATRIX_ROW_END_CHARPOS (row
))
9338 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
9339 delta_bytes
, dy
, dvpos
);
9342 else if (MATRIX_ROW_BOTTOM_Y (row
) >= last_y
)
9348 /* Give up if cursor was not found. */
9349 if (w
->cursor
.vpos
< 0)
9351 clear_glyph_matrix (w
->desired_matrix
);
9356 /* Don't let the cursor end in the scroll margins. */
9358 int this_scroll_margin
, cursor_height
;
9360 this_scroll_margin
= max (0, scroll_margin
);
9361 this_scroll_margin
= min (this_scroll_margin
,
9362 XFASTINT (w
->height
) / 4);
9363 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
9364 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
9366 if ((w
->cursor
.y
< this_scroll_margin
9367 && CHARPOS (start
) > BEGV
)
9368 /* Don't take scroll margin into account at the bottom because
9369 old redisplay didn't do it either. */
9370 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
9372 w
->cursor
.vpos
= -1;
9373 clear_glyph_matrix (w
->desired_matrix
);
9378 /* Scroll the display. Do it before changing the current matrix so
9379 that xterm.c doesn't get confused about where the cursor glyph is
9385 if (FRAME_WINDOW_P (f
))
9387 rif
->update_window_begin_hook (w
);
9388 rif
->scroll_run_hook (w
, &run
);
9389 rif
->update_window_end_hook (w
, 0);
9393 /* Terminal frame. In this case, dvpos gives the number of
9394 lines to scroll by; dvpos < 0 means scroll up. */
9395 int first_unchanged_at_end_vpos
9396 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
9397 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
9398 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
9400 /* Perform the operation on the screen. */
9403 /* Scroll last_unchanged_at_beg_row to the end of the
9404 window down dvpos lines. */
9405 set_terminal_window (end
);
9407 /* On dumb terminals delete dvpos lines at the end
9408 before inserting dvpos empty lines. */
9409 if (!scroll_region_ok
)
9410 ins_del_lines (end
- dvpos
, -dvpos
);
9412 /* Insert dvpos empty lines in front of
9413 last_unchanged_at_beg_row. */
9414 ins_del_lines (from
, dvpos
);
9418 /* Scroll up last_unchanged_at_beg_vpos to the end of
9419 the window to last_unchanged_at_beg_vpos - |dvpos|. */
9420 set_terminal_window (end
);
9422 /* Delete dvpos lines in front of
9423 last_unchanged_at_beg_vpos. ins_del_lines will set
9424 the cursor to the given vpos and emit |dvpos| delete
9426 ins_del_lines (from
+ dvpos
, dvpos
);
9428 /* On a dumb terminal insert dvpos empty lines at the
9430 if (!scroll_region_ok
)
9431 ins_del_lines (end
+ dvpos
, -dvpos
);
9434 set_terminal_window (0);
9440 /* Shift reused rows of the current matrix to the right position. */
9443 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
9444 bottom_vpos
, dvpos
);
9445 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
9450 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
9451 bottom_vpos
, dvpos
);
9452 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
9453 first_unchanged_at_end_vpos
+ dvpos
, 0);
9456 /* For frame-based redisplay, make sure that current frame and window
9457 matrix are in sync with respect to glyph memory. */
9458 if (!FRAME_WINDOW_P (f
))
9459 sync_frame_with_window_matrix_rows (w
);
9461 /* Adjust buffer positions in reused rows. */
9463 increment_glyph_matrix_buffer_positions (current_matrix
,
9464 first_unchanged_at_end_vpos
+ dvpos
,
9465 bottom_vpos
, delta
, delta_bytes
);
9467 /* Adjust Y positions. */
9469 shift_glyph_matrix (w
, current_matrix
,
9470 first_unchanged_at_end_vpos
+ dvpos
,
9473 if (first_unchanged_at_end_row
)
9474 first_unchanged_at_end_row
+= dvpos
;
9476 /* If scrolling up, there may be some lines to display at the end of
9478 last_text_row_at_end
= NULL
;
9481 /* Set last_row to the glyph row in the current matrix where the
9482 window end line is found. It has been moved up or down in
9483 the matrix by dvpos. */
9484 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
9485 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
9487 /* If last_row is the window end line, it should display text. */
9488 xassert (last_row
->displays_text_p
);
9490 /* If window end line was partially visible before, begin
9491 displaying at that line. Otherwise begin displaying with the
9492 line following it. */
9493 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
9495 init_to_row_start (&it
, w
, last_row
);
9496 it
.vpos
= last_vpos
;
9497 it
.current_y
= last_row
->y
;
9501 init_to_row_end (&it
, w
, last_row
);
9502 it
.vpos
= 1 + last_vpos
;
9503 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
9507 /* We may start in a continuation line. If so, we have to get
9508 the right continuation_lines_width and current_x. */
9509 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
9510 it
.hpos
= it
.current_x
= 0;
9512 /* Display the rest of the lines at the window end. */
9513 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
9514 while (it
.current_y
< it
.last_visible_y
9515 && !fonts_changed_p
)
9517 /* Is it always sure that the display agrees with lines in
9518 the current matrix? I don't think so, so we mark rows
9519 displayed invalid in the current matrix by setting their
9520 enabled_p flag to zero. */
9521 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
9522 if (display_line (&it
))
9523 last_text_row_at_end
= it
.glyph_row
- 1;
9527 /* Update window_end_pos and window_end_vpos. */
9528 if (first_unchanged_at_end_row
9529 && first_unchanged_at_end_row
->y
< it
.last_visible_y
9530 && !last_text_row_at_end
)
9532 /* Window end line if one of the preserved rows from the current
9533 matrix. Set row to the last row displaying text in current
9534 matrix starting at first_unchanged_at_end_row, after
9536 xassert (first_unchanged_at_end_row
->displays_text_p
);
9537 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
9538 first_unchanged_at_end_row
);
9539 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
9541 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
9542 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
9543 XSETFASTINT (w
->window_end_vpos
,
9544 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
9546 else if (last_text_row_at_end
)
9548 XSETFASTINT (w
->window_end_pos
,
9549 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
9550 w
->window_end_bytepos
9551 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
9552 XSETFASTINT (w
->window_end_vpos
,
9553 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
9555 else if (last_text_row
)
9557 /* We have displayed either to the end of the window or at the
9558 end of the window, i.e. the last row with text is to be found
9559 in the desired matrix. */
9560 XSETFASTINT (w
->window_end_pos
,
9561 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9562 w
->window_end_bytepos
9563 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9564 XSETFASTINT (w
->window_end_vpos
,
9565 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
9567 else if (first_unchanged_at_end_row
== NULL
9568 && last_text_row
== NULL
9569 && last_text_row_at_end
== NULL
)
9571 /* Displayed to end of window, but no line containing text was
9572 displayed. Lines were deleted at the end of the window. */
9574 int top_line_p
= WINDOW_WANTS_TOP_LINE_P (w
) ? 1 : 0;
9576 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
9577 if ((w
->desired_matrix
->rows
[vpos
+ top_line_p
].enabled_p
9578 && w
->desired_matrix
->rows
[vpos
+ top_line_p
].displays_text_p
)
9579 || (!w
->desired_matrix
->rows
[vpos
+ top_line_p
].enabled_p
9580 && w
->current_matrix
->rows
[vpos
+ top_line_p
].displays_text_p
))
9583 w
->window_end_vpos
= make_number (vpos
);
9588 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
9589 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
9591 /* Record that display has not been completed. */
9592 w
->window_end_valid
= Qnil
;
9593 w
->desired_matrix
->no_scrolling_p
= 1;
9599 /***********************************************************************
9600 More debugging support
9601 ***********************************************************************/
9605 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
9606 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
9609 /* Dump the contents of glyph matrix MATRIX on stderr. If
9610 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
9613 dump_glyph_matrix (matrix
, with_glyphs_p
)
9614 struct glyph_matrix
*matrix
;
9618 for (i
= 0; i
< matrix
->nrows
; ++i
)
9619 dump_glyph_row (matrix
, i
, with_glyphs_p
);
9623 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
9624 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
9627 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
9628 struct glyph_matrix
*matrix
;
9629 int vpos
, with_glyphs_p
;
9631 struct glyph_row
*row
;
9633 if (vpos
< 0 || vpos
>= matrix
->nrows
)
9636 row
= MATRIX_ROW (matrix
, vpos
);
9638 fprintf (stderr
, "Row Start End Used oEI><O\\CTZF X Y W\n");
9639 fprintf (stderr
, "=============================================\n");
9641 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",
9643 MATRIX_ROW_START_CHARPOS (row
),
9644 MATRIX_ROW_END_CHARPOS (row
),
9645 row
->used
[TEXT_AREA
],
9646 row
->contains_overlapping_glyphs_p
,
9649 row
->truncated_on_left_p
,
9650 row
->truncated_on_right_p
,
9651 row
->overlay_arrow_p
,
9653 MATRIX_ROW_CONTINUATION_LINE_P (row
),
9654 row
->displays_text_p
,
9660 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
9661 row
->end
.overlay_string_index
);
9662 fprintf (stderr
, "%9d %5d\n",
9663 CHARPOS (row
->start
.string_pos
),
9664 CHARPOS (row
->end
.string_pos
));
9665 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
9666 row
->end
.dpvec_index
);
9670 struct glyph
*glyph
, *glyph_end
;
9671 int prev_had_glyphs_p
;
9673 glyph
= row
->glyphs
[TEXT_AREA
];
9674 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
9676 /* Glyph for a line end in text. */
9677 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
9680 if (glyph
< glyph_end
)
9682 fprintf (stderr
, " Glyph Type Pos W Code C Face LR\n");
9683 prev_had_glyphs_p
= 1;
9686 prev_had_glyphs_p
= 0;
9688 while (glyph
< glyph_end
)
9690 if (glyph
->type
== CHAR_GLYPH
)
9693 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
9694 glyph
- row
->glyphs
[TEXT_AREA
],
9699 (glyph
->u
.ch
.code
< 0x80 && glyph
->u
.ch
.code
>= ' '
9702 glyph
->u
.ch
.face_id
,
9703 glyph
->left_box_line_p
,
9704 glyph
->right_box_line_p
);
9706 else if (glyph
->type
== STRETCH_GLYPH
)
9709 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
9710 glyph
- row
->glyphs
[TEXT_AREA
],
9716 glyph
->u
.stretch
.face_id
,
9717 glyph
->left_box_line_p
,
9718 glyph
->right_box_line_p
);
9720 else if (glyph
->type
== IMAGE_GLYPH
)
9723 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
9724 glyph
- row
->glyphs
[TEXT_AREA
],
9730 glyph
->u
.img
.face_id
,
9731 glyph
->left_box_line_p
,
9732 glyph
->right_box_line_p
);
9740 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
9741 Sdump_glyph_matrix
, 0, 1, "p",
9742 "Dump the current matrix of the selected window to stderr.\n\
9743 Shows contents of glyph row structures. With non-nil optional\n\
9744 parameter WITH-GLYPHS-P, dump glyphs as well.")
9747 struct window
*w
= XWINDOW (selected_window
);
9748 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9750 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
9751 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
9752 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
9753 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
9754 fprintf (stderr
, "=============================================\n");
9755 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
9760 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
9761 "Dump glyph row ROW to stderr.")
9765 CHECK_NUMBER (row
, 0);
9766 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
9771 DEFUN ("dump-toolbar-row", Fdump_toolbar_row
, Sdump_toolbar_row
,
9775 struct glyph_matrix
*m
= (XWINDOW (selected_frame
->toolbar_window
)
9777 dump_glyph_row (m
, 0, 1);
9782 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
9783 Strace_redisplay_toggle
, 0, 0, "",
9784 "Toggle tracing of redisplay.")
9787 trace_redisplay_p
= !trace_redisplay_p
;
9792 #endif /* GLYPH_DEBUG */
9796 /***********************************************************************
9797 Building Desired Matrix Rows
9798 ***********************************************************************/
9800 /* Return a temporary glyph row holding the glyphs of an overlay
9801 arrow. Only used for non-window-redisplay windows. */
9803 static struct glyph_row
*
9804 get_overlay_arrow_glyph_row (w
)
9807 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9808 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9809 struct buffer
*old
= current_buffer
;
9810 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
9811 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
9812 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
9816 int n_glyphs_before
;
9818 set_buffer_temp (buffer
);
9819 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
9820 it
.glyph_row
->used
[TEXT_AREA
] = 0;
9821 SET_TEXT_POS (it
.position
, 0, 0);
9823 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
9825 while (p
< arrow_end
)
9827 Lisp_Object face
, ilisp
;
9829 /* Get the next character. */
9831 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
9833 it
.c
= *p
, it
.len
= 1;
9837 XSETFASTINT (ilisp
, p
- arrow_string
);
9838 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
9839 it
.face_id
= compute_char_face (f
, it
.c
, face
);
9841 /* Compute its width, get its glyphs. */
9842 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
9843 SET_TEXT_POS (it
.position
, -1, -1);
9844 PRODUCE_GLYPHS (&it
);
9846 /* If this character doesn't fit any more in the line, we have
9847 to remove some glyphs. */
9848 if (it
.current_x
> it
.last_visible_x
)
9850 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
9855 set_buffer_temp (old
);
9856 return it
.glyph_row
;
9860 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
9861 glyphs are only inserted for terminal frames since we can't really
9862 win with truncation glyphs when partially visible glyphs are
9863 involved. Which glyphs to insert is determined by
9864 produce_special_glyphs. */
9867 insert_left_trunc_glyphs (it
)
9870 struct it truncate_it
;
9871 struct glyph
*from
, *end
, *to
, *toend
;
9873 xassert (!FRAME_WINDOW_P (it
->f
));
9875 /* Get the truncation glyphs. */
9877 truncate_it
.charset
= -1;
9878 truncate_it
.current_x
= 0;
9879 truncate_it
.face_id
= DEFAULT_FACE_ID
;
9880 truncate_it
.glyph_row
= &scratch_glyph_row
;
9881 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
9882 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
9883 truncate_it
.object
= 0;
9884 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
9886 /* Overwrite glyphs from IT with truncation glyphs. */
9887 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
9888 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
9889 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
9890 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
9895 /* There may be padding glyphs left over. Remove them. */
9897 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
9899 while (from
< toend
)
9902 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
9906 /* Compute the pixel height and width of IT->glyph_row.
9908 Most of the time, ascent and height of a display line will be equal
9909 to the max_ascent and max_height values of the display iterator
9910 structure. This is not the case if
9912 1. We hit ZV without displaying anything. In this case, max_ascent
9913 and max_height will be zero.
9915 2. We have some glyphs that don't contribute to the line height.
9916 (The glyph row flag contributes_to_line_height_p is for future
9919 The first case is easily covered by using default values because in
9920 these cases, the line height does not really matter, except that it
9921 must not be zero. */
9924 compute_line_metrics (it
)
9927 struct glyph_row
*row
= it
->glyph_row
;
9930 if (FRAME_WINDOW_P (it
->f
))
9932 int i
, top_line_height
;
9934 /* The line may consist of one space only, that was added to
9935 place the cursor on it. If so, the row's height hasn't been
9937 if (row
->height
== 0)
9939 if (it
->max_ascent
+ it
->max_descent
== 0)
9940 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
9941 row
->ascent
= it
->max_ascent
;
9942 row
->height
= it
->max_ascent
+ it
->max_descent
;
9943 row
->phys_ascent
= it
->max_phys_ascent
;
9944 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
9947 /* Compute the width of this line. */
9948 row
->pixel_width
= row
->x
;
9949 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
9950 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9952 xassert (row
->pixel_width
>= 0);
9953 xassert (row
->ascent
>= 0 && row
->height
> 0);
9955 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
9956 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
9958 /* If first line's physical ascent is larger than its logical
9959 ascent, use the physical ascent, and make the row taller.
9960 This makes accented characters fully visible. */
9961 if (row
== it
->w
->desired_matrix
->rows
9962 && row
->phys_ascent
> row
->ascent
)
9964 row
->height
+= row
->phys_ascent
- row
->ascent
;
9965 row
->ascent
= row
->phys_ascent
;
9968 /* Compute how much of the line is visible. */
9969 row
->visible_height
= row
->height
;
9971 top_line_height
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (it
->w
);
9972 if (row
->y
< top_line_height
)
9973 row
->visible_height
-= top_line_height
- row
->y
;
9976 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
9977 if (row
->y
+ row
->height
> max_y
)
9978 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
9983 row
->pixel_width
= row
->used
[TEXT_AREA
];
9984 row
->ascent
= row
->phys_ascent
= 0;
9985 row
->height
= row
->phys_height
= row
->visible_height
= 1;
9988 /* Compute a hash code for this row. */
9990 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
9991 for (i
= 0; i
< row
->used
[area
]; ++i
)
9992 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
9993 + row
->glyphs
[area
][i
].u
.val
9994 + (row
->glyphs
[area
][i
].type
<< 2));
9996 it
->max_ascent
= it
->max_descent
= 0;
9997 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
10001 /* Append one space to the glyph row of iterator IT if doing a
10002 window-based redisplay. DEFAULT_FACE_P non-zero means let the
10003 space have the default face, otherwise let it have the same face as
10004 IT->face_id. This function is called to make sure that there is
10005 always one glyph at the end of a glyph row that the cursor can be
10006 set on under window-systems. (If there weren't such a glyph we
10007 would not know how wide and tall the cursor should be displayed). */
10010 append_space (it
, default_face_p
)
10012 int default_face_p
;
10014 if (FRAME_WINDOW_P (it
->f
))
10016 int n
= it
->glyph_row
->used
[TEXT_AREA
];
10018 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
10019 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
10021 /* Save some values that must not be changed. */
10022 int saved_x
= it
->current_x
;
10023 struct text_pos saved_pos
;
10024 int saved_what
= it
->what
;
10025 int saved_face_id
= it
->face_id
;
10026 int saved_charset
= it
->charset
;
10027 Lisp_Object saved_object
;
10029 saved_object
= it
->object
;
10030 saved_pos
= it
->position
;
10032 it
->what
= IT_CHARACTER
;
10033 bzero (&it
->position
, sizeof it
->position
);
10037 it
->charset
= CHARSET_ASCII
;
10039 if (default_face_p
)
10040 it
->face_id
= DEFAULT_FACE_ID
;
10041 if (it
->multibyte_p
)
10042 it
->face_id
= FACE_FOR_CHARSET (it
->f
, it
->face_id
, CHARSET_ASCII
);
10044 it
->face_id
= FACE_FOR_CHARSET (it
->f
, it
->face_id
, -1);
10046 PRODUCE_GLYPHS (it
);
10048 it
->current_x
= saved_x
;
10049 it
->object
= saved_object
;
10050 it
->position
= saved_pos
;
10051 it
->what
= saved_what
;
10052 it
->face_id
= saved_face_id
;
10053 it
->charset
= saved_charset
;
10059 /* Extend the face of the last glyph in the text area of IT->glyph_row
10060 to the end of the display line. Called from display_line.
10061 If the glyph row is empty, add a space glyph to it so that we
10062 know the face to draw. Set the glyph row flag fill_line_p. */
10065 extend_face_to_end_of_line (it
)
10069 struct frame
*f
= it
->f
;
10071 /* If line is already filled, do nothing. */
10072 if (it
->current_x
>= it
->last_visible_x
)
10075 /* Face extension extends the background and box of IT->face_id
10076 to the end of the line. If the background equals the background
10077 of the frame, we haven't to do anything. */
10078 face
= FACE_FROM_ID (f
, it
->face_id
);
10079 if (FRAME_WINDOW_P (f
)
10080 && face
->box
== FACE_NO_BOX
10081 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
10085 /* Set the glyph row flag indicating that the face of the last glyph
10086 in the text area has to be drawn to the end of the text area. */
10087 it
->glyph_row
->fill_line_p
= 1;
10089 /* If current charset of IT is not ASCII, make sure we have the
10090 ASCII face. This will be automatically undone the next time
10091 get_next_display_element returns a character from a different
10092 charset. Note that the charset will always be ASCII in unibyte
10094 if (it
->charset
!= CHARSET_ASCII
)
10096 it
->charset
= CHARSET_ASCII
;
10097 it
->face_id
= FACE_FOR_CHARSET (f
, it
->face_id
, CHARSET_ASCII
);
10100 if (FRAME_WINDOW_P (f
))
10102 /* If the row is empty, add a space with the current face of IT,
10103 so that we know which face to draw. */
10104 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
10106 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
10107 it
->glyph_row
->glyphs
[TEXT_AREA
][0].u
.ch
.face_id
= it
->face_id
;
10108 it
->glyph_row
->used
[TEXT_AREA
] = 1;
10113 /* Save some values that must not be changed. */
10114 int saved_x
= it
->current_x
;
10115 struct text_pos saved_pos
;
10116 Lisp_Object saved_object
;
10117 int saved_what
= it
->what
;
10119 saved_object
= it
->object
;
10120 saved_pos
= it
->position
;
10122 it
->what
= IT_CHARACTER
;
10123 bzero (&it
->position
, sizeof it
->position
);
10128 PRODUCE_GLYPHS (it
);
10130 while (it
->current_x
<= it
->last_visible_x
)
10131 PRODUCE_GLYPHS (it
);
10133 /* Don't count these blanks really. It would let us insert a left
10134 truncation glyph below and make us set the cursor on them, maybe. */
10135 it
->current_x
= saved_x
;
10136 it
->object
= saved_object
;
10137 it
->position
= saved_pos
;
10138 it
->what
= saved_what
;
10143 /* Value is non-zero if text starting at CHARPOS in current_buffer is
10144 trailing whitespace. */
10147 trailing_whitespace_p (charpos
)
10150 int bytepos
= CHAR_TO_BYTE (charpos
);
10153 while (bytepos
< ZV_BYTE
10154 && (c
= FETCH_CHAR (bytepos
),
10155 c
== ' ' || c
== '\t'))
10158 return bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r';
10162 /* Highlight trailing whitespace, if any, in ROW. */
10165 highlight_trailing_whitespace (f
, row
)
10167 struct glyph_row
*row
;
10169 int used
= row
->used
[TEXT_AREA
];
10173 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
10174 struct glyph
*glyph
= start
+ used
- 1;
10176 /* Skip over the space glyph inserted to display the
10177 cursor at the end of a line. */
10178 if (glyph
->type
== CHAR_GLYPH
10179 && glyph
->u
.ch
.code
== ' '
10180 && glyph
->object
== 0)
10183 /* If last glyph is a space or stretch, and it's trailing
10184 whitespace, set the face of all trailing whitespace glyphs in
10185 IT->glyph_row to `trailing-whitespace'. */
10187 && BUFFERP (glyph
->object
)
10188 && (glyph
->type
== STRETCH_GLYPH
10189 || (glyph
->type
== CHAR_GLYPH
10190 && glyph
->u
.ch
.code
== ' '))
10191 && trailing_whitespace_p (glyph
->charpos
))
10193 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
,
10196 while (glyph
>= start
10197 && BUFFERP (glyph
->object
)
10198 && (glyph
->type
== STRETCH_GLYPH
10199 || (glyph
->type
== CHAR_GLYPH
10200 && glyph
->u
.ch
.code
== ' ')))
10202 if (glyph
->type
== STRETCH_GLYPH
)
10203 glyph
->u
.stretch
.face_id
= face_id
;
10205 glyph
->u
.ch
.face_id
= face_id
;
10214 /* Construct the glyph row IT->glyph_row in the desired matrix of
10215 IT->w from text at the current position of IT. See dispextern.h
10216 for an overview of struct it. Value is non-zero if
10217 IT->glyph_row displays text, as opposed to a line displaying ZV
10224 struct glyph_row
*row
= it
->glyph_row
;
10226 /* We always start displaying at hpos zero even if hscrolled. */
10227 xassert (it
->hpos
== 0 && it
->current_x
== 0);
10229 /* We must not display in a row that's not a text row. */
10230 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
10231 < it
->w
->desired_matrix
->nrows
);
10233 /* Is IT->w showing the region? */
10234 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
10236 /* Clear the result glyph row and enable it. */
10237 prepare_desired_row (row
);
10239 row
->y
= it
->current_y
;
10240 row
->start
= it
->current
;
10241 row
->continuation_lines_width
= it
->continuation_lines_width
;
10242 row
->displays_text_p
= 1;
10244 /* Arrange the overlays nicely for our purposes. Usually, we call
10245 display_line on only one line at a time, in which case this
10246 can't really hurt too much, or we call it on lines which appear
10247 one after another in the buffer, in which case all calls to
10248 recenter_overlay_lists but the first will be pretty cheap. */
10249 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
10251 #if NO_PROMPT_IN_BUFFER
10252 /* Show mini-buffer prompt, if at the beginning of a mini-buffer
10254 if (MINI_WINDOW_P (it
->w
)
10255 && MATRIX_ROW_START_CHARPOS (row
) == BEG
10258 if (NILP (minibuf_prompt
))
10259 minibuf_prompt_width
= minibuf_prompt_pixel_width
= 0;
10262 /* We would like to truncate the prompt a little bit before
10263 the right margin of the window, so that user input can
10264 start on the first line. Set max_x to this position. */
10265 int max_x
= (it
->last_visible_x
- 4 * CANON_X_UNIT (it
->f
));
10267 /* We use a temporary iterator different from IT so that
10268 IT's settings are not overwritten when displaying
10274 /* Display the prompt. Set minibuf_prompt_width to the
10275 number of glyphs generated for the prompt, set
10276 minibuf_prompt_pixel_width to its width in pixels. */
10277 xassert (it
->current_x
== 0);
10278 display_string (NULL
, minibuf_prompt
, Qnil
, 0, 0, &ti
,
10280 minibuf_prompt_width
= ti
.hpos
;
10281 minibuf_prompt_pixel_width
= ti
.current_x
;
10283 /* Transfer pixel and hpos information to IT. */
10284 it
->hpos
= ti
.hpos
;
10285 it
->current_x
= ti
.current_x
;
10288 #endif /* NO_PROMPT_IN_BUFFER */
10290 /* Move over display elements that are not visible because we are
10291 hscrolled. This may stop at an x-position < IT->first_visible_x
10292 if the first glyph is partially visible or if we hit a line end. */
10293 if (it
->current_x
< it
->first_visible_x
)
10294 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
10295 MOVE_TO_POS
| MOVE_TO_X
);
10297 /* Get the initial row height. This is either the height of the
10298 text hscrolled, if there is any, or zero. */
10299 row
->ascent
= it
->max_ascent
;
10300 row
->height
= it
->max_ascent
+ it
->max_descent
;
10301 row
->phys_ascent
= it
->max_phys_ascent
;
10302 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
10304 /* Loop generating characters. The loop is left with IT on the next
10305 character to display. */
10308 int n_glyphs_before
, hpos_before
, x_before
;
10311 /* Retrieve the next thing to display. Value is zero if end of
10313 if (!get_next_display_element (it
))
10315 /* Maybe add a space at the end of this line that is used to
10316 display the cursor there under X. */
10317 append_space (it
, 1);
10319 /* The position -1 below indicates a blank line not
10320 corresponding to any text, as opposed to an empty line
10321 corresponding to a line end. */
10322 if (row
->used
[TEXT_AREA
] <= 1)
10324 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
10325 row
->displays_text_p
= 0;
10327 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
10328 row
->indicate_empty_line_p
= 1;
10331 it
->continuation_lines_width
= 0;
10332 row
->ends_at_zv_p
= 1;
10336 /* Now, get the metrics of what we want to display. This also
10337 generates glyphs in `row' (which is IT->glyph_row). */
10338 n_glyphs_before
= row
->used
[TEXT_AREA
];
10340 PRODUCE_GLYPHS (it
);
10342 /* If this display element was in marginal areas, continue with
10344 if (it
->area
!= TEXT_AREA
)
10346 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
10347 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
10348 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
10349 row
->phys_height
= max (row
->phys_height
,
10350 it
->max_phys_ascent
+ it
->max_phys_descent
);
10351 set_iterator_to_next (it
);
10355 /* Does the display element fit on the line? If we truncate
10356 lines, we should draw past the right edge of the window. If
10357 we don't truncate, we want to stop so that we can display the
10358 continuation glyph before the right margin. If lines are
10359 continued, there are two possible strategies for characters
10360 resulting in more than 1 glyph (e.g. tabs): Display as many
10361 glyphs as possible in this line and leave the rest for the
10362 continuation line, or display the whole element in the next
10363 line. Original redisplay did the former, so we do it also. */
10364 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10365 hpos_before
= it
->hpos
;
10369 && it
->current_x
< it
->last_visible_x
)
10372 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
10373 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
10374 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
10375 row
->phys_height
= max (row
->phys_height
,
10376 it
->max_phys_ascent
+ it
->max_phys_descent
);
10377 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
10378 row
->x
= x
- it
->first_visible_x
;
10383 struct glyph
*glyph
;
10385 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
10387 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10388 new_x
= x
+ glyph
->pixel_width
;
10390 if (/* Lines are continued. */
10391 !it
->truncate_lines_p
10392 && (/* Glyph doesn't fit on the line. */
10393 new_x
> it
->last_visible_x
10394 /* Or it fits exactly on a window system frame. */
10395 || (new_x
== it
->last_visible_x
10396 && FRAME_WINDOW_P (it
->f
))))
10398 /* End of a continued line. */
10401 || (new_x
== it
->last_visible_x
10402 && FRAME_WINDOW_P (it
->f
)))
10404 /* Current glyph fits exactly on the line. We
10405 must continue the line because we can't draw
10406 the cursor after the glyph. */
10407 row
->continued_p
= 1;
10408 it
->current_x
= new_x
;
10409 it
->continuation_lines_width
+= new_x
;
10411 if (i
== nglyphs
- 1)
10412 set_iterator_to_next (it
);
10416 /* Display element draws past the right edge of
10417 the window. Restore positions to values
10418 before the element. The next line starts
10419 with current_x before the glyph that could
10420 not be displayed, so that TAB works right. */
10421 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
10423 /* Display continuation glyphs. */
10424 if (!FRAME_WINDOW_P (it
->f
))
10425 produce_special_glyphs (it
, IT_CONTINUATION
);
10426 row
->continued_p
= 1;
10429 it
->continuation_lines_width
+= x
;
10433 else if (new_x
> it
->first_visible_x
)
10435 /* Increment number of glyphs actually displayed. */
10438 if (x
< it
->first_visible_x
)
10439 /* Glyph is partially visible, i.e. row starts at
10440 negative X position. */
10441 row
->x
= x
- it
->first_visible_x
;
10445 /* Glyph is completely off the left margin of the
10446 window. This should not happen because of the
10447 move_it_in_display_line at the start of
10453 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
10454 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
10455 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
10456 row
->phys_height
= max (row
->phys_height
,
10457 it
->max_phys_ascent
+ it
->max_phys_descent
);
10459 /* End of this display line if row is continued. */
10460 if (row
->continued_p
)
10464 /* Is this a line end? If yes, we're also done, after making
10465 sure that a non-default face is extended up to the right
10466 margin of the window. */
10467 if (ITERATOR_AT_END_OF_LINE_P (it
))
10469 int used_before
= row
->used
[TEXT_AREA
];
10471 /* Add a space at the end of the line that is used to
10472 display the cursor there. */
10473 append_space (it
, 0);
10475 /* Extend the face to the end of the line. */
10476 extend_face_to_end_of_line (it
);
10478 /* Make sure we have the position. */
10479 if (used_before
== 0)
10480 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
10482 /* Consume the line end. This skips over invisible lines. */
10483 set_iterator_to_next (it
);
10484 it
->continuation_lines_width
= 0;
10488 /* Proceed with next display element. Note that this skips
10489 over lines invisible because of selective display. */
10490 set_iterator_to_next (it
);
10492 /* If we truncate lines, we are done when the last displayed
10493 glyphs reach past the right margin of the window. */
10494 if (it
->truncate_lines_p
10495 && (FRAME_WINDOW_P (it
->f
)
10496 ? (it
->current_x
>= it
->last_visible_x
)
10497 : (it
->current_x
> it
->last_visible_x
)))
10499 /* Maybe add truncation glyphs. */
10500 if (!FRAME_WINDOW_P (it
->f
))
10502 --it
->glyph_row
->used
[TEXT_AREA
];
10503 produce_special_glyphs (it
, IT_TRUNCATION
);
10506 row
->truncated_on_right_p
= 1;
10507 it
->continuation_lines_width
= 0;
10508 reseat_at_next_visible_line_start (it
, 0);
10509 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
10510 it
->hpos
= hpos_before
;
10511 it
->current_x
= x_before
;
10516 /* If line is not empty and hscrolled, maybe insert truncation glyphs
10517 at the left window margin. */
10518 if (it
->first_visible_x
10519 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
10521 if (!FRAME_WINDOW_P (it
->f
))
10522 insert_left_trunc_glyphs (it
);
10523 row
->truncated_on_left_p
= 1;
10526 /* If the start of this line is the overlay arrow-position, then
10527 mark this glyph row as the one containing the overlay arrow.
10528 This is clearly a mess with variable size fonts. It would be
10529 better to let it be displayed like cursors under X. */
10530 if (MARKERP (Voverlay_arrow_position
)
10531 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
10532 && (MATRIX_ROW_START_CHARPOS (row
)
10533 == marker_position (Voverlay_arrow_position
))
10534 && STRINGP (Voverlay_arrow_string
)
10535 && ! overlay_arrow_seen
)
10537 /* Overlay arrow in window redisplay is a bitmap. */
10538 if (!FRAME_WINDOW_P (it
->f
))
10540 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
10541 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
10542 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
10543 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
10544 struct glyph
*p2
, *end
;
10546 /* Copy the arrow glyphs. */
10547 while (glyph
< arrow_end
)
10550 /* Throw away padding glyphs. */
10552 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
10553 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
10559 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
10563 overlay_arrow_seen
= 1;
10564 row
->overlay_arrow_p
= 1;
10567 /* Compute pixel dimensions of this line. */
10568 compute_line_metrics (it
);
10570 /* Remember the position at which this line ends. */
10571 row
->end
= it
->current
;
10573 /* Maybe set the cursor. If you change this, it's probably a good
10574 idea to also change the code in redisplay_window for cursor
10575 movement in an unchanged window. */
10576 if (it
->w
->cursor
.vpos
< 0
10577 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
10578 && MATRIX_ROW_END_CHARPOS (row
) >= PT
10579 && !(MATRIX_ROW_END_CHARPOS (row
) == PT
10580 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
10581 || !row
->ends_at_zv_p
)))
10582 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
10584 /* Highlight trailing whitespace. */
10585 if (it
->show_trailing_whitespace_p
)
10586 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
10588 /* Prepare for the next line. This line starts horizontally at (X
10589 HPOS) = (0 0). Vertical positions are incremented. As a
10590 convenience for the caller, IT->glyph_row is set to the next
10592 it
->current_x
= it
->hpos
= 0;
10593 it
->current_y
+= row
->height
;
10596 return row
->displays_text_p
;
10601 /***********************************************************************
10603 ***********************************************************************/
10605 /* Redisplay the menu bar in the frame for window W.
10607 The menu bar of X frames that don't have X toolkit support is
10608 displayed in a special window W->frame->menu_bar_window.
10610 The menu bar of terminal frames is treated specially as far as
10611 glyph matrices are concerned. Menu bar lines are not part of
10612 windows, so the update is done directly on the frame matrix rows
10613 for the menu bar. */
10616 display_menu_bar (w
)
10619 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10624 /* Don't do all this for graphical frames. */
10626 if (!NILP (Vwindow_system
))
10629 #ifdef USE_X_TOOLKIT
10634 #ifdef USE_X_TOOLKIT
10635 xassert (!FRAME_WINDOW_P (f
));
10636 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MODE_LINE_FACE_ID
);
10637 it
.first_visible_x
= 0;
10638 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
10639 #else /* not USE_X_TOOLKIT */
10640 if (FRAME_WINDOW_P (f
))
10642 /* Menu bar lines are displayed in the desired matrix of the
10643 dummy window menu_bar_window. */
10644 struct window
*menu_w
;
10645 xassert (WINDOWP (f
->menu_bar_window
));
10646 menu_w
= XWINDOW (f
->menu_bar_window
);
10647 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
10648 MODE_LINE_FACE_ID
);
10649 it
.first_visible_x
= 0;
10650 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
10654 /* This is a TTY frame, i.e. character hpos/vpos are used as
10656 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
10657 MODE_LINE_FACE_ID
);
10658 it
.first_visible_x
= 0;
10659 it
.last_visible_x
= FRAME_WIDTH (f
);
10661 #endif /* not USE_X_TOOLKIT */
10663 /* Clear all rows of the menu bar. */
10664 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
10666 struct glyph_row
*row
= it
.glyph_row
+ i
;
10667 clear_glyph_row (row
);
10668 row
->enabled_p
= 1;
10669 row
->full_width_p
= 1;
10672 /* Make the first line of the menu bar appear in reverse video. */
10673 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
10675 /* Display all items of the menu bar. */
10676 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
10677 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
10679 Lisp_Object string
;
10681 /* Stop at nil string. */
10682 string
= XVECTOR (items
)->contents
[i
+ 1];
10686 /* Remember where item was displayed. */
10687 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
10689 /* Display the item, pad with one space. */
10690 if (it
.current_x
< it
.last_visible_x
)
10691 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
10692 XSTRING (string
)->size
+ 1, 0, 0, -1);
10695 /* Fill out the line with spaces. */
10696 if (it
.current_x
< it
.last_visible_x
)
10697 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
10699 /* Compute the total height of the lines. */
10700 compute_line_metrics (&it
);
10705 /***********************************************************************
10707 ***********************************************************************/
10709 /* Display the mode and/or top line of window W. */
10712 display_mode_lines (w
)
10715 /* These will be set while the mode line specs are processed. */
10716 line_number_displayed
= 0;
10717 w
->column_number_displayed
= Qnil
;
10719 if (WINDOW_WANTS_MODELINE_P (w
))
10720 display_mode_line (w
, MODE_LINE_FACE_ID
, current_buffer
->mode_line_format
);
10722 if (WINDOW_WANTS_TOP_LINE_P (w
))
10723 display_mode_line (w
, TOP_LINE_FACE_ID
, current_buffer
->top_line_format
);
10727 /* Display mode or top line of window W. FACE_ID specifies which line
10728 to display; it is either MODE_LINE_FACE_ID or TOP_LINE_FACE_ID.
10729 FORMAT is the mode line format to display. */
10732 display_mode_line (w
, face_id
, format
)
10734 enum face_id face_id
;
10735 Lisp_Object format
;
10740 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
10741 prepare_desired_row (it
.glyph_row
);
10743 /* Temporarily make frame's keyboard the current kboard so that
10744 kboard-local variables in the mode_line_format will get the right
10746 push_frame_kboard (it
.f
);
10747 display_mode_element (&it
, 0, 0, 0, format
);
10748 pop_frame_kboard ();
10750 /* Fill up with spaces. */
10751 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
10753 compute_line_metrics (&it
);
10754 it
.glyph_row
->full_width_p
= 1;
10755 it
.glyph_row
->mode_line_p
= 1;
10756 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
10757 it
.glyph_row
->continued_p
= 0;
10758 it
.glyph_row
->truncated_on_left_p
= 0;
10759 it
.glyph_row
->truncated_on_right_p
= 0;
10761 /* Make a 3D mode-line have a shadow at its right end. */
10762 face
= FACE_FROM_ID (it
.f
, face_id
);
10763 extend_face_to_end_of_line (&it
);
10764 if (face
->box
!= FACE_NO_BOX
)
10766 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
10767 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
10768 last
->right_box_line_p
= 1;
10773 /* Contribute ELT to the mode line for window IT->w. How it
10774 translates into text depends on its data type.
10776 IT describes the display environment in which we display, as usual.
10778 DEPTH is the depth in recursion. It is used to prevent
10779 infinite recursion here.
10781 FIELD_WIDTH is the number of characters the display of ELT should
10782 occupy in the mode line, and PRECISION is the maximum number of
10783 characters to display from ELT's representation. See
10784 display_string for details. *
10786 Returns the hpos of the end of the text generated by ELT. */
10789 display_mode_element (it
, depth
, field_width
, precision
, elt
)
10792 int field_width
, precision
;
10795 int n
= 0, field
, prec
;
10803 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
10807 /* A string: output it and check for %-constructs within it. */
10809 unsigned char *this = XSTRING (elt
)->data
;
10810 unsigned char *lisp_string
= this;
10812 while ((precision
<= 0 || n
< precision
)
10814 && (frame_title_ptr
10815 || it
->current_x
< it
->last_visible_x
))
10817 unsigned char *last
= this;
10819 /* Advance to end of string or next format specifier. */
10820 while ((c
= *this++) != '\0' && c
!= '%')
10823 if (this - 1 != last
)
10825 /* Output to end of string or up to '%'. Field width
10826 is length of string. Don't output more than
10827 PRECISION allows us. */
10828 prec
= --this - last
;
10829 if (precision
> 0 && prec
> precision
- n
)
10830 prec
= precision
- n
;
10832 if (frame_title_ptr
)
10833 n
+= store_frame_title (last
, prec
, prec
);
10835 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
10836 it
, 0, prec
, 0, -1);
10838 else /* c == '%' */
10840 unsigned char *percent_position
= this;
10842 /* Get the specified minimum width. Zero means
10845 while ((c
= *this++) >= '0' && c
<= '9')
10846 field
= field
* 10 + c
- '0';
10848 /* Don't pad beyond the total padding allowed. */
10849 if (field_width
- n
> 0 && field
> field_width
- n
)
10850 field
= field_width
- n
;
10852 /* Note that either PRECISION <= 0 or N < PRECISION. */
10853 prec
= precision
- n
;
10856 n
+= display_mode_element (it
, depth
, field
, prec
,
10857 Vglobal_mode_string
);
10860 unsigned char *spec
10861 = decode_mode_spec (it
->w
, c
, field
, prec
);
10863 if (frame_title_ptr
)
10864 n
+= store_frame_title (spec
, field
, prec
);
10868 = it
->glyph_row
->used
[TEXT_AREA
];
10870 = percent_position
- XSTRING (elt
)->data
;
10872 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
10873 field
, prec
, 0, -1);
10875 /* Assign to the glyphs written above the
10876 string where the `%x' came from, position
10880 struct glyph
*glyph
10881 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
10885 for (i
= 0; i
< nwritten
; ++i
)
10887 glyph
[i
].object
= elt
;
10888 glyph
[i
].charpos
= charpos
;
10901 /* A symbol: process the value of the symbol recursively
10902 as if it appeared here directly. Avoid error if symbol void.
10903 Special case: if value of symbol is a string, output the string
10906 register Lisp_Object tem
;
10907 tem
= Fboundp (elt
);
10910 tem
= Fsymbol_value (elt
);
10911 /* If value is a string, output that string literally:
10912 don't check for % within it. */
10915 prec
= XSTRING (tem
)->size
;
10916 if (precision
> 0 && prec
> precision
- n
)
10917 prec
= precision
- n
;
10918 if (frame_title_ptr
)
10919 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
10921 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
10924 else if (!EQ (tem
, elt
))
10926 /* Give up right away for nil or t. */
10936 register Lisp_Object car
, tem
;
10938 /* A cons cell: three distinct cases.
10939 If first element is a string or a cons, process all the elements
10940 and effectively concatenate them.
10941 If first element is a negative number, truncate displaying cdr to
10942 at most that many characters. If positive, pad (with spaces)
10943 to at least that many characters.
10944 If first element is a symbol, process the cadr or caddr recursively
10945 according to whether the symbol's value is non-nil or nil. */
10946 car
= XCONS (elt
)->car
;
10947 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
10949 /* An element of the form (:eval FORM) means evaluate FORM
10950 and use the result as mode line elements. */
10951 struct gcpro gcpro1
;
10954 spec
= eval_form (XCAR (XCDR (elt
)));
10956 n
+= display_mode_element (it
, depth
, field_width
- n
,
10957 precision
- n
, spec
);
10960 else if (SYMBOLP (car
))
10962 tem
= Fboundp (car
);
10963 elt
= XCONS (elt
)->cdr
;
10966 /* elt is now the cdr, and we know it is a cons cell.
10967 Use its car if CAR has a non-nil value. */
10970 tem
= Fsymbol_value (car
);
10972 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
10974 /* Symbol's value is nil (or symbol is unbound)
10975 Get the cddr of the original list
10976 and if possible find the caddr and use that. */
10977 elt
= XCONS (elt
)->cdr
;
10980 else if (!CONSP (elt
))
10982 elt
= XCONS (elt
)->car
;
10985 else if (INTEGERP (car
))
10987 register int lim
= XINT (car
);
10988 elt
= XCONS (elt
)->cdr
;
10991 /* Negative int means reduce maximum width. */
10992 if (precision
<= 0)
10995 precision
= min (precision
, -lim
);
10999 /* Padding specified. Don't let it be more than
11000 current maximum. */
11002 lim
= min (precision
, lim
);
11004 /* If that's more padding than already wanted, queue it.
11005 But don't reduce padding already specified even if
11006 that is beyond the current truncation point. */
11007 field_width
= max (lim
, field_width
);
11011 else if (STRINGP (car
) || CONSP (car
))
11013 register int limit
= 50;
11014 /* Limit is to protect against circular lists. */
11017 && (precision
<= 0 || n
< precision
))
11019 n
+= display_mode_element (it
, depth
, field_width
- n
,
11020 precision
- n
, XCONS (elt
)->car
);
11021 elt
= XCONS (elt
)->cdr
;
11029 if (frame_title_ptr
)
11030 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
11032 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
11033 precision
- n
, 0, 0);
11037 /* Pad to FIELD_WIDTH. */
11038 if (field_width
> 0 && n
< field_width
)
11040 if (frame_title_ptr
)
11041 n
+= store_frame_title ("", field_width
- n
, 0);
11043 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
11051 /* Write a null-terminated, right justified decimal representation of
11052 the positive integer D to BUF using a minimal field width WIDTH. */
11055 pint2str (buf
, width
, d
)
11056 register char *buf
;
11057 register int width
;
11060 register char *p
= buf
;
11068 *p
++ = d
% 10 + '0';
11073 for (width
-= (int) (p
- buf
); width
> 0; --width
)
11084 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
11085 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
11086 type of CODING_SYSTEM. Return updated pointer into BUF. */
11088 static unsigned char invalid_eol_type
[] = "(*invalid*)";
11091 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
11092 Lisp_Object coding_system
;
11093 register char *buf
;
11097 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
11098 unsigned char *eol_str
;
11100 /* The EOL conversion we are using. */
11101 Lisp_Object eoltype
;
11103 val
= coding_system
;
11105 if (NILP (val
)) /* Not yet decided. */
11110 eoltype
= eol_mnemonic_undecided
;
11111 /* Don't mention EOL conversion if it isn't decided. */
11115 Lisp_Object eolvalue
;
11117 eolvalue
= Fget (coding_system
, Qeol_type
);
11119 while (!NILP (val
) && SYMBOLP (val
))
11121 val
= Fget (val
, Qcoding_system
);
11122 if (NILP (eolvalue
))
11123 eolvalue
= Fget (val
, Qeol_type
);
11127 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
11131 /* The EOL conversion that is normal on this system. */
11133 if (NILP (eolvalue
)) /* Not yet decided. */
11134 eoltype
= eol_mnemonic_undecided
;
11135 else if (VECTORP (eolvalue
)) /* Not yet decided. */
11136 eoltype
= eol_mnemonic_undecided
;
11137 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
11138 eoltype
= (XFASTINT (eolvalue
) == 0
11139 ? eol_mnemonic_unix
11140 : (XFASTINT (eolvalue
) == 1
11141 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
11147 /* Mention the EOL conversion if it is not the usual one. */
11148 if (STRINGP (eoltype
))
11150 eol_str
= XSTRING (eoltype
)->data
;
11151 eol_str_len
= XSTRING (eoltype
)->size
;
11153 else if (INTEGERP (eoltype
)
11154 && CHAR_VALID_P (XINT (eoltype
), 0))
11156 int c
= XINT (eoltype
);
11157 unsigned char work
[4];
11159 eol_str_len
= CHAR_STRING (XINT (eoltype
), work
, eol_str
);
11163 eol_str
= invalid_eol_type
;
11164 eol_str_len
= sizeof (invalid_eol_type
) - 1;
11166 bcopy (eol_str
, buf
, eol_str_len
);
11167 buf
+= eol_str_len
;
11173 /* Return a string for the output of a mode line %-spec for window W,
11174 generated by character C. PRECISION >= 0 means don't return a
11175 string longer than that value. FIELD_WIDTH > 0 means pad the
11176 string returned with spaces to that value. */
11178 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
11181 decode_mode_spec (w
, c
, field_width
, precision
)
11184 int field_width
, precision
;
11187 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11188 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
11189 struct buffer
*b
= XBUFFER (w
->buffer
);
11196 if (!NILP (b
->read_only
))
11198 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
11203 /* This differs from %* only for a modified read-only buffer. */
11204 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
11206 if (!NILP (b
->read_only
))
11211 /* This differs from %* in ignoring read-only-ness. */
11212 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
11224 if (command_loop_level
> 5)
11226 p
= decode_mode_spec_buf
;
11227 for (i
= 0; i
< command_loop_level
; i
++)
11230 return decode_mode_spec_buf
;
11238 if (command_loop_level
> 5)
11240 p
= decode_mode_spec_buf
;
11241 for (i
= 0; i
< command_loop_level
; i
++)
11244 return decode_mode_spec_buf
;
11251 /* Let lots_of_dashes be a string of infinite length. */
11252 if (field_width
<= 0
11253 || field_width
> sizeof (lots_of_dashes
))
11255 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
11256 decode_mode_spec_buf
[i
] = '-';
11257 decode_mode_spec_buf
[i
] = '\0';
11258 return decode_mode_spec_buf
;
11261 return lots_of_dashes
;
11270 int col
= current_column ();
11271 XSETFASTINT (w
->column_number_displayed
, col
);
11272 pint2str (decode_mode_spec_buf
, field_width
, col
);
11273 return decode_mode_spec_buf
;
11277 /* %F displays the frame name. */
11278 if (!NILP (f
->title
))
11279 return (char *) XSTRING (f
->title
)->data
;
11280 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
11281 return (char *) XSTRING (f
->name
)->data
;
11290 int startpos
= XMARKER (w
->start
)->charpos
;
11291 int startpos_byte
= marker_byte_position (w
->start
);
11292 int line
, linepos
, linepos_byte
, topline
;
11294 int height
= XFASTINT (w
->height
);
11296 /* If we decided that this buffer isn't suitable for line numbers,
11297 don't forget that too fast. */
11298 if (EQ (w
->base_line_pos
, w
->buffer
))
11300 /* But do forget it, if the window shows a different buffer now. */
11301 else if (BUFFERP (w
->base_line_pos
))
11302 w
->base_line_pos
= Qnil
;
11304 /* If the buffer is very big, don't waste time. */
11305 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
11307 w
->base_line_pos
= Qnil
;
11308 w
->base_line_number
= Qnil
;
11312 if (!NILP (w
->base_line_number
)
11313 && !NILP (w
->base_line_pos
)
11314 && XFASTINT (w
->base_line_pos
) <= startpos
)
11316 line
= XFASTINT (w
->base_line_number
);
11317 linepos
= XFASTINT (w
->base_line_pos
);
11318 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
11323 linepos
= BUF_BEGV (b
);
11324 linepos_byte
= BUF_BEGV_BYTE (b
);
11327 /* Count lines from base line to window start position. */
11328 nlines
= display_count_lines (linepos
, linepos_byte
,
11332 topline
= nlines
+ line
;
11334 /* Determine a new base line, if the old one is too close
11335 or too far away, or if we did not have one.
11336 "Too close" means it's plausible a scroll-down would
11337 go back past it. */
11338 if (startpos
== BUF_BEGV (b
))
11340 XSETFASTINT (w
->base_line_number
, topline
);
11341 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
11343 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
11344 || linepos
== BUF_BEGV (b
))
11346 int limit
= BUF_BEGV (b
);
11347 int limit_byte
= BUF_BEGV_BYTE (b
);
11349 int distance
= (height
* 2 + 30) * 200;
11351 if (startpos
- distance
> limit
)
11353 limit
= startpos
- distance
;
11354 limit_byte
= CHAR_TO_BYTE (limit
);
11357 nlines
= display_count_lines (startpos
, startpos_byte
,
11359 - (height
* 2 + 30),
11361 /* If we couldn't find the lines we wanted within
11362 200 chars per line,
11363 give up on line numbers for this window. */
11364 if (position
== limit_byte
&& limit
== startpos
- distance
)
11366 w
->base_line_pos
= w
->buffer
;
11367 w
->base_line_number
= Qnil
;
11371 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
11372 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
11375 /* Now count lines from the start pos to point. */
11376 nlines
= display_count_lines (startpos
, startpos_byte
,
11377 PT_BYTE
, PT
, &junk
);
11379 /* Record that we did display the line number. */
11380 line_number_displayed
= 1;
11382 /* Make the string to show. */
11383 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
11384 return decode_mode_spec_buf
;
11387 char* p
= decode_mode_spec_buf
;
11388 int pad
= field_width
- 2;
11393 return decode_mode_spec_buf
;
11399 obj
= b
->mode_name
;
11403 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
11409 int pos
= marker_position (w
->start
);
11410 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
11412 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
11414 if (pos
<= BUF_BEGV (b
))
11419 else if (pos
<= BUF_BEGV (b
))
11423 if (total
> 1000000)
11424 /* Do it differently for a large value, to avoid overflow. */
11425 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
11427 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
11428 /* We can't normally display a 3-digit number,
11429 so get us a 2-digit number that is close. */
11432 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
11433 return decode_mode_spec_buf
;
11437 /* Display percentage of size above the bottom of the screen. */
11440 int toppos
= marker_position (w
->start
);
11441 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
11442 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
11444 if (botpos
>= BUF_ZV (b
))
11446 if (toppos
<= BUF_BEGV (b
))
11453 if (total
> 1000000)
11454 /* Do it differently for a large value, to avoid overflow. */
11455 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
11457 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
11458 /* We can't normally display a 3-digit number,
11459 so get us a 2-digit number that is close. */
11462 if (toppos
<= BUF_BEGV (b
))
11463 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
11465 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
11466 return decode_mode_spec_buf
;
11471 /* status of process */
11472 obj
= Fget_buffer_process (w
->buffer
);
11474 return "no process";
11475 #ifdef subprocesses
11476 obj
= Fsymbol_name (Fprocess_status (obj
));
11480 case 't': /* indicate TEXT or BINARY */
11481 #ifdef MODE_LINE_BINARY_TEXT
11482 return MODE_LINE_BINARY_TEXT (b
);
11488 /* coding-system (not including end-of-line format) */
11490 /* coding-system (including end-of-line type) */
11492 int eol_flag
= (c
== 'Z');
11493 char *p
= decode_mode_spec_buf
;
11495 if (! FRAME_WINDOW_P (f
))
11497 /* No need to mention EOL here--the terminal never needs
11498 to do EOL conversion. */
11499 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
11500 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
11502 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
11505 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
11506 #ifdef subprocesses
11507 obj
= Fget_buffer_process (Fcurrent_buffer ());
11508 if (PROCESSP (obj
))
11510 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
11512 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
11515 #endif /* subprocesses */
11518 return decode_mode_spec_buf
;
11523 return (char *) XSTRING (obj
)->data
;
11529 /* Count up to COUNT lines starting from START / START_BYTE.
11530 But don't go beyond LIMIT_BYTE.
11531 Return the number of lines thus found (always nonnegative).
11533 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
11536 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
11537 int start
, start_byte
, limit_byte
, count
;
11540 register unsigned char *cursor
;
11541 unsigned char *base
;
11543 register int ceiling
;
11544 register unsigned char *ceiling_addr
;
11545 int orig_count
= count
;
11547 /* If we are not in selective display mode,
11548 check only for newlines. */
11549 int selective_display
= (!NILP (current_buffer
->selective_display
)
11550 && !INTEGERP (current_buffer
->selective_display
));
11554 while (start_byte
< limit_byte
)
11556 ceiling
= BUFFER_CEILING_OF (start_byte
);
11557 ceiling
= min (limit_byte
- 1, ceiling
);
11558 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
11559 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
11562 if (selective_display
)
11563 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
11566 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
11569 if (cursor
!= ceiling_addr
)
11573 start_byte
+= cursor
- base
+ 1;
11574 *byte_pos_ptr
= start_byte
;
11578 if (++cursor
== ceiling_addr
)
11584 start_byte
+= cursor
- base
;
11589 while (start_byte
> limit_byte
)
11591 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
11592 ceiling
= max (limit_byte
, ceiling
);
11593 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
11594 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
11597 if (selective_display
)
11598 while (--cursor
!= ceiling_addr
11599 && *cursor
!= '\n' && *cursor
!= 015)
11602 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
11605 if (cursor
!= ceiling_addr
)
11609 start_byte
+= cursor
- base
+ 1;
11610 *byte_pos_ptr
= start_byte
;
11611 /* When scanning backwards, we should
11612 not count the newline posterior to which we stop. */
11613 return - orig_count
- 1;
11619 /* Here we add 1 to compensate for the last decrement
11620 of CURSOR, which took it past the valid range. */
11621 start_byte
+= cursor
- base
+ 1;
11625 *byte_pos_ptr
= limit_byte
;
11628 return - orig_count
+ count
;
11629 return orig_count
- count
;
11635 /***********************************************************************
11637 ***********************************************************************/
11639 /* Display a NUL-terminated string, starting with index START.
11641 If STRING is non-null, display that C string. Otherwise, the Lisp
11642 string LISP_STRING is displayed.
11644 If FACE_STRING is not nil, FACE_STRING_POS is a position in
11645 FACE_STRING. Display STRING or LISP_STRING with the face at
11646 FACE_STRING_POS in FACE_STRING:
11648 Display the string in the environment given by IT, but use the
11649 standard display table, temporarily.
11651 FIELD_WIDTH is the minimum number of output glyphs to produce.
11652 If STRING has fewer characters than FIELD_WIDTH, pad to the right
11653 with spaces. If STRING has more characters, more than FIELD_WIDTH
11654 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
11656 PRECISION is the maximum number of characters to output from
11657 STRING. PRECISION < 0 means don't truncate the string.
11659 This is roughly equivalent to printf format specifiers:
11661 FIELD_WIDTH PRECISION PRINTF
11662 ----------------------------------------
11668 MULTIBYTE zero means do not display multibyte chars, > 0 means do
11669 display them, and < 0 means obey the current buffer's value of
11670 enable_multibyte_characters.
11672 Value is the number of glyphs produced. */
11675 display_string (string
, lisp_string
, face_string
, face_string_pos
,
11676 start
, it
, field_width
, precision
, max_x
, multibyte
)
11677 unsigned char *string
;
11678 Lisp_Object lisp_string
;
11681 int field_width
, precision
, max_x
;
11684 int hpos_at_start
= it
->hpos
;
11685 int saved_face_id
= it
->face_id
;
11686 struct glyph_row
*row
= it
->glyph_row
;
11688 /* Initialize the iterator IT for iteration over STRING beginning
11689 with index START. We assume that IT may be modified here (which
11690 means that display_line has to do something when displaying a
11691 mini-buffer prompt, which it does). */
11692 reseat_to_string (it
, string
, lisp_string
, start
,
11693 precision
, field_width
, multibyte
);
11695 /* If displaying STRING, set up the face of the iterator
11696 from LISP_STRING, if that's given. */
11697 if (STRINGP (face_string
))
11703 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
11704 0, it
->region_beg_charpos
,
11705 it
->region_end_charpos
,
11706 &endptr
, it
->base_face_id
);
11707 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11708 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
11711 /* Set max_x to the maximum allowed X position. Don't let it go
11712 beyond the right edge of the window. */
11714 max_x
= it
->last_visible_x
;
11716 max_x
= min (max_x
, it
->last_visible_x
);
11718 /* Skip over display elements that are not visible. because IT->w is
11720 if (it
->current_x
< it
->first_visible_x
)
11721 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
11722 MOVE_TO_POS
| MOVE_TO_X
);
11724 row
->ascent
= it
->max_ascent
;
11725 row
->height
= it
->max_ascent
+ it
->max_descent
;
11726 row
->phys_ascent
= it
->max_phys_ascent
;
11727 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11729 /* This condition is for the case that we are called with current_x
11730 past last_visible_x. */
11731 while (it
->current_x
< max_x
)
11733 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
11735 /* Get the next display element. */
11736 if (!get_next_display_element (it
))
11739 /* Produce glyphs. */
11740 x_before
= it
->current_x
;
11741 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
11742 PRODUCE_GLYPHS (it
);
11744 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
11747 while (i
< nglyphs
)
11749 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11751 if (!it
->truncate_lines_p
11752 && x
+ glyph
->pixel_width
> max_x
)
11754 /* End of continued line or max_x reached. */
11755 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11759 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
11761 /* Glyph is at least partially visible. */
11763 if (x
< it
->first_visible_x
)
11764 it
->glyph_row
->x
= x
- it
->first_visible_x
;
11768 /* Glyph is off the left margin of the display area.
11769 Should not happen. */
11773 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11774 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11775 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11776 row
->phys_height
= max (row
->phys_height
,
11777 it
->max_phys_ascent
+ it
->max_phys_descent
);
11778 x
+= glyph
->pixel_width
;
11782 /* Stop if max_x reached. */
11786 /* Stop at line ends. */
11787 if (ITERATOR_AT_END_OF_LINE_P (it
))
11789 it
->continuation_lines_width
= 0;
11793 set_iterator_to_next (it
);
11795 /* Stop if truncating at the right edge. */
11796 if (it
->truncate_lines_p
11797 && it
->current_x
>= it
->last_visible_x
)
11799 /* Add truncation mark, but don't do it if the line is
11800 truncated at a padding space. */
11801 if (IT_CHARPOS (*it
) < it
->string_nchars
)
11803 if (!FRAME_WINDOW_P (it
->f
))
11804 produce_special_glyphs (it
, IT_TRUNCATION
);
11805 it
->glyph_row
->truncated_on_right_p
= 1;
11811 /* Maybe insert a truncation at the left. */
11812 if (it
->first_visible_x
11813 && IT_CHARPOS (*it
) > 0)
11815 if (!FRAME_WINDOW_P (it
->f
))
11816 insert_left_trunc_glyphs (it
);
11817 it
->glyph_row
->truncated_on_left_p
= 1;
11820 it
->face_id
= saved_face_id
;
11822 /* Value is number of columns displayed. */
11823 return it
->hpos
- hpos_at_start
;
11828 /* This is like a combination of memq and assq. Return 1 if PROPVAL
11829 appears as an element of LIST or as the car of an element of LIST.
11830 If PROPVAL is a list, compare each element against LIST in that
11831 way, and return 1 if any element of PROPVAL is found in LIST.
11832 Otherwise return 0. This function cannot quit. */
11835 invisible_p (propval
, list
)
11836 register Lisp_Object propval
;
11839 register Lisp_Object tail
, proptail
;
11840 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
11842 register Lisp_Object tem
;
11843 tem
= XCONS (tail
)->car
;
11844 if (EQ (propval
, tem
))
11846 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
11849 if (CONSP (propval
))
11850 for (proptail
= propval
; CONSP (proptail
);
11851 proptail
= XCONS (proptail
)->cdr
)
11853 Lisp_Object propelt
;
11854 propelt
= XCONS (proptail
)->car
;
11855 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
11857 register Lisp_Object tem
;
11858 tem
= XCONS (tail
)->car
;
11859 if (EQ (propelt
, tem
))
11861 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
11869 /* Return 1 if PROPVAL appears as the car of an element of LIST and
11870 the cdr of that element is non-nil. If PROPVAL is a list, check
11871 each element of PROPVAL in that way, and the first time some
11872 element is found, return 1 if the cdr of that element is non-nil.
11873 Otherwise return 0. This function cannot quit. */
11876 invisible_ellipsis_p (propval
, list
)
11877 register Lisp_Object propval
;
11880 register Lisp_Object tail
, proptail
;
11881 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
11883 register Lisp_Object tem
;
11884 tem
= XCONS (tail
)->car
;
11885 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
11886 return ! NILP (XCONS (tem
)->cdr
);
11888 if (CONSP (propval
))
11889 for (proptail
= propval
; CONSP (proptail
);
11890 proptail
= XCONS (proptail
)->cdr
)
11892 Lisp_Object propelt
;
11893 propelt
= XCONS (proptail
)->car
;
11894 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
11896 register Lisp_Object tem
;
11897 tem
= XCONS (tail
)->car
;
11898 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
11899 return ! NILP (XCONS (tem
)->cdr
);
11907 /***********************************************************************
11909 ***********************************************************************/
11914 echo_area_message
= previous_echo_area_message
= Qnil
;
11915 staticpro (&echo_area_message
);
11916 staticpro (&previous_echo_area_message
);
11918 staticpro (&Qinhibit_redisplay
);
11919 Qinhibit_redisplay
= intern ("inhibit-redisplay");
11922 defsubr (&Sdump_glyph_matrix
);
11923 defsubr (&Sdump_glyph_row
);
11924 defsubr (&Sdump_toolbar_row
);
11925 defsubr (&Strace_redisplay_toggle
);
11928 staticpro (&Qmenu_bar_update_hook
);
11929 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
11931 staticpro (&Qoverriding_terminal_local_map
);
11932 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
11934 staticpro (&Qoverriding_local_map
);
11935 Qoverriding_local_map
= intern ("overriding-local-map");
11937 staticpro (&Qwindow_scroll_functions
);
11938 Qwindow_scroll_functions
= intern ("window-scroll-functions");
11940 staticpro (&Qredisplay_end_trigger_functions
);
11941 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
11943 staticpro (&Qinhibit_point_motion_hooks
);
11944 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
11946 staticpro (&Qdisplay
);
11947 Qdisplay
= intern ("display");
11948 staticpro (&Qleft_margin
);
11949 Qspace_width
= intern ("space-width");
11950 staticpro (&Qspace_width
);
11951 Qheight
= intern ("height");
11952 staticpro (&Qheight
);
11953 Qraise
= intern ("raise");
11954 staticpro (&Qraise
);
11955 Qspace
= intern ("space");
11956 staticpro (&Qspace
);
11957 Qleft_margin
= intern ("left-margin");
11958 staticpro (&Qright_margin
);
11959 Qright_margin
= intern ("right-margin");
11960 Qalign_to
= intern ("align-to");
11961 staticpro (&Qalign_to
);
11962 QCalign_to
= intern (":align-to");
11963 staticpro (&QCalign_to
);
11964 Qwidth
= intern ("width");
11965 staticpro (&Qwidth
);
11966 Qrelative_width
= intern ("relative-width");
11967 staticpro (&Qrelative_width
);
11968 QCrelative_width
= intern (":relative-width");
11969 staticpro (&QCrelative_width
);
11970 QCrelative_height
= intern (":relative-height");
11971 staticpro (&QCrelative_height
);
11972 QCeval
= intern (":eval");
11973 staticpro (&QCeval
);
11974 QCwhen
= intern (":when");
11975 staticpro (&QCwhen
);
11976 Qfontified
= intern ("fontified");
11977 staticpro (&Qfontified
);
11978 Qfontification_functions
= intern ("fontification-functions");
11979 staticpro (&Qfontification_functions
);
11980 Qshow_trailing_whitespace
= intern ("show-trailing-whitespace");
11981 staticpro (&Qshow_trailing_whitespace
);
11982 Qtrailing_whitespace
= intern ("trailing-whitespace");
11983 staticpro (&Qtrailing_whitespace
);
11984 Qimage
= intern ("image");
11985 staticpro (&Qimage
);
11987 staticpro (&last_arrow_position
);
11988 staticpro (&last_arrow_string
);
11989 last_arrow_position
= Qnil
;
11990 last_arrow_string
= Qnil
;
11992 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
11993 "Non-nil means don't actually do any redisplay.\n\
11994 This is used for internal purposes.");
11995 Vinhibit_redisplay
= Qnil
;
11997 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
11998 "String (or mode line construct) included (normally) in `mode-line-format'.");
11999 Vglobal_mode_string
= Qnil
;
12001 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
12002 "Marker for where to display an arrow on top of the buffer text.\n\
12003 This must be the beginning of a line in order to work.\n\
12004 See also `overlay-arrow-string'.");
12005 Voverlay_arrow_position
= Qnil
;
12007 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
12008 "String to display as an arrow. See also `overlay-arrow-position'.");
12009 Voverlay_arrow_string
= Qnil
;
12011 DEFVAR_INT ("scroll-step", &scroll_step
,
12012 "*The number of lines to try scrolling a window by when point moves out.\n\
12013 If that fails to bring point back on frame, point is centered instead.\n\
12014 If this is zero, point is always centered after it moves off frame.");
12016 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
12017 "*Scroll up to this many lines, to bring point back on screen.");
12018 scroll_conservatively
= 0;
12020 DEFVAR_INT ("scroll-margin", &scroll_margin
,
12021 "*Number of lines of margin at the top and bottom of a window.\n\
12022 Recenter the window whenever point gets within this many lines\n\
12023 of the top or bottom of the window.");
12027 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
12030 DEFVAR_BOOL ("truncate-partial-width-windows",
12031 &truncate_partial_width_windows
,
12032 "*Non-nil means truncate lines in all windows less than full frame wide.");
12033 truncate_partial_width_windows
= 1;
12035 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
12036 "*Non-nil means use inverse video for the mode line.");
12037 mode_line_inverse_video
= 1;
12039 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
12040 "*Maximum buffer size for which line number should be displayed.\n\
12041 If the buffer is bigger than this, the line number does not appear\n\
12042 in the mode line.");
12043 line_number_display_limit
= 1000000;
12045 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
12046 "*Non-nil means highlight region even in nonselected windows.");
12047 highlight_nonselected_windows
= 0;
12049 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
12050 "Non-nil if more than one frame is visible on this display.\n\
12051 Minibuffer-only frames don't count, but iconified frames do.\n\
12052 This variable is not guaranteed to be accurate except while processing\n\
12053 `frame-title-format' and `icon-title-format'.");
12055 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
12056 "Template for displaying the title bar of visible frames.\n\
12057 \(Assuming the window manager supports this feature.)\n\
12058 This variable has the same structure as `mode-line-format' (which see),\n\
12059 and is used only on frames for which no explicit name has been set\n\
12060 \(see `modify-frame-parameters').");
12061 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
12062 "Template for displaying the title bar of an iconified frame.\n\
12063 \(Assuming the window manager supports this feature.)\n\
12064 This variable has the same structure as `mode-line-format' (which see),\n\
12065 and is used only on frames for which no explicit name has been set\n\
12066 \(see `modify-frame-parameters').");
12068 = Vframe_title_format
12069 = Fcons (intern ("multiple-frames"),
12070 Fcons (build_string ("%b"),
12071 Fcons (Fcons (build_string (""),
12072 Fcons (intern ("invocation-name"),
12073 Fcons (build_string ("@"),
12074 Fcons (intern ("system-name"),
12078 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
12079 "Maximum number of lines to keep in the message log buffer.\n\
12080 If nil, disable message logging. If t, log messages but don't truncate\n\
12081 the buffer when it becomes large.");
12082 XSETFASTINT (Vmessage_log_max
, 50);
12084 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
12085 "Functions called before redisplay, if window sizes have changed.\n\
12086 The value should be a list of functions that take one argument.\n\
12087 Just before redisplay, for each frame, if any of its windows have changed\n\
12088 size since the last redisplay, or have been split or deleted,\n\
12089 all the functions in the list are called, with the frame as argument.");
12090 Vwindow_size_change_functions
= Qnil
;
12092 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
12093 "List of Functions to call before redisplaying a window with scrolling.\n\
12094 Each function is called with two arguments, the window\n\
12095 and its new display-start position. Note that the value of `window-end'\n\
12096 is not valid when these functions are called.");
12097 Vwindow_scroll_functions
= Qnil
;
12099 DEFVAR_BOOL ("auto-resize-toolbars", &auto_resize_toolbars_p
,
12100 "*Non-nil means automatically resize toolbars.\n\
12101 This increases a toolbar's height if not all toolbar items are visible.\n\
12102 It decreases a toolbar's height when it would display blank lines\n\
12104 auto_resize_toolbars_p
= 1;
12106 DEFVAR_BOOL ("auto-raise-toolbar-buttons", &auto_raise_toolbar_buttons_p
,
12107 "*Non-nil means raise toolbar buttons when the mouse moves over them.");
12108 auto_raise_toolbar_buttons_p
= 1;
12110 DEFVAR_INT ("toolbar-button-margin", &toolbar_button_margin
,
12111 "*Margin around toolbar buttons in pixels.");
12112 toolbar_button_margin
= 1;
12114 DEFVAR_INT ("toolbar-button-relief", &toolbar_button_relief
,
12115 "Relief thickness of toolbar buttons.");
12116 toolbar_button_relief
= 3;
12118 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
12119 "List of functions to call to fontify regions of text.\n\
12120 Each function is called with one argument POS. Functions must\n\
12121 fontify a region starting at POS in the current buffer, and give\n\
12122 fontified regions the property `fontified'.\n\
12123 This variable automatically becomes buffer-local when set.");
12124 Vfontification_functions
= Qnil
;
12125 Fmake_local_variable (Qfontification_functions
);
12127 DEFVAR_BOOL ("unibyte-display-via-language-environment",
12128 &unibyte_display_via_language_environment
,
12129 "*Non-nil means display unibyte text according to language environment.\n\
12130 Specifically this means that unibyte non-ASCII characters\n\
12131 are displayed by converting them to the equivalent multibyte characters\n\
12132 according to the current language environment. As a result, they are\n\
12133 displayed according to the current fontset.");
12134 unibyte_display_via_language_environment
= 0;
12138 /* Initialize this module when Emacs starts. */
12143 Lisp_Object root_window
;
12144 struct window
*mini_w
;
12146 CHARPOS (this_line_start_pos
) = 0;
12148 mini_w
= XWINDOW (minibuf_window
);
12149 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
12151 echo_area_glyphs
= 0;
12152 previous_echo_glyphs
= 0;
12153 echo_area_message
= previous_echo_area_message
= Qnil
;
12155 if (!noninteractive
)
12157 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
12160 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
12161 set_window_height (root_window
,
12162 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
12164 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
12165 set_window_height (minibuf_window
, 1, 0);
12167 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
12168 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
12170 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
12171 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
12172 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
12174 /* The default ellipsis glyphs `...'. */
12175 for (i
= 0; i
< 3; ++i
)
12176 XSETFASTINT (default_invis_vector
[i
], '.');
12179 #ifdef HAVE_WINDOW_SYSTEM
12181 /* Allocate the buffer for frame titles. */
12183 frame_title_buf
= (char *) xmalloc (size
);
12184 frame_title_buf_end
= frame_title_buf
+ size
;
12185 frame_title_ptr
= NULL
;
12187 #endif /* HAVE_WINDOW_SYSTEM */