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 int next_element_from_display_vector
P_ ((struct it
*));
647 static int next_element_from_string
P_ ((struct it
*));
648 static int next_element_from_c_string
P_ ((struct it
*));
649 static int next_element_from_buffer
P_ ((struct it
*));
650 static int next_element_from_image
P_ ((struct it
*));
651 static int next_element_from_stretch
P_ ((struct it
*));
652 static void load_overlay_strings
P_ ((struct it
*));
653 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
654 struct display_pos
*));
655 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
656 Lisp_Object
, int, int, int, int));
657 static int charset_at_position
P_ ((struct text_pos
));
658 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
660 void move_it_vertically_backward
P_ ((struct it
*, int));
661 static void init_to_row_start
P_ ((struct it
*, struct window
*,
662 struct glyph_row
*));
663 static void init_to_row_end
P_ ((struct it
*, struct window
*,
664 struct glyph_row
*));
665 static void back_to_previous_line_start
P_ ((struct it
*));
666 static void forward_to_next_line_start
P_ ((struct it
*));
667 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
669 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
670 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
671 static int number_of_chars
P_ ((unsigned char *, int));
672 static void compute_stop_pos
P_ ((struct it
*));
673 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
675 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
676 static int next_overlay_change
P_ ((int));
677 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
678 Lisp_Object
, struct text_pos
*));
680 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
681 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
683 #ifdef HAVE_WINDOW_SYSTEM
685 static void update_toolbar
P_ ((struct frame
*, int));
686 static void build_desired_toolbar_string
P_ ((struct frame
*f
));
687 static int redisplay_toolbar
P_ ((struct frame
*));
688 static void display_toolbar_line
P_ ((struct it
*));
690 #endif /* HAVE_WINDOW_SYSTEM */
693 /***********************************************************************
694 Window display dimensions
695 ***********************************************************************/
697 /* Return the window-relative maximum y + 1 for glyph rows displaying
698 text in window W. This is the height of W minus the height of a
699 mode line, if any. */
702 window_text_bottom_y (w
)
705 struct frame
*f
= XFRAME (w
->frame
);
706 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
708 if (WINDOW_WANTS_MODELINE_P (w
))
709 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
714 /* Return the pixel width of display area AREA of window W. AREA < 0
715 means return the total width of W, not including bitmap areas to
716 the left and right of the window. */
719 window_box_width (w
, area
)
723 struct frame
*f
= XFRAME (w
->frame
);
724 int width
= XFASTINT (w
->width
);
726 if (!w
->pseudo_window_p
)
728 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + 2 * FRAME_FLAGS_AREA_COLS (f
);
730 if (area
== TEXT_AREA
)
732 if (INTEGERP (w
->left_margin_width
))
733 width
-= XFASTINT (w
->left_margin_width
);
734 if (INTEGERP (w
->right_margin_width
))
735 width
-= XFASTINT (w
->right_margin_width
);
737 else if (area
== LEFT_MARGIN_AREA
)
738 width
= (INTEGERP (w
->left_margin_width
)
739 ? XFASTINT (w
->left_margin_width
) : 0);
740 else if (area
== RIGHT_MARGIN_AREA
)
741 width
= (INTEGERP (w
->right_margin_width
)
742 ? XFASTINT (w
->right_margin_width
) : 0);
745 return width
* CANON_X_UNIT (f
);
749 /* Return the pixel height of the display area of window W, not
750 including mode lines of W, if any.. */
753 window_box_height (w
)
756 struct frame
*f
= XFRAME (w
->frame
);
757 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
759 if (WINDOW_WANTS_MODELINE_P (w
))
760 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
762 if (WINDOW_WANTS_TOP_LINE_P (w
))
763 height
-= CURRENT_TOP_LINE_HEIGHT (w
);
769 /* Return the frame-relative coordinate of the left edge of display
770 area AREA of window W. AREA < 0 means return the left edge of the
771 whole window, to the right of any bitmap area at the left side of
775 window_box_left (w
, area
)
779 struct frame
*f
= XFRAME (w
->frame
);
780 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
782 if (!w
->pseudo_window_p
)
784 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
785 + FRAME_FLAGS_AREA_WIDTH (f
));
787 if (area
== TEXT_AREA
)
788 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
789 else if (area
== RIGHT_MARGIN_AREA
)
790 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
791 + window_box_width (w
, TEXT_AREA
));
798 /* Return the frame-relative coordinate of the right edge of display
799 area AREA of window W. AREA < 0 means return the left edge of the
800 whole window, to the left of any bitmap area at the right side of
804 window_box_right (w
, area
)
808 return window_box_left (w
, area
) + window_box_width (w
, area
);
812 /* Get the bounding box of the display area AREA of window W, without
813 mode lines, in frame-relative coordinates. AREA < 0 means the
814 whole window, not including bitmap areas to the left and right of
815 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
816 coordinates of the upper-left corner of the box. Return in
817 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
820 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
823 int *box_x
, *box_y
, *box_width
, *box_height
;
825 struct frame
*f
= XFRAME (w
->frame
);
827 *box_width
= window_box_width (w
, area
);
828 *box_height
= window_box_height (w
);
829 *box_x
= window_box_left (w
, area
);
830 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
831 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
832 if (WINDOW_WANTS_TOP_LINE_P (w
))
833 *box_y
+= CURRENT_TOP_LINE_HEIGHT (w
);
837 /* Get the bounding box of the display area AREA of window W, without
838 mode lines. AREA < 0 means the whole window, not including bitmap
839 areas to the left and right of the window. Return in *TOP_LEFT_X
840 and TOP_LEFT_Y the frame-relative pixel coordinates of the
841 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
842 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
846 window_box_edges (w
, area
, top_left_x
, top_left_y
,
847 bottom_right_x
, bottom_right_y
)
850 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
852 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
854 *bottom_right_x
+= *top_left_x
;
855 *bottom_right_y
+= *top_left_y
;
860 /***********************************************************************
862 ***********************************************************************/
864 /* Return the next character from STR which is MAXLEN bytes long.
865 Return in *LEN the length of the character. This is like
866 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
867 we find one, we return a `?', but with the length of the illegal
871 string_char_and_length (str
, maxlen
, len
)
877 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
878 if (!CHAR_VALID_P (c
, 1))
879 /* We may not change the length here because other places in Emacs
880 don't use this function, i.e. they silently accept illegal
889 /* Given a position POS containing a valid character and byte position
890 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
892 static struct text_pos
893 string_pos_nchars_ahead (pos
, string
, nchars
)
898 xassert (STRINGP (string
) && nchars
>= 0);
900 if (STRING_MULTIBYTE (string
))
902 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
903 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
908 string_char_and_length (p
, rest
, &len
);
909 p
+= len
, rest
-= len
;
912 BYTEPOS (pos
) += len
;
916 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
922 /* Value is the text position, i.e. character and byte position,
923 for character position CHARPOS in STRING. */
925 static INLINE
struct text_pos
926 string_pos (charpos
, string
)
931 xassert (STRINGP (string
));
932 xassert (charpos
>= 0);
933 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
938 /* Value is a text position, i.e. character and byte position, for
939 character position CHARPOS in C string S. MULTIBYTE_P non-zero
940 means recognize multibyte characters. */
942 static struct text_pos
943 c_string_pos (charpos
, s
, multibyte_p
)
951 xassert (charpos
>= 0);
955 int rest
= strlen (s
), len
;
957 SET_TEXT_POS (pos
, 0, 0);
960 string_char_and_length (s
, rest
, &len
);
961 s
+= len
, rest
-= len
;
964 BYTEPOS (pos
) += len
;
968 SET_TEXT_POS (pos
, charpos
, charpos
);
974 /* Value is the number of characters in C string S. MULTIBYTE_P
975 non-zero means recognize multibyte characters. */
978 number_of_chars (s
, multibyte_p
)
986 int rest
= strlen (s
), len
;
987 unsigned char *p
= (unsigned char *) s
;
989 for (nchars
= 0; rest
> 0; ++nchars
)
991 string_char_and_length (p
, rest
, &len
);
992 rest
-= len
, p
+= len
;
1002 /* Compute byte position NEWPOS->bytepos corresponding to
1003 NEWPOS->charpos. POS is a known position in string STRING.
1004 NEWPOS->charpos must be >= POS.charpos. */
1007 compute_string_pos (newpos
, pos
, string
)
1008 struct text_pos
*newpos
, pos
;
1011 xassert (STRINGP (string
));
1012 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1014 if (STRING_MULTIBYTE (string
))
1015 *newpos
= string_pos_nchars_ahead (pos
, CHARPOS (*newpos
) - CHARPOS (pos
),
1018 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1022 /* Return the charset of the character at position POS in
1026 charset_at_position (pos
)
1027 struct text_pos pos
;
1030 unsigned char *p
= BYTE_POS_ADDR (BYTEPOS (pos
));
1032 multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1035 int maxlen
= ((BYTEPOS (pos
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
1038 c
= string_char_and_length (p
, maxlen
, &len
);
1043 return CHAR_CHARSET (c
);
1048 /***********************************************************************
1049 Lisp form evaluation
1050 ***********************************************************************/
1052 /* Error handler for eval_form. */
1062 /* Evaluate SEXPR and return the result, or nil if something went
1069 int count
= specpdl_ptr
- specpdl
;
1071 specbind (Qinhibit_redisplay
, Qt
);
1072 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, eval_handler
);
1073 return unbind_to (count
, val
);
1078 /***********************************************************************
1080 ***********************************************************************/
1084 /* Define CHECK_IT to perform sanity checks on iterators.
1085 This is for debugging. It is too slow to do unconditionally. */
1091 if (it
->method
== next_element_from_string
)
1093 xassert (STRINGP (it
->string
));
1094 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1096 else if (it
->method
== next_element_from_buffer
)
1098 /* Check that character and byte positions agree. */
1099 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1103 xassert (it
->current
.dpvec_index
>= 0);
1105 xassert (it
->current
.dpvec_index
< 0);
1108 #define CHECK_IT(IT) check_it ((IT))
1112 #define CHECK_IT(IT) (void) 0
1119 /* Check that the window end of window W is what we expect it
1120 to be---the last row in the current matrix displaying text. */
1123 check_window_end (w
)
1126 if (!MINI_WINDOW_P (w
)
1127 && !NILP (w
->window_end_valid
))
1129 struct glyph_row
*row
;
1130 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1131 XFASTINT (w
->window_end_vpos
)),
1133 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1134 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1138 #define CHECK_WINDOW_END(W) check_window_end ((W))
1140 #else /* not GLYPH_DEBUG */
1142 #define CHECK_WINDOW_END(W) (void) 0
1144 #endif /* not GLYPH_DEBUG */
1148 /***********************************************************************
1149 Iterator initialization
1150 ***********************************************************************/
1152 /* Initialize IT for displaying current_buffer in window W, starting
1153 at character position CHARPOS. CHARPOS < 0 means that no buffer
1154 position is specified which is useful when the iterator is assigned
1155 a position later. BYTEPOS is the byte position corresponding to
1156 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1158 If ROW is not null, calls to produce_glyphs with IT as parameter
1159 will produce glyphs in that row.
1161 BASE_FACE_ID is the id of a base face to use. It must be one of
1162 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1163 TOP_LINE_FACE_ID for displaying mode lines, or TOOLBAR_FACE_ID for
1164 displaying the toolbar.
1166 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1167 TOP_LINE_FACE_ID, the iterator will be initialized to use the
1168 corresponding mode line glyph row of the desired matrix of W. */
1171 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1174 int charpos
, bytepos
;
1175 struct glyph_row
*row
;
1176 enum face_id base_face_id
;
1178 int highlight_region_p
;
1181 /* Some precondition checks. */
1182 xassert (w
!= NULL
&& it
!= NULL
);
1183 xassert (charpos
< 0 || current_buffer
== XBUFFER (w
->buffer
));
1184 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1186 /* If face attributes have been changed since the last redisplay,
1187 free realized faces now because they depend on face definitions
1188 that might have changed. */
1189 if (face_change_count
)
1191 face_change_count
= 0;
1192 free_all_realized_faces (Qnil
);
1195 /* Use one of the mode line rows of W's desired matrix if
1199 if (base_face_id
== MODE_LINE_FACE_ID
)
1200 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1201 else if (base_face_id
== TOP_LINE_FACE_ID
)
1202 row
= MATRIX_TOP_LINE_ROW (w
->desired_matrix
);
1206 bzero (it
, sizeof *it
);
1207 it
->current
.overlay_string_index
= -1;
1208 it
->current
.dpvec_index
= -1;
1209 it
->charset
= CHARSET_ASCII
;
1210 it
->base_face_id
= base_face_id
;
1212 /* The window in which we iterate over current_buffer: */
1213 XSETWINDOW (it
->window
, w
);
1215 it
->f
= XFRAME (w
->frame
);
1217 /* If realized faces have been removed, e.g. because of face
1218 attribute changes of named faces, recompute them. */
1219 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1220 recompute_basic_faces (it
->f
);
1222 /* Should we highlight trailing whitespace? */
1223 value
= find_symbol_value (Qshow_trailing_whitespace
);
1224 it
->show_trailing_whitespace_p
1225 = EQ (value
, Qunbound
) ? 0 : !NILP (value
);
1227 /* Current value of the `space-width', and 'height' properties. */
1228 it
->space_width
= Qnil
;
1229 it
->font_height
= Qnil
;
1231 /* Are control characters displayed as `^C'? */
1232 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1234 /* -1 means everything between a CR and the following line end
1235 is invisible. >0 means lines indented more than this value are
1237 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1238 ? XFASTINT (current_buffer
->selective_display
)
1239 : (!NILP (current_buffer
->selective_display
)
1241 it
->selective_display_ellipsis_p
1242 = !NILP (current_buffer
->selective_display_ellipses
);
1244 /* Display table to use. */
1245 it
->dp
= window_display_table (w
);
1247 /* Are multibyte characters enabled in current_buffer? */
1248 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1250 /* Non-zero if we should highlight the region. */
1252 = (!NILP (Vtransient_mark_mode
)
1253 && !NILP (current_buffer
->mark_active
)
1254 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1256 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1257 start and end of a visible region in window IT->w. Set both to
1258 -1 to indicate no region. */
1259 if (highlight_region_p
1260 /* Maybe highlight only in selected window. */
1261 && (/* Either show region everywhere. */
1262 highlight_nonselected_windows
1263 /* Or show region in the selected window. */
1264 || w
== XWINDOW (selected_window
)
1265 /* Or show the region if we are in the mini-buffer and W is
1266 the window the mini-buffer refers to. */
1267 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1268 && w
== XWINDOW (Vminibuf_scroll_window
))))
1270 int charpos
= marker_position (current_buffer
->mark
);
1271 it
->region_beg_charpos
= min (PT
, charpos
);
1272 it
->region_end_charpos
= max (PT
, charpos
);
1275 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1277 /* Get the position at which the redisplay_end_trigger hook should
1278 be run, if it is to be run at all. */
1279 if (MARKERP (w
->redisplay_end_trigger
)
1280 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1281 it
->redisplay_end_trigger_charpos
1282 = marker_position (w
->redisplay_end_trigger
);
1283 else if (INTEGERP (w
->redisplay_end_trigger
))
1284 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1286 /* Correct bogus values of tab_width. */
1287 it
->tab_width
= XINT (current_buffer
->tab_width
);
1288 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1291 /* Are lines in the display truncated? */
1292 it
->truncate_lines_p
1293 = (base_face_id
!= DEFAULT_FACE_ID
1294 || XINT (it
->w
->hscroll
)
1295 || (truncate_partial_width_windows
1296 && !WINDOW_FULL_WIDTH_P (it
->w
))
1297 || !NILP (current_buffer
->truncate_lines
));
1299 /* Get dimensions of truncation and continuation glyphs. These are
1300 displayed as bitmaps under X, so we don't need them for such
1302 if (!FRAME_WINDOW_P (it
->f
))
1304 if (it
->truncate_lines_p
)
1306 /* We will need the truncation glyph. */
1307 xassert (it
->glyph_row
== NULL
);
1308 produce_special_glyphs (it
, IT_TRUNCATION
);
1309 it
->truncation_pixel_width
= it
->pixel_width
;
1313 /* We will need the continuation glyph. */
1314 xassert (it
->glyph_row
== NULL
);
1315 produce_special_glyphs (it
, IT_CONTINUATION
);
1316 it
->continuation_pixel_width
= it
->pixel_width
;
1319 /* Reset these values to zero becaue the produce_special_glyphs
1320 above has changed them. */
1321 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1324 /* Set this after getting the dimensions of truncation and
1325 continuation glyphs, so that we don't produce glyphs when calling
1326 produce_special_glyphs, above. */
1327 it
->glyph_row
= row
;
1328 it
->area
= TEXT_AREA
;
1330 /* Get the dimensions of the display area. The display area
1331 consists of the visible window area plus a horizontally scrolled
1332 part to the left of the window. All x-values are relative to the
1333 start of this total display area. */
1334 if (base_face_id
!= DEFAULT_FACE_ID
)
1336 /* Mode lines, menu bar in terminal frames. */
1337 it
->first_visible_x
= 0;
1338 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1343 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1344 it
->last_visible_x
= (it
->first_visible_x
1345 + window_box_width (w
, TEXT_AREA
));
1347 /* If we truncate lines, leave room for the truncator glyph(s) at
1348 the right margin. Otherwise, leave room for the continuation
1349 glyph(s). Truncation and continuation glyphs are not inserted
1350 for window-based redisplay. */
1351 if (!FRAME_WINDOW_P (it
->f
))
1353 if (it
->truncate_lines_p
)
1354 it
->last_visible_x
-= it
->truncation_pixel_width
;
1356 it
->last_visible_x
-= it
->continuation_pixel_width
;
1359 it
->top_line_p
= WINDOW_WANTS_TOP_LINE_P (w
);
1360 it
->current_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
) + w
->vscroll
;
1363 /* Leave room for a border glyph. */
1364 if (!FRAME_WINDOW_P (it
->f
)
1365 && !WINDOW_RIGHTMOST_P (it
->w
))
1366 it
->last_visible_x
-= 1;
1368 it
->last_visible_y
= window_text_bottom_y (w
);
1370 /* For mode lines and alike, arrange for the first glyph having a
1371 left box line if the face specifies a box. */
1372 if (base_face_id
!= DEFAULT_FACE_ID
)
1376 it
->face_id
= base_face_id
;
1378 /* If we have a boxed mode line, make the first character appear
1379 with a left box line. */
1380 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1381 if (face
->box
!= FACE_NO_BOX
)
1382 it
->start_of_box_run_p
= 1;
1385 /* If a buffer position was specified, set the iterator there,
1386 getting overlays and face properties from that position. */
1389 it
->end_charpos
= ZV
;
1391 IT_CHARPOS (*it
) = charpos
;
1393 /* Compute byte position if not specified. */
1395 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1397 IT_BYTEPOS (*it
) = bytepos
;
1399 /* Compute faces etc. */
1400 reseat (it
, it
->current
.pos
, 1);
1407 /* Initialize IT for the display of window W with window start POS. */
1410 start_display (it
, w
, pos
)
1413 struct text_pos pos
;
1415 int start_at_line_beg_p
;
1416 struct glyph_row
*row
;
1417 int first_vpos
= WINDOW_WANTS_TOP_LINE_P (w
) ? 1 : 0;
1420 row
= w
->desired_matrix
->rows
+ first_vpos
;
1421 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1422 first_y
= it
->current_y
;
1424 /* If window start is not at a line start, move back to the line
1425 start. This makes sure that we take continuation lines into
1427 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1428 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1429 if (!start_at_line_beg_p
)
1430 reseat_at_previous_visible_line_start (it
);
1432 #if NO_PROMPT_IN_BUFFER
1433 /* Take the mini-buffer prompt width into account for tab
1435 if (MINI_WINDOW_P (w
) && IT_CHARPOS (*it
) == BEGV
)
1437 /* Why is mini-buffer_prompt_width guaranteed to be set here? */
1438 it
->prompt_width
= minibuf_prompt_pixel_width
;
1440 #endif /* NO_PROMPT_IN_BUFFER */
1442 /* If window start is not at a line start, skip forward to POS to
1443 get the correct continuation_lines_width and current_x. */
1444 if (!start_at_line_beg_p
)
1446 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1448 /* If lines are continued, this line may end in the middle of a
1449 multi-glyph character (e.g. a control character displayed as
1450 \003, or in the middle of an overlay string). In this case
1451 move_it_to above will not have taken us to the start of
1452 the continuation line but to the end of the continued line. */
1453 if (!it
->truncate_lines_p
&& it
->current_x
> 0)
1455 if (it
->current
.dpvec_index
>= 0
1456 || it
->current
.overlay_string_index
>= 0)
1458 set_iterator_to_next (it
);
1459 move_it_in_display_line_to (it
, -1, -1, 0);
1461 it
->continuation_lines_width
+= it
->current_x
;
1464 it
->current_y
= first_y
;
1466 it
->current_x
= it
->hpos
= 0;
1469 #if 0 /* Don't assert the following because start_display is sometimes
1470 called intentionally with a window start that is not at a
1471 line start. Please leave this code in as a comment. */
1473 /* Window start should be on a line start, now. */
1474 xassert (it
->continuation_lines_width
1475 || IT_CHARPOS (it
) == BEGV
1476 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1481 /* Initialize IT for stepping through current_buffer in window W,
1482 starting at position POS that includes overlay string and display
1483 vector/ control character translation position information. */
1486 init_from_display_pos (it
, w
, pos
)
1489 struct display_pos
*pos
;
1491 /* Keep in mind: the call to reseat in init_iterator skips invisible
1492 text, so we might end up at a position different from POS. This
1493 is only a problem when POS is a row start after a newline and an
1494 overlay starts there with an after-string, and the overlay has an
1495 invisible property. Since we don't skip invisible text in
1496 display_line and elsewhere immediately after consuming the
1497 newline before the row start, such a POS will not be in a string,
1498 but the call to init_iterator below will move us to the
1500 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1501 NULL
, DEFAULT_FACE_ID
);
1503 /* If position is within an overlay string, set up IT to
1504 the right overlay string. */
1505 if (pos
->overlay_string_index
>= 0)
1509 /* We already have the first chunk of overlay strings in
1510 IT->overlay_strings. Load more until the one for
1511 pos->overlay_string_index is in IT->overlay_strings. */
1512 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1514 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1515 it
->current
.overlay_string_index
= 0;
1518 load_overlay_strings (it
);
1519 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1523 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1524 relative_index
= (it
->current
.overlay_string_index
1525 % OVERLAY_STRING_CHUNK_SIZE
);
1526 it
->string
= it
->overlay_strings
[relative_index
];
1527 it
->current
.string_pos
= pos
->string_pos
;
1528 it
->method
= next_element_from_string
;
1530 else if (CHARPOS (pos
->string_pos
) >= 0)
1532 /* Recorded position is not in an overlay string, but in another
1533 string. This can only be a string from a `display' property.
1534 IT should already be filled with that string. */
1535 it
->current
.string_pos
= pos
->string_pos
;
1536 xassert (STRINGP (it
->string
));
1539 /* Restore position in display vector translations or control
1540 character translations. */
1541 if (pos
->dpvec_index
>= 0)
1543 /* This fills IT->dpvec. */
1544 get_next_display_element (it
);
1545 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1546 it
->current
.dpvec_index
= pos
->dpvec_index
;
1553 /* Initialize IT for stepping through current_buffer in window W
1554 starting at ROW->start. */
1557 init_to_row_start (it
, w
, row
)
1560 struct glyph_row
*row
;
1562 init_from_display_pos (it
, w
, &row
->start
);
1563 it
->continuation_lines_width
= row
->continuation_lines_width
;
1568 /* Initialize IT for stepping through current_buffer in window W
1569 starting in the line following ROW, i.e. starting at ROW->end. */
1572 init_to_row_end (it
, w
, row
)
1575 struct glyph_row
*row
;
1577 init_from_display_pos (it
, w
, &row
->end
);
1579 if (row
->continued_p
)
1580 it
->continuation_lines_width
= (row
->continuation_lines_width
1581 + row
->pixel_width
);
1588 /***********************************************************************
1590 ***********************************************************************/
1592 /* Called when IT reaches IT->stop_charpos. Handle text property and
1593 overlay changes. Set IT->stop_charpos to the next position where
1600 enum prop_handled handled
;
1601 int handle_overlay_change_p
= 1;
1605 it
->current
.dpvec_index
= -1;
1609 handled
= HANDLED_NORMALLY
;
1611 /* Call text property handlers. */
1612 for (p
= it_props
; p
->handler
; ++p
)
1614 handled
= p
->handler (it
);
1616 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1618 else if (handled
== HANDLED_RETURN
)
1620 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1621 handle_overlay_change_p
= 0;
1624 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1626 /* Don't check for overlay strings below when set to deliver
1627 characters from a display vector. */
1628 if (it
->method
== next_element_from_display_vector
)
1629 handle_overlay_change_p
= 0;
1631 /* Handle overlay changes. */
1632 if (handle_overlay_change_p
)
1633 handled
= handle_overlay_change (it
);
1635 /* Determine where to stop next. */
1636 if (handled
== HANDLED_NORMALLY
)
1637 compute_stop_pos (it
);
1640 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1644 /* Compute IT->stop_charpos from text property and overlay change
1645 information for IT's current position. */
1648 compute_stop_pos (it
)
1651 register INTERVAL iv
, next_iv
;
1652 Lisp_Object object
, limit
, position
;
1654 /* If nowhere else, stop at the end. */
1655 it
->stop_charpos
= it
->end_charpos
;
1657 if (STRINGP (it
->string
))
1659 /* Strings are usually short, so don't limit the search for
1661 object
= it
->string
;
1663 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1669 /* If next overlay change is in front of the current stop pos
1670 (which is IT->end_charpos), stop there. Note: value of
1671 next_overlay_change is point-max if no overlay change
1673 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1674 if (charpos
< it
->stop_charpos
)
1675 it
->stop_charpos
= charpos
;
1677 /* If showing the region, we have to stop at the region
1678 start or end because the face might change there. */
1679 if (it
->region_beg_charpos
> 0)
1681 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1682 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1683 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1684 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1687 /* Set up variables for computing the stop position from text
1688 property changes. */
1689 XSETBUFFER (object
, current_buffer
);
1690 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1691 XSETFASTINT (position
, IT_CHARPOS (*it
));
1695 /* Get the interval containing IT's position. Value is a null
1696 interval if there isn't such an interval. */
1697 iv
= validate_interval_range (object
, &position
, &position
, 0);
1698 if (!NULL_INTERVAL_P (iv
))
1700 Lisp_Object values_here
[LAST_PROP_IDX
];
1703 /* Get properties here. */
1704 for (p
= it_props
; p
->handler
; ++p
)
1705 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1707 /* Look for an interval following iv that has different
1709 for (next_iv
= next_interval (iv
);
1710 (!NULL_INTERVAL_P (next_iv
)
1712 || XFASTINT (limit
) > next_iv
->position
));
1713 next_iv
= next_interval (next_iv
))
1715 for (p
= it_props
; p
->handler
; ++p
)
1717 Lisp_Object new_value
;
1719 new_value
= textget (next_iv
->plist
, *p
->name
);
1720 if (!EQ (values_here
[p
->idx
], new_value
))
1728 if (!NULL_INTERVAL_P (next_iv
))
1730 if (INTEGERP (limit
)
1731 && next_iv
->position
>= XFASTINT (limit
))
1732 /* No text property change up to limit. */
1733 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1735 /* Text properties change in next_iv. */
1736 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1740 xassert (STRINGP (it
->string
)
1741 || (it
->stop_charpos
>= BEGV
1742 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1746 /* Return the position of the next overlay change after POS in
1747 current_buffer. Value is point-max if no overlay change
1748 follows. This is like `next-overlay-change' but doesn't use
1752 next_overlay_change (pos
)
1757 Lisp_Object
*overlays
;
1761 /* Get all overlays at the given position. */
1763 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1764 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1765 if (noverlays
> len
)
1768 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1769 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1772 /* If any of these overlays ends before endpos,
1773 use its ending point instead. */
1774 for (i
= 0; i
< noverlays
; ++i
)
1779 oend
= OVERLAY_END (overlays
[i
]);
1780 oendpos
= OVERLAY_POSITION (oend
);
1781 endpos
= min (endpos
, oendpos
);
1789 /***********************************************************************
1791 ***********************************************************************/
1793 /* Handle changes in the `fontified' property of the current buffer by
1794 calling hook functions from Qfontification_functions to fontify
1797 static enum prop_handled
1798 handle_fontified_prop (it
)
1801 Lisp_Object prop
, pos
;
1802 enum prop_handled handled
= HANDLED_NORMALLY
;
1804 /* Get the value of the `fontified' property at IT's current buffer
1805 position. (The `fontified' property doesn't have a special
1806 meaning in strings.) If the value is nil, call functions from
1807 Qfontification_functions. */
1808 if (!STRINGP (it
->string
)
1810 && !NILP (Vfontification_functions
)
1811 && (pos
= make_number (IT_CHARPOS (*it
)),
1812 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1815 Lisp_Object args
[2];
1817 /* Run the hook functions. */
1818 args
[0] = Qfontification_functions
;
1820 Frun_hook_with_args (make_number (2), args
);
1822 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
1823 something. This avoids an endless loop if they failed to
1824 fontify the text for which reason ever. */
1825 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
1826 handled
= HANDLED_RECOMPUTE_PROPS
;
1834 /***********************************************************************
1836 ***********************************************************************/
1838 /* Set up iterator IT from face properties at its current position.
1839 Called from handle_stop. */
1841 static enum prop_handled
1842 handle_face_prop (it
)
1845 int new_face_id
, next_stop
;
1847 if (!STRINGP (it
->string
))
1850 = face_at_buffer_position (it
->w
,
1852 it
->region_beg_charpos
,
1853 it
->region_end_charpos
,
1856 + TEXT_PROP_DISTANCE_LIMIT
),
1859 /* Is this a start of a run of characters with box face?
1860 Caveat: this can be called for a freshly initialized
1861 iterator; face_id is -1 is this case. We know that the new
1862 face will not change until limit, i.e. if the new face has a
1863 box, all characters up to limit will have one. But, as
1864 usual, we don't know whether limit is really the end. */
1865 if (new_face_id
!= it
->face_id
)
1867 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1869 /* If new face has a box but old face has not, this is
1870 the start of a run of characters with box, i.e. it has
1871 a shadow on the left side. The value of face_id of the
1872 iterator will be -1 if this is the initial call that gets
1873 the face. In this case, we have to look in front of IT's
1874 position and see whether there is a face != new_face_id. */
1875 it
->start_of_box_run_p
1876 = (new_face
->box
!= FACE_NO_BOX
1877 && (it
->face_id
>= 0
1878 || IT_CHARPOS (*it
) == BEG
1879 || new_face_id
!= face_before_it_pos (it
)));
1880 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1886 = face_at_string_position (it
->w
,
1888 IT_STRING_CHARPOS (*it
),
1889 (it
->current
.overlay_string_index
>= 0
1892 it
->region_beg_charpos
,
1893 it
->region_end_charpos
,
1897 #if 0 /* This shouldn't be neccessary. Let's check it. */
1898 /* If IT is used to display a mode line we would really like to
1899 use the mode line face instead of the frame's default face. */
1900 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
1901 && new_face_id
== DEFAULT_FACE_ID
)
1902 new_face_id
= MODE_LINE_FACE_ID
;
1905 /* Is this a start of a run of characters with box? Caveat:
1906 this can be called for a freshly allocated iterator; face_id
1907 is -1 is this case. We know that the new face will not
1908 change until the next check pos, i.e. if the new face has a
1909 box, all characters up to that position will have a
1910 box. But, as usual, we don't know whether that position
1911 is really the end. */
1912 if (new_face_id
!= it
->face_id
)
1914 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1915 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1917 /* If new face has a box but old face hasn't, this is the
1918 start of a run of characters with box, i.e. it has a
1919 shadow on the left side. */
1920 it
->start_of_box_run_p
1921 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
1922 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1926 it
->face_id
= new_face_id
;
1927 it
->charset
= CHARSET_ASCII
;
1928 return HANDLED_NORMALLY
;
1932 /* Compute the face one character before or after the current position
1933 of IT. BEFORE_P non-zero means get the face in front of IT's
1934 position. Value is the id of the face. */
1937 face_before_or_after_it_pos (it
, before_p
)
1942 int next_check_charpos
;
1943 struct text_pos pos
;
1945 xassert (it
->s
== NULL
);
1947 if (STRINGP (it
->string
))
1949 /* No face change past the end of the string (for the case
1950 we are padding with spaces). No face change before the
1952 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
1953 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
1956 /* Set pos to the position before or after IT's current position. */
1958 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
1960 pos
= string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
);
1962 /* Get the face for ASCII, or unibyte. */
1964 = face_at_string_position (it
->w
,
1967 (it
->current
.overlay_string_index
>= 0
1970 it
->region_beg_charpos
,
1971 it
->region_end_charpos
,
1972 &next_check_charpos
,
1975 /* Correct the face for charsets different from ASCII. Do it
1976 for the multibyte case only. The face returned above is
1977 suitable for unibyte text if IT->string is unibyte. */
1978 if (STRING_MULTIBYTE (it
->string
))
1980 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
1981 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
1982 int c
, len
, charset
;
1984 c
= string_char_and_length (p
, rest
, &len
);
1985 charset
= CHAR_CHARSET (c
);
1986 if (charset
!= CHARSET_ASCII
)
1987 face_id
= FACE_FOR_CHARSET (it
->f
, face_id
, charset
);
1992 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
1993 pos
= it
->current
.pos
;
2000 /* Determine face for CHARSET_ASCII, or unibyte. */
2001 face_id
= face_at_buffer_position (it
->w
,
2003 it
->region_beg_charpos
,
2004 it
->region_end_charpos
,
2005 &next_check_charpos
,
2008 /* Correct the face for charsets different from ASCII. Do it
2009 for the multibyte case only. The face returned above is
2010 suitable for unibyte text if current_buffer is unibyte. */
2011 if (it
->multibyte_p
)
2013 int charset
= charset_at_position (pos
);
2014 if (charset
!= CHARSET_ASCII
)
2015 face_id
= FACE_FOR_CHARSET (it
->f
, face_id
, charset
);
2024 /***********************************************************************
2026 ***********************************************************************/
2028 /* Set up iterator IT from invisible properties at its current
2029 position. Called from handle_stop. */
2031 static enum prop_handled
2032 handle_invisible_prop (it
)
2035 enum prop_handled handled
= HANDLED_NORMALLY
;
2037 if (STRINGP (it
->string
))
2039 extern Lisp_Object Qinvisible
;
2040 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2042 /* Get the value of the invisible text property at the
2043 current position. Value will be nil if there is no such
2045 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2046 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2050 handled
= HANDLED_RECOMPUTE_PROPS
;
2052 /* Get the position at which the next change of the
2053 invisible text property can be found in IT->string.
2054 Value will be nil if the property value is the same for
2055 all the rest of IT->string. */
2056 XSETINT (limit
, XSTRING (it
->string
)->size
);
2057 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2060 /* Text at current position is invisible. The next
2061 change in the property is at position end_charpos.
2062 Move IT's current position to that position. */
2063 if (INTEGERP (end_charpos
)
2064 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2066 struct text_pos old
;
2067 old
= it
->current
.string_pos
;
2068 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2069 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2073 /* The rest of the string is invisible. If this is an
2074 overlay string, proceed with the next overlay string
2075 or whatever comes and return a character from there. */
2076 if (it
->current
.overlay_string_index
>= 0)
2078 next_overlay_string (it
);
2079 /* Don't check for overlay strings when we just
2080 finished processing them. */
2081 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2085 struct Lisp_String
*s
= XSTRING (it
->string
);
2086 IT_STRING_CHARPOS (*it
) = s
->size
;
2087 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2094 int visible_p
, newpos
, next_stop
;
2095 Lisp_Object pos
, prop
;
2097 /* First of all, is there invisible text at this position? */
2098 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2099 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2101 /* If we are on invisible text, skip over it. */
2102 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
2104 /* Record whether we have to display an ellipsis for the
2106 int display_ellipsis_p
2107 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2109 handled
= HANDLED_RECOMPUTE_PROPS
;
2111 /* Loop skipping over invisible text. The loop is left at
2112 ZV or with IT on the first char being visible again. */
2115 /* Try to skip some invisible text. Return value is the
2116 position reached which can be equal to IT's position
2117 if there is nothing invisible here. This skips both
2118 over invisible text properties and overlays with
2119 invisible property. */
2120 newpos
= skip_invisible (IT_CHARPOS (*it
),
2121 &next_stop
, ZV
, it
->window
);
2123 /* If we skipped nothing at all we weren't at invisible
2124 text in the first place. If everything to the end of
2125 the buffer was skipped, end the loop. */
2126 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2130 /* We skipped some characters but not necessarily
2131 all there are. Check if we ended up on visible
2132 text. Fget_char_property returns the property of
2133 the char before the given position, i.e. if we
2134 get visible_p = 1, this means that the char at
2135 newpos is visible. */
2136 XSETFASTINT (pos
, newpos
);
2137 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2138 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2141 /* If we ended up on invisible text, proceed to
2142 skip starting with next_stop. */
2144 IT_CHARPOS (*it
) = next_stop
;
2148 /* The position newpos is now either ZV or on visible text. */
2149 IT_CHARPOS (*it
) = newpos
;
2150 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2152 /* Maybe return `...' next for the end of the invisible text. */
2153 if (display_ellipsis_p
)
2156 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2158 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2159 it
->dpvec
= v
->contents
;
2160 it
->dpend
= v
->contents
+ v
->size
;
2164 /* Default `...'. */
2165 it
->dpvec
= default_invis_vector
;
2166 it
->dpend
= default_invis_vector
+ 3;
2169 /* The ellipsis display does not replace the display of
2170 the character at the new position. Indicate this by
2171 setting IT->dpvec_char_len to zero. */
2172 it
->dpvec_char_len
= 0;
2174 it
->current
.dpvec_index
= 0;
2175 it
->method
= next_element_from_display_vector
;
2185 /***********************************************************************
2187 ***********************************************************************/
2189 /* Set up iterator IT from `display' property at its current position.
2190 Called from handle_stop. */
2192 static enum prop_handled
2193 handle_display_prop (it
)
2196 Lisp_Object prop
, object
;
2197 struct text_pos
*position
;
2198 int space_or_image_found_p
;
2200 if (STRINGP (it
->string
))
2202 object
= it
->string
;
2203 position
= &it
->current
.string_pos
;
2208 position
= &it
->current
.pos
;
2211 /* Reset those iterator values set from display property values. */
2212 it
->font_height
= Qnil
;
2213 it
->space_width
= Qnil
;
2216 /* We don't support recursive `display' properties, i.e. string
2217 values that have a string `display' property, that have a string
2218 `display' property etc. */
2219 if (!it
->string_from_display_prop_p
)
2220 it
->area
= TEXT_AREA
;
2222 prop
= Fget_char_property (make_number (position
->charpos
),
2225 return HANDLED_NORMALLY
;
2227 space_or_image_found_p
= 0;
2228 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2230 while (CONSP (prop
))
2232 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2233 space_or_image_found_p
= 1;
2237 else if (VECTORP (prop
))
2240 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2241 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2243 space_or_image_found_p
= 1;
2247 if (handle_single_display_prop (it
, prop
, object
, position
))
2248 space_or_image_found_p
= 1;
2251 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2255 /* Value is the position of the end of the `display' property stating
2256 at START_POS in OBJECT. */
2258 static struct text_pos
2259 display_prop_end (it
, object
, start_pos
)
2262 struct text_pos start_pos
;
2265 struct text_pos end_pos
;
2267 /* Characters having this form of property are not displayed, so
2268 we have to find the end of the property. */
2269 end
= Fnext_single_property_change (make_number (start_pos
.charpos
),
2270 Qdisplay
, object
, Qnil
);
2273 /* A nil value of `end' means there are no changes of the
2274 property to the end of the buffer or string. */
2275 if (it
->current
.overlay_string_index
>= 0)
2276 end_pos
.charpos
= XSTRING (it
->string
)->size
;
2278 end_pos
.charpos
= it
->end_charpos
;
2281 end_pos
.charpos
= XFASTINT (end
);
2283 if (STRINGP (it
->string
))
2284 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2286 end_pos
.bytepos
= CHAR_TO_BYTE (end_pos
.charpos
);
2292 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2293 is the object in which the `display' property was found. *POSITION
2294 is the position at which it was found.
2296 If PROP is a `space' or `image' sub-property, set *POSITION to the
2297 end position of the `display' property.
2299 Value is non-zero if a `space' or `image' property value was found. */
2302 handle_single_display_prop (it
, prop
, object
, position
)
2306 struct text_pos
*position
;
2309 int space_or_image_found_p
= 0;
2313 /* If PROP is a list of the form `(:when FORM VALUE)', FORM is
2314 evaluated. If the result is nil, VALUE is ignored. */
2316 if (CONSP (prop
) && EQ (XCAR (prop
), QCwhen
))
2328 if (!NILP (form
) && !EQ (form
, Qt
))
2330 struct gcpro gcpro1
;
2331 struct text_pos end_pos
, pt
;
2333 end_pos
= display_prop_end (it
, object
, *position
);
2336 /* Temporarily set point to the end position, and then evaluate
2337 the form. This makes `(eolp)' work as FORM. */
2339 BYTEPOS (pt
) = PT_BYTE
;
2340 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2341 form
= eval_form (form
);
2342 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2350 && EQ (XCAR (prop
), Qheight
)
2351 && CONSP (XCDR (prop
)))
2353 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2356 /* `(height HEIGHT)'. */
2357 it
->font_height
= XCAR (XCDR (prop
));
2358 if (!NILP (it
->font_height
))
2360 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2361 int new_height
= -1;
2363 if (CONSP (it
->font_height
)
2364 && (EQ (XCAR (it
->font_height
), Qplus
)
2365 || EQ (XCAR (it
->font_height
), Qminus
))
2366 && CONSP (XCDR (it
->font_height
))
2367 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2369 /* `(+ N)' or `(- N)' where N is an integer. */
2370 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2371 if (EQ (XCAR (it
->font_height
), Qplus
))
2373 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2375 else if (SYMBOLP (it
->font_height
))
2377 /* Call function with current height as argument.
2378 Value is the new height. */
2379 Lisp_Object form
, height
;
2380 struct gcpro gcpro1
;
2382 height
= face
->lface
[LFACE_HEIGHT_INDEX
];
2383 form
= Fcons (it
->font_height
, Fcons (height
, Qnil
));
2385 height
= eval_form (form
);
2386 if (NUMBERP (height
))
2387 new_height
= XFLOATINT (height
);
2390 else if (NUMBERP (it
->font_height
))
2392 /* Value is a multiple of the canonical char height. */
2395 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2396 new_height
= (XFLOATINT (it
->font_height
)
2397 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2401 /* Evaluate IT->font_height with `height' bound to the
2402 current specified height to get the new height. */
2404 int count
= specpdl_ptr
- specpdl
;
2406 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2407 value
= eval_form (it
->font_height
);
2408 unbind_to (count
, Qnil
);
2410 if (NUMBERP (value
))
2411 new_height
= XFLOATINT (value
);
2415 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2418 else if (CONSP (prop
)
2419 && EQ (XCAR (prop
), Qspace_width
)
2420 && CONSP (XCDR (prop
)))
2422 /* `(space_width WIDTH)'. */
2423 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2426 value
= XCAR (XCDR (prop
));
2427 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2428 it
->space_width
= value
;
2430 else if (CONSP (prop
)
2431 && EQ (XCAR (prop
), Qraise
)
2432 && CONSP (XCDR (prop
)))
2434 #ifdef HAVE_WINDOW_SYSTEM
2435 /* `(raise FACTOR)'. */
2436 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2439 value
= XCAR (XCDR (prop
));
2440 if (NUMBERP (value
))
2442 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2443 it
->voffset
= - (XFLOATINT (value
)
2444 * (face
->font
->ascent
+ face
->font
->descent
));
2446 #endif /* HAVE_WINDOW_SYSTEM */
2448 else if (!it
->string_from_display_prop_p
)
2450 /* `(left-margin VALUE)' or `(right-margin VALUE)
2451 or `(nil VALUE)' or VALUE. */
2452 Lisp_Object location
, value
;
2453 struct text_pos start_pos
;
2456 /* Characters having this form of property are not displayed, so
2457 we have to find the end of the property. */
2458 space_or_image_found_p
= 1;
2459 start_pos
= *position
;
2460 *position
= display_prop_end (it
, object
, start_pos
);
2462 /* Let's stop at the new position and assume that all
2463 text properties change there. */
2464 it
->stop_charpos
= position
->charpos
;
2467 && !EQ (XCAR (prop
), Qspace
)
2468 && !EQ (XCAR (prop
), Qimage
))
2470 location
= XCAR (prop
);
2471 value
= XCDR (prop
);
2479 #ifdef HAVE_WINDOW_SYSTEM
2480 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2481 valid_p
= STRINGP (value
);
2483 valid_p
= (STRINGP (value
)
2484 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2485 || valid_image_p (value
));
2486 #else /* not HAVE_WINDOW_SYSTEM */
2487 valid_p
= STRINGP (value
);
2488 #endif /* not HAVE_WINDOW_SYSTEM */
2490 if ((EQ (location
, Qleft_margin
)
2491 || EQ (location
, Qright_margin
)
2495 /* Save current settings of IT so that we can restore them
2496 when we are finished with the glyph property value. */
2499 if (NILP (location
))
2500 it
->area
= TEXT_AREA
;
2501 else if (EQ (location
, Qleft_margin
))
2502 it
->area
= LEFT_MARGIN_AREA
;
2504 it
->area
= RIGHT_MARGIN_AREA
;
2506 if (STRINGP (value
))
2509 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2510 it
->current
.overlay_string_index
= -1;
2511 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2512 it
->end_charpos
= it
->string_nchars
2513 = XSTRING (it
->string
)->size
;
2514 it
->method
= next_element_from_string
;
2515 it
->stop_charpos
= 0;
2516 it
->string_from_display_prop_p
= 1;
2518 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2520 it
->method
= next_element_from_stretch
;
2522 it
->current
.pos
= it
->position
= start_pos
;
2524 #ifdef HAVE_WINDOW_SYSTEM
2527 it
->what
= IT_IMAGE
;
2528 it
->image_id
= lookup_image (it
->f
, value
);
2529 it
->position
= start_pos
;
2530 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2531 it
->method
= next_element_from_image
;
2533 /* Say that we don't have consumed the characters with
2534 `display' property yet. The call to pop_it in
2535 set_iterator_to_next will clean this up. */
2536 *position
= start_pos
;
2538 #endif /* HAVE_WINDOW_SYSTEM */
2542 return space_or_image_found_p
;
2547 /***********************************************************************
2549 ***********************************************************************/
2551 /* The following structure is used to record overlay strings for
2552 later sorting in load_overlay_strings. */
2554 struct overlay_entry
2562 /* Set up iterator IT from overlay strings at its current position.
2563 Called from handle_stop. */
2565 static enum prop_handled
2566 handle_overlay_change (it
)
2569 /* Overlays are handled in current_buffer only. */
2570 if (STRINGP (it
->string
))
2571 return HANDLED_NORMALLY
;
2573 return (get_overlay_strings (it
)
2574 ? HANDLED_RECOMPUTE_PROPS
2575 : HANDLED_NORMALLY
);
2579 /* Set up the next overlay string for delivery by IT, if there is an
2580 overlay string to deliver. Called by set_iterator_to_next when the
2581 end of the current overlay string is reached. If there are more
2582 overlay strings to display, IT->string and
2583 IT->current.overlay_string_index are set appropriately here.
2584 Otherwise IT->string is set to nil. */
2587 next_overlay_string (it
)
2590 ++it
->current
.overlay_string_index
;
2591 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2593 /* No more overlay strings. Restore IT's settings to what
2594 they were before overlay strings were processed, and
2595 continue to deliver from current_buffer. */
2597 xassert (it
->stop_charpos
>= BEGV
2598 && it
->stop_charpos
<= it
->end_charpos
);
2600 it
->current
.overlay_string_index
= -1;
2601 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2602 it
->n_overlay_strings
= 0;
2603 it
->method
= next_element_from_buffer
;
2607 /* There are more overlay strings to process. If
2608 IT->current.overlay_string_index has advanced to a position
2609 where we must load IT->overlay_strings with more strings, do
2611 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2613 if (it
->current
.overlay_string_index
&& i
== 0)
2614 load_overlay_strings (it
);
2616 /* Initialize IT to deliver display elements from the overlay
2618 it
->string
= it
->overlay_strings
[i
];
2619 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2620 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2621 it
->method
= next_element_from_string
;
2622 it
->stop_charpos
= 0;
2629 /* Compare two overlay_entry structures E1 and E2. Used as a
2630 comparison function for qsort in load_overlay_strings. Overlay
2631 strings for the same position are sorted so that
2633 1. All after-strings come in front of before-strings.
2635 2. Within after-strings, strings are sorted so that overlay strings
2636 from overlays with higher priorities come first.
2638 2. Within before-strings, strings are sorted so that overlay
2639 strings from overlays with higher priorities come last.
2641 Value is analogous to strcmp. */
2645 compare_overlay_entries (e1
, e2
)
2648 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
2649 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
2652 if (entry1
->after_string_p
!= entry2
->after_string_p
)
2653 /* Let after-strings appear in front of before-strings. */
2654 result
= entry1
->after_string_p
? -1 : 1;
2655 else if (entry1
->after_string_p
)
2656 /* After-strings sorted in order of decreasing priority. */
2657 result
= entry2
->priority
- entry1
->priority
;
2659 /* Before-strings sorted in order of increasing priority. */
2660 result
= entry1
->priority
- entry2
->priority
;
2666 /* Load the vector IT->overlay_strings with overlay strings from IT's
2667 current buffer position. Set IT->n_overlays to the total number of
2668 overlay strings found.
2670 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
2671 a time. On entry into load_overlay_strings,
2672 IT->current.overlay_string_index gives the number of overlay
2673 strings that have already been loaded by previous calls to this
2676 Overlay strings are sorted so that after-string strings come in
2677 front of before-string strings. Within before and after-strings,
2678 strings are sorted by overlay priority. See also function
2679 compare_overlay_entries. */
2682 load_overlay_strings (it
)
2685 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
2686 Lisp_Object ov
, overlay
, window
, str
;
2690 struct overlay_entry
*entries
2691 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
2693 /* Append the overlay string STRING of overlay OVERLAY to vector
2694 `entries' which has size `size' and currently contains `n'
2695 elements. AFTER_P non-zero means STRING is an after-string of
2697 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
2700 Lisp_Object priority; \
2704 int new_size = 2 * size; \
2705 struct overlay_entry *old = entries; \
2707 (struct overlay_entry *) alloca (new_size \
2708 * sizeof *entries); \
2709 bcopy (old, entries, size * sizeof *entries); \
2713 entries[n].string = (STRING); \
2714 priority = Foverlay_get ((OVERLAY), Qpriority); \
2715 entries[n].priority \
2716 = INTEGERP (priority) ? XFASTINT (priority) : 0; \
2717 entries[n].after_string_p = (AFTER_P); \
2722 /* Process overlay before the overlay center. */
2723 for (ov
= current_buffer
->overlays_before
;
2725 ov
= XCONS (ov
)->cdr
)
2727 overlay
= XCONS (ov
)->car
;
2728 xassert (OVERLAYP (overlay
));
2729 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2730 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2732 if (end
< IT_CHARPOS (*it
))
2735 /* Skip this overlay if it doesn't start or end at IT's current
2737 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2740 /* Skip this overlay if it doesn't apply to IT->w. */
2741 window
= Foverlay_get (overlay
, Qwindow
);
2742 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2745 /* If overlay has a non-empty before-string, record it. */
2746 if (start
== IT_CHARPOS (*it
)
2747 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2748 && XSTRING (str
)->size
)
2749 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2751 /* If overlay has a non-empty after-string, record it. */
2752 if (end
== IT_CHARPOS (*it
)
2753 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2754 && XSTRING (str
)->size
)
2755 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2758 /* Process overlays after the overlay center. */
2759 for (ov
= current_buffer
->overlays_after
;
2761 ov
= XCONS (ov
)->cdr
)
2763 overlay
= XCONS (ov
)->car
;
2764 xassert (OVERLAYP (overlay
));
2765 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2766 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2768 if (start
> IT_CHARPOS (*it
))
2771 /* Skip this overlay if it doesn't start or end at IT's current
2773 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2776 /* Skip this overlay if it doesn't apply to IT->w. */
2777 window
= Foverlay_get (overlay
, Qwindow
);
2778 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2781 /* If overlay has a non-empty before-string, record it. */
2782 if (start
== IT_CHARPOS (*it
)
2783 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2784 && XSTRING (str
)->size
)
2785 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2787 /* If overlay has a non-empty after-string, record it. */
2788 if (end
== IT_CHARPOS (*it
)
2789 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2790 && XSTRING (str
)->size
)
2791 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2794 #undef RECORD_OVERLAY_STRING
2797 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
2799 /* Record the total number of strings to process. */
2800 it
->n_overlay_strings
= n
;
2802 /* IT->current.overlay_string_index is the number of overlay strings
2803 that have already been consumed by IT. Copy some of the
2804 remaining overlay strings to IT->overlay_strings. */
2806 j
= it
->current
.overlay_string_index
;
2807 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
2808 it
->overlay_strings
[i
++] = entries
[j
++].string
;
2814 /* Get the first chunk of overlay strings at IT's current buffer
2815 position. Value is non-zero if at least one overlay string was
2819 get_overlay_strings (it
)
2822 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
2823 process. This fills IT->overlay_strings with strings, and sets
2824 IT->n_overlay_strings to the total number of strings to process.
2825 IT->pos.overlay_string_index has to be set temporarily to zero
2826 because load_overlay_strings needs this; it must be set to -1
2827 when no overlay strings are found because a zero value would
2828 indicate a position in the first overlay string. */
2829 it
->current
.overlay_string_index
= 0;
2830 load_overlay_strings (it
);
2832 /* If we found overlay strings, set up IT to deliver display
2833 elements from the first one. Otherwise set up IT to deliver
2834 from current_buffer. */
2835 if (it
->n_overlay_strings
)
2837 /* Make sure we know settings in current_buffer, so that we can
2838 restore meaningful values when we're done with the overlay
2840 compute_stop_pos (it
);
2841 xassert (it
->face_id
>= 0);
2843 /* Save IT's settings. They are restored after all overlay
2844 strings have been processed. */
2845 xassert (it
->sp
== 0);
2848 /* Set up IT to deliver display elements from the first overlay
2850 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2851 it
->stop_charpos
= 0;
2852 it
->string
= it
->overlay_strings
[0];
2853 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2854 xassert (STRINGP (it
->string
));
2855 it
->method
= next_element_from_string
;
2860 it
->current
.overlay_string_index
= -1;
2861 it
->method
= next_element_from_buffer
;
2866 /* Value is non-zero if we found at least one overlay string. */
2867 return STRINGP (it
->string
);
2872 /***********************************************************************
2873 Saving and restoring state
2874 ***********************************************************************/
2876 /* Save current settings of IT on IT->stack. Called, for example,
2877 before setting up IT for an overlay string, to be able to restore
2878 IT's settings to what they were after the overlay string has been
2885 struct iterator_stack_entry
*p
;
2887 xassert (it
->sp
< 2);
2888 p
= it
->stack
+ it
->sp
;
2890 p
->stop_charpos
= it
->stop_charpos
;
2891 xassert (it
->face_id
>= 0);
2892 p
->face_id
= it
->face_id
;
2893 p
->string
= it
->string
;
2894 p
->pos
= it
->current
;
2895 p
->end_charpos
= it
->end_charpos
;
2896 p
->string_nchars
= it
->string_nchars
;
2898 p
->multibyte_p
= it
->multibyte_p
;
2899 p
->space_width
= it
->space_width
;
2900 p
->font_height
= it
->font_height
;
2901 p
->voffset
= it
->voffset
;
2902 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
2907 /* Restore IT's settings from IT->stack. Called, for example, when no
2908 more overlay strings must be processed, and we return to delivering
2909 display elements from a buffer, or when the end of a string from a
2910 `display' property is reached and we return to delivering display
2911 elements from an overlay string, or from a buffer. */
2917 struct iterator_stack_entry
*p
;
2919 xassert (it
->sp
> 0);
2921 p
= it
->stack
+ it
->sp
;
2922 it
->stop_charpos
= p
->stop_charpos
;
2923 it
->face_id
= p
->face_id
;
2924 it
->string
= p
->string
;
2925 it
->current
= p
->pos
;
2926 it
->end_charpos
= p
->end_charpos
;
2927 it
->string_nchars
= p
->string_nchars
;
2929 it
->multibyte_p
= p
->multibyte_p
;
2930 it
->space_width
= p
->space_width
;
2931 it
->font_height
= p
->font_height
;
2932 it
->voffset
= p
->voffset
;
2933 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
2938 /***********************************************************************
2940 ***********************************************************************/
2942 /* Set IT's current position to the previous line start. */
2945 back_to_previous_line_start (it
)
2948 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
2949 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
2953 /* Set IT's current position to the next line start. */
2956 forward_to_next_line_start (it
)
2959 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), 1);
2960 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
2964 /* Set IT's current position to the previous visible line start. Skip
2965 invisible text that is so either due to text properties or due to
2966 selective display. Caution: this does not change IT->current_x and
2970 back_to_previous_visible_line_start (it
)
2975 /* Go back one newline if not on BEGV already. */
2976 if (IT_CHARPOS (*it
) > BEGV
)
2977 back_to_previous_line_start (it
);
2979 /* Move over lines that are invisible because of selective display
2980 or text properties. */
2981 while (IT_CHARPOS (*it
) > BEGV
2986 /* If selective > 0, then lines indented more than that values
2988 if (it
->selective
> 0
2989 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
2992 #ifdef USE_TEXT_PROPERTIES
2997 prop
= Fget_char_property (IT_CHARPOS (*it
), Qinvisible
, it
->window
);
2998 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3001 #endif /* USE_TEXT_PROPERTIES */
3003 /* Back one more newline if the current one is invisible. */
3005 back_to_previous_line_start (it
);
3008 xassert (IT_CHARPOS (*it
) >= BEGV
);
3009 xassert (IT_CHARPOS (*it
) == BEGV
3010 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3015 /* Reseat iterator IT at the previous visible line start. Skip
3016 invisible text that is so either due to text properties or due to
3017 selective display. At the end, update IT's overlay information,
3018 face information etc. */
3021 reseat_at_previous_visible_line_start (it
)
3024 back_to_previous_visible_line_start (it
);
3025 reseat (it
, it
->current
.pos
, 1);
3030 /* Reseat iterator IT on the next visible line start in the current
3031 buffer. Skip over invisible text that is so because of selective
3032 display. Compute faces, overlays etc at the new position. Note
3033 that this function does not skip over text that is invisible
3034 because of text properties. */
3037 reseat_at_next_visible_line_start (it
)
3040 /* Restore the buffer position when currently not delivering display
3041 elements from the current buffer. This is the case, for example,
3042 when called at the end of a truncated overlay string. */
3045 it
->method
= next_element_from_buffer
;
3047 /* Otherwise, scan_buffer would not work. */
3048 if (IT_CHARPOS (*it
) < ZV
)
3050 /* If on a newline, advance past it. Otherwise, find the next
3051 newline which automatically gives us the position following
3053 if (FETCH_BYTE (IT_BYTEPOS (*it
)) == '\n')
3059 forward_to_next_line_start (it
);
3061 /* We must either have reached the end of the buffer or end up
3063 xassert (IT_CHARPOS (*it
) == ZV
3064 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3066 /* Skip over lines that are invisible because they are indented
3067 more than the value of IT->selective. */
3068 if (it
->selective
> 0)
3069 while (IT_CHARPOS (*it
) < ZV
3070 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3072 forward_to_next_line_start (it
);
3074 /* Set the iterator there. The 0 as the last parameter of
3075 reseat means don't force a text property lookup. The lookup
3076 is then only done if we've skipped past the iterator's
3077 check_charpos'es. This optimization is important because
3078 text property lookups tend to be expensive. */
3079 reseat (it
, it
->current
.pos
, 0);
3087 /***********************************************************************
3088 Changing an iterator's position
3089 ***********************************************************************/
3091 /* Change IT's current position to POS in current_buffer. If FORCE_P
3092 is non-zero, always check for text properties at the new position.
3093 Otherwise, text properties are only looked up if POS >=
3094 IT->check_charpos of a property. */
3097 reseat (it
, pos
, force_p
)
3099 struct text_pos pos
;
3102 int original_pos
= IT_CHARPOS (*it
);
3104 reseat_1 (it
, pos
, 0);
3106 /* Determine where to check text properties. Avoid doing it
3107 where possible because text property lookup is very expensive. */
3109 || CHARPOS (pos
) > it
->stop_charpos
3110 || CHARPOS (pos
) < original_pos
)
3117 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3118 IT->stop_pos to POS, also. */
3121 reseat_1 (it
, pos
, set_stop_p
)
3123 struct text_pos pos
;
3126 /* Don't call this function when scanning a C string. */
3127 xassert (it
->s
== NULL
);
3129 /* POS must be a reasonable value. */
3130 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3132 it
->current
.pos
= it
->position
= pos
;
3133 XSETBUFFER (it
->object
, current_buffer
);
3135 it
->current
.dpvec_index
= -1;
3136 it
->current
.overlay_string_index
= -1;
3137 IT_STRING_CHARPOS (*it
) = -1;
3138 IT_STRING_BYTEPOS (*it
) = -1;
3140 it
->method
= next_element_from_buffer
;
3144 it
->stop_charpos
= CHARPOS (pos
);
3148 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3149 If S is non-null, it is a C string to iterate over. Otherwise,
3150 STRING gives a Lisp string to iterate over.
3152 If PRECISION > 0, don't return more then PRECISION number of
3153 characters from the string.
3155 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3156 characters have been returned. FIELD_WIDTH < 0 means an infinite
3159 MULTIBYTE = 0 means disable processing of multibyte characters,
3160 MULTIBYTE > 0 means enable it,
3161 MULTIBYTE < 0 means use IT->multibyte_p.
3163 IT must be initialized via a prior call to init_iterator before
3164 calling this function. */
3167 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3172 int precision
, field_width
, multibyte
;
3174 /* No region in strings. */
3175 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3177 /* No text property checks performed by default, but see below. */
3178 it
->stop_charpos
= -1;
3180 /* Set iterator position and end position. */
3181 bzero (&it
->current
, sizeof it
->current
);
3182 it
->current
.overlay_string_index
= -1;
3183 it
->current
.dpvec_index
= -1;
3184 it
->charset
= CHARSET_ASCII
;
3185 xassert (charpos
>= 0);
3187 /* Use the setting of MULTIBYTE if specified. */
3189 it
->multibyte_p
= multibyte
> 0;
3193 xassert (STRINGP (string
));
3194 it
->string
= string
;
3196 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3197 it
->method
= next_element_from_string
;
3198 it
->current
.string_pos
= string_pos (charpos
, string
);
3205 /* Note that we use IT->current.pos, not it->current.string_pos,
3206 for displaying C strings. */
3207 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3208 if (it
->multibyte_p
)
3210 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3211 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3215 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3216 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3219 it
->method
= next_element_from_c_string
;
3222 /* PRECISION > 0 means don't return more than PRECISION characters
3224 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3225 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3227 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3228 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3229 FIELD_WIDTH < 0 means infinite field width. This is useful for
3230 padding with `-' at the end of a mode line. */
3231 if (field_width
< 0)
3232 field_width
= INFINITY
;
3233 if (field_width
> it
->end_charpos
- charpos
)
3234 it
->end_charpos
= charpos
+ field_width
;
3236 /* Use the standard display table for displaying strings. */
3237 if (DISP_TABLE_P (Vstandard_display_table
))
3238 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3240 it
->stop_charpos
= charpos
;
3246 /***********************************************************************
3248 ***********************************************************************/
3250 /* Load IT's display element fields with information about the next
3251 display element from the current position of IT. Value is zero if
3252 end of buffer (or C string) is reached. */
3255 get_next_display_element (it
)
3258 /* Non-zero means that we found an display element. Zero means that
3259 we hit the end of what we iterate over. Performance note: the
3260 function pointer `method' used here turns out to be faster than
3261 using a sequence of if-statements. */
3262 int success_p
= (*it
->method
) (it
);
3265 if (it
->what
== IT_CHARACTER
)
3267 /* Map via display table or translate control characters.
3268 IT->c, IT->len etc. have been set to the next character by
3269 the function call above. If we have a display table, and it
3270 contains an entry for IT->c, translate it. Don't do this if
3271 IT->c itself comes from a display table, otherwise we could
3272 end up in an infinite recursion. (An alternative could be to
3273 count the recursion depth of this function and signal an
3274 error when a certain maximum depth is reached.) Is it worth
3276 if (success_p
&& it
->dpvec
== NULL
)
3281 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3284 struct Lisp_Vector
*v
= XVECTOR (dv
);
3286 /* Return the first character from the display table
3287 entry, if not empty. If empty, don't display the
3288 current character. */
3291 it
->dpvec_char_len
= it
->len
;
3292 it
->dpvec
= v
->contents
;
3293 it
->dpend
= v
->contents
+ v
->size
;
3294 it
->current
.dpvec_index
= 0;
3295 it
->method
= next_element_from_display_vector
;
3298 success_p
= get_next_display_element (it
);
3301 /* Translate control characters into `\003' or `^C' form.
3302 Control characters coming from a display table entry are
3303 currently not translated because we use IT->dpvec to hold
3304 the translation. This could easily be changed but I
3305 don't believe that it is worth doing. */
3306 else if ((it
->c
< ' '
3307 && (it
->area
!= TEXT_AREA
3314 /* IT->c is a control character which must be displayed
3315 either as '\003' or as `^C' where the '\\' and '^'
3316 can be defined in the display table. Fill
3317 IT->ctl_chars with glyphs for what we have to
3318 display. Then, set IT->dpvec to these glyphs. */
3321 if (it
->c
< 128 && it
->ctl_arrow_p
)
3323 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3325 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3326 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3327 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3329 g
= FAST_MAKE_GLYPH ('^', 0);
3330 XSETINT (it
->ctl_chars
[0], g
);
3332 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3333 XSETINT (it
->ctl_chars
[1], g
);
3335 /* Set up IT->dpvec and return first character from it. */
3336 it
->dpvec_char_len
= it
->len
;
3337 it
->dpvec
= it
->ctl_chars
;
3338 it
->dpend
= it
->dpvec
+ 2;
3339 it
->current
.dpvec_index
= 0;
3340 it
->method
= next_element_from_display_vector
;
3341 get_next_display_element (it
);
3345 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3347 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3348 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3349 g
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3351 g
= FAST_MAKE_GLYPH ('\\', 0);
3352 XSETINT (it
->ctl_chars
[0], g
);
3354 /* Insert three more glyphs into IT->ctl_chars for
3355 the octal display of the character. */
3356 g
= FAST_MAKE_GLYPH (((it
->c
>> 6) & 7) + '0', 0);
3357 XSETINT (it
->ctl_chars
[1], g
);
3358 g
= FAST_MAKE_GLYPH (((it
->c
>> 3) & 7) + '0', 0);
3359 XSETINT (it
->ctl_chars
[2], g
);
3360 g
= FAST_MAKE_GLYPH ((it
->c
& 7) + '0', 0);
3361 XSETINT (it
->ctl_chars
[3], g
);
3363 /* Set up IT->dpvec and return the first character
3365 it
->dpvec_char_len
= it
->len
;
3366 it
->dpvec
= it
->ctl_chars
;
3367 it
->dpend
= it
->dpvec
+ 4;
3368 it
->current
.dpvec_index
= 0;
3369 it
->method
= next_element_from_display_vector
;
3370 get_next_display_element (it
);
3375 /* Adjust face id if charset changes. There are no charset
3376 changes in unibyte text because Emacs' charsets are not
3377 applicable there. */
3380 && (charset
= CHAR_CHARSET (it
->c
),
3381 charset
!= it
->charset
))
3383 it
->charset
= charset
;
3384 it
->face_id
= FACE_FOR_CHARSET (it
->f
, it
->face_id
, charset
);
3388 /* Is this character the last one of a run of characters with
3389 box? If yes, set IT->end_of_box_run_p to 1. */
3396 it
->end_of_box_run_p
3397 = ((face_id
= face_after_it_pos (it
),
3398 face_id
!= it
->face_id
)
3399 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3400 face
->box
== FACE_NO_BOX
));
3403 /* Value is 0 if end of buffer or string reached. */
3408 /* Move IT to the next display element.
3410 Functions get_next_display_element and set_iterator_to_next are
3411 separate because I find this arrangement easier to handle than a
3412 get_next_display_element function that also increments IT's
3413 position. The way it is we can first look at an iterator's current
3414 display element, decide whether it fits on a line, and if it does,
3415 increment the iterator position. The other way around we probably
3416 would either need a flag indicating whether the iterator has to be
3417 incremented the next time, or we would have to implement a
3418 decrement position function which would not be easy to write. */
3421 set_iterator_to_next (it
)
3424 if (it
->method
== next_element_from_buffer
)
3426 /* The current display element of IT is a character from
3427 current_buffer. Advance in the buffer, and maybe skip over
3428 invisible lines that are so because of selective display. */
3429 if (ITERATOR_AT_END_OF_LINE_P (it
))
3430 reseat_at_next_visible_line_start (it
);
3433 xassert (it
->len
!= 0);
3434 IT_BYTEPOS (*it
) += it
->len
;
3435 IT_CHARPOS (*it
) += 1;
3436 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3439 else if (it
->method
== next_element_from_c_string
)
3441 /* Current display element of IT is from a C string. */
3442 IT_BYTEPOS (*it
) += it
->len
;
3443 IT_CHARPOS (*it
) += 1;
3445 else if (it
->method
== next_element_from_display_vector
)
3447 /* Current display element of IT is from a display table entry.
3448 Advance in the display table definition. Reset it to null if
3449 end reached, and continue with characters from buffers/
3451 ++it
->current
.dpvec_index
;
3452 it
->face_id
= it
->saved_face_id
;
3453 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3456 it
->method
= next_element_from_c_string
;
3457 else if (STRINGP (it
->string
))
3458 it
->method
= next_element_from_string
;
3460 it
->method
= next_element_from_buffer
;
3463 it
->current
.dpvec_index
= -1;
3465 /* Consume the character which was displayed via IT->dpvec. */
3466 if (it
->dpvec_char_len
)
3468 it
->len
= it
->dpvec_char_len
;
3469 set_iterator_to_next (it
);
3473 else if (it
->method
== next_element_from_string
)
3475 /* Current display element is a character from a Lisp string. */
3476 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3477 IT_STRING_BYTEPOS (*it
) += it
->len
;
3478 IT_STRING_CHARPOS (*it
) += 1;
3480 consider_string_end
:
3482 if (it
->current
.overlay_string_index
>= 0)
3484 /* IT->string is an overlay string. Advance to the
3485 next, if there is one. */
3486 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3487 next_overlay_string (it
);
3491 /* IT->string is not an overlay string. If we reached
3492 its end, and there is something on IT->stack, proceed
3493 with what is on the stack. This can be either another
3494 string, this time an overlay string, or a buffer. */
3495 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3499 if (!STRINGP (it
->string
))
3500 it
->method
= next_element_from_buffer
;
3504 else if (it
->method
== next_element_from_image
3505 || it
->method
== next_element_from_stretch
)
3507 /* The position etc with which we have to proceed are on
3508 the stack. The position may be at the end of a string,
3509 if the `display' property takes up the whole string. */
3512 if (STRINGP (it
->string
))
3514 it
->method
= next_element_from_string
;
3515 goto consider_string_end
;
3518 it
->method
= next_element_from_buffer
;
3521 /* There are no other methods defined, so this should be a bug. */
3524 /* Reset flags indicating start and end of a sequence of
3525 characters with box. */
3526 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3528 xassert (it
->method
!= next_element_from_string
3529 || (STRINGP (it
->string
)
3530 && IT_STRING_CHARPOS (*it
) >= 0));
3534 /* Load IT's display element fields with information about the next
3535 display element which comes from a display table entry or from the
3536 result of translating a control character to one of the forms `^C'
3537 or `\003'. IT->dpvec holds the glyphs to return as characters. */
3540 next_element_from_display_vector (it
)
3544 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
3546 /* Remember the current face id in case glyphs specify faces.
3547 IT's face is restored in set_iterator_to_next. */
3548 it
->saved_face_id
= it
->face_id
;
3550 if (INTEGERP (*it
->dpvec
)
3551 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
3556 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
3557 it
->c
= FAST_GLYPH_CHAR (g
);
3558 it
->len
= CHAR_LEN (it
->c
);
3560 /* The entry may contain a face id to use. Such a face id is
3561 the id of a Lisp face, not a realized face. A face id of
3562 zero means no face. */
3563 lface_id
= FAST_GLYPH_FACE (g
);
3566 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
3569 it
->face_id
= face_id
;
3570 it
->charset
= CHARSET_ASCII
;
3575 /* Display table entry is invalid. Return a space. */
3576 it
->c
= ' ', it
->len
= 1;
3578 /* Don't change position and object of the iterator here. They are
3579 still the values of the character that had this display table
3580 entry or was translated, and that's what we want. */
3581 it
->what
= IT_CHARACTER
;
3586 /* Load IT with the next display element from Lisp string IT->string.
3587 IT->current.string_pos is the current position within the string.
3588 If IT->current.overlay_string_index >= 0, the Lisp string is an
3592 next_element_from_string (it
)
3595 struct text_pos position
;
3597 xassert (STRINGP (it
->string
));
3598 xassert (IT_STRING_CHARPOS (*it
) >= 0);
3599 position
= it
->current
.string_pos
;
3601 /* Time to check for invisible text? */
3602 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
3603 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
3607 /* Since a handler may have changed IT->method, we must
3609 return get_next_display_element (it
);
3612 if (it
->current
.overlay_string_index
>= 0)
3614 /* Get the next character from an overlay string. In overlay
3615 strings, There is no field width or padding with spaces to
3617 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3622 else if (STRING_MULTIBYTE (it
->string
))
3624 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
3625 - IT_STRING_BYTEPOS (*it
));
3626 unsigned char *s
= (XSTRING (it
->string
)->data
3627 + IT_STRING_BYTEPOS (*it
));
3628 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
3632 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3638 /* Get the next character from a Lisp string that is not an
3639 overlay string. Such strings come from the mode line, for
3640 example. We may have to pad with spaces, or truncate the
3641 string. See also next_element_from_c_string. */
3642 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
3647 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
3649 /* Pad with spaces. */
3650 it
->c
= ' ', it
->len
= 1;
3651 CHARPOS (position
) = BYTEPOS (position
) = -1;
3653 else if (STRING_MULTIBYTE (it
->string
))
3655 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
3656 - IT_STRING_BYTEPOS (*it
));
3657 unsigned char *s
= (XSTRING (it
->string
)->data
3658 + IT_STRING_BYTEPOS (*it
));
3659 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
3663 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3668 /* Record what we have and where it came from. Note that we store a
3669 buffer position in IT->position although it could arguably be a
3671 it
->what
= IT_CHARACTER
;
3672 it
->object
= it
->string
;
3673 it
->position
= position
;
3678 /* Load IT with next display element from C string IT->s.
3679 IT->string_nchars is the maximum number of characters to return
3680 from the string. IT->end_charpos may be greater than
3681 IT->string_nchars when this function is called, in which case we
3682 may have to return padding spaces. Value is zero if end of string
3683 reached, including padding spaces. */
3686 next_element_from_c_string (it
)
3692 it
->what
= IT_CHARACTER
;
3693 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
3696 /* IT's position can be greater IT->string_nchars in case a field
3697 width or precision has been specified when the iterator was
3699 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3701 /* End of the game. */
3705 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
3707 /* Pad with spaces. */
3708 it
->c
= ' ', it
->len
= 1;
3709 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
3711 else if (it
->multibyte_p
)
3713 /* Implementation note: The calls to strlen apparently aren't a
3714 performance problem because there is no noticeable performance
3715 difference between Emacs running in unibyte or multibyte mode. */
3716 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
3717 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
3721 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
3727 /* Set up IT to return characters from an ellipsis, if appropriate.
3728 The definition of the ellipsis glyphs may come from a display table
3729 entry. This function Fills IT with the first glyph from the
3730 ellipsis if an ellipsis is to be displayed. */
3733 next_element_from_ellipsis (it
)
3736 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3738 /* Use the display table definition for `...'. Invalid glyphs
3739 will be handled by the method returning elements from dpvec. */
3740 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3741 it
->dpvec_char_len
= it
->len
;
3742 it
->dpvec
= v
->contents
;
3743 it
->dpend
= v
->contents
+ v
->size
;
3744 it
->current
.dpvec_index
= 0;
3745 it
->method
= next_element_from_display_vector
;
3746 get_next_display_element (it
);
3748 else if (it
->selective_display_ellipsis_p
)
3750 /* Use default `...' which is stored in default_invis_vector. */
3751 it
->dpvec_char_len
= it
->len
;
3752 it
->dpvec
= default_invis_vector
;
3753 it
->dpend
= default_invis_vector
+ 3;
3754 it
->current
.dpvec_index
= 0;
3755 it
->method
= next_element_from_display_vector
;
3756 get_next_display_element (it
);
3761 /* Deliver an image display element. The iterator IT is already
3762 filled with image information (done in handle_display_prop). Value
3767 next_element_from_image (it
)
3770 it
->what
= IT_IMAGE
;
3775 /* Fill iterator IT with next display element from a stretch glyph
3776 property. IT->object is the value of the text property. Value is
3780 next_element_from_stretch (it
)
3783 it
->what
= IT_STRETCH
;
3788 /* Load IT with the next display element from current_buffer. Value
3789 is zero if end of buffer reached. IT->stop_charpos is the next
3790 position at which to stop and check for text properties or buffer
3794 next_element_from_buffer (it
)
3799 /* Check this assumption, otherwise, we would never enter the
3800 if-statement, below. */
3801 xassert (IT_CHARPOS (*it
) >= BEGV
3802 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
3804 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
3806 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3808 int overlay_strings_follow_p
;
3810 /* End of the game, except when overlay strings follow that
3811 haven't been returned yet. */
3812 if (it
->overlay_strings_at_end_processed_p
)
3813 overlay_strings_follow_p
= 0;
3816 it
->overlay_strings_at_end_processed_p
= 1;
3817 overlay_strings_follow_p
3818 = get_overlay_strings (it
);
3821 if (overlay_strings_follow_p
)
3822 success_p
= get_next_display_element (it
);
3826 it
->position
= it
->current
.pos
;
3833 return get_next_display_element (it
);
3838 /* No face changes, overlays etc. in sight, so just return a
3839 character from current_buffer. */
3842 /* Maybe run the redisplay end trigger hook. Performance note:
3843 This doesn't seem to cost measurable time. */
3844 if (it
->redisplay_end_trigger_charpos
3846 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
3847 run_redisplay_end_trigger_hook (it
);
3849 /* Get the next character, maybe multibyte. */
3850 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
3851 if (it
->multibyte_p
)
3853 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
3854 - IT_BYTEPOS (*it
));
3855 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
3858 it
->c
= *p
, it
->len
= 1;
3860 /* Record what we have and where it came from. */
3861 it
->what
= IT_CHARACTER
;;
3862 it
->object
= it
->w
->buffer
;
3863 it
->position
= it
->current
.pos
;
3865 /* Normally we return the character found above, except when we
3866 really want to return an ellipsis for selective display. */
3871 /* A value of selective > 0 means hide lines indented more
3872 than that number of columns. */
3873 if (it
->selective
> 0
3874 && IT_CHARPOS (*it
) + 1 < ZV
3875 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
3876 IT_BYTEPOS (*it
) + 1,
3878 next_element_from_ellipsis (it
);
3880 else if (it
->c
== '\r' && it
->selective
== -1)
3882 /* A value of selective == -1 means that everything from the
3883 CR to the end of the line is invisible, with maybe an
3884 ellipsis displayed for it. */
3885 next_element_from_ellipsis (it
);
3890 /* Value is zero if end of buffer reached. */
3891 xassert (!success_p
|| it
->len
> 0);
3896 /* Run the redisplay end trigger hook for IT. */
3899 run_redisplay_end_trigger_hook (it
)
3902 Lisp_Object args
[3];
3904 /* IT->glyph_row should be non-null, i.e. we should be actually
3905 displaying something, or otherwise we should not run the hook. */
3906 xassert (it
->glyph_row
);
3908 /* Set up hook arguments. */
3909 args
[0] = Qredisplay_end_trigger_functions
;
3910 args
[1] = it
->window
;
3911 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
3912 it
->redisplay_end_trigger_charpos
= 0;
3914 /* Since we are *trying* to run these functions, don't try to run
3915 them again, even if they get an error. */
3916 it
->w
->redisplay_end_trigger
= Qnil
;
3917 Frun_hook_with_args (3, args
);
3919 /* Notice if it changed the face of the character we are on. */
3920 handle_face_prop (it
);
3925 /***********************************************************************
3926 Moving an iterator without producing glyphs
3927 ***********************************************************************/
3929 /* Move iterator IT to a specified buffer or X position within one
3930 line on the display without producing glyphs.
3932 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
3933 whichever is reached first.
3935 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
3937 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
3938 0 <= TO_X <= IT->last_visible_x. This means in particular, that
3939 TO_X includes the amount by which a window is horizontally
3944 MOVE_POS_MATCH_OR_ZV
3945 - when TO_POS or ZV was reached.
3948 -when TO_X was reached before TO_POS or ZV were reached.
3951 - when we reached the end of the display area and the line must
3955 - when we reached the end of the display area and the line is
3959 - when we stopped at a line end, i.e. a newline or a CR and selective
3963 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
3965 int to_charpos
, to_x
, op
;
3967 enum move_it_result result
= MOVE_UNDEFINED
;
3968 struct glyph_row
*saved_glyph_row
;
3970 /* Don't produce glyphs in produce_glyphs. */
3971 saved_glyph_row
= it
->glyph_row
;
3972 it
->glyph_row
= NULL
;
3974 #if NO_PROMPT_IN_BUFFER
3975 /* Take a mini-buffer prompt into account. */
3976 if (MINI_WINDOW_P (it
->w
)
3977 && IT_CHARPOS (*it
) == BEGV
)
3979 it
->current_x
= minibuf_prompt_pixel_width
;
3980 it
->hpos
= minibuf_prompt_width
;
3988 /* Stop when ZV or TO_CHARPOS reached. */
3989 if (!get_next_display_element (it
)
3990 || ((op
& MOVE_TO_POS
) != 0
3991 && BUFFERP (it
->object
)
3992 && IT_CHARPOS (*it
) >= to_charpos
))
3994 result
= MOVE_POS_MATCH_OR_ZV
;
3998 /* The call to produce_glyphs will get the metrics of the
3999 display element IT is loaded with. We record in x the
4000 x-position before this display element in case it does not
4003 PRODUCE_GLYPHS (it
);
4005 if (it
->area
!= TEXT_AREA
)
4007 set_iterator_to_next (it
);
4011 /* The number of glyphs we get back in IT->nglyphs will normally
4012 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4013 character on a terminal frame, or (iii) a line end. For the
4014 second case, IT->nglyphs - 1 padding glyphs will be present
4015 (on X frames, there is only one glyph produced for a
4016 composite character.
4018 The behavior implemented below means, for continuation lines,
4019 that as many spaces of a TAB as fit on the current line are
4020 displayed there. For terminal frames, as many glyphs of a
4021 multi-glyph character are displayed in the current line, too.
4022 This is what the old redisplay code did, and we keep it that
4023 way. Under X, the whole shape of a complex character must
4024 fit on the line or it will be completely displayed in the
4027 Note that both for tabs and padding glyphs, all glyphs have
4031 /* More than one glyph or glyph doesn't fit on line. All
4032 glyphs have the same width. */
4033 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4036 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4038 new_x
= x
+ single_glyph_width
;
4040 /* We want to leave anything reaching TO_X to the caller. */
4041 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4044 result
= MOVE_X_REACHED
;
4047 else if (/* Lines are continued. */
4048 !it
->truncate_lines_p
4049 && (/* And glyph doesn't fit on the line. */
4050 new_x
> it
->last_visible_x
4051 /* Or it fits exactly and we're on a window
4053 || (new_x
== it
->last_visible_x
4054 && FRAME_WINDOW_P (it
->f
))))
4056 if (/* IT->hpos == 0 means the very first glyph
4057 doesn't fit on the line, e.g. a wide image. */
4059 || (new_x
== it
->last_visible_x
4060 && FRAME_WINDOW_P (it
->f
)))
4063 it
->current_x
= new_x
;
4064 if (i
== it
->nglyphs
- 1)
4065 set_iterator_to_next (it
);
4070 result
= MOVE_LINE_CONTINUED
;
4073 else if (new_x
> it
->first_visible_x
)
4075 /* Glyph is visible. Increment number of glyphs that
4076 would be displayed. */
4081 /* Glyph is completely off the left margin of the display
4082 area. Nothing to do. */
4086 if (result
!= MOVE_UNDEFINED
)
4089 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4091 /* Stop when TO_X specified and reached. This check is
4092 necessary here because of lines consisting of a line end,
4093 only. The line end will not produce any glyphs and we
4094 would never get MOVE_X_REACHED. */
4095 xassert (it
->nglyphs
== 0);
4096 result
= MOVE_X_REACHED
;
4100 /* Is this a line end? If yes, we're done. */
4101 if (ITERATOR_AT_END_OF_LINE_P (it
))
4103 result
= MOVE_NEWLINE_OR_CR
;
4107 /* The current display element has been consumed. Advance
4109 set_iterator_to_next (it
);
4111 /* Stop if lines are truncated and IT's current x-position is
4112 past the right edge of the window now. */
4113 if (it
->truncate_lines_p
4114 && it
->current_x
>= it
->last_visible_x
)
4116 result
= MOVE_LINE_TRUNCATED
;
4121 /* Restore the iterator settings altered at the beginning of this
4123 it
->glyph_row
= saved_glyph_row
;
4128 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4129 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4130 the description of enum move_operation_enum.
4132 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4133 screen line, this function will set IT to the next position >
4137 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4139 int to_charpos
, to_x
, to_y
, to_vpos
;
4142 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4145 xassert (XBUFFER (it
->w
->buffer
) == current_buffer
);
4149 if (op
& MOVE_TO_VPOS
)
4151 /* If no TO_CHARPOS and no TO_X specified, stop at the
4152 start of the line TO_VPOS. */
4153 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4155 if (it
->vpos
== to_vpos
)
4157 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4161 /* TO_VPOS >= 0 means stop at TO_X in the line at
4162 TO_VPOS, or at TO_POS, whichever comes first. */
4163 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4165 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4167 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4169 /* We have reached TO_X but not in the line we want. */
4170 skip
= move_it_in_display_line_to (it
, to_charpos
,
4172 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4177 else if (op
& MOVE_TO_Y
)
4179 struct it it_backup
;
4182 /* TO_Y specified means stop at TO_X in the line containing
4183 TO_Y---or at TO_CHARPOS if this is reached first. The
4184 problem is that we can't really tell whether the line
4185 contains TO_Y before we have completely scanned it, and
4186 this may skip past TO_X. What we do is to first scan to
4189 If TO_X is not specified, use a TO_X of zero. The reason
4190 is to make the outcome of this function more predictable.
4191 If we didn't use TO_X == 0, we would stop at the end of
4192 the line which is probably not what a caller would expect
4194 skip
= move_it_in_display_line_to (it
, to_charpos
,
4198 | (op
& MOVE_TO_POS
)));
4200 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4201 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4204 /* If TO_X was reached, we would like to know whether TO_Y
4205 is in the line. This can only be said if we know the
4206 total line height which requires us to scan the rest of
4209 if (skip
== MOVE_X_REACHED
)
4212 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4216 /* Now, decide whether TO_Y is in this line. */
4217 line_height
= it
->max_ascent
+ it
->max_descent
;
4219 if (to_y
>= it
->current_y
4220 && to_y
< it
->current_y
+ line_height
)
4222 if (skip
== MOVE_X_REACHED
)
4223 /* If TO_Y is in this line and TO_X was reached above,
4224 we scanned too far. We have to restore IT's settings
4225 to the ones before skipping. */
4229 else if (skip
== MOVE_X_REACHED
)
4232 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4240 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4244 case MOVE_POS_MATCH_OR_ZV
:
4247 case MOVE_NEWLINE_OR_CR
:
4248 set_iterator_to_next (it
);
4249 it
->continuation_lines_width
= 0;
4252 case MOVE_LINE_TRUNCATED
:
4253 it
->continuation_lines_width
= 0;
4254 reseat_at_next_visible_line_start (it
);
4255 if ((op
& MOVE_TO_POS
) != 0
4256 && IT_CHARPOS (*it
) > to_charpos
)
4260 case MOVE_LINE_CONTINUED
:
4261 it
->continuation_lines_width
+= it
->current_x
;
4268 /* Reset/increment for the next run. */
4269 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4270 it
->current_x
= it
->hpos
= 0;
4271 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4273 last_height
= it
->max_ascent
+ it
->max_descent
;
4274 last_max_ascent
= it
->max_ascent
;
4275 it
->max_ascent
= it
->max_descent
= 0;
4281 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4283 If DY > 0, move IT backward at least that many pixels. DY = 0
4284 means move IT backward to the preceding line start or BEGV. This
4285 function may move over more than DY pixels if IT->current_y - DY
4286 ends up in the middle of a line; in this case IT->current_y will be
4287 set to the top of the line moved to. */
4290 move_it_vertically_backward (it
, dy
)
4294 int nlines
, h
, line_height
;
4296 int start_pos
= IT_CHARPOS (*it
);
4300 /* Estimate how many newlines we must move back. */
4301 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4303 /* Set the iterator's position that many lines back. */
4304 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4305 back_to_previous_visible_line_start (it
);
4307 /* Reseat the iterator here. When moving backward, we don't want
4308 reseat to skip forward over invisible text, set up the iterator
4309 to deliver from overlay strings at the new position etc. So,
4310 use reseat_1 here. */
4311 reseat_1 (it
, it
->current
.pos
, 1);
4313 /* We are now surely at a line start. */
4314 it
->current_x
= it
->hpos
= 0;
4316 /* Move forward and see what y-distance we moved. First move to the
4317 start of the next line so that we get its height. We need this
4318 height to be able to tell whether we reached the specified
4321 it2
.max_ascent
= it2
.max_descent
= 0;
4322 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4323 MOVE_TO_POS
| MOVE_TO_VPOS
);
4324 xassert (IT_CHARPOS (*it
) >= BEGV
);
4325 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4326 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4327 xassert (IT_CHARPOS (*it
) >= BEGV
);
4328 h
= it2
.current_y
- it
->current_y
;
4329 nlines
= it2
.vpos
- it
->vpos
;
4331 /* Correct IT's y and vpos position. */
4337 /* DY == 0 means move to the start of the screen line. The
4338 value of nlines is > 0 if continuation lines were involved. */
4340 move_it_by_lines (it
, nlines
, 1);
4341 xassert (IT_CHARPOS (*it
) <= start_pos
);
4345 /* The y-position we try to reach. Note that h has been
4346 subtracted in front of the if-statement. */
4347 int target_y
= it
->current_y
+ h
- dy
;
4349 /* If we did not reach target_y, try to move further backward if
4350 we can. If we moved too far backward, try to move forward. */
4351 if (target_y
< it
->current_y
4352 && IT_CHARPOS (*it
) > BEGV
)
4354 move_it_vertically (it
, target_y
- it
->current_y
);
4355 xassert (IT_CHARPOS (*it
) >= BEGV
);
4357 else if (target_y
>= it
->current_y
+ line_height
4358 && IT_CHARPOS (*it
) < ZV
)
4360 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4361 xassert (IT_CHARPOS (*it
) >= BEGV
);
4367 /* Move IT by a specified amount of pixel lines DY. DY negative means
4368 move backwards. DY = 0 means move to start of screen line. At the
4369 end, IT will be on the start of a screen line. */
4372 move_it_vertically (it
, dy
)
4377 move_it_vertically_backward (it
, -dy
);
4380 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4381 MOVE_TO_POS
| MOVE_TO_Y
);
4383 /* If buffer ends in ZV without a newline, move to the start of
4384 the line to satisfy the post-condition. */
4385 if (IT_CHARPOS (*it
) == ZV
4386 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4387 move_it_by_lines (it
, 0, 0);
4392 /* Return non-zero if some text between buffer positions START_CHARPOS
4393 and END_CHARPOS is invisible. IT->window is the window for text
4397 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4399 int start_charpos
, end_charpos
;
4401 #ifdef USE_TEXT_PROPERTIES
4402 Lisp_Object prop
, limit
;
4403 int invisible_found_p
;
4405 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4407 /* Is text at START invisible? */
4408 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4410 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4411 invisible_found_p
= 1;
4414 limit
= Fnext_single_property_change (make_number (start_charpos
),
4417 make_number (end_charpos
));
4418 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4421 return invisible_found_p
;
4423 #else /* not USE_TEXT_PROPERTIES */
4425 #endif /* not USE_TEXT_PROPERTIES */
4429 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4430 negative means move up. DVPOS == 0 means move to the start of the
4431 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4432 NEED_Y_P is zero, IT->current_y will be left unchanged.
4434 Further optimization ideas: If we would know that IT->f doesn't use
4435 a face with proportional font, we could be faster for
4436 truncate-lines nil. */
4439 move_it_by_lines (it
, dvpos
, need_y_p
)
4441 int dvpos
, need_y_p
;
4443 struct position pos
;
4445 if (!FRAME_WINDOW_P (it
->f
))
4447 struct text_pos textpos
;
4449 /* We can use vmotion on frames without proportional fonts. */
4450 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4451 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4452 reseat (it
, textpos
, 1);
4453 it
->vpos
+= pos
.vpos
;
4454 it
->current_y
+= pos
.vpos
;
4456 else if (dvpos
== 0)
4458 /* DVPOS == 0 means move to the start of the screen line. */
4459 move_it_vertically_backward (it
, 0);
4460 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4464 /* If there are no continuation lines, and if there is no
4465 selective display, try the simple method of moving forward
4466 DVPOS newlines, then see where we are. */
4467 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4469 int shortage
= 0, charpos
;
4471 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
4472 charpos
= IT_CHARPOS (*it
) + 1;
4474 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
4477 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
4479 struct text_pos pos
;
4480 CHARPOS (pos
) = charpos
;
4481 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4482 reseat (it
, pos
, 1);
4483 it
->vpos
+= dvpos
- shortage
;
4484 it
->hpos
= it
->current_x
= 0;
4489 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
4494 int start_charpos
, i
;
4496 /* If there are no continuation lines, and if there is no
4497 selective display, try the simple method of moving backward
4499 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4502 int charpos
= IT_CHARPOS (*it
);
4503 int bytepos
= IT_BYTEPOS (*it
);
4505 /* If in the middle of a line, go to its start. */
4506 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
4508 charpos
= find_next_newline_no_quit (charpos
, -1);
4509 bytepos
= CHAR_TO_BYTE (charpos
);
4512 if (charpos
== BEGV
)
4514 struct text_pos pos
;
4515 CHARPOS (pos
) = charpos
;
4516 BYTEPOS (pos
) = bytepos
;
4517 reseat (it
, pos
, 1);
4518 it
->hpos
= it
->current_x
= 0;
4523 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
4524 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
4526 struct text_pos pos
;
4527 CHARPOS (pos
) = charpos
;
4528 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4529 reseat (it
, pos
, 1);
4530 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
4531 it
->hpos
= it
->current_x
= 0;
4537 /* Go back -DVPOS visible lines and reseat the iterator there. */
4538 start_charpos
= IT_CHARPOS (*it
);
4539 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
4540 back_to_previous_visible_line_start (it
);
4541 reseat (it
, it
->current
.pos
, 1);
4542 it
->current_x
= it
->hpos
= 0;
4544 /* Above call may have moved too far if continuation lines
4545 are involved. Scan forward and see if it did. */
4547 it2
.vpos
= it2
.current_y
= 0;
4548 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
4549 it
->vpos
-= it2
.vpos
;
4550 it
->current_y
-= it2
.current_y
;
4551 it
->current_x
= it
->hpos
= 0;
4553 /* If we moved too far, move IT some lines forward. */
4554 if (it2
.vpos
> -dvpos
)
4556 int delta
= it2
.vpos
+ dvpos
;
4557 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
4564 /***********************************************************************
4566 ***********************************************************************/
4569 /* Output a newline in the *Messages* buffer if "needs" one. */
4572 message_log_maybe_newline ()
4574 if (message_log_need_newline
)
4575 message_dolog ("", 0, 1, 0);
4579 /* Add a string M of length LEN to the message log, optionally
4580 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
4581 nonzero, means interpret the contents of M as multibyte. This
4582 function calls low-level routines in order to bypass text property
4583 hooks, etc. which might not be safe to run. */
4586 message_dolog (m
, len
, nlflag
, multibyte
)
4588 int len
, nlflag
, multibyte
;
4590 if (!NILP (Vmessage_log_max
))
4592 struct buffer
*oldbuf
;
4593 Lisp_Object oldpoint
, oldbegv
, oldzv
;
4594 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4595 int point_at_end
= 0;
4597 Lisp_Object old_deactivate_mark
, tem
;
4598 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4600 old_deactivate_mark
= Vdeactivate_mark
;
4601 oldbuf
= current_buffer
;
4602 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
4603 current_buffer
->undo_list
= Qt
;
4605 oldpoint
= Fpoint_marker ();
4606 oldbegv
= Fpoint_min_marker ();
4607 oldzv
= Fpoint_max_marker ();
4608 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
4616 BEGV_BYTE
= BEG_BYTE
;
4619 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4621 /* Insert the string--maybe converting multibyte to single byte
4622 or vice versa, so that all the text fits the buffer. */
4624 && NILP (current_buffer
->enable_multibyte_characters
))
4627 unsigned char work
[1];
4629 /* Convert a multibyte string to single-byte
4630 for the *Message* buffer. */
4631 for (i
= 0; i
< len
; i
+= nbytes
)
4633 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
4634 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
4636 : multibyte_char_to_unibyte (c
, Qnil
));
4637 insert_1_both (work
, 1, 1, 1, 0, 0);
4640 else if (! multibyte
4641 && ! NILP (current_buffer
->enable_multibyte_characters
))
4644 unsigned char *msg
= (unsigned char *) m
;
4645 unsigned char *str
, work
[4];
4646 /* Convert a single-byte string to multibyte
4647 for the *Message* buffer. */
4648 for (i
= 0; i
< len
; i
++)
4650 c
= unibyte_char_to_multibyte (msg
[i
]);
4651 nbytes
= CHAR_STRING (c
, work
, str
);
4652 insert_1_both (work
, 1, nbytes
, 1, 0, 0);
4656 insert_1 (m
, len
, 1, 0, 0);
4660 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
4661 insert_1 ("\n", 1, 1, 0, 0);
4663 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4665 this_bol_byte
= PT_BYTE
;
4669 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4671 prev_bol_byte
= PT_BYTE
;
4673 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
4674 this_bol
, this_bol_byte
);
4677 del_range_both (prev_bol
, prev_bol_byte
,
4678 this_bol
, this_bol_byte
, 0);
4684 /* If you change this format, don't forget to also
4685 change message_log_check_duplicate. */
4686 sprintf (dupstr
, " [%d times]", dup
);
4687 duplen
= strlen (dupstr
);
4688 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
4689 insert_1 (dupstr
, duplen
, 1, 0, 1);
4694 if (NATNUMP (Vmessage_log_max
))
4696 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
4697 -XFASTINT (Vmessage_log_max
) - 1, 0);
4698 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
4701 BEGV
= XMARKER (oldbegv
)->charpos
;
4702 BEGV_BYTE
= marker_byte_position (oldbegv
);
4711 ZV
= XMARKER (oldzv
)->charpos
;
4712 ZV_BYTE
= marker_byte_position (oldzv
);
4716 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4718 /* We can't do Fgoto_char (oldpoint) because it will run some
4720 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
4721 XMARKER (oldpoint
)->bytepos
);
4724 free_marker (oldpoint
);
4725 free_marker (oldbegv
);
4726 free_marker (oldzv
);
4728 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
4729 set_buffer_internal (oldbuf
);
4731 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
4732 message_log_need_newline
= !nlflag
;
4733 Vdeactivate_mark
= old_deactivate_mark
;
4738 /* We are at the end of the buffer after just having inserted a newline.
4739 (Note: We depend on the fact we won't be crossing the gap.)
4740 Check to see if the most recent message looks a lot like the previous one.
4741 Return 0 if different, 1 if the new one should just replace it, or a
4742 value N > 1 if we should also append " [N times]". */
4745 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
4746 int prev_bol
, this_bol
;
4747 int prev_bol_byte
, this_bol_byte
;
4750 int len
= Z_BYTE
- 1 - this_bol_byte
;
4752 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
4753 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
4755 for (i
= 0; i
< len
; i
++)
4757 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
4766 if (*p1
++ == ' ' && *p1
++ == '[')
4769 while (*p1
>= '0' && *p1
<= '9')
4770 n
= n
* 10 + *p1
++ - '0';
4771 if (strncmp (p1
, " times]\n", 8) == 0)
4778 /* Display an echo area message M with a specified length of LEN
4779 chars. The string may include null characters. If M is 0, clear
4780 out any existing message, and let the mini-buffer text show through.
4782 The buffer M must continue to exist until after the echo area gets
4783 cleared or some other message gets displayed there. This means do
4784 not pass text that is stored in a Lisp string; do not pass text in
4785 a buffer that was alloca'd. */
4788 message2 (m
, len
, multibyte
)
4793 /* First flush out any partial line written with print. */
4794 message_log_maybe_newline ();
4796 message_dolog (m
, len
, 1, multibyte
);
4797 message2_nolog (m
, len
, multibyte
);
4801 /* The non-logging counterpart of message2. */
4804 message2_nolog (m
, len
, multibyte
)
4808 message_enable_multibyte
= multibyte
;
4812 if (noninteractive_need_newline
)
4813 putc ('\n', stderr
);
4814 noninteractive_need_newline
= 0;
4816 fwrite (m
, len
, 1, stderr
);
4817 if (cursor_in_echo_area
== 0)
4818 fprintf (stderr
, "\n");
4821 /* A null message buffer means that the frame hasn't really been
4822 initialized yet. Error messages get reported properly by
4823 cmd_error, so this must be just an informative message; toss it. */
4824 else if (INTERACTIVE
4825 && selected_frame
->glyphs_initialized_p
4826 && FRAME_MESSAGE_BUF (selected_frame
))
4828 Lisp_Object mini_window
;
4831 /* Get the frame containing the mini-buffer
4832 that the selected frame is using. */
4833 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
4834 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4836 FRAME_SAMPLE_VISIBILITY (f
);
4837 if (FRAME_VISIBLE_P (selected_frame
)
4838 && ! FRAME_VISIBLE_P (f
))
4839 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
4843 echo_area_glyphs
= m
;
4844 echo_area_glyphs_length
= len
;
4845 echo_area_message
= Qnil
;
4847 if (minibuffer_auto_raise
)
4848 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
4852 echo_area_glyphs
= previous_echo_glyphs
= NULL
;
4853 echo_area_message
= previous_echo_area_message
= Qnil
;
4856 do_pending_window_change ();
4857 echo_area_display (1);
4858 do_pending_window_change ();
4859 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
4860 (*frame_up_to_date_hook
) (f
);
4865 /* Display an echo area message M with a specified length of LEN
4866 chars. The string may include null characters. If M is not a
4867 string, clear out any existing message, and let the mini-buffer
4868 text show through. */
4871 message3 (m
, len
, multibyte
)
4876 struct gcpro gcpro1
;
4880 /* First flush out any partial line written with print. */
4881 message_log_maybe_newline ();
4883 message_dolog (XSTRING (m
)->data
, len
, 1, multibyte
);
4884 message3_nolog (m
, len
, multibyte
);
4890 /* The non-logging version of message3. */
4893 message3_nolog (m
, len
, multibyte
)
4897 message_enable_multibyte
= multibyte
;
4901 if (noninteractive_need_newline
)
4902 putc ('\n', stderr
);
4903 noninteractive_need_newline
= 0;
4905 fwrite (XSTRING (m
)->data
, len
, 1, stderr
);
4906 if (cursor_in_echo_area
== 0)
4907 fprintf (stderr
, "\n");
4910 /* A null message buffer means that the frame hasn't really been
4911 initialized yet. Error messages get reported properly by
4912 cmd_error, so this must be just an informative message; toss it. */
4913 else if (INTERACTIVE
4914 && selected_frame
->glyphs_initialized_p
4915 && FRAME_MESSAGE_BUF (selected_frame
))
4917 Lisp_Object mini_window
;
4920 /* Get the frame containing the mini-buffer
4921 that the selected frame is using. */
4922 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
4923 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4925 FRAME_SAMPLE_VISIBILITY (f
);
4926 if (FRAME_VISIBLE_P (selected_frame
)
4927 && ! FRAME_VISIBLE_P (f
))
4928 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
4932 echo_area_glyphs
= NULL
;
4933 echo_area_message
= m
;
4934 echo_area_glyphs_length
= len
;
4936 if (minibuffer_auto_raise
)
4937 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
4941 echo_area_glyphs
= previous_echo_glyphs
= NULL
;
4942 echo_area_message
= previous_echo_area_message
= Qnil
;
4945 do_pending_window_change ();
4946 echo_area_display (1);
4947 do_pending_window_change ();
4948 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
4949 (*frame_up_to_date_hook
) (f
);
4954 /* Display a null-terminated echo area message M. If M is 0, clear
4955 out any existing message, and let the mini-buffer text show through.
4957 The buffer M must continue to exist until after the echo area gets
4958 cleared or some other message gets displayed there. Do not pass
4959 text that is stored in a Lisp string. Do not pass text in a buffer
4960 that was alloca'd. */
4966 message2 (m
, (m
? strlen (m
) : 0), 0);
4970 /* The non-logging counterpart of message1. */
4976 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
4979 /* Display a message M which contains a single %s
4980 which gets replaced with STRING. */
4983 message_with_string (m
, string
, log
)
4992 if (noninteractive_need_newline
)
4993 putc ('\n', stderr
);
4994 noninteractive_need_newline
= 0;
4995 fprintf (stderr
, m
, XSTRING (string
)->data
);
4996 if (cursor_in_echo_area
== 0)
4997 fprintf (stderr
, "\n");
5001 else if (INTERACTIVE
)
5003 /* The frame whose minibuffer we're going to display the message on.
5004 It may be larger than the selected frame, so we need
5005 to use its buffer, not the selected frame's buffer. */
5006 Lisp_Object mini_window
;
5009 /* Get the frame containing the minibuffer
5010 that the selected frame is using. */
5011 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
5012 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5014 /* A null message buffer means that the frame hasn't really been
5015 initialized yet. Error messages get reported properly by
5016 cmd_error, so this must be just an informative message; toss it. */
5017 if (FRAME_MESSAGE_BUF (f
))
5021 a
[0] = (char *) XSTRING (string
)->data
;
5023 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5024 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5027 message2 (FRAME_MESSAGE_BUF (f
), len
,
5028 STRING_MULTIBYTE (string
));
5030 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5031 STRING_MULTIBYTE (string
));
5033 /* Print should start at the beginning of the message
5034 buffer next time. */
5035 message_buf_print
= 0;
5041 /* Truncate what will be displayed in the echo area
5042 the next time we display it--but don't redisplay it now. */
5045 truncate_echo_area (len
)
5048 /* A null message buffer means that the frame hasn't really been
5049 initialized yet. Error messages get reported properly by
5050 cmd_error, so this must be just an informative message; toss it. */
5051 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
5052 echo_area_glyphs_length
= len
;
5056 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by
5057 print; zero if being used by message. */
5059 int message_buf_print
;
5062 /* Dump an informative message to the minibuf. If M is 0, clear out
5063 any existing message, and let the mini-buffer text show through. */
5067 message (m
, a1
, a2
, a3
)
5069 EMACS_INT a1
, a2
, a3
;
5075 if (noninteractive_need_newline
)
5076 putc ('\n', stderr
);
5077 noninteractive_need_newline
= 0;
5078 fprintf (stderr
, m
, a1
, a2
, a3
);
5079 if (cursor_in_echo_area
== 0)
5080 fprintf (stderr
, "\n");
5084 else if (INTERACTIVE
)
5086 /* The frame whose mini-buffer we're going to display the message
5087 on. It may be larger than the selected frame, so we need to
5088 use its buffer, not the selected frame's buffer. */
5089 Lisp_Object mini_window
;
5092 /* Get the frame containing the mini-buffer
5093 that the selected frame is using. */
5094 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
5095 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5097 /* A null message buffer means that the frame hasn't really been
5098 initialized yet. Error messages get reported properly by
5099 cmd_error, so this must be just an informative message; toss
5101 if (FRAME_MESSAGE_BUF (f
))
5112 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5113 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5115 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5116 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5118 #endif /* NO_ARG_ARRAY */
5120 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5125 /* Print should start at the beginning of the message
5126 buffer next time. */
5127 message_buf_print
= 0;
5133 /* The non-logging version of message. */
5136 message_nolog (m
, a1
, a2
, a3
)
5138 EMACS_INT a1
, a2
, a3
;
5140 Lisp_Object old_log_max
;
5141 old_log_max
= Vmessage_log_max
;
5142 Vmessage_log_max
= Qnil
;
5143 message (m
, a1
, a2
, a3
);
5144 Vmessage_log_max
= old_log_max
;
5148 /* Display echo_area_message or echo_area_glyphs in the current
5154 if (STRINGP (echo_area_message
))
5155 message3 (echo_area_message
, echo_area_glyphs_length
,
5156 !NILP (current_buffer
->enable_multibyte_characters
));
5158 message2 (echo_area_glyphs
, echo_area_glyphs_length
,
5159 !NILP (current_buffer
->enable_multibyte_characters
));
5163 /* Redisplay the echo area of selected_frame. If UPDATE_FRAME_P is
5164 non-zero update selected_frame. */
5167 echo_area_display (update_frame_p
)
5170 Lisp_Object mini_window
;
5174 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
5175 w
= XWINDOW (mini_window
);
5176 f
= XFRAME (WINDOW_FRAME (w
));
5178 /* Don't display if frame is invisible or not yet initialized. */
5179 if (!FRAME_VISIBLE_P (f
)
5180 || !f
->glyphs_initialized_p
)
5183 /* When Emacs starts, selected_frame may be a visible terminal
5184 frame, even if we run under a window system. If we let this
5185 through, a message would be displayed on the terminal. */
5186 #ifdef HAVE_WINDOW_SYSTEM
5187 if (!inhibit_window_system
&& !FRAME_WINDOW_P (selected_frame
))
5189 #endif /* HAVE_WINDOW_SYSTEM */
5191 /* Redraw garbaged frames. */
5194 /* Old redisplay called redraw_garbaged_frames here which in
5195 turn called redraw_frame which in turn called clear_frame.
5196 The call to clear_frame is a source of flickering. After
5197 checking the places where SET_FRAME_GARBAGED is called, I
5198 believe a clear_frame is not necessary. It should suffice in
5199 the new redisplay to invalidate all current matrices, and
5200 ensure a complete redisplay of all windows. */
5201 Lisp_Object tail
, frame
;
5203 FOR_EACH_FRAME (tail
, frame
)
5205 struct frame
*f
= XFRAME (frame
);
5207 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
5209 clear_current_matrices (f
);
5215 ++windows_or_buffers_changed
;
5218 if (echo_area_glyphs
5219 || STRINGP (echo_area_message
)
5220 || minibuf_level
== 0)
5224 echo_area_window
= mini_window
;
5225 clear_glyph_matrix (w
->desired_matrix
);
5226 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, DEFAULT_FACE_ID
);
5228 if (STRINGP (echo_area_message
)
5229 && echo_area_glyphs_length
)
5231 prepare_desired_row (it
.glyph_row
);
5232 display_string (NULL
, echo_area_message
, Qnil
, 0, 0,
5233 &it
, -1, echo_area_glyphs_length
, 0,
5234 message_enable_multibyte
);
5235 it
.glyph_row
->truncated_on_right_p
= 0;
5236 compute_line_metrics (&it
);
5238 else if (echo_area_glyphs
5239 && echo_area_glyphs_length
)
5241 prepare_desired_row (it
.glyph_row
);
5242 display_string (echo_area_glyphs
, Qnil
, Qnil
, 0, 0, &it
,
5243 -1, echo_area_glyphs_length
, 0,
5244 message_enable_multibyte
);
5245 it
.glyph_row
->truncated_on_right_p
= 0;
5246 compute_line_metrics (&it
);
5249 blank_row (w
, it
.glyph_row
, 0);
5251 it
.glyph_row
->y
= it
.current_y
;
5252 it
.current_y
+= it
.glyph_row
->height
;
5254 /* Clear the rest of the lines. */
5255 while (it
.current_y
< it
.last_visible_y
)
5258 blank_row (w
, it
.glyph_row
, it
.current_y
);
5259 it
.current_y
+= it
.glyph_row
->height
;
5262 w
->must_be_updated_p
= 1;
5265 /* Calling update_single_window is faster when we can use
5266 window-based redisplay. */
5267 if (FRAME_WINDOW_P (f
))
5269 update_single_window (w
, 1);
5270 rif
->flush_display (f
);
5273 update_frame (f
, 1, 1);
5276 else if (!EQ (mini_window
, selected_window
))
5277 windows_or_buffers_changed
++;
5279 /* Prevent redisplay optimization in redisplay_internal by resetting
5280 this_line_start_pos. This is done because the mini-buffer now
5281 displays the message instead of its buffer text. */
5282 if (EQ (mini_window
, selected_window
))
5283 CHARPOS (this_line_start_pos
) = 0;
5285 previous_echo_glyphs
= echo_area_glyphs
;
5286 previous_echo_area_message
= echo_area_message
;
5287 previous_echo_glyphs_length
= echo_area_glyphs_length
;
5292 /***********************************************************************
5294 ***********************************************************************/
5297 #ifdef HAVE_WINDOW_SYSTEM
5299 /* A buffer for constructing frame titles in it; allocated from the
5300 heap in init_xdisp and resized as needed in store_frame_title_char. */
5302 static char *frame_title_buf
;
5304 /* The buffer's end, and a current output position in it. */
5306 static char *frame_title_buf_end
;
5307 static char *frame_title_ptr
;
5310 /* Store a single character C for the frame title in frame_title_buf.
5311 Re-allocate frame_title_buf if necessary. */
5314 store_frame_title_char (c
)
5317 /* If output position has reached the end of the allocated buffer,
5318 double the buffer's size. */
5319 if (frame_title_ptr
== frame_title_buf_end
)
5321 int len
= frame_title_ptr
- frame_title_buf
;
5322 int new_size
= 2 * len
* sizeof *frame_title_buf
;
5323 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
5324 frame_title_buf_end
= frame_title_buf
+ new_size
;
5325 frame_title_ptr
= frame_title_buf
+ len
;
5328 *frame_title_ptr
++ = c
;
5332 /* Store part of a frame title in frame_title_buf, beginning at
5333 frame_title_ptr. STR is the string to store. Do not copy more
5334 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
5335 the whole string. Pad with spaces until FIELD_WIDTH number of
5336 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
5337 Called from display_mode_element when it is used to build a frame
5341 store_frame_title (str
, field_width
, precision
)
5343 int field_width
, precision
;
5347 /* Copy at most PRECISION chars from STR. */
5348 while ((precision
<= 0 || n
< precision
)
5351 store_frame_title_char (*str
++);
5355 /* Fill up with spaces until FIELD_WIDTH reached. */
5356 while (field_width
> 0
5359 store_frame_title_char (' ');
5367 /* Set the title of FRAME, if it has changed. The title format is
5368 Vicon_title_format if FRAME is iconified, otherwise it is
5369 frame_title_format. */
5372 x_consider_frame_title (frame
)
5375 struct frame
*f
= XFRAME (frame
);
5377 if (FRAME_WINDOW_P (f
)
5378 || FRAME_MINIBUF_ONLY_P (f
)
5379 || f
->explicit_name
)
5381 /* Do we have more than one visible frame on this X display? */
5384 struct buffer
*obuf
;
5388 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5390 struct frame
*tf
= XFRAME (XCONS (tail
)->car
);
5393 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
5394 && !FRAME_MINIBUF_ONLY_P (tf
)
5395 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
5399 /* Set global variable indicating that multiple frames exist. */
5400 multiple_frames
= CONSP (tail
);
5402 /* Switch to the buffer of selected window of the frame. Set up
5403 frame_title_ptr so that display_mode_element will output into it;
5404 then display the title. */
5405 obuf
= current_buffer
;
5406 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
5407 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
5408 frame_title_ptr
= frame_title_buf
;
5409 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
5410 NULL
, DEFAULT_FACE_ID
);
5411 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
5412 frame_title_ptr
= NULL
;
5413 set_buffer_internal (obuf
);
5415 /* Set the title only if it's changed. This avoids consing in
5416 the common case where it hasn't. (If it turns out that we've
5417 already wasted too much time by walking through the list with
5418 display_mode_element, then we might need to optimize at a
5419 higher level than this.) */
5420 if (! STRINGP (f
->name
)
5421 || STRING_BYTES (XSTRING (f
->name
)) != len
5422 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
5423 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
5427 #else /* not HAVE_WINDOW_SYSTEM */
5429 #define frame_title_ptr ((char *)0)
5430 #define store_frame_title(str, mincol, maxcol) 0
5432 #endif /* not HAVE_WINDOW_SYSTEM */
5437 /***********************************************************************
5439 ***********************************************************************/
5442 /* Prepare for redisplay by updating menu-bar item lists when
5443 appropriate. This can call eval. */
5446 prepare_menu_bars ()
5449 struct gcpro gcpro1
, gcpro2
;
5451 struct frame
*tooltip_frame
;
5453 #ifdef HAVE_X_WINDOWS
5454 tooltip_frame
= tip_frame
;
5456 tooltip_frame
= NULL
;
5459 /* Update all frame titles based on their buffer names, etc. We do
5460 this before the menu bars so that the buffer-menu will show the
5461 up-to-date frame titles. */
5462 #ifdef HAVE_WINDOW_SYSTEM
5463 if (windows_or_buffers_changed
|| update_mode_lines
)
5465 Lisp_Object tail
, frame
;
5467 FOR_EACH_FRAME (tail
, frame
)
5470 if (f
!= tooltip_frame
5471 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
5472 x_consider_frame_title (frame
);
5475 #endif /* HAVE_WINDOW_SYSTEM */
5477 /* Update the menu bar item lists, if appropriate. This has to be
5478 done before any actual redisplay or generation of display lines. */
5479 all_windows
= (update_mode_lines
5480 || buffer_shared
> 1
5481 || windows_or_buffers_changed
);
5484 Lisp_Object tail
, frame
;
5485 int count
= specpdl_ptr
- specpdl
;
5487 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
5489 FOR_EACH_FRAME (tail
, frame
)
5493 /* Ignore tooltip frame. */
5494 if (f
== tooltip_frame
)
5497 /* If a window on this frame changed size, report that to
5498 the user and clear the size-change flag. */
5499 if (FRAME_WINDOW_SIZES_CHANGED (f
))
5501 Lisp_Object functions
;
5503 /* Clear flag first in case we get an error below. */
5504 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
5505 functions
= Vwindow_size_change_functions
;
5506 GCPRO2 (tail
, functions
);
5508 while (CONSP (functions
))
5510 call1 (XCAR (functions
), frame
);
5511 functions
= XCDR (functions
);
5517 update_menu_bar (f
, 0);
5518 #ifdef HAVE_WINDOW_SYSTEM
5519 update_toolbar (f
, 0);
5524 unbind_to (count
, Qnil
);
5528 update_menu_bar (selected_frame
, 1);
5529 #ifdef HAVE_WINDOW_SYSTEM
5530 update_toolbar (selected_frame
, 1);
5534 /* Motif needs this. See comment in xmenu.c. Turn it off when
5535 pending_menu_activation is not defined. */
5536 #ifdef USE_X_TOOLKIT
5537 pending_menu_activation
= 0;
5542 /* Update the menu bar item list for frame F. This has to be done
5543 before we start to fill in any display lines, because it can call
5546 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
5549 update_menu_bar (f
, save_match_data
)
5551 int save_match_data
;
5554 register struct window
*w
;
5556 window
= FRAME_SELECTED_WINDOW (f
);
5557 w
= XWINDOW (window
);
5559 if (update_mode_lines
)
5560 w
->update_mode_line
= Qt
;
5562 if (FRAME_WINDOW_P (f
)
5564 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
5565 FRAME_EXTERNAL_MENU_BAR (f
)
5567 FRAME_MENU_BAR_LINES (f
) > 0
5569 : FRAME_MENU_BAR_LINES (f
) > 0)
5571 /* If the user has switched buffers or windows, we need to
5572 recompute to reflect the new bindings. But we'll
5573 recompute when update_mode_lines is set too; that means
5574 that people can use force-mode-line-update to request
5575 that the menu bar be recomputed. The adverse effect on
5576 the rest of the redisplay algorithm is about the same as
5577 windows_or_buffers_changed anyway. */
5578 if (windows_or_buffers_changed
5579 || !NILP (w
->update_mode_line
)
5580 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
5581 < BUF_MODIFF (XBUFFER (w
->buffer
)))
5582 != !NILP (w
->last_had_star
))
5583 || ((!NILP (Vtransient_mark_mode
)
5584 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
5585 != !NILP (w
->region_showing
)))
5587 struct buffer
*prev
= current_buffer
;
5588 int count
= specpdl_ptr
- specpdl
;
5590 set_buffer_internal_1 (XBUFFER (w
->buffer
));
5591 if (save_match_data
)
5592 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
5593 if (NILP (Voverriding_local_map_menu_flag
))
5595 specbind (Qoverriding_terminal_local_map
, Qnil
);
5596 specbind (Qoverriding_local_map
, Qnil
);
5599 /* Run the Lucid hook. */
5600 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
5602 /* If it has changed current-menubar from previous value,
5603 really recompute the menu-bar from the value. */
5604 if (! NILP (Vlucid_menu_bar_dirty_flag
))
5605 call0 (Qrecompute_lucid_menubar
);
5607 safe_run_hooks (Qmenu_bar_update_hook
);
5608 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
5610 /* Redisplay the menu bar in case we changed it. */
5611 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
5612 if (FRAME_WINDOW_P (f
))
5613 set_frame_menubar (f
, 0, 0);
5615 /* On a terminal screen, the menu bar is an ordinary screen
5616 line, and this makes it get updated. */
5617 w
->update_mode_line
= Qt
;
5618 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
5619 /* In the non-toolkit version, the menu bar is an ordinary screen
5620 line, and this makes it get updated. */
5621 w
->update_mode_line
= Qt
;
5622 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
5624 unbind_to (count
, Qnil
);
5625 set_buffer_internal_1 (prev
);
5632 /***********************************************************************
5634 ***********************************************************************/
5636 #ifdef HAVE_WINDOW_SYSTEM
5638 /* Update the toolbar item list for frame F. This has to be done
5639 before we start to fill in any display lines. Called from
5640 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
5641 and restore it here. */
5644 update_toolbar (f
, save_match_data
)
5646 int save_match_data
;
5648 if (WINDOWP (f
->toolbar_window
)
5649 && XFASTINT (XWINDOW (f
->toolbar_window
)->height
) > 0)
5654 window
= FRAME_SELECTED_WINDOW (f
);
5655 w
= XWINDOW (window
);
5657 /* If the user has switched buffers or windows, we need to
5658 recompute to reflect the new bindings. But we'll
5659 recompute when update_mode_lines is set too; that means
5660 that people can use force-mode-line-update to request
5661 that the menu bar be recomputed. The adverse effect on
5662 the rest of the redisplay algorithm is about the same as
5663 windows_or_buffers_changed anyway. */
5664 if (windows_or_buffers_changed
5665 || !NILP (w
->update_mode_line
)
5666 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
5667 < BUF_MODIFF (XBUFFER (w
->buffer
)))
5668 != !NILP (w
->last_had_star
))
5669 || ((!NILP (Vtransient_mark_mode
)
5670 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
5671 != !NILP (w
->region_showing
)))
5673 struct buffer
*prev
= current_buffer
;
5674 int count
= specpdl_ptr
- specpdl
;
5676 /* Set current_buffer to the buffer of the selected
5677 window of the frame, so that we get the right local
5679 set_buffer_internal_1 (XBUFFER (w
->buffer
));
5681 /* Save match data, if we must. */
5682 if (save_match_data
)
5683 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
5685 /* Make sure that we don't accidentally use bogus keymaps. */
5686 if (NILP (Voverriding_local_map_menu_flag
))
5688 specbind (Qoverriding_terminal_local_map
, Qnil
);
5689 specbind (Qoverriding_local_map
, Qnil
);
5692 /* Build desired toolbar items from keymaps. */
5693 f
->desired_toolbar_items
5694 = toolbar_items (f
->desired_toolbar_items
,
5695 &f
->n_desired_toolbar_items
);
5697 /* Redisplay the toolbar in case we changed it. */
5698 w
->update_mode_line
= Qt
;
5700 unbind_to (count
, Qnil
);
5701 set_buffer_internal_1 (prev
);
5707 /* Set F->desired_toolbar_string to a Lisp string representing frame
5708 F's desired toolbar contents. F->desired_toolbar_items must have
5709 been set up previously by calling prepare_menu_bars. */
5712 build_desired_toolbar_string (f
)
5715 int i
, size
, size_needed
, string_idx
;
5716 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5717 Lisp_Object image
, plist
, props
;
5719 image
= plist
= props
= Qnil
;
5720 GCPRO3 (image
, plist
, props
);
5722 /* Prepare F->desired_toolbar_string. If we can reuse it, do so.
5723 Otherwise, make a new string. */
5725 /* The size of the string we might be able to reuse. */
5726 size
= (STRINGP (f
->desired_toolbar_string
)
5727 ? XSTRING (f
->desired_toolbar_string
)->size
5730 /* Each image in the string we build is preceded by a space,
5731 and there is a space at the end. */
5732 size_needed
= f
->n_desired_toolbar_items
+ 1;
5734 /* Reuse f->desired_toolbar_string, if possible. */
5735 if (size
< size_needed
)
5736 f
->desired_toolbar_string
= Fmake_string (make_number (size_needed
), ' ');
5739 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
5740 Fremove_text_properties (make_number (0), make_number (size
),
5741 props
, f
->desired_toolbar_string
);
5744 /* Put a `display' property on the string for the images to display,
5745 put a `menu_item' property on toolbar items with a value that
5746 is the index of the item in F's toolbar item vector. */
5747 for (i
= 0, string_idx
= 0;
5748 i
< f
->n_desired_toolbar_items
;
5749 ++i
, string_idx
+= 1)
5752 (XVECTOR (f->desired_toolbar_items) \
5753 ->contents[i * TOOLBAR_ITEM_NSLOTS + (IDX)])
5755 int enabled_p
= !NILP (PROP (TOOLBAR_ITEM_ENABLED_P
));
5756 int selected_p
= !NILP (PROP (TOOLBAR_ITEM_SELECTED_P
));
5758 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
5759 extern Lisp_Object Qlaplace
;
5761 /* If image is a vector, choose the image according to the
5763 image
= PROP (TOOLBAR_ITEM_IMAGES
);
5764 if (VECTORP (image
))
5766 enum toolbar_item_image idx
;
5770 ? TOOLBAR_IMAGE_ENABLED_SELECTED
5771 : TOOLBAR_IMAGE_ENABLED_DESELECTED
);
5774 ? TOOLBAR_IMAGE_DISABLED_SELECTED
5775 : TOOLBAR_IMAGE_DISABLED_DESELECTED
);
5777 xassert (XVECTOR (image
)->size
>= idx
);
5778 image
= XVECTOR (image
)->contents
[idx
];
5781 /* Ignore invalid image specifications. */
5782 if (!valid_image_p (image
))
5785 /* Display the toolbar button pressed, or depressed. */
5786 plist
= Fcopy_sequence (XCDR (image
));
5788 /* Compute margin and relief to draw. */
5789 relief
= toolbar_button_relief
> 0 ? toolbar_button_relief
: 3;
5790 margin
= relief
+ max (0, toolbar_button_margin
);
5792 if (auto_raise_toolbar_buttons_p
)
5794 /* Add a `:relief' property to the image spec if the item is
5798 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
5804 /* If image is selected, display it pressed, i.e. with a
5805 negative relief. If it's not selected, display it with a
5807 plist
= Fplist_put (plist
, QCrelief
,
5809 ? make_number (-relief
)
5810 : make_number (relief
)));
5814 /* Put a margin around the image. */
5816 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
5818 /* If button is not enabled, make the image appear disabled by
5819 applying an appropriate algorithm to it. */
5821 plist
= Fplist_put (plist
, QCalgorithm
, Qlaplace
);
5823 /* Put a `display' text property on the string for the image to
5824 display. Put a `menu-item' property on the string that gives
5825 the start of this item's properties in the toolbar items
5827 image
= Fcons (Qimage
, plist
);
5828 props
= list4 (Qdisplay
, image
,
5829 Qmenu_item
, make_number (i
* TOOLBAR_ITEM_NSLOTS
)),
5830 Fadd_text_properties (make_number (string_idx
),
5831 make_number (string_idx
+ 1),
5832 props
, f
->desired_toolbar_string
);
5840 /* Display one line of the toolbar of frame IT->f. */
5843 display_toolbar_line (it
)
5846 struct glyph_row
*row
= it
->glyph_row
;
5847 int max_x
= it
->last_visible_x
;
5850 prepare_desired_row (row
);
5851 row
->y
= it
->current_y
;
5853 while (it
->current_x
< max_x
)
5855 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
5857 /* Get the next display element. */
5858 if (!get_next_display_element (it
))
5861 /* Produce glyphs. */
5862 x_before
= it
->current_x
;
5863 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
5864 PRODUCE_GLYPHS (it
);
5866 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
5871 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
5873 if (x
+ glyph
->pixel_width
> max_x
)
5875 /* Glyph doesn't fit on line. */
5876 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
5882 x
+= glyph
->pixel_width
;
5886 /* Stop at line ends. */
5887 if (ITERATOR_AT_END_OF_LINE_P (it
))
5890 set_iterator_to_next (it
);
5895 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
5896 extend_face_to_end_of_line (it
);
5897 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
5898 last
->right_box_line_p
= 1;
5899 compute_line_metrics (it
);
5901 /* If line is empty, make it occupy the rest of the toolbar. */
5902 if (!row
->displays_text_p
)
5904 row
->height
= it
->last_visible_y
- row
->y
;
5908 row
->full_width_p
= 1;
5909 row
->continued_p
= 0;
5910 row
->truncated_on_left_p
= 0;
5911 row
->truncated_on_right_p
= 0;
5913 it
->current_x
= it
->hpos
= 0;
5914 it
->current_y
+= row
->height
;
5920 /* Value is the number of screen lines needed to make all toolbar
5921 items of frame F visible. */
5924 toolbar_lines_needed (f
)
5927 struct window
*w
= XWINDOW (f
->toolbar_window
);
5930 /* Initialize an iterator for iteration over F->desired_toolbar_string
5931 in the toolbar window of frame F. */
5932 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOLBAR_FACE_ID
);
5933 it
.first_visible_x
= 0;
5934 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
5935 reseat_to_string (&it
, NULL
, f
->desired_toolbar_string
, 0, 0, 0, -1);
5937 while (!ITERATOR_AT_END_P (&it
))
5939 it
.glyph_row
= w
->desired_matrix
->rows
;
5940 clear_glyph_row (it
.glyph_row
);
5941 display_toolbar_line (&it
);
5944 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
5948 /* Display the toolbar of frame F. Value is non-zero if toolbar's
5949 height should be changed. */
5952 redisplay_toolbar (f
)
5957 struct glyph_row
*row
;
5958 int change_height_p
= 0;
5960 /* If frame hasn't a toolbar window or if it is zero-height, don't
5961 do anything. This means you must start with toolbar-lines
5962 non-zero to get the auto-sizing effect. Or in other words, you
5963 can turn off toolbars by specifying toolbar-lines zero. */
5964 if (!WINDOWP (f
->toolbar_window
)
5965 || (w
= XWINDOW (f
->toolbar_window
),
5966 XFASTINT (w
->height
) == 0))
5969 /* Set up an iterator for the toolbar window. */
5970 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOLBAR_FACE_ID
);
5971 it
.first_visible_x
= 0;
5972 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
5975 /* Build a string that represents the contents of the toolbar. */
5976 build_desired_toolbar_string (f
);
5977 reseat_to_string (&it
, NULL
, f
->desired_toolbar_string
, 0, 0, 0, -1);
5979 /* Display as many lines as needed to display all toolbar items. */
5980 while (it
.current_y
< it
.last_visible_y
)
5981 display_toolbar_line (&it
);
5983 /* It doesn't make much sense to try scrolling in the toolbar
5984 window, so don't do it. */
5985 w
->desired_matrix
->no_scrolling_p
= 1;
5986 w
->must_be_updated_p
= 1;
5988 if (auto_resize_toolbars_p
)
5992 /* If there are blank lines at the end, except for a partially
5993 visible blank line at the end that is smaller than
5994 CANON_Y_UNIT, change the toolbar's height. */
5995 row
= it
.glyph_row
- 1;
5996 if (!row
->displays_text_p
5997 && row
->height
>= CANON_Y_UNIT (f
))
5998 change_height_p
= 1;
6000 /* If row displays toolbar items, but is partially visible,
6001 change the toolbar's height. */
6002 if (row
->displays_text_p
6003 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
6004 change_height_p
= 1;
6006 /* Resize windows as needed by changing the `toolbar-lines'
6009 && (nlines
= toolbar_lines_needed (f
),
6010 nlines
!= XFASTINT (w
->height
)))
6012 extern Lisp_Object Qtoolbar_lines
;
6015 XSETFRAME (frame
, f
);
6016 clear_glyph_matrix (w
->desired_matrix
);
6017 Fmodify_frame_parameters (frame
,
6018 Fcons (Fcons (Qtoolbar_lines
,
6019 make_number (nlines
)),
6021 fonts_changed_p
= 1;
6025 return change_height_p
;
6029 /* Get information about the toolbar item which is displayed in GLYPH
6030 on frame F. Return in *PROP_IDX the index where toolbar item
6031 properties start in F->current_toolbar_items. Value is zero if
6032 GLYPH doesn't display a toolbar item. */
6035 toolbar_item_info (f
, glyph
, prop_idx
)
6037 struct glyph
*glyph
;
6043 /* Get the text property `menu-item' at pos. The value of that
6044 property is the start index of this item's properties in
6045 F->current_toolbar_items. */
6046 prop
= Fget_text_property (make_number (glyph
->charpos
),
6047 Qmenu_item
, f
->current_toolbar_string
);
6048 if (INTEGERP (prop
))
6050 *prop_idx
= XINT (prop
);
6059 #endif /* HAVE_WINDOW_SYSTEM */
6063 /************************************************************************
6064 Horizontal scrolling
6065 ************************************************************************/
6067 static int hscroll_window_tree
P_ ((Lisp_Object
));
6068 static int hscroll_windows
P_ ((Lisp_Object
));
6070 /* For all leaf windows in the window tree rooted at WINDOW, set their
6071 hscroll value so that PT is (i) visible in the window, and (ii) so
6072 that it is not within a certain margin at the window's left and
6073 right border. Value is non-zero if any window's hscroll has been
6077 hscroll_window_tree (window
)
6080 int hscrolled_p
= 0;
6082 while (WINDOWP (window
))
6084 struct window
*w
= XWINDOW (window
);
6086 if (WINDOWP (w
->hchild
))
6087 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
6088 else if (WINDOWP (w
->vchild
))
6089 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
6090 else if (w
->cursor
.vpos
>= 0)
6092 int hscroll_margin
, text_area_x
, text_area_y
;
6093 int text_area_width
, text_area_height
;
6094 struct glyph_row
*cursor_row
= MATRIX_ROW (w
->current_matrix
,
6097 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
6098 &text_area_width
, &text_area_height
);
6100 /* Scroll when cursor is inside this scroll margin. */
6101 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
6103 if ((XFASTINT (w
->hscroll
)
6104 && w
->cursor
.x
< hscroll_margin
)
6105 || (cursor_row
->truncated_on_right_p
6106 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
6110 struct buffer
*saved_current_buffer
;
6113 /* Find point in a display of infinite width. */
6114 saved_current_buffer
= current_buffer
;
6115 current_buffer
= XBUFFER (w
->buffer
);
6117 if (w
== XWINDOW (selected_window
))
6118 pt
= BUF_PT (current_buffer
);
6121 pt
= marker_position (w
->pointm
);
6122 pt
= max (BEGV
, pt
);
6126 /* Move iterator to pt starting at cursor_row->start in
6127 a line with infinite width. */
6128 init_to_row_start (&it
, w
, cursor_row
);
6129 it
.last_visible_x
= INFINITY
;
6130 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
6131 current_buffer
= saved_current_buffer
;
6133 /* Center cursor in window. */
6134 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
6135 / CANON_X_UNIT (it
.f
));
6137 /* Don't call Fset_window_hscroll if value hasn't
6138 changed because it will prevent redisplay
6140 if (XFASTINT (w
->hscroll
) != hscroll
)
6142 Fset_window_hscroll (window
, make_number (hscroll
));
6151 /* Value is non-zero if hscroll of any leaf window has been changed. */
6156 /* Set hscroll so that cursor is visible and not inside horizontal
6157 scroll margins for all windows in the tree rooted at WINDOW. See
6158 also hscroll_window_tree above. Value is non-zero if any window's
6159 hscroll has been changed. If it has, desired matrices on the frame
6160 of WINDOW are cleared. */
6163 hscroll_windows (window
)
6166 int hscrolled_p
= hscroll_window_tree (window
);
6168 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
6174 /************************************************************************
6176 ************************************************************************/
6178 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
6179 to a non-zero value. This is sometimes handy to have in a debugger
6184 /* Values of beg_unchanged and end_unchanged as of last call to
6187 int debug_beg_unchanged
, debug_end_unchanged
;
6189 /* First and last unchanged row for try_window_id. */
6191 int debug_first_unchanged_at_end_vpos
;
6192 int debug_last_unchanged_at_beg_vpos
;
6194 /* Delta vpos and y. */
6196 int debug_dvpos
, debug_dy
;
6198 /* Delta in characters and bytes for try_window_id. */
6200 int debug_delta
, debug_delta_bytes
;
6202 /* Values of window_end_pos and window_end_vpos at the end of
6205 int debug_end_pos
, debug_end_vpos
;
6207 /* Append a string to W->desired_matrix->method. FMT is a printf
6208 format string. A1...A9 are a supplement for a variable-length
6209 argument list. If trace_redisplay_p is non-zero also printf the
6210 resulting string to stderr. */
6213 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
6216 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
6219 char *method
= w
->desired_matrix
->method
;
6220 int len
= strlen (method
);
6221 int size
= sizeof w
->desired_matrix
->method
;
6222 int remaining
= size
- len
- 1;
6224 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
6225 if (len
&& remaining
)
6231 strncpy (method
+ len
, buffer
, remaining
);
6233 if (trace_redisplay_p
)
6234 fprintf (stderr
, "%p (%s): %s\n",
6236 ((BUFFERP (w
->buffer
)
6237 && STRINGP (XBUFFER (w
->buffer
)->name
))
6238 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
6243 #endif /* GLYPH_DEBUG */
6246 /* This counter is used to clear the face cache every once in a while
6247 in redisplay_internal. It is incremented for each redisplay.
6248 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
6251 #define CLEAR_FACE_CACHE_COUNT 10000
6252 static int clear_face_cache_count
;
6254 /* Record the previous terminal frame we displayed. */
6256 static struct frame
*previous_terminal_frame
;
6258 /* Non-zero while redisplay_internal is in progress. */
6263 /* Value is non-zero if all changes in window W, which displays
6264 current_buffer, are in the text between START and END. START is a
6265 buffer position, END is given as a distance from Z. Used in
6266 redisplay_internal for display optimization. */
6269 text_outside_line_unchanged_p (w
, start
, end
)
6273 int unchanged_p
= 1;
6275 /* If text or overlays have changed, see where. */
6276 if (XFASTINT (w
->last_modified
) < MODIFF
6277 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
6279 /* Gap in the line? */
6280 if (GPT
< start
|| Z
- GPT
< end
)
6283 /* Changes start in front of the line, or end after it? */
6285 && (beg_unchanged
< start
- 1
6286 || end_unchanged
< end
))
6289 /* If selective display, can't optimize if changes start at the
6290 beginning of the line. */
6292 && INTEGERP (current_buffer
->selective_display
)
6293 && XINT (current_buffer
->selective_display
) > 0
6294 && (beg_unchanged
< start
|| GPT
<= start
))
6302 /* Do a frame update, taking possible shortcuts into account. This is
6303 the main external entry point for redisplay.
6305 If the last redisplay displayed an echo area message and that message
6306 is no longer requested, we clear the echo area or bring back the
6307 mini-buffer if that is in use. */
6312 redisplay_internal (0);
6316 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
6317 response to any user action; therefore, we should preserve the echo
6318 area. (Actually, our caller does that job.) Perhaps in the future
6319 avoid recentering windows if it is not necessary; currently that
6320 causes some problems. */
6323 redisplay_internal (preserve_echo_area
)
6324 int preserve_echo_area
;
6326 struct window
*w
= XWINDOW (selected_window
);
6327 struct frame
*f
= XFRAME (w
->frame
);
6329 int must_finish
= 0;
6330 struct text_pos tlbufpos
, tlendpos
;
6331 int number_of_visible_frames
;
6333 /* Non-zero means redisplay has to consider all windows on all
6334 frames. Zero means, only selected_window is considered. */
6335 int consider_all_windows_p
;
6337 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
6339 /* No redisplay if running in batch mode or frame is not yet fully
6340 initialized, or redisplay is explicitly turned off by setting
6341 Vinhibit_redisplay. */
6343 || !NILP (Vinhibit_redisplay
)
6344 || !f
->glyphs_initialized_p
)
6347 /* The flag redisplay_performed_directly_p is set by
6348 direct_output_for_insert when it already did the whole screen
6349 update necessary. */
6350 if (redisplay_performed_directly_p
)
6352 redisplay_performed_directly_p
= 0;
6353 if (!hscroll_windows (selected_window
))
6357 #ifdef USE_X_TOOLKIT
6358 if (popup_activated ())
6368 /* If new fonts have been loaded that make a glyph matrix adjustment
6369 necessary, do it. */
6370 if (fonts_changed_p
)
6372 adjust_glyphs (NULL
);
6373 ++windows_or_buffers_changed
;
6374 fonts_changed_p
= 0;
6377 if (! FRAME_WINDOW_P (selected_frame
)
6378 && previous_terminal_frame
!= selected_frame
)
6380 /* Since frames on an ASCII terminal share the same display
6381 area, displaying a different frame means redisplay the whole
6383 windows_or_buffers_changed
++;
6384 SET_FRAME_GARBAGED (selected_frame
);
6385 XSETFRAME (Vterminal_frame
, selected_frame
);
6387 previous_terminal_frame
= selected_frame
;
6389 /* Set the visible flags for all frames. Do this before checking
6390 for resized or garbaged frames; they want to know if their frames
6391 are visible. See the comment in frame.h for
6392 FRAME_SAMPLE_VISIBILITY. */
6394 Lisp_Object tail
, frame
;
6396 number_of_visible_frames
= 0;
6398 FOR_EACH_FRAME (tail
, frame
)
6400 struct frame
*f
= XFRAME (frame
);
6402 FRAME_SAMPLE_VISIBILITY (f
);
6403 if (FRAME_VISIBLE_P (f
))
6404 ++number_of_visible_frames
;
6405 clear_desired_matrices (f
);
6409 /* Notice any pending interrupt request to change frame size. */
6410 do_pending_window_change ();
6412 /* Clear frames marked as garbaged. */
6415 /* Old redisplay called redraw_garbaged_frames here which in
6416 turn called redraw_frame which in turn called clear_frame.
6417 The call to clear_frame is a source of flickering. After
6418 checking the places where SET_FRAME_GARBAGED is called, I
6419 believe a clear_frame is not necessary. It should suffice in
6420 the new redisplay to invalidate all current matrices, and
6421 ensure a complete redisplay of all windows. */
6422 Lisp_Object tail
, frame
;
6424 FOR_EACH_FRAME (tail
, frame
)
6426 struct frame
*f
= XFRAME (frame
);
6428 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6430 clear_current_matrices (f
);
6436 ++windows_or_buffers_changed
;
6439 /* Build menubar and toolbar items. */
6440 prepare_menu_bars ();
6442 if (windows_or_buffers_changed
)
6443 update_mode_lines
++;
6445 /* Detect case that we need to write or remove a star in the mode line. */
6446 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
6448 w
->update_mode_line
= Qt
;
6449 if (buffer_shared
> 1)
6450 update_mode_lines
++;
6453 /* If %c is in the mode line, update it if needed. */
6454 if (!NILP (w
->column_number_displayed
)
6455 /* This alternative quickly identifies a common case
6456 where no change is needed. */
6457 && !(PT
== XFASTINT (w
->last_point
)
6458 && XFASTINT (w
->last_modified
) >= MODIFF
6459 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
6460 && XFASTINT (w
->column_number_displayed
) != current_column ())
6461 w
->update_mode_line
= Qt
;
6463 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
6465 /* The variable buffer_shared is set in redisplay_window and
6466 indicates that we redisplay a buffer in different windows. See
6468 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
6470 /* If specs for an arrow have changed, do thorough redisplay
6471 to ensure we remove any arrow that should no longer exist. */
6472 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
6473 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
6474 consider_all_windows_p
= windows_or_buffers_changed
= 1;
6476 /* Normally the message* functions will have already displayed and
6477 updated the echo area, but the frame may have been trashed, or
6478 the update may have been preempted, so display the echo area
6480 if (echo_area_glyphs
6481 || STRINGP (echo_area_message
)
6482 || previous_echo_glyphs
6483 || STRINGP (previous_echo_area_message
))
6485 echo_area_display (0);
6489 /* If showing the region, and mark has changed, we must redisplay
6490 the whole window. The assignment to this_line_start_pos prevents
6491 the optimization directly below this if-statement. */
6492 if (((!NILP (Vtransient_mark_mode
)
6493 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6494 != !NILP (w
->region_showing
))
6495 || (!NILP (w
->region_showing
)
6496 && !EQ (w
->region_showing
,
6497 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
6498 CHARPOS (this_line_start_pos
) = 0;
6500 /* Optimize the case that only the line containing the cursor in the
6501 selected window has changed. Variables starting with this_ are
6502 set in display_line and record information about the line
6503 containing the cursor. */
6504 tlbufpos
= this_line_start_pos
;
6505 tlendpos
= this_line_end_pos
;
6506 if (!consider_all_windows_p
6507 && CHARPOS (tlbufpos
) > 0
6508 && NILP (w
->update_mode_line
)
6509 && !current_buffer
->clip_changed
6510 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
6511 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
6512 /* Make sure recorded data applies to current buffer, etc. */
6513 && this_line_buffer
== current_buffer
6514 && current_buffer
== XBUFFER (w
->buffer
)
6515 && NILP (w
->force_start
)
6516 /* Point must be on the line that we have info recorded about. */
6517 && PT
>= CHARPOS (tlbufpos
)
6518 && PT
<= Z
- CHARPOS (tlendpos
)
6519 /* All text outside that line, including its final newline,
6520 must be unchanged */
6521 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
6522 CHARPOS (tlendpos
)))
6524 if (CHARPOS (tlbufpos
) > BEGV
6525 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
6526 && (CHARPOS (tlbufpos
) == ZV
6527 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
6528 /* Former continuation line has disappeared by becoming empty */
6530 else if (XFASTINT (w
->last_modified
) < MODIFF
6531 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
6532 || MINI_WINDOW_P (w
))
6534 /* We have to handle the case of continuation around a
6535 wide-column character (See the comment in indent.c around
6538 For instance, in the following case:
6540 -------- Insert --------
6541 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
6542 J_I_ ==> J_I_ `^^' are cursors.
6546 As we have to redraw the line above, we should goto cancel. */
6549 int line_height_before
= this_line_pixel_height
;
6551 /* Note that start_display will handle the case that the
6552 line starting at tlbufpos is a continuation lines. */
6553 start_display (&it
, w
, tlbufpos
);
6555 /* Implementation note: It this still necessary? */
6556 if (it
.current_x
!= this_line_start_x
)
6559 TRACE ((stderr
, "trying display optimization 1\n"));
6560 w
->cursor
.vpos
= -1;
6561 overlay_arrow_seen
= 0;
6562 it
.vpos
= this_line_vpos
;
6563 it
.current_y
= this_line_y
;
6564 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
6567 /* If line contains point, is not continued,
6568 and ends at same distance from eob as before, we win */
6569 if (w
->cursor
.vpos
>= 0
6570 /* Line is not continued, otherwise this_line_start_pos
6571 would have been set to 0 in display_line. */
6572 && CHARPOS (this_line_start_pos
)
6573 /* Line ends as before. */
6574 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
6575 /* Line has same height as before. Otherwise other lines
6576 would have to be shifted up or down. */
6577 && this_line_pixel_height
== line_height_before
)
6579 /* If this is not the window's last line, we must adjust
6580 the charstarts of the lines below. */
6581 if (it
.current_y
< it
.last_visible_y
)
6583 struct glyph_row
*row
6584 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
6585 int delta
, delta_bytes
;
6587 if (Z
- CHARPOS (tlendpos
) == ZV
)
6589 /* This line ends at end of (accessible part of)
6590 buffer. There is no newline to count. */
6592 - CHARPOS (tlendpos
)
6593 - MATRIX_ROW_START_CHARPOS (row
));
6594 delta_bytes
= (Z_BYTE
6595 - BYTEPOS (tlendpos
)
6596 - MATRIX_ROW_START_BYTEPOS (row
));
6600 /* This line ends in a newline. Must take
6601 account of the newline and the rest of the
6602 text that follows. */
6604 - CHARPOS (tlendpos
)
6605 - MATRIX_ROW_START_CHARPOS (row
));
6606 delta_bytes
= (Z_BYTE
6607 - BYTEPOS (tlendpos
)
6608 - MATRIX_ROW_START_BYTEPOS (row
));
6611 increment_glyph_matrix_buffer_positions (w
->current_matrix
,
6613 w
->current_matrix
->nrows
,
6614 delta
, delta_bytes
);
6617 /* If this row displays text now but previously didn't,
6618 or vice versa, w->window_end_vpos may have to be
6620 if ((it
.glyph_row
- 1)->displays_text_p
)
6622 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
6623 XSETINT (w
->window_end_vpos
, this_line_vpos
);
6625 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
6626 && this_line_vpos
> 0)
6627 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
6628 w
->window_end_valid
= Qnil
;
6630 /* Update hint: No need to try to scroll in update_window. */
6631 w
->desired_matrix
->no_scrolling_p
= 1;
6634 *w
->desired_matrix
->method
= 0;
6635 debug_method_add (w
, "optimization 1");
6642 else if (/* Cursor position hasn't changed. */
6643 PT
== XFASTINT (w
->last_point
)
6644 /* Make sure the cursor was last displayed
6645 in this window. Otherwise we have to reposition it. */
6646 && 0 <= w
->cursor
.vpos
6647 && XINT (w
->height
) > w
->cursor
.vpos
)
6651 do_pending_window_change ();
6653 /* We used to always goto end_of_redisplay here, but this
6654 isn't enough if we have a blinking cursor. */
6655 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
6656 goto end_of_redisplay
;
6660 /* If highlighting the region, or if the cursor is in the echo area,
6661 then we can't just move the cursor. */
6662 else if (! (!NILP (Vtransient_mark_mode
)
6663 && !NILP (current_buffer
->mark_active
))
6664 && (w
== XWINDOW (current_buffer
->last_selected_window
)
6665 || highlight_nonselected_windows
)
6666 && NILP (w
->region_showing
)
6667 && !cursor_in_echo_area
)
6670 struct glyph_row
*row
;
6672 /* Skip from tlbufpos to PT and see where it is. Note that
6673 PT may be in invisible text. If so, we will end at the
6674 next visible position. */
6675 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
6676 NULL
, DEFAULT_FACE_ID
);
6677 it
.current_x
= this_line_start_x
;
6678 it
.current_y
= this_line_y
;
6679 it
.vpos
= this_line_vpos
;
6681 /* The call to move_it_to stops in front of PT, but
6682 moves over before-strings. */
6683 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
6685 if (it
.vpos
== this_line_vpos
6686 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
6689 xassert (this_line_vpos
== it
.vpos
);
6690 xassert (this_line_y
== it
.current_y
);
6691 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
6699 /* Text changed drastically or point moved off of line. */
6700 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
6703 CHARPOS (this_line_start_pos
) = 0;
6704 consider_all_windows_p
|= buffer_shared
> 1;
6705 ++clear_face_cache_count
;
6708 /* Build desired matrices. If consider_all_windows_p is non-zero,
6709 do it for all windows on all frames. Otherwise do it for
6710 selected_window, only. */
6712 if (consider_all_windows_p
)
6714 Lisp_Object tail
, frame
;
6716 /* Clear the face cache eventually. */
6717 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
6719 clear_face_cache (0);
6720 clear_face_cache_count
= 0;
6723 /* Recompute # windows showing selected buffer. This will be
6724 incremented each time such a window is displayed. */
6727 FOR_EACH_FRAME (tail
, frame
)
6729 struct frame
*f
= XFRAME (frame
);
6730 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
6732 /* Mark all the scroll bars to be removed; we'll redeem
6733 the ones we want when we redisplay their windows. */
6734 if (condemn_scroll_bars_hook
)
6735 (*condemn_scroll_bars_hook
) (f
);
6737 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
6738 redisplay_windows (FRAME_ROOT_WINDOW (f
));
6740 /* Any scroll bars which redisplay_windows should have
6741 nuked should now go away. */
6742 if (judge_scroll_bars_hook
)
6743 (*judge_scroll_bars_hook
) (f
);
6747 else if (FRAME_VISIBLE_P (selected_frame
)
6748 && !FRAME_OBSCURED_P (selected_frame
))
6749 redisplay_window (selected_window
, 1);
6752 /* Compare desired and current matrices, perform output. */
6756 /* If fonts changed, display again. */
6757 if (fonts_changed_p
)
6760 /* Prevent various kinds of signals during display update.
6761 stdio is not robust about handling signals,
6762 which can cause an apparent I/O error. */
6763 if (interrupt_input
)
6767 if (consider_all_windows_p
)
6773 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
6777 if (!FRAMEP (XCONS (tail
)->car
))
6780 f
= XFRAME (XCONS (tail
)->car
);
6782 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
6783 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
6785 /* Mark all windows as to be updated. */
6786 set_window_update_flags (XWINDOW (f
->root_window
), 1);
6787 pause
|= update_frame (f
, 0, 0);
6790 if (hscroll_windows (f
->root_window
))
6793 mark_window_display_accurate (f
->root_window
, 1);
6794 if (frame_up_to_date_hook
!= 0)
6795 (*frame_up_to_date_hook
) (f
);
6802 if (FRAME_VISIBLE_P (selected_frame
)
6803 && !FRAME_OBSCURED_P (selected_frame
))
6805 XWINDOW (selected_window
)->must_be_updated_p
= 1;
6806 pause
= update_frame (selected_frame
, 0, 0);
6807 if (!pause
&& hscroll_windows (selected_window
))
6813 /* We may have called echo_area_display at the top of this
6814 function. If the echo area is on another frame, that may
6815 have put text on a frame other than the selected one, so the
6816 above call to update_frame would not have caught it. Catch
6819 Lisp_Object mini_window
;
6820 struct frame
*mini_frame
;
6822 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
6823 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6825 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
6827 XWINDOW (mini_window
)->must_be_updated_p
= 1;
6828 pause
|= update_frame (mini_frame
, 0, 0);
6829 if (!pause
&& hscroll_windows (mini_window
))
6835 /* If display was paused because of pending input, make sure we do a
6836 thorough update the next time. */
6839 /* Prevent the optimization at the beginning of
6840 redisplay_internal that tries a single-line update of the
6841 line containing the cursor in the selected window. */
6842 CHARPOS (this_line_start_pos
) = 0;
6844 /* Let the overlay arrow be updated the next time. */
6845 if (!NILP (last_arrow_position
))
6847 last_arrow_position
= Qt
;
6848 last_arrow_string
= Qt
;
6851 /* If we pause after scrolling, some rows in the current
6852 matrices of some windows are not valid. */
6853 if (!WINDOW_FULL_WIDTH_P (w
)
6854 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
6855 update_mode_lines
= 1;
6858 /* Now text on frame agrees with windows, so put info into the
6859 windows for partial redisplay to follow. */
6862 register struct buffer
*b
= XBUFFER (w
->buffer
);
6864 unchanged_modified
= BUF_MODIFF (b
);
6865 overlay_unchanged_modified
= BUF_OVERLAY_MODIFF (b
);
6866 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
6867 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
6869 if (consider_all_windows_p
)
6870 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
6873 XSETFASTINT (w
->last_point
, BUF_PT (b
));
6874 w
->last_cursor
= w
->cursor
;
6875 w
->last_cursor_off_p
= w
->cursor_off_p
;
6877 b
->clip_changed
= 0;
6878 w
->update_mode_line
= Qnil
;
6879 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
6880 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
6882 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6885 /* Record if we are showing a region, so can make sure to
6886 update it fully at next redisplay. */
6887 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
6888 && (w
== XWINDOW (current_buffer
->last_selected_window
)
6889 || highlight_nonselected_windows
)
6890 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
6891 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
6894 w
->window_end_valid
= w
->buffer
;
6895 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
6896 last_arrow_string
= Voverlay_arrow_string
;
6897 if (frame_up_to_date_hook
!= 0)
6898 (*frame_up_to_date_hook
) (selected_frame
);
6901 update_mode_lines
= 0;
6902 windows_or_buffers_changed
= 0;
6905 /* Start SIGIO interrupts coming again. Having them off during the
6906 code above makes it less likely one will discard output, but not
6907 impossible, since there might be stuff in the system buffer here.
6908 But it is much hairier to try to do anything about that. */
6909 if (interrupt_input
)
6913 /* If a frame has become visible which was not before, redisplay
6914 again, so that we display it. Expose events for such a frame
6915 (which it gets when becoming visible) don't call the parts of
6916 redisplay constructing glyphs, so simply exposing a frame won't
6917 display anything in this case. So, we have to display these
6918 frames here explicitly. */
6921 Lisp_Object tail
, frame
;
6924 FOR_EACH_FRAME (tail
, frame
)
6926 int this_is_visible
= 0;
6928 if (XFRAME (frame
)->visible
)
6929 this_is_visible
= 1;
6930 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
6931 if (XFRAME (frame
)->visible
)
6932 this_is_visible
= 1;
6934 if (this_is_visible
)
6938 if (new_count
!= number_of_visible_frames
)
6939 windows_or_buffers_changed
++;
6942 /* Change frame size now if a change is pending. */
6943 do_pending_window_change ();
6945 /* If we just did a pending size change, or have additional
6946 visible frames, redisplay again. */
6947 if (windows_or_buffers_changed
&& !pause
)
6952 if (--redisplaying_p
< 0)
6957 /* Redisplay, but leave alone any recent echo area message unless
6958 another message has been requested in its place.
6960 This is useful in situations where you need to redisplay but no
6961 user action has occurred, making it inappropriate for the message
6962 area to be cleared. See tracking_off and
6963 wait_reading_process_input for examples of these situations. */
6966 redisplay_preserve_echo_area ()
6968 if (!echo_area_glyphs
6969 && !STRINGP (echo_area_message
)
6970 && (previous_echo_glyphs
6971 || STRINGP (previous_echo_area_message
)))
6973 echo_area_glyphs
= previous_echo_glyphs
;
6974 echo_area_message
= previous_echo_area_message
;
6975 echo_area_glyphs_length
= previous_echo_glyphs_length
;
6976 redisplay_internal (1);
6977 echo_area_glyphs
= NULL
;
6978 echo_area_message
= Qnil
;
6981 redisplay_internal (1);
6985 /* Mark the display of windows in the window tree rooted at WINDOW as
6986 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
6987 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
6988 the next time redisplay_internal is called. */
6991 mark_window_display_accurate (window
, accurate_p
)
6997 for (; !NILP (window
); window
= w
->next
)
6999 w
= XWINDOW (window
);
7001 if (BUFFERP (w
->buffer
))
7003 struct buffer
*b
= XBUFFER (w
->buffer
);
7005 XSETFASTINT (w
->last_modified
,
7006 accurate_p
? BUF_MODIFF (b
) : 0);
7007 XSETFASTINT (w
->last_overlay_modified
,
7008 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
7009 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
7012 #if 0 /* I don't think this is necessary because display_line does it.
7014 /* Record if we are showing a region, so can make sure to
7015 update it fully at next redisplay. */
7017 = (!NILP (Vtransient_mark_mode
)
7018 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7019 || highlight_nonselected_windows
)
7020 && (!NILP (b
->mark_active
)
7021 ? Fmarker_position (b
->mark
)
7027 b
->clip_changed
= 0;
7028 w
->last_cursor
= w
->cursor
;
7029 w
->last_cursor_off_p
= w
->cursor_off_p
;
7030 if (w
== XWINDOW (selected_window
))
7031 w
->last_point
= BUF_PT (b
);
7033 w
->last_point
= XMARKER (w
->pointm
)->charpos
;
7037 w
->window_end_valid
= w
->buffer
;
7038 w
->update_mode_line
= Qnil
;
7040 if (!NILP (w
->vchild
))
7041 mark_window_display_accurate (w
->vchild
, accurate_p
);
7042 if (!NILP (w
->hchild
))
7043 mark_window_display_accurate (w
->hchild
, accurate_p
);
7048 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7049 last_arrow_string
= Voverlay_arrow_string
;
7053 /* Force a thorough redisplay the next time by setting
7054 last_arrow_position and last_arrow_string to t, which is
7055 unequal to any useful value of Voverlay_arrow_... */
7056 last_arrow_position
= Qt
;
7057 last_arrow_string
= Qt
;
7062 /* Return value in display table DP (Lisp_Char_Table *) for character
7063 C. Since a display table doesn't have any parent, we don't have to
7064 follow parent. Do not call this function directly but use the
7065 macro DISP_CHAR_VECTOR. */
7068 disp_char_vector (dp
, c
)
7069 struct Lisp_Char_Table
*dp
;
7075 if (SINGLE_BYTE_CHAR_P (c
))
7076 return (dp
->contents
[c
]);
7078 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
7079 if (code
[0] != CHARSET_COMPOSITION
)
7083 else if (code
[2] < 32)
7087 /* Here, the possible range of code[0] (== charset ID) is
7088 128..max_charset. Since the top level char table contains data
7089 for multibyte characters after 256th element, we must increment
7090 code[0] by 128 to get a correct index. */
7092 code
[3] = -1; /* anchor */
7094 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
7096 val
= dp
->contents
[code
[i
]];
7097 if (!SUB_CHAR_TABLE_P (val
))
7098 return (NILP (val
) ? dp
->defalt
: val
);
7101 /* Here, val is a sub char table. We return the default value of
7103 return (dp
->defalt
);
7108 /***********************************************************************
7110 ***********************************************************************/
7112 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
7115 redisplay_windows (window
)
7118 while (!NILP (window
))
7120 struct window
*w
= XWINDOW (window
);
7122 if (!NILP (w
->hchild
))
7123 redisplay_windows (w
->hchild
);
7124 else if (!NILP (w
->vchild
))
7125 redisplay_windows (w
->vchild
);
7127 redisplay_window (window
, 0);
7134 /* Set cursor position of W. PT is assumed to be displayed in ROW.
7135 DELTA is the number of bytes by which positions recorded in ROW
7136 differ from current buffer positions. */
7139 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
7141 struct glyph_row
*row
;
7142 struct glyph_matrix
*matrix
;
7143 int delta
, delta_bytes
, dy
, dvpos
;
7145 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
7146 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
7148 int pt_old
= PT
- delta
;
7150 /* Skip over glyphs not having an object at the start of the row.
7151 These are special glyphs like truncation marks on terminal
7153 if (row
->displays_text_p
)
7156 && glyph
->charpos
< 0)
7158 x
+= glyph
->pixel_width
;
7164 && (!BUFFERP (glyph
->object
)
7165 || glyph
->charpos
< pt_old
))
7167 x
+= glyph
->pixel_width
;
7171 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7173 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
7174 w
->cursor
.y
= row
->y
+ dy
;
7176 if (w
== XWINDOW (selected_window
))
7178 if (!row
->continued_p
7179 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
7182 this_line_buffer
= XBUFFER (w
->buffer
);
7184 CHARPOS (this_line_start_pos
)
7185 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
7186 BYTEPOS (this_line_start_pos
)
7187 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
7189 CHARPOS (this_line_end_pos
)
7190 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
7191 BYTEPOS (this_line_end_pos
)
7192 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
7194 this_line_y
= w
->cursor
.y
;
7195 this_line_pixel_height
= row
->height
;
7196 this_line_vpos
= w
->cursor
.vpos
;
7197 this_line_start_x
= row
->x
;
7200 CHARPOS (this_line_start_pos
) = 0;
7205 /* Run window scroll functions, if any, for WINDOW with new window
7206 start STARTP. Sets the window start of WINDOW to that position. */
7208 static INLINE
struct text_pos
7209 run_window_scroll_functions (window
, startp
)
7211 struct text_pos startp
;
7213 struct window
*w
= XWINDOW (window
);
7214 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
7216 if (!NILP (Vwindow_scroll_functions
))
7218 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
7219 make_number (CHARPOS (startp
)));
7220 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
7227 /* Modify the desired matrix of window W and W->vscroll so that the
7228 line containing the cursor is fully visible. */
7231 make_cursor_line_fully_visible (w
)
7234 struct glyph_matrix
*matrix
;
7235 struct glyph_row
*row
;
7236 int top_line_height
;
7238 /* It's not always possible to find the cursor, e.g, when a window
7239 is full of overlay strings. Don't do anything in that case. */
7240 if (w
->cursor
.vpos
< 0)
7243 matrix
= w
->desired_matrix
;
7244 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
7246 /* If row->y == top y of window display area, the window isn't tall
7247 enough to display a single line. There is nothing we can do
7249 top_line_height
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
7250 if (row
->y
== top_line_height
)
7253 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
7255 int dy
= row
->height
- row
->visible_height
;
7258 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
7260 else if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w
, row
))
7262 int dy
= - (row
->height
- row
->visible_height
);
7265 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
7268 /* When we change the cursor y-position of the selected window,
7269 change this_line_y as well so that the display optimization for
7270 the cursor line of the selected window in redisplay_internal uses
7271 the correct y-position. */
7272 if (w
== XWINDOW (selected_window
))
7273 this_line_y
= w
->cursor
.y
;
7277 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
7278 non-zero means only WINDOW is redisplayed in redisplay_internal.
7279 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
7280 in redisplay_window to bring a partially visible line into view in
7281 the case that only the cursor has moved.
7285 1 if scrolling succeeded
7287 0 if scrolling didn't find point.
7289 -1 if new fonts have been loaded so that we must interrupt
7290 redisplay, adjust glyph matrices, and try again. */
7293 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
7294 scroll_step
, temp_scroll_step
)
7296 int just_this_one_p
;
7297 int scroll_conservatively
, scroll_step
;
7298 int temp_scroll_step
;
7300 struct window
*w
= XWINDOW (window
);
7301 struct frame
*f
= XFRAME (w
->frame
);
7302 struct text_pos scroll_margin_pos
;
7303 struct text_pos pos
;
7304 struct text_pos startp
;
7306 Lisp_Object window_end
;
7307 int this_scroll_margin
;
7310 int line_height
, rc
;
7311 int amount_to_scroll
= 0;
7312 Lisp_Object aggressive
;
7316 debug_method_add (w
, "try_scrolling");
7319 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
7321 /* Compute scroll margin height in pixels. We scroll when point is
7322 within this distance from the top or bottom of the window. */
7323 if (scroll_margin
> 0)
7325 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
7326 this_scroll_margin
*= CANON_Y_UNIT (f
);
7329 this_scroll_margin
= 0;
7331 /* Compute how much we should try to scroll maximally to bring point
7334 scroll_max
= scroll_step
;
7335 else if (scroll_conservatively
)
7336 scroll_max
= scroll_conservatively
;
7337 else if (temp_scroll_step
)
7338 scroll_max
= temp_scroll_step
;
7339 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
7340 || NUMBERP (current_buffer
->scroll_up_aggressively
))
7341 /* We're trying to scroll because of aggressive scrolling
7342 but no scroll_step is set. Choose an arbitrary one. Maybe
7343 there should be a variable for this. */
7347 scroll_max
*= CANON_Y_UNIT (f
);
7349 /* Decide whether we have to scroll down. Start at the window end
7350 and move this_scroll_margin up to find the position of the scroll
7352 window_end
= Fwindow_end (window
, Qt
);
7353 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
7354 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
7355 if (this_scroll_margin
)
7357 start_display (&it
, w
, scroll_margin_pos
);
7358 move_it_vertically (&it
, - this_scroll_margin
);
7359 scroll_margin_pos
= it
.current
.pos
;
7362 if (PT
>= CHARPOS (scroll_margin_pos
))
7366 /* Point is in the scroll margin at the bottom of the window, or
7367 below. Compute a new window start that makes point visible. */
7369 /* Compute the distance from the scroll margin to PT.
7370 Give up if the distance is greater than scroll_max. */
7371 start_display (&it
, w
, scroll_margin_pos
);
7373 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
7374 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
7375 line_height
= (it
.max_ascent
+ it
.max_descent
7376 ? it
.max_ascent
+ it
.max_descent
7378 dy
= it
.current_y
+ line_height
- y0
;
7379 if (dy
> scroll_max
)
7382 /* Move the window start down. If scrolling conservatively,
7383 move it just enough down to make point visible. If
7384 scroll_step is set, move it down by scroll_step. */
7385 start_display (&it
, w
, startp
);
7387 if (scroll_conservatively
)
7388 amount_to_scroll
= dy
;
7389 else if (scroll_step
|| temp_scroll_step
)
7390 amount_to_scroll
= scroll_max
;
7393 aggressive
= current_buffer
->scroll_down_aggressively
;
7394 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
7395 - WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
));
7396 if (NUMBERP (aggressive
))
7397 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
7400 if (amount_to_scroll
<= 0)
7403 move_it_vertically (&it
, amount_to_scroll
);
7404 startp
= it
.current
.pos
;
7408 /* See if point is inside the scroll margin at the top of the
7410 scroll_margin_pos
= startp
;
7411 if (this_scroll_margin
)
7413 start_display (&it
, w
, startp
);
7414 move_it_vertically (&it
, this_scroll_margin
);
7415 scroll_margin_pos
= it
.current
.pos
;
7418 if (PT
< CHARPOS (scroll_margin_pos
))
7420 /* Point is in the scroll margin at the top of the window or
7421 above what is displayed in the window. */
7424 /* Compute the vertical distance from PT to the scroll
7425 margin position. Give up if distance is greater than
7427 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
7428 start_display (&it
, w
, pos
);
7430 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
7431 it
.last_visible_y
, -1,
7432 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
7433 dy
= it
.current_y
- y0
;
7434 if (dy
> scroll_max
)
7437 /* Compute new window start. */
7438 start_display (&it
, w
, startp
);
7440 if (scroll_conservatively
)
7441 amount_to_scroll
= dy
;
7442 else if (scroll_step
|| temp_scroll_step
)
7443 amount_to_scroll
= scroll_max
;
7446 aggressive
= current_buffer
->scroll_up_aggressively
;
7447 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
7448 - WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
));
7449 if (NUMBERP (aggressive
))
7450 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
7453 if (amount_to_scroll
<= 0)
7456 move_it_vertically (&it
, - amount_to_scroll
);
7457 startp
= it
.current
.pos
;
7461 /* Run window scroll functions. */
7462 startp
= run_window_scroll_functions (window
, startp
);
7464 /* Display the window. Give up if new fonts are loaded, or if point
7466 if (!try_window (window
, startp
))
7468 else if (w
->cursor
.vpos
< 0)
7470 clear_glyph_matrix (w
->desired_matrix
);
7475 /* Maybe forget recorded base line for line number display. */
7476 if (!just_this_one_p
7477 || current_buffer
->clip_changed
7478 || beg_unchanged
< CHARPOS (startp
))
7479 w
->base_line_number
= Qnil
;
7481 /* If cursor ends up on a partially visible line, shift display
7482 lines up or down. */
7483 make_cursor_line_fully_visible (w
);
7491 /* Compute a suitable window start for window W if display of W starts
7492 on a continuation line. Value is non-zero if a new window start
7495 The new window start will be computed, based on W's width, starting
7496 from the start of the continued line. It is the start of the
7497 screen line with the minimum distance from the old start W->start. */
7500 compute_window_start_on_continuation_line (w
)
7503 struct text_pos pos
, start_pos
;
7504 int window_start_changed_p
= 0;
7506 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
7508 /* If window start is on a continuation line... Window start may be
7509 < BEGV in case there's invisible text at the start of the
7510 buffer (M-x rmail, for example). */
7511 if (CHARPOS (start_pos
) > BEGV
7512 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
7515 struct glyph_row
*row
;
7517 /* Find the start of the continued line. This should be fast
7518 because scan_buffer is fast (newline cache). */
7519 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_TOP_LINE_P (w
) ? 1 : 0);
7520 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
7521 row
, DEFAULT_FACE_ID
);
7522 reseat_at_previous_visible_line_start (&it
);
7524 /* If the line start is "too far" away from the window start,
7525 say it takes too much time to compute a new window start. */
7526 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
7527 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
7529 int min_distance
, distance
;
7531 /* Move forward by display lines to find the new window
7532 start. If window width was enlarged, the new start can
7533 be expected to be > the old start. If window width was
7534 decreased, the new window start will be < the old start.
7535 So, we're looking for the display line start with the
7536 minimum distance from the old window start. */
7537 pos
= it
.current
.pos
;
7538 min_distance
= INFINITY
;
7539 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
7540 distance
< min_distance
)
7542 min_distance
= distance
;
7543 pos
= it
.current
.pos
;
7544 move_it_by_lines (&it
, 1, 0);
7547 /* Set the window start there. */
7548 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
7549 window_start_changed_p
= 1;
7553 return window_start_changed_p
;
7557 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
7558 selected_window is redisplayed. */
7561 redisplay_window (window
, just_this_one_p
)
7563 int just_this_one_p
;
7565 struct window
*w
= XWINDOW (window
);
7566 struct frame
*f
= XFRAME (w
->frame
);
7567 struct buffer
*buffer
= XBUFFER (w
->buffer
);
7568 struct buffer
*old
= current_buffer
;
7569 struct text_pos lpoint
, opoint
, startp
;
7570 int update_mode_line
;
7573 /* Record it now because it's overwritten. */
7574 int current_matrix_up_to_date_p
= 0;
7575 int really_switched_buffer
= 0;
7576 int temp_scroll_step
= 0;
7577 int count
= specpdl_ptr
- specpdl
;
7579 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
7582 /* W must be a leaf window here. */
7583 xassert (!NILP (w
->buffer
));
7585 *w
->desired_matrix
->method
= 0;
7588 specbind (Qinhibit_point_motion_hooks
, Qt
);
7590 /* Has the mode line to be updated? */
7591 update_mode_line
= (!NILP (w
->update_mode_line
)
7592 || update_mode_lines
7593 || buffer
->clip_changed
);
7595 if (MINI_WINDOW_P (w
))
7597 if (w
== XWINDOW (echo_area_window
)
7598 && (echo_area_glyphs
7599 || STRINGP (echo_area_message
)))
7601 if (update_mode_line
)
7602 /* We may have to update a tty frame's menu bar or a
7603 toolbar. Example `M-x C-h C-h C-g'. */
7604 goto finish_menu_bars
;
7606 /* We've already displayed the echo area glyphs in this window. */
7607 goto finish_scroll_bars
;
7609 else if (w
!= XWINDOW (minibuf_window
))
7611 /* W is a mini-buffer window, but it's not the currently
7612 active one, so clear it. */
7613 int yb
= window_text_bottom_y (w
);
7614 struct glyph_row
*row
;
7617 for (y
= 0, row
= w
->desired_matrix
->rows
;
7619 y
+= row
->height
, ++row
)
7620 blank_row (w
, row
, y
);
7621 goto finish_scroll_bars
;
7625 /* Otherwise set up data on this window; select its buffer and point
7627 if (update_mode_line
)
7629 /* Really select the buffer, for the sake of buffer-local
7631 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7632 really_switched_buffer
= 1;
7635 set_buffer_temp (XBUFFER (w
->buffer
));
7636 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
7638 current_matrix_up_to_date_p
7639 = (!NILP (w
->window_end_valid
)
7640 && !current_buffer
->clip_changed
7641 && XFASTINT (w
->last_modified
) >= MODIFF
7642 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
7644 /* When windows_or_buffers_changed is non-zero, we can't rely on
7645 the window end being valid, so set it to nil there. */
7646 if (windows_or_buffers_changed
)
7648 /* If window starts on a continuation line, maybe adjust the
7649 window start in case the window's width changed. */
7650 if (XMARKER (w
->start
)->buffer
== current_buffer
)
7651 compute_window_start_on_continuation_line (w
);
7653 w
->window_end_valid
= Qnil
;
7656 /* Some sanity checks. */
7657 CHECK_WINDOW_END (w
);
7658 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
7660 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
7663 /* If %c is in mode line, update it if needed. */
7664 if (!NILP (w
->column_number_displayed
)
7665 /* This alternative quickly identifies a common case
7666 where no change is needed. */
7667 && !(PT
== XFASTINT (w
->last_point
)
7668 && XFASTINT (w
->last_modified
) >= MODIFF
7669 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7670 && XFASTINT (w
->column_number_displayed
) != current_column ())
7671 update_mode_line
= 1;
7673 /* Count number of windows showing the selected buffer. An indirect
7674 buffer counts as its base buffer. */
7675 if (!just_this_one_p
)
7677 struct buffer
*current_base
, *window_base
;
7678 current_base
= current_buffer
;
7679 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
7680 if (current_base
->base_buffer
)
7681 current_base
= current_base
->base_buffer
;
7682 if (window_base
->base_buffer
)
7683 window_base
= window_base
->base_buffer
;
7684 if (current_base
== window_base
)
7688 /* Point refers normally to the selected window. For any other
7689 window, set up appropriate value. */
7690 if (!EQ (window
, selected_window
))
7692 int new_pt
= XMARKER (w
->pointm
)->charpos
;
7693 int new_pt_byte
= marker_byte_position (w
->pointm
);
7697 new_pt_byte
= BEGV_BYTE
;
7698 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
7700 else if (new_pt
> (ZV
- 1))
7703 new_pt_byte
= ZV_BYTE
;
7704 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
7707 /* We don't use SET_PT so that the point-motion hooks don't run. */
7708 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
7711 /* If any of the character widths specified in the display table
7712 have changed, invalidate the width run cache. It's true that
7713 this may be a bit late to catch such changes, but the rest of
7714 redisplay goes (non-fatally) haywire when the display table is
7715 changed, so why should we worry about doing any better? */
7716 if (current_buffer
->width_run_cache
)
7718 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
7720 if (! disptab_matches_widthtab (disptab
,
7721 XVECTOR (current_buffer
->width_table
)))
7723 invalidate_region_cache (current_buffer
,
7724 current_buffer
->width_run_cache
,
7726 recompute_width_table (current_buffer
, disptab
);
7730 /* If window-start is screwed up, choose a new one. */
7731 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
7734 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
7736 /* If someone specified a new starting point but did not insist,
7737 check whether it can be used. */
7738 if (!NILP (w
->optional_new_start
))
7740 w
->optional_new_start
= Qnil
;
7741 /* This takes a mini-buffer prompt into account. */
7742 start_display (&it
, w
, startp
);
7743 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
7744 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
7745 if (IT_CHARPOS (it
) == PT
)
7746 w
->force_start
= Qt
;
7749 /* Handle case where place to start displaying has been specified,
7750 unless the specified location is outside the accessible range. */
7751 if (!NILP (w
->force_start
))
7753 w
->force_start
= Qnil
;
7755 w
->window_end_valid
= Qnil
;
7757 /* Forget any recorded base line for line number display. */
7758 if (!current_matrix_up_to_date_p
7759 || current_buffer
->clip_changed
)
7760 w
->base_line_number
= Qnil
;
7762 /* Redisplay the mode line. Select the buffer properly for that.
7763 Also, run the hook window-scroll-functions
7764 because we have scrolled. */
7765 /* Note, we do this after clearing force_start because
7766 if there's an error, it is better to forget about force_start
7767 than to get into an infinite loop calling the hook functions
7768 and having them get more errors. */
7769 if (!update_mode_line
7770 || ! NILP (Vwindow_scroll_functions
))
7772 if (!really_switched_buffer
)
7774 set_buffer_temp (old
);
7775 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7776 really_switched_buffer
= 1;
7779 update_mode_line
= 1;
7780 w
->update_mode_line
= Qt
;
7781 startp
= run_window_scroll_functions (window
, startp
);
7784 XSETFASTINT (w
->last_modified
, 0);
7785 XSETFASTINT (w
->last_overlay_modified
, 0);
7786 if (CHARPOS (startp
) < BEGV
)
7787 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
7788 else if (CHARPOS (startp
) > ZV
)
7789 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
7791 /* Redisplay, then check if cursor has been set during the
7792 redisplay. Give up if new fonts were loaded. */
7793 if (!try_window (window
, startp
))
7795 w
->force_start
= Qt
;
7796 clear_glyph_matrix (w
->desired_matrix
);
7797 goto restore_buffers
;
7800 if (w
->cursor
.vpos
< 0)
7802 /* If point does not appear, or on a line that is not fully
7803 visible, move point so it does appear. The desired
7804 matrix has been built above, so we can use it. */
7805 int height
= window_box_height (w
) / 2;
7806 struct glyph_row
*row
= MATRIX_ROW (w
->desired_matrix
, 0);
7808 while (row
->y
< height
)
7811 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
7812 MATRIX_ROW_START_BYTEPOS (row
));
7814 if (w
!= XWINDOW (selected_window
))
7815 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
7816 else if (current_buffer
== old
)
7817 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
7819 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
7821 /* If we are highlighting the region, then we just changed
7822 the region, so redisplay to show it. */
7823 if (!NILP (Vtransient_mark_mode
)
7824 && !NILP (current_buffer
->mark_active
))
7826 clear_glyph_matrix (w
->desired_matrix
);
7827 if (!try_window (window
, startp
))
7828 goto restore_buffers
;
7832 make_cursor_line_fully_visible (w
);
7834 debug_method_add (w
, "forced window start");
7839 /* Handle case where text has not changed, only point, and it has
7840 not moved off the frame. */
7841 if (current_matrix_up_to_date_p
7842 /* Point may be in this window. */
7843 && PT
>= CHARPOS (startp
)
7844 /* If we don't check this, we are called to move the cursor in a
7845 horizontally split window with a current matrix that doesn't
7847 && !windows_or_buffers_changed
7848 /* Selective display hasn't changed. */
7849 && !current_buffer
->clip_changed
7850 /* If force-mode-line-update was called, really redisplay;
7851 that's how redisplay is forced after e.g. changing
7852 buffer-invisibility-spec. */
7853 && NILP (w
->update_mode_line
)
7854 /* Can't use this case if highlighting a region. When a
7855 region exists, cursor movement has to do more than just
7857 && !(!NILP (Vtransient_mark_mode
)
7858 && !NILP (current_buffer
->mark_active
))
7859 && NILP (w
->region_showing
)
7860 /* Right after splitting windows, last_point may be nil. */
7861 && INTEGERP (w
->last_point
)
7862 /* This code is not used for mini-buffer for the sake of the case
7863 of redisplaying to replace an echo area message; since in
7864 that case the mini-buffer contents per se are usually
7865 unchanged. This code is of no real use in the mini-buffer
7866 since the handling of this_line_start_pos, etc., in redisplay
7867 handles the same cases. */
7868 && !EQ (window
, minibuf_window
)
7869 /* When splitting windows or for new windows, it happens that
7870 redisplay is called with a nil window_end_vpos or one being
7871 larger than the window. This should really be fixed in
7872 window.c. I don't have this on my list, now, so we do
7873 approximately the same as the old redisplay code. --gerd. */
7874 && INTEGERP (w
->window_end_vpos
)
7875 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
7876 && (FRAME_WINDOW_P (f
)
7877 || !MARKERP (Voverlay_arrow_position
)
7878 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
7880 int this_scroll_margin
;
7881 struct glyph_row
*row
;
7885 debug_method_add (w
, "cursor movement");
7888 /* Scroll if point within this distance from the top or bottom
7889 of the window. This is a pixel value. */
7890 this_scroll_margin
= max (0, scroll_margin
);
7891 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
7892 this_scroll_margin
*= CANON_Y_UNIT (f
);
7894 /* Start with the row the cursor was displayed during the last
7895 not paused redisplay. Give up if that row is not valid. */
7896 if (w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
7898 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
7899 if (row
->mode_line_p
)
7901 if (!row
->enabled_p
)
7905 if (PT
> XFASTINT (w
->last_point
))
7907 /* Point has moved forward. */
7908 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
7910 while ((MATRIX_ROW_END_CHARPOS (row
) < PT
7911 /* The end position of a row equals the start
7912 position of the next row. If PT is there, we
7913 would rather display it in the next line, except
7914 when this line ends in ZV. */
7915 || (MATRIX_ROW_END_CHARPOS (row
) == PT
7916 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
7917 || !row
->ends_at_zv_p
)))
7918 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
7920 xassert (row
->enabled_p
);
7924 /* If within the scroll margin, scroll. Note that
7925 MATRIX_ROW_BOTTOM_Y gives the pixel position at which the
7926 next line would be drawn, and that this_scroll_margin can
7928 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
7929 || PT
> MATRIX_ROW_END_CHARPOS (row
)
7930 /* Line is completely visible last line in window and PT
7931 is to be set in the next line. */
7932 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
7933 && PT
== MATRIX_ROW_END_CHARPOS (row
)
7934 && !row
->ends_at_zv_p
7935 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
7938 else if (PT
< XFASTINT (w
->last_point
))
7940 /* Cursor has to be moved backward. Note that PT >=
7941 CHARPOS (startp) because of the outer if-statement. */
7942 while (!row
->mode_line_p
7943 && (MATRIX_ROW_START_CHARPOS (row
) > PT
7944 || (MATRIX_ROW_START_CHARPOS (row
) == PT
7945 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
7946 && (row
->y
> this_scroll_margin
7947 || CHARPOS (startp
) == BEGV
))
7949 xassert (row
->enabled_p
);
7953 /* Consider the following case: Window starts at BEGV, there
7954 is invisible, intangible text at BEGV, so that display
7955 starts at some point START > BEGV. It can happen that
7956 we are called with PT somewhere between BEGV and START.
7957 Try to handle that case. */
7958 if (row
< w
->current_matrix
->rows
7959 || row
->mode_line_p
)
7961 row
= w
->current_matrix
->rows
;
7962 if (row
->mode_line_p
)
7966 /* Due to newlines in overlay strings, we may have to skip
7967 forward over overlay strings. */
7968 while (MATRIX_ROW_END_CHARPOS (row
) == PT
7969 && MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P (row
)
7970 && !row
->ends_at_zv_p
)
7973 /* If within the scroll margin, scroll. */
7974 if (row
->y
< this_scroll_margin
7975 && CHARPOS (startp
) != BEGV
)
7979 /* if PT is not in the glyph row, give up. */
7980 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
7981 || PT
> MATRIX_ROW_END_CHARPOS (row
))
7984 /* If we end up in a partially visible line, let's make it fully
7985 visible. This can be done most easily by using the existing
7987 if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
7989 temp_scroll_step
= 1;
7995 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
7999 /* If current starting point was originally the beginning of a line
8000 but no longer is, find a new starting point. */
8001 else if (!NILP (w
->start_at_line_beg
)
8002 && !(CHARPOS (startp
) <= BEGV
8003 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
8006 debug_method_add (w
, "recenter 1");
8011 /* Try scrolling with try_window_id. */
8012 else if (!windows_or_buffers_changed
8013 /* Window must be either use window-based redisplay or
8015 && (FRAME_WINDOW_P (f
)
8016 || ((line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
))
8017 && just_this_one_p
))
8018 && !MINI_WINDOW_P (w
)
8019 /* Point is not known NOT to appear in window. */
8020 && PT
>= CHARPOS (startp
)
8021 && XFASTINT (w
->last_modified
)
8022 /* Window is not hscrolled. */
8023 && XFASTINT (w
->hscroll
) == 0
8024 /* Selective display has not changed. */
8025 && !current_buffer
->clip_changed
8026 /* Current matrix is up to date. */
8027 && !NILP (w
->window_end_valid
)
8028 /* Can't use this case if highlighting a region because
8029 a cursor movement will do more than just set the cursor. */
8030 && !(!NILP (Vtransient_mark_mode
)
8031 && !NILP (current_buffer
->mark_active
))
8032 && NILP (w
->region_showing
)
8033 /* Overlay arrow position and string not changed. */
8034 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
8035 && EQ (last_arrow_string
, Voverlay_arrow_string
)
8036 /* Value is > 0 if update has been done, it is -1 if we
8037 know that the same window start will not work. It is 0
8038 if unsuccessful for some other reason. */
8039 && (tem
= try_window_id (w
)) != 0)
8042 debug_method_add (w
, "try_window_id");
8045 if (fonts_changed_p
)
8046 goto restore_buffers
;
8049 /* Otherwise try_window_id has returned -1 which means that we
8050 don't want the alternative below this comment to execute. */
8052 else if (CHARPOS (startp
) >= BEGV
8053 && CHARPOS (startp
) <= ZV
8054 && PT
>= CHARPOS (startp
)
8055 && (CHARPOS (startp
) < ZV
8056 /* Avoid starting at end of buffer. */
8057 || CHARPOS (startp
) == BEGV
8058 || (XFASTINT (w
->last_modified
) >= MODIFF
8059 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
8062 debug_method_add (w
, "same window start");
8065 /* Try to redisplay starting at same place as before.
8066 If point has not moved off frame, accept the results. */
8067 if (!current_matrix_up_to_date_p
8068 /* Don't use try_window_reusing_current_matrix in this case
8069 because it can have changed the buffer. */
8070 || !NILP (Vwindow_scroll_functions
)
8071 || MINI_WINDOW_P (w
)
8072 || !try_window_reusing_current_matrix (w
))
8074 IF_DEBUG (debug_method_add (w
, "1"));
8075 try_window (window
, startp
);
8078 if (fonts_changed_p
)
8079 goto restore_buffers
;
8081 if (w
->cursor
.vpos
>= 0)
8083 if (!just_this_one_p
8084 || current_buffer
->clip_changed
8085 || beg_unchanged
< CHARPOS (startp
))
8086 /* Forget any recorded base line for line number display. */
8087 w
->base_line_number
= Qnil
;
8089 make_cursor_line_fully_visible (w
);
8093 clear_glyph_matrix (w
->desired_matrix
);
8098 XSETFASTINT (w
->last_modified
, 0);
8099 XSETFASTINT (w
->last_overlay_modified
, 0);
8101 /* Redisplay the mode line. Select the buffer properly for that. */
8102 if (!update_mode_line
)
8104 if (!really_switched_buffer
)
8106 set_buffer_temp (old
);
8107 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8108 really_switched_buffer
= 1;
8110 update_mode_line
= 1;
8111 w
->update_mode_line
= Qt
;
8114 /* Try to scroll by specified few lines. */
8115 if ((scroll_conservatively
8118 || NUMBERP (current_buffer
->scroll_up_aggressively
)
8119 || NUMBERP (current_buffer
->scroll_down_aggressively
))
8120 && !current_buffer
->clip_changed
8121 && CHARPOS (startp
) >= BEGV
8122 && CHARPOS (startp
) <= ZV
)
8124 /* The function returns -1 if new fonts were loaded, 1 if
8125 successful, 0 if not successful. */
8126 int rc
= try_scrolling (window
, just_this_one_p
,
8127 scroll_conservatively
,
8133 goto restore_buffers
;
8136 /* Finally, just choose place to start which centers point */
8141 debug_method_add (w
, "recenter");
8144 /* w->vscroll = 0; */
8146 /* Forget any previously recorded base line for line number display. */
8147 if (!current_matrix_up_to_date_p
8148 || current_buffer
->clip_changed
)
8149 w
->base_line_number
= Qnil
;
8151 /* Move backward half the height of the window. */
8152 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
8153 it
.current_y
= it
.last_visible_y
;
8154 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
8155 xassert (IT_CHARPOS (it
) >= BEGV
);
8157 /* The function move_it_vertically_backward may move over more
8158 than the specified y-distance. If it->w is small, e.g. a
8159 mini-buffer window, we may end up in front of the window's
8160 display area. Start displaying at the start of the line
8161 containing PT in this case. */
8162 if (it
.current_y
<= 0)
8164 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
8165 move_it_vertically (&it
, 0);
8166 xassert (IT_CHARPOS (it
) <= PT
);
8170 it
.current_x
= it
.hpos
= 0;
8172 /* Set startp here explicitly in case that helps avoid an infinite loop
8173 in case the window-scroll-functions functions get errors. */
8174 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
8176 /* Run scroll hooks. */
8177 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
8179 /* Redisplay the window. */
8180 if (!current_matrix_up_to_date_p
8181 || windows_or_buffers_changed
8182 /* Don't use try_window_reusing_current_matrix in this case
8183 because it can have changed the buffer. */
8184 || !NILP (Vwindow_scroll_functions
)
8186 || MINI_WINDOW_P (w
)
8187 || !try_window_reusing_current_matrix (w
))
8188 try_window (window
, startp
);
8190 /* If new fonts have been loaded (due to fontsets), give up. We
8191 have to start a new redisplay since we need to re-adjust glyph
8193 if (fonts_changed_p
)
8194 goto restore_buffers
;
8196 /* If cursor did not appear assume that the middle of the window is
8197 in the first line of the window. Do it again with the next line.
8198 (Imagine a window of height 100, displaying two lines of height
8199 60. Moving back 50 from it->last_visible_y will end in the first
8201 if (w
->cursor
.vpos
< 0)
8203 if (!NILP (w
->window_end_valid
)
8204 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
8206 clear_glyph_matrix (w
->desired_matrix
);
8207 move_it_by_lines (&it
, 1, 0);
8208 try_window (window
, it
.current
.pos
);
8210 else if (PT
< IT_CHARPOS (it
))
8212 clear_glyph_matrix (w
->desired_matrix
);
8213 move_it_by_lines (&it
, -1, 0);
8214 try_window (window
, it
.current
.pos
);
8218 /* Not much we can do about it. */
8222 /* Consider the following case: Window starts at BEGV, there is
8223 invisible, intangible text at BEGV, so that display starts at
8224 some point START > BEGV. It can happen that we are called with
8225 PT somewhere between BEGV and START. Try to handle that case. */
8226 if (w
->cursor
.vpos
< 0)
8228 struct glyph_row
*row
= w
->current_matrix
->rows
;
8229 if (row
->mode_line_p
)
8231 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8234 make_cursor_line_fully_visible (w
);
8236 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8237 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
8238 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
8243 /* Display the mode line, if we must. */
8244 if ((update_mode_line
8245 /* If window not full width, must redo its mode line
8246 if (a) the window to its side is being redone and
8247 (b) we do a frame-based redisplay. This is a consequence
8248 of how inverted lines are drawn in frame-based redisplay. */
8249 || (!just_this_one_p
8250 && !FRAME_WINDOW_P (f
)
8251 && !WINDOW_FULL_WIDTH_P (w
))
8252 /* Line number to display. */
8253 || INTEGERP (w
->base_line_pos
)
8254 /* Column number is displayed and different from the one displayed. */
8255 || (!NILP (w
->column_number_displayed
)
8256 && XFASTINT (w
->column_number_displayed
) != current_column ()))
8257 /* This means that the window has a mode line. */
8258 && (WINDOW_WANTS_MODELINE_P (w
)
8259 || WINDOW_WANTS_TOP_LINE_P (w
)))
8261 display_mode_lines (w
);
8263 /* If mode line height has changed, arrange for a thorough
8264 immediate redisplay using the correct mode line height. */
8265 if (WINDOW_WANTS_MODELINE_P (w
)
8266 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
8268 fonts_changed_p
= 1;
8269 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
8270 = DESIRED_MODE_LINE_HEIGHT (w
);
8273 /* If top line height has changed, arrange for a thorough
8274 immediate redisplay using the correct mode line height. */
8275 if (WINDOW_WANTS_TOP_LINE_P (w
)
8276 && CURRENT_TOP_LINE_HEIGHT (w
) != DESIRED_TOP_LINE_HEIGHT (w
))
8278 fonts_changed_p
= 1;
8279 MATRIX_TOP_LINE_ROW (w
->current_matrix
)->height
8280 = DESIRED_TOP_LINE_HEIGHT (w
);
8283 if (fonts_changed_p
)
8284 goto restore_buffers
;
8287 if (!line_number_displayed
8288 && !BUFFERP (w
->base_line_pos
))
8290 w
->base_line_pos
= Qnil
;
8291 w
->base_line_number
= Qnil
;
8296 /* When we reach a frame's selected window, redo the frame's menu bar. */
8297 if (update_mode_line
8298 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
8300 int redisplay_menu_p
= 0;
8302 if (FRAME_WINDOW_P (f
))
8304 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
8305 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
8307 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
8311 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
8313 if (redisplay_menu_p
)
8314 display_menu_bar (w
);
8316 #ifdef HAVE_WINDOW_SYSTEM
8317 if (WINDOWP (f
->toolbar_window
)
8318 && (FRAME_TOOLBAR_LINES (f
) > 0
8319 || auto_resize_toolbars_p
))
8320 redisplay_toolbar (f
);
8326 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8328 int start
, end
, whole
;
8330 /* Calculate the start and end positions for the current window.
8331 At some point, it would be nice to choose between scrollbars
8332 which reflect the whole buffer size, with special markers
8333 indicating narrowing, and scrollbars which reflect only the
8336 Note that mini-buffers sometimes aren't displaying any text. */
8337 if (! MINI_WINDOW_P (w
)
8338 || (w
== XWINDOW (minibuf_window
)
8339 && !echo_area_glyphs
8340 && !STRINGP (echo_area_message
)))
8343 start
= marker_position (w
->start
) - BEGV
;
8344 /* I don't think this is guaranteed to be right. For the
8345 moment, we'll pretend it is. */
8346 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
8350 if (whole
< (end
- start
))
8351 whole
= end
- start
;
8354 start
= end
= whole
= 0;
8356 /* Indicate what this scroll bar ought to be displaying now. */
8357 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
8359 /* Note that we actually used the scroll bar attached to this
8360 window, so it shouldn't be deleted at the end of redisplay. */
8361 (*redeem_scroll_bar_hook
) (w
);
8366 /* Restore current_buffer and value of point in it. */
8367 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
8368 if (really_switched_buffer
)
8369 set_buffer_internal_1 (old
);
8371 set_buffer_temp (old
);
8372 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
8374 unbind_to (count
, Qnil
);
8378 /* Build the complete desired matrix of WINDOW with a window start
8379 buffer position POS. Value is non-zero if successful. It is zero
8380 if fonts were loaded during redisplay which makes re-adjusting
8381 glyph matrices necessary. */
8384 try_window (window
, pos
)
8386 struct text_pos pos
;
8388 struct window
*w
= XWINDOW (window
);
8390 struct glyph_row
*last_text_row
= NULL
;
8392 /* Make POS the new window start. */
8393 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
8395 /* Mark cursor position as unknown. No overlay arrow seen. */
8396 w
->cursor
.vpos
= -1;
8397 overlay_arrow_seen
= 0;
8399 /* Initialize iterator and info to start at POS. */
8400 start_display (&it
, w
, pos
);
8402 /* Display all lines of W. */
8403 while (it
.current_y
< it
.last_visible_y
)
8405 if (display_line (&it
))
8406 last_text_row
= it
.glyph_row
- 1;
8407 if (fonts_changed_p
)
8411 /* If bottom moved off end of frame, change mode line percentage. */
8412 if (XFASTINT (w
->window_end_pos
) <= 0
8413 && Z
!= IT_CHARPOS (it
))
8414 w
->update_mode_line
= Qt
;
8416 /* Set window_end_pos to the offset of the last character displayed
8417 on the window from the end of current_buffer. Set
8418 window_end_vpos to its row number. */
8421 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
8422 w
->window_end_bytepos
8423 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
8424 XSETFASTINT (w
->window_end_pos
,
8425 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
8426 XSETFASTINT (w
->window_end_vpos
,
8427 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
8428 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
8433 w
->window_end_bytepos
= 0;
8434 XSETFASTINT (w
->window_end_pos
, 0);
8435 XSETFASTINT (w
->window_end_vpos
, 0);
8438 /* But that is not valid info until redisplay finishes. */
8439 w
->window_end_valid
= Qnil
;
8445 /************************************************************************
8446 Window redisplay reusing current matrix when buffer has not changed
8447 ************************************************************************/
8449 /* Try redisplay of window W showing an unchanged buffer with a
8450 different window start than the last time it was displayed by
8451 reusing its current matrix. Value is non-zero if successful.
8452 W->start is the new window start. */
8455 try_window_reusing_current_matrix (w
)
8458 struct frame
*f
= XFRAME (w
->frame
);
8459 struct glyph_row
*row
, *bottom_row
;
8462 struct text_pos start
, new_start
;
8463 int nrows_scrolled
, i
;
8464 struct glyph_row
*last_text_row
;
8465 struct glyph_row
*last_reused_text_row
;
8466 struct glyph_row
*start_row
;
8467 int start_vpos
, min_y
, max_y
;
8469 /* Right now this function doesn't handle terminal frames. */
8470 if (!FRAME_WINDOW_P (f
))
8473 /* Can't do this if region may have changed. */
8474 if ((!NILP (Vtransient_mark_mode
)
8475 && !NILP (current_buffer
->mark_active
))
8476 || !NILP (w
->region_showing
))
8479 /* If top-line visibility has changed, give up. */
8480 if (WINDOW_WANTS_TOP_LINE_P (w
)
8481 != MATRIX_TOP_LINE_ROW (w
->current_matrix
)->mode_line_p
)
8484 /* Give up if old or new display is scrolled vertically. We could
8485 make this function handle this, but right now it doesn't. */
8486 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8487 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
8490 /* The variable new_start now holds the new window start. The old
8491 start `start' can be determined from the current matrix. */
8492 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
8493 start
= start_row
->start
.pos
;
8494 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
8496 /* Clear the desired matrix for the display below. */
8497 clear_glyph_matrix (w
->desired_matrix
);
8499 if (CHARPOS (new_start
) <= CHARPOS (start
))
8503 IF_DEBUG (debug_method_add (w
, "twu1"));
8505 /* Display up to a row that can be reused. The variable
8506 last_text_row is set to the last row displayed that displays
8508 start_display (&it
, w
, new_start
);
8509 first_row_y
= it
.current_y
;
8510 w
->cursor
.vpos
= -1;
8511 last_text_row
= last_reused_text_row
= NULL
;
8512 while (it
.current_y
< it
.last_visible_y
8513 && IT_CHARPOS (it
) < CHARPOS (start
)
8514 && !fonts_changed_p
)
8515 if (display_line (&it
))
8516 last_text_row
= it
.glyph_row
- 1;
8518 /* A value of current_y < last_visible_y means that we stopped
8519 at the previous window start, which in turn means that we
8520 have at least one reusable row. */
8521 if (it
.current_y
< it
.last_visible_y
)
8523 nrows_scrolled
= it
.vpos
;
8525 /* Find PT if not already found in the lines displayed. */
8526 if (w
->cursor
.vpos
< 0)
8528 int dy
= it
.current_y
- first_row_y
;
8530 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8531 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
8533 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
8534 && PT
< MATRIX_ROW_END_CHARPOS (row
))
8536 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
8537 dy
, nrows_scrolled
);
8541 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
8547 /* Give up if point was not found. This shouldn't
8548 happen often; not more often than with try_window
8550 if (w
->cursor
.vpos
< 0)
8552 clear_glyph_matrix (w
->desired_matrix
);
8557 /* Scroll the display. Do it before the current matrix is
8558 changed. The problem here is that update has not yet
8559 run, i.e. part of the current matrix is not up to date.
8560 scroll_run_hook will clear the cursor, and use the
8561 current matrix to get the height of the row the cursor is
8563 run
.current_y
= first_row_y
;
8564 run
.desired_y
= it
.current_y
;
8565 run
.height
= it
.last_visible_y
- it
.current_y
;
8569 rif
->update_window_begin_hook (w
);
8570 rif
->scroll_run_hook (w
, &run
);
8571 rif
->update_window_end_hook (w
, 0);
8575 /* Shift current matrix down by nrows_scrolled lines. */
8576 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
8577 rotate_matrix (w
->current_matrix
,
8579 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
8582 /* Disable lines not reused. */
8583 for (i
= 0; i
< it
.vpos
; ++i
)
8584 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
8586 /* Re-compute Y positions. */
8587 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
) + nrows_scrolled
;
8588 min_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
8589 max_y
= it
.last_visible_y
;
8590 while (row
< bottom_row
)
8592 row
->y
= it
.current_y
;
8595 row
->visible_height
= row
->height
- (min_y
- row
->y
);
8596 else if (row
->y
+ row
->height
> max_y
)
8598 = row
->height
- (row
->y
+ row
->height
- max_y
);
8600 row
->visible_height
= row
->height
;
8602 it
.current_y
+= row
->height
;
8605 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
8606 last_reused_text_row
= row
;
8607 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
8613 /* Update window_end_pos etc.; last_reused_text_row is the last
8614 reused row from the current matrix containing text, if any.
8615 The value of last_text_row is the last displayed line
8617 if (last_reused_text_row
)
8619 w
->window_end_bytepos
8620 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
8621 XSETFASTINT (w
->window_end_pos
,
8622 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
8623 XSETFASTINT (w
->window_end_vpos
,
8624 MATRIX_ROW_VPOS (last_reused_text_row
,
8625 w
->current_matrix
));
8627 else if (last_text_row
)
8629 w
->window_end_bytepos
8630 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
8631 XSETFASTINT (w
->window_end_pos
,
8632 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
8633 XSETFASTINT (w
->window_end_vpos
,
8634 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
8638 /* This window must be completely empty. */
8639 w
->window_end_bytepos
= 0;
8640 XSETFASTINT (w
->window_end_pos
, 0);
8641 XSETFASTINT (w
->window_end_vpos
, 0);
8643 w
->window_end_valid
= Qnil
;
8645 /* Update hint: don't try scrolling again in update_window. */
8646 w
->desired_matrix
->no_scrolling_p
= 1;
8649 debug_method_add (w
, "try_window_reusing_current_matrix 1");
8653 else if (CHARPOS (new_start
) > CHARPOS (start
))
8655 struct glyph_row
*pt_row
, *row
;
8656 struct glyph_row
*first_reusable_row
;
8657 struct glyph_row
*first_row_to_display
;
8659 int yb
= window_text_bottom_y (w
);
8661 IF_DEBUG (debug_method_add (w
, "twu2"));
8663 /* Find the row starting at new_start, if there is one. Don't
8664 reuse a partially visible line at the end. */
8665 first_reusable_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8666 while (first_reusable_row
->enabled_p
8667 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
8668 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
8669 < CHARPOS (new_start
)))
8670 ++first_reusable_row
;
8672 /* Give up if there is no row to reuse. */
8673 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
8674 || !first_reusable_row
->enabled_p
)
8677 /* The row we found must start at new_start, or else something
8679 xassert (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
8680 == CHARPOS (new_start
));
8682 /* We can reuse fully visible rows beginning with
8683 first_reusable_row to the end of the window. Set
8684 first_row_to_display to the first row that cannot be reused.
8685 Set pt_row to the row containing point, if there is any. */
8686 first_row_to_display
= first_reusable_row
;
8688 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
8690 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
8691 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
8692 pt_row
= first_row_to_display
;
8694 ++first_row_to_display
;
8697 /* Start displaying at the start of first_row_to_display. */
8698 xassert (first_row_to_display
->y
< yb
);
8699 init_to_row_start (&it
, w
, first_row_to_display
);
8700 nrows_scrolled
= MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
);
8701 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
8703 it
.current_y
= first_row_to_display
->y
- first_reusable_row
->y
;
8705 /* Display lines beginning with first_row_to_display in the
8706 desired matrix. Set last_text_row to the last row displayed
8707 that displays text. */
8708 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
8710 w
->cursor
.vpos
= -1;
8711 last_text_row
= NULL
;
8712 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
8713 if (display_line (&it
))
8714 last_text_row
= it
.glyph_row
- 1;
8716 /* Give up If point isn't in a row displayed or reused. */
8717 if (w
->cursor
.vpos
< 0)
8719 clear_glyph_matrix (w
->desired_matrix
);
8723 /* If point is in a reused row, adjust y and vpos of the cursor
8727 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
8729 w
->cursor
.y
-= first_reusable_row
->y
;
8732 /* Scroll the display. */
8733 run
.current_y
= first_reusable_row
->y
;
8734 run
.desired_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
8735 run
.height
= it
.last_visible_y
- run
.current_y
;
8738 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8740 rif
->update_window_begin_hook (w
);
8741 rif
->scroll_run_hook (w
, &run
);
8742 rif
->update_window_end_hook (w
, 0);
8746 /* Adjust Y positions of reused rows. */
8747 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
8748 row
= first_reusable_row
;
8749 dy
= first_reusable_row
->y
;
8750 min_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
8751 max_y
= it
.last_visible_y
;
8752 while (row
< first_row_to_display
)
8756 row
->visible_height
= row
->height
- (min_y
- row
->y
);
8757 else if (row
->y
+ row
->height
> max_y
)
8759 = row
->height
- (row
->y
+ row
->height
- max_y
);
8761 row
->visible_height
= row
->height
;
8765 /* Disable rows not reused. */
8766 while (row
< bottom_row
)
8772 /* Scroll the current matrix. */
8773 xassert (nrows_scrolled
> 0);
8774 rotate_matrix (w
->current_matrix
,
8776 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
8779 /* Adjust window end. A null value of last_text_row means that
8780 the window end is in reused rows which in turn means that
8781 only its vpos can have changed. */
8784 w
->window_end_bytepos
8785 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
8786 XSETFASTINT (w
->window_end_pos
,
8787 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
8788 XSETFASTINT (w
->window_end_vpos
,
8789 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
8793 XSETFASTINT (w
->window_end_vpos
,
8794 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
8797 w
->window_end_valid
= Qnil
;
8798 w
->desired_matrix
->no_scrolling_p
= 1;
8801 debug_method_add (w
, "try_window_reusing_current_matrix 2");
8811 /************************************************************************
8812 Window redisplay reusing current matrix when buffer has changed
8813 ************************************************************************/
8815 static struct glyph_row
*get_last_unchanged_at_beg_row
P_ ((struct window
*));
8816 static struct glyph_row
*get_first_unchanged_at_end_row
P_ ((struct window
*,
8818 static struct glyph_row
*
8819 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
8820 struct glyph_row
*));
8823 /* Return the last row in MATRIX displaying text. If row START is
8824 non-null, start searching with that row. IT gives the dimensions
8825 of the display. Value is null if matrix is empty; otherwise it is
8826 a pointer to the row found. */
8828 static struct glyph_row
*
8829 find_last_row_displaying_text (matrix
, it
, start
)
8830 struct glyph_matrix
*matrix
;
8832 struct glyph_row
*start
;
8834 struct glyph_row
*row
, *row_found
;
8836 /* Set row_found to the last row in IT->w's current matrix
8837 displaying text. The loop looks funny but think of partially
8840 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
8841 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
8843 xassert (row
->enabled_p
);
8845 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
8854 /* Return the last row in the current matrix of W that is not affected
8855 by changes at the start of current_buffer that occurred since the
8856 last time W was redisplayed. Value is null if no such row exists.
8858 The global variable beg_unchanged has to contain the number of
8859 bytes unchanged at the start of current_buffer. BEG +
8860 beg_unchanged is the buffer position of the first changed byte in
8861 current_buffer. Characters at positions < BEG + beg_unchanged are
8862 at the same buffer positions as they were when the current matrix
8865 static struct glyph_row
*
8866 get_last_unchanged_at_beg_row (w
)
8869 int first_changed_pos
= BEG
+ beg_unchanged
;
8870 struct glyph_row
*row
;
8871 struct glyph_row
*row_found
= NULL
;
8872 int yb
= window_text_bottom_y (w
);
8874 /* Find the last row displaying unchanged text. */
8875 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8876 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
8877 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
8879 if (/* If row ends before first_changed_pos, it is unchanged,
8880 except in some case. */
8881 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
8882 /* When row ends in ZV and we write at ZV it is not
8884 && !row
->ends_at_zv_p
8885 /* When first_changed_pos is the end of a continued line,
8886 row is not unchanged because it may be no longer
8888 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
8889 && row
->continued_p
))
8892 /* Stop if last visible row. */
8893 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
8903 /* Find the first glyph row in the current matrix of W that is not
8904 affected by changes at the end of current_buffer since the last
8905 time the window was redisplayed. Return in *DELTA the number of
8906 bytes by which buffer positions in unchanged text at the end of
8907 current_buffer must be adjusted. Value is null if no such row
8908 exists, i.e. all rows are affected by changes.
8910 The global variable end_unchanged is assumed to contain the number
8911 of unchanged bytes at the end of current_buffer. The buffer
8912 position of the last changed byte in current_buffer is then Z -
8915 static struct glyph_row
*
8916 get_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
8918 int *delta
, *delta_bytes
;
8920 struct glyph_row
*row
;
8921 struct glyph_row
*row_found
= NULL
;
8923 *delta
= *delta_bytes
= 0;
8925 /* A value of window_end_pos >= end_unchanged means that the window
8926 end is in the range of changed text. If so, there is no
8927 unchanged row at the end of W's current matrix. */
8928 xassert (!NILP (w
->window_end_valid
));
8929 if (XFASTINT (w
->window_end_pos
) >= end_unchanged
)
8932 /* Set row to the last row in W's current matrix displaying text. */
8933 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
8935 /* End vpos should always be on text, except in an entirely empty
8937 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
8938 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0);
8940 /* If matrix is entirely empty, no unchanged row exists. */
8941 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
8943 /* The value of row is the last glyph row in the matrix having a
8944 meaningful buffer position in it. The end position of row
8945 corresponds to window_end_pos. This allows us to translate
8946 buffer positions in the current matrix to current buffer
8947 positions for characters not in changed text. */
8948 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
8949 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
8950 int last_unchanged_pos
, last_unchanged_pos_old
;
8951 struct glyph_row
*first_text_row
8952 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8955 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
8957 /* Set last_unchanged_pos to the buffer position of the last
8958 character in the buffer that has not been changed. Z is the
8959 index + 1 of the last byte in current_buffer, i.e. by
8960 subtracting end_unchanged we get the index of the last
8961 unchanged character, and we have to add BEG to get its buffer
8963 last_unchanged_pos
= Z
- end_unchanged
+ BEG
;
8964 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
8966 /* Search backward from ROW for a row displaying a line that
8967 starts at a minimum position >= last_unchanged_pos_old. */
8968 while (row
>= first_text_row
)
8970 xassert (row
->enabled_p
);
8971 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
));
8973 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
8979 xassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
8984 /* Make sure that glyph rows in the current matrix of window W
8985 reference the same glyph memory as corresponding rows in the
8986 frame's frame matrix. This function is called after scrolling W's
8987 current matrix on a terminal frame in try_window_id and
8988 try_window_reusing_current_matrix. */
8991 sync_frame_with_window_matrix_rows (w
)
8994 struct frame
*f
= XFRAME (w
->frame
);
8995 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
8997 /* Preconditions: W must be a leaf window and full-width. Its frame
8998 must have a frame matrix. */
8999 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
9000 xassert (WINDOW_FULL_WIDTH_P (w
));
9001 xassert (!FRAME_WINDOW_P (f
));
9003 /* If W is a full-width window, glyph pointers in W's current matrix
9004 have, by definition, to be the same as glyph pointers in the
9005 corresponding frame matrix. */
9006 window_row
= w
->current_matrix
->rows
;
9007 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
9008 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
9009 while (window_row
< window_row_end
)
9012 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
9013 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
9014 ++window_row
, ++frame_row
;
9019 /* Try to redisplay window W by reusing its existing display. W's
9020 current matrix must be up to date when this function is called,
9021 i.e. window_end_valid must not be nil.
9025 1 if display has been updated
9026 0 if otherwise unsuccessful
9027 -1 if redisplay with same window start is known not to succeed
9029 The following steps are performed:
9031 1. Find the last row in the current matrix of W that is not
9032 affected by changes at the start of current_buffer. If no such row
9035 2. Find the first row in W's current matrix that is not affected by
9036 changes at the end of current_buffer. Maybe there is no such row.
9038 3. Display lines beginning with the row + 1 found in step 1 to the
9039 row found in step 2 or, if step 2 didn't find a row, to the end of
9042 4. If cursor is not known to appear on the window, give up.
9044 5. If display stopped at the row found in step 2, scroll the
9045 display and current matrix as needed.
9047 6. Maybe display some lines at the end of W, if we must. This can
9048 happen under various circumstances, like a partially visible line
9049 becoming fully visible, or because newly displayed lines are displayed
9050 in smaller font sizes.
9052 7. Update W's window end information. */
9054 /* Check that window end is what we expect it to be. */
9060 struct frame
*f
= XFRAME (w
->frame
);
9061 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
9062 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
9063 struct glyph_row
*last_unchanged_at_beg_row
;
9064 struct glyph_row
*first_unchanged_at_end_row
;
9065 struct glyph_row
*row
;
9066 struct glyph_row
*bottom_row
;
9069 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
9070 struct text_pos start_pos
;
9072 int first_unchanged_at_end_vpos
= 0;
9073 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
9074 struct text_pos start
;
9076 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
9078 /* Check pre-conditions. Window end must be valid, otherwise
9079 the current matrix would not be up to date. */
9080 xassert (!NILP (w
->window_end_valid
));
9081 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
9082 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
9084 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
9085 only if buffer has really changed. The reason is that the gap is
9086 initially at Z for freshly visited files. The code below would
9087 set end_unchanged to 0 in that case. */
9088 if (MODIFF
> SAVE_MODIFF
)
9090 if (GPT
- BEG
< beg_unchanged
)
9091 beg_unchanged
= GPT
- BEG
;
9092 if (Z
- GPT
< end_unchanged
)
9093 end_unchanged
= Z
- GPT
;
9096 /* If window starts after a line end, and the last change is in
9097 front of that newline, then changes don't affect the display.
9098 This case happens with stealth-fontification. */
9099 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
9100 if (CHARPOS (start
) > BEGV
9101 && Z
- end_unchanged
< CHARPOS (start
) - 1
9102 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
9103 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9105 /* We have to update window end positions because the buffer's
9106 size has changed. */
9108 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
9109 w
->window_end_bytepos
9110 = make_number (Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
));
9114 /* Return quickly if changes are all below what is displayed in the
9115 window, and if PT is in the window. */
9116 if (beg_unchanged
> MATRIX_ROW_END_CHARPOS (row
)
9117 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9119 /* We have to update window end positions because the buffer's
9120 size has changed. */
9122 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
9123 w
->window_end_bytepos
9124 = make_number (Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
));
9128 /* Check that window start agrees with the start of the first glyph
9129 row in its current matrix. Check this after we know the window
9130 start is not in changed text, otherwise positions would not be
9132 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9133 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
9136 /* Remember beg_unchanged and end_unchanged for debugging purposes. */
9137 IF_DEBUG (debug_beg_unchanged
= beg_unchanged
;
9138 debug_end_unchanged
= end_unchanged
);
9140 /* Compute the position at which we have to start displaying new
9141 lines. Some of the lines at the top of the window might be
9142 reusable because they are not displaying changed text. Find the
9143 last row in W's current matrix not affected by changes at the
9144 start of current_buffer. Value is null if changes start in the
9145 first line of window. */
9146 last_unchanged_at_beg_row
= get_last_unchanged_at_beg_row (w
);
9147 if (last_unchanged_at_beg_row
)
9149 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
9150 start_pos
= it
.current
.pos
;
9152 /* Start displaying new lines in the desired matrix at the same
9153 vpos we would use in the current matrix, i.e. below
9154 last_unchanged_at_beg_row. */
9155 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
9157 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
9158 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
9160 xassert (it
.hpos
== 0 && it
.current_x
== 0);
9164 /* There are no reusable lines at the start of the window.
9165 Start displaying in the first line. */
9166 start_display (&it
, w
, start
);
9167 start_pos
= it
.current
.pos
;
9170 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
9171 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
9173 /* Find the first row that is not affected by changes at the end of
9174 the buffer. Value will be null if there is no unchanged row, in
9175 which case we must redisplay to the end of the window. delta
9176 will be set to the value by which buffer positions beginning with
9177 first_unchanged_at_end_row have to be adjusted due to text
9179 first_unchanged_at_end_row
9180 = get_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
9181 IF_DEBUG (debug_delta
= delta
);
9182 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
9184 /* Set stop_pos to the buffer position up to which we will have to
9185 display new lines. If first_unchanged_at_end_row != NULL, this
9186 is the buffer position of the start of the line displayed in that
9187 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
9188 that we don't stop at a buffer position. */
9190 if (first_unchanged_at_end_row
)
9192 xassert (last_unchanged_at_beg_row
== NULL
9193 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
9195 /* If this is a continuation line, move forward to the next one
9196 that isn't. Changes in lines above affect this line.
9197 Caution: this may move first_unchanged_at_end_row to a row
9198 not displaying text. */
9199 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
9200 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
9201 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
9202 < it
.last_visible_y
))
9203 ++first_unchanged_at_end_row
;
9205 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
9206 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
9207 >= it
.last_visible_y
))
9208 first_unchanged_at_end_row
= NULL
;
9211 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
9213 first_unchanged_at_end_vpos
9214 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
9215 xassert (stop_pos
>= Z
- end_unchanged
);
9218 else if (last_unchanged_at_beg_row
== NULL
)
9224 /* Either there is no unchanged row at the end, or the one we have
9225 now displays text. This is a necessary condition for the window
9226 end pos calculation at the end of this function. */
9227 xassert (first_unchanged_at_end_row
== NULL
9228 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
9230 debug_last_unchanged_at_beg_vpos
9231 = (last_unchanged_at_beg_row
9232 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
9234 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
9236 #endif /* GLYPH_DEBUG != 0 */
9239 /* Display new lines. Set last_text_row to the last new line
9240 displayed which has text on it, i.e. might end up as being the
9241 line where the window_end_vpos is. */
9242 w
->cursor
.vpos
= -1;
9243 last_text_row
= NULL
;
9244 overlay_arrow_seen
= 0;
9245 while (it
.current_y
< it
.last_visible_y
9247 && (first_unchanged_at_end_row
== NULL
9248 || IT_CHARPOS (it
) < stop_pos
))
9250 if (display_line (&it
))
9251 last_text_row
= it
.glyph_row
- 1;
9254 if (fonts_changed_p
)
9258 /* Compute differences in buffer positions, y-positions etc. for
9259 lines reused at the bottom of the window. Compute what we can
9261 if (first_unchanged_at_end_row
)
9264 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
9266 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
9267 run
.current_y
= first_unchanged_at_end_row
->y
;
9268 run
.desired_y
= run
.current_y
+ dy
;
9269 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
9272 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
9273 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
9276 /* Find the cursor if not already found. We have to decide whether
9277 PT will appear on this window (it sometimes doesn't, but this is
9278 not a very frequent case.) This decision has to be made before
9279 the current matrix is altered. A value of cursor.vpos < 0 means
9280 that PT is either in one of the lines beginning at
9281 first_unchanged_at_end_row or below the window. Don't care for
9282 lines that might be displayed later at the window end; as
9283 mentioned, this is not a frequent case. */
9284 if (w
->cursor
.vpos
< 0)
9286 int last_y
= min (it
.last_visible_y
, it
.last_visible_y
+ dy
);
9288 /* Cursor in unchanged rows at the top? */
9289 if (PT
< CHARPOS (start_pos
)
9290 && last_unchanged_at_beg_row
)
9292 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9293 while (row
<= last_unchanged_at_beg_row
9294 && MATRIX_ROW_END_CHARPOS (row
) <= PT
)
9296 xassert (row
<= last_unchanged_at_beg_row
);
9297 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9300 /* Start from first_unchanged_at_end_row looking for PT. */
9301 else if (first_unchanged_at_end_row
)
9303 row
= first_unchanged_at_end_row
;
9304 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9306 if (PT
- delta
>= MATRIX_ROW_START_CHARPOS (row
)
9307 && PT
- delta
< MATRIX_ROW_END_CHARPOS (row
))
9309 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
9310 delta_bytes
, dy
, dvpos
);
9313 else if (MATRIX_ROW_BOTTOM_Y (row
) >= last_y
)
9319 /* Give up if cursor was not found. */
9320 if (w
->cursor
.vpos
< 0)
9322 clear_glyph_matrix (w
->desired_matrix
);
9327 /* Don't let the cursor end in the scroll margins. */
9329 int this_scroll_margin
, cursor_height
;
9331 this_scroll_margin
= max (0, scroll_margin
);
9332 this_scroll_margin
= min (this_scroll_margin
,
9333 XFASTINT (w
->height
) / 4);
9334 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
9335 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
9337 if ((w
->cursor
.y
< this_scroll_margin
9338 && CHARPOS (start
) > BEGV
)
9339 /* Don't take scroll margin into account at the bottom because
9340 old redisplay didn't do it either. */
9341 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
9343 w
->cursor
.vpos
= -1;
9344 clear_glyph_matrix (w
->desired_matrix
);
9349 /* Scroll the display. Do it before changing the current matrix so
9350 that xterm.c doesn't get confused about where the cursor glyph is
9356 if (FRAME_WINDOW_P (f
))
9358 rif
->update_window_begin_hook (w
);
9359 rif
->scroll_run_hook (w
, &run
);
9360 rif
->update_window_end_hook (w
, 0);
9364 /* Terminal frame. In this case, dvpos gives the number of
9365 lines to scroll by; dvpos < 0 means scroll up. */
9366 int first_unchanged_at_end_vpos
9367 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
9368 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
9369 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
9371 /* Perform the operation on the screen. */
9374 /* Scroll last_unchanged_at_beg_row to the end of the
9375 window down dvpos lines. */
9376 set_terminal_window (end
);
9378 /* On dumb terminals delete dvpos lines at the end
9379 before inserting dvpos empty lines. */
9380 if (!scroll_region_ok
)
9381 ins_del_lines (end
- dvpos
, -dvpos
);
9383 /* Insert dvpos empty lines in front of
9384 last_unchanged_at_beg_row. */
9385 ins_del_lines (from
, dvpos
);
9389 /* Scroll up last_unchanged_at_beg_vpos to the end of
9390 the window to last_unchanged_at_beg_vpos - |dvpos|. */
9391 set_terminal_window (end
);
9393 /* Delete dvpos lines in front of
9394 last_unchanged_at_beg_vpos. ins_del_lines will set
9395 the cursor to the given vpos and emit |dvpos| delete
9397 ins_del_lines (from
+ dvpos
, dvpos
);
9399 /* On a dumb terminal insert dvpos empty lines at the
9401 if (!scroll_region_ok
)
9402 ins_del_lines (end
+ dvpos
, -dvpos
);
9405 set_terminal_window (0);
9411 /* Shift reused rows of the current matrix to the right position. */
9414 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
9415 bottom_vpos
, dvpos
);
9416 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
9421 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
9422 bottom_vpos
, dvpos
);
9423 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
9424 first_unchanged_at_end_vpos
+ dvpos
, 0);
9427 /* For frame-based redisplay, make sure that current frame and window
9428 matrix are in sync with respect to glyph memory. */
9429 if (!FRAME_WINDOW_P (f
))
9430 sync_frame_with_window_matrix_rows (w
);
9432 /* Adjust buffer positions in reused rows. */
9434 increment_glyph_matrix_buffer_positions (current_matrix
,
9435 first_unchanged_at_end_vpos
+ dvpos
,
9436 bottom_vpos
, delta
, delta_bytes
);
9438 /* Adjust Y positions. */
9440 shift_glyph_matrix (w
, current_matrix
,
9441 first_unchanged_at_end_vpos
+ dvpos
,
9444 if (first_unchanged_at_end_row
)
9445 first_unchanged_at_end_row
+= dvpos
;
9447 /* If scrolling up, there may be some lines to display at the end of
9449 last_text_row_at_end
= NULL
;
9452 /* Set last_row to the glyph row in the current matrix where the
9453 window end line is found. It has been moved up or down in
9454 the matrix by dvpos. */
9455 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
9456 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
9458 /* If last_row is the window end line, it should display text. */
9459 xassert (last_row
->displays_text_p
);
9461 /* If window end line was partially visible before, begin
9462 displaying at that line. Otherwise begin displaying with the
9463 line following it. */
9464 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
9466 init_to_row_start (&it
, w
, last_row
);
9467 it
.vpos
= last_vpos
;
9468 it
.current_y
= last_row
->y
;
9472 init_to_row_end (&it
, w
, last_row
);
9473 it
.vpos
= 1 + last_vpos
;
9474 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
9478 /* We may start in a continuation line. If so, we have to get
9479 the right continuation_lines_width and current_x. */
9480 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
9481 it
.hpos
= it
.current_x
= 0;
9483 /* Display the rest of the lines at the window end. */
9484 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
9485 while (it
.current_y
< it
.last_visible_y
9486 && !fonts_changed_p
)
9488 /* Is it always sure that the display agrees with lines in
9489 the current matrix? I don't think so, so we mark rows
9490 displayed invalid in the current matrix by setting their
9491 enabled_p flag to zero. */
9492 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
9493 if (display_line (&it
))
9494 last_text_row_at_end
= it
.glyph_row
- 1;
9498 /* Update window_end_pos and window_end_vpos. */
9499 if (first_unchanged_at_end_row
9500 && first_unchanged_at_end_row
->y
< it
.last_visible_y
9501 && !last_text_row_at_end
)
9503 /* Window end line if one of the preserved rows from the current
9504 matrix. Set row to the last row displaying text in current
9505 matrix starting at first_unchanged_at_end_row, after
9507 xassert (first_unchanged_at_end_row
->displays_text_p
);
9508 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
9509 first_unchanged_at_end_row
);
9510 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
9512 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
9513 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
9514 XSETFASTINT (w
->window_end_vpos
,
9515 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
9517 else if (last_text_row_at_end
)
9519 XSETFASTINT (w
->window_end_pos
,
9520 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
9521 w
->window_end_bytepos
9522 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
9523 XSETFASTINT (w
->window_end_vpos
,
9524 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
9526 else if (last_text_row
)
9528 /* We have displayed either to the end of the window or at the
9529 end of the window, i.e. the last row with text is to be found
9530 in the desired matrix. */
9531 XSETFASTINT (w
->window_end_pos
,
9532 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9533 w
->window_end_bytepos
9534 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9535 XSETFASTINT (w
->window_end_vpos
,
9536 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
9538 else if (first_unchanged_at_end_row
== NULL
9539 && last_text_row
== NULL
9540 && last_text_row_at_end
== NULL
)
9542 /* Displayed to end of window, but no line containing text was
9543 displayed. Lines were deleted at the end of the window. */
9545 int top_line_p
= WINDOW_WANTS_TOP_LINE_P (w
) ? 1 : 0;
9547 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
9548 if ((w
->desired_matrix
->rows
[vpos
+ top_line_p
].enabled_p
9549 && w
->desired_matrix
->rows
[vpos
+ top_line_p
].displays_text_p
)
9550 || (!w
->desired_matrix
->rows
[vpos
+ top_line_p
].enabled_p
9551 && w
->current_matrix
->rows
[vpos
+ top_line_p
].displays_text_p
))
9554 w
->window_end_vpos
= make_number (vpos
);
9559 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
9560 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
9562 /* Record that display has not been completed. */
9563 w
->window_end_valid
= Qnil
;
9564 w
->desired_matrix
->no_scrolling_p
= 1;
9570 /***********************************************************************
9571 More debugging support
9572 ***********************************************************************/
9576 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
9577 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
9580 /* Dump the contents of glyph matrix MATRIX on stderr. If
9581 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
9584 dump_glyph_matrix (matrix
, with_glyphs_p
)
9585 struct glyph_matrix
*matrix
;
9589 for (i
= 0; i
< matrix
->nrows
; ++i
)
9590 dump_glyph_row (matrix
, i
, with_glyphs_p
);
9594 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
9595 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
9598 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
9599 struct glyph_matrix
*matrix
;
9600 int vpos
, with_glyphs_p
;
9602 struct glyph_row
*row
;
9604 if (vpos
< 0 || vpos
>= matrix
->nrows
)
9607 row
= MATRIX_ROW (matrix
, vpos
);
9609 fprintf (stderr
, "Row Start End Used oEI><O\\CTZF X Y W\n");
9610 fprintf (stderr
, "=============================================\n");
9612 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",
9614 MATRIX_ROW_START_CHARPOS (row
),
9615 MATRIX_ROW_END_CHARPOS (row
),
9616 row
->used
[TEXT_AREA
],
9617 row
->contains_overlapping_glyphs_p
,
9620 row
->truncated_on_left_p
,
9621 row
->truncated_on_right_p
,
9622 row
->overlay_arrow_p
,
9624 MATRIX_ROW_CONTINUATION_LINE_P (row
),
9625 row
->displays_text_p
,
9631 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
9632 row
->end
.overlay_string_index
);
9633 fprintf (stderr
, "%9d %5d\n",
9634 CHARPOS (row
->start
.string_pos
),
9635 CHARPOS (row
->end
.string_pos
));
9636 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
9637 row
->end
.dpvec_index
);
9641 struct glyph
*glyph
, *glyph_end
;
9642 int prev_had_glyphs_p
;
9644 glyph
= row
->glyphs
[TEXT_AREA
];
9645 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
9647 /* Glyph for a line end in text. */
9648 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
9651 if (glyph
< glyph_end
)
9653 fprintf (stderr
, " Glyph Type Pos W Code C Face LR\n");
9654 prev_had_glyphs_p
= 1;
9657 prev_had_glyphs_p
= 0;
9659 while (glyph
< glyph_end
)
9661 if (glyph
->type
== CHAR_GLYPH
)
9664 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
9665 glyph
- row
->glyphs
[TEXT_AREA
],
9670 (glyph
->u
.ch
.code
< 0x80 && glyph
->u
.ch
.code
>= ' '
9673 glyph
->u
.ch
.face_id
,
9674 glyph
->left_box_line_p
,
9675 glyph
->right_box_line_p
);
9677 else if (glyph
->type
== STRETCH_GLYPH
)
9680 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
9681 glyph
- row
->glyphs
[TEXT_AREA
],
9687 glyph
->u
.stretch
.face_id
,
9688 glyph
->left_box_line_p
,
9689 glyph
->right_box_line_p
);
9691 else if (glyph
->type
== IMAGE_GLYPH
)
9694 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
9695 glyph
- row
->glyphs
[TEXT_AREA
],
9701 glyph
->u
.img
.face_id
,
9702 glyph
->left_box_line_p
,
9703 glyph
->right_box_line_p
);
9711 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
9712 Sdump_glyph_matrix
, 0, 1, "p",
9713 "Dump the current matrix of the selected window to stderr.\n\
9714 Shows contents of glyph row structures. With non-nil optional\n\
9715 parameter WITH-GLYPHS-P, dump glyphs as well.")
9718 struct window
*w
= XWINDOW (selected_window
);
9719 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9721 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
9722 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
9723 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
9724 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
9725 fprintf (stderr
, "=============================================\n");
9726 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
9731 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
9732 "Dump glyph row ROW to stderr.")
9736 CHECK_NUMBER (row
, 0);
9737 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
9742 DEFUN ("dump-toolbar-row", Fdump_toolbar_row
, Sdump_toolbar_row
,
9746 struct glyph_matrix
*m
= (XWINDOW (selected_frame
->toolbar_window
)
9748 dump_glyph_row (m
, 0, 1);
9753 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
9754 Strace_redisplay_toggle
, 0, 0, "",
9755 "Toggle tracing of redisplay.")
9758 trace_redisplay_p
= !trace_redisplay_p
;
9763 #endif /* GLYPH_DEBUG */
9767 /***********************************************************************
9768 Building Desired Matrix Rows
9769 ***********************************************************************/
9771 /* Return a temporary glyph row holding the glyphs of an overlay
9772 arrow. Only used for non-window-redisplay windows. */
9774 static struct glyph_row
*
9775 get_overlay_arrow_glyph_row (w
)
9778 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9779 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9780 struct buffer
*old
= current_buffer
;
9781 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
9782 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
9783 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
9787 int n_glyphs_before
;
9789 set_buffer_temp (buffer
);
9790 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
9791 it
.glyph_row
->used
[TEXT_AREA
] = 0;
9792 SET_TEXT_POS (it
.position
, 0, 0);
9794 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
9796 while (p
< arrow_end
)
9798 Lisp_Object face
, ilisp
;
9800 /* Get the next character. */
9802 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
9804 it
.c
= *p
, it
.len
= 1;
9808 XSETFASTINT (ilisp
, p
- arrow_string
);
9809 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
9810 it
.face_id
= compute_char_face (f
, it
.c
, face
);
9812 /* Compute its width, get its glyphs. */
9813 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
9814 PRODUCE_GLYPHS (&it
);
9816 /* If this character doesn't fit any more in the line, we have
9817 to remove some glyphs. */
9818 if (it
.current_x
> it
.last_visible_x
)
9820 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
9825 set_buffer_temp (old
);
9826 return it
.glyph_row
;
9830 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
9831 glyphs are only inserted for terminal frames since we can't really
9832 win with truncation glyphs when partially visible glyphs are
9833 involved. Which glyphs to insert is determined by
9834 produce_special_glyphs. */
9837 insert_left_trunc_glyphs (it
)
9840 struct it truncate_it
;
9841 struct glyph
*from
, *end
, *to
, *toend
;
9843 xassert (!FRAME_WINDOW_P (it
->f
));
9845 /* Get the truncation glyphs. */
9847 truncate_it
.charset
= -1;
9848 truncate_it
.current_x
= 0;
9849 truncate_it
.face_id
= DEFAULT_FACE_ID
;
9850 truncate_it
.glyph_row
= &scratch_glyph_row
;
9851 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
9852 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
9853 truncate_it
.object
= 0;
9854 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
9856 /* Overwrite glyphs from IT with truncation glyphs. */
9857 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
9858 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
9859 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
9860 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
9865 /* There may be padding glyphs left over. Remove them. */
9867 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
9869 while (from
< toend
)
9872 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
9876 /* Compute the pixel height and width of IT->glyph_row.
9878 Most of the time, ascent and height of a display line will be equal
9879 to the max_ascent and max_height values of the display iterator
9880 structure. This is not the case if
9882 1. We hit ZV without displaying anything. In this case, max_ascent
9883 and max_height will be zero.
9885 2. We have some glyphs that don't contribute to the line height.
9886 (The glyph row flag contributes_to_line_height_p is for future
9889 The first case is easily covered by using default values because in
9890 these cases, the line height does not really matter, except that it
9891 must not be zero. */
9894 compute_line_metrics (it
)
9897 struct glyph_row
*row
= it
->glyph_row
;
9900 if (FRAME_WINDOW_P (it
->f
))
9902 int i
, top_line_height
;
9904 /* The line may consist of one space only, that was added to
9905 place the cursor on it. If so, the row's height hasn't been
9907 if (row
->height
== 0)
9909 if (it
->max_ascent
+ it
->max_descent
== 0)
9910 it
->max_descent
= CANON_Y_UNIT (it
->f
);
9911 row
->ascent
= it
->max_ascent
;
9912 row
->height
= it
->max_ascent
+ it
->max_descent
;
9915 /* Compute the width of this line. */
9916 row
->pixel_width
= row
->x
;
9917 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
9918 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9920 xassert (row
->pixel_width
>= 0);
9921 xassert (row
->ascent
>= 0 && row
->height
> 0);
9923 /* Compute how much of the line is visible. */
9924 row
->visible_height
= row
->height
;
9926 top_line_height
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (it
->w
);
9927 if (row
->y
< top_line_height
)
9928 row
->visible_height
-= top_line_height
- row
->y
;
9931 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
9932 if (row
->y
+ row
->height
> max_y
)
9933 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
9938 row
->pixel_width
= row
->used
[TEXT_AREA
];
9940 row
->height
= row
->visible_height
= 1;
9943 /* Compute a hash code for this row. */
9945 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
9946 for (i
= 0; i
< row
->used
[area
]; ++i
)
9947 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
9948 + row
->glyphs
[area
][i
].u
.val
9949 + (row
->glyphs
[area
][i
].type
<< 2));
9951 it
->max_ascent
= it
->max_descent
= 0;
9955 /* Append one space to the glyph row of iterator IT if doing a
9956 window-based redisplay. DEFAULT_FACE_P non-zero means let the
9957 space have the default face, otherwise let it have the same face as
9958 IT->face_id. This function is called to make sure that there is
9959 always one glyph at the end of a glyph row that the cursor can be
9960 set on under window-systems. (If there weren't such a glyph we
9961 would not know how wide and tall the cursor should be displayed). */
9964 append_space (it
, default_face_p
)
9968 if (FRAME_WINDOW_P (it
->f
))
9970 int n
= it
->glyph_row
->used
[TEXT_AREA
];
9972 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
9973 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
9975 /* Save some values that must not be changed. */
9976 int saved_x
= it
->current_x
;
9977 struct text_pos saved_pos
;
9978 int saved_what
= it
->what
;
9979 int saved_face_id
= it
->face_id
;
9980 int saved_charset
= it
->charset
;
9981 Lisp_Object saved_object
;
9983 saved_object
= it
->object
;
9984 saved_pos
= it
->position
;
9986 it
->what
= IT_CHARACTER
;
9987 bzero (&it
->position
, sizeof it
->position
);
9991 it
->charset
= CHARSET_ASCII
;
9994 it
->face_id
= DEFAULT_FACE_ID
;
9995 if (it
->multibyte_p
)
9996 it
->face_id
= FACE_FOR_CHARSET (it
->f
, it
->face_id
, CHARSET_ASCII
);
9998 it
->face_id
= FACE_FOR_CHARSET (it
->f
, it
->face_id
, -1);
10000 PRODUCE_GLYPHS (it
);
10002 it
->current_x
= saved_x
;
10003 it
->object
= saved_object
;
10004 it
->position
= saved_pos
;
10005 it
->what
= saved_what
;
10006 it
->face_id
= saved_face_id
;
10007 it
->charset
= saved_charset
;
10013 /* Extend the face of the last glyph in the text area of IT->glyph_row
10014 to the end of the display line. Called from display_line.
10015 If the glyph row is empty, add a space glyph to it so that we
10016 know the face to draw. Set the glyph row flag fill_line_p. */
10019 extend_face_to_end_of_line (it
)
10023 struct frame
*f
= it
->f
;
10025 /* If line is already filled, do nothing. */
10026 if (it
->current_x
>= it
->last_visible_x
)
10029 /* Face extension extends the background and box of IT->face_id
10030 to the end of the line. If the background equals the background
10031 of the frame, we haven't to do anything. */
10032 face
= FACE_FROM_ID (f
, it
->face_id
);
10033 if (FRAME_WINDOW_P (f
)
10034 && face
->box
== FACE_NO_BOX
10035 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
10039 /* Set the glyph row flag indicating that the face of the last glyph
10040 in the text area has to be drawn to the end of the text area. */
10041 it
->glyph_row
->fill_line_p
= 1;
10043 /* If current charset of IT is not ASCII, make sure we have the
10044 ASCII face. This will be automatically undone the next time
10045 get_next_display_element returns a character from a different
10046 charset. Note that the charset will always be ASCII in unibyte
10048 if (it
->charset
!= CHARSET_ASCII
)
10050 it
->charset
= CHARSET_ASCII
;
10051 it
->face_id
= FACE_FOR_CHARSET (f
, it
->face_id
, CHARSET_ASCII
);
10054 if (FRAME_WINDOW_P (f
))
10056 /* If the row is empty, add a space with the current face of IT,
10057 so that we know which face to draw. */
10058 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
10060 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
10061 it
->glyph_row
->glyphs
[TEXT_AREA
][0].u
.ch
.face_id
= it
->face_id
;
10062 it
->glyph_row
->used
[TEXT_AREA
] = 1;
10067 /* Save some values that must not be changed. */
10068 int saved_x
= it
->current_x
;
10069 struct text_pos saved_pos
;
10070 Lisp_Object saved_object
;
10071 int saved_what
= it
->what
;
10073 saved_object
= it
->object
;
10074 saved_pos
= it
->position
;
10076 it
->what
= IT_CHARACTER
;
10077 bzero (&it
->position
, sizeof it
->position
);
10082 PRODUCE_GLYPHS (it
);
10084 while (it
->current_x
<= it
->last_visible_x
)
10085 PRODUCE_GLYPHS (it
);
10087 /* Don't count these blanks really. It would let us insert a left
10088 truncation glyph below and make us set the cursor on them, maybe. */
10089 it
->current_x
= saved_x
;
10090 it
->object
= saved_object
;
10091 it
->position
= saved_pos
;
10092 it
->what
= saved_what
;
10097 /* Value is non-zero if text starting at CHARPOS in current_buffer is
10098 trailing whitespace. */
10101 trailing_whitespace_p (charpos
)
10104 int bytepos
= CHAR_TO_BYTE (charpos
);
10107 while (bytepos
< ZV_BYTE
10108 && (c
= FETCH_CHAR (bytepos
),
10109 c
== ' ' || c
== '\t'))
10112 return bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r';
10116 /* Highlight trailing whitespace, if any, in ROW. */
10119 highlight_trailing_whitespace (f
, row
)
10121 struct glyph_row
*row
;
10123 int used
= row
->used
[TEXT_AREA
];
10127 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
10128 struct glyph
*glyph
= start
+ used
- 1;
10130 /* Skip over the space glyph inserted to display the
10131 cursor at the end of a line. */
10132 if (glyph
->type
== CHAR_GLYPH
10133 && glyph
->u
.ch
.code
== ' '
10134 && glyph
->object
== 0)
10137 /* If last glyph is a space or stretch, and it's trailing
10138 whitespace, set the face of all trailing whitespace glyphs in
10139 IT->glyph_row to `trailing-whitespace'. */
10141 && BUFFERP (glyph
->object
)
10142 && (glyph
->type
== STRETCH_GLYPH
10143 || (glyph
->type
== CHAR_GLYPH
10144 && glyph
->u
.ch
.code
== ' '))
10145 && trailing_whitespace_p (glyph
->charpos
))
10147 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
,
10150 while (glyph
>= start
10151 && BUFFERP (glyph
->object
)
10152 && (glyph
->type
== STRETCH_GLYPH
10153 || (glyph
->type
== CHAR_GLYPH
10154 && glyph
->u
.ch
.code
== ' ')))
10156 if (glyph
->type
== STRETCH_GLYPH
)
10157 glyph
->u
.stretch
.face_id
= face_id
;
10159 glyph
->u
.ch
.face_id
= face_id
;
10168 /* Construct the glyph row IT->glyph_row in the desired matrix of
10169 IT->w from text at the current position of IT. See dispextern.h
10170 for an overview of struct it. Value is non-zero if
10171 IT->glyph_row displays text, as opposed to a line displaying ZV
10178 struct glyph_row
*row
= it
->glyph_row
;
10180 /* We always start displaying at hpos zero even if hscrolled. */
10181 xassert (it
->hpos
== 0 && it
->current_x
== 0);
10183 /* We must not display in a row that's not a text row. */
10184 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
10185 < it
->w
->desired_matrix
->nrows
);
10187 /* Is IT->w showing the region? */
10188 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
10190 /* Clear the result glyph row and enable it. */
10191 prepare_desired_row (row
);
10193 row
->y
= it
->current_y
;
10194 row
->start
= it
->current
;
10195 row
->continuation_lines_width
= it
->continuation_lines_width
;
10196 row
->displays_text_p
= 1;
10198 /* Arrange the overlays nicely for our purposes. Usually, we call
10199 display_line on only one line at a time, in which case this
10200 can't really hurt too much, or we call it on lines which appear
10201 one after another in the buffer, in which case all calls to
10202 recenter_overlay_lists but the first will be pretty cheap. */
10203 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
10205 #if NO_PROMPT_IN_BUFFER
10206 /* Show mini-buffer prompt, if at the beginning of a mini-buffer
10208 if (MINI_WINDOW_P (it
->w
)
10209 && MATRIX_ROW_START_CHARPOS (row
) == BEG
10212 if (NILP (minibuf_prompt
))
10213 minibuf_prompt_width
= minibuf_prompt_pixel_width
= 0;
10216 /* We would like to truncate the prompt a little bit before
10217 the right margin of the window, so that user input can
10218 start on the first line. Set max_x to this position. */
10219 int max_x
= (it
->last_visible_x
- 4 * CANON_X_UNIT (it
->f
));
10221 /* We use a temporary iterator different from IT so that
10222 IT's settings are not overwritten when displaying
10228 /* Display the prompt. Set minibuf_prompt_width to the
10229 number of glyphs generated for the prompt, set
10230 minibuf_prompt_pixel_width to its width in pixels. */
10231 xassert (it
->current_x
== 0);
10232 display_string (NULL
, minibuf_prompt
, Qnil
, 0, 0, &ti
,
10234 minibuf_prompt_width
= ti
.hpos
;
10235 minibuf_prompt_pixel_width
= ti
.current_x
;
10237 /* Transfer pixel and hpos information to IT. */
10238 it
->hpos
= ti
.hpos
;
10239 it
->current_x
= ti
.current_x
;
10242 #endif /* NO_PROMPT_IN_BUFFER */
10244 /* Move over display elements that are not visible because we are
10245 hscrolled. This may stop at an x-position < IT->first_visible_x
10246 if the first glyph is partially visible or if we hit a line end. */
10247 if (it
->current_x
< it
->first_visible_x
)
10248 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
10249 MOVE_TO_POS
| MOVE_TO_X
);
10251 /* Get the initial row height. This is either the height of the
10252 text hscrolled, if there is any, or zero. */
10253 row
->ascent
= it
->max_ascent
;
10254 row
->height
= it
->max_ascent
+ it
->max_descent
;
10256 /* Loop generating characters. The loop is left with IT on the next
10257 character to display. */
10260 int n_glyphs_before
, hpos_before
, x_before
;
10263 /* Retrieve the next thing to display. Value is zero if end of
10265 if (!get_next_display_element (it
))
10267 /* Maybe add a space at the end of this line that is used to
10268 display the cursor there under X. */
10269 append_space (it
, 1);
10271 /* The position -1 below indicates a blank line not
10272 corresponding to any text, as opposed to an empty line
10273 corresponding to a line end. */
10274 if (row
->used
[TEXT_AREA
] <= 1)
10276 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
10277 row
->displays_text_p
= 0;
10279 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
10280 row
->indicate_empty_line_p
= 1;
10283 it
->continuation_lines_width
= 0;
10284 row
->ends_at_zv_p
= 1;
10288 /* Now, get the metrics of what we want to display. This also
10289 generates glyphs in `row' (which is IT->glyph_row). */
10290 n_glyphs_before
= row
->used
[TEXT_AREA
];
10292 PRODUCE_GLYPHS (it
);
10294 /* If this display element was in marginal areas, continue with
10296 if (it
->area
!= TEXT_AREA
)
10298 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
10299 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
10300 set_iterator_to_next (it
);
10304 /* Does the display element fit on the line? If we truncate
10305 lines, we should draw past the right edge of the window. If
10306 we don't truncate, we want to stop so that we can display the
10307 continuation glyph before the right margin. If lines are
10308 continued, there are two possible strategies for characters
10309 resulting in more than 1 glyph (e.g. tabs): Display as many
10310 glyphs as possible in this line and leave the rest for the
10311 continuation line, or display the whole element in the next
10312 line. Original redisplay did the former, so we do it also. */
10313 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10314 hpos_before
= it
->hpos
;
10318 && it
->current_x
< it
->last_visible_x
)
10321 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
10322 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
10323 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
10324 row
->x
= x
- it
->first_visible_x
;
10329 struct glyph
*glyph
;
10331 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
10333 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10334 new_x
= x
+ glyph
->pixel_width
;
10336 if (/* Lines are continued. */
10337 !it
->truncate_lines_p
10338 && (/* Glyph doesn't fit on the line. */
10339 new_x
> it
->last_visible_x
10340 /* Or it fits exactly on a window system frame. */
10341 || (new_x
== it
->last_visible_x
10342 && FRAME_WINDOW_P (it
->f
))))
10344 /* End of a continued line. */
10347 || (new_x
== it
->last_visible_x
10348 && FRAME_WINDOW_P (it
->f
)))
10350 /* Current glyph fits exactly on the line. We
10351 must continue the line because we can't draw
10352 the cursor after the glyph. */
10353 row
->continued_p
= 1;
10354 it
->current_x
= new_x
;
10355 it
->continuation_lines_width
+= new_x
;
10357 if (i
== nglyphs
- 1)
10358 set_iterator_to_next (it
);
10362 /* Display element draws past the right edge of
10363 the window. Restore positions to values
10364 before the element. The next line starts
10365 with current_x before the glyph that could
10366 not be displayed, so that TAB works right. */
10367 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
10369 /* Display continuation glyphs. */
10370 if (!FRAME_WINDOW_P (it
->f
))
10371 produce_special_glyphs (it
, IT_CONTINUATION
);
10372 row
->continued_p
= 1;
10375 it
->continuation_lines_width
+= x
;
10379 else if (new_x
> it
->first_visible_x
)
10381 /* Increment number of glyphs actually displayed. */
10384 if (x
< it
->first_visible_x
)
10385 /* Glyph is partially visible, i.e. row starts at
10386 negative X position. */
10387 row
->x
= x
- it
->first_visible_x
;
10391 /* Glyph is completely off the left margin of the
10392 window. This should not happen because of the
10393 move_it_in_display_line at the start of
10399 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
10400 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
10402 /* End of this display line if row is continued. */
10403 if (row
->continued_p
)
10407 /* Is this a line end? If yes, we're also done, after making
10408 sure that a non-default face is extended up to the right
10409 margin of the window. */
10410 if (ITERATOR_AT_END_OF_LINE_P (it
))
10412 int used_before
= row
->used
[TEXT_AREA
];
10414 /* Add a space at the end of the line that is used to
10415 display the cursor there. */
10416 append_space (it
, 0);
10418 /* Extend the face to the end of the line. */
10419 extend_face_to_end_of_line (it
);
10421 /* Make sure we have the position. */
10422 if (used_before
== 0)
10423 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
10425 /* Consume the line end. This skips over invisible lines. */
10426 set_iterator_to_next (it
);
10427 it
->continuation_lines_width
= 0;
10431 /* Proceed with next display element. Note that this skips
10432 over lines invisible because of selective display. */
10433 set_iterator_to_next (it
);
10435 /* If we truncate lines, we are done when the last displayed
10436 glyphs reach past the right margin of the window. */
10437 if (it
->truncate_lines_p
10438 && (FRAME_WINDOW_P (it
->f
)
10439 ? (it
->current_x
>= it
->last_visible_x
)
10440 : (it
->current_x
> it
->last_visible_x
)))
10442 /* Maybe add truncation glyphs. */
10443 if (!FRAME_WINDOW_P (it
->f
))
10445 --it
->glyph_row
->used
[TEXT_AREA
];
10446 produce_special_glyphs (it
, IT_TRUNCATION
);
10449 row
->truncated_on_right_p
= 1;
10450 it
->continuation_lines_width
= 0;
10451 reseat_at_next_visible_line_start (it
);
10452 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
10453 it
->hpos
= hpos_before
;
10454 it
->current_x
= x_before
;
10459 /* If line is not empty and hscrolled, maybe insert truncation glyphs
10460 at the left window margin. */
10461 if (it
->first_visible_x
10462 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
10464 if (!FRAME_WINDOW_P (it
->f
))
10465 insert_left_trunc_glyphs (it
);
10466 row
->truncated_on_left_p
= 1;
10469 /* If the start of this line is the overlay arrow-position, then
10470 mark this glyph row as the one containing the overlay arrow.
10471 This is clearly a mess with variable size fonts. It would be
10472 better to let it be displayed like cursors under X. */
10473 if (MARKERP (Voverlay_arrow_position
)
10474 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
10475 && (MATRIX_ROW_START_CHARPOS (row
)
10476 == marker_position (Voverlay_arrow_position
))
10477 && STRINGP (Voverlay_arrow_string
)
10478 && ! overlay_arrow_seen
)
10480 /* Overlay arrow in window redisplay is a bitmap. */
10481 if (!FRAME_WINDOW_P (it
->f
))
10483 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
10484 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
10485 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
10486 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
10487 struct glyph
*p2
, *end
;
10489 /* Copy the arrow glyphs. */
10490 while (glyph
< arrow_end
)
10493 /* Throw away padding glyphs. */
10495 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
10496 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
10502 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
10506 overlay_arrow_seen
= 1;
10507 row
->overlay_arrow_p
= 1;
10510 /* Compute pixel dimensions of this line. */
10511 compute_line_metrics (it
);
10513 /* Remember the position at which this line ends. */
10514 row
->end
= it
->current
;
10516 /* Maybe set the cursor. If you change this, it's probably a good
10517 idea to also change the code in redisplay_window for cursor
10518 movement in an unchanged window. */
10519 if (it
->w
->cursor
.vpos
< 0
10520 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
10521 && MATRIX_ROW_END_CHARPOS (row
) >= PT
10522 && !(MATRIX_ROW_END_CHARPOS (row
) == PT
10523 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
10524 || !row
->ends_at_zv_p
)))
10525 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
10527 /* Highlight trailing whitespace. */
10528 if (it
->show_trailing_whitespace_p
)
10529 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
10531 /* Prepare for the next line. This line starts horizontally at (X
10532 HPOS) = (0 0). Vertical positions are incremented. As a
10533 convenience for the caller, IT->glyph_row is set to the next
10535 it
->current_x
= it
->hpos
= 0;
10536 it
->current_y
+= row
->height
;
10539 return row
->displays_text_p
;
10544 /***********************************************************************
10546 ***********************************************************************/
10548 /* Redisplay the menu bar in the frame for window W.
10550 The menu bar of X frames that don't have X toolkit support is
10551 displayed in a special window W->frame->menu_bar_window.
10553 The menu bar of terminal frames is treated specially as far as
10554 glyph matrices are concerned. Menu bar lines are not part of
10555 windows, so the update is done directly on the frame matrix rows
10556 for the menu bar. */
10559 display_menu_bar (w
)
10562 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10567 /* Don't do all this for graphical frames. */
10569 if (!NILP (Vwindow_system
))
10572 #ifdef USE_X_TOOLKIT
10577 #ifdef USE_X_TOOLKIT
10578 xassert (!FRAME_WINDOW_P (f
));
10579 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MODE_LINE_FACE_ID
);
10580 it
.first_visible_x
= 0;
10581 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
10582 #else /* not USE_X_TOOLKIT */
10583 if (FRAME_WINDOW_P (f
))
10585 /* Menu bar lines are displayed in the desired matrix of the
10586 dummy window menu_bar_window. */
10587 struct window
*menu_w
;
10588 xassert (WINDOWP (f
->menu_bar_window
));
10589 menu_w
= XWINDOW (f
->menu_bar_window
);
10590 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
10591 MODE_LINE_FACE_ID
);
10592 it
.first_visible_x
= 0;
10593 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
10597 /* This is a TTY frame, i.e. character hpos/vpos are used as
10599 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
10600 MODE_LINE_FACE_ID
);
10601 it
.first_visible_x
= 0;
10602 it
.last_visible_x
= FRAME_WIDTH (f
);
10604 #endif /* not USE_X_TOOLKIT */
10606 /* Clear all rows of the menu bar. */
10607 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
10609 struct glyph_row
*row
= it
.glyph_row
+ i
;
10610 clear_glyph_row (row
);
10611 row
->enabled_p
= 1;
10612 row
->full_width_p
= 1;
10615 /* Make the first line of the menu bar appear in reverse video. */
10616 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
10618 /* Display all items of the menu bar. */
10619 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
10620 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
10622 Lisp_Object string
;
10624 /* Stop at nil string. */
10625 string
= XVECTOR (items
)->contents
[i
+ 1];
10629 /* Remember where item was displayed. */
10630 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
10632 /* Display the item, pad with one space. */
10633 if (it
.current_x
< it
.last_visible_x
)
10634 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
10635 XSTRING (string
)->size
+ 1, 0, 0, -1);
10638 /* Fill out the line with spaces. */
10639 if (it
.current_x
< it
.last_visible_x
)
10640 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
10642 /* Compute the total height of the lines. */
10643 compute_line_metrics (&it
);
10648 /***********************************************************************
10650 ***********************************************************************/
10652 /* Display the mode and/or top line of window W. */
10655 display_mode_lines (w
)
10658 /* These will be set while the mode line specs are processed. */
10659 line_number_displayed
= 0;
10660 w
->column_number_displayed
= Qnil
;
10662 if (WINDOW_WANTS_MODELINE_P (w
))
10663 display_mode_line (w
, MODE_LINE_FACE_ID
, current_buffer
->mode_line_format
);
10665 if (WINDOW_WANTS_TOP_LINE_P (w
))
10666 display_mode_line (w
, TOP_LINE_FACE_ID
, current_buffer
->top_line_format
);
10670 /* Display mode or top line of window W. FACE_ID specifies which line
10671 to display; it is either MODE_LINE_FACE_ID or TOP_LINE_FACE_ID.
10672 FORMAT is the mode line format to display. */
10675 display_mode_line (w
, face_id
, format
)
10677 enum face_id face_id
;
10678 Lisp_Object format
;
10683 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
10684 prepare_desired_row (it
.glyph_row
);
10686 /* Temporarily make frame's keyboard the current kboard so that
10687 kboard-local variables in the mode_line_format will get the right
10689 push_frame_kboard (it
.f
);
10690 display_mode_element (&it
, 0, 0, 0, format
);
10691 pop_frame_kboard ();
10693 /* Fill up with spaces. */
10694 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
10696 compute_line_metrics (&it
);
10697 it
.glyph_row
->full_width_p
= 1;
10698 it
.glyph_row
->mode_line_p
= 1;
10699 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
10700 it
.glyph_row
->continued_p
= 0;
10701 it
.glyph_row
->truncated_on_left_p
= 0;
10702 it
.glyph_row
->truncated_on_right_p
= 0;
10704 /* Make a 3D mode-line have a shadow at its right end. */
10705 face
= FACE_FROM_ID (it
.f
, face_id
);
10706 extend_face_to_end_of_line (&it
);
10707 if (face
->box
!= FACE_NO_BOX
)
10709 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
10710 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
10711 last
->right_box_line_p
= 1;
10716 /* Contribute ELT to the mode line for window IT->w. How it
10717 translates into text depends on its data type.
10719 IT describes the display environment in which we display, as usual.
10721 DEPTH is the depth in recursion. It is used to prevent
10722 infinite recursion here.
10724 FIELD_WIDTH is the number of characters the display of ELT should
10725 occupy in the mode line, and PRECISION is the maximum number of
10726 characters to display from ELT's representation. See
10727 display_string for details. *
10729 Returns the hpos of the end of the text generated by ELT. */
10732 display_mode_element (it
, depth
, field_width
, precision
, elt
)
10735 int field_width
, precision
;
10738 int n
= 0, field
, prec
;
10746 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
10750 /* A string: output it and check for %-constructs within it. */
10752 unsigned char *this = XSTRING (elt
)->data
;
10753 unsigned char *lisp_string
= this;
10755 while ((precision
<= 0 || n
< precision
)
10757 && (frame_title_ptr
10758 || it
->current_x
< it
->last_visible_x
))
10760 unsigned char *last
= this;
10762 /* Advance to end of string or next format specifier. */
10763 while ((c
= *this++) != '\0' && c
!= '%')
10766 if (this - 1 != last
)
10768 /* Output to end of string or up to '%'. Field width
10769 is length of string. Don't output more than
10770 PRECISION allows us. */
10771 prec
= --this - last
;
10772 if (precision
> 0 && prec
> precision
- n
)
10773 prec
= precision
- n
;
10775 if (frame_title_ptr
)
10776 n
+= store_frame_title (last
, prec
, prec
);
10778 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
10779 it
, 0, prec
, 0, -1);
10781 else /* c == '%' */
10783 unsigned char *percent_position
= this;
10785 /* Get the specified minimum width. Zero means
10788 while ((c
= *this++) >= '0' && c
<= '9')
10789 field
= field
* 10 + c
- '0';
10791 /* Don't pad beyond the total padding allowed. */
10792 if (field_width
- n
> 0 && field
> field_width
- n
)
10793 field
= field_width
- n
;
10795 /* Note that either PRECISION <= 0 or N < PRECISION. */
10796 prec
= precision
- n
;
10799 n
+= display_mode_element (it
, depth
, field
, prec
,
10800 Vglobal_mode_string
);
10803 unsigned char *spec
10804 = decode_mode_spec (it
->w
, c
, field
, prec
);
10806 if (frame_title_ptr
)
10807 n
+= store_frame_title (spec
, field
, prec
);
10811 = it
->glyph_row
->used
[TEXT_AREA
];
10813 = percent_position
- XSTRING (elt
)->data
;
10815 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
10816 field
, prec
, 0, -1);
10818 /* Assign to the glyphs written above the
10819 string where the `%x' came from, position
10823 struct glyph
*glyph
10824 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
10828 for (i
= 0; i
< nwritten
; ++i
)
10830 glyph
[i
].object
= elt
;
10831 glyph
[i
].charpos
= charpos
;
10844 /* A symbol: process the value of the symbol recursively
10845 as if it appeared here directly. Avoid error if symbol void.
10846 Special case: if value of symbol is a string, output the string
10849 register Lisp_Object tem
;
10850 tem
= Fboundp (elt
);
10853 tem
= Fsymbol_value (elt
);
10854 /* If value is a string, output that string literally:
10855 don't check for % within it. */
10858 prec
= XSTRING (tem
)->size
;
10859 if (precision
> 0 && prec
> precision
- n
)
10860 prec
= precision
- n
;
10861 if (frame_title_ptr
)
10862 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
10864 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
10867 else if (!EQ (tem
, elt
))
10869 /* Give up right away for nil or t. */
10879 register Lisp_Object car
, tem
;
10881 /* A cons cell: three distinct cases.
10882 If first element is a string or a cons, process all the elements
10883 and effectively concatenate them.
10884 If first element is a negative number, truncate displaying cdr to
10885 at most that many characters. If positive, pad (with spaces)
10886 to at least that many characters.
10887 If first element is a symbol, process the cadr or caddr recursively
10888 according to whether the symbol's value is non-nil or nil. */
10889 car
= XCONS (elt
)->car
;
10890 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
10892 /* An element of the form (:eval FORM) means evaluate FORM
10893 and use the result as mode line elements. */
10894 struct gcpro gcpro1
;
10897 spec
= eval_form (XCAR (XCDR (elt
)));
10899 n
+= display_mode_element (it
, depth
, field_width
- n
,
10900 precision
- n
, spec
);
10903 else if (SYMBOLP (car
))
10905 tem
= Fboundp (car
);
10906 elt
= XCONS (elt
)->cdr
;
10909 /* elt is now the cdr, and we know it is a cons cell.
10910 Use its car if CAR has a non-nil value. */
10913 tem
= Fsymbol_value (car
);
10915 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
10917 /* Symbol's value is nil (or symbol is unbound)
10918 Get the cddr of the original list
10919 and if possible find the caddr and use that. */
10920 elt
= XCONS (elt
)->cdr
;
10923 else if (!CONSP (elt
))
10925 elt
= XCONS (elt
)->car
;
10928 else if (INTEGERP (car
))
10930 register int lim
= XINT (car
);
10931 elt
= XCONS (elt
)->cdr
;
10934 /* Negative int means reduce maximum width. */
10935 if (precision
<= 0)
10938 precision
= min (precision
, -lim
);
10942 /* Padding specified. Don't let it be more than
10943 current maximum. */
10945 lim
= min (precision
, lim
);
10947 /* If that's more padding than already wanted, queue it.
10948 But don't reduce padding already specified even if
10949 that is beyond the current truncation point. */
10950 field_width
= max (lim
, field_width
);
10954 else if (STRINGP (car
) || CONSP (car
))
10956 register int limit
= 50;
10957 /* Limit is to protect against circular lists. */
10960 && (precision
<= 0 || n
< precision
))
10962 n
+= display_mode_element (it
, depth
, field_width
- n
,
10963 precision
- n
, XCONS (elt
)->car
);
10964 elt
= XCONS (elt
)->cdr
;
10972 if (frame_title_ptr
)
10973 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
10975 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
10976 precision
- n
, 0, 0);
10980 /* Pad to FIELD_WIDTH. */
10981 if (field_width
> 0 && n
< field_width
)
10983 if (frame_title_ptr
)
10984 n
+= store_frame_title ("", field_width
- n
, 0);
10986 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
10994 /* Write a null-terminated, right justified decimal representation of
10995 the positive integer D to BUF using a minimal field width WIDTH. */
10998 pint2str (buf
, width
, d
)
10999 register char *buf
;
11000 register int width
;
11003 register char *p
= buf
;
11011 *p
++ = d
% 10 + '0';
11016 for (width
-= (int) (p
- buf
); width
> 0; --width
)
11027 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
11028 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
11029 type of CODING_SYSTEM. Return updated pointer into BUF. */
11031 static unsigned char invalid_eol_type
[] = "(*invalid*)";
11034 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
11035 Lisp_Object coding_system
;
11036 register char *buf
;
11040 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
11041 unsigned char *eol_str
;
11043 /* The EOL conversion we are using. */
11044 Lisp_Object eoltype
;
11046 val
= coding_system
;
11048 if (NILP (val
)) /* Not yet decided. */
11053 eoltype
= eol_mnemonic_undecided
;
11054 /* Don't mention EOL conversion if it isn't decided. */
11058 Lisp_Object eolvalue
;
11060 eolvalue
= Fget (coding_system
, Qeol_type
);
11062 while (!NILP (val
) && SYMBOLP (val
))
11064 val
= Fget (val
, Qcoding_system
);
11065 if (NILP (eolvalue
))
11066 eolvalue
= Fget (val
, Qeol_type
);
11070 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
11074 /* The EOL conversion that is normal on this system. */
11076 if (NILP (eolvalue
)) /* Not yet decided. */
11077 eoltype
= eol_mnemonic_undecided
;
11078 else if (VECTORP (eolvalue
)) /* Not yet decided. */
11079 eoltype
= eol_mnemonic_undecided
;
11080 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
11081 eoltype
= (XFASTINT (eolvalue
) == 0
11082 ? eol_mnemonic_unix
11083 : (XFASTINT (eolvalue
) == 1
11084 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
11090 /* Mention the EOL conversion if it is not the usual one. */
11091 if (STRINGP (eoltype
))
11093 eol_str
= XSTRING (eoltype
)->data
;
11094 eol_str_len
= XSTRING (eoltype
)->size
;
11096 else if (INTEGERP (eoltype
)
11097 && CHAR_VALID_P (XINT (eoltype
), 0))
11099 int c
= XINT (eoltype
);
11100 unsigned char work
[4];
11102 eol_str_len
= CHAR_STRING (XINT (eoltype
), work
, eol_str
);
11106 eol_str
= invalid_eol_type
;
11107 eol_str_len
= sizeof (invalid_eol_type
) - 1;
11109 bcopy (eol_str
, buf
, eol_str_len
);
11110 buf
+= eol_str_len
;
11116 /* Return a string for the output of a mode line %-spec for window W,
11117 generated by character C. PRECISION >= 0 means don't return a
11118 string longer than that value. FIELD_WIDTH > 0 means pad the
11119 string returned with spaces to that value. */
11121 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
11124 decode_mode_spec (w
, c
, field_width
, precision
)
11127 int field_width
, precision
;
11130 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11131 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
11132 struct buffer
*b
= XBUFFER (w
->buffer
);
11139 if (!NILP (b
->read_only
))
11141 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
11146 /* This differs from %* only for a modified read-only buffer. */
11147 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
11149 if (!NILP (b
->read_only
))
11154 /* This differs from %* in ignoring read-only-ness. */
11155 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
11167 if (command_loop_level
> 5)
11169 p
= decode_mode_spec_buf
;
11170 for (i
= 0; i
< command_loop_level
; i
++)
11173 return decode_mode_spec_buf
;
11181 if (command_loop_level
> 5)
11183 p
= decode_mode_spec_buf
;
11184 for (i
= 0; i
< command_loop_level
; i
++)
11187 return decode_mode_spec_buf
;
11194 /* Let lots_of_dashes be a string of infinite length. */
11195 if (field_width
<= 0
11196 || field_width
> sizeof (lots_of_dashes
))
11198 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
11199 decode_mode_spec_buf
[i
] = '-';
11200 decode_mode_spec_buf
[i
] = '\0';
11201 return decode_mode_spec_buf
;
11204 return lots_of_dashes
;
11213 int col
= current_column ();
11214 XSETFASTINT (w
->column_number_displayed
, col
);
11215 pint2str (decode_mode_spec_buf
, field_width
, col
);
11216 return decode_mode_spec_buf
;
11220 /* %F displays the frame name. */
11221 if (!NILP (f
->title
))
11222 return (char *) XSTRING (f
->title
)->data
;
11223 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
11224 return (char *) XSTRING (f
->name
)->data
;
11233 int startpos
= XMARKER (w
->start
)->charpos
;
11234 int startpos_byte
= marker_byte_position (w
->start
);
11235 int line
, linepos
, linepos_byte
, topline
;
11237 int height
= XFASTINT (w
->height
);
11239 /* If we decided that this buffer isn't suitable for line numbers,
11240 don't forget that too fast. */
11241 if (EQ (w
->base_line_pos
, w
->buffer
))
11243 /* But do forget it, if the window shows a different buffer now. */
11244 else if (BUFFERP (w
->base_line_pos
))
11245 w
->base_line_pos
= Qnil
;
11247 /* If the buffer is very big, don't waste time. */
11248 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
11250 w
->base_line_pos
= Qnil
;
11251 w
->base_line_number
= Qnil
;
11255 if (!NILP (w
->base_line_number
)
11256 && !NILP (w
->base_line_pos
)
11257 && XFASTINT (w
->base_line_pos
) <= startpos
)
11259 line
= XFASTINT (w
->base_line_number
);
11260 linepos
= XFASTINT (w
->base_line_pos
);
11261 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
11266 linepos
= BUF_BEGV (b
);
11267 linepos_byte
= BUF_BEGV_BYTE (b
);
11270 /* Count lines from base line to window start position. */
11271 nlines
= display_count_lines (linepos
, linepos_byte
,
11275 topline
= nlines
+ line
;
11277 /* Determine a new base line, if the old one is too close
11278 or too far away, or if we did not have one.
11279 "Too close" means it's plausible a scroll-down would
11280 go back past it. */
11281 if (startpos
== BUF_BEGV (b
))
11283 XSETFASTINT (w
->base_line_number
, topline
);
11284 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
11286 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
11287 || linepos
== BUF_BEGV (b
))
11289 int limit
= BUF_BEGV (b
);
11290 int limit_byte
= BUF_BEGV_BYTE (b
);
11292 int distance
= (height
* 2 + 30) * 200;
11294 if (startpos
- distance
> limit
)
11296 limit
= startpos
- distance
;
11297 limit_byte
= CHAR_TO_BYTE (limit
);
11300 nlines
= display_count_lines (startpos
, startpos_byte
,
11302 - (height
* 2 + 30),
11304 /* If we couldn't find the lines we wanted within
11305 200 chars per line,
11306 give up on line numbers for this window. */
11307 if (position
== limit_byte
&& limit
== startpos
- distance
)
11309 w
->base_line_pos
= w
->buffer
;
11310 w
->base_line_number
= Qnil
;
11314 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
11315 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
11318 /* Now count lines from the start pos to point. */
11319 nlines
= display_count_lines (startpos
, startpos_byte
,
11320 PT_BYTE
, PT
, &junk
);
11322 /* Record that we did display the line number. */
11323 line_number_displayed
= 1;
11325 /* Make the string to show. */
11326 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
11327 return decode_mode_spec_buf
;
11330 char* p
= decode_mode_spec_buf
;
11331 int pad
= field_width
- 2;
11336 return decode_mode_spec_buf
;
11342 obj
= b
->mode_name
;
11346 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
11352 int pos
= marker_position (w
->start
);
11353 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
11355 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
11357 if (pos
<= BUF_BEGV (b
))
11362 else if (pos
<= BUF_BEGV (b
))
11366 if (total
> 1000000)
11367 /* Do it differently for a large value, to avoid overflow. */
11368 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
11370 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
11371 /* We can't normally display a 3-digit number,
11372 so get us a 2-digit number that is close. */
11375 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
11376 return decode_mode_spec_buf
;
11380 /* Display percentage of size above the bottom of the screen. */
11383 int toppos
= marker_position (w
->start
);
11384 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
11385 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
11387 if (botpos
>= BUF_ZV (b
))
11389 if (toppos
<= BUF_BEGV (b
))
11396 if (total
> 1000000)
11397 /* Do it differently for a large value, to avoid overflow. */
11398 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
11400 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
11401 /* We can't normally display a 3-digit number,
11402 so get us a 2-digit number that is close. */
11405 if (toppos
<= BUF_BEGV (b
))
11406 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
11408 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
11409 return decode_mode_spec_buf
;
11414 /* status of process */
11415 obj
= Fget_buffer_process (w
->buffer
);
11417 return "no process";
11418 #ifdef subprocesses
11419 obj
= Fsymbol_name (Fprocess_status (obj
));
11423 case 't': /* indicate TEXT or BINARY */
11424 #ifdef MODE_LINE_BINARY_TEXT
11425 return MODE_LINE_BINARY_TEXT (b
);
11431 /* coding-system (not including end-of-line format) */
11433 /* coding-system (including end-of-line type) */
11435 int eol_flag
= (c
== 'Z');
11436 char *p
= decode_mode_spec_buf
;
11438 if (! FRAME_WINDOW_P (f
))
11440 /* No need to mention EOL here--the terminal never needs
11441 to do EOL conversion. */
11442 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
11443 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
11445 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
11448 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
11449 #ifdef subprocesses
11450 obj
= Fget_buffer_process (Fcurrent_buffer ());
11451 if (PROCESSP (obj
))
11453 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
11455 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
11458 #endif /* subprocesses */
11461 return decode_mode_spec_buf
;
11466 return (char *) XSTRING (obj
)->data
;
11472 /* Count up to COUNT lines starting from START / START_BYTE.
11473 But don't go beyond LIMIT_BYTE.
11474 Return the number of lines thus found (always nonnegative).
11476 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
11479 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
11480 int start
, start_byte
, limit_byte
, count
;
11483 register unsigned char *cursor
;
11484 unsigned char *base
;
11486 register int ceiling
;
11487 register unsigned char *ceiling_addr
;
11488 int orig_count
= count
;
11490 /* If we are not in selective display mode,
11491 check only for newlines. */
11492 int selective_display
= (!NILP (current_buffer
->selective_display
)
11493 && !INTEGERP (current_buffer
->selective_display
));
11497 while (start_byte
< limit_byte
)
11499 ceiling
= BUFFER_CEILING_OF (start_byte
);
11500 ceiling
= min (limit_byte
- 1, ceiling
);
11501 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
11502 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
11505 if (selective_display
)
11506 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
11509 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
11512 if (cursor
!= ceiling_addr
)
11516 start_byte
+= cursor
- base
+ 1;
11517 *byte_pos_ptr
= start_byte
;
11521 if (++cursor
== ceiling_addr
)
11527 start_byte
+= cursor
- base
;
11532 while (start_byte
> limit_byte
)
11534 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
11535 ceiling
= max (limit_byte
, ceiling
);
11536 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
11537 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
11540 if (selective_display
)
11541 while (--cursor
!= ceiling_addr
11542 && *cursor
!= '\n' && *cursor
!= 015)
11545 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
11548 if (cursor
!= ceiling_addr
)
11552 start_byte
+= cursor
- base
+ 1;
11553 *byte_pos_ptr
= start_byte
;
11554 /* When scanning backwards, we should
11555 not count the newline posterior to which we stop. */
11556 return - orig_count
- 1;
11562 /* Here we add 1 to compensate for the last decrement
11563 of CURSOR, which took it past the valid range. */
11564 start_byte
+= cursor
- base
+ 1;
11568 *byte_pos_ptr
= limit_byte
;
11571 return - orig_count
+ count
;
11572 return orig_count
- count
;
11578 /***********************************************************************
11580 ***********************************************************************/
11582 /* Display a NUL-terminated string, starting with index START.
11584 If STRING is non-null, display that C string. Otherwise, the Lisp
11585 string LISP_STRING is displayed.
11587 If FACE_STRING is not nil, FACE_STRING_POS is a position in
11588 FACE_STRING. Display STRING or LISP_STRING with the face at
11589 FACE_STRING_POS in FACE_STRING:
11591 Display the string in the environment given by IT, but use the
11592 standard display table, temporarily.
11594 FIELD_WIDTH is the minimum number of output glyphs to produce.
11595 If STRING has fewer characters than FIELD_WIDTH, pad to the right
11596 with spaces. If STRING has more characters, more than FIELD_WIDTH
11597 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
11599 PRECISION is the maximum number of characters to output from
11600 STRING. PRECISION < 0 means don't truncate the string.
11602 This is roughly equivalent to printf format specifiers:
11604 FIELD_WIDTH PRECISION PRINTF
11605 ----------------------------------------
11611 MULTIBYTE zero means do not display multibyte chars, > 0 means do
11612 display them, and < 0 means obey the current buffer's value of
11613 enable_multibyte_characters.
11615 Value is the number of glyphs produced. */
11618 display_string (string
, lisp_string
, face_string
, face_string_pos
,
11619 start
, it
, field_width
, precision
, max_x
, multibyte
)
11620 unsigned char *string
;
11621 Lisp_Object lisp_string
;
11624 int field_width
, precision
, max_x
;
11627 int hpos_at_start
= it
->hpos
;
11628 int saved_face_id
= it
->face_id
;
11629 struct glyph_row
*row
= it
->glyph_row
;
11631 /* Initialize the iterator IT for iteration over STRING beginning
11632 with index START. We assume that IT may be modified here (which
11633 means that display_line has to do something when displaying a
11634 mini-buffer prompt, which it does). */
11635 reseat_to_string (it
, string
, lisp_string
, start
,
11636 precision
, field_width
, multibyte
);
11638 /* If displaying STRING, set up the face of the iterator
11639 from LISP_STRING, if that's given. */
11640 if (STRINGP (face_string
))
11646 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
11647 0, it
->region_beg_charpos
,
11648 it
->region_end_charpos
,
11649 &endptr
, it
->base_face_id
);
11650 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11651 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
11654 /* Set max_x to the maximum allowed X position. Don't let it go
11655 beyond the right edge of the window. */
11657 max_x
= it
->last_visible_x
;
11659 max_x
= min (max_x
, it
->last_visible_x
);
11661 /* Skip over display elements that are not visible. because IT->w is
11663 if (it
->current_x
< it
->first_visible_x
)
11664 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
11665 MOVE_TO_POS
| MOVE_TO_X
);
11667 row
->ascent
= it
->max_ascent
;
11668 row
->height
= it
->max_ascent
+ it
->max_descent
;
11670 /* This condition is for the case that we are called with current_x
11671 past last_visible_x. */
11672 while (it
->current_x
< max_x
)
11674 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
11676 /* Get the next display element. */
11677 if (!get_next_display_element (it
))
11680 /* Produce glyphs. */
11681 x_before
= it
->current_x
;
11682 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
11683 PRODUCE_GLYPHS (it
);
11685 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
11688 while (i
< nglyphs
)
11690 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11692 if (!it
->truncate_lines_p
11693 && x
+ glyph
->pixel_width
> max_x
)
11695 /* End of continued line or max_x reached. */
11696 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11700 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
11702 /* Glyph is at least partially visible. */
11704 if (x
< it
->first_visible_x
)
11705 it
->glyph_row
->x
= x
- it
->first_visible_x
;
11709 /* Glyph is off the left margin of the display area.
11710 Should not happen. */
11714 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11715 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11716 x
+= glyph
->pixel_width
;
11720 /* Stop if max_x reached. */
11724 /* Stop at line ends. */
11725 if (ITERATOR_AT_END_OF_LINE_P (it
))
11727 it
->continuation_lines_width
= 0;
11731 set_iterator_to_next (it
);
11733 /* Stop if truncating at the right edge. */
11734 if (it
->truncate_lines_p
11735 && it
->current_x
>= it
->last_visible_x
)
11737 /* Add truncation mark, but don't do it if the line is
11738 truncated at a padding space. */
11739 if (IT_CHARPOS (*it
) < it
->string_nchars
)
11741 if (!FRAME_WINDOW_P (it
->f
))
11742 produce_special_glyphs (it
, IT_TRUNCATION
);
11743 it
->glyph_row
->truncated_on_right_p
= 1;
11749 /* Maybe insert a truncation at the left. */
11750 if (it
->first_visible_x
11751 && IT_CHARPOS (*it
) > 0)
11753 if (!FRAME_WINDOW_P (it
->f
))
11754 insert_left_trunc_glyphs (it
);
11755 it
->glyph_row
->truncated_on_left_p
= 1;
11758 it
->face_id
= saved_face_id
;
11760 /* Value is number of columns displayed. */
11761 return it
->hpos
- hpos_at_start
;
11766 /* This is like a combination of memq and assq. Return 1 if PROPVAL
11767 appears as an element of LIST or as the car of an element of LIST.
11768 If PROPVAL is a list, compare each element against LIST in that
11769 way, and return 1 if any element of PROPVAL is found in LIST.
11770 Otherwise return 0. This function cannot quit. */
11773 invisible_p (propval
, list
)
11774 register Lisp_Object propval
;
11777 register Lisp_Object tail
, proptail
;
11778 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
11780 register Lisp_Object tem
;
11781 tem
= XCONS (tail
)->car
;
11782 if (EQ (propval
, tem
))
11784 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
11787 if (CONSP (propval
))
11788 for (proptail
= propval
; CONSP (proptail
);
11789 proptail
= XCONS (proptail
)->cdr
)
11791 Lisp_Object propelt
;
11792 propelt
= XCONS (proptail
)->car
;
11793 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
11795 register Lisp_Object tem
;
11796 tem
= XCONS (tail
)->car
;
11797 if (EQ (propelt
, tem
))
11799 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
11807 /* Return 1 if PROPVAL appears as the car of an element of LIST and
11808 the cdr of that element is non-nil. If PROPVAL is a list, check
11809 each element of PROPVAL in that way, and the first time some
11810 element is found, return 1 if the cdr of that element is non-nil.
11811 Otherwise return 0. This function cannot quit. */
11814 invisible_ellipsis_p (propval
, list
)
11815 register Lisp_Object propval
;
11818 register Lisp_Object tail
, proptail
;
11819 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
11821 register Lisp_Object tem
;
11822 tem
= XCONS (tail
)->car
;
11823 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
11824 return ! NILP (XCONS (tem
)->cdr
);
11826 if (CONSP (propval
))
11827 for (proptail
= propval
; CONSP (proptail
);
11828 proptail
= XCONS (proptail
)->cdr
)
11830 Lisp_Object propelt
;
11831 propelt
= XCONS (proptail
)->car
;
11832 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
11834 register Lisp_Object tem
;
11835 tem
= XCONS (tail
)->car
;
11836 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
11837 return ! NILP (XCONS (tem
)->cdr
);
11845 /***********************************************************************
11847 ***********************************************************************/
11852 echo_area_message
= previous_echo_area_message
= Qnil
;
11853 staticpro (&echo_area_message
);
11854 staticpro (&previous_echo_area_message
);
11856 staticpro (&Qinhibit_redisplay
);
11857 Qinhibit_redisplay
= intern ("inhibit-redisplay");
11860 defsubr (&Sdump_glyph_matrix
);
11861 defsubr (&Sdump_glyph_row
);
11862 defsubr (&Sdump_toolbar_row
);
11863 defsubr (&Strace_redisplay_toggle
);
11866 staticpro (&Qmenu_bar_update_hook
);
11867 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
11869 staticpro (&Qoverriding_terminal_local_map
);
11870 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
11872 staticpro (&Qoverriding_local_map
);
11873 Qoverriding_local_map
= intern ("overriding-local-map");
11875 staticpro (&Qwindow_scroll_functions
);
11876 Qwindow_scroll_functions
= intern ("window-scroll-functions");
11878 staticpro (&Qredisplay_end_trigger_functions
);
11879 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
11881 staticpro (&Qinhibit_point_motion_hooks
);
11882 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
11884 staticpro (&Qdisplay
);
11885 Qdisplay
= intern ("display");
11886 staticpro (&Qleft_margin
);
11887 Qspace_width
= intern ("space-width");
11888 staticpro (&Qspace_width
);
11889 Qheight
= intern ("height");
11890 staticpro (&Qheight
);
11891 Qraise
= intern ("raise");
11892 staticpro (&Qraise
);
11893 Qspace
= intern ("space");
11894 staticpro (&Qspace
);
11895 Qleft_margin
= intern ("left-margin");
11896 staticpro (&Qright_margin
);
11897 Qright_margin
= intern ("right-margin");
11898 Qalign_to
= intern ("align-to");
11899 staticpro (&Qalign_to
);
11900 QCalign_to
= intern (":align-to");
11901 staticpro (&QCalign_to
);
11902 Qwidth
= intern ("width");
11903 staticpro (&Qwidth
);
11904 Qrelative_width
= intern ("relative-width");
11905 staticpro (&Qrelative_width
);
11906 QCrelative_width
= intern (":relative-width");
11907 staticpro (&QCrelative_width
);
11908 QCrelative_height
= intern (":relative-height");
11909 staticpro (&QCrelative_height
);
11910 QCeval
= intern (":eval");
11911 staticpro (&QCeval
);
11912 QCwhen
= intern (":when");
11913 staticpro (&QCwhen
);
11914 Qfontified
= intern ("fontified");
11915 staticpro (&Qfontified
);
11916 Qfontification_functions
= intern ("fontification-functions");
11917 staticpro (&Qfontification_functions
);
11918 Qshow_trailing_whitespace
= intern ("show-trailing-whitespace");
11919 staticpro (&Qshow_trailing_whitespace
);
11920 Qtrailing_whitespace
= intern ("trailing-whitespace");
11921 staticpro (&Qtrailing_whitespace
);
11922 Qimage
= intern ("image");
11923 staticpro (&Qimage
);
11925 staticpro (&last_arrow_position
);
11926 staticpro (&last_arrow_string
);
11927 last_arrow_position
= Qnil
;
11928 last_arrow_string
= Qnil
;
11930 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
11931 "Non-nil means don't actually do any redisplay.\n\
11932 This is used for internal purposes.");
11933 Vinhibit_redisplay
= Qnil
;
11935 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
11936 "String (or mode line construct) included (normally) in `mode-line-format'.");
11937 Vglobal_mode_string
= Qnil
;
11939 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
11940 "Marker for where to display an arrow on top of the buffer text.\n\
11941 This must be the beginning of a line in order to work.\n\
11942 See also `overlay-arrow-string'.");
11943 Voverlay_arrow_position
= Qnil
;
11945 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
11946 "String to display as an arrow. See also `overlay-arrow-position'.");
11947 Voverlay_arrow_string
= Qnil
;
11949 DEFVAR_INT ("scroll-step", &scroll_step
,
11950 "*The number of lines to try scrolling a window by when point moves out.\n\
11951 If that fails to bring point back on frame, point is centered instead.\n\
11952 If this is zero, point is always centered after it moves off frame.");
11954 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
11955 "*Scroll up to this many lines, to bring point back on screen.");
11956 scroll_conservatively
= 0;
11958 DEFVAR_INT ("scroll-margin", &scroll_margin
,
11959 "*Number of lines of margin at the top and bottom of a window.\n\
11960 Recenter the window whenever point gets within this many lines\n\
11961 of the top or bottom of the window.");
11965 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
11968 DEFVAR_BOOL ("truncate-partial-width-windows",
11969 &truncate_partial_width_windows
,
11970 "*Non-nil means truncate lines in all windows less than full frame wide.");
11971 truncate_partial_width_windows
= 1;
11973 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
11974 "*Non-nil means use inverse video for the mode line.");
11975 mode_line_inverse_video
= 1;
11977 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
11978 "*Maximum buffer size for which line number should be displayed.\n\
11979 If the buffer is bigger than this, the line number does not appear\n\
11980 in the mode line.");
11981 line_number_display_limit
= 1000000;
11983 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
11984 "*Non-nil means highlight region even in nonselected windows.");
11985 highlight_nonselected_windows
= 0;
11987 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
11988 "Non-nil if more than one frame is visible on this display.\n\
11989 Minibuffer-only frames don't count, but iconified frames do.\n\
11990 This variable is not guaranteed to be accurate except while processing\n\
11991 `frame-title-format' and `icon-title-format'.");
11993 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
11994 "Template for displaying the title bar of visible frames.\n\
11995 \(Assuming the window manager supports this feature.)\n\
11996 This variable has the same structure as `mode-line-format' (which see),\n\
11997 and is used only on frames for which no explicit name has been set\n\
11998 \(see `modify-frame-parameters').");
11999 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
12000 "Template for displaying the title bar of an iconified frame.\n\
12001 \(Assuming the window manager supports this feature.)\n\
12002 This variable has the same structure as `mode-line-format' (which see),\n\
12003 and is used only on frames for which no explicit name has been set\n\
12004 \(see `modify-frame-parameters').");
12006 = Vframe_title_format
12007 = Fcons (intern ("multiple-frames"),
12008 Fcons (build_string ("%b"),
12009 Fcons (Fcons (build_string (""),
12010 Fcons (intern ("invocation-name"),
12011 Fcons (build_string ("@"),
12012 Fcons (intern ("system-name"),
12016 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
12017 "Maximum number of lines to keep in the message log buffer.\n\
12018 If nil, disable message logging. If t, log messages but don't truncate\n\
12019 the buffer when it becomes large.");
12020 XSETFASTINT (Vmessage_log_max
, 50);
12022 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
12023 "Functions called before redisplay, if window sizes have changed.\n\
12024 The value should be a list of functions that take one argument.\n\
12025 Just before redisplay, for each frame, if any of its windows have changed\n\
12026 size since the last redisplay, or have been split or deleted,\n\
12027 all the functions in the list are called, with the frame as argument.");
12028 Vwindow_size_change_functions
= Qnil
;
12030 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
12031 "List of Functions to call before redisplaying a window with scrolling.\n\
12032 Each function is called with two arguments, the window\n\
12033 and its new display-start position. Note that the value of `window-end'\n\
12034 is not valid when these functions are called.");
12035 Vwindow_scroll_functions
= Qnil
;
12037 DEFVAR_BOOL ("auto-resize-toolbars", &auto_resize_toolbars_p
,
12038 "*Non-nil means automatically resize toolbars.\n\
12039 This increases a toolbar's height if not all toolbar items are visible.\n\
12040 It decreases a toolbar's height when it would display blank lines\n\
12042 auto_resize_toolbars_p
= 1;
12044 DEFVAR_BOOL ("auto-raise-toolbar-buttons", &auto_raise_toolbar_buttons_p
,
12045 "*Non-nil means raise toolbar buttons when the mouse moves over them.");
12046 auto_raise_toolbar_buttons_p
= 1;
12048 DEFVAR_INT ("toolbar-button-margin", &toolbar_button_margin
,
12049 "*Margin around toolbar buttons in pixels.");
12050 toolbar_button_margin
= 1;
12052 DEFVAR_INT ("toolbar-button-relief", &toolbar_button_relief
,
12053 "Relief thickness of toolbar buttons.");
12054 toolbar_button_relief
= 3;
12056 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
12057 "List of functions to call to fontify regions of text.\n\
12058 Each function is called with one argument POS. Functions must\n\
12059 fontify a region starting at POS in the current buffer, and give\n\
12060 fontified regions the property `fontified'.\n\
12061 This variable automatically becomes buffer-local when set.");
12062 Vfontification_functions
= Qnil
;
12063 Fmake_local_variable (Qfontification_functions
);
12065 DEFVAR_BOOL ("unibyte-display-via-language-environment",
12066 &unibyte_display_via_language_environment
,
12067 "*Non-nil means display unibyte text according to language environment.\n\
12068 Specifically this means that unibyte non-ASCII characters\n\
12069 are displayed by converting them to the equivalent multibyte characters\n\
12070 according to the current language environment. As a result, they are\n\
12071 displayed according to the current fontset.");
12072 unibyte_display_via_language_environment
= 0;
12076 /* Initialize this module when Emacs starts. */
12081 Lisp_Object root_window
;
12082 struct window
*mini_w
;
12084 CHARPOS (this_line_start_pos
) = 0;
12086 mini_w
= XWINDOW (minibuf_window
);
12087 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
12089 echo_area_glyphs
= 0;
12090 previous_echo_glyphs
= 0;
12091 echo_area_message
= previous_echo_area_message
= Qnil
;
12093 if (!noninteractive
)
12095 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
12098 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
12099 set_window_height (root_window
,
12100 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
12102 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
12103 set_window_height (minibuf_window
, 1, 0);
12105 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
12106 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
12108 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
12109 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
12110 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
12112 /* The default ellipsis glyphs `...'. */
12113 for (i
= 0; i
< 3; ++i
)
12114 XSETFASTINT (default_invis_vector
[i
], '.');
12117 #ifdef HAVE_WINDOW_SYSTEM
12119 /* Allocate the buffer for frame titles. */
12121 frame_title_buf
= (char *) xmalloc (size
);
12122 frame_title_buf_end
= frame_title_buf
+ size
;
12123 frame_title_ptr
= NULL
;
12125 #endif /* HAVE_WINDOW_SYSTEM */