1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay() +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking a iterator structure (struct it)
126 Iteration over things to be be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator
128 (or init_string_iterator for that matter). Calls to
129 get_next_display_element fill the iterator structure with relevant
130 information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
175 #include "termchar.h"
176 #include "dispextern.h"
180 #include "commands.h"
183 #include "termhooks.h"
184 #include "intervals.h"
185 #include "keyboard.h"
188 #include "region-cache.h"
191 #ifdef HAVE_X_WINDOWS
198 #define min(a, b) ((a) < (b) ? (a) : (b))
199 #define max(a, b) ((a) > (b) ? (a) : (b))
201 #define INFINITY 10000000
203 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
204 extern void set_frame_menubar ();
205 extern int pending_menu_activation
;
208 extern int interrupt_input
;
209 extern int command_loop_level
;
211 extern int minibuffer_auto_raise
;
213 extern Lisp_Object Qface
;
215 extern Lisp_Object Voverriding_local_map
;
216 extern Lisp_Object Voverriding_local_map_menu_flag
;
217 extern Lisp_Object Qmenu_item
;
219 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
220 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
221 Lisp_Object Qredisplay_end_trigger_functions
;
222 Lisp_Object Qinhibit_point_motion_hooks
;
223 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
;
224 Lisp_Object Qfontified
;
226 /* Functions called to fontify regions of text. */
228 Lisp_Object Vfontification_functions
;
229 Lisp_Object Qfontification_functions
;
231 /* Non-zero means draw tool bar buttons raised when the mouse moves
234 int auto_raise_tool_bar_buttons_p
;
236 /* Margin around tool bar buttons in pixels. */
238 int tool_bar_button_margin
;
240 /* Thickness of shadow to draw around tool bar buttons. */
242 int tool_bar_button_relief
;
244 /* Non-zero means automatically resize tool-bars so that all tool-bar
245 items are visible, and no blank lines remain. */
247 int auto_resize_tool_bars_p
;
249 /* Non-nil means don't actually do any redisplay. */
251 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
253 /* Names of text properties relevant for redisplay. */
255 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
256 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
258 /* Symbols used in text property values. */
260 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
261 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
263 extern Lisp_Object Qheight
;
265 /* Non-nil means highlight trailing whitespace. */
267 Lisp_Object Vshow_trailing_whitespace
;
269 /* Name of the face used to highlight trailing whitespace. */
271 Lisp_Object Qtrailing_whitespace
;
273 /* The symbol `image' which is the car of the lists used to represent
278 /* Non-zero means print newline to stdout before next mini-buffer
281 int noninteractive_need_newline
;
283 /* Non-zero means print newline to message log before next message. */
285 static int message_log_need_newline
;
288 /* The buffer position of the first character appearing entirely or
289 partially on the line of the selected window which contains the
290 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
291 redisplay optimization in redisplay_internal. */
293 static struct text_pos this_line_start_pos
;
295 /* Number of characters past the end of the line above, including the
296 terminating newline. */
298 static struct text_pos this_line_end_pos
;
300 /* The vertical positions and the height of this line. */
302 static int this_line_vpos
;
303 static int this_line_y
;
304 static int this_line_pixel_height
;
306 /* X position at which this display line starts. Usually zero;
307 negative if first character is partially visible. */
309 static int this_line_start_x
;
311 /* Buffer that this_line_.* variables are referring to. */
313 static struct buffer
*this_line_buffer
;
315 /* Nonzero means truncate lines in all windows less wide than the
318 int truncate_partial_width_windows
;
320 /* A flag to control how to display unibyte 8-bit character. */
322 int unibyte_display_via_language_environment
;
324 /* Nonzero means we have more than one non-mini-buffer-only frame.
325 Not guaranteed to be accurate except while parsing
326 frame-title-format. */
330 Lisp_Object Vglobal_mode_string
;
332 /* Marker for where to display an arrow on top of the buffer text. */
334 Lisp_Object Voverlay_arrow_position
;
336 /* String to display for the arrow. Only used on terminal frames. */
338 Lisp_Object Voverlay_arrow_string
;
340 /* Values of those variables at last redisplay. However, if
341 Voverlay_arrow_position is a marker, last_arrow_position is its
342 numerical position. */
344 static Lisp_Object last_arrow_position
, last_arrow_string
;
346 /* Like mode-line-format, but for the title bar on a visible frame. */
348 Lisp_Object Vframe_title_format
;
350 /* Like mode-line-format, but for the title bar on an iconified frame. */
352 Lisp_Object Vicon_title_format
;
354 /* List of functions to call when a window's size changes. These
355 functions get one arg, a frame on which one or more windows' sizes
358 static Lisp_Object Vwindow_size_change_functions
;
360 Lisp_Object Qmenu_bar_update_hook
;
362 /* Nonzero if overlay arrow has been displayed once in this window. */
364 static int overlay_arrow_seen
;
366 /* Nonzero means highlight the region even in nonselected windows. */
368 int highlight_nonselected_windows
;
370 /* If cursor motion alone moves point off frame, try scrolling this
371 many lines up or down if that will bring it back. */
373 static int scroll_step
;
375 /* Non-0 means scroll just far enough to bring point back on the
376 screen, when appropriate. */
378 static int scroll_conservatively
;
380 /* Recenter the window whenever point gets within this many lines of
381 the top or bottom of the window. This value is translated into a
382 pixel value by multiplying it with CANON_Y_UNIT, which means that
383 there is really a fixed pixel height scroll margin. */
387 /* Number of windows showing the buffer of the selected window (or
388 another buffer with the same base buffer). keyboard.c refers to
393 /* Vector containing glyphs for an ellipsis `...'. */
395 static Lisp_Object default_invis_vector
[3];
397 /* Nonzero means display mode line highlighted. */
399 int mode_line_inverse_video
;
401 /* Prompt to display in front of the mini-buffer contents. */
403 Lisp_Object minibuf_prompt
;
405 /* Width of current mini-buffer prompt. Only set after display_line
406 of the line that contains the prompt. */
408 int minibuf_prompt_width
;
409 int minibuf_prompt_pixel_width
;
411 /* This is the window where the echo area message was displayed. It
412 is always a mini-buffer window, but it may not be the same window
413 currently active as a mini-buffer. */
415 Lisp_Object echo_area_window
;
417 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
418 pushes the current message and the value of
419 message_enable_multibyte on the stack, the function restore_message
420 pops the stack and displays MESSAGE again. */
422 Lisp_Object Vmessage_stack
;
424 /* Nonzero means multibyte characters were enabled when the echo area
425 message was specified. */
427 int message_enable_multibyte
;
429 /* True if we should redraw the mode lines on the next redisplay. */
431 int update_mode_lines
;
433 /* Nonzero if window sizes or contents have changed since last
434 redisplay that finished */
436 int windows_or_buffers_changed
;
438 /* Nonzero after display_mode_line if %l was used and it displayed a
441 int line_number_displayed
;
443 /* Maximum buffer size for which to display line numbers. */
445 static int line_number_display_limit
;
447 /* line width to consider when repostioning for line number display */
449 static int line_number_display_limit_width
;
451 /* Number of lines to keep in the message log buffer. t means
452 infinite. nil means don't log at all. */
454 Lisp_Object Vmessage_log_max
;
456 /* Current, index 0, and last displayed echo area message. Either
457 buffers from echo_buffers, or nil to indicate no message. */
459 Lisp_Object echo_area_buffer
[2];
461 /* The buffers referenced from echo_area_buffer. */
463 static Lisp_Object echo_buffer
[2];
465 /* A vector saved used in with_area_buffer to reduce consing. */
467 static Lisp_Object Vwith_echo_area_save_vector
;
469 /* Non-zero means display_echo_area should display the last echo area
470 message again. Set by redisplay_preserve_echo_area. */
472 static int display_last_displayed_message_p
;
474 /* Nonzero if echo area is being used by print; zero if being used by
477 int message_buf_print
;
479 /* Maximum height for resizing mini-windows. Either a float
480 specifying a fraction of the available height, or an integer
481 specifying a number of lines. */
483 static Lisp_Object Vmax_mini_window_height
;
485 /* Non-zero means we want a hollow cursor in windows that are not
486 selected. Zero means there's no cursor in such windows. */
488 int cursor_in_non_selected_windows
;
490 /* A scratch glyph row with contents used for generating truncation
491 glyphs. Also used in direct_output_for_insert. */
493 #define MAX_SCRATCH_GLYPHS 100
494 struct glyph_row scratch_glyph_row
;
495 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
497 /* Ascent and height of the last line processed by move_it_to. */
499 static int last_max_ascent
, last_height
;
501 /* The maximum distance to look ahead for text properties. Values
502 that are too small let us call compute_char_face and similar
503 functions too often which is expensive. Values that are too large
504 let us call compute_char_face and alike too often because we
505 might not be interested in text properties that far away. */
507 #define TEXT_PROP_DISTANCE_LIMIT 100
509 /* Non-zero means print traces of redisplay if compiled with
513 int trace_redisplay_p
;
516 /* Non-zero means automatically scroll windows horizontally to make
519 int automatic_hscrolling_p
;
521 /* A list of symbols, one for each supported image type. */
523 Lisp_Object Vimage_types
;
525 /* Value returned from text property handlers (see below). */
530 HANDLED_RECOMPUTE_PROPS
,
531 HANDLED_OVERLAY_STRING_CONSUMED
,
535 /* A description of text properties that redisplay is interested
540 /* The name of the property. */
543 /* A unique index for the property. */
546 /* A handler function called to set up iterator IT from the property
547 at IT's current position. Value is used to steer handle_stop. */
548 enum prop_handled (*handler
) P_ ((struct it
*it
));
551 static enum prop_handled handle_face_prop
P_ ((struct it
*));
552 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
553 static enum prop_handled handle_display_prop
P_ ((struct it
*));
554 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
555 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
556 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
558 /* Properties handled by iterators. */
560 static struct props it_props
[] =
562 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
563 /* Handle `face' before `display' because some sub-properties of
564 `display' need to know the face. */
565 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
566 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
567 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
568 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
572 /* Value is the position described by X. If X is a marker, value is
573 the marker_position of X. Otherwise, value is X. */
575 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
577 /* Enumeration returned by some move_it_.* functions internally. */
581 /* Not used. Undefined value. */
584 /* Move ended at the requested buffer position or ZV. */
585 MOVE_POS_MATCH_OR_ZV
,
587 /* Move ended at the requested X pixel position. */
590 /* Move within a line ended at the end of a line that must be
594 /* Move within a line ended at the end of a line that would
595 be displayed truncated. */
598 /* Move within a line ended at a line end. */
604 /* Function prototypes. */
606 static void ensure_echo_area_buffers
P_ ((void));
607 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
609 struct glyph_row
*));
610 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
611 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
612 static void clear_garbaged_frames
P_ ((void));
613 static int current_message_1
P_ ((Lisp_Object
*));
614 static int truncate_message_1
P_ ((int));
615 static int set_message_1
P_ ((char *s
, Lisp_Object
, int, int));
616 static int display_echo_area
P_ ((struct window
*));
617 static int display_echo_area_1
P_ ((struct window
*));
618 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
619 static int string_char_and_length
P_ ((unsigned char *, int, int *));
620 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
622 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
623 static Lisp_Object eval_handler
P_ ((Lisp_Object
));
624 static Lisp_Object eval_form
P_ ((Lisp_Object
));
625 static void insert_left_trunc_glyphs
P_ ((struct it
*));
626 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
627 static void extend_face_to_end_of_line
P_ ((struct it
*));
628 static int append_space
P_ ((struct it
*, int));
629 static void make_cursor_line_fully_visible
P_ ((struct window
*));
630 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
631 static int trailing_whitespace_p
P_ ((int));
632 static int message_log_check_duplicate
P_ ((int, int, int, int));
633 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
634 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
635 static void push_it
P_ ((struct it
*));
636 static void pop_it
P_ ((struct it
*));
637 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
638 static void redisplay_internal
P_ ((int));
639 static int echo_area_display
P_ ((int));
640 static void redisplay_windows
P_ ((Lisp_Object
));
641 static void redisplay_window
P_ ((Lisp_Object
, int));
642 static void update_menu_bar
P_ ((struct frame
*, int));
643 static int try_window_reusing_current_matrix
P_ ((struct window
*));
644 static int try_window_id
P_ ((struct window
*));
645 static int display_line
P_ ((struct it
*));
646 static void display_mode_lines
P_ ((struct window
*));
647 static void display_mode_line
P_ ((struct window
*, enum face_id
,
649 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
650 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
651 static void display_menu_bar
P_ ((struct window
*));
652 static int display_count_lines
P_ ((int, int, int, int, int *));
653 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
654 int, int, struct it
*, int, int, int, int));
655 static void compute_line_metrics
P_ ((struct it
*));
656 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
657 static int get_overlay_strings
P_ ((struct it
*));
658 static void next_overlay_string
P_ ((struct it
*));
659 void set_iterator_to_next
P_ ((struct it
*));
660 static void reseat
P_ ((struct it
*, struct text_pos
, int));
661 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
662 static void back_to_previous_visible_line_start
P_ ((struct it
*));
663 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
664 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
665 static int next_element_from_display_vector
P_ ((struct it
*));
666 static int next_element_from_string
P_ ((struct it
*));
667 static int next_element_from_c_string
P_ ((struct it
*));
668 static int next_element_from_buffer
P_ ((struct it
*));
669 static int next_element_from_composition
P_ ((struct it
*));
670 static int next_element_from_image
P_ ((struct it
*));
671 static int next_element_from_stretch
P_ ((struct it
*));
672 static void load_overlay_strings
P_ ((struct it
*));
673 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
674 struct display_pos
*));
675 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
676 Lisp_Object
, int, int, int, int));
677 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
679 void move_it_vertically_backward
P_ ((struct it
*, int));
680 static void init_to_row_start
P_ ((struct it
*, struct window
*,
681 struct glyph_row
*));
682 static void init_to_row_end
P_ ((struct it
*, struct window
*,
683 struct glyph_row
*));
684 static void back_to_previous_line_start
P_ ((struct it
*));
685 static void forward_to_next_line_start
P_ ((struct it
*));
686 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
688 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
689 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
690 static int number_of_chars
P_ ((unsigned char *, int));
691 static void compute_stop_pos
P_ ((struct it
*));
692 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
694 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
695 static int next_overlay_change
P_ ((int));
696 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
697 Lisp_Object
, struct text_pos
*));
699 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
700 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
702 #ifdef HAVE_WINDOW_SYSTEM
704 static void update_tool_bar
P_ ((struct frame
*, int));
705 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
706 static int redisplay_tool_bar
P_ ((struct frame
*));
707 static void display_tool_bar_line
P_ ((struct it
*));
709 #endif /* HAVE_WINDOW_SYSTEM */
712 /***********************************************************************
713 Window display dimensions
714 ***********************************************************************/
716 /* Return the window-relative maximum y + 1 for glyph rows displaying
717 text in window W. This is the height of W minus the height of a
718 mode line, if any. */
721 window_text_bottom_y (w
)
724 struct frame
*f
= XFRAME (w
->frame
);
725 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
727 if (WINDOW_WANTS_MODELINE_P (w
))
728 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
733 /* Return the pixel width of display area AREA of window W. AREA < 0
734 means return the total width of W, not including bitmap areas to
735 the left and right of the window. */
738 window_box_width (w
, area
)
742 struct frame
*f
= XFRAME (w
->frame
);
743 int width
= XFASTINT (w
->width
);
745 if (!w
->pseudo_window_p
)
747 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
749 if (area
== TEXT_AREA
)
751 if (INTEGERP (w
->left_margin_width
))
752 width
-= XFASTINT (w
->left_margin_width
);
753 if (INTEGERP (w
->right_margin_width
))
754 width
-= XFASTINT (w
->right_margin_width
);
756 else if (area
== LEFT_MARGIN_AREA
)
757 width
= (INTEGERP (w
->left_margin_width
)
758 ? XFASTINT (w
->left_margin_width
) : 0);
759 else if (area
== RIGHT_MARGIN_AREA
)
760 width
= (INTEGERP (w
->right_margin_width
)
761 ? XFASTINT (w
->right_margin_width
) : 0);
764 return width
* CANON_X_UNIT (f
);
768 /* Return the pixel height of the display area of window W, not
769 including mode lines of W, if any.. */
772 window_box_height (w
)
775 struct frame
*f
= XFRAME (w
->frame
);
776 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
778 if (WINDOW_WANTS_MODELINE_P (w
))
779 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
781 if (WINDOW_WANTS_HEADER_LINE_P (w
))
782 height
-= CURRENT_HEADER_LINE_HEIGHT (w
);
788 /* Return the frame-relative coordinate of the left edge of display
789 area AREA of window W. AREA < 0 means return the left edge of the
790 whole window, to the right of any bitmap area at the left side of
794 window_box_left (w
, area
)
798 struct frame
*f
= XFRAME (w
->frame
);
799 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
801 if (!w
->pseudo_window_p
)
803 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
804 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
806 if (area
== TEXT_AREA
)
807 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
808 else if (area
== RIGHT_MARGIN_AREA
)
809 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
810 + window_box_width (w
, TEXT_AREA
));
817 /* Return the frame-relative coordinate of the right edge of display
818 area AREA of window W. AREA < 0 means return the left edge of the
819 whole window, to the left of any bitmap area at the right side of
823 window_box_right (w
, area
)
827 return window_box_left (w
, area
) + window_box_width (w
, area
);
831 /* Get the bounding box of the display area AREA of window W, without
832 mode lines, in frame-relative coordinates. AREA < 0 means the
833 whole window, not including bitmap areas to the left and right of
834 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
835 coordinates of the upper-left corner of the box. Return in
836 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
839 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
842 int *box_x
, *box_y
, *box_width
, *box_height
;
844 struct frame
*f
= XFRAME (w
->frame
);
846 *box_width
= window_box_width (w
, area
);
847 *box_height
= window_box_height (w
);
848 *box_x
= window_box_left (w
, area
);
849 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
850 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
851 if (WINDOW_WANTS_HEADER_LINE_P (w
))
852 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
856 /* Get the bounding box of the display area AREA of window W, without
857 mode lines. AREA < 0 means the whole window, not including bitmap
858 areas to the left and right of the window. Return in *TOP_LEFT_X
859 and TOP_LEFT_Y the frame-relative pixel coordinates of the
860 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
861 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
865 window_box_edges (w
, area
, top_left_x
, top_left_y
,
866 bottom_right_x
, bottom_right_y
)
869 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
871 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
873 *bottom_right_x
+= *top_left_x
;
874 *bottom_right_y
+= *top_left_y
;
879 /***********************************************************************
881 ***********************************************************************/
883 /* Return the next character from STR which is MAXLEN bytes long.
884 Return in *LEN the length of the character. This is like
885 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
886 we find one, we return a `?', but with the length of the invalid
890 string_char_and_length (str
, maxlen
, len
)
896 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
897 if (!CHAR_VALID_P (c
, 1))
898 /* We may not change the length here because other places in Emacs
899 don't use this function, i.e. they silently accept invalid
908 /* Given a position POS containing a valid character and byte position
909 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
911 static struct text_pos
912 string_pos_nchars_ahead (pos
, string
, nchars
)
917 xassert (STRINGP (string
) && nchars
>= 0);
919 if (STRING_MULTIBYTE (string
))
921 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
922 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
927 string_char_and_length (p
, rest
, &len
);
928 p
+= len
, rest
-= len
;
931 BYTEPOS (pos
) += len
;
935 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
941 /* Value is the text position, i.e. character and byte position,
942 for character position CHARPOS in STRING. */
944 static INLINE
struct text_pos
945 string_pos (charpos
, string
)
950 xassert (STRINGP (string
));
951 xassert (charpos
>= 0);
952 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
957 /* Value is a text position, i.e. character and byte position, for
958 character position CHARPOS in C string S. MULTIBYTE_P non-zero
959 means recognize multibyte characters. */
961 static struct text_pos
962 c_string_pos (charpos
, s
, multibyte_p
)
970 xassert (charpos
>= 0);
974 int rest
= strlen (s
), len
;
976 SET_TEXT_POS (pos
, 0, 0);
979 string_char_and_length (s
, rest
, &len
);
980 s
+= len
, rest
-= len
;
983 BYTEPOS (pos
) += len
;
987 SET_TEXT_POS (pos
, charpos
, charpos
);
993 /* Value is the number of characters in C string S. MULTIBYTE_P
994 non-zero means recognize multibyte characters. */
997 number_of_chars (s
, multibyte_p
)
1005 int rest
= strlen (s
), len
;
1006 unsigned char *p
= (unsigned char *) s
;
1008 for (nchars
= 0; rest
> 0; ++nchars
)
1010 string_char_and_length (p
, rest
, &len
);
1011 rest
-= len
, p
+= len
;
1015 nchars
= strlen (s
);
1021 /* Compute byte position NEWPOS->bytepos corresponding to
1022 NEWPOS->charpos. POS is a known position in string STRING.
1023 NEWPOS->charpos must be >= POS.charpos. */
1026 compute_string_pos (newpos
, pos
, string
)
1027 struct text_pos
*newpos
, pos
;
1030 xassert (STRINGP (string
));
1031 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1033 if (STRING_MULTIBYTE (string
))
1034 *newpos
= string_pos_nchars_ahead (pos
, string
,
1035 CHARPOS (*newpos
) - CHARPOS (pos
));
1037 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1042 /***********************************************************************
1043 Lisp form evaluation
1044 ***********************************************************************/
1046 /* Error handler for eval_form. */
1056 /* Evaluate SEXPR and return the result, or nil if something went
1063 int count
= specpdl_ptr
- specpdl
;
1065 specbind (Qinhibit_redisplay
, Qt
);
1066 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, eval_handler
);
1067 return unbind_to (count
, val
);
1072 /***********************************************************************
1074 ***********************************************************************/
1078 /* Define CHECK_IT to perform sanity checks on iterators.
1079 This is for debugging. It is too slow to do unconditionally. */
1085 if (it
->method
== next_element_from_string
)
1087 xassert (STRINGP (it
->string
));
1088 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1090 else if (it
->method
== next_element_from_buffer
)
1092 /* Check that character and byte positions agree. */
1093 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1097 xassert (it
->current
.dpvec_index
>= 0);
1099 xassert (it
->current
.dpvec_index
< 0);
1102 #define CHECK_IT(IT) check_it ((IT))
1106 #define CHECK_IT(IT) (void) 0
1113 /* Check that the window end of window W is what we expect it
1114 to be---the last row in the current matrix displaying text. */
1117 check_window_end (w
)
1120 if (!MINI_WINDOW_P (w
)
1121 && !NILP (w
->window_end_valid
))
1123 struct glyph_row
*row
;
1124 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1125 XFASTINT (w
->window_end_vpos
)),
1127 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1128 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1132 #define CHECK_WINDOW_END(W) check_window_end ((W))
1134 #else /* not GLYPH_DEBUG */
1136 #define CHECK_WINDOW_END(W) (void) 0
1138 #endif /* not GLYPH_DEBUG */
1142 /***********************************************************************
1143 Iterator initialization
1144 ***********************************************************************/
1146 /* Initialize IT for displaying current_buffer in window W, starting
1147 at character position CHARPOS. CHARPOS < 0 means that no buffer
1148 position is specified which is useful when the iterator is assigned
1149 a position later. BYTEPOS is the byte position corresponding to
1150 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1152 If ROW is not null, calls to produce_glyphs with IT as parameter
1153 will produce glyphs in that row.
1155 BASE_FACE_ID is the id of a base face to use. It must be one of
1156 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1157 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1158 displaying the tool-bar.
1160 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1161 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1162 corresponding mode line glyph row of the desired matrix of W. */
1165 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1168 int charpos
, bytepos
;
1169 struct glyph_row
*row
;
1170 enum face_id base_face_id
;
1172 int highlight_region_p
;
1174 /* Some precondition checks. */
1175 xassert (w
!= NULL
&& it
!= NULL
);
1176 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1178 /* If face attributes have been changed since the last redisplay,
1179 free realized faces now because they depend on face definitions
1180 that might have changed. */
1181 if (face_change_count
)
1183 face_change_count
= 0;
1184 free_all_realized_faces (Qnil
);
1187 /* Use one of the mode line rows of W's desired matrix if
1191 if (base_face_id
== MODE_LINE_FACE_ID
)
1192 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1193 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1194 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1198 bzero (it
, sizeof *it
);
1199 it
->current
.overlay_string_index
= -1;
1200 it
->current
.dpvec_index
= -1;
1201 it
->base_face_id
= base_face_id
;
1203 /* The window in which we iterate over current_buffer: */
1204 XSETWINDOW (it
->window
, w
);
1206 it
->f
= XFRAME (w
->frame
);
1208 /* Extra space between lines (on window systems only). */
1209 if (base_face_id
== DEFAULT_FACE_ID
1210 && FRAME_WINDOW_P (it
->f
))
1212 if (NATNUMP (current_buffer
->extra_line_spacing
))
1213 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1214 else if (it
->f
->extra_line_spacing
> 0)
1215 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1218 /* If realized faces have been removed, e.g. because of face
1219 attribute changes of named faces, recompute them. */
1220 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1221 recompute_basic_faces (it
->f
);
1223 /* Current value of the `space-width', and 'height' properties. */
1224 it
->space_width
= Qnil
;
1225 it
->font_height
= Qnil
;
1227 /* Are control characters displayed as `^C'? */
1228 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1230 /* -1 means everything between a CR and the following line end
1231 is invisible. >0 means lines indented more than this value are
1233 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1234 ? XFASTINT (current_buffer
->selective_display
)
1235 : (!NILP (current_buffer
->selective_display
)
1237 it
->selective_display_ellipsis_p
1238 = !NILP (current_buffer
->selective_display_ellipses
);
1240 /* Display table to use. */
1241 it
->dp
= window_display_table (w
);
1243 /* Are multibyte characters enabled in current_buffer? */
1244 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1246 /* Non-zero if we should highlight the region. */
1248 = (!NILP (Vtransient_mark_mode
)
1249 && !NILP (current_buffer
->mark_active
)
1250 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1252 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1253 start and end of a visible region in window IT->w. Set both to
1254 -1 to indicate no region. */
1255 if (highlight_region_p
1256 /* Maybe highlight only in selected window. */
1257 && (/* Either show region everywhere. */
1258 highlight_nonselected_windows
1259 /* Or show region in the selected window. */
1260 || w
== XWINDOW (selected_window
)
1261 /* Or show the region if we are in the mini-buffer and W is
1262 the window the mini-buffer refers to. */
1263 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1264 && w
== XWINDOW (Vminibuf_scroll_window
))))
1266 int charpos
= marker_position (current_buffer
->mark
);
1267 it
->region_beg_charpos
= min (PT
, charpos
);
1268 it
->region_end_charpos
= max (PT
, charpos
);
1271 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1273 /* Get the position at which the redisplay_end_trigger hook should
1274 be run, if it is to be run at all. */
1275 if (MARKERP (w
->redisplay_end_trigger
)
1276 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1277 it
->redisplay_end_trigger_charpos
1278 = marker_position (w
->redisplay_end_trigger
);
1279 else if (INTEGERP (w
->redisplay_end_trigger
))
1280 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1282 /* Correct bogus values of tab_width. */
1283 it
->tab_width
= XINT (current_buffer
->tab_width
);
1284 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1287 /* Are lines in the display truncated? */
1288 it
->truncate_lines_p
1289 = (base_face_id
!= DEFAULT_FACE_ID
1290 || XINT (it
->w
->hscroll
)
1291 || (truncate_partial_width_windows
1292 && !WINDOW_FULL_WIDTH_P (it
->w
))
1293 || !NILP (current_buffer
->truncate_lines
));
1295 /* Get dimensions of truncation and continuation glyphs. These are
1296 displayed as bitmaps under X, so we don't need them for such
1298 if (!FRAME_WINDOW_P (it
->f
))
1300 if (it
->truncate_lines_p
)
1302 /* We will need the truncation glyph. */
1303 xassert (it
->glyph_row
== NULL
);
1304 produce_special_glyphs (it
, IT_TRUNCATION
);
1305 it
->truncation_pixel_width
= it
->pixel_width
;
1309 /* We will need the continuation glyph. */
1310 xassert (it
->glyph_row
== NULL
);
1311 produce_special_glyphs (it
, IT_CONTINUATION
);
1312 it
->continuation_pixel_width
= it
->pixel_width
;
1315 /* Reset these values to zero becaue the produce_special_glyphs
1316 above has changed them. */
1317 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1318 it
->phys_ascent
= it
->phys_descent
= 0;
1321 /* Set this after getting the dimensions of truncation and
1322 continuation glyphs, so that we don't produce glyphs when calling
1323 produce_special_glyphs, above. */
1324 it
->glyph_row
= row
;
1325 it
->area
= TEXT_AREA
;
1327 /* Get the dimensions of the display area. The display area
1328 consists of the visible window area plus a horizontally scrolled
1329 part to the left of the window. All x-values are relative to the
1330 start of this total display area. */
1331 if (base_face_id
!= DEFAULT_FACE_ID
)
1333 /* Mode lines, menu bar in terminal frames. */
1334 it
->first_visible_x
= 0;
1335 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1340 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1341 it
->last_visible_x
= (it
->first_visible_x
1342 + window_box_width (w
, TEXT_AREA
));
1344 /* If we truncate lines, leave room for the truncator glyph(s) at
1345 the right margin. Otherwise, leave room for the continuation
1346 glyph(s). Truncation and continuation glyphs are not inserted
1347 for window-based redisplay. */
1348 if (!FRAME_WINDOW_P (it
->f
))
1350 if (it
->truncate_lines_p
)
1351 it
->last_visible_x
-= it
->truncation_pixel_width
;
1353 it
->last_visible_x
-= it
->continuation_pixel_width
;
1356 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1357 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1360 /* Leave room for a border glyph. */
1361 if (!FRAME_WINDOW_P (it
->f
)
1362 && !WINDOW_RIGHTMOST_P (it
->w
))
1363 it
->last_visible_x
-= 1;
1365 it
->last_visible_y
= window_text_bottom_y (w
);
1367 /* For mode lines and alike, arrange for the first glyph having a
1368 left box line if the face specifies a box. */
1369 if (base_face_id
!= DEFAULT_FACE_ID
)
1373 it
->face_id
= base_face_id
;
1375 /* If we have a boxed mode line, make the first character appear
1376 with a left box line. */
1377 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1378 if (face
->box
!= FACE_NO_BOX
)
1379 it
->start_of_box_run_p
= 1;
1382 /* If a buffer position was specified, set the iterator there,
1383 getting overlays and face properties from that position. */
1386 it
->end_charpos
= ZV
;
1388 IT_CHARPOS (*it
) = charpos
;
1390 /* Compute byte position if not specified. */
1392 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1394 IT_BYTEPOS (*it
) = bytepos
;
1396 /* Compute faces etc. */
1397 reseat (it
, it
->current
.pos
, 1);
1404 /* Initialize IT for the display of window W with window start POS. */
1407 start_display (it
, w
, pos
)
1410 struct text_pos pos
;
1412 int start_at_line_beg_p
;
1413 struct glyph_row
*row
;
1414 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1417 row
= w
->desired_matrix
->rows
+ first_vpos
;
1418 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1419 first_y
= it
->current_y
;
1421 /* If window start is not at a line start, move back to the line
1422 start. This makes sure that we take continuation lines into
1424 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1425 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1426 if (!start_at_line_beg_p
)
1427 reseat_at_previous_visible_line_start (it
);
1429 /* If window start is not at a line start, skip forward to POS to
1430 get the correct continuation_lines_width and current_x. */
1431 if (!start_at_line_beg_p
)
1433 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1435 /* If lines are continued, this line may end in the middle of a
1436 multi-glyph character (e.g. a control character displayed as
1437 \003, or in the middle of an overlay string). In this case
1438 move_it_to above will not have taken us to the start of
1439 the continuation line but to the end of the continued line. */
1440 if (!it
->truncate_lines_p
&& it
->current_x
> 0)
1442 if (it
->current
.dpvec_index
>= 0
1443 || it
->current
.overlay_string_index
>= 0)
1445 set_iterator_to_next (it
);
1446 move_it_in_display_line_to (it
, -1, -1, 0);
1448 it
->continuation_lines_width
+= it
->current_x
;
1451 it
->current_y
= first_y
;
1453 it
->current_x
= it
->hpos
= 0;
1456 #if 0 /* Don't assert the following because start_display is sometimes
1457 called intentionally with a window start that is not at a
1458 line start. Please leave this code in as a comment. */
1460 /* Window start should be on a line start, now. */
1461 xassert (it
->continuation_lines_width
1462 || IT_CHARPOS (it
) == BEGV
1463 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1468 /* Initialize IT for stepping through current_buffer in window W,
1469 starting at position POS that includes overlay string and display
1470 vector/ control character translation position information. */
1473 init_from_display_pos (it
, w
, pos
)
1476 struct display_pos
*pos
;
1478 /* Keep in mind: the call to reseat in init_iterator skips invisible
1479 text, so we might end up at a position different from POS. This
1480 is only a problem when POS is a row start after a newline and an
1481 overlay starts there with an after-string, and the overlay has an
1482 invisible property. Since we don't skip invisible text in
1483 display_line and elsewhere immediately after consuming the
1484 newline before the row start, such a POS will not be in a string,
1485 but the call to init_iterator below will move us to the
1487 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1488 NULL
, DEFAULT_FACE_ID
);
1490 /* If position is within an overlay string, set up IT to
1491 the right overlay string. */
1492 if (pos
->overlay_string_index
>= 0)
1496 /* We already have the first chunk of overlay strings in
1497 IT->overlay_strings. Load more until the one for
1498 pos->overlay_string_index is in IT->overlay_strings. */
1499 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1501 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1502 it
->current
.overlay_string_index
= 0;
1505 load_overlay_strings (it
);
1506 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1510 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1511 relative_index
= (it
->current
.overlay_string_index
1512 % OVERLAY_STRING_CHUNK_SIZE
);
1513 it
->string
= it
->overlay_strings
[relative_index
];
1514 it
->current
.string_pos
= pos
->string_pos
;
1515 it
->method
= next_element_from_string
;
1517 else if (CHARPOS (pos
->string_pos
) >= 0)
1519 /* Recorded position is not in an overlay string, but in another
1520 string. This can only be a string from a `display' property.
1521 IT should already be filled with that string. */
1522 it
->current
.string_pos
= pos
->string_pos
;
1523 xassert (STRINGP (it
->string
));
1526 /* Restore position in display vector translations or control
1527 character translations. */
1528 if (pos
->dpvec_index
>= 0)
1530 /* This fills IT->dpvec. */
1531 get_next_display_element (it
);
1532 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1533 it
->current
.dpvec_index
= pos
->dpvec_index
;
1540 /* Initialize IT for stepping through current_buffer in window W
1541 starting at ROW->start. */
1544 init_to_row_start (it
, w
, row
)
1547 struct glyph_row
*row
;
1549 init_from_display_pos (it
, w
, &row
->start
);
1550 it
->continuation_lines_width
= row
->continuation_lines_width
;
1555 /* Initialize IT for stepping through current_buffer in window W
1556 starting in the line following ROW, i.e. starting at ROW->end. */
1559 init_to_row_end (it
, w
, row
)
1562 struct glyph_row
*row
;
1564 init_from_display_pos (it
, w
, &row
->end
);
1566 if (row
->continued_p
)
1567 it
->continuation_lines_width
= (row
->continuation_lines_width
1568 + row
->pixel_width
);
1575 /***********************************************************************
1577 ***********************************************************************/
1579 /* Called when IT reaches IT->stop_charpos. Handle text property and
1580 overlay changes. Set IT->stop_charpos to the next position where
1587 enum prop_handled handled
;
1588 int handle_overlay_change_p
= 1;
1592 it
->current
.dpvec_index
= -1;
1596 handled
= HANDLED_NORMALLY
;
1598 /* Call text property handlers. */
1599 for (p
= it_props
; p
->handler
; ++p
)
1601 handled
= p
->handler (it
);
1603 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1605 else if (handled
== HANDLED_RETURN
)
1607 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1608 handle_overlay_change_p
= 0;
1611 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1613 /* Don't check for overlay strings below when set to deliver
1614 characters from a display vector. */
1615 if (it
->method
== next_element_from_display_vector
)
1616 handle_overlay_change_p
= 0;
1618 /* Handle overlay changes. */
1619 if (handle_overlay_change_p
)
1620 handled
= handle_overlay_change (it
);
1622 /* Determine where to stop next. */
1623 if (handled
== HANDLED_NORMALLY
)
1624 compute_stop_pos (it
);
1627 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1631 /* Compute IT->stop_charpos from text property and overlay change
1632 information for IT's current position. */
1635 compute_stop_pos (it
)
1638 register INTERVAL iv
, next_iv
;
1639 Lisp_Object object
, limit
, position
;
1641 /* If nowhere else, stop at the end. */
1642 it
->stop_charpos
= it
->end_charpos
;
1644 if (STRINGP (it
->string
))
1646 /* Strings are usually short, so don't limit the search for
1648 object
= it
->string
;
1650 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1656 /* If next overlay change is in front of the current stop pos
1657 (which is IT->end_charpos), stop there. Note: value of
1658 next_overlay_change is point-max if no overlay change
1660 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1661 if (charpos
< it
->stop_charpos
)
1662 it
->stop_charpos
= charpos
;
1664 /* If showing the region, we have to stop at the region
1665 start or end because the face might change there. */
1666 if (it
->region_beg_charpos
> 0)
1668 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1669 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1670 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1671 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1674 /* Set up variables for computing the stop position from text
1675 property changes. */
1676 XSETBUFFER (object
, current_buffer
);
1677 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1678 XSETFASTINT (position
, IT_CHARPOS (*it
));
1682 /* Get the interval containing IT's position. Value is a null
1683 interval if there isn't such an interval. */
1684 iv
= validate_interval_range (object
, &position
, &position
, 0);
1685 if (!NULL_INTERVAL_P (iv
))
1687 Lisp_Object values_here
[LAST_PROP_IDX
];
1690 /* Get properties here. */
1691 for (p
= it_props
; p
->handler
; ++p
)
1692 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1694 /* Look for an interval following iv that has different
1696 for (next_iv
= next_interval (iv
);
1697 (!NULL_INTERVAL_P (next_iv
)
1699 || XFASTINT (limit
) > next_iv
->position
));
1700 next_iv
= next_interval (next_iv
))
1702 for (p
= it_props
; p
->handler
; ++p
)
1704 Lisp_Object new_value
;
1706 new_value
= textget (next_iv
->plist
, *p
->name
);
1707 if (!EQ (values_here
[p
->idx
], new_value
))
1715 if (!NULL_INTERVAL_P (next_iv
))
1717 if (INTEGERP (limit
)
1718 && next_iv
->position
>= XFASTINT (limit
))
1719 /* No text property change up to limit. */
1720 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1722 /* Text properties change in next_iv. */
1723 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1727 xassert (STRINGP (it
->string
)
1728 || (it
->stop_charpos
>= BEGV
1729 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1733 /* Return the position of the next overlay change after POS in
1734 current_buffer. Value is point-max if no overlay change
1735 follows. This is like `next-overlay-change' but doesn't use
1739 next_overlay_change (pos
)
1744 Lisp_Object
*overlays
;
1748 /* Get all overlays at the given position. */
1750 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1751 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1752 if (noverlays
> len
)
1755 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1756 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1759 /* If any of these overlays ends before endpos,
1760 use its ending point instead. */
1761 for (i
= 0; i
< noverlays
; ++i
)
1766 oend
= OVERLAY_END (overlays
[i
]);
1767 oendpos
= OVERLAY_POSITION (oend
);
1768 endpos
= min (endpos
, oendpos
);
1776 /***********************************************************************
1778 ***********************************************************************/
1780 /* Handle changes in the `fontified' property of the current buffer by
1781 calling hook functions from Qfontification_functions to fontify
1784 static enum prop_handled
1785 handle_fontified_prop (it
)
1788 Lisp_Object prop
, pos
;
1789 enum prop_handled handled
= HANDLED_NORMALLY
;
1790 struct gcpro gcpro1
;
1792 /* Get the value of the `fontified' property at IT's current buffer
1793 position. (The `fontified' property doesn't have a special
1794 meaning in strings.) If the value is nil, call functions from
1795 Qfontification_functions. */
1796 if (!STRINGP (it
->string
)
1798 && !NILP (Vfontification_functions
)
1799 && (pos
= make_number (IT_CHARPOS (*it
)),
1800 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1803 Lisp_Object args
[2];
1806 /* Run the hook functions. */
1807 args
[0] = Qfontification_functions
;
1809 Frun_hook_with_args (2, args
);
1811 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
1812 something. This avoids an endless loop if they failed to
1813 fontify the text for which reason ever. */
1814 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
1815 handled
= HANDLED_RECOMPUTE_PROPS
;
1824 /***********************************************************************
1826 ***********************************************************************/
1828 /* Set up iterator IT from face properties at its current position.
1829 Called from handle_stop. */
1831 static enum prop_handled
1832 handle_face_prop (it
)
1835 int new_face_id
, next_stop
;
1837 if (!STRINGP (it
->string
))
1840 = face_at_buffer_position (it
->w
,
1842 it
->region_beg_charpos
,
1843 it
->region_end_charpos
,
1846 + TEXT_PROP_DISTANCE_LIMIT
),
1849 /* Is this a start of a run of characters with box face?
1850 Caveat: this can be called for a freshly initialized
1851 iterator; face_id is -1 is this case. We know that the new
1852 face will not change until limit, i.e. if the new face has a
1853 box, all characters up to limit will have one. But, as
1854 usual, we don't know whether limit is really the end. */
1855 if (new_face_id
!= it
->face_id
)
1857 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1859 /* If new face has a box but old face has not, this is
1860 the start of a run of characters with box, i.e. it has
1861 a shadow on the left side. The value of face_id of the
1862 iterator will be -1 if this is the initial call that gets
1863 the face. In this case, we have to look in front of IT's
1864 position and see whether there is a face != new_face_id. */
1865 it
->start_of_box_run_p
1866 = (new_face
->box
!= FACE_NO_BOX
1867 && (it
->face_id
>= 0
1868 || IT_CHARPOS (*it
) == BEG
1869 || new_face_id
!= face_before_it_pos (it
)));
1870 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1876 = face_at_string_position (it
->w
,
1878 IT_STRING_CHARPOS (*it
),
1879 (it
->current
.overlay_string_index
>= 0
1882 it
->region_beg_charpos
,
1883 it
->region_end_charpos
,
1887 #if 0 /* This shouldn't be neccessary. Let's check it. */
1888 /* If IT is used to display a mode line we would really like to
1889 use the mode line face instead of the frame's default face. */
1890 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
1891 && new_face_id
== DEFAULT_FACE_ID
)
1892 new_face_id
= MODE_LINE_FACE_ID
;
1895 /* Is this a start of a run of characters with box? Caveat:
1896 this can be called for a freshly allocated iterator; face_id
1897 is -1 is this case. We know that the new face will not
1898 change until the next check pos, i.e. if the new face has a
1899 box, all characters up to that position will have a
1900 box. But, as usual, we don't know whether that position
1901 is really the end. */
1902 if (new_face_id
!= it
->face_id
)
1904 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1905 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1907 /* If new face has a box but old face hasn't, this is the
1908 start of a run of characters with box, i.e. it has a
1909 shadow on the left side. */
1910 it
->start_of_box_run_p
1911 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
1912 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1916 it
->face_id
= new_face_id
;
1917 return HANDLED_NORMALLY
;
1921 /* Compute the face one character before or after the current position
1922 of IT. BEFORE_P non-zero means get the face in front of IT's
1923 position. Value is the id of the face. */
1926 face_before_or_after_it_pos (it
, before_p
)
1931 int next_check_charpos
;
1932 struct text_pos pos
;
1934 xassert (it
->s
== NULL
);
1936 if (STRINGP (it
->string
))
1938 /* No face change past the end of the string (for the case
1939 we are padding with spaces). No face change before the
1941 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
1942 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
1945 /* Set pos to the position before or after IT's current position. */
1947 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
1949 /* For composition, we must check the character after the
1951 pos
= (it
->what
== IT_COMPOSITION
1952 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
1953 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
1955 /* Get the face for ASCII, or unibyte. */
1957 = face_at_string_position (it
->w
,
1960 (it
->current
.overlay_string_index
>= 0
1963 it
->region_beg_charpos
,
1964 it
->region_end_charpos
,
1965 &next_check_charpos
,
1968 /* Correct the face for charsets different from ASCII. Do it
1969 for the multibyte case only. The face returned above is
1970 suitable for unibyte text if IT->string is unibyte. */
1971 if (STRING_MULTIBYTE (it
->string
))
1973 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
1974 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
1976 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
1978 c
= string_char_and_length (p
, rest
, &len
);
1979 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
1984 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
1985 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
1988 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
1989 pos
= it
->current
.pos
;
1992 DEC_TEXT_POS (pos
, it
->multibyte_p
);
1995 if (it
->what
== IT_COMPOSITION
)
1996 /* For composition, we must check the position after the
1998 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2000 INC_TEXT_POS (pos
, it
->multibyte_p
);
2002 /* Determine face for CHARSET_ASCII, or unibyte. */
2003 face_id
= face_at_buffer_position (it
->w
,
2005 it
->region_beg_charpos
,
2006 it
->region_end_charpos
,
2007 &next_check_charpos
,
2010 /* Correct the face for charsets different from ASCII. Do it
2011 for the multibyte case only. The face returned above is
2012 suitable for unibyte text if current_buffer is unibyte. */
2013 if (it
->multibyte_p
)
2015 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2016 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2017 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2026 /***********************************************************************
2028 ***********************************************************************/
2030 /* Set up iterator IT from invisible properties at its current
2031 position. Called from handle_stop. */
2033 static enum prop_handled
2034 handle_invisible_prop (it
)
2037 enum prop_handled handled
= HANDLED_NORMALLY
;
2039 if (STRINGP (it
->string
))
2041 extern Lisp_Object Qinvisible
;
2042 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2044 /* Get the value of the invisible text property at the
2045 current position. Value will be nil if there is no such
2047 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2048 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2051 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2053 handled
= HANDLED_RECOMPUTE_PROPS
;
2055 /* Get the position at which the next change of the
2056 invisible text property can be found in IT->string.
2057 Value will be nil if the property value is the same for
2058 all the rest of IT->string. */
2059 XSETINT (limit
, XSTRING (it
->string
)->size
);
2060 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2063 /* Text at current position is invisible. The next
2064 change in the property is at position end_charpos.
2065 Move IT's current position to that position. */
2066 if (INTEGERP (end_charpos
)
2067 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2069 struct text_pos old
;
2070 old
= it
->current
.string_pos
;
2071 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2072 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2076 /* The rest of the string is invisible. If this is an
2077 overlay string, proceed with the next overlay string
2078 or whatever comes and return a character from there. */
2079 if (it
->current
.overlay_string_index
>= 0)
2081 next_overlay_string (it
);
2082 /* Don't check for overlay strings when we just
2083 finished processing them. */
2084 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2088 struct Lisp_String
*s
= XSTRING (it
->string
);
2089 IT_STRING_CHARPOS (*it
) = s
->size
;
2090 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2097 int visible_p
, newpos
, next_stop
;
2098 Lisp_Object pos
, prop
;
2100 /* First of all, is there invisible text at this position? */
2101 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2102 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2104 /* If we are on invisible text, skip over it. */
2105 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2106 && IT_CHARPOS (*it
) < it
->end_charpos
)
2108 /* Record whether we have to display an ellipsis for the
2110 int display_ellipsis_p
2111 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2113 handled
= HANDLED_RECOMPUTE_PROPS
;
2115 /* Loop skipping over invisible text. The loop is left at
2116 ZV or with IT on the first char being visible again. */
2119 /* Try to skip some invisible text. Return value is the
2120 position reached which can be equal to IT's position
2121 if there is nothing invisible here. This skips both
2122 over invisible text properties and overlays with
2123 invisible property. */
2124 newpos
= skip_invisible (IT_CHARPOS (*it
),
2125 &next_stop
, ZV
, it
->window
);
2127 /* If we skipped nothing at all we weren't at invisible
2128 text in the first place. If everything to the end of
2129 the buffer was skipped, end the loop. */
2130 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2134 /* We skipped some characters but not necessarily
2135 all there are. Check if we ended up on visible
2136 text. Fget_char_property returns the property of
2137 the char before the given position, i.e. if we
2138 get visible_p = 1, this means that the char at
2139 newpos is visible. */
2140 XSETFASTINT (pos
, newpos
);
2141 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2142 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2145 /* If we ended up on invisible text, proceed to
2146 skip starting with next_stop. */
2148 IT_CHARPOS (*it
) = next_stop
;
2152 /* The position newpos is now either ZV or on visible text. */
2153 IT_CHARPOS (*it
) = newpos
;
2154 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2156 /* Maybe return `...' next for the end of the invisible text. */
2157 if (display_ellipsis_p
)
2160 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2162 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2163 it
->dpvec
= v
->contents
;
2164 it
->dpend
= v
->contents
+ v
->size
;
2168 /* Default `...'. */
2169 it
->dpvec
= default_invis_vector
;
2170 it
->dpend
= default_invis_vector
+ 3;
2173 /* The ellipsis display does not replace the display of
2174 the character at the new position. Indicate this by
2175 setting IT->dpvec_char_len to zero. */
2176 it
->dpvec_char_len
= 0;
2178 it
->current
.dpvec_index
= 0;
2179 it
->method
= next_element_from_display_vector
;
2189 /***********************************************************************
2191 ***********************************************************************/
2193 /* Set up iterator IT from `display' property at its current position.
2194 Called from handle_stop. */
2196 static enum prop_handled
2197 handle_display_prop (it
)
2200 Lisp_Object prop
, object
;
2201 struct text_pos
*position
;
2202 int space_or_image_found_p
;
2204 if (STRINGP (it
->string
))
2206 object
= it
->string
;
2207 position
= &it
->current
.string_pos
;
2212 position
= &it
->current
.pos
;
2215 /* Reset those iterator values set from display property values. */
2216 it
->font_height
= Qnil
;
2217 it
->space_width
= Qnil
;
2220 /* We don't support recursive `display' properties, i.e. string
2221 values that have a string `display' property, that have a string
2222 `display' property etc. */
2223 if (!it
->string_from_display_prop_p
)
2224 it
->area
= TEXT_AREA
;
2226 prop
= Fget_char_property (make_number (position
->charpos
),
2229 return HANDLED_NORMALLY
;
2231 space_or_image_found_p
= 0;
2233 && CONSP (XCAR (prop
))
2234 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2236 /* A list of sub-properties. */
2237 while (CONSP (prop
))
2239 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2240 space_or_image_found_p
= 1;
2244 else if (VECTORP (prop
))
2247 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2248 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2250 space_or_image_found_p
= 1;
2254 if (handle_single_display_prop (it
, prop
, object
, position
))
2255 space_or_image_found_p
= 1;
2258 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2262 /* Value is the position of the end of the `display' property starting
2263 at START_POS in OBJECT. */
2265 static struct text_pos
2266 display_prop_end (it
, object
, start_pos
)
2269 struct text_pos start_pos
;
2272 struct text_pos end_pos
;
2274 end
= next_single_char_property_change (make_number (CHARPOS (start_pos
)),
2275 Qdisplay
, object
, Qnil
);
2276 CHARPOS (end_pos
) = XFASTINT (end
);
2277 if (STRINGP (object
))
2278 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2280 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2286 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2287 is the object in which the `display' property was found. *POSITION
2288 is the position at which it was found.
2290 If PROP is a `space' or `image' sub-property, set *POSITION to the
2291 end position of the `display' property.
2293 Value is non-zero if a `space' or `image' property value was found. */
2296 handle_single_display_prop (it
, prop
, object
, position
)
2300 struct text_pos
*position
;
2303 int space_or_image_found_p
= 0;
2307 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2308 evaluated. If the result is nil, VALUE is ignored. */
2310 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2319 if (!NILP (form
) && !EQ (form
, Qt
))
2321 struct gcpro gcpro1
;
2322 struct text_pos end_pos
, pt
;
2325 end_pos
= display_prop_end (it
, object
, *position
);
2327 /* Temporarily set point to the end position, and then evaluate
2328 the form. This makes `(eolp)' work as FORM. */
2329 if (BUFFERP (object
))
2332 BYTEPOS (pt
) = PT_BYTE
;
2333 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2336 form
= eval_form (form
);
2338 if (BUFFERP (object
))
2339 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2347 && EQ (XCAR (prop
), Qheight
)
2348 && CONSP (XCDR (prop
)))
2350 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2353 /* `(height HEIGHT)'. */
2354 it
->font_height
= XCAR (XCDR (prop
));
2355 if (!NILP (it
->font_height
))
2357 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2358 int new_height
= -1;
2360 if (CONSP (it
->font_height
)
2361 && (EQ (XCAR (it
->font_height
), Qplus
)
2362 || EQ (XCAR (it
->font_height
), Qminus
))
2363 && CONSP (XCDR (it
->font_height
))
2364 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2366 /* `(+ N)' or `(- N)' where N is an integer. */
2367 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2368 if (EQ (XCAR (it
->font_height
), Qplus
))
2370 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2372 else if (SYMBOLP (it
->font_height
))
2374 /* Call function with current height as argument.
2375 Value is the new height. */
2376 Lisp_Object form
, height
;
2377 struct gcpro gcpro1
;
2379 height
= face
->lface
[LFACE_HEIGHT_INDEX
];
2380 form
= Fcons (it
->font_height
, Fcons (height
, Qnil
));
2382 height
= eval_form (form
);
2383 if (NUMBERP (height
))
2384 new_height
= XFLOATINT (height
);
2387 else if (NUMBERP (it
->font_height
))
2389 /* Value is a multiple of the canonical char height. */
2392 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2393 new_height
= (XFLOATINT (it
->font_height
)
2394 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2398 /* Evaluate IT->font_height with `height' bound to the
2399 current specified height to get the new height. */
2401 int count
= specpdl_ptr
- specpdl
;
2403 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2404 value
= eval_form (it
->font_height
);
2405 unbind_to (count
, Qnil
);
2407 if (NUMBERP (value
))
2408 new_height
= XFLOATINT (value
);
2412 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2415 else if (CONSP (prop
)
2416 && EQ (XCAR (prop
), Qspace_width
)
2417 && CONSP (XCDR (prop
)))
2419 /* `(space_width WIDTH)'. */
2420 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2423 value
= XCAR (XCDR (prop
));
2424 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2425 it
->space_width
= value
;
2427 else if (CONSP (prop
)
2428 && EQ (XCAR (prop
), Qraise
)
2429 && CONSP (XCDR (prop
)))
2431 /* `(raise FACTOR)'. */
2432 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2435 #ifdef HAVE_WINDOW_SYSTEM
2436 value
= XCAR (XCDR (prop
));
2437 if (NUMBERP (value
))
2439 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2440 it
->voffset
= - (XFLOATINT (value
)
2441 * (FONT_HEIGHT (face
->font
)));
2443 #endif /* HAVE_WINDOW_SYSTEM */
2445 else if (!it
->string_from_display_prop_p
)
2447 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2448 VALUE) or `((margin nil) VALUE)' or VALUE. */
2449 Lisp_Object location
, value
;
2450 struct text_pos start_pos
;
2453 /* Characters having this form of property are not displayed, so
2454 we have to find the end of the property. */
2455 start_pos
= *position
;
2456 *position
= display_prop_end (it
, object
, start_pos
);
2459 /* Let's stop at the new position and assume that all
2460 text properties change there. */
2461 it
->stop_charpos
= position
->charpos
;
2463 location
= Qunbound
;
2464 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2468 value
= XCDR (prop
);
2470 value
= XCAR (value
);
2473 if (EQ (XCAR (tem
), Qmargin
)
2474 && (tem
= XCDR (tem
),
2475 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2477 || EQ (tem
, Qleft_margin
)
2478 || EQ (tem
, Qright_margin
))))
2482 if (EQ (location
, Qunbound
))
2488 #ifdef HAVE_WINDOW_SYSTEM
2489 if (FRAME_TERMCAP_P (it
->f
))
2490 valid_p
= STRINGP (value
);
2492 valid_p
= (STRINGP (value
)
2493 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2494 || valid_image_p (value
));
2495 #else /* not HAVE_WINDOW_SYSTEM */
2496 valid_p
= STRINGP (value
);
2497 #endif /* not HAVE_WINDOW_SYSTEM */
2499 if ((EQ (location
, Qleft_margin
)
2500 || EQ (location
, Qright_margin
)
2504 space_or_image_found_p
= 1;
2506 /* Save current settings of IT so that we can restore them
2507 when we are finished with the glyph property value. */
2510 if (NILP (location
))
2511 it
->area
= TEXT_AREA
;
2512 else if (EQ (location
, Qleft_margin
))
2513 it
->area
= LEFT_MARGIN_AREA
;
2515 it
->area
= RIGHT_MARGIN_AREA
;
2517 if (STRINGP (value
))
2520 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2521 it
->current
.overlay_string_index
= -1;
2522 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2523 it
->end_charpos
= it
->string_nchars
2524 = XSTRING (it
->string
)->size
;
2525 it
->method
= next_element_from_string
;
2526 it
->stop_charpos
= 0;
2527 it
->string_from_display_prop_p
= 1;
2529 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2531 it
->method
= next_element_from_stretch
;
2533 it
->current
.pos
= it
->position
= start_pos
;
2535 #ifdef HAVE_WINDOW_SYSTEM
2538 it
->what
= IT_IMAGE
;
2539 it
->image_id
= lookup_image (it
->f
, value
);
2540 it
->position
= start_pos
;
2541 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2542 it
->method
= next_element_from_image
;
2544 /* Say that we haven't consumed the characters with
2545 `display' property yet. The call to pop_it in
2546 set_iterator_to_next will clean this up. */
2547 *position
= start_pos
;
2549 #endif /* HAVE_WINDOW_SYSTEM */
2552 /* Invalid property or property not supported. Restore
2553 the position to what it was before. */
2554 *position
= start_pos
;
2557 return space_or_image_found_p
;
2562 /***********************************************************************
2563 `composition' property
2564 ***********************************************************************/
2566 /* Set up iterator IT from `composition' property at its current
2567 position. Called from handle_stop. */
2569 static enum prop_handled
2570 handle_composition_prop (it
)
2573 Lisp_Object prop
, string
;
2574 int pos
, pos_byte
, end
;
2575 enum prop_handled handled
= HANDLED_NORMALLY
;
2577 if (STRINGP (it
->string
))
2579 pos
= IT_STRING_CHARPOS (*it
);
2580 pos_byte
= IT_STRING_BYTEPOS (*it
);
2581 string
= it
->string
;
2585 pos
= IT_CHARPOS (*it
);
2586 pos_byte
= IT_BYTEPOS (*it
);
2590 /* If there's a valid composition and point is not inside of the
2591 composition (in the case that the composition is from the current
2592 buffer), draw a glyph composed from the composition components. */
2593 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
2594 && COMPOSITION_VALID_P (pos
, end
, prop
)
2595 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
2597 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
2601 it
->method
= next_element_from_composition
;
2603 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
2604 /* For a terminal, draw only the first character of the
2606 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
2607 it
->len
= (STRINGP (it
->string
)
2608 ? string_char_to_byte (it
->string
, end
)
2609 : CHAR_TO_BYTE (end
)) - pos_byte
;
2610 it
->stop_charpos
= end
;
2611 handled
= HANDLED_RETURN
;
2620 /***********************************************************************
2622 ***********************************************************************/
2624 /* The following structure is used to record overlay strings for
2625 later sorting in load_overlay_strings. */
2627 struct overlay_entry
2635 /* Set up iterator IT from overlay strings at its current position.
2636 Called from handle_stop. */
2638 static enum prop_handled
2639 handle_overlay_change (it
)
2642 /* Overlays are handled in current_buffer only. */
2643 if (STRINGP (it
->string
))
2644 return HANDLED_NORMALLY
;
2646 return (get_overlay_strings (it
)
2647 ? HANDLED_RECOMPUTE_PROPS
2648 : HANDLED_NORMALLY
);
2652 /* Set up the next overlay string for delivery by IT, if there is an
2653 overlay string to deliver. Called by set_iterator_to_next when the
2654 end of the current overlay string is reached. If there are more
2655 overlay strings to display, IT->string and
2656 IT->current.overlay_string_index are set appropriately here.
2657 Otherwise IT->string is set to nil. */
2660 next_overlay_string (it
)
2663 ++it
->current
.overlay_string_index
;
2664 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2666 /* No more overlay strings. Restore IT's settings to what
2667 they were before overlay strings were processed, and
2668 continue to deliver from current_buffer. */
2670 xassert (it
->stop_charpos
>= BEGV
2671 && it
->stop_charpos
<= it
->end_charpos
);
2673 it
->current
.overlay_string_index
= -1;
2674 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2675 it
->n_overlay_strings
= 0;
2676 it
->method
= next_element_from_buffer
;
2680 /* There are more overlay strings to process. If
2681 IT->current.overlay_string_index has advanced to a position
2682 where we must load IT->overlay_strings with more strings, do
2684 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2686 if (it
->current
.overlay_string_index
&& i
== 0)
2687 load_overlay_strings (it
);
2689 /* Initialize IT to deliver display elements from the overlay
2691 it
->string
= it
->overlay_strings
[i
];
2692 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2693 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2694 it
->method
= next_element_from_string
;
2695 it
->stop_charpos
= 0;
2702 /* Compare two overlay_entry structures E1 and E2. Used as a
2703 comparison function for qsort in load_overlay_strings. Overlay
2704 strings for the same position are sorted so that
2706 1. All after-strings come in front of before-strings.
2708 2. Within after-strings, strings are sorted so that overlay strings
2709 from overlays with higher priorities come first.
2711 2. Within before-strings, strings are sorted so that overlay
2712 strings from overlays with higher priorities come last.
2714 Value is analogous to strcmp. */
2718 compare_overlay_entries (e1
, e2
)
2721 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
2722 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
2725 if (entry1
->after_string_p
!= entry2
->after_string_p
)
2726 /* Let after-strings appear in front of before-strings. */
2727 result
= entry1
->after_string_p
? -1 : 1;
2728 else if (entry1
->after_string_p
)
2729 /* After-strings sorted in order of decreasing priority. */
2730 result
= entry2
->priority
- entry1
->priority
;
2732 /* Before-strings sorted in order of increasing priority. */
2733 result
= entry1
->priority
- entry2
->priority
;
2739 /* Load the vector IT->overlay_strings with overlay strings from IT's
2740 current buffer position. Set IT->n_overlays to the total number of
2741 overlay strings found.
2743 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
2744 a time. On entry into load_overlay_strings,
2745 IT->current.overlay_string_index gives the number of overlay
2746 strings that have already been loaded by previous calls to this
2749 Overlay strings are sorted so that after-string strings come in
2750 front of before-string strings. Within before and after-strings,
2751 strings are sorted by overlay priority. See also function
2752 compare_overlay_entries. */
2755 load_overlay_strings (it
)
2758 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
2759 Lisp_Object ov
, overlay
, window
, str
;
2763 struct overlay_entry
*entries
2764 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
2766 /* Append the overlay string STRING of overlay OVERLAY to vector
2767 `entries' which has size `size' and currently contains `n'
2768 elements. AFTER_P non-zero means STRING is an after-string of
2770 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
2773 Lisp_Object priority; \
2777 int new_size = 2 * size; \
2778 struct overlay_entry *old = entries; \
2780 (struct overlay_entry *) alloca (new_size \
2781 * sizeof *entries); \
2782 bcopy (old, entries, size * sizeof *entries); \
2786 entries[n].string = (STRING); \
2787 priority = Foverlay_get ((OVERLAY), Qpriority); \
2788 entries[n].priority \
2789 = INTEGERP (priority) ? XFASTINT (priority) : 0; \
2790 entries[n].after_string_p = (AFTER_P); \
2795 /* Process overlay before the overlay center. */
2796 for (ov
= current_buffer
->overlays_before
;
2800 overlay
= XCAR (ov
);
2801 xassert (OVERLAYP (overlay
));
2802 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2803 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2805 if (end
< IT_CHARPOS (*it
))
2808 /* Skip this overlay if it doesn't start or end at IT's current
2810 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2813 /* Skip this overlay if it doesn't apply to IT->w. */
2814 window
= Foverlay_get (overlay
, Qwindow
);
2815 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2818 /* If overlay has a non-empty before-string, record it. */
2819 if (start
== IT_CHARPOS (*it
)
2820 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2821 && XSTRING (str
)->size
)
2822 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2824 /* If overlay has a non-empty after-string, record it. */
2825 if (end
== IT_CHARPOS (*it
)
2826 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2827 && XSTRING (str
)->size
)
2828 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2831 /* Process overlays after the overlay center. */
2832 for (ov
= current_buffer
->overlays_after
;
2836 overlay
= XCAR (ov
);
2837 xassert (OVERLAYP (overlay
));
2838 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2839 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2841 if (start
> IT_CHARPOS (*it
))
2844 /* Skip this overlay if it doesn't start or end at IT's current
2846 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2849 /* Skip this overlay if it doesn't apply to IT->w. */
2850 window
= Foverlay_get (overlay
, Qwindow
);
2851 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2854 /* If overlay has a non-empty before-string, record it. */
2855 if (start
== IT_CHARPOS (*it
)
2856 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2857 && XSTRING (str
)->size
)
2858 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2860 /* If overlay has a non-empty after-string, record it. */
2861 if (end
== IT_CHARPOS (*it
)
2862 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2863 && XSTRING (str
)->size
)
2864 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2867 #undef RECORD_OVERLAY_STRING
2870 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
2872 /* Record the total number of strings to process. */
2873 it
->n_overlay_strings
= n
;
2875 /* IT->current.overlay_string_index is the number of overlay strings
2876 that have already been consumed by IT. Copy some of the
2877 remaining overlay strings to IT->overlay_strings. */
2879 j
= it
->current
.overlay_string_index
;
2880 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
2881 it
->overlay_strings
[i
++] = entries
[j
++].string
;
2887 /* Get the first chunk of overlay strings at IT's current buffer
2888 position. Value is non-zero if at least one overlay string was
2892 get_overlay_strings (it
)
2895 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
2896 process. This fills IT->overlay_strings with strings, and sets
2897 IT->n_overlay_strings to the total number of strings to process.
2898 IT->pos.overlay_string_index has to be set temporarily to zero
2899 because load_overlay_strings needs this; it must be set to -1
2900 when no overlay strings are found because a zero value would
2901 indicate a position in the first overlay string. */
2902 it
->current
.overlay_string_index
= 0;
2903 load_overlay_strings (it
);
2905 /* If we found overlay strings, set up IT to deliver display
2906 elements from the first one. Otherwise set up IT to deliver
2907 from current_buffer. */
2908 if (it
->n_overlay_strings
)
2910 /* Make sure we know settings in current_buffer, so that we can
2911 restore meaningful values when we're done with the overlay
2913 compute_stop_pos (it
);
2914 xassert (it
->face_id
>= 0);
2916 /* Save IT's settings. They are restored after all overlay
2917 strings have been processed. */
2918 xassert (it
->sp
== 0);
2921 /* Set up IT to deliver display elements from the first overlay
2923 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2924 it
->stop_charpos
= 0;
2925 it
->string
= it
->overlay_strings
[0];
2926 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2927 xassert (STRINGP (it
->string
));
2928 it
->method
= next_element_from_string
;
2933 it
->current
.overlay_string_index
= -1;
2934 it
->method
= next_element_from_buffer
;
2939 /* Value is non-zero if we found at least one overlay string. */
2940 return STRINGP (it
->string
);
2945 /***********************************************************************
2946 Saving and restoring state
2947 ***********************************************************************/
2949 /* Save current settings of IT on IT->stack. Called, for example,
2950 before setting up IT for an overlay string, to be able to restore
2951 IT's settings to what they were after the overlay string has been
2958 struct iterator_stack_entry
*p
;
2960 xassert (it
->sp
< 2);
2961 p
= it
->stack
+ it
->sp
;
2963 p
->stop_charpos
= it
->stop_charpos
;
2964 xassert (it
->face_id
>= 0);
2965 p
->face_id
= it
->face_id
;
2966 p
->string
= it
->string
;
2967 p
->pos
= it
->current
;
2968 p
->end_charpos
= it
->end_charpos
;
2969 p
->string_nchars
= it
->string_nchars
;
2971 p
->multibyte_p
= it
->multibyte_p
;
2972 p
->space_width
= it
->space_width
;
2973 p
->font_height
= it
->font_height
;
2974 p
->voffset
= it
->voffset
;
2975 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
2980 /* Restore IT's settings from IT->stack. Called, for example, when no
2981 more overlay strings must be processed, and we return to delivering
2982 display elements from a buffer, or when the end of a string from a
2983 `display' property is reached and we return to delivering display
2984 elements from an overlay string, or from a buffer. */
2990 struct iterator_stack_entry
*p
;
2992 xassert (it
->sp
> 0);
2994 p
= it
->stack
+ it
->sp
;
2995 it
->stop_charpos
= p
->stop_charpos
;
2996 it
->face_id
= p
->face_id
;
2997 it
->string
= p
->string
;
2998 it
->current
= p
->pos
;
2999 it
->end_charpos
= p
->end_charpos
;
3000 it
->string_nchars
= p
->string_nchars
;
3002 it
->multibyte_p
= p
->multibyte_p
;
3003 it
->space_width
= p
->space_width
;
3004 it
->font_height
= p
->font_height
;
3005 it
->voffset
= p
->voffset
;
3006 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3011 /***********************************************************************
3013 ***********************************************************************/
3015 /* Set IT's current position to the previous line start. */
3018 back_to_previous_line_start (it
)
3021 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3022 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3026 /* Set IT's current position to the next line start. */
3029 forward_to_next_line_start (it
)
3032 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), 1);
3033 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3037 /* Set IT's current position to the previous visible line start. Skip
3038 invisible text that is so either due to text properties or due to
3039 selective display. Caution: this does not change IT->current_x and
3043 back_to_previous_visible_line_start (it
)
3048 /* Go back one newline if not on BEGV already. */
3049 if (IT_CHARPOS (*it
) > BEGV
)
3050 back_to_previous_line_start (it
);
3052 /* Move over lines that are invisible because of selective display
3053 or text properties. */
3054 while (IT_CHARPOS (*it
) > BEGV
3059 /* If selective > 0, then lines indented more than that values
3061 if (it
->selective
> 0
3062 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3069 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3070 Qinvisible
, it
->window
);
3071 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3075 /* Back one more newline if the current one is invisible. */
3077 back_to_previous_line_start (it
);
3080 xassert (IT_CHARPOS (*it
) >= BEGV
);
3081 xassert (IT_CHARPOS (*it
) == BEGV
3082 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3087 /* Reseat iterator IT at the previous visible line start. Skip
3088 invisible text that is so either due to text properties or due to
3089 selective display. At the end, update IT's overlay information,
3090 face information etc. */
3093 reseat_at_previous_visible_line_start (it
)
3096 back_to_previous_visible_line_start (it
);
3097 reseat (it
, it
->current
.pos
, 1);
3102 /* Reseat iterator IT on the next visible line start in the current
3103 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3104 preceding the line start. Skip over invisible text that is so
3105 because of selective display. Compute faces, overlays etc at the
3106 new position. Note that this function does not skip over text that
3107 is invisible because of text properties. */
3110 reseat_at_next_visible_line_start (it
, on_newline_p
)
3114 /* Restore the buffer position when currently not delivering display
3115 elements from the current buffer. This is the case, for example,
3116 when called at the end of a truncated overlay string. */
3119 it
->method
= next_element_from_buffer
;
3121 /* Otherwise, scan_buffer would not work. */
3122 if (IT_CHARPOS (*it
) < ZV
)
3124 /* If on a newline, advance past it. Otherwise, find the next
3125 newline which automatically gives us the position following
3127 if (FETCH_BYTE (IT_BYTEPOS (*it
)) == '\n')
3133 forward_to_next_line_start (it
);
3135 /* We must either have reached the end of the buffer or end up
3137 xassert (IT_CHARPOS (*it
) == ZV
3138 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3140 /* Skip over lines that are invisible because they are indented
3141 more than the value of IT->selective. */
3142 if (it
->selective
> 0)
3143 while (IT_CHARPOS (*it
) < ZV
3144 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3146 forward_to_next_line_start (it
);
3148 /* Position on the newline if we should. */
3150 && IT_CHARPOS (*it
) > BEGV
3151 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n')
3154 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3157 /* Set the iterator there. The 0 as the last parameter of
3158 reseat means don't force a text property lookup. The lookup
3159 is then only done if we've skipped past the iterator's
3160 check_charpos'es. This optimization is important because
3161 text property lookups tend to be expensive. */
3162 reseat (it
, it
->current
.pos
, 0);
3170 /***********************************************************************
3171 Changing an iterator's position
3172 ***********************************************************************/
3174 /* Change IT's current position to POS in current_buffer. If FORCE_P
3175 is non-zero, always check for text properties at the new position.
3176 Otherwise, text properties are only looked up if POS >=
3177 IT->check_charpos of a property. */
3180 reseat (it
, pos
, force_p
)
3182 struct text_pos pos
;
3185 int original_pos
= IT_CHARPOS (*it
);
3187 reseat_1 (it
, pos
, 0);
3189 /* Determine where to check text properties. Avoid doing it
3190 where possible because text property lookup is very expensive. */
3192 || CHARPOS (pos
) > it
->stop_charpos
3193 || CHARPOS (pos
) < original_pos
)
3200 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3201 IT->stop_pos to POS, also. */
3204 reseat_1 (it
, pos
, set_stop_p
)
3206 struct text_pos pos
;
3209 /* Don't call this function when scanning a C string. */
3210 xassert (it
->s
== NULL
);
3212 /* POS must be a reasonable value. */
3213 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3215 it
->current
.pos
= it
->position
= pos
;
3216 XSETBUFFER (it
->object
, current_buffer
);
3218 it
->current
.dpvec_index
= -1;
3219 it
->current
.overlay_string_index
= -1;
3220 IT_STRING_CHARPOS (*it
) = -1;
3221 IT_STRING_BYTEPOS (*it
) = -1;
3223 it
->method
= next_element_from_buffer
;
3227 it
->stop_charpos
= CHARPOS (pos
);
3231 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3232 If S is non-null, it is a C string to iterate over. Otherwise,
3233 STRING gives a Lisp string to iterate over.
3235 If PRECISION > 0, don't return more then PRECISION number of
3236 characters from the string.
3238 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3239 characters have been returned. FIELD_WIDTH < 0 means an infinite
3242 MULTIBYTE = 0 means disable processing of multibyte characters,
3243 MULTIBYTE > 0 means enable it,
3244 MULTIBYTE < 0 means use IT->multibyte_p.
3246 IT must be initialized via a prior call to init_iterator before
3247 calling this function. */
3250 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3255 int precision
, field_width
, multibyte
;
3257 /* No region in strings. */
3258 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3260 /* No text property checks performed by default, but see below. */
3261 it
->stop_charpos
= -1;
3263 /* Set iterator position and end position. */
3264 bzero (&it
->current
, sizeof it
->current
);
3265 it
->current
.overlay_string_index
= -1;
3266 it
->current
.dpvec_index
= -1;
3267 xassert (charpos
>= 0);
3269 /* Use the setting of MULTIBYTE if specified. */
3271 it
->multibyte_p
= multibyte
> 0;
3275 xassert (STRINGP (string
));
3276 it
->string
= string
;
3278 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3279 it
->method
= next_element_from_string
;
3280 it
->current
.string_pos
= string_pos (charpos
, string
);
3287 /* Note that we use IT->current.pos, not it->current.string_pos,
3288 for displaying C strings. */
3289 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3290 if (it
->multibyte_p
)
3292 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3293 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3297 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3298 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3301 it
->method
= next_element_from_c_string
;
3304 /* PRECISION > 0 means don't return more than PRECISION characters
3306 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3307 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3309 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3310 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3311 FIELD_WIDTH < 0 means infinite field width. This is useful for
3312 padding with `-' at the end of a mode line. */
3313 if (field_width
< 0)
3314 field_width
= INFINITY
;
3315 if (field_width
> it
->end_charpos
- charpos
)
3316 it
->end_charpos
= charpos
+ field_width
;
3318 /* Use the standard display table for displaying strings. */
3319 if (DISP_TABLE_P (Vstandard_display_table
))
3320 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3322 it
->stop_charpos
= charpos
;
3328 /***********************************************************************
3330 ***********************************************************************/
3332 /* Load IT's display element fields with information about the next
3333 display element from the current position of IT. Value is zero if
3334 end of buffer (or C string) is reached. */
3337 get_next_display_element (it
)
3340 /* Non-zero means that we found an display element. Zero means that
3341 we hit the end of what we iterate over. Performance note: the
3342 function pointer `method' used here turns out to be faster than
3343 using a sequence of if-statements. */
3344 int success_p
= (*it
->method
) (it
);
3346 if (it
->what
== IT_CHARACTER
)
3348 /* Map via display table or translate control characters.
3349 IT->c, IT->len etc. have been set to the next character by
3350 the function call above. If we have a display table, and it
3351 contains an entry for IT->c, translate it. Don't do this if
3352 IT->c itself comes from a display table, otherwise we could
3353 end up in an infinite recursion. (An alternative could be to
3354 count the recursion depth of this function and signal an
3355 error when a certain maximum depth is reached.) Is it worth
3357 if (success_p
&& it
->dpvec
== NULL
)
3362 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3365 struct Lisp_Vector
*v
= XVECTOR (dv
);
3367 /* Return the first character from the display table
3368 entry, if not empty. If empty, don't display the
3369 current character. */
3372 it
->dpvec_char_len
= it
->len
;
3373 it
->dpvec
= v
->contents
;
3374 it
->dpend
= v
->contents
+ v
->size
;
3375 it
->current
.dpvec_index
= 0;
3376 it
->method
= next_element_from_display_vector
;
3379 success_p
= get_next_display_element (it
);
3382 /* Translate control characters into `\003' or `^C' form.
3383 Control characters coming from a display table entry are
3384 currently not translated because we use IT->dpvec to hold
3385 the translation. This could easily be changed but I
3386 don't believe that it is worth doing.
3388 Non-printable multibyte characters are also translated
3390 else if ((it
->c
< ' '
3391 && (it
->area
!= TEXT_AREA
3392 || (it
->c
!= '\n' && it
->c
!= '\t')))
3395 || !CHAR_PRINTABLE_P (it
->c
))
3397 /* IT->c is a control character which must be displayed
3398 either as '\003' or as `^C' where the '\\' and '^'
3399 can be defined in the display table. Fill
3400 IT->ctl_chars with glyphs for what we have to
3401 display. Then, set IT->dpvec to these glyphs. */
3404 if (it
->c
< 128 && it
->ctl_arrow_p
)
3406 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3408 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3409 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3410 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3412 g
= FAST_MAKE_GLYPH ('^', 0);
3413 XSETINT (it
->ctl_chars
[0], g
);
3415 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3416 XSETINT (it
->ctl_chars
[1], g
);
3418 /* Set up IT->dpvec and return first character from it. */
3419 it
->dpvec_char_len
= it
->len
;
3420 it
->dpvec
= it
->ctl_chars
;
3421 it
->dpend
= it
->dpvec
+ 2;
3422 it
->current
.dpvec_index
= 0;
3423 it
->method
= next_element_from_display_vector
;
3424 get_next_display_element (it
);
3428 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
3433 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3435 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3436 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3437 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3439 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
3441 if (SINGLE_BYTE_CHAR_P (it
->c
))
3442 str
[0] = it
->c
, len
= 1;
3444 len
= CHAR_STRING (it
->c
, str
);
3446 for (i
= 0; i
< len
; i
++)
3448 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
3449 /* Insert three more glyphs into IT->ctl_chars for
3450 the octal display of the character. */
3451 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
3452 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
3453 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
3454 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
3455 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
3456 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
3459 /* Set up IT->dpvec and return the first character
3461 it
->dpvec_char_len
= it
->len
;
3462 it
->dpvec
= it
->ctl_chars
;
3463 it
->dpend
= it
->dpvec
+ len
* 4;
3464 it
->current
.dpvec_index
= 0;
3465 it
->method
= next_element_from_display_vector
;
3466 get_next_display_element (it
);
3471 /* Adjust face id for a multibyte character. There are no
3472 multibyte character in unibyte text. */
3475 && FRAME_WINDOW_P (it
->f
))
3477 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3478 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
3482 /* Is this character the last one of a run of characters with
3483 box? If yes, set IT->end_of_box_run_p to 1. */
3490 it
->end_of_box_run_p
3491 = ((face_id
= face_after_it_pos (it
),
3492 face_id
!= it
->face_id
)
3493 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3494 face
->box
== FACE_NO_BOX
));
3497 /* Value is 0 if end of buffer or string reached. */
3502 /* Move IT to the next display element.
3504 Functions get_next_display_element and set_iterator_to_next are
3505 separate because I find this arrangement easier to handle than a
3506 get_next_display_element function that also increments IT's
3507 position. The way it is we can first look at an iterator's current
3508 display element, decide whether it fits on a line, and if it does,
3509 increment the iterator position. The other way around we probably
3510 would either need a flag indicating whether the iterator has to be
3511 incremented the next time, or we would have to implement a
3512 decrement position function which would not be easy to write. */
3515 set_iterator_to_next (it
)
3518 if (it
->method
== next_element_from_buffer
)
3520 /* The current display element of IT is a character from
3521 current_buffer. Advance in the buffer, and maybe skip over
3522 invisible lines that are so because of selective display. */
3523 if (ITERATOR_AT_END_OF_LINE_P (it
))
3524 reseat_at_next_visible_line_start (it
, 0);
3527 xassert (it
->len
!= 0);
3528 IT_BYTEPOS (*it
) += it
->len
;
3529 IT_CHARPOS (*it
) += 1;
3530 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3533 else if (it
->method
== next_element_from_composition
)
3535 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
3536 if (STRINGP (it
->string
))
3538 IT_STRING_BYTEPOS (*it
) += it
->len
;
3539 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
3540 it
->method
= next_element_from_string
;
3541 goto consider_string_end
;
3545 IT_BYTEPOS (*it
) += it
->len
;
3546 IT_CHARPOS (*it
) += it
->cmp_len
;
3547 it
->method
= next_element_from_buffer
;
3550 else if (it
->method
== next_element_from_c_string
)
3552 /* Current display element of IT is from a C string. */
3553 IT_BYTEPOS (*it
) += it
->len
;
3554 IT_CHARPOS (*it
) += 1;
3556 else if (it
->method
== next_element_from_display_vector
)
3558 /* Current display element of IT is from a display table entry.
3559 Advance in the display table definition. Reset it to null if
3560 end reached, and continue with characters from buffers/
3562 ++it
->current
.dpvec_index
;
3564 /* Restore face of the iterator to what they were before the
3565 display vector entry (these entries may contain faces). */
3566 it
->face_id
= it
->saved_face_id
;
3568 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3571 it
->method
= next_element_from_c_string
;
3572 else if (STRINGP (it
->string
))
3573 it
->method
= next_element_from_string
;
3575 it
->method
= next_element_from_buffer
;
3578 it
->current
.dpvec_index
= -1;
3580 /* Skip over characters which were displayed via IT->dpvec. */
3581 if (it
->dpvec_char_len
< 0)
3582 reseat_at_next_visible_line_start (it
, 1);
3583 else if (it
->dpvec_char_len
> 0)
3585 it
->len
= it
->dpvec_char_len
;
3586 set_iterator_to_next (it
);
3590 else if (it
->method
== next_element_from_string
)
3592 /* Current display element is a character from a Lisp string. */
3593 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3594 IT_STRING_BYTEPOS (*it
) += it
->len
;
3595 IT_STRING_CHARPOS (*it
) += 1;
3597 consider_string_end
:
3599 if (it
->current
.overlay_string_index
>= 0)
3601 /* IT->string is an overlay string. Advance to the
3602 next, if there is one. */
3603 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3604 next_overlay_string (it
);
3608 /* IT->string is not an overlay string. If we reached
3609 its end, and there is something on IT->stack, proceed
3610 with what is on the stack. This can be either another
3611 string, this time an overlay string, or a buffer. */
3612 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3616 if (!STRINGP (it
->string
))
3617 it
->method
= next_element_from_buffer
;
3621 else if (it
->method
== next_element_from_image
3622 || it
->method
== next_element_from_stretch
)
3624 /* The position etc with which we have to proceed are on
3625 the stack. The position may be at the end of a string,
3626 if the `display' property takes up the whole string. */
3629 if (STRINGP (it
->string
))
3631 it
->method
= next_element_from_string
;
3632 goto consider_string_end
;
3635 it
->method
= next_element_from_buffer
;
3638 /* There are no other methods defined, so this should be a bug. */
3641 /* Reset flags indicating start and end of a sequence of
3642 characters with box. */
3643 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3645 xassert (it
->method
!= next_element_from_string
3646 || (STRINGP (it
->string
)
3647 && IT_STRING_CHARPOS (*it
) >= 0));
3651 /* Load IT's display element fields with information about the next
3652 display element which comes from a display table entry or from the
3653 result of translating a control character to one of the forms `^C'
3654 or `\003'. IT->dpvec holds the glyphs to return as characters. */
3657 next_element_from_display_vector (it
)
3661 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
3663 /* Remember the current face id in case glyphs specify faces.
3664 IT's face is restored in set_iterator_to_next. */
3665 it
->saved_face_id
= it
->face_id
;
3667 if (INTEGERP (*it
->dpvec
)
3668 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
3673 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
3674 it
->c
= FAST_GLYPH_CHAR (g
);
3675 it
->len
= CHAR_BYTES (it
->c
);
3677 /* The entry may contain a face id to use. Such a face id is
3678 the id of a Lisp face, not a realized face. A face id of
3679 zero means no face. */
3680 lface_id
= FAST_GLYPH_FACE (g
);
3683 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
3686 it
->face_id
= face_id
;
3691 /* Display table entry is invalid. Return a space. */
3692 it
->c
= ' ', it
->len
= 1;
3694 /* Don't change position and object of the iterator here. They are
3695 still the values of the character that had this display table
3696 entry or was translated, and that's what we want. */
3697 it
->what
= IT_CHARACTER
;
3702 /* Load IT with the next display element from Lisp string IT->string.
3703 IT->current.string_pos is the current position within the string.
3704 If IT->current.overlay_string_index >= 0, the Lisp string is an
3708 next_element_from_string (it
)
3711 struct text_pos position
;
3713 xassert (STRINGP (it
->string
));
3714 xassert (IT_STRING_CHARPOS (*it
) >= 0);
3715 position
= it
->current
.string_pos
;
3717 /* Time to check for invisible text? */
3718 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
3719 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
3723 /* Since a handler may have changed IT->method, we must
3725 return get_next_display_element (it
);
3728 if (it
->current
.overlay_string_index
>= 0)
3730 /* Get the next character from an overlay string. In overlay
3731 strings, There is no field width or padding with spaces to
3733 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3738 else if (STRING_MULTIBYTE (it
->string
))
3740 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
3741 - IT_STRING_BYTEPOS (*it
));
3742 unsigned char *s
= (XSTRING (it
->string
)->data
3743 + IT_STRING_BYTEPOS (*it
));
3744 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
3748 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3754 /* Get the next character from a Lisp string that is not an
3755 overlay string. Such strings come from the mode line, for
3756 example. We may have to pad with spaces, or truncate the
3757 string. See also next_element_from_c_string. */
3758 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
3763 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
3765 /* Pad with spaces. */
3766 it
->c
= ' ', it
->len
= 1;
3767 CHARPOS (position
) = BYTEPOS (position
) = -1;
3769 else if (STRING_MULTIBYTE (it
->string
))
3771 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
3772 - IT_STRING_BYTEPOS (*it
));
3773 unsigned char *s
= (XSTRING (it
->string
)->data
3774 + IT_STRING_BYTEPOS (*it
));
3775 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
3779 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3784 /* Record what we have and where it came from. Note that we store a
3785 buffer position in IT->position although it could arguably be a
3787 it
->what
= IT_CHARACTER
;
3788 it
->object
= it
->string
;
3789 it
->position
= position
;
3794 /* Load IT with next display element from C string IT->s.
3795 IT->string_nchars is the maximum number of characters to return
3796 from the string. IT->end_charpos may be greater than
3797 IT->string_nchars when this function is called, in which case we
3798 may have to return padding spaces. Value is zero if end of string
3799 reached, including padding spaces. */
3802 next_element_from_c_string (it
)
3808 it
->what
= IT_CHARACTER
;
3809 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
3812 /* IT's position can be greater IT->string_nchars in case a field
3813 width or precision has been specified when the iterator was
3815 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3817 /* End of the game. */
3821 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
3823 /* Pad with spaces. */
3824 it
->c
= ' ', it
->len
= 1;
3825 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
3827 else if (it
->multibyte_p
)
3829 /* Implementation note: The calls to strlen apparently aren't a
3830 performance problem because there is no noticeable performance
3831 difference between Emacs running in unibyte or multibyte mode. */
3832 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
3833 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
3837 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
3843 /* Set up IT to return characters from an ellipsis, if appropriate.
3844 The definition of the ellipsis glyphs may come from a display table
3845 entry. This function Fills IT with the first glyph from the
3846 ellipsis if an ellipsis is to be displayed. */
3849 next_element_from_ellipsis (it
)
3852 if (it
->selective_display_ellipsis_p
)
3854 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3856 /* Use the display table definition for `...'. Invalid glyphs
3857 will be handled by the method returning elements from dpvec. */
3858 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3859 it
->dpvec_char_len
= it
->len
;
3860 it
->dpvec
= v
->contents
;
3861 it
->dpend
= v
->contents
+ v
->size
;
3862 it
->current
.dpvec_index
= 0;
3863 it
->method
= next_element_from_display_vector
;
3867 /* Use default `...' which is stored in default_invis_vector. */
3868 it
->dpvec_char_len
= it
->len
;
3869 it
->dpvec
= default_invis_vector
;
3870 it
->dpend
= default_invis_vector
+ 3;
3871 it
->current
.dpvec_index
= 0;
3872 it
->method
= next_element_from_display_vector
;
3876 reseat_at_next_visible_line_start (it
, 1);
3878 return get_next_display_element (it
);
3882 /* Deliver an image display element. The iterator IT is already
3883 filled with image information (done in handle_display_prop). Value
3888 next_element_from_image (it
)
3891 it
->what
= IT_IMAGE
;
3896 /* Fill iterator IT with next display element from a stretch glyph
3897 property. IT->object is the value of the text property. Value is
3901 next_element_from_stretch (it
)
3904 it
->what
= IT_STRETCH
;
3909 /* Load IT with the next display element from current_buffer. Value
3910 is zero if end of buffer reached. IT->stop_charpos is the next
3911 position at which to stop and check for text properties or buffer
3915 next_element_from_buffer (it
)
3920 /* Check this assumption, otherwise, we would never enter the
3921 if-statement, below. */
3922 xassert (IT_CHARPOS (*it
) >= BEGV
3923 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
3925 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
3927 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3929 int overlay_strings_follow_p
;
3931 /* End of the game, except when overlay strings follow that
3932 haven't been returned yet. */
3933 if (it
->overlay_strings_at_end_processed_p
)
3934 overlay_strings_follow_p
= 0;
3937 it
->overlay_strings_at_end_processed_p
= 1;
3938 overlay_strings_follow_p
= get_overlay_strings (it
);
3941 if (overlay_strings_follow_p
)
3942 success_p
= get_next_display_element (it
);
3946 it
->position
= it
->current
.pos
;
3953 return get_next_display_element (it
);
3958 /* No face changes, overlays etc. in sight, so just return a
3959 character from current_buffer. */
3962 /* Maybe run the redisplay end trigger hook. Performance note:
3963 This doesn't seem to cost measurable time. */
3964 if (it
->redisplay_end_trigger_charpos
3966 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
3967 run_redisplay_end_trigger_hook (it
);
3969 /* Get the next character, maybe multibyte. */
3970 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
3971 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
3973 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
3974 - IT_BYTEPOS (*it
));
3975 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
3978 it
->c
= *p
, it
->len
= 1;
3980 /* Record what we have and where it came from. */
3981 it
->what
= IT_CHARACTER
;;
3982 it
->object
= it
->w
->buffer
;
3983 it
->position
= it
->current
.pos
;
3985 /* Normally we return the character found above, except when we
3986 really want to return an ellipsis for selective display. */
3991 /* A value of selective > 0 means hide lines indented more
3992 than that number of columns. */
3993 if (it
->selective
> 0
3994 && IT_CHARPOS (*it
) + 1 < ZV
3995 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
3996 IT_BYTEPOS (*it
) + 1,
3999 success_p
= next_element_from_ellipsis (it
);
4000 it
->dpvec_char_len
= -1;
4003 else if (it
->c
== '\r' && it
->selective
== -1)
4005 /* A value of selective == -1 means that everything from the
4006 CR to the end of the line is invisible, with maybe an
4007 ellipsis displayed for it. */
4008 success_p
= next_element_from_ellipsis (it
);
4009 it
->dpvec_char_len
= -1;
4014 /* Value is zero if end of buffer reached. */
4015 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4020 /* Run the redisplay end trigger hook for IT. */
4023 run_redisplay_end_trigger_hook (it
)
4026 Lisp_Object args
[3];
4028 /* IT->glyph_row should be non-null, i.e. we should be actually
4029 displaying something, or otherwise we should not run the hook. */
4030 xassert (it
->glyph_row
);
4032 /* Set up hook arguments. */
4033 args
[0] = Qredisplay_end_trigger_functions
;
4034 args
[1] = it
->window
;
4035 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4036 it
->redisplay_end_trigger_charpos
= 0;
4038 /* Since we are *trying* to run these functions, don't try to run
4039 them again, even if they get an error. */
4040 it
->w
->redisplay_end_trigger
= Qnil
;
4041 Frun_hook_with_args (3, args
);
4043 /* Notice if it changed the face of the character we are on. */
4044 handle_face_prop (it
);
4048 /* Deliver a composition display element. The iterator IT is already
4049 filled with composition information (done in
4050 handle_composition_prop). Value is always 1. */
4053 next_element_from_composition (it
)
4056 it
->what
= IT_COMPOSITION
;
4057 it
->position
= (STRINGP (it
->string
)
4058 ? it
->current
.string_pos
4065 /***********************************************************************
4066 Moving an iterator without producing glyphs
4067 ***********************************************************************/
4069 /* Move iterator IT to a specified buffer or X position within one
4070 line on the display without producing glyphs.
4072 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4073 whichever is reached first.
4075 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4077 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4078 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4079 TO_X includes the amount by which a window is horizontally
4084 MOVE_POS_MATCH_OR_ZV
4085 - when TO_POS or ZV was reached.
4088 -when TO_X was reached before TO_POS or ZV were reached.
4091 - when we reached the end of the display area and the line must
4095 - when we reached the end of the display area and the line is
4099 - when we stopped at a line end, i.e. a newline or a CR and selective
4102 static enum move_it_result
4103 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4105 int to_charpos
, to_x
, op
;
4107 enum move_it_result result
= MOVE_UNDEFINED
;
4108 struct glyph_row
*saved_glyph_row
;
4110 /* Don't produce glyphs in produce_glyphs. */
4111 saved_glyph_row
= it
->glyph_row
;
4112 it
->glyph_row
= NULL
;
4118 /* Stop when ZV or TO_CHARPOS reached. */
4119 if (!get_next_display_element (it
)
4120 || ((op
& MOVE_TO_POS
) != 0
4121 && BUFFERP (it
->object
)
4122 && IT_CHARPOS (*it
) >= to_charpos
))
4124 result
= MOVE_POS_MATCH_OR_ZV
;
4128 /* The call to produce_glyphs will get the metrics of the
4129 display element IT is loaded with. We record in x the
4130 x-position before this display element in case it does not
4133 PRODUCE_GLYPHS (it
);
4135 if (it
->area
!= TEXT_AREA
)
4137 set_iterator_to_next (it
);
4141 /* The number of glyphs we get back in IT->nglyphs will normally
4142 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4143 character on a terminal frame, or (iii) a line end. For the
4144 second case, IT->nglyphs - 1 padding glyphs will be present
4145 (on X frames, there is only one glyph produced for a
4146 composite character.
4148 The behavior implemented below means, for continuation lines,
4149 that as many spaces of a TAB as fit on the current line are
4150 displayed there. For terminal frames, as many glyphs of a
4151 multi-glyph character are displayed in the current line, too.
4152 This is what the old redisplay code did, and we keep it that
4153 way. Under X, the whole shape of a complex character must
4154 fit on the line or it will be completely displayed in the
4157 Note that both for tabs and padding glyphs, all glyphs have
4161 /* More than one glyph or glyph doesn't fit on line. All
4162 glyphs have the same width. */
4163 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4166 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4168 new_x
= x
+ single_glyph_width
;
4170 /* We want to leave anything reaching TO_X to the caller. */
4171 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4174 result
= MOVE_X_REACHED
;
4177 else if (/* Lines are continued. */
4178 !it
->truncate_lines_p
4179 && (/* And glyph doesn't fit on the line. */
4180 new_x
> it
->last_visible_x
4181 /* Or it fits exactly and we're on a window
4183 || (new_x
== it
->last_visible_x
4184 && FRAME_WINDOW_P (it
->f
))))
4186 if (/* IT->hpos == 0 means the very first glyph
4187 doesn't fit on the line, e.g. a wide image. */
4189 || (new_x
== it
->last_visible_x
4190 && FRAME_WINDOW_P (it
->f
)))
4193 it
->current_x
= new_x
;
4194 if (i
== it
->nglyphs
- 1)
4195 set_iterator_to_next (it
);
4200 result
= MOVE_LINE_CONTINUED
;
4203 else if (new_x
> it
->first_visible_x
)
4205 /* Glyph is visible. Increment number of glyphs that
4206 would be displayed. */
4211 /* Glyph is completely off the left margin of the display
4212 area. Nothing to do. */
4216 if (result
!= MOVE_UNDEFINED
)
4219 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4221 /* Stop when TO_X specified and reached. This check is
4222 necessary here because of lines consisting of a line end,
4223 only. The line end will not produce any glyphs and we
4224 would never get MOVE_X_REACHED. */
4225 xassert (it
->nglyphs
== 0);
4226 result
= MOVE_X_REACHED
;
4230 /* Is this a line end? If yes, we're done. */
4231 if (ITERATOR_AT_END_OF_LINE_P (it
))
4233 result
= MOVE_NEWLINE_OR_CR
;
4237 /* The current display element has been consumed. Advance
4239 set_iterator_to_next (it
);
4241 /* Stop if lines are truncated and IT's current x-position is
4242 past the right edge of the window now. */
4243 if (it
->truncate_lines_p
4244 && it
->current_x
>= it
->last_visible_x
)
4246 result
= MOVE_LINE_TRUNCATED
;
4251 /* Restore the iterator settings altered at the beginning of this
4253 it
->glyph_row
= saved_glyph_row
;
4258 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4259 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4260 the description of enum move_operation_enum.
4262 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4263 screen line, this function will set IT to the next position >
4267 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4269 int to_charpos
, to_x
, to_y
, to_vpos
;
4272 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4277 if (op
& MOVE_TO_VPOS
)
4279 /* If no TO_CHARPOS and no TO_X specified, stop at the
4280 start of the line TO_VPOS. */
4281 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4283 if (it
->vpos
== to_vpos
)
4285 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4289 /* TO_VPOS >= 0 means stop at TO_X in the line at
4290 TO_VPOS, or at TO_POS, whichever comes first. */
4291 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4293 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4295 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4297 /* We have reached TO_X but not in the line we want. */
4298 skip
= move_it_in_display_line_to (it
, to_charpos
,
4300 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4305 else if (op
& MOVE_TO_Y
)
4307 struct it it_backup
;
4310 /* TO_Y specified means stop at TO_X in the line containing
4311 TO_Y---or at TO_CHARPOS if this is reached first. The
4312 problem is that we can't really tell whether the line
4313 contains TO_Y before we have completely scanned it, and
4314 this may skip past TO_X. What we do is to first scan to
4317 If TO_X is not specified, use a TO_X of zero. The reason
4318 is to make the outcome of this function more predictable.
4319 If we didn't use TO_X == 0, we would stop at the end of
4320 the line which is probably not what a caller would expect
4322 skip
= move_it_in_display_line_to (it
, to_charpos
,
4326 | (op
& MOVE_TO_POS
)));
4328 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4329 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4332 /* If TO_X was reached, we would like to know whether TO_Y
4333 is in the line. This can only be said if we know the
4334 total line height which requires us to scan the rest of
4337 if (skip
== MOVE_X_REACHED
)
4340 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4344 /* Now, decide whether TO_Y is in this line. */
4345 line_height
= it
->max_ascent
+ it
->max_descent
;
4347 if (to_y
>= it
->current_y
4348 && to_y
< it
->current_y
+ line_height
)
4350 if (skip
== MOVE_X_REACHED
)
4351 /* If TO_Y is in this line and TO_X was reached above,
4352 we scanned too far. We have to restore IT's settings
4353 to the ones before skipping. */
4357 else if (skip
== MOVE_X_REACHED
)
4360 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4368 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4372 case MOVE_POS_MATCH_OR_ZV
:
4375 case MOVE_NEWLINE_OR_CR
:
4376 set_iterator_to_next (it
);
4377 it
->continuation_lines_width
= 0;
4380 case MOVE_LINE_TRUNCATED
:
4381 it
->continuation_lines_width
= 0;
4382 reseat_at_next_visible_line_start (it
, 0);
4383 if ((op
& MOVE_TO_POS
) != 0
4384 && IT_CHARPOS (*it
) > to_charpos
)
4388 case MOVE_LINE_CONTINUED
:
4389 it
->continuation_lines_width
+= it
->current_x
;
4396 /* Reset/increment for the next run. */
4397 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4398 it
->current_x
= it
->hpos
= 0;
4399 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4401 last_height
= it
->max_ascent
+ it
->max_descent
;
4402 last_max_ascent
= it
->max_ascent
;
4403 it
->max_ascent
= it
->max_descent
= 0;
4409 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4411 If DY > 0, move IT backward at least that many pixels. DY = 0
4412 means move IT backward to the preceding line start or BEGV. This
4413 function may move over more than DY pixels if IT->current_y - DY
4414 ends up in the middle of a line; in this case IT->current_y will be
4415 set to the top of the line moved to. */
4418 move_it_vertically_backward (it
, dy
)
4422 int nlines
, h
, line_height
;
4424 int start_pos
= IT_CHARPOS (*it
);
4428 /* Estimate how many newlines we must move back. */
4429 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4431 /* Set the iterator's position that many lines back. */
4432 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4433 back_to_previous_visible_line_start (it
);
4435 /* Reseat the iterator here. When moving backward, we don't want
4436 reseat to skip forward over invisible text, set up the iterator
4437 to deliver from overlay strings at the new position etc. So,
4438 use reseat_1 here. */
4439 reseat_1 (it
, it
->current
.pos
, 1);
4441 /* We are now surely at a line start. */
4442 it
->current_x
= it
->hpos
= 0;
4444 /* Move forward and see what y-distance we moved. First move to the
4445 start of the next line so that we get its height. We need this
4446 height to be able to tell whether we reached the specified
4449 it2
.max_ascent
= it2
.max_descent
= 0;
4450 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4451 MOVE_TO_POS
| MOVE_TO_VPOS
);
4452 xassert (IT_CHARPOS (*it
) >= BEGV
);
4453 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4454 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4455 xassert (IT_CHARPOS (*it
) >= BEGV
);
4456 h
= it2
.current_y
- it
->current_y
;
4457 nlines
= it2
.vpos
- it
->vpos
;
4459 /* Correct IT's y and vpos position. */
4465 /* DY == 0 means move to the start of the screen line. The
4466 value of nlines is > 0 if continuation lines were involved. */
4468 move_it_by_lines (it
, nlines
, 1);
4469 xassert (IT_CHARPOS (*it
) <= start_pos
);
4473 /* The y-position we try to reach. Note that h has been
4474 subtracted in front of the if-statement. */
4475 int target_y
= it
->current_y
+ h
- dy
;
4477 /* If we did not reach target_y, try to move further backward if
4478 we can. If we moved too far backward, try to move forward. */
4479 if (target_y
< it
->current_y
4480 && IT_CHARPOS (*it
) > BEGV
)
4482 move_it_vertically (it
, target_y
- it
->current_y
);
4483 xassert (IT_CHARPOS (*it
) >= BEGV
);
4485 else if (target_y
>= it
->current_y
+ line_height
4486 && IT_CHARPOS (*it
) < ZV
)
4488 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4489 xassert (IT_CHARPOS (*it
) >= BEGV
);
4495 /* Move IT by a specified amount of pixel lines DY. DY negative means
4496 move backwards. DY = 0 means move to start of screen line. At the
4497 end, IT will be on the start of a screen line. */
4500 move_it_vertically (it
, dy
)
4505 move_it_vertically_backward (it
, -dy
);
4508 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4509 MOVE_TO_POS
| MOVE_TO_Y
);
4511 /* If buffer ends in ZV without a newline, move to the start of
4512 the line to satisfy the post-condition. */
4513 if (IT_CHARPOS (*it
) == ZV
4514 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4515 move_it_by_lines (it
, 0, 0);
4520 /* Return non-zero if some text between buffer positions START_CHARPOS
4521 and END_CHARPOS is invisible. IT->window is the window for text
4525 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4527 int start_charpos
, end_charpos
;
4529 Lisp_Object prop
, limit
;
4530 int invisible_found_p
;
4532 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4534 /* Is text at START invisible? */
4535 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4537 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4538 invisible_found_p
= 1;
4541 limit
= next_single_char_property_change (make_number (start_charpos
),
4543 make_number (end_charpos
));
4544 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4547 return invisible_found_p
;
4551 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4552 negative means move up. DVPOS == 0 means move to the start of the
4553 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4554 NEED_Y_P is zero, IT->current_y will be left unchanged.
4556 Further optimization ideas: If we would know that IT->f doesn't use
4557 a face with proportional font, we could be faster for
4558 truncate-lines nil. */
4561 move_it_by_lines (it
, dvpos
, need_y_p
)
4563 int dvpos
, need_y_p
;
4565 struct position pos
;
4567 if (!FRAME_WINDOW_P (it
->f
))
4569 struct text_pos textpos
;
4571 /* We can use vmotion on frames without proportional fonts. */
4572 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4573 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4574 reseat (it
, textpos
, 1);
4575 it
->vpos
+= pos
.vpos
;
4576 it
->current_y
+= pos
.vpos
;
4578 else if (dvpos
== 0)
4580 /* DVPOS == 0 means move to the start of the screen line. */
4581 move_it_vertically_backward (it
, 0);
4582 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4586 /* If there are no continuation lines, and if there is no
4587 selective display, try the simple method of moving forward
4588 DVPOS newlines, then see where we are. */
4589 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4591 int shortage
= 0, charpos
;
4593 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
4594 charpos
= IT_CHARPOS (*it
) + 1;
4596 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
4599 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
4601 struct text_pos pos
;
4602 CHARPOS (pos
) = charpos
;
4603 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4604 reseat (it
, pos
, 1);
4605 it
->vpos
+= dvpos
- shortage
;
4606 it
->hpos
= it
->current_x
= 0;
4611 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
4616 int start_charpos
, i
;
4618 /* If there are no continuation lines, and if there is no
4619 selective display, try the simple method of moving backward
4621 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4624 int charpos
= IT_CHARPOS (*it
);
4625 int bytepos
= IT_BYTEPOS (*it
);
4627 /* If in the middle of a line, go to its start. */
4628 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
4630 charpos
= find_next_newline_no_quit (charpos
, -1);
4631 bytepos
= CHAR_TO_BYTE (charpos
);
4634 if (charpos
== BEGV
)
4636 struct text_pos pos
;
4637 CHARPOS (pos
) = charpos
;
4638 BYTEPOS (pos
) = bytepos
;
4639 reseat (it
, pos
, 1);
4640 it
->hpos
= it
->current_x
= 0;
4645 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
4646 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
4648 struct text_pos pos
;
4649 CHARPOS (pos
) = charpos
;
4650 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4651 reseat (it
, pos
, 1);
4652 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
4653 it
->hpos
= it
->current_x
= 0;
4659 /* Go back -DVPOS visible lines and reseat the iterator there. */
4660 start_charpos
= IT_CHARPOS (*it
);
4661 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
4662 back_to_previous_visible_line_start (it
);
4663 reseat (it
, it
->current
.pos
, 1);
4664 it
->current_x
= it
->hpos
= 0;
4666 /* Above call may have moved too far if continuation lines
4667 are involved. Scan forward and see if it did. */
4669 it2
.vpos
= it2
.current_y
= 0;
4670 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
4671 it
->vpos
-= it2
.vpos
;
4672 it
->current_y
-= it2
.current_y
;
4673 it
->current_x
= it
->hpos
= 0;
4675 /* If we moved too far, move IT some lines forward. */
4676 if (it2
.vpos
> -dvpos
)
4678 int delta
= it2
.vpos
+ dvpos
;
4679 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
4686 /***********************************************************************
4688 ***********************************************************************/
4691 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
4695 add_to_log (format
, arg1
, arg2
)
4697 Lisp_Object arg1
, arg2
;
4699 Lisp_Object args
[3];
4700 Lisp_Object msg
, fmt
;
4703 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4706 GCPRO4 (fmt
, msg
, arg1
, arg2
);
4708 args
[0] = fmt
= build_string (format
);
4711 msg
= Fformat (3, args
);
4713 len
= STRING_BYTES (XSTRING (msg
)) + 1;
4714 buffer
= (char *) alloca (len
);
4715 strcpy (buffer
, XSTRING (msg
)->data
);
4717 message_dolog (buffer
, len
- 1, 1, 0);
4722 /* Output a newline in the *Messages* buffer if "needs" one. */
4725 message_log_maybe_newline ()
4727 if (message_log_need_newline
)
4728 message_dolog ("", 0, 1, 0);
4732 /* Add a string M of length LEN to the message log, optionally
4733 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
4734 nonzero, means interpret the contents of M as multibyte. This
4735 function calls low-level routines in order to bypass text property
4736 hooks, etc. which might not be safe to run. */
4739 message_dolog (m
, len
, nlflag
, multibyte
)
4741 int len
, nlflag
, multibyte
;
4743 if (!NILP (Vmessage_log_max
))
4745 struct buffer
*oldbuf
;
4746 Lisp_Object oldpoint
, oldbegv
, oldzv
;
4747 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4748 int point_at_end
= 0;
4750 Lisp_Object old_deactivate_mark
, tem
;
4751 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4753 old_deactivate_mark
= Vdeactivate_mark
;
4754 oldbuf
= current_buffer
;
4755 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
4756 current_buffer
->undo_list
= Qt
;
4758 oldpoint
= Fpoint_marker ();
4759 oldbegv
= Fpoint_min_marker ();
4760 oldzv
= Fpoint_max_marker ();
4761 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
4769 BEGV_BYTE
= BEG_BYTE
;
4772 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4774 /* Insert the string--maybe converting multibyte to single byte
4775 or vice versa, so that all the text fits the buffer. */
4777 && NILP (current_buffer
->enable_multibyte_characters
))
4780 unsigned char work
[1];
4782 /* Convert a multibyte string to single-byte
4783 for the *Message* buffer. */
4784 for (i
= 0; i
< len
; i
+= nbytes
)
4786 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
4787 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
4789 : multibyte_char_to_unibyte (c
, Qnil
));
4790 insert_1_both (work
, 1, 1, 1, 0, 0);
4793 else if (! multibyte
4794 && ! NILP (current_buffer
->enable_multibyte_characters
))
4797 unsigned char *msg
= (unsigned char *) m
;
4798 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4799 /* Convert a single-byte string to multibyte
4800 for the *Message* buffer. */
4801 for (i
= 0; i
< len
; i
++)
4803 c
= unibyte_char_to_multibyte (msg
[i
]);
4804 nbytes
= CHAR_STRING (c
, str
);
4805 insert_1_both (str
, 1, nbytes
, 1, 0, 0);
4809 insert_1 (m
, len
, 1, 0, 0);
4813 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
4814 insert_1 ("\n", 1, 1, 0, 0);
4816 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4818 this_bol_byte
= PT_BYTE
;
4822 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4824 prev_bol_byte
= PT_BYTE
;
4826 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
4827 this_bol
, this_bol_byte
);
4830 del_range_both (prev_bol
, prev_bol_byte
,
4831 this_bol
, this_bol_byte
, 0);
4837 /* If you change this format, don't forget to also
4838 change message_log_check_duplicate. */
4839 sprintf (dupstr
, " [%d times]", dup
);
4840 duplen
= strlen (dupstr
);
4841 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
4842 insert_1 (dupstr
, duplen
, 1, 0, 1);
4847 if (NATNUMP (Vmessage_log_max
))
4849 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
4850 -XFASTINT (Vmessage_log_max
) - 1, 0);
4851 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
4854 BEGV
= XMARKER (oldbegv
)->charpos
;
4855 BEGV_BYTE
= marker_byte_position (oldbegv
);
4864 ZV
= XMARKER (oldzv
)->charpos
;
4865 ZV_BYTE
= marker_byte_position (oldzv
);
4869 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4871 /* We can't do Fgoto_char (oldpoint) because it will run some
4873 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
4874 XMARKER (oldpoint
)->bytepos
);
4877 free_marker (oldpoint
);
4878 free_marker (oldbegv
);
4879 free_marker (oldzv
);
4881 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
4882 set_buffer_internal (oldbuf
);
4884 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
4885 message_log_need_newline
= !nlflag
;
4886 Vdeactivate_mark
= old_deactivate_mark
;
4891 /* We are at the end of the buffer after just having inserted a newline.
4892 (Note: We depend on the fact we won't be crossing the gap.)
4893 Check to see if the most recent message looks a lot like the previous one.
4894 Return 0 if different, 1 if the new one should just replace it, or a
4895 value N > 1 if we should also append " [N times]". */
4898 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
4899 int prev_bol
, this_bol
;
4900 int prev_bol_byte
, this_bol_byte
;
4903 int len
= Z_BYTE
- 1 - this_bol_byte
;
4905 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
4906 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
4908 for (i
= 0; i
< len
; i
++)
4910 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
4919 if (*p1
++ == ' ' && *p1
++ == '[')
4922 while (*p1
>= '0' && *p1
<= '9')
4923 n
= n
* 10 + *p1
++ - '0';
4924 if (strncmp (p1
, " times]\n", 8) == 0)
4931 /* Display an echo area message M with a specified length of LEN
4932 chars. The string may include null characters. If M is 0, clear
4933 out any existing message, and let the mini-buffer text show through.
4935 The buffer M must continue to exist until after the echo area gets
4936 cleared or some other message gets displayed there. This means do
4937 not pass text that is stored in a Lisp string; do not pass text in
4938 a buffer that was alloca'd. */
4941 message2 (m
, len
, multibyte
)
4946 /* First flush out any partial line written with print. */
4947 message_log_maybe_newline ();
4949 message_dolog (m
, len
, 1, multibyte
);
4950 message2_nolog (m
, len
, multibyte
);
4954 /* The non-logging counterpart of message2. */
4957 message2_nolog (m
, len
, multibyte
)
4961 struct frame
*sf
= SELECTED_FRAME ();
4962 message_enable_multibyte
= multibyte
;
4966 if (noninteractive_need_newline
)
4967 putc ('\n', stderr
);
4968 noninteractive_need_newline
= 0;
4970 fwrite (m
, len
, 1, stderr
);
4971 if (cursor_in_echo_area
== 0)
4972 fprintf (stderr
, "\n");
4975 /* A null message buffer means that the frame hasn't really been
4976 initialized yet. Error messages get reported properly by
4977 cmd_error, so this must be just an informative message; toss it. */
4978 else if (INTERACTIVE
4979 && sf
->glyphs_initialized_p
4980 && FRAME_MESSAGE_BUF (sf
))
4982 Lisp_Object mini_window
;
4985 /* Get the frame containing the mini-buffer
4986 that the selected frame is using. */
4987 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
4988 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4990 FRAME_SAMPLE_VISIBILITY (f
);
4991 if (FRAME_VISIBLE_P (sf
)
4992 && ! FRAME_VISIBLE_P (f
))
4993 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
4997 set_message (m
, Qnil
, len
, multibyte
);
4998 if (minibuffer_auto_raise
)
4999 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5002 clear_message (1, 1);
5004 do_pending_window_change (0);
5005 echo_area_display (1);
5006 do_pending_window_change (0);
5007 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5008 (*frame_up_to_date_hook
) (f
);
5013 /* Display an echo area message M with a specified length of NBYTES
5014 bytes. The string may include null characters. If M is not a
5015 string, clear out any existing message, and let the mini-buffer
5016 text show through. */
5019 message3 (m
, nbytes
, multibyte
)
5024 struct gcpro gcpro1
;
5028 /* First flush out any partial line written with print. */
5029 message_log_maybe_newline ();
5031 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5032 message3_nolog (m
, nbytes
, multibyte
);
5038 /* The non-logging version of message3. */
5041 message3_nolog (m
, nbytes
, multibyte
)
5043 int nbytes
, multibyte
;
5045 struct frame
*sf
= SELECTED_FRAME ();
5046 message_enable_multibyte
= multibyte
;
5050 if (noninteractive_need_newline
)
5051 putc ('\n', stderr
);
5052 noninteractive_need_newline
= 0;
5054 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5055 if (cursor_in_echo_area
== 0)
5056 fprintf (stderr
, "\n");
5059 /* A null message buffer means that the frame hasn't really been
5060 initialized yet. Error messages get reported properly by
5061 cmd_error, so this must be just an informative message; toss it. */
5062 else if (INTERACTIVE
5063 && sf
->glyphs_initialized_p
5064 && FRAME_MESSAGE_BUF (sf
))
5066 Lisp_Object mini_window
;
5070 /* Get the frame containing the mini-buffer
5071 that the selected frame is using. */
5072 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5073 frame
= XWINDOW (mini_window
)->frame
;
5076 FRAME_SAMPLE_VISIBILITY (f
);
5077 if (FRAME_VISIBLE_P (sf
)
5078 && !FRAME_VISIBLE_P (f
))
5079 Fmake_frame_visible (frame
);
5081 if (STRINGP (m
) && XSTRING (m
)->size
)
5083 set_message (NULL
, m
, nbytes
, multibyte
);
5084 if (minibuffer_auto_raise
)
5085 Fraise_frame (frame
);
5088 clear_message (1, 1);
5090 do_pending_window_change (0);
5091 echo_area_display (1);
5092 do_pending_window_change (0);
5093 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5094 (*frame_up_to_date_hook
) (f
);
5099 /* Display a null-terminated echo area message M. If M is 0, clear
5100 out any existing message, and let the mini-buffer text show through.
5102 The buffer M must continue to exist until after the echo area gets
5103 cleared or some other message gets displayed there. Do not pass
5104 text that is stored in a Lisp string. Do not pass text in a buffer
5105 that was alloca'd. */
5111 message2 (m
, (m
? strlen (m
) : 0), 0);
5115 /* The non-logging counterpart of message1. */
5121 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5124 /* Display a message M which contains a single %s
5125 which gets replaced with STRING. */
5128 message_with_string (m
, string
, log
)
5137 if (noninteractive_need_newline
)
5138 putc ('\n', stderr
);
5139 noninteractive_need_newline
= 0;
5140 fprintf (stderr
, m
, XSTRING (string
)->data
);
5141 if (cursor_in_echo_area
== 0)
5142 fprintf (stderr
, "\n");
5146 else if (INTERACTIVE
)
5148 /* The frame whose minibuffer we're going to display the message on.
5149 It may be larger than the selected frame, so we need
5150 to use its buffer, not the selected frame's buffer. */
5151 Lisp_Object mini_window
;
5152 struct frame
*f
, *sf
= SELECTED_FRAME ();
5154 /* Get the frame containing the minibuffer
5155 that the selected frame is using. */
5156 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5157 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5159 /* A null message buffer means that the frame hasn't really been
5160 initialized yet. Error messages get reported properly by
5161 cmd_error, so this must be just an informative message; toss it. */
5162 if (FRAME_MESSAGE_BUF (f
))
5166 a
[0] = (char *) XSTRING (string
)->data
;
5168 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5169 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5172 message2 (FRAME_MESSAGE_BUF (f
), len
,
5173 STRING_MULTIBYTE (string
));
5175 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5176 STRING_MULTIBYTE (string
));
5178 /* Print should start at the beginning of the message
5179 buffer next time. */
5180 message_buf_print
= 0;
5186 /* Dump an informative message to the minibuf. If M is 0, clear out
5187 any existing message, and let the mini-buffer text show through. */
5191 message (m
, a1
, a2
, a3
)
5193 EMACS_INT a1
, a2
, a3
;
5199 if (noninteractive_need_newline
)
5200 putc ('\n', stderr
);
5201 noninteractive_need_newline
= 0;
5202 fprintf (stderr
, m
, a1
, a2
, a3
);
5203 if (cursor_in_echo_area
== 0)
5204 fprintf (stderr
, "\n");
5208 else if (INTERACTIVE
)
5210 /* The frame whose mini-buffer we're going to display the message
5211 on. It may be larger than the selected frame, so we need to
5212 use its buffer, not the selected frame's buffer. */
5213 Lisp_Object mini_window
;
5214 struct frame
*f
, *sf
= SELECTED_FRAME ();
5216 /* Get the frame containing the mini-buffer
5217 that the selected frame is using. */
5218 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5219 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5221 /* A null message buffer means that the frame hasn't really been
5222 initialized yet. Error messages get reported properly by
5223 cmd_error, so this must be just an informative message; toss
5225 if (FRAME_MESSAGE_BUF (f
))
5236 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5237 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5239 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5240 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5242 #endif /* NO_ARG_ARRAY */
5244 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5249 /* Print should start at the beginning of the message
5250 buffer next time. */
5251 message_buf_print
= 0;
5257 /* The non-logging version of message. */
5260 message_nolog (m
, a1
, a2
, a3
)
5262 EMACS_INT a1
, a2
, a3
;
5264 Lisp_Object old_log_max
;
5265 old_log_max
= Vmessage_log_max
;
5266 Vmessage_log_max
= Qnil
;
5267 message (m
, a1
, a2
, a3
);
5268 Vmessage_log_max
= old_log_max
;
5272 /* Display the current message in the current mini-buffer. This is
5273 only called from error handlers in process.c, and is not time
5279 if (!NILP (echo_area_buffer
[0]))
5282 string
= Fcurrent_message ();
5283 message3 (string
, XSTRING (string
)->size
,
5284 !NILP (current_buffer
->enable_multibyte_characters
));
5289 /* Make sure echo area buffers in echo_buffers[] are life. If they
5290 aren't, make new ones. */
5293 ensure_echo_area_buffers ()
5297 for (i
= 0; i
< 2; ++i
)
5298 if (!BUFFERP (echo_buffer
[i
])
5299 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5302 sprintf (name
, " *Echo Area %d*", i
);
5303 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5308 /* Call FN with args A1..A5 with either the current or last displayed
5309 echo_area_buffer as current buffer.
5311 WHICH zero means use the current message buffer
5312 echo_area_buffer[0]. If that is nil, choose a suitable buffer
5313 from echo_buffer[] and clear it.
5315 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
5316 suitable buffer from echo_buffer[] and clear it.
5318 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
5319 that the current message becomes the last displayed one, make
5320 choose a suitable buffer for echo_area_buffer[0], and clear it.
5322 Value is what FN returns. */
5325 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
)
5329 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
;
5332 int this_one
, the_other
, clear_buffer_p
, rc
;
5333 int count
= specpdl_ptr
- specpdl
;
5335 /* If buffers aren't life, make new ones. */
5336 ensure_echo_area_buffers ();
5341 this_one
= 0, the_other
= 1;
5343 this_one
= 1, the_other
= 0;
5346 this_one
= 0, the_other
= 1;
5349 /* We need a fresh one in case the current echo buffer equals
5350 the one containing the last displayed echo area message. */
5351 if (!NILP (echo_area_buffer
[this_one
])
5352 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
5353 echo_area_buffer
[this_one
] = Qnil
;
5356 /* Choose a suitable buffer from echo_buffer[] is we don't
5358 if (NILP (echo_area_buffer
[this_one
]))
5360 echo_area_buffer
[this_one
]
5361 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
5362 ? echo_buffer
[the_other
]
5363 : echo_buffer
[this_one
]);
5367 buffer
= echo_area_buffer
[this_one
];
5369 record_unwind_protect (unwind_with_echo_area_buffer
,
5370 with_echo_area_buffer_unwind_data (w
));
5372 /* Make the echo area buffer current. Note that for display
5373 purposes, it is not necessary that the displayed window's buffer
5374 == current_buffer, except for text property lookup. So, let's
5375 only set that buffer temporarily here without doing a full
5376 Fset_window_buffer. We must also change w->pointm, though,
5377 because otherwise an assertions in unshow_buffer fails, and Emacs
5379 set_buffer_internal_1 (XBUFFER (buffer
));
5383 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
5385 current_buffer
->truncate_lines
= Qnil
;
5386 current_buffer
->undo_list
= Qt
;
5387 current_buffer
->read_only
= Qnil
;
5389 if (clear_buffer_p
&& Z
> BEG
)
5392 xassert (BEGV
>= BEG
);
5393 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5395 rc
= fn (a1
, a2
, a3
, a4
, a5
);
5397 xassert (BEGV
>= BEG
);
5398 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5400 unbind_to (count
, Qnil
);
5405 /* Save state that should be preserved around the call to the function
5406 FN called in with_echo_area_buffer. */
5409 with_echo_area_buffer_unwind_data (w
)
5415 /* Reduce consing by keeping one vector in
5416 Vwith_echo_area_save_vector. */
5417 vector
= Vwith_echo_area_save_vector
;
5418 Vwith_echo_area_save_vector
= Qnil
;
5421 vector
= Fmake_vector (make_number (7), Qnil
);
5423 XSETBUFFER (XVECTOR (vector
)->contents
[i
], current_buffer
); ++i
;
5424 XVECTOR (vector
)->contents
[i
++] = Vdeactivate_mark
;
5425 XVECTOR (vector
)->contents
[i
++] = make_number (windows_or_buffers_changed
);
5429 XSETWINDOW (XVECTOR (vector
)->contents
[i
], w
); ++i
;
5430 XVECTOR (vector
)->contents
[i
++] = w
->buffer
;
5431 XVECTOR (vector
)->contents
[i
++]
5432 = make_number (XMARKER (w
->pointm
)->charpos
);
5433 XVECTOR (vector
)->contents
[i
++]
5434 = make_number (XMARKER (w
->pointm
)->bytepos
);
5440 XVECTOR (vector
)->contents
[i
++] = Qnil
;
5443 xassert (i
== XVECTOR (vector
)->size
);
5448 /* Restore global state from VECTOR which was created by
5449 with_echo_area_buffer_unwind_data. */
5452 unwind_with_echo_area_buffer (vector
)
5457 set_buffer_internal_1 (XBUFFER (XVECTOR (vector
)->contents
[i
])); ++i
;
5458 Vdeactivate_mark
= XVECTOR (vector
)->contents
[i
]; ++i
;
5459 windows_or_buffers_changed
= XFASTINT (XVECTOR (vector
)->contents
[i
]); ++i
;
5461 if (WINDOWP (XVECTOR (vector
)->contents
[i
]))
5464 Lisp_Object buffer
, charpos
, bytepos
;
5466 w
= XWINDOW (XVECTOR (vector
)->contents
[i
]); ++i
;
5467 buffer
= XVECTOR (vector
)->contents
[i
]; ++i
;
5468 charpos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5469 bytepos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5472 set_marker_both (w
->pointm
, buffer
,
5473 XFASTINT (charpos
), XFASTINT (bytepos
));
5476 Vwith_echo_area_save_vector
= vector
;
5481 /* Set up the echo area for use by print functions. MULTIBYTE_P
5482 non-zero means we will print multibyte. */
5485 setup_echo_area_for_printing (multibyte_p
)
5488 ensure_echo_area_buffers ();
5490 if (!message_buf_print
)
5492 /* A message has been output since the last time we printed.
5493 Choose a fresh echo area buffer. */
5494 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5495 echo_area_buffer
[0] = echo_buffer
[1];
5497 echo_area_buffer
[0] = echo_buffer
[0];
5499 /* Switch to that buffer and clear it. */
5500 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5503 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5505 /* Set up the buffer for the multibyteness we need. */
5507 != !NILP (current_buffer
->enable_multibyte_characters
))
5508 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
5510 /* Raise the frame containing the echo area. */
5511 if (minibuffer_auto_raise
)
5513 struct frame
*sf
= SELECTED_FRAME ();
5514 Lisp_Object mini_window
;
5515 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5516 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5519 message_buf_print
= 1;
5523 if (NILP (echo_area_buffer
[0]))
5525 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5526 echo_area_buffer
[0] = echo_buffer
[1];
5528 echo_area_buffer
[0] = echo_buffer
[0];
5531 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
5532 /* Someone switched buffers between print requests. */
5533 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5538 /* Display an echo area message in window W. Value is non-zero if W's
5539 height is changed. If display_last_displayed_message_p is
5540 non-zero, display the message that was last displayed, otherwise
5541 display the current message. */
5544 display_echo_area (w
)
5547 int i
, no_message_p
, window_height_changed_p
, count
;
5549 /* Temporarily disable garbage collections while displaying the echo
5550 area. This is done because a GC can print a message itself.
5551 That message would modify the echo area buffer's contents while a
5552 redisplay of the buffer is going on, and seriously confuse
5554 count
= inhibit_garbage_collection ();
5556 /* If there is no message, we must call display_echo_area_1
5557 nevertheless because it resizes the window. But we will have to
5558 reset the echo_area_buffer in question to nil at the end because
5559 with_echo_area_buffer will sets it to an empty buffer. */
5560 i
= display_last_displayed_message_p
? 1 : 0;
5561 no_message_p
= NILP (echo_area_buffer
[i
]);
5563 window_height_changed_p
5564 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
5565 (int (*) ()) display_echo_area_1
, w
);
5568 echo_area_buffer
[i
] = Qnil
;
5570 unbind_to (count
, Qnil
);
5571 return window_height_changed_p
;
5575 /* Helper for display_echo_area. Display the current buffer which
5576 contains the current echo area message in window W, a mini-window.
5577 Change the height of W so that all of the message is displayed.
5578 Value is non-zero if height of W was changed. */
5581 display_echo_area_1 (w
)
5585 struct text_pos start
;
5586 int window_height_changed_p
= 0;
5588 /* Do this before displaying, so that we have a large enough glyph
5589 matrix for the display. */
5590 window_height_changed_p
= resize_mini_window (w
, 0);
5593 clear_glyph_matrix (w
->desired_matrix
);
5594 XSETWINDOW (window
, w
);
5595 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
5596 try_window (window
, start
);
5598 return window_height_changed_p
;
5602 /* Resize the echo area window to exactly the size needed for the
5603 currently displayed message, if there is one. */
5606 resize_echo_area_axactly ()
5608 if (BUFFERP (echo_area_buffer
[0])
5609 && WINDOWP (echo_area_window
))
5611 struct window
*w
= XWINDOW (echo_area_window
);
5614 resized_p
= with_echo_area_buffer (w
, 0,
5615 (int (*) ()) resize_mini_window
,
5619 ++windows_or_buffers_changed
;
5620 ++update_mode_lines
;
5621 redisplay_internal (0);
5627 /* Resize mini-window W to fit the size of its contents. EXACT:P
5628 means size the window exactly to the size needed. Otherwise, it's
5629 only enlarged until W's buffer is empty. Value is non-zero if
5630 the window height has been changed. */
5633 resize_mini_window (w
, exact_p
)
5637 struct frame
*f
= XFRAME (w
->frame
);
5638 int window_height_changed_p
= 0;
5640 xassert (MINI_WINDOW_P (w
));
5642 /* Nil means don't try to resize. */
5643 if (NILP (Vmax_mini_window_height
)
5644 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
5647 if (!FRAME_MINIBUF_ONLY_P (f
))
5650 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5651 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
5652 int height
, max_height
;
5653 int unit
= CANON_Y_UNIT (f
);
5654 struct text_pos start
;
5656 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
5658 /* Compute the max. number of lines specified by the user. */
5659 if (FLOATP (Vmax_mini_window_height
))
5660 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
5661 else if (INTEGERP (Vmax_mini_window_height
))
5662 max_height
= XINT (Vmax_mini_window_height
);
5664 max_height
= total_height
/ 4;
5666 /* Correct that max. height if it's bogus. */
5667 max_height
= max (1, max_height
);
5668 max_height
= min (total_height
, max_height
);
5670 /* Find out the height of the text in the window. */
5672 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
5673 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
5674 height
= it
.current_y
+ last_height
;
5676 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
5677 height
= (height
+ unit
- 1) / unit
;
5679 /* Compute a suitable window start. */
5680 if (height
> max_height
)
5682 height
= max_height
;
5683 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
5684 move_it_vertically_backward (&it
, (height
- 1) * unit
);
5685 start
= it
.current
.pos
;
5688 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5689 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
5691 /* Let it grow only, until we display an empty message, in which
5692 case the window shrinks again. */
5693 if (height
> XFASTINT (w
->height
))
5695 int old_height
= XFASTINT (w
->height
);
5696 freeze_window_starts (f
, 1);
5697 grow_mini_window (w
, height
- XFASTINT (w
->height
));
5698 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5700 else if (height
< XFASTINT (w
->height
)
5701 && (exact_p
|| BEGV
== ZV
))
5703 int old_height
= XFASTINT (w
->height
);
5704 freeze_window_starts (f
, 0);
5705 shrink_mini_window (w
);
5706 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5710 return window_height_changed_p
;
5714 /* Value is the current message, a string, or nil if there is no
5722 if (NILP (echo_area_buffer
[0]))
5726 with_echo_area_buffer (0, 0, (int (*) ()) current_message_1
, &msg
);
5728 echo_area_buffer
[0] = Qnil
;
5736 current_message_1 (msg
)
5740 *msg
= make_buffer_string (BEG
, Z
, 1);
5747 /* Push the current message on Vmessage_stack for later restauration
5748 by restore_message. Value is non-zero if the current message isn't
5749 empty. This is a relatively infrequent operation, so it's not
5750 worth optimizing. */
5756 msg
= current_message ();
5757 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
5758 return STRINGP (msg
);
5762 /* Restore message display from the top of Vmessage_stack. */
5769 xassert (CONSP (Vmessage_stack
));
5770 msg
= XCAR (Vmessage_stack
);
5772 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
5774 message3_nolog (msg
, 0, 0);
5778 /* Pop the top-most entry off Vmessage_stack. */
5783 xassert (CONSP (Vmessage_stack
));
5784 Vmessage_stack
= XCDR (Vmessage_stack
);
5788 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
5789 exits. If the stack is not empty, we have a missing pop_message
5793 check_message_stack ()
5795 if (!NILP (Vmessage_stack
))
5800 /* Truncate to NCHARS what will be displayed in the echo area the next
5801 time we display it---but don't redisplay it now. */
5804 truncate_echo_area (nchars
)
5808 echo_area_buffer
[0] = Qnil
;
5809 /* A null message buffer means that the frame hasn't really been
5810 initialized yet. Error messages get reported properly by
5811 cmd_error, so this must be just an informative message; toss it. */
5812 else if (!noninteractive
5814 && !NILP (echo_area_buffer
[0]))
5816 struct frame
*sf
= SELECTED_FRAME ();
5817 if (FRAME_MESSAGE_BUF (sf
))
5818 with_echo_area_buffer (0, 0, (int (*) ()) truncate_message_1
, nchars
);
5823 /* Helper function for truncate_echo_area. Truncate the current
5824 message to at most NCHARS characters. */
5827 truncate_message_1 (nchars
)
5830 if (BEG
+ nchars
< Z
)
5831 del_range (BEG
+ nchars
, Z
);
5833 echo_area_buffer
[0] = Qnil
;
5838 /* Set the current message to a substring of S or STRING.
5840 If STRING is a Lisp string, set the message to the first NBYTES
5841 bytes from STRING. NBYTES zero means use the whole string. If
5842 STRING is multibyte, the message will be displayed multibyte.
5844 If S is not null, set the message to the first LEN bytes of S. LEN
5845 zero means use the whole string. MULTIBYTE_P non-zero means S is
5846 multibyte. Display the message multibyte in that case. */
5849 set_message (s
, string
, nbytes
, multibyte_p
)
5854 message_enable_multibyte
5855 = ((s
&& multibyte_p
)
5856 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
5858 with_echo_area_buffer (0, -1, (int (*) ()) set_message_1
,
5859 s
, string
, nbytes
, multibyte_p
);
5860 message_buf_print
= 0;
5864 /* Helper function for set_message. Arguments have the same meaning
5865 as there. This function is called with the echo area buffer being
5869 set_message_1 (s
, string
, nbytes
, multibyte_p
)
5872 int nbytes
, multibyte_p
;
5876 /* Change multibyteness of the echo buffer appropriately. */
5877 if (message_enable_multibyte
5878 != !NILP (current_buffer
->enable_multibyte_characters
))
5879 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
5881 /* Insert new message at BEG. */
5882 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5884 if (STRINGP (string
))
5889 nbytes
= XSTRING (string
)->size_byte
;
5890 nchars
= string_byte_to_char (string
, nbytes
);
5892 /* This function takes care of single/multibyte conversion. We
5893 just have to ensure that the echo area buffer has the right
5894 setting of enable_multibyte_characters. */
5895 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
5900 nbytes
= strlen (s
);
5902 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
5904 /* Convert from multi-byte to single-byte. */
5906 unsigned char work
[1];
5908 /* Convert a multibyte string to single-byte. */
5909 for (i
= 0; i
< nbytes
; i
+= n
)
5911 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
5912 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5914 : multibyte_char_to_unibyte (c
, Qnil
));
5915 insert_1_both (work
, 1, 1, 1, 0, 0);
5918 else if (!multibyte_p
5919 && !NILP (current_buffer
->enable_multibyte_characters
))
5921 /* Convert from single-byte to multi-byte. */
5923 unsigned char *msg
= (unsigned char *) s
;
5924 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5926 /* Convert a single-byte string to multibyte. */
5927 for (i
= 0; i
< nbytes
; i
++)
5929 c
= unibyte_char_to_multibyte (msg
[i
]);
5930 n
= CHAR_STRING (c
, str
);
5931 insert_1_both (str
, 1, n
, 1, 0, 0);
5935 insert_1 (s
, nbytes
, 1, 0, 0);
5942 /* Clear messages. CURRENT_P non-zero means clear the current
5943 message. LAST_DISPLAYED_P non-zero means clear the message
5947 clear_message (current_p
, last_displayed_p
)
5948 int current_p
, last_displayed_p
;
5951 echo_area_buffer
[0] = Qnil
;
5953 if (last_displayed_p
)
5954 echo_area_buffer
[1] = Qnil
;
5956 message_buf_print
= 0;
5959 /* Clear garbaged frames.
5961 This function is used where the old redisplay called
5962 redraw_garbaged_frames which in turn called redraw_frame which in
5963 turn called clear_frame. The call to clear_frame was a source of
5964 flickering. I believe a clear_frame is not necessary. It should
5965 suffice in the new redisplay to invalidate all current matrices,
5966 and ensure a complete redisplay of all windows. */
5969 clear_garbaged_frames ()
5973 Lisp_Object tail
, frame
;
5975 FOR_EACH_FRAME (tail
, frame
)
5977 struct frame
*f
= XFRAME (frame
);
5979 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
5981 clear_current_matrices (f
);
5987 ++windows_or_buffers_changed
;
5992 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
5993 is non-zero update selected_frame. Value is non-zero if the
5994 mini-windows height has been changed. */
5997 echo_area_display (update_frame_p
)
6000 Lisp_Object mini_window
;
6003 int window_height_changed_p
= 0;
6004 struct frame
*sf
= SELECTED_FRAME ();
6006 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6007 w
= XWINDOW (mini_window
);
6008 f
= XFRAME (WINDOW_FRAME (w
));
6010 /* Don't display if frame is invisible or not yet initialized. */
6011 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6014 #ifdef HAVE_WINDOW_SYSTEM
6015 /* When Emacs starts, selected_frame may be a visible terminal
6016 frame, even if we run under a window system. If we let this
6017 through, a message would be displayed on the terminal. */
6018 if (EQ (selected_frame
, Vterminal_frame
)
6019 && !NILP (Vwindow_system
))
6021 #endif /* HAVE_WINDOW_SYSTEM */
6023 /* Redraw garbaged frames. */
6025 clear_garbaged_frames ();
6027 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6029 echo_area_window
= mini_window
;
6030 window_height_changed_p
= display_echo_area (w
);
6031 w
->must_be_updated_p
= 1;
6035 /* Not called from redisplay_internal. If we changed
6036 window configuration, we must redisplay thoroughly.
6037 Otherwise, we can do with updating what we displayed
6039 if (window_height_changed_p
)
6041 ++windows_or_buffers_changed
;
6042 ++update_mode_lines
;
6043 redisplay_internal (0);
6045 else if (FRAME_WINDOW_P (f
))
6047 update_single_window (w
, 1);
6048 rif
->flush_display (f
);
6051 update_frame (f
, 1, 1);
6054 else if (!EQ (mini_window
, selected_window
))
6055 windows_or_buffers_changed
++;
6057 /* Last displayed message is now the current message. */
6058 echo_area_buffer
[1] = echo_area_buffer
[0];
6060 /* Prevent redisplay optimization in redisplay_internal by resetting
6061 this_line_start_pos. This is done because the mini-buffer now
6062 displays the message instead of its buffer text. */
6063 if (EQ (mini_window
, selected_window
))
6064 CHARPOS (this_line_start_pos
) = 0;
6066 return window_height_changed_p
;
6071 /***********************************************************************
6073 ***********************************************************************/
6076 #ifdef HAVE_WINDOW_SYSTEM
6078 /* A buffer for constructing frame titles in it; allocated from the
6079 heap in init_xdisp and resized as needed in store_frame_title_char. */
6081 static char *frame_title_buf
;
6083 /* The buffer's end, and a current output position in it. */
6085 static char *frame_title_buf_end
;
6086 static char *frame_title_ptr
;
6089 /* Store a single character C for the frame title in frame_title_buf.
6090 Re-allocate frame_title_buf if necessary. */
6093 store_frame_title_char (c
)
6096 /* If output position has reached the end of the allocated buffer,
6097 double the buffer's size. */
6098 if (frame_title_ptr
== frame_title_buf_end
)
6100 int len
= frame_title_ptr
- frame_title_buf
;
6101 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6102 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6103 frame_title_buf_end
= frame_title_buf
+ new_size
;
6104 frame_title_ptr
= frame_title_buf
+ len
;
6107 *frame_title_ptr
++ = c
;
6111 /* Store part of a frame title in frame_title_buf, beginning at
6112 frame_title_ptr. STR is the string to store. Do not copy more
6113 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
6114 the whole string. Pad with spaces until FIELD_WIDTH number of
6115 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
6116 Called from display_mode_element when it is used to build a frame
6120 store_frame_title (str
, field_width
, precision
)
6122 int field_width
, precision
;
6126 /* Copy at most PRECISION chars from STR. */
6127 while ((precision
<= 0 || n
< precision
)
6130 store_frame_title_char (*str
++);
6134 /* Fill up with spaces until FIELD_WIDTH reached. */
6135 while (field_width
> 0
6138 store_frame_title_char (' ');
6146 /* Set the title of FRAME, if it has changed. The title format is
6147 Vicon_title_format if FRAME is iconified, otherwise it is
6148 frame_title_format. */
6151 x_consider_frame_title (frame
)
6154 struct frame
*f
= XFRAME (frame
);
6156 if (FRAME_WINDOW_P (f
)
6157 || FRAME_MINIBUF_ONLY_P (f
)
6158 || f
->explicit_name
)
6160 /* Do we have more than one visible frame on this X display? */
6163 struct buffer
*obuf
;
6167 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
6169 struct frame
*tf
= XFRAME (XCAR (tail
));
6172 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
6173 && !FRAME_MINIBUF_ONLY_P (tf
)
6174 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
6178 /* Set global variable indicating that multiple frames exist. */
6179 multiple_frames
= CONSP (tail
);
6181 /* Switch to the buffer of selected window of the frame. Set up
6182 frame_title_ptr so that display_mode_element will output into it;
6183 then display the title. */
6184 obuf
= current_buffer
;
6185 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
6186 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
6187 frame_title_ptr
= frame_title_buf
;
6188 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
6189 NULL
, DEFAULT_FACE_ID
);
6190 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
6191 frame_title_ptr
= NULL
;
6192 set_buffer_internal (obuf
);
6194 /* Set the title only if it's changed. This avoids consing in
6195 the common case where it hasn't. (If it turns out that we've
6196 already wasted too much time by walking through the list with
6197 display_mode_element, then we might need to optimize at a
6198 higher level than this.) */
6199 if (! STRINGP (f
->name
)
6200 || STRING_BYTES (XSTRING (f
->name
)) != len
6201 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
6202 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
6206 #else /* not HAVE_WINDOW_SYSTEM */
6208 #define frame_title_ptr ((char *)0)
6209 #define store_frame_title(str, mincol, maxcol) 0
6211 #endif /* not HAVE_WINDOW_SYSTEM */
6216 /***********************************************************************
6218 ***********************************************************************/
6221 /* Prepare for redisplay by updating menu-bar item lists when
6222 appropriate. This can call eval. */
6225 prepare_menu_bars ()
6228 struct gcpro gcpro1
, gcpro2
;
6230 struct frame
*tooltip_frame
;
6232 #ifdef HAVE_X_WINDOWS
6233 tooltip_frame
= tip_frame
;
6235 tooltip_frame
= NULL
;
6238 /* Update all frame titles based on their buffer names, etc. We do
6239 this before the menu bars so that the buffer-menu will show the
6240 up-to-date frame titles. */
6241 #ifdef HAVE_WINDOW_SYSTEM
6242 if (windows_or_buffers_changed
|| update_mode_lines
)
6244 Lisp_Object tail
, frame
;
6246 FOR_EACH_FRAME (tail
, frame
)
6249 if (f
!= tooltip_frame
6250 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
6251 x_consider_frame_title (frame
);
6254 #endif /* HAVE_WINDOW_SYSTEM */
6256 /* Update the menu bar item lists, if appropriate. This has to be
6257 done before any actual redisplay or generation of display lines. */
6258 all_windows
= (update_mode_lines
6259 || buffer_shared
> 1
6260 || windows_or_buffers_changed
);
6263 Lisp_Object tail
, frame
;
6264 int count
= specpdl_ptr
- specpdl
;
6266 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6268 FOR_EACH_FRAME (tail
, frame
)
6272 /* Ignore tooltip frame. */
6273 if (f
== tooltip_frame
)
6276 /* If a window on this frame changed size, report that to
6277 the user and clear the size-change flag. */
6278 if (FRAME_WINDOW_SIZES_CHANGED (f
))
6280 Lisp_Object functions
;
6282 /* Clear flag first in case we get an error below. */
6283 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
6284 functions
= Vwindow_size_change_functions
;
6285 GCPRO2 (tail
, functions
);
6287 while (CONSP (functions
))
6289 call1 (XCAR (functions
), frame
);
6290 functions
= XCDR (functions
);
6296 update_menu_bar (f
, 0);
6297 #ifdef HAVE_WINDOW_SYSTEM
6298 update_tool_bar (f
, 0);
6303 unbind_to (count
, Qnil
);
6307 struct frame
*sf
= SELECTED_FRAME ();
6308 update_menu_bar (sf
, 1);
6309 #ifdef HAVE_WINDOW_SYSTEM
6310 update_tool_bar (sf
, 1);
6314 /* Motif needs this. See comment in xmenu.c. Turn it off when
6315 pending_menu_activation is not defined. */
6316 #ifdef USE_X_TOOLKIT
6317 pending_menu_activation
= 0;
6322 /* Update the menu bar item list for frame F. This has to be done
6323 before we start to fill in any display lines, because it can call
6326 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
6329 update_menu_bar (f
, save_match_data
)
6331 int save_match_data
;
6334 register struct window
*w
;
6336 window
= FRAME_SELECTED_WINDOW (f
);
6337 w
= XWINDOW (window
);
6339 if (update_mode_lines
)
6340 w
->update_mode_line
= Qt
;
6342 if (FRAME_WINDOW_P (f
)
6344 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6345 FRAME_EXTERNAL_MENU_BAR (f
)
6347 FRAME_MENU_BAR_LINES (f
) > 0
6349 : FRAME_MENU_BAR_LINES (f
) > 0)
6351 /* If the user has switched buffers or windows, we need to
6352 recompute to reflect the new bindings. But we'll
6353 recompute when update_mode_lines is set too; that means
6354 that people can use force-mode-line-update to request
6355 that the menu bar be recomputed. The adverse effect on
6356 the rest of the redisplay algorithm is about the same as
6357 windows_or_buffers_changed anyway. */
6358 if (windows_or_buffers_changed
6359 || !NILP (w
->update_mode_line
)
6360 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6361 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6362 != !NILP (w
->last_had_star
))
6363 || ((!NILP (Vtransient_mark_mode
)
6364 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6365 != !NILP (w
->region_showing
)))
6367 struct buffer
*prev
= current_buffer
;
6368 int count
= specpdl_ptr
- specpdl
;
6370 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6371 if (save_match_data
)
6372 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6373 if (NILP (Voverriding_local_map_menu_flag
))
6375 specbind (Qoverriding_terminal_local_map
, Qnil
);
6376 specbind (Qoverriding_local_map
, Qnil
);
6379 /* Run the Lucid hook. */
6380 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
6382 /* If it has changed current-menubar from previous value,
6383 really recompute the menu-bar from the value. */
6384 if (! NILP (Vlucid_menu_bar_dirty_flag
))
6385 call0 (Qrecompute_lucid_menubar
);
6387 safe_run_hooks (Qmenu_bar_update_hook
);
6388 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
6390 /* Redisplay the menu bar in case we changed it. */
6391 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6392 if (FRAME_WINDOW_P (f
))
6393 set_frame_menubar (f
, 0, 0);
6395 /* On a terminal screen, the menu bar is an ordinary screen
6396 line, and this makes it get updated. */
6397 w
->update_mode_line
= Qt
;
6398 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6399 /* In the non-toolkit version, the menu bar is an ordinary screen
6400 line, and this makes it get updated. */
6401 w
->update_mode_line
= Qt
;
6402 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6404 unbind_to (count
, Qnil
);
6405 set_buffer_internal_1 (prev
);
6412 /***********************************************************************
6414 ***********************************************************************/
6416 #ifdef HAVE_WINDOW_SYSTEM
6418 /* Update the tool-bar item list for frame F. This has to be done
6419 before we start to fill in any display lines. Called from
6420 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
6421 and restore it here. */
6424 update_tool_bar (f
, save_match_data
)
6426 int save_match_data
;
6428 if (WINDOWP (f
->tool_bar_window
)
6429 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
6434 window
= FRAME_SELECTED_WINDOW (f
);
6435 w
= XWINDOW (window
);
6437 /* If the user has switched buffers or windows, we need to
6438 recompute to reflect the new bindings. But we'll
6439 recompute when update_mode_lines is set too; that means
6440 that people can use force-mode-line-update to request
6441 that the menu bar be recomputed. The adverse effect on
6442 the rest of the redisplay algorithm is about the same as
6443 windows_or_buffers_changed anyway. */
6444 if (windows_or_buffers_changed
6445 || !NILP (w
->update_mode_line
)
6446 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6447 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6448 != !NILP (w
->last_had_star
))
6449 || ((!NILP (Vtransient_mark_mode
)
6450 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6451 != !NILP (w
->region_showing
)))
6453 struct buffer
*prev
= current_buffer
;
6454 int count
= specpdl_ptr
- specpdl
;
6456 /* Set current_buffer to the buffer of the selected
6457 window of the frame, so that we get the right local
6459 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6461 /* Save match data, if we must. */
6462 if (save_match_data
)
6463 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6465 /* Make sure that we don't accidentally use bogus keymaps. */
6466 if (NILP (Voverriding_local_map_menu_flag
))
6468 specbind (Qoverriding_terminal_local_map
, Qnil
);
6469 specbind (Qoverriding_local_map
, Qnil
);
6472 /* Build desired tool-bar items from keymaps. */
6473 f
->desired_tool_bar_items
6474 = tool_bar_items (f
->desired_tool_bar_items
,
6475 &f
->n_desired_tool_bar_items
);
6477 /* Redisplay the tool-bar in case we changed it. */
6478 w
->update_mode_line
= Qt
;
6480 unbind_to (count
, Qnil
);
6481 set_buffer_internal_1 (prev
);
6487 /* Set F->desired_tool_bar_string to a Lisp string representing frame
6488 F's desired tool-bar contents. F->desired_tool_bar_items must have
6489 been set up previously by calling prepare_menu_bars. */
6492 build_desired_tool_bar_string (f
)
6495 int i
, size
, size_needed
, string_idx
;
6496 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6497 Lisp_Object image
, plist
, props
;
6499 image
= plist
= props
= Qnil
;
6500 GCPRO3 (image
, plist
, props
);
6502 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
6503 Otherwise, make a new string. */
6505 /* The size of the string we might be able to reuse. */
6506 size
= (STRINGP (f
->desired_tool_bar_string
)
6507 ? XSTRING (f
->desired_tool_bar_string
)->size
6510 /* Each image in the string we build is preceded by a space,
6511 and there is a space at the end. */
6512 size_needed
= f
->n_desired_tool_bar_items
+ 1;
6514 /* Reuse f->desired_tool_bar_string, if possible. */
6515 if (size
< size_needed
)
6516 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
6520 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
6521 Fremove_text_properties (make_number (0), make_number (size
),
6522 props
, f
->desired_tool_bar_string
);
6525 /* Put a `display' property on the string for the images to display,
6526 put a `menu_item' property on tool-bar items with a value that
6527 is the index of the item in F's tool-bar item vector. */
6528 for (i
= 0, string_idx
= 0;
6529 i
< f
->n_desired_tool_bar_items
;
6530 ++i
, string_idx
+= 1)
6533 (XVECTOR (f->desired_tool_bar_items) \
6534 ->contents[i * TOOL_BAR_ITEM_NSLOTS + (IDX)])
6536 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
6537 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
6539 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
6540 extern Lisp_Object Qlaplace
;
6542 /* If image is a vector, choose the image according to the
6544 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
6545 if (VECTORP (image
))
6547 enum tool_bar_item_image idx
;
6551 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
6552 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
6555 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
6556 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
6558 xassert (XVECTOR (image
)->size
>= idx
);
6559 image
= XVECTOR (image
)->contents
[idx
];
6562 /* Ignore invalid image specifications. */
6563 if (!valid_image_p (image
))
6566 /* Display the tool-bar button pressed, or depressed. */
6567 plist
= Fcopy_sequence (XCDR (image
));
6569 /* Compute margin and relief to draw. */
6570 relief
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
6571 margin
= relief
+ max (0, tool_bar_button_margin
);
6573 if (auto_raise_tool_bar_buttons_p
)
6575 /* Add a `:relief' property to the image spec if the item is
6579 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
6585 /* If image is selected, display it pressed, i.e. with a
6586 negative relief. If it's not selected, display it with a
6588 plist
= Fplist_put (plist
, QCrelief
,
6590 ? make_number (-relief
)
6591 : make_number (relief
)));
6595 /* Put a margin around the image. */
6597 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
6599 /* If button is not enabled, make the image appear disabled by
6600 applying an appropriate algorithm to it. */
6602 plist
= Fplist_put (plist
, QCalgorithm
, Qlaplace
);
6604 /* Put a `display' text property on the string for the image to
6605 display. Put a `menu-item' property on the string that gives
6606 the start of this item's properties in the tool-bar items
6608 image
= Fcons (Qimage
, plist
);
6609 props
= list4 (Qdisplay
, image
,
6610 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
)),
6611 Fadd_text_properties (make_number (string_idx
),
6612 make_number (string_idx
+ 1),
6613 props
, f
->desired_tool_bar_string
);
6621 /* Display one line of the tool-bar of frame IT->f. */
6624 display_tool_bar_line (it
)
6627 struct glyph_row
*row
= it
->glyph_row
;
6628 int max_x
= it
->last_visible_x
;
6631 prepare_desired_row (row
);
6632 row
->y
= it
->current_y
;
6634 while (it
->current_x
< max_x
)
6636 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
6638 /* Get the next display element. */
6639 if (!get_next_display_element (it
))
6642 /* Produce glyphs. */
6643 x_before
= it
->current_x
;
6644 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
6645 PRODUCE_GLYPHS (it
);
6647 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
6652 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
6654 if (x
+ glyph
->pixel_width
> max_x
)
6656 /* Glyph doesn't fit on line. */
6657 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
6663 x
+= glyph
->pixel_width
;
6667 /* Stop at line ends. */
6668 if (ITERATOR_AT_END_OF_LINE_P (it
))
6671 set_iterator_to_next (it
);
6676 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
6677 extend_face_to_end_of_line (it
);
6678 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
6679 last
->right_box_line_p
= 1;
6680 compute_line_metrics (it
);
6682 /* If line is empty, make it occupy the rest of the tool-bar. */
6683 if (!row
->displays_text_p
)
6685 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
6686 row
->ascent
= row
->phys_ascent
= 0;
6689 row
->full_width_p
= 1;
6690 row
->continued_p
= 0;
6691 row
->truncated_on_left_p
= 0;
6692 row
->truncated_on_right_p
= 0;
6694 it
->current_x
= it
->hpos
= 0;
6695 it
->current_y
+= row
->height
;
6701 /* Value is the number of screen lines needed to make all tool-bar
6702 items of frame F visible. */
6705 tool_bar_lines_needed (f
)
6708 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6711 /* Initialize an iterator for iteration over
6712 F->desired_tool_bar_string in the tool-bar window of frame F. */
6713 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
6714 it
.first_visible_x
= 0;
6715 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6716 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
6718 while (!ITERATOR_AT_END_P (&it
))
6720 it
.glyph_row
= w
->desired_matrix
->rows
;
6721 clear_glyph_row (it
.glyph_row
);
6722 display_tool_bar_line (&it
);
6725 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
6729 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
6730 height should be changed. */
6733 redisplay_tool_bar (f
)
6738 struct glyph_row
*row
;
6739 int change_height_p
= 0;
6741 /* If frame hasn't a tool-bar window or if it is zero-height, don't
6742 do anything. This means you must start with tool-bar-lines
6743 non-zero to get the auto-sizing effect. Or in other words, you
6744 can turn off tool-bars by specifying tool-bar-lines zero. */
6745 if (!WINDOWP (f
->tool_bar_window
)
6746 || (w
= XWINDOW (f
->tool_bar_window
),
6747 XFASTINT (w
->height
) == 0))
6750 /* Set up an iterator for the tool-bar window. */
6751 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
6752 it
.first_visible_x
= 0;
6753 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6756 /* Build a string that represents the contents of the tool-bar. */
6757 build_desired_tool_bar_string (f
);
6758 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
6760 /* Display as many lines as needed to display all tool-bar items. */
6761 while (it
.current_y
< it
.last_visible_y
)
6762 display_tool_bar_line (&it
);
6764 /* It doesn't make much sense to try scrolling in the tool-bar
6765 window, so don't do it. */
6766 w
->desired_matrix
->no_scrolling_p
= 1;
6767 w
->must_be_updated_p
= 1;
6769 if (auto_resize_tool_bars_p
)
6773 /* If there are blank lines at the end, except for a partially
6774 visible blank line at the end that is smaller than
6775 CANON_Y_UNIT, change the tool-bar's height. */
6776 row
= it
.glyph_row
- 1;
6777 if (!row
->displays_text_p
6778 && row
->height
>= CANON_Y_UNIT (f
))
6779 change_height_p
= 1;
6781 /* If row displays tool-bar items, but is partially visible,
6782 change the tool-bar's height. */
6783 if (row
->displays_text_p
6784 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
6785 change_height_p
= 1;
6787 /* Resize windows as needed by changing the `tool-bar-lines'
6790 && (nlines
= tool_bar_lines_needed (f
),
6791 nlines
!= XFASTINT (w
->height
)))
6793 extern Lisp_Object Qtool_bar_lines
;
6796 XSETFRAME (frame
, f
);
6797 clear_glyph_matrix (w
->desired_matrix
);
6798 Fmodify_frame_parameters (frame
,
6799 Fcons (Fcons (Qtool_bar_lines
,
6800 make_number (nlines
)),
6802 fonts_changed_p
= 1;
6806 return change_height_p
;
6810 /* Get information about the tool-bar item which is displayed in GLYPH
6811 on frame F. Return in *PROP_IDX the index where tool-bar item
6812 properties start in F->current_tool_bar_items. Value is zero if
6813 GLYPH doesn't display a tool-bar item. */
6816 tool_bar_item_info (f
, glyph
, prop_idx
)
6818 struct glyph
*glyph
;
6824 /* Get the text property `menu-item' at pos. The value of that
6825 property is the start index of this item's properties in
6826 F->current_tool_bar_items. */
6827 prop
= Fget_text_property (make_number (glyph
->charpos
),
6828 Qmenu_item
, f
->current_tool_bar_string
);
6829 if (INTEGERP (prop
))
6831 *prop_idx
= XINT (prop
);
6840 #endif /* HAVE_WINDOW_SYSTEM */
6844 /************************************************************************
6845 Horizontal scrolling
6846 ************************************************************************/
6848 static int hscroll_window_tree
P_ ((Lisp_Object
));
6849 static int hscroll_windows
P_ ((Lisp_Object
));
6851 /* For all leaf windows in the window tree rooted at WINDOW, set their
6852 hscroll value so that PT is (i) visible in the window, and (ii) so
6853 that it is not within a certain margin at the window's left and
6854 right border. Value is non-zero if any window's hscroll has been
6858 hscroll_window_tree (window
)
6861 int hscrolled_p
= 0;
6863 while (WINDOWP (window
))
6865 struct window
*w
= XWINDOW (window
);
6867 if (WINDOWP (w
->hchild
))
6868 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
6869 else if (WINDOWP (w
->vchild
))
6870 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
6871 else if (w
->cursor
.vpos
>= 0)
6873 int hscroll_margin
, text_area_x
, text_area_y
;
6874 int text_area_width
, text_area_height
;
6875 struct glyph_row
*current_cursor_row
6876 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
6877 struct glyph_row
*desired_cursor_row
6878 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
6879 struct glyph_row
*cursor_row
6880 = (desired_cursor_row
->enabled_p
6881 ? desired_cursor_row
6882 : current_cursor_row
);
6884 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
6885 &text_area_width
, &text_area_height
);
6887 /* Scroll when cursor is inside this scroll margin. */
6888 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
6890 if ((XFASTINT (w
->hscroll
)
6891 && w
->cursor
.x
< hscroll_margin
)
6892 || (cursor_row
->enabled_p
6893 && cursor_row
->truncated_on_right_p
6894 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
6898 struct buffer
*saved_current_buffer
;
6901 /* Find point in a display of infinite width. */
6902 saved_current_buffer
= current_buffer
;
6903 current_buffer
= XBUFFER (w
->buffer
);
6905 if (w
== XWINDOW (selected_window
))
6906 pt
= BUF_PT (current_buffer
);
6909 pt
= marker_position (w
->pointm
);
6910 pt
= max (BEGV
, pt
);
6914 /* Move iterator to pt starting at cursor_row->start in
6915 a line with infinite width. */
6916 init_to_row_start (&it
, w
, cursor_row
);
6917 it
.last_visible_x
= INFINITY
;
6918 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
6919 current_buffer
= saved_current_buffer
;
6921 /* Center cursor in window. */
6922 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
6923 / CANON_X_UNIT (it
.f
));
6925 /* Don't call Fset_window_hscroll if value hasn't
6926 changed because it will prevent redisplay
6928 if (XFASTINT (w
->hscroll
) != hscroll
)
6930 Fset_window_hscroll (window
, make_number (hscroll
));
6939 /* Value is non-zero if hscroll of any leaf window has been changed. */
6944 /* Set hscroll so that cursor is visible and not inside horizontal
6945 scroll margins for all windows in the tree rooted at WINDOW. See
6946 also hscroll_window_tree above. Value is non-zero if any window's
6947 hscroll has been changed. If it has, desired matrices on the frame
6948 of WINDOW are cleared. */
6951 hscroll_windows (window
)
6956 if (automatic_hscrolling_p
)
6958 hscrolled_p
= hscroll_window_tree (window
);
6960 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
6969 /************************************************************************
6971 ************************************************************************/
6973 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
6974 to a non-zero value. This is sometimes handy to have in a debugger
6979 /* First and last unchanged row for try_window_id. */
6981 int debug_first_unchanged_at_end_vpos
;
6982 int debug_last_unchanged_at_beg_vpos
;
6984 /* Delta vpos and y. */
6986 int debug_dvpos
, debug_dy
;
6988 /* Delta in characters and bytes for try_window_id. */
6990 int debug_delta
, debug_delta_bytes
;
6992 /* Values of window_end_pos and window_end_vpos at the end of
6995 int debug_end_pos
, debug_end_vpos
;
6997 /* Append a string to W->desired_matrix->method. FMT is a printf
6998 format string. A1...A9 are a supplement for a variable-length
6999 argument list. If trace_redisplay_p is non-zero also printf the
7000 resulting string to stderr. */
7003 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
7006 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
7009 char *method
= w
->desired_matrix
->method
;
7010 int len
= strlen (method
);
7011 int size
= sizeof w
->desired_matrix
->method
;
7012 int remaining
= size
- len
- 1;
7014 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
7015 if (len
&& remaining
)
7021 strncpy (method
+ len
, buffer
, remaining
);
7023 if (trace_redisplay_p
)
7024 fprintf (stderr
, "%p (%s): %s\n",
7026 ((BUFFERP (w
->buffer
)
7027 && STRINGP (XBUFFER (w
->buffer
)->name
))
7028 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
7033 #endif /* GLYPH_DEBUG */
7036 /* This counter is used to clear the face cache every once in a while
7037 in redisplay_internal. It is incremented for each redisplay.
7038 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
7041 #define CLEAR_FACE_CACHE_COUNT 10000
7042 static int clear_face_cache_count
;
7044 /* Record the previous terminal frame we displayed. */
7046 static struct frame
*previous_terminal_frame
;
7048 /* Non-zero while redisplay_internal is in progress. */
7053 /* Value is non-zero if all changes in window W, which displays
7054 current_buffer, are in the text between START and END. START is a
7055 buffer position, END is given as a distance from Z. Used in
7056 redisplay_internal for display optimization. */
7059 text_outside_line_unchanged_p (w
, start
, end
)
7063 int unchanged_p
= 1;
7065 /* If text or overlays have changed, see where. */
7066 if (XFASTINT (w
->last_modified
) < MODIFF
7067 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7069 /* Gap in the line? */
7070 if (GPT
< start
|| Z
- GPT
< end
)
7073 /* Changes start in front of the line, or end after it? */
7075 && (BEG_UNCHANGED
< start
- 1
7076 || END_UNCHANGED
< end
))
7079 /* If selective display, can't optimize if changes start at the
7080 beginning of the line. */
7082 && INTEGERP (current_buffer
->selective_display
)
7083 && XINT (current_buffer
->selective_display
) > 0
7084 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
7092 /* Do a frame update, taking possible shortcuts into account. This is
7093 the main external entry point for redisplay.
7095 If the last redisplay displayed an echo area message and that message
7096 is no longer requested, we clear the echo area or bring back the
7097 mini-buffer if that is in use. */
7102 redisplay_internal (0);
7105 /* Return 1 if point moved out of or into a composition. Otherwise
7106 return 0. PREV_BUF and PREV_PT are the last point buffer and
7107 position. BUF and PT are the current point buffer and position. */
7110 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
7111 struct buffer
*prev_buf
, *buf
;
7118 XSETBUFFER (buffer
, buf
);
7119 /* Check a composition at the last point if point moved within the
7121 if (prev_buf
== buf
)
7124 /* Point didn't move. */
7127 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
7128 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
7129 && COMPOSITION_VALID_P (start
, end
, prop
)
7130 && start
< prev_pt
&& end
> prev_pt
)
7131 /* The last point was within the composition. Return 1 iff
7132 point moved out of the composition. */
7133 return (pt
<= start
|| pt
>= end
);
7136 /* Check a composition at the current point. */
7137 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
7138 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
7139 && COMPOSITION_VALID_P (start
, end
, prop
)
7140 && start
< pt
&& end
> pt
);
7143 /* Reconsider the setting of B->clip_changed which is displayed
7147 reconsider_clip_changes (w
, b
)
7151 if (b
->prevent_redisplay_optimizations_p
)
7152 b
->clip_changed
= 1;
7153 else if (b
->clip_changed
7154 && !NILP (w
->window_end_valid
)
7155 && w
->current_matrix
->buffer
== b
7156 && w
->current_matrix
->zv
== BUF_ZV (b
)
7157 && w
->current_matrix
->begv
== BUF_BEGV (b
))
7158 b
->clip_changed
= 0;
7160 /* If display wasn't paused, and W is not a tool bar window, see if
7161 point has been moved into or out of a composition. In that case,
7162 we set b->clip_changed to 1 to force updating the screen. If
7163 b->clip_changed has already been set to 1, we can skip this
7165 if (!b
->clip_changed
7166 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
7170 if (w
== XWINDOW (selected_window
))
7171 pt
= BUF_PT (current_buffer
);
7173 pt
= marker_position (w
->pointm
);
7175 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
7176 || pt
!= XINT (w
->last_point
))
7177 && check_point_in_composition (w
->current_matrix
->buffer
,
7178 XINT (w
->last_point
),
7179 XBUFFER (w
->buffer
), pt
))
7180 b
->clip_changed
= 1;
7185 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
7186 response to any user action; therefore, we should preserve the echo
7187 area. (Actually, our caller does that job.) Perhaps in the future
7188 avoid recentering windows if it is not necessary; currently that
7189 causes some problems. */
7192 redisplay_internal (preserve_echo_area
)
7193 int preserve_echo_area
;
7195 struct window
*w
= XWINDOW (selected_window
);
7196 struct frame
*f
= XFRAME (w
->frame
);
7198 int must_finish
= 0;
7199 struct text_pos tlbufpos
, tlendpos
;
7200 int number_of_visible_frames
;
7202 struct frame
*sf
= SELECTED_FRAME ();
7204 /* Non-zero means redisplay has to consider all windows on all
7205 frames. Zero means, only selected_window is considered. */
7206 int consider_all_windows_p
;
7208 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
7210 /* No redisplay if running in batch mode or frame is not yet fully
7211 initialized, or redisplay is explicitly turned off by setting
7212 Vinhibit_redisplay. */
7214 || !NILP (Vinhibit_redisplay
)
7215 || !f
->glyphs_initialized_p
)
7218 /* The flag redisplay_performed_directly_p is set by
7219 direct_output_for_insert when it already did the whole screen
7220 update necessary. */
7221 if (redisplay_performed_directly_p
)
7223 redisplay_performed_directly_p
= 0;
7224 if (!hscroll_windows (selected_window
))
7228 #ifdef USE_X_TOOLKIT
7229 if (popup_activated ())
7233 /* I don't think this happens but let's be paranoid. */
7237 /* Record a function that resets redisplaying_p to its old value
7238 when we leave this function. */
7239 count
= specpdl_ptr
- specpdl
;
7240 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
7245 reconsider_clip_changes (w
, current_buffer
);
7247 /* If new fonts have been loaded that make a glyph matrix adjustment
7248 necessary, do it. */
7249 if (fonts_changed_p
)
7251 adjust_glyphs (NULL
);
7252 ++windows_or_buffers_changed
;
7253 fonts_changed_p
= 0;
7256 if (! FRAME_WINDOW_P (sf
)
7257 && previous_terminal_frame
!= sf
)
7259 /* Since frames on an ASCII terminal share the same display
7260 area, displaying a different frame means redisplay the whole
7262 windows_or_buffers_changed
++;
7263 SET_FRAME_GARBAGED (sf
);
7264 XSETFRAME (Vterminal_frame
, sf
);
7266 previous_terminal_frame
= sf
;
7268 /* Set the visible flags for all frames. Do this before checking
7269 for resized or garbaged frames; they want to know if their frames
7270 are visible. See the comment in frame.h for
7271 FRAME_SAMPLE_VISIBILITY. */
7273 Lisp_Object tail
, frame
;
7275 number_of_visible_frames
= 0;
7277 FOR_EACH_FRAME (tail
, frame
)
7279 struct frame
*f
= XFRAME (frame
);
7281 FRAME_SAMPLE_VISIBILITY (f
);
7282 if (FRAME_VISIBLE_P (f
))
7283 ++number_of_visible_frames
;
7284 clear_desired_matrices (f
);
7288 /* Notice any pending interrupt request to change frame size. */
7289 do_pending_window_change (1);
7291 /* Clear frames marked as garbaged. */
7293 clear_garbaged_frames ();
7295 /* Build menubar and tool-bar items. */
7296 prepare_menu_bars ();
7298 if (windows_or_buffers_changed
)
7299 update_mode_lines
++;
7301 /* Detect case that we need to write or remove a star in the mode line. */
7302 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
7304 w
->update_mode_line
= Qt
;
7305 if (buffer_shared
> 1)
7306 update_mode_lines
++;
7309 /* If %c is in the mode line, update it if needed. */
7310 if (!NILP (w
->column_number_displayed
)
7311 /* This alternative quickly identifies a common case
7312 where no change is needed. */
7313 && !(PT
== XFASTINT (w
->last_point
)
7314 && XFASTINT (w
->last_modified
) >= MODIFF
7315 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7316 && XFASTINT (w
->column_number_displayed
) != current_column ())
7317 w
->update_mode_line
= Qt
;
7319 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
7321 /* The variable buffer_shared is set in redisplay_window and
7322 indicates that we redisplay a buffer in different windows. See
7324 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
7326 /* If specs for an arrow have changed, do thorough redisplay
7327 to ensure we remove any arrow that should no longer exist. */
7328 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
7329 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
7330 consider_all_windows_p
= windows_or_buffers_changed
= 1;
7332 /* Normally the message* functions will have already displayed and
7333 updated the echo area, but the frame may have been trashed, or
7334 the update may have been preempted, so display the echo area
7335 again here. Checking both message buffers captures the case that
7336 the echo area should be cleared. */
7337 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
7339 int window_height_changed_p
= echo_area_display (0);
7342 if (fonts_changed_p
)
7344 else if (window_height_changed_p
)
7346 consider_all_windows_p
= 1;
7347 ++update_mode_lines
;
7348 ++windows_or_buffers_changed
;
7350 /* If window configuration was changed, frames may have been
7351 marked garbaged. Clear them or we will experience
7352 surprises wrt scrolling. */
7354 clear_garbaged_frames ();
7357 else if (w
== XWINDOW (minibuf_window
)
7358 && (current_buffer
->clip_changed
7359 || XFASTINT (w
->last_modified
) < MODIFF
7360 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7361 && resize_mini_window (w
, 0))
7363 /* Resized active mini-window to fit the size of what it is
7364 showing if its contents might have changed. */
7366 consider_all_windows_p
= 1;
7367 ++windows_or_buffers_changed
;
7368 ++update_mode_lines
;
7370 /* If window configuration was changed, frames may have been
7371 marked garbaged. Clear them or we will experience
7372 surprises wrt scrolling. */
7374 clear_garbaged_frames ();
7378 /* If showing the region, and mark has changed, we must redisplay
7379 the whole window. The assignment to this_line_start_pos prevents
7380 the optimization directly below this if-statement. */
7381 if (((!NILP (Vtransient_mark_mode
)
7382 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7383 != !NILP (w
->region_showing
))
7384 || (!NILP (w
->region_showing
)
7385 && !EQ (w
->region_showing
,
7386 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
7387 CHARPOS (this_line_start_pos
) = 0;
7389 /* Optimize the case that only the line containing the cursor in the
7390 selected window has changed. Variables starting with this_ are
7391 set in display_line and record information about the line
7392 containing the cursor. */
7393 tlbufpos
= this_line_start_pos
;
7394 tlendpos
= this_line_end_pos
;
7395 if (!consider_all_windows_p
7396 && CHARPOS (tlbufpos
) > 0
7397 && NILP (w
->update_mode_line
)
7398 && !current_buffer
->clip_changed
7399 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
7400 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
7401 /* Make sure recorded data applies to current buffer, etc. */
7402 && this_line_buffer
== current_buffer
7403 && current_buffer
== XBUFFER (w
->buffer
)
7404 && NILP (w
->force_start
)
7405 /* Point must be on the line that we have info recorded about. */
7406 && PT
>= CHARPOS (tlbufpos
)
7407 && PT
<= Z
- CHARPOS (tlendpos
)
7408 /* All text outside that line, including its final newline,
7409 must be unchanged */
7410 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
7411 CHARPOS (tlendpos
)))
7413 if (CHARPOS (tlbufpos
) > BEGV
7414 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
7415 && (CHARPOS (tlbufpos
) == ZV
7416 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
7417 /* Former continuation line has disappeared by becoming empty */
7419 else if (XFASTINT (w
->last_modified
) < MODIFF
7420 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
7421 || MINI_WINDOW_P (w
))
7423 /* We have to handle the case of continuation around a
7424 wide-column character (See the comment in indent.c around
7427 For instance, in the following case:
7429 -------- Insert --------
7430 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
7431 J_I_ ==> J_I_ `^^' are cursors.
7435 As we have to redraw the line above, we should goto cancel. */
7438 int line_height_before
= this_line_pixel_height
;
7440 /* Note that start_display will handle the case that the
7441 line starting at tlbufpos is a continuation lines. */
7442 start_display (&it
, w
, tlbufpos
);
7444 /* Implementation note: It this still necessary? */
7445 if (it
.current_x
!= this_line_start_x
)
7448 TRACE ((stderr
, "trying display optimization 1\n"));
7449 w
->cursor
.vpos
= -1;
7450 overlay_arrow_seen
= 0;
7451 it
.vpos
= this_line_vpos
;
7452 it
.current_y
= this_line_y
;
7453 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
7456 /* If line contains point, is not continued,
7457 and ends at same distance from eob as before, we win */
7458 if (w
->cursor
.vpos
>= 0
7459 /* Line is not continued, otherwise this_line_start_pos
7460 would have been set to 0 in display_line. */
7461 && CHARPOS (this_line_start_pos
)
7462 /* Line ends as before. */
7463 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
7464 /* Line has same height as before. Otherwise other lines
7465 would have to be shifted up or down. */
7466 && this_line_pixel_height
== line_height_before
)
7468 /* If this is not the window's last line, we must adjust
7469 the charstarts of the lines below. */
7470 if (it
.current_y
< it
.last_visible_y
)
7472 struct glyph_row
*row
7473 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
7474 int delta
, delta_bytes
;
7476 if (Z
- CHARPOS (tlendpos
) == ZV
)
7478 /* This line ends at end of (accessible part of)
7479 buffer. There is no newline to count. */
7481 - CHARPOS (tlendpos
)
7482 - MATRIX_ROW_START_CHARPOS (row
));
7483 delta_bytes
= (Z_BYTE
7484 - BYTEPOS (tlendpos
)
7485 - MATRIX_ROW_START_BYTEPOS (row
));
7489 /* This line ends in a newline. Must take
7490 account of the newline and the rest of the
7491 text that follows. */
7493 - CHARPOS (tlendpos
)
7494 - MATRIX_ROW_START_CHARPOS (row
));
7495 delta_bytes
= (Z_BYTE
7496 - BYTEPOS (tlendpos
)
7497 - MATRIX_ROW_START_BYTEPOS (row
));
7500 increment_matrix_positions (w
->current_matrix
,
7502 w
->current_matrix
->nrows
,
7503 delta
, delta_bytes
);
7506 /* If this row displays text now but previously didn't,
7507 or vice versa, w->window_end_vpos may have to be
7509 if ((it
.glyph_row
- 1)->displays_text_p
)
7511 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
7512 XSETINT (w
->window_end_vpos
, this_line_vpos
);
7514 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
7515 && this_line_vpos
> 0)
7516 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
7517 w
->window_end_valid
= Qnil
;
7519 /* Update hint: No need to try to scroll in update_window. */
7520 w
->desired_matrix
->no_scrolling_p
= 1;
7523 *w
->desired_matrix
->method
= 0;
7524 debug_method_add (w
, "optimization 1");
7531 else if (/* Cursor position hasn't changed. */
7532 PT
== XFASTINT (w
->last_point
)
7533 /* Make sure the cursor was last displayed
7534 in this window. Otherwise we have to reposition it. */
7535 && 0 <= w
->cursor
.vpos
7536 && XINT (w
->height
) > w
->cursor
.vpos
)
7540 do_pending_window_change (1);
7542 /* We used to always goto end_of_redisplay here, but this
7543 isn't enough if we have a blinking cursor. */
7544 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
7545 goto end_of_redisplay
;
7549 /* If highlighting the region, or if the cursor is in the echo area,
7550 then we can't just move the cursor. */
7551 else if (! (!NILP (Vtransient_mark_mode
)
7552 && !NILP (current_buffer
->mark_active
))
7553 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7554 || highlight_nonselected_windows
)
7555 && NILP (w
->region_showing
)
7556 && NILP (Vshow_trailing_whitespace
)
7557 && !cursor_in_echo_area
)
7560 struct glyph_row
*row
;
7562 /* Skip from tlbufpos to PT and see where it is. Note that
7563 PT may be in invisible text. If so, we will end at the
7564 next visible position. */
7565 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
7566 NULL
, DEFAULT_FACE_ID
);
7567 it
.current_x
= this_line_start_x
;
7568 it
.current_y
= this_line_y
;
7569 it
.vpos
= this_line_vpos
;
7571 /* The call to move_it_to stops in front of PT, but
7572 moves over before-strings. */
7573 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
7575 if (it
.vpos
== this_line_vpos
7576 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
7579 xassert (this_line_vpos
== it
.vpos
);
7580 xassert (this_line_y
== it
.current_y
);
7581 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
7589 /* Text changed drastically or point moved off of line. */
7590 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
7593 CHARPOS (this_line_start_pos
) = 0;
7594 consider_all_windows_p
|= buffer_shared
> 1;
7595 ++clear_face_cache_count
;
7598 /* Build desired matrices. If consider_all_windows_p is non-zero,
7599 do it for all windows on all frames. Otherwise do it for
7600 selected_window, only. */
7602 if (consider_all_windows_p
)
7604 Lisp_Object tail
, frame
;
7606 /* Clear the face cache eventually. */
7607 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
7609 clear_face_cache (0);
7610 clear_face_cache_count
= 0;
7613 /* Recompute # windows showing selected buffer. This will be
7614 incremented each time such a window is displayed. */
7617 FOR_EACH_FRAME (tail
, frame
)
7619 struct frame
*f
= XFRAME (frame
);
7620 if (FRAME_WINDOW_P (f
) || f
== sf
)
7622 /* Mark all the scroll bars to be removed; we'll redeem
7623 the ones we want when we redisplay their windows. */
7624 if (condemn_scroll_bars_hook
)
7625 (*condemn_scroll_bars_hook
) (f
);
7627 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7628 redisplay_windows (FRAME_ROOT_WINDOW (f
));
7630 /* Any scroll bars which redisplay_windows should have
7631 nuked should now go away. */
7632 if (judge_scroll_bars_hook
)
7633 (*judge_scroll_bars_hook
) (f
);
7637 else if (FRAME_VISIBLE_P (sf
)
7638 && !FRAME_OBSCURED_P (sf
))
7639 redisplay_window (selected_window
, 1);
7642 /* Compare desired and current matrices, perform output. */
7646 /* If fonts changed, display again. */
7647 if (fonts_changed_p
)
7650 /* Prevent various kinds of signals during display update.
7651 stdio is not robust about handling signals,
7652 which can cause an apparent I/O error. */
7653 if (interrupt_input
)
7657 if (consider_all_windows_p
)
7666 /* See if we have to hscroll. */
7667 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7668 if (FRAMEP (XCAR (tail
)))
7670 f
= XFRAME (XCAR (tail
));
7672 if ((FRAME_WINDOW_P (f
)
7674 && FRAME_VISIBLE_P (f
)
7675 && !FRAME_OBSCURED_P (f
)
7676 && hscroll_windows (f
->root_window
))
7683 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7685 if (!FRAMEP (XCAR (tail
)))
7688 f
= XFRAME (XCAR (tail
));
7690 if ((FRAME_WINDOW_P (f
) || f
== sf
)
7691 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7693 /* Mark all windows as to be updated. */
7694 set_window_update_flags (XWINDOW (f
->root_window
), 1);
7695 pause
|= update_frame (f
, 0, 0);
7698 mark_window_display_accurate (f
->root_window
, 1);
7699 if (frame_up_to_date_hook
!= 0)
7700 (*frame_up_to_date_hook
) (f
);
7707 if (FRAME_VISIBLE_P (sf
)
7708 && !FRAME_OBSCURED_P (sf
))
7710 if (hscroll_windows (selected_window
))
7713 XWINDOW (selected_window
)->must_be_updated_p
= 1;
7714 pause
= update_frame (sf
, 0, 0);
7719 /* We may have called echo_area_display at the top of this
7720 function. If the echo area is on another frame, that may
7721 have put text on a frame other than the selected one, so the
7722 above call to update_frame would not have caught it. Catch
7725 Lisp_Object mini_window
;
7726 struct frame
*mini_frame
;
7728 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7729 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7731 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
7733 XWINDOW (mini_window
)->must_be_updated_p
= 1;
7734 pause
|= update_frame (mini_frame
, 0, 0);
7735 if (!pause
&& hscroll_windows (mini_window
))
7741 /* If display was paused because of pending input, make sure we do a
7742 thorough update the next time. */
7745 /* Prevent the optimization at the beginning of
7746 redisplay_internal that tries a single-line update of the
7747 line containing the cursor in the selected window. */
7748 CHARPOS (this_line_start_pos
) = 0;
7750 /* Let the overlay arrow be updated the next time. */
7751 if (!NILP (last_arrow_position
))
7753 last_arrow_position
= Qt
;
7754 last_arrow_string
= Qt
;
7757 /* If we pause after scrolling, some rows in the current
7758 matrices of some windows are not valid. */
7759 if (!WINDOW_FULL_WIDTH_P (w
)
7760 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
7761 update_mode_lines
= 1;
7764 /* Now text on frame agrees with windows, so put info into the
7765 windows for partial redisplay to follow. */
7768 register struct buffer
*b
= XBUFFER (w
->buffer
);
7770 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
7771 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
7772 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
7773 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
7775 if (consider_all_windows_p
)
7776 mark_window_display_accurate (FRAME_ROOT_WINDOW (sf
), 1);
7779 XSETFASTINT (w
->last_point
, BUF_PT (b
));
7780 w
->last_cursor
= w
->cursor
;
7781 w
->last_cursor_off_p
= w
->cursor_off_p
;
7783 b
->clip_changed
= 0;
7784 b
->prevent_redisplay_optimizations_p
= 0;
7785 w
->update_mode_line
= Qnil
;
7786 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
7787 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
7789 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7792 /* Record if we are showing a region, so can make sure to
7793 update it fully at next redisplay. */
7794 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
7795 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7796 || highlight_nonselected_windows
)
7797 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
7798 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
7801 w
->window_end_valid
= w
->buffer
;
7802 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7803 last_arrow_string
= Voverlay_arrow_string
;
7804 if (frame_up_to_date_hook
!= 0)
7805 (*frame_up_to_date_hook
) (sf
);
7807 w
->current_matrix
->buffer
= b
;
7808 w
->current_matrix
->begv
= BUF_BEGV (b
);
7809 w
->current_matrix
->zv
= BUF_ZV (b
);
7812 update_mode_lines
= 0;
7813 windows_or_buffers_changed
= 0;
7816 /* Start SIGIO interrupts coming again. Having them off during the
7817 code above makes it less likely one will discard output, but not
7818 impossible, since there might be stuff in the system buffer here.
7819 But it is much hairier to try to do anything about that. */
7820 if (interrupt_input
)
7824 /* If a frame has become visible which was not before, redisplay
7825 again, so that we display it. Expose events for such a frame
7826 (which it gets when becoming visible) don't call the parts of
7827 redisplay constructing glyphs, so simply exposing a frame won't
7828 display anything in this case. So, we have to display these
7829 frames here explicitly. */
7832 Lisp_Object tail
, frame
;
7835 FOR_EACH_FRAME (tail
, frame
)
7837 int this_is_visible
= 0;
7839 if (XFRAME (frame
)->visible
)
7840 this_is_visible
= 1;
7841 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
7842 if (XFRAME (frame
)->visible
)
7843 this_is_visible
= 1;
7845 if (this_is_visible
)
7849 if (new_count
!= number_of_visible_frames
)
7850 windows_or_buffers_changed
++;
7853 /* Change frame size now if a change is pending. */
7854 do_pending_window_change (1);
7856 /* If we just did a pending size change, or have additional
7857 visible frames, redisplay again. */
7858 if (windows_or_buffers_changed
&& !pause
)
7863 unbind_to (count
, Qnil
);
7867 /* Redisplay, but leave alone any recent echo area message unless
7868 another message has been requested in its place.
7870 This is useful in situations where you need to redisplay but no
7871 user action has occurred, making it inappropriate for the message
7872 area to be cleared. See tracking_off and
7873 wait_reading_process_input for examples of these situations. */
7876 redisplay_preserve_echo_area ()
7878 if (!NILP (echo_area_buffer
[1]))
7880 /* We have a previously displayed message, but no current
7881 message. Redisplay the previous message. */
7882 display_last_displayed_message_p
= 1;
7883 redisplay_internal (1);
7884 display_last_displayed_message_p
= 0;
7887 redisplay_internal (1);
7891 /* Function registered with record_unwind_protect in
7892 redisplay_internal. Clears the flag indicating that a redisplay is
7896 unwind_redisplay (old_redisplaying_p
)
7897 Lisp_Object old_redisplaying_p
;
7899 redisplaying_p
= XFASTINT (old_redisplaying_p
);
7904 /* Mark the display of windows in the window tree rooted at WINDOW as
7905 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
7906 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
7907 the next time redisplay_internal is called. */
7910 mark_window_display_accurate (window
, accurate_p
)
7916 for (; !NILP (window
); window
= w
->next
)
7918 w
= XWINDOW (window
);
7920 if (BUFFERP (w
->buffer
))
7922 struct buffer
*b
= XBUFFER (w
->buffer
);
7924 XSETFASTINT (w
->last_modified
,
7925 accurate_p
? BUF_MODIFF (b
) : 0);
7926 XSETFASTINT (w
->last_overlay_modified
,
7927 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
7928 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
7931 #if 0 /* I don't think this is necessary because display_line does it.
7933 /* Record if we are showing a region, so can make sure to
7934 update it fully at next redisplay. */
7936 = (!NILP (Vtransient_mark_mode
)
7937 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7938 || highlight_nonselected_windows
)
7939 && (!NILP (b
->mark_active
)
7940 ? Fmarker_position (b
->mark
)
7946 b
->clip_changed
= 0;
7947 b
->prevent_redisplay_optimizations_p
= 0;
7948 w
->current_matrix
->buffer
= b
;
7949 w
->current_matrix
->begv
= BUF_BEGV (b
);
7950 w
->current_matrix
->zv
= BUF_ZV (b
);
7951 w
->last_cursor
= w
->cursor
;
7952 w
->last_cursor_off_p
= w
->cursor_off_p
;
7953 if (w
== XWINDOW (selected_window
))
7954 w
->last_point
= make_number (BUF_PT (b
));
7956 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
7960 w
->window_end_valid
= w
->buffer
;
7961 w
->update_mode_line
= Qnil
;
7963 if (!NILP (w
->vchild
))
7964 mark_window_display_accurate (w
->vchild
, accurate_p
);
7965 if (!NILP (w
->hchild
))
7966 mark_window_display_accurate (w
->hchild
, accurate_p
);
7971 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7972 last_arrow_string
= Voverlay_arrow_string
;
7976 /* Force a thorough redisplay the next time by setting
7977 last_arrow_position and last_arrow_string to t, which is
7978 unequal to any useful value of Voverlay_arrow_... */
7979 last_arrow_position
= Qt
;
7980 last_arrow_string
= Qt
;
7985 /* Return value in display table DP (Lisp_Char_Table *) for character
7986 C. Since a display table doesn't have any parent, we don't have to
7987 follow parent. Do not call this function directly but use the
7988 macro DISP_CHAR_VECTOR. */
7991 disp_char_vector (dp
, c
)
7992 struct Lisp_Char_Table
*dp
;
7998 if (SINGLE_BYTE_CHAR_P (c
))
7999 return (dp
->contents
[c
]);
8001 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
8004 else if (code
[2] < 32)
8007 /* Here, the possible range of code[0] (== charset ID) is
8008 128..max_charset. Since the top level char table contains data
8009 for multibyte characters after 256th element, we must increment
8010 code[0] by 128 to get a correct index. */
8012 code
[3] = -1; /* anchor */
8014 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
8016 val
= dp
->contents
[code
[i
]];
8017 if (!SUB_CHAR_TABLE_P (val
))
8018 return (NILP (val
) ? dp
->defalt
: val
);
8021 /* Here, val is a sub char table. We return the default value of
8023 return (dp
->defalt
);
8028 /***********************************************************************
8030 ***********************************************************************/
8032 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
8035 redisplay_windows (window
)
8038 while (!NILP (window
))
8040 struct window
*w
= XWINDOW (window
);
8042 if (!NILP (w
->hchild
))
8043 redisplay_windows (w
->hchild
);
8044 else if (!NILP (w
->vchild
))
8045 redisplay_windows (w
->vchild
);
8047 redisplay_window (window
, 0);
8054 /* Set cursor position of W. PT is assumed to be displayed in ROW.
8055 DELTA is the number of bytes by which positions recorded in ROW
8056 differ from current buffer positions. */
8059 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
8061 struct glyph_row
*row
;
8062 struct glyph_matrix
*matrix
;
8063 int delta
, delta_bytes
, dy
, dvpos
;
8065 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
8066 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
8068 int pt_old
= PT
- delta
;
8070 /* Skip over glyphs not having an object at the start of the row.
8071 These are special glyphs like truncation marks on terminal
8073 if (row
->displays_text_p
)
8075 && INTEGERP (glyph
->object
)
8076 && glyph
->charpos
< 0)
8078 x
+= glyph
->pixel_width
;
8083 && !INTEGERP (glyph
->object
)
8084 && (!BUFFERP (glyph
->object
)
8085 || glyph
->charpos
< pt_old
))
8087 x
+= glyph
->pixel_width
;
8091 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
8093 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
8094 w
->cursor
.y
= row
->y
+ dy
;
8096 if (w
== XWINDOW (selected_window
))
8098 if (!row
->continued_p
8099 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
8102 this_line_buffer
= XBUFFER (w
->buffer
);
8104 CHARPOS (this_line_start_pos
)
8105 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
8106 BYTEPOS (this_line_start_pos
)
8107 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
8109 CHARPOS (this_line_end_pos
)
8110 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
8111 BYTEPOS (this_line_end_pos
)
8112 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
8114 this_line_y
= w
->cursor
.y
;
8115 this_line_pixel_height
= row
->height
;
8116 this_line_vpos
= w
->cursor
.vpos
;
8117 this_line_start_x
= row
->x
;
8120 CHARPOS (this_line_start_pos
) = 0;
8125 /* Run window scroll functions, if any, for WINDOW with new window
8126 start STARTP. Sets the window start of WINDOW to that position.
8128 We assume that the window's buffer is really current. */
8130 static INLINE
struct text_pos
8131 run_window_scroll_functions (window
, startp
)
8133 struct text_pos startp
;
8135 struct window
*w
= XWINDOW (window
);
8136 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
8138 if (current_buffer
!= XBUFFER (w
->buffer
))
8141 if (!NILP (Vwindow_scroll_functions
))
8143 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
8144 make_number (CHARPOS (startp
)));
8145 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8146 /* In case the hook functions switch buffers. */
8147 if (current_buffer
!= XBUFFER (w
->buffer
))
8148 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8155 /* Modify the desired matrix of window W and W->vscroll so that the
8156 line containing the cursor is fully visible. */
8159 make_cursor_line_fully_visible (w
)
8162 struct glyph_matrix
*matrix
;
8163 struct glyph_row
*row
;
8164 int header_line_height
;
8166 /* It's not always possible to find the cursor, e.g, when a window
8167 is full of overlay strings. Don't do anything in that case. */
8168 if (w
->cursor
.vpos
< 0)
8171 matrix
= w
->desired_matrix
;
8172 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
8174 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
)
8175 /* The row may be partially visible at the top because we
8176 already have chosen a vscroll to align the bottom of the
8177 row with the bottom of the window. This happens for rows
8178 taller than the window. */
8179 && row
->y
+ row
->height
< window_box_height (w
))
8181 int dy
= row
->height
- row
->visible_height
;
8184 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8186 else if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w
, row
)
8187 /* The row may be partially visible at the bottom because
8188 we chose a vscroll to align the row's top with the
8189 window's top. This happens for rows taller than the
8191 && row
->y
> WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
))
8193 int dy
= - (row
->height
- row
->visible_height
);
8196 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8199 /* When we change the cursor y-position of the selected window,
8200 change this_line_y as well so that the display optimization for
8201 the cursor line of the selected window in redisplay_internal uses
8202 the correct y-position. */
8203 if (w
== XWINDOW (selected_window
))
8204 this_line_y
= w
->cursor
.y
;
8208 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
8209 non-zero means only WINDOW is redisplayed in redisplay_internal.
8210 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
8211 in redisplay_window to bring a partially visible line into view in
8212 the case that only the cursor has moved.
8216 1 if scrolling succeeded
8218 0 if scrolling didn't find point.
8220 -1 if new fonts have been loaded so that we must interrupt
8221 redisplay, adjust glyph matrices, and try again. */
8224 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
8225 scroll_step
, temp_scroll_step
)
8227 int just_this_one_p
;
8228 int scroll_conservatively
, scroll_step
;
8229 int temp_scroll_step
;
8231 struct window
*w
= XWINDOW (window
);
8232 struct frame
*f
= XFRAME (w
->frame
);
8233 struct text_pos scroll_margin_pos
;
8234 struct text_pos pos
;
8235 struct text_pos startp
;
8237 Lisp_Object window_end
;
8238 int this_scroll_margin
;
8241 int line_height
, rc
;
8242 int amount_to_scroll
= 0;
8243 Lisp_Object aggressive
;
8247 debug_method_add (w
, "try_scrolling");
8250 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8252 /* Compute scroll margin height in pixels. We scroll when point is
8253 within this distance from the top or bottom of the window. */
8254 if (scroll_margin
> 0)
8256 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
8257 this_scroll_margin
*= CANON_Y_UNIT (f
);
8260 this_scroll_margin
= 0;
8262 /* Compute how much we should try to scroll maximally to bring point
8265 scroll_max
= scroll_step
;
8266 else if (scroll_conservatively
)
8267 scroll_max
= scroll_conservatively
;
8268 else if (temp_scroll_step
)
8269 scroll_max
= temp_scroll_step
;
8270 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
8271 || NUMBERP (current_buffer
->scroll_up_aggressively
))
8272 /* We're trying to scroll because of aggressive scrolling
8273 but no scroll_step is set. Choose an arbitrary one. Maybe
8274 there should be a variable for this. */
8278 scroll_max
*= CANON_Y_UNIT (f
);
8280 /* Decide whether we have to scroll down. Start at the window end
8281 and move this_scroll_margin up to find the position of the scroll
8283 window_end
= Fwindow_end (window
, Qt
);
8284 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
8285 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
8286 if (this_scroll_margin
)
8288 start_display (&it
, w
, scroll_margin_pos
);
8289 move_it_vertically (&it
, - this_scroll_margin
);
8290 scroll_margin_pos
= it
.current
.pos
;
8293 if (PT
>= CHARPOS (scroll_margin_pos
))
8297 /* Point is in the scroll margin at the bottom of the window, or
8298 below. Compute a new window start that makes point visible. */
8300 /* Compute the distance from the scroll margin to PT.
8301 Give up if the distance is greater than scroll_max. */
8302 start_display (&it
, w
, scroll_margin_pos
);
8304 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8305 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8306 line_height
= (it
.max_ascent
+ it
.max_descent
8307 ? it
.max_ascent
+ it
.max_descent
8309 dy
= it
.current_y
+ line_height
- y0
;
8310 if (dy
> scroll_max
)
8313 /* Move the window start down. If scrolling conservatively,
8314 move it just enough down to make point visible. If
8315 scroll_step is set, move it down by scroll_step. */
8316 start_display (&it
, w
, startp
);
8318 if (scroll_conservatively
)
8319 amount_to_scroll
= dy
;
8320 else if (scroll_step
|| temp_scroll_step
)
8321 amount_to_scroll
= scroll_max
;
8324 aggressive
= current_buffer
->scroll_down_aggressively
;
8325 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8326 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8327 if (NUMBERP (aggressive
))
8328 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8331 if (amount_to_scroll
<= 0)
8334 move_it_vertically (&it
, amount_to_scroll
);
8335 startp
= it
.current
.pos
;
8339 /* See if point is inside the scroll margin at the top of the
8341 scroll_margin_pos
= startp
;
8342 if (this_scroll_margin
)
8344 start_display (&it
, w
, startp
);
8345 move_it_vertically (&it
, this_scroll_margin
);
8346 scroll_margin_pos
= it
.current
.pos
;
8349 if (PT
< CHARPOS (scroll_margin_pos
))
8351 /* Point is in the scroll margin at the top of the window or
8352 above what is displayed in the window. */
8355 /* Compute the vertical distance from PT to the scroll
8356 margin position. Give up if distance is greater than
8358 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
8359 start_display (&it
, w
, pos
);
8361 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
8362 it
.last_visible_y
, -1,
8363 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8364 dy
= it
.current_y
- y0
;
8365 if (dy
> scroll_max
)
8368 /* Compute new window start. */
8369 start_display (&it
, w
, startp
);
8371 if (scroll_conservatively
)
8372 amount_to_scroll
= dy
;
8373 else if (scroll_step
|| temp_scroll_step
)
8374 amount_to_scroll
= scroll_max
;
8377 aggressive
= current_buffer
->scroll_up_aggressively
;
8378 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8379 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8380 if (NUMBERP (aggressive
))
8381 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8384 if (amount_to_scroll
<= 0)
8387 move_it_vertically (&it
, - amount_to_scroll
);
8388 startp
= it
.current
.pos
;
8392 /* Run window scroll functions. */
8393 startp
= run_window_scroll_functions (window
, startp
);
8395 /* Display the window. Give up if new fonts are loaded, or if point
8397 if (!try_window (window
, startp
))
8399 else if (w
->cursor
.vpos
< 0)
8401 clear_glyph_matrix (w
->desired_matrix
);
8406 /* Maybe forget recorded base line for line number display. */
8407 if (!just_this_one_p
8408 || current_buffer
->clip_changed
8409 || BEG_UNCHANGED
< CHARPOS (startp
))
8410 w
->base_line_number
= Qnil
;
8412 /* If cursor ends up on a partially visible line, shift display
8413 lines up or down. */
8414 make_cursor_line_fully_visible (w
);
8422 /* Compute a suitable window start for window W if display of W starts
8423 on a continuation line. Value is non-zero if a new window start
8426 The new window start will be computed, based on W's width, starting
8427 from the start of the continued line. It is the start of the
8428 screen line with the minimum distance from the old start W->start. */
8431 compute_window_start_on_continuation_line (w
)
8434 struct text_pos pos
, start_pos
;
8435 int window_start_changed_p
= 0;
8437 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
8439 /* If window start is on a continuation line... Window start may be
8440 < BEGV in case there's invisible text at the start of the
8441 buffer (M-x rmail, for example). */
8442 if (CHARPOS (start_pos
) > BEGV
8443 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
8446 struct glyph_row
*row
;
8448 /* Handle the case that the window start is out of range. */
8449 if (CHARPOS (start_pos
) < BEGV
)
8450 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
8451 else if (CHARPOS (start_pos
) > ZV
)
8452 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
8454 /* Find the start of the continued line. This should be fast
8455 because scan_buffer is fast (newline cache). */
8456 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
8457 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
8458 row
, DEFAULT_FACE_ID
);
8459 reseat_at_previous_visible_line_start (&it
);
8461 /* If the line start is "too far" away from the window start,
8462 say it takes too much time to compute a new window start. */
8463 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
8464 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
8466 int min_distance
, distance
;
8468 /* Move forward by display lines to find the new window
8469 start. If window width was enlarged, the new start can
8470 be expected to be > the old start. If window width was
8471 decreased, the new window start will be < the old start.
8472 So, we're looking for the display line start with the
8473 minimum distance from the old window start. */
8474 pos
= it
.current
.pos
;
8475 min_distance
= INFINITY
;
8476 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
8477 distance
< min_distance
)
8479 min_distance
= distance
;
8480 pos
= it
.current
.pos
;
8481 move_it_by_lines (&it
, 1, 0);
8484 /* Set the window start there. */
8485 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
8486 window_start_changed_p
= 1;
8490 return window_start_changed_p
;
8494 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
8495 selected_window is redisplayed. */
8498 redisplay_window (window
, just_this_one_p
)
8500 int just_this_one_p
;
8502 struct window
*w
= XWINDOW (window
);
8503 struct frame
*f
= XFRAME (w
->frame
);
8504 struct buffer
*buffer
= XBUFFER (w
->buffer
);
8505 struct buffer
*old
= current_buffer
;
8506 struct text_pos lpoint
, opoint
, startp
;
8507 int update_mode_line
;
8510 /* Record it now because it's overwritten. */
8511 int current_matrix_up_to_date_p
= 0;
8512 int temp_scroll_step
= 0;
8513 int count
= specpdl_ptr
- specpdl
;
8515 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8518 /* W must be a leaf window here. */
8519 xassert (!NILP (w
->buffer
));
8521 *w
->desired_matrix
->method
= 0;
8524 specbind (Qinhibit_point_motion_hooks
, Qt
);
8526 reconsider_clip_changes (w
, buffer
);
8528 /* Has the mode line to be updated? */
8529 update_mode_line
= (!NILP (w
->update_mode_line
)
8530 || update_mode_lines
8531 || buffer
->clip_changed
);
8533 if (MINI_WINDOW_P (w
))
8535 if (w
== XWINDOW (echo_area_window
)
8536 && !NILP (echo_area_buffer
[0]))
8538 if (update_mode_line
)
8539 /* We may have to update a tty frame's menu bar or a
8540 tool-bar. Example `M-x C-h C-h C-g'. */
8541 goto finish_menu_bars
;
8543 /* We've already displayed the echo area glyphs in this window. */
8544 goto finish_scroll_bars
;
8546 else if (w
!= XWINDOW (minibuf_window
))
8548 /* W is a mini-buffer window, but it's not the currently
8549 active one, so clear it. */
8550 int yb
= window_text_bottom_y (w
);
8551 struct glyph_row
*row
;
8554 for (y
= 0, row
= w
->desired_matrix
->rows
;
8556 y
+= row
->height
, ++row
)
8557 blank_row (w
, row
, y
);
8558 goto finish_scroll_bars
;
8562 /* Otherwise set up data on this window; select its buffer and point
8564 /* Really select the buffer, for the sake of buffer-local
8566 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8567 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
8569 current_matrix_up_to_date_p
8570 = (!NILP (w
->window_end_valid
)
8571 && !current_buffer
->clip_changed
8572 && XFASTINT (w
->last_modified
) >= MODIFF
8573 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
8575 /* When windows_or_buffers_changed is non-zero, we can't rely on
8576 the window end being valid, so set it to nil there. */
8577 if (windows_or_buffers_changed
)
8579 /* If window starts on a continuation line, maybe adjust the
8580 window start in case the window's width changed. */
8581 if (XMARKER (w
->start
)->buffer
== current_buffer
)
8582 compute_window_start_on_continuation_line (w
);
8584 w
->window_end_valid
= Qnil
;
8587 /* Some sanity checks. */
8588 CHECK_WINDOW_END (w
);
8589 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
8591 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
8594 /* If %c is in mode line, update it if needed. */
8595 if (!NILP (w
->column_number_displayed
)
8596 /* This alternative quickly identifies a common case
8597 where no change is needed. */
8598 && !(PT
== XFASTINT (w
->last_point
)
8599 && XFASTINT (w
->last_modified
) >= MODIFF
8600 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8601 && XFASTINT (w
->column_number_displayed
) != current_column ())
8602 update_mode_line
= 1;
8604 /* Count number of windows showing the selected buffer. An indirect
8605 buffer counts as its base buffer. */
8606 if (!just_this_one_p
)
8608 struct buffer
*current_base
, *window_base
;
8609 current_base
= current_buffer
;
8610 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
8611 if (current_base
->base_buffer
)
8612 current_base
= current_base
->base_buffer
;
8613 if (window_base
->base_buffer
)
8614 window_base
= window_base
->base_buffer
;
8615 if (current_base
== window_base
)
8619 /* Point refers normally to the selected window. For any other
8620 window, set up appropriate value. */
8621 if (!EQ (window
, selected_window
))
8623 int new_pt
= XMARKER (w
->pointm
)->charpos
;
8624 int new_pt_byte
= marker_byte_position (w
->pointm
);
8628 new_pt_byte
= BEGV_BYTE
;
8629 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
8631 else if (new_pt
> (ZV
- 1))
8634 new_pt_byte
= ZV_BYTE
;
8635 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
8638 /* We don't use SET_PT so that the point-motion hooks don't run. */
8639 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
8642 /* If any of the character widths specified in the display table
8643 have changed, invalidate the width run cache. It's true that
8644 this may be a bit late to catch such changes, but the rest of
8645 redisplay goes (non-fatally) haywire when the display table is
8646 changed, so why should we worry about doing any better? */
8647 if (current_buffer
->width_run_cache
)
8649 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
8651 if (! disptab_matches_widthtab (disptab
,
8652 XVECTOR (current_buffer
->width_table
)))
8654 invalidate_region_cache (current_buffer
,
8655 current_buffer
->width_run_cache
,
8657 recompute_width_table (current_buffer
, disptab
);
8661 /* If window-start is screwed up, choose a new one. */
8662 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
8665 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8667 /* If someone specified a new starting point but did not insist,
8668 check whether it can be used. */
8669 if (!NILP (w
->optional_new_start
)
8670 && CHARPOS (startp
) >= BEGV
8671 && CHARPOS (startp
) <= ZV
)
8673 w
->optional_new_start
= Qnil
;
8674 /* This takes a mini-buffer prompt into account. */
8675 start_display (&it
, w
, startp
);
8676 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8677 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8678 if (IT_CHARPOS (it
) == PT
)
8679 w
->force_start
= Qt
;
8682 /* Handle case where place to start displaying has been specified,
8683 unless the specified location is outside the accessible range. */
8684 if (!NILP (w
->force_start
)
8685 || w
->frozen_window_start_p
)
8687 w
->force_start
= Qnil
;
8689 w
->window_end_valid
= Qnil
;
8691 /* Forget any recorded base line for line number display. */
8692 if (!current_matrix_up_to_date_p
8693 || current_buffer
->clip_changed
)
8694 w
->base_line_number
= Qnil
;
8696 /* Redisplay the mode line. Select the buffer properly for that.
8697 Also, run the hook window-scroll-functions
8698 because we have scrolled. */
8699 /* Note, we do this after clearing force_start because
8700 if there's an error, it is better to forget about force_start
8701 than to get into an infinite loop calling the hook functions
8702 and having them get more errors. */
8703 if (!update_mode_line
8704 || ! NILP (Vwindow_scroll_functions
))
8706 update_mode_line
= 1;
8707 w
->update_mode_line
= Qt
;
8708 startp
= run_window_scroll_functions (window
, startp
);
8711 XSETFASTINT (w
->last_modified
, 0);
8712 XSETFASTINT (w
->last_overlay_modified
, 0);
8713 if (CHARPOS (startp
) < BEGV
)
8714 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
8715 else if (CHARPOS (startp
) > ZV
)
8716 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
8718 /* Redisplay, then check if cursor has been set during the
8719 redisplay. Give up if new fonts were loaded. */
8720 if (!try_window (window
, startp
))
8722 w
->force_start
= Qt
;
8723 clear_glyph_matrix (w
->desired_matrix
);
8724 goto restore_buffers
;
8727 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
8729 /* If point does not appear, or on a line that is not fully
8730 visible, move point so it does appear. The desired
8731 matrix has been built above, so we can use it. */
8732 int height
= window_box_height (w
) / 2;
8733 struct glyph_row
*row
= MATRIX_ROW (w
->desired_matrix
, 0);
8735 while (row
->y
< height
)
8738 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
8739 MATRIX_ROW_START_BYTEPOS (row
));
8741 if (w
!= XWINDOW (selected_window
))
8742 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
8743 else if (current_buffer
== old
)
8744 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8746 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
8748 /* If we are highlighting the region, then we just changed
8749 the region, so redisplay to show it. */
8750 if (!NILP (Vtransient_mark_mode
)
8751 && !NILP (current_buffer
->mark_active
))
8753 clear_glyph_matrix (w
->desired_matrix
);
8754 if (!try_window (window
, startp
))
8755 goto restore_buffers
;
8759 make_cursor_line_fully_visible (w
);
8761 debug_method_add (w
, "forced window start");
8766 /* Handle case where text has not changed, only point, and it has
8767 not moved off the frame. */
8768 if (current_matrix_up_to_date_p
8769 /* Point may be in this window. */
8770 && PT
>= CHARPOS (startp
)
8771 /* If we don't check this, we are called to move the cursor in a
8772 horizontally split window with a current matrix that doesn't
8774 && !windows_or_buffers_changed
8775 /* Selective display hasn't changed. */
8776 && !current_buffer
->clip_changed
8777 /* If force-mode-line-update was called, really redisplay;
8778 that's how redisplay is forced after e.g. changing
8779 buffer-invisibility-spec. */
8780 && NILP (w
->update_mode_line
)
8781 /* Can't use this case if highlighting a region. When a
8782 region exists, cursor movement has to do more than just
8784 && !(!NILP (Vtransient_mark_mode
)
8785 && !NILP (current_buffer
->mark_active
))
8786 && NILP (w
->region_showing
)
8787 && NILP (Vshow_trailing_whitespace
)
8788 /* Right after splitting windows, last_point may be nil. */
8789 && INTEGERP (w
->last_point
)
8790 /* This code is not used for mini-buffer for the sake of the case
8791 of redisplaying to replace an echo area message; since in
8792 that case the mini-buffer contents per se are usually
8793 unchanged. This code is of no real use in the mini-buffer
8794 since the handling of this_line_start_pos, etc., in redisplay
8795 handles the same cases. */
8796 && !EQ (window
, minibuf_window
)
8797 /* When splitting windows or for new windows, it happens that
8798 redisplay is called with a nil window_end_vpos or one being
8799 larger than the window. This should really be fixed in
8800 window.c. I don't have this on my list, now, so we do
8801 approximately the same as the old redisplay code. --gerd. */
8802 && INTEGERP (w
->window_end_vpos
)
8803 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
8804 && (FRAME_WINDOW_P (f
)
8805 || !MARKERP (Voverlay_arrow_position
)
8806 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
8808 int this_scroll_margin
;
8809 struct glyph_row
*row
;
8813 debug_method_add (w
, "cursor movement");
8816 /* Scroll if point within this distance from the top or bottom
8817 of the window. This is a pixel value. */
8818 this_scroll_margin
= max (0, scroll_margin
);
8819 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
8820 this_scroll_margin
*= CANON_Y_UNIT (f
);
8822 /* Start with the row the cursor was displayed during the last
8823 not paused redisplay. Give up if that row is not valid. */
8824 if (w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
8826 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
8827 if (row
->mode_line_p
)
8829 if (!row
->enabled_p
)
8833 if (PT
> XFASTINT (w
->last_point
))
8835 /* Point has moved forward. */
8836 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
8838 while (MATRIX_ROW_END_CHARPOS (row
) < PT
8839 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
8841 xassert (row
->enabled_p
);
8845 /* The end position of a row equals the start position of
8846 the next row. If PT is there, we would rather display it
8847 in the next line. Exceptions are when the row ends in
8848 the middle of a character, or ends in ZV. */
8849 if (MATRIX_ROW_BOTTOM_Y (row
) < last_y
8850 && MATRIX_ROW_END_CHARPOS (row
) == PT
8851 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
8852 && !row
->ends_at_zv_p
)
8854 xassert (row
->enabled_p
);
8858 /* If within the scroll margin, scroll. Note that
8859 MATRIX_ROW_BOTTOM_Y gives the pixel position at which the
8860 next line would be drawn, and that this_scroll_margin can
8862 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
8863 || PT
> MATRIX_ROW_END_CHARPOS (row
)
8864 /* Line is completely visible last line in window and PT
8865 is to be set in the next line. */
8866 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
8867 && PT
== MATRIX_ROW_END_CHARPOS (row
)
8868 && !row
->ends_at_zv_p
8869 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
8872 else if (PT
< XFASTINT (w
->last_point
))
8874 /* Cursor has to be moved backward. Note that PT >=
8875 CHARPOS (startp) because of the outer if-statement. */
8876 while (!row
->mode_line_p
8877 && (MATRIX_ROW_START_CHARPOS (row
) > PT
8878 || (MATRIX_ROW_START_CHARPOS (row
) == PT
8879 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
8880 && (row
->y
> this_scroll_margin
8881 || CHARPOS (startp
) == BEGV
))
8883 xassert (row
->enabled_p
);
8887 /* Consider the following case: Window starts at BEGV, there
8888 is invisible, intangible text at BEGV, so that display
8889 starts at some point START > BEGV. It can happen that
8890 we are called with PT somewhere between BEGV and START.
8891 Try to handle that case. */
8892 if (row
< w
->current_matrix
->rows
8893 || row
->mode_line_p
)
8895 row
= w
->current_matrix
->rows
;
8896 if (row
->mode_line_p
)
8900 /* Due to newlines in overlay strings, we may have to skip
8901 forward over overlay strings. */
8902 while (MATRIX_ROW_END_CHARPOS (row
) == PT
8903 && MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P (row
)
8904 && !row
->ends_at_zv_p
)
8907 /* If within the scroll margin, scroll. */
8908 if (row
->y
< this_scroll_margin
8909 && CHARPOS (startp
) != BEGV
)
8913 /* if PT is not in the glyph row, give up. */
8914 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
8915 || PT
> MATRIX_ROW_END_CHARPOS (row
))
8918 /* If we end up in a partially visible line, let's make it fully
8919 visible. This can be done most easily by using the existing
8921 if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8923 temp_scroll_step
= 1;
8929 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8933 /* If current starting point was originally the beginning of a line
8934 but no longer is, find a new starting point. */
8935 else if (!NILP (w
->start_at_line_beg
)
8936 && !(CHARPOS (startp
) <= BEGV
8937 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
8940 debug_method_add (w
, "recenter 1");
8945 /* Try scrolling with try_window_id. */
8946 else if (/* Windows and buffers haven't changed. */
8947 !windows_or_buffers_changed
8948 /* Window must be either use window-based redisplay or
8950 && (FRAME_WINDOW_P (f
)
8951 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
8952 && !MINI_WINDOW_P (w
)
8953 /* Point is not known NOT to appear in window. */
8954 && PT
>= CHARPOS (startp
)
8955 && XFASTINT (w
->last_modified
)
8956 /* Window is not hscrolled. */
8957 && XFASTINT (w
->hscroll
) == 0
8958 /* Selective display has not changed. */
8959 && !current_buffer
->clip_changed
8960 /* Current matrix is up to date. */
8961 && !NILP (w
->window_end_valid
)
8962 /* Can't use this case if highlighting a region because
8963 a cursor movement will do more than just set the cursor. */
8964 && !(!NILP (Vtransient_mark_mode
)
8965 && !NILP (current_buffer
->mark_active
))
8966 && NILP (w
->region_showing
)
8967 && NILP (Vshow_trailing_whitespace
)
8968 /* Overlay arrow position and string not changed. */
8969 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
8970 && EQ (last_arrow_string
, Voverlay_arrow_string
)
8971 /* Value is > 0 if update has been done, it is -1 if we
8972 know that the same window start will not work. It is 0
8973 if unsuccessful for some other reason. */
8974 && (tem
= try_window_id (w
)) != 0)
8977 debug_method_add (w
, "try_window_id");
8980 if (fonts_changed_p
)
8981 goto restore_buffers
;
8984 /* Otherwise try_window_id has returned -1 which means that we
8985 don't want the alternative below this comment to execute. */
8987 else if (CHARPOS (startp
) >= BEGV
8988 && CHARPOS (startp
) <= ZV
8989 && PT
>= CHARPOS (startp
)
8990 && (CHARPOS (startp
) < ZV
8991 /* Avoid starting at end of buffer. */
8992 || CHARPOS (startp
) == BEGV
8993 || (XFASTINT (w
->last_modified
) >= MODIFF
8994 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
8997 debug_method_add (w
, "same window start");
9000 /* Try to redisplay starting at same place as before.
9001 If point has not moved off frame, accept the results. */
9002 if (!current_matrix_up_to_date_p
9003 /* Don't use try_window_reusing_current_matrix in this case
9004 because a window scroll function can have changed the
9006 || !NILP (Vwindow_scroll_functions
)
9007 || MINI_WINDOW_P (w
)
9008 || !try_window_reusing_current_matrix (w
))
9010 IF_DEBUG (debug_method_add (w
, "1"));
9011 try_window (window
, startp
);
9014 if (fonts_changed_p
)
9015 goto restore_buffers
;
9017 if (w
->cursor
.vpos
>= 0)
9019 if (!just_this_one_p
9020 || current_buffer
->clip_changed
9021 || BEG_UNCHANGED
< CHARPOS (startp
))
9022 /* Forget any recorded base line for line number display. */
9023 w
->base_line_number
= Qnil
;
9025 make_cursor_line_fully_visible (w
);
9029 clear_glyph_matrix (w
->desired_matrix
);
9034 XSETFASTINT (w
->last_modified
, 0);
9035 XSETFASTINT (w
->last_overlay_modified
, 0);
9037 /* Redisplay the mode line. Select the buffer properly for that. */
9038 if (!update_mode_line
)
9040 update_mode_line
= 1;
9041 w
->update_mode_line
= Qt
;
9044 /* Try to scroll by specified few lines. */
9045 if ((scroll_conservatively
9048 || NUMBERP (current_buffer
->scroll_up_aggressively
)
9049 || NUMBERP (current_buffer
->scroll_down_aggressively
))
9050 && !current_buffer
->clip_changed
9051 && CHARPOS (startp
) >= BEGV
9052 && CHARPOS (startp
) <= ZV
)
9054 /* The function returns -1 if new fonts were loaded, 1 if
9055 successful, 0 if not successful. */
9056 int rc
= try_scrolling (window
, just_this_one_p
,
9057 scroll_conservatively
,
9063 goto restore_buffers
;
9066 /* Finally, just choose place to start which centers point */
9071 debug_method_add (w
, "recenter");
9074 /* w->vscroll = 0; */
9076 /* Forget any previously recorded base line for line number display. */
9077 if (!current_matrix_up_to_date_p
9078 || current_buffer
->clip_changed
)
9079 w
->base_line_number
= Qnil
;
9081 /* Move backward half the height of the window. */
9082 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9083 it
.current_y
= it
.last_visible_y
;
9084 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
9085 xassert (IT_CHARPOS (it
) >= BEGV
);
9087 /* The function move_it_vertically_backward may move over more
9088 than the specified y-distance. If it->w is small, e.g. a
9089 mini-buffer window, we may end up in front of the window's
9090 display area. Start displaying at the start of the line
9091 containing PT in this case. */
9092 if (it
.current_y
<= 0)
9094 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9095 move_it_vertically (&it
, 0);
9096 xassert (IT_CHARPOS (it
) <= PT
);
9100 it
.current_x
= it
.hpos
= 0;
9102 /* Set startp here explicitly in case that helps avoid an infinite loop
9103 in case the window-scroll-functions functions get errors. */
9104 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
9106 /* Run scroll hooks. */
9107 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
9109 /* Redisplay the window. */
9110 if (!current_matrix_up_to_date_p
9111 || windows_or_buffers_changed
9112 /* Don't use try_window_reusing_current_matrix in this case
9113 because it can have changed the buffer. */
9114 || !NILP (Vwindow_scroll_functions
)
9116 || MINI_WINDOW_P (w
)
9117 || !try_window_reusing_current_matrix (w
))
9118 try_window (window
, startp
);
9120 /* If new fonts have been loaded (due to fontsets), give up. We
9121 have to start a new redisplay since we need to re-adjust glyph
9123 if (fonts_changed_p
)
9124 goto restore_buffers
;
9126 /* If cursor did not appear assume that the middle of the window is
9127 in the first line of the window. Do it again with the next line.
9128 (Imagine a window of height 100, displaying two lines of height
9129 60. Moving back 50 from it->last_visible_y will end in the first
9131 if (w
->cursor
.vpos
< 0)
9133 if (!NILP (w
->window_end_valid
)
9134 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
9136 clear_glyph_matrix (w
->desired_matrix
);
9137 move_it_by_lines (&it
, 1, 0);
9138 try_window (window
, it
.current
.pos
);
9140 else if (PT
< IT_CHARPOS (it
))
9142 clear_glyph_matrix (w
->desired_matrix
);
9143 move_it_by_lines (&it
, -1, 0);
9144 try_window (window
, it
.current
.pos
);
9148 /* Not much we can do about it. */
9152 /* Consider the following case: Window starts at BEGV, there is
9153 invisible, intangible text at BEGV, so that display starts at
9154 some point START > BEGV. It can happen that we are called with
9155 PT somewhere between BEGV and START. Try to handle that case. */
9156 if (w
->cursor
.vpos
< 0)
9158 struct glyph_row
*row
= w
->current_matrix
->rows
;
9159 if (row
->mode_line_p
)
9161 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9164 make_cursor_line_fully_visible (w
);
9168 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9169 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
9170 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
9173 /* Display the mode line, if we must. */
9174 if ((update_mode_line
9175 /* If window not full width, must redo its mode line
9176 if (a) the window to its side is being redone and
9177 (b) we do a frame-based redisplay. This is a consequence
9178 of how inverted lines are drawn in frame-based redisplay. */
9179 || (!just_this_one_p
9180 && !FRAME_WINDOW_P (f
)
9181 && !WINDOW_FULL_WIDTH_P (w
))
9182 /* Line number to display. */
9183 || INTEGERP (w
->base_line_pos
)
9184 /* Column number is displayed and different from the one displayed. */
9185 || (!NILP (w
->column_number_displayed
)
9186 && XFASTINT (w
->column_number_displayed
) != current_column ()))
9187 /* This means that the window has a mode line. */
9188 && (WINDOW_WANTS_MODELINE_P (w
)
9189 || WINDOW_WANTS_HEADER_LINE_P (w
)))
9191 Lisp_Object old_selected_frame
;
9193 old_selected_frame
= selected_frame
;
9195 XSETFRAME (selected_frame
, f
);
9196 display_mode_lines (w
);
9197 selected_frame
= old_selected_frame
;
9199 /* If mode line height has changed, arrange for a thorough
9200 immediate redisplay using the correct mode line height. */
9201 if (WINDOW_WANTS_MODELINE_P (w
)
9202 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
9204 fonts_changed_p
= 1;
9205 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
9206 = DESIRED_MODE_LINE_HEIGHT (w
);
9209 /* If top line height has changed, arrange for a thorough
9210 immediate redisplay using the correct mode line height. */
9211 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9212 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
9214 fonts_changed_p
= 1;
9215 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
9216 = DESIRED_HEADER_LINE_HEIGHT (w
);
9219 if (fonts_changed_p
)
9220 goto restore_buffers
;
9223 if (!line_number_displayed
9224 && !BUFFERP (w
->base_line_pos
))
9226 w
->base_line_pos
= Qnil
;
9227 w
->base_line_number
= Qnil
;
9232 /* When we reach a frame's selected window, redo the frame's menu bar. */
9233 if (update_mode_line
9234 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
9236 int redisplay_menu_p
= 0;
9238 if (FRAME_WINDOW_P (f
))
9240 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
9241 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
9243 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9247 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9249 if (redisplay_menu_p
)
9250 display_menu_bar (w
);
9252 #ifdef HAVE_WINDOW_SYSTEM
9253 if (WINDOWP (f
->tool_bar_window
)
9254 && (FRAME_TOOL_BAR_LINES (f
) > 0
9255 || auto_resize_tool_bars_p
))
9256 redisplay_tool_bar (f
);
9262 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9264 int start
, end
, whole
;
9266 /* Calculate the start and end positions for the current window.
9267 At some point, it would be nice to choose between scrollbars
9268 which reflect the whole buffer size, with special markers
9269 indicating narrowing, and scrollbars which reflect only the
9272 Note that mini-buffers sometimes aren't displaying any text. */
9273 if (!MINI_WINDOW_P (w
)
9274 || (w
== XWINDOW (minibuf_window
)
9275 && NILP (echo_area_buffer
[0])))
9278 start
= marker_position (w
->start
) - BEGV
;
9279 /* I don't think this is guaranteed to be right. For the
9280 moment, we'll pretend it is. */
9281 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
9285 if (whole
< (end
- start
))
9286 whole
= end
- start
;
9289 start
= end
= whole
= 0;
9291 /* Indicate what this scroll bar ought to be displaying now. */
9292 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
9294 /* Note that we actually used the scroll bar attached to this
9295 window, so it shouldn't be deleted at the end of redisplay. */
9296 (*redeem_scroll_bar_hook
) (w
);
9301 /* Restore current_buffer and value of point in it. */
9302 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
9303 set_buffer_internal_1 (old
);
9304 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
9306 unbind_to (count
, Qnil
);
9310 /* Build the complete desired matrix of WINDOW with a window start
9311 buffer position POS. Value is non-zero if successful. It is zero
9312 if fonts were loaded during redisplay which makes re-adjusting
9313 glyph matrices necessary. */
9316 try_window (window
, pos
)
9318 struct text_pos pos
;
9320 struct window
*w
= XWINDOW (window
);
9322 struct glyph_row
*last_text_row
= NULL
;
9324 /* Make POS the new window start. */
9325 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
9327 /* Mark cursor position as unknown. No overlay arrow seen. */
9328 w
->cursor
.vpos
= -1;
9329 overlay_arrow_seen
= 0;
9331 /* Initialize iterator and info to start at POS. */
9332 start_display (&it
, w
, pos
);
9334 /* Display all lines of W. */
9335 while (it
.current_y
< it
.last_visible_y
)
9337 if (display_line (&it
))
9338 last_text_row
= it
.glyph_row
- 1;
9339 if (fonts_changed_p
)
9343 /* If bottom moved off end of frame, change mode line percentage. */
9344 if (XFASTINT (w
->window_end_pos
) <= 0
9345 && Z
!= IT_CHARPOS (it
))
9346 w
->update_mode_line
= Qt
;
9348 /* Set window_end_pos to the offset of the last character displayed
9349 on the window from the end of current_buffer. Set
9350 window_end_vpos to its row number. */
9353 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
9354 w
->window_end_bytepos
9355 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9356 XSETFASTINT (w
->window_end_pos
,
9357 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9358 XSETFASTINT (w
->window_end_vpos
,
9359 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9360 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
9365 w
->window_end_bytepos
= 0;
9366 XSETFASTINT (w
->window_end_pos
, 0);
9367 XSETFASTINT (w
->window_end_vpos
, 0);
9370 /* But that is not valid info until redisplay finishes. */
9371 w
->window_end_valid
= Qnil
;
9377 /************************************************************************
9378 Window redisplay reusing current matrix when buffer has not changed
9379 ************************************************************************/
9381 /* Try redisplay of window W showing an unchanged buffer with a
9382 different window start than the last time it was displayed by
9383 reusing its current matrix. Value is non-zero if successful.
9384 W->start is the new window start. */
9387 try_window_reusing_current_matrix (w
)
9390 struct frame
*f
= XFRAME (w
->frame
);
9391 struct glyph_row
*row
, *bottom_row
;
9394 struct text_pos start
, new_start
;
9395 int nrows_scrolled
, i
;
9396 struct glyph_row
*last_text_row
;
9397 struct glyph_row
*last_reused_text_row
;
9398 struct glyph_row
*start_row
;
9399 int start_vpos
, min_y
, max_y
;
9401 /* Right now this function doesn't handle terminal frames. */
9402 if (!FRAME_WINDOW_P (f
))
9405 /* Can't do this if region may have changed. */
9406 if ((!NILP (Vtransient_mark_mode
)
9407 && !NILP (current_buffer
->mark_active
))
9408 || !NILP (w
->region_showing
)
9409 || !NILP (Vshow_trailing_whitespace
))
9412 /* If top-line visibility has changed, give up. */
9413 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9414 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
9417 /* Give up if old or new display is scrolled vertically. We could
9418 make this function handle this, but right now it doesn't. */
9419 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9420 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
9423 /* The variable new_start now holds the new window start. The old
9424 start `start' can be determined from the current matrix. */
9425 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
9426 start
= start_row
->start
.pos
;
9427 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
9429 /* Clear the desired matrix for the display below. */
9430 clear_glyph_matrix (w
->desired_matrix
);
9432 if (CHARPOS (new_start
) <= CHARPOS (start
))
9436 IF_DEBUG (debug_method_add (w
, "twu1"));
9438 /* Display up to a row that can be reused. The variable
9439 last_text_row is set to the last row displayed that displays
9441 start_display (&it
, w
, new_start
);
9442 first_row_y
= it
.current_y
;
9443 w
->cursor
.vpos
= -1;
9444 last_text_row
= last_reused_text_row
= NULL
;
9445 while (it
.current_y
< it
.last_visible_y
9446 && IT_CHARPOS (it
) < CHARPOS (start
)
9447 && !fonts_changed_p
)
9448 if (display_line (&it
))
9449 last_text_row
= it
.glyph_row
- 1;
9451 /* A value of current_y < last_visible_y means that we stopped
9452 at the previous window start, which in turn means that we
9453 have at least one reusable row. */
9454 if (it
.current_y
< it
.last_visible_y
)
9456 nrows_scrolled
= it
.vpos
;
9458 /* Find PT if not already found in the lines displayed. */
9459 if (w
->cursor
.vpos
< 0)
9461 int dy
= it
.current_y
- first_row_y
;
9463 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9464 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9466 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
9467 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9469 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
9470 dy
, nrows_scrolled
);
9474 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
9480 /* Give up if point was not found. This shouldn't
9481 happen often; not more often than with try_window
9483 if (w
->cursor
.vpos
< 0)
9485 clear_glyph_matrix (w
->desired_matrix
);
9490 /* Scroll the display. Do it before the current matrix is
9491 changed. The problem here is that update has not yet
9492 run, i.e. part of the current matrix is not up to date.
9493 scroll_run_hook will clear the cursor, and use the
9494 current matrix to get the height of the row the cursor is
9496 run
.current_y
= first_row_y
;
9497 run
.desired_y
= it
.current_y
;
9498 run
.height
= it
.last_visible_y
- it
.current_y
;
9500 && run
.current_y
!= run
.desired_y
)
9503 rif
->update_window_begin_hook (w
);
9504 rif
->scroll_run_hook (w
, &run
);
9505 rif
->update_window_end_hook (w
, 0);
9509 /* Shift current matrix down by nrows_scrolled lines. */
9510 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9511 rotate_matrix (w
->current_matrix
,
9513 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9516 /* Disable lines not reused. */
9517 for (i
= 0; i
< it
.vpos
; ++i
)
9518 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
9520 /* Re-compute Y positions. */
9521 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
) + nrows_scrolled
;
9522 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9523 max_y
= it
.last_visible_y
;
9524 while (row
< bottom_row
)
9526 row
->y
= it
.current_y
;
9529 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9530 else if (row
->y
+ row
->height
> max_y
)
9532 = row
->height
- (row
->y
+ row
->height
- max_y
);
9534 row
->visible_height
= row
->height
;
9536 it
.current_y
+= row
->height
;
9539 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9540 last_reused_text_row
= row
;
9541 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
9547 /* Update window_end_pos etc.; last_reused_text_row is the last
9548 reused row from the current matrix containing text, if any.
9549 The value of last_text_row is the last displayed line
9551 if (last_reused_text_row
)
9553 w
->window_end_bytepos
9554 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
9555 XSETFASTINT (w
->window_end_pos
,
9556 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
9557 XSETFASTINT (w
->window_end_vpos
,
9558 MATRIX_ROW_VPOS (last_reused_text_row
,
9559 w
->current_matrix
));
9561 else if (last_text_row
)
9563 w
->window_end_bytepos
9564 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9565 XSETFASTINT (w
->window_end_pos
,
9566 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9567 XSETFASTINT (w
->window_end_vpos
,
9568 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9572 /* This window must be completely empty. */
9573 w
->window_end_bytepos
= 0;
9574 XSETFASTINT (w
->window_end_pos
, 0);
9575 XSETFASTINT (w
->window_end_vpos
, 0);
9577 w
->window_end_valid
= Qnil
;
9579 /* Update hint: don't try scrolling again in update_window. */
9580 w
->desired_matrix
->no_scrolling_p
= 1;
9583 debug_method_add (w
, "try_window_reusing_current_matrix 1");
9587 else if (CHARPOS (new_start
) > CHARPOS (start
))
9589 struct glyph_row
*pt_row
, *row
;
9590 struct glyph_row
*first_reusable_row
;
9591 struct glyph_row
*first_row_to_display
;
9593 int yb
= window_text_bottom_y (w
);
9595 IF_DEBUG (debug_method_add (w
, "twu2"));
9597 /* Find the row starting at new_start, if there is one. Don't
9598 reuse a partially visible line at the end. */
9599 first_reusable_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9600 while (first_reusable_row
->enabled_p
9601 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
9602 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9603 < CHARPOS (new_start
)))
9604 ++first_reusable_row
;
9606 /* Give up if there is no row to reuse. */
9607 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
9608 || !first_reusable_row
->enabled_p
9609 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9610 != CHARPOS (new_start
)))
9613 /* We can reuse fully visible rows beginning with
9614 first_reusable_row to the end of the window. Set
9615 first_row_to_display to the first row that cannot be reused.
9616 Set pt_row to the row containing point, if there is any. */
9617 first_row_to_display
= first_reusable_row
;
9619 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
9621 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
9622 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
9623 pt_row
= first_row_to_display
;
9625 ++first_row_to_display
;
9628 /* Start displaying at the start of first_row_to_display. */
9629 xassert (first_row_to_display
->y
< yb
);
9630 init_to_row_start (&it
, w
, first_row_to_display
);
9631 nrows_scrolled
= MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
);
9632 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
9634 it
.current_y
= first_row_to_display
->y
- first_reusable_row
->y
;
9636 /* Display lines beginning with first_row_to_display in the
9637 desired matrix. Set last_text_row to the last row displayed
9638 that displays text. */
9639 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
9641 w
->cursor
.vpos
= -1;
9642 last_text_row
= NULL
;
9643 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
9644 if (display_line (&it
))
9645 last_text_row
= it
.glyph_row
- 1;
9647 /* Give up If point isn't in a row displayed or reused. */
9648 if (w
->cursor
.vpos
< 0)
9650 clear_glyph_matrix (w
->desired_matrix
);
9654 /* If point is in a reused row, adjust y and vpos of the cursor
9658 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
9660 w
->cursor
.y
-= first_reusable_row
->y
;
9663 /* Scroll the display. */
9664 run
.current_y
= first_reusable_row
->y
;
9665 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9666 run
.height
= it
.last_visible_y
- run
.current_y
;
9669 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9671 rif
->update_window_begin_hook (w
);
9672 rif
->scroll_run_hook (w
, &run
);
9673 rif
->update_window_end_hook (w
, 0);
9677 /* Adjust Y positions of reused rows. */
9678 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9679 row
= first_reusable_row
;
9680 dy
= first_reusable_row
->y
;
9681 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9682 max_y
= it
.last_visible_y
;
9683 while (row
< first_row_to_display
)
9687 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9688 else if (row
->y
+ row
->height
> max_y
)
9690 = row
->height
- (row
->y
+ row
->height
- max_y
);
9692 row
->visible_height
= row
->height
;
9696 /* Disable rows not reused. */
9697 while (row
< bottom_row
)
9703 /* Scroll the current matrix. */
9704 xassert (nrows_scrolled
> 0);
9705 rotate_matrix (w
->current_matrix
,
9707 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9710 /* Adjust window end. A null value of last_text_row means that
9711 the window end is in reused rows which in turn means that
9712 only its vpos can have changed. */
9715 w
->window_end_bytepos
9716 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9717 XSETFASTINT (w
->window_end_pos
,
9718 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9719 XSETFASTINT (w
->window_end_vpos
,
9720 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9724 XSETFASTINT (w
->window_end_vpos
,
9725 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
9728 w
->window_end_valid
= Qnil
;
9729 w
->desired_matrix
->no_scrolling_p
= 1;
9732 debug_method_add (w
, "try_window_reusing_current_matrix 2");
9742 /************************************************************************
9743 Window redisplay reusing current matrix when buffer has changed
9744 ************************************************************************/
9746 static struct glyph_row
*get_last_unchanged_at_beg_row
P_ ((struct window
*));
9747 static struct glyph_row
*get_first_unchanged_at_end_row
P_ ((struct window
*,
9749 static struct glyph_row
*
9750 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
9751 struct glyph_row
*));
9754 /* Return the last row in MATRIX displaying text. If row START is
9755 non-null, start searching with that row. IT gives the dimensions
9756 of the display. Value is null if matrix is empty; otherwise it is
9757 a pointer to the row found. */
9759 static struct glyph_row
*
9760 find_last_row_displaying_text (matrix
, it
, start
)
9761 struct glyph_matrix
*matrix
;
9763 struct glyph_row
*start
;
9765 struct glyph_row
*row
, *row_found
;
9767 /* Set row_found to the last row in IT->w's current matrix
9768 displaying text. The loop looks funny but think of partially
9771 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
9772 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9774 xassert (row
->enabled_p
);
9776 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
9785 /* Return the last row in the current matrix of W that is not affected
9786 by changes at the start of current_buffer that occurred since the
9787 last time W was redisplayed. Value is null if no such row exists.
9789 The global variable beg_unchanged has to contain the number of
9790 bytes unchanged at the start of current_buffer. BEG +
9791 beg_unchanged is the buffer position of the first changed byte in
9792 current_buffer. Characters at positions < BEG + beg_unchanged are
9793 at the same buffer positions as they were when the current matrix
9796 static struct glyph_row
*
9797 get_last_unchanged_at_beg_row (w
)
9800 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
9801 struct glyph_row
*row
;
9802 struct glyph_row
*row_found
= NULL
;
9803 int yb
= window_text_bottom_y (w
);
9805 /* Find the last row displaying unchanged text. */
9806 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9807 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
9808 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
9810 if (/* If row ends before first_changed_pos, it is unchanged,
9811 except in some case. */
9812 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
9813 /* When row ends in ZV and we write at ZV it is not
9815 && !row
->ends_at_zv_p
9816 /* When first_changed_pos is the end of a continued line,
9817 row is not unchanged because it may be no longer
9819 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
9820 && row
->continued_p
))
9823 /* Stop if last visible row. */
9824 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
9834 /* Find the first glyph row in the current matrix of W that is not
9835 affected by changes at the end of current_buffer since the last
9836 time the window was redisplayed. Return in *DELTA the number of
9837 chars by which buffer positions in unchanged text at the end of
9838 current_buffer must be adjusted. Return in *DELTA_BYTES the
9839 corresponding number of bytes. Value is null if no such row
9840 exists, i.e. all rows are affected by changes. */
9842 static struct glyph_row
*
9843 get_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
9845 int *delta
, *delta_bytes
;
9847 struct glyph_row
*row
;
9848 struct glyph_row
*row_found
= NULL
;
9850 *delta
= *delta_bytes
= 0;
9852 /* A value of window_end_pos >= end_unchanged means that the window
9853 end is in the range of changed text. If so, there is no
9854 unchanged row at the end of W's current matrix. */
9855 xassert (!NILP (w
->window_end_valid
));
9856 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
9859 /* Set row to the last row in W's current matrix displaying text. */
9860 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
9862 /* If matrix is entirely empty, no unchanged row exists. */
9863 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9865 /* The value of row is the last glyph row in the matrix having a
9866 meaningful buffer position in it. The end position of row
9867 corresponds to window_end_pos. This allows us to translate
9868 buffer positions in the current matrix to current buffer
9869 positions for characters not in changed text. */
9870 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
9871 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
9872 int last_unchanged_pos
, last_unchanged_pos_old
;
9873 struct glyph_row
*first_text_row
9874 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9877 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
9879 /* Set last_unchanged_pos to the buffer position of the last
9880 character in the buffer that has not been changed. Z is the
9881 index + 1 of the last byte in current_buffer, i.e. by
9882 subtracting end_unchanged we get the index of the last
9883 unchanged character, and we have to add BEG to get its buffer
9885 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
9886 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
9888 /* Search backward from ROW for a row displaying a line that
9889 starts at a minimum position >= last_unchanged_pos_old. */
9890 while (row
>= first_text_row
)
9892 xassert (row
->enabled_p
);
9893 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
));
9895 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
9901 xassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
9906 /* Make sure that glyph rows in the current matrix of window W
9907 reference the same glyph memory as corresponding rows in the
9908 frame's frame matrix. This function is called after scrolling W's
9909 current matrix on a terminal frame in try_window_id and
9910 try_window_reusing_current_matrix. */
9913 sync_frame_with_window_matrix_rows (w
)
9916 struct frame
*f
= XFRAME (w
->frame
);
9917 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
9919 /* Preconditions: W must be a leaf window and full-width. Its frame
9920 must have a frame matrix. */
9921 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
9922 xassert (WINDOW_FULL_WIDTH_P (w
));
9923 xassert (!FRAME_WINDOW_P (f
));
9925 /* If W is a full-width window, glyph pointers in W's current matrix
9926 have, by definition, to be the same as glyph pointers in the
9927 corresponding frame matrix. */
9928 window_row
= w
->current_matrix
->rows
;
9929 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
9930 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
9931 while (window_row
< window_row_end
)
9935 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
9936 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
9938 /* Disable frame rows whose corresponding window rows have
9939 been disabled in try_window_id. */
9940 if (!window_row
->enabled_p
)
9941 frame_row
->enabled_p
= 0;
9943 ++window_row
, ++frame_row
;
9948 /* Find the glyph row in window W containing CHARPOS. Consider all
9949 rows between START and END (not inclusive). END null means search
9950 all rows to the end of the display area of W. Value is the row
9951 containing CHARPOS or null. */
9953 static struct glyph_row
*
9954 row_containing_pos (w
, charpos
, start
, end
)
9957 struct glyph_row
*start
, *end
;
9959 struct glyph_row
*row
= start
;
9962 /* If we happen to start on a header-line, skip that. */
9963 if (row
->mode_line_p
)
9966 if ((end
&& row
>= end
) || !row
->enabled_p
)
9969 last_y
= window_text_bottom_y (w
);
9971 while ((end
== NULL
|| row
< end
)
9972 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
9973 /* The end position of a row equals the start
9974 position of the next row. If CHARPOS is there, we
9975 would rather display it in the next line, except
9976 when this line ends in ZV. */
9977 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
9978 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
9979 || !row
->ends_at_zv_p
)))
9980 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9983 /* Give up if CHARPOS not found. */
9984 if ((end
&& row
>= end
)
9985 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
9986 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
9993 /* Try to redisplay window W by reusing its existing display. W's
9994 current matrix must be up to date when this function is called,
9995 i.e. window_end_valid must not be nil.
9999 1 if display has been updated
10000 0 if otherwise unsuccessful
10001 -1 if redisplay with same window start is known not to succeed
10003 The following steps are performed:
10005 1. Find the last row in the current matrix of W that is not
10006 affected by changes at the start of current_buffer. If no such row
10009 2. Find the first row in W's current matrix that is not affected by
10010 changes at the end of current_buffer. Maybe there is no such row.
10012 3. Display lines beginning with the row + 1 found in step 1 to the
10013 row found in step 2 or, if step 2 didn't find a row, to the end of
10016 4. If cursor is not known to appear on the window, give up.
10018 5. If display stopped at the row found in step 2, scroll the
10019 display and current matrix as needed.
10021 6. Maybe display some lines at the end of W, if we must. This can
10022 happen under various circumstances, like a partially visible line
10023 becoming fully visible, or because newly displayed lines are displayed
10024 in smaller font sizes.
10026 7. Update W's window end information. */
10028 /* Check that window end is what we expect it to be. */
10034 struct frame
*f
= XFRAME (w
->frame
);
10035 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
10036 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
10037 struct glyph_row
*last_unchanged_at_beg_row
;
10038 struct glyph_row
*first_unchanged_at_end_row
;
10039 struct glyph_row
*row
;
10040 struct glyph_row
*bottom_row
;
10043 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
10044 struct text_pos start_pos
;
10046 int first_unchanged_at_end_vpos
= 0;
10047 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
10048 struct text_pos start
;
10050 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10052 /* Check pre-conditions. Window end must be valid, otherwise
10053 the current matrix would not be up to date. */
10054 xassert (!NILP (w
->window_end_valid
));
10055 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
10056 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
10058 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
10059 only if buffer has really changed. The reason is that the gap is
10060 initially at Z for freshly visited files. The code below would
10061 set end_unchanged to 0 in that case. */
10062 if (MODIFF
> SAVE_MODIFF
10063 /* This seems to happen sometimes after saving a buffer. */
10064 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
10066 if (GPT
- BEG
< BEG_UNCHANGED
)
10067 BEG_UNCHANGED
= GPT
- BEG
;
10068 if (Z
- GPT
< END_UNCHANGED
)
10069 END_UNCHANGED
= Z
- GPT
;
10072 /* If window starts after a line end, and the last change is in
10073 front of that newline, then changes don't affect the display.
10074 This case happens with stealth-fontification. Note that although
10075 the display is unchanged, glyph positions in the matrix have to
10076 be adjusted, of course. */
10077 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10078 if (CHARPOS (start
) > BEGV
10079 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
10080 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
10081 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10083 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
10084 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
10088 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10089 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
10091 increment_matrix_positions (w
->current_matrix
,
10092 MATRIX_ROW_VPOS (r0
, current_matrix
),
10093 MATRIX_ROW_VPOS (r1
, current_matrix
),
10094 delta
, delta_bytes
);
10097 #if 0 /* If changes are all in front of the window start, the
10098 distance of the last displayed glyph from Z hasn't
10101 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10102 w
->window_end_bytepos
10103 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10109 /* Return quickly if changes are all below what is displayed in the
10110 window, and if PT is in the window. */
10111 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
10112 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10114 /* We have to update window end positions because the buffer's
10115 size has changed. */
10117 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10118 w
->window_end_bytepos
10119 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10123 /* Check that window start agrees with the start of the first glyph
10124 row in its current matrix. Check this after we know the window
10125 start is not in changed text, otherwise positions would not be
10127 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10128 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
10131 /* Compute the position at which we have to start displaying new
10132 lines. Some of the lines at the top of the window might be
10133 reusable because they are not displaying changed text. Find the
10134 last row in W's current matrix not affected by changes at the
10135 start of current_buffer. Value is null if changes start in the
10136 first line of window. */
10137 last_unchanged_at_beg_row
= get_last_unchanged_at_beg_row (w
);
10138 if (last_unchanged_at_beg_row
)
10140 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
10141 start_pos
= it
.current
.pos
;
10143 /* Start displaying new lines in the desired matrix at the same
10144 vpos we would use in the current matrix, i.e. below
10145 last_unchanged_at_beg_row. */
10146 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
10148 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10149 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
10151 xassert (it
.hpos
== 0 && it
.current_x
== 0);
10155 /* There are no reusable lines at the start of the window.
10156 Start displaying in the first line. */
10157 start_display (&it
, w
, start
);
10158 start_pos
= it
.current
.pos
;
10161 /* Find the first row that is not affected by changes at the end of
10162 the buffer. Value will be null if there is no unchanged row, in
10163 which case we must redisplay to the end of the window. delta
10164 will be set to the value by which buffer positions beginning with
10165 first_unchanged_at_end_row have to be adjusted due to text
10167 first_unchanged_at_end_row
10168 = get_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
10169 IF_DEBUG (debug_delta
= delta
);
10170 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
10172 /* Set stop_pos to the buffer position up to which we will have to
10173 display new lines. If first_unchanged_at_end_row != NULL, this
10174 is the buffer position of the start of the line displayed in that
10175 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
10176 that we don't stop at a buffer position. */
10178 if (first_unchanged_at_end_row
)
10180 xassert (last_unchanged_at_beg_row
== NULL
10181 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
10183 /* If this is a continuation line, move forward to the next one
10184 that isn't. Changes in lines above affect this line.
10185 Caution: this may move first_unchanged_at_end_row to a row
10186 not displaying text. */
10187 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
10188 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10189 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10190 < it
.last_visible_y
))
10191 ++first_unchanged_at_end_row
;
10193 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10194 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10195 >= it
.last_visible_y
))
10196 first_unchanged_at_end_row
= NULL
;
10199 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
10201 first_unchanged_at_end_vpos
10202 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
10203 xassert (stop_pos
>= Z
- END_UNCHANGED
);
10206 else if (last_unchanged_at_beg_row
== NULL
)
10212 /* Either there is no unchanged row at the end, or the one we have
10213 now displays text. This is a necessary condition for the window
10214 end pos calculation at the end of this function. */
10215 xassert (first_unchanged_at_end_row
== NULL
10216 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
10218 debug_last_unchanged_at_beg_vpos
10219 = (last_unchanged_at_beg_row
10220 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
10222 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
10224 #endif /* GLYPH_DEBUG != 0 */
10227 /* Display new lines. Set last_text_row to the last new line
10228 displayed which has text on it, i.e. might end up as being the
10229 line where the window_end_vpos is. */
10230 w
->cursor
.vpos
= -1;
10231 last_text_row
= NULL
;
10232 overlay_arrow_seen
= 0;
10233 while (it
.current_y
< it
.last_visible_y
10234 && !fonts_changed_p
10235 && (first_unchanged_at_end_row
== NULL
10236 || IT_CHARPOS (it
) < stop_pos
))
10238 if (display_line (&it
))
10239 last_text_row
= it
.glyph_row
- 1;
10242 if (fonts_changed_p
)
10246 /* Compute differences in buffer positions, y-positions etc. for
10247 lines reused at the bottom of the window. Compute what we can
10249 if (first_unchanged_at_end_row
10250 /* No lines reused because we displayed everything up to the
10251 bottom of the window. */
10252 && it
.current_y
< it
.last_visible_y
)
10255 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
10257 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
10258 run
.current_y
= first_unchanged_at_end_row
->y
;
10259 run
.desired_y
= run
.current_y
+ dy
;
10260 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
10264 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
10265 first_unchanged_at_end_row
= NULL
;
10267 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
10270 /* Find the cursor if not already found. We have to decide whether
10271 PT will appear on this window (it sometimes doesn't, but this is
10272 not a very frequent case.) This decision has to be made before
10273 the current matrix is altered. A value of cursor.vpos < 0 means
10274 that PT is either in one of the lines beginning at
10275 first_unchanged_at_end_row or below the window. Don't care for
10276 lines that might be displayed later at the window end; as
10277 mentioned, this is not a frequent case. */
10278 if (w
->cursor
.vpos
< 0)
10280 /* Cursor in unchanged rows at the top? */
10281 if (PT
< CHARPOS (start_pos
)
10282 && last_unchanged_at_beg_row
)
10284 row
= row_containing_pos (w
, PT
,
10285 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
10286 last_unchanged_at_beg_row
+ 1);
10287 xassert (row
&& row
<= last_unchanged_at_beg_row
);
10288 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10291 /* Start from first_unchanged_at_end_row looking for PT. */
10292 else if (first_unchanged_at_end_row
)
10294 row
= row_containing_pos (w
, PT
- delta
,
10295 first_unchanged_at_end_row
, NULL
);
10297 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
10298 delta_bytes
, dy
, dvpos
);
10301 /* Give up if cursor was not found. */
10302 if (w
->cursor
.vpos
< 0)
10304 clear_glyph_matrix (w
->desired_matrix
);
10309 /* Don't let the cursor end in the scroll margins. */
10311 int this_scroll_margin
, cursor_height
;
10313 this_scroll_margin
= max (0, scroll_margin
);
10314 this_scroll_margin
= min (this_scroll_margin
,
10315 XFASTINT (w
->height
) / 4);
10316 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
10317 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
10319 if ((w
->cursor
.y
< this_scroll_margin
10320 && CHARPOS (start
) > BEGV
)
10321 /* Don't take scroll margin into account at the bottom because
10322 old redisplay didn't do it either. */
10323 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
10325 w
->cursor
.vpos
= -1;
10326 clear_glyph_matrix (w
->desired_matrix
);
10331 /* Scroll the display. Do it before changing the current matrix so
10332 that xterm.c doesn't get confused about where the cursor glyph is
10334 if (dy
&& run
.height
)
10338 if (FRAME_WINDOW_P (f
))
10340 rif
->update_window_begin_hook (w
);
10341 rif
->scroll_run_hook (w
, &run
);
10342 rif
->update_window_end_hook (w
, 0);
10346 /* Terminal frame. In this case, dvpos gives the number of
10347 lines to scroll by; dvpos < 0 means scroll up. */
10348 int first_unchanged_at_end_vpos
10349 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
10350 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
10351 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
10353 /* Perform the operation on the screen. */
10356 /* Scroll last_unchanged_at_beg_row to the end of the
10357 window down dvpos lines. */
10358 set_terminal_window (end
);
10360 /* On dumb terminals delete dvpos lines at the end
10361 before inserting dvpos empty lines. */
10362 if (!scroll_region_ok
)
10363 ins_del_lines (end
- dvpos
, -dvpos
);
10365 /* Insert dvpos empty lines in front of
10366 last_unchanged_at_beg_row. */
10367 ins_del_lines (from
, dvpos
);
10369 else if (dvpos
< 0)
10371 /* Scroll up last_unchanged_at_beg_vpos to the end of
10372 the window to last_unchanged_at_beg_vpos - |dvpos|. */
10373 set_terminal_window (end
);
10375 /* Delete dvpos lines in front of
10376 last_unchanged_at_beg_vpos. ins_del_lines will set
10377 the cursor to the given vpos and emit |dvpos| delete
10379 ins_del_lines (from
+ dvpos
, dvpos
);
10381 /* On a dumb terminal insert dvpos empty lines at the
10383 if (!scroll_region_ok
)
10384 ins_del_lines (end
+ dvpos
, -dvpos
);
10387 set_terminal_window (0);
10393 /* Shift reused rows of the current matrix to the right position.
10394 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
10396 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10397 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
10400 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
10401 bottom_vpos
, dvpos
);
10402 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
10405 else if (dvpos
> 0)
10407 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
10408 bottom_vpos
, dvpos
);
10409 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
10410 first_unchanged_at_end_vpos
+ dvpos
, 0);
10413 /* For frame-based redisplay, make sure that current frame and window
10414 matrix are in sync with respect to glyph memory. */
10415 if (!FRAME_WINDOW_P (f
))
10416 sync_frame_with_window_matrix_rows (w
);
10418 /* Adjust buffer positions in reused rows. */
10420 increment_matrix_positions (current_matrix
,
10421 first_unchanged_at_end_vpos
+ dvpos
,
10422 bottom_vpos
, delta
, delta_bytes
);
10424 /* Adjust Y positions. */
10426 shift_glyph_matrix (w
, current_matrix
,
10427 first_unchanged_at_end_vpos
+ dvpos
,
10430 if (first_unchanged_at_end_row
)
10431 first_unchanged_at_end_row
+= dvpos
;
10433 /* If scrolling up, there may be some lines to display at the end of
10435 last_text_row_at_end
= NULL
;
10438 /* Set last_row to the glyph row in the current matrix where the
10439 window end line is found. It has been moved up or down in
10440 the matrix by dvpos. */
10441 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
10442 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
10444 /* If last_row is the window end line, it should display text. */
10445 xassert (last_row
->displays_text_p
);
10447 /* If window end line was partially visible before, begin
10448 displaying at that line. Otherwise begin displaying with the
10449 line following it. */
10450 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
10452 init_to_row_start (&it
, w
, last_row
);
10453 it
.vpos
= last_vpos
;
10454 it
.current_y
= last_row
->y
;
10458 init_to_row_end (&it
, w
, last_row
);
10459 it
.vpos
= 1 + last_vpos
;
10460 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
10464 /* We may start in a continuation line. If so, we have to get
10465 the right continuation_lines_width and current_x. */
10466 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
10467 it
.hpos
= it
.current_x
= 0;
10469 /* Display the rest of the lines at the window end. */
10470 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10471 while (it
.current_y
< it
.last_visible_y
10472 && !fonts_changed_p
)
10474 /* Is it always sure that the display agrees with lines in
10475 the current matrix? I don't think so, so we mark rows
10476 displayed invalid in the current matrix by setting their
10477 enabled_p flag to zero. */
10478 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
10479 if (display_line (&it
))
10480 last_text_row_at_end
= it
.glyph_row
- 1;
10484 /* Update window_end_pos and window_end_vpos. */
10485 if (first_unchanged_at_end_row
10486 && first_unchanged_at_end_row
->y
< it
.last_visible_y
10487 && !last_text_row_at_end
)
10489 /* Window end line if one of the preserved rows from the current
10490 matrix. Set row to the last row displaying text in current
10491 matrix starting at first_unchanged_at_end_row, after
10493 xassert (first_unchanged_at_end_row
->displays_text_p
);
10494 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
10495 first_unchanged_at_end_row
);
10496 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
10498 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
10499 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10500 XSETFASTINT (w
->window_end_vpos
,
10501 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
10503 else if (last_text_row_at_end
)
10505 XSETFASTINT (w
->window_end_pos
,
10506 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
10507 w
->window_end_bytepos
10508 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
10509 XSETFASTINT (w
->window_end_vpos
,
10510 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
10512 else if (last_text_row
)
10514 /* We have displayed either to the end of the window or at the
10515 end of the window, i.e. the last row with text is to be found
10516 in the desired matrix. */
10517 XSETFASTINT (w
->window_end_pos
,
10518 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10519 w
->window_end_bytepos
10520 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10521 XSETFASTINT (w
->window_end_vpos
,
10522 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
10524 else if (first_unchanged_at_end_row
== NULL
10525 && last_text_row
== NULL
10526 && last_text_row_at_end
== NULL
)
10528 /* Displayed to end of window, but no line containing text was
10529 displayed. Lines were deleted at the end of the window. */
10531 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
10533 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
10534 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10535 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
10536 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10537 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
10540 w
->window_end_vpos
= make_number (vpos
);
10545 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
10546 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
10548 /* Record that display has not been completed. */
10549 w
->window_end_valid
= Qnil
;
10550 w
->desired_matrix
->no_scrolling_p
= 1;
10556 /***********************************************************************
10557 More debugging support
10558 ***********************************************************************/
10562 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
10563 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
10566 /* Dump the contents of glyph matrix MATRIX on stderr. If
10567 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
10570 dump_glyph_matrix (matrix
, with_glyphs_p
)
10571 struct glyph_matrix
*matrix
;
10575 for (i
= 0; i
< matrix
->nrows
; ++i
)
10576 dump_glyph_row (matrix
, i
, with_glyphs_p
);
10580 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
10581 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
10584 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
10585 struct glyph_matrix
*matrix
;
10586 int vpos
, with_glyphs_p
;
10588 struct glyph_row
*row
;
10590 if (vpos
< 0 || vpos
>= matrix
->nrows
)
10593 row
= MATRIX_ROW (matrix
, vpos
);
10595 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFes X Y W\n");
10596 fprintf (stderr
, "=============================================\n");
10598 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%1.1d%1.1d %4d %4d %4d\n",
10599 row
- matrix
->rows
,
10600 MATRIX_ROW_START_CHARPOS (row
),
10601 MATRIX_ROW_END_CHARPOS (row
),
10602 row
->used
[TEXT_AREA
],
10603 row
->contains_overlapping_glyphs_p
,
10606 row
->truncated_on_left_p
,
10607 row
->truncated_on_right_p
,
10608 row
->overlay_arrow_p
,
10610 MATRIX_ROW_CONTINUATION_LINE_P (row
),
10611 row
->displays_text_p
,
10614 row
->ends_in_middle_of_char_p
,
10615 row
->starts_in_middle_of_char_p
,
10619 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
10620 row
->end
.overlay_string_index
);
10621 fprintf (stderr
, "%9d %5d\n",
10622 CHARPOS (row
->start
.string_pos
),
10623 CHARPOS (row
->end
.string_pos
));
10624 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
10625 row
->end
.dpvec_index
);
10629 struct glyph
*glyph
, *glyph_end
;
10630 int prev_had_glyphs_p
;
10632 glyph
= row
->glyphs
[TEXT_AREA
];
10633 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
10635 /* Glyph for a line end in text. */
10636 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
10639 if (glyph
< glyph_end
)
10641 fprintf (stderr
, " Glyph Type Pos W Code C Face LR\n");
10642 prev_had_glyphs_p
= 1;
10645 prev_had_glyphs_p
= 0;
10647 while (glyph
< glyph_end
)
10649 if (glyph
->type
== CHAR_GLYPH
)
10652 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10653 glyph
- row
->glyphs
[TEXT_AREA
],
10656 glyph
->pixel_width
,
10658 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
10662 glyph
->left_box_line_p
,
10663 glyph
->right_box_line_p
);
10665 else if (glyph
->type
== STRETCH_GLYPH
)
10668 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10669 glyph
- row
->glyphs
[TEXT_AREA
],
10672 glyph
->pixel_width
,
10676 glyph
->left_box_line_p
,
10677 glyph
->right_box_line_p
);
10679 else if (glyph
->type
== IMAGE_GLYPH
)
10682 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10683 glyph
- row
->glyphs
[TEXT_AREA
],
10686 glyph
->pixel_width
,
10690 glyph
->left_box_line_p
,
10691 glyph
->right_box_line_p
);
10699 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
10700 Sdump_glyph_matrix
, 0, 1, "p",
10701 "Dump the current matrix of the selected window to stderr.\n\
10702 Shows contents of glyph row structures. With non-nil optional\n\
10703 parameter WITH-GLYPHS-P, dump glyphs as well.")
10705 Lisp_Object with_glyphs_p
;
10707 struct window
*w
= XWINDOW (selected_window
);
10708 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10710 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
10711 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
10712 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
10713 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
10714 fprintf (stderr
, "=============================================\n");
10715 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
10720 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
10721 "Dump glyph row ROW to stderr.")
10725 CHECK_NUMBER (row
, 0);
10726 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
10731 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
,
10735 struct frame
*sf
= SELECTED_FRAME ();
10736 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)
10738 dump_glyph_row (m
, 0, 1);
10743 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
10744 Strace_redisplay_toggle
, 0, 0, "",
10745 "Toggle tracing of redisplay.")
10748 trace_redisplay_p
= !trace_redisplay_p
;
10753 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
10754 "Print STRING to stderr.")
10756 Lisp_Object string
;
10758 CHECK_STRING (string
, 0);
10759 fprintf (stderr
, "%s", XSTRING (string
)->data
);
10763 #endif /* GLYPH_DEBUG */
10767 /***********************************************************************
10768 Building Desired Matrix Rows
10769 ***********************************************************************/
10771 /* Return a temporary glyph row holding the glyphs of an overlay
10772 arrow. Only used for non-window-redisplay windows. */
10774 static struct glyph_row
*
10775 get_overlay_arrow_glyph_row (w
)
10778 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10779 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10780 struct buffer
*old
= current_buffer
;
10781 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
10782 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
10783 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
10787 int n_glyphs_before
;
10789 set_buffer_temp (buffer
);
10790 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
10791 it
.glyph_row
->used
[TEXT_AREA
] = 0;
10792 SET_TEXT_POS (it
.position
, 0, 0);
10794 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
10796 while (p
< arrow_end
)
10798 Lisp_Object face
, ilisp
;
10800 /* Get the next character. */
10802 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
10804 it
.c
= *p
, it
.len
= 1;
10807 /* Get its face. */
10808 XSETFASTINT (ilisp
, p
- arrow_string
);
10809 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
10810 it
.face_id
= compute_char_face (f
, it
.c
, face
);
10812 /* Compute its width, get its glyphs. */
10813 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
10814 SET_TEXT_POS (it
.position
, -1, -1);
10815 PRODUCE_GLYPHS (&it
);
10817 /* If this character doesn't fit any more in the line, we have
10818 to remove some glyphs. */
10819 if (it
.current_x
> it
.last_visible_x
)
10821 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
10826 set_buffer_temp (old
);
10827 return it
.glyph_row
;
10831 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
10832 glyphs are only inserted for terminal frames since we can't really
10833 win with truncation glyphs when partially visible glyphs are
10834 involved. Which glyphs to insert is determined by
10835 produce_special_glyphs. */
10838 insert_left_trunc_glyphs (it
)
10841 struct it truncate_it
;
10842 struct glyph
*from
, *end
, *to
, *toend
;
10844 xassert (!FRAME_WINDOW_P (it
->f
));
10846 /* Get the truncation glyphs. */
10848 truncate_it
.current_x
= 0;
10849 truncate_it
.face_id
= DEFAULT_FACE_ID
;
10850 truncate_it
.glyph_row
= &scratch_glyph_row
;
10851 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
10852 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
10853 truncate_it
.object
= make_number (0);
10854 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
10856 /* Overwrite glyphs from IT with truncation glyphs. */
10857 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
10858 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
10859 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
10860 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
10865 /* There may be padding glyphs left over. Remove them. */
10867 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
10869 while (from
< toend
)
10872 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
10876 /* Compute the pixel height and width of IT->glyph_row.
10878 Most of the time, ascent and height of a display line will be equal
10879 to the max_ascent and max_height values of the display iterator
10880 structure. This is not the case if
10882 1. We hit ZV without displaying anything. In this case, max_ascent
10883 and max_height will be zero.
10885 2. We have some glyphs that don't contribute to the line height.
10886 (The glyph row flag contributes_to_line_height_p is for future
10887 pixmap extensions).
10889 The first case is easily covered by using default values because in
10890 these cases, the line height does not really matter, except that it
10891 must not be zero. */
10894 compute_line_metrics (it
)
10897 struct glyph_row
*row
= it
->glyph_row
;
10900 if (FRAME_WINDOW_P (it
->f
))
10902 int i
, header_line_height
;
10904 /* The line may consist of one space only, that was added to
10905 place the cursor on it. If so, the row's height hasn't been
10907 if (row
->height
== 0)
10909 if (it
->max_ascent
+ it
->max_descent
== 0)
10910 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
10911 row
->ascent
= it
->max_ascent
;
10912 row
->height
= it
->max_ascent
+ it
->max_descent
;
10913 row
->phys_ascent
= it
->max_phys_ascent
;
10914 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
10917 /* Compute the width of this line. */
10918 row
->pixel_width
= row
->x
;
10919 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
10920 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10922 xassert (row
->pixel_width
>= 0);
10923 xassert (row
->ascent
>= 0 && row
->height
> 0);
10925 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
10926 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
10928 /* If first line's physical ascent is larger than its logical
10929 ascent, use the physical ascent, and make the row taller.
10930 This makes accented characters fully visible. */
10931 if (row
== it
->w
->desired_matrix
->rows
10932 && row
->phys_ascent
> row
->ascent
)
10934 row
->height
+= row
->phys_ascent
- row
->ascent
;
10935 row
->ascent
= row
->phys_ascent
;
10938 /* Compute how much of the line is visible. */
10939 row
->visible_height
= row
->height
;
10941 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
10942 if (row
->y
< header_line_height
)
10943 row
->visible_height
-= header_line_height
- row
->y
;
10946 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
10947 if (row
->y
+ row
->height
> max_y
)
10948 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10953 row
->pixel_width
= row
->used
[TEXT_AREA
];
10954 row
->ascent
= row
->phys_ascent
= 0;
10955 row
->height
= row
->phys_height
= row
->visible_height
= 1;
10958 /* Compute a hash code for this row. */
10960 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
10961 for (i
= 0; i
< row
->used
[area
]; ++i
)
10962 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
10963 + row
->glyphs
[area
][i
].u
.val
10964 + row
->glyphs
[area
][i
].face_id
10965 + row
->glyphs
[area
][i
].padding_p
10966 + (row
->glyphs
[area
][i
].type
<< 2));
10968 it
->max_ascent
= it
->max_descent
= 0;
10969 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
10973 /* Append one space to the glyph row of iterator IT if doing a
10974 window-based redisplay. DEFAULT_FACE_P non-zero means let the
10975 space have the default face, otherwise let it have the same face as
10976 IT->face_id. Value is non-zero if a space was added.
10978 This function is called to make sure that there is always one glyph
10979 at the end of a glyph row that the cursor can be set on under
10980 window-systems. (If there weren't such a glyph we would not know
10981 how wide and tall a box cursor should be displayed).
10983 At the same time this space let's a nicely handle clearing to the
10984 end of the line if the row ends in italic text. */
10987 append_space (it
, default_face_p
)
10989 int default_face_p
;
10991 if (FRAME_WINDOW_P (it
->f
))
10993 int n
= it
->glyph_row
->used
[TEXT_AREA
];
10995 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
10996 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
10998 /* Save some values that must not be changed. */
10999 int saved_x
= it
->current_x
;
11000 struct text_pos saved_pos
;
11001 int saved_what
= it
->what
;
11002 int saved_face_id
= it
->face_id
;
11003 Lisp_Object saved_object
;
11006 saved_object
= it
->object
;
11007 saved_pos
= it
->position
;
11009 it
->what
= IT_CHARACTER
;
11010 bzero (&it
->position
, sizeof it
->position
);
11011 it
->object
= make_number (0);
11015 if (default_face_p
)
11016 it
->face_id
= DEFAULT_FACE_ID
;
11017 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11018 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
11020 PRODUCE_GLYPHS (it
);
11022 it
->current_x
= saved_x
;
11023 it
->object
= saved_object
;
11024 it
->position
= saved_pos
;
11025 it
->what
= saved_what
;
11026 it
->face_id
= saved_face_id
;
11035 /* Extend the face of the last glyph in the text area of IT->glyph_row
11036 to the end of the display line. Called from display_line.
11037 If the glyph row is empty, add a space glyph to it so that we
11038 know the face to draw. Set the glyph row flag fill_line_p. */
11041 extend_face_to_end_of_line (it
)
11045 struct frame
*f
= it
->f
;
11047 /* If line is already filled, do nothing. */
11048 if (it
->current_x
>= it
->last_visible_x
)
11051 /* Face extension extends the background and box of IT->face_id
11052 to the end of the line. If the background equals the background
11053 of the frame, we haven't to do anything. */
11054 face
= FACE_FROM_ID (f
, it
->face_id
);
11055 if (FRAME_WINDOW_P (f
)
11056 && face
->box
== FACE_NO_BOX
11057 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
11061 /* Set the glyph row flag indicating that the face of the last glyph
11062 in the text area has to be drawn to the end of the text area. */
11063 it
->glyph_row
->fill_line_p
= 1;
11065 /* If current character of IT is not ASCII, make sure we have the
11066 ASCII face. This will be automatically undone the next time
11067 get_next_display_element returns a multibyte character. Note
11068 that the character will always be single byte in unibyte text. */
11069 if (!SINGLE_BYTE_CHAR_P (it
->c
))
11071 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
11074 if (FRAME_WINDOW_P (f
))
11076 /* If the row is empty, add a space with the current face of IT,
11077 so that we know which face to draw. */
11078 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
11080 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
11081 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
11082 it
->glyph_row
->used
[TEXT_AREA
] = 1;
11087 /* Save some values that must not be changed. */
11088 int saved_x
= it
->current_x
;
11089 struct text_pos saved_pos
;
11090 Lisp_Object saved_object
;
11091 int saved_what
= it
->what
;
11093 saved_object
= it
->object
;
11094 saved_pos
= it
->position
;
11096 it
->what
= IT_CHARACTER
;
11097 bzero (&it
->position
, sizeof it
->position
);
11098 it
->object
= make_number (0);
11102 PRODUCE_GLYPHS (it
);
11104 while (it
->current_x
<= it
->last_visible_x
)
11105 PRODUCE_GLYPHS (it
);
11107 /* Don't count these blanks really. It would let us insert a left
11108 truncation glyph below and make us set the cursor on them, maybe. */
11109 it
->current_x
= saved_x
;
11110 it
->object
= saved_object
;
11111 it
->position
= saved_pos
;
11112 it
->what
= saved_what
;
11117 /* Value is non-zero if text starting at CHARPOS in current_buffer is
11118 trailing whitespace. */
11121 trailing_whitespace_p (charpos
)
11124 int bytepos
= CHAR_TO_BYTE (charpos
);
11127 while (bytepos
< ZV_BYTE
11128 && (c
= FETCH_CHAR (bytepos
),
11129 c
== ' ' || c
== '\t'))
11132 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
11134 if (bytepos
!= PT_BYTE
)
11141 /* Highlight trailing whitespace, if any, in ROW. */
11144 highlight_trailing_whitespace (f
, row
)
11146 struct glyph_row
*row
;
11148 int used
= row
->used
[TEXT_AREA
];
11152 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
11153 struct glyph
*glyph
= start
+ used
- 1;
11155 /* Skip over the space glyph inserted to display the
11156 cursor at the end of a line. */
11157 if (glyph
->type
== CHAR_GLYPH
11158 && glyph
->u
.ch
== ' '
11159 && INTEGERP (glyph
->object
))
11162 /* If last glyph is a space or stretch, and it's trailing
11163 whitespace, set the face of all trailing whitespace glyphs in
11164 IT->glyph_row to `trailing-whitespace'. */
11166 && BUFFERP (glyph
->object
)
11167 && (glyph
->type
== STRETCH_GLYPH
11168 || (glyph
->type
== CHAR_GLYPH
11169 && glyph
->u
.ch
== ' '))
11170 && trailing_whitespace_p (glyph
->charpos
))
11172 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
11174 while (glyph
>= start
11175 && BUFFERP (glyph
->object
)
11176 && (glyph
->type
== STRETCH_GLYPH
11177 || (glyph
->type
== CHAR_GLYPH
11178 && glyph
->u
.ch
== ' ')))
11179 (glyph
--)->face_id
= face_id
;
11185 /* Construct the glyph row IT->glyph_row in the desired matrix of
11186 IT->w from text at the current position of IT. See dispextern.h
11187 for an overview of struct it. Value is non-zero if
11188 IT->glyph_row displays text, as opposed to a line displaying ZV
11195 struct glyph_row
*row
= it
->glyph_row
;
11197 /* We always start displaying at hpos zero even if hscrolled. */
11198 xassert (it
->hpos
== 0 && it
->current_x
== 0);
11200 /* We must not display in a row that's not a text row. */
11201 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
11202 < it
->w
->desired_matrix
->nrows
);
11204 /* Is IT->w showing the region? */
11205 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
11207 /* Clear the result glyph row and enable it. */
11208 prepare_desired_row (row
);
11210 row
->y
= it
->current_y
;
11211 row
->start
= it
->current
;
11212 row
->continuation_lines_width
= it
->continuation_lines_width
;
11213 row
->displays_text_p
= 1;
11214 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
11215 it
->starts_in_middle_of_char_p
= 0;
11217 /* Arrange the overlays nicely for our purposes. Usually, we call
11218 display_line on only one line at a time, in which case this
11219 can't really hurt too much, or we call it on lines which appear
11220 one after another in the buffer, in which case all calls to
11221 recenter_overlay_lists but the first will be pretty cheap. */
11222 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
11224 /* Move over display elements that are not visible because we are
11225 hscrolled. This may stop at an x-position < IT->first_visible_x
11226 if the first glyph is partially visible or if we hit a line end. */
11227 if (it
->current_x
< it
->first_visible_x
)
11228 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
11229 MOVE_TO_POS
| MOVE_TO_X
);
11231 /* Get the initial row height. This is either the height of the
11232 text hscrolled, if there is any, or zero. */
11233 row
->ascent
= it
->max_ascent
;
11234 row
->height
= it
->max_ascent
+ it
->max_descent
;
11235 row
->phys_ascent
= it
->max_phys_ascent
;
11236 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11238 /* Loop generating characters. The loop is left with IT on the next
11239 character to display. */
11242 int n_glyphs_before
, hpos_before
, x_before
;
11244 int ascent
, descent
, phys_ascent
, phys_descent
;
11246 /* Retrieve the next thing to display. Value is zero if end of
11248 if (!get_next_display_element (it
))
11250 /* Maybe add a space at the end of this line that is used to
11251 display the cursor there under X. Set the charpos of the
11252 first glyph of blank lines not corresponding to any text
11254 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
11255 || row
->used
[TEXT_AREA
] == 0)
11257 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
11258 row
->displays_text_p
= 0;
11260 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
11261 row
->indicate_empty_line_p
= 1;
11264 it
->continuation_lines_width
= 0;
11265 row
->ends_at_zv_p
= 1;
11269 /* Now, get the metrics of what we want to display. This also
11270 generates glyphs in `row' (which is IT->glyph_row). */
11271 n_glyphs_before
= row
->used
[TEXT_AREA
];
11274 /* Remember the line height so far in case the next element doesn't
11275 fit on the line. */
11276 if (!it
->truncate_lines_p
)
11278 ascent
= it
->max_ascent
;
11279 descent
= it
->max_descent
;
11280 phys_ascent
= it
->max_phys_ascent
;
11281 phys_descent
= it
->max_phys_descent
;
11284 PRODUCE_GLYPHS (it
);
11286 /* If this display element was in marginal areas, continue with
11288 if (it
->area
!= TEXT_AREA
)
11290 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11291 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11292 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11293 row
->phys_height
= max (row
->phys_height
,
11294 it
->max_phys_ascent
+ it
->max_phys_descent
);
11295 set_iterator_to_next (it
);
11299 /* Does the display element fit on the line? If we truncate
11300 lines, we should draw past the right edge of the window. If
11301 we don't truncate, we want to stop so that we can display the
11302 continuation glyph before the right margin. If lines are
11303 continued, there are two possible strategies for characters
11304 resulting in more than 1 glyph (e.g. tabs): Display as many
11305 glyphs as possible in this line and leave the rest for the
11306 continuation line, or display the whole element in the next
11307 line. Original redisplay did the former, so we do it also. */
11308 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11309 hpos_before
= it
->hpos
;
11313 && it
->current_x
< it
->last_visible_x
)
11316 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11317 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11318 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11319 row
->phys_height
= max (row
->phys_height
,
11320 it
->max_phys_ascent
+ it
->max_phys_descent
);
11321 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
11322 row
->x
= x
- it
->first_visible_x
;
11327 struct glyph
*glyph
;
11329 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
11331 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11332 new_x
= x
+ glyph
->pixel_width
;
11334 if (/* Lines are continued. */
11335 !it
->truncate_lines_p
11336 && (/* Glyph doesn't fit on the line. */
11337 new_x
> it
->last_visible_x
11338 /* Or it fits exactly on a window system frame. */
11339 || (new_x
== it
->last_visible_x
11340 && FRAME_WINDOW_P (it
->f
))))
11342 /* End of a continued line. */
11345 || (new_x
== it
->last_visible_x
11346 && FRAME_WINDOW_P (it
->f
)))
11348 /* Current glyph is the only one on the line or
11349 fits exactly on the line. We must continue
11350 the line because we can't draw the cursor
11351 after the glyph. */
11352 row
->continued_p
= 1;
11353 it
->current_x
= new_x
;
11354 it
->continuation_lines_width
+= new_x
;
11356 if (i
== nglyphs
- 1)
11357 set_iterator_to_next (it
);
11359 else if (CHAR_GLYPH_PADDING_P (*glyph
)
11360 && !FRAME_WINDOW_P (it
->f
))
11362 /* A padding glyph that doesn't fit on this line.
11363 This means the whole character doesn't fit
11365 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11367 /* Fill the rest of the row with continuation
11368 glyphs like in 20.x. */
11369 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
11370 < row
->glyphs
[1 + TEXT_AREA
])
11371 produce_special_glyphs (it
, IT_CONTINUATION
);
11373 row
->continued_p
= 1;
11374 it
->current_x
= x_before
;
11375 it
->continuation_lines_width
+= x_before
;
11377 /* Restore the height to what it was before the
11378 element not fitting on the line. */
11379 it
->max_ascent
= ascent
;
11380 it
->max_descent
= descent
;
11381 it
->max_phys_ascent
= phys_ascent
;
11382 it
->max_phys_descent
= phys_descent
;
11386 /* Display element draws past the right edge of
11387 the window. Restore positions to values
11388 before the element. The next line starts
11389 with current_x before the glyph that could
11390 not be displayed, so that TAB works right. */
11391 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11393 /* Display continuation glyphs. */
11394 if (!FRAME_WINDOW_P (it
->f
))
11395 produce_special_glyphs (it
, IT_CONTINUATION
);
11396 row
->continued_p
= 1;
11399 it
->continuation_lines_width
+= x
;
11400 if (nglyphs
> 1 && i
> 0)
11402 row
->ends_in_middle_of_char_p
= 1;
11403 it
->starts_in_middle_of_char_p
= 1;
11406 /* Restore the height to what it was before the
11407 element not fitting on the line. */
11408 it
->max_ascent
= ascent
;
11409 it
->max_descent
= descent
;
11410 it
->max_phys_ascent
= phys_ascent
;
11411 it
->max_phys_descent
= phys_descent
;
11416 else if (new_x
> it
->first_visible_x
)
11418 /* Increment number of glyphs actually displayed. */
11421 if (x
< it
->first_visible_x
)
11422 /* Glyph is partially visible, i.e. row starts at
11423 negative X position. */
11424 row
->x
= x
- it
->first_visible_x
;
11428 /* Glyph is completely off the left margin of the
11429 window. This should not happen because of the
11430 move_it_in_display_line at the start of
11436 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11437 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11438 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11439 row
->phys_height
= max (row
->phys_height
,
11440 it
->max_phys_ascent
+ it
->max_phys_descent
);
11442 /* End of this display line if row is continued. */
11443 if (row
->continued_p
)
11447 /* Is this a line end? If yes, we're also done, after making
11448 sure that a non-default face is extended up to the right
11449 margin of the window. */
11450 if (ITERATOR_AT_END_OF_LINE_P (it
))
11452 int used_before
= row
->used
[TEXT_AREA
];
11454 /* Add a space at the end of the line that is used to
11455 display the cursor there. */
11456 append_space (it
, 0);
11458 /* Extend the face to the end of the line. */
11459 extend_face_to_end_of_line (it
);
11461 /* Make sure we have the position. */
11462 if (used_before
== 0)
11463 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
11465 /* Consume the line end. This skips over invisible lines. */
11466 set_iterator_to_next (it
);
11467 it
->continuation_lines_width
= 0;
11471 /* Proceed with next display element. Note that this skips
11472 over lines invisible because of selective display. */
11473 set_iterator_to_next (it
);
11475 /* If we truncate lines, we are done when the last displayed
11476 glyphs reach past the right margin of the window. */
11477 if (it
->truncate_lines_p
11478 && (FRAME_WINDOW_P (it
->f
)
11479 ? (it
->current_x
>= it
->last_visible_x
)
11480 : (it
->current_x
> it
->last_visible_x
)))
11482 /* Maybe add truncation glyphs. */
11483 if (!FRAME_WINDOW_P (it
->f
))
11485 --it
->glyph_row
->used
[TEXT_AREA
];
11486 produce_special_glyphs (it
, IT_TRUNCATION
);
11489 row
->truncated_on_right_p
= 1;
11490 it
->continuation_lines_width
= 0;
11491 reseat_at_next_visible_line_start (it
, 0);
11492 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
11493 it
->hpos
= hpos_before
;
11494 it
->current_x
= x_before
;
11499 /* If line is not empty and hscrolled, maybe insert truncation glyphs
11500 at the left window margin. */
11501 if (it
->first_visible_x
11502 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
11504 if (!FRAME_WINDOW_P (it
->f
))
11505 insert_left_trunc_glyphs (it
);
11506 row
->truncated_on_left_p
= 1;
11509 /* If the start of this line is the overlay arrow-position, then
11510 mark this glyph row as the one containing the overlay arrow.
11511 This is clearly a mess with variable size fonts. It would be
11512 better to let it be displayed like cursors under X. */
11513 if (MARKERP (Voverlay_arrow_position
)
11514 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
11515 && (MATRIX_ROW_START_CHARPOS (row
)
11516 == marker_position (Voverlay_arrow_position
))
11517 && STRINGP (Voverlay_arrow_string
)
11518 && ! overlay_arrow_seen
)
11520 /* Overlay arrow in window redisplay is a bitmap. */
11521 if (!FRAME_WINDOW_P (it
->f
))
11523 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
11524 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
11525 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
11526 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
11527 struct glyph
*p2
, *end
;
11529 /* Copy the arrow glyphs. */
11530 while (glyph
< arrow_end
)
11533 /* Throw away padding glyphs. */
11535 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
11536 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
11542 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
11546 overlay_arrow_seen
= 1;
11547 row
->overlay_arrow_p
= 1;
11550 /* Compute pixel dimensions of this line. */
11551 compute_line_metrics (it
);
11553 /* Remember the position at which this line ends. */
11554 row
->end
= it
->current
;
11556 /* Maybe set the cursor. */
11557 if (it
->w
->cursor
.vpos
< 0
11558 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
11559 && PT
<= MATRIX_ROW_END_CHARPOS (row
))
11561 /* Also see redisplay_window, case cursor movement in unchanged
11563 if (MATRIX_ROW_END_CHARPOS (row
) == PT
11564 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11565 && !row
->ends_at_zv_p
)
11568 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
11571 /* Highlight trailing whitespace. */
11572 if (!NILP (Vshow_trailing_whitespace
))
11573 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
11575 /* Prepare for the next line. This line starts horizontally at (X
11576 HPOS) = (0 0). Vertical positions are incremented. As a
11577 convenience for the caller, IT->glyph_row is set to the next
11579 it
->current_x
= it
->hpos
= 0;
11580 it
->current_y
+= row
->height
;
11583 return row
->displays_text_p
;
11588 /***********************************************************************
11590 ***********************************************************************/
11592 /* Redisplay the menu bar in the frame for window W.
11594 The menu bar of X frames that don't have X toolkit support is
11595 displayed in a special window W->frame->menu_bar_window.
11597 The menu bar of terminal frames is treated specially as far as
11598 glyph matrices are concerned. Menu bar lines are not part of
11599 windows, so the update is done directly on the frame matrix rows
11600 for the menu bar. */
11603 display_menu_bar (w
)
11606 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11611 /* Don't do all this for graphical frames. */
11613 if (!NILP (Vwindow_system
))
11616 #ifdef USE_X_TOOLKIT
11621 #ifdef USE_X_TOOLKIT
11622 xassert (!FRAME_WINDOW_P (f
));
11623 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
11624 it
.first_visible_x
= 0;
11625 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11626 #else /* not USE_X_TOOLKIT */
11627 if (FRAME_WINDOW_P (f
))
11629 /* Menu bar lines are displayed in the desired matrix of the
11630 dummy window menu_bar_window. */
11631 struct window
*menu_w
;
11632 xassert (WINDOWP (f
->menu_bar_window
));
11633 menu_w
= XWINDOW (f
->menu_bar_window
);
11634 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
11636 it
.first_visible_x
= 0;
11637 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11641 /* This is a TTY frame, i.e. character hpos/vpos are used as
11643 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
11645 it
.first_visible_x
= 0;
11646 it
.last_visible_x
= FRAME_WIDTH (f
);
11648 #endif /* not USE_X_TOOLKIT */
11650 /* Clear all rows of the menu bar. */
11651 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
11653 struct glyph_row
*row
= it
.glyph_row
+ i
;
11654 clear_glyph_row (row
);
11655 row
->enabled_p
= 1;
11656 row
->full_width_p
= 1;
11659 /* Make the first line of the menu bar appear in reverse video. */
11660 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11662 /* Display all items of the menu bar. */
11663 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
11664 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
11666 Lisp_Object string
;
11668 /* Stop at nil string. */
11669 string
= XVECTOR (items
)->contents
[i
+ 1];
11673 /* Remember where item was displayed. */
11674 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
11676 /* Display the item, pad with one space. */
11677 if (it
.current_x
< it
.last_visible_x
)
11678 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
11679 XSTRING (string
)->size
+ 1, 0, 0, -1);
11682 /* Fill out the line with spaces. */
11683 if (it
.current_x
< it
.last_visible_x
)
11684 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
11686 /* Compute the total height of the lines. */
11687 compute_line_metrics (&it
);
11692 /***********************************************************************
11694 ***********************************************************************/
11696 /* Display the mode and/or top line of window W. */
11699 display_mode_lines (w
)
11702 /* These will be set while the mode line specs are processed. */
11703 line_number_displayed
= 0;
11704 w
->column_number_displayed
= Qnil
;
11706 if (WINDOW_WANTS_MODELINE_P (w
))
11707 display_mode_line (w
, MODE_LINE_FACE_ID
,
11708 current_buffer
->mode_line_format
);
11710 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11711 display_mode_line (w
, HEADER_LINE_FACE_ID
,
11712 current_buffer
->header_line_format
);
11716 /* Display mode or top line of window W. FACE_ID specifies which line
11717 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
11718 FORMAT is the mode line format to display. */
11721 display_mode_line (w
, face_id
, format
)
11723 enum face_id face_id
;
11724 Lisp_Object format
;
11729 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
11730 prepare_desired_row (it
.glyph_row
);
11732 /* Temporarily make frame's keyboard the current kboard so that
11733 kboard-local variables in the mode_line_format will get the right
11735 push_frame_kboard (it
.f
);
11736 display_mode_element (&it
, 0, 0, 0, format
);
11737 pop_frame_kboard ();
11739 /* Fill up with spaces. */
11740 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
11742 compute_line_metrics (&it
);
11743 it
.glyph_row
->full_width_p
= 1;
11744 it
.glyph_row
->mode_line_p
= 1;
11745 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11746 it
.glyph_row
->continued_p
= 0;
11747 it
.glyph_row
->truncated_on_left_p
= 0;
11748 it
.glyph_row
->truncated_on_right_p
= 0;
11750 /* Make a 3D mode-line have a shadow at its right end. */
11751 face
= FACE_FROM_ID (it
.f
, face_id
);
11752 extend_face_to_end_of_line (&it
);
11753 if (face
->box
!= FACE_NO_BOX
)
11755 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
11756 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
11757 last
->right_box_line_p
= 1;
11762 /* Contribute ELT to the mode line for window IT->w. How it
11763 translates into text depends on its data type.
11765 IT describes the display environment in which we display, as usual.
11767 DEPTH is the depth in recursion. It is used to prevent
11768 infinite recursion here.
11770 FIELD_WIDTH is the number of characters the display of ELT should
11771 occupy in the mode line, and PRECISION is the maximum number of
11772 characters to display from ELT's representation. See
11773 display_string for details. *
11775 Returns the hpos of the end of the text generated by ELT. */
11778 display_mode_element (it
, depth
, field_width
, precision
, elt
)
11781 int field_width
, precision
;
11784 int n
= 0, field
, prec
;
11792 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
11796 /* A string: output it and check for %-constructs within it. */
11798 unsigned char *this = XSTRING (elt
)->data
;
11799 unsigned char *lisp_string
= this;
11801 while ((precision
<= 0 || n
< precision
)
11803 && (frame_title_ptr
11804 || it
->current_x
< it
->last_visible_x
))
11806 unsigned char *last
= this;
11808 /* Advance to end of string or next format specifier. */
11809 while ((c
= *this++) != '\0' && c
!= '%')
11812 if (this - 1 != last
)
11814 /* Output to end of string or up to '%'. Field width
11815 is length of string. Don't output more than
11816 PRECISION allows us. */
11817 prec
= --this - last
;
11818 if (precision
> 0 && prec
> precision
- n
)
11819 prec
= precision
- n
;
11821 if (frame_title_ptr
)
11822 n
+= store_frame_title (last
, prec
, prec
);
11824 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
11825 it
, 0, prec
, 0, -1);
11827 else /* c == '%' */
11829 unsigned char *percent_position
= this;
11831 /* Get the specified minimum width. Zero means
11834 while ((c
= *this++) >= '0' && c
<= '9')
11835 field
= field
* 10 + c
- '0';
11837 /* Don't pad beyond the total padding allowed. */
11838 if (field_width
- n
> 0 && field
> field_width
- n
)
11839 field
= field_width
- n
;
11841 /* Note that either PRECISION <= 0 or N < PRECISION. */
11842 prec
= precision
- n
;
11845 n
+= display_mode_element (it
, depth
, field
, prec
,
11846 Vglobal_mode_string
);
11849 unsigned char *spec
11850 = decode_mode_spec (it
->w
, c
, field
, prec
);
11852 if (frame_title_ptr
)
11853 n
+= store_frame_title (spec
, field
, prec
);
11857 = it
->glyph_row
->used
[TEXT_AREA
];
11859 = percent_position
- XSTRING (elt
)->data
;
11861 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
11862 field
, prec
, 0, -1);
11864 /* Assign to the glyphs written above the
11865 string where the `%x' came from, position
11869 struct glyph
*glyph
11870 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
11874 for (i
= 0; i
< nwritten
; ++i
)
11876 glyph
[i
].object
= elt
;
11877 glyph
[i
].charpos
= charpos
;
11890 /* A symbol: process the value of the symbol recursively
11891 as if it appeared here directly. Avoid error if symbol void.
11892 Special case: if value of symbol is a string, output the string
11895 register Lisp_Object tem
;
11896 tem
= Fboundp (elt
);
11899 tem
= Fsymbol_value (elt
);
11900 /* If value is a string, output that string literally:
11901 don't check for % within it. */
11904 prec
= XSTRING (tem
)->size
;
11905 if (precision
> 0 && prec
> precision
- n
)
11906 prec
= precision
- n
;
11907 if (frame_title_ptr
)
11908 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
11910 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
11913 else if (!EQ (tem
, elt
))
11915 /* Give up right away for nil or t. */
11925 register Lisp_Object car
, tem
;
11927 /* A cons cell: three distinct cases.
11928 If first element is a string or a cons, process all the elements
11929 and effectively concatenate them.
11930 If first element is a negative number, truncate displaying cdr to
11931 at most that many characters. If positive, pad (with spaces)
11932 to at least that many characters.
11933 If first element is a symbol, process the cadr or caddr recursively
11934 according to whether the symbol's value is non-nil or nil. */
11936 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
11938 /* An element of the form (:eval FORM) means evaluate FORM
11939 and use the result as mode line elements. */
11940 struct gcpro gcpro1
;
11943 spec
= eval_form (XCAR (XCDR (elt
)));
11945 n
+= display_mode_element (it
, depth
, field_width
- n
,
11946 precision
- n
, spec
);
11949 else if (SYMBOLP (car
))
11951 tem
= Fboundp (car
);
11955 /* elt is now the cdr, and we know it is a cons cell.
11956 Use its car if CAR has a non-nil value. */
11959 tem
= Fsymbol_value (car
);
11966 /* Symbol's value is nil (or symbol is unbound)
11967 Get the cddr of the original list
11968 and if possible find the caddr and use that. */
11972 else if (!CONSP (elt
))
11977 else if (INTEGERP (car
))
11979 register int lim
= XINT (car
);
11983 /* Negative int means reduce maximum width. */
11984 if (precision
<= 0)
11987 precision
= min (precision
, -lim
);
11991 /* Padding specified. Don't let it be more than
11992 current maximum. */
11994 lim
= min (precision
, lim
);
11996 /* If that's more padding than already wanted, queue it.
11997 But don't reduce padding already specified even if
11998 that is beyond the current truncation point. */
11999 field_width
= max (lim
, field_width
);
12003 else if (STRINGP (car
) || CONSP (car
))
12005 register int limit
= 50;
12006 /* Limit is to protect against circular lists. */
12009 && (precision
<= 0 || n
< precision
))
12011 n
+= display_mode_element (it
, depth
, field_width
- n
,
12012 precision
- n
, XCAR (elt
));
12021 if (frame_title_ptr
)
12022 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
12024 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
12025 precision
- n
, 0, 0);
12029 /* Pad to FIELD_WIDTH. */
12030 if (field_width
> 0 && n
< field_width
)
12032 if (frame_title_ptr
)
12033 n
+= store_frame_title ("", field_width
- n
, 0);
12035 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
12043 /* Write a null-terminated, right justified decimal representation of
12044 the positive integer D to BUF using a minimal field width WIDTH. */
12047 pint2str (buf
, width
, d
)
12048 register char *buf
;
12049 register int width
;
12052 register char *p
= buf
;
12060 *p
++ = d
% 10 + '0';
12065 for (width
-= (int) (p
- buf
); width
> 0; --width
)
12076 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
12077 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
12078 type of CODING_SYSTEM. Return updated pointer into BUF. */
12080 static unsigned char invalid_eol_type
[] = "(*invalid*)";
12083 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
12084 Lisp_Object coding_system
;
12085 register char *buf
;
12089 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
12090 unsigned char *eol_str
;
12092 /* The EOL conversion we are using. */
12093 Lisp_Object eoltype
;
12095 val
= Fget (coding_system
, Qcoding_system
);
12097 if (!VECTORP (val
)) /* Not yet decided. */
12102 eoltype
= eol_mnemonic_undecided
;
12103 /* Don't mention EOL conversion if it isn't decided. */
12107 Lisp_Object eolvalue
;
12109 eolvalue
= Fget (coding_system
, Qeol_type
);
12112 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
12116 /* The EOL conversion that is normal on this system. */
12118 if (NILP (eolvalue
)) /* Not yet decided. */
12119 eoltype
= eol_mnemonic_undecided
;
12120 else if (VECTORP (eolvalue
)) /* Not yet decided. */
12121 eoltype
= eol_mnemonic_undecided
;
12122 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
12123 eoltype
= (XFASTINT (eolvalue
) == 0
12124 ? eol_mnemonic_unix
12125 : (XFASTINT (eolvalue
) == 1
12126 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
12132 /* Mention the EOL conversion if it is not the usual one. */
12133 if (STRINGP (eoltype
))
12135 eol_str
= XSTRING (eoltype
)->data
;
12136 eol_str_len
= XSTRING (eoltype
)->size
;
12138 else if (INTEGERP (eoltype
)
12139 && CHAR_VALID_P (XINT (eoltype
), 0))
12141 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
12142 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
12146 eol_str
= invalid_eol_type
;
12147 eol_str_len
= sizeof (invalid_eol_type
) - 1;
12149 bcopy (eol_str
, buf
, eol_str_len
);
12150 buf
+= eol_str_len
;
12156 /* Return a string for the output of a mode line %-spec for window W,
12157 generated by character C. PRECISION >= 0 means don't return a
12158 string longer than that value. FIELD_WIDTH > 0 means pad the
12159 string returned with spaces to that value. */
12161 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
12164 decode_mode_spec (w
, c
, field_width
, precision
)
12167 int field_width
, precision
;
12170 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12171 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
12172 struct buffer
*b
= XBUFFER (w
->buffer
);
12179 if (!NILP (b
->read_only
))
12181 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12186 /* This differs from %* only for a modified read-only buffer. */
12187 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12189 if (!NILP (b
->read_only
))
12194 /* This differs from %* in ignoring read-only-ness. */
12195 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12207 if (command_loop_level
> 5)
12209 p
= decode_mode_spec_buf
;
12210 for (i
= 0; i
< command_loop_level
; i
++)
12213 return decode_mode_spec_buf
;
12221 if (command_loop_level
> 5)
12223 p
= decode_mode_spec_buf
;
12224 for (i
= 0; i
< command_loop_level
; i
++)
12227 return decode_mode_spec_buf
;
12234 /* Let lots_of_dashes be a string of infinite length. */
12235 if (field_width
<= 0
12236 || field_width
> sizeof (lots_of_dashes
))
12238 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
12239 decode_mode_spec_buf
[i
] = '-';
12240 decode_mode_spec_buf
[i
] = '\0';
12241 return decode_mode_spec_buf
;
12244 return lots_of_dashes
;
12253 int col
= current_column ();
12254 XSETFASTINT (w
->column_number_displayed
, col
);
12255 pint2str (decode_mode_spec_buf
, field_width
, col
);
12256 return decode_mode_spec_buf
;
12260 /* %F displays the frame name. */
12261 if (!NILP (f
->title
))
12262 return (char *) XSTRING (f
->title
)->data
;
12263 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
12264 return (char *) XSTRING (f
->name
)->data
;
12273 int startpos
= XMARKER (w
->start
)->charpos
;
12274 int startpos_byte
= marker_byte_position (w
->start
);
12275 int line
, linepos
, linepos_byte
, topline
;
12277 int height
= XFASTINT (w
->height
);
12279 /* If we decided that this buffer isn't suitable for line numbers,
12280 don't forget that too fast. */
12281 if (EQ (w
->base_line_pos
, w
->buffer
))
12283 /* But do forget it, if the window shows a different buffer now. */
12284 else if (BUFFERP (w
->base_line_pos
))
12285 w
->base_line_pos
= Qnil
;
12287 /* If the buffer is very big, don't waste time. */
12288 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
12290 w
->base_line_pos
= Qnil
;
12291 w
->base_line_number
= Qnil
;
12295 if (!NILP (w
->base_line_number
)
12296 && !NILP (w
->base_line_pos
)
12297 && XFASTINT (w
->base_line_pos
) <= startpos
)
12299 line
= XFASTINT (w
->base_line_number
);
12300 linepos
= XFASTINT (w
->base_line_pos
);
12301 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
12306 linepos
= BUF_BEGV (b
);
12307 linepos_byte
= BUF_BEGV_BYTE (b
);
12310 /* Count lines from base line to window start position. */
12311 nlines
= display_count_lines (linepos
, linepos_byte
,
12315 topline
= nlines
+ line
;
12317 /* Determine a new base line, if the old one is too close
12318 or too far away, or if we did not have one.
12319 "Too close" means it's plausible a scroll-down would
12320 go back past it. */
12321 if (startpos
== BUF_BEGV (b
))
12323 XSETFASTINT (w
->base_line_number
, topline
);
12324 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
12326 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
12327 || linepos
== BUF_BEGV (b
))
12329 int limit
= BUF_BEGV (b
);
12330 int limit_byte
= BUF_BEGV_BYTE (b
);
12332 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
12334 if (startpos
- distance
> limit
)
12336 limit
= startpos
- distance
;
12337 limit_byte
= CHAR_TO_BYTE (limit
);
12340 nlines
= display_count_lines (startpos
, startpos_byte
,
12342 - (height
* 2 + 30),
12344 /* If we couldn't find the lines we wanted within
12345 line_number_display_limit_width chars per line,
12346 give up on line numbers for this window. */
12347 if (position
== limit_byte
&& limit
== startpos
- distance
)
12349 w
->base_line_pos
= w
->buffer
;
12350 w
->base_line_number
= Qnil
;
12354 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
12355 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
12358 /* Now count lines from the start pos to point. */
12359 nlines
= display_count_lines (startpos
, startpos_byte
,
12360 PT_BYTE
, PT
, &junk
);
12362 /* Record that we did display the line number. */
12363 line_number_displayed
= 1;
12365 /* Make the string to show. */
12366 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
12367 return decode_mode_spec_buf
;
12370 char* p
= decode_mode_spec_buf
;
12371 int pad
= field_width
- 2;
12376 return decode_mode_spec_buf
;
12382 obj
= b
->mode_name
;
12386 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
12392 int pos
= marker_position (w
->start
);
12393 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12395 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
12397 if (pos
<= BUF_BEGV (b
))
12402 else if (pos
<= BUF_BEGV (b
))
12406 if (total
> 1000000)
12407 /* Do it differently for a large value, to avoid overflow. */
12408 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12410 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12411 /* We can't normally display a 3-digit number,
12412 so get us a 2-digit number that is close. */
12415 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12416 return decode_mode_spec_buf
;
12420 /* Display percentage of size above the bottom of the screen. */
12423 int toppos
= marker_position (w
->start
);
12424 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
12425 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12427 if (botpos
>= BUF_ZV (b
))
12429 if (toppos
<= BUF_BEGV (b
))
12436 if (total
> 1000000)
12437 /* Do it differently for a large value, to avoid overflow. */
12438 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12440 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12441 /* We can't normally display a 3-digit number,
12442 so get us a 2-digit number that is close. */
12445 if (toppos
<= BUF_BEGV (b
))
12446 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
12448 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12449 return decode_mode_spec_buf
;
12454 /* status of process */
12455 obj
= Fget_buffer_process (w
->buffer
);
12457 return "no process";
12458 #ifdef subprocesses
12459 obj
= Fsymbol_name (Fprocess_status (obj
));
12463 case 't': /* indicate TEXT or BINARY */
12464 #ifdef MODE_LINE_BINARY_TEXT
12465 return MODE_LINE_BINARY_TEXT (b
);
12471 /* coding-system (not including end-of-line format) */
12473 /* coding-system (including end-of-line type) */
12475 int eol_flag
= (c
== 'Z');
12476 char *p
= decode_mode_spec_buf
;
12478 if (! FRAME_WINDOW_P (f
))
12480 /* No need to mention EOL here--the terminal never needs
12481 to do EOL conversion. */
12482 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
12483 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
12485 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
12488 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
12489 #ifdef subprocesses
12490 obj
= Fget_buffer_process (Fcurrent_buffer ());
12491 if (PROCESSP (obj
))
12493 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
12495 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
12498 #endif /* subprocesses */
12501 return decode_mode_spec_buf
;
12506 return (char *) XSTRING (obj
)->data
;
12512 /* Count up to COUNT lines starting from START / START_BYTE.
12513 But don't go beyond LIMIT_BYTE.
12514 Return the number of lines thus found (always nonnegative).
12516 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
12519 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
12520 int start
, start_byte
, limit_byte
, count
;
12523 register unsigned char *cursor
;
12524 unsigned char *base
;
12526 register int ceiling
;
12527 register unsigned char *ceiling_addr
;
12528 int orig_count
= count
;
12530 /* If we are not in selective display mode,
12531 check only for newlines. */
12532 int selective_display
= (!NILP (current_buffer
->selective_display
)
12533 && !INTEGERP (current_buffer
->selective_display
));
12537 while (start_byte
< limit_byte
)
12539 ceiling
= BUFFER_CEILING_OF (start_byte
);
12540 ceiling
= min (limit_byte
- 1, ceiling
);
12541 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
12542 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
12545 if (selective_display
)
12546 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
12549 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
12552 if (cursor
!= ceiling_addr
)
12556 start_byte
+= cursor
- base
+ 1;
12557 *byte_pos_ptr
= start_byte
;
12561 if (++cursor
== ceiling_addr
)
12567 start_byte
+= cursor
- base
;
12572 while (start_byte
> limit_byte
)
12574 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
12575 ceiling
= max (limit_byte
, ceiling
);
12576 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
12577 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
12580 if (selective_display
)
12581 while (--cursor
!= ceiling_addr
12582 && *cursor
!= '\n' && *cursor
!= 015)
12585 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
12588 if (cursor
!= ceiling_addr
)
12592 start_byte
+= cursor
- base
+ 1;
12593 *byte_pos_ptr
= start_byte
;
12594 /* When scanning backwards, we should
12595 not count the newline posterior to which we stop. */
12596 return - orig_count
- 1;
12602 /* Here we add 1 to compensate for the last decrement
12603 of CURSOR, which took it past the valid range. */
12604 start_byte
+= cursor
- base
+ 1;
12608 *byte_pos_ptr
= limit_byte
;
12611 return - orig_count
+ count
;
12612 return orig_count
- count
;
12618 /***********************************************************************
12620 ***********************************************************************/
12622 /* Display a NUL-terminated string, starting with index START.
12624 If STRING is non-null, display that C string. Otherwise, the Lisp
12625 string LISP_STRING is displayed.
12627 If FACE_STRING is not nil, FACE_STRING_POS is a position in
12628 FACE_STRING. Display STRING or LISP_STRING with the face at
12629 FACE_STRING_POS in FACE_STRING:
12631 Display the string in the environment given by IT, but use the
12632 standard display table, temporarily.
12634 FIELD_WIDTH is the minimum number of output glyphs to produce.
12635 If STRING has fewer characters than FIELD_WIDTH, pad to the right
12636 with spaces. If STRING has more characters, more than FIELD_WIDTH
12637 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
12639 PRECISION is the maximum number of characters to output from
12640 STRING. PRECISION < 0 means don't truncate the string.
12642 This is roughly equivalent to printf format specifiers:
12644 FIELD_WIDTH PRECISION PRINTF
12645 ----------------------------------------
12651 MULTIBYTE zero means do not display multibyte chars, > 0 means do
12652 display them, and < 0 means obey the current buffer's value of
12653 enable_multibyte_characters.
12655 Value is the number of glyphs produced. */
12658 display_string (string
, lisp_string
, face_string
, face_string_pos
,
12659 start
, it
, field_width
, precision
, max_x
, multibyte
)
12660 unsigned char *string
;
12661 Lisp_Object lisp_string
;
12662 Lisp_Object face_string
;
12663 int face_string_pos
;
12666 int field_width
, precision
, max_x
;
12669 int hpos_at_start
= it
->hpos
;
12670 int saved_face_id
= it
->face_id
;
12671 struct glyph_row
*row
= it
->glyph_row
;
12673 /* Initialize the iterator IT for iteration over STRING beginning
12674 with index START. We assume that IT may be modified here (which
12675 means that display_line has to do something when displaying a
12676 mini-buffer prompt, which it does). */
12677 reseat_to_string (it
, string
, lisp_string
, start
,
12678 precision
, field_width
, multibyte
);
12680 /* If displaying STRING, set up the face of the iterator
12681 from LISP_STRING, if that's given. */
12682 if (STRINGP (face_string
))
12688 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
12689 0, it
->region_beg_charpos
,
12690 it
->region_end_charpos
,
12691 &endptr
, it
->base_face_id
);
12692 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12693 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
12696 /* Set max_x to the maximum allowed X position. Don't let it go
12697 beyond the right edge of the window. */
12699 max_x
= it
->last_visible_x
;
12701 max_x
= min (max_x
, it
->last_visible_x
);
12703 /* Skip over display elements that are not visible. because IT->w is
12705 if (it
->current_x
< it
->first_visible_x
)
12706 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
12707 MOVE_TO_POS
| MOVE_TO_X
);
12709 row
->ascent
= it
->max_ascent
;
12710 row
->height
= it
->max_ascent
+ it
->max_descent
;
12711 row
->phys_ascent
= it
->max_phys_ascent
;
12712 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12714 /* This condition is for the case that we are called with current_x
12715 past last_visible_x. */
12716 while (it
->current_x
< max_x
)
12718 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
12720 /* Get the next display element. */
12721 if (!get_next_display_element (it
))
12724 /* Produce glyphs. */
12725 x_before
= it
->current_x
;
12726 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
12727 PRODUCE_GLYPHS (it
);
12729 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
12732 while (i
< nglyphs
)
12734 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12736 if (!it
->truncate_lines_p
12737 && x
+ glyph
->pixel_width
> max_x
)
12739 /* End of continued line or max_x reached. */
12740 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12744 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
12746 /* Glyph is at least partially visible. */
12748 if (x
< it
->first_visible_x
)
12749 it
->glyph_row
->x
= x
- it
->first_visible_x
;
12753 /* Glyph is off the left margin of the display area.
12754 Should not happen. */
12758 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12759 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12760 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12761 row
->phys_height
= max (row
->phys_height
,
12762 it
->max_phys_ascent
+ it
->max_phys_descent
);
12763 x
+= glyph
->pixel_width
;
12767 /* Stop if max_x reached. */
12771 /* Stop at line ends. */
12772 if (ITERATOR_AT_END_OF_LINE_P (it
))
12774 it
->continuation_lines_width
= 0;
12778 set_iterator_to_next (it
);
12780 /* Stop if truncating at the right edge. */
12781 if (it
->truncate_lines_p
12782 && it
->current_x
>= it
->last_visible_x
)
12784 /* Add truncation mark, but don't do it if the line is
12785 truncated at a padding space. */
12786 if (IT_CHARPOS (*it
) < it
->string_nchars
)
12788 if (!FRAME_WINDOW_P (it
->f
))
12789 produce_special_glyphs (it
, IT_TRUNCATION
);
12790 it
->glyph_row
->truncated_on_right_p
= 1;
12796 /* Maybe insert a truncation at the left. */
12797 if (it
->first_visible_x
12798 && IT_CHARPOS (*it
) > 0)
12800 if (!FRAME_WINDOW_P (it
->f
))
12801 insert_left_trunc_glyphs (it
);
12802 it
->glyph_row
->truncated_on_left_p
= 1;
12805 it
->face_id
= saved_face_id
;
12807 /* Value is number of columns displayed. */
12808 return it
->hpos
- hpos_at_start
;
12813 /* This is like a combination of memq and assq. Return 1 if PROPVAL
12814 appears as an element of LIST or as the car of an element of LIST.
12815 If PROPVAL is a list, compare each element against LIST in that
12816 way, and return 1 if any element of PROPVAL is found in LIST.
12817 Otherwise return 0. This function cannot quit. */
12820 invisible_p (propval
, list
)
12821 register Lisp_Object propval
;
12824 register Lisp_Object tail
, proptail
;
12825 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12827 register Lisp_Object tem
;
12829 if (EQ (propval
, tem
))
12831 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
12834 if (CONSP (propval
))
12835 for (proptail
= propval
; CONSP (proptail
);
12836 proptail
= XCDR (proptail
))
12838 Lisp_Object propelt
;
12839 propelt
= XCAR (proptail
);
12840 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12842 register Lisp_Object tem
;
12844 if (EQ (propelt
, tem
))
12846 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
12854 /* Return 1 if PROPVAL appears as the car of an element of LIST and
12855 the cdr of that element is non-nil. If PROPVAL is a list, check
12856 each element of PROPVAL in that way, and the first time some
12857 element is found, return 1 if the cdr of that element is non-nil.
12858 Otherwise return 0. This function cannot quit. */
12861 invisible_ellipsis_p (propval
, list
)
12862 register Lisp_Object propval
;
12865 register Lisp_Object tail
, proptail
;
12867 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12869 register Lisp_Object tem
;
12871 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
12872 return ! NILP (XCDR (tem
));
12875 if (CONSP (propval
))
12876 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
12878 Lisp_Object propelt
;
12879 propelt
= XCAR (proptail
);
12880 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12882 register Lisp_Object tem
;
12884 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
12885 return ! NILP (XCDR (tem
));
12894 /***********************************************************************
12896 ***********************************************************************/
12901 Vwith_echo_area_save_vector
= Qnil
;
12902 staticpro (&Vwith_echo_area_save_vector
);
12904 Vmessage_stack
= Qnil
;
12905 staticpro (&Vmessage_stack
);
12907 Qinhibit_redisplay
= intern ("inhibit-redisplay");
12908 staticpro (&Qinhibit_redisplay
);
12911 defsubr (&Sdump_glyph_matrix
);
12912 defsubr (&Sdump_glyph_row
);
12913 defsubr (&Sdump_tool_bar_row
);
12914 defsubr (&Strace_redisplay_toggle
);
12915 defsubr (&Strace_to_stderr
);
12918 staticpro (&Qmenu_bar_update_hook
);
12919 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
12921 staticpro (&Qoverriding_terminal_local_map
);
12922 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
12924 staticpro (&Qoverriding_local_map
);
12925 Qoverriding_local_map
= intern ("overriding-local-map");
12927 staticpro (&Qwindow_scroll_functions
);
12928 Qwindow_scroll_functions
= intern ("window-scroll-functions");
12930 staticpro (&Qredisplay_end_trigger_functions
);
12931 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
12933 staticpro (&Qinhibit_point_motion_hooks
);
12934 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
12936 QCdata
= intern (":data");
12937 staticpro (&QCdata
);
12938 Qdisplay
= intern ("display");
12939 staticpro (&Qdisplay
);
12940 Qspace_width
= intern ("space-width");
12941 staticpro (&Qspace_width
);
12942 Qraise
= intern ("raise");
12943 staticpro (&Qraise
);
12944 Qspace
= intern ("space");
12945 staticpro (&Qspace
);
12946 Qmargin
= intern ("margin");
12947 staticpro (&Qmargin
);
12948 Qleft_margin
= intern ("left-margin");
12949 staticpro (&Qleft_margin
);
12950 Qright_margin
= intern ("right-margin");
12951 staticpro (&Qright_margin
);
12952 Qalign_to
= intern ("align-to");
12953 staticpro (&Qalign_to
);
12954 QCalign_to
= intern (":align-to");
12955 staticpro (&QCalign_to
);
12956 Qrelative_width
= intern ("relative-width");
12957 staticpro (&Qrelative_width
);
12958 QCrelative_width
= intern (":relative-width");
12959 staticpro (&QCrelative_width
);
12960 QCrelative_height
= intern (":relative-height");
12961 staticpro (&QCrelative_height
);
12962 QCeval
= intern (":eval");
12963 staticpro (&QCeval
);
12964 Qwhen
= intern ("when");
12965 staticpro (&Qwhen
);
12966 QCfile
= intern (":file");
12967 staticpro (&QCfile
);
12968 Qfontified
= intern ("fontified");
12969 staticpro (&Qfontified
);
12970 Qfontification_functions
= intern ("fontification-functions");
12971 staticpro (&Qfontification_functions
);
12972 Qtrailing_whitespace
= intern ("trailing-whitespace");
12973 staticpro (&Qtrailing_whitespace
);
12974 Qimage
= intern ("image");
12975 staticpro (&Qimage
);
12977 last_arrow_position
= Qnil
;
12978 last_arrow_string
= Qnil
;
12979 staticpro (&last_arrow_position
);
12980 staticpro (&last_arrow_string
);
12982 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
12983 staticpro (&echo_buffer
[0]);
12984 staticpro (&echo_buffer
[1]);
12986 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
12987 staticpro (&echo_area_buffer
[0]);
12988 staticpro (&echo_area_buffer
[1]);
12990 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
12991 "Non-nil means highlight trailing whitespace.\n\
12992 The face used for trailing whitespace is `trailing-whitespace'.");
12993 Vshow_trailing_whitespace
= Qnil
;
12995 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
12996 "Non-nil means don't actually do any redisplay.\n\
12997 This is used for internal purposes.");
12998 Vinhibit_redisplay
= Qnil
;
13000 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
13001 "String (or mode line construct) included (normally) in `mode-line-format'.");
13002 Vglobal_mode_string
= Qnil
;
13004 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
13005 "Marker for where to display an arrow on top of the buffer text.\n\
13006 This must be the beginning of a line in order to work.\n\
13007 See also `overlay-arrow-string'.");
13008 Voverlay_arrow_position
= Qnil
;
13010 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
13011 "String to display as an arrow. See also `overlay-arrow-position'.");
13012 Voverlay_arrow_string
= Qnil
;
13014 DEFVAR_INT ("scroll-step", &scroll_step
,
13015 "*The number of lines to try scrolling a window by when point moves out.\n\
13016 If that fails to bring point back on frame, point is centered instead.\n\
13017 If this is zero, point is always centered after it moves off frame.");
13019 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
13020 "*Scroll up to this many lines, to bring point back on screen.\n\
13021 A value of zero means to scroll the text to center point vertically\n\
13023 scroll_conservatively
= 0;
13025 DEFVAR_INT ("scroll-margin", &scroll_margin
,
13026 "*Number of lines of margin at the top and bottom of a window.\n\
13027 Recenter the window whenever point gets within this many lines\n\
13028 of the top or bottom of the window.");
13032 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
13035 DEFVAR_BOOL ("truncate-partial-width-windows",
13036 &truncate_partial_width_windows
,
13037 "*Non-nil means truncate lines in all windows less than full frame wide.");
13038 truncate_partial_width_windows
= 1;
13040 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
13041 "*Non-nil means use inverse video for the mode line.");
13042 mode_line_inverse_video
= 1;
13044 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
13045 "*Maximum buffer size for which line number should be displayed.\n\
13046 If the buffer is bigger than this, the line number does not appear\n\
13047 in the mode line.");
13048 line_number_display_limit
= 1000000;
13050 DEFVAR_INT ("line-number-display-limit-width", &line_number_display_limit_width
,
13051 "*Maximum line width (in characters) for line number display.\n\
13052 If the average length of the lines near point is bigger than this, then the\n\
13053 line number may be omitted from the mode line.");
13054 line_number_display_limit_width
= 200;
13056 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
13057 "*Non-nil means highlight region even in nonselected windows.");
13058 highlight_nonselected_windows
= 0;
13060 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
13061 "Non-nil if more than one frame is visible on this display.\n\
13062 Minibuffer-only frames don't count, but iconified frames do.\n\
13063 This variable is not guaranteed to be accurate except while processing\n\
13064 `frame-title-format' and `icon-title-format'.");
13066 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
13067 "Template for displaying the title bar of visible frames.\n\
13068 \(Assuming the window manager supports this feature.)\n\
13069 This variable has the same structure as `mode-line-format' (which see),\n\
13070 and is used only on frames for which no explicit name has been set\n\
13071 \(see `modify-frame-parameters').");
13072 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
13073 "Template for displaying the title bar of an iconified frame.\n\
13074 \(Assuming the window manager supports this feature.)\n\
13075 This variable has the same structure as `mode-line-format' (which see),\n\
13076 and is used only on frames for which no explicit name has been set\n\
13077 \(see `modify-frame-parameters').");
13079 = Vframe_title_format
13080 = Fcons (intern ("multiple-frames"),
13081 Fcons (build_string ("%b"),
13082 Fcons (Fcons (build_string (""),
13083 Fcons (intern ("invocation-name"),
13084 Fcons (build_string ("@"),
13085 Fcons (intern ("system-name"),
13089 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
13090 "Maximum number of lines to keep in the message log buffer.\n\
13091 If nil, disable message logging. If t, log messages but don't truncate\n\
13092 the buffer when it becomes large.");
13093 XSETFASTINT (Vmessage_log_max
, 50);
13095 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
13096 "Functions called before redisplay, if window sizes have changed.\n\
13097 The value should be a list of functions that take one argument.\n\
13098 Just before redisplay, for each frame, if any of its windows have changed\n\
13099 size since the last redisplay, or have been split or deleted,\n\
13100 all the functions in the list are called, with the frame as argument.");
13101 Vwindow_size_change_functions
= Qnil
;
13103 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
13104 "List of Functions to call before redisplaying a window with scrolling.\n\
13105 Each function is called with two arguments, the window\n\
13106 and its new display-start position. Note that the value of `window-end'\n\
13107 is not valid when these functions are called.");
13108 Vwindow_scroll_functions
= Qnil
;
13110 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
13111 "*Non-nil means automatically resize tool-bars.\n\
13112 This increases a tool-bar's height if not all tool-bar items are visible.\n\
13113 It decreases a tool-bar's height when it would display blank lines\n\
13115 auto_resize_tool_bars_p
= 1;
13117 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
13118 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
13119 auto_raise_tool_bar_buttons_p
= 1;
13121 DEFVAR_INT ("tool-bar-button-margin", &tool_bar_button_margin
,
13122 "*Margin around tool-bar buttons in pixels.");
13123 tool_bar_button_margin
= 1;
13125 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
13126 "Relief thickness of tool-bar buttons.");
13127 tool_bar_button_relief
= 3;
13129 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
13130 "List of functions to call to fontify regions of text.\n\
13131 Each function is called with one argument POS. Functions must\n\
13132 fontify a region starting at POS in the current buffer, and give\n\
13133 fontified regions the property `fontified'.\n\
13134 This variable automatically becomes buffer-local when set.");
13135 Vfontification_functions
= Qnil
;
13136 Fmake_local_variable (Qfontification_functions
);
13138 DEFVAR_BOOL ("unibyte-display-via-language-environment",
13139 &unibyte_display_via_language_environment
,
13140 "*Non-nil means display unibyte text according to language environment.\n\
13141 Specifically this means that unibyte non-ASCII characters\n\
13142 are displayed by converting them to the equivalent multibyte characters\n\
13143 according to the current language environment. As a result, they are\n\
13144 displayed according to the current fontset.");
13145 unibyte_display_via_language_environment
= 0;
13147 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
13148 "*Maximum height for resizing mini-windows.\n\
13149 If a float, it specifies a fraction of the mini-window frame's height.\n\
13150 If an integer, it specifies a number of lines.\n\
13151 If nil, don't resize.");
13152 Vmax_mini_window_height
= make_float (0.25);
13154 DEFVAR_BOOL ("cursor-in-non-selected-windows",
13155 &cursor_in_non_selected_windows
,
13156 "*Non-nil means display a hollow cursor in non-selected windows.\n\
13157 Nil means don't display a cursor there.");
13158 cursor_in_non_selected_windows
= 1;
13160 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
13161 "*Non-nil means scroll the display automatically to make point visible.");
13162 automatic_hscrolling_p
= 1;
13164 DEFVAR_LISP ("image-types", &Vimage_types
,
13165 "List of supported image types.\n\
13166 Each element of the list is a symbol for a supported image type.");
13167 Vimage_types
= Qnil
;
13171 /* Initialize this module when Emacs starts. */
13176 Lisp_Object root_window
;
13177 struct window
*mini_w
;
13179 CHARPOS (this_line_start_pos
) = 0;
13181 mini_w
= XWINDOW (minibuf_window
);
13182 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
13184 if (!noninteractive
)
13186 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
13189 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
13190 set_window_height (root_window
,
13191 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
13193 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
13194 set_window_height (minibuf_window
, 1, 0);
13196 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
13197 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
13199 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
13200 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
13201 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
13203 /* The default ellipsis glyphs `...'. */
13204 for (i
= 0; i
< 3; ++i
)
13205 XSETFASTINT (default_invis_vector
[i
], '.');
13208 #ifdef HAVE_WINDOW_SYSTEM
13210 /* Allocate the buffer for frame titles. */
13212 frame_title_buf
= (char *) xmalloc (size
);
13213 frame_title_buf_end
= frame_title_buf
+ size
;
13214 frame_title_ptr
= NULL
;
13216 #endif /* HAVE_WINDOW_SYSTEM */