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 struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
603 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
604 static Lisp_Object eval_handler
P_ ((Lisp_Object
));
605 static Lisp_Object eval_form
P_ ((Lisp_Object
));
606 static void insert_left_trunc_glyphs
P_ ((struct it
*));
607 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
608 static void extend_face_to_end_of_line
P_ ((struct it
*));
609 static void append_space
P_ ((struct it
*, int));
610 static void make_cursor_line_fully_visible
P_ ((struct window
*));
611 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
612 static int trailing_whitespace_p
P_ ((int));
613 static int message_log_check_duplicate
P_ ((int, int, int, int));
614 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
615 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
616 static void push_it
P_ ((struct it
*));
617 static void pop_it
P_ ((struct it
*));
618 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
619 static void redisplay_internal
P_ ((int));
620 static void echo_area_display
P_ ((int));
621 static void redisplay_windows
P_ ((Lisp_Object
));
622 static void redisplay_window
P_ ((Lisp_Object
, int));
623 static void update_menu_bar
P_ ((struct frame
*, int));
624 static int try_window_reusing_current_matrix
P_ ((struct window
*));
625 static int try_window_id
P_ ((struct window
*));
626 static int display_line
P_ ((struct it
*));
627 static void display_mode_lines
P_ ((struct window
*));
628 static void display_mode_line
P_ ((struct window
*, enum face_id
,
630 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
631 static char *decode_mode_spec
P_ ((struct window
*, char, int, int));
632 static void display_menu_bar
P_ ((struct window
*));
633 static int display_count_lines
P_ ((int, int, int, int, int *));
634 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
635 int, int, struct it
*, int, int, int, int));
636 static void compute_line_metrics
P_ ((struct it
*));
637 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
638 static int get_overlay_strings
P_ ((struct it
*));
639 static void next_overlay_string
P_ ((struct it
*));
640 void set_iterator_to_next
P_ ((struct it
*));
641 static void reseat
P_ ((struct it
*, struct text_pos
, int));
642 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
643 static void back_to_previous_visible_line_start
P_ ((struct it
*));
644 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
645 static int next_element_from_display_vector
P_ ((struct it
*));
646 static int next_element_from_string
P_ ((struct it
*));
647 static int next_element_from_c_string
P_ ((struct it
*));
648 static int next_element_from_buffer
P_ ((struct it
*));
649 static int next_element_from_image
P_ ((struct it
*));
650 static int next_element_from_stretch
P_ ((struct it
*));
651 static void load_overlay_strings
P_ ((struct it
*));
652 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
653 struct display_pos
*));
654 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
655 Lisp_Object
, int, int, int, int));
656 static int charset_at_position
P_ ((struct text_pos
));
657 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
659 void move_it_vertically_backward
P_ ((struct it
*, int));
660 static void init_to_row_start
P_ ((struct it
*, struct window
*,
661 struct glyph_row
*));
662 static void init_to_row_end
P_ ((struct it
*, struct window
*,
663 struct glyph_row
*));
664 static void back_to_previous_line_start
P_ ((struct it
*));
665 static void forward_to_next_line_start
P_ ((struct it
*));
666 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
668 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
669 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
670 static int number_of_chars
P_ ((unsigned char *, int));
671 static void compute_stop_pos
P_ ((struct it
*));
672 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
674 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
675 static int next_overlay_change
P_ ((int));
676 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
677 Lisp_Object
, struct text_pos
*));
679 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
680 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
682 #ifdef HAVE_WINDOW_SYSTEM
684 static void update_toolbar
P_ ((struct frame
*, int));
685 static void build_desired_toolbar_string
P_ ((struct frame
*f
));
686 static int redisplay_toolbar
P_ ((struct frame
*));
687 static void display_toolbar_line
P_ ((struct it
*));
689 #endif /* HAVE_WINDOW_SYSTEM */
692 /***********************************************************************
693 Window display dimensions
694 ***********************************************************************/
696 /* Return the window-relative maximum y + 1 for glyph rows displaying
697 text in window W. This is the height of W minus the height of a
698 mode line, if any. */
701 window_text_bottom_y (w
)
704 struct frame
*f
= XFRAME (w
->frame
);
705 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
707 if (WINDOW_WANTS_MODELINE_P (w
))
708 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
713 /* Return the pixel width of display area AREA of window W. AREA < 0
714 means return the total width of W, not including bitmap areas to
715 the left and right of the window. */
718 window_box_width (w
, area
)
722 struct frame
*f
= XFRAME (w
->frame
);
723 int width
= XFASTINT (w
->width
);
725 if (!w
->pseudo_window_p
)
727 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + 2 * FRAME_FLAGS_AREA_COLS (f
);
729 if (area
== TEXT_AREA
)
731 if (INTEGERP (w
->left_margin_width
))
732 width
-= XFASTINT (w
->left_margin_width
);
733 if (INTEGERP (w
->right_margin_width
))
734 width
-= XFASTINT (w
->right_margin_width
);
736 else if (area
== LEFT_MARGIN_AREA
)
737 width
= (INTEGERP (w
->left_margin_width
)
738 ? XFASTINT (w
->left_margin_width
) : 0);
739 else if (area
== RIGHT_MARGIN_AREA
)
740 width
= (INTEGERP (w
->right_margin_width
)
741 ? XFASTINT (w
->right_margin_width
) : 0);
744 return width
* CANON_X_UNIT (f
);
748 /* Return the pixel height of the display area of window W, not
749 including mode lines of W, if any.. */
752 window_box_height (w
)
755 struct frame
*f
= XFRAME (w
->frame
);
756 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
758 if (WINDOW_WANTS_MODELINE_P (w
))
759 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
761 if (WINDOW_WANTS_TOP_LINE_P (w
))
762 height
-= CURRENT_TOP_LINE_HEIGHT (w
);
768 /* Return the frame-relative coordinate of the left edge of display
769 area AREA of window W. AREA < 0 means return the left edge of the
770 whole window, to the right of any bitmap area at the left side of
774 window_box_left (w
, area
)
778 struct frame
*f
= XFRAME (w
->frame
);
779 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
781 if (!w
->pseudo_window_p
)
783 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
784 + FRAME_FLAGS_AREA_WIDTH (f
));
786 if (area
== TEXT_AREA
)
787 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
788 else if (area
== RIGHT_MARGIN_AREA
)
789 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
790 + window_box_width (w
, TEXT_AREA
));
797 /* Return the frame-relative coordinate of the right edge of display
798 area AREA of window W. AREA < 0 means return the left edge of the
799 whole window, to the left of any bitmap area at the right side of
803 window_box_right (w
, area
)
807 return window_box_left (w
, area
) + window_box_width (w
, area
);
811 /* Get the bounding box of the display area AREA of window W, without
812 mode lines, in frame-relative coordinates. AREA < 0 means the
813 whole window, not including bitmap areas to the left and right of
814 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
815 coordinates of the upper-left corner of the box. Return in
816 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
819 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
822 int *box_x
, *box_y
, *box_width
, *box_height
;
824 struct frame
*f
= XFRAME (w
->frame
);
826 *box_width
= window_box_width (w
, area
);
827 *box_height
= window_box_height (w
);
828 *box_x
= window_box_left (w
, area
);
829 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
830 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
831 if (WINDOW_WANTS_TOP_LINE_P (w
))
832 *box_y
+= CURRENT_TOP_LINE_HEIGHT (w
);
836 /* Get the bounding box of the display area AREA of window W, without
837 mode lines. AREA < 0 means the whole window, not including bitmap
838 areas to the left and right of the window. Return in *TOP_LEFT_X
839 and TOP_LEFT_Y the frame-relative pixel coordinates of the
840 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
841 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
845 window_box_edges (w
, area
, top_left_x
, top_left_y
,
846 bottom_right_x
, bottom_right_y
)
849 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
851 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
853 *bottom_right_x
+= *top_left_x
;
854 *bottom_right_y
+= *top_left_y
;
859 /***********************************************************************
861 ***********************************************************************/
863 /* Given a position POS containing a valid character and byte position
864 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
866 static struct text_pos
867 string_pos_nchars_ahead (pos
, string
, nchars
)
872 xassert (STRINGP (string
) && nchars
>= 0);
874 if (STRING_MULTIBYTE (string
))
876 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
877 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
882 STRING_CHAR_AND_LENGTH (p
, rest
, len
);
883 p
+= len
, rest
-= len
;
886 BYTEPOS (pos
) += len
;
890 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
896 /* Value is the text position, i.e. character and byte position,
897 for character position CHARPOS in STRING. */
899 static INLINE
struct text_pos
900 string_pos (charpos
, string
)
905 xassert (STRINGP (string
));
906 xassert (charpos
>= 0);
907 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
912 /* Value is a text position, i.e. character and byte position, for
913 character position CHARPOS in C string S. MULTIBYTE_P non-zero
914 means recognize multibyte characters. */
916 static struct text_pos
917 c_string_pos (charpos
, s
, multibyte_p
)
925 xassert (charpos
>= 0);
929 int rest
= strlen (s
), len
;
931 SET_TEXT_POS (pos
, 0, 0);
934 STRING_CHAR_AND_LENGTH (s
, rest
, len
);
935 s
+= len
, rest
-= len
;
938 BYTEPOS (pos
) += len
;
942 SET_TEXT_POS (pos
, charpos
, charpos
);
948 /* Value is the number of characters in C string S. MULTIBYTE_P
949 non-zero means recognize multibyte characters. */
952 number_of_chars (s
, multibyte_p
)
960 int rest
= strlen (s
), len
;
961 unsigned char *p
= (unsigned char *) s
;
963 for (nchars
= 0; rest
> 0; ++nchars
)
965 STRING_CHAR_AND_LENGTH (p
, rest
, len
);
966 rest
-= len
, p
+= len
;
976 /* Compute byte position NEWPOS->bytepos corresponding to
977 NEWPOS->charpos. POS is a known position in string STRING.
978 NEWPOS->charpos must be >= POS.charpos. */
981 compute_string_pos (newpos
, pos
, string
)
982 struct text_pos
*newpos
, pos
;
985 xassert (STRINGP (string
));
986 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
988 if (STRING_MULTIBYTE (string
))
989 *newpos
= string_pos_nchars_ahead (pos
, CHARPOS (*newpos
) - CHARPOS (pos
),
992 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
996 /* Return the charset of the character at position POS in
1000 charset_at_position (pos
)
1001 struct text_pos pos
;
1004 unsigned char *p
= BYTE_POS_ADDR (BYTEPOS (pos
));
1006 multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1009 int maxlen
= ((BYTEPOS (pos
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
1012 c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, len
);
1017 return CHAR_CHARSET (c
);
1022 /***********************************************************************
1023 Lisp form evaluation
1024 ***********************************************************************/
1026 /* Error handler for eval_form. */
1036 /* Evaluate SEXPR and return the result, or nil if something went
1043 int count
= specpdl_ptr
- specpdl
;
1045 specbind (Qinhibit_redisplay
, Qt
);
1046 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, eval_handler
);
1047 return unbind_to (count
, val
);
1052 /***********************************************************************
1054 ***********************************************************************/
1058 /* Define CHECK_IT to perform sanity checks on iterators.
1059 This is for debugging. It is too slow to do unconditionally. */
1065 if (it
->method
== next_element_from_string
)
1067 xassert (STRINGP (it
->string
));
1068 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1070 else if (it
->method
== next_element_from_buffer
)
1072 /* Check that character and byte positions agree. */
1073 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1077 xassert (it
->current
.dpvec_index
>= 0);
1079 xassert (it
->current
.dpvec_index
< 0);
1082 #define CHECK_IT(IT) check_it ((IT))
1086 #define CHECK_IT(IT) (void) 0
1093 /* Check that the window end of window W is what we expect it
1094 to be---the last row in the current matrix displaying text. */
1097 check_window_end (w
)
1100 if (!MINI_WINDOW_P (w
)
1101 && !NILP (w
->window_end_valid
))
1103 struct glyph_row
*row
;
1104 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1105 XFASTINT (w
->window_end_vpos
)),
1107 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1108 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1112 #define CHECK_WINDOW_END(W) check_window_end ((W))
1114 #else /* not GLYPH_DEBUG */
1116 #define CHECK_WINDOW_END(W) (void) 0
1118 #endif /* not GLYPH_DEBUG */
1122 /***********************************************************************
1123 Iterator initialization
1124 ***********************************************************************/
1126 /* Initialize IT for displaying current_buffer in window W, starting
1127 at character position CHARPOS. CHARPOS < 0 means that no buffer
1128 position is specified which is useful when the iterator is assigned
1129 a position later. BYTEPOS is the byte position corresponding to
1130 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1132 If ROW is not null, calls to produce_glyphs with IT as parameter
1133 will produce glyphs in that row.
1135 BASE_FACE_ID is the id of a base face to use. It must be one of
1136 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1137 TOP_LINE_FACE_ID for displaying mode lines, or TOOLBAR_FACE_ID for
1138 displaying the toolbar.
1140 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1141 TOP_LINE_FACE_ID, the iterator will be initialized to use the
1142 corresponding mode line glyph row of the desired matrix of W. */
1145 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1148 int charpos
, bytepos
;
1149 struct glyph_row
*row
;
1150 enum face_id base_face_id
;
1152 int highlight_region_p
;
1155 /* Some precondition checks. */
1156 xassert (w
!= NULL
&& it
!= NULL
);
1157 xassert (charpos
< 0 || current_buffer
== XBUFFER (w
->buffer
));
1158 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1160 /* If face attributes have been changed since the last redisplay,
1161 free realized faces now because they depend on face definitions
1162 that might have changed. */
1163 if (face_change_count
)
1165 face_change_count
= 0;
1166 free_all_realized_faces (Qnil
);
1169 /* Use one of the mode line rows of W's desired matrix if
1173 if (base_face_id
== MODE_LINE_FACE_ID
)
1174 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1175 else if (base_face_id
== TOP_LINE_FACE_ID
)
1176 row
= MATRIX_TOP_LINE_ROW (w
->desired_matrix
);
1180 bzero (it
, sizeof *it
);
1181 it
->current
.overlay_string_index
= -1;
1182 it
->current
.dpvec_index
= -1;
1183 it
->charset
= CHARSET_ASCII
;
1184 it
->base_face_id
= base_face_id
;
1186 /* The window in which we iterate over current_buffer: */
1187 XSETWINDOW (it
->window
, w
);
1189 it
->f
= XFRAME (w
->frame
);
1191 /* If realized faces have been removed, e.g. because of face
1192 attribute changes of named faces, recompute them. */
1193 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1194 recompute_basic_faces (it
->f
);
1196 /* Should we highlight trailing whitespace? */
1197 value
= find_symbol_value (Qshow_trailing_whitespace
);
1198 it
->show_trailing_whitespace_p
1199 = EQ (value
, Qunbound
) ? 0 : !NILP (value
);
1201 /* Current value of the `space-width', and 'height' properties. */
1202 it
->space_width
= Qnil
;
1203 it
->font_height
= Qnil
;
1205 /* Are control characters displayed as `^C'? */
1206 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1208 /* -1 means everything between a CR and the following line end
1209 is invisible. >0 means lines indented more than this value are
1211 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1212 ? XFASTINT (current_buffer
->selective_display
)
1213 : (!NILP (current_buffer
->selective_display
)
1215 it
->selective_display_ellipsis_p
1216 = !NILP (current_buffer
->selective_display_ellipses
);
1218 /* Display table to use. */
1219 it
->dp
= window_display_table (w
);
1221 /* Are multibyte characters enabled in current_buffer? */
1222 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1224 /* Non-zero if we should highlight the region. */
1226 = (!NILP (Vtransient_mark_mode
)
1227 && !NILP (current_buffer
->mark_active
)
1228 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1230 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1231 start and end of a visible region in window IT->w. Set both to
1232 -1 to indicate no region. */
1233 if (highlight_region_p
1234 /* Maybe highlight only in selected window. */
1235 && (/* Either show region everywhere. */
1236 highlight_nonselected_windows
1237 /* Or show region in the selected window. */
1238 || w
== XWINDOW (selected_window
)
1239 /* Or show the region if we are in the mini-buffer and W is
1240 the window the mini-buffer refers to. */
1241 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1242 && w
== XWINDOW (Vminibuf_scroll_window
))))
1244 int charpos
= marker_position (current_buffer
->mark
);
1245 it
->region_beg_charpos
= min (PT
, charpos
);
1246 it
->region_end_charpos
= max (PT
, charpos
);
1249 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1251 /* Get the position at which the redisplay_end_trigger hook should
1252 be run, if it is to be run at all. */
1253 if (MARKERP (w
->redisplay_end_trigger
)
1254 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1255 it
->redisplay_end_trigger_charpos
1256 = marker_position (w
->redisplay_end_trigger
);
1257 else if (INTEGERP (w
->redisplay_end_trigger
))
1258 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1260 /* Correct bogus values of tab_width. */
1261 it
->tab_width
= XINT (current_buffer
->tab_width
);
1262 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1265 /* Are lines in the display truncated? */
1266 it
->truncate_lines_p
1267 = (base_face_id
!= DEFAULT_FACE_ID
1268 || XINT (it
->w
->hscroll
)
1269 || (truncate_partial_width_windows
1270 && !WINDOW_FULL_WIDTH_P (it
->w
))
1271 || !NILP (current_buffer
->truncate_lines
));
1273 /* Get dimensions of truncation and continuation glyphs. These are
1274 displayed as bitmaps under X, so we don't need them for such
1276 if (!FRAME_WINDOW_P (it
->f
))
1278 if (it
->truncate_lines_p
)
1280 /* We will need the truncation glyph. */
1281 xassert (it
->glyph_row
== NULL
);
1282 produce_special_glyphs (it
, IT_TRUNCATION
);
1283 it
->truncation_pixel_width
= it
->pixel_width
;
1287 /* We will need the continuation glyph. */
1288 xassert (it
->glyph_row
== NULL
);
1289 produce_special_glyphs (it
, IT_CONTINUATION
);
1290 it
->continuation_pixel_width
= it
->pixel_width
;
1293 /* Reset these values to zero becaue the produce_special_glyphs
1294 above has changed them. */
1295 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1298 /* Set this after getting the dimensions of truncation and
1299 continuation glyphs, so that we don't produce glyphs when calling
1300 produce_special_glyphs, above. */
1301 it
->glyph_row
= row
;
1302 it
->area
= TEXT_AREA
;
1304 /* Get the dimensions of the display area. The display area
1305 consists of the visible window area plus a horizontally scrolled
1306 part to the left of the window. All x-values are relative to the
1307 start of this total display area. */
1308 if (base_face_id
!= DEFAULT_FACE_ID
)
1310 /* Mode lines, menu bar in terminal frames. */
1311 it
->first_visible_x
= 0;
1312 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1317 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1318 it
->last_visible_x
= (it
->first_visible_x
1319 + window_box_width (w
, TEXT_AREA
));
1321 /* If we truncate lines, leave room for the truncator glyph(s) at
1322 the right margin. Otherwise, leave room for the continuation
1323 glyph(s). Truncation and continuation glyphs are not inserted
1324 for window-based redisplay. */
1325 if (!FRAME_WINDOW_P (it
->f
))
1327 if (it
->truncate_lines_p
)
1328 it
->last_visible_x
-= it
->truncation_pixel_width
;
1330 it
->last_visible_x
-= it
->continuation_pixel_width
;
1333 it
->top_line_p
= WINDOW_WANTS_TOP_LINE_P (w
);
1334 it
->current_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
) + w
->vscroll
;
1337 /* Leave room for a border glyph. */
1338 if (!FRAME_WINDOW_P (it
->f
)
1339 && !WINDOW_RIGHTMOST_P (it
->w
))
1340 it
->last_visible_x
-= 1;
1342 it
->last_visible_y
= window_text_bottom_y (w
);
1344 /* For mode lines and alike, arrange for the first glyph having a
1345 left box line if the face specifies a box. */
1346 if (base_face_id
!= DEFAULT_FACE_ID
)
1350 it
->face_id
= base_face_id
;
1352 /* If we have a boxed mode line, make the first character appear
1353 with a left box line. */
1354 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1355 if (face
->box
!= FACE_NO_BOX
)
1356 it
->start_of_box_run_p
= 1;
1359 /* If a buffer position was specified, set the iterator there,
1360 getting overlays and face properties from that position. */
1363 it
->end_charpos
= ZV
;
1365 IT_CHARPOS (*it
) = charpos
;
1367 /* Compute byte position if not specified. */
1369 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1371 IT_BYTEPOS (*it
) = bytepos
;
1373 /* Compute faces etc. */
1374 reseat (it
, it
->current
.pos
, 1);
1381 /* Initialize IT for the display of window W with window start POS. */
1384 start_display (it
, w
, pos
)
1387 struct text_pos pos
;
1389 int start_at_line_beg_p
;
1390 struct glyph_row
*row
;
1391 int first_vpos
= WINDOW_WANTS_TOP_LINE_P (w
) ? 1 : 0;
1394 row
= w
->desired_matrix
->rows
+ first_vpos
;
1395 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1396 first_y
= it
->current_y
;
1398 /* If window start is not at a line start, move back to the line
1399 start. This makes sure that we take continuation lines into
1401 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1402 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1403 if (!start_at_line_beg_p
)
1404 reseat_at_previous_visible_line_start (it
);
1406 #if NO_PROMPT_IN_BUFFER
1407 /* Take the mini-buffer prompt width into account for tab
1409 if (MINI_WINDOW_P (w
) && IT_CHARPOS (*it
) == BEGV
)
1411 /* Why is mini-buffer_prompt_width guaranteed to be set here? */
1412 it
->prompt_width
= minibuf_prompt_pixel_width
;
1414 #endif /* NO_PROMPT_IN_BUFFER */
1416 /* If window start is not at a line start, skip forward to POS to
1417 get the correct continuation_lines_width and current_x. */
1418 if (!start_at_line_beg_p
)
1420 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1422 /* If lines are continued, this line may end in the middle of a
1423 multi-glyph character (e.g. a control character displayed as
1424 \003, or in the middle of an overlay string). In this case
1425 move_it_to above will not have taken us to the start of
1426 the continuation line but to the end of the continued line. */
1427 if (!it
->truncate_lines_p
&& it
->current_x
> 0)
1429 if (it
->current
.dpvec_index
>= 0
1430 || it
->current
.overlay_string_index
>= 0)
1432 set_iterator_to_next (it
);
1433 move_it_in_display_line_to (it
, -1, -1, 0);
1435 it
->continuation_lines_width
+= it
->current_x
;
1438 it
->current_y
= first_y
;
1440 it
->current_x
= it
->hpos
= 0;
1443 #if 0 /* Don't assert the following because start_display is sometimes
1444 called intentionally with a window start that is not at a
1445 line start. Please leave this code in as a comment. */
1447 /* Window start should be on a line start, now. */
1448 xassert (it
->continuation_lines_width
1449 || IT_CHARPOS (it
) == BEGV
1450 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1455 /* Initialize IT for stepping through current_buffer in window W,
1456 starting at position POS that includes overlay string and display
1457 vector/ control character translation position information. */
1460 init_from_display_pos (it
, w
, pos
)
1463 struct display_pos
*pos
;
1465 /* Keep in mind: the call to reseat in init_iterator skips invisible
1466 text, so we might end up at a position different from POS. This
1467 is only a problem when POS is a row start after a newline and an
1468 overlay starts there with an after-string, and the overlay has an
1469 invisible property. Since we don't skip invisible text in
1470 display_line and elsewhere immediately after consuming the
1471 newline before the row start, such a POS will not be in a string,
1472 but the call to init_iterator below will move us to the
1474 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1475 NULL
, DEFAULT_FACE_ID
);
1477 /* If position is within an overlay string, set up IT to
1478 the right overlay string. */
1479 if (pos
->overlay_string_index
>= 0)
1483 /* We already have the first chunk of overlay strings in
1484 IT->overlay_strings. Load more until the one for
1485 pos->overlay_string_index is in IT->overlay_strings. */
1486 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1488 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1489 it
->current
.overlay_string_index
= 0;
1492 load_overlay_strings (it
);
1493 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1497 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1498 relative_index
= (it
->current
.overlay_string_index
1499 % OVERLAY_STRING_CHUNK_SIZE
);
1500 it
->string
= it
->overlay_strings
[relative_index
];
1501 it
->current
.string_pos
= pos
->string_pos
;
1502 it
->method
= next_element_from_string
;
1504 else if (CHARPOS (pos
->string_pos
) >= 0)
1506 /* Recorded position is not in an overlay string, but in another
1507 string. This can only be a string from a `display' property.
1508 IT should already be filled with that string. */
1509 it
->current
.string_pos
= pos
->string_pos
;
1510 xassert (STRINGP (it
->string
));
1513 /* Restore position in display vector translations or control
1514 character translations. */
1515 if (pos
->dpvec_index
>= 0)
1517 /* This fills IT->dpvec. */
1518 get_next_display_element (it
);
1519 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1520 it
->current
.dpvec_index
= pos
->dpvec_index
;
1527 /* Initialize IT for stepping through current_buffer in window W
1528 starting at ROW->start. */
1531 init_to_row_start (it
, w
, row
)
1534 struct glyph_row
*row
;
1536 init_from_display_pos (it
, w
, &row
->start
);
1537 it
->continuation_lines_width
= row
->continuation_lines_width
;
1542 /* Initialize IT for stepping through current_buffer in window W
1543 starting in the line following ROW, i.e. starting at ROW->end. */
1546 init_to_row_end (it
, w
, row
)
1549 struct glyph_row
*row
;
1551 init_from_display_pos (it
, w
, &row
->end
);
1553 if (row
->continued_p
)
1554 it
->continuation_lines_width
= (row
->continuation_lines_width
1555 + row
->pixel_width
);
1562 /***********************************************************************
1564 ***********************************************************************/
1566 /* Called when IT reaches IT->stop_charpos. Handle text property and
1567 overlay changes. Set IT->stop_charpos to the next position where
1574 enum prop_handled handled
;
1575 int handle_overlay_change_p
= 1;
1579 it
->current
.dpvec_index
= -1;
1583 handled
= HANDLED_NORMALLY
;
1585 /* Call text property handlers. */
1586 for (p
= it_props
; p
->handler
; ++p
)
1588 handled
= p
->handler (it
);
1590 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1592 else if (handled
== HANDLED_RETURN
)
1594 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1595 handle_overlay_change_p
= 0;
1598 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1600 /* Don't check for overlay strings below when set to deliver
1601 characters from a display vector. */
1602 if (it
->method
== next_element_from_display_vector
)
1603 handle_overlay_change_p
= 0;
1605 /* Handle overlay changes. */
1606 if (handle_overlay_change_p
)
1607 handled
= handle_overlay_change (it
);
1609 /* Determine where to stop next. */
1610 if (handled
== HANDLED_NORMALLY
)
1611 compute_stop_pos (it
);
1614 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1618 /* Compute IT->stop_charpos from text property and overlay change
1619 information for IT's current position. */
1622 compute_stop_pos (it
)
1625 register INTERVAL iv
, next_iv
;
1626 Lisp_Object object
, limit
, position
;
1628 /* If nowhere else, stop at the end. */
1629 it
->stop_charpos
= it
->end_charpos
;
1631 if (STRINGP (it
->string
))
1633 /* Strings are usually short, so don't limit the search for
1635 object
= it
->string
;
1637 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1643 /* If next overlay change is in front of the current stop pos
1644 (which is IT->end_charpos), stop there. Note: value of
1645 next_overlay_change is point-max if no overlay change
1647 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1648 if (charpos
< it
->stop_charpos
)
1649 it
->stop_charpos
= charpos
;
1651 /* If showing the region, we have to stop at the region
1652 start or end because the face might change there. */
1653 if (it
->region_beg_charpos
> 0)
1655 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1656 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1657 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1658 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1661 /* Set up variables for computing the stop position from text
1662 property changes. */
1663 XSETBUFFER (object
, current_buffer
);
1664 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1665 XSETFASTINT (position
, IT_CHARPOS (*it
));
1669 /* Get the interval containing IT's position. Value is a null
1670 interval if there isn't such an interval. */
1671 iv
= validate_interval_range (object
, &position
, &position
, 0);
1672 if (!NULL_INTERVAL_P (iv
))
1674 Lisp_Object values_here
[LAST_PROP_IDX
];
1677 /* Get properties here. */
1678 for (p
= it_props
; p
->handler
; ++p
)
1679 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1681 /* Look for an interval following iv that has different
1683 for (next_iv
= next_interval (iv
);
1684 (!NULL_INTERVAL_P (next_iv
)
1686 || XFASTINT (limit
) > next_iv
->position
));
1687 next_iv
= next_interval (next_iv
))
1689 for (p
= it_props
; p
->handler
; ++p
)
1691 Lisp_Object new_value
;
1693 new_value
= textget (next_iv
->plist
, *p
->name
);
1694 if (!EQ (values_here
[p
->idx
], new_value
))
1702 if (!NULL_INTERVAL_P (next_iv
))
1704 if (INTEGERP (limit
)
1705 && next_iv
->position
>= XFASTINT (limit
))
1706 /* No text property change up to limit. */
1707 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1709 /* Text properties change in next_iv. */
1710 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1714 xassert (STRINGP (it
->string
)
1715 || (it
->stop_charpos
>= BEGV
1716 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1720 /* Return the position of the next overlay change after POS in
1721 current_buffer. Value is point-max if no overlay change
1722 follows. This is like `next-overlay-change' but doesn't use
1726 next_overlay_change (pos
)
1731 Lisp_Object
*overlays
;
1735 /* Get all overlays at the given position. */
1737 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1738 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1739 if (noverlays
> len
)
1742 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1743 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1746 /* If any of these overlays ends before endpos,
1747 use its ending point instead. */
1748 for (i
= 0; i
< noverlays
; ++i
)
1753 oend
= OVERLAY_END (overlays
[i
]);
1754 oendpos
= OVERLAY_POSITION (oend
);
1755 endpos
= min (endpos
, oendpos
);
1763 /***********************************************************************
1765 ***********************************************************************/
1767 /* Handle changes in the `fontified' property of the current buffer by
1768 calling hook functions from Qfontification_functions to fontify
1771 static enum prop_handled
1772 handle_fontified_prop (it
)
1775 Lisp_Object prop
, pos
;
1776 enum prop_handled handled
= HANDLED_NORMALLY
;
1778 /* Get the value of the `fontified' property at IT's current buffer
1779 position. (The `fontified' property doesn't have a special
1780 meaning in strings.) If the value is nil, call functions from
1781 Qfontification_functions. */
1782 if (!STRINGP (it
->string
)
1784 && !NILP (Vfontification_functions
)
1785 && (pos
= make_number (IT_CHARPOS (*it
)),
1786 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1789 Lisp_Object args
[2];
1791 /* Run the hook functions. */
1792 args
[0] = Qfontification_functions
;
1794 Frun_hook_with_args (make_number (2), args
);
1796 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
1797 something. This avoids an endless loop if they failed to
1798 fontify the text for which reason ever. */
1799 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
1800 handled
= HANDLED_RECOMPUTE_PROPS
;
1808 /***********************************************************************
1810 ***********************************************************************/
1812 /* Set up iterator IT from face properties at its current position.
1813 Called from handle_stop. */
1815 static enum prop_handled
1816 handle_face_prop (it
)
1819 int new_face_id
, next_stop
;
1821 if (!STRINGP (it
->string
))
1824 = face_at_buffer_position (it
->w
,
1826 it
->region_beg_charpos
,
1827 it
->region_end_charpos
,
1830 + TEXT_PROP_DISTANCE_LIMIT
),
1833 /* Is this a start of a run of characters with box face?
1834 Caveat: this can be called for a freshly initialized
1835 iterator; face_id is -1 is this case. We know that the new
1836 face will not change until limit, i.e. if the new face has a
1837 box, all characters up to limit will have one. But, as
1838 usual, we don't know whether limit is really the end. */
1839 if (new_face_id
!= it
->face_id
)
1841 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1843 /* If new face has a box but old face has not, this is
1844 the start of a run of characters with box, i.e. it has
1845 a shadow on the left side. The value of face_id of the
1846 iterator will be -1 if this is the initial call that gets
1847 the face. In this case, we have to look in front of IT's
1848 position and see whether there is a face != new_face_id. */
1849 it
->start_of_box_run_p
1850 = (new_face
->box
!= FACE_NO_BOX
1851 && (it
->face_id
>= 0
1852 || IT_CHARPOS (*it
) == BEG
1853 || new_face_id
!= face_before_it_pos (it
)));
1854 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1860 = face_at_string_position (it
->w
,
1862 IT_STRING_CHARPOS (*it
),
1863 (it
->current
.overlay_string_index
>= 0
1866 it
->region_beg_charpos
,
1867 it
->region_end_charpos
,
1871 #if 0 /* This shouldn't be neccessary. Let's check it. */
1872 /* If IT is used to display a mode line we would really like to
1873 use the mode line face instead of the frame's default face. */
1874 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
1875 && new_face_id
== DEFAULT_FACE_ID
)
1876 new_face_id
= MODE_LINE_FACE_ID
;
1879 /* Is this a start of a run of characters with box? Caveat:
1880 this can be called for a freshly allocated iterator; face_id
1881 is -1 is this case. We know that the new face will not
1882 change until the next check pos, i.e. if the new face has a
1883 box, all characters up to that position will have a
1884 box. But, as usual, we don't know whether that position
1885 is really the end. */
1886 if (new_face_id
!= it
->face_id
)
1888 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1889 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1891 /* If new face has a box but old face hasn't, this is the
1892 start of a run of characters with box, i.e. it has a
1893 shadow on the left side. */
1894 it
->start_of_box_run_p
1895 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
1896 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1900 it
->face_id
= new_face_id
;
1901 it
->charset
= CHARSET_ASCII
;
1902 return HANDLED_NORMALLY
;
1906 /* Compute the face one character before or after the current position
1907 of IT. BEFORE_P non-zero means get the face in front of IT's
1908 position. Value is the id of the face. */
1911 face_before_or_after_it_pos (it
, before_p
)
1916 int next_check_charpos
;
1917 struct text_pos pos
;
1919 xassert (it
->s
== NULL
);
1921 if (STRINGP (it
->string
))
1923 /* No face change past the end of the string (for the case
1924 we are padding with spaces). No face change before the
1926 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
1927 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
1930 /* Set pos to the position before or after IT's current position. */
1932 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
1934 pos
= string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
);
1936 /* Get the face for ASCII, or unibyte. */
1938 = face_at_string_position (it
->w
,
1941 (it
->current
.overlay_string_index
>= 0
1944 it
->region_beg_charpos
,
1945 it
->region_end_charpos
,
1946 &next_check_charpos
,
1949 /* Correct the face for charsets different from ASCII. Do it
1950 for the multibyte case only. The face returned above is
1951 suitable for unibyte text if IT->string is unibyte. */
1952 if (STRING_MULTIBYTE (it
->string
))
1954 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
1955 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
1956 int c
, len
, charset
;
1958 c
= STRING_CHAR_AND_LENGTH (p
, rest
, len
);
1959 charset
= CHAR_CHARSET (c
);
1960 if (charset
!= CHARSET_ASCII
)
1961 face_id
= FACE_FOR_CHARSET (it
->f
, face_id
, charset
);
1966 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
1967 pos
= it
->current
.pos
;
1974 /* Determine face for CHARSET_ASCII, or unibyte. */
1975 face_id
= face_at_buffer_position (it
->w
,
1977 it
->region_beg_charpos
,
1978 it
->region_end_charpos
,
1979 &next_check_charpos
,
1982 /* Correct the face for charsets different from ASCII. Do it
1983 for the multibyte case only. The face returned above is
1984 suitable for unibyte text if current_buffer is unibyte. */
1985 if (it
->multibyte_p
)
1987 int charset
= charset_at_position (pos
);
1988 if (charset
!= CHARSET_ASCII
)
1989 face_id
= FACE_FOR_CHARSET (it
->f
, face_id
, charset
);
1998 /***********************************************************************
2000 ***********************************************************************/
2002 /* Set up iterator IT from invisible properties at its current
2003 position. Called from handle_stop. */
2005 static enum prop_handled
2006 handle_invisible_prop (it
)
2009 enum prop_handled handled
= HANDLED_NORMALLY
;
2011 if (STRINGP (it
->string
))
2013 extern Lisp_Object Qinvisible
;
2014 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2016 /* Get the value of the invisible text property at the
2017 current position. Value will be nil if there is no such
2019 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2020 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2024 handled
= HANDLED_RECOMPUTE_PROPS
;
2026 /* Get the position at which the next change of the
2027 invisible text property can be found in IT->string.
2028 Value will be nil if the property value is the same for
2029 all the rest of IT->string. */
2030 XSETINT (limit
, XSTRING (it
->string
)->size
);
2031 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2034 /* Text at current position is invisible. The next
2035 change in the property is at position end_charpos.
2036 Move IT's current position to that position. */
2037 if (INTEGERP (end_charpos
)
2038 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2040 struct text_pos old
;
2041 old
= it
->current
.string_pos
;
2042 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2043 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2047 /* The rest of the string is invisible. If this is an
2048 overlay string, proceed with the next overlay string
2049 or whatever comes and return a character from there. */
2050 if (it
->current
.overlay_string_index
>= 0)
2052 next_overlay_string (it
);
2053 /* Don't check for overlay strings when we just
2054 finished processing them. */
2055 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2059 struct Lisp_String
*s
= XSTRING (it
->string
);
2060 IT_STRING_CHARPOS (*it
) = s
->size
;
2061 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2068 int visible_p
, newpos
, next_stop
;
2069 Lisp_Object pos
, prop
;
2071 /* First of all, is there invisible text at this position? */
2072 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2073 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2075 /* If we are on invisible text, skip over it. */
2076 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
2078 /* Record whether we have to display an ellipsis for the
2080 int display_ellipsis_p
2081 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2083 handled
= HANDLED_RECOMPUTE_PROPS
;
2085 /* Loop skipping over invisible text. The loop is left at
2086 ZV or with IT on the first char being visible again. */
2089 /* Try to skip some invisible text. Return value is the
2090 position reached which can be equal to IT's position
2091 if there is nothing invisible here. This skips both
2092 over invisible text properties and overlays with
2093 invisible property. */
2094 newpos
= skip_invisible (IT_CHARPOS (*it
),
2095 &next_stop
, ZV
, it
->window
);
2097 /* If we skipped nothing at all we weren't at invisible
2098 text in the first place. If everything to the end of
2099 the buffer was skipped, end the loop. */
2100 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2104 /* We skipped some characters but not necessarily
2105 all there are. Check if we ended up on visible
2106 text. Fget_char_property returns the property of
2107 the char before the given position, i.e. if we
2108 get visible_p = 1, this means that the char at
2109 newpos is visible. */
2110 XSETFASTINT (pos
, newpos
);
2111 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2112 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2115 /* If we ended up on invisible text, proceed to
2116 skip starting with next_stop. */
2118 IT_CHARPOS (*it
) = next_stop
;
2122 /* The position newpos is now either ZV or on visible text. */
2123 IT_CHARPOS (*it
) = newpos
;
2124 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2126 /* Maybe return `...' next for the end of the invisible text. */
2127 if (display_ellipsis_p
)
2130 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2132 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2133 it
->dpvec
= v
->contents
;
2134 it
->dpend
= v
->contents
+ v
->size
;
2138 /* Default `...'. */
2139 it
->dpvec
= default_invis_vector
;
2140 it
->dpend
= default_invis_vector
+ 3;
2143 /* The ellipsis display does not replace the display of
2144 the character at the new position. Indicate this by
2145 setting IT->dpvec_char_len to zero. */
2146 it
->dpvec_char_len
= 0;
2148 it
->current
.dpvec_index
= 0;
2149 it
->method
= next_element_from_display_vector
;
2159 /***********************************************************************
2161 ***********************************************************************/
2163 /* Set up iterator IT from `display' property at its current position.
2164 Called from handle_stop. */
2166 static enum prop_handled
2167 handle_display_prop (it
)
2170 Lisp_Object prop
, object
;
2171 struct text_pos
*position
;
2172 int space_or_image_found_p
;
2174 if (STRINGP (it
->string
))
2176 object
= it
->string
;
2177 position
= &it
->current
.string_pos
;
2182 position
= &it
->current
.pos
;
2185 /* Reset those iterator values set from display property values. */
2186 it
->font_height
= Qnil
;
2187 it
->space_width
= Qnil
;
2190 /* We don't support recursive `display' properties, i.e. string
2191 values that have a string `display' property, that have a string
2192 `display' property etc. */
2193 if (!it
->string_from_display_prop_p
)
2194 it
->area
= TEXT_AREA
;
2196 prop
= Fget_char_property (make_number (position
->charpos
),
2199 return HANDLED_NORMALLY
;
2201 space_or_image_found_p
= 0;
2202 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2204 while (CONSP (prop
))
2206 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2207 space_or_image_found_p
= 1;
2211 else if (VECTORP (prop
))
2214 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2215 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2217 space_or_image_found_p
= 1;
2221 if (handle_single_display_prop (it
, prop
, object
, position
))
2222 space_or_image_found_p
= 1;
2225 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2229 /* Value is the position of the end of the `display' property stating
2230 at START_POS in OBJECT. */
2232 static struct text_pos
2233 display_prop_end (it
, object
, start_pos
)
2236 struct text_pos start_pos
;
2239 struct text_pos end_pos
;
2241 /* Characters having this form of property are not displayed, so
2242 we have to find the end of the property. */
2243 end
= Fnext_single_property_change (make_number (start_pos
.charpos
),
2244 Qdisplay
, object
, Qnil
);
2247 /* A nil value of `end' means there are no changes of the
2248 property to the end of the buffer or string. */
2249 if (it
->current
.overlay_string_index
>= 0)
2250 end_pos
.charpos
= XSTRING (it
->string
)->size
;
2252 end_pos
.charpos
= it
->end_charpos
;
2255 end_pos
.charpos
= XFASTINT (end
);
2257 if (STRINGP (it
->string
))
2258 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2260 end_pos
.bytepos
= CHAR_TO_BYTE (end_pos
.charpos
);
2266 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2267 is the object in which the `display' property was found. *POSITION
2268 is the position at which it was found.
2270 If PROP is a `space' or `image' sub-property, set *POSITION to the
2271 end position of the `display' property.
2273 Value is non-zero if a `space' or `image' property value was found. */
2276 handle_single_display_prop (it
, prop
, object
, position
)
2280 struct text_pos
*position
;
2283 int space_or_image_found_p
= 0;
2287 /* If PROP is a list of the form `(:when FORM VALUE)', FORM is
2288 evaluated. If the result is nil, VALUE is ignored. */
2290 if (CONSP (prop
) && EQ (XCAR (prop
), QCwhen
))
2302 if (!NILP (form
) && !EQ (form
, Qt
))
2304 struct gcpro gcpro1
;
2305 struct text_pos end_pos
, pt
;
2307 end_pos
= display_prop_end (it
, object
, *position
);
2310 /* Temporarily set point to the end position, and then evaluate
2311 the form. This makes `(eolp)' work as FORM. */
2313 BYTEPOS (pt
) = PT_BYTE
;
2314 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2315 form
= eval_form (form
);
2316 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2324 && EQ (XCAR (prop
), Qheight
)
2325 && CONSP (XCDR (prop
)))
2327 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2330 /* `(height HEIGHT)'. */
2331 it
->font_height
= XCAR (XCDR (prop
));
2332 if (!NILP (it
->font_height
))
2334 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2335 int new_height
= -1;
2337 if (CONSP (it
->font_height
)
2338 && (EQ (XCAR (it
->font_height
), Qplus
)
2339 || EQ (XCAR (it
->font_height
), Qminus
))
2340 && CONSP (XCDR (it
->font_height
))
2341 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2343 /* `(+ N)' or `(- N)' where N is an integer. */
2344 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2345 if (EQ (XCAR (it
->font_height
), Qplus
))
2347 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2349 else if (SYMBOLP (it
->font_height
))
2351 /* Call function with current height as argument.
2352 Value is the new height. */
2353 Lisp_Object form
, height
;
2354 struct gcpro gcpro1
;
2356 height
= face
->lface
[LFACE_HEIGHT_INDEX
];
2357 form
= Fcons (it
->font_height
, Fcons (height
, Qnil
));
2359 height
= eval_form (form
);
2360 if (NUMBERP (height
))
2361 new_height
= XFLOATINT (height
);
2364 else if (NUMBERP (it
->font_height
))
2366 /* Value is a multiple of the canonical char height. */
2369 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2370 new_height
= (XFLOATINT (it
->font_height
)
2371 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2375 /* Evaluate IT->font_height with `height' bound to the
2376 current specified height to get the new height. */
2378 int count
= specpdl_ptr
- specpdl
;
2380 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2381 value
= eval_form (it
->font_height
);
2382 unbind_to (count
, Qnil
);
2384 if (NUMBERP (value
))
2385 new_height
= XFLOATINT (value
);
2389 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2392 else if (CONSP (prop
)
2393 && EQ (XCAR (prop
), Qspace_width
)
2394 && CONSP (XCDR (prop
)))
2396 /* `(space_width WIDTH)'. */
2397 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2400 value
= XCAR (XCDR (prop
));
2401 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2402 it
->space_width
= value
;
2404 else if (CONSP (prop
)
2405 && EQ (XCAR (prop
), Qraise
)
2406 && CONSP (XCDR (prop
)))
2408 #ifdef HAVE_WINDOW_SYSTEM
2409 /* `(raise FACTOR)'. */
2410 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2413 value
= XCAR (XCDR (prop
));
2414 if (NUMBERP (value
))
2416 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2417 it
->voffset
= - (XFLOATINT (value
)
2418 * (face
->font
->ascent
+ face
->font
->descent
));
2420 #endif /* HAVE_WINDOW_SYSTEM */
2422 else if (!it
->string_from_display_prop_p
)
2424 /* `(left-margin VALUE)' or `(right-margin VALUE)
2425 or `(nil VALUE)' or VALUE. */
2426 Lisp_Object location
, value
;
2427 struct text_pos start_pos
;
2430 /* Characters having this form of property are not displayed, so
2431 we have to find the end of the property. */
2432 space_or_image_found_p
= 1;
2433 start_pos
= *position
;
2434 *position
= display_prop_end (it
, object
, start_pos
);
2436 /* Let's stop at the new position and assume that all
2437 text properties change there. */
2438 it
->stop_charpos
= position
->charpos
;
2441 && !EQ (XCAR (prop
), Qspace
)
2442 && !EQ (XCAR (prop
), Qimage
))
2444 location
= XCAR (prop
);
2445 value
= XCDR (prop
);
2453 #ifdef HAVE_WINDOW_SYSTEM
2454 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2455 valid_p
= STRINGP (value
);
2457 valid_p
= (STRINGP (value
)
2458 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2459 || valid_image_p (value
));
2460 #else /* not HAVE_WINDOW_SYSTEM */
2461 valid_p
= STRINGP (value
);
2462 #endif /* not HAVE_WINDOW_SYSTEM */
2464 if ((EQ (location
, Qleft_margin
)
2465 || EQ (location
, Qright_margin
)
2469 /* Save current settings of IT so that we can restore them
2470 when we are finished with the glyph property value. */
2473 if (NILP (location
))
2474 it
->area
= TEXT_AREA
;
2475 else if (EQ (location
, Qleft_margin
))
2476 it
->area
= LEFT_MARGIN_AREA
;
2478 it
->area
= RIGHT_MARGIN_AREA
;
2480 if (STRINGP (value
))
2483 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2484 it
->current
.overlay_string_index
= -1;
2485 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2486 it
->end_charpos
= it
->string_nchars
2487 = XSTRING (it
->string
)->size
;
2488 it
->method
= next_element_from_string
;
2489 it
->stop_charpos
= 0;
2490 it
->string_from_display_prop_p
= 1;
2492 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2494 it
->method
= next_element_from_stretch
;
2496 it
->current
.pos
= it
->position
= start_pos
;
2498 #ifdef HAVE_WINDOW_SYSTEM
2501 it
->what
= IT_IMAGE
;
2502 it
->image_id
= lookup_image (it
->f
, value
);
2503 it
->position
= start_pos
;
2504 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2505 it
->method
= next_element_from_image
;
2507 /* Say that we don't have consumed the characters with
2508 `display' property yet. The call to pop_it in
2509 set_iterator_to_next will clean this up. */
2510 *position
= start_pos
;
2512 #endif /* HAVE_WINDOW_SYSTEM */
2516 return space_or_image_found_p
;
2521 /***********************************************************************
2523 ***********************************************************************/
2525 /* The following structure is used to record overlay strings for
2526 later sorting in load_overlay_strings. */
2528 struct overlay_entry
2536 /* Set up iterator IT from overlay strings at its current position.
2537 Called from handle_stop. */
2539 static enum prop_handled
2540 handle_overlay_change (it
)
2543 /* Overlays are handled in current_buffer only. */
2544 if (STRINGP (it
->string
))
2545 return HANDLED_NORMALLY
;
2547 return (get_overlay_strings (it
)
2548 ? HANDLED_RECOMPUTE_PROPS
2549 : HANDLED_NORMALLY
);
2553 /* Set up the next overlay string for delivery by IT, if there is an
2554 overlay string to deliver. Called by set_iterator_to_next when the
2555 end of the current overlay string is reached. If there are more
2556 overlay strings to display, IT->string and
2557 IT->current.overlay_string_index are set appropriately here.
2558 Otherwise IT->string is set to nil. */
2561 next_overlay_string (it
)
2564 ++it
->current
.overlay_string_index
;
2565 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2567 /* No more overlay strings. Restore IT's settings to what
2568 they were before overlay strings were processed, and
2569 continue to deliver from current_buffer. */
2571 xassert (it
->stop_charpos
>= BEGV
2572 && it
->stop_charpos
<= it
->end_charpos
);
2574 it
->current
.overlay_string_index
= -1;
2575 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2576 it
->n_overlay_strings
= 0;
2577 it
->method
= next_element_from_buffer
;
2581 /* There are more overlay strings to process. If
2582 IT->current.overlay_string_index has advanced to a position
2583 where we must load IT->overlay_strings with more strings, do
2585 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2587 if (it
->current
.overlay_string_index
&& i
== 0)
2588 load_overlay_strings (it
);
2590 /* Initialize IT to deliver display elements from the overlay
2592 it
->string
= it
->overlay_strings
[i
];
2593 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2594 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2595 it
->method
= next_element_from_string
;
2596 it
->stop_charpos
= 0;
2603 /* Compare two overlay_entry structures E1 and E2. Used as a
2604 comparison function for qsort in load_overlay_strings. Overlay
2605 strings for the same position are sorted so that
2607 1. All after-strings come in front of before-strings.
2609 2. Within after-strings, strings are sorted so that overlay strings
2610 from overlays with higher priorities come first.
2612 2. Within before-strings, strings are sorted so that overlay
2613 strings from overlays with higher priorities come last.
2615 Value is analogous to strcmp. */
2619 compare_overlay_entries (e1
, e2
)
2622 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
2623 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
2626 if (entry1
->after_string_p
!= entry2
->after_string_p
)
2627 /* Let after-strings appear in front of before-strings. */
2628 result
= entry1
->after_string_p
? -1 : 1;
2629 else if (entry1
->after_string_p
)
2630 /* After-strings sorted in order of decreasing priority. */
2631 result
= entry2
->priority
- entry1
->priority
;
2633 /* Before-strings sorted in order of increasing priority. */
2634 result
= entry1
->priority
- entry2
->priority
;
2640 /* Load the vector IT->overlay_strings with overlay strings from IT's
2641 current buffer position. Set IT->n_overlays to the total number of
2642 overlay strings found.
2644 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
2645 a time. On entry into load_overlay_strings,
2646 IT->current.overlay_string_index gives the number of overlay
2647 strings that have already been loaded by previous calls to this
2650 Overlay strings are sorted so that after-string strings come in
2651 front of before-string strings. Within before and after-strings,
2652 strings are sorted by overlay priority. See also function
2653 compare_overlay_entries. */
2656 load_overlay_strings (it
)
2659 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
2660 Lisp_Object ov
, overlay
, window
, str
;
2664 struct overlay_entry
*entries
2665 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
2667 /* Append the overlay string STRING of overlay OVERLAY to vector
2668 `entries' which has size `size' and currently contains `n'
2669 elements. AFTER_P non-zero means STRING is an after-string of
2671 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
2674 Lisp_Object priority; \
2678 int new_size = 2 * size; \
2679 struct overlay_entry *old = entries; \
2681 (struct overlay_entry *) alloca (new_size \
2682 * sizeof *entries); \
2683 bcopy (old, entries, size * sizeof *entries); \
2687 entries[n].string = (STRING); \
2688 priority = Foverlay_get ((OVERLAY), Qpriority); \
2689 entries[n].priority \
2690 = INTEGERP (priority) ? XFASTINT (priority) : 0; \
2691 entries[n].after_string_p = (AFTER_P); \
2696 /* Process overlay before the overlay center. */
2697 for (ov
= current_buffer
->overlays_before
;
2699 ov
= XCONS (ov
)->cdr
)
2701 overlay
= XCONS (ov
)->car
;
2702 xassert (OVERLAYP (overlay
));
2703 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2704 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2706 if (end
< IT_CHARPOS (*it
))
2709 /* Skip this overlay if it doesn't start or end at IT's current
2711 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2714 /* Skip this overlay if it doesn't apply to IT->w. */
2715 window
= Foverlay_get (overlay
, Qwindow
);
2716 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2719 /* If overlay has a non-empty before-string, record it. */
2720 if (start
== IT_CHARPOS (*it
)
2721 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2722 && XSTRING (str
)->size
)
2723 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2725 /* If overlay has a non-empty after-string, record it. */
2726 if (end
== IT_CHARPOS (*it
)
2727 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2728 && XSTRING (str
)->size
)
2729 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2732 /* Process overlays after the overlay center. */
2733 for (ov
= current_buffer
->overlays_after
;
2735 ov
= XCONS (ov
)->cdr
)
2737 overlay
= XCONS (ov
)->car
;
2738 xassert (OVERLAYP (overlay
));
2739 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2740 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2742 if (start
> IT_CHARPOS (*it
))
2745 /* Skip this overlay if it doesn't start or end at IT's current
2747 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2750 /* Skip this overlay if it doesn't apply to IT->w. */
2751 window
= Foverlay_get (overlay
, Qwindow
);
2752 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2755 /* If overlay has a non-empty before-string, record it. */
2756 if (start
== IT_CHARPOS (*it
)
2757 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2758 && XSTRING (str
)->size
)
2759 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2761 /* If overlay has a non-empty after-string, record it. */
2762 if (end
== IT_CHARPOS (*it
)
2763 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2764 && XSTRING (str
)->size
)
2765 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2768 #undef RECORD_OVERLAY_STRING
2771 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
2773 /* Record the total number of strings to process. */
2774 it
->n_overlay_strings
= n
;
2776 /* IT->current.overlay_string_index is the number of overlay strings
2777 that have already been consumed by IT. Copy some of the
2778 remaining overlay strings to IT->overlay_strings. */
2780 j
= it
->current
.overlay_string_index
;
2781 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
2782 it
->overlay_strings
[i
++] = entries
[j
++].string
;
2788 /* Get the first chunk of overlay strings at IT's current buffer
2789 position. Value is non-zero if at least one overlay string was
2793 get_overlay_strings (it
)
2796 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
2797 process. This fills IT->overlay_strings with strings, and sets
2798 IT->n_overlay_strings to the total number of strings to process.
2799 IT->pos.overlay_string_index has to be set temporarily to zero
2800 because load_overlay_strings needs this; it must be set to -1
2801 when no overlay strings are found because a zero value would
2802 indicate a position in the first overlay string. */
2803 it
->current
.overlay_string_index
= 0;
2804 load_overlay_strings (it
);
2806 /* If we found overlay strings, set up IT to deliver display
2807 elements from the first one. Otherwise set up IT to deliver
2808 from current_buffer. */
2809 if (it
->n_overlay_strings
)
2811 /* Make sure we know settings in current_buffer, so that we can
2812 restore meaningful values when we're done with the overlay
2814 compute_stop_pos (it
);
2815 xassert (it
->face_id
>= 0);
2817 /* Save IT's settings. They are restored after all overlay
2818 strings have been processed. */
2819 xassert (it
->sp
== 0);
2822 /* Set up IT to deliver display elements from the first overlay
2824 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2825 it
->stop_charpos
= 0;
2826 it
->string
= it
->overlay_strings
[0];
2827 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2828 xassert (STRINGP (it
->string
));
2829 it
->method
= next_element_from_string
;
2834 it
->current
.overlay_string_index
= -1;
2835 it
->method
= next_element_from_buffer
;
2840 /* Value is non-zero if we found at least one overlay string. */
2841 return STRINGP (it
->string
);
2846 /***********************************************************************
2847 Saving and restoring state
2848 ***********************************************************************/
2850 /* Save current settings of IT on IT->stack. Called, for example,
2851 before setting up IT for an overlay string, to be able to restore
2852 IT's settings to what they were after the overlay string has been
2859 struct iterator_stack_entry
*p
;
2861 xassert (it
->sp
< 2);
2862 p
= it
->stack
+ it
->sp
;
2864 p
->stop_charpos
= it
->stop_charpos
;
2865 xassert (it
->face_id
>= 0);
2866 p
->face_id
= it
->face_id
;
2867 p
->string
= it
->string
;
2868 p
->pos
= it
->current
;
2869 p
->end_charpos
= it
->end_charpos
;
2870 p
->string_nchars
= it
->string_nchars
;
2872 p
->multibyte_p
= it
->multibyte_p
;
2873 p
->space_width
= it
->space_width
;
2874 p
->font_height
= it
->font_height
;
2875 p
->voffset
= it
->voffset
;
2876 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
2881 /* Restore IT's settings from IT->stack. Called, for example, when no
2882 more overlay strings must be processed, and we return to delivering
2883 display elements from a buffer, or when the end of a string from a
2884 `display' property is reached and we return to delivering display
2885 elements from an overlay string, or from a buffer. */
2891 struct iterator_stack_entry
*p
;
2893 xassert (it
->sp
> 0);
2895 p
= it
->stack
+ it
->sp
;
2896 it
->stop_charpos
= p
->stop_charpos
;
2897 it
->face_id
= p
->face_id
;
2898 it
->string
= p
->string
;
2899 it
->current
= p
->pos
;
2900 it
->end_charpos
= p
->end_charpos
;
2901 it
->string_nchars
= p
->string_nchars
;
2903 it
->multibyte_p
= p
->multibyte_p
;
2904 it
->space_width
= p
->space_width
;
2905 it
->font_height
= p
->font_height
;
2906 it
->voffset
= p
->voffset
;
2907 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
2912 /***********************************************************************
2914 ***********************************************************************/
2916 /* Set IT's current position to the previous line start. */
2919 back_to_previous_line_start (it
)
2922 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
2923 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
2927 /* Set IT's current position to the next line start. */
2930 forward_to_next_line_start (it
)
2933 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), 1);
2934 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
2938 /* Set IT's current position to the previous visible line start. Skip
2939 invisible text that is so either due to text properties or due to
2940 selective display. Caution: this does not change IT->current_x and
2944 back_to_previous_visible_line_start (it
)
2949 /* Go back one newline if not on BEGV already. */
2950 if (IT_CHARPOS (*it
) > BEGV
)
2951 back_to_previous_line_start (it
);
2953 /* Move over lines that are invisible because of selective display
2954 or text properties. */
2955 while (IT_CHARPOS (*it
) > BEGV
2960 /* If selective > 0, then lines indented more than that values
2962 if (it
->selective
> 0
2963 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
2966 #ifdef USE_TEXT_PROPERTIES
2971 prop
= Fget_char_property (IT_CHARPOS (*it
), Qinvisible
, it
->window
);
2972 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
2975 #endif /* USE_TEXT_PROPERTIES */
2977 /* Back one more newline if the current one is invisible. */
2979 back_to_previous_line_start (it
);
2982 xassert (IT_CHARPOS (*it
) >= BEGV
);
2983 xassert (IT_CHARPOS (*it
) == BEGV
2984 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
2989 /* Reseat iterator IT at the previous visible line start. Skip
2990 invisible text that is so either due to text properties or due to
2991 selective display. At the end, update IT's overlay information,
2992 face information etc. */
2995 reseat_at_previous_visible_line_start (it
)
2998 back_to_previous_visible_line_start (it
);
2999 reseat (it
, it
->current
.pos
, 1);
3004 /* Reseat iterator IT on the next visible line start in the current
3005 buffer. Skip over invisible text that is so because of selective
3006 display. Compute faces, overlays etc at the new position. Note
3007 that this function does not skip over text that is invisible
3008 because of text properties. */
3011 reseat_at_next_visible_line_start (it
)
3014 /* Restore the buffer position when currently not delivering display
3015 elements from the current buffer. This is the case, for example,
3016 when called at the end of a truncated overlay string. */
3019 it
->method
= next_element_from_buffer
;
3021 /* Otherwise, scan_buffer would not work. */
3022 if (IT_CHARPOS (*it
) < ZV
)
3024 /* If on a newline, advance past it. Otherwise, find the next
3025 newline which automatically gives us the position following
3027 if (FETCH_BYTE (IT_BYTEPOS (*it
)) == '\n')
3033 forward_to_next_line_start (it
);
3035 /* We must either have reached the end of the buffer or end up
3037 xassert (IT_CHARPOS (*it
) == ZV
3038 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3040 /* Skip over lines that are invisible because they are indented
3041 more than the value of IT->selective. */
3042 if (it
->selective
> 0)
3043 while (IT_CHARPOS (*it
) < ZV
3044 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3046 forward_to_next_line_start (it
);
3048 /* Set the iterator there. The 0 as the last parameter of
3049 reseat means don't force a text property lookup. The lookup
3050 is then only done if we've skipped past the iterator's
3051 check_charpos'es. This optimization is important because
3052 text property lookups tend to be expensive. */
3053 reseat (it
, it
->current
.pos
, 0);
3061 /***********************************************************************
3062 Changing an iterator's position
3063 ***********************************************************************/
3065 /* Change IT's current position to POS in current_buffer. If FORCE_P
3066 is non-zero, always check for text properties at the new position.
3067 Otherwise, text properties are only looked up if POS >=
3068 IT->check_charpos of a property. */
3071 reseat (it
, pos
, force_p
)
3073 struct text_pos pos
;
3076 int original_pos
= IT_CHARPOS (*it
);
3078 reseat_1 (it
, pos
, 0);
3080 /* Determine where to check text properties. Avoid doing it
3081 where possible because text property lookup is very expensive. */
3083 || CHARPOS (pos
) > it
->stop_charpos
3084 || CHARPOS (pos
) < original_pos
)
3091 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3092 IT->stop_pos to POS, also. */
3095 reseat_1 (it
, pos
, set_stop_p
)
3097 struct text_pos pos
;
3100 /* Don't call this function when scanning a C string. */
3101 xassert (it
->s
== NULL
);
3103 /* POS must be a reasonable value. */
3104 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3106 it
->current
.pos
= it
->position
= pos
;
3107 XSETBUFFER (it
->object
, current_buffer
);
3109 it
->current
.dpvec_index
= -1;
3110 it
->current
.overlay_string_index
= -1;
3111 IT_STRING_CHARPOS (*it
) = -1;
3112 IT_STRING_BYTEPOS (*it
) = -1;
3114 it
->method
= next_element_from_buffer
;
3118 it
->stop_charpos
= CHARPOS (pos
);
3122 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3123 If S is non-null, it is a C string to iterate over. Otherwise,
3124 STRING gives a Lisp string to iterate over.
3126 If PRECISION > 0, don't return more then PRECISION number of
3127 characters from the string.
3129 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3130 characters have been returned. FIELD_WIDTH < 0 means an infinite
3133 MULTIBYTE = 0 means disable processing of multibyte characters,
3134 MULTIBYTE > 0 means enable it,
3135 MULTIBYTE < 0 means use IT->multibyte_p.
3137 IT must be initialized via a prior call to init_iterator before
3138 calling this function. */
3141 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3146 int precision
, field_width
, multibyte
;
3148 /* No region in strings. */
3149 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3151 /* No text property checks performed by default, but see below. */
3152 it
->stop_charpos
= -1;
3154 /* Set iterator position and end position. */
3155 bzero (&it
->current
, sizeof it
->current
);
3156 it
->current
.overlay_string_index
= -1;
3157 it
->current
.dpvec_index
= -1;
3158 it
->charset
= CHARSET_ASCII
;
3159 xassert (charpos
>= 0);
3161 /* Use the setting of MULTIBYTE if specified. */
3163 it
->multibyte_p
= multibyte
> 0;
3167 xassert (STRINGP (string
));
3168 it
->string
= string
;
3170 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3171 it
->method
= next_element_from_string
;
3172 it
->current
.string_pos
= string_pos (charpos
, string
);
3179 /* Note that we use IT->current.pos, not it->current.string_pos,
3180 for displaying C strings. */
3181 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3182 if (it
->multibyte_p
)
3184 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3185 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3189 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3190 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3193 it
->method
= next_element_from_c_string
;
3196 /* PRECISION > 0 means don't return more than PRECISION characters
3198 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3199 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3201 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3202 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3203 FIELD_WIDTH < 0 means infinite field width. This is useful for
3204 padding with `-' at the end of a mode line. */
3205 if (field_width
< 0)
3206 field_width
= INFINITY
;
3207 if (field_width
> it
->end_charpos
- charpos
)
3208 it
->end_charpos
= charpos
+ field_width
;
3210 /* Use the standard display table for displaying strings. */
3211 if (DISP_TABLE_P (Vstandard_display_table
))
3212 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3214 it
->stop_charpos
= charpos
;
3220 /***********************************************************************
3222 ***********************************************************************/
3224 /* Load IT's display element fields with information about the next
3225 display element from the current position of IT. Value is zero if
3226 end of buffer (or C string) is reached. */
3229 get_next_display_element (it
)
3232 /* Non-zero means that we found an display element. Zero means that
3233 we hit the end of what we iterate over. Performance note: the
3234 function pointer `method' used here turns out to be faster than
3235 using a sequence of if-statements. */
3236 int success_p
= (*it
->method
) (it
);
3239 if (it
->what
== IT_CHARACTER
)
3241 /* Map via display table or translate control characters.
3242 IT->c, IT->len etc. have been set to the next character by
3243 the function call above. If we have a display table, and it
3244 contains an entry for IT->c, translate it. Don't do this if
3245 IT->c itself comes from a display table, otherwise we could
3246 end up in an infinite recursion. (An alternative could be to
3247 count the recursion depth of this function and signal an
3248 error when a certain maximum depth is reached.) Is it worth
3250 if (success_p
&& it
->dpvec
== NULL
)
3255 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3258 struct Lisp_Vector
*v
= XVECTOR (dv
);
3260 /* Return the first character from the display table
3261 entry, if not empty. If empty, don't display the
3262 current character. */
3265 it
->dpvec_char_len
= it
->len
;
3266 it
->dpvec
= v
->contents
;
3267 it
->dpend
= v
->contents
+ v
->size
;
3268 it
->current
.dpvec_index
= 0;
3269 it
->method
= next_element_from_display_vector
;
3272 success_p
= get_next_display_element (it
);
3275 /* Translate control characters into `\003' or `^C' form.
3276 Control characters coming from a display table entry are
3277 currently not translated because we use IT->dpvec to hold
3278 the translation. This could easily be changed but I
3279 don't believe that it is worth doing. */
3280 else if ((it
->c
< ' '
3281 && (it
->area
!= TEXT_AREA
3288 /* IT->c is a control character which must be displayed
3289 either as '\003' or as `^C' where the '\\' and '^'
3290 can be defined in the display table. Fill
3291 IT->ctl_chars with glyphs for what we have to
3292 display. Then, set IT->dpvec to these glyphs. */
3295 if (it
->c
< 128 && it
->ctl_arrow_p
)
3297 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3299 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3300 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3301 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3303 g
= FAST_MAKE_GLYPH ('^', 0);
3304 XSETINT (it
->ctl_chars
[0], g
);
3306 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3307 XSETINT (it
->ctl_chars
[1], g
);
3309 /* Set up IT->dpvec and return first character from it. */
3310 it
->dpvec_char_len
= it
->len
;
3311 it
->dpvec
= it
->ctl_chars
;
3312 it
->dpend
= it
->dpvec
+ 2;
3313 it
->current
.dpvec_index
= 0;
3314 it
->method
= next_element_from_display_vector
;
3315 get_next_display_element (it
);
3319 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3321 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3322 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3323 g
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3325 g
= FAST_MAKE_GLYPH ('\\', 0);
3326 XSETINT (it
->ctl_chars
[0], g
);
3328 /* Insert three more glyphs into IT->ctl_chars for
3329 the octal display of the character. */
3330 g
= FAST_MAKE_GLYPH (((it
->c
>> 6) & 7) + '0', 0);
3331 XSETINT (it
->ctl_chars
[1], g
);
3332 g
= FAST_MAKE_GLYPH (((it
->c
>> 3) & 7) + '0', 0);
3333 XSETINT (it
->ctl_chars
[2], g
);
3334 g
= FAST_MAKE_GLYPH ((it
->c
& 7) + '0', 0);
3335 XSETINT (it
->ctl_chars
[3], g
);
3337 /* Set up IT->dpvec and return the first character
3339 it
->dpvec_char_len
= it
->len
;
3340 it
->dpvec
= it
->ctl_chars
;
3341 it
->dpend
= it
->dpvec
+ 4;
3342 it
->current
.dpvec_index
= 0;
3343 it
->method
= next_element_from_display_vector
;
3344 get_next_display_element (it
);
3349 /* Adjust face id if charset changes. There are no charset
3350 changes in unibyte text because Emacs' charsets are not
3351 applicable there. */
3354 && (charset
= CHAR_CHARSET (it
->c
),
3355 charset
!= it
->charset
))
3357 it
->charset
= charset
;
3358 it
->face_id
= FACE_FOR_CHARSET (it
->f
, it
->face_id
, charset
);
3362 /* Is this character the last one of a run of characters with
3363 box? If yes, set IT->end_of_box_run_p to 1. */
3370 it
->end_of_box_run_p
3371 = ((face_id
= face_after_it_pos (it
),
3372 face_id
!= it
->face_id
)
3373 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3374 face
->box
== FACE_NO_BOX
));
3377 /* Value is 0 if end of buffer or string reached. */
3382 /* Move IT to the next display element.
3384 Functions get_next_display_element and set_iterator_to_next are
3385 separate because I find this arrangement easier to handle than a
3386 get_next_display_element function that also increments IT's
3387 position. The way it is we can first look at an iterator's current
3388 display element, decide whether it fits on a line, and if it does,
3389 increment the iterator position. The other way around we probably
3390 would either need a flag indicating whether the iterator has to be
3391 incremented the next time, or we would have to implement a
3392 decrement position function which would not be easy to write. */
3395 set_iterator_to_next (it
)
3398 if (it
->method
== next_element_from_buffer
)
3400 /* The current display element of IT is a character from
3401 current_buffer. Advance in the buffer, and maybe skip over
3402 invisible lines that are so because of selective display. */
3403 if (ITERATOR_AT_END_OF_LINE_P (it
))
3404 reseat_at_next_visible_line_start (it
);
3407 xassert (it
->len
!= 0);
3408 IT_BYTEPOS (*it
) += it
->len
;
3409 IT_CHARPOS (*it
) += 1;
3410 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3413 else if (it
->method
== next_element_from_c_string
)
3415 /* Current display element of IT is from a C string. */
3416 IT_BYTEPOS (*it
) += it
->len
;
3417 IT_CHARPOS (*it
) += 1;
3419 else if (it
->method
== next_element_from_display_vector
)
3421 /* Current display element of IT is from a display table entry.
3422 Advance in the display table definition. Reset it to null if
3423 end reached, and continue with characters from buffers/
3425 ++it
->current
.dpvec_index
;
3426 it
->face_id
= it
->saved_face_id
;
3427 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3430 it
->method
= next_element_from_c_string
;
3431 else if (STRINGP (it
->string
))
3432 it
->method
= next_element_from_string
;
3434 it
->method
= next_element_from_buffer
;
3437 it
->current
.dpvec_index
= -1;
3439 /* Consume the character which was displayed via IT->dpvec. */
3440 if (it
->dpvec_char_len
)
3442 it
->len
= it
->dpvec_char_len
;
3443 set_iterator_to_next (it
);
3447 else if (it
->method
== next_element_from_string
)
3449 /* Current display element is a character from a Lisp string. */
3450 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3451 IT_STRING_BYTEPOS (*it
) += it
->len
;
3452 IT_STRING_CHARPOS (*it
) += 1;
3454 consider_string_end
:
3456 if (it
->current
.overlay_string_index
>= 0)
3458 /* IT->string is an overlay string. Advance to the
3459 next, if there is one. */
3460 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3461 next_overlay_string (it
);
3465 /* IT->string is not an overlay string. If we reached
3466 its end, and there is something on IT->stack, proceed
3467 with what is on the stack. This can be either another
3468 string, this time an overlay string, or a buffer. */
3469 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3473 if (!STRINGP (it
->string
))
3474 it
->method
= next_element_from_buffer
;
3478 else if (it
->method
== next_element_from_image
3479 || it
->method
== next_element_from_stretch
)
3481 /* The position etc with which we have to proceed are on
3482 the stack. The position may be at the end of a string,
3483 if the `display' property takes up the whole string. */
3486 if (STRINGP (it
->string
))
3488 it
->method
= next_element_from_string
;
3489 goto consider_string_end
;
3492 it
->method
= next_element_from_buffer
;
3495 /* There are no other methods defined, so this should be a bug. */
3498 /* Reset flags indicating start and end of a sequence of
3499 characters with box. */
3500 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3502 xassert (it
->method
!= next_element_from_string
3503 || (STRINGP (it
->string
)
3504 && IT_STRING_CHARPOS (*it
) >= 0));
3508 /* Load IT's display element fields with information about the next
3509 display element which comes from a display table entry or from the
3510 result of translating a control character to one of the forms `^C'
3511 or `\003'. IT->dpvec holds the glyphs to return as characters. */
3514 next_element_from_display_vector (it
)
3518 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
3520 /* Remember the current face id in case glyphs specify faces.
3521 IT's face is restored in set_iterator_to_next. */
3522 it
->saved_face_id
= it
->face_id
;
3524 if (INTEGERP (*it
->dpvec
)
3525 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
3530 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
3531 it
->c
= FAST_GLYPH_CHAR (g
);
3532 it
->len
= CHAR_LEN (it
->c
);
3534 /* The entry may contain a face id to use. Such a face id is
3535 the id of a Lisp face, not a realized face. A face id of
3536 zero means no face. */
3537 lface_id
= FAST_GLYPH_FACE (g
);
3540 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
3543 it
->face_id
= face_id
;
3544 it
->charset
= CHARSET_ASCII
;
3549 /* Display table entry is invalid. Return a space. */
3550 it
->c
= ' ', it
->len
= 1;
3552 /* Don't change position and object of the iterator here. They are
3553 still the values of the character that had this display table
3554 entry or was translated, and that's what we want. */
3555 it
->what
= IT_CHARACTER
;
3560 /* Load IT with the next display element from Lisp string IT->string.
3561 IT->current.string_pos is the current position within the string.
3562 If IT->current.overlay_string_index >= 0, the Lisp string is an
3566 next_element_from_string (it
)
3569 struct text_pos position
;
3571 xassert (STRINGP (it
->string
));
3572 xassert (IT_STRING_CHARPOS (*it
) >= 0);
3573 position
= it
->current
.string_pos
;
3575 /* Time to check for invisible text? */
3576 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
3577 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
3581 /* Since a handler may have changed IT->method, we must
3583 return get_next_display_element (it
);
3586 if (it
->current
.overlay_string_index
>= 0)
3588 /* Get the next character from an overlay string. In overlay
3589 strings, There is no field width or padding with spaces to
3591 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3596 else if (STRING_MULTIBYTE (it
->string
))
3598 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
3599 - IT_STRING_BYTEPOS (*it
));
3600 unsigned char *s
= (XSTRING (it
->string
)->data
3601 + IT_STRING_BYTEPOS (*it
));
3602 it
->c
= STRING_CHAR_AND_LENGTH (s
, remaining
, it
->len
);
3606 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3612 /* Get the next character from a Lisp string that is not an
3613 overlay string. Such strings come from the mode line, for
3614 example. We may have to pad with spaces, or truncate the
3615 string. See also next_element_from_c_string. */
3616 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
3621 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
3623 /* Pad with spaces. */
3624 it
->c
= ' ', it
->len
= 1;
3625 CHARPOS (position
) = BYTEPOS (position
) = -1;
3627 else if (STRING_MULTIBYTE (it
->string
))
3629 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
3630 - IT_STRING_BYTEPOS (*it
));
3631 unsigned char *s
= (XSTRING (it
->string
)->data
3632 + IT_STRING_BYTEPOS (*it
));
3633 it
->c
= STRING_CHAR_AND_LENGTH (s
, maxlen
, it
->len
);
3637 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3642 /* Record what we have and where it came from. Note that we store a
3643 buffer position in IT->position although it could arguably be a
3645 it
->what
= IT_CHARACTER
;
3646 it
->object
= it
->string
;
3647 it
->position
= position
;
3652 /* Load IT with next display element from C string IT->s.
3653 IT->string_nchars is the maximum number of characters to return
3654 from the string. IT->end_charpos may be greater than
3655 IT->string_nchars when this function is called, in which case we
3656 may have to return padding spaces. Value is zero if end of string
3657 reached, including padding spaces. */
3660 next_element_from_c_string (it
)
3666 it
->what
= IT_CHARACTER
;
3667 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
3670 /* IT's position can be greater IT->string_nchars in case a field
3671 width or precision has been specified when the iterator was
3673 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3675 /* End of the game. */
3679 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
3681 /* Pad with spaces. */
3682 it
->c
= ' ', it
->len
= 1;
3683 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
3685 else if (it
->multibyte_p
)
3687 /* Implementation note: The calls to strlen apparently aren't a
3688 performance problem because there is no noticeable performance
3689 difference between Emacs running in unibyte or multibyte mode. */
3690 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
3691 it
->c
= STRING_CHAR_AND_LENGTH (it
->s
+ IT_BYTEPOS (*it
),
3695 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
3701 /* Set up IT to return characters from an ellipsis, if appropriate.
3702 The definition of the ellipsis glyphs may come from a display table
3703 entry. This function Fills IT with the first glyph from the
3704 ellipsis if an ellipsis is to be displayed. */
3707 next_element_from_ellipsis (it
)
3710 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3712 /* Use the display table definition for `...'. Invalid glyphs
3713 will be handled by the method returning elements from dpvec. */
3714 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3715 it
->dpvec_char_len
= it
->len
;
3716 it
->dpvec
= v
->contents
;
3717 it
->dpend
= v
->contents
+ v
->size
;
3718 it
->current
.dpvec_index
= 0;
3719 it
->method
= next_element_from_display_vector
;
3720 get_next_display_element (it
);
3722 else if (it
->selective_display_ellipsis_p
)
3724 /* Use default `...' which is stored in default_invis_vector. */
3725 it
->dpvec_char_len
= it
->len
;
3726 it
->dpvec
= default_invis_vector
;
3727 it
->dpend
= default_invis_vector
+ 3;
3728 it
->current
.dpvec_index
= 0;
3729 it
->method
= next_element_from_display_vector
;
3730 get_next_display_element (it
);
3735 /* Deliver an image display element. The iterator IT is already
3736 filled with image information (done in handle_display_prop). Value
3741 next_element_from_image (it
)
3744 it
->what
= IT_IMAGE
;
3749 /* Fill iterator IT with next display element from a stretch glyph
3750 property. IT->object is the value of the text property. Value is
3754 next_element_from_stretch (it
)
3757 it
->what
= IT_STRETCH
;
3762 /* Load IT with the next display element from current_buffer. Value
3763 is zero if end of buffer reached. IT->stop_charpos is the next
3764 position at which to stop and check for text properties or buffer
3768 next_element_from_buffer (it
)
3773 /* Check this assumption, otherwise, we would never enter the
3774 if-statement, below. */
3775 xassert (IT_CHARPOS (*it
) >= BEGV
3776 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
3778 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
3780 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3782 int overlay_strings_follow_p
;
3784 /* End of the game, except when overlay strings follow that
3785 haven't been returned yet. */
3786 if (it
->overlay_strings_at_end_processed_p
)
3787 overlay_strings_follow_p
= 0;
3790 it
->overlay_strings_at_end_processed_p
= 1;
3791 overlay_strings_follow_p
3792 = get_overlay_strings (it
);
3795 if (overlay_strings_follow_p
)
3796 success_p
= get_next_display_element (it
);
3800 it
->position
= it
->current
.pos
;
3807 return get_next_display_element (it
);
3812 /* No face changes, overlays etc. in sight, so just return a
3813 character from current_buffer. */
3816 /* Maybe run the redisplay end trigger hook. Performance note:
3817 This doesn't seem to cost measurable time. */
3818 if (it
->redisplay_end_trigger_charpos
3820 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
3821 run_redisplay_end_trigger_hook (it
);
3823 /* Get the next character, maybe multibyte. */
3824 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
3825 if (it
->multibyte_p
)
3827 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
3828 - IT_BYTEPOS (*it
));
3829 it
->c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it
->len
);
3832 it
->c
= *p
, it
->len
= 1;
3834 /* Record what we have and where it came from. */
3835 it
->what
= IT_CHARACTER
;;
3836 it
->object
= it
->w
->buffer
;
3837 it
->position
= it
->current
.pos
;
3839 /* Normally we return the character found above, except when we
3840 really want to return an ellipsis for selective display. */
3845 /* A value of selective > 0 means hide lines indented more
3846 than that number of columns. */
3847 if (it
->selective
> 0
3848 && IT_CHARPOS (*it
) + 1 < ZV
3849 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
3850 IT_BYTEPOS (*it
) + 1,
3852 next_element_from_ellipsis (it
);
3854 else if (it
->c
== '\r' && it
->selective
== -1)
3856 /* A value of selective == -1 means that everything from the
3857 CR to the end of the line is invisible, with maybe an
3858 ellipsis displayed for it. */
3859 next_element_from_ellipsis (it
);
3864 /* Value is zero if end of buffer reached. */
3865 xassert (!success_p
|| it
->len
> 0);
3870 /* Run the redisplay end trigger hook for IT. */
3873 run_redisplay_end_trigger_hook (it
)
3876 Lisp_Object args
[3];
3878 /* IT->glyph_row should be non-null, i.e. we should be actually
3879 displaying something, or otherwise we should not run the hook. */
3880 xassert (it
->glyph_row
);
3882 /* Set up hook arguments. */
3883 args
[0] = Qredisplay_end_trigger_functions
;
3884 args
[1] = it
->window
;
3885 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
3886 it
->redisplay_end_trigger_charpos
= 0;
3888 /* Since we are *trying* to run these functions, don't try to run
3889 them again, even if they get an error. */
3890 it
->w
->redisplay_end_trigger
= Qnil
;
3891 Frun_hook_with_args (3, args
);
3893 /* Notice if it changed the face of the character we are on. */
3894 handle_face_prop (it
);
3899 /***********************************************************************
3900 Moving an iterator without producing glyphs
3901 ***********************************************************************/
3903 /* Move iterator IT to a specified buffer or X position within one
3904 line on the display without producing glyphs.
3906 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
3907 whichever is reached first.
3909 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
3911 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
3912 0 <= TO_X <= IT->last_visible_x. This means in particular, that
3913 TO_X includes the amount by which a window is horizontally
3918 MOVE_POS_MATCH_OR_ZV
3919 - when TO_POS or ZV was reached.
3922 -when TO_X was reached before TO_POS or ZV were reached.
3925 - when we reached the end of the display area and the line must
3929 - when we reached the end of the display area and the line is
3933 - when we stopped at a line end, i.e. a newline or a CR and selective
3937 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
3939 int to_charpos
, to_x
, op
;
3941 enum move_it_result result
= MOVE_UNDEFINED
;
3942 struct glyph_row
*saved_glyph_row
;
3944 /* Don't produce glyphs in produce_glyphs. */
3945 saved_glyph_row
= it
->glyph_row
;
3946 it
->glyph_row
= NULL
;
3948 #if NO_PROMPT_IN_BUFFER
3949 /* Take a mini-buffer prompt into account. */
3950 if (MINI_WINDOW_P (it
->w
)
3951 && IT_CHARPOS (*it
) == BEGV
)
3953 it
->current_x
= minibuf_prompt_pixel_width
;
3954 it
->hpos
= minibuf_prompt_width
;
3962 /* Stop when ZV or TO_CHARPOS reached. */
3963 if (!get_next_display_element (it
)
3964 || ((op
& MOVE_TO_POS
) != 0
3965 && BUFFERP (it
->object
)
3966 && IT_CHARPOS (*it
) >= to_charpos
))
3968 result
= MOVE_POS_MATCH_OR_ZV
;
3972 /* The call to produce_glyphs will get the metrics of the
3973 display element IT is loaded with. We record in x the
3974 x-position before this display element in case it does not
3977 PRODUCE_GLYPHS (it
);
3979 if (it
->area
!= TEXT_AREA
)
3981 set_iterator_to_next (it
);
3985 /* The number of glyphs we get back in IT->nglyphs will normally
3986 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
3987 character on a terminal frame, or (iii) a line end. For the
3988 second case, IT->nglyphs - 1 padding glyphs will be present
3989 (on X frames, there is only one glyph produced for a
3990 composite character.
3992 The behavior implemented below means, for continuation lines,
3993 that as many spaces of a TAB as fit on the current line are
3994 displayed there. For terminal frames, as many glyphs of a
3995 multi-glyph character are displayed in the current line, too.
3996 This is what the old redisplay code did, and we keep it that
3997 way. Under X, the whole shape of a complex character must
3998 fit on the line or it will be completely displayed in the
4001 Note that both for tabs and padding glyphs, all glyphs have
4005 /* More than one glyph or glyph doesn't fit on line. All
4006 glyphs have the same width. */
4007 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4010 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4012 new_x
= x
+ single_glyph_width
;
4014 /* We want to leave anything reaching TO_X to the caller. */
4015 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4018 result
= MOVE_X_REACHED
;
4021 else if (/* Lines are continued. */
4022 !it
->truncate_lines_p
4023 && (/* And glyph doesn't fit on the line. */
4024 new_x
> it
->last_visible_x
4025 /* Or it fits exactly and we're on a window
4027 || (new_x
== it
->last_visible_x
4028 && FRAME_WINDOW_P (it
->f
))))
4030 if (/* IT->hpos == 0 means the very first glyph
4031 doesn't fit on the line, e.g. a wide image. */
4033 || (new_x
== it
->last_visible_x
4034 && FRAME_WINDOW_P (it
->f
)))
4037 it
->current_x
= new_x
;
4038 if (i
== it
->nglyphs
- 1)
4039 set_iterator_to_next (it
);
4044 result
= MOVE_LINE_CONTINUED
;
4047 else if (new_x
> it
->first_visible_x
)
4049 /* Glyph is visible. Increment number of glyphs that
4050 would be displayed. */
4055 /* Glyph is completely off the left margin of the display
4056 area. Nothing to do. */
4060 if (result
!= MOVE_UNDEFINED
)
4063 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4065 /* Stop when TO_X specified and reached. This check is
4066 necessary here because of lines consisting of a line end,
4067 only. The line end will not produce any glyphs and we
4068 would never get MOVE_X_REACHED. */
4069 xassert (it
->nglyphs
== 0);
4070 result
= MOVE_X_REACHED
;
4074 /* Is this a line end? If yes, we're done. */
4075 if (ITERATOR_AT_END_OF_LINE_P (it
))
4077 result
= MOVE_NEWLINE_OR_CR
;
4081 /* The current display element has been consumed. Advance
4083 set_iterator_to_next (it
);
4085 /* Stop if lines are truncated and IT's current x-position is
4086 past the right edge of the window now. */
4087 if (it
->truncate_lines_p
4088 && it
->current_x
>= it
->last_visible_x
)
4090 result
= MOVE_LINE_TRUNCATED
;
4095 /* Restore the iterator settings altered at the beginning of this
4097 it
->glyph_row
= saved_glyph_row
;
4102 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4103 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4104 the description of enum move_operation_enum.
4106 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4107 screen line, this function will set IT to the next position >
4111 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4113 int to_charpos
, to_x
, to_y
, to_vpos
;
4116 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4119 xassert (XBUFFER (it
->w
->buffer
) == current_buffer
);
4123 if (op
& MOVE_TO_VPOS
)
4125 /* If no TO_CHARPOS and no TO_X specified, stop at the
4126 start of the line TO_VPOS. */
4127 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4129 if (it
->vpos
== to_vpos
)
4131 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4135 /* TO_VPOS >= 0 means stop at TO_X in the line at
4136 TO_VPOS, or at TO_POS, whichever comes first. */
4137 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4139 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4141 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4143 /* We have reached TO_X but not in the line we want. */
4144 skip
= move_it_in_display_line_to (it
, to_charpos
,
4146 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4151 else if (op
& MOVE_TO_Y
)
4153 struct it it_backup
;
4156 /* TO_Y specified means stop at TO_X in the line containing
4157 TO_Y---or at TO_CHARPOS if this is reached first. The
4158 problem is that we can't really tell whether the line
4159 contains TO_Y before we have completely scanned it, and
4160 this may skip past TO_X. What we do is to first scan to
4163 If TO_X is not specified, use a TO_X of zero. The reason
4164 is to make the outcome of this function more predictable.
4165 If we didn't use TO_X == 0, we would stop at the end of
4166 the line which is probably not what a caller would expect
4168 skip
= move_it_in_display_line_to (it
, to_charpos
,
4172 | (op
& MOVE_TO_POS
)));
4174 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4175 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4178 /* If TO_X was reached, we would like to know whether TO_Y
4179 is in the line. This can only be said if we know the
4180 total line height which requires us to scan the rest of
4183 if (skip
== MOVE_X_REACHED
)
4186 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4190 /* Now, decide whether TO_Y is in this line. */
4191 line_height
= it
->max_ascent
+ it
->max_descent
;
4193 if (to_y
>= it
->current_y
4194 && to_y
< it
->current_y
+ line_height
)
4196 if (skip
== MOVE_X_REACHED
)
4197 /* If TO_Y is in this line and TO_X was reached above,
4198 we scanned too far. We have to restore IT's settings
4199 to the ones before skipping. */
4203 else if (skip
== MOVE_X_REACHED
)
4206 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4214 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4218 case MOVE_POS_MATCH_OR_ZV
:
4221 case MOVE_NEWLINE_OR_CR
:
4222 set_iterator_to_next (it
);
4223 it
->continuation_lines_width
= 0;
4226 case MOVE_LINE_TRUNCATED
:
4227 it
->continuation_lines_width
= 0;
4228 reseat_at_next_visible_line_start (it
);
4229 if ((op
& MOVE_TO_POS
) != 0
4230 && IT_CHARPOS (*it
) > to_charpos
)
4234 case MOVE_LINE_CONTINUED
:
4235 it
->continuation_lines_width
+= it
->current_x
;
4242 /* Reset/increment for the next run. */
4243 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4244 it
->current_x
= it
->hpos
= 0;
4245 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4247 last_height
= it
->max_ascent
+ it
->max_descent
;
4248 last_max_ascent
= it
->max_ascent
;
4249 it
->max_ascent
= it
->max_descent
= 0;
4255 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4257 If DY > 0, move IT backward at least that many pixels. DY = 0
4258 means move IT backward to the preceding line start or BEGV. This
4259 function may move over more than DY pixels if IT->current_y - DY
4260 ends up in the middle of a line; in this case IT->current_y will be
4261 set to the top of the line moved to. */
4264 move_it_vertically_backward (it
, dy
)
4268 int nlines
, h
, line_height
;
4270 int start_pos
= IT_CHARPOS (*it
);
4274 /* Estimate how many newlines we must move back. */
4275 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4277 /* Set the iterator's position that many lines back. */
4278 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4279 back_to_previous_visible_line_start (it
);
4281 /* Reseat the iterator here. When moving backward, we don't want
4282 reseat to skip forward over invisible text, set up the iterator
4283 to deliver from overlay strings at the new position etc. So,
4284 use reseat_1 here. */
4285 reseat_1 (it
, it
->current
.pos
, 1);
4287 /* We are now surely at a line start. */
4288 it
->current_x
= it
->hpos
= 0;
4290 /* Move forward and see what y-distance we moved. First move to the
4291 start of the next line so that we get its height. We need this
4292 height to be able to tell whether we reached the specified
4295 it2
.max_ascent
= it2
.max_descent
= 0;
4296 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4297 MOVE_TO_POS
| MOVE_TO_VPOS
);
4298 xassert (IT_CHARPOS (*it
) >= BEGV
);
4299 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4300 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4301 xassert (IT_CHARPOS (*it
) >= BEGV
);
4302 h
= it2
.current_y
- it
->current_y
;
4303 nlines
= it2
.vpos
- it
->vpos
;
4305 /* Correct IT's y and vpos position. */
4311 /* DY == 0 means move to the start of the screen line. The
4312 value of nlines is > 0 if continuation lines were involved. */
4314 move_it_by_lines (it
, nlines
, 1);
4315 xassert (IT_CHARPOS (*it
) <= start_pos
);
4319 /* The y-position we try to reach. Note that h has been
4320 subtracted in front of the if-statement. */
4321 int target_y
= it
->current_y
+ h
- dy
;
4323 /* If we did not reach target_y, try to move further backward if
4324 we can. If we moved too far backward, try to move forward. */
4325 if (target_y
< it
->current_y
4326 && IT_CHARPOS (*it
) > BEGV
)
4328 move_it_vertically (it
, target_y
- it
->current_y
);
4329 xassert (IT_CHARPOS (*it
) >= BEGV
);
4331 else if (target_y
>= it
->current_y
+ line_height
4332 && IT_CHARPOS (*it
) < ZV
)
4334 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4335 xassert (IT_CHARPOS (*it
) >= BEGV
);
4341 /* Move IT by a specified amount of pixel lines DY. DY negative means
4342 move backwards. DY = 0 means move to start of screen line. At the
4343 end, IT will be on the start of a screen line. */
4346 move_it_vertically (it
, dy
)
4351 move_it_vertically_backward (it
, -dy
);
4354 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4355 MOVE_TO_POS
| MOVE_TO_Y
);
4357 /* If buffer ends in ZV without a newline, move to the start of
4358 the line to satisfy the post-condition. */
4359 if (IT_CHARPOS (*it
) == ZV
4360 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4361 move_it_by_lines (it
, 0, 0);
4366 /* Return non-zero if some text between buffer positions START_CHARPOS
4367 and END_CHARPOS is invisible. IT->window is the window for text
4371 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4373 int start_charpos
, end_charpos
;
4375 #ifdef USE_TEXT_PROPERTIES
4376 Lisp_Object prop
, limit
;
4377 int invisible_found_p
;
4379 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4381 /* Is text at START invisible? */
4382 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4384 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4385 invisible_found_p
= 1;
4388 limit
= Fnext_single_property_change (make_number (start_charpos
),
4391 make_number (end_charpos
));
4392 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4395 return invisible_found_p
;
4397 #else /* not USE_TEXT_PROPERTIES */
4399 #endif /* not USE_TEXT_PROPERTIES */
4403 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4404 negative means move up. DVPOS == 0 means move to the start of the
4405 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4406 NEED_Y_P is zero, IT->current_y will be left unchanged.
4408 Further optimization ideas: If we would know that IT->f doesn't use
4409 a face with proportional font, we could be faster for
4410 truncate-lines nil. */
4413 move_it_by_lines (it
, dvpos
, need_y_p
)
4415 int dvpos
, need_y_p
;
4417 struct position pos
;
4419 if (!FRAME_WINDOW_P (it
->f
))
4421 struct text_pos textpos
;
4423 /* We can use vmotion on frames without proportional fonts. */
4424 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4425 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4426 reseat (it
, textpos
, 1);
4427 it
->vpos
+= pos
.vpos
;
4428 it
->current_y
+= pos
.vpos
;
4430 else if (dvpos
== 0)
4432 /* DVPOS == 0 means move to the start of the screen line. */
4433 move_it_vertically_backward (it
, 0);
4434 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4438 /* If there are no continuation lines, and if there is no
4439 selective display, try the simple method of moving forward
4440 DVPOS newlines, then see where we are. */
4441 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4443 int shortage
= 0, charpos
;
4445 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
4446 charpos
= IT_CHARPOS (*it
) + 1;
4448 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
4451 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
4453 struct text_pos pos
;
4454 CHARPOS (pos
) = charpos
;
4455 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4456 reseat (it
, pos
, 1);
4457 it
->vpos
+= dvpos
- shortage
;
4458 it
->hpos
= it
->current_x
= 0;
4463 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
4468 int start_charpos
, i
;
4470 /* If there are no continuation lines, and if there is no
4471 selective display, try the simple method of moving backward
4473 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4476 int charpos
= IT_CHARPOS (*it
);
4477 int bytepos
= IT_BYTEPOS (*it
);
4479 /* If in the middle of a line, go to its start. */
4480 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
4482 charpos
= find_next_newline_no_quit (charpos
, -1);
4483 bytepos
= CHAR_TO_BYTE (charpos
);
4486 if (charpos
== BEGV
)
4488 struct text_pos pos
;
4489 CHARPOS (pos
) = charpos
;
4490 BYTEPOS (pos
) = bytepos
;
4491 reseat (it
, pos
, 1);
4492 it
->hpos
= it
->current_x
= 0;
4497 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
4498 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
4500 struct text_pos pos
;
4501 CHARPOS (pos
) = charpos
;
4502 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4503 reseat (it
, pos
, 1);
4504 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
4505 it
->hpos
= it
->current_x
= 0;
4511 /* Go back -DVPOS visible lines and reseat the iterator there. */
4512 start_charpos
= IT_CHARPOS (*it
);
4513 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
4514 back_to_previous_visible_line_start (it
);
4515 reseat (it
, it
->current
.pos
, 1);
4516 it
->current_x
= it
->hpos
= 0;
4518 /* Above call may have moved too far if continuation lines
4519 are involved. Scan forward and see if it did. */
4521 it2
.vpos
= it2
.current_y
= 0;
4522 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
4523 it
->vpos
-= it2
.vpos
;
4524 it
->current_y
-= it2
.current_y
;
4525 it
->current_x
= it
->hpos
= 0;
4527 /* If we moved too far, move IT some lines forward. */
4528 if (it2
.vpos
> -dvpos
)
4530 int delta
= it2
.vpos
+ dvpos
;
4531 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
4538 /***********************************************************************
4540 ***********************************************************************/
4543 /* Output a newline in the *Messages* buffer if "needs" one. */
4546 message_log_maybe_newline ()
4548 if (message_log_need_newline
)
4549 message_dolog ("", 0, 1, 0);
4553 /* Add a string M of length LEN to the message log, optionally
4554 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
4555 nonzero, means interpret the contents of M as multibyte. This
4556 function calls low-level routines in order to bypass text property
4557 hooks, etc. which might not be safe to run. */
4560 message_dolog (m
, len
, nlflag
, multibyte
)
4562 int len
, nlflag
, multibyte
;
4564 if (!NILP (Vmessage_log_max
))
4566 struct buffer
*oldbuf
;
4567 Lisp_Object oldpoint
, oldbegv
, oldzv
;
4568 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4569 int point_at_end
= 0;
4571 Lisp_Object old_deactivate_mark
, tem
;
4572 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4574 old_deactivate_mark
= Vdeactivate_mark
;
4575 oldbuf
= current_buffer
;
4576 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
4577 current_buffer
->undo_list
= Qt
;
4579 oldpoint
= Fpoint_marker ();
4580 oldbegv
= Fpoint_min_marker ();
4581 oldzv
= Fpoint_max_marker ();
4582 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
4590 BEGV_BYTE
= BEG_BYTE
;
4593 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4595 /* Insert the string--maybe converting multibyte to single byte
4596 or vice versa, so that all the text fits the buffer. */
4598 && NILP (current_buffer
->enable_multibyte_characters
))
4601 unsigned char work
[1];
4603 /* Convert a multibyte string to single-byte
4604 for the *Message* buffer. */
4605 for (i
= 0; i
< len
; i
+= nbytes
)
4607 c
= STRING_CHAR_AND_LENGTH (m
+ i
, len
- i
, nbytes
);
4608 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
4610 : multibyte_char_to_unibyte (c
, Qnil
));
4611 insert_1_both (work
, 1, 1, 1, 0, 0);
4614 else if (! multibyte
4615 && ! NILP (current_buffer
->enable_multibyte_characters
))
4618 unsigned char *msg
= (unsigned char *) m
;
4619 unsigned char *str
, work
[4];
4620 /* Convert a single-byte string to multibyte
4621 for the *Message* buffer. */
4622 for (i
= 0; i
< len
; i
++)
4624 c
= unibyte_char_to_multibyte (msg
[i
]);
4625 nbytes
= CHAR_STRING (c
, work
, str
);
4626 insert_1_both (work
, 1, nbytes
, 1, 0, 0);
4630 insert_1 (m
, len
, 1, 0, 0);
4634 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
4635 insert_1 ("\n", 1, 1, 0, 0);
4637 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4639 this_bol_byte
= PT_BYTE
;
4643 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4645 prev_bol_byte
= PT_BYTE
;
4647 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
4648 this_bol
, this_bol_byte
);
4651 del_range_both (prev_bol
, prev_bol_byte
,
4652 this_bol
, this_bol_byte
, 0);
4658 /* If you change this format, don't forget to also
4659 change message_log_check_duplicate. */
4660 sprintf (dupstr
, " [%d times]", dup
);
4661 duplen
= strlen (dupstr
);
4662 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
4663 insert_1 (dupstr
, duplen
, 1, 0, 1);
4668 if (NATNUMP (Vmessage_log_max
))
4670 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
4671 -XFASTINT (Vmessage_log_max
) - 1, 0);
4672 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
4675 BEGV
= XMARKER (oldbegv
)->charpos
;
4676 BEGV_BYTE
= marker_byte_position (oldbegv
);
4685 ZV
= XMARKER (oldzv
)->charpos
;
4686 ZV_BYTE
= marker_byte_position (oldzv
);
4690 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4692 /* We can't do Fgoto_char (oldpoint) because it will run some
4694 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
4695 XMARKER (oldpoint
)->bytepos
);
4698 free_marker (oldpoint
);
4699 free_marker (oldbegv
);
4700 free_marker (oldzv
);
4702 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
4703 set_buffer_internal (oldbuf
);
4705 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
4706 message_log_need_newline
= !nlflag
;
4707 Vdeactivate_mark
= old_deactivate_mark
;
4712 /* We are at the end of the buffer after just having inserted a newline.
4713 (Note: We depend on the fact we won't be crossing the gap.)
4714 Check to see if the most recent message looks a lot like the previous one.
4715 Return 0 if different, 1 if the new one should just replace it, or a
4716 value N > 1 if we should also append " [N times]". */
4719 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
4720 int prev_bol
, this_bol
;
4721 int prev_bol_byte
, this_bol_byte
;
4724 int len
= Z_BYTE
- 1 - this_bol_byte
;
4726 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
4727 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
4729 for (i
= 0; i
< len
; i
++)
4731 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
4740 if (*p1
++ == ' ' && *p1
++ == '[')
4743 while (*p1
>= '0' && *p1
<= '9')
4744 n
= n
* 10 + *p1
++ - '0';
4745 if (strncmp (p1
, " times]\n", 8) == 0)
4752 /* Display an echo area message M with a specified length of LEN
4753 chars. The string may include null characters. If M is 0, clear
4754 out any existing message, and let the mini-buffer text show through.
4756 The buffer M must continue to exist until after the echo area gets
4757 cleared or some other message gets displayed there. This means do
4758 not pass text that is stored in a Lisp string; do not pass text in
4759 a buffer that was alloca'd. */
4762 message2 (m
, len
, multibyte
)
4767 /* First flush out any partial line written with print. */
4768 message_log_maybe_newline ();
4770 message_dolog (m
, len
, 1, multibyte
);
4771 message2_nolog (m
, len
, multibyte
);
4775 /* The non-logging counterpart of message2. */
4778 message2_nolog (m
, len
, multibyte
)
4782 message_enable_multibyte
= multibyte
;
4786 if (noninteractive_need_newline
)
4787 putc ('\n', stderr
);
4788 noninteractive_need_newline
= 0;
4790 fwrite (m
, len
, 1, stderr
);
4791 if (cursor_in_echo_area
== 0)
4792 fprintf (stderr
, "\n");
4795 /* A null message buffer means that the frame hasn't really been
4796 initialized yet. Error messages get reported properly by
4797 cmd_error, so this must be just an informative message; toss it. */
4798 else if (INTERACTIVE
4799 && selected_frame
->glyphs_initialized_p
4800 && FRAME_MESSAGE_BUF (selected_frame
))
4802 Lisp_Object mini_window
;
4805 /* Get the frame containing the mini-buffer
4806 that the selected frame is using. */
4807 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
4808 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4810 FRAME_SAMPLE_VISIBILITY (f
);
4811 if (FRAME_VISIBLE_P (selected_frame
)
4812 && ! FRAME_VISIBLE_P (f
))
4813 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
4817 echo_area_glyphs
= m
;
4818 echo_area_glyphs_length
= len
;
4819 echo_area_message
= Qnil
;
4821 if (minibuffer_auto_raise
)
4822 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
4826 echo_area_glyphs
= previous_echo_glyphs
= NULL
;
4827 echo_area_message
= previous_echo_area_message
= Qnil
;
4830 do_pending_window_change ();
4831 echo_area_display (1);
4832 do_pending_window_change ();
4833 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
4834 (*frame_up_to_date_hook
) (f
);
4839 /* Display an echo area message M with a specified length of LEN
4840 chars. The string may include null characters. If M is not a
4841 string, clear out any existing message, and let the mini-buffer
4842 text show through. */
4845 message3 (m
, len
, multibyte
)
4850 struct gcpro gcpro1
;
4854 /* First flush out any partial line written with print. */
4855 message_log_maybe_newline ();
4857 message_dolog (XSTRING (m
)->data
, len
, 1, multibyte
);
4858 message3_nolog (m
, len
, multibyte
);
4864 /* The non-logging version of message3. */
4867 message3_nolog (m
, len
, multibyte
)
4871 message_enable_multibyte
= multibyte
;
4875 if (noninteractive_need_newline
)
4876 putc ('\n', stderr
);
4877 noninteractive_need_newline
= 0;
4879 fwrite (XSTRING (m
)->data
, len
, 1, stderr
);
4880 if (cursor_in_echo_area
== 0)
4881 fprintf (stderr
, "\n");
4884 /* A null message buffer means that the frame hasn't really been
4885 initialized yet. Error messages get reported properly by
4886 cmd_error, so this must be just an informative message; toss it. */
4887 else if (INTERACTIVE
4888 && selected_frame
->glyphs_initialized_p
4889 && FRAME_MESSAGE_BUF (selected_frame
))
4891 Lisp_Object mini_window
;
4894 /* Get the frame containing the mini-buffer
4895 that the selected frame is using. */
4896 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
4897 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4899 FRAME_SAMPLE_VISIBILITY (f
);
4900 if (FRAME_VISIBLE_P (selected_frame
)
4901 && ! FRAME_VISIBLE_P (f
))
4902 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
4906 echo_area_glyphs
= NULL
;
4907 echo_area_message
= m
;
4908 echo_area_glyphs_length
= len
;
4910 if (minibuffer_auto_raise
)
4911 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
4915 echo_area_glyphs
= previous_echo_glyphs
= NULL
;
4916 echo_area_message
= previous_echo_area_message
= Qnil
;
4919 do_pending_window_change ();
4920 echo_area_display (1);
4921 do_pending_window_change ();
4922 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
4923 (*frame_up_to_date_hook
) (f
);
4928 /* Display a null-terminated echo area message M. If M is 0, clear
4929 out any existing message, and let the mini-buffer text show through.
4931 The buffer M must continue to exist until after the echo area gets
4932 cleared or some other message gets displayed there. Do not pass
4933 text that is stored in a Lisp string. Do not pass text in a buffer
4934 that was alloca'd. */
4940 message2 (m
, (m
? strlen (m
) : 0), 0);
4944 /* The non-logging counterpart of message1. */
4950 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
4953 /* Display a message M which contains a single %s
4954 which gets replaced with STRING. */
4957 message_with_string (m
, string
, log
)
4966 if (noninteractive_need_newline
)
4967 putc ('\n', stderr
);
4968 noninteractive_need_newline
= 0;
4969 fprintf (stderr
, m
, XSTRING (string
)->data
);
4970 if (cursor_in_echo_area
== 0)
4971 fprintf (stderr
, "\n");
4975 else if (INTERACTIVE
)
4977 /* The frame whose minibuffer we're going to display the message on.
4978 It may be larger than the selected frame, so we need
4979 to use its buffer, not the selected frame's buffer. */
4980 Lisp_Object mini_window
;
4983 /* Get the frame containing the minibuffer
4984 that the selected frame is using. */
4985 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
4986 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4988 /* A null message buffer means that the frame hasn't really been
4989 initialized yet. Error messages get reported properly by
4990 cmd_error, so this must be just an informative message; toss it. */
4991 if (FRAME_MESSAGE_BUF (f
))
4995 a
[0] = (char *) XSTRING (string
)->data
;
4997 len
= doprnt (FRAME_MESSAGE_BUF (f
),
4998 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5001 message2 (FRAME_MESSAGE_BUF (f
), len
,
5002 STRING_MULTIBYTE (string
));
5004 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5005 STRING_MULTIBYTE (string
));
5007 /* Print should start at the beginning of the message
5008 buffer next time. */
5009 message_buf_print
= 0;
5015 /* Truncate what will be displayed in the echo area
5016 the next time we display it--but don't redisplay it now. */
5019 truncate_echo_area (len
)
5022 /* A null message buffer means that the frame hasn't really been
5023 initialized yet. Error messages get reported properly by
5024 cmd_error, so this must be just an informative message; toss it. */
5025 if (!noninteractive
&& INTERACTIVE
&& FRAME_MESSAGE_BUF (selected_frame
))
5026 echo_area_glyphs_length
= len
;
5030 /* Nonzero if FRAME_MESSAGE_BUF (selected_frame) is being used by
5031 print; zero if being used by message. */
5033 int message_buf_print
;
5036 /* Dump an informative message to the minibuf. If M is 0, clear out
5037 any existing message, and let the mini-buffer text show through. */
5041 message (m
, a1
, a2
, a3
)
5043 EMACS_INT a1
, a2
, a3
;
5049 if (noninteractive_need_newline
)
5050 putc ('\n', stderr
);
5051 noninteractive_need_newline
= 0;
5052 fprintf (stderr
, m
, a1
, a2
, a3
);
5053 if (cursor_in_echo_area
== 0)
5054 fprintf (stderr
, "\n");
5058 else if (INTERACTIVE
)
5060 /* The frame whose mini-buffer we're going to display the message
5061 on. It may be larger than the selected frame, so we need to
5062 use its buffer, not the selected frame's buffer. */
5063 Lisp_Object mini_window
;
5066 /* Get the frame containing the mini-buffer
5067 that the selected frame is using. */
5068 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
5069 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5071 /* A null message buffer means that the frame hasn't really been
5072 initialized yet. Error messages get reported properly by
5073 cmd_error, so this must be just an informative message; toss
5075 if (FRAME_MESSAGE_BUF (f
))
5086 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5087 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5089 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5090 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5092 #endif /* NO_ARG_ARRAY */
5094 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5099 /* Print should start at the beginning of the message
5100 buffer next time. */
5101 message_buf_print
= 0;
5107 /* The non-logging version of message. */
5110 message_nolog (m
, a1
, a2
, a3
)
5112 EMACS_INT a1
, a2
, a3
;
5114 Lisp_Object old_log_max
;
5115 old_log_max
= Vmessage_log_max
;
5116 Vmessage_log_max
= Qnil
;
5117 message (m
, a1
, a2
, a3
);
5118 Vmessage_log_max
= old_log_max
;
5122 /* Display echo_area_message or echo_area_glyphs in the current
5128 if (STRINGP (echo_area_message
))
5129 message3 (echo_area_message
, echo_area_glyphs_length
,
5130 !NILP (current_buffer
->enable_multibyte_characters
));
5132 message2 (echo_area_glyphs
, echo_area_glyphs_length
,
5133 !NILP (current_buffer
->enable_multibyte_characters
));
5137 /* Redisplay the echo area of selected_frame. If UPDATE_FRAME_P is
5138 non-zero update selected_frame. */
5141 echo_area_display (update_frame_p
)
5144 Lisp_Object mini_window
;
5148 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
5149 w
= XWINDOW (mini_window
);
5150 f
= XFRAME (WINDOW_FRAME (w
));
5152 /* Don't display if frame is invisible or not yet initialized. */
5153 if (!FRAME_VISIBLE_P (f
)
5154 || !f
->glyphs_initialized_p
)
5157 /* When Emacs starts, selected_frame may be a visible terminal
5158 frame, even if we run under a window system. If we let this
5159 through, a message would be displayed on the terminal. */
5160 #ifdef HAVE_WINDOW_SYSTEM
5161 if (!inhibit_window_system
&& !FRAME_WINDOW_P (selected_frame
))
5163 #endif /* HAVE_WINDOW_SYSTEM */
5165 /* Redraw garbaged frames. */
5168 /* Old redisplay called redraw_garbaged_frames here which in
5169 turn called redraw_frame which in turn called clear_frame.
5170 The call to clear_frame is a source of flickering. After
5171 checking the places where SET_FRAME_GARBAGED is called, I
5172 believe a clear_frame is not necessary. It should suffice in
5173 the new redisplay to invalidate all current matrices, and
5174 ensure a complete redisplay of all windows. */
5175 Lisp_Object tail
, frame
;
5177 FOR_EACH_FRAME (tail
, frame
)
5179 struct frame
*f
= XFRAME (frame
);
5181 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
5183 clear_current_matrices (f
);
5189 ++windows_or_buffers_changed
;
5192 if (echo_area_glyphs
5193 || STRINGP (echo_area_message
)
5194 || minibuf_level
== 0)
5198 echo_area_window
= mini_window
;
5199 clear_glyph_matrix (w
->desired_matrix
);
5200 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, DEFAULT_FACE_ID
);
5202 if (STRINGP (echo_area_message
)
5203 && echo_area_glyphs_length
)
5205 prepare_desired_row (it
.glyph_row
);
5206 display_string (NULL
, echo_area_message
, Qnil
, 0, 0,
5207 &it
, -1, echo_area_glyphs_length
, 0,
5208 message_enable_multibyte
);
5209 it
.glyph_row
->truncated_on_right_p
= 0;
5210 compute_line_metrics (&it
);
5212 else if (echo_area_glyphs
5213 && echo_area_glyphs_length
)
5215 prepare_desired_row (it
.glyph_row
);
5216 display_string (echo_area_glyphs
, Qnil
, Qnil
, 0, 0, &it
,
5217 -1, echo_area_glyphs_length
, 0,
5218 message_enable_multibyte
);
5219 it
.glyph_row
->truncated_on_right_p
= 0;
5220 compute_line_metrics (&it
);
5223 blank_row (w
, it
.glyph_row
, 0);
5225 it
.glyph_row
->y
= it
.current_y
;
5226 it
.current_y
+= it
.glyph_row
->height
;
5228 /* Clear the rest of the lines. */
5229 while (it
.current_y
< it
.last_visible_y
)
5232 blank_row (w
, it
.glyph_row
, it
.current_y
);
5233 it
.current_y
+= it
.glyph_row
->height
;
5236 w
->must_be_updated_p
= 1;
5239 /* Calling update_single_window is faster when we can use
5240 window-based redisplay. */
5241 if (FRAME_WINDOW_P (f
))
5243 update_single_window (w
, 1);
5244 rif
->flush_display (f
);
5247 update_frame (f
, 1, 1);
5250 else if (!EQ (mini_window
, selected_window
))
5251 windows_or_buffers_changed
++;
5253 /* Prevent redisplay optimization in redisplay_internal by resetting
5254 this_line_start_pos. This is done because the mini-buffer now
5255 displays the message instead of its buffer text. */
5256 if (EQ (mini_window
, selected_window
))
5257 CHARPOS (this_line_start_pos
) = 0;
5259 previous_echo_glyphs
= echo_area_glyphs
;
5260 previous_echo_area_message
= echo_area_message
;
5261 previous_echo_glyphs_length
= echo_area_glyphs_length
;
5266 /***********************************************************************
5268 ***********************************************************************/
5271 #ifdef HAVE_WINDOW_SYSTEM
5273 /* A buffer for constructing frame titles in it; allocated from the
5274 heap in init_xdisp and resized as needed in store_frame_title_char. */
5276 static char *frame_title_buf
;
5278 /* The buffer's end, and a current output position in it. */
5280 static char *frame_title_buf_end
;
5281 static char *frame_title_ptr
;
5284 /* Store a single character C for the frame title in frame_title_buf.
5285 Re-allocate frame_title_buf if necessary. */
5288 store_frame_title_char (c
)
5291 /* If output position has reached the end of the allocated buffer,
5292 double the buffer's size. */
5293 if (frame_title_ptr
== frame_title_buf_end
)
5295 int len
= frame_title_ptr
- frame_title_buf
;
5296 int new_size
= 2 * len
* sizeof *frame_title_buf
;
5297 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
5298 frame_title_buf_end
= frame_title_buf
+ new_size
;
5299 frame_title_ptr
= frame_title_buf
+ len
;
5302 *frame_title_ptr
++ = c
;
5306 /* Store part of a frame title in frame_title_buf, beginning at
5307 frame_title_ptr. STR is the string to store. Do not copy more
5308 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
5309 the whole string. Pad with spaces until FIELD_WIDTH number of
5310 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
5311 Called from display_mode_element when it is used to build a frame
5315 store_frame_title (str
, field_width
, precision
)
5317 int field_width
, precision
;
5321 /* Copy at most PRECISION chars from STR. */
5322 while ((precision
<= 0 || n
< precision
)
5325 store_frame_title_char (*str
++);
5329 /* Fill up with spaces until FIELD_WIDTH reached. */
5330 while (field_width
> 0
5333 store_frame_title_char (' ');
5341 /* Set the title of FRAME, if it has changed. The title format is
5342 Vicon_title_format if FRAME is iconified, otherwise it is
5343 frame_title_format. */
5346 x_consider_frame_title (frame
)
5349 struct frame
*f
= XFRAME (frame
);
5351 if (FRAME_WINDOW_P (f
)
5352 || FRAME_MINIBUF_ONLY_P (f
)
5353 || f
->explicit_name
)
5355 /* Do we have more than one visible frame on this X display? */
5358 struct buffer
*obuf
;
5362 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5364 struct frame
*tf
= XFRAME (XCONS (tail
)->car
);
5367 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
5368 && !FRAME_MINIBUF_ONLY_P (tf
)
5369 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
5373 /* Set global variable indicating that multiple frames exist. */
5374 multiple_frames
= CONSP (tail
);
5376 /* Switch to the buffer of selected window of the frame. Set up
5377 frame_title_ptr so that display_mode_element will output into it;
5378 then display the title. */
5379 obuf
= current_buffer
;
5380 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
5381 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
5382 frame_title_ptr
= frame_title_buf
;
5383 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
5384 NULL
, DEFAULT_FACE_ID
);
5385 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
5386 frame_title_ptr
= NULL
;
5387 set_buffer_internal (obuf
);
5389 /* Set the title only if it's changed. This avoids consing in
5390 the common case where it hasn't. (If it turns out that we've
5391 already wasted too much time by walking through the list with
5392 display_mode_element, then we might need to optimize at a
5393 higher level than this.) */
5394 if (! STRINGP (f
->name
)
5395 || STRING_BYTES (XSTRING (f
->name
)) != len
5396 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
5397 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
5401 #else /* not HAVE_WINDOW_SYSTEM */
5403 #define frame_title_ptr ((char *)0)
5404 #define store_frame_title(str, mincol, maxcol) 0
5406 #endif /* not HAVE_WINDOW_SYSTEM */
5411 /***********************************************************************
5413 ***********************************************************************/
5416 /* Prepare for redisplay by updating menu-bar item lists when
5417 appropriate. This can call eval. */
5420 prepare_menu_bars ()
5423 struct gcpro gcpro1
, gcpro2
;
5425 struct frame
*tooltip_frame
;
5427 #ifdef HAVE_X_WINDOWS
5428 tooltip_frame
= tip_frame
;
5430 tooltip_frame
= NULL
;
5433 /* Update all frame titles based on their buffer names, etc. We do
5434 this before the menu bars so that the buffer-menu will show the
5435 up-to-date frame titles. */
5436 #ifdef HAVE_WINDOW_SYSTEM
5437 if (windows_or_buffers_changed
|| update_mode_lines
)
5439 Lisp_Object tail
, frame
;
5441 FOR_EACH_FRAME (tail
, frame
)
5444 if (f
!= tooltip_frame
5445 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
5446 x_consider_frame_title (frame
);
5449 #endif /* HAVE_WINDOW_SYSTEM */
5451 /* Update the menu bar item lists, if appropriate. This has to be
5452 done before any actual redisplay or generation of display lines. */
5453 all_windows
= (update_mode_lines
5454 || buffer_shared
> 1
5455 || windows_or_buffers_changed
);
5458 Lisp_Object tail
, frame
;
5459 int count
= specpdl_ptr
- specpdl
;
5461 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
5463 FOR_EACH_FRAME (tail
, frame
)
5467 /* Ignore tooltip frame. */
5468 if (f
== tooltip_frame
)
5471 /* If a window on this frame changed size, report that to
5472 the user and clear the size-change flag. */
5473 if (FRAME_WINDOW_SIZES_CHANGED (f
))
5475 Lisp_Object functions
;
5477 /* Clear flag first in case we get an error below. */
5478 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
5479 functions
= Vwindow_size_change_functions
;
5480 GCPRO2 (tail
, functions
);
5482 while (CONSP (functions
))
5484 call1 (XCAR (functions
), frame
);
5485 functions
= XCDR (functions
);
5491 update_menu_bar (f
, 0);
5492 #ifdef HAVE_WINDOW_SYSTEM
5493 update_toolbar (f
, 0);
5498 unbind_to (count
, Qnil
);
5502 update_menu_bar (selected_frame
, 1);
5503 #ifdef HAVE_WINDOW_SYSTEM
5504 update_toolbar (selected_frame
, 1);
5508 /* Motif needs this. See comment in xmenu.c. Turn it off when
5509 pending_menu_activation is not defined. */
5510 #ifdef USE_X_TOOLKIT
5511 pending_menu_activation
= 0;
5516 /* Update the menu bar item list for frame F. This has to be done
5517 before we start to fill in any display lines, because it can call
5520 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
5523 update_menu_bar (f
, save_match_data
)
5525 int save_match_data
;
5528 register struct window
*w
;
5530 window
= FRAME_SELECTED_WINDOW (f
);
5531 w
= XWINDOW (window
);
5533 if (update_mode_lines
)
5534 w
->update_mode_line
= Qt
;
5536 if (FRAME_WINDOW_P (f
)
5538 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
5539 FRAME_EXTERNAL_MENU_BAR (f
)
5541 FRAME_MENU_BAR_LINES (f
) > 0
5543 : FRAME_MENU_BAR_LINES (f
) > 0)
5545 /* If the user has switched buffers or windows, we need to
5546 recompute to reflect the new bindings. But we'll
5547 recompute when update_mode_lines is set too; that means
5548 that people can use force-mode-line-update to request
5549 that the menu bar be recomputed. The adverse effect on
5550 the rest of the redisplay algorithm is about the same as
5551 windows_or_buffers_changed anyway. */
5552 if (windows_or_buffers_changed
5553 || !NILP (w
->update_mode_line
)
5554 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
5555 < BUF_MODIFF (XBUFFER (w
->buffer
)))
5556 != !NILP (w
->last_had_star
))
5557 || ((!NILP (Vtransient_mark_mode
)
5558 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
5559 != !NILP (w
->region_showing
)))
5561 struct buffer
*prev
= current_buffer
;
5562 int count
= specpdl_ptr
- specpdl
;
5564 set_buffer_internal_1 (XBUFFER (w
->buffer
));
5565 if (save_match_data
)
5566 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
5567 if (NILP (Voverriding_local_map_menu_flag
))
5569 specbind (Qoverriding_terminal_local_map
, Qnil
);
5570 specbind (Qoverriding_local_map
, Qnil
);
5573 /* Run the Lucid hook. */
5574 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
5576 /* If it has changed current-menubar from previous value,
5577 really recompute the menu-bar from the value. */
5578 if (! NILP (Vlucid_menu_bar_dirty_flag
))
5579 call0 (Qrecompute_lucid_menubar
);
5581 safe_run_hooks (Qmenu_bar_update_hook
);
5582 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
5584 /* Redisplay the menu bar in case we changed it. */
5585 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
5586 if (FRAME_WINDOW_P (f
))
5587 set_frame_menubar (f
, 0, 0);
5589 /* On a terminal screen, the menu bar is an ordinary screen
5590 line, and this makes it get updated. */
5591 w
->update_mode_line
= Qt
;
5592 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
5593 /* In the non-toolkit version, the menu bar is an ordinary screen
5594 line, and this makes it get updated. */
5595 w
->update_mode_line
= Qt
;
5596 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
5598 unbind_to (count
, Qnil
);
5599 set_buffer_internal_1 (prev
);
5606 /***********************************************************************
5608 ***********************************************************************/
5610 #ifdef HAVE_WINDOW_SYSTEM
5612 /* Update the toolbar item list for frame F. This has to be done
5613 before we start to fill in any display lines. Called from
5614 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
5615 and restore it here. */
5618 update_toolbar (f
, save_match_data
)
5620 int save_match_data
;
5622 if (WINDOWP (f
->toolbar_window
)
5623 && XFASTINT (XWINDOW (f
->toolbar_window
)->height
) > 0)
5628 window
= FRAME_SELECTED_WINDOW (f
);
5629 w
= XWINDOW (window
);
5631 /* If the user has switched buffers or windows, we need to
5632 recompute to reflect the new bindings. But we'll
5633 recompute when update_mode_lines is set too; that means
5634 that people can use force-mode-line-update to request
5635 that the menu bar be recomputed. The adverse effect on
5636 the rest of the redisplay algorithm is about the same as
5637 windows_or_buffers_changed anyway. */
5638 if (windows_or_buffers_changed
5639 || !NILP (w
->update_mode_line
)
5640 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
5641 < BUF_MODIFF (XBUFFER (w
->buffer
)))
5642 != !NILP (w
->last_had_star
))
5643 || ((!NILP (Vtransient_mark_mode
)
5644 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
5645 != !NILP (w
->region_showing
)))
5647 struct buffer
*prev
= current_buffer
;
5648 int count
= specpdl_ptr
- specpdl
;
5650 /* Set current_buffer to the buffer of the selected
5651 window of the frame, so that we get the right local
5653 set_buffer_internal_1 (XBUFFER (w
->buffer
));
5655 /* Save match data, if we must. */
5656 if (save_match_data
)
5657 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
5659 /* Make sure that we don't accidentally use bogus keymaps. */
5660 if (NILP (Voverriding_local_map_menu_flag
))
5662 specbind (Qoverriding_terminal_local_map
, Qnil
);
5663 specbind (Qoverriding_local_map
, Qnil
);
5666 /* Build desired toolbar items from keymaps. */
5667 f
->desired_toolbar_items
5668 = toolbar_items (f
->desired_toolbar_items
,
5669 &f
->n_desired_toolbar_items
);
5671 /* Redisplay the toolbar in case we changed it. */
5672 w
->update_mode_line
= Qt
;
5674 unbind_to (count
, Qnil
);
5675 set_buffer_internal_1 (prev
);
5681 /* Set F->desired_toolbar_string to a Lisp string representing frame
5682 F's desired toolbar contents. F->desired_toolbar_items must have
5683 been set up previously by calling prepare_menu_bars. */
5686 build_desired_toolbar_string (f
)
5689 int i
, size
, size_needed
, string_idx
;
5690 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5691 Lisp_Object image
, plist
, props
;
5693 image
= plist
= props
= Qnil
;
5694 GCPRO3 (image
, plist
, props
);
5696 /* Prepare F->desired_toolbar_string. If we can reuse it, do so.
5697 Otherwise, make a new string. */
5699 /* The size of the string we might be able to reuse. */
5700 size
= (STRINGP (f
->desired_toolbar_string
)
5701 ? XSTRING (f
->desired_toolbar_string
)->size
5704 /* Each image in the string we build is preceded by a space,
5705 and there is a space at the end. */
5706 size_needed
= f
->n_desired_toolbar_items
+ 1;
5708 /* Reuse f->desired_toolbar_string, if possible. */
5709 if (size
< size_needed
)
5710 f
->desired_toolbar_string
= Fmake_string (make_number (size_needed
), ' ');
5713 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
5714 Fremove_text_properties (make_number (0), make_number (size
),
5715 props
, f
->desired_toolbar_string
);
5718 /* Put a `display' property on the string for the images to display,
5719 put a `menu_item' property on toolbar items with a value that
5720 is the index of the item in F's toolbar item vector. */
5721 for (i
= 0, string_idx
= 0;
5722 i
< f
->n_desired_toolbar_items
;
5723 ++i
, string_idx
+= 1)
5726 (XVECTOR (f->desired_toolbar_items) \
5727 ->contents[i * TOOLBAR_ITEM_NSLOTS + (IDX)])
5729 int enabled_p
= !NILP (PROP (TOOLBAR_ITEM_ENABLED_P
));
5730 int selected_p
= !NILP (PROP (TOOLBAR_ITEM_SELECTED_P
));
5732 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
5733 extern Lisp_Object Qlaplace
;
5735 /* If image is a vector, choose the image according to the
5737 image
= PROP (TOOLBAR_ITEM_IMAGES
);
5738 if (VECTORP (image
))
5740 enum toolbar_item_image idx
;
5744 ? TOOLBAR_IMAGE_ENABLED_SELECTED
5745 : TOOLBAR_IMAGE_ENABLED_DESELECTED
);
5748 ? TOOLBAR_IMAGE_DISABLED_SELECTED
5749 : TOOLBAR_IMAGE_DISABLED_DESELECTED
);
5751 xassert (XVECTOR (image
)->size
>= idx
);
5752 image
= XVECTOR (image
)->contents
[idx
];
5755 /* Ignore invalid image specifications. */
5756 if (!valid_image_p (image
))
5759 /* Display the toolbar button pressed, or depressed. */
5760 plist
= Fcopy_sequence (XCDR (image
));
5762 /* Compute margin and relief to draw. */
5763 relief
= toolbar_button_relief
> 0 ? toolbar_button_relief
: 3;
5764 margin
= relief
+ max (0, toolbar_button_margin
);
5766 if (auto_raise_toolbar_buttons_p
)
5768 /* Add a `:relief' property to the image spec if the item is
5772 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
5778 /* If image is selected, display it pressed, i.e. with a
5779 negative relief. If it's not selected, display it with a
5781 plist
= Fplist_put (plist
, QCrelief
,
5783 ? make_number (-relief
)
5784 : make_number (relief
)));
5788 /* Put a margin around the image. */
5790 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
5792 /* If button is not enabled, make the image appear disabled by
5793 applying an appropriate algorithm to it. */
5795 plist
= Fplist_put (plist
, QCalgorithm
, Qlaplace
);
5797 /* Put a `display' text property on the string for the image to
5798 display. Put a `menu-item' property on the string that gives
5799 the start of this item's properties in the toolbar items
5801 image
= Fcons (Qimage
, plist
);
5802 props
= list4 (Qdisplay
, image
,
5803 Qmenu_item
, make_number (i
* TOOLBAR_ITEM_NSLOTS
)),
5804 Fadd_text_properties (make_number (string_idx
),
5805 make_number (string_idx
+ 1),
5806 props
, f
->desired_toolbar_string
);
5814 /* Display one line of the toolbar of frame IT->f. */
5817 display_toolbar_line (it
)
5820 struct glyph_row
*row
= it
->glyph_row
;
5821 int max_x
= it
->last_visible_x
;
5824 prepare_desired_row (row
);
5825 row
->y
= it
->current_y
;
5827 while (it
->current_x
< max_x
)
5829 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
5831 /* Get the next display element. */
5832 if (!get_next_display_element (it
))
5835 /* Produce glyphs. */
5836 x_before
= it
->current_x
;
5837 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
5838 PRODUCE_GLYPHS (it
);
5840 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
5845 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
5847 if (x
+ glyph
->pixel_width
> max_x
)
5849 /* Glyph doesn't fit on line. */
5850 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
5856 x
+= glyph
->pixel_width
;
5860 /* Stop at line ends. */
5861 if (ITERATOR_AT_END_OF_LINE_P (it
))
5864 set_iterator_to_next (it
);
5869 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
5870 extend_face_to_end_of_line (it
);
5871 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
5872 last
->right_box_line_p
= 1;
5873 compute_line_metrics (it
);
5875 /* If line is empty, make it occupy the rest of the toolbar. */
5876 if (!row
->displays_text_p
)
5878 row
->height
= it
->last_visible_y
- row
->y
;
5882 row
->full_width_p
= 1;
5883 row
->continued_p
= 0;
5884 row
->truncated_on_left_p
= 0;
5885 row
->truncated_on_right_p
= 0;
5887 it
->current_x
= it
->hpos
= 0;
5888 it
->current_y
+= row
->height
;
5894 /* Value is the number of screen lines needed to make all toolbar
5895 items of frame F visible. */
5898 toolbar_lines_needed (f
)
5901 struct window
*w
= XWINDOW (f
->toolbar_window
);
5904 /* Initialize an iterator for iteration over F->desired_toolbar_string
5905 in the toolbar window of frame F. */
5906 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOLBAR_FACE_ID
);
5907 it
.first_visible_x
= 0;
5908 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
5909 reseat_to_string (&it
, NULL
, f
->desired_toolbar_string
, 0, 0, 0, -1);
5911 while (!ITERATOR_AT_END_P (&it
))
5913 it
.glyph_row
= w
->desired_matrix
->rows
;
5914 clear_glyph_row (it
.glyph_row
);
5915 display_toolbar_line (&it
);
5918 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
5922 /* Display the toolbar of frame F. Value is non-zero if toolbar's
5923 height should be changed. */
5926 redisplay_toolbar (f
)
5931 struct glyph_row
*row
;
5932 int change_height_p
= 0;
5934 /* If frame hasn't a toolbar window or if it is zero-height, don't
5935 do anything. This means you must start with toolbar-lines
5936 non-zero to get the auto-sizing effect. Or in other words, you
5937 can turn off toolbars by specifying toolbar-lines zero. */
5938 if (!WINDOWP (f
->toolbar_window
)
5939 || (w
= XWINDOW (f
->toolbar_window
),
5940 XFASTINT (w
->height
) == 0))
5943 /* Set up an iterator for the toolbar window. */
5944 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOLBAR_FACE_ID
);
5945 it
.first_visible_x
= 0;
5946 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
5949 /* Build a string that represents the contents of the toolbar. */
5950 build_desired_toolbar_string (f
);
5951 reseat_to_string (&it
, NULL
, f
->desired_toolbar_string
, 0, 0, 0, -1);
5953 /* Display as many lines as needed to display all toolbar items. */
5954 while (it
.current_y
< it
.last_visible_y
)
5955 display_toolbar_line (&it
);
5957 /* It doesn't make much sense to try scrolling in the toolbar
5958 window, so don't do it. */
5959 w
->desired_matrix
->no_scrolling_p
= 1;
5960 w
->must_be_updated_p
= 1;
5962 if (auto_resize_toolbars_p
)
5966 /* If there are blank lines at the end, except for a partially
5967 visible blank line at the end that is smaller than
5968 CANON_Y_UNIT, change the toolbar's height. */
5969 row
= it
.glyph_row
- 1;
5970 if (!row
->displays_text_p
5971 && row
->height
>= CANON_Y_UNIT (f
))
5972 change_height_p
= 1;
5974 /* If row displays toolbar items, but is partially visible,
5975 change the toolbar's height. */
5976 if (row
->displays_text_p
5977 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
5978 change_height_p
= 1;
5980 /* Resize windows as needed by changing the `toolbar-lines'
5983 && (nlines
= toolbar_lines_needed (f
),
5984 nlines
!= XFASTINT (w
->height
)))
5986 extern Lisp_Object Qtoolbar_lines
;
5989 XSETFRAME (frame
, f
);
5990 clear_glyph_matrix (w
->desired_matrix
);
5991 Fmodify_frame_parameters (frame
,
5992 Fcons (Fcons (Qtoolbar_lines
,
5993 make_number (nlines
)),
5995 fonts_changed_p
= 1;
5999 return change_height_p
;
6003 /* Get information about the toolbar item which is displayed in GLYPH
6004 on frame F. Return in *PROP_IDX the index where toolbar item
6005 properties start in F->current_toolbar_items. Value is zero if
6006 GLYPH doesn't display a toolbar item. */
6009 toolbar_item_info (f
, glyph
, prop_idx
)
6011 struct glyph
*glyph
;
6017 /* Get the text property `menu-item' at pos. The value of that
6018 property is the start index of this item's properties in
6019 F->current_toolbar_items. */
6020 prop
= Fget_text_property (make_number (glyph
->charpos
),
6021 Qmenu_item
, f
->current_toolbar_string
);
6022 if (INTEGERP (prop
))
6024 *prop_idx
= XINT (prop
);
6033 #endif /* HAVE_WINDOW_SYSTEM */
6037 /************************************************************************
6038 Horizontal scrolling
6039 ************************************************************************/
6041 static int hscroll_window_tree
P_ ((Lisp_Object
));
6042 static int hscroll_windows
P_ ((Lisp_Object
));
6044 /* For all leaf windows in the window tree rooted at WINDOW, set their
6045 hscroll value so that PT is (i) visible in the window, and (ii) so
6046 that it is not within a certain margin at the window's left and
6047 right border. Value is non-zero if any window's hscroll has been
6051 hscroll_window_tree (window
)
6054 int hscrolled_p
= 0;
6056 while (WINDOWP (window
))
6058 struct window
*w
= XWINDOW (window
);
6060 if (WINDOWP (w
->hchild
))
6061 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
6062 else if (WINDOWP (w
->vchild
))
6063 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
6064 else if (w
->cursor
.vpos
>= 0)
6066 int hscroll_margin
, text_area_x
, text_area_y
;
6067 int text_area_width
, text_area_height
;
6068 struct glyph_row
*cursor_row
= MATRIX_ROW (w
->current_matrix
,
6071 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
6072 &text_area_width
, &text_area_height
);
6074 /* Scroll when cursor is inside this scroll margin. */
6075 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
6077 if ((XFASTINT (w
->hscroll
)
6078 && w
->cursor
.x
< hscroll_margin
)
6079 || (cursor_row
->truncated_on_right_p
6080 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
6084 struct buffer
*saved_current_buffer
;
6087 /* Find point in a display of infinite width. */
6088 saved_current_buffer
= current_buffer
;
6089 current_buffer
= XBUFFER (w
->buffer
);
6091 if (w
== XWINDOW (selected_window
))
6092 pt
= BUF_PT (current_buffer
);
6095 pt
= marker_position (w
->pointm
);
6096 pt
= max (BEGV
, pt
);
6100 /* Move iterator to pt starting at cursor_row->start in
6101 a line with infinite width. */
6102 init_to_row_start (&it
, w
, cursor_row
);
6103 it
.last_visible_x
= INFINITY
;
6104 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
6105 current_buffer
= saved_current_buffer
;
6107 /* Center cursor in window. */
6108 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
6109 / CANON_X_UNIT (it
.f
));
6111 /* Don't call Fset_window_hscroll if value hasn't
6112 changed because it will prevent redisplay
6114 if (XFASTINT (w
->hscroll
) != hscroll
)
6116 Fset_window_hscroll (window
, make_number (hscroll
));
6125 /* Value is non-zero if hscroll of any leaf window has been changed. */
6130 /* Set hscroll so that cursor is visible and not inside horizontal
6131 scroll margins for all windows in the tree rooted at WINDOW. See
6132 also hscroll_window_tree above. Value is non-zero if any window's
6133 hscroll has been changed. If it has, desired matrices on the frame
6134 of WINDOW are cleared. */
6137 hscroll_windows (window
)
6140 int hscrolled_p
= hscroll_window_tree (window
);
6142 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
6148 /************************************************************************
6150 ************************************************************************/
6152 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
6153 to a non-zero value. This is sometimes handy to have in a debugger
6158 /* Values of beg_unchanged and end_unchanged as of last call to
6161 int debug_beg_unchanged
, debug_end_unchanged
;
6163 /* First and last unchanged row for try_window_id. */
6165 int debug_first_unchanged_at_end_vpos
;
6166 int debug_last_unchanged_at_beg_vpos
;
6168 /* Delta vpos and y. */
6170 int debug_dvpos
, debug_dy
;
6172 /* Delta in characters and bytes for try_window_id. */
6174 int debug_delta
, debug_delta_bytes
;
6176 /* Values of window_end_pos and window_end_vpos at the end of
6179 int debug_end_pos
, debug_end_vpos
;
6181 /* Append a string to W->desired_matrix->method. FMT is a printf
6182 format string. A1...A9 are a supplement for a variable-length
6183 argument list. If trace_redisplay_p is non-zero also printf the
6184 resulting string to stderr. */
6187 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
6190 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
6193 char *method
= w
->desired_matrix
->method
;
6194 int len
= strlen (method
);
6195 int size
= sizeof w
->desired_matrix
->method
;
6196 int remaining
= size
- len
- 1;
6198 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
6199 if (len
&& remaining
)
6205 strncpy (method
+ len
, buffer
, remaining
);
6207 if (trace_redisplay_p
)
6208 fprintf (stderr
, "%p (%s): %s\n",
6210 ((BUFFERP (w
->buffer
)
6211 && STRINGP (XBUFFER (w
->buffer
)->name
))
6212 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
6217 #endif /* GLYPH_DEBUG */
6220 /* This counter is used to clear the face cache every once in a while
6221 in redisplay_internal. It is incremented for each redisplay.
6222 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
6225 #define CLEAR_FACE_CACHE_COUNT 10000
6226 static int clear_face_cache_count
;
6228 /* Record the previous terminal frame we displayed. */
6230 static struct frame
*previous_terminal_frame
;
6232 /* Non-zero while redisplay_internal is in progress. */
6237 /* Value is non-zero if all changes in window W, which displays
6238 current_buffer, are in the text between START and END. START is a
6239 buffer position, END is given as a distance from Z. Used in
6240 redisplay_internal for display optimization. */
6243 text_outside_line_unchanged_p (w
, start
, end
)
6247 int unchanged_p
= 1;
6249 /* If text or overlays have changed, see where. */
6250 if (XFASTINT (w
->last_modified
) < MODIFF
6251 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
6253 /* Gap in the line? */
6254 if (GPT
< start
|| Z
- GPT
< end
)
6257 /* Changes start in front of the line, or end after it? */
6259 && (beg_unchanged
< start
- 1
6260 || end_unchanged
< end
))
6263 /* If selective display, can't optimize if changes start at the
6264 beginning of the line. */
6266 && INTEGERP (current_buffer
->selective_display
)
6267 && XINT (current_buffer
->selective_display
) > 0
6268 && (beg_unchanged
< start
|| GPT
<= start
))
6276 /* Do a frame update, taking possible shortcuts into account. This is
6277 the main external entry point for redisplay.
6279 If the last redisplay displayed an echo area message and that message
6280 is no longer requested, we clear the echo area or bring back the
6281 mini-buffer if that is in use. */
6286 redisplay_internal (0);
6290 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
6291 response to any user action; therefore, we should preserve the echo
6292 area. (Actually, our caller does that job.) Perhaps in the future
6293 avoid recentering windows if it is not necessary; currently that
6294 causes some problems. */
6297 redisplay_internal (preserve_echo_area
)
6298 int preserve_echo_area
;
6300 struct window
*w
= XWINDOW (selected_window
);
6301 struct frame
*f
= XFRAME (w
->frame
);
6303 int must_finish
= 0;
6304 struct text_pos tlbufpos
, tlendpos
;
6305 int number_of_visible_frames
;
6307 /* Non-zero means redisplay has to consider all windows on all
6308 frames. Zero means, only selected_window is considered. */
6309 int consider_all_windows_p
;
6311 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
6313 /* No redisplay if running in batch mode or frame is not yet fully
6314 initialized, or redisplay is explicitly turned off by setting
6315 Vinhibit_redisplay. */
6317 || !NILP (Vinhibit_redisplay
)
6318 || !f
->glyphs_initialized_p
)
6321 /* The flag redisplay_performed_directly_p is set by
6322 direct_output_for_insert when it already did the whole screen
6323 update necessary. */
6324 if (redisplay_performed_directly_p
)
6326 redisplay_performed_directly_p
= 0;
6327 if (!hscroll_windows (selected_window
))
6331 #ifdef USE_X_TOOLKIT
6332 if (popup_activated ())
6342 /* If new fonts have been loaded that make a glyph matrix adjustment
6343 necessary, do it. */
6344 if (fonts_changed_p
)
6346 adjust_glyphs (NULL
);
6347 ++windows_or_buffers_changed
;
6348 fonts_changed_p
= 0;
6351 if (! FRAME_WINDOW_P (selected_frame
)
6352 && previous_terminal_frame
!= selected_frame
)
6354 /* Since frames on an ASCII terminal share the same display
6355 area, displaying a different frame means redisplay the whole
6357 windows_or_buffers_changed
++;
6358 SET_FRAME_GARBAGED (selected_frame
);
6359 XSETFRAME (Vterminal_frame
, selected_frame
);
6361 previous_terminal_frame
= selected_frame
;
6363 /* Set the visible flags for all frames. Do this before checking
6364 for resized or garbaged frames; they want to know if their frames
6365 are visible. See the comment in frame.h for
6366 FRAME_SAMPLE_VISIBILITY. */
6368 Lisp_Object tail
, frame
;
6370 number_of_visible_frames
= 0;
6372 FOR_EACH_FRAME (tail
, frame
)
6374 struct frame
*f
= XFRAME (frame
);
6376 FRAME_SAMPLE_VISIBILITY (f
);
6377 if (FRAME_VISIBLE_P (f
))
6378 ++number_of_visible_frames
;
6379 clear_desired_matrices (f
);
6383 /* Notice any pending interrupt request to change frame size. */
6384 do_pending_window_change ();
6386 /* Clear frames marked as garbaged. */
6389 /* Old redisplay called redraw_garbaged_frames here which in
6390 turn called redraw_frame which in turn called clear_frame.
6391 The call to clear_frame is a source of flickering. After
6392 checking the places where SET_FRAME_GARBAGED is called, I
6393 believe a clear_frame is not necessary. It should suffice in
6394 the new redisplay to invalidate all current matrices, and
6395 ensure a complete redisplay of all windows. */
6396 Lisp_Object tail
, frame
;
6398 FOR_EACH_FRAME (tail
, frame
)
6400 struct frame
*f
= XFRAME (frame
);
6402 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6404 clear_current_matrices (f
);
6410 ++windows_or_buffers_changed
;
6413 /* Build menubar and toolbar items. */
6414 prepare_menu_bars ();
6416 if (windows_or_buffers_changed
)
6417 update_mode_lines
++;
6419 /* Detect case that we need to write or remove a star in the mode line. */
6420 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
6422 w
->update_mode_line
= Qt
;
6423 if (buffer_shared
> 1)
6424 update_mode_lines
++;
6427 /* If %c is in the mode line, update it if needed. */
6428 if (!NILP (w
->column_number_displayed
)
6429 /* This alternative quickly identifies a common case
6430 where no change is needed. */
6431 && !(PT
== XFASTINT (w
->last_point
)
6432 && XFASTINT (w
->last_modified
) >= MODIFF
6433 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
6434 && XFASTINT (w
->column_number_displayed
) != current_column ())
6435 w
->update_mode_line
= Qt
;
6437 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
6439 /* The variable buffer_shared is set in redisplay_window and
6440 indicates that we redisplay a buffer in different windows. See
6442 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
6444 /* If specs for an arrow have changed, do thorough redisplay
6445 to ensure we remove any arrow that should no longer exist. */
6446 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
6447 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
6448 consider_all_windows_p
= windows_or_buffers_changed
= 1;
6450 /* Normally the message* functions will have already displayed and
6451 updated the echo area, but the frame may have been trashed, or
6452 the update may have been preempted, so display the echo area
6454 if (echo_area_glyphs
6455 || STRINGP (echo_area_message
)
6456 || previous_echo_glyphs
6457 || STRINGP (previous_echo_area_message
))
6459 echo_area_display (0);
6463 /* If showing the region, and mark has changed, we must redisplay
6464 the whole window. The assignment to this_line_start_pos prevents
6465 the optimization directly below this if-statement. */
6466 if (((!NILP (Vtransient_mark_mode
)
6467 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6468 != !NILP (w
->region_showing
))
6469 || (!NILP (w
->region_showing
)
6470 && !EQ (w
->region_showing
,
6471 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
6472 CHARPOS (this_line_start_pos
) = 0;
6474 /* Optimize the case that only the line containing the cursor in the
6475 selected window has changed. Variables starting with this_ are
6476 set in display_line and record information about the line
6477 containing the cursor. */
6478 tlbufpos
= this_line_start_pos
;
6479 tlendpos
= this_line_end_pos
;
6480 if (!consider_all_windows_p
6481 && CHARPOS (tlbufpos
) > 0
6482 && NILP (w
->update_mode_line
)
6483 && !current_buffer
->clip_changed
6484 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
6485 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
6486 /* Make sure recorded data applies to current buffer, etc. */
6487 && this_line_buffer
== current_buffer
6488 && current_buffer
== XBUFFER (w
->buffer
)
6489 && NILP (w
->force_start
)
6490 /* Point must be on the line that we have info recorded about. */
6491 && PT
>= CHARPOS (tlbufpos
)
6492 && PT
<= Z
- CHARPOS (tlendpos
)
6493 /* All text outside that line, including its final newline,
6494 must be unchanged */
6495 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
6496 CHARPOS (tlendpos
)))
6498 if (CHARPOS (tlbufpos
) > BEGV
6499 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
6500 && (CHARPOS (tlbufpos
) == ZV
6501 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
6502 /* Former continuation line has disappeared by becoming empty */
6504 else if (XFASTINT (w
->last_modified
) < MODIFF
6505 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
6506 || MINI_WINDOW_P (w
))
6508 /* We have to handle the case of continuation around a
6509 wide-column character (See the comment in indent.c around
6512 For instance, in the following case:
6514 -------- Insert --------
6515 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
6516 J_I_ ==> J_I_ `^^' are cursors.
6520 As we have to redraw the line above, we should goto cancel. */
6523 int line_height_before
= this_line_pixel_height
;
6525 /* Note that start_display will handle the case that the
6526 line starting at tlbufpos is a continuation lines. */
6527 start_display (&it
, w
, tlbufpos
);
6529 /* Implementation note: It this still necessary? */
6530 if (it
.current_x
!= this_line_start_x
)
6533 TRACE ((stderr
, "trying display optimization 1\n"));
6534 w
->cursor
.vpos
= -1;
6535 overlay_arrow_seen
= 0;
6536 it
.vpos
= this_line_vpos
;
6537 it
.current_y
= this_line_y
;
6538 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
6541 /* If line contains point, is not continued,
6542 and ends at same distance from eob as before, we win */
6543 if (w
->cursor
.vpos
>= 0
6544 /* Line is not continued, otherwise this_line_start_pos
6545 would have been set to 0 in display_line. */
6546 && CHARPOS (this_line_start_pos
)
6547 /* Line ends as before. */
6548 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
6549 /* Line has same height as before. Otherwise other lines
6550 would have to be shifted up or down. */
6551 && this_line_pixel_height
== line_height_before
)
6553 /* If this is not the window's last line, we must adjust
6554 the charstarts of the lines below. */
6555 if (it
.current_y
< it
.last_visible_y
)
6557 struct glyph_row
*row
6558 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
6559 int delta
, delta_bytes
;
6561 if (Z
- CHARPOS (tlendpos
) == ZV
)
6563 /* This line ends at end of (accessible part of)
6564 buffer. There is no newline to count. */
6566 - CHARPOS (tlendpos
)
6567 - MATRIX_ROW_START_CHARPOS (row
));
6568 delta_bytes
= (Z_BYTE
6569 - BYTEPOS (tlendpos
)
6570 - MATRIX_ROW_START_BYTEPOS (row
));
6574 /* This line ends in a newline. Must take
6575 account of the newline and the rest of the
6576 text that follows. */
6578 - CHARPOS (tlendpos
)
6579 - MATRIX_ROW_START_CHARPOS (row
));
6580 delta_bytes
= (Z_BYTE
6581 - BYTEPOS (tlendpos
)
6582 - MATRIX_ROW_START_BYTEPOS (row
));
6585 increment_glyph_matrix_buffer_positions (w
->current_matrix
,
6587 w
->current_matrix
->nrows
,
6588 delta
, delta_bytes
);
6591 /* If this row displays text now but previously didn't,
6592 or vice versa, w->window_end_vpos may have to be
6594 if ((it
.glyph_row
- 1)->displays_text_p
)
6596 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
6597 XSETINT (w
->window_end_vpos
, this_line_vpos
);
6599 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
6600 && this_line_vpos
> 0)
6601 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
6602 w
->window_end_valid
= Qnil
;
6604 /* Update hint: No need to try to scroll in update_window. */
6605 w
->desired_matrix
->no_scrolling_p
= 1;
6608 *w
->desired_matrix
->method
= 0;
6609 debug_method_add (w
, "optimization 1");
6616 else if (/* Cursor position hasn't changed. */
6617 PT
== XFASTINT (w
->last_point
)
6618 /* Make sure the cursor was last displayed
6619 in this window. Otherwise we have to reposition it. */
6620 && 0 <= w
->cursor
.vpos
6621 && XINT (w
->height
) > w
->cursor
.vpos
)
6625 do_pending_window_change ();
6627 /* We used to always goto end_of_redisplay here, but this
6628 isn't enough if we have a blinking cursor. */
6629 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
6630 goto end_of_redisplay
;
6634 /* If highlighting the region, or if the cursor is in the echo area,
6635 then we can't just move the cursor. */
6636 else if (! (!NILP (Vtransient_mark_mode
)
6637 && !NILP (current_buffer
->mark_active
))
6638 && (w
== XWINDOW (current_buffer
->last_selected_window
)
6639 || highlight_nonselected_windows
)
6640 && NILP (w
->region_showing
)
6641 && !cursor_in_echo_area
)
6644 struct glyph_row
*row
;
6646 /* Skip from tlbufpos to PT and see where it is. Note that
6647 PT may be in invisible text. If so, we will end at the
6648 next visible position. */
6649 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
6650 NULL
, DEFAULT_FACE_ID
);
6651 it
.current_x
= this_line_start_x
;
6652 it
.current_y
= this_line_y
;
6653 it
.vpos
= this_line_vpos
;
6655 /* The call to move_it_to stops in front of PT, but
6656 moves over before-strings. */
6657 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
6659 if (it
.vpos
== this_line_vpos
6660 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
6663 xassert (this_line_vpos
== it
.vpos
);
6664 xassert (this_line_y
== it
.current_y
);
6665 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
6673 /* Text changed drastically or point moved off of line. */
6674 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
6677 CHARPOS (this_line_start_pos
) = 0;
6678 consider_all_windows_p
|= buffer_shared
> 1;
6679 ++clear_face_cache_count
;
6682 /* Build desired matrices. If consider_all_windows_p is non-zero,
6683 do it for all windows on all frames. Otherwise do it for
6684 selected_window, only. */
6686 if (consider_all_windows_p
)
6688 Lisp_Object tail
, frame
;
6690 /* Clear the face cache eventually. */
6691 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
6693 clear_face_cache (0);
6694 clear_face_cache_count
= 0;
6697 /* Recompute # windows showing selected buffer. This will be
6698 incremented each time such a window is displayed. */
6701 FOR_EACH_FRAME (tail
, frame
)
6703 struct frame
*f
= XFRAME (frame
);
6704 if (FRAME_WINDOW_P (f
) || f
== selected_frame
)
6706 /* Mark all the scroll bars to be removed; we'll redeem
6707 the ones we want when we redisplay their windows. */
6708 if (condemn_scroll_bars_hook
)
6709 (*condemn_scroll_bars_hook
) (f
);
6711 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
6712 redisplay_windows (FRAME_ROOT_WINDOW (f
));
6714 /* Any scroll bars which redisplay_windows should have
6715 nuked should now go away. */
6716 if (judge_scroll_bars_hook
)
6717 (*judge_scroll_bars_hook
) (f
);
6721 else if (FRAME_VISIBLE_P (selected_frame
)
6722 && !FRAME_OBSCURED_P (selected_frame
))
6723 redisplay_window (selected_window
, 1);
6726 /* Compare desired and current matrices, perform output. */
6730 /* If fonts changed, display again. */
6731 if (fonts_changed_p
)
6734 /* Prevent various kinds of signals during display update.
6735 stdio is not robust about handling signals,
6736 which can cause an apparent I/O error. */
6737 if (interrupt_input
)
6741 if (consider_all_windows_p
)
6747 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
6751 if (!FRAMEP (XCONS (tail
)->car
))
6754 f
= XFRAME (XCONS (tail
)->car
);
6756 if ((FRAME_WINDOW_P (f
) || f
== selected_frame
)
6757 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
6759 /* Mark all windows as to be updated. */
6760 set_window_update_flags (XWINDOW (f
->root_window
), 1);
6761 pause
|= update_frame (f
, 0, 0);
6764 if (hscroll_windows (f
->root_window
))
6767 mark_window_display_accurate (f
->root_window
, 1);
6768 if (frame_up_to_date_hook
!= 0)
6769 (*frame_up_to_date_hook
) (f
);
6776 if (FRAME_VISIBLE_P (selected_frame
)
6777 && !FRAME_OBSCURED_P (selected_frame
))
6779 XWINDOW (selected_window
)->must_be_updated_p
= 1;
6780 pause
= update_frame (selected_frame
, 0, 0);
6781 if (!pause
&& hscroll_windows (selected_window
))
6787 /* We may have called echo_area_display at the top of this
6788 function. If the echo area is on another frame, that may
6789 have put text on a frame other than the selected one, so the
6790 above call to update_frame would not have caught it. Catch
6793 Lisp_Object mini_window
;
6794 struct frame
*mini_frame
;
6796 mini_window
= FRAME_MINIBUF_WINDOW (selected_frame
);
6797 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6799 if (mini_frame
!= selected_frame
&& FRAME_WINDOW_P (mini_frame
))
6801 XWINDOW (mini_window
)->must_be_updated_p
= 1;
6802 pause
|= update_frame (mini_frame
, 0, 0);
6803 if (!pause
&& hscroll_windows (mini_window
))
6809 /* If display was paused because of pending input, make sure we do a
6810 thorough update the next time. */
6813 /* Prevent the optimization at the beginning of
6814 redisplay_internal that tries a single-line update of the
6815 line containing the cursor in the selected window. */
6816 CHARPOS (this_line_start_pos
) = 0;
6818 /* Let the overlay arrow be updated the next time. */
6819 if (!NILP (last_arrow_position
))
6821 last_arrow_position
= Qt
;
6822 last_arrow_string
= Qt
;
6825 /* If we pause after scrolling, some rows in the current
6826 matrices of some windows are not valid. */
6827 if (!WINDOW_FULL_WIDTH_P (w
)
6828 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
6829 update_mode_lines
= 1;
6832 /* Now text on frame agrees with windows, so put info into the
6833 windows for partial redisplay to follow. */
6836 register struct buffer
*b
= XBUFFER (w
->buffer
);
6838 unchanged_modified
= BUF_MODIFF (b
);
6839 overlay_unchanged_modified
= BUF_OVERLAY_MODIFF (b
);
6840 beg_unchanged
= BUF_GPT (b
) - BUF_BEG (b
);
6841 end_unchanged
= BUF_Z (b
) - BUF_GPT (b
);
6843 if (consider_all_windows_p
)
6844 mark_window_display_accurate (FRAME_ROOT_WINDOW (selected_frame
), 1);
6847 XSETFASTINT (w
->last_point
, BUF_PT (b
));
6848 w
->last_cursor
= w
->cursor
;
6849 w
->last_cursor_off_p
= w
->cursor_off_p
;
6851 b
->clip_changed
= 0;
6852 w
->update_mode_line
= Qnil
;
6853 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
6854 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
6856 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6859 /* Record if we are showing a region, so can make sure to
6860 update it fully at next redisplay. */
6861 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
6862 && (w
== XWINDOW (current_buffer
->last_selected_window
)
6863 || highlight_nonselected_windows
)
6864 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
6865 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
6868 w
->window_end_valid
= w
->buffer
;
6869 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
6870 last_arrow_string
= Voverlay_arrow_string
;
6871 if (frame_up_to_date_hook
!= 0)
6872 (*frame_up_to_date_hook
) (selected_frame
);
6875 update_mode_lines
= 0;
6876 windows_or_buffers_changed
= 0;
6879 /* Start SIGIO interrupts coming again. Having them off during the
6880 code above makes it less likely one will discard output, but not
6881 impossible, since there might be stuff in the system buffer here.
6882 But it is much hairier to try to do anything about that. */
6883 if (interrupt_input
)
6887 /* If a frame has become visible which was not before, redisplay
6888 again, so that we display it. Expose events for such a frame
6889 (which it gets when becoming visible) don't call the parts of
6890 redisplay constructing glyphs, so simply exposing a frame won't
6891 display anything in this case. So, we have to display these
6892 frames here explicitly. */
6895 Lisp_Object tail
, frame
;
6898 FOR_EACH_FRAME (tail
, frame
)
6900 int this_is_visible
= 0;
6902 if (XFRAME (frame
)->visible
)
6903 this_is_visible
= 1;
6904 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
6905 if (XFRAME (frame
)->visible
)
6906 this_is_visible
= 1;
6908 if (this_is_visible
)
6912 if (new_count
!= number_of_visible_frames
)
6913 windows_or_buffers_changed
++;
6916 /* Change frame size now if a change is pending. */
6917 do_pending_window_change ();
6919 /* If we just did a pending size change, or have additional
6920 visible frames, redisplay again. */
6921 if (windows_or_buffers_changed
&& !pause
)
6926 if (--redisplaying_p
< 0)
6931 /* Redisplay, but leave alone any recent echo area message unless
6932 another message has been requested in its place.
6934 This is useful in situations where you need to redisplay but no
6935 user action has occurred, making it inappropriate for the message
6936 area to be cleared. See tracking_off and
6937 wait_reading_process_input for examples of these situations. */
6940 redisplay_preserve_echo_area ()
6942 if (!echo_area_glyphs
6943 && !STRINGP (echo_area_message
)
6944 && (previous_echo_glyphs
6945 || STRINGP (previous_echo_area_message
)))
6947 echo_area_glyphs
= previous_echo_glyphs
;
6948 echo_area_message
= previous_echo_area_message
;
6949 echo_area_glyphs_length
= previous_echo_glyphs_length
;
6950 redisplay_internal (1);
6951 echo_area_glyphs
= NULL
;
6952 echo_area_message
= Qnil
;
6955 redisplay_internal (1);
6959 /* Mark the display of windows in the window tree rooted at WINDOW as
6960 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
6961 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
6962 the next time redisplay_internal is called. */
6965 mark_window_display_accurate (window
, accurate_p
)
6971 for (; !NILP (window
); window
= w
->next
)
6973 w
= XWINDOW (window
);
6975 if (BUFFERP (w
->buffer
))
6977 struct buffer
*b
= XBUFFER (w
->buffer
);
6979 XSETFASTINT (w
->last_modified
,
6980 accurate_p
? BUF_MODIFF (b
) : 0);
6981 XSETFASTINT (w
->last_overlay_modified
,
6982 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
6983 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
6986 #if 0 /* I don't think this is necessary because display_line does it.
6988 /* Record if we are showing a region, so can make sure to
6989 update it fully at next redisplay. */
6991 = (!NILP (Vtransient_mark_mode
)
6992 && (w
== XWINDOW (current_buffer
->last_selected_window
)
6993 || highlight_nonselected_windows
)
6994 && (!NILP (b
->mark_active
)
6995 ? Fmarker_position (b
->mark
)
7001 b
->clip_changed
= 0;
7002 w
->last_cursor
= w
->cursor
;
7003 w
->last_cursor_off_p
= w
->cursor_off_p
;
7004 if (w
== XWINDOW (selected_window
))
7005 w
->last_point
= BUF_PT (b
);
7007 w
->last_point
= XMARKER (w
->pointm
)->charpos
;
7011 w
->window_end_valid
= w
->buffer
;
7012 w
->update_mode_line
= Qnil
;
7014 if (!NILP (w
->vchild
))
7015 mark_window_display_accurate (w
->vchild
, accurate_p
);
7016 if (!NILP (w
->hchild
))
7017 mark_window_display_accurate (w
->hchild
, accurate_p
);
7022 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7023 last_arrow_string
= Voverlay_arrow_string
;
7027 /* Force a thorough redisplay the next time by setting
7028 last_arrow_position and last_arrow_string to t, which is
7029 unequal to any useful value of Voverlay_arrow_... */
7030 last_arrow_position
= Qt
;
7031 last_arrow_string
= Qt
;
7036 /* Return value in display table DP (Lisp_Char_Table *) for character
7037 C. Since a display table doesn't have any parent, we don't have to
7038 follow parent. Do not call this function directly but use the
7039 macro DISP_CHAR_VECTOR. */
7042 disp_char_vector (dp
, c
)
7043 struct Lisp_Char_Table
*dp
;
7049 if (SINGLE_BYTE_CHAR_P (c
))
7050 return (dp
->contents
[c
]);
7052 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
7053 if (code
[0] != CHARSET_COMPOSITION
)
7057 else if (code
[2] < 32)
7061 /* Here, the possible range of code[0] (== charset ID) is
7062 128..max_charset. Since the top level char table contains data
7063 for multibyte characters after 256th element, we must increment
7064 code[0] by 128 to get a correct index. */
7066 code
[3] = -1; /* anchor */
7068 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
7070 val
= dp
->contents
[code
[i
]];
7071 if (!SUB_CHAR_TABLE_P (val
))
7072 return (NILP (val
) ? dp
->defalt
: val
);
7075 /* Here, val is a sub char table. We return the default value of
7077 return (dp
->defalt
);
7082 /***********************************************************************
7084 ***********************************************************************/
7086 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
7089 redisplay_windows (window
)
7092 while (!NILP (window
))
7094 struct window
*w
= XWINDOW (window
);
7096 if (!NILP (w
->hchild
))
7097 redisplay_windows (w
->hchild
);
7098 else if (!NILP (w
->vchild
))
7099 redisplay_windows (w
->vchild
);
7101 redisplay_window (window
, 0);
7108 /* Set cursor position of W. PT is assumed to be displayed in ROW.
7109 DELTA is the number of bytes by which positions recorded in ROW
7110 differ from current buffer positions. */
7113 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
7115 struct glyph_row
*row
;
7116 struct glyph_matrix
*matrix
;
7117 int delta
, delta_bytes
, dy
, dvpos
;
7119 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
7120 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
7122 int pt_old
= PT
- delta
;
7124 /* Skip over glyphs not having an object at the start of the row.
7125 These are special glyphs like truncation marks on terminal
7127 if (row
->displays_text_p
)
7130 && glyph
->charpos
< 0)
7132 x
+= glyph
->pixel_width
;
7138 && (!BUFFERP (glyph
->object
)
7139 || glyph
->charpos
< pt_old
))
7141 x
+= glyph
->pixel_width
;
7145 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7147 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
7148 w
->cursor
.y
= row
->y
+ dy
;
7150 if (w
== XWINDOW (selected_window
))
7152 if (!row
->continued_p
7153 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
7156 this_line_buffer
= XBUFFER (w
->buffer
);
7158 CHARPOS (this_line_start_pos
)
7159 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
7160 BYTEPOS (this_line_start_pos
)
7161 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
7163 CHARPOS (this_line_end_pos
)
7164 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
7165 BYTEPOS (this_line_end_pos
)
7166 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
7168 this_line_y
= w
->cursor
.y
;
7169 this_line_pixel_height
= row
->height
;
7170 this_line_vpos
= w
->cursor
.vpos
;
7171 this_line_start_x
= row
->x
;
7174 CHARPOS (this_line_start_pos
) = 0;
7179 /* Run window scroll functions, if any, for WINDOW with new window
7180 start STARTP. Sets the window start of WINDOW to that position. */
7182 static INLINE
struct text_pos
7183 run_window_scroll_functions (window
, startp
)
7185 struct text_pos startp
;
7187 struct window
*w
= XWINDOW (window
);
7188 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
7190 if (!NILP (Vwindow_scroll_functions
))
7192 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
7193 make_number (CHARPOS (startp
)));
7194 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
7201 /* Modify the desired matrix of window W and W->vscroll so that the
7202 line containing the cursor is fully visible. */
7205 make_cursor_line_fully_visible (w
)
7208 struct glyph_matrix
*matrix
;
7209 struct glyph_row
*row
;
7210 int top_line_height
;
7212 /* It's not always possible to find the cursor, e.g, when a window
7213 is full of overlay strings. Don't do anything in that case. */
7214 if (w
->cursor
.vpos
< 0)
7217 matrix
= w
->desired_matrix
;
7218 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
7220 /* If row->y == top y of window display area, the window isn't tall
7221 enough to display a single line. There is nothing we can do
7223 top_line_height
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
7224 if (row
->y
== top_line_height
)
7227 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
7229 int dy
= row
->height
- row
->visible_height
;
7232 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
7234 else if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w
, row
))
7236 int dy
= - (row
->height
- row
->visible_height
);
7239 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
7242 /* When we change the cursor y-position of the selected window,
7243 change this_line_y as well so that the display optimization for
7244 the cursor line of the selected window in redisplay_internal uses
7245 the correct y-position. */
7246 if (w
== XWINDOW (selected_window
))
7247 this_line_y
= w
->cursor
.y
;
7251 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
7252 non-zero means only WINDOW is redisplayed in redisplay_internal.
7253 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
7254 in redisplay_window to bring a partially visible line into view in
7255 the case that only the cursor has moved.
7259 1 if scrolling succeeded
7261 0 if scrolling didn't find point.
7263 -1 if new fonts have been loaded so that we must interrupt
7264 redisplay, adjust glyph matrices, and try again. */
7267 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
7268 scroll_step
, temp_scroll_step
)
7270 int just_this_one_p
;
7271 int scroll_conservatively
, scroll_step
;
7272 int temp_scroll_step
;
7274 struct window
*w
= XWINDOW (window
);
7275 struct frame
*f
= XFRAME (w
->frame
);
7276 struct text_pos scroll_margin_pos
;
7277 struct text_pos pos
;
7278 struct text_pos startp
;
7280 Lisp_Object window_end
;
7281 int this_scroll_margin
;
7284 int line_height
, rc
;
7285 int amount_to_scroll
= 0;
7286 Lisp_Object aggressive
;
7290 debug_method_add (w
, "try_scrolling");
7293 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
7295 /* Compute scroll margin height in pixels. We scroll when point is
7296 within this distance from the top or bottom of the window. */
7297 if (scroll_margin
> 0)
7299 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
7300 this_scroll_margin
*= CANON_Y_UNIT (f
);
7303 this_scroll_margin
= 0;
7305 /* Compute how much we should try to scroll maximally to bring point
7308 scroll_max
= scroll_step
;
7309 else if (scroll_conservatively
)
7310 scroll_max
= scroll_conservatively
;
7311 else if (temp_scroll_step
)
7312 scroll_max
= temp_scroll_step
;
7313 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
7314 || NUMBERP (current_buffer
->scroll_up_aggressively
))
7315 /* We're trying to scroll because of aggressive scrolling
7316 but no scroll_step is set. Choose an arbitrary one. Maybe
7317 there should be a variable for this. */
7321 scroll_max
*= CANON_Y_UNIT (f
);
7323 /* Decide whether we have to scroll down. Start at the window end
7324 and move this_scroll_margin up to find the position of the scroll
7326 window_end
= Fwindow_end (window
, Qt
);
7327 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
7328 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
7329 if (this_scroll_margin
)
7331 start_display (&it
, w
, scroll_margin_pos
);
7332 move_it_vertically (&it
, - this_scroll_margin
);
7333 scroll_margin_pos
= it
.current
.pos
;
7336 if (PT
>= CHARPOS (scroll_margin_pos
))
7340 /* Point is in the scroll margin at the bottom of the window, or
7341 below. Compute a new window start that makes point visible. */
7343 /* Compute the distance from the scroll margin to PT.
7344 Give up if the distance is greater than scroll_max. */
7345 start_display (&it
, w
, scroll_margin_pos
);
7347 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
7348 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
7349 line_height
= (it
.max_ascent
+ it
.max_descent
7350 ? it
.max_ascent
+ it
.max_descent
7352 dy
= it
.current_y
+ line_height
- y0
;
7353 if (dy
> scroll_max
)
7356 /* Move the window start down. If scrolling conservatively,
7357 move it just enough down to make point visible. If
7358 scroll_step is set, move it down by scroll_step. */
7359 start_display (&it
, w
, startp
);
7361 if (scroll_conservatively
)
7362 amount_to_scroll
= dy
;
7363 else if (scroll_step
|| temp_scroll_step
)
7364 amount_to_scroll
= scroll_max
;
7367 aggressive
= current_buffer
->scroll_down_aggressively
;
7368 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
7369 - WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
));
7370 if (NUMBERP (aggressive
))
7371 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
7374 if (amount_to_scroll
<= 0)
7377 move_it_vertically (&it
, amount_to_scroll
);
7378 startp
= it
.current
.pos
;
7382 /* See if point is inside the scroll margin at the top of the
7384 scroll_margin_pos
= startp
;
7385 if (this_scroll_margin
)
7387 start_display (&it
, w
, startp
);
7388 move_it_vertically (&it
, this_scroll_margin
);
7389 scroll_margin_pos
= it
.current
.pos
;
7392 if (PT
< CHARPOS (scroll_margin_pos
))
7394 /* Point is in the scroll margin at the top of the window or
7395 above what is displayed in the window. */
7398 /* Compute the vertical distance from PT to the scroll
7399 margin position. Give up if distance is greater than
7401 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
7402 start_display (&it
, w
, pos
);
7404 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
7405 it
.last_visible_y
, -1,
7406 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
7407 dy
= it
.current_y
- y0
;
7408 if (dy
> scroll_max
)
7411 /* Compute new window start. */
7412 start_display (&it
, w
, startp
);
7414 if (scroll_conservatively
)
7415 amount_to_scroll
= dy
;
7416 else if (scroll_step
|| temp_scroll_step
)
7417 amount_to_scroll
= scroll_max
;
7420 aggressive
= current_buffer
->scroll_up_aggressively
;
7421 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
7422 - WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
));
7423 if (NUMBERP (aggressive
))
7424 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
7427 if (amount_to_scroll
<= 0)
7430 move_it_vertically (&it
, - amount_to_scroll
);
7431 startp
= it
.current
.pos
;
7435 /* Run window scroll functions. */
7436 startp
= run_window_scroll_functions (window
, startp
);
7438 /* Display the window. Give up if new fonts are loaded, or if point
7440 if (!try_window (window
, startp
))
7442 else if (w
->cursor
.vpos
< 0)
7444 clear_glyph_matrix (w
->desired_matrix
);
7449 /* Maybe forget recorded base line for line number display. */
7450 if (!just_this_one_p
7451 || current_buffer
->clip_changed
7452 || beg_unchanged
< CHARPOS (startp
))
7453 w
->base_line_number
= Qnil
;
7455 /* If cursor ends up on a partially visible line, shift display
7456 lines up or down. */
7457 make_cursor_line_fully_visible (w
);
7465 /* Compute a suitable window start for window W if display of W starts
7466 on a continuation line. Value is non-zero if a new window start
7469 The new window start will be computed, based on W's width, starting
7470 from the start of the continued line. It is the start of the
7471 screen line with the minimum distance from the old start W->start. */
7474 compute_window_start_on_continuation_line (w
)
7477 struct text_pos pos
, start_pos
;
7478 int window_start_changed_p
= 0;
7480 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
7482 /* If window start is on a continuation line... Window start may be
7483 < BEGV in case there's invisible text at the start of the
7484 buffer (M-x rmail, for example). */
7485 if (CHARPOS (start_pos
) > BEGV
7486 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
7489 struct glyph_row
*row
;
7491 /* Find the start of the continued line. This should be fast
7492 because scan_buffer is fast (newline cache). */
7493 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_TOP_LINE_P (w
) ? 1 : 0);
7494 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
7495 row
, DEFAULT_FACE_ID
);
7496 reseat_at_previous_visible_line_start (&it
);
7498 /* If the line start is "too far" away from the window start,
7499 say it takes too much time to compute a new window start. */
7500 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
7501 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
7503 int min_distance
, distance
;
7505 /* Move forward by display lines to find the new window
7506 start. If window width was enlarged, the new start can
7507 be expected to be > the old start. If window width was
7508 decreased, the new window start will be < the old start.
7509 So, we're looking for the display line start with the
7510 minimum distance from the old window start. */
7511 pos
= it
.current
.pos
;
7512 min_distance
= INFINITY
;
7513 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
7514 distance
< min_distance
)
7516 min_distance
= distance
;
7517 pos
= it
.current
.pos
;
7518 move_it_by_lines (&it
, 1, 0);
7521 /* Set the window start there. */
7522 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
7523 window_start_changed_p
= 1;
7527 return window_start_changed_p
;
7531 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
7532 selected_window is redisplayed. */
7535 redisplay_window (window
, just_this_one_p
)
7537 int just_this_one_p
;
7539 struct window
*w
= XWINDOW (window
);
7540 struct frame
*f
= XFRAME (w
->frame
);
7541 struct buffer
*buffer
= XBUFFER (w
->buffer
);
7542 struct buffer
*old
= current_buffer
;
7543 struct text_pos lpoint
, opoint
, startp
;
7544 int update_mode_line
;
7547 /* Record it now because it's overwritten. */
7548 int current_matrix_up_to_date_p
= 0;
7549 int really_switched_buffer
= 0;
7550 int temp_scroll_step
= 0;
7551 int count
= specpdl_ptr
- specpdl
;
7553 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
7556 /* W must be a leaf window here. */
7557 xassert (!NILP (w
->buffer
));
7559 *w
->desired_matrix
->method
= 0;
7562 specbind (Qinhibit_point_motion_hooks
, Qt
);
7564 /* Has the mode line to be updated? */
7565 update_mode_line
= (!NILP (w
->update_mode_line
)
7566 || update_mode_lines
7567 || buffer
->clip_changed
);
7569 if (MINI_WINDOW_P (w
))
7571 if (w
== XWINDOW (echo_area_window
)
7572 && (echo_area_glyphs
7573 || STRINGP (echo_area_message
)))
7575 if (update_mode_line
)
7576 /* We may have to update a tty frame's menu bar or a
7577 toolbar. Example `M-x C-h C-h C-g'. */
7578 goto finish_menu_bars
;
7580 /* We've already displayed the echo area glyphs in this window. */
7581 goto finish_scroll_bars
;
7583 else if (w
!= XWINDOW (minibuf_window
))
7585 /* W is a mini-buffer window, but it's not the currently
7586 active one, so clear it. */
7587 int yb
= window_text_bottom_y (w
);
7588 struct glyph_row
*row
;
7591 for (y
= 0, row
= w
->desired_matrix
->rows
;
7593 y
+= row
->height
, ++row
)
7594 blank_row (w
, row
, y
);
7595 goto finish_scroll_bars
;
7599 /* Otherwise set up data on this window; select its buffer and point
7601 if (update_mode_line
)
7603 /* Really select the buffer, for the sake of buffer-local
7605 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7606 really_switched_buffer
= 1;
7609 set_buffer_temp (XBUFFER (w
->buffer
));
7610 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
7612 current_matrix_up_to_date_p
7613 = (!NILP (w
->window_end_valid
)
7614 && !current_buffer
->clip_changed
7615 && XFASTINT (w
->last_modified
) >= MODIFF
7616 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
7618 /* When windows_or_buffers_changed is non-zero, we can't rely on
7619 the window end being valid, so set it to nil there. */
7620 if (windows_or_buffers_changed
)
7622 /* If window starts on a continuation line, maybe adjust the
7623 window start in case the window's width changed. */
7624 if (XMARKER (w
->start
)->buffer
== current_buffer
)
7625 compute_window_start_on_continuation_line (w
);
7627 w
->window_end_valid
= Qnil
;
7630 /* Some sanity checks. */
7631 CHECK_WINDOW_END (w
);
7632 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
7634 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
7637 /* If %c is in mode line, update it if needed. */
7638 if (!NILP (w
->column_number_displayed
)
7639 /* This alternative quickly identifies a common case
7640 where no change is needed. */
7641 && !(PT
== XFASTINT (w
->last_point
)
7642 && XFASTINT (w
->last_modified
) >= MODIFF
7643 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7644 && XFASTINT (w
->column_number_displayed
) != current_column ())
7645 update_mode_line
= 1;
7647 /* Count number of windows showing the selected buffer. An indirect
7648 buffer counts as its base buffer. */
7649 if (!just_this_one_p
)
7651 struct buffer
*current_base
, *window_base
;
7652 current_base
= current_buffer
;
7653 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
7654 if (current_base
->base_buffer
)
7655 current_base
= current_base
->base_buffer
;
7656 if (window_base
->base_buffer
)
7657 window_base
= window_base
->base_buffer
;
7658 if (current_base
== window_base
)
7662 /* Point refers normally to the selected window. For any other
7663 window, set up appropriate value. */
7664 if (!EQ (window
, selected_window
))
7666 int new_pt
= XMARKER (w
->pointm
)->charpos
;
7667 int new_pt_byte
= marker_byte_position (w
->pointm
);
7671 new_pt_byte
= BEGV_BYTE
;
7672 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
7674 else if (new_pt
> (ZV
- 1))
7677 new_pt_byte
= ZV_BYTE
;
7678 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
7681 /* We don't use SET_PT so that the point-motion hooks don't run. */
7682 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
7685 /* If any of the character widths specified in the display table
7686 have changed, invalidate the width run cache. It's true that
7687 this may be a bit late to catch such changes, but the rest of
7688 redisplay goes (non-fatally) haywire when the display table is
7689 changed, so why should we worry about doing any better? */
7690 if (current_buffer
->width_run_cache
)
7692 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
7694 if (! disptab_matches_widthtab (disptab
,
7695 XVECTOR (current_buffer
->width_table
)))
7697 invalidate_region_cache (current_buffer
,
7698 current_buffer
->width_run_cache
,
7700 recompute_width_table (current_buffer
, disptab
);
7704 /* If window-start is screwed up, choose a new one. */
7705 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
7708 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
7710 /* If someone specified a new starting point but did not insist,
7711 check whether it can be used. */
7712 if (!NILP (w
->optional_new_start
))
7714 w
->optional_new_start
= Qnil
;
7715 /* This takes a mini-buffer prompt into account. */
7716 start_display (&it
, w
, startp
);
7717 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
7718 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
7719 if (IT_CHARPOS (it
) == PT
)
7720 w
->force_start
= Qt
;
7723 /* Handle case where place to start displaying has been specified,
7724 unless the specified location is outside the accessible range. */
7725 if (!NILP (w
->force_start
))
7727 w
->force_start
= Qnil
;
7729 w
->window_end_valid
= Qnil
;
7731 /* Forget any recorded base line for line number display. */
7732 if (!current_matrix_up_to_date_p
7733 || current_buffer
->clip_changed
)
7734 w
->base_line_number
= Qnil
;
7736 /* Redisplay the mode line. Select the buffer properly for that.
7737 Also, run the hook window-scroll-functions
7738 because we have scrolled. */
7739 /* Note, we do this after clearing force_start because
7740 if there's an error, it is better to forget about force_start
7741 than to get into an infinite loop calling the hook functions
7742 and having them get more errors. */
7743 if (!update_mode_line
7744 || ! NILP (Vwindow_scroll_functions
))
7746 if (!really_switched_buffer
)
7748 set_buffer_temp (old
);
7749 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7750 really_switched_buffer
= 1;
7753 update_mode_line
= 1;
7754 w
->update_mode_line
= Qt
;
7755 startp
= run_window_scroll_functions (window
, startp
);
7758 XSETFASTINT (w
->last_modified
, 0);
7759 XSETFASTINT (w
->last_overlay_modified
, 0);
7760 if (CHARPOS (startp
) < BEGV
)
7761 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
7762 else if (CHARPOS (startp
) > ZV
)
7763 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
7765 /* Redisplay, then check if cursor has been set during the
7766 redisplay. Give up if new fonts were loaded. */
7767 if (!try_window (window
, startp
))
7769 w
->force_start
= Qt
;
7770 clear_glyph_matrix (w
->desired_matrix
);
7771 goto restore_buffers
;
7774 if (w
->cursor
.vpos
< 0)
7776 /* If point does not appear, or on a line that is not fully
7777 visible, move point so it does appear. The desired
7778 matrix has been built above, so we can use it. */
7779 int height
= window_box_height (w
) / 2;
7780 struct glyph_row
*row
= MATRIX_ROW (w
->desired_matrix
, 0);
7782 while (row
->y
< height
)
7785 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
7786 MATRIX_ROW_START_BYTEPOS (row
));
7788 if (w
!= XWINDOW (selected_window
))
7789 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
7790 else if (current_buffer
== old
)
7791 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
7793 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
7795 /* If we are highlighting the region, then we just changed
7796 the region, so redisplay to show it. */
7797 if (!NILP (Vtransient_mark_mode
)
7798 && !NILP (current_buffer
->mark_active
))
7800 clear_glyph_matrix (w
->desired_matrix
);
7801 if (!try_window (window
, startp
))
7802 goto restore_buffers
;
7806 make_cursor_line_fully_visible (w
);
7808 debug_method_add (w
, "forced window start");
7813 /* Handle case where text has not changed, only point, and it has
7814 not moved off the frame. */
7815 if (current_matrix_up_to_date_p
7816 /* Point may be in this window. */
7817 && PT
>= CHARPOS (startp
)
7818 /* If we don't check this, we are called to move the cursor in a
7819 horizontally split window with a current matrix that doesn't
7821 && !windows_or_buffers_changed
7822 /* Selective display hasn't changed. */
7823 && !current_buffer
->clip_changed
7824 /* If force-mode-line-update was called, really redisplay;
7825 that's how redisplay is forced after e.g. changing
7826 buffer-invisibility-spec. */
7827 && NILP (w
->update_mode_line
)
7828 /* Can't use this case if highlighting a region. When a
7829 region exists, cursor movement has to do more than just
7831 && !(!NILP (Vtransient_mark_mode
)
7832 && !NILP (current_buffer
->mark_active
))
7833 && NILP (w
->region_showing
)
7834 /* Right after splitting windows, last_point may be nil. */
7835 && INTEGERP (w
->last_point
)
7836 /* This code is not used for mini-buffer for the sake of the case
7837 of redisplaying to replace an echo area message; since in
7838 that case the mini-buffer contents per se are usually
7839 unchanged. This code is of no real use in the mini-buffer
7840 since the handling of this_line_start_pos, etc., in redisplay
7841 handles the same cases. */
7842 && !EQ (window
, minibuf_window
)
7843 /* When splitting windows or for new windows, it happens that
7844 redisplay is called with a nil window_end_vpos or one being
7845 larger than the window. This should really be fixed in
7846 window.c. I don't have this on my list, now, so we do
7847 approximately the same as the old redisplay code. --gerd. */
7848 && INTEGERP (w
->window_end_vpos
)
7849 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
7850 && (FRAME_WINDOW_P (f
)
7851 || !MARKERP (Voverlay_arrow_position
)
7852 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
7854 int this_scroll_margin
;
7855 struct glyph_row
*row
;
7859 debug_method_add (w
, "cursor movement");
7862 /* Scroll if point within this distance from the top or bottom
7863 of the window. This is a pixel value. */
7864 this_scroll_margin
= max (0, scroll_margin
);
7865 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
7866 this_scroll_margin
*= CANON_Y_UNIT (f
);
7868 /* Start with the row the cursor was displayed during the last
7869 not paused redisplay. Give up if that row is not valid. */
7870 if (w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
7872 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
7873 if (row
->mode_line_p
)
7875 if (!row
->enabled_p
)
7879 if (PT
> XFASTINT (w
->last_point
))
7881 /* Point has moved forward. */
7882 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
7884 while ((MATRIX_ROW_END_CHARPOS (row
) < PT
7885 /* The end position of a row equals the start
7886 position of the next row. If PT is there, we
7887 would rather display it in the next line, except
7888 when this line ends in ZV. */
7889 || (MATRIX_ROW_END_CHARPOS (row
) == PT
7890 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
7891 || !row
->ends_at_zv_p
)))
7892 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
7894 xassert (row
->enabled_p
);
7898 /* If within the scroll margin, scroll. Note that
7899 MATRIX_ROW_BOTTOM_Y gives the pixel position at which the
7900 next line would be drawn, and that this_scroll_margin can
7902 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
7903 || PT
> MATRIX_ROW_END_CHARPOS (row
)
7904 /* Line is completely visible last line in window and PT
7905 is to be set in the next line. */
7906 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
7907 && PT
== MATRIX_ROW_END_CHARPOS (row
)
7908 && !row
->ends_at_zv_p
7909 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
7912 else if (PT
< XFASTINT (w
->last_point
))
7914 /* Cursor has to be moved backward. Note that PT >=
7915 CHARPOS (startp) because of the outer if-statement. */
7916 while (!row
->mode_line_p
7917 && (MATRIX_ROW_START_CHARPOS (row
) > PT
7918 || (MATRIX_ROW_START_CHARPOS (row
) == PT
7919 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
7920 && (row
->y
> this_scroll_margin
7921 || CHARPOS (startp
) == BEGV
))
7923 xassert (row
->enabled_p
);
7927 /* Consider the following case: Window starts at BEGV, there
7928 is invisible, intangible text at BEGV, so that display
7929 starts at some point START > BEGV. It can happen that
7930 we are called with PT somewhere between BEGV and START.
7931 Try to handle that case. */
7932 if (row
< w
->current_matrix
->rows
7933 || row
->mode_line_p
)
7935 row
= w
->current_matrix
->rows
;
7936 if (row
->mode_line_p
)
7940 /* Due to newlines in overlay strings, we may have to skip
7941 forward over overlay strings. */
7942 while (MATRIX_ROW_END_CHARPOS (row
) == PT
7943 && MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P (row
)
7944 && !row
->ends_at_zv_p
)
7947 /* If within the scroll margin, scroll. */
7948 if (row
->y
< this_scroll_margin
7949 && CHARPOS (startp
) != BEGV
)
7953 /* if PT is not in the glyph row, give up. */
7954 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
7955 || PT
> MATRIX_ROW_END_CHARPOS (row
))
7958 /* If we end up in a partially visible line, let's make it fully
7959 visible. This can be done most easily by using the existing
7961 if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
7963 temp_scroll_step
= 1;
7969 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
7973 /* If current starting point was originally the beginning of a line
7974 but no longer is, find a new starting point. */
7975 else if (!NILP (w
->start_at_line_beg
)
7976 && !(CHARPOS (startp
) <= BEGV
7977 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
7980 debug_method_add (w
, "recenter 1");
7985 /* Try scrolling with try_window_id. */
7986 else if (!windows_or_buffers_changed
7987 /* Window must be either use window-based redisplay or
7989 && (FRAME_WINDOW_P (f
)
7990 || ((line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
))
7991 && just_this_one_p
))
7992 && !MINI_WINDOW_P (w
)
7993 /* Point is not known NOT to appear in window. */
7994 && PT
>= CHARPOS (startp
)
7995 && XFASTINT (w
->last_modified
)
7996 /* Window is not hscrolled. */
7997 && XFASTINT (w
->hscroll
) == 0
7998 /* Selective display has not changed. */
7999 && !current_buffer
->clip_changed
8000 /* Current matrix is up to date. */
8001 && !NILP (w
->window_end_valid
)
8002 /* Can't use this case if highlighting a region because
8003 a cursor movement will do more than just set the cursor. */
8004 && !(!NILP (Vtransient_mark_mode
)
8005 && !NILP (current_buffer
->mark_active
))
8006 && NILP (w
->region_showing
)
8007 /* Overlay arrow position and string not changed. */
8008 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
8009 && EQ (last_arrow_string
, Voverlay_arrow_string
)
8010 /* Value is > 0 if update has been done, it is -1 if we
8011 know that the same window start will not work. It is 0
8012 if unsuccessful for some other reason. */
8013 && (tem
= try_window_id (w
)) != 0)
8016 debug_method_add (w
, "try_window_id");
8019 if (fonts_changed_p
)
8020 goto restore_buffers
;
8023 /* Otherwise try_window_id has returned -1 which means that we
8024 don't want the alternative below this comment to execute. */
8026 else if (CHARPOS (startp
) >= BEGV
8027 && CHARPOS (startp
) <= ZV
8028 && PT
>= CHARPOS (startp
)
8029 && (CHARPOS (startp
) < ZV
8030 /* Avoid starting at end of buffer. */
8031 || CHARPOS (startp
) == BEGV
8032 || (XFASTINT (w
->last_modified
) >= MODIFF
8033 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
8036 debug_method_add (w
, "same window start");
8039 /* Try to redisplay starting at same place as before.
8040 If point has not moved off frame, accept the results. */
8041 if (!current_matrix_up_to_date_p
8042 /* Don't use try_window_reusing_current_matrix in this case
8043 because it can have changed the buffer. */
8044 || !NILP (Vwindow_scroll_functions
)
8045 || MINI_WINDOW_P (w
)
8046 || !try_window_reusing_current_matrix (w
))
8048 IF_DEBUG (debug_method_add (w
, "1"));
8049 try_window (window
, startp
);
8052 if (fonts_changed_p
)
8053 goto restore_buffers
;
8055 if (w
->cursor
.vpos
>= 0)
8057 if (!just_this_one_p
8058 || current_buffer
->clip_changed
8059 || beg_unchanged
< CHARPOS (startp
))
8060 /* Forget any recorded base line for line number display. */
8061 w
->base_line_number
= Qnil
;
8063 make_cursor_line_fully_visible (w
);
8067 clear_glyph_matrix (w
->desired_matrix
);
8072 XSETFASTINT (w
->last_modified
, 0);
8073 XSETFASTINT (w
->last_overlay_modified
, 0);
8075 /* Redisplay the mode line. Select the buffer properly for that. */
8076 if (!update_mode_line
)
8078 if (!really_switched_buffer
)
8080 set_buffer_temp (old
);
8081 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8082 really_switched_buffer
= 1;
8084 update_mode_line
= 1;
8085 w
->update_mode_line
= Qt
;
8088 /* Try to scroll by specified few lines. */
8089 if ((scroll_conservatively
8092 || NUMBERP (current_buffer
->scroll_up_aggressively
)
8093 || NUMBERP (current_buffer
->scroll_down_aggressively
))
8094 && !current_buffer
->clip_changed
8095 && CHARPOS (startp
) >= BEGV
8096 && CHARPOS (startp
) <= ZV
)
8098 /* The function returns -1 if new fonts were loaded, 1 if
8099 successful, 0 if not successful. */
8100 int rc
= try_scrolling (window
, just_this_one_p
,
8101 scroll_conservatively
,
8107 goto restore_buffers
;
8110 /* Finally, just choose place to start which centers point */
8115 debug_method_add (w
, "recenter");
8118 /* w->vscroll = 0; */
8120 /* Forget any previously recorded base line for line number display. */
8121 if (!current_matrix_up_to_date_p
8122 || current_buffer
->clip_changed
)
8123 w
->base_line_number
= Qnil
;
8125 /* Move backward half the height of the window. */
8126 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
8127 it
.current_y
= it
.last_visible_y
;
8128 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
8129 xassert (IT_CHARPOS (it
) >= BEGV
);
8131 /* The function move_it_vertically_backward may move over more
8132 than the specified y-distance. If it->w is small, e.g. a
8133 mini-buffer window, we may end up in front of the window's
8134 display area. Start displaying at the start of the line
8135 containing PT in this case. */
8136 if (it
.current_y
<= 0)
8138 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
8139 move_it_vertically (&it
, 0);
8140 xassert (IT_CHARPOS (it
) <= PT
);
8144 it
.current_x
= it
.hpos
= 0;
8146 /* Set startp here explicitly in case that helps avoid an infinite loop
8147 in case the window-scroll-functions functions get errors. */
8148 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
8150 /* Run scroll hooks. */
8151 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
8153 /* Redisplay the window. */
8154 if (!current_matrix_up_to_date_p
8155 || windows_or_buffers_changed
8156 /* Don't use try_window_reusing_current_matrix in this case
8157 because it can have changed the buffer. */
8158 || !NILP (Vwindow_scroll_functions
)
8160 || MINI_WINDOW_P (w
)
8161 || !try_window_reusing_current_matrix (w
))
8162 try_window (window
, startp
);
8164 /* If new fonts have been loaded (due to fontsets), give up. We
8165 have to start a new redisplay since we need to re-adjust glyph
8167 if (fonts_changed_p
)
8168 goto restore_buffers
;
8170 /* If cursor did not appear assume that the middle of the window is
8171 in the first line of the window. Do it again with the next line.
8172 (Imagine a window of height 100, displaying two lines of height
8173 60. Moving back 50 from it->last_visible_y will end in the first
8175 if (w
->cursor
.vpos
< 0)
8177 if (!NILP (w
->window_end_valid
)
8178 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
8180 clear_glyph_matrix (w
->desired_matrix
);
8181 move_it_by_lines (&it
, 1, 0);
8182 try_window (window
, it
.current
.pos
);
8184 else if (PT
< IT_CHARPOS (it
))
8186 clear_glyph_matrix (w
->desired_matrix
);
8187 move_it_by_lines (&it
, -1, 0);
8188 try_window (window
, it
.current
.pos
);
8192 /* Not much we can do about it. */
8196 /* Consider the following case: Window starts at BEGV, there is
8197 invisible, intangible text at BEGV, so that display starts at
8198 some point START > BEGV. It can happen that we are called with
8199 PT somewhere between BEGV and START. Try to handle that case. */
8200 if (w
->cursor
.vpos
< 0)
8202 struct glyph_row
*row
= w
->current_matrix
->rows
;
8203 if (row
->mode_line_p
)
8205 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8208 make_cursor_line_fully_visible (w
);
8210 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8211 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
8212 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
8217 /* Display the mode line, if we must. */
8218 if ((update_mode_line
8219 /* If window not full width, must redo its mode line
8220 if (a) the window to its side is being redone and
8221 (b) we do a frame-based redisplay. This is a consequence
8222 of how inverted lines are drawn in frame-based redisplay. */
8223 || (!just_this_one_p
8224 && !FRAME_WINDOW_P (f
)
8225 && !WINDOW_FULL_WIDTH_P (w
))
8226 /* Line number to display. */
8227 || INTEGERP (w
->base_line_pos
)
8228 /* Column number is displayed and different from the one displayed. */
8229 || (!NILP (w
->column_number_displayed
)
8230 && XFASTINT (w
->column_number_displayed
) != current_column ()))
8231 /* This means that the window has a mode line. */
8232 && (WINDOW_WANTS_MODELINE_P (w
)
8233 || WINDOW_WANTS_TOP_LINE_P (w
)))
8235 display_mode_lines (w
);
8237 /* If mode line height has changed, arrange for a thorough
8238 immediate redisplay using the correct mode line height. */
8239 if (WINDOW_WANTS_MODELINE_P (w
)
8240 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
8242 fonts_changed_p
= 1;
8243 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
8244 = DESIRED_MODE_LINE_HEIGHT (w
);
8247 /* If top line height has changed, arrange for a thorough
8248 immediate redisplay using the correct mode line height. */
8249 if (WINDOW_WANTS_TOP_LINE_P (w
)
8250 && CURRENT_TOP_LINE_HEIGHT (w
) != DESIRED_TOP_LINE_HEIGHT (w
))
8252 fonts_changed_p
= 1;
8253 MATRIX_TOP_LINE_ROW (w
->current_matrix
)->height
8254 = DESIRED_TOP_LINE_HEIGHT (w
);
8257 if (fonts_changed_p
)
8258 goto restore_buffers
;
8261 if (!line_number_displayed
8262 && !BUFFERP (w
->base_line_pos
))
8264 w
->base_line_pos
= Qnil
;
8265 w
->base_line_number
= Qnil
;
8270 /* When we reach a frame's selected window, redo the frame's menu bar. */
8271 if (update_mode_line
8272 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
8274 int redisplay_menu_p
= 0;
8276 if (FRAME_WINDOW_P (f
))
8278 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
8279 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
8281 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
8285 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
8287 if (redisplay_menu_p
)
8288 display_menu_bar (w
);
8290 #ifdef HAVE_WINDOW_SYSTEM
8291 if (WINDOWP (f
->toolbar_window
)
8292 && (FRAME_TOOLBAR_LINES (f
) > 0
8293 || auto_resize_toolbars_p
))
8294 redisplay_toolbar (f
);
8300 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8302 int start
, end
, whole
;
8304 /* Calculate the start and end positions for the current window.
8305 At some point, it would be nice to choose between scrollbars
8306 which reflect the whole buffer size, with special markers
8307 indicating narrowing, and scrollbars which reflect only the
8310 Note that mini-buffers sometimes aren't displaying any text. */
8311 if (! MINI_WINDOW_P (w
)
8312 || (w
== XWINDOW (minibuf_window
)
8313 && !echo_area_glyphs
8314 && !STRINGP (echo_area_message
)))
8317 start
= marker_position (w
->start
) - BEGV
;
8318 /* I don't think this is guaranteed to be right. For the
8319 moment, we'll pretend it is. */
8320 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
8324 if (whole
< (end
- start
))
8325 whole
= end
- start
;
8328 start
= end
= whole
= 0;
8330 /* Indicate what this scroll bar ought to be displaying now. */
8331 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
8333 /* Note that we actually used the scroll bar attached to this
8334 window, so it shouldn't be deleted at the end of redisplay. */
8335 (*redeem_scroll_bar_hook
) (w
);
8340 /* Restore current_buffer and value of point in it. */
8341 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
8342 if (really_switched_buffer
)
8343 set_buffer_internal_1 (old
);
8345 set_buffer_temp (old
);
8346 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
8348 unbind_to (count
, Qnil
);
8352 /* Build the complete desired matrix of WINDOW with a window start
8353 buffer position POS. Value is non-zero if successful. It is zero
8354 if fonts were loaded during redisplay which makes re-adjusting
8355 glyph matrices necessary. */
8358 try_window (window
, pos
)
8360 struct text_pos pos
;
8362 struct window
*w
= XWINDOW (window
);
8364 struct glyph_row
*last_text_row
= NULL
;
8366 /* Make POS the new window start. */
8367 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
8369 /* Mark cursor position as unknown. No overlay arrow seen. */
8370 w
->cursor
.vpos
= -1;
8371 overlay_arrow_seen
= 0;
8373 /* Initialize iterator and info to start at POS. */
8374 start_display (&it
, w
, pos
);
8376 /* Display all lines of W. */
8377 while (it
.current_y
< it
.last_visible_y
)
8379 if (display_line (&it
))
8380 last_text_row
= it
.glyph_row
- 1;
8381 if (fonts_changed_p
)
8385 /* If bottom moved off end of frame, change mode line percentage. */
8386 if (XFASTINT (w
->window_end_pos
) <= 0
8387 && Z
!= IT_CHARPOS (it
))
8388 w
->update_mode_line
= Qt
;
8390 /* Set window_end_pos to the offset of the last character displayed
8391 on the window from the end of current_buffer. Set
8392 window_end_vpos to its row number. */
8395 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
8396 w
->window_end_bytepos
8397 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
8398 XSETFASTINT (w
->window_end_pos
,
8399 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
8400 XSETFASTINT (w
->window_end_vpos
,
8401 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
8402 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
8407 w
->window_end_bytepos
= 0;
8408 XSETFASTINT (w
->window_end_pos
, 0);
8409 XSETFASTINT (w
->window_end_vpos
, 0);
8412 /* But that is not valid info until redisplay finishes. */
8413 w
->window_end_valid
= Qnil
;
8419 /************************************************************************
8420 Window redisplay reusing current matrix when buffer has not changed
8421 ************************************************************************/
8423 /* Try redisplay of window W showing an unchanged buffer with a
8424 different window start than the last time it was displayed by
8425 reusing its current matrix. Value is non-zero if successful.
8426 W->start is the new window start. */
8429 try_window_reusing_current_matrix (w
)
8432 struct frame
*f
= XFRAME (w
->frame
);
8433 struct glyph_row
*row
, *bottom_row
;
8436 struct text_pos start
, new_start
;
8437 int nrows_scrolled
, i
;
8438 struct glyph_row
*last_text_row
;
8439 struct glyph_row
*last_reused_text_row
;
8440 struct glyph_row
*start_row
;
8441 int start_vpos
, min_y
, max_y
;
8443 /* Right now this function doesn't handle terminal frames. */
8444 if (!FRAME_WINDOW_P (f
))
8447 /* Can't do this if region may have changed. */
8448 if ((!NILP (Vtransient_mark_mode
)
8449 && !NILP (current_buffer
->mark_active
))
8450 || !NILP (w
->region_showing
))
8453 /* If top-line visibility has changed, give up. */
8454 if (WINDOW_WANTS_TOP_LINE_P (w
)
8455 != MATRIX_TOP_LINE_ROW (w
->current_matrix
)->mode_line_p
)
8458 /* Give up if old or new display is scrolled vertically. We could
8459 make this function handle this, but right now it doesn't. */
8460 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8461 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
8464 /* The variable new_start now holds the new window start. The old
8465 start `start' can be determined from the current matrix. */
8466 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
8467 start
= start_row
->start
.pos
;
8468 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
8470 /* Clear the desired matrix for the display below. */
8471 clear_glyph_matrix (w
->desired_matrix
);
8473 if (CHARPOS (new_start
) <= CHARPOS (start
))
8477 IF_DEBUG (debug_method_add (w
, "twu1"));
8479 /* Display up to a row that can be reused. The variable
8480 last_text_row is set to the last row displayed that displays
8482 start_display (&it
, w
, new_start
);
8483 first_row_y
= it
.current_y
;
8484 w
->cursor
.vpos
= -1;
8485 last_text_row
= last_reused_text_row
= NULL
;
8486 while (it
.current_y
< it
.last_visible_y
8487 && IT_CHARPOS (it
) < CHARPOS (start
)
8488 && !fonts_changed_p
)
8489 if (display_line (&it
))
8490 last_text_row
= it
.glyph_row
- 1;
8492 /* A value of current_y < last_visible_y means that we stopped
8493 at the previous window start, which in turn means that we
8494 have at least one reusable row. */
8495 if (it
.current_y
< it
.last_visible_y
)
8497 nrows_scrolled
= it
.vpos
;
8499 /* Find PT if not already found in the lines displayed. */
8500 if (w
->cursor
.vpos
< 0)
8502 int dy
= it
.current_y
- first_row_y
;
8504 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8505 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
8507 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
8508 && PT
< MATRIX_ROW_END_CHARPOS (row
))
8510 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
8511 dy
, nrows_scrolled
);
8515 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
8521 /* Give up if point was not found. This shouldn't
8522 happen often; not more often than with try_window
8524 if (w
->cursor
.vpos
< 0)
8526 clear_glyph_matrix (w
->desired_matrix
);
8531 /* Scroll the display. Do it before the current matrix is
8532 changed. The problem here is that update has not yet
8533 run, i.e. part of the current matrix is not up to date.
8534 scroll_run_hook will clear the cursor, and use the
8535 current matrix to get the height of the row the cursor is
8537 run
.current_y
= first_row_y
;
8538 run
.desired_y
= it
.current_y
;
8539 run
.height
= it
.last_visible_y
- it
.current_y
;
8543 rif
->update_window_begin_hook (w
);
8544 rif
->scroll_run_hook (w
, &run
);
8545 rif
->update_window_end_hook (w
, 0);
8549 /* Shift current matrix down by nrows_scrolled lines. */
8550 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
8551 rotate_matrix (w
->current_matrix
,
8553 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
8556 /* Disable lines not reused. */
8557 for (i
= 0; i
< it
.vpos
; ++i
)
8558 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
8560 /* Re-compute Y positions. */
8561 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
) + nrows_scrolled
;
8562 min_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
8563 max_y
= it
.last_visible_y
;
8564 while (row
< bottom_row
)
8566 row
->y
= it
.current_y
;
8569 row
->visible_height
= row
->height
- (min_y
- row
->y
);
8570 else if (row
->y
+ row
->height
> max_y
)
8572 = row
->height
- (row
->y
+ row
->height
- max_y
);
8574 row
->visible_height
= row
->height
;
8576 it
.current_y
+= row
->height
;
8579 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
8580 last_reused_text_row
= row
;
8581 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
8587 /* Update window_end_pos etc.; last_reused_text_row is the last
8588 reused row from the current matrix containing text, if any.
8589 The value of last_text_row is the last displayed line
8591 if (last_reused_text_row
)
8593 w
->window_end_bytepos
8594 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
8595 XSETFASTINT (w
->window_end_pos
,
8596 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
8597 XSETFASTINT (w
->window_end_vpos
,
8598 MATRIX_ROW_VPOS (last_reused_text_row
,
8599 w
->current_matrix
));
8601 else if (last_text_row
)
8603 w
->window_end_bytepos
8604 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
8605 XSETFASTINT (w
->window_end_pos
,
8606 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
8607 XSETFASTINT (w
->window_end_vpos
,
8608 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
8612 /* This window must be completely empty. */
8613 w
->window_end_bytepos
= 0;
8614 XSETFASTINT (w
->window_end_pos
, 0);
8615 XSETFASTINT (w
->window_end_vpos
, 0);
8617 w
->window_end_valid
= Qnil
;
8619 /* Update hint: don't try scrolling again in update_window. */
8620 w
->desired_matrix
->no_scrolling_p
= 1;
8623 debug_method_add (w
, "try_window_reusing_current_matrix 1");
8627 else if (CHARPOS (new_start
) > CHARPOS (start
))
8629 struct glyph_row
*pt_row
, *row
;
8630 struct glyph_row
*first_reusable_row
;
8631 struct glyph_row
*first_row_to_display
;
8633 int yb
= window_text_bottom_y (w
);
8635 IF_DEBUG (debug_method_add (w
, "twu2"));
8637 /* Find the row starting at new_start, if there is one. Don't
8638 reuse a partially visible line at the end. */
8639 first_reusable_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8640 while (first_reusable_row
->enabled_p
8641 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
8642 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
8643 < CHARPOS (new_start
)))
8644 ++first_reusable_row
;
8646 /* Give up if there is no row to reuse. */
8647 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
8648 || !first_reusable_row
->enabled_p
)
8651 /* The row we found must start at new_start, or else something
8653 xassert (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
8654 == CHARPOS (new_start
));
8656 /* We can reuse fully visible rows beginning with
8657 first_reusable_row to the end of the window. Set
8658 first_row_to_display to the first row that cannot be reused.
8659 Set pt_row to the row containing point, if there is any. */
8660 first_row_to_display
= first_reusable_row
;
8662 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
8664 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
8665 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
8666 pt_row
= first_row_to_display
;
8668 ++first_row_to_display
;
8671 /* Start displaying at the start of first_row_to_display. */
8672 xassert (first_row_to_display
->y
< yb
);
8673 init_to_row_start (&it
, w
, first_row_to_display
);
8674 nrows_scrolled
= MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
);
8675 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
8677 it
.current_y
= first_row_to_display
->y
- first_reusable_row
->y
;
8679 /* Display lines beginning with first_row_to_display in the
8680 desired matrix. Set last_text_row to the last row displayed
8681 that displays text. */
8682 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
8684 w
->cursor
.vpos
= -1;
8685 last_text_row
= NULL
;
8686 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
8687 if (display_line (&it
))
8688 last_text_row
= it
.glyph_row
- 1;
8690 /* Give up If point isn't in a row displayed or reused. */
8691 if (w
->cursor
.vpos
< 0)
8693 clear_glyph_matrix (w
->desired_matrix
);
8697 /* If point is in a reused row, adjust y and vpos of the cursor
8701 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
8703 w
->cursor
.y
-= first_reusable_row
->y
;
8706 /* Scroll the display. */
8707 run
.current_y
= first_reusable_row
->y
;
8708 run
.desired_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
8709 run
.height
= it
.last_visible_y
- run
.current_y
;
8712 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8714 rif
->update_window_begin_hook (w
);
8715 rif
->scroll_run_hook (w
, &run
);
8716 rif
->update_window_end_hook (w
, 0);
8720 /* Adjust Y positions of reused rows. */
8721 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
8722 row
= first_reusable_row
;
8723 dy
= first_reusable_row
->y
;
8724 min_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
8725 max_y
= it
.last_visible_y
;
8726 while (row
< first_row_to_display
)
8730 row
->visible_height
= row
->height
- (min_y
- row
->y
);
8731 else if (row
->y
+ row
->height
> max_y
)
8733 = row
->height
- (row
->y
+ row
->height
- max_y
);
8735 row
->visible_height
= row
->height
;
8739 /* Disable rows not reused. */
8740 while (row
< bottom_row
)
8746 /* Scroll the current matrix. */
8747 xassert (nrows_scrolled
> 0);
8748 rotate_matrix (w
->current_matrix
,
8750 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
8753 /* Adjust window end. A null value of last_text_row means that
8754 the window end is in reused rows which in turn means that
8755 only its vpos can have changed. */
8758 w
->window_end_bytepos
8759 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
8760 XSETFASTINT (w
->window_end_pos
,
8761 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
8762 XSETFASTINT (w
->window_end_vpos
,
8763 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
8767 XSETFASTINT (w
->window_end_vpos
,
8768 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
8771 w
->window_end_valid
= Qnil
;
8772 w
->desired_matrix
->no_scrolling_p
= 1;
8775 debug_method_add (w
, "try_window_reusing_current_matrix 2");
8785 /************************************************************************
8786 Window redisplay reusing current matrix when buffer has changed
8787 ************************************************************************/
8789 static struct glyph_row
*get_last_unchanged_at_beg_row
P_ ((struct window
*));
8790 static struct glyph_row
*get_first_unchanged_at_end_row
P_ ((struct window
*,
8792 static struct glyph_row
*
8793 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
8794 struct glyph_row
*));
8797 /* Return the last row in MATRIX displaying text. If row START is
8798 non-null, start searching with that row. IT gives the dimensions
8799 of the display. Value is null if matrix is empty; otherwise it is
8800 a pointer to the row found. */
8802 static struct glyph_row
*
8803 find_last_row_displaying_text (matrix
, it
, start
)
8804 struct glyph_matrix
*matrix
;
8806 struct glyph_row
*start
;
8808 struct glyph_row
*row
, *row_found
;
8810 /* Set row_found to the last row in IT->w's current matrix
8811 displaying text. The loop looks funny but think of partially
8814 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
8815 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
8817 xassert (row
->enabled_p
);
8819 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
8828 /* Return the last row in the current matrix of W that is not affected
8829 by changes at the start of current_buffer that occurred since the
8830 last time W was redisplayed. Value is null if no such row exists.
8832 The global variable beg_unchanged has to contain the number of
8833 bytes unchanged at the start of current_buffer. BEG +
8834 beg_unchanged is the buffer position of the first changed byte in
8835 current_buffer. Characters at positions < BEG + beg_unchanged are
8836 at the same buffer positions as they were when the current matrix
8839 static struct glyph_row
*
8840 get_last_unchanged_at_beg_row (w
)
8843 int first_changed_pos
= BEG
+ beg_unchanged
;
8844 struct glyph_row
*row
;
8845 struct glyph_row
*row_found
= NULL
;
8846 int yb
= window_text_bottom_y (w
);
8848 /* Find the last row displaying unchanged text. */
8849 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8850 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
8851 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
8853 if (/* If row ends before first_changed_pos, it is unchanged,
8854 except in some case. */
8855 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
8856 /* When row ends in ZV and we write at ZV it is not
8858 && !row
->ends_at_zv_p
8859 /* When first_changed_pos is the end of a continued line,
8860 row is not unchanged because it may be no longer
8862 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
8863 && row
->continued_p
))
8866 /* Stop if last visible row. */
8867 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
8877 /* Find the first glyph row in the current matrix of W that is not
8878 affected by changes at the end of current_buffer since the last
8879 time the window was redisplayed. Return in *DELTA the number of
8880 bytes by which buffer positions in unchanged text at the end of
8881 current_buffer must be adjusted. Value is null if no such row
8882 exists, i.e. all rows are affected by changes.
8884 The global variable end_unchanged is assumed to contain the number
8885 of unchanged bytes at the end of current_buffer. The buffer
8886 position of the last changed byte in current_buffer is then Z -
8889 static struct glyph_row
*
8890 get_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
8892 int *delta
, *delta_bytes
;
8894 struct glyph_row
*row
;
8895 struct glyph_row
*row_found
= NULL
;
8897 *delta
= *delta_bytes
= 0;
8899 /* A value of window_end_pos >= end_unchanged means that the window
8900 end is in the range of changed text. If so, there is no
8901 unchanged row at the end of W's current matrix. */
8902 xassert (!NILP (w
->window_end_valid
));
8903 if (XFASTINT (w
->window_end_pos
) >= end_unchanged
)
8906 /* Set row to the last row in W's current matrix displaying text. */
8907 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
8909 /* End vpos should always be on text, except in an entirely empty
8911 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
8912 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0);
8914 /* If matrix is entirely empty, no unchanged row exists. */
8915 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
8917 /* The value of row is the last glyph row in the matrix having a
8918 meaningful buffer position in it. The end position of row
8919 corresponds to window_end_pos. This allows us to translate
8920 buffer positions in the current matrix to current buffer
8921 positions for characters not in changed text. */
8922 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
8923 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
8924 int last_unchanged_pos
, last_unchanged_pos_old
;
8925 struct glyph_row
*first_text_row
8926 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8929 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
8931 /* Set last_unchanged_pos to the buffer position of the last
8932 character in the buffer that has not been changed. Z is the
8933 index + 1 of the last byte in current_buffer, i.e. by
8934 subtracting end_unchanged we get the index of the last
8935 unchanged character, and we have to add BEG to get its buffer
8937 last_unchanged_pos
= Z
- end_unchanged
+ BEG
;
8938 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
8940 /* Search backward from ROW for a row displaying a line that
8941 starts at a minimum position >= last_unchanged_pos_old. */
8942 while (row
>= first_text_row
)
8944 xassert (row
->enabled_p
);
8945 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
));
8947 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
8953 xassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
8958 /* Make sure that glyph rows in the current matrix of window W
8959 reference the same glyph memory as corresponding rows in the
8960 frame's frame matrix. This function is called after scrolling W's
8961 current matrix on a terminal frame in try_window_id and
8962 try_window_reusing_current_matrix. */
8965 sync_frame_with_window_matrix_rows (w
)
8968 struct frame
*f
= XFRAME (w
->frame
);
8969 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
8971 /* Preconditions: W must be a leaf window and full-width. Its frame
8972 must have a frame matrix. */
8973 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
8974 xassert (WINDOW_FULL_WIDTH_P (w
));
8975 xassert (!FRAME_WINDOW_P (f
));
8977 /* If W is a full-width window, glyph pointers in W's current matrix
8978 have, by definition, to be the same as glyph pointers in the
8979 corresponding frame matrix. */
8980 window_row
= w
->current_matrix
->rows
;
8981 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
8982 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
8983 while (window_row
< window_row_end
)
8986 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
8987 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
8988 ++window_row
, ++frame_row
;
8993 /* Try to redisplay window W by reusing its existing display. W's
8994 current matrix must be up to date when this function is called,
8995 i.e. window_end_valid must not be nil.
8999 1 if display has been updated
9000 0 if otherwise unsuccessful
9001 -1 if redisplay with same window start is known not to succeed
9003 The following steps are performed:
9005 1. Find the last row in the current matrix of W that is not
9006 affected by changes at the start of current_buffer. If no such row
9009 2. Find the first row in W's current matrix that is not affected by
9010 changes at the end of current_buffer. Maybe there is no such row.
9012 3. Display lines beginning with the row + 1 found in step 1 to the
9013 row found in step 2 or, if step 2 didn't find a row, to the end of
9016 4. If cursor is not known to appear on the window, give up.
9018 5. If display stopped at the row found in step 2, scroll the
9019 display and current matrix as needed.
9021 6. Maybe display some lines at the end of W, if we must. This can
9022 happen under various circumstances, like a partially visible line
9023 becoming fully visible, or because newly displayed lines are displayed
9024 in smaller font sizes.
9026 7. Update W's window end information. */
9028 /* Check that window end is what we expect it to be. */
9034 struct frame
*f
= XFRAME (w
->frame
);
9035 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
9036 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
9037 struct glyph_row
*last_unchanged_at_beg_row
;
9038 struct glyph_row
*first_unchanged_at_end_row
;
9039 struct glyph_row
*row
;
9040 struct glyph_row
*bottom_row
;
9043 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
9044 struct text_pos start_pos
;
9046 int first_unchanged_at_end_vpos
= 0;
9047 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
9048 struct text_pos start
;
9050 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
9052 /* Check pre-conditions. Window end must be valid, otherwise
9053 the current matrix would not be up to date. */
9054 xassert (!NILP (w
->window_end_valid
));
9055 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
9056 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
9058 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
9059 only if buffer has really changed. The reason is that the gap is
9060 initially at Z for freshly visited files. The code below would
9061 set end_unchanged to 0 in that case. */
9062 if (MODIFF
> SAVE_MODIFF
)
9064 if (GPT
- BEG
< beg_unchanged
)
9065 beg_unchanged
= GPT
- BEG
;
9066 if (Z
- GPT
< end_unchanged
)
9067 end_unchanged
= Z
- GPT
;
9070 /* If window starts after a line end, and the last change is in
9071 front of that newline, then changes don't affect the display.
9072 This case happens with stealth-fontification. */
9073 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
9074 if (CHARPOS (start
) > BEGV
9075 && Z
- end_unchanged
< CHARPOS (start
) - 1
9076 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
9077 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9079 /* We have to update window end positions because the buffer's
9080 size has changed. */
9082 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
9083 w
->window_end_bytepos
9084 = make_number (Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
));
9088 /* Return quickly if changes are all below what is displayed in the
9089 window, and if PT is in the window. */
9090 if (beg_unchanged
> MATRIX_ROW_END_CHARPOS (row
)
9091 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9093 /* We have to update window end positions because the buffer's
9094 size has changed. */
9096 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
9097 w
->window_end_bytepos
9098 = make_number (Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
));
9102 /* Check that window start agrees with the start of the first glyph
9103 row in its current matrix. Check this after we know the window
9104 start is not in changed text, otherwise positions would not be
9106 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9107 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
9110 /* Remember beg_unchanged and end_unchanged for debugging purposes. */
9111 IF_DEBUG (debug_beg_unchanged
= beg_unchanged
;
9112 debug_end_unchanged
= end_unchanged
);
9114 /* Compute the position at which we have to start displaying new
9115 lines. Some of the lines at the top of the window might be
9116 reusable because they are not displaying changed text. Find the
9117 last row in W's current matrix not affected by changes at the
9118 start of current_buffer. Value is null if changes start in the
9119 first line of window. */
9120 last_unchanged_at_beg_row
= get_last_unchanged_at_beg_row (w
);
9121 if (last_unchanged_at_beg_row
)
9123 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
9124 start_pos
= it
.current
.pos
;
9126 /* Start displaying new lines in the desired matrix at the same
9127 vpos we would use in the current matrix, i.e. below
9128 last_unchanged_at_beg_row. */
9129 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
9131 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
9132 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
9134 xassert (it
.hpos
== 0 && it
.current_x
== 0);
9138 /* There are no reusable lines at the start of the window.
9139 Start displaying in the first line. */
9140 start_display (&it
, w
, start
);
9141 start_pos
= it
.current
.pos
;
9144 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
9145 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
9147 /* Find the first row that is not affected by changes at the end of
9148 the buffer. Value will be null if there is no unchanged row, in
9149 which case we must redisplay to the end of the window. delta
9150 will be set to the value by which buffer positions beginning with
9151 first_unchanged_at_end_row have to be adjusted due to text
9153 first_unchanged_at_end_row
9154 = get_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
9155 IF_DEBUG (debug_delta
= delta
);
9156 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
9158 /* Set stop_pos to the buffer position up to which we will have to
9159 display new lines. If first_unchanged_at_end_row != NULL, this
9160 is the buffer position of the start of the line displayed in that
9161 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
9162 that we don't stop at a buffer position. */
9164 if (first_unchanged_at_end_row
)
9166 xassert (last_unchanged_at_beg_row
== NULL
9167 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
9169 /* If this is a continuation line, move forward to the next one
9170 that isn't. Changes in lines above affect this line.
9171 Caution: this may move first_unchanged_at_end_row to a row
9172 not displaying text. */
9173 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
9174 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
9175 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
9176 < it
.last_visible_y
))
9177 ++first_unchanged_at_end_row
;
9179 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
9180 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
9181 >= it
.last_visible_y
))
9182 first_unchanged_at_end_row
= NULL
;
9185 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
9187 first_unchanged_at_end_vpos
9188 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
9189 xassert (stop_pos
>= Z
- end_unchanged
);
9192 else if (last_unchanged_at_beg_row
== NULL
)
9198 /* Either there is no unchanged row at the end, or the one we have
9199 now displays text. This is a necessary condition for the window
9200 end pos calculation at the end of this function. */
9201 xassert (first_unchanged_at_end_row
== NULL
9202 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
9204 debug_last_unchanged_at_beg_vpos
9205 = (last_unchanged_at_beg_row
9206 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
9208 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
9210 #endif /* GLYPH_DEBUG != 0 */
9213 /* Display new lines. Set last_text_row to the last new line
9214 displayed which has text on it, i.e. might end up as being the
9215 line where the window_end_vpos is. */
9216 w
->cursor
.vpos
= -1;
9217 last_text_row
= NULL
;
9218 overlay_arrow_seen
= 0;
9219 while (it
.current_y
< it
.last_visible_y
9221 && (first_unchanged_at_end_row
== NULL
9222 || IT_CHARPOS (it
) < stop_pos
))
9224 if (display_line (&it
))
9225 last_text_row
= it
.glyph_row
- 1;
9228 if (fonts_changed_p
)
9232 /* Compute differences in buffer positions, y-positions etc. for
9233 lines reused at the bottom of the window. Compute what we can
9235 if (first_unchanged_at_end_row
)
9238 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
9240 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
9241 run
.current_y
= first_unchanged_at_end_row
->y
;
9242 run
.desired_y
= run
.current_y
+ dy
;
9243 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
9246 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
9247 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
9250 /* Find the cursor if not already found. We have to decide whether
9251 PT will appear on this window (it sometimes doesn't, but this is
9252 not a very frequent case.) This decision has to be made before
9253 the current matrix is altered. A value of cursor.vpos < 0 means
9254 that PT is either in one of the lines beginning at
9255 first_unchanged_at_end_row or below the window. Don't care for
9256 lines that might be displayed later at the window end; as
9257 mentioned, this is not a frequent case. */
9258 if (w
->cursor
.vpos
< 0)
9260 int last_y
= min (it
.last_visible_y
, it
.last_visible_y
+ dy
);
9262 /* Cursor in unchanged rows at the top? */
9263 if (PT
< CHARPOS (start_pos
)
9264 && last_unchanged_at_beg_row
)
9266 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9267 while (row
<= last_unchanged_at_beg_row
9268 && MATRIX_ROW_END_CHARPOS (row
) <= PT
)
9270 xassert (row
<= last_unchanged_at_beg_row
);
9271 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9274 /* Start from first_unchanged_at_end_row looking for PT. */
9275 else if (first_unchanged_at_end_row
)
9277 row
= first_unchanged_at_end_row
;
9278 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9280 if (PT
- delta
>= MATRIX_ROW_START_CHARPOS (row
)
9281 && PT
- delta
< MATRIX_ROW_END_CHARPOS (row
))
9283 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
9284 delta_bytes
, dy
, dvpos
);
9287 else if (MATRIX_ROW_BOTTOM_Y (row
) >= last_y
)
9293 /* Give up if cursor was not found. */
9294 if (w
->cursor
.vpos
< 0)
9296 clear_glyph_matrix (w
->desired_matrix
);
9301 /* Don't let the cursor end in the scroll margins. */
9303 int this_scroll_margin
, cursor_height
;
9305 this_scroll_margin
= max (0, scroll_margin
);
9306 this_scroll_margin
= min (this_scroll_margin
,
9307 XFASTINT (w
->height
) / 4);
9308 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
9309 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
9311 if ((w
->cursor
.y
< this_scroll_margin
9312 && CHARPOS (start
) > BEGV
)
9313 /* Don't take scroll margin into account at the bottom because
9314 old redisplay didn't do it either. */
9315 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
9317 w
->cursor
.vpos
= -1;
9318 clear_glyph_matrix (w
->desired_matrix
);
9323 /* Scroll the display. Do it before changing the current matrix so
9324 that xterm.c doesn't get confused about where the cursor glyph is
9330 if (FRAME_WINDOW_P (f
))
9332 rif
->update_window_begin_hook (w
);
9333 rif
->scroll_run_hook (w
, &run
);
9334 rif
->update_window_end_hook (w
, 0);
9338 /* Terminal frame. In this case, dvpos gives the number of
9339 lines to scroll by; dvpos < 0 means scroll up. */
9340 int first_unchanged_at_end_vpos
9341 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
9342 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
9343 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
9345 /* Perform the operation on the screen. */
9348 /* Scroll last_unchanged_at_beg_row to the end of the
9349 window down dvpos lines. */
9350 set_terminal_window (end
);
9352 /* On dumb terminals delete dvpos lines at the end
9353 before inserting dvpos empty lines. */
9354 if (!scroll_region_ok
)
9355 ins_del_lines (end
- dvpos
, -dvpos
);
9357 /* Insert dvpos empty lines in front of
9358 last_unchanged_at_beg_row. */
9359 ins_del_lines (from
, dvpos
);
9363 /* Scroll up last_unchanged_at_beg_vpos to the end of
9364 the window to last_unchanged_at_beg_vpos - |dvpos|. */
9365 set_terminal_window (end
);
9367 /* Delete dvpos lines in front of
9368 last_unchanged_at_beg_vpos. ins_del_lines will set
9369 the cursor to the given vpos and emit |dvpos| delete
9371 ins_del_lines (from
+ dvpos
, dvpos
);
9373 /* On a dumb terminal insert dvpos empty lines at the
9375 if (!scroll_region_ok
)
9376 ins_del_lines (end
+ dvpos
, -dvpos
);
9379 set_terminal_window (0);
9385 /* Shift reused rows of the current matrix to the right position. */
9388 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
9389 bottom_vpos
, dvpos
);
9390 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
9395 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
9396 bottom_vpos
, dvpos
);
9397 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
9398 first_unchanged_at_end_vpos
+ dvpos
, 0);
9401 /* For frame-based redisplay, make sure that current frame and window
9402 matrix are in sync with respect to glyph memory. */
9403 if (!FRAME_WINDOW_P (f
))
9404 sync_frame_with_window_matrix_rows (w
);
9406 /* Adjust buffer positions in reused rows. */
9408 increment_glyph_matrix_buffer_positions (current_matrix
,
9409 first_unchanged_at_end_vpos
+ dvpos
,
9410 bottom_vpos
, delta
, delta_bytes
);
9412 /* Adjust Y positions. */
9414 shift_glyph_matrix (w
, current_matrix
,
9415 first_unchanged_at_end_vpos
+ dvpos
,
9418 if (first_unchanged_at_end_row
)
9419 first_unchanged_at_end_row
+= dvpos
;
9421 /* If scrolling up, there may be some lines to display at the end of
9423 last_text_row_at_end
= NULL
;
9426 /* Set last_row to the glyph row in the current matrix where the
9427 window end line is found. It has been moved up or down in
9428 the matrix by dvpos. */
9429 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
9430 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
9432 /* If last_row is the window end line, it should display text. */
9433 xassert (last_row
->displays_text_p
);
9435 /* If window end line was partially visible before, begin
9436 displaying at that line. Otherwise begin displaying with the
9437 line following it. */
9438 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
9440 init_to_row_start (&it
, w
, last_row
);
9441 it
.vpos
= last_vpos
;
9442 it
.current_y
= last_row
->y
;
9446 init_to_row_end (&it
, w
, last_row
);
9447 it
.vpos
= 1 + last_vpos
;
9448 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
9452 /* We may start in a continuation line. If so, we have to get
9453 the right continuation_lines_width and current_x. */
9454 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
9455 it
.hpos
= it
.current_x
= 0;
9457 /* Display the rest of the lines at the window end. */
9458 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
9459 while (it
.current_y
< it
.last_visible_y
9460 && !fonts_changed_p
)
9462 /* Is it always sure that the display agrees with lines in
9463 the current matrix? I don't think so, so we mark rows
9464 displayed invalid in the current matrix by setting their
9465 enabled_p flag to zero. */
9466 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
9467 if (display_line (&it
))
9468 last_text_row_at_end
= it
.glyph_row
- 1;
9472 /* Update window_end_pos and window_end_vpos. */
9473 if (first_unchanged_at_end_row
9474 && first_unchanged_at_end_row
->y
< it
.last_visible_y
9475 && !last_text_row_at_end
)
9477 /* Window end line if one of the preserved rows from the current
9478 matrix. Set row to the last row displaying text in current
9479 matrix starting at first_unchanged_at_end_row, after
9481 xassert (first_unchanged_at_end_row
->displays_text_p
);
9482 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
9483 first_unchanged_at_end_row
);
9484 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
9486 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
9487 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
9488 XSETFASTINT (w
->window_end_vpos
,
9489 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
9491 else if (last_text_row_at_end
)
9493 XSETFASTINT (w
->window_end_pos
,
9494 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
9495 w
->window_end_bytepos
9496 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
9497 XSETFASTINT (w
->window_end_vpos
,
9498 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
9500 else if (last_text_row
)
9502 /* We have displayed either to the end of the window or at the
9503 end of the window, i.e. the last row with text is to be found
9504 in the desired matrix. */
9505 XSETFASTINT (w
->window_end_pos
,
9506 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9507 w
->window_end_bytepos
9508 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9509 XSETFASTINT (w
->window_end_vpos
,
9510 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
9512 else if (first_unchanged_at_end_row
== NULL
9513 && last_text_row
== NULL
9514 && last_text_row_at_end
== NULL
)
9516 /* Displayed to end of window, but no line containing text was
9517 displayed. Lines were deleted at the end of the window. */
9519 int top_line_p
= WINDOW_WANTS_TOP_LINE_P (w
) ? 1 : 0;
9521 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
9522 if ((w
->desired_matrix
->rows
[vpos
+ top_line_p
].enabled_p
9523 && w
->desired_matrix
->rows
[vpos
+ top_line_p
].displays_text_p
)
9524 || (!w
->desired_matrix
->rows
[vpos
+ top_line_p
].enabled_p
9525 && w
->current_matrix
->rows
[vpos
+ top_line_p
].displays_text_p
))
9528 w
->window_end_vpos
= make_number (vpos
);
9533 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
9534 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
9536 /* Record that display has not been completed. */
9537 w
->window_end_valid
= Qnil
;
9538 w
->desired_matrix
->no_scrolling_p
= 1;
9544 /***********************************************************************
9545 More debugging support
9546 ***********************************************************************/
9550 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
9551 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
9554 /* Dump the contents of glyph matrix MATRIX on stderr. If
9555 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
9558 dump_glyph_matrix (matrix
, with_glyphs_p
)
9559 struct glyph_matrix
*matrix
;
9563 for (i
= 0; i
< matrix
->nrows
; ++i
)
9564 dump_glyph_row (matrix
, i
, with_glyphs_p
);
9568 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
9569 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
9572 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
9573 struct glyph_matrix
*matrix
;
9574 int vpos
, with_glyphs_p
;
9576 struct glyph_row
*row
;
9578 if (vpos
< 0 || vpos
>= matrix
->nrows
)
9581 row
= MATRIX_ROW (matrix
, vpos
);
9583 fprintf (stderr
, "Row Start End Used oEI><O\\CTZF X Y W\n");
9584 fprintf (stderr
, "=============================================\n");
9586 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",
9588 MATRIX_ROW_START_CHARPOS (row
),
9589 MATRIX_ROW_END_CHARPOS (row
),
9590 row
->used
[TEXT_AREA
],
9591 row
->contains_overlapping_glyphs_p
,
9594 row
->truncated_on_left_p
,
9595 row
->truncated_on_right_p
,
9596 row
->overlay_arrow_p
,
9598 MATRIX_ROW_CONTINUATION_LINE_P (row
),
9599 row
->displays_text_p
,
9605 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
9606 row
->end
.overlay_string_index
);
9607 fprintf (stderr
, "%9d %5d\n",
9608 CHARPOS (row
->start
.string_pos
),
9609 CHARPOS (row
->end
.string_pos
));
9610 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
9611 row
->end
.dpvec_index
);
9615 struct glyph
*glyph
, *glyph_end
;
9616 int prev_had_glyphs_p
;
9618 glyph
= row
->glyphs
[TEXT_AREA
];
9619 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
9621 /* Glyph for a line end in text. */
9622 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
9625 if (glyph
< glyph_end
)
9627 fprintf (stderr
, " Glyph Type Pos W Code C Face LR\n");
9628 prev_had_glyphs_p
= 1;
9631 prev_had_glyphs_p
= 0;
9633 while (glyph
< glyph_end
)
9635 if (glyph
->type
== CHAR_GLYPH
)
9638 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
9639 glyph
- row
->glyphs
[TEXT_AREA
],
9644 (glyph
->u
.ch
.code
< 0x80 && glyph
->u
.ch
.code
>= ' '
9647 glyph
->u
.ch
.face_id
,
9648 glyph
->left_box_line_p
,
9649 glyph
->right_box_line_p
);
9651 else if (glyph
->type
== STRETCH_GLYPH
)
9654 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
9655 glyph
- row
->glyphs
[TEXT_AREA
],
9661 glyph
->u
.stretch
.face_id
,
9662 glyph
->left_box_line_p
,
9663 glyph
->right_box_line_p
);
9665 else if (glyph
->type
== IMAGE_GLYPH
)
9668 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
9669 glyph
- row
->glyphs
[TEXT_AREA
],
9675 glyph
->u
.img
.face_id
,
9676 glyph
->left_box_line_p
,
9677 glyph
->right_box_line_p
);
9685 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
9686 Sdump_glyph_matrix
, 0, 1, "p",
9687 "Dump the current matrix of the selected window to stderr.\n\
9688 Shows contents of glyph row structures. With non-nil optional\n\
9689 parameter WITH-GLYPHS-P, dump glyphs as well.")
9692 struct window
*w
= XWINDOW (selected_window
);
9693 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9695 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
9696 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
9697 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
9698 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
9699 fprintf (stderr
, "=============================================\n");
9700 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
9705 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
9706 "Dump glyph row ROW to stderr.")
9710 CHECK_NUMBER (row
, 0);
9711 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
9716 DEFUN ("dump-toolbar-row", Fdump_toolbar_row
, Sdump_toolbar_row
,
9720 struct glyph_matrix
*m
= (XWINDOW (selected_frame
->toolbar_window
)
9722 dump_glyph_row (m
, 0, 1);
9727 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
9728 Strace_redisplay_toggle
, 0, 0, "",
9729 "Toggle tracing of redisplay.")
9732 trace_redisplay_p
= !trace_redisplay_p
;
9737 #endif /* GLYPH_DEBUG */
9741 /***********************************************************************
9742 Building Desired Matrix Rows
9743 ***********************************************************************/
9745 /* Return a temporary glyph row holding the glyphs of an overlay
9746 arrow. Only used for non-window-redisplay windows. */
9748 static struct glyph_row
*
9749 get_overlay_arrow_glyph_row (w
)
9752 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9753 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9754 struct buffer
*old
= current_buffer
;
9755 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
9756 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
9757 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
9761 int n_glyphs_before
;
9763 set_buffer_temp (buffer
);
9764 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
9765 it
.glyph_row
->used
[TEXT_AREA
] = 0;
9766 SET_TEXT_POS (it
.position
, 0, 0);
9768 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
9770 while (p
< arrow_end
)
9772 Lisp_Object face
, ilisp
;
9774 /* Get the next character. */
9776 it
.c
= STRING_CHAR_AND_LENGTH (p
, arrow_len
, it
.len
);
9778 it
.c
= *p
, it
.len
= 1;
9782 XSETFASTINT (ilisp
, p
- arrow_string
);
9783 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
9784 it
.face_id
= compute_char_face (f
, it
.c
, face
);
9786 /* Compute its width, get its glyphs. */
9787 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
9788 PRODUCE_GLYPHS (&it
);
9790 /* If this character doesn't fit any more in the line, we have
9791 to remove some glyphs. */
9792 if (it
.current_x
> it
.last_visible_x
)
9794 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
9799 set_buffer_temp (old
);
9800 return it
.glyph_row
;
9804 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
9805 glyphs are only inserted for terminal frames since we can't really
9806 win with truncation glyphs when partially visible glyphs are
9807 involved. Which glyphs to insert is determined by
9808 produce_special_glyphs. */
9811 insert_left_trunc_glyphs (it
)
9814 struct it truncate_it
;
9815 struct glyph
*from
, *end
, *to
, *toend
;
9817 xassert (!FRAME_WINDOW_P (it
->f
));
9819 /* Get the truncation glyphs. */
9821 truncate_it
.charset
= -1;
9822 truncate_it
.current_x
= 0;
9823 truncate_it
.face_id
= DEFAULT_FACE_ID
;
9824 truncate_it
.glyph_row
= &scratch_glyph_row
;
9825 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
9826 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
9827 truncate_it
.object
= 0;
9828 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
9830 /* Overwrite glyphs from IT with truncation glyphs. */
9831 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
9832 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
9833 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
9834 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
9839 /* There may be padding glyphs left over. Remove them. */
9841 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
9843 while (from
< toend
)
9846 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
9850 /* Compute the pixel height and width of IT->glyph_row.
9852 Most of the time, ascent and height of a display line will be equal
9853 to the max_ascent and max_height values of the display iterator
9854 structure. This is not the case if
9856 1. We hit ZV without displaying anything. In this case, max_ascent
9857 and max_height will be zero.
9859 2. We have some glyphs that don't contribute to the line height.
9860 (The glyph row flag contributes_to_line_height_p is for future
9863 The first case is easily covered by using default values because in
9864 these cases, the line height does not really matter, except that it
9865 must not be zero. */
9868 compute_line_metrics (it
)
9871 struct glyph_row
*row
= it
->glyph_row
;
9874 if (FRAME_WINDOW_P (it
->f
))
9876 int i
, top_line_height
;
9878 /* The line may consist of one space only, that was added to
9879 place the cursor on it. If so, the row's height hasn't been
9881 if (row
->height
== 0)
9883 if (it
->max_ascent
+ it
->max_descent
== 0)
9884 it
->max_descent
= CANON_Y_UNIT (it
->f
);
9885 row
->ascent
= it
->max_ascent
;
9886 row
->height
= it
->max_ascent
+ it
->max_descent
;
9889 /* Compute the width of this line. */
9890 row
->pixel_width
= row
->x
;
9891 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
9892 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9894 xassert (row
->pixel_width
>= 0);
9895 xassert (row
->ascent
>= 0 && row
->height
> 0);
9897 /* Compute how much of the line is visible. */
9898 row
->visible_height
= row
->height
;
9900 top_line_height
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (it
->w
);
9901 if (row
->y
< top_line_height
)
9902 row
->visible_height
-= top_line_height
- row
->y
;
9905 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
9906 if (row
->y
+ row
->height
> max_y
)
9907 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
9912 row
->pixel_width
= row
->used
[TEXT_AREA
];
9914 row
->height
= row
->visible_height
= 1;
9917 /* Compute a hash code for this row. */
9919 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
9920 for (i
= 0; i
< row
->used
[area
]; ++i
)
9921 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
9922 + row
->glyphs
[area
][i
].u
.val
9923 + (row
->glyphs
[area
][i
].type
<< 2));
9925 it
->max_ascent
= it
->max_descent
= 0;
9929 /* Append one space to the glyph row of iterator IT if doing a
9930 window-based redisplay. DEFAULT_FACE_P non-zero means let the
9931 space have the default face, otherwise let it have the same face as
9932 IT->face_id. This function is called to make sure that there is
9933 always one glyph at the end of a glyph row that the cursor can be
9934 set on under window-systems. (If there weren't such a glyph we
9935 would not know how wide and tall the cursor should be displayed). */
9938 append_space (it
, default_face_p
)
9942 if (FRAME_WINDOW_P (it
->f
))
9944 int n
= it
->glyph_row
->used
[TEXT_AREA
];
9946 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
9947 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
9949 /* Save some values that must not be changed. */
9950 int saved_x
= it
->current_x
;
9951 struct text_pos saved_pos
;
9952 int saved_what
= it
->what
;
9953 int saved_face_id
= it
->face_id
;
9954 int saved_charset
= it
->charset
;
9955 Lisp_Object saved_object
;
9957 saved_object
= it
->object
;
9958 saved_pos
= it
->position
;
9960 it
->what
= IT_CHARACTER
;
9961 bzero (&it
->position
, sizeof it
->position
);
9965 it
->charset
= CHARSET_ASCII
;
9968 it
->face_id
= DEFAULT_FACE_ID
;
9969 if (it
->multibyte_p
)
9970 it
->face_id
= FACE_FOR_CHARSET (it
->f
, it
->face_id
, CHARSET_ASCII
);
9972 it
->face_id
= FACE_FOR_CHARSET (it
->f
, it
->face_id
, -1);
9974 PRODUCE_GLYPHS (it
);
9976 it
->current_x
= saved_x
;
9977 it
->object
= saved_object
;
9978 it
->position
= saved_pos
;
9979 it
->what
= saved_what
;
9980 it
->face_id
= saved_face_id
;
9981 it
->charset
= saved_charset
;
9987 /* Extend the face of the last glyph in the text area of IT->glyph_row
9988 to the end of the display line. Called from display_line.
9989 If the glyph row is empty, add a space glyph to it so that we
9990 know the face to draw. Set the glyph row flag fill_line_p. */
9993 extend_face_to_end_of_line (it
)
9997 struct frame
*f
= it
->f
;
9999 /* If line is already filled, do nothing. */
10000 if (it
->current_x
>= it
->last_visible_x
)
10003 /* Face extension extends the background and box of IT->face_id
10004 to the end of the line. If the background equals the background
10005 of the frame, we haven't to do anything. */
10006 face
= FACE_FROM_ID (f
, it
->face_id
);
10007 if (FRAME_WINDOW_P (f
)
10008 && face
->box
== FACE_NO_BOX
10009 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
10013 /* Set the glyph row flag indicating that the face of the last glyph
10014 in the text area has to be drawn to the end of the text area. */
10015 it
->glyph_row
->fill_line_p
= 1;
10017 /* If current charset of IT is not ASCII, make sure we have the
10018 ASCII face. This will be automatically undone the next time
10019 get_next_display_element returns a character from a different
10020 charset. Note that the charset will always be ASCII in unibyte
10022 if (it
->charset
!= CHARSET_ASCII
)
10024 it
->charset
= CHARSET_ASCII
;
10025 it
->face_id
= FACE_FOR_CHARSET (f
, it
->face_id
, CHARSET_ASCII
);
10028 if (FRAME_WINDOW_P (f
))
10030 /* If the row is empty, add a space with the current face of IT,
10031 so that we know which face to draw. */
10032 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
10034 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
10035 it
->glyph_row
->glyphs
[TEXT_AREA
][0].u
.ch
.face_id
= it
->face_id
;
10036 it
->glyph_row
->used
[TEXT_AREA
] = 1;
10041 /* Save some values that must not be changed. */
10042 int saved_x
= it
->current_x
;
10043 struct text_pos saved_pos
;
10044 Lisp_Object saved_object
;
10045 int saved_what
= it
->what
;
10047 saved_object
= it
->object
;
10048 saved_pos
= it
->position
;
10050 it
->what
= IT_CHARACTER
;
10051 bzero (&it
->position
, sizeof it
->position
);
10056 PRODUCE_GLYPHS (it
);
10058 while (it
->current_x
<= it
->last_visible_x
)
10059 PRODUCE_GLYPHS (it
);
10061 /* Don't count these blanks really. It would let us insert a left
10062 truncation glyph below and make us set the cursor on them, maybe. */
10063 it
->current_x
= saved_x
;
10064 it
->object
= saved_object
;
10065 it
->position
= saved_pos
;
10066 it
->what
= saved_what
;
10071 /* Value is non-zero if text starting at CHARPOS in current_buffer is
10072 trailing whitespace. */
10075 trailing_whitespace_p (charpos
)
10078 int bytepos
= CHAR_TO_BYTE (charpos
);
10081 while (bytepos
< ZV_BYTE
10082 && (c
= FETCH_CHAR (bytepos
),
10083 c
== ' ' || c
== '\t'))
10086 return bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r';
10090 /* Highlight trailing whitespace, if any, in ROW. */
10093 highlight_trailing_whitespace (f
, row
)
10095 struct glyph_row
*row
;
10097 int used
= row
->used
[TEXT_AREA
];
10101 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
10102 struct glyph
*glyph
= start
+ used
- 1;
10104 /* Skip over the space glyph inserted to display the
10105 cursor at the end of a line. */
10106 if (glyph
->type
== CHAR_GLYPH
10107 && glyph
->u
.ch
.code
== ' '
10108 && glyph
->object
== 0)
10111 /* If last glyph is a space or stretch, and it's trailing
10112 whitespace, set the face of all trailing whitespace glyphs in
10113 IT->glyph_row to `trailing-whitespace'. */
10115 && BUFFERP (glyph
->object
)
10116 && (glyph
->type
== STRETCH_GLYPH
10117 || (glyph
->type
== CHAR_GLYPH
10118 && glyph
->u
.ch
.code
== ' '))
10119 && trailing_whitespace_p (glyph
->charpos
))
10121 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
,
10124 while (glyph
>= start
10125 && BUFFERP (glyph
->object
)
10126 && (glyph
->type
== STRETCH_GLYPH
10127 || (glyph
->type
== CHAR_GLYPH
10128 && glyph
->u
.ch
.code
== ' ')))
10130 if (glyph
->type
== STRETCH_GLYPH
)
10131 glyph
->u
.stretch
.face_id
= face_id
;
10133 glyph
->u
.ch
.face_id
= face_id
;
10142 /* Construct the glyph row IT->glyph_row in the desired matrix of
10143 IT->w from text at the current position of IT. See dispextern.h
10144 for an overview of struct it. Value is non-zero if
10145 IT->glyph_row displays text, as opposed to a line displaying ZV
10152 struct glyph_row
*row
= it
->glyph_row
;
10154 /* We always start displaying at hpos zero even if hscrolled. */
10155 xassert (it
->hpos
== 0 && it
->current_x
== 0);
10157 /* We must not display in a row that's not a text row. */
10158 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
10159 < it
->w
->desired_matrix
->nrows
);
10161 /* Is IT->w showing the region? */
10162 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
10164 /* Clear the result glyph row and enable it. */
10165 prepare_desired_row (row
);
10167 row
->y
= it
->current_y
;
10168 row
->start
= it
->current
;
10169 row
->continuation_lines_width
= it
->continuation_lines_width
;
10170 row
->displays_text_p
= 1;
10172 /* Arrange the overlays nicely for our purposes. Usually, we call
10173 display_line on only one line at a time, in which case this
10174 can't really hurt too much, or we call it on lines which appear
10175 one after another in the buffer, in which case all calls to
10176 recenter_overlay_lists but the first will be pretty cheap. */
10177 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
10179 #if NO_PROMPT_IN_BUFFER
10180 /* Show mini-buffer prompt, if at the beginning of a mini-buffer
10182 if (MINI_WINDOW_P (it
->w
)
10183 && MATRIX_ROW_START_CHARPOS (row
) == BEG
10186 if (NILP (minibuf_prompt
))
10187 minibuf_prompt_width
= minibuf_prompt_pixel_width
= 0;
10190 /* We would like to truncate the prompt a little bit before
10191 the right margin of the window, so that user input can
10192 start on the first line. Set max_x to this position. */
10193 int max_x
= (it
->last_visible_x
- 4 * CANON_X_UNIT (it
->f
));
10195 /* We use a temporary iterator different from IT so that
10196 IT's settings are not overwritten when displaying
10202 /* Display the prompt. Set minibuf_prompt_width to the
10203 number of glyphs generated for the prompt, set
10204 minibuf_prompt_pixel_width to its width in pixels. */
10205 xassert (it
->current_x
== 0);
10206 display_string (NULL
, minibuf_prompt
, Qnil
, 0, 0, &ti
,
10208 minibuf_prompt_width
= ti
.hpos
;
10209 minibuf_prompt_pixel_width
= ti
.current_x
;
10211 /* Transfer pixel and hpos information to IT. */
10212 it
->hpos
= ti
.hpos
;
10213 it
->current_x
= ti
.current_x
;
10216 #endif /* NO_PROMPT_IN_BUFFER */
10218 /* Move over display elements that are not visible because we are
10219 hscrolled. This may stop at an x-position < IT->first_visible_x
10220 if the first glyph is partially visible or if we hit a line end. */
10221 if (it
->current_x
< it
->first_visible_x
)
10222 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
10223 MOVE_TO_POS
| MOVE_TO_X
);
10225 /* Get the initial row height. This is either the height of the
10226 text hscrolled, if there is any, or zero. */
10227 row
->ascent
= it
->max_ascent
;
10228 row
->height
= it
->max_ascent
+ it
->max_descent
;
10230 /* Loop generating characters. The loop is left with IT on the next
10231 character to display. */
10234 int n_glyphs_before
, hpos_before
, x_before
;
10237 /* Retrieve the next thing to display. Value is zero if end of
10239 if (!get_next_display_element (it
))
10241 /* Maybe add a space at the end of this line that is used to
10242 display the cursor there under X. */
10243 append_space (it
, 1);
10245 /* The position -1 below indicates a blank line not
10246 corresponding to any text, as opposed to an empty line
10247 corresponding to a line end. */
10248 if (row
->used
[TEXT_AREA
] <= 1)
10250 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
10251 row
->displays_text_p
= 0;
10253 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
10254 row
->indicate_empty_line_p
= 1;
10257 it
->continuation_lines_width
= 0;
10258 row
->ends_at_zv_p
= 1;
10262 /* Now, get the metrics of what we want to display. This also
10263 generates glyphs in `row' (which is IT->glyph_row). */
10264 n_glyphs_before
= row
->used
[TEXT_AREA
];
10266 PRODUCE_GLYPHS (it
);
10268 /* If this display element was in marginal areas, continue with
10270 if (it
->area
!= TEXT_AREA
)
10272 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
10273 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
10274 set_iterator_to_next (it
);
10278 /* Does the display element fit on the line? If we truncate
10279 lines, we should draw past the right edge of the window. If
10280 we don't truncate, we want to stop so that we can display the
10281 continuation glyph before the right margin. If lines are
10282 continued, there are two possible strategies for characters
10283 resulting in more than 1 glyph (e.g. tabs): Display as many
10284 glyphs as possible in this line and leave the rest for the
10285 continuation line, or display the whole element in the next
10286 line. Original redisplay did the former, so we do it also. */
10287 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10288 hpos_before
= it
->hpos
;
10292 && it
->current_x
< it
->last_visible_x
)
10295 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
10296 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
10297 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
10298 row
->x
= x
- it
->first_visible_x
;
10303 struct glyph
*glyph
;
10305 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
10307 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10308 new_x
= x
+ glyph
->pixel_width
;
10310 if (/* Lines are continued. */
10311 !it
->truncate_lines_p
10312 && (/* Glyph doesn't fit on the line. */
10313 new_x
> it
->last_visible_x
10314 /* Or it fits exactly on a window system frame. */
10315 || (new_x
== it
->last_visible_x
10316 && FRAME_WINDOW_P (it
->f
))))
10318 /* End of a continued line. */
10321 || (new_x
== it
->last_visible_x
10322 && FRAME_WINDOW_P (it
->f
)))
10324 /* Current glyph fits exactly on the line. We
10325 must continue the line because we can't draw
10326 the cursor after the glyph. */
10327 row
->continued_p
= 1;
10328 it
->current_x
= new_x
;
10329 it
->continuation_lines_width
+= new_x
;
10331 if (i
== nglyphs
- 1)
10332 set_iterator_to_next (it
);
10336 /* Display element draws past the right edge of
10337 the window. Restore positions to values
10338 before the element. The next line starts
10339 with current_x before the glyph that could
10340 not be displayed, so that TAB works right. */
10341 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
10343 /* Display continuation glyphs. */
10344 if (!FRAME_WINDOW_P (it
->f
))
10345 produce_special_glyphs (it
, IT_CONTINUATION
);
10346 row
->continued_p
= 1;
10349 it
->continuation_lines_width
+= x
;
10353 else if (new_x
> it
->first_visible_x
)
10355 /* Increment number of glyphs actually displayed. */
10358 if (x
< it
->first_visible_x
)
10359 /* Glyph is partially visible, i.e. row starts at
10360 negative X position. */
10361 row
->x
= x
- it
->first_visible_x
;
10365 /* Glyph is completely off the left margin of the
10366 window. This should not happen because of the
10367 move_it_in_display_line at the start of
10373 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
10374 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
10376 /* End of this display line if row is continued. */
10377 if (row
->continued_p
)
10381 /* Is this a line end? If yes, we're also done, after making
10382 sure that a non-default face is extended up to the right
10383 margin of the window. */
10384 if (ITERATOR_AT_END_OF_LINE_P (it
))
10386 int used_before
= row
->used
[TEXT_AREA
];
10388 /* Add a space at the end of the line that is used to
10389 display the cursor there. */
10390 append_space (it
, 0);
10392 /* Extend the face to the end of the line. */
10393 extend_face_to_end_of_line (it
);
10395 /* Make sure we have the position. */
10396 if (used_before
== 0)
10397 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
10399 /* Consume the line end. This skips over invisible lines. */
10400 set_iterator_to_next (it
);
10401 it
->continuation_lines_width
= 0;
10405 /* Proceed with next display element. Note that this skips
10406 over lines invisible because of selective display. */
10407 set_iterator_to_next (it
);
10409 /* If we truncate lines, we are done when the last displayed
10410 glyphs reach past the right margin of the window. */
10411 if (it
->truncate_lines_p
10412 && (FRAME_WINDOW_P (it
->f
)
10413 ? (it
->current_x
>= it
->last_visible_x
)
10414 : (it
->current_x
> it
->last_visible_x
)))
10416 /* Maybe add truncation glyphs. */
10417 if (!FRAME_WINDOW_P (it
->f
))
10419 --it
->glyph_row
->used
[TEXT_AREA
];
10420 produce_special_glyphs (it
, IT_TRUNCATION
);
10423 row
->truncated_on_right_p
= 1;
10424 it
->continuation_lines_width
= 0;
10425 reseat_at_next_visible_line_start (it
);
10426 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
10427 it
->hpos
= hpos_before
;
10428 it
->current_x
= x_before
;
10433 /* If line is not empty and hscrolled, maybe insert truncation glyphs
10434 at the left window margin. */
10435 if (it
->first_visible_x
10436 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
10438 if (!FRAME_WINDOW_P (it
->f
))
10439 insert_left_trunc_glyphs (it
);
10440 row
->truncated_on_left_p
= 1;
10443 /* If the start of this line is the overlay arrow-position, then
10444 mark this glyph row as the one containing the overlay arrow.
10445 This is clearly a mess with variable size fonts. It would be
10446 better to let it be displayed like cursors under X. */
10447 if (MARKERP (Voverlay_arrow_position
)
10448 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
10449 && (MATRIX_ROW_START_CHARPOS (row
)
10450 == marker_position (Voverlay_arrow_position
))
10451 && STRINGP (Voverlay_arrow_string
)
10452 && ! overlay_arrow_seen
)
10454 /* Overlay arrow in window redisplay is a bitmap. */
10455 if (!FRAME_WINDOW_P (it
->f
))
10457 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
10458 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
10459 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
10460 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
10461 struct glyph
*p2
, *end
;
10463 /* Copy the arrow glyphs. */
10464 while (glyph
< arrow_end
)
10467 /* Throw away padding glyphs. */
10469 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
10470 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
10476 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
10480 overlay_arrow_seen
= 1;
10481 row
->overlay_arrow_p
= 1;
10484 /* Compute pixel dimensions of this line. */
10485 compute_line_metrics (it
);
10487 /* Remember the position at which this line ends. */
10488 row
->end
= it
->current
;
10490 /* Maybe set the cursor. If you change this, it's probably a good
10491 idea to also change the code in redisplay_window for cursor
10492 movement in an unchanged window. */
10493 if (it
->w
->cursor
.vpos
< 0
10494 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
10495 && MATRIX_ROW_END_CHARPOS (row
) >= PT
10496 && !(MATRIX_ROW_END_CHARPOS (row
) == PT
10497 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
10498 || !row
->ends_at_zv_p
)))
10499 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
10501 /* Highlight trailing whitespace. */
10502 if (it
->show_trailing_whitespace_p
)
10503 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
10505 /* Prepare for the next line. This line starts horizontally at (X
10506 HPOS) = (0 0). Vertical positions are incremented. As a
10507 convenience for the caller, IT->glyph_row is set to the next
10509 it
->current_x
= it
->hpos
= 0;
10510 it
->current_y
+= row
->height
;
10513 return row
->displays_text_p
;
10518 /***********************************************************************
10520 ***********************************************************************/
10522 /* Redisplay the menu bar in the frame for window W.
10524 The menu bar of X frames that don't have X toolkit support is
10525 displayed in a special window W->frame->menu_bar_window.
10527 The menu bar of terminal frames is treated specially as far as
10528 glyph matrices are concerned. Menu bar lines are not part of
10529 windows, so the update is done directly on the frame matrix rows
10530 for the menu bar. */
10533 display_menu_bar (w
)
10536 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10541 /* Don't do all this for graphical frames. */
10543 if (!NILP (Vwindow_system
))
10546 #ifdef USE_X_TOOLKIT
10551 #ifdef USE_X_TOOLKIT
10552 xassert (!FRAME_WINDOW_P (f
));
10553 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MODE_LINE_FACE_ID
);
10554 it
.first_visible_x
= 0;
10555 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
10556 #else /* not USE_X_TOOLKIT */
10557 if (FRAME_WINDOW_P (f
))
10559 /* Menu bar lines are displayed in the desired matrix of the
10560 dummy window menu_bar_window. */
10561 struct window
*menu_w
;
10562 xassert (WINDOWP (f
->menu_bar_window
));
10563 menu_w
= XWINDOW (f
->menu_bar_window
);
10564 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
10565 MODE_LINE_FACE_ID
);
10566 it
.first_visible_x
= 0;
10567 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
10571 /* This is a TTY frame, i.e. character hpos/vpos are used as
10573 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
10574 MODE_LINE_FACE_ID
);
10575 it
.first_visible_x
= 0;
10576 it
.last_visible_x
= FRAME_WIDTH (f
);
10578 #endif /* not USE_X_TOOLKIT */
10580 /* Clear all rows of the menu bar. */
10581 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
10583 struct glyph_row
*row
= it
.glyph_row
+ i
;
10584 clear_glyph_row (row
);
10585 row
->enabled_p
= 1;
10586 row
->full_width_p
= 1;
10589 /* Make the first line of the menu bar appear in reverse video. */
10590 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
10592 /* Display all items of the menu bar. */
10593 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
10594 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
10596 Lisp_Object string
;
10598 /* Stop at nil string. */
10599 string
= XVECTOR (items
)->contents
[i
+ 1];
10603 /* Remember where item was displayed. */
10604 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
10606 /* Display the item, pad with one space. */
10607 if (it
.current_x
< it
.last_visible_x
)
10608 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
10609 XSTRING (string
)->size
+ 1, 0, 0, -1);
10612 /* Fill out the line with spaces. */
10613 if (it
.current_x
< it
.last_visible_x
)
10614 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
10616 /* Compute the total height of the lines. */
10617 compute_line_metrics (&it
);
10622 /***********************************************************************
10624 ***********************************************************************/
10626 /* Display the mode and/or top line of window W. */
10629 display_mode_lines (w
)
10632 /* These will be set while the mode line specs are processed. */
10633 line_number_displayed
= 0;
10634 w
->column_number_displayed
= Qnil
;
10636 if (WINDOW_WANTS_MODELINE_P (w
))
10637 display_mode_line (w
, MODE_LINE_FACE_ID
, current_buffer
->mode_line_format
);
10639 if (WINDOW_WANTS_TOP_LINE_P (w
))
10640 display_mode_line (w
, TOP_LINE_FACE_ID
, current_buffer
->top_line_format
);
10644 /* Display mode or top line of window W. FACE_ID specifies which line
10645 to display; it is either MODE_LINE_FACE_ID or TOP_LINE_FACE_ID.
10646 FORMAT is the mode line format to display. */
10649 display_mode_line (w
, face_id
, format
)
10651 enum face_id face_id
;
10652 Lisp_Object format
;
10657 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
10658 prepare_desired_row (it
.glyph_row
);
10660 /* Temporarily make frame's keyboard the current kboard so that
10661 kboard-local variables in the mode_line_format will get the right
10663 push_frame_kboard (it
.f
);
10664 display_mode_element (&it
, 0, 0, 0, format
);
10665 pop_frame_kboard ();
10667 /* Fill up with spaces. */
10668 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
10670 compute_line_metrics (&it
);
10671 it
.glyph_row
->full_width_p
= 1;
10672 it
.glyph_row
->mode_line_p
= 1;
10673 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
10674 it
.glyph_row
->continued_p
= 0;
10675 it
.glyph_row
->truncated_on_left_p
= 0;
10676 it
.glyph_row
->truncated_on_right_p
= 0;
10678 /* Make a 3D mode-line have a shadow at its right end. */
10679 face
= FACE_FROM_ID (it
.f
, face_id
);
10680 extend_face_to_end_of_line (&it
);
10681 if (face
->box
!= FACE_NO_BOX
)
10683 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
10684 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
10685 last
->right_box_line_p
= 1;
10690 /* Contribute ELT to the mode line for window IT->w. How it
10691 translates into text depends on its data type.
10693 IT describes the display environment in which we display, as usual.
10695 DEPTH is the depth in recursion. It is used to prevent
10696 infinite recursion here.
10698 FIELD_WIDTH is the number of characters the display of ELT should
10699 occupy in the mode line, and PRECISION is the maximum number of
10700 characters to display from ELT's representation. See
10701 display_string for details. *
10703 Returns the hpos of the end of the text generated by ELT. */
10706 display_mode_element (it
, depth
, field_width
, precision
, elt
)
10709 int field_width
, precision
;
10712 int n
= 0, field
, prec
;
10720 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
10724 /* A string: output it and check for %-constructs within it. */
10726 unsigned char *this = XSTRING (elt
)->data
;
10727 unsigned char *lisp_string
= this;
10729 while ((precision
<= 0 || n
< precision
)
10731 && (frame_title_ptr
10732 || it
->current_x
< it
->last_visible_x
))
10734 unsigned char *last
= this;
10736 /* Advance to end of string or next format specifier. */
10737 while ((c
= *this++) != '\0' && c
!= '%')
10740 if (this - 1 != last
)
10742 /* Output to end of string or up to '%'. Field width
10743 is length of string. Don't output more than
10744 PRECISION allows us. */
10745 prec
= --this - last
;
10746 if (precision
> 0 && prec
> precision
- n
)
10747 prec
= precision
- n
;
10749 if (frame_title_ptr
)
10750 n
+= store_frame_title (last
, prec
, prec
);
10752 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
10753 it
, 0, prec
, 0, -1);
10755 else /* c == '%' */
10757 unsigned char *percent_position
= this;
10759 /* Get the specified minimum width. Zero means
10762 while ((c
= *this++) >= '0' && c
<= '9')
10763 field
= field
* 10 + c
- '0';
10765 /* Don't pad beyond the total padding allowed. */
10766 if (field_width
- n
> 0 && field
> field_width
- n
)
10767 field
= field_width
- n
;
10769 /* Note that either PRECISION <= 0 or N < PRECISION. */
10770 prec
= precision
- n
;
10773 n
+= display_mode_element (it
, depth
, field
, prec
,
10774 Vglobal_mode_string
);
10777 unsigned char *spec
10778 = decode_mode_spec (it
->w
, c
, field
, prec
);
10780 if (frame_title_ptr
)
10781 n
+= store_frame_title (spec
, field
, prec
);
10785 = it
->glyph_row
->used
[TEXT_AREA
];
10787 = percent_position
- XSTRING (elt
)->data
;
10789 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
10790 field
, prec
, 0, -1);
10792 /* Assign to the glyphs written above the
10793 string where the `%x' came from, position
10797 struct glyph
*glyph
10798 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
10802 for (i
= 0; i
< nwritten
; ++i
)
10804 glyph
[i
].object
= elt
;
10805 glyph
[i
].charpos
= charpos
;
10818 /* A symbol: process the value of the symbol recursively
10819 as if it appeared here directly. Avoid error if symbol void.
10820 Special case: if value of symbol is a string, output the string
10823 register Lisp_Object tem
;
10824 tem
= Fboundp (elt
);
10827 tem
= Fsymbol_value (elt
);
10828 /* If value is a string, output that string literally:
10829 don't check for % within it. */
10832 prec
= XSTRING (tem
)->size
;
10833 if (precision
> 0 && prec
> precision
- n
)
10834 prec
= precision
- n
;
10835 if (frame_title_ptr
)
10836 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
10838 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
10841 else if (!EQ (tem
, elt
))
10843 /* Give up right away for nil or t. */
10853 register Lisp_Object car
, tem
;
10855 /* A cons cell: three distinct cases.
10856 If first element is a string or a cons, process all the elements
10857 and effectively concatenate them.
10858 If first element is a negative number, truncate displaying cdr to
10859 at most that many characters. If positive, pad (with spaces)
10860 to at least that many characters.
10861 If first element is a symbol, process the cadr or caddr recursively
10862 according to whether the symbol's value is non-nil or nil. */
10863 car
= XCONS (elt
)->car
;
10864 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
10866 /* An element of the form (:eval FORM) means evaluate FORM
10867 and use the result as mode line elements. */
10868 struct gcpro gcpro1
;
10871 spec
= eval_form (XCAR (XCDR (elt
)));
10873 n
+= display_mode_element (it
, depth
, field_width
- n
,
10874 precision
- n
, spec
);
10877 else if (SYMBOLP (car
))
10879 tem
= Fboundp (car
);
10880 elt
= XCONS (elt
)->cdr
;
10883 /* elt is now the cdr, and we know it is a cons cell.
10884 Use its car if CAR has a non-nil value. */
10887 tem
= Fsymbol_value (car
);
10889 { elt
= XCONS (elt
)->car
; goto tail_recurse
; }
10891 /* Symbol's value is nil (or symbol is unbound)
10892 Get the cddr of the original list
10893 and if possible find the caddr and use that. */
10894 elt
= XCONS (elt
)->cdr
;
10897 else if (!CONSP (elt
))
10899 elt
= XCONS (elt
)->car
;
10902 else if (INTEGERP (car
))
10904 register int lim
= XINT (car
);
10905 elt
= XCONS (elt
)->cdr
;
10908 /* Negative int means reduce maximum width. */
10909 if (precision
<= 0)
10912 precision
= min (precision
, -lim
);
10916 /* Padding specified. Don't let it be more than
10917 current maximum. */
10919 lim
= min (precision
, lim
);
10921 /* If that's more padding than already wanted, queue it.
10922 But don't reduce padding already specified even if
10923 that is beyond the current truncation point. */
10924 field_width
= max (lim
, field_width
);
10928 else if (STRINGP (car
) || CONSP (car
))
10930 register int limit
= 50;
10931 /* Limit is to protect against circular lists. */
10934 && (precision
<= 0 || n
< precision
))
10936 n
+= display_mode_element (it
, depth
, field_width
- n
,
10937 precision
- n
, XCONS (elt
)->car
);
10938 elt
= XCONS (elt
)->cdr
;
10946 if (frame_title_ptr
)
10947 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
10949 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
10950 precision
- n
, 0, 0);
10954 /* Pad to FIELD_WIDTH. */
10955 if (field_width
> 0 && n
< field_width
)
10957 if (frame_title_ptr
)
10958 n
+= store_frame_title ("", field_width
- n
, 0);
10960 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
10968 /* Write a null-terminated, right justified decimal representation of
10969 the positive integer D to BUF using a minimal field width WIDTH. */
10972 pint2str (buf
, width
, d
)
10973 register char *buf
;
10974 register int width
;
10977 register char *p
= buf
;
10985 *p
++ = d
% 10 + '0';
10990 for (width
-= (int) (p
- buf
); width
> 0; --width
)
11001 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
11002 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
11003 type of CODING_SYSTEM. Return updated pointer into BUF. */
11005 static unsigned char invalid_eol_type
[] = "(*invalid*)";
11008 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
11009 Lisp_Object coding_system
;
11010 register char *buf
;
11014 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
11015 unsigned char *eol_str
;
11017 /* The EOL conversion we are using. */
11018 Lisp_Object eoltype
;
11020 val
= coding_system
;
11022 if (NILP (val
)) /* Not yet decided. */
11027 eoltype
= eol_mnemonic_undecided
;
11028 /* Don't mention EOL conversion if it isn't decided. */
11032 Lisp_Object eolvalue
;
11034 eolvalue
= Fget (coding_system
, Qeol_type
);
11036 while (!NILP (val
) && SYMBOLP (val
))
11038 val
= Fget (val
, Qcoding_system
);
11039 if (NILP (eolvalue
))
11040 eolvalue
= Fget (val
, Qeol_type
);
11044 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
11048 /* The EOL conversion that is normal on this system. */
11050 if (NILP (eolvalue
)) /* Not yet decided. */
11051 eoltype
= eol_mnemonic_undecided
;
11052 else if (VECTORP (eolvalue
)) /* Not yet decided. */
11053 eoltype
= eol_mnemonic_undecided
;
11054 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
11055 eoltype
= (XFASTINT (eolvalue
) == 0
11056 ? eol_mnemonic_unix
11057 : (XFASTINT (eolvalue
) == 1
11058 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
11064 /* Mention the EOL conversion if it is not the usual one. */
11065 if (STRINGP (eoltype
))
11067 eol_str
= XSTRING (eoltype
)->data
;
11068 eol_str_len
= XSTRING (eoltype
)->size
;
11070 else if (INTEGERP (eoltype
)
11071 && CHAR_VALID_P (XINT (eoltype
), 0))
11073 int c
= XINT (eoltype
);
11074 unsigned char work
[4];
11076 eol_str_len
= CHAR_STRING (XINT (eoltype
), work
, eol_str
);
11080 eol_str
= invalid_eol_type
;
11081 eol_str_len
= sizeof (invalid_eol_type
) - 1;
11083 bcopy (eol_str
, buf
, eol_str_len
);
11084 buf
+= eol_str_len
;
11090 /* Return a string for the output of a mode line %-spec for window W,
11091 generated by character C. PRECISION >= 0 means don't return a
11092 string longer than that value. FIELD_WIDTH > 0 means pad the
11093 string returned with spaces to that value. */
11095 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
11098 decode_mode_spec (w
, c
, field_width
, precision
)
11101 int field_width
, precision
;
11104 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11105 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
11106 struct buffer
*b
= XBUFFER (w
->buffer
);
11113 if (!NILP (b
->read_only
))
11115 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
11120 /* This differs from %* only for a modified read-only buffer. */
11121 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
11123 if (!NILP (b
->read_only
))
11128 /* This differs from %* in ignoring read-only-ness. */
11129 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
11141 if (command_loop_level
> 5)
11143 p
= decode_mode_spec_buf
;
11144 for (i
= 0; i
< command_loop_level
; i
++)
11147 return decode_mode_spec_buf
;
11155 if (command_loop_level
> 5)
11157 p
= decode_mode_spec_buf
;
11158 for (i
= 0; i
< command_loop_level
; i
++)
11161 return decode_mode_spec_buf
;
11168 /* Let lots_of_dashes be a string of infinite length. */
11169 if (field_width
<= 0
11170 || field_width
> sizeof (lots_of_dashes
))
11172 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
11173 decode_mode_spec_buf
[i
] = '-';
11174 decode_mode_spec_buf
[i
] = '\0';
11175 return decode_mode_spec_buf
;
11178 return lots_of_dashes
;
11187 int col
= current_column ();
11188 XSETFASTINT (w
->column_number_displayed
, col
);
11189 pint2str (decode_mode_spec_buf
, field_width
, col
);
11190 return decode_mode_spec_buf
;
11194 /* %F displays the frame name. */
11195 if (!NILP (f
->title
))
11196 return (char *) XSTRING (f
->title
)->data
;
11197 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
11198 return (char *) XSTRING (f
->name
)->data
;
11207 int startpos
= XMARKER (w
->start
)->charpos
;
11208 int startpos_byte
= marker_byte_position (w
->start
);
11209 int line
, linepos
, linepos_byte
, topline
;
11211 int height
= XFASTINT (w
->height
);
11213 /* If we decided that this buffer isn't suitable for line numbers,
11214 don't forget that too fast. */
11215 if (EQ (w
->base_line_pos
, w
->buffer
))
11217 /* But do forget it, if the window shows a different buffer now. */
11218 else if (BUFFERP (w
->base_line_pos
))
11219 w
->base_line_pos
= Qnil
;
11221 /* If the buffer is very big, don't waste time. */
11222 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
11224 w
->base_line_pos
= Qnil
;
11225 w
->base_line_number
= Qnil
;
11229 if (!NILP (w
->base_line_number
)
11230 && !NILP (w
->base_line_pos
)
11231 && XFASTINT (w
->base_line_pos
) <= startpos
)
11233 line
= XFASTINT (w
->base_line_number
);
11234 linepos
= XFASTINT (w
->base_line_pos
);
11235 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
11240 linepos
= BUF_BEGV (b
);
11241 linepos_byte
= BUF_BEGV_BYTE (b
);
11244 /* Count lines from base line to window start position. */
11245 nlines
= display_count_lines (linepos
, linepos_byte
,
11249 topline
= nlines
+ line
;
11251 /* Determine a new base line, if the old one is too close
11252 or too far away, or if we did not have one.
11253 "Too close" means it's plausible a scroll-down would
11254 go back past it. */
11255 if (startpos
== BUF_BEGV (b
))
11257 XSETFASTINT (w
->base_line_number
, topline
);
11258 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
11260 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
11261 || linepos
== BUF_BEGV (b
))
11263 int limit
= BUF_BEGV (b
);
11264 int limit_byte
= BUF_BEGV_BYTE (b
);
11266 int distance
= (height
* 2 + 30) * 200;
11268 if (startpos
- distance
> limit
)
11270 limit
= startpos
- distance
;
11271 limit_byte
= CHAR_TO_BYTE (limit
);
11274 nlines
= display_count_lines (startpos
, startpos_byte
,
11276 - (height
* 2 + 30),
11278 /* If we couldn't find the lines we wanted within
11279 200 chars per line,
11280 give up on line numbers for this window. */
11281 if (position
== limit_byte
&& limit
== startpos
- distance
)
11283 w
->base_line_pos
= w
->buffer
;
11284 w
->base_line_number
= Qnil
;
11288 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
11289 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
11292 /* Now count lines from the start pos to point. */
11293 nlines
= display_count_lines (startpos
, startpos_byte
,
11294 PT_BYTE
, PT
, &junk
);
11296 /* Record that we did display the line number. */
11297 line_number_displayed
= 1;
11299 /* Make the string to show. */
11300 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
11301 return decode_mode_spec_buf
;
11304 char* p
= decode_mode_spec_buf
;
11305 int pad
= field_width
- 2;
11310 return decode_mode_spec_buf
;
11316 obj
= b
->mode_name
;
11320 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
11326 int pos
= marker_position (w
->start
);
11327 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
11329 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
11331 if (pos
<= BUF_BEGV (b
))
11336 else if (pos
<= BUF_BEGV (b
))
11340 if (total
> 1000000)
11341 /* Do it differently for a large value, to avoid overflow. */
11342 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
11344 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
11345 /* We can't normally display a 3-digit number,
11346 so get us a 2-digit number that is close. */
11349 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
11350 return decode_mode_spec_buf
;
11354 /* Display percentage of size above the bottom of the screen. */
11357 int toppos
= marker_position (w
->start
);
11358 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
11359 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
11361 if (botpos
>= BUF_ZV (b
))
11363 if (toppos
<= BUF_BEGV (b
))
11370 if (total
> 1000000)
11371 /* Do it differently for a large value, to avoid overflow. */
11372 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
11374 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
11375 /* We can't normally display a 3-digit number,
11376 so get us a 2-digit number that is close. */
11379 if (toppos
<= BUF_BEGV (b
))
11380 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
11382 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
11383 return decode_mode_spec_buf
;
11388 /* status of process */
11389 obj
= Fget_buffer_process (w
->buffer
);
11391 return "no process";
11392 #ifdef subprocesses
11393 obj
= Fsymbol_name (Fprocess_status (obj
));
11397 case 't': /* indicate TEXT or BINARY */
11398 #ifdef MODE_LINE_BINARY_TEXT
11399 return MODE_LINE_BINARY_TEXT (b
);
11405 /* coding-system (not including end-of-line format) */
11407 /* coding-system (including end-of-line type) */
11409 int eol_flag
= (c
== 'Z');
11410 char *p
= decode_mode_spec_buf
;
11412 if (! FRAME_WINDOW_P (f
))
11414 /* No need to mention EOL here--the terminal never needs
11415 to do EOL conversion. */
11416 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
11417 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
11419 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
11422 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
11423 #ifdef subprocesses
11424 obj
= Fget_buffer_process (Fcurrent_buffer ());
11425 if (PROCESSP (obj
))
11427 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
11429 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
11432 #endif /* subprocesses */
11435 return decode_mode_spec_buf
;
11440 return (char *) XSTRING (obj
)->data
;
11446 /* Count up to COUNT lines starting from START / START_BYTE.
11447 But don't go beyond LIMIT_BYTE.
11448 Return the number of lines thus found (always nonnegative).
11450 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
11453 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
11454 int start
, start_byte
, limit_byte
, count
;
11457 register unsigned char *cursor
;
11458 unsigned char *base
;
11460 register int ceiling
;
11461 register unsigned char *ceiling_addr
;
11462 int orig_count
= count
;
11464 /* If we are not in selective display mode,
11465 check only for newlines. */
11466 int selective_display
= (!NILP (current_buffer
->selective_display
)
11467 && !INTEGERP (current_buffer
->selective_display
));
11471 while (start_byte
< limit_byte
)
11473 ceiling
= BUFFER_CEILING_OF (start_byte
);
11474 ceiling
= min (limit_byte
- 1, ceiling
);
11475 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
11476 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
11479 if (selective_display
)
11480 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
11483 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
11486 if (cursor
!= ceiling_addr
)
11490 start_byte
+= cursor
- base
+ 1;
11491 *byte_pos_ptr
= start_byte
;
11495 if (++cursor
== ceiling_addr
)
11501 start_byte
+= cursor
- base
;
11506 while (start_byte
> limit_byte
)
11508 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
11509 ceiling
= max (limit_byte
, ceiling
);
11510 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
11511 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
11514 if (selective_display
)
11515 while (--cursor
!= ceiling_addr
11516 && *cursor
!= '\n' && *cursor
!= 015)
11519 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
11522 if (cursor
!= ceiling_addr
)
11526 start_byte
+= cursor
- base
+ 1;
11527 *byte_pos_ptr
= start_byte
;
11528 /* When scanning backwards, we should
11529 not count the newline posterior to which we stop. */
11530 return - orig_count
- 1;
11536 /* Here we add 1 to compensate for the last decrement
11537 of CURSOR, which took it past the valid range. */
11538 start_byte
+= cursor
- base
+ 1;
11542 *byte_pos_ptr
= limit_byte
;
11545 return - orig_count
+ count
;
11546 return orig_count
- count
;
11552 /***********************************************************************
11554 ***********************************************************************/
11556 /* Display a NUL-terminated string, starting with index START.
11558 If STRING is non-null, display that C string. Otherwise, the Lisp
11559 string LISP_STRING is displayed.
11561 If FACE_STRING is not nil, FACE_STRING_POS is a position in
11562 FACE_STRING. Display STRING or LISP_STRING with the face at
11563 FACE_STRING_POS in FACE_STRING:
11565 Display the string in the environment given by IT, but use the
11566 standard display table, temporarily.
11568 FIELD_WIDTH is the minimum number of output glyphs to produce.
11569 If STRING has fewer characters than FIELD_WIDTH, pad to the right
11570 with spaces. If STRING has more characters, more than FIELD_WIDTH
11571 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
11573 PRECISION is the maximum number of characters to output from
11574 STRING. PRECISION < 0 means don't truncate the string.
11576 This is roughly equivalent to printf format specifiers:
11578 FIELD_WIDTH PRECISION PRINTF
11579 ----------------------------------------
11585 MULTIBYTE zero means do not display multibyte chars, > 0 means do
11586 display them, and < 0 means obey the current buffer's value of
11587 enable_multibyte_characters.
11589 Value is the number of glyphs produced. */
11592 display_string (string
, lisp_string
, face_string
, face_string_pos
,
11593 start
, it
, field_width
, precision
, max_x
, multibyte
)
11594 unsigned char *string
;
11595 Lisp_Object lisp_string
;
11598 int field_width
, precision
, max_x
;
11601 int hpos_at_start
= it
->hpos
;
11602 int saved_face_id
= it
->face_id
;
11603 struct glyph_row
*row
= it
->glyph_row
;
11605 /* Initialize the iterator IT for iteration over STRING beginning
11606 with index START. We assume that IT may be modified here (which
11607 means that display_line has to do something when displaying a
11608 mini-buffer prompt, which it does). */
11609 reseat_to_string (it
, string
, lisp_string
, start
,
11610 precision
, field_width
, multibyte
);
11612 /* If displaying STRING, set up the face of the iterator
11613 from LISP_STRING, if that's given. */
11614 if (STRINGP (face_string
))
11620 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
11621 0, it
->region_beg_charpos
,
11622 it
->region_end_charpos
,
11623 &endptr
, it
->base_face_id
);
11624 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11625 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
11628 /* Set max_x to the maximum allowed X position. Don't let it go
11629 beyond the right edge of the window. */
11631 max_x
= it
->last_visible_x
;
11633 max_x
= min (max_x
, it
->last_visible_x
);
11635 /* Skip over display elements that are not visible. because IT->w is
11637 if (it
->current_x
< it
->first_visible_x
)
11638 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
11639 MOVE_TO_POS
| MOVE_TO_X
);
11641 row
->ascent
= it
->max_ascent
;
11642 row
->height
= it
->max_ascent
+ it
->max_descent
;
11644 /* This condition is for the case that we are called with current_x
11645 past last_visible_x. */
11646 while (it
->current_x
< max_x
)
11648 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
11650 /* Get the next display element. */
11651 if (!get_next_display_element (it
))
11654 /* Produce glyphs. */
11655 x_before
= it
->current_x
;
11656 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
11657 PRODUCE_GLYPHS (it
);
11659 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
11662 while (i
< nglyphs
)
11664 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11666 if (!it
->truncate_lines_p
11667 && x
+ glyph
->pixel_width
> max_x
)
11669 /* End of continued line or max_x reached. */
11670 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11674 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
11676 /* Glyph is at least partially visible. */
11678 if (x
< it
->first_visible_x
)
11679 it
->glyph_row
->x
= x
- it
->first_visible_x
;
11683 /* Glyph is off the left margin of the display area.
11684 Should not happen. */
11688 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11689 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11690 x
+= glyph
->pixel_width
;
11694 /* Stop if max_x reached. */
11698 /* Stop at line ends. */
11699 if (ITERATOR_AT_END_OF_LINE_P (it
))
11701 it
->continuation_lines_width
= 0;
11705 set_iterator_to_next (it
);
11707 /* Stop if truncating at the right edge. */
11708 if (it
->truncate_lines_p
11709 && it
->current_x
>= it
->last_visible_x
)
11711 /* Add truncation mark, but don't do it if the line is
11712 truncated at a padding space. */
11713 if (IT_CHARPOS (*it
) < it
->string_nchars
)
11715 if (!FRAME_WINDOW_P (it
->f
))
11716 produce_special_glyphs (it
, IT_TRUNCATION
);
11717 it
->glyph_row
->truncated_on_right_p
= 1;
11723 /* Maybe insert a truncation at the left. */
11724 if (it
->first_visible_x
11725 && IT_CHARPOS (*it
) > 0)
11727 if (!FRAME_WINDOW_P (it
->f
))
11728 insert_left_trunc_glyphs (it
);
11729 it
->glyph_row
->truncated_on_left_p
= 1;
11732 it
->face_id
= saved_face_id
;
11734 /* Value is number of columns displayed. */
11735 return it
->hpos
- hpos_at_start
;
11740 /* This is like a combination of memq and assq. Return 1 if PROPVAL
11741 appears as an element of LIST or as the car of an element of LIST.
11742 If PROPVAL is a list, compare each element against LIST in that
11743 way, and return 1 if any element of PROPVAL is found in LIST.
11744 Otherwise return 0. This function cannot quit. */
11747 invisible_p (propval
, list
)
11748 register Lisp_Object propval
;
11751 register Lisp_Object tail
, proptail
;
11752 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
11754 register Lisp_Object tem
;
11755 tem
= XCONS (tail
)->car
;
11756 if (EQ (propval
, tem
))
11758 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
11761 if (CONSP (propval
))
11762 for (proptail
= propval
; CONSP (proptail
);
11763 proptail
= XCONS (proptail
)->cdr
)
11765 Lisp_Object propelt
;
11766 propelt
= XCONS (proptail
)->car
;
11767 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
11769 register Lisp_Object tem
;
11770 tem
= XCONS (tail
)->car
;
11771 if (EQ (propelt
, tem
))
11773 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
11781 /* Return 1 if PROPVAL appears as the car of an element of LIST and
11782 the cdr of that element is non-nil. If PROPVAL is a list, check
11783 each element of PROPVAL in that way, and the first time some
11784 element is found, return 1 if the cdr of that element is non-nil.
11785 Otherwise return 0. This function cannot quit. */
11788 invisible_ellipsis_p (propval
, list
)
11789 register Lisp_Object propval
;
11792 register Lisp_Object tail
, proptail
;
11793 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
11795 register Lisp_Object tem
;
11796 tem
= XCONS (tail
)->car
;
11797 if (CONSP (tem
) && EQ (propval
, XCONS (tem
)->car
))
11798 return ! NILP (XCONS (tem
)->cdr
);
11800 if (CONSP (propval
))
11801 for (proptail
= propval
; CONSP (proptail
);
11802 proptail
= XCONS (proptail
)->cdr
)
11804 Lisp_Object propelt
;
11805 propelt
= XCONS (proptail
)->car
;
11806 for (tail
= list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
11808 register Lisp_Object tem
;
11809 tem
= XCONS (tail
)->car
;
11810 if (CONSP (tem
) && EQ (propelt
, XCONS (tem
)->car
))
11811 return ! NILP (XCONS (tem
)->cdr
);
11819 /***********************************************************************
11821 ***********************************************************************/
11826 echo_area_message
= previous_echo_area_message
= Qnil
;
11827 staticpro (&echo_area_message
);
11828 staticpro (&previous_echo_area_message
);
11830 staticpro (&Qinhibit_redisplay
);
11831 Qinhibit_redisplay
= intern ("inhibit-redisplay");
11834 defsubr (&Sdump_glyph_matrix
);
11835 defsubr (&Sdump_glyph_row
);
11836 defsubr (&Sdump_toolbar_row
);
11837 defsubr (&Strace_redisplay_toggle
);
11840 staticpro (&Qmenu_bar_update_hook
);
11841 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
11843 staticpro (&Qoverriding_terminal_local_map
);
11844 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
11846 staticpro (&Qoverriding_local_map
);
11847 Qoverriding_local_map
= intern ("overriding-local-map");
11849 staticpro (&Qwindow_scroll_functions
);
11850 Qwindow_scroll_functions
= intern ("window-scroll-functions");
11852 staticpro (&Qredisplay_end_trigger_functions
);
11853 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
11855 staticpro (&Qinhibit_point_motion_hooks
);
11856 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
11858 staticpro (&Qdisplay
);
11859 Qdisplay
= intern ("display");
11860 staticpro (&Qleft_margin
);
11861 Qspace_width
= intern ("space-width");
11862 staticpro (&Qspace_width
);
11863 Qheight
= intern ("height");
11864 staticpro (&Qheight
);
11865 Qraise
= intern ("raise");
11866 staticpro (&Qraise
);
11867 Qspace
= intern ("space");
11868 staticpro (&Qspace
);
11869 Qleft_margin
= intern ("left-margin");
11870 staticpro (&Qright_margin
);
11871 Qright_margin
= intern ("right-margin");
11872 Qalign_to
= intern ("align-to");
11873 staticpro (&Qalign_to
);
11874 QCalign_to
= intern (":align-to");
11875 staticpro (&QCalign_to
);
11876 Qwidth
= intern ("width");
11877 staticpro (&Qwidth
);
11878 Qrelative_width
= intern ("relative-width");
11879 staticpro (&Qrelative_width
);
11880 QCrelative_width
= intern (":relative-width");
11881 staticpro (&QCrelative_width
);
11882 QCrelative_height
= intern (":relative-height");
11883 staticpro (&QCrelative_height
);
11884 QCeval
= intern (":eval");
11885 staticpro (&QCeval
);
11886 QCwhen
= intern (":when");
11887 staticpro (&QCwhen
);
11888 Qfontified
= intern ("fontified");
11889 staticpro (&Qfontified
);
11890 Qfontification_functions
= intern ("fontification-functions");
11891 staticpro (&Qfontification_functions
);
11892 Qshow_trailing_whitespace
= intern ("show-trailing-whitespace");
11893 staticpro (&Qshow_trailing_whitespace
);
11894 Qtrailing_whitespace
= intern ("trailing-whitespace");
11895 staticpro (&Qtrailing_whitespace
);
11896 Qimage
= intern ("image");
11897 staticpro (&Qimage
);
11899 staticpro (&last_arrow_position
);
11900 staticpro (&last_arrow_string
);
11901 last_arrow_position
= Qnil
;
11902 last_arrow_string
= Qnil
;
11904 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
11905 "Non-nil means don't actually do any redisplay.\n\
11906 This is used for internal purposes.");
11907 Vinhibit_redisplay
= Qnil
;
11909 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
11910 "String (or mode line construct) included (normally) in `mode-line-format'.");
11911 Vglobal_mode_string
= Qnil
;
11913 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
11914 "Marker for where to display an arrow on top of the buffer text.\n\
11915 This must be the beginning of a line in order to work.\n\
11916 See also `overlay-arrow-string'.");
11917 Voverlay_arrow_position
= Qnil
;
11919 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
11920 "String to display as an arrow. See also `overlay-arrow-position'.");
11921 Voverlay_arrow_string
= Qnil
;
11923 DEFVAR_INT ("scroll-step", &scroll_step
,
11924 "*The number of lines to try scrolling a window by when point moves out.\n\
11925 If that fails to bring point back on frame, point is centered instead.\n\
11926 If this is zero, point is always centered after it moves off frame.");
11928 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
11929 "*Scroll up to this many lines, to bring point back on screen.");
11930 scroll_conservatively
= 0;
11932 DEFVAR_INT ("scroll-margin", &scroll_margin
,
11933 "*Number of lines of margin at the top and bottom of a window.\n\
11934 Recenter the window whenever point gets within this many lines\n\
11935 of the top or bottom of the window.");
11939 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
11942 DEFVAR_BOOL ("truncate-partial-width-windows",
11943 &truncate_partial_width_windows
,
11944 "*Non-nil means truncate lines in all windows less than full frame wide.");
11945 truncate_partial_width_windows
= 1;
11947 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
11948 "*Non-nil means use inverse video for the mode line.");
11949 mode_line_inverse_video
= 1;
11951 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
11952 "*Maximum buffer size for which line number should be displayed.\n\
11953 If the buffer is bigger than this, the line number does not appear\n\
11954 in the mode line.");
11955 line_number_display_limit
= 1000000;
11957 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
11958 "*Non-nil means highlight region even in nonselected windows.");
11959 highlight_nonselected_windows
= 0;
11961 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
11962 "Non-nil if more than one frame is visible on this display.\n\
11963 Minibuffer-only frames don't count, but iconified frames do.\n\
11964 This variable is not guaranteed to be accurate except while processing\n\
11965 `frame-title-format' and `icon-title-format'.");
11967 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
11968 "Template for displaying the title bar of visible frames.\n\
11969 \(Assuming the window manager supports this feature.)\n\
11970 This variable has the same structure as `mode-line-format' (which see),\n\
11971 and is used only on frames for which no explicit name has been set\n\
11972 \(see `modify-frame-parameters').");
11973 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
11974 "Template for displaying the title bar of an iconified frame.\n\
11975 \(Assuming the window manager supports this feature.)\n\
11976 This variable has the same structure as `mode-line-format' (which see),\n\
11977 and is used only on frames for which no explicit name has been set\n\
11978 \(see `modify-frame-parameters').");
11980 = Vframe_title_format
11981 = Fcons (intern ("multiple-frames"),
11982 Fcons (build_string ("%b"),
11983 Fcons (Fcons (build_string (""),
11984 Fcons (intern ("invocation-name"),
11985 Fcons (build_string ("@"),
11986 Fcons (intern ("system-name"),
11990 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
11991 "Maximum number of lines to keep in the message log buffer.\n\
11992 If nil, disable message logging. If t, log messages but don't truncate\n\
11993 the buffer when it becomes large.");
11994 XSETFASTINT (Vmessage_log_max
, 50);
11996 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
11997 "Functions called before redisplay, if window sizes have changed.\n\
11998 The value should be a list of functions that take one argument.\n\
11999 Just before redisplay, for each frame, if any of its windows have changed\n\
12000 size since the last redisplay, or have been split or deleted,\n\
12001 all the functions in the list are called, with the frame as argument.");
12002 Vwindow_size_change_functions
= Qnil
;
12004 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
12005 "List of Functions to call before redisplaying a window with scrolling.\n\
12006 Each function is called with two arguments, the window\n\
12007 and its new display-start position. Note that the value of `window-end'\n\
12008 is not valid when these functions are called.");
12009 Vwindow_scroll_functions
= Qnil
;
12011 DEFVAR_BOOL ("auto-resize-toolbars", &auto_resize_toolbars_p
,
12012 "*Non-nil means automatically resize toolbars.\n\
12013 This increases a toolbar's height if not all toolbar items are visible.\n\
12014 It decreases a toolbar's height when it would display blank lines\n\
12016 auto_resize_toolbars_p
= 1;
12018 DEFVAR_BOOL ("auto-raise-toolbar-buttons", &auto_raise_toolbar_buttons_p
,
12019 "*Non-nil means raise toolbar buttons when the mouse moves over them.");
12020 auto_raise_toolbar_buttons_p
= 1;
12022 DEFVAR_INT ("toolbar-button-margin", &toolbar_button_margin
,
12023 "*Margin around toolbar buttons in pixels.");
12024 toolbar_button_margin
= 1;
12026 DEFVAR_INT ("toolbar-button-relief", &toolbar_button_relief
,
12027 "Relief thickness of toolbar buttons.");
12028 toolbar_button_relief
= 3;
12030 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
12031 "List of functions to call to fontify regions of text.\n\
12032 Each function is called with one argument POS. Functions must\n\
12033 fontify a region starting at POS in the current buffer, and give\n\
12034 fontified regions the property `fontified'.\n\
12035 This variable automatically becomes buffer-local when set.");
12036 Vfontification_functions
= Qnil
;
12037 Fmake_local_variable (Qfontification_functions
);
12039 DEFVAR_BOOL ("unibyte-display-via-language-environment",
12040 &unibyte_display_via_language_environment
,
12041 "*Non-nil means display unibyte text according to language environment.\n\
12042 Specifically this means that unibyte non-ASCII characters\n\
12043 are displayed by converting them to the equivalent multibyte characters\n\
12044 according to the current language environment. As a result, they are\n\
12045 displayed according to the current fontset.");
12046 unibyte_display_via_language_environment
= 0;
12050 /* Initialize this module when Emacs starts. */
12055 Lisp_Object root_window
;
12056 struct window
*mini_w
;
12058 CHARPOS (this_line_start_pos
) = 0;
12060 mini_w
= XWINDOW (minibuf_window
);
12061 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
12063 echo_area_glyphs
= 0;
12064 previous_echo_glyphs
= 0;
12065 echo_area_message
= previous_echo_area_message
= Qnil
;
12067 if (!noninteractive
)
12069 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
12072 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
12073 set_window_height (root_window
,
12074 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
12076 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
12077 set_window_height (minibuf_window
, 1, 0);
12079 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
12080 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
12082 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
12083 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
12084 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
12086 /* The default ellipsis glyphs `...'. */
12087 for (i
= 0; i
< 3; ++i
)
12088 XSETFASTINT (default_invis_vector
[i
], '.');
12091 #ifdef HAVE_WINDOW_SYSTEM
12093 /* Allocate the buffer for frame titles. */
12095 frame_title_buf
= (char *) xmalloc (size
);
12096 frame_title_buf_end
= frame_title_buf
+ size
;
12097 frame_title_ptr
= NULL
;
12099 #endif /* HAVE_WINDOW_SYSTEM */