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 Lisp_Object Vline_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 Lisp_Object Vmax_mini_window_height
;
485 /* Non-zero means messages should be displayed with truncated
486 lines instead of being continued. */
488 int message_truncate_lines
;
489 Lisp_Object Qmessage_truncate_lines
;
491 /* Non-zero means we want a hollow cursor in windows that are not
492 selected. Zero means there's no cursor in such windows. */
494 int cursor_in_non_selected_windows
;
496 /* A scratch glyph row with contents used for generating truncation
497 glyphs. Also used in direct_output_for_insert. */
499 #define MAX_SCRATCH_GLYPHS 100
500 struct glyph_row scratch_glyph_row
;
501 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
503 /* Ascent and height of the last line processed by move_it_to. */
505 static int last_max_ascent
, last_height
;
507 /* The maximum distance to look ahead for text properties. Values
508 that are too small let us call compute_char_face and similar
509 functions too often which is expensive. Values that are too large
510 let us call compute_char_face and alike too often because we
511 might not be interested in text properties that far away. */
513 #define TEXT_PROP_DISTANCE_LIMIT 100
515 /* Non-zero means print traces of redisplay if compiled with
519 int trace_redisplay_p
;
522 /* Non-zero means automatically scroll windows horizontally to make
525 int automatic_hscrolling_p
;
527 /* A list of symbols, one for each supported image type. */
529 Lisp_Object Vimage_types
;
531 /* Value returned from text property handlers (see below). */
536 HANDLED_RECOMPUTE_PROPS
,
537 HANDLED_OVERLAY_STRING_CONSUMED
,
541 /* A description of text properties that redisplay is interested
546 /* The name of the property. */
549 /* A unique index for the property. */
552 /* A handler function called to set up iterator IT from the property
553 at IT's current position. Value is used to steer handle_stop. */
554 enum prop_handled (*handler
) P_ ((struct it
*it
));
557 static enum prop_handled handle_face_prop
P_ ((struct it
*));
558 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
559 static enum prop_handled handle_display_prop
P_ ((struct it
*));
560 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
561 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
562 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
564 /* Properties handled by iterators. */
566 static struct props it_props
[] =
568 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
569 /* Handle `face' before `display' because some sub-properties of
570 `display' need to know the face. */
571 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
572 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
573 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
574 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
578 /* Value is the position described by X. If X is a marker, value is
579 the marker_position of X. Otherwise, value is X. */
581 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
583 /* Enumeration returned by some move_it_.* functions internally. */
587 /* Not used. Undefined value. */
590 /* Move ended at the requested buffer position or ZV. */
591 MOVE_POS_MATCH_OR_ZV
,
593 /* Move ended at the requested X pixel position. */
596 /* Move within a line ended at the end of a line that must be
600 /* Move within a line ended at the end of a line that would
601 be displayed truncated. */
604 /* Move within a line ended at a line end. */
610 /* Function prototypes. */
612 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
613 static void ensure_echo_area_buffers
P_ ((void));
614 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
616 struct glyph_row
*));
617 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
618 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
619 static void clear_garbaged_frames
P_ ((void));
620 static int current_message_1
P_ ((Lisp_Object
*));
621 static int truncate_message_1
P_ ((int));
622 static int set_message_1
P_ ((char *s
, Lisp_Object
, int, int));
623 static int display_echo_area
P_ ((struct window
*));
624 static int display_echo_area_1
P_ ((struct window
*));
625 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
626 static int string_char_and_length
P_ ((unsigned char *, int, int *));
627 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
629 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
630 static Lisp_Object eval_handler
P_ ((Lisp_Object
));
631 static void insert_left_trunc_glyphs
P_ ((struct it
*));
632 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
633 static void extend_face_to_end_of_line
P_ ((struct it
*));
634 static int append_space
P_ ((struct it
*, int));
635 static void make_cursor_line_fully_visible
P_ ((struct window
*));
636 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
637 static int trailing_whitespace_p
P_ ((int));
638 static int message_log_check_duplicate
P_ ((int, int, int, int));
639 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
640 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
641 static void push_it
P_ ((struct it
*));
642 static void pop_it
P_ ((struct it
*));
643 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
644 static void redisplay_internal
P_ ((int));
645 static int echo_area_display
P_ ((int));
646 static void redisplay_windows
P_ ((Lisp_Object
));
647 static void redisplay_window
P_ ((Lisp_Object
, int));
648 static void update_menu_bar
P_ ((struct frame
*, int));
649 static int try_window_reusing_current_matrix
P_ ((struct window
*));
650 static int try_window_id
P_ ((struct window
*));
651 static int display_line
P_ ((struct it
*));
652 static void display_mode_lines
P_ ((struct window
*));
653 static void display_mode_line
P_ ((struct window
*, enum face_id
,
655 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
656 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
657 static void display_menu_bar
P_ ((struct window
*));
658 static int display_count_lines
P_ ((int, int, int, int, int *));
659 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
660 int, int, struct it
*, int, int, int, int));
661 static void compute_line_metrics
P_ ((struct it
*));
662 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
663 static int get_overlay_strings
P_ ((struct it
*));
664 static void next_overlay_string
P_ ((struct it
*));
665 void set_iterator_to_next
P_ ((struct it
*));
666 static void reseat
P_ ((struct it
*, struct text_pos
, int));
667 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
668 static void back_to_previous_visible_line_start
P_ ((struct it
*));
669 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
670 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
671 static int next_element_from_display_vector
P_ ((struct it
*));
672 static int next_element_from_string
P_ ((struct it
*));
673 static int next_element_from_c_string
P_ ((struct it
*));
674 static int next_element_from_buffer
P_ ((struct it
*));
675 static int next_element_from_composition
P_ ((struct it
*));
676 static int next_element_from_image
P_ ((struct it
*));
677 static int next_element_from_stretch
P_ ((struct it
*));
678 static void load_overlay_strings
P_ ((struct it
*));
679 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
680 struct display_pos
*));
681 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
682 Lisp_Object
, int, int, int, int));
683 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
685 void move_it_vertically_backward
P_ ((struct it
*, int));
686 static void init_to_row_start
P_ ((struct it
*, struct window
*,
687 struct glyph_row
*));
688 static void init_to_row_end
P_ ((struct it
*, struct window
*,
689 struct glyph_row
*));
690 static void back_to_previous_line_start
P_ ((struct it
*));
691 static void forward_to_next_line_start
P_ ((struct it
*));
692 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
694 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
695 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
696 static int number_of_chars
P_ ((unsigned char *, int));
697 static void compute_stop_pos
P_ ((struct it
*));
698 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
700 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
701 static int next_overlay_change
P_ ((int));
702 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
703 Lisp_Object
, struct text_pos
*));
705 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
706 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
708 #ifdef HAVE_WINDOW_SYSTEM
710 static void update_tool_bar
P_ ((struct frame
*, int));
711 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
712 static int redisplay_tool_bar
P_ ((struct frame
*));
713 static void display_tool_bar_line
P_ ((struct it
*));
715 #endif /* HAVE_WINDOW_SYSTEM */
718 /***********************************************************************
719 Window display dimensions
720 ***********************************************************************/
722 /* Return the window-relative maximum y + 1 for glyph rows displaying
723 text in window W. This is the height of W minus the height of a
724 mode line, if any. */
727 window_text_bottom_y (w
)
730 struct frame
*f
= XFRAME (w
->frame
);
731 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
733 if (WINDOW_WANTS_MODELINE_P (w
))
734 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
739 /* Return the pixel width of display area AREA of window W. AREA < 0
740 means return the total width of W, not including bitmap areas to
741 the left and right of the window. */
744 window_box_width (w
, area
)
748 struct frame
*f
= XFRAME (w
->frame
);
749 int width
= XFASTINT (w
->width
);
751 if (!w
->pseudo_window_p
)
753 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
755 if (area
== TEXT_AREA
)
757 if (INTEGERP (w
->left_margin_width
))
758 width
-= XFASTINT (w
->left_margin_width
);
759 if (INTEGERP (w
->right_margin_width
))
760 width
-= XFASTINT (w
->right_margin_width
);
762 else if (area
== LEFT_MARGIN_AREA
)
763 width
= (INTEGERP (w
->left_margin_width
)
764 ? XFASTINT (w
->left_margin_width
) : 0);
765 else if (area
== RIGHT_MARGIN_AREA
)
766 width
= (INTEGERP (w
->right_margin_width
)
767 ? XFASTINT (w
->right_margin_width
) : 0);
770 return width
* CANON_X_UNIT (f
);
774 /* Return the pixel height of the display area of window W, not
775 including mode lines of W, if any.. */
778 window_box_height (w
)
781 struct frame
*f
= XFRAME (w
->frame
);
782 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
784 if (WINDOW_WANTS_MODELINE_P (w
))
785 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
787 if (WINDOW_WANTS_HEADER_LINE_P (w
))
788 height
-= CURRENT_HEADER_LINE_HEIGHT (w
);
794 /* Return the frame-relative coordinate of the left edge of display
795 area AREA of window W. AREA < 0 means return the left edge of the
796 whole window, to the right of any bitmap area at the left side of
800 window_box_left (w
, area
)
804 struct frame
*f
= XFRAME (w
->frame
);
805 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
807 if (!w
->pseudo_window_p
)
809 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
810 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
812 if (area
== TEXT_AREA
)
813 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
814 else if (area
== RIGHT_MARGIN_AREA
)
815 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
816 + window_box_width (w
, TEXT_AREA
));
823 /* Return the frame-relative coordinate of the right edge of display
824 area AREA of window W. AREA < 0 means return the left edge of the
825 whole window, to the left of any bitmap area at the right side of
829 window_box_right (w
, area
)
833 return window_box_left (w
, area
) + window_box_width (w
, area
);
837 /* Get the bounding box of the display area AREA of window W, without
838 mode lines, in frame-relative coordinates. AREA < 0 means the
839 whole window, not including bitmap areas to the left and right of
840 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
841 coordinates of the upper-left corner of the box. Return in
842 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
845 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
848 int *box_x
, *box_y
, *box_width
, *box_height
;
850 struct frame
*f
= XFRAME (w
->frame
);
852 *box_width
= window_box_width (w
, area
);
853 *box_height
= window_box_height (w
);
854 *box_x
= window_box_left (w
, area
);
855 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
856 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
857 if (WINDOW_WANTS_HEADER_LINE_P (w
))
858 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
862 /* Get the bounding box of the display area AREA of window W, without
863 mode lines. AREA < 0 means the whole window, not including bitmap
864 areas to the left and right of the window. Return in *TOP_LEFT_X
865 and TOP_LEFT_Y the frame-relative pixel coordinates of the
866 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
867 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
871 window_box_edges (w
, area
, top_left_x
, top_left_y
,
872 bottom_right_x
, bottom_right_y
)
875 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
877 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
879 *bottom_right_x
+= *top_left_x
;
880 *bottom_right_y
+= *top_left_y
;
885 /***********************************************************************
887 ***********************************************************************/
889 /* Return the next character from STR which is MAXLEN bytes long.
890 Return in *LEN the length of the character. This is like
891 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
892 we find one, we return a `?', but with the length of the invalid
896 string_char_and_length (str
, maxlen
, len
)
902 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
903 if (!CHAR_VALID_P (c
, 1))
904 /* We may not change the length here because other places in Emacs
905 don't use this function, i.e. they silently accept invalid
914 /* Given a position POS containing a valid character and byte position
915 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
917 static struct text_pos
918 string_pos_nchars_ahead (pos
, string
, nchars
)
923 xassert (STRINGP (string
) && nchars
>= 0);
925 if (STRING_MULTIBYTE (string
))
927 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
928 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
933 string_char_and_length (p
, rest
, &len
);
934 p
+= len
, rest
-= len
;
937 BYTEPOS (pos
) += len
;
941 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
947 /* Value is the text position, i.e. character and byte position,
948 for character position CHARPOS in STRING. */
950 static INLINE
struct text_pos
951 string_pos (charpos
, string
)
956 xassert (STRINGP (string
));
957 xassert (charpos
>= 0);
958 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
963 /* Value is a text position, i.e. character and byte position, for
964 character position CHARPOS in C string S. MULTIBYTE_P non-zero
965 means recognize multibyte characters. */
967 static struct text_pos
968 c_string_pos (charpos
, s
, multibyte_p
)
976 xassert (charpos
>= 0);
980 int rest
= strlen (s
), len
;
982 SET_TEXT_POS (pos
, 0, 0);
985 string_char_and_length (s
, rest
, &len
);
986 s
+= len
, rest
-= len
;
989 BYTEPOS (pos
) += len
;
993 SET_TEXT_POS (pos
, charpos
, charpos
);
999 /* Value is the number of characters in C string S. MULTIBYTE_P
1000 non-zero means recognize multibyte characters. */
1003 number_of_chars (s
, multibyte_p
)
1011 int rest
= strlen (s
), len
;
1012 unsigned char *p
= (unsigned char *) s
;
1014 for (nchars
= 0; rest
> 0; ++nchars
)
1016 string_char_and_length (p
, rest
, &len
);
1017 rest
-= len
, p
+= len
;
1021 nchars
= strlen (s
);
1027 /* Compute byte position NEWPOS->bytepos corresponding to
1028 NEWPOS->charpos. POS is a known position in string STRING.
1029 NEWPOS->charpos must be >= POS.charpos. */
1032 compute_string_pos (newpos
, pos
, string
)
1033 struct text_pos
*newpos
, pos
;
1036 xassert (STRINGP (string
));
1037 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1039 if (STRING_MULTIBYTE (string
))
1040 *newpos
= string_pos_nchars_ahead (pos
, string
,
1041 CHARPOS (*newpos
) - CHARPOS (pos
));
1043 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1048 /***********************************************************************
1049 Lisp form evaluation
1050 ***********************************************************************/
1052 /* Error handler for eval_form and call_function. */
1062 /* Evaluate SEXPR and return the result, or nil if something went
1069 int count
= specpdl_ptr
- specpdl
;
1070 struct gcpro gcpro1
;
1074 specbind (Qinhibit_redisplay
, Qt
);
1075 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, eval_handler
);
1077 return unbind_to (count
, val
);
1081 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1082 Return the result, or nil if something went wrong. */
1085 call_function (nargs
, args
)
1089 int count
= specpdl_ptr
- specpdl
;
1091 struct gcpro gcpro1
;
1094 gcpro1
.nvars
= nargs
;
1095 specbind (Qinhibit_redisplay
, Qt
);
1096 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1099 return unbind_to (count
, val
);
1104 /***********************************************************************
1106 ***********************************************************************/
1110 /* Define CHECK_IT to perform sanity checks on iterators.
1111 This is for debugging. It is too slow to do unconditionally. */
1117 if (it
->method
== next_element_from_string
)
1119 xassert (STRINGP (it
->string
));
1120 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1122 else if (it
->method
== next_element_from_buffer
)
1124 /* Check that character and byte positions agree. */
1125 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1129 xassert (it
->current
.dpvec_index
>= 0);
1131 xassert (it
->current
.dpvec_index
< 0);
1134 #define CHECK_IT(IT) check_it ((IT))
1138 #define CHECK_IT(IT) (void) 0
1145 /* Check that the window end of window W is what we expect it
1146 to be---the last row in the current matrix displaying text. */
1149 check_window_end (w
)
1152 if (!MINI_WINDOW_P (w
)
1153 && !NILP (w
->window_end_valid
))
1155 struct glyph_row
*row
;
1156 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1157 XFASTINT (w
->window_end_vpos
)),
1159 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1160 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1164 #define CHECK_WINDOW_END(W) check_window_end ((W))
1166 #else /* not GLYPH_DEBUG */
1168 #define CHECK_WINDOW_END(W) (void) 0
1170 #endif /* not GLYPH_DEBUG */
1174 /***********************************************************************
1175 Iterator initialization
1176 ***********************************************************************/
1178 /* Initialize IT for displaying current_buffer in window W, starting
1179 at character position CHARPOS. CHARPOS < 0 means that no buffer
1180 position is specified which is useful when the iterator is assigned
1181 a position later. BYTEPOS is the byte position corresponding to
1182 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1184 If ROW is not null, calls to produce_glyphs with IT as parameter
1185 will produce glyphs in that row.
1187 BASE_FACE_ID is the id of a base face to use. It must be one of
1188 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1189 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1190 displaying the tool-bar.
1192 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1193 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1194 corresponding mode line glyph row of the desired matrix of W. */
1197 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1200 int charpos
, bytepos
;
1201 struct glyph_row
*row
;
1202 enum face_id base_face_id
;
1204 int highlight_region_p
;
1206 /* Some precondition checks. */
1207 xassert (w
!= NULL
&& it
!= NULL
);
1208 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1210 /* If face attributes have been changed since the last redisplay,
1211 free realized faces now because they depend on face definitions
1212 that might have changed. */
1213 if (face_change_count
)
1215 face_change_count
= 0;
1216 free_all_realized_faces (Qnil
);
1219 /* Use one of the mode line rows of W's desired matrix if
1223 if (base_face_id
== MODE_LINE_FACE_ID
)
1224 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1225 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1226 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1230 bzero (it
, sizeof *it
);
1231 it
->current
.overlay_string_index
= -1;
1232 it
->current
.dpvec_index
= -1;
1233 it
->base_face_id
= base_face_id
;
1235 /* The window in which we iterate over current_buffer: */
1236 XSETWINDOW (it
->window
, w
);
1238 it
->f
= XFRAME (w
->frame
);
1240 /* Extra space between lines (on window systems only). */
1241 if (base_face_id
== DEFAULT_FACE_ID
1242 && FRAME_WINDOW_P (it
->f
))
1244 if (NATNUMP (current_buffer
->extra_line_spacing
))
1245 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1246 else if (it
->f
->extra_line_spacing
> 0)
1247 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1250 /* If realized faces have been removed, e.g. because of face
1251 attribute changes of named faces, recompute them. */
1252 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1253 recompute_basic_faces (it
->f
);
1255 /* Current value of the `space-width', and 'height' properties. */
1256 it
->space_width
= Qnil
;
1257 it
->font_height
= Qnil
;
1259 /* Are control characters displayed as `^C'? */
1260 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1262 /* -1 means everything between a CR and the following line end
1263 is invisible. >0 means lines indented more than this value are
1265 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1266 ? XFASTINT (current_buffer
->selective_display
)
1267 : (!NILP (current_buffer
->selective_display
)
1269 it
->selective_display_ellipsis_p
1270 = !NILP (current_buffer
->selective_display_ellipses
);
1272 /* Display table to use. */
1273 it
->dp
= window_display_table (w
);
1275 /* Are multibyte characters enabled in current_buffer? */
1276 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1278 /* Non-zero if we should highlight the region. */
1280 = (!NILP (Vtransient_mark_mode
)
1281 && !NILP (current_buffer
->mark_active
)
1282 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1284 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1285 start and end of a visible region in window IT->w. Set both to
1286 -1 to indicate no region. */
1287 if (highlight_region_p
1288 /* Maybe highlight only in selected window. */
1289 && (/* Either show region everywhere. */
1290 highlight_nonselected_windows
1291 /* Or show region in the selected window. */
1292 || w
== XWINDOW (selected_window
)
1293 /* Or show the region if we are in the mini-buffer and W is
1294 the window the mini-buffer refers to. */
1295 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1296 && w
== XWINDOW (Vminibuf_scroll_window
))))
1298 int charpos
= marker_position (current_buffer
->mark
);
1299 it
->region_beg_charpos
= min (PT
, charpos
);
1300 it
->region_end_charpos
= max (PT
, charpos
);
1303 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1305 /* Get the position at which the redisplay_end_trigger hook should
1306 be run, if it is to be run at all. */
1307 if (MARKERP (w
->redisplay_end_trigger
)
1308 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1309 it
->redisplay_end_trigger_charpos
1310 = marker_position (w
->redisplay_end_trigger
);
1311 else if (INTEGERP (w
->redisplay_end_trigger
))
1312 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1314 /* Correct bogus values of tab_width. */
1315 it
->tab_width
= XINT (current_buffer
->tab_width
);
1316 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1319 /* Are lines in the display truncated? */
1320 it
->truncate_lines_p
1321 = (base_face_id
!= DEFAULT_FACE_ID
1322 || XINT (it
->w
->hscroll
)
1323 || (truncate_partial_width_windows
1324 && !WINDOW_FULL_WIDTH_P (it
->w
))
1325 || !NILP (current_buffer
->truncate_lines
));
1327 /* Get dimensions of truncation and continuation glyphs. These are
1328 displayed as bitmaps under X, so we don't need them for such
1330 if (!FRAME_WINDOW_P (it
->f
))
1332 if (it
->truncate_lines_p
)
1334 /* We will need the truncation glyph. */
1335 xassert (it
->glyph_row
== NULL
);
1336 produce_special_glyphs (it
, IT_TRUNCATION
);
1337 it
->truncation_pixel_width
= it
->pixel_width
;
1341 /* We will need the continuation glyph. */
1342 xassert (it
->glyph_row
== NULL
);
1343 produce_special_glyphs (it
, IT_CONTINUATION
);
1344 it
->continuation_pixel_width
= it
->pixel_width
;
1347 /* Reset these values to zero becaue the produce_special_glyphs
1348 above has changed them. */
1349 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1350 it
->phys_ascent
= it
->phys_descent
= 0;
1353 /* Set this after getting the dimensions of truncation and
1354 continuation glyphs, so that we don't produce glyphs when calling
1355 produce_special_glyphs, above. */
1356 it
->glyph_row
= row
;
1357 it
->area
= TEXT_AREA
;
1359 /* Get the dimensions of the display area. The display area
1360 consists of the visible window area plus a horizontally scrolled
1361 part to the left of the window. All x-values are relative to the
1362 start of this total display area. */
1363 if (base_face_id
!= DEFAULT_FACE_ID
)
1365 /* Mode lines, menu bar in terminal frames. */
1366 it
->first_visible_x
= 0;
1367 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1372 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1373 it
->last_visible_x
= (it
->first_visible_x
1374 + window_box_width (w
, TEXT_AREA
));
1376 /* If we truncate lines, leave room for the truncator glyph(s) at
1377 the right margin. Otherwise, leave room for the continuation
1378 glyph(s). Truncation and continuation glyphs are not inserted
1379 for window-based redisplay. */
1380 if (!FRAME_WINDOW_P (it
->f
))
1382 if (it
->truncate_lines_p
)
1383 it
->last_visible_x
-= it
->truncation_pixel_width
;
1385 it
->last_visible_x
-= it
->continuation_pixel_width
;
1388 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1389 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1392 /* Leave room for a border glyph. */
1393 if (!FRAME_WINDOW_P (it
->f
)
1394 && !WINDOW_RIGHTMOST_P (it
->w
))
1395 it
->last_visible_x
-= 1;
1397 it
->last_visible_y
= window_text_bottom_y (w
);
1399 /* For mode lines and alike, arrange for the first glyph having a
1400 left box line if the face specifies a box. */
1401 if (base_face_id
!= DEFAULT_FACE_ID
)
1405 it
->face_id
= base_face_id
;
1407 /* If we have a boxed mode line, make the first character appear
1408 with a left box line. */
1409 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1410 if (face
->box
!= FACE_NO_BOX
)
1411 it
->start_of_box_run_p
= 1;
1414 /* If a buffer position was specified, set the iterator there,
1415 getting overlays and face properties from that position. */
1418 it
->end_charpos
= ZV
;
1420 IT_CHARPOS (*it
) = charpos
;
1422 /* Compute byte position if not specified. */
1424 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1426 IT_BYTEPOS (*it
) = bytepos
;
1428 /* Compute faces etc. */
1429 reseat (it
, it
->current
.pos
, 1);
1436 /* Initialize IT for the display of window W with window start POS. */
1439 start_display (it
, w
, pos
)
1442 struct text_pos pos
;
1444 int start_at_line_beg_p
;
1445 struct glyph_row
*row
;
1446 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1449 row
= w
->desired_matrix
->rows
+ first_vpos
;
1450 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1451 first_y
= it
->current_y
;
1453 /* If window start is not at a line start, move back to the line
1454 start. This makes sure that we take continuation lines into
1456 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1457 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1458 if (!start_at_line_beg_p
)
1459 reseat_at_previous_visible_line_start (it
);
1461 /* If window start is not at a line start, skip forward to POS to
1462 get the correct continuation_lines_width and current_x. */
1463 if (!start_at_line_beg_p
)
1465 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1467 /* If lines are continued, this line may end in the middle of a
1468 multi-glyph character (e.g. a control character displayed as
1469 \003, or in the middle of an overlay string). In this case
1470 move_it_to above will not have taken us to the start of
1471 the continuation line but to the end of the continued line. */
1472 if (!it
->truncate_lines_p
&& it
->current_x
> 0)
1474 if (it
->current
.dpvec_index
>= 0
1475 || it
->current
.overlay_string_index
>= 0)
1477 set_iterator_to_next (it
);
1478 move_it_in_display_line_to (it
, -1, -1, 0);
1480 it
->continuation_lines_width
+= it
->current_x
;
1483 it
->current_y
= first_y
;
1485 it
->current_x
= it
->hpos
= 0;
1488 #if 0 /* Don't assert the following because start_display is sometimes
1489 called intentionally with a window start that is not at a
1490 line start. Please leave this code in as a comment. */
1492 /* Window start should be on a line start, now. */
1493 xassert (it
->continuation_lines_width
1494 || IT_CHARPOS (it
) == BEGV
1495 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1500 /* Initialize IT for stepping through current_buffer in window W,
1501 starting at position POS that includes overlay string and display
1502 vector/ control character translation position information. */
1505 init_from_display_pos (it
, w
, pos
)
1508 struct display_pos
*pos
;
1510 /* Keep in mind: the call to reseat in init_iterator skips invisible
1511 text, so we might end up at a position different from POS. This
1512 is only a problem when POS is a row start after a newline and an
1513 overlay starts there with an after-string, and the overlay has an
1514 invisible property. Since we don't skip invisible text in
1515 display_line and elsewhere immediately after consuming the
1516 newline before the row start, such a POS will not be in a string,
1517 but the call to init_iterator below will move us to the
1519 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1520 NULL
, DEFAULT_FACE_ID
);
1522 /* If position is within an overlay string, set up IT to
1523 the right overlay string. */
1524 if (pos
->overlay_string_index
>= 0)
1528 /* We already have the first chunk of overlay strings in
1529 IT->overlay_strings. Load more until the one for
1530 pos->overlay_string_index is in IT->overlay_strings. */
1531 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1533 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1534 it
->current
.overlay_string_index
= 0;
1537 load_overlay_strings (it
);
1538 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1542 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1543 relative_index
= (it
->current
.overlay_string_index
1544 % OVERLAY_STRING_CHUNK_SIZE
);
1545 it
->string
= it
->overlay_strings
[relative_index
];
1546 it
->current
.string_pos
= pos
->string_pos
;
1547 it
->method
= next_element_from_string
;
1549 else if (CHARPOS (pos
->string_pos
) >= 0)
1551 /* Recorded position is not in an overlay string, but in another
1552 string. This can only be a string from a `display' property.
1553 IT should already be filled with that string. */
1554 it
->current
.string_pos
= pos
->string_pos
;
1555 xassert (STRINGP (it
->string
));
1558 /* Restore position in display vector translations or control
1559 character translations. */
1560 if (pos
->dpvec_index
>= 0)
1562 /* This fills IT->dpvec. */
1563 get_next_display_element (it
);
1564 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1565 it
->current
.dpvec_index
= pos
->dpvec_index
;
1572 /* Initialize IT for stepping through current_buffer in window W
1573 starting at ROW->start. */
1576 init_to_row_start (it
, w
, row
)
1579 struct glyph_row
*row
;
1581 init_from_display_pos (it
, w
, &row
->start
);
1582 it
->continuation_lines_width
= row
->continuation_lines_width
;
1587 /* Initialize IT for stepping through current_buffer in window W
1588 starting in the line following ROW, i.e. starting at ROW->end. */
1591 init_to_row_end (it
, w
, row
)
1594 struct glyph_row
*row
;
1596 init_from_display_pos (it
, w
, &row
->end
);
1598 if (row
->continued_p
)
1599 it
->continuation_lines_width
= (row
->continuation_lines_width
1600 + row
->pixel_width
);
1607 /***********************************************************************
1609 ***********************************************************************/
1611 /* Called when IT reaches IT->stop_charpos. Handle text property and
1612 overlay changes. Set IT->stop_charpos to the next position where
1619 enum prop_handled handled
;
1620 int handle_overlay_change_p
= 1;
1624 it
->current
.dpvec_index
= -1;
1625 it
->add_overlay_start
= 0;
1629 handled
= HANDLED_NORMALLY
;
1631 /* Call text property handlers. */
1632 for (p
= it_props
; p
->handler
; ++p
)
1634 handled
= p
->handler (it
);
1636 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1638 else if (handled
== HANDLED_RETURN
)
1640 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1641 handle_overlay_change_p
= 0;
1644 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1646 /* Don't check for overlay strings below when set to deliver
1647 characters from a display vector. */
1648 if (it
->method
== next_element_from_display_vector
)
1649 handle_overlay_change_p
= 0;
1651 /* Handle overlay changes. */
1652 if (handle_overlay_change_p
)
1653 handled
= handle_overlay_change (it
);
1655 /* Determine where to stop next. */
1656 if (handled
== HANDLED_NORMALLY
)
1657 compute_stop_pos (it
);
1660 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1664 /* Compute IT->stop_charpos from text property and overlay change
1665 information for IT's current position. */
1668 compute_stop_pos (it
)
1671 register INTERVAL iv
, next_iv
;
1672 Lisp_Object object
, limit
, position
;
1674 /* If nowhere else, stop at the end. */
1675 it
->stop_charpos
= it
->end_charpos
;
1677 if (STRINGP (it
->string
))
1679 /* Strings are usually short, so don't limit the search for
1681 object
= it
->string
;
1683 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1689 /* If next overlay change is in front of the current stop pos
1690 (which is IT->end_charpos), stop there. Note: value of
1691 next_overlay_change is point-max if no overlay change
1693 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1694 if (charpos
< it
->stop_charpos
)
1695 it
->stop_charpos
= charpos
;
1697 /* If showing the region, we have to stop at the region
1698 start or end because the face might change there. */
1699 if (it
->region_beg_charpos
> 0)
1701 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1702 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1703 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1704 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1707 /* Set up variables for computing the stop position from text
1708 property changes. */
1709 XSETBUFFER (object
, current_buffer
);
1710 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1711 XSETFASTINT (position
, IT_CHARPOS (*it
));
1715 /* Get the interval containing IT's position. Value is a null
1716 interval if there isn't such an interval. */
1717 iv
= validate_interval_range (object
, &position
, &position
, 0);
1718 if (!NULL_INTERVAL_P (iv
))
1720 Lisp_Object values_here
[LAST_PROP_IDX
];
1723 /* Get properties here. */
1724 for (p
= it_props
; p
->handler
; ++p
)
1725 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1727 /* Look for an interval following iv that has different
1729 for (next_iv
= next_interval (iv
);
1730 (!NULL_INTERVAL_P (next_iv
)
1732 || XFASTINT (limit
) > next_iv
->position
));
1733 next_iv
= next_interval (next_iv
))
1735 for (p
= it_props
; p
->handler
; ++p
)
1737 Lisp_Object new_value
;
1739 new_value
= textget (next_iv
->plist
, *p
->name
);
1740 if (!EQ (values_here
[p
->idx
], new_value
))
1748 if (!NULL_INTERVAL_P (next_iv
))
1750 if (INTEGERP (limit
)
1751 && next_iv
->position
>= XFASTINT (limit
))
1752 /* No text property change up to limit. */
1753 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1755 /* Text properties change in next_iv. */
1756 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1760 xassert (STRINGP (it
->string
)
1761 || (it
->stop_charpos
>= BEGV
1762 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1766 /* Return the position of the next overlay change after POS in
1767 current_buffer. Value is point-max if no overlay change
1768 follows. This is like `next-overlay-change' but doesn't use
1772 next_overlay_change (pos
)
1777 Lisp_Object
*overlays
;
1781 /* Get all overlays at the given position. */
1783 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1784 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1785 if (noverlays
> len
)
1788 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1789 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1792 /* If any of these overlays ends before endpos,
1793 use its ending point instead. */
1794 for (i
= 0; i
< noverlays
; ++i
)
1799 oend
= OVERLAY_END (overlays
[i
]);
1800 oendpos
= OVERLAY_POSITION (oend
);
1801 endpos
= min (endpos
, oendpos
);
1809 /***********************************************************************
1811 ***********************************************************************/
1813 /* Handle changes in the `fontified' property of the current buffer by
1814 calling hook functions from Qfontification_functions to fontify
1817 static enum prop_handled
1818 handle_fontified_prop (it
)
1821 Lisp_Object prop
, pos
;
1822 enum prop_handled handled
= HANDLED_NORMALLY
;
1824 /* Get the value of the `fontified' property at IT's current buffer
1825 position. (The `fontified' property doesn't have a special
1826 meaning in strings.) If the value is nil, call functions from
1827 Qfontification_functions. */
1828 if (!STRINGP (it
->string
)
1830 && !NILP (Vfontification_functions
)
1831 && (pos
= make_number (IT_CHARPOS (*it
)),
1832 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1835 Lisp_Object args
[2];
1837 /* Run the hook functions. */
1838 args
[0] = Qfontification_functions
;
1840 Frun_hook_with_args (2, args
);
1842 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
1843 something. This avoids an endless loop if they failed to
1844 fontify the text for which reason ever. */
1845 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
1846 handled
= HANDLED_RECOMPUTE_PROPS
;
1854 /***********************************************************************
1856 ***********************************************************************/
1858 /* Set up iterator IT from face properties at its current position.
1859 Called from handle_stop. */
1861 static enum prop_handled
1862 handle_face_prop (it
)
1865 int new_face_id
, next_stop
;
1867 if (!STRINGP (it
->string
))
1870 = face_at_buffer_position (it
->w
,
1872 it
->region_beg_charpos
,
1873 it
->region_end_charpos
,
1876 + TEXT_PROP_DISTANCE_LIMIT
),
1879 /* Is this a start of a run of characters with box face?
1880 Caveat: this can be called for a freshly initialized
1881 iterator; face_id is -1 is this case. We know that the new
1882 face will not change until limit, i.e. if the new face has a
1883 box, all characters up to limit will have one. But, as
1884 usual, we don't know whether limit is really the end. */
1885 if (new_face_id
!= it
->face_id
)
1887 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1889 /* If new face has a box but old face has not, this is
1890 the start of a run of characters with box, i.e. it has
1891 a shadow on the left side. The value of face_id of the
1892 iterator will be -1 if this is the initial call that gets
1893 the face. In this case, we have to look in front of IT's
1894 position and see whether there is a face != new_face_id. */
1895 it
->start_of_box_run_p
1896 = (new_face
->box
!= FACE_NO_BOX
1897 && (it
->face_id
>= 0
1898 || IT_CHARPOS (*it
) == BEG
1899 || new_face_id
!= face_before_it_pos (it
)));
1900 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1906 = face_at_string_position (it
->w
,
1908 IT_STRING_CHARPOS (*it
),
1909 (it
->current
.overlay_string_index
>= 0
1912 it
->region_beg_charpos
,
1913 it
->region_end_charpos
,
1917 #if 0 /* This shouldn't be neccessary. Let's check it. */
1918 /* If IT is used to display a mode line we would really like to
1919 use the mode line face instead of the frame's default face. */
1920 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
1921 && new_face_id
== DEFAULT_FACE_ID
)
1922 new_face_id
= MODE_LINE_FACE_ID
;
1925 /* Is this a start of a run of characters with box? Caveat:
1926 this can be called for a freshly allocated iterator; face_id
1927 is -1 is this case. We know that the new face will not
1928 change until the next check pos, i.e. if the new face has a
1929 box, all characters up to that position will have a
1930 box. But, as usual, we don't know whether that position
1931 is really the end. */
1932 if (new_face_id
!= it
->face_id
)
1934 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1935 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1937 /* If new face has a box but old face hasn't, this is the
1938 start of a run of characters with box, i.e. it has a
1939 shadow on the left side. */
1940 it
->start_of_box_run_p
1941 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
1942 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1946 it
->face_id
= new_face_id
;
1947 return HANDLED_NORMALLY
;
1951 /* Compute the face one character before or after the current position
1952 of IT. BEFORE_P non-zero means get the face in front of IT's
1953 position. Value is the id of the face. */
1956 face_before_or_after_it_pos (it
, before_p
)
1961 int next_check_charpos
;
1962 struct text_pos pos
;
1964 xassert (it
->s
== NULL
);
1966 if (STRINGP (it
->string
))
1968 /* No face change past the end of the string (for the case
1969 we are padding with spaces). No face change before the
1971 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
1972 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
1975 /* Set pos to the position before or after IT's current position. */
1977 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
1979 /* For composition, we must check the character after the
1981 pos
= (it
->what
== IT_COMPOSITION
1982 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
1983 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
1985 /* Get the face for ASCII, or unibyte. */
1987 = face_at_string_position (it
->w
,
1990 (it
->current
.overlay_string_index
>= 0
1993 it
->region_beg_charpos
,
1994 it
->region_end_charpos
,
1995 &next_check_charpos
,
1998 /* Correct the face for charsets different from ASCII. Do it
1999 for the multibyte case only. The face returned above is
2000 suitable for unibyte text if IT->string is unibyte. */
2001 if (STRING_MULTIBYTE (it
->string
))
2003 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2004 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2006 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2008 c
= string_char_and_length (p
, rest
, &len
);
2009 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2014 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2015 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2018 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2019 pos
= it
->current
.pos
;
2022 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2025 if (it
->what
== IT_COMPOSITION
)
2026 /* For composition, we must check the position after the
2028 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2030 INC_TEXT_POS (pos
, it
->multibyte_p
);
2032 /* Determine face for CHARSET_ASCII, or unibyte. */
2033 face_id
= face_at_buffer_position (it
->w
,
2035 it
->region_beg_charpos
,
2036 it
->region_end_charpos
,
2037 &next_check_charpos
,
2040 /* Correct the face for charsets different from ASCII. Do it
2041 for the multibyte case only. The face returned above is
2042 suitable for unibyte text if current_buffer is unibyte. */
2043 if (it
->multibyte_p
)
2045 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2046 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2047 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2056 /***********************************************************************
2058 ***********************************************************************/
2060 /* Set up iterator IT from invisible properties at its current
2061 position. Called from handle_stop. */
2063 static enum prop_handled
2064 handle_invisible_prop (it
)
2067 enum prop_handled handled
= HANDLED_NORMALLY
;
2069 if (STRINGP (it
->string
))
2071 extern Lisp_Object Qinvisible
;
2072 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2074 /* Get the value of the invisible text property at the
2075 current position. Value will be nil if there is no such
2077 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2078 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2081 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2083 handled
= HANDLED_RECOMPUTE_PROPS
;
2085 /* Get the position at which the next change of the
2086 invisible text property can be found in IT->string.
2087 Value will be nil if the property value is the same for
2088 all the rest of IT->string. */
2089 XSETINT (limit
, XSTRING (it
->string
)->size
);
2090 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2093 /* Text at current position is invisible. The next
2094 change in the property is at position end_charpos.
2095 Move IT's current position to that position. */
2096 if (INTEGERP (end_charpos
)
2097 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2099 struct text_pos old
;
2100 old
= it
->current
.string_pos
;
2101 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2102 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2106 /* The rest of the string is invisible. If this is an
2107 overlay string, proceed with the next overlay string
2108 or whatever comes and return a character from there. */
2109 if (it
->current
.overlay_string_index
>= 0)
2111 next_overlay_string (it
);
2112 /* Don't check for overlay strings when we just
2113 finished processing them. */
2114 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2118 struct Lisp_String
*s
= XSTRING (it
->string
);
2119 IT_STRING_CHARPOS (*it
) = s
->size
;
2120 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2127 int visible_p
, newpos
, next_stop
;
2128 Lisp_Object pos
, prop
;
2130 /* First of all, is there invisible text at this position? */
2131 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2132 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2134 /* If we are on invisible text, skip over it. */
2135 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2136 && IT_CHARPOS (*it
) < it
->end_charpos
)
2138 /* Record whether we have to display an ellipsis for the
2140 int display_ellipsis_p
2141 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2143 handled
= HANDLED_RECOMPUTE_PROPS
;
2144 it
->add_overlay_start
= IT_CHARPOS (*it
);
2146 /* Loop skipping over invisible text. The loop is left at
2147 ZV or with IT on the first char being visible again. */
2150 /* Try to skip some invisible text. Return value is the
2151 position reached which can be equal to IT's position
2152 if there is nothing invisible here. This skips both
2153 over invisible text properties and overlays with
2154 invisible property. */
2155 newpos
= skip_invisible (IT_CHARPOS (*it
),
2156 &next_stop
, ZV
, it
->window
);
2158 /* If we skipped nothing at all we weren't at invisible
2159 text in the first place. If everything to the end of
2160 the buffer was skipped, end the loop. */
2161 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2165 /* We skipped some characters but not necessarily
2166 all there are. Check if we ended up on visible
2167 text. Fget_char_property returns the property of
2168 the char before the given position, i.e. if we
2169 get visible_p = 1, this means that the char at
2170 newpos is visible. */
2171 XSETFASTINT (pos
, newpos
);
2172 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2173 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2176 /* If we ended up on invisible text, proceed to
2177 skip starting with next_stop. */
2179 IT_CHARPOS (*it
) = next_stop
;
2183 /* The position newpos is now either ZV or on visible text. */
2184 IT_CHARPOS (*it
) = newpos
;
2185 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2187 /* Maybe return `...' next for the end of the invisible text. */
2188 if (display_ellipsis_p
)
2191 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2193 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2194 it
->dpvec
= v
->contents
;
2195 it
->dpend
= v
->contents
+ v
->size
;
2199 /* Default `...'. */
2200 it
->dpvec
= default_invis_vector
;
2201 it
->dpend
= default_invis_vector
+ 3;
2204 /* The ellipsis display does not replace the display of
2205 the character at the new position. Indicate this by
2206 setting IT->dpvec_char_len to zero. */
2207 it
->dpvec_char_len
= 0;
2209 it
->current
.dpvec_index
= 0;
2210 it
->method
= next_element_from_display_vector
;
2220 /***********************************************************************
2222 ***********************************************************************/
2224 /* Set up iterator IT from `display' property at its current position.
2225 Called from handle_stop. */
2227 static enum prop_handled
2228 handle_display_prop (it
)
2231 Lisp_Object prop
, object
;
2232 struct text_pos
*position
;
2233 int space_or_image_found_p
;
2235 if (STRINGP (it
->string
))
2237 object
= it
->string
;
2238 position
= &it
->current
.string_pos
;
2243 position
= &it
->current
.pos
;
2246 /* Reset those iterator values set from display property values. */
2247 it
->font_height
= Qnil
;
2248 it
->space_width
= Qnil
;
2251 /* We don't support recursive `display' properties, i.e. string
2252 values that have a string `display' property, that have a string
2253 `display' property etc. */
2254 if (!it
->string_from_display_prop_p
)
2255 it
->area
= TEXT_AREA
;
2257 prop
= Fget_char_property (make_number (position
->charpos
),
2260 return HANDLED_NORMALLY
;
2262 space_or_image_found_p
= 0;
2264 && CONSP (XCAR (prop
))
2265 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2267 /* A list of sub-properties. */
2268 while (CONSP (prop
))
2270 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2271 space_or_image_found_p
= 1;
2275 else if (VECTORP (prop
))
2278 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2279 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2281 space_or_image_found_p
= 1;
2285 if (handle_single_display_prop (it
, prop
, object
, position
))
2286 space_or_image_found_p
= 1;
2289 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2293 /* Value is the position of the end of the `display' property starting
2294 at START_POS in OBJECT. */
2296 static struct text_pos
2297 display_prop_end (it
, object
, start_pos
)
2300 struct text_pos start_pos
;
2303 struct text_pos end_pos
;
2305 end
= next_single_char_property_change (make_number (CHARPOS (start_pos
)),
2306 Qdisplay
, object
, Qnil
);
2307 CHARPOS (end_pos
) = XFASTINT (end
);
2308 if (STRINGP (object
))
2309 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2311 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2317 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2318 is the object in which the `display' property was found. *POSITION
2319 is the position at which it was found.
2321 If PROP is a `space' or `image' sub-property, set *POSITION to the
2322 end position of the `display' property.
2324 Value is non-zero if a `space' or `image' property value was found. */
2327 handle_single_display_prop (it
, prop
, object
, position
)
2331 struct text_pos
*position
;
2334 int space_or_image_found_p
= 0;
2337 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2338 evaluated. If the result is nil, VALUE is ignored. */
2340 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2349 if (!NILP (form
) && !EQ (form
, Qt
))
2351 struct gcpro gcpro1
;
2352 struct text_pos end_pos
, pt
;
2355 end_pos
= display_prop_end (it
, object
, *position
);
2357 /* Temporarily set point to the end position, and then evaluate
2358 the form. This makes `(eolp)' work as FORM. */
2359 if (BUFFERP (object
))
2362 BYTEPOS (pt
) = PT_BYTE
;
2363 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2366 form
= eval_form (form
);
2368 if (BUFFERP (object
))
2369 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2377 && EQ (XCAR (prop
), Qheight
)
2378 && CONSP (XCDR (prop
)))
2380 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2383 /* `(height HEIGHT)'. */
2384 it
->font_height
= XCAR (XCDR (prop
));
2385 if (!NILP (it
->font_height
))
2387 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2388 int new_height
= -1;
2390 if (CONSP (it
->font_height
)
2391 && (EQ (XCAR (it
->font_height
), Qplus
)
2392 || EQ (XCAR (it
->font_height
), Qminus
))
2393 && CONSP (XCDR (it
->font_height
))
2394 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2396 /* `(+ N)' or `(- N)' where N is an integer. */
2397 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2398 if (EQ (XCAR (it
->font_height
), Qplus
))
2400 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2402 else if (FUNCTIONP (it
->font_height
))
2404 /* Call function with current height as argument.
2405 Value is the new height. */
2406 Lisp_Object args
[2], height
;
2408 args
[0] = it
->font_height
;
2409 args
[1] = face
->lface
[LFACE_HEIGHT_INDEX
];
2410 height
= call_function (2, args
);
2412 if (NUMBERP (height
))
2413 new_height
= XFLOATINT (height
);
2415 else if (NUMBERP (it
->font_height
))
2417 /* Value is a multiple of the canonical char height. */
2420 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2421 new_height
= (XFLOATINT (it
->font_height
)
2422 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2426 /* Evaluate IT->font_height with `height' bound to the
2427 current specified height to get the new height. */
2429 int count
= specpdl_ptr
- specpdl
;
2431 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2432 value
= eval_form (it
->font_height
);
2433 unbind_to (count
, Qnil
);
2435 if (NUMBERP (value
))
2436 new_height
= XFLOATINT (value
);
2440 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2443 else if (CONSP (prop
)
2444 && EQ (XCAR (prop
), Qspace_width
)
2445 && CONSP (XCDR (prop
)))
2447 /* `(space_width WIDTH)'. */
2448 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2451 value
= XCAR (XCDR (prop
));
2452 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2453 it
->space_width
= value
;
2455 else if (CONSP (prop
)
2456 && EQ (XCAR (prop
), Qraise
)
2457 && CONSP (XCDR (prop
)))
2459 /* `(raise FACTOR)'. */
2460 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2463 #ifdef HAVE_WINDOW_SYSTEM
2464 value
= XCAR (XCDR (prop
));
2465 if (NUMBERP (value
))
2467 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2468 it
->voffset
= - (XFLOATINT (value
)
2469 * (FONT_HEIGHT (face
->font
)));
2471 #endif /* HAVE_WINDOW_SYSTEM */
2473 else if (!it
->string_from_display_prop_p
)
2475 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2476 VALUE) or `((margin nil) VALUE)' or VALUE. */
2477 Lisp_Object location
, value
;
2478 struct text_pos start_pos
;
2481 /* Characters having this form of property are not displayed, so
2482 we have to find the end of the property. */
2483 start_pos
= *position
;
2484 *position
= display_prop_end (it
, object
, start_pos
);
2487 /* Let's stop at the new position and assume that all
2488 text properties change there. */
2489 it
->stop_charpos
= position
->charpos
;
2491 location
= Qunbound
;
2492 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2496 value
= XCDR (prop
);
2498 value
= XCAR (value
);
2501 if (EQ (XCAR (tem
), Qmargin
)
2502 && (tem
= XCDR (tem
),
2503 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2505 || EQ (tem
, Qleft_margin
)
2506 || EQ (tem
, Qright_margin
))))
2510 if (EQ (location
, Qunbound
))
2516 #ifdef HAVE_WINDOW_SYSTEM
2517 if (FRAME_TERMCAP_P (it
->f
))
2518 valid_p
= STRINGP (value
);
2520 valid_p
= (STRINGP (value
)
2521 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2522 || valid_image_p (value
));
2523 #else /* not HAVE_WINDOW_SYSTEM */
2524 valid_p
= STRINGP (value
);
2525 #endif /* not HAVE_WINDOW_SYSTEM */
2527 if ((EQ (location
, Qleft_margin
)
2528 || EQ (location
, Qright_margin
)
2532 space_or_image_found_p
= 1;
2534 /* Save current settings of IT so that we can restore them
2535 when we are finished with the glyph property value. */
2538 if (NILP (location
))
2539 it
->area
= TEXT_AREA
;
2540 else if (EQ (location
, Qleft_margin
))
2541 it
->area
= LEFT_MARGIN_AREA
;
2543 it
->area
= RIGHT_MARGIN_AREA
;
2545 if (STRINGP (value
))
2548 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2549 it
->current
.overlay_string_index
= -1;
2550 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2551 it
->end_charpos
= it
->string_nchars
2552 = XSTRING (it
->string
)->size
;
2553 it
->method
= next_element_from_string
;
2554 it
->stop_charpos
= 0;
2555 it
->string_from_display_prop_p
= 1;
2557 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2559 it
->method
= next_element_from_stretch
;
2561 it
->current
.pos
= it
->position
= start_pos
;
2563 #ifdef HAVE_WINDOW_SYSTEM
2566 it
->what
= IT_IMAGE
;
2567 it
->image_id
= lookup_image (it
->f
, value
);
2568 it
->position
= start_pos
;
2569 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2570 it
->method
= next_element_from_image
;
2572 /* Say that we haven't consumed the characters with
2573 `display' property yet. The call to pop_it in
2574 set_iterator_to_next will clean this up. */
2575 *position
= start_pos
;
2577 #endif /* HAVE_WINDOW_SYSTEM */
2580 /* Invalid property or property not supported. Restore
2581 the position to what it was before. */
2582 *position
= start_pos
;
2585 return space_or_image_found_p
;
2589 /* Check if PROP is a display sub-property value whose text should be
2590 treated as intangible. */
2593 single_display_prop_intangible_p (prop
)
2596 /* Skip over `when FORM'. */
2597 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2608 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
2609 we don't need to treat text as intangible. */
2610 if (EQ (XCAR (prop
), Qmargin
))
2618 || EQ (XCAR (prop
), Qleft_margin
)
2619 || EQ (XCAR (prop
), Qright_margin
))
2623 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
2627 /* Check if PROP is a display property value whose text should be
2628 treated as intangible. */
2631 display_prop_intangible_p (prop
)
2635 && CONSP (XCAR (prop
))
2636 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2638 /* A list of sub-properties. */
2639 while (CONSP (prop
))
2641 if (single_display_prop_intangible_p (XCAR (prop
)))
2646 else if (VECTORP (prop
))
2648 /* A vector of sub-properties. */
2650 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2651 if (single_display_prop_intangible_p (XVECTOR (prop
)->contents
[i
]))
2655 return single_display_prop_intangible_p (prop
);
2661 /***********************************************************************
2662 `composition' property
2663 ***********************************************************************/
2665 /* Set up iterator IT from `composition' property at its current
2666 position. Called from handle_stop. */
2668 static enum prop_handled
2669 handle_composition_prop (it
)
2672 Lisp_Object prop
, string
;
2673 int pos
, pos_byte
, end
;
2674 enum prop_handled handled
= HANDLED_NORMALLY
;
2676 if (STRINGP (it
->string
))
2678 pos
= IT_STRING_CHARPOS (*it
);
2679 pos_byte
= IT_STRING_BYTEPOS (*it
);
2680 string
= it
->string
;
2684 pos
= IT_CHARPOS (*it
);
2685 pos_byte
= IT_BYTEPOS (*it
);
2689 /* If there's a valid composition and point is not inside of the
2690 composition (in the case that the composition is from the current
2691 buffer), draw a glyph composed from the composition components. */
2692 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
2693 && COMPOSITION_VALID_P (pos
, end
, prop
)
2694 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
2696 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
2700 it
->method
= next_element_from_composition
;
2702 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
2703 /* For a terminal, draw only the first character of the
2705 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
2706 it
->len
= (STRINGP (it
->string
)
2707 ? string_char_to_byte (it
->string
, end
)
2708 : CHAR_TO_BYTE (end
)) - pos_byte
;
2709 it
->stop_charpos
= end
;
2710 handled
= HANDLED_RETURN
;
2719 /***********************************************************************
2721 ***********************************************************************/
2723 /* The following structure is used to record overlay strings for
2724 later sorting in load_overlay_strings. */
2726 struct overlay_entry
2728 Lisp_Object overlay
;
2735 /* Set up iterator IT from overlay strings at its current position.
2736 Called from handle_stop. */
2738 static enum prop_handled
2739 handle_overlay_change (it
)
2742 if (!STRINGP (it
->string
) && get_overlay_strings (it
))
2743 return HANDLED_RECOMPUTE_PROPS
;
2745 return HANDLED_NORMALLY
;
2749 /* Set up the next overlay string for delivery by IT, if there is an
2750 overlay string to deliver. Called by set_iterator_to_next when the
2751 end of the current overlay string is reached. If there are more
2752 overlay strings to display, IT->string and
2753 IT->current.overlay_string_index are set appropriately here.
2754 Otherwise IT->string is set to nil. */
2757 next_overlay_string (it
)
2760 ++it
->current
.overlay_string_index
;
2761 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2763 /* No more overlay strings. Restore IT's settings to what
2764 they were before overlay strings were processed, and
2765 continue to deliver from current_buffer. */
2767 xassert (it
->stop_charpos
>= BEGV
2768 && it
->stop_charpos
<= it
->end_charpos
);
2770 it
->current
.overlay_string_index
= -1;
2771 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2772 it
->n_overlay_strings
= 0;
2773 it
->method
= next_element_from_buffer
;
2775 /* If we're at the end of the buffer, record that we have
2776 processed the overlay strings there already, so that
2777 next_element_from_buffer doesn't try it again. */
2778 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
2779 it
->overlay_strings_at_end_processed_p
= 1;
2783 /* There are more overlay strings to process. If
2784 IT->current.overlay_string_index has advanced to a position
2785 where we must load IT->overlay_strings with more strings, do
2787 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2789 if (it
->current
.overlay_string_index
&& i
== 0)
2790 load_overlay_strings (it
);
2792 /* Initialize IT to deliver display elements from the overlay
2794 it
->string
= it
->overlay_strings
[i
];
2795 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2796 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2797 it
->method
= next_element_from_string
;
2798 it
->stop_charpos
= 0;
2805 /* Compare two overlay_entry structures E1 and E2. Used as a
2806 comparison function for qsort in load_overlay_strings. Overlay
2807 strings for the same position are sorted so that
2809 1. All after-strings come in front of before-strings, except
2810 when they come from the same overlay.
2812 2. Within after-strings, strings are sorted so that overlay strings
2813 from overlays with higher priorities come first.
2815 2. Within before-strings, strings are sorted so that overlay
2816 strings from overlays with higher priorities come last.
2818 Value is analogous to strcmp. */
2822 compare_overlay_entries (e1
, e2
)
2825 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
2826 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
2829 if (entry1
->after_string_p
!= entry2
->after_string_p
)
2831 /* Let after-strings appear in front of before-strings if
2832 they come from different overlays. */
2833 if (EQ (entry1
->overlay
, entry2
->overlay
))
2834 result
= entry1
->after_string_p
? 1 : -1;
2836 result
= entry1
->after_string_p
? -1 : 1;
2838 else if (entry1
->after_string_p
)
2839 /* After-strings sorted in order of decreasing priority. */
2840 result
= entry2
->priority
- entry1
->priority
;
2842 /* Before-strings sorted in order of increasing priority. */
2843 result
= entry1
->priority
- entry2
->priority
;
2849 /* Load the vector IT->overlay_strings with overlay strings from IT's
2850 current buffer position. Set IT->n_overlays to the total number of
2851 overlay strings found.
2853 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
2854 a time. On entry into load_overlay_strings,
2855 IT->current.overlay_string_index gives the number of overlay
2856 strings that have already been loaded by previous calls to this
2859 IT->add_overlay_start contains an additional overlay start
2860 position to consider for taking overlay strings from, if non-zero.
2861 This position comes into play when the overlay has an `invisible'
2862 property, and both before and after-strings. When we've skipped to
2863 the end of the overlay, because of its `invisible' property, we
2864 nevertheless want its before-string to appear.
2865 IT->add_overlay_start will contain the overlay start position
2868 Overlay strings are sorted so that after-string strings come in
2869 front of before-string strings. Within before and after-strings,
2870 strings are sorted by overlay priority. See also function
2871 compare_overlay_entries. */
2874 load_overlay_strings (it
)
2877 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
2878 Lisp_Object ov
, overlay
, window
, str
;
2882 struct overlay_entry
*entries
2883 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
2885 /* Append the overlay string STRING of overlay OVERLAY to vector
2886 `entries' which has size `size' and currently contains `n'
2887 elements. AFTER_P non-zero means STRING is an after-string of
2889 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
2892 Lisp_Object priority; \
2896 int new_size = 2 * size; \
2897 struct overlay_entry *old = entries; \
2899 (struct overlay_entry *) alloca (new_size \
2900 * sizeof *entries); \
2901 bcopy (old, entries, size * sizeof *entries); \
2905 entries[n].string = (STRING); \
2906 entries[n].overlay = (OVERLAY); \
2907 priority = Foverlay_get ((OVERLAY), Qpriority); \
2908 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
2909 entries[n].after_string_p = (AFTER_P); \
2914 /* Process overlay before the overlay center. */
2915 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
2917 overlay
= XCAR (ov
);
2918 xassert (OVERLAYP (overlay
));
2919 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2920 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2922 if (end
< IT_CHARPOS (*it
))
2925 /* Skip this overlay if it doesn't start or end at IT's current
2927 if (end
!= IT_CHARPOS (*it
)
2928 && start
!= IT_CHARPOS (*it
)
2929 && it
->add_overlay_start
!= IT_CHARPOS (*it
))
2932 /* Skip this overlay if it doesn't apply to IT->w. */
2933 window
= Foverlay_get (overlay
, Qwindow
);
2934 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2937 /* If overlay has a non-empty before-string, record it. */
2938 if ((start
== IT_CHARPOS (*it
)
2939 || start
== it
->add_overlay_start
)
2940 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2941 && XSTRING (str
)->size
)
2942 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2944 /* If overlay has a non-empty after-string, record it. */
2945 if (end
== IT_CHARPOS (*it
)
2946 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2947 && XSTRING (str
)->size
)
2948 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2951 /* Process overlays after the overlay center. */
2952 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
2954 overlay
= XCAR (ov
);
2955 xassert (OVERLAYP (overlay
));
2956 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2957 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2959 if (start
> IT_CHARPOS (*it
))
2962 /* Skip this overlay if it doesn't start or end at IT's current
2964 if (end
!= IT_CHARPOS (*it
)
2965 && start
!= IT_CHARPOS (*it
)
2966 && it
->add_overlay_start
!= IT_CHARPOS (*it
))
2969 /* Skip this overlay if it doesn't apply to IT->w. */
2970 window
= Foverlay_get (overlay
, Qwindow
);
2971 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2974 /* If overlay has a non-empty before-string, record it. */
2975 if ((start
== IT_CHARPOS (*it
)
2976 || start
== it
->add_overlay_start
)
2977 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2978 && XSTRING (str
)->size
)
2979 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2981 /* If overlay has a non-empty after-string, record it. */
2982 if (end
== IT_CHARPOS (*it
)
2983 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2984 && XSTRING (str
)->size
)
2985 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2988 #undef RECORD_OVERLAY_STRING
2992 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
2994 /* Record the total number of strings to process. */
2995 it
->n_overlay_strings
= n
;
2997 /* IT->current.overlay_string_index is the number of overlay strings
2998 that have already been consumed by IT. Copy some of the
2999 remaining overlay strings to IT->overlay_strings. */
3001 j
= it
->current
.overlay_string_index
;
3002 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3003 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3009 /* Get the first chunk of overlay strings at IT's current buffer
3010 position. Value is non-zero if at least one overlay string was
3014 get_overlay_strings (it
)
3017 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3018 process. This fills IT->overlay_strings with strings, and sets
3019 IT->n_overlay_strings to the total number of strings to process.
3020 IT->pos.overlay_string_index has to be set temporarily to zero
3021 because load_overlay_strings needs this; it must be set to -1
3022 when no overlay strings are found because a zero value would
3023 indicate a position in the first overlay string. */
3024 it
->current
.overlay_string_index
= 0;
3025 load_overlay_strings (it
);
3027 /* If we found overlay strings, set up IT to deliver display
3028 elements from the first one. Otherwise set up IT to deliver
3029 from current_buffer. */
3030 if (it
->n_overlay_strings
)
3032 /* Make sure we know settings in current_buffer, so that we can
3033 restore meaningful values when we're done with the overlay
3035 compute_stop_pos (it
);
3036 xassert (it
->face_id
>= 0);
3038 /* Save IT's settings. They are restored after all overlay
3039 strings have been processed. */
3040 xassert (it
->sp
== 0);
3043 /* Set up IT to deliver display elements from the first overlay
3045 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3046 it
->stop_charpos
= 0;
3047 it
->string
= it
->overlay_strings
[0];
3048 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3049 xassert (STRINGP (it
->string
));
3050 it
->method
= next_element_from_string
;
3055 it
->current
.overlay_string_index
= -1;
3056 it
->method
= next_element_from_buffer
;
3061 /* Value is non-zero if we found at least one overlay string. */
3062 return STRINGP (it
->string
);
3067 /***********************************************************************
3068 Saving and restoring state
3069 ***********************************************************************/
3071 /* Save current settings of IT on IT->stack. Called, for example,
3072 before setting up IT for an overlay string, to be able to restore
3073 IT's settings to what they were after the overlay string has been
3080 struct iterator_stack_entry
*p
;
3082 xassert (it
->sp
< 2);
3083 p
= it
->stack
+ it
->sp
;
3085 p
->stop_charpos
= it
->stop_charpos
;
3086 xassert (it
->face_id
>= 0);
3087 p
->face_id
= it
->face_id
;
3088 p
->string
= it
->string
;
3089 p
->pos
= it
->current
;
3090 p
->end_charpos
= it
->end_charpos
;
3091 p
->string_nchars
= it
->string_nchars
;
3093 p
->multibyte_p
= it
->multibyte_p
;
3094 p
->space_width
= it
->space_width
;
3095 p
->font_height
= it
->font_height
;
3096 p
->voffset
= it
->voffset
;
3097 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3102 /* Restore IT's settings from IT->stack. Called, for example, when no
3103 more overlay strings must be processed, and we return to delivering
3104 display elements from a buffer, or when the end of a string from a
3105 `display' property is reached and we return to delivering display
3106 elements from an overlay string, or from a buffer. */
3112 struct iterator_stack_entry
*p
;
3114 xassert (it
->sp
> 0);
3116 p
= it
->stack
+ it
->sp
;
3117 it
->stop_charpos
= p
->stop_charpos
;
3118 it
->face_id
= p
->face_id
;
3119 it
->string
= p
->string
;
3120 it
->current
= p
->pos
;
3121 it
->end_charpos
= p
->end_charpos
;
3122 it
->string_nchars
= p
->string_nchars
;
3124 it
->multibyte_p
= p
->multibyte_p
;
3125 it
->space_width
= p
->space_width
;
3126 it
->font_height
= p
->font_height
;
3127 it
->voffset
= p
->voffset
;
3128 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3133 /***********************************************************************
3135 ***********************************************************************/
3137 /* Set IT's current position to the previous line start. */
3140 back_to_previous_line_start (it
)
3143 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3144 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3148 /* Set IT's current position to the next line start. */
3151 forward_to_next_line_start (it
)
3154 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), 1);
3155 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3159 /* Set IT's current position to the previous visible line start. Skip
3160 invisible text that is so either due to text properties or due to
3161 selective display. Caution: this does not change IT->current_x and
3165 back_to_previous_visible_line_start (it
)
3170 /* Go back one newline if not on BEGV already. */
3171 if (IT_CHARPOS (*it
) > BEGV
)
3172 back_to_previous_line_start (it
);
3174 /* Move over lines that are invisible because of selective display
3175 or text properties. */
3176 while (IT_CHARPOS (*it
) > BEGV
3181 /* If selective > 0, then lines indented more than that values
3183 if (it
->selective
> 0
3184 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3191 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3192 Qinvisible
, it
->window
);
3193 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3197 /* Back one more newline if the current one is invisible. */
3199 back_to_previous_line_start (it
);
3202 xassert (IT_CHARPOS (*it
) >= BEGV
);
3203 xassert (IT_CHARPOS (*it
) == BEGV
3204 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3209 /* Reseat iterator IT at the previous visible line start. Skip
3210 invisible text that is so either due to text properties or due to
3211 selective display. At the end, update IT's overlay information,
3212 face information etc. */
3215 reseat_at_previous_visible_line_start (it
)
3218 back_to_previous_visible_line_start (it
);
3219 reseat (it
, it
->current
.pos
, 1);
3224 /* Reseat iterator IT on the next visible line start in the current
3225 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3226 preceding the line start. Skip over invisible text that is so
3227 because of selective display. Compute faces, overlays etc at the
3228 new position. Note that this function does not skip over text that
3229 is invisible because of text properties. */
3232 reseat_at_next_visible_line_start (it
, on_newline_p
)
3236 /* Restore the buffer position when currently not delivering display
3237 elements from the current buffer. This is the case, for example,
3238 when called at the end of a truncated overlay string. */
3241 it
->method
= next_element_from_buffer
;
3243 /* Otherwise, scan_buffer would not work. */
3244 if (IT_CHARPOS (*it
) < ZV
)
3246 /* If on a newline, advance past it. Otherwise, find the next
3247 newline which automatically gives us the position following
3249 if (FETCH_BYTE (IT_BYTEPOS (*it
)) == '\n')
3255 forward_to_next_line_start (it
);
3257 /* We must either have reached the end of the buffer or end up
3259 xassert (IT_CHARPOS (*it
) == ZV
3260 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3262 /* Skip over lines that are invisible because they are indented
3263 more than the value of IT->selective. */
3264 if (it
->selective
> 0)
3265 while (IT_CHARPOS (*it
) < ZV
3266 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3268 forward_to_next_line_start (it
);
3270 /* Position on the newline if we should. */
3272 && IT_CHARPOS (*it
) > BEGV
3273 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n')
3276 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3279 /* Set the iterator there. The 0 as the last parameter of
3280 reseat means don't force a text property lookup. The lookup
3281 is then only done if we've skipped past the iterator's
3282 check_charpos'es. This optimization is important because
3283 text property lookups tend to be expensive. */
3284 reseat (it
, it
->current
.pos
, 0);
3292 /***********************************************************************
3293 Changing an iterator's position
3294 ***********************************************************************/
3296 /* Change IT's current position to POS in current_buffer. If FORCE_P
3297 is non-zero, always check for text properties at the new position.
3298 Otherwise, text properties are only looked up if POS >=
3299 IT->check_charpos of a property. */
3302 reseat (it
, pos
, force_p
)
3304 struct text_pos pos
;
3307 int original_pos
= IT_CHARPOS (*it
);
3309 reseat_1 (it
, pos
, 0);
3311 /* Determine where to check text properties. Avoid doing it
3312 where possible because text property lookup is very expensive. */
3314 || CHARPOS (pos
) > it
->stop_charpos
3315 || CHARPOS (pos
) < original_pos
)
3322 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3323 IT->stop_pos to POS, also. */
3326 reseat_1 (it
, pos
, set_stop_p
)
3328 struct text_pos pos
;
3331 /* Don't call this function when scanning a C string. */
3332 xassert (it
->s
== NULL
);
3334 /* POS must be a reasonable value. */
3335 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3337 it
->current
.pos
= it
->position
= pos
;
3338 XSETBUFFER (it
->object
, current_buffer
);
3340 it
->current
.dpvec_index
= -1;
3341 it
->current
.overlay_string_index
= -1;
3342 IT_STRING_CHARPOS (*it
) = -1;
3343 IT_STRING_BYTEPOS (*it
) = -1;
3345 it
->method
= next_element_from_buffer
;
3349 it
->stop_charpos
= CHARPOS (pos
);
3353 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3354 If S is non-null, it is a C string to iterate over. Otherwise,
3355 STRING gives a Lisp string to iterate over.
3357 If PRECISION > 0, don't return more then PRECISION number of
3358 characters from the string.
3360 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3361 characters have been returned. FIELD_WIDTH < 0 means an infinite
3364 MULTIBYTE = 0 means disable processing of multibyte characters,
3365 MULTIBYTE > 0 means enable it,
3366 MULTIBYTE < 0 means use IT->multibyte_p.
3368 IT must be initialized via a prior call to init_iterator before
3369 calling this function. */
3372 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3377 int precision
, field_width
, multibyte
;
3379 /* No region in strings. */
3380 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3382 /* No text property checks performed by default, but see below. */
3383 it
->stop_charpos
= -1;
3385 /* Set iterator position and end position. */
3386 bzero (&it
->current
, sizeof it
->current
);
3387 it
->current
.overlay_string_index
= -1;
3388 it
->current
.dpvec_index
= -1;
3389 xassert (charpos
>= 0);
3391 /* Use the setting of MULTIBYTE if specified. */
3393 it
->multibyte_p
= multibyte
> 0;
3397 xassert (STRINGP (string
));
3398 it
->string
= string
;
3400 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3401 it
->method
= next_element_from_string
;
3402 it
->current
.string_pos
= string_pos (charpos
, string
);
3409 /* Note that we use IT->current.pos, not it->current.string_pos,
3410 for displaying C strings. */
3411 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3412 if (it
->multibyte_p
)
3414 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3415 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3419 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3420 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3423 it
->method
= next_element_from_c_string
;
3426 /* PRECISION > 0 means don't return more than PRECISION characters
3428 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3429 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3431 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3432 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3433 FIELD_WIDTH < 0 means infinite field width. This is useful for
3434 padding with `-' at the end of a mode line. */
3435 if (field_width
< 0)
3436 field_width
= INFINITY
;
3437 if (field_width
> it
->end_charpos
- charpos
)
3438 it
->end_charpos
= charpos
+ field_width
;
3440 /* Use the standard display table for displaying strings. */
3441 if (DISP_TABLE_P (Vstandard_display_table
))
3442 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3444 it
->stop_charpos
= charpos
;
3450 /***********************************************************************
3452 ***********************************************************************/
3454 /* Load IT's display element fields with information about the next
3455 display element from the current position of IT. Value is zero if
3456 end of buffer (or C string) is reached. */
3459 get_next_display_element (it
)
3462 /* Non-zero means that we found an display element. Zero means that
3463 we hit the end of what we iterate over. Performance note: the
3464 function pointer `method' used here turns out to be faster than
3465 using a sequence of if-statements. */
3466 int success_p
= (*it
->method
) (it
);
3468 if (it
->what
== IT_CHARACTER
)
3470 /* Map via display table or translate control characters.
3471 IT->c, IT->len etc. have been set to the next character by
3472 the function call above. If we have a display table, and it
3473 contains an entry for IT->c, translate it. Don't do this if
3474 IT->c itself comes from a display table, otherwise we could
3475 end up in an infinite recursion. (An alternative could be to
3476 count the recursion depth of this function and signal an
3477 error when a certain maximum depth is reached.) Is it worth
3479 if (success_p
&& it
->dpvec
== NULL
)
3484 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3487 struct Lisp_Vector
*v
= XVECTOR (dv
);
3489 /* Return the first character from the display table
3490 entry, if not empty. If empty, don't display the
3491 current character. */
3494 it
->dpvec_char_len
= it
->len
;
3495 it
->dpvec
= v
->contents
;
3496 it
->dpend
= v
->contents
+ v
->size
;
3497 it
->current
.dpvec_index
= 0;
3498 it
->method
= next_element_from_display_vector
;
3501 success_p
= get_next_display_element (it
);
3504 /* Translate control characters into `\003' or `^C' form.
3505 Control characters coming from a display table entry are
3506 currently not translated because we use IT->dpvec to hold
3507 the translation. This could easily be changed but I
3508 don't believe that it is worth doing.
3510 Non-printable multibyte characters are also translated
3512 else if ((it
->c
< ' '
3513 && (it
->area
!= TEXT_AREA
3514 || (it
->c
!= '\n' && it
->c
!= '\t')))
3517 || !CHAR_PRINTABLE_P (it
->c
))
3519 /* IT->c is a control character which must be displayed
3520 either as '\003' or as `^C' where the '\\' and '^'
3521 can be defined in the display table. Fill
3522 IT->ctl_chars with glyphs for what we have to
3523 display. Then, set IT->dpvec to these glyphs. */
3526 if (it
->c
< 128 && it
->ctl_arrow_p
)
3528 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3530 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3531 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3532 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3534 g
= FAST_MAKE_GLYPH ('^', 0);
3535 XSETINT (it
->ctl_chars
[0], g
);
3537 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3538 XSETINT (it
->ctl_chars
[1], g
);
3540 /* Set up IT->dpvec and return first character from it. */
3541 it
->dpvec_char_len
= it
->len
;
3542 it
->dpvec
= it
->ctl_chars
;
3543 it
->dpend
= it
->dpvec
+ 2;
3544 it
->current
.dpvec_index
= 0;
3545 it
->method
= next_element_from_display_vector
;
3546 get_next_display_element (it
);
3550 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
3555 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3557 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3558 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3559 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3561 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
3563 if (SINGLE_BYTE_CHAR_P (it
->c
))
3564 str
[0] = it
->c
, len
= 1;
3566 len
= CHAR_STRING (it
->c
, str
);
3568 for (i
= 0; i
< len
; i
++)
3570 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
3571 /* Insert three more glyphs into IT->ctl_chars for
3572 the octal display of the character. */
3573 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
3574 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
3575 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
3576 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
3577 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
3578 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
3581 /* Set up IT->dpvec and return the first character
3583 it
->dpvec_char_len
= it
->len
;
3584 it
->dpvec
= it
->ctl_chars
;
3585 it
->dpend
= it
->dpvec
+ len
* 4;
3586 it
->current
.dpvec_index
= 0;
3587 it
->method
= next_element_from_display_vector
;
3588 get_next_display_element (it
);
3593 /* Adjust face id for a multibyte character. There are no
3594 multibyte character in unibyte text. */
3597 && FRAME_WINDOW_P (it
->f
))
3599 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3600 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
3604 /* Is this character the last one of a run of characters with
3605 box? If yes, set IT->end_of_box_run_p to 1. */
3612 it
->end_of_box_run_p
3613 = ((face_id
= face_after_it_pos (it
),
3614 face_id
!= it
->face_id
)
3615 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3616 face
->box
== FACE_NO_BOX
));
3619 /* Value is 0 if end of buffer or string reached. */
3624 /* Move IT to the next display element.
3626 Functions get_next_display_element and set_iterator_to_next are
3627 separate because I find this arrangement easier to handle than a
3628 get_next_display_element function that also increments IT's
3629 position. The way it is we can first look at an iterator's current
3630 display element, decide whether it fits on a line, and if it does,
3631 increment the iterator position. The other way around we probably
3632 would either need a flag indicating whether the iterator has to be
3633 incremented the next time, or we would have to implement a
3634 decrement position function which would not be easy to write. */
3637 set_iterator_to_next (it
)
3640 if (it
->method
== next_element_from_buffer
)
3642 /* The current display element of IT is a character from
3643 current_buffer. Advance in the buffer, and maybe skip over
3644 invisible lines that are so because of selective display. */
3645 if (ITERATOR_AT_END_OF_LINE_P (it
))
3646 reseat_at_next_visible_line_start (it
, 0);
3649 xassert (it
->len
!= 0);
3650 IT_BYTEPOS (*it
) += it
->len
;
3651 IT_CHARPOS (*it
) += 1;
3652 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3655 else if (it
->method
== next_element_from_composition
)
3657 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
3658 if (STRINGP (it
->string
))
3660 IT_STRING_BYTEPOS (*it
) += it
->len
;
3661 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
3662 it
->method
= next_element_from_string
;
3663 goto consider_string_end
;
3667 IT_BYTEPOS (*it
) += it
->len
;
3668 IT_CHARPOS (*it
) += it
->cmp_len
;
3669 it
->method
= next_element_from_buffer
;
3672 else if (it
->method
== next_element_from_c_string
)
3674 /* Current display element of IT is from a C string. */
3675 IT_BYTEPOS (*it
) += it
->len
;
3676 IT_CHARPOS (*it
) += 1;
3678 else if (it
->method
== next_element_from_display_vector
)
3680 /* Current display element of IT is from a display table entry.
3681 Advance in the display table definition. Reset it to null if
3682 end reached, and continue with characters from buffers/
3684 ++it
->current
.dpvec_index
;
3686 /* Restore face of the iterator to what they were before the
3687 display vector entry (these entries may contain faces). */
3688 it
->face_id
= it
->saved_face_id
;
3690 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3693 it
->method
= next_element_from_c_string
;
3694 else if (STRINGP (it
->string
))
3695 it
->method
= next_element_from_string
;
3697 it
->method
= next_element_from_buffer
;
3700 it
->current
.dpvec_index
= -1;
3702 /* Skip over characters which were displayed via IT->dpvec. */
3703 if (it
->dpvec_char_len
< 0)
3704 reseat_at_next_visible_line_start (it
, 1);
3705 else if (it
->dpvec_char_len
> 0)
3707 it
->len
= it
->dpvec_char_len
;
3708 set_iterator_to_next (it
);
3712 else if (it
->method
== next_element_from_string
)
3714 /* Current display element is a character from a Lisp string. */
3715 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3716 IT_STRING_BYTEPOS (*it
) += it
->len
;
3717 IT_STRING_CHARPOS (*it
) += 1;
3719 consider_string_end
:
3721 if (it
->current
.overlay_string_index
>= 0)
3723 /* IT->string is an overlay string. Advance to the
3724 next, if there is one. */
3725 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3726 next_overlay_string (it
);
3730 /* IT->string is not an overlay string. If we reached
3731 its end, and there is something on IT->stack, proceed
3732 with what is on the stack. This can be either another
3733 string, this time an overlay string, or a buffer. */
3734 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3738 if (!STRINGP (it
->string
))
3739 it
->method
= next_element_from_buffer
;
3743 else if (it
->method
== next_element_from_image
3744 || it
->method
== next_element_from_stretch
)
3746 /* The position etc with which we have to proceed are on
3747 the stack. The position may be at the end of a string,
3748 if the `display' property takes up the whole string. */
3751 if (STRINGP (it
->string
))
3753 it
->method
= next_element_from_string
;
3754 goto consider_string_end
;
3757 it
->method
= next_element_from_buffer
;
3760 /* There are no other methods defined, so this should be a bug. */
3763 /* Reset flags indicating start and end of a sequence of
3764 characters with box. */
3765 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3767 xassert (it
->method
!= next_element_from_string
3768 || (STRINGP (it
->string
)
3769 && IT_STRING_CHARPOS (*it
) >= 0));
3773 /* Load IT's display element fields with information about the next
3774 display element which comes from a display table entry or from the
3775 result of translating a control character to one of the forms `^C'
3776 or `\003'. IT->dpvec holds the glyphs to return as characters. */
3779 next_element_from_display_vector (it
)
3783 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
3785 /* Remember the current face id in case glyphs specify faces.
3786 IT's face is restored in set_iterator_to_next. */
3787 it
->saved_face_id
= it
->face_id
;
3789 if (INTEGERP (*it
->dpvec
)
3790 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
3795 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
3796 it
->c
= FAST_GLYPH_CHAR (g
);
3797 it
->len
= CHAR_BYTES (it
->c
);
3799 /* The entry may contain a face id to use. Such a face id is
3800 the id of a Lisp face, not a realized face. A face id of
3801 zero means no face. */
3802 lface_id
= FAST_GLYPH_FACE (g
);
3805 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
3808 it
->face_id
= face_id
;
3813 /* Display table entry is invalid. Return a space. */
3814 it
->c
= ' ', it
->len
= 1;
3816 /* Don't change position and object of the iterator here. They are
3817 still the values of the character that had this display table
3818 entry or was translated, and that's what we want. */
3819 it
->what
= IT_CHARACTER
;
3824 /* Load IT with the next display element from Lisp string IT->string.
3825 IT->current.string_pos is the current position within the string.
3826 If IT->current.overlay_string_index >= 0, the Lisp string is an
3830 next_element_from_string (it
)
3833 struct text_pos position
;
3835 xassert (STRINGP (it
->string
));
3836 xassert (IT_STRING_CHARPOS (*it
) >= 0);
3837 position
= it
->current
.string_pos
;
3839 /* Time to check for invisible text? */
3840 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
3841 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
3845 /* Since a handler may have changed IT->method, we must
3847 return get_next_display_element (it
);
3850 if (it
->current
.overlay_string_index
>= 0)
3852 /* Get the next character from an overlay string. In overlay
3853 strings, There is no field width or padding with spaces to
3855 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3860 else if (STRING_MULTIBYTE (it
->string
))
3862 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
3863 - IT_STRING_BYTEPOS (*it
));
3864 unsigned char *s
= (XSTRING (it
->string
)->data
3865 + IT_STRING_BYTEPOS (*it
));
3866 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
3870 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3876 /* Get the next character from a Lisp string that is not an
3877 overlay string. Such strings come from the mode line, for
3878 example. We may have to pad with spaces, or truncate the
3879 string. See also next_element_from_c_string. */
3880 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
3885 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
3887 /* Pad with spaces. */
3888 it
->c
= ' ', it
->len
= 1;
3889 CHARPOS (position
) = BYTEPOS (position
) = -1;
3891 else if (STRING_MULTIBYTE (it
->string
))
3893 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
3894 - IT_STRING_BYTEPOS (*it
));
3895 unsigned char *s
= (XSTRING (it
->string
)->data
3896 + IT_STRING_BYTEPOS (*it
));
3897 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
3901 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3906 /* Record what we have and where it came from. Note that we store a
3907 buffer position in IT->position although it could arguably be a
3909 it
->what
= IT_CHARACTER
;
3910 it
->object
= it
->string
;
3911 it
->position
= position
;
3916 /* Load IT with next display element from C string IT->s.
3917 IT->string_nchars is the maximum number of characters to return
3918 from the string. IT->end_charpos may be greater than
3919 IT->string_nchars when this function is called, in which case we
3920 may have to return padding spaces. Value is zero if end of string
3921 reached, including padding spaces. */
3924 next_element_from_c_string (it
)
3930 it
->what
= IT_CHARACTER
;
3931 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
3934 /* IT's position can be greater IT->string_nchars in case a field
3935 width or precision has been specified when the iterator was
3937 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3939 /* End of the game. */
3943 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
3945 /* Pad with spaces. */
3946 it
->c
= ' ', it
->len
= 1;
3947 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
3949 else if (it
->multibyte_p
)
3951 /* Implementation note: The calls to strlen apparently aren't a
3952 performance problem because there is no noticeable performance
3953 difference between Emacs running in unibyte or multibyte mode. */
3954 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
3955 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
3959 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
3965 /* Set up IT to return characters from an ellipsis, if appropriate.
3966 The definition of the ellipsis glyphs may come from a display table
3967 entry. This function Fills IT with the first glyph from the
3968 ellipsis if an ellipsis is to be displayed. */
3971 next_element_from_ellipsis (it
)
3974 if (it
->selective_display_ellipsis_p
)
3976 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3978 /* Use the display table definition for `...'. Invalid glyphs
3979 will be handled by the method returning elements from dpvec. */
3980 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3981 it
->dpvec_char_len
= it
->len
;
3982 it
->dpvec
= v
->contents
;
3983 it
->dpend
= v
->contents
+ v
->size
;
3984 it
->current
.dpvec_index
= 0;
3985 it
->method
= next_element_from_display_vector
;
3989 /* Use default `...' which is stored in default_invis_vector. */
3990 it
->dpvec_char_len
= it
->len
;
3991 it
->dpvec
= default_invis_vector
;
3992 it
->dpend
= default_invis_vector
+ 3;
3993 it
->current
.dpvec_index
= 0;
3994 it
->method
= next_element_from_display_vector
;
3998 reseat_at_next_visible_line_start (it
, 1);
4000 return get_next_display_element (it
);
4004 /* Deliver an image display element. The iterator IT is already
4005 filled with image information (done in handle_display_prop). Value
4010 next_element_from_image (it
)
4013 it
->what
= IT_IMAGE
;
4018 /* Fill iterator IT with next display element from a stretch glyph
4019 property. IT->object is the value of the text property. Value is
4023 next_element_from_stretch (it
)
4026 it
->what
= IT_STRETCH
;
4031 /* Load IT with the next display element from current_buffer. Value
4032 is zero if end of buffer reached. IT->stop_charpos is the next
4033 position at which to stop and check for text properties or buffer
4037 next_element_from_buffer (it
)
4042 /* Check this assumption, otherwise, we would never enter the
4043 if-statement, below. */
4044 xassert (IT_CHARPOS (*it
) >= BEGV
4045 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4047 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4049 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4051 int overlay_strings_follow_p
;
4053 /* End of the game, except when overlay strings follow that
4054 haven't been returned yet. */
4055 if (it
->overlay_strings_at_end_processed_p
)
4056 overlay_strings_follow_p
= 0;
4059 it
->overlay_strings_at_end_processed_p
= 1;
4060 overlay_strings_follow_p
= get_overlay_strings (it
);
4063 if (overlay_strings_follow_p
)
4064 success_p
= get_next_display_element (it
);
4068 it
->position
= it
->current
.pos
;
4075 return get_next_display_element (it
);
4080 /* No face changes, overlays etc. in sight, so just return a
4081 character from current_buffer. */
4084 /* Maybe run the redisplay end trigger hook. Performance note:
4085 This doesn't seem to cost measurable time. */
4086 if (it
->redisplay_end_trigger_charpos
4088 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4089 run_redisplay_end_trigger_hook (it
);
4091 /* Get the next character, maybe multibyte. */
4092 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4093 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4095 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4096 - IT_BYTEPOS (*it
));
4097 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4100 it
->c
= *p
, it
->len
= 1;
4102 /* Record what we have and where it came from. */
4103 it
->what
= IT_CHARACTER
;;
4104 it
->object
= it
->w
->buffer
;
4105 it
->position
= it
->current
.pos
;
4107 /* Normally we return the character found above, except when we
4108 really want to return an ellipsis for selective display. */
4113 /* A value of selective > 0 means hide lines indented more
4114 than that number of columns. */
4115 if (it
->selective
> 0
4116 && IT_CHARPOS (*it
) + 1 < ZV
4117 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4118 IT_BYTEPOS (*it
) + 1,
4121 success_p
= next_element_from_ellipsis (it
);
4122 it
->dpvec_char_len
= -1;
4125 else if (it
->c
== '\r' && it
->selective
== -1)
4127 /* A value of selective == -1 means that everything from the
4128 CR to the end of the line is invisible, with maybe an
4129 ellipsis displayed for it. */
4130 success_p
= next_element_from_ellipsis (it
);
4131 it
->dpvec_char_len
= -1;
4136 /* Value is zero if end of buffer reached. */
4137 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4142 /* Run the redisplay end trigger hook for IT. */
4145 run_redisplay_end_trigger_hook (it
)
4148 Lisp_Object args
[3];
4150 /* IT->glyph_row should be non-null, i.e. we should be actually
4151 displaying something, or otherwise we should not run the hook. */
4152 xassert (it
->glyph_row
);
4154 /* Set up hook arguments. */
4155 args
[0] = Qredisplay_end_trigger_functions
;
4156 args
[1] = it
->window
;
4157 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4158 it
->redisplay_end_trigger_charpos
= 0;
4160 /* Since we are *trying* to run these functions, don't try to run
4161 them again, even if they get an error. */
4162 it
->w
->redisplay_end_trigger
= Qnil
;
4163 Frun_hook_with_args (3, args
);
4165 /* Notice if it changed the face of the character we are on. */
4166 handle_face_prop (it
);
4170 /* Deliver a composition display element. The iterator IT is already
4171 filled with composition information (done in
4172 handle_composition_prop). Value is always 1. */
4175 next_element_from_composition (it
)
4178 it
->what
= IT_COMPOSITION
;
4179 it
->position
= (STRINGP (it
->string
)
4180 ? it
->current
.string_pos
4187 /***********************************************************************
4188 Moving an iterator without producing glyphs
4189 ***********************************************************************/
4191 /* Move iterator IT to a specified buffer or X position within one
4192 line on the display without producing glyphs.
4194 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4195 whichever is reached first.
4197 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4199 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4200 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4201 TO_X includes the amount by which a window is horizontally
4206 MOVE_POS_MATCH_OR_ZV
4207 - when TO_POS or ZV was reached.
4210 -when TO_X was reached before TO_POS or ZV were reached.
4213 - when we reached the end of the display area and the line must
4217 - when we reached the end of the display area and the line is
4221 - when we stopped at a line end, i.e. a newline or a CR and selective
4224 static enum move_it_result
4225 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4227 int to_charpos
, to_x
, op
;
4229 enum move_it_result result
= MOVE_UNDEFINED
;
4230 struct glyph_row
*saved_glyph_row
;
4232 /* Don't produce glyphs in produce_glyphs. */
4233 saved_glyph_row
= it
->glyph_row
;
4234 it
->glyph_row
= NULL
;
4240 /* Stop when ZV or TO_CHARPOS reached. */
4241 if (!get_next_display_element (it
)
4242 || ((op
& MOVE_TO_POS
) != 0
4243 && BUFFERP (it
->object
)
4244 && IT_CHARPOS (*it
) >= to_charpos
))
4246 result
= MOVE_POS_MATCH_OR_ZV
;
4250 /* The call to produce_glyphs will get the metrics of the
4251 display element IT is loaded with. We record in x the
4252 x-position before this display element in case it does not
4255 PRODUCE_GLYPHS (it
);
4257 if (it
->area
!= TEXT_AREA
)
4259 set_iterator_to_next (it
);
4263 /* The number of glyphs we get back in IT->nglyphs will normally
4264 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4265 character on a terminal frame, or (iii) a line end. For the
4266 second case, IT->nglyphs - 1 padding glyphs will be present
4267 (on X frames, there is only one glyph produced for a
4268 composite character.
4270 The behavior implemented below means, for continuation lines,
4271 that as many spaces of a TAB as fit on the current line are
4272 displayed there. For terminal frames, as many glyphs of a
4273 multi-glyph character are displayed in the current line, too.
4274 This is what the old redisplay code did, and we keep it that
4275 way. Under X, the whole shape of a complex character must
4276 fit on the line or it will be completely displayed in the
4279 Note that both for tabs and padding glyphs, all glyphs have
4283 /* More than one glyph or glyph doesn't fit on line. All
4284 glyphs have the same width. */
4285 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4288 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4290 new_x
= x
+ single_glyph_width
;
4292 /* We want to leave anything reaching TO_X to the caller. */
4293 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4296 result
= MOVE_X_REACHED
;
4299 else if (/* Lines are continued. */
4300 !it
->truncate_lines_p
4301 && (/* And glyph doesn't fit on the line. */
4302 new_x
> it
->last_visible_x
4303 /* Or it fits exactly and we're on a window
4305 || (new_x
== it
->last_visible_x
4306 && FRAME_WINDOW_P (it
->f
))))
4308 if (/* IT->hpos == 0 means the very first glyph
4309 doesn't fit on the line, e.g. a wide image. */
4311 || (new_x
== it
->last_visible_x
4312 && FRAME_WINDOW_P (it
->f
)))
4315 it
->current_x
= new_x
;
4316 if (i
== it
->nglyphs
- 1)
4317 set_iterator_to_next (it
);
4322 result
= MOVE_LINE_CONTINUED
;
4325 else if (new_x
> it
->first_visible_x
)
4327 /* Glyph is visible. Increment number of glyphs that
4328 would be displayed. */
4333 /* Glyph is completely off the left margin of the display
4334 area. Nothing to do. */
4338 if (result
!= MOVE_UNDEFINED
)
4341 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4343 /* Stop when TO_X specified and reached. This check is
4344 necessary here because of lines consisting of a line end,
4345 only. The line end will not produce any glyphs and we
4346 would never get MOVE_X_REACHED. */
4347 xassert (it
->nglyphs
== 0);
4348 result
= MOVE_X_REACHED
;
4352 /* Is this a line end? If yes, we're done. */
4353 if (ITERATOR_AT_END_OF_LINE_P (it
))
4355 result
= MOVE_NEWLINE_OR_CR
;
4359 /* The current display element has been consumed. Advance
4361 set_iterator_to_next (it
);
4363 /* Stop if lines are truncated and IT's current x-position is
4364 past the right edge of the window now. */
4365 if (it
->truncate_lines_p
4366 && it
->current_x
>= it
->last_visible_x
)
4368 result
= MOVE_LINE_TRUNCATED
;
4373 /* Restore the iterator settings altered at the beginning of this
4375 it
->glyph_row
= saved_glyph_row
;
4380 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4381 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4382 the description of enum move_operation_enum.
4384 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4385 screen line, this function will set IT to the next position >
4389 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4391 int to_charpos
, to_x
, to_y
, to_vpos
;
4394 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4399 if (op
& MOVE_TO_VPOS
)
4401 /* If no TO_CHARPOS and no TO_X specified, stop at the
4402 start of the line TO_VPOS. */
4403 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4405 if (it
->vpos
== to_vpos
)
4407 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4411 /* TO_VPOS >= 0 means stop at TO_X in the line at
4412 TO_VPOS, or at TO_POS, whichever comes first. */
4413 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4415 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4417 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4419 /* We have reached TO_X but not in the line we want. */
4420 skip
= move_it_in_display_line_to (it
, to_charpos
,
4422 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4427 else if (op
& MOVE_TO_Y
)
4429 struct it it_backup
;
4432 /* TO_Y specified means stop at TO_X in the line containing
4433 TO_Y---or at TO_CHARPOS if this is reached first. The
4434 problem is that we can't really tell whether the line
4435 contains TO_Y before we have completely scanned it, and
4436 this may skip past TO_X. What we do is to first scan to
4439 If TO_X is not specified, use a TO_X of zero. The reason
4440 is to make the outcome of this function more predictable.
4441 If we didn't use TO_X == 0, we would stop at the end of
4442 the line which is probably not what a caller would expect
4444 skip
= move_it_in_display_line_to (it
, to_charpos
,
4448 | (op
& MOVE_TO_POS
)));
4450 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4451 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4454 /* If TO_X was reached, we would like to know whether TO_Y
4455 is in the line. This can only be said if we know the
4456 total line height which requires us to scan the rest of
4459 if (skip
== MOVE_X_REACHED
)
4462 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4466 /* Now, decide whether TO_Y is in this line. */
4467 line_height
= it
->max_ascent
+ it
->max_descent
;
4469 if (to_y
>= it
->current_y
4470 && to_y
< it
->current_y
+ line_height
)
4472 if (skip
== MOVE_X_REACHED
)
4473 /* If TO_Y is in this line and TO_X was reached above,
4474 we scanned too far. We have to restore IT's settings
4475 to the ones before skipping. */
4479 else if (skip
== MOVE_X_REACHED
)
4482 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4490 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4494 case MOVE_POS_MATCH_OR_ZV
:
4497 case MOVE_NEWLINE_OR_CR
:
4498 set_iterator_to_next (it
);
4499 it
->continuation_lines_width
= 0;
4502 case MOVE_LINE_TRUNCATED
:
4503 it
->continuation_lines_width
= 0;
4504 reseat_at_next_visible_line_start (it
, 0);
4505 if ((op
& MOVE_TO_POS
) != 0
4506 && IT_CHARPOS (*it
) > to_charpos
)
4510 case MOVE_LINE_CONTINUED
:
4511 it
->continuation_lines_width
+= it
->current_x
;
4518 /* Reset/increment for the next run. */
4519 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4520 it
->current_x
= it
->hpos
= 0;
4521 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4523 last_height
= it
->max_ascent
+ it
->max_descent
;
4524 last_max_ascent
= it
->max_ascent
;
4525 it
->max_ascent
= it
->max_descent
= 0;
4531 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4533 If DY > 0, move IT backward at least that many pixels. DY = 0
4534 means move IT backward to the preceding line start or BEGV. This
4535 function may move over more than DY pixels if IT->current_y - DY
4536 ends up in the middle of a line; in this case IT->current_y will be
4537 set to the top of the line moved to. */
4540 move_it_vertically_backward (it
, dy
)
4544 int nlines
, h
, line_height
;
4546 int start_pos
= IT_CHARPOS (*it
);
4550 /* Estimate how many newlines we must move back. */
4551 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4553 /* Set the iterator's position that many lines back. */
4554 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4555 back_to_previous_visible_line_start (it
);
4557 /* Reseat the iterator here. When moving backward, we don't want
4558 reseat to skip forward over invisible text, set up the iterator
4559 to deliver from overlay strings at the new position etc. So,
4560 use reseat_1 here. */
4561 reseat_1 (it
, it
->current
.pos
, 1);
4563 /* We are now surely at a line start. */
4564 it
->current_x
= it
->hpos
= 0;
4566 /* Move forward and see what y-distance we moved. First move to the
4567 start of the next line so that we get its height. We need this
4568 height to be able to tell whether we reached the specified
4571 it2
.max_ascent
= it2
.max_descent
= 0;
4572 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4573 MOVE_TO_POS
| MOVE_TO_VPOS
);
4574 xassert (IT_CHARPOS (*it
) >= BEGV
);
4575 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4576 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4577 xassert (IT_CHARPOS (*it
) >= BEGV
);
4578 h
= it2
.current_y
- it
->current_y
;
4579 nlines
= it2
.vpos
- it
->vpos
;
4581 /* Correct IT's y and vpos position. */
4587 /* DY == 0 means move to the start of the screen line. The
4588 value of nlines is > 0 if continuation lines were involved. */
4590 move_it_by_lines (it
, nlines
, 1);
4591 xassert (IT_CHARPOS (*it
) <= start_pos
);
4595 /* The y-position we try to reach. Note that h has been
4596 subtracted in front of the if-statement. */
4597 int target_y
= it
->current_y
+ h
- dy
;
4599 /* If we did not reach target_y, try to move further backward if
4600 we can. If we moved too far backward, try to move forward. */
4601 if (target_y
< it
->current_y
4602 && IT_CHARPOS (*it
) > BEGV
)
4604 move_it_vertically (it
, target_y
- it
->current_y
);
4605 xassert (IT_CHARPOS (*it
) >= BEGV
);
4607 else if (target_y
>= it
->current_y
+ line_height
4608 && IT_CHARPOS (*it
) < ZV
)
4610 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4611 xassert (IT_CHARPOS (*it
) >= BEGV
);
4617 /* Move IT by a specified amount of pixel lines DY. DY negative means
4618 move backwards. DY = 0 means move to start of screen line. At the
4619 end, IT will be on the start of a screen line. */
4622 move_it_vertically (it
, dy
)
4627 move_it_vertically_backward (it
, -dy
);
4630 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4631 MOVE_TO_POS
| MOVE_TO_Y
);
4633 /* If buffer ends in ZV without a newline, move to the start of
4634 the line to satisfy the post-condition. */
4635 if (IT_CHARPOS (*it
) == ZV
4636 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4637 move_it_by_lines (it
, 0, 0);
4642 /* Return non-zero if some text between buffer positions START_CHARPOS
4643 and END_CHARPOS is invisible. IT->window is the window for text
4647 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4649 int start_charpos
, end_charpos
;
4651 Lisp_Object prop
, limit
;
4652 int invisible_found_p
;
4654 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4656 /* Is text at START invisible? */
4657 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4659 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4660 invisible_found_p
= 1;
4663 limit
= next_single_char_property_change (make_number (start_charpos
),
4665 make_number (end_charpos
));
4666 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4669 return invisible_found_p
;
4673 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4674 negative means move up. DVPOS == 0 means move to the start of the
4675 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4676 NEED_Y_P is zero, IT->current_y will be left unchanged.
4678 Further optimization ideas: If we would know that IT->f doesn't use
4679 a face with proportional font, we could be faster for
4680 truncate-lines nil. */
4683 move_it_by_lines (it
, dvpos
, need_y_p
)
4685 int dvpos
, need_y_p
;
4687 struct position pos
;
4689 if (!FRAME_WINDOW_P (it
->f
))
4691 struct text_pos textpos
;
4693 /* We can use vmotion on frames without proportional fonts. */
4694 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4695 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4696 reseat (it
, textpos
, 1);
4697 it
->vpos
+= pos
.vpos
;
4698 it
->current_y
+= pos
.vpos
;
4700 else if (dvpos
== 0)
4702 /* DVPOS == 0 means move to the start of the screen line. */
4703 move_it_vertically_backward (it
, 0);
4704 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4708 /* If there are no continuation lines, and if there is no
4709 selective display, try the simple method of moving forward
4710 DVPOS newlines, then see where we are. */
4711 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4713 int shortage
= 0, charpos
;
4715 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
4716 charpos
= IT_CHARPOS (*it
) + 1;
4718 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
4721 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
4723 struct text_pos pos
;
4724 CHARPOS (pos
) = charpos
;
4725 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4726 reseat (it
, pos
, 1);
4727 it
->vpos
+= dvpos
- shortage
;
4728 it
->hpos
= it
->current_x
= 0;
4733 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
4738 int start_charpos
, i
;
4740 /* If there are no continuation lines, and if there is no
4741 selective display, try the simple method of moving backward
4743 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4746 int charpos
= IT_CHARPOS (*it
);
4747 int bytepos
= IT_BYTEPOS (*it
);
4749 /* If in the middle of a line, go to its start. */
4750 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
4752 charpos
= find_next_newline_no_quit (charpos
, -1);
4753 bytepos
= CHAR_TO_BYTE (charpos
);
4756 if (charpos
== BEGV
)
4758 struct text_pos pos
;
4759 CHARPOS (pos
) = charpos
;
4760 BYTEPOS (pos
) = bytepos
;
4761 reseat (it
, pos
, 1);
4762 it
->hpos
= it
->current_x
= 0;
4767 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
4768 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
4770 struct text_pos pos
;
4771 CHARPOS (pos
) = charpos
;
4772 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4773 reseat (it
, pos
, 1);
4774 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
4775 it
->hpos
= it
->current_x
= 0;
4781 /* Go back -DVPOS visible lines and reseat the iterator there. */
4782 start_charpos
= IT_CHARPOS (*it
);
4783 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
4784 back_to_previous_visible_line_start (it
);
4785 reseat (it
, it
->current
.pos
, 1);
4786 it
->current_x
= it
->hpos
= 0;
4788 /* Above call may have moved too far if continuation lines
4789 are involved. Scan forward and see if it did. */
4791 it2
.vpos
= it2
.current_y
= 0;
4792 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
4793 it
->vpos
-= it2
.vpos
;
4794 it
->current_y
-= it2
.current_y
;
4795 it
->current_x
= it
->hpos
= 0;
4797 /* If we moved too far, move IT some lines forward. */
4798 if (it2
.vpos
> -dvpos
)
4800 int delta
= it2
.vpos
+ dvpos
;
4801 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
4808 /***********************************************************************
4810 ***********************************************************************/
4813 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
4817 add_to_log (format
, arg1
, arg2
)
4819 Lisp_Object arg1
, arg2
;
4821 Lisp_Object args
[3];
4822 Lisp_Object msg
, fmt
;
4825 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4828 GCPRO4 (fmt
, msg
, arg1
, arg2
);
4830 args
[0] = fmt
= build_string (format
);
4833 msg
= Fformat (3, args
);
4835 len
= STRING_BYTES (XSTRING (msg
)) + 1;
4836 buffer
= (char *) alloca (len
);
4837 strcpy (buffer
, XSTRING (msg
)->data
);
4839 message_dolog (buffer
, len
- 1, 1, 0);
4844 /* Output a newline in the *Messages* buffer if "needs" one. */
4847 message_log_maybe_newline ()
4849 if (message_log_need_newline
)
4850 message_dolog ("", 0, 1, 0);
4854 /* Add a string M of length LEN to the message log, optionally
4855 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
4856 nonzero, means interpret the contents of M as multibyte. This
4857 function calls low-level routines in order to bypass text property
4858 hooks, etc. which might not be safe to run. */
4861 message_dolog (m
, len
, nlflag
, multibyte
)
4863 int len
, nlflag
, multibyte
;
4865 if (!NILP (Vmessage_log_max
))
4867 struct buffer
*oldbuf
;
4868 Lisp_Object oldpoint
, oldbegv
, oldzv
;
4869 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4870 int point_at_end
= 0;
4872 Lisp_Object old_deactivate_mark
, tem
;
4873 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4875 old_deactivate_mark
= Vdeactivate_mark
;
4876 oldbuf
= current_buffer
;
4877 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
4878 current_buffer
->undo_list
= Qt
;
4880 oldpoint
= Fpoint_marker ();
4881 oldbegv
= Fpoint_min_marker ();
4882 oldzv
= Fpoint_max_marker ();
4883 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
4891 BEGV_BYTE
= BEG_BYTE
;
4894 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4896 /* Insert the string--maybe converting multibyte to single byte
4897 or vice versa, so that all the text fits the buffer. */
4899 && NILP (current_buffer
->enable_multibyte_characters
))
4902 unsigned char work
[1];
4904 /* Convert a multibyte string to single-byte
4905 for the *Message* buffer. */
4906 for (i
= 0; i
< len
; i
+= nbytes
)
4908 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
4909 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
4911 : multibyte_char_to_unibyte (c
, Qnil
));
4912 insert_1_both (work
, 1, 1, 1, 0, 0);
4915 else if (! multibyte
4916 && ! NILP (current_buffer
->enable_multibyte_characters
))
4919 unsigned char *msg
= (unsigned char *) m
;
4920 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4921 /* Convert a single-byte string to multibyte
4922 for the *Message* buffer. */
4923 for (i
= 0; i
< len
; i
++)
4925 c
= unibyte_char_to_multibyte (msg
[i
]);
4926 nbytes
= CHAR_STRING (c
, str
);
4927 insert_1_both (str
, 1, nbytes
, 1, 0, 0);
4931 insert_1 (m
, len
, 1, 0, 0);
4935 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
4936 insert_1 ("\n", 1, 1, 0, 0);
4938 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4940 this_bol_byte
= PT_BYTE
;
4944 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4946 prev_bol_byte
= PT_BYTE
;
4948 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
4949 this_bol
, this_bol_byte
);
4952 del_range_both (prev_bol
, prev_bol_byte
,
4953 this_bol
, this_bol_byte
, 0);
4959 /* If you change this format, don't forget to also
4960 change message_log_check_duplicate. */
4961 sprintf (dupstr
, " [%d times]", dup
);
4962 duplen
= strlen (dupstr
);
4963 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
4964 insert_1 (dupstr
, duplen
, 1, 0, 1);
4969 if (NATNUMP (Vmessage_log_max
))
4971 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
4972 -XFASTINT (Vmessage_log_max
) - 1, 0);
4973 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
4976 BEGV
= XMARKER (oldbegv
)->charpos
;
4977 BEGV_BYTE
= marker_byte_position (oldbegv
);
4986 ZV
= XMARKER (oldzv
)->charpos
;
4987 ZV_BYTE
= marker_byte_position (oldzv
);
4991 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4993 /* We can't do Fgoto_char (oldpoint) because it will run some
4995 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
4996 XMARKER (oldpoint
)->bytepos
);
4999 free_marker (oldpoint
);
5000 free_marker (oldbegv
);
5001 free_marker (oldzv
);
5003 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5004 set_buffer_internal (oldbuf
);
5006 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5007 message_log_need_newline
= !nlflag
;
5008 Vdeactivate_mark
= old_deactivate_mark
;
5013 /* We are at the end of the buffer after just having inserted a newline.
5014 (Note: We depend on the fact we won't be crossing the gap.)
5015 Check to see if the most recent message looks a lot like the previous one.
5016 Return 0 if different, 1 if the new one should just replace it, or a
5017 value N > 1 if we should also append " [N times]". */
5020 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5021 int prev_bol
, this_bol
;
5022 int prev_bol_byte
, this_bol_byte
;
5025 int len
= Z_BYTE
- 1 - this_bol_byte
;
5027 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5028 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5030 for (i
= 0; i
< len
; i
++)
5032 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
5041 if (*p1
++ == ' ' && *p1
++ == '[')
5044 while (*p1
>= '0' && *p1
<= '9')
5045 n
= n
* 10 + *p1
++ - '0';
5046 if (strncmp (p1
, " times]\n", 8) == 0)
5053 /* Display an echo area message M with a specified length of LEN
5054 chars. The string may include null characters. If M is 0, clear
5055 out any existing message, and let the mini-buffer text show through.
5057 The buffer M must continue to exist until after the echo area gets
5058 cleared or some other message gets displayed there. This means do
5059 not pass text that is stored in a Lisp string; do not pass text in
5060 a buffer that was alloca'd. */
5063 message2 (m
, len
, multibyte
)
5068 /* First flush out any partial line written with print. */
5069 message_log_maybe_newline ();
5071 message_dolog (m
, len
, 1, multibyte
);
5072 message2_nolog (m
, len
, multibyte
);
5076 /* The non-logging counterpart of message2. */
5079 message2_nolog (m
, len
, multibyte
)
5083 struct frame
*sf
= SELECTED_FRAME ();
5084 message_enable_multibyte
= multibyte
;
5088 if (noninteractive_need_newline
)
5089 putc ('\n', stderr
);
5090 noninteractive_need_newline
= 0;
5092 fwrite (m
, len
, 1, stderr
);
5093 if (cursor_in_echo_area
== 0)
5094 fprintf (stderr
, "\n");
5097 /* A null message buffer means that the frame hasn't really been
5098 initialized yet. Error messages get reported properly by
5099 cmd_error, so this must be just an informative message; toss it. */
5100 else if (INTERACTIVE
5101 && sf
->glyphs_initialized_p
5102 && FRAME_MESSAGE_BUF (sf
))
5104 Lisp_Object mini_window
;
5107 /* Get the frame containing the mini-buffer
5108 that the selected frame is using. */
5109 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5110 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5112 FRAME_SAMPLE_VISIBILITY (f
);
5113 if (FRAME_VISIBLE_P (sf
)
5114 && ! FRAME_VISIBLE_P (f
))
5115 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5119 set_message (m
, Qnil
, len
, multibyte
);
5120 if (minibuffer_auto_raise
)
5121 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5124 clear_message (1, 1);
5126 do_pending_window_change (0);
5127 echo_area_display (1);
5128 do_pending_window_change (0);
5129 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5130 (*frame_up_to_date_hook
) (f
);
5135 /* Display an echo area message M with a specified length of NBYTES
5136 bytes. The string may include null characters. If M is not a
5137 string, clear out any existing message, and let the mini-buffer
5138 text show through. */
5141 message3 (m
, nbytes
, multibyte
)
5146 struct gcpro gcpro1
;
5150 /* First flush out any partial line written with print. */
5151 message_log_maybe_newline ();
5153 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5154 message3_nolog (m
, nbytes
, multibyte
);
5160 /* The non-logging version of message3. */
5163 message3_nolog (m
, nbytes
, multibyte
)
5165 int nbytes
, multibyte
;
5167 struct frame
*sf
= SELECTED_FRAME ();
5168 message_enable_multibyte
= multibyte
;
5172 if (noninteractive_need_newline
)
5173 putc ('\n', stderr
);
5174 noninteractive_need_newline
= 0;
5176 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5177 if (cursor_in_echo_area
== 0)
5178 fprintf (stderr
, "\n");
5181 /* A null message buffer means that the frame hasn't really been
5182 initialized yet. Error messages get reported properly by
5183 cmd_error, so this must be just an informative message; toss it. */
5184 else if (INTERACTIVE
5185 && sf
->glyphs_initialized_p
5186 && FRAME_MESSAGE_BUF (sf
))
5188 Lisp_Object mini_window
;
5192 /* Get the frame containing the mini-buffer
5193 that the selected frame is using. */
5194 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5195 frame
= XWINDOW (mini_window
)->frame
;
5198 FRAME_SAMPLE_VISIBILITY (f
);
5199 if (FRAME_VISIBLE_P (sf
)
5200 && !FRAME_VISIBLE_P (f
))
5201 Fmake_frame_visible (frame
);
5203 if (STRINGP (m
) && XSTRING (m
)->size
)
5205 set_message (NULL
, m
, nbytes
, multibyte
);
5206 if (minibuffer_auto_raise
)
5207 Fraise_frame (frame
);
5210 clear_message (1, 1);
5212 do_pending_window_change (0);
5213 echo_area_display (1);
5214 do_pending_window_change (0);
5215 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5216 (*frame_up_to_date_hook
) (f
);
5221 /* Display a null-terminated echo area message M. If M is 0, clear
5222 out any existing message, and let the mini-buffer text show through.
5224 The buffer M must continue to exist until after the echo area gets
5225 cleared or some other message gets displayed there. Do not pass
5226 text that is stored in a Lisp string. Do not pass text in a buffer
5227 that was alloca'd. */
5233 message2 (m
, (m
? strlen (m
) : 0), 0);
5237 /* The non-logging counterpart of message1. */
5243 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5246 /* Display a message M which contains a single %s
5247 which gets replaced with STRING. */
5250 message_with_string (m
, string
, log
)
5259 if (noninteractive_need_newline
)
5260 putc ('\n', stderr
);
5261 noninteractive_need_newline
= 0;
5262 fprintf (stderr
, m
, XSTRING (string
)->data
);
5263 if (cursor_in_echo_area
== 0)
5264 fprintf (stderr
, "\n");
5268 else if (INTERACTIVE
)
5270 /* The frame whose minibuffer we're going to display the message on.
5271 It may be larger than the selected frame, so we need
5272 to use its buffer, not the selected frame's buffer. */
5273 Lisp_Object mini_window
;
5274 struct frame
*f
, *sf
= SELECTED_FRAME ();
5276 /* Get the frame containing the minibuffer
5277 that the selected frame is using. */
5278 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5279 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5281 /* A null message buffer means that the frame hasn't really been
5282 initialized yet. Error messages get reported properly by
5283 cmd_error, so this must be just an informative message; toss it. */
5284 if (FRAME_MESSAGE_BUF (f
))
5288 a
[0] = (char *) XSTRING (string
)->data
;
5290 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5291 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5294 message2 (FRAME_MESSAGE_BUF (f
), len
,
5295 STRING_MULTIBYTE (string
));
5297 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5298 STRING_MULTIBYTE (string
));
5300 /* Print should start at the beginning of the message
5301 buffer next time. */
5302 message_buf_print
= 0;
5308 /* Dump an informative message to the minibuf. If M is 0, clear out
5309 any existing message, and let the mini-buffer text show through. */
5313 message (m
, a1
, a2
, a3
)
5315 EMACS_INT a1
, a2
, a3
;
5321 if (noninteractive_need_newline
)
5322 putc ('\n', stderr
);
5323 noninteractive_need_newline
= 0;
5324 fprintf (stderr
, m
, a1
, a2
, a3
);
5325 if (cursor_in_echo_area
== 0)
5326 fprintf (stderr
, "\n");
5330 else if (INTERACTIVE
)
5332 /* The frame whose mini-buffer we're going to display the message
5333 on. It may be larger than the selected frame, so we need to
5334 use its buffer, not the selected frame's buffer. */
5335 Lisp_Object mini_window
;
5336 struct frame
*f
, *sf
= SELECTED_FRAME ();
5338 /* Get the frame containing the mini-buffer
5339 that the selected frame is using. */
5340 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5341 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5343 /* A null message buffer means that the frame hasn't really been
5344 initialized yet. Error messages get reported properly by
5345 cmd_error, so this must be just an informative message; toss
5347 if (FRAME_MESSAGE_BUF (f
))
5358 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5359 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5361 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5362 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5364 #endif /* NO_ARG_ARRAY */
5366 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5371 /* Print should start at the beginning of the message
5372 buffer next time. */
5373 message_buf_print
= 0;
5379 /* The non-logging version of message. */
5382 message_nolog (m
, a1
, a2
, a3
)
5384 EMACS_INT a1
, a2
, a3
;
5386 Lisp_Object old_log_max
;
5387 old_log_max
= Vmessage_log_max
;
5388 Vmessage_log_max
= Qnil
;
5389 message (m
, a1
, a2
, a3
);
5390 Vmessage_log_max
= old_log_max
;
5394 /* Display the current message in the current mini-buffer. This is
5395 only called from error handlers in process.c, and is not time
5401 if (!NILP (echo_area_buffer
[0]))
5404 string
= Fcurrent_message ();
5405 message3 (string
, XSTRING (string
)->size
,
5406 !NILP (current_buffer
->enable_multibyte_characters
));
5411 /* Make sure echo area buffers in echo_buffers[] are life. If they
5412 aren't, make new ones. */
5415 ensure_echo_area_buffers ()
5419 for (i
= 0; i
< 2; ++i
)
5420 if (!BUFFERP (echo_buffer
[i
])
5421 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5424 sprintf (name
, " *Echo Area %d*", i
);
5425 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5426 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
5431 /* Call FN with args A1..A5 with either the current or last displayed
5432 echo_area_buffer as current buffer.
5434 WHICH zero means use the current message buffer
5435 echo_area_buffer[0]. If that is nil, choose a suitable buffer
5436 from echo_buffer[] and clear it.
5438 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
5439 suitable buffer from echo_buffer[] and clear it.
5441 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
5442 that the current message becomes the last displayed one, make
5443 choose a suitable buffer for echo_area_buffer[0], and clear it.
5445 Value is what FN returns. */
5448 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
)
5452 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
;
5455 int this_one
, the_other
, clear_buffer_p
, rc
;
5456 int count
= specpdl_ptr
- specpdl
;
5458 /* If buffers aren't life, make new ones. */
5459 ensure_echo_area_buffers ();
5464 this_one
= 0, the_other
= 1;
5466 this_one
= 1, the_other
= 0;
5469 this_one
= 0, the_other
= 1;
5472 /* We need a fresh one in case the current echo buffer equals
5473 the one containing the last displayed echo area message. */
5474 if (!NILP (echo_area_buffer
[this_one
])
5475 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
5476 echo_area_buffer
[this_one
] = Qnil
;
5479 /* Choose a suitable buffer from echo_buffer[] is we don't
5481 if (NILP (echo_area_buffer
[this_one
]))
5483 echo_area_buffer
[this_one
]
5484 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
5485 ? echo_buffer
[the_other
]
5486 : echo_buffer
[this_one
]);
5490 buffer
= echo_area_buffer
[this_one
];
5492 record_unwind_protect (unwind_with_echo_area_buffer
,
5493 with_echo_area_buffer_unwind_data (w
));
5495 /* Make the echo area buffer current. Note that for display
5496 purposes, it is not necessary that the displayed window's buffer
5497 == current_buffer, except for text property lookup. So, let's
5498 only set that buffer temporarily here without doing a full
5499 Fset_window_buffer. We must also change w->pointm, though,
5500 because otherwise an assertions in unshow_buffer fails, and Emacs
5502 set_buffer_internal_1 (XBUFFER (buffer
));
5506 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
5509 current_buffer
->undo_list
= Qt
;
5510 current_buffer
->read_only
= Qnil
;
5512 if (clear_buffer_p
&& Z
> BEG
)
5515 xassert (BEGV
>= BEG
);
5516 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5518 rc
= fn (a1
, a2
, a3
, a4
, a5
);
5520 xassert (BEGV
>= BEG
);
5521 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5523 unbind_to (count
, Qnil
);
5528 /* Save state that should be preserved around the call to the function
5529 FN called in with_echo_area_buffer. */
5532 with_echo_area_buffer_unwind_data (w
)
5538 /* Reduce consing by keeping one vector in
5539 Vwith_echo_area_save_vector. */
5540 vector
= Vwith_echo_area_save_vector
;
5541 Vwith_echo_area_save_vector
= Qnil
;
5544 vector
= Fmake_vector (make_number (7), Qnil
);
5546 XSETBUFFER (XVECTOR (vector
)->contents
[i
], current_buffer
); ++i
;
5547 XVECTOR (vector
)->contents
[i
++] = Vdeactivate_mark
;
5548 XVECTOR (vector
)->contents
[i
++] = make_number (windows_or_buffers_changed
);
5552 XSETWINDOW (XVECTOR (vector
)->contents
[i
], w
); ++i
;
5553 XVECTOR (vector
)->contents
[i
++] = w
->buffer
;
5554 XVECTOR (vector
)->contents
[i
++]
5555 = make_number (XMARKER (w
->pointm
)->charpos
);
5556 XVECTOR (vector
)->contents
[i
++]
5557 = make_number (XMARKER (w
->pointm
)->bytepos
);
5563 XVECTOR (vector
)->contents
[i
++] = Qnil
;
5566 xassert (i
== XVECTOR (vector
)->size
);
5571 /* Restore global state from VECTOR which was created by
5572 with_echo_area_buffer_unwind_data. */
5575 unwind_with_echo_area_buffer (vector
)
5580 set_buffer_internal_1 (XBUFFER (XVECTOR (vector
)->contents
[i
])); ++i
;
5581 Vdeactivate_mark
= XVECTOR (vector
)->contents
[i
]; ++i
;
5582 windows_or_buffers_changed
= XFASTINT (XVECTOR (vector
)->contents
[i
]); ++i
;
5584 if (WINDOWP (XVECTOR (vector
)->contents
[i
]))
5587 Lisp_Object buffer
, charpos
, bytepos
;
5589 w
= XWINDOW (XVECTOR (vector
)->contents
[i
]); ++i
;
5590 buffer
= XVECTOR (vector
)->contents
[i
]; ++i
;
5591 charpos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5592 bytepos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5595 set_marker_both (w
->pointm
, buffer
,
5596 XFASTINT (charpos
), XFASTINT (bytepos
));
5599 Vwith_echo_area_save_vector
= vector
;
5604 /* Set up the echo area for use by print functions. MULTIBYTE_P
5605 non-zero means we will print multibyte. */
5608 setup_echo_area_for_printing (multibyte_p
)
5611 ensure_echo_area_buffers ();
5613 if (!message_buf_print
)
5615 /* A message has been output since the last time we printed.
5616 Choose a fresh echo area buffer. */
5617 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5618 echo_area_buffer
[0] = echo_buffer
[1];
5620 echo_area_buffer
[0] = echo_buffer
[0];
5622 /* Switch to that buffer and clear it. */
5623 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5626 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5628 /* Set up the buffer for the multibyteness we need. */
5630 != !NILP (current_buffer
->enable_multibyte_characters
))
5631 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
5633 /* Raise the frame containing the echo area. */
5634 if (minibuffer_auto_raise
)
5636 struct frame
*sf
= SELECTED_FRAME ();
5637 Lisp_Object mini_window
;
5638 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5639 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5642 message_log_maybe_newline ();
5643 message_buf_print
= 1;
5647 if (NILP (echo_area_buffer
[0]))
5649 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5650 echo_area_buffer
[0] = echo_buffer
[1];
5652 echo_area_buffer
[0] = echo_buffer
[0];
5655 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
5656 /* Someone switched buffers between print requests. */
5657 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5662 /* Display an echo area message in window W. Value is non-zero if W's
5663 height is changed. If display_last_displayed_message_p is
5664 non-zero, display the message that was last displayed, otherwise
5665 display the current message. */
5668 display_echo_area (w
)
5671 int i
, no_message_p
, window_height_changed_p
, count
;
5673 /* Temporarily disable garbage collections while displaying the echo
5674 area. This is done because a GC can print a message itself.
5675 That message would modify the echo area buffer's contents while a
5676 redisplay of the buffer is going on, and seriously confuse
5678 count
= inhibit_garbage_collection ();
5680 /* If there is no message, we must call display_echo_area_1
5681 nevertheless because it resizes the window. But we will have to
5682 reset the echo_area_buffer in question to nil at the end because
5683 with_echo_area_buffer will sets it to an empty buffer. */
5684 i
= display_last_displayed_message_p
? 1 : 0;
5685 no_message_p
= NILP (echo_area_buffer
[i
]);
5687 window_height_changed_p
5688 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
5689 (int (*) ()) display_echo_area_1
, w
);
5692 echo_area_buffer
[i
] = Qnil
;
5694 unbind_to (count
, Qnil
);
5695 return window_height_changed_p
;
5699 /* Helper for display_echo_area. Display the current buffer which
5700 contains the current echo area message in window W, a mini-window.
5701 Change the height of W so that all of the message is displayed.
5702 Value is non-zero if height of W was changed. */
5705 display_echo_area_1 (w
)
5709 struct text_pos start
;
5710 int window_height_changed_p
= 0;
5712 /* Do this before displaying, so that we have a large enough glyph
5713 matrix for the display. */
5714 window_height_changed_p
= resize_mini_window (w
, 0);
5717 clear_glyph_matrix (w
->desired_matrix
);
5718 XSETWINDOW (window
, w
);
5719 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
5720 try_window (window
, start
);
5722 return window_height_changed_p
;
5726 /* Resize the echo area window to exactly the size needed for the
5727 currently displayed message, if there is one. */
5730 resize_echo_area_axactly ()
5732 if (BUFFERP (echo_area_buffer
[0])
5733 && WINDOWP (echo_area_window
))
5735 struct window
*w
= XWINDOW (echo_area_window
);
5738 resized_p
= with_echo_area_buffer (w
, 0,
5739 (int (*) ()) resize_mini_window
,
5743 ++windows_or_buffers_changed
;
5744 ++update_mode_lines
;
5745 redisplay_internal (0);
5751 /* Resize mini-window W to fit the size of its contents. EXACT:P
5752 means size the window exactly to the size needed. Otherwise, it's
5753 only enlarged until W's buffer is empty. Value is non-zero if
5754 the window height has been changed. */
5757 resize_mini_window (w
, exact_p
)
5761 struct frame
*f
= XFRAME (w
->frame
);
5762 int window_height_changed_p
= 0;
5764 xassert (MINI_WINDOW_P (w
));
5766 /* Nil means don't try to resize. */
5767 if (NILP (Vmax_mini_window_height
)
5768 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
5771 if (!FRAME_MINIBUF_ONLY_P (f
))
5774 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5775 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
5776 int height
, max_height
;
5777 int unit
= CANON_Y_UNIT (f
);
5778 struct text_pos start
;
5780 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
5782 /* Compute the max. number of lines specified by the user. */
5783 if (FLOATP (Vmax_mini_window_height
))
5784 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
5785 else if (INTEGERP (Vmax_mini_window_height
))
5786 max_height
= XINT (Vmax_mini_window_height
);
5788 max_height
= total_height
/ 4;
5790 /* Correct that max. height if it's bogus. */
5791 max_height
= max (1, max_height
);
5792 max_height
= min (total_height
, max_height
);
5794 /* Find out the height of the text in the window. */
5795 if (it
.truncate_lines_p
)
5800 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
5801 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
5802 height
= it
.current_y
+ last_height
;
5804 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
5805 height
-= it
.extra_line_spacing
;
5806 height
= (height
+ unit
- 1) / unit
;
5809 /* Compute a suitable window start. */
5810 if (height
> max_height
)
5812 height
= max_height
;
5813 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
5814 move_it_vertically_backward (&it
, (height
- 1) * unit
);
5815 start
= it
.current
.pos
;
5818 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5819 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
5821 /* Let it grow only, until we display an empty message, in which
5822 case the window shrinks again. */
5823 if (height
> XFASTINT (w
->height
))
5825 int old_height
= XFASTINT (w
->height
);
5826 freeze_window_starts (f
, 1);
5827 grow_mini_window (w
, height
- XFASTINT (w
->height
));
5828 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5830 else if (height
< XFASTINT (w
->height
)
5831 && (exact_p
|| BEGV
== ZV
))
5833 int old_height
= XFASTINT (w
->height
);
5834 freeze_window_starts (f
, 0);
5835 shrink_mini_window (w
);
5836 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5840 return window_height_changed_p
;
5844 /* Value is the current message, a string, or nil if there is no
5852 if (NILP (echo_area_buffer
[0]))
5856 with_echo_area_buffer (0, 0, (int (*) ()) current_message_1
, &msg
);
5858 echo_area_buffer
[0] = Qnil
;
5866 current_message_1 (msg
)
5870 *msg
= make_buffer_string (BEG
, Z
, 1);
5877 /* Push the current message on Vmessage_stack for later restauration
5878 by restore_message. Value is non-zero if the current message isn't
5879 empty. This is a relatively infrequent operation, so it's not
5880 worth optimizing. */
5886 msg
= current_message ();
5887 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
5888 return STRINGP (msg
);
5892 /* Restore message display from the top of Vmessage_stack. */
5899 xassert (CONSP (Vmessage_stack
));
5900 msg
= XCAR (Vmessage_stack
);
5902 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
5904 message3_nolog (msg
, 0, 0);
5908 /* Pop the top-most entry off Vmessage_stack. */
5913 xassert (CONSP (Vmessage_stack
));
5914 Vmessage_stack
= XCDR (Vmessage_stack
);
5918 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
5919 exits. If the stack is not empty, we have a missing pop_message
5923 check_message_stack ()
5925 if (!NILP (Vmessage_stack
))
5930 /* Truncate to NCHARS what will be displayed in the echo area the next
5931 time we display it---but don't redisplay it now. */
5934 truncate_echo_area (nchars
)
5938 echo_area_buffer
[0] = Qnil
;
5939 /* A null message buffer means that the frame hasn't really been
5940 initialized yet. Error messages get reported properly by
5941 cmd_error, so this must be just an informative message; toss it. */
5942 else if (!noninteractive
5944 && !NILP (echo_area_buffer
[0]))
5946 struct frame
*sf
= SELECTED_FRAME ();
5947 if (FRAME_MESSAGE_BUF (sf
))
5948 with_echo_area_buffer (0, 0, (int (*) ()) truncate_message_1
, nchars
);
5953 /* Helper function for truncate_echo_area. Truncate the current
5954 message to at most NCHARS characters. */
5957 truncate_message_1 (nchars
)
5960 if (BEG
+ nchars
< Z
)
5961 del_range (BEG
+ nchars
, Z
);
5963 echo_area_buffer
[0] = Qnil
;
5968 /* Set the current message to a substring of S or STRING.
5970 If STRING is a Lisp string, set the message to the first NBYTES
5971 bytes from STRING. NBYTES zero means use the whole string. If
5972 STRING is multibyte, the message will be displayed multibyte.
5974 If S is not null, set the message to the first LEN bytes of S. LEN
5975 zero means use the whole string. MULTIBYTE_P non-zero means S is
5976 multibyte. Display the message multibyte in that case. */
5979 set_message (s
, string
, nbytes
, multibyte_p
)
5984 message_enable_multibyte
5985 = ((s
&& multibyte_p
)
5986 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
5988 with_echo_area_buffer (0, -1, (int (*) ()) set_message_1
,
5989 s
, string
, nbytes
, multibyte_p
);
5990 message_buf_print
= 0;
5994 /* Helper function for set_message. Arguments have the same meaning
5995 as there. This function is called with the echo area buffer being
5999 set_message_1 (s
, string
, nbytes
, multibyte_p
)
6002 int nbytes
, multibyte_p
;
6006 /* Change multibyteness of the echo buffer appropriately. */
6007 if (message_enable_multibyte
6008 != !NILP (current_buffer
->enable_multibyte_characters
))
6009 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6011 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6013 /* Insert new message at BEG. */
6014 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6016 if (STRINGP (string
))
6021 nbytes
= XSTRING (string
)->size_byte
;
6022 nchars
= string_byte_to_char (string
, nbytes
);
6024 /* This function takes care of single/multibyte conversion. We
6025 just have to ensure that the echo area buffer has the right
6026 setting of enable_multibyte_characters. */
6027 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6032 nbytes
= strlen (s
);
6034 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6036 /* Convert from multi-byte to single-byte. */
6038 unsigned char work
[1];
6040 /* Convert a multibyte string to single-byte. */
6041 for (i
= 0; i
< nbytes
; i
+= n
)
6043 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6044 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6046 : multibyte_char_to_unibyte (c
, Qnil
));
6047 insert_1_both (work
, 1, 1, 1, 0, 0);
6050 else if (!multibyte_p
6051 && !NILP (current_buffer
->enable_multibyte_characters
))
6053 /* Convert from single-byte to multi-byte. */
6055 unsigned char *msg
= (unsigned char *) s
;
6056 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6058 /* Convert a single-byte string to multibyte. */
6059 for (i
= 0; i
< nbytes
; i
++)
6061 c
= unibyte_char_to_multibyte (msg
[i
]);
6062 n
= CHAR_STRING (c
, str
);
6063 insert_1_both (str
, 1, n
, 1, 0, 0);
6067 insert_1 (s
, nbytes
, 1, 0, 0);
6074 /* Clear messages. CURRENT_P non-zero means clear the current
6075 message. LAST_DISPLAYED_P non-zero means clear the message
6079 clear_message (current_p
, last_displayed_p
)
6080 int current_p
, last_displayed_p
;
6083 echo_area_buffer
[0] = Qnil
;
6085 if (last_displayed_p
)
6086 echo_area_buffer
[1] = Qnil
;
6088 message_buf_print
= 0;
6091 /* Clear garbaged frames.
6093 This function is used where the old redisplay called
6094 redraw_garbaged_frames which in turn called redraw_frame which in
6095 turn called clear_frame. The call to clear_frame was a source of
6096 flickering. I believe a clear_frame is not necessary. It should
6097 suffice in the new redisplay to invalidate all current matrices,
6098 and ensure a complete redisplay of all windows. */
6101 clear_garbaged_frames ()
6105 Lisp_Object tail
, frame
;
6107 FOR_EACH_FRAME (tail
, frame
)
6109 struct frame
*f
= XFRAME (frame
);
6111 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6113 clear_current_matrices (f
);
6119 ++windows_or_buffers_changed
;
6124 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6125 is non-zero update selected_frame. Value is non-zero if the
6126 mini-windows height has been changed. */
6129 echo_area_display (update_frame_p
)
6132 Lisp_Object mini_window
;
6135 int window_height_changed_p
= 0;
6136 struct frame
*sf
= SELECTED_FRAME ();
6138 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6139 w
= XWINDOW (mini_window
);
6140 f
= XFRAME (WINDOW_FRAME (w
));
6142 /* Don't display if frame is invisible or not yet initialized. */
6143 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6146 #ifdef HAVE_WINDOW_SYSTEM
6147 /* When Emacs starts, selected_frame may be a visible terminal
6148 frame, even if we run under a window system. If we let this
6149 through, a message would be displayed on the terminal. */
6150 if (EQ (selected_frame
, Vterminal_frame
)
6151 && !NILP (Vwindow_system
))
6153 #endif /* HAVE_WINDOW_SYSTEM */
6155 /* Redraw garbaged frames. */
6157 clear_garbaged_frames ();
6159 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6161 echo_area_window
= mini_window
;
6162 window_height_changed_p
= display_echo_area (w
);
6163 w
->must_be_updated_p
= 1;
6167 /* Not called from redisplay_internal. If we changed
6168 window configuration, we must redisplay thoroughly.
6169 Otherwise, we can do with updating what we displayed
6171 if (window_height_changed_p
)
6173 ++windows_or_buffers_changed
;
6174 ++update_mode_lines
;
6175 redisplay_internal (0);
6177 else if (FRAME_WINDOW_P (f
))
6179 update_single_window (w
, 1);
6180 rif
->flush_display (f
);
6183 update_frame (f
, 1, 1);
6186 else if (!EQ (mini_window
, selected_window
))
6187 windows_or_buffers_changed
++;
6189 /* Last displayed message is now the current message. */
6190 echo_area_buffer
[1] = echo_area_buffer
[0];
6192 /* Prevent redisplay optimization in redisplay_internal by resetting
6193 this_line_start_pos. This is done because the mini-buffer now
6194 displays the message instead of its buffer text. */
6195 if (EQ (mini_window
, selected_window
))
6196 CHARPOS (this_line_start_pos
) = 0;
6198 return window_height_changed_p
;
6203 /***********************************************************************
6205 ***********************************************************************/
6208 #ifdef HAVE_WINDOW_SYSTEM
6210 /* A buffer for constructing frame titles in it; allocated from the
6211 heap in init_xdisp and resized as needed in store_frame_title_char. */
6213 static char *frame_title_buf
;
6215 /* The buffer's end, and a current output position in it. */
6217 static char *frame_title_buf_end
;
6218 static char *frame_title_ptr
;
6221 /* Store a single character C for the frame title in frame_title_buf.
6222 Re-allocate frame_title_buf if necessary. */
6225 store_frame_title_char (c
)
6228 /* If output position has reached the end of the allocated buffer,
6229 double the buffer's size. */
6230 if (frame_title_ptr
== frame_title_buf_end
)
6232 int len
= frame_title_ptr
- frame_title_buf
;
6233 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6234 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6235 frame_title_buf_end
= frame_title_buf
+ new_size
;
6236 frame_title_ptr
= frame_title_buf
+ len
;
6239 *frame_title_ptr
++ = c
;
6243 /* Store part of a frame title in frame_title_buf, beginning at
6244 frame_title_ptr. STR is the string to store. Do not copy more
6245 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
6246 the whole string. Pad with spaces until FIELD_WIDTH number of
6247 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
6248 Called from display_mode_element when it is used to build a frame
6252 store_frame_title (str
, field_width
, precision
)
6254 int field_width
, precision
;
6258 /* Copy at most PRECISION chars from STR. */
6259 while ((precision
<= 0 || n
< precision
)
6262 store_frame_title_char (*str
++);
6266 /* Fill up with spaces until FIELD_WIDTH reached. */
6267 while (field_width
> 0
6270 store_frame_title_char (' ');
6278 /* Set the title of FRAME, if it has changed. The title format is
6279 Vicon_title_format if FRAME is iconified, otherwise it is
6280 frame_title_format. */
6283 x_consider_frame_title (frame
)
6286 struct frame
*f
= XFRAME (frame
);
6288 if (FRAME_WINDOW_P (f
)
6289 || FRAME_MINIBUF_ONLY_P (f
)
6290 || f
->explicit_name
)
6292 /* Do we have more than one visible frame on this X display? */
6295 struct buffer
*obuf
;
6299 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
6301 struct frame
*tf
= XFRAME (XCAR (tail
));
6304 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
6305 && !FRAME_MINIBUF_ONLY_P (tf
)
6306 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
6310 /* Set global variable indicating that multiple frames exist. */
6311 multiple_frames
= CONSP (tail
);
6313 /* Switch to the buffer of selected window of the frame. Set up
6314 frame_title_ptr so that display_mode_element will output into it;
6315 then display the title. */
6316 obuf
= current_buffer
;
6317 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
6318 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
6319 frame_title_ptr
= frame_title_buf
;
6320 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
6321 NULL
, DEFAULT_FACE_ID
);
6322 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
6323 frame_title_ptr
= NULL
;
6324 set_buffer_internal (obuf
);
6326 /* Set the title only if it's changed. This avoids consing in
6327 the common case where it hasn't. (If it turns out that we've
6328 already wasted too much time by walking through the list with
6329 display_mode_element, then we might need to optimize at a
6330 higher level than this.) */
6331 if (! STRINGP (f
->name
)
6332 || STRING_BYTES (XSTRING (f
->name
)) != len
6333 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
6334 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
6338 #else /* not HAVE_WINDOW_SYSTEM */
6340 #define frame_title_ptr ((char *)0)
6341 #define store_frame_title(str, mincol, maxcol) 0
6343 #endif /* not HAVE_WINDOW_SYSTEM */
6348 /***********************************************************************
6350 ***********************************************************************/
6353 /* Prepare for redisplay by updating menu-bar item lists when
6354 appropriate. This can call eval. */
6357 prepare_menu_bars ()
6360 struct gcpro gcpro1
, gcpro2
;
6362 struct frame
*tooltip_frame
;
6364 #ifdef HAVE_X_WINDOWS
6365 tooltip_frame
= tip_frame
;
6367 tooltip_frame
= NULL
;
6370 /* Update all frame titles based on their buffer names, etc. We do
6371 this before the menu bars so that the buffer-menu will show the
6372 up-to-date frame titles. */
6373 #ifdef HAVE_WINDOW_SYSTEM
6374 if (windows_or_buffers_changed
|| update_mode_lines
)
6376 Lisp_Object tail
, frame
;
6378 FOR_EACH_FRAME (tail
, frame
)
6381 if (f
!= tooltip_frame
6382 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
6383 x_consider_frame_title (frame
);
6386 #endif /* HAVE_WINDOW_SYSTEM */
6388 /* Update the menu bar item lists, if appropriate. This has to be
6389 done before any actual redisplay or generation of display lines. */
6390 all_windows
= (update_mode_lines
6391 || buffer_shared
> 1
6392 || windows_or_buffers_changed
);
6395 Lisp_Object tail
, frame
;
6396 int count
= specpdl_ptr
- specpdl
;
6398 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6400 FOR_EACH_FRAME (tail
, frame
)
6404 /* Ignore tooltip frame. */
6405 if (f
== tooltip_frame
)
6408 /* If a window on this frame changed size, report that to
6409 the user and clear the size-change flag. */
6410 if (FRAME_WINDOW_SIZES_CHANGED (f
))
6412 Lisp_Object functions
;
6414 /* Clear flag first in case we get an error below. */
6415 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
6416 functions
= Vwindow_size_change_functions
;
6417 GCPRO2 (tail
, functions
);
6419 while (CONSP (functions
))
6421 call1 (XCAR (functions
), frame
);
6422 functions
= XCDR (functions
);
6428 update_menu_bar (f
, 0);
6429 #ifdef HAVE_WINDOW_SYSTEM
6430 update_tool_bar (f
, 0);
6435 unbind_to (count
, Qnil
);
6439 struct frame
*sf
= SELECTED_FRAME ();
6440 update_menu_bar (sf
, 1);
6441 #ifdef HAVE_WINDOW_SYSTEM
6442 update_tool_bar (sf
, 1);
6446 /* Motif needs this. See comment in xmenu.c. Turn it off when
6447 pending_menu_activation is not defined. */
6448 #ifdef USE_X_TOOLKIT
6449 pending_menu_activation
= 0;
6454 /* Update the menu bar item list for frame F. This has to be done
6455 before we start to fill in any display lines, because it can call
6458 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
6461 update_menu_bar (f
, save_match_data
)
6463 int save_match_data
;
6466 register struct window
*w
;
6468 window
= FRAME_SELECTED_WINDOW (f
);
6469 w
= XWINDOW (window
);
6471 if (update_mode_lines
)
6472 w
->update_mode_line
= Qt
;
6474 if (FRAME_WINDOW_P (f
)
6476 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6477 FRAME_EXTERNAL_MENU_BAR (f
)
6479 FRAME_MENU_BAR_LINES (f
) > 0
6481 : FRAME_MENU_BAR_LINES (f
) > 0)
6483 /* If the user has switched buffers or windows, we need to
6484 recompute to reflect the new bindings. But we'll
6485 recompute when update_mode_lines is set too; that means
6486 that people can use force-mode-line-update to request
6487 that the menu bar be recomputed. The adverse effect on
6488 the rest of the redisplay algorithm is about the same as
6489 windows_or_buffers_changed anyway. */
6490 if (windows_or_buffers_changed
6491 || !NILP (w
->update_mode_line
)
6492 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6493 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6494 != !NILP (w
->last_had_star
))
6495 || ((!NILP (Vtransient_mark_mode
)
6496 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6497 != !NILP (w
->region_showing
)))
6499 struct buffer
*prev
= current_buffer
;
6500 int count
= specpdl_ptr
- specpdl
;
6502 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6503 if (save_match_data
)
6504 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6505 if (NILP (Voverriding_local_map_menu_flag
))
6507 specbind (Qoverriding_terminal_local_map
, Qnil
);
6508 specbind (Qoverriding_local_map
, Qnil
);
6511 /* Run the Lucid hook. */
6512 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
6514 /* If it has changed current-menubar from previous value,
6515 really recompute the menu-bar from the value. */
6516 if (! NILP (Vlucid_menu_bar_dirty_flag
))
6517 call0 (Qrecompute_lucid_menubar
);
6519 safe_run_hooks (Qmenu_bar_update_hook
);
6520 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
6522 /* Redisplay the menu bar in case we changed it. */
6523 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6524 if (FRAME_WINDOW_P (f
))
6525 set_frame_menubar (f
, 0, 0);
6527 /* On a terminal screen, the menu bar is an ordinary screen
6528 line, and this makes it get updated. */
6529 w
->update_mode_line
= Qt
;
6530 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6531 /* In the non-toolkit version, the menu bar is an ordinary screen
6532 line, and this makes it get updated. */
6533 w
->update_mode_line
= Qt
;
6534 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6536 unbind_to (count
, Qnil
);
6537 set_buffer_internal_1 (prev
);
6544 /***********************************************************************
6546 ***********************************************************************/
6548 #ifdef HAVE_WINDOW_SYSTEM
6550 /* Update the tool-bar item list for frame F. This has to be done
6551 before we start to fill in any display lines. Called from
6552 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
6553 and restore it here. */
6556 update_tool_bar (f
, save_match_data
)
6558 int save_match_data
;
6560 if (WINDOWP (f
->tool_bar_window
)
6561 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
6566 window
= FRAME_SELECTED_WINDOW (f
);
6567 w
= XWINDOW (window
);
6569 /* If the user has switched buffers or windows, we need to
6570 recompute to reflect the new bindings. But we'll
6571 recompute when update_mode_lines is set too; that means
6572 that people can use force-mode-line-update to request
6573 that the menu bar be recomputed. The adverse effect on
6574 the rest of the redisplay algorithm is about the same as
6575 windows_or_buffers_changed anyway. */
6576 if (windows_or_buffers_changed
6577 || !NILP (w
->update_mode_line
)
6578 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6579 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6580 != !NILP (w
->last_had_star
))
6581 || ((!NILP (Vtransient_mark_mode
)
6582 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6583 != !NILP (w
->region_showing
)))
6585 struct buffer
*prev
= current_buffer
;
6586 int count
= specpdl_ptr
- specpdl
;
6588 /* Set current_buffer to the buffer of the selected
6589 window of the frame, so that we get the right local
6591 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6593 /* Save match data, if we must. */
6594 if (save_match_data
)
6595 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6597 /* Make sure that we don't accidentally use bogus keymaps. */
6598 if (NILP (Voverriding_local_map_menu_flag
))
6600 specbind (Qoverriding_terminal_local_map
, Qnil
);
6601 specbind (Qoverriding_local_map
, Qnil
);
6604 /* Build desired tool-bar items from keymaps. */
6605 f
->desired_tool_bar_items
6606 = tool_bar_items (f
->desired_tool_bar_items
,
6607 &f
->n_desired_tool_bar_items
);
6609 /* Redisplay the tool-bar in case we changed it. */
6610 w
->update_mode_line
= Qt
;
6612 unbind_to (count
, Qnil
);
6613 set_buffer_internal_1 (prev
);
6619 /* Set F->desired_tool_bar_string to a Lisp string representing frame
6620 F's desired tool-bar contents. F->desired_tool_bar_items must have
6621 been set up previously by calling prepare_menu_bars. */
6624 build_desired_tool_bar_string (f
)
6627 int i
, size
, size_needed
, string_idx
;
6628 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6629 Lisp_Object image
, plist
, props
;
6631 image
= plist
= props
= Qnil
;
6632 GCPRO3 (image
, plist
, props
);
6634 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
6635 Otherwise, make a new string. */
6637 /* The size of the string we might be able to reuse. */
6638 size
= (STRINGP (f
->desired_tool_bar_string
)
6639 ? XSTRING (f
->desired_tool_bar_string
)->size
6642 /* Each image in the string we build is preceded by a space,
6643 and there is a space at the end. */
6644 size_needed
= f
->n_desired_tool_bar_items
+ 1;
6646 /* Reuse f->desired_tool_bar_string, if possible. */
6647 if (size
< size_needed
)
6648 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
6652 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
6653 Fremove_text_properties (make_number (0), make_number (size
),
6654 props
, f
->desired_tool_bar_string
);
6657 /* Put a `display' property on the string for the images to display,
6658 put a `menu_item' property on tool-bar items with a value that
6659 is the index of the item in F's tool-bar item vector. */
6660 for (i
= 0, string_idx
= 0;
6661 i
< f
->n_desired_tool_bar_items
;
6662 ++i
, string_idx
+= 1)
6665 (XVECTOR (f->desired_tool_bar_items) \
6666 ->contents[i * TOOL_BAR_ITEM_NSLOTS + (IDX)])
6668 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
6669 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
6671 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
6672 extern Lisp_Object Qlaplace
;
6674 /* If image is a vector, choose the image according to the
6676 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
6677 if (VECTORP (image
))
6679 enum tool_bar_item_image idx
;
6683 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
6684 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
6687 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
6688 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
6690 xassert (XVECTOR (image
)->size
>= idx
);
6691 image
= XVECTOR (image
)->contents
[idx
];
6694 /* Ignore invalid image specifications. */
6695 if (!valid_image_p (image
))
6698 /* Display the tool-bar button pressed, or depressed. */
6699 plist
= Fcopy_sequence (XCDR (image
));
6701 /* Compute margin and relief to draw. */
6702 relief
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
6703 margin
= relief
+ max (0, tool_bar_button_margin
);
6705 if (auto_raise_tool_bar_buttons_p
)
6707 /* Add a `:relief' property to the image spec if the item is
6711 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
6717 /* If image is selected, display it pressed, i.e. with a
6718 negative relief. If it's not selected, display it with a
6720 plist
= Fplist_put (plist
, QCrelief
,
6722 ? make_number (-relief
)
6723 : make_number (relief
)));
6727 /* Put a margin around the image. */
6729 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
6731 /* If button is not enabled, make the image appear disabled by
6732 applying an appropriate algorithm to it. */
6734 plist
= Fplist_put (plist
, QCalgorithm
, Qlaplace
);
6736 /* Put a `display' text property on the string for the image to
6737 display. Put a `menu-item' property on the string that gives
6738 the start of this item's properties in the tool-bar items
6740 image
= Fcons (Qimage
, plist
);
6741 props
= list4 (Qdisplay
, image
,
6742 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
)),
6743 Fadd_text_properties (make_number (string_idx
),
6744 make_number (string_idx
+ 1),
6745 props
, f
->desired_tool_bar_string
);
6753 /* Display one line of the tool-bar of frame IT->f. */
6756 display_tool_bar_line (it
)
6759 struct glyph_row
*row
= it
->glyph_row
;
6760 int max_x
= it
->last_visible_x
;
6763 prepare_desired_row (row
);
6764 row
->y
= it
->current_y
;
6766 while (it
->current_x
< max_x
)
6768 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
6770 /* Get the next display element. */
6771 if (!get_next_display_element (it
))
6774 /* Produce glyphs. */
6775 x_before
= it
->current_x
;
6776 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
6777 PRODUCE_GLYPHS (it
);
6779 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
6784 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
6786 if (x
+ glyph
->pixel_width
> max_x
)
6788 /* Glyph doesn't fit on line. */
6789 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
6795 x
+= glyph
->pixel_width
;
6799 /* Stop at line ends. */
6800 if (ITERATOR_AT_END_OF_LINE_P (it
))
6803 set_iterator_to_next (it
);
6808 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
6809 extend_face_to_end_of_line (it
);
6810 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
6811 last
->right_box_line_p
= 1;
6812 compute_line_metrics (it
);
6814 /* If line is empty, make it occupy the rest of the tool-bar. */
6815 if (!row
->displays_text_p
)
6817 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
6818 row
->ascent
= row
->phys_ascent
= 0;
6821 row
->full_width_p
= 1;
6822 row
->continued_p
= 0;
6823 row
->truncated_on_left_p
= 0;
6824 row
->truncated_on_right_p
= 0;
6826 it
->current_x
= it
->hpos
= 0;
6827 it
->current_y
+= row
->height
;
6833 /* Value is the number of screen lines needed to make all tool-bar
6834 items of frame F visible. */
6837 tool_bar_lines_needed (f
)
6840 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6843 /* Initialize an iterator for iteration over
6844 F->desired_tool_bar_string in the tool-bar window of frame F. */
6845 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
6846 it
.first_visible_x
= 0;
6847 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6848 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
6850 while (!ITERATOR_AT_END_P (&it
))
6852 it
.glyph_row
= w
->desired_matrix
->rows
;
6853 clear_glyph_row (it
.glyph_row
);
6854 display_tool_bar_line (&it
);
6857 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
6861 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
6862 height should be changed. */
6865 redisplay_tool_bar (f
)
6870 struct glyph_row
*row
;
6871 int change_height_p
= 0;
6873 /* If frame hasn't a tool-bar window or if it is zero-height, don't
6874 do anything. This means you must start with tool-bar-lines
6875 non-zero to get the auto-sizing effect. Or in other words, you
6876 can turn off tool-bars by specifying tool-bar-lines zero. */
6877 if (!WINDOWP (f
->tool_bar_window
)
6878 || (w
= XWINDOW (f
->tool_bar_window
),
6879 XFASTINT (w
->height
) == 0))
6882 /* Set up an iterator for the tool-bar window. */
6883 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
6884 it
.first_visible_x
= 0;
6885 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6888 /* Build a string that represents the contents of the tool-bar. */
6889 build_desired_tool_bar_string (f
);
6890 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
6892 /* Display as many lines as needed to display all tool-bar items. */
6893 while (it
.current_y
< it
.last_visible_y
)
6894 display_tool_bar_line (&it
);
6896 /* It doesn't make much sense to try scrolling in the tool-bar
6897 window, so don't do it. */
6898 w
->desired_matrix
->no_scrolling_p
= 1;
6899 w
->must_be_updated_p
= 1;
6901 if (auto_resize_tool_bars_p
)
6905 /* If there are blank lines at the end, except for a partially
6906 visible blank line at the end that is smaller than
6907 CANON_Y_UNIT, change the tool-bar's height. */
6908 row
= it
.glyph_row
- 1;
6909 if (!row
->displays_text_p
6910 && row
->height
>= CANON_Y_UNIT (f
))
6911 change_height_p
= 1;
6913 /* If row displays tool-bar items, but is partially visible,
6914 change the tool-bar's height. */
6915 if (row
->displays_text_p
6916 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
6917 change_height_p
= 1;
6919 /* Resize windows as needed by changing the `tool-bar-lines'
6922 && (nlines
= tool_bar_lines_needed (f
),
6923 nlines
!= XFASTINT (w
->height
)))
6925 extern Lisp_Object Qtool_bar_lines
;
6928 XSETFRAME (frame
, f
);
6929 clear_glyph_matrix (w
->desired_matrix
);
6930 Fmodify_frame_parameters (frame
,
6931 Fcons (Fcons (Qtool_bar_lines
,
6932 make_number (nlines
)),
6934 fonts_changed_p
= 1;
6938 return change_height_p
;
6942 /* Get information about the tool-bar item which is displayed in GLYPH
6943 on frame F. Return in *PROP_IDX the index where tool-bar item
6944 properties start in F->current_tool_bar_items. Value is zero if
6945 GLYPH doesn't display a tool-bar item. */
6948 tool_bar_item_info (f
, glyph
, prop_idx
)
6950 struct glyph
*glyph
;
6956 /* Get the text property `menu-item' at pos. The value of that
6957 property is the start index of this item's properties in
6958 F->current_tool_bar_items. */
6959 prop
= Fget_text_property (make_number (glyph
->charpos
),
6960 Qmenu_item
, f
->current_tool_bar_string
);
6961 if (INTEGERP (prop
))
6963 *prop_idx
= XINT (prop
);
6972 #endif /* HAVE_WINDOW_SYSTEM */
6976 /************************************************************************
6977 Horizontal scrolling
6978 ************************************************************************/
6980 static int hscroll_window_tree
P_ ((Lisp_Object
));
6981 static int hscroll_windows
P_ ((Lisp_Object
));
6983 /* For all leaf windows in the window tree rooted at WINDOW, set their
6984 hscroll value so that PT is (i) visible in the window, and (ii) so
6985 that it is not within a certain margin at the window's left and
6986 right border. Value is non-zero if any window's hscroll has been
6990 hscroll_window_tree (window
)
6993 int hscrolled_p
= 0;
6995 while (WINDOWP (window
))
6997 struct window
*w
= XWINDOW (window
);
6999 if (WINDOWP (w
->hchild
))
7000 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7001 else if (WINDOWP (w
->vchild
))
7002 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7003 else if (w
->cursor
.vpos
>= 0)
7005 int hscroll_margin
, text_area_x
, text_area_y
;
7006 int text_area_width
, text_area_height
;
7007 struct glyph_row
*current_cursor_row
7008 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7009 struct glyph_row
*desired_cursor_row
7010 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7011 struct glyph_row
*cursor_row
7012 = (desired_cursor_row
->enabled_p
7013 ? desired_cursor_row
7014 : current_cursor_row
);
7016 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7017 &text_area_width
, &text_area_height
);
7019 /* Scroll when cursor is inside this scroll margin. */
7020 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
7022 if ((XFASTINT (w
->hscroll
)
7023 && w
->cursor
.x
< hscroll_margin
)
7024 || (cursor_row
->enabled_p
7025 && cursor_row
->truncated_on_right_p
7026 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
7030 struct buffer
*saved_current_buffer
;
7033 /* Find point in a display of infinite width. */
7034 saved_current_buffer
= current_buffer
;
7035 current_buffer
= XBUFFER (w
->buffer
);
7037 if (w
== XWINDOW (selected_window
))
7038 pt
= BUF_PT (current_buffer
);
7041 pt
= marker_position (w
->pointm
);
7042 pt
= max (BEGV
, pt
);
7046 /* Move iterator to pt starting at cursor_row->start in
7047 a line with infinite width. */
7048 init_to_row_start (&it
, w
, cursor_row
);
7049 it
.last_visible_x
= INFINITY
;
7050 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
7051 current_buffer
= saved_current_buffer
;
7053 /* Center cursor in window. */
7054 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
7055 / CANON_X_UNIT (it
.f
));
7057 /* Don't call Fset_window_hscroll if value hasn't
7058 changed because it will prevent redisplay
7060 if (XFASTINT (w
->hscroll
) != hscroll
)
7062 Fset_window_hscroll (window
, make_number (hscroll
));
7071 /* Value is non-zero if hscroll of any leaf window has been changed. */
7076 /* Set hscroll so that cursor is visible and not inside horizontal
7077 scroll margins for all windows in the tree rooted at WINDOW. See
7078 also hscroll_window_tree above. Value is non-zero if any window's
7079 hscroll has been changed. If it has, desired matrices on the frame
7080 of WINDOW are cleared. */
7083 hscroll_windows (window
)
7088 if (automatic_hscrolling_p
)
7090 hscrolled_p
= hscroll_window_tree (window
);
7092 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
7101 /************************************************************************
7103 ************************************************************************/
7105 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
7106 to a non-zero value. This is sometimes handy to have in a debugger
7111 /* First and last unchanged row for try_window_id. */
7113 int debug_first_unchanged_at_end_vpos
;
7114 int debug_last_unchanged_at_beg_vpos
;
7116 /* Delta vpos and y. */
7118 int debug_dvpos
, debug_dy
;
7120 /* Delta in characters and bytes for try_window_id. */
7122 int debug_delta
, debug_delta_bytes
;
7124 /* Values of window_end_pos and window_end_vpos at the end of
7127 int debug_end_pos
, debug_end_vpos
;
7129 /* Append a string to W->desired_matrix->method. FMT is a printf
7130 format string. A1...A9 are a supplement for a variable-length
7131 argument list. If trace_redisplay_p is non-zero also printf the
7132 resulting string to stderr. */
7135 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
7138 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
7141 char *method
= w
->desired_matrix
->method
;
7142 int len
= strlen (method
);
7143 int size
= sizeof w
->desired_matrix
->method
;
7144 int remaining
= size
- len
- 1;
7146 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
7147 if (len
&& remaining
)
7153 strncpy (method
+ len
, buffer
, remaining
);
7155 if (trace_redisplay_p
)
7156 fprintf (stderr
, "%p (%s): %s\n",
7158 ((BUFFERP (w
->buffer
)
7159 && STRINGP (XBUFFER (w
->buffer
)->name
))
7160 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
7165 #endif /* GLYPH_DEBUG */
7168 /* This counter is used to clear the face cache every once in a while
7169 in redisplay_internal. It is incremented for each redisplay.
7170 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
7173 #define CLEAR_FACE_CACHE_COUNT 10000
7174 static int clear_face_cache_count
;
7176 /* Record the previous terminal frame we displayed. */
7178 static struct frame
*previous_terminal_frame
;
7180 /* Non-zero while redisplay_internal is in progress. */
7185 /* Value is non-zero if all changes in window W, which displays
7186 current_buffer, are in the text between START and END. START is a
7187 buffer position, END is given as a distance from Z. Used in
7188 redisplay_internal for display optimization. */
7191 text_outside_line_unchanged_p (w
, start
, end
)
7195 int unchanged_p
= 1;
7197 /* If text or overlays have changed, see where. */
7198 if (XFASTINT (w
->last_modified
) < MODIFF
7199 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7201 /* Gap in the line? */
7202 if (GPT
< start
|| Z
- GPT
< end
)
7205 /* Changes start in front of the line, or end after it? */
7207 && (BEG_UNCHANGED
< start
- 1
7208 || END_UNCHANGED
< end
))
7211 /* If selective display, can't optimize if changes start at the
7212 beginning of the line. */
7214 && INTEGERP (current_buffer
->selective_display
)
7215 && XINT (current_buffer
->selective_display
) > 0
7216 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
7224 /* Do a frame update, taking possible shortcuts into account. This is
7225 the main external entry point for redisplay.
7227 If the last redisplay displayed an echo area message and that message
7228 is no longer requested, we clear the echo area or bring back the
7229 mini-buffer if that is in use. */
7234 redisplay_internal (0);
7237 /* Return 1 if point moved out of or into a composition. Otherwise
7238 return 0. PREV_BUF and PREV_PT are the last point buffer and
7239 position. BUF and PT are the current point buffer and position. */
7242 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
7243 struct buffer
*prev_buf
, *buf
;
7250 XSETBUFFER (buffer
, buf
);
7251 /* Check a composition at the last point if point moved within the
7253 if (prev_buf
== buf
)
7256 /* Point didn't move. */
7259 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
7260 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
7261 && COMPOSITION_VALID_P (start
, end
, prop
)
7262 && start
< prev_pt
&& end
> prev_pt
)
7263 /* The last point was within the composition. Return 1 iff
7264 point moved out of the composition. */
7265 return (pt
<= start
|| pt
>= end
);
7268 /* Check a composition at the current point. */
7269 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
7270 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
7271 && COMPOSITION_VALID_P (start
, end
, prop
)
7272 && start
< pt
&& end
> pt
);
7275 /* Reconsider the setting of B->clip_changed which is displayed
7279 reconsider_clip_changes (w
, b
)
7283 if (b
->prevent_redisplay_optimizations_p
)
7284 b
->clip_changed
= 1;
7285 else if (b
->clip_changed
7286 && !NILP (w
->window_end_valid
)
7287 && w
->current_matrix
->buffer
== b
7288 && w
->current_matrix
->zv
== BUF_ZV (b
)
7289 && w
->current_matrix
->begv
== BUF_BEGV (b
))
7290 b
->clip_changed
= 0;
7292 /* If display wasn't paused, and W is not a tool bar window, see if
7293 point has been moved into or out of a composition. In that case,
7294 we set b->clip_changed to 1 to force updating the screen. If
7295 b->clip_changed has already been set to 1, we can skip this
7297 if (!b
->clip_changed
7298 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
7302 if (w
== XWINDOW (selected_window
))
7303 pt
= BUF_PT (current_buffer
);
7305 pt
= marker_position (w
->pointm
);
7307 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
7308 || pt
!= XINT (w
->last_point
))
7309 && check_point_in_composition (w
->current_matrix
->buffer
,
7310 XINT (w
->last_point
),
7311 XBUFFER (w
->buffer
), pt
))
7312 b
->clip_changed
= 1;
7317 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
7318 response to any user action; therefore, we should preserve the echo
7319 area. (Actually, our caller does that job.) Perhaps in the future
7320 avoid recentering windows if it is not necessary; currently that
7321 causes some problems. */
7324 redisplay_internal (preserve_echo_area
)
7325 int preserve_echo_area
;
7327 struct window
*w
= XWINDOW (selected_window
);
7328 struct frame
*f
= XFRAME (w
->frame
);
7330 int must_finish
= 0;
7331 struct text_pos tlbufpos
, tlendpos
;
7332 int number_of_visible_frames
;
7334 struct frame
*sf
= SELECTED_FRAME ();
7336 /* Non-zero means redisplay has to consider all windows on all
7337 frames. Zero means, only selected_window is considered. */
7338 int consider_all_windows_p
;
7340 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
7342 /* No redisplay if running in batch mode or frame is not yet fully
7343 initialized, or redisplay is explicitly turned off by setting
7344 Vinhibit_redisplay. */
7346 || !NILP (Vinhibit_redisplay
)
7347 || !f
->glyphs_initialized_p
)
7350 /* The flag redisplay_performed_directly_p is set by
7351 direct_output_for_insert when it already did the whole screen
7352 update necessary. */
7353 if (redisplay_performed_directly_p
)
7355 redisplay_performed_directly_p
= 0;
7356 if (!hscroll_windows (selected_window
))
7360 #ifdef USE_X_TOOLKIT
7361 if (popup_activated ())
7365 /* I don't think this happens but let's be paranoid. */
7369 /* Record a function that resets redisplaying_p to its old value
7370 when we leave this function. */
7371 count
= specpdl_ptr
- specpdl
;
7372 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
7377 reconsider_clip_changes (w
, current_buffer
);
7379 /* If new fonts have been loaded that make a glyph matrix adjustment
7380 necessary, do it. */
7381 if (fonts_changed_p
)
7383 adjust_glyphs (NULL
);
7384 ++windows_or_buffers_changed
;
7385 fonts_changed_p
= 0;
7388 if (! FRAME_WINDOW_P (sf
)
7389 && previous_terminal_frame
!= sf
)
7391 /* Since frames on an ASCII terminal share the same display
7392 area, displaying a different frame means redisplay the whole
7394 windows_or_buffers_changed
++;
7395 SET_FRAME_GARBAGED (sf
);
7396 XSETFRAME (Vterminal_frame
, sf
);
7398 previous_terminal_frame
= sf
;
7400 /* Set the visible flags for all frames. Do this before checking
7401 for resized or garbaged frames; they want to know if their frames
7402 are visible. See the comment in frame.h for
7403 FRAME_SAMPLE_VISIBILITY. */
7405 Lisp_Object tail
, frame
;
7407 number_of_visible_frames
= 0;
7409 FOR_EACH_FRAME (tail
, frame
)
7411 struct frame
*f
= XFRAME (frame
);
7413 FRAME_SAMPLE_VISIBILITY (f
);
7414 if (FRAME_VISIBLE_P (f
))
7415 ++number_of_visible_frames
;
7416 clear_desired_matrices (f
);
7420 /* Notice any pending interrupt request to change frame size. */
7421 do_pending_window_change (1);
7423 /* Clear frames marked as garbaged. */
7425 clear_garbaged_frames ();
7427 /* Build menubar and tool-bar items. */
7428 prepare_menu_bars ();
7430 if (windows_or_buffers_changed
)
7431 update_mode_lines
++;
7433 /* Detect case that we need to write or remove a star in the mode line. */
7434 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
7436 w
->update_mode_line
= Qt
;
7437 if (buffer_shared
> 1)
7438 update_mode_lines
++;
7441 /* If %c is in the mode line, update it if needed. */
7442 if (!NILP (w
->column_number_displayed
)
7443 /* This alternative quickly identifies a common case
7444 where no change is needed. */
7445 && !(PT
== XFASTINT (w
->last_point
)
7446 && XFASTINT (w
->last_modified
) >= MODIFF
7447 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7448 && XFASTINT (w
->column_number_displayed
) != current_column ())
7449 w
->update_mode_line
= Qt
;
7451 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
7453 /* The variable buffer_shared is set in redisplay_window and
7454 indicates that we redisplay a buffer in different windows. See
7456 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
7458 /* If specs for an arrow have changed, do thorough redisplay
7459 to ensure we remove any arrow that should no longer exist. */
7460 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
7461 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
7462 consider_all_windows_p
= windows_or_buffers_changed
= 1;
7464 /* Normally the message* functions will have already displayed and
7465 updated the echo area, but the frame may have been trashed, or
7466 the update may have been preempted, so display the echo area
7467 again here. Checking both message buffers captures the case that
7468 the echo area should be cleared. */
7469 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
7471 int window_height_changed_p
= echo_area_display (0);
7474 if (fonts_changed_p
)
7476 else if (window_height_changed_p
)
7478 consider_all_windows_p
= 1;
7479 ++update_mode_lines
;
7480 ++windows_or_buffers_changed
;
7482 /* If window configuration was changed, frames may have been
7483 marked garbaged. Clear them or we will experience
7484 surprises wrt scrolling. */
7486 clear_garbaged_frames ();
7489 else if (w
== XWINDOW (minibuf_window
)
7490 && (current_buffer
->clip_changed
7491 || XFASTINT (w
->last_modified
) < MODIFF
7492 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7493 && resize_mini_window (w
, 0))
7495 /* Resized active mini-window to fit the size of what it is
7496 showing if its contents might have changed. */
7498 consider_all_windows_p
= 1;
7499 ++windows_or_buffers_changed
;
7500 ++update_mode_lines
;
7502 /* If window configuration was changed, frames may have been
7503 marked garbaged. Clear them or we will experience
7504 surprises wrt scrolling. */
7506 clear_garbaged_frames ();
7510 /* If showing the region, and mark has changed, we must redisplay
7511 the whole window. The assignment to this_line_start_pos prevents
7512 the optimization directly below this if-statement. */
7513 if (((!NILP (Vtransient_mark_mode
)
7514 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7515 != !NILP (w
->region_showing
))
7516 || (!NILP (w
->region_showing
)
7517 && !EQ (w
->region_showing
,
7518 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
7519 CHARPOS (this_line_start_pos
) = 0;
7521 /* Optimize the case that only the line containing the cursor in the
7522 selected window has changed. Variables starting with this_ are
7523 set in display_line and record information about the line
7524 containing the cursor. */
7525 tlbufpos
= this_line_start_pos
;
7526 tlendpos
= this_line_end_pos
;
7527 if (!consider_all_windows_p
7528 && CHARPOS (tlbufpos
) > 0
7529 && NILP (w
->update_mode_line
)
7530 && !current_buffer
->clip_changed
7531 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
7532 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
7533 /* Make sure recorded data applies to current buffer, etc. */
7534 && this_line_buffer
== current_buffer
7535 && current_buffer
== XBUFFER (w
->buffer
)
7536 && NILP (w
->force_start
)
7537 /* Point must be on the line that we have info recorded about. */
7538 && PT
>= CHARPOS (tlbufpos
)
7539 && PT
<= Z
- CHARPOS (tlendpos
)
7540 /* All text outside that line, including its final newline,
7541 must be unchanged */
7542 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
7543 CHARPOS (tlendpos
)))
7545 if (CHARPOS (tlbufpos
) > BEGV
7546 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
7547 && (CHARPOS (tlbufpos
) == ZV
7548 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
7549 /* Former continuation line has disappeared by becoming empty */
7551 else if (XFASTINT (w
->last_modified
) < MODIFF
7552 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
7553 || MINI_WINDOW_P (w
))
7555 /* We have to handle the case of continuation around a
7556 wide-column character (See the comment in indent.c around
7559 For instance, in the following case:
7561 -------- Insert --------
7562 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
7563 J_I_ ==> J_I_ `^^' are cursors.
7567 As we have to redraw the line above, we should goto cancel. */
7570 int line_height_before
= this_line_pixel_height
;
7572 /* Note that start_display will handle the case that the
7573 line starting at tlbufpos is a continuation lines. */
7574 start_display (&it
, w
, tlbufpos
);
7576 /* Implementation note: It this still necessary? */
7577 if (it
.current_x
!= this_line_start_x
)
7580 TRACE ((stderr
, "trying display optimization 1\n"));
7581 w
->cursor
.vpos
= -1;
7582 overlay_arrow_seen
= 0;
7583 it
.vpos
= this_line_vpos
;
7584 it
.current_y
= this_line_y
;
7585 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
7588 /* If line contains point, is not continued,
7589 and ends at same distance from eob as before, we win */
7590 if (w
->cursor
.vpos
>= 0
7591 /* Line is not continued, otherwise this_line_start_pos
7592 would have been set to 0 in display_line. */
7593 && CHARPOS (this_line_start_pos
)
7594 /* Line ends as before. */
7595 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
7596 /* Line has same height as before. Otherwise other lines
7597 would have to be shifted up or down. */
7598 && this_line_pixel_height
== line_height_before
)
7600 /* If this is not the window's last line, we must adjust
7601 the charstarts of the lines below. */
7602 if (it
.current_y
< it
.last_visible_y
)
7604 struct glyph_row
*row
7605 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
7606 int delta
, delta_bytes
;
7608 if (Z
- CHARPOS (tlendpos
) == ZV
)
7610 /* This line ends at end of (accessible part of)
7611 buffer. There is no newline to count. */
7613 - CHARPOS (tlendpos
)
7614 - MATRIX_ROW_START_CHARPOS (row
));
7615 delta_bytes
= (Z_BYTE
7616 - BYTEPOS (tlendpos
)
7617 - MATRIX_ROW_START_BYTEPOS (row
));
7621 /* This line ends in a newline. Must take
7622 account of the newline and the rest of the
7623 text that follows. */
7625 - CHARPOS (tlendpos
)
7626 - MATRIX_ROW_START_CHARPOS (row
));
7627 delta_bytes
= (Z_BYTE
7628 - BYTEPOS (tlendpos
)
7629 - MATRIX_ROW_START_BYTEPOS (row
));
7632 increment_matrix_positions (w
->current_matrix
,
7634 w
->current_matrix
->nrows
,
7635 delta
, delta_bytes
);
7638 /* If this row displays text now but previously didn't,
7639 or vice versa, w->window_end_vpos may have to be
7641 if ((it
.glyph_row
- 1)->displays_text_p
)
7643 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
7644 XSETINT (w
->window_end_vpos
, this_line_vpos
);
7646 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
7647 && this_line_vpos
> 0)
7648 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
7649 w
->window_end_valid
= Qnil
;
7651 /* Update hint: No need to try to scroll in update_window. */
7652 w
->desired_matrix
->no_scrolling_p
= 1;
7655 *w
->desired_matrix
->method
= 0;
7656 debug_method_add (w
, "optimization 1");
7663 else if (/* Cursor position hasn't changed. */
7664 PT
== XFASTINT (w
->last_point
)
7665 /* Make sure the cursor was last displayed
7666 in this window. Otherwise we have to reposition it. */
7667 && 0 <= w
->cursor
.vpos
7668 && XINT (w
->height
) > w
->cursor
.vpos
)
7672 do_pending_window_change (1);
7674 /* We used to always goto end_of_redisplay here, but this
7675 isn't enough if we have a blinking cursor. */
7676 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
7677 goto end_of_redisplay
;
7681 /* If highlighting the region, or if the cursor is in the echo area,
7682 then we can't just move the cursor. */
7683 else if (! (!NILP (Vtransient_mark_mode
)
7684 && !NILP (current_buffer
->mark_active
))
7685 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7686 || highlight_nonselected_windows
)
7687 && NILP (w
->region_showing
)
7688 && NILP (Vshow_trailing_whitespace
)
7689 && !cursor_in_echo_area
)
7692 struct glyph_row
*row
;
7694 /* Skip from tlbufpos to PT and see where it is. Note that
7695 PT may be in invisible text. If so, we will end at the
7696 next visible position. */
7697 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
7698 NULL
, DEFAULT_FACE_ID
);
7699 it
.current_x
= this_line_start_x
;
7700 it
.current_y
= this_line_y
;
7701 it
.vpos
= this_line_vpos
;
7703 /* The call to move_it_to stops in front of PT, but
7704 moves over before-strings. */
7705 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
7707 if (it
.vpos
== this_line_vpos
7708 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
7711 xassert (this_line_vpos
== it
.vpos
);
7712 xassert (this_line_y
== it
.current_y
);
7713 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
7721 /* Text changed drastically or point moved off of line. */
7722 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
7725 CHARPOS (this_line_start_pos
) = 0;
7726 consider_all_windows_p
|= buffer_shared
> 1;
7727 ++clear_face_cache_count
;
7730 /* Build desired matrices. If consider_all_windows_p is non-zero,
7731 do it for all windows on all frames. Otherwise do it for
7732 selected_window, only. */
7734 if (consider_all_windows_p
)
7736 Lisp_Object tail
, frame
;
7738 /* Clear the face cache eventually. */
7739 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
7741 clear_face_cache (0);
7742 clear_face_cache_count
= 0;
7745 /* Recompute # windows showing selected buffer. This will be
7746 incremented each time such a window is displayed. */
7749 FOR_EACH_FRAME (tail
, frame
)
7751 struct frame
*f
= XFRAME (frame
);
7752 if (FRAME_WINDOW_P (f
) || f
== sf
)
7754 /* Mark all the scroll bars to be removed; we'll redeem
7755 the ones we want when we redisplay their windows. */
7756 if (condemn_scroll_bars_hook
)
7757 (*condemn_scroll_bars_hook
) (f
);
7759 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7760 redisplay_windows (FRAME_ROOT_WINDOW (f
));
7762 /* Any scroll bars which redisplay_windows should have
7763 nuked should now go away. */
7764 if (judge_scroll_bars_hook
)
7765 (*judge_scroll_bars_hook
) (f
);
7769 else if (FRAME_VISIBLE_P (sf
)
7770 && !FRAME_OBSCURED_P (sf
))
7771 redisplay_window (selected_window
, 1);
7774 /* Compare desired and current matrices, perform output. */
7778 /* If fonts changed, display again. */
7779 if (fonts_changed_p
)
7782 /* Prevent various kinds of signals during display update.
7783 stdio is not robust about handling signals,
7784 which can cause an apparent I/O error. */
7785 if (interrupt_input
)
7789 if (consider_all_windows_p
)
7798 /* See if we have to hscroll. */
7799 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7800 if (FRAMEP (XCAR (tail
)))
7802 f
= XFRAME (XCAR (tail
));
7804 if ((FRAME_WINDOW_P (f
)
7806 && FRAME_VISIBLE_P (f
)
7807 && !FRAME_OBSCURED_P (f
)
7808 && hscroll_windows (f
->root_window
))
7815 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7817 if (!FRAMEP (XCAR (tail
)))
7820 f
= XFRAME (XCAR (tail
));
7822 if ((FRAME_WINDOW_P (f
) || f
== sf
)
7823 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7825 /* Mark all windows as to be updated. */
7826 set_window_update_flags (XWINDOW (f
->root_window
), 1);
7827 pause
|= update_frame (f
, 0, 0);
7830 mark_window_display_accurate (f
->root_window
, 1);
7831 if (frame_up_to_date_hook
!= 0)
7832 (*frame_up_to_date_hook
) (f
);
7839 if (FRAME_VISIBLE_P (sf
)
7840 && !FRAME_OBSCURED_P (sf
))
7842 if (hscroll_windows (selected_window
))
7845 XWINDOW (selected_window
)->must_be_updated_p
= 1;
7846 pause
= update_frame (sf
, 0, 0);
7851 /* We may have called echo_area_display at the top of this
7852 function. If the echo area is on another frame, that may
7853 have put text on a frame other than the selected one, so the
7854 above call to update_frame would not have caught it. Catch
7857 Lisp_Object mini_window
;
7858 struct frame
*mini_frame
;
7860 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7861 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7863 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
7865 XWINDOW (mini_window
)->must_be_updated_p
= 1;
7866 pause
|= update_frame (mini_frame
, 0, 0);
7867 if (!pause
&& hscroll_windows (mini_window
))
7873 /* If display was paused because of pending input, make sure we do a
7874 thorough update the next time. */
7877 /* Prevent the optimization at the beginning of
7878 redisplay_internal that tries a single-line update of the
7879 line containing the cursor in the selected window. */
7880 CHARPOS (this_line_start_pos
) = 0;
7882 /* Let the overlay arrow be updated the next time. */
7883 if (!NILP (last_arrow_position
))
7885 last_arrow_position
= Qt
;
7886 last_arrow_string
= Qt
;
7889 /* If we pause after scrolling, some rows in the current
7890 matrices of some windows are not valid. */
7891 if (!WINDOW_FULL_WIDTH_P (w
)
7892 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
7893 update_mode_lines
= 1;
7896 /* Now text on frame agrees with windows, so put info into the
7897 windows for partial redisplay to follow. */
7900 register struct buffer
*b
= XBUFFER (w
->buffer
);
7902 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
7903 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
7904 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
7905 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
7907 if (consider_all_windows_p
)
7908 mark_window_display_accurate (FRAME_ROOT_WINDOW (sf
), 1);
7911 XSETFASTINT (w
->last_point
, BUF_PT (b
));
7912 w
->last_cursor
= w
->cursor
;
7913 w
->last_cursor_off_p
= w
->cursor_off_p
;
7915 b
->clip_changed
= 0;
7916 b
->prevent_redisplay_optimizations_p
= 0;
7917 w
->update_mode_line
= Qnil
;
7918 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
7919 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
7921 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7924 /* Record if we are showing a region, so can make sure to
7925 update it fully at next redisplay. */
7926 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
7927 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7928 || highlight_nonselected_windows
)
7929 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
7930 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
7933 w
->window_end_valid
= w
->buffer
;
7934 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7935 last_arrow_string
= Voverlay_arrow_string
;
7936 if (frame_up_to_date_hook
!= 0)
7937 (*frame_up_to_date_hook
) (sf
);
7939 w
->current_matrix
->buffer
= b
;
7940 w
->current_matrix
->begv
= BUF_BEGV (b
);
7941 w
->current_matrix
->zv
= BUF_ZV (b
);
7944 update_mode_lines
= 0;
7945 windows_or_buffers_changed
= 0;
7948 /* Start SIGIO interrupts coming again. Having them off during the
7949 code above makes it less likely one will discard output, but not
7950 impossible, since there might be stuff in the system buffer here.
7951 But it is much hairier to try to do anything about that. */
7952 if (interrupt_input
)
7956 /* If a frame has become visible which was not before, redisplay
7957 again, so that we display it. Expose events for such a frame
7958 (which it gets when becoming visible) don't call the parts of
7959 redisplay constructing glyphs, so simply exposing a frame won't
7960 display anything in this case. So, we have to display these
7961 frames here explicitly. */
7964 Lisp_Object tail
, frame
;
7967 FOR_EACH_FRAME (tail
, frame
)
7969 int this_is_visible
= 0;
7971 if (XFRAME (frame
)->visible
)
7972 this_is_visible
= 1;
7973 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
7974 if (XFRAME (frame
)->visible
)
7975 this_is_visible
= 1;
7977 if (this_is_visible
)
7981 if (new_count
!= number_of_visible_frames
)
7982 windows_or_buffers_changed
++;
7985 /* Change frame size now if a change is pending. */
7986 do_pending_window_change (1);
7988 /* If we just did a pending size change, or have additional
7989 visible frames, redisplay again. */
7990 if (windows_or_buffers_changed
&& !pause
)
7995 unbind_to (count
, Qnil
);
7999 /* Redisplay, but leave alone any recent echo area message unless
8000 another message has been requested in its place.
8002 This is useful in situations where you need to redisplay but no
8003 user action has occurred, making it inappropriate for the message
8004 area to be cleared. See tracking_off and
8005 wait_reading_process_input for examples of these situations. */
8008 redisplay_preserve_echo_area ()
8010 if (!NILP (echo_area_buffer
[1]))
8012 /* We have a previously displayed message, but no current
8013 message. Redisplay the previous message. */
8014 display_last_displayed_message_p
= 1;
8015 redisplay_internal (1);
8016 display_last_displayed_message_p
= 0;
8019 redisplay_internal (1);
8023 /* Function registered with record_unwind_protect in
8024 redisplay_internal. Clears the flag indicating that a redisplay is
8028 unwind_redisplay (old_redisplaying_p
)
8029 Lisp_Object old_redisplaying_p
;
8031 redisplaying_p
= XFASTINT (old_redisplaying_p
);
8036 /* Mark the display of windows in the window tree rooted at WINDOW as
8037 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
8038 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
8039 the next time redisplay_internal is called. */
8042 mark_window_display_accurate (window
, accurate_p
)
8048 for (; !NILP (window
); window
= w
->next
)
8050 w
= XWINDOW (window
);
8052 if (BUFFERP (w
->buffer
))
8054 struct buffer
*b
= XBUFFER (w
->buffer
);
8056 XSETFASTINT (w
->last_modified
,
8057 accurate_p
? BUF_MODIFF (b
) : 0);
8058 XSETFASTINT (w
->last_overlay_modified
,
8059 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
8060 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
8063 #if 0 /* I don't think this is necessary because display_line does it.
8065 /* Record if we are showing a region, so can make sure to
8066 update it fully at next redisplay. */
8068 = (!NILP (Vtransient_mark_mode
)
8069 && (w
== XWINDOW (current_buffer
->last_selected_window
)
8070 || highlight_nonselected_windows
)
8071 && (!NILP (b
->mark_active
)
8072 ? Fmarker_position (b
->mark
)
8078 b
->clip_changed
= 0;
8079 b
->prevent_redisplay_optimizations_p
= 0;
8080 w
->current_matrix
->buffer
= b
;
8081 w
->current_matrix
->begv
= BUF_BEGV (b
);
8082 w
->current_matrix
->zv
= BUF_ZV (b
);
8083 w
->last_cursor
= w
->cursor
;
8084 w
->last_cursor_off_p
= w
->cursor_off_p
;
8085 if (w
== XWINDOW (selected_window
))
8086 w
->last_point
= make_number (BUF_PT (b
));
8088 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
8092 w
->window_end_valid
= w
->buffer
;
8093 w
->update_mode_line
= Qnil
;
8095 if (!NILP (w
->vchild
))
8096 mark_window_display_accurate (w
->vchild
, accurate_p
);
8097 if (!NILP (w
->hchild
))
8098 mark_window_display_accurate (w
->hchild
, accurate_p
);
8103 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8104 last_arrow_string
= Voverlay_arrow_string
;
8108 /* Force a thorough redisplay the next time by setting
8109 last_arrow_position and last_arrow_string to t, which is
8110 unequal to any useful value of Voverlay_arrow_... */
8111 last_arrow_position
= Qt
;
8112 last_arrow_string
= Qt
;
8117 /* Return value in display table DP (Lisp_Char_Table *) for character
8118 C. Since a display table doesn't have any parent, we don't have to
8119 follow parent. Do not call this function directly but use the
8120 macro DISP_CHAR_VECTOR. */
8123 disp_char_vector (dp
, c
)
8124 struct Lisp_Char_Table
*dp
;
8130 if (SINGLE_BYTE_CHAR_P (c
))
8131 return (dp
->contents
[c
]);
8133 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
8136 else if (code
[2] < 32)
8139 /* Here, the possible range of code[0] (== charset ID) is
8140 128..max_charset. Since the top level char table contains data
8141 for multibyte characters after 256th element, we must increment
8142 code[0] by 128 to get a correct index. */
8144 code
[3] = -1; /* anchor */
8146 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
8148 val
= dp
->contents
[code
[i
]];
8149 if (!SUB_CHAR_TABLE_P (val
))
8150 return (NILP (val
) ? dp
->defalt
: val
);
8153 /* Here, val is a sub char table. We return the default value of
8155 return (dp
->defalt
);
8160 /***********************************************************************
8162 ***********************************************************************/
8164 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
8167 redisplay_windows (window
)
8170 while (!NILP (window
))
8172 struct window
*w
= XWINDOW (window
);
8174 if (!NILP (w
->hchild
))
8175 redisplay_windows (w
->hchild
);
8176 else if (!NILP (w
->vchild
))
8177 redisplay_windows (w
->vchild
);
8179 redisplay_window (window
, 0);
8186 /* Set cursor position of W. PT is assumed to be displayed in ROW.
8187 DELTA is the number of bytes by which positions recorded in ROW
8188 differ from current buffer positions. */
8191 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
8193 struct glyph_row
*row
;
8194 struct glyph_matrix
*matrix
;
8195 int delta
, delta_bytes
, dy
, dvpos
;
8197 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
8198 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
8200 int pt_old
= PT
- delta
;
8202 /* Skip over glyphs not having an object at the start of the row.
8203 These are special glyphs like truncation marks on terminal
8205 if (row
->displays_text_p
)
8207 && INTEGERP (glyph
->object
)
8208 && glyph
->charpos
< 0)
8210 x
+= glyph
->pixel_width
;
8215 && !INTEGERP (glyph
->object
)
8216 && (!BUFFERP (glyph
->object
)
8217 || glyph
->charpos
< pt_old
))
8219 x
+= glyph
->pixel_width
;
8223 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
8225 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
8226 w
->cursor
.y
= row
->y
+ dy
;
8228 if (w
== XWINDOW (selected_window
))
8230 if (!row
->continued_p
8231 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
8234 this_line_buffer
= XBUFFER (w
->buffer
);
8236 CHARPOS (this_line_start_pos
)
8237 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
8238 BYTEPOS (this_line_start_pos
)
8239 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
8241 CHARPOS (this_line_end_pos
)
8242 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
8243 BYTEPOS (this_line_end_pos
)
8244 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
8246 this_line_y
= w
->cursor
.y
;
8247 this_line_pixel_height
= row
->height
;
8248 this_line_vpos
= w
->cursor
.vpos
;
8249 this_line_start_x
= row
->x
;
8252 CHARPOS (this_line_start_pos
) = 0;
8257 /* Run window scroll functions, if any, for WINDOW with new window
8258 start STARTP. Sets the window start of WINDOW to that position.
8260 We assume that the window's buffer is really current. */
8262 static INLINE
struct text_pos
8263 run_window_scroll_functions (window
, startp
)
8265 struct text_pos startp
;
8267 struct window
*w
= XWINDOW (window
);
8268 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
8270 if (current_buffer
!= XBUFFER (w
->buffer
))
8273 if (!NILP (Vwindow_scroll_functions
))
8275 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
8276 make_number (CHARPOS (startp
)));
8277 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8278 /* In case the hook functions switch buffers. */
8279 if (current_buffer
!= XBUFFER (w
->buffer
))
8280 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8287 /* Modify the desired matrix of window W and W->vscroll so that the
8288 line containing the cursor is fully visible. */
8291 make_cursor_line_fully_visible (w
)
8294 struct glyph_matrix
*matrix
;
8295 struct glyph_row
*row
;
8296 int header_line_height
;
8298 /* It's not always possible to find the cursor, e.g, when a window
8299 is full of overlay strings. Don't do anything in that case. */
8300 if (w
->cursor
.vpos
< 0)
8303 matrix
= w
->desired_matrix
;
8304 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
8306 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
)
8307 /* The row may be partially visible at the top because we
8308 already have chosen a vscroll to align the bottom of the
8309 row with the bottom of the window. This happens for rows
8310 taller than the window. */
8311 && row
->y
+ row
->height
< window_box_height (w
))
8313 int dy
= row
->height
- row
->visible_height
;
8316 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8318 else if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w
, row
)
8319 /* The row may be partially visible at the bottom because
8320 we chose a vscroll to align the row's top with the
8321 window's top. This happens for rows taller than the
8323 && row
->y
> WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
))
8325 int dy
= - (row
->height
- row
->visible_height
);
8328 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8331 /* When we change the cursor y-position of the selected window,
8332 change this_line_y as well so that the display optimization for
8333 the cursor line of the selected window in redisplay_internal uses
8334 the correct y-position. */
8335 if (w
== XWINDOW (selected_window
))
8336 this_line_y
= w
->cursor
.y
;
8340 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
8341 non-zero means only WINDOW is redisplayed in redisplay_internal.
8342 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
8343 in redisplay_window to bring a partially visible line into view in
8344 the case that only the cursor has moved.
8348 1 if scrolling succeeded
8350 0 if scrolling didn't find point.
8352 -1 if new fonts have been loaded so that we must interrupt
8353 redisplay, adjust glyph matrices, and try again. */
8356 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
8357 scroll_step
, temp_scroll_step
)
8359 int just_this_one_p
;
8360 int scroll_conservatively
, scroll_step
;
8361 int temp_scroll_step
;
8363 struct window
*w
= XWINDOW (window
);
8364 struct frame
*f
= XFRAME (w
->frame
);
8365 struct text_pos scroll_margin_pos
;
8366 struct text_pos pos
;
8367 struct text_pos startp
;
8369 Lisp_Object window_end
;
8370 int this_scroll_margin
;
8373 int line_height
, rc
;
8374 int amount_to_scroll
= 0;
8375 Lisp_Object aggressive
;
8379 debug_method_add (w
, "try_scrolling");
8382 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8384 /* Compute scroll margin height in pixels. We scroll when point is
8385 within this distance from the top or bottom of the window. */
8386 if (scroll_margin
> 0)
8388 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
8389 this_scroll_margin
*= CANON_Y_UNIT (f
);
8392 this_scroll_margin
= 0;
8394 /* Compute how much we should try to scroll maximally to bring point
8397 scroll_max
= scroll_step
;
8398 else if (scroll_conservatively
)
8399 scroll_max
= scroll_conservatively
;
8400 else if (temp_scroll_step
)
8401 scroll_max
= temp_scroll_step
;
8402 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
8403 || NUMBERP (current_buffer
->scroll_up_aggressively
))
8404 /* We're trying to scroll because of aggressive scrolling
8405 but no scroll_step is set. Choose an arbitrary one. Maybe
8406 there should be a variable for this. */
8410 scroll_max
*= CANON_Y_UNIT (f
);
8412 /* Decide whether we have to scroll down. Start at the window end
8413 and move this_scroll_margin up to find the position of the scroll
8415 window_end
= Fwindow_end (window
, Qt
);
8416 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
8417 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
8418 if (this_scroll_margin
)
8420 start_display (&it
, w
, scroll_margin_pos
);
8421 move_it_vertically (&it
, - this_scroll_margin
);
8422 scroll_margin_pos
= it
.current
.pos
;
8425 if (PT
>= CHARPOS (scroll_margin_pos
))
8429 /* Point is in the scroll margin at the bottom of the window, or
8430 below. Compute a new window start that makes point visible. */
8432 /* Compute the distance from the scroll margin to PT.
8433 Give up if the distance is greater than scroll_max. */
8434 start_display (&it
, w
, scroll_margin_pos
);
8436 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8437 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8438 line_height
= (it
.max_ascent
+ it
.max_descent
8439 ? it
.max_ascent
+ it
.max_descent
8441 dy
= it
.current_y
+ line_height
- y0
;
8442 if (dy
> scroll_max
)
8445 /* Move the window start down. If scrolling conservatively,
8446 move it just enough down to make point visible. If
8447 scroll_step is set, move it down by scroll_step. */
8448 start_display (&it
, w
, startp
);
8450 if (scroll_conservatively
)
8451 amount_to_scroll
= dy
;
8452 else if (scroll_step
|| temp_scroll_step
)
8453 amount_to_scroll
= scroll_max
;
8456 aggressive
= current_buffer
->scroll_down_aggressively
;
8457 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8458 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8459 if (NUMBERP (aggressive
))
8460 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8463 if (amount_to_scroll
<= 0)
8466 move_it_vertically (&it
, amount_to_scroll
);
8467 startp
= it
.current
.pos
;
8471 /* See if point is inside the scroll margin at the top of the
8473 scroll_margin_pos
= startp
;
8474 if (this_scroll_margin
)
8476 start_display (&it
, w
, startp
);
8477 move_it_vertically (&it
, this_scroll_margin
);
8478 scroll_margin_pos
= it
.current
.pos
;
8481 if (PT
< CHARPOS (scroll_margin_pos
))
8483 /* Point is in the scroll margin at the top of the window or
8484 above what is displayed in the window. */
8487 /* Compute the vertical distance from PT to the scroll
8488 margin position. Give up if distance is greater than
8490 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
8491 start_display (&it
, w
, pos
);
8493 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
8494 it
.last_visible_y
, -1,
8495 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8496 dy
= it
.current_y
- y0
;
8497 if (dy
> scroll_max
)
8500 /* Compute new window start. */
8501 start_display (&it
, w
, startp
);
8503 if (scroll_conservatively
)
8504 amount_to_scroll
= dy
;
8505 else if (scroll_step
|| temp_scroll_step
)
8506 amount_to_scroll
= scroll_max
;
8509 aggressive
= current_buffer
->scroll_up_aggressively
;
8510 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8511 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8512 if (NUMBERP (aggressive
))
8513 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8516 if (amount_to_scroll
<= 0)
8519 move_it_vertically (&it
, - amount_to_scroll
);
8520 startp
= it
.current
.pos
;
8524 /* Run window scroll functions. */
8525 startp
= run_window_scroll_functions (window
, startp
);
8527 /* Display the window. Give up if new fonts are loaded, or if point
8529 if (!try_window (window
, startp
))
8531 else if (w
->cursor
.vpos
< 0)
8533 clear_glyph_matrix (w
->desired_matrix
);
8538 /* Maybe forget recorded base line for line number display. */
8539 if (!just_this_one_p
8540 || current_buffer
->clip_changed
8541 || BEG_UNCHANGED
< CHARPOS (startp
))
8542 w
->base_line_number
= Qnil
;
8544 /* If cursor ends up on a partially visible line, shift display
8545 lines up or down. */
8546 make_cursor_line_fully_visible (w
);
8554 /* Compute a suitable window start for window W if display of W starts
8555 on a continuation line. Value is non-zero if a new window start
8558 The new window start will be computed, based on W's width, starting
8559 from the start of the continued line. It is the start of the
8560 screen line with the minimum distance from the old start W->start. */
8563 compute_window_start_on_continuation_line (w
)
8566 struct text_pos pos
, start_pos
;
8567 int window_start_changed_p
= 0;
8569 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
8571 /* If window start is on a continuation line... Window start may be
8572 < BEGV in case there's invisible text at the start of the
8573 buffer (M-x rmail, for example). */
8574 if (CHARPOS (start_pos
) > BEGV
8575 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
8578 struct glyph_row
*row
;
8580 /* Handle the case that the window start is out of range. */
8581 if (CHARPOS (start_pos
) < BEGV
)
8582 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
8583 else if (CHARPOS (start_pos
) > ZV
)
8584 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
8586 /* Find the start of the continued line. This should be fast
8587 because scan_buffer is fast (newline cache). */
8588 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
8589 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
8590 row
, DEFAULT_FACE_ID
);
8591 reseat_at_previous_visible_line_start (&it
);
8593 /* If the line start is "too far" away from the window start,
8594 say it takes too much time to compute a new window start. */
8595 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
8596 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
8598 int min_distance
, distance
;
8600 /* Move forward by display lines to find the new window
8601 start. If window width was enlarged, the new start can
8602 be expected to be > the old start. If window width was
8603 decreased, the new window start will be < the old start.
8604 So, we're looking for the display line start with the
8605 minimum distance from the old window start. */
8606 pos
= it
.current
.pos
;
8607 min_distance
= INFINITY
;
8608 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
8609 distance
< min_distance
)
8611 min_distance
= distance
;
8612 pos
= it
.current
.pos
;
8613 move_it_by_lines (&it
, 1, 0);
8616 /* Set the window start there. */
8617 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
8618 window_start_changed_p
= 1;
8622 return window_start_changed_p
;
8626 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
8627 selected_window is redisplayed. */
8630 redisplay_window (window
, just_this_one_p
)
8632 int just_this_one_p
;
8634 struct window
*w
= XWINDOW (window
);
8635 struct frame
*f
= XFRAME (w
->frame
);
8636 struct buffer
*buffer
= XBUFFER (w
->buffer
);
8637 struct buffer
*old
= current_buffer
;
8638 struct text_pos lpoint
, opoint
, startp
;
8639 int update_mode_line
;
8642 /* Record it now because it's overwritten. */
8643 int current_matrix_up_to_date_p
= 0;
8644 int temp_scroll_step
= 0;
8645 int count
= specpdl_ptr
- specpdl
;
8647 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8650 /* W must be a leaf window here. */
8651 xassert (!NILP (w
->buffer
));
8653 *w
->desired_matrix
->method
= 0;
8656 specbind (Qinhibit_point_motion_hooks
, Qt
);
8658 reconsider_clip_changes (w
, buffer
);
8660 /* Has the mode line to be updated? */
8661 update_mode_line
= (!NILP (w
->update_mode_line
)
8662 || update_mode_lines
8663 || buffer
->clip_changed
);
8665 if (MINI_WINDOW_P (w
))
8667 if (w
== XWINDOW (echo_area_window
)
8668 && !NILP (echo_area_buffer
[0]))
8670 if (update_mode_line
)
8671 /* We may have to update a tty frame's menu bar or a
8672 tool-bar. Example `M-x C-h C-h C-g'. */
8673 goto finish_menu_bars
;
8675 /* We've already displayed the echo area glyphs in this window. */
8676 goto finish_scroll_bars
;
8678 else if (w
!= XWINDOW (minibuf_window
))
8680 /* W is a mini-buffer window, but it's not the currently
8681 active one, so clear it. */
8682 int yb
= window_text_bottom_y (w
);
8683 struct glyph_row
*row
;
8686 for (y
= 0, row
= w
->desired_matrix
->rows
;
8688 y
+= row
->height
, ++row
)
8689 blank_row (w
, row
, y
);
8690 goto finish_scroll_bars
;
8694 /* Otherwise set up data on this window; select its buffer and point
8696 /* Really select the buffer, for the sake of buffer-local
8698 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8699 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
8701 current_matrix_up_to_date_p
8702 = (!NILP (w
->window_end_valid
)
8703 && !current_buffer
->clip_changed
8704 && XFASTINT (w
->last_modified
) >= MODIFF
8705 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
8707 /* When windows_or_buffers_changed is non-zero, we can't rely on
8708 the window end being valid, so set it to nil there. */
8709 if (windows_or_buffers_changed
)
8711 /* If window starts on a continuation line, maybe adjust the
8712 window start in case the window's width changed. */
8713 if (XMARKER (w
->start
)->buffer
== current_buffer
)
8714 compute_window_start_on_continuation_line (w
);
8716 w
->window_end_valid
= Qnil
;
8719 /* Some sanity checks. */
8720 CHECK_WINDOW_END (w
);
8721 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
8723 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
8726 /* If %c is in mode line, update it if needed. */
8727 if (!NILP (w
->column_number_displayed
)
8728 /* This alternative quickly identifies a common case
8729 where no change is needed. */
8730 && !(PT
== XFASTINT (w
->last_point
)
8731 && XFASTINT (w
->last_modified
) >= MODIFF
8732 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8733 && XFASTINT (w
->column_number_displayed
) != current_column ())
8734 update_mode_line
= 1;
8736 /* Count number of windows showing the selected buffer. An indirect
8737 buffer counts as its base buffer. */
8738 if (!just_this_one_p
)
8740 struct buffer
*current_base
, *window_base
;
8741 current_base
= current_buffer
;
8742 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
8743 if (current_base
->base_buffer
)
8744 current_base
= current_base
->base_buffer
;
8745 if (window_base
->base_buffer
)
8746 window_base
= window_base
->base_buffer
;
8747 if (current_base
== window_base
)
8751 /* Point refers normally to the selected window. For any other
8752 window, set up appropriate value. */
8753 if (!EQ (window
, selected_window
))
8755 int new_pt
= XMARKER (w
->pointm
)->charpos
;
8756 int new_pt_byte
= marker_byte_position (w
->pointm
);
8760 new_pt_byte
= BEGV_BYTE
;
8761 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
8763 else if (new_pt
> (ZV
- 1))
8766 new_pt_byte
= ZV_BYTE
;
8767 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
8770 /* We don't use SET_PT so that the point-motion hooks don't run. */
8771 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
8774 /* If any of the character widths specified in the display table
8775 have changed, invalidate the width run cache. It's true that
8776 this may be a bit late to catch such changes, but the rest of
8777 redisplay goes (non-fatally) haywire when the display table is
8778 changed, so why should we worry about doing any better? */
8779 if (current_buffer
->width_run_cache
)
8781 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
8783 if (! disptab_matches_widthtab (disptab
,
8784 XVECTOR (current_buffer
->width_table
)))
8786 invalidate_region_cache (current_buffer
,
8787 current_buffer
->width_run_cache
,
8789 recompute_width_table (current_buffer
, disptab
);
8793 /* If window-start is screwed up, choose a new one. */
8794 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
8797 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8799 /* If someone specified a new starting point but did not insist,
8800 check whether it can be used. */
8801 if (!NILP (w
->optional_new_start
)
8802 && CHARPOS (startp
) >= BEGV
8803 && CHARPOS (startp
) <= ZV
)
8805 w
->optional_new_start
= Qnil
;
8806 /* This takes a mini-buffer prompt into account. */
8807 start_display (&it
, w
, startp
);
8808 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8809 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8810 if (IT_CHARPOS (it
) == PT
)
8811 w
->force_start
= Qt
;
8814 /* Handle case where place to start displaying has been specified,
8815 unless the specified location is outside the accessible range. */
8816 if (!NILP (w
->force_start
)
8817 || w
->frozen_window_start_p
)
8819 w
->force_start
= Qnil
;
8821 w
->window_end_valid
= Qnil
;
8823 /* Forget any recorded base line for line number display. */
8824 if (!current_matrix_up_to_date_p
8825 || current_buffer
->clip_changed
)
8826 w
->base_line_number
= Qnil
;
8828 /* Redisplay the mode line. Select the buffer properly for that.
8829 Also, run the hook window-scroll-functions
8830 because we have scrolled. */
8831 /* Note, we do this after clearing force_start because
8832 if there's an error, it is better to forget about force_start
8833 than to get into an infinite loop calling the hook functions
8834 and having them get more errors. */
8835 if (!update_mode_line
8836 || ! NILP (Vwindow_scroll_functions
))
8838 update_mode_line
= 1;
8839 w
->update_mode_line
= Qt
;
8840 startp
= run_window_scroll_functions (window
, startp
);
8843 XSETFASTINT (w
->last_modified
, 0);
8844 XSETFASTINT (w
->last_overlay_modified
, 0);
8845 if (CHARPOS (startp
) < BEGV
)
8846 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
8847 else if (CHARPOS (startp
) > ZV
)
8848 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
8850 /* Redisplay, then check if cursor has been set during the
8851 redisplay. Give up if new fonts were loaded. */
8852 if (!try_window (window
, startp
))
8854 w
->force_start
= Qt
;
8855 clear_glyph_matrix (w
->desired_matrix
);
8856 goto restore_buffers
;
8859 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
8861 /* If point does not appear, or on a line that is not fully
8862 visible, move point so it does appear. The desired
8863 matrix has been built above, so we can use it. */
8864 int height
= window_box_height (w
) / 2;
8865 struct glyph_row
*row
= MATRIX_ROW (w
->desired_matrix
, 0);
8867 while (row
->y
< height
)
8870 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
8871 MATRIX_ROW_START_BYTEPOS (row
));
8873 if (w
!= XWINDOW (selected_window
))
8874 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
8875 else if (current_buffer
== old
)
8876 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8878 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
8880 /* If we are highlighting the region, then we just changed
8881 the region, so redisplay to show it. */
8882 if (!NILP (Vtransient_mark_mode
)
8883 && !NILP (current_buffer
->mark_active
))
8885 clear_glyph_matrix (w
->desired_matrix
);
8886 if (!try_window (window
, startp
))
8887 goto restore_buffers
;
8891 make_cursor_line_fully_visible (w
);
8893 debug_method_add (w
, "forced window start");
8898 /* Handle case where text has not changed, only point, and it has
8899 not moved off the frame. */
8900 if (current_matrix_up_to_date_p
8901 /* Point may be in this window. */
8902 && PT
>= CHARPOS (startp
)
8903 /* If we don't check this, we are called to move the cursor in a
8904 horizontally split window with a current matrix that doesn't
8906 && !windows_or_buffers_changed
8907 /* Selective display hasn't changed. */
8908 && !current_buffer
->clip_changed
8909 /* If force-mode-line-update was called, really redisplay;
8910 that's how redisplay is forced after e.g. changing
8911 buffer-invisibility-spec. */
8912 && NILP (w
->update_mode_line
)
8913 /* Can't use this case if highlighting a region. When a
8914 region exists, cursor movement has to do more than just
8916 && !(!NILP (Vtransient_mark_mode
)
8917 && !NILP (current_buffer
->mark_active
))
8918 && NILP (w
->region_showing
)
8919 && NILP (Vshow_trailing_whitespace
)
8920 /* Right after splitting windows, last_point may be nil. */
8921 && INTEGERP (w
->last_point
)
8922 /* This code is not used for mini-buffer for the sake of the case
8923 of redisplaying to replace an echo area message; since in
8924 that case the mini-buffer contents per se are usually
8925 unchanged. This code is of no real use in the mini-buffer
8926 since the handling of this_line_start_pos, etc., in redisplay
8927 handles the same cases. */
8928 && !EQ (window
, minibuf_window
)
8929 /* When splitting windows or for new windows, it happens that
8930 redisplay is called with a nil window_end_vpos or one being
8931 larger than the window. This should really be fixed in
8932 window.c. I don't have this on my list, now, so we do
8933 approximately the same as the old redisplay code. --gerd. */
8934 && INTEGERP (w
->window_end_vpos
)
8935 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
8936 && (FRAME_WINDOW_P (f
)
8937 || !MARKERP (Voverlay_arrow_position
)
8938 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
8940 int this_scroll_margin
;
8941 struct glyph_row
*row
;
8945 debug_method_add (w
, "cursor movement");
8948 /* Scroll if point within this distance from the top or bottom
8949 of the window. This is a pixel value. */
8950 this_scroll_margin
= max (0, scroll_margin
);
8951 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
8952 this_scroll_margin
*= CANON_Y_UNIT (f
);
8954 /* Start with the row the cursor was displayed during the last
8955 not paused redisplay. Give up if that row is not valid. */
8956 if (w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
8958 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
8959 if (row
->mode_line_p
)
8961 if (!row
->enabled_p
)
8965 if (PT
> XFASTINT (w
->last_point
))
8967 /* Point has moved forward. */
8968 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
8970 while (MATRIX_ROW_END_CHARPOS (row
) < PT
8971 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
8973 xassert (row
->enabled_p
);
8977 /* The end position of a row equals the start position of
8978 the next row. If PT is there, we would rather display it
8979 in the next line. Exceptions are when the row ends in
8980 the middle of a character, or ends in ZV. */
8981 if (MATRIX_ROW_BOTTOM_Y (row
) < last_y
8982 && MATRIX_ROW_END_CHARPOS (row
) == PT
8983 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
8984 && !row
->ends_at_zv_p
)
8986 xassert (row
->enabled_p
);
8990 /* If within the scroll margin, scroll. Note that
8991 MATRIX_ROW_BOTTOM_Y gives the pixel position at which the
8992 next line would be drawn, and that this_scroll_margin can
8994 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
8995 || PT
> MATRIX_ROW_END_CHARPOS (row
)
8996 /* Line is completely visible last line in window and PT
8997 is to be set in the next line. */
8998 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
8999 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9000 && !row
->ends_at_zv_p
9001 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9004 else if (PT
< XFASTINT (w
->last_point
))
9006 /* Cursor has to be moved backward. Note that PT >=
9007 CHARPOS (startp) because of the outer if-statement. */
9008 while (!row
->mode_line_p
9009 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9010 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9011 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9012 && (row
->y
> this_scroll_margin
9013 || CHARPOS (startp
) == BEGV
))
9015 xassert (row
->enabled_p
);
9019 /* Consider the following case: Window starts at BEGV, there
9020 is invisible, intangible text at BEGV, so that display
9021 starts at some point START > BEGV. It can happen that
9022 we are called with PT somewhere between BEGV and START.
9023 Try to handle that case. */
9024 if (row
< w
->current_matrix
->rows
9025 || row
->mode_line_p
)
9027 row
= w
->current_matrix
->rows
;
9028 if (row
->mode_line_p
)
9032 /* Due to newlines in overlay strings, we may have to skip
9033 forward over overlay strings. */
9034 while (MATRIX_ROW_END_CHARPOS (row
) == PT
9035 && MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P (row
)
9036 && !row
->ends_at_zv_p
)
9039 /* If within the scroll margin, scroll. */
9040 if (row
->y
< this_scroll_margin
9041 && CHARPOS (startp
) != BEGV
)
9045 /* if PT is not in the glyph row, give up. */
9046 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9047 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9050 /* If we end up in a partially visible line, let's make it fully
9051 visible. This can be done most easily by using the existing
9053 if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9055 temp_scroll_step
= 1;
9061 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9065 /* If current starting point was originally the beginning of a line
9066 but no longer is, find a new starting point. */
9067 else if (!NILP (w
->start_at_line_beg
)
9068 && !(CHARPOS (startp
) <= BEGV
9069 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
9072 debug_method_add (w
, "recenter 1");
9077 /* Try scrolling with try_window_id. */
9078 else if (/* Windows and buffers haven't changed. */
9079 !windows_or_buffers_changed
9080 /* Window must be either use window-based redisplay or
9082 && (FRAME_WINDOW_P (f
)
9083 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
9084 && !MINI_WINDOW_P (w
)
9085 /* Point is not known NOT to appear in window. */
9086 && PT
>= CHARPOS (startp
)
9087 && XFASTINT (w
->last_modified
)
9088 /* Window is not hscrolled. */
9089 && XFASTINT (w
->hscroll
) == 0
9090 /* Selective display has not changed. */
9091 && !current_buffer
->clip_changed
9092 /* Current matrix is up to date. */
9093 && !NILP (w
->window_end_valid
)
9094 /* Can't use this case if highlighting a region because
9095 a cursor movement will do more than just set the cursor. */
9096 && !(!NILP (Vtransient_mark_mode
)
9097 && !NILP (current_buffer
->mark_active
))
9098 && NILP (w
->region_showing
)
9099 && NILP (Vshow_trailing_whitespace
)
9100 /* Overlay arrow position and string not changed. */
9101 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
9102 && EQ (last_arrow_string
, Voverlay_arrow_string
)
9103 /* Value is > 0 if update has been done, it is -1 if we
9104 know that the same window start will not work. It is 0
9105 if unsuccessful for some other reason. */
9106 && (tem
= try_window_id (w
)) != 0)
9109 debug_method_add (w
, "try_window_id %d", tem
);
9112 if (fonts_changed_p
)
9113 goto restore_buffers
;
9117 /* Otherwise try_window_id has returned -1 which means that we
9118 don't want the alternative below this comment to execute. */
9120 else if (CHARPOS (startp
) >= BEGV
9121 && CHARPOS (startp
) <= ZV
9122 && PT
>= CHARPOS (startp
)
9123 && (CHARPOS (startp
) < ZV
9124 /* Avoid starting at end of buffer. */
9125 || CHARPOS (startp
) == BEGV
9126 || (XFASTINT (w
->last_modified
) >= MODIFF
9127 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
9130 debug_method_add (w
, "same window start");
9133 /* Try to redisplay starting at same place as before.
9134 If point has not moved off frame, accept the results. */
9135 if (!current_matrix_up_to_date_p
9136 /* Don't use try_window_reusing_current_matrix in this case
9137 because a window scroll function can have changed the
9139 || !NILP (Vwindow_scroll_functions
)
9140 || MINI_WINDOW_P (w
)
9141 || !try_window_reusing_current_matrix (w
))
9143 IF_DEBUG (debug_method_add (w
, "1"));
9144 try_window (window
, startp
);
9147 if (fonts_changed_p
)
9148 goto restore_buffers
;
9150 if (w
->cursor
.vpos
>= 0)
9152 if (!just_this_one_p
9153 || current_buffer
->clip_changed
9154 || BEG_UNCHANGED
< CHARPOS (startp
))
9155 /* Forget any recorded base line for line number display. */
9156 w
->base_line_number
= Qnil
;
9158 make_cursor_line_fully_visible (w
);
9162 clear_glyph_matrix (w
->desired_matrix
);
9167 XSETFASTINT (w
->last_modified
, 0);
9168 XSETFASTINT (w
->last_overlay_modified
, 0);
9170 /* Redisplay the mode line. Select the buffer properly for that. */
9171 if (!update_mode_line
)
9173 update_mode_line
= 1;
9174 w
->update_mode_line
= Qt
;
9177 /* Try to scroll by specified few lines. */
9178 if ((scroll_conservatively
9181 || NUMBERP (current_buffer
->scroll_up_aggressively
)
9182 || NUMBERP (current_buffer
->scroll_down_aggressively
))
9183 && !current_buffer
->clip_changed
9184 && CHARPOS (startp
) >= BEGV
9185 && CHARPOS (startp
) <= ZV
)
9187 /* The function returns -1 if new fonts were loaded, 1 if
9188 successful, 0 if not successful. */
9189 int rc
= try_scrolling (window
, just_this_one_p
,
9190 scroll_conservatively
,
9196 goto restore_buffers
;
9199 /* Finally, just choose place to start which centers point */
9204 debug_method_add (w
, "recenter");
9207 /* w->vscroll = 0; */
9209 /* Forget any previously recorded base line for line number display. */
9210 if (!current_matrix_up_to_date_p
9211 || current_buffer
->clip_changed
)
9212 w
->base_line_number
= Qnil
;
9214 /* Move backward half the height of the window. */
9215 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9216 it
.current_y
= it
.last_visible_y
;
9217 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
9218 xassert (IT_CHARPOS (it
) >= BEGV
);
9220 /* The function move_it_vertically_backward may move over more
9221 than the specified y-distance. If it->w is small, e.g. a
9222 mini-buffer window, we may end up in front of the window's
9223 display area. Start displaying at the start of the line
9224 containing PT in this case. */
9225 if (it
.current_y
<= 0)
9227 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9228 move_it_vertically (&it
, 0);
9229 xassert (IT_CHARPOS (it
) <= PT
);
9233 it
.current_x
= it
.hpos
= 0;
9235 /* Set startp here explicitly in case that helps avoid an infinite loop
9236 in case the window-scroll-functions functions get errors. */
9237 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
9239 /* Run scroll hooks. */
9240 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
9242 /* Redisplay the window. */
9243 if (!current_matrix_up_to_date_p
9244 || windows_or_buffers_changed
9245 /* Don't use try_window_reusing_current_matrix in this case
9246 because it can have changed the buffer. */
9247 || !NILP (Vwindow_scroll_functions
)
9249 || MINI_WINDOW_P (w
)
9250 || !try_window_reusing_current_matrix (w
))
9251 try_window (window
, startp
);
9253 /* If new fonts have been loaded (due to fontsets), give up. We
9254 have to start a new redisplay since we need to re-adjust glyph
9256 if (fonts_changed_p
)
9257 goto restore_buffers
;
9259 /* If cursor did not appear assume that the middle of the window is
9260 in the first line of the window. Do it again with the next line.
9261 (Imagine a window of height 100, displaying two lines of height
9262 60. Moving back 50 from it->last_visible_y will end in the first
9264 if (w
->cursor
.vpos
< 0)
9266 if (!NILP (w
->window_end_valid
)
9267 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
9269 clear_glyph_matrix (w
->desired_matrix
);
9270 move_it_by_lines (&it
, 1, 0);
9271 try_window (window
, it
.current
.pos
);
9273 else if (PT
< IT_CHARPOS (it
))
9275 clear_glyph_matrix (w
->desired_matrix
);
9276 move_it_by_lines (&it
, -1, 0);
9277 try_window (window
, it
.current
.pos
);
9281 /* Not much we can do about it. */
9285 /* Consider the following case: Window starts at BEGV, there is
9286 invisible, intangible text at BEGV, so that display starts at
9287 some point START > BEGV. It can happen that we are called with
9288 PT somewhere between BEGV and START. Try to handle that case. */
9289 if (w
->cursor
.vpos
< 0)
9291 struct glyph_row
*row
= w
->current_matrix
->rows
;
9292 if (row
->mode_line_p
)
9294 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9297 make_cursor_line_fully_visible (w
);
9301 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9302 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
9303 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
9306 /* Display the mode line, if we must. */
9307 if ((update_mode_line
9308 /* If window not full width, must redo its mode line
9309 if (a) the window to its side is being redone and
9310 (b) we do a frame-based redisplay. This is a consequence
9311 of how inverted lines are drawn in frame-based redisplay. */
9312 || (!just_this_one_p
9313 && !FRAME_WINDOW_P (f
)
9314 && !WINDOW_FULL_WIDTH_P (w
))
9315 /* Line number to display. */
9316 || INTEGERP (w
->base_line_pos
)
9317 /* Column number is displayed and different from the one displayed. */
9318 || (!NILP (w
->column_number_displayed
)
9319 && XFASTINT (w
->column_number_displayed
) != current_column ()))
9320 /* This means that the window has a mode line. */
9321 && (WINDOW_WANTS_MODELINE_P (w
)
9322 || WINDOW_WANTS_HEADER_LINE_P (w
)))
9324 Lisp_Object old_selected_frame
;
9326 old_selected_frame
= selected_frame
;
9328 XSETFRAME (selected_frame
, f
);
9329 display_mode_lines (w
);
9330 selected_frame
= old_selected_frame
;
9332 /* If mode line height has changed, arrange for a thorough
9333 immediate redisplay using the correct mode line height. */
9334 if (WINDOW_WANTS_MODELINE_P (w
)
9335 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
9337 fonts_changed_p
= 1;
9338 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
9339 = DESIRED_MODE_LINE_HEIGHT (w
);
9342 /* If top line height has changed, arrange for a thorough
9343 immediate redisplay using the correct mode line height. */
9344 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9345 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
9347 fonts_changed_p
= 1;
9348 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
9349 = DESIRED_HEADER_LINE_HEIGHT (w
);
9352 if (fonts_changed_p
)
9353 goto restore_buffers
;
9356 if (!line_number_displayed
9357 && !BUFFERP (w
->base_line_pos
))
9359 w
->base_line_pos
= Qnil
;
9360 w
->base_line_number
= Qnil
;
9365 /* When we reach a frame's selected window, redo the frame's menu bar. */
9366 if (update_mode_line
9367 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
9369 int redisplay_menu_p
= 0;
9371 if (FRAME_WINDOW_P (f
))
9373 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
9374 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
9376 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9380 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9382 if (redisplay_menu_p
)
9383 display_menu_bar (w
);
9385 #ifdef HAVE_WINDOW_SYSTEM
9386 if (WINDOWP (f
->tool_bar_window
)
9387 && (FRAME_TOOL_BAR_LINES (f
) > 0
9388 || auto_resize_tool_bars_p
))
9389 redisplay_tool_bar (f
);
9395 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9397 int start
, end
, whole
;
9399 /* Calculate the start and end positions for the current window.
9400 At some point, it would be nice to choose between scrollbars
9401 which reflect the whole buffer size, with special markers
9402 indicating narrowing, and scrollbars which reflect only the
9405 Note that mini-buffers sometimes aren't displaying any text. */
9406 if (!MINI_WINDOW_P (w
)
9407 || (w
== XWINDOW (minibuf_window
)
9408 && NILP (echo_area_buffer
[0])))
9411 start
= marker_position (w
->start
) - BEGV
;
9412 /* I don't think this is guaranteed to be right. For the
9413 moment, we'll pretend it is. */
9414 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
9418 if (whole
< (end
- start
))
9419 whole
= end
- start
;
9422 start
= end
= whole
= 0;
9424 /* Indicate what this scroll bar ought to be displaying now. */
9425 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
9427 /* Note that we actually used the scroll bar attached to this
9428 window, so it shouldn't be deleted at the end of redisplay. */
9429 (*redeem_scroll_bar_hook
) (w
);
9434 /* Restore current_buffer and value of point in it. */
9435 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
9436 set_buffer_internal_1 (old
);
9437 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
9439 unbind_to (count
, Qnil
);
9443 /* Build the complete desired matrix of WINDOW with a window start
9444 buffer position POS. Value is non-zero if successful. It is zero
9445 if fonts were loaded during redisplay which makes re-adjusting
9446 glyph matrices necessary. */
9449 try_window (window
, pos
)
9451 struct text_pos pos
;
9453 struct window
*w
= XWINDOW (window
);
9455 struct glyph_row
*last_text_row
= NULL
;
9457 /* Make POS the new window start. */
9458 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
9460 /* Mark cursor position as unknown. No overlay arrow seen. */
9461 w
->cursor
.vpos
= -1;
9462 overlay_arrow_seen
= 0;
9464 /* Initialize iterator and info to start at POS. */
9465 start_display (&it
, w
, pos
);
9467 /* Display all lines of W. */
9468 while (it
.current_y
< it
.last_visible_y
)
9470 if (display_line (&it
))
9471 last_text_row
= it
.glyph_row
- 1;
9472 if (fonts_changed_p
)
9476 /* If bottom moved off end of frame, change mode line percentage. */
9477 if (XFASTINT (w
->window_end_pos
) <= 0
9478 && Z
!= IT_CHARPOS (it
))
9479 w
->update_mode_line
= Qt
;
9481 /* Set window_end_pos to the offset of the last character displayed
9482 on the window from the end of current_buffer. Set
9483 window_end_vpos to its row number. */
9486 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
9487 w
->window_end_bytepos
9488 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9489 XSETFASTINT (w
->window_end_pos
,
9490 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9491 XSETFASTINT (w
->window_end_vpos
,
9492 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9493 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
9498 w
->window_end_bytepos
= 0;
9499 XSETFASTINT (w
->window_end_pos
, 0);
9500 XSETFASTINT (w
->window_end_vpos
, 0);
9503 /* But that is not valid info until redisplay finishes. */
9504 w
->window_end_valid
= Qnil
;
9510 /************************************************************************
9511 Window redisplay reusing current matrix when buffer has not changed
9512 ************************************************************************/
9514 /* Try redisplay of window W showing an unchanged buffer with a
9515 different window start than the last time it was displayed by
9516 reusing its current matrix. Value is non-zero if successful.
9517 W->start is the new window start. */
9520 try_window_reusing_current_matrix (w
)
9523 struct frame
*f
= XFRAME (w
->frame
);
9524 struct glyph_row
*row
, *bottom_row
;
9527 struct text_pos start
, new_start
;
9528 int nrows_scrolled
, i
;
9529 struct glyph_row
*last_text_row
;
9530 struct glyph_row
*last_reused_text_row
;
9531 struct glyph_row
*start_row
;
9532 int start_vpos
, min_y
, max_y
;
9535 if (/* This function doesn't handle terminal frames. */
9537 /* Don't try to reuse the display if windows have been split
9539 || windows_or_buffers_changed
)
9542 /* Can't do this if region may have changed. */
9543 if ((!NILP (Vtransient_mark_mode
)
9544 && !NILP (current_buffer
->mark_active
))
9545 || !NILP (w
->region_showing
)
9546 || !NILP (Vshow_trailing_whitespace
))
9549 /* If top-line visibility has changed, give up. */
9550 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9551 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
9554 /* Give up if old or new display is scrolled vertically. We could
9555 make this function handle this, but right now it doesn't. */
9556 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9557 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
9560 /* The variable new_start now holds the new window start. The old
9561 start `start' can be determined from the current matrix. */
9562 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
9563 start
= start_row
->start
.pos
;
9564 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
9566 /* Clear the desired matrix for the display below. */
9567 clear_glyph_matrix (w
->desired_matrix
);
9569 if (CHARPOS (new_start
) <= CHARPOS (start
))
9573 IF_DEBUG (debug_method_add (w
, "twu1"));
9575 /* Display up to a row that can be reused. The variable
9576 last_text_row is set to the last row displayed that displays
9578 start_display (&it
, w
, new_start
);
9579 first_row_y
= it
.current_y
;
9580 w
->cursor
.vpos
= -1;
9581 last_text_row
= last_reused_text_row
= NULL
;
9582 while (it
.current_y
< it
.last_visible_y
9583 && IT_CHARPOS (it
) < CHARPOS (start
)
9584 && !fonts_changed_p
)
9585 if (display_line (&it
))
9586 last_text_row
= it
.glyph_row
- 1;
9588 /* A value of current_y < last_visible_y means that we stopped
9589 at the previous window start, which in turn means that we
9590 have at least one reusable row. */
9591 if (it
.current_y
< it
.last_visible_y
)
9593 nrows_scrolled
= it
.vpos
;
9595 /* Find PT if not already found in the lines displayed. */
9596 if (w
->cursor
.vpos
< 0)
9598 int dy
= it
.current_y
- first_row_y
;
9600 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9601 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9603 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
9604 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9606 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
9607 dy
, nrows_scrolled
);
9611 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
9617 /* Give up if point was not found. This shouldn't
9618 happen often; not more often than with try_window
9620 if (w
->cursor
.vpos
< 0)
9622 clear_glyph_matrix (w
->desired_matrix
);
9627 /* Scroll the display. Do it before the current matrix is
9628 changed. The problem here is that update has not yet
9629 run, i.e. part of the current matrix is not up to date.
9630 scroll_run_hook will clear the cursor, and use the
9631 current matrix to get the height of the row the cursor is
9633 run
.current_y
= first_row_y
;
9634 run
.desired_y
= it
.current_y
;
9635 run
.height
= it
.last_visible_y
- it
.current_y
;
9637 && run
.current_y
!= run
.desired_y
)
9640 rif
->update_window_begin_hook (w
);
9641 rif
->clear_mouse_face (w
);
9642 rif
->scroll_run_hook (w
, &run
);
9643 rif
->update_window_end_hook (w
, 0, 0);
9647 /* Shift current matrix down by nrows_scrolled lines. */
9648 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9649 rotate_matrix (w
->current_matrix
,
9651 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9654 /* Disable lines not reused. */
9655 for (i
= 0; i
< it
.vpos
; ++i
)
9656 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
9658 /* Re-compute Y positions. */
9659 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
) + nrows_scrolled
;
9660 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9661 max_y
= it
.last_visible_y
;
9662 while (row
< bottom_row
)
9664 row
->y
= it
.current_y
;
9667 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9668 else if (row
->y
+ row
->height
> max_y
)
9670 = row
->height
- (row
->y
+ row
->height
- max_y
);
9672 row
->visible_height
= row
->height
;
9674 it
.current_y
+= row
->height
;
9677 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9678 last_reused_text_row
= row
;
9679 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
9685 /* Update window_end_pos etc.; last_reused_text_row is the last
9686 reused row from the current matrix containing text, if any.
9687 The value of last_text_row is the last displayed line
9689 if (last_reused_text_row
)
9691 w
->window_end_bytepos
9692 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
9693 XSETFASTINT (w
->window_end_pos
,
9694 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
9695 XSETFASTINT (w
->window_end_vpos
,
9696 MATRIX_ROW_VPOS (last_reused_text_row
,
9697 w
->current_matrix
));
9699 else if (last_text_row
)
9701 w
->window_end_bytepos
9702 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9703 XSETFASTINT (w
->window_end_pos
,
9704 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9705 XSETFASTINT (w
->window_end_vpos
,
9706 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9710 /* This window must be completely empty. */
9711 w
->window_end_bytepos
= 0;
9712 XSETFASTINT (w
->window_end_pos
, 0);
9713 XSETFASTINT (w
->window_end_vpos
, 0);
9715 w
->window_end_valid
= Qnil
;
9717 /* Update hint: don't try scrolling again in update_window. */
9718 w
->desired_matrix
->no_scrolling_p
= 1;
9721 debug_method_add (w
, "try_window_reusing_current_matrix 1");
9725 else if (CHARPOS (new_start
) > CHARPOS (start
))
9727 struct glyph_row
*pt_row
, *row
;
9728 struct glyph_row
*first_reusable_row
;
9729 struct glyph_row
*first_row_to_display
;
9731 int yb
= window_text_bottom_y (w
);
9733 IF_DEBUG (debug_method_add (w
, "twu2"));
9735 /* Find the row starting at new_start, if there is one. Don't
9736 reuse a partially visible line at the end. */
9737 first_reusable_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9738 while (first_reusable_row
->enabled_p
9739 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
9740 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9741 < CHARPOS (new_start
)))
9742 ++first_reusable_row
;
9744 /* Give up if there is no row to reuse. */
9745 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
9746 || !first_reusable_row
->enabled_p
9747 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9748 != CHARPOS (new_start
)))
9751 /* We can reuse fully visible rows beginning with
9752 first_reusable_row to the end of the window. Set
9753 first_row_to_display to the first row that cannot be reused.
9754 Set pt_row to the row containing point, if there is any. */
9755 first_row_to_display
= first_reusable_row
;
9757 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
9759 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
9760 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
9761 pt_row
= first_row_to_display
;
9763 ++first_row_to_display
;
9766 /* Start displaying at the start of first_row_to_display. */
9767 xassert (first_row_to_display
->y
< yb
);
9768 init_to_row_start (&it
, w
, first_row_to_display
);
9769 nrows_scrolled
= MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
);
9770 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
9772 it
.current_y
= first_row_to_display
->y
- first_reusable_row
->y
;
9774 /* Display lines beginning with first_row_to_display in the
9775 desired matrix. Set last_text_row to the last row displayed
9776 that displays text. */
9777 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
9779 w
->cursor
.vpos
= -1;
9780 last_text_row
= NULL
;
9781 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
9782 if (display_line (&it
))
9783 last_text_row
= it
.glyph_row
- 1;
9785 /* Give up If point isn't in a row displayed or reused. */
9786 if (w
->cursor
.vpos
< 0)
9788 clear_glyph_matrix (w
->desired_matrix
);
9792 /* If point is in a reused row, adjust y and vpos of the cursor
9796 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
9798 w
->cursor
.y
-= first_reusable_row
->y
;
9801 /* Scroll the display. */
9802 run
.current_y
= first_reusable_row
->y
;
9803 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9804 run
.height
= it
.last_visible_y
- run
.current_y
;
9807 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9809 rif
->update_window_begin_hook (w
);
9810 rif
->clear_mouse_face (w
);
9811 rif
->scroll_run_hook (w
, &run
);
9812 rif
->update_window_end_hook (w
, 0, 0);
9816 /* Adjust Y positions of reused rows. */
9817 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9818 row
= first_reusable_row
;
9819 dy
= first_reusable_row
->y
;
9820 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9821 max_y
= it
.last_visible_y
;
9822 while (row
< first_row_to_display
)
9826 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9827 else if (row
->y
+ row
->height
> max_y
)
9829 = row
->height
- (row
->y
+ row
->height
- max_y
);
9831 row
->visible_height
= row
->height
;
9835 /* Disable rows not reused. */
9836 while (row
< bottom_row
)
9842 /* Scroll the current matrix. */
9843 xassert (nrows_scrolled
> 0);
9844 rotate_matrix (w
->current_matrix
,
9846 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9849 /* Adjust window end. A null value of last_text_row means that
9850 the window end is in reused rows which in turn means that
9851 only its vpos can have changed. */
9854 w
->window_end_bytepos
9855 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9856 XSETFASTINT (w
->window_end_pos
,
9857 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9858 XSETFASTINT (w
->window_end_vpos
,
9859 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9863 XSETFASTINT (w
->window_end_vpos
,
9864 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
9867 w
->window_end_valid
= Qnil
;
9868 w
->desired_matrix
->no_scrolling_p
= 1;
9871 debug_method_add (w
, "try_window_reusing_current_matrix 2");
9881 /************************************************************************
9882 Window redisplay reusing current matrix when buffer has changed
9883 ************************************************************************/
9885 static struct glyph_row
*get_last_unchanged_at_beg_row
P_ ((struct window
*));
9886 static struct glyph_row
*get_first_unchanged_at_end_row
P_ ((struct window
*,
9888 static struct glyph_row
*
9889 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
9890 struct glyph_row
*));
9893 /* Return the last row in MATRIX displaying text. If row START is
9894 non-null, start searching with that row. IT gives the dimensions
9895 of the display. Value is null if matrix is empty; otherwise it is
9896 a pointer to the row found. */
9898 static struct glyph_row
*
9899 find_last_row_displaying_text (matrix
, it
, start
)
9900 struct glyph_matrix
*matrix
;
9902 struct glyph_row
*start
;
9904 struct glyph_row
*row
, *row_found
;
9906 /* Set row_found to the last row in IT->w's current matrix
9907 displaying text. The loop looks funny but think of partially
9910 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
9911 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9913 xassert (row
->enabled_p
);
9915 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
9924 /* Return the last row in the current matrix of W that is not affected
9925 by changes at the start of current_buffer that occurred since the
9926 last time W was redisplayed. Value is null if no such row exists.
9928 The global variable beg_unchanged has to contain the number of
9929 bytes unchanged at the start of current_buffer. BEG +
9930 beg_unchanged is the buffer position of the first changed byte in
9931 current_buffer. Characters at positions < BEG + beg_unchanged are
9932 at the same buffer positions as they were when the current matrix
9935 static struct glyph_row
*
9936 get_last_unchanged_at_beg_row (w
)
9939 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
9940 struct glyph_row
*row
;
9941 struct glyph_row
*row_found
= NULL
;
9942 int yb
= window_text_bottom_y (w
);
9944 /* Find the last row displaying unchanged text. */
9945 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9946 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
9947 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
9949 if (/* If row ends before first_changed_pos, it is unchanged,
9950 except in some case. */
9951 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
9952 /* When row ends in ZV and we write at ZV it is not
9954 && !row
->ends_at_zv_p
9955 /* When first_changed_pos is the end of a continued line,
9956 row is not unchanged because it may be no longer
9958 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
9959 && row
->continued_p
))
9962 /* Stop if last visible row. */
9963 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
9973 /* Find the first glyph row in the current matrix of W that is not
9974 affected by changes at the end of current_buffer since the last
9975 time the window was redisplayed. Return in *DELTA the number of
9976 chars by which buffer positions in unchanged text at the end of
9977 current_buffer must be adjusted. Return in *DELTA_BYTES the
9978 corresponding number of bytes. Value is null if no such row
9979 exists, i.e. all rows are affected by changes. */
9981 static struct glyph_row
*
9982 get_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
9984 int *delta
, *delta_bytes
;
9986 struct glyph_row
*row
;
9987 struct glyph_row
*row_found
= NULL
;
9989 *delta
= *delta_bytes
= 0;
9991 /* A value of window_end_pos >= end_unchanged means that the window
9992 end is in the range of changed text. If so, there is no
9993 unchanged row at the end of W's current matrix. */
9994 xassert (!NILP (w
->window_end_valid
));
9995 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
9998 /* Set row to the last row in W's current matrix displaying text. */
9999 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10001 /* If matrix is entirely empty, no unchanged row exists. */
10002 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10004 /* The value of row is the last glyph row in the matrix having a
10005 meaningful buffer position in it. The end position of row
10006 corresponds to window_end_pos. This allows us to translate
10007 buffer positions in the current matrix to current buffer
10008 positions for characters not in changed text. */
10009 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
10010 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
10011 int last_unchanged_pos
, last_unchanged_pos_old
;
10012 struct glyph_row
*first_text_row
10013 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10015 *delta
= Z
- Z_old
;
10016 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
10018 /* Set last_unchanged_pos to the buffer position of the last
10019 character in the buffer that has not been changed. Z is the
10020 index + 1 of the last byte in current_buffer, i.e. by
10021 subtracting end_unchanged we get the index of the last
10022 unchanged character, and we have to add BEG to get its buffer
10024 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
10025 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
10027 /* Search backward from ROW for a row displaying a line that
10028 starts at a minimum position >= last_unchanged_pos_old. */
10029 while (row
>= first_text_row
)
10031 xassert (row
->enabled_p
);
10032 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
));
10034 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
10040 xassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
10045 /* Make sure that glyph rows in the current matrix of window W
10046 reference the same glyph memory as corresponding rows in the
10047 frame's frame matrix. This function is called after scrolling W's
10048 current matrix on a terminal frame in try_window_id and
10049 try_window_reusing_current_matrix. */
10052 sync_frame_with_window_matrix_rows (w
)
10055 struct frame
*f
= XFRAME (w
->frame
);
10056 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
10058 /* Preconditions: W must be a leaf window and full-width. Its frame
10059 must have a frame matrix. */
10060 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
10061 xassert (WINDOW_FULL_WIDTH_P (w
));
10062 xassert (!FRAME_WINDOW_P (f
));
10064 /* If W is a full-width window, glyph pointers in W's current matrix
10065 have, by definition, to be the same as glyph pointers in the
10066 corresponding frame matrix. */
10067 window_row
= w
->current_matrix
->rows
;
10068 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
10069 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
10070 while (window_row
< window_row_end
)
10074 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
10075 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
10077 /* Disable frame rows whose corresponding window rows have
10078 been disabled in try_window_id. */
10079 if (!window_row
->enabled_p
)
10080 frame_row
->enabled_p
= 0;
10082 ++window_row
, ++frame_row
;
10087 /* Find the glyph row in window W containing CHARPOS. Consider all
10088 rows between START and END (not inclusive). END null means search
10089 all rows to the end of the display area of W. Value is the row
10090 containing CHARPOS or null. */
10092 static struct glyph_row
*
10093 row_containing_pos (w
, charpos
, start
, end
)
10096 struct glyph_row
*start
, *end
;
10098 struct glyph_row
*row
= start
;
10101 /* If we happen to start on a header-line, skip that. */
10102 if (row
->mode_line_p
)
10105 if ((end
&& row
>= end
) || !row
->enabled_p
)
10108 last_y
= window_text_bottom_y (w
);
10110 while ((end
== NULL
|| row
< end
)
10111 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
10112 /* The end position of a row equals the start
10113 position of the next row. If CHARPOS is there, we
10114 would rather display it in the next line, except
10115 when this line ends in ZV. */
10116 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
10117 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
10118 || !row
->ends_at_zv_p
)))
10119 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
10122 /* Give up if CHARPOS not found. */
10123 if ((end
&& row
>= end
)
10124 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
10125 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
10132 /* Try to redisplay window W by reusing its existing display. W's
10133 current matrix must be up to date when this function is called,
10134 i.e. window_end_valid must not be nil.
10138 1 if display has been updated
10139 0 if otherwise unsuccessful
10140 -1 if redisplay with same window start is known not to succeed
10142 The following steps are performed:
10144 1. Find the last row in the current matrix of W that is not
10145 affected by changes at the start of current_buffer. If no such row
10148 2. Find the first row in W's current matrix that is not affected by
10149 changes at the end of current_buffer. Maybe there is no such row.
10151 3. Display lines beginning with the row + 1 found in step 1 to the
10152 row found in step 2 or, if step 2 didn't find a row, to the end of
10155 4. If cursor is not known to appear on the window, give up.
10157 5. If display stopped at the row found in step 2, scroll the
10158 display and current matrix as needed.
10160 6. Maybe display some lines at the end of W, if we must. This can
10161 happen under various circumstances, like a partially visible line
10162 becoming fully visible, or because newly displayed lines are displayed
10163 in smaller font sizes.
10165 7. Update W's window end information. */
10167 /* Check that window end is what we expect it to be. */
10173 struct frame
*f
= XFRAME (w
->frame
);
10174 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
10175 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
10176 struct glyph_row
*last_unchanged_at_beg_row
;
10177 struct glyph_row
*first_unchanged_at_end_row
;
10178 struct glyph_row
*row
;
10179 struct glyph_row
*bottom_row
;
10182 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
10183 struct text_pos start_pos
;
10185 int first_unchanged_at_end_vpos
= 0;
10186 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
10187 struct text_pos start
;
10189 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10191 /* Check pre-conditions. Window end must be valid, otherwise
10192 the current matrix would not be up to date. */
10193 xassert (!NILP (w
->window_end_valid
));
10194 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
10195 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
10197 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
10198 only if buffer has really changed. The reason is that the gap is
10199 initially at Z for freshly visited files. The code below would
10200 set end_unchanged to 0 in that case. */
10201 if (MODIFF
> SAVE_MODIFF
10202 /* This seems to happen sometimes after saving a buffer. */
10203 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
10205 if (GPT
- BEG
< BEG_UNCHANGED
)
10206 BEG_UNCHANGED
= GPT
- BEG
;
10207 if (Z
- GPT
< END_UNCHANGED
)
10208 END_UNCHANGED
= Z
- GPT
;
10211 /* If window starts after a line end, and the last change is in
10212 front of that newline, then changes don't affect the display.
10213 This case happens with stealth-fontification. Note that although
10214 the display is unchanged, glyph positions in the matrix have to
10215 be adjusted, of course. */
10216 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10217 if (CHARPOS (start
) > BEGV
10218 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
10219 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
10220 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10222 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
10223 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
10227 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10228 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
10230 increment_matrix_positions (w
->current_matrix
,
10231 MATRIX_ROW_VPOS (r0
, current_matrix
),
10232 MATRIX_ROW_VPOS (r1
, current_matrix
),
10233 delta
, delta_bytes
);
10236 #if 0 /* If changes are all in front of the window start, the
10237 distance of the last displayed glyph from Z hasn't
10240 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10241 w
->window_end_bytepos
10242 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10248 /* Return quickly if changes are all below what is displayed in the
10249 window, and if PT is in the window. */
10250 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
10251 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10253 /* We have to update window end positions because the buffer's
10254 size has changed. */
10256 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10257 w
->window_end_bytepos
10258 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10260 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10261 row
= row_containing_pos (w
, PT
, row
, NULL
);
10262 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10266 /* Check that window start agrees with the start of the first glyph
10267 row in its current matrix. Check this after we know the window
10268 start is not in changed text, otherwise positions would not be
10270 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10271 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
10274 /* Compute the position at which we have to start displaying new
10275 lines. Some of the lines at the top of the window might be
10276 reusable because they are not displaying changed text. Find the
10277 last row in W's current matrix not affected by changes at the
10278 start of current_buffer. Value is null if changes start in the
10279 first line of window. */
10280 last_unchanged_at_beg_row
= get_last_unchanged_at_beg_row (w
);
10281 if (last_unchanged_at_beg_row
)
10283 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
10284 start_pos
= it
.current
.pos
;
10286 /* Start displaying new lines in the desired matrix at the same
10287 vpos we would use in the current matrix, i.e. below
10288 last_unchanged_at_beg_row. */
10289 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
10291 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10292 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
10294 xassert (it
.hpos
== 0 && it
.current_x
== 0);
10298 /* There are no reusable lines at the start of the window.
10299 Start displaying in the first line. */
10300 start_display (&it
, w
, start
);
10301 start_pos
= it
.current
.pos
;
10304 /* Find the first row that is not affected by changes at the end of
10305 the buffer. Value will be null if there is no unchanged row, in
10306 which case we must redisplay to the end of the window. delta
10307 will be set to the value by which buffer positions beginning with
10308 first_unchanged_at_end_row have to be adjusted due to text
10310 first_unchanged_at_end_row
10311 = get_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
10312 IF_DEBUG (debug_delta
= delta
);
10313 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
10315 /* Set stop_pos to the buffer position up to which we will have to
10316 display new lines. If first_unchanged_at_end_row != NULL, this
10317 is the buffer position of the start of the line displayed in that
10318 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
10319 that we don't stop at a buffer position. */
10321 if (first_unchanged_at_end_row
)
10323 xassert (last_unchanged_at_beg_row
== NULL
10324 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
10326 /* If this is a continuation line, move forward to the next one
10327 that isn't. Changes in lines above affect this line.
10328 Caution: this may move first_unchanged_at_end_row to a row
10329 not displaying text. */
10330 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
10331 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10332 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10333 < it
.last_visible_y
))
10334 ++first_unchanged_at_end_row
;
10336 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10337 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10338 >= it
.last_visible_y
))
10339 first_unchanged_at_end_row
= NULL
;
10342 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
10344 first_unchanged_at_end_vpos
10345 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
10346 xassert (stop_pos
>= Z
- END_UNCHANGED
);
10349 else if (last_unchanged_at_beg_row
== NULL
)
10355 /* Either there is no unchanged row at the end, or the one we have
10356 now displays text. This is a necessary condition for the window
10357 end pos calculation at the end of this function. */
10358 xassert (first_unchanged_at_end_row
== NULL
10359 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
10361 debug_last_unchanged_at_beg_vpos
10362 = (last_unchanged_at_beg_row
10363 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
10365 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
10367 #endif /* GLYPH_DEBUG != 0 */
10370 /* Display new lines. Set last_text_row to the last new line
10371 displayed which has text on it, i.e. might end up as being the
10372 line where the window_end_vpos is. */
10373 w
->cursor
.vpos
= -1;
10374 last_text_row
= NULL
;
10375 overlay_arrow_seen
= 0;
10376 while (it
.current_y
< it
.last_visible_y
10377 && !fonts_changed_p
10378 && (first_unchanged_at_end_row
== NULL
10379 || IT_CHARPOS (it
) < stop_pos
))
10381 if (display_line (&it
))
10382 last_text_row
= it
.glyph_row
- 1;
10385 if (fonts_changed_p
)
10389 /* Compute differences in buffer positions, y-positions etc. for
10390 lines reused at the bottom of the window. Compute what we can
10392 if (first_unchanged_at_end_row
10393 /* No lines reused because we displayed everything up to the
10394 bottom of the window. */
10395 && it
.current_y
< it
.last_visible_y
)
10398 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
10400 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
10401 run
.current_y
= first_unchanged_at_end_row
->y
;
10402 run
.desired_y
= run
.current_y
+ dy
;
10403 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
10407 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
10408 first_unchanged_at_end_row
= NULL
;
10410 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
10413 /* Find the cursor if not already found. We have to decide whether
10414 PT will appear on this window (it sometimes doesn't, but this is
10415 not a very frequent case.) This decision has to be made before
10416 the current matrix is altered. A value of cursor.vpos < 0 means
10417 that PT is either in one of the lines beginning at
10418 first_unchanged_at_end_row or below the window. Don't care for
10419 lines that might be displayed later at the window end; as
10420 mentioned, this is not a frequent case. */
10421 if (w
->cursor
.vpos
< 0)
10423 /* Cursor in unchanged rows at the top? */
10424 if (PT
< CHARPOS (start_pos
)
10425 && last_unchanged_at_beg_row
)
10427 row
= row_containing_pos (w
, PT
,
10428 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
10429 last_unchanged_at_beg_row
+ 1);
10430 xassert (row
&& row
<= last_unchanged_at_beg_row
);
10431 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10434 /* Start from first_unchanged_at_end_row looking for PT. */
10435 else if (first_unchanged_at_end_row
)
10437 row
= row_containing_pos (w
, PT
- delta
,
10438 first_unchanged_at_end_row
, NULL
);
10440 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
10441 delta_bytes
, dy
, dvpos
);
10444 /* Give up if cursor was not found. */
10445 if (w
->cursor
.vpos
< 0)
10447 clear_glyph_matrix (w
->desired_matrix
);
10452 /* Don't let the cursor end in the scroll margins. */
10454 int this_scroll_margin
, cursor_height
;
10456 this_scroll_margin
= max (0, scroll_margin
);
10457 this_scroll_margin
= min (this_scroll_margin
,
10458 XFASTINT (w
->height
) / 4);
10459 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
10460 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
10462 if ((w
->cursor
.y
< this_scroll_margin
10463 && CHARPOS (start
) > BEGV
)
10464 /* Don't take scroll margin into account at the bottom because
10465 old redisplay didn't do it either. */
10466 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
10468 w
->cursor
.vpos
= -1;
10469 clear_glyph_matrix (w
->desired_matrix
);
10474 /* Scroll the display. Do it before changing the current matrix so
10475 that xterm.c doesn't get confused about where the cursor glyph is
10477 if (dy
&& run
.height
)
10481 if (FRAME_WINDOW_P (f
))
10483 rif
->update_window_begin_hook (w
);
10484 rif
->clear_mouse_face (w
);
10485 rif
->scroll_run_hook (w
, &run
);
10486 rif
->update_window_end_hook (w
, 0, 0);
10490 /* Terminal frame. In this case, dvpos gives the number of
10491 lines to scroll by; dvpos < 0 means scroll up. */
10492 int first_unchanged_at_end_vpos
10493 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
10494 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
10495 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
10497 /* Perform the operation on the screen. */
10500 /* Scroll last_unchanged_at_beg_row to the end of the
10501 window down dvpos lines. */
10502 set_terminal_window (end
);
10504 /* On dumb terminals delete dvpos lines at the end
10505 before inserting dvpos empty lines. */
10506 if (!scroll_region_ok
)
10507 ins_del_lines (end
- dvpos
, -dvpos
);
10509 /* Insert dvpos empty lines in front of
10510 last_unchanged_at_beg_row. */
10511 ins_del_lines (from
, dvpos
);
10513 else if (dvpos
< 0)
10515 /* Scroll up last_unchanged_at_beg_vpos to the end of
10516 the window to last_unchanged_at_beg_vpos - |dvpos|. */
10517 set_terminal_window (end
);
10519 /* Delete dvpos lines in front of
10520 last_unchanged_at_beg_vpos. ins_del_lines will set
10521 the cursor to the given vpos and emit |dvpos| delete
10523 ins_del_lines (from
+ dvpos
, dvpos
);
10525 /* On a dumb terminal insert dvpos empty lines at the
10527 if (!scroll_region_ok
)
10528 ins_del_lines (end
+ dvpos
, -dvpos
);
10531 set_terminal_window (0);
10537 /* Shift reused rows of the current matrix to the right position.
10538 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
10540 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10541 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
10544 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
10545 bottom_vpos
, dvpos
);
10546 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
10549 else if (dvpos
> 0)
10551 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
10552 bottom_vpos
, dvpos
);
10553 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
10554 first_unchanged_at_end_vpos
+ dvpos
, 0);
10557 /* For frame-based redisplay, make sure that current frame and window
10558 matrix are in sync with respect to glyph memory. */
10559 if (!FRAME_WINDOW_P (f
))
10560 sync_frame_with_window_matrix_rows (w
);
10562 /* Adjust buffer positions in reused rows. */
10564 increment_matrix_positions (current_matrix
,
10565 first_unchanged_at_end_vpos
+ dvpos
,
10566 bottom_vpos
, delta
, delta_bytes
);
10568 /* Adjust Y positions. */
10570 shift_glyph_matrix (w
, current_matrix
,
10571 first_unchanged_at_end_vpos
+ dvpos
,
10574 if (first_unchanged_at_end_row
)
10575 first_unchanged_at_end_row
+= dvpos
;
10577 /* If scrolling up, there may be some lines to display at the end of
10579 last_text_row_at_end
= NULL
;
10582 /* Set last_row to the glyph row in the current matrix where the
10583 window end line is found. It has been moved up or down in
10584 the matrix by dvpos. */
10585 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
10586 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
10588 /* If last_row is the window end line, it should display text. */
10589 xassert (last_row
->displays_text_p
);
10591 /* If window end line was partially visible before, begin
10592 displaying at that line. Otherwise begin displaying with the
10593 line following it. */
10594 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
10596 init_to_row_start (&it
, w
, last_row
);
10597 it
.vpos
= last_vpos
;
10598 it
.current_y
= last_row
->y
;
10602 init_to_row_end (&it
, w
, last_row
);
10603 it
.vpos
= 1 + last_vpos
;
10604 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
10608 /* We may start in a continuation line. If so, we have to get
10609 the right continuation_lines_width and current_x. */
10610 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
10611 it
.hpos
= it
.current_x
= 0;
10613 /* Display the rest of the lines at the window end. */
10614 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10615 while (it
.current_y
< it
.last_visible_y
10616 && !fonts_changed_p
)
10618 /* Is it always sure that the display agrees with lines in
10619 the current matrix? I don't think so, so we mark rows
10620 displayed invalid in the current matrix by setting their
10621 enabled_p flag to zero. */
10622 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
10623 if (display_line (&it
))
10624 last_text_row_at_end
= it
.glyph_row
- 1;
10628 /* Update window_end_pos and window_end_vpos. */
10629 if (first_unchanged_at_end_row
10630 && first_unchanged_at_end_row
->y
< it
.last_visible_y
10631 && !last_text_row_at_end
)
10633 /* Window end line if one of the preserved rows from the current
10634 matrix. Set row to the last row displaying text in current
10635 matrix starting at first_unchanged_at_end_row, after
10637 xassert (first_unchanged_at_end_row
->displays_text_p
);
10638 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
10639 first_unchanged_at_end_row
);
10640 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
10642 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
10643 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10644 XSETFASTINT (w
->window_end_vpos
,
10645 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
10647 else if (last_text_row_at_end
)
10649 XSETFASTINT (w
->window_end_pos
,
10650 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
10651 w
->window_end_bytepos
10652 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
10653 XSETFASTINT (w
->window_end_vpos
,
10654 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
10656 else if (last_text_row
)
10658 /* We have displayed either to the end of the window or at the
10659 end of the window, i.e. the last row with text is to be found
10660 in the desired matrix. */
10661 XSETFASTINT (w
->window_end_pos
,
10662 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10663 w
->window_end_bytepos
10664 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10665 XSETFASTINT (w
->window_end_vpos
,
10666 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
10668 else if (first_unchanged_at_end_row
== NULL
10669 && last_text_row
== NULL
10670 && last_text_row_at_end
== NULL
)
10672 /* Displayed to end of window, but no line containing text was
10673 displayed. Lines were deleted at the end of the window. */
10675 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
10677 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
10678 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10679 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
10680 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10681 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
10684 w
->window_end_vpos
= make_number (vpos
);
10689 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
10690 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
10692 /* Record that display has not been completed. */
10693 w
->window_end_valid
= Qnil
;
10694 w
->desired_matrix
->no_scrolling_p
= 1;
10700 /***********************************************************************
10701 More debugging support
10702 ***********************************************************************/
10706 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
10707 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
10710 /* Dump the contents of glyph matrix MATRIX on stderr. If
10711 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
10714 dump_glyph_matrix (matrix
, with_glyphs_p
)
10715 struct glyph_matrix
*matrix
;
10719 for (i
= 0; i
< matrix
->nrows
; ++i
)
10720 dump_glyph_row (matrix
, i
, with_glyphs_p
);
10724 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
10725 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
10728 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
10729 struct glyph_matrix
*matrix
;
10730 int vpos
, with_glyphs_p
;
10732 struct glyph_row
*row
;
10734 if (vpos
< 0 || vpos
>= matrix
->nrows
)
10737 row
= MATRIX_ROW (matrix
, vpos
);
10739 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFes X Y W\n");
10740 fprintf (stderr
, "=============================================\n");
10742 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",
10743 row
- matrix
->rows
,
10744 MATRIX_ROW_START_CHARPOS (row
),
10745 MATRIX_ROW_END_CHARPOS (row
),
10746 row
->used
[TEXT_AREA
],
10747 row
->contains_overlapping_glyphs_p
,
10750 row
->truncated_on_left_p
,
10751 row
->truncated_on_right_p
,
10752 row
->overlay_arrow_p
,
10754 MATRIX_ROW_CONTINUATION_LINE_P (row
),
10755 row
->displays_text_p
,
10758 row
->ends_in_middle_of_char_p
,
10759 row
->starts_in_middle_of_char_p
,
10763 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
10764 row
->end
.overlay_string_index
);
10765 fprintf (stderr
, "%9d %5d\n",
10766 CHARPOS (row
->start
.string_pos
),
10767 CHARPOS (row
->end
.string_pos
));
10768 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
10769 row
->end
.dpvec_index
);
10773 struct glyph
*glyph
, *glyph_end
;
10774 int prev_had_glyphs_p
;
10776 glyph
= row
->glyphs
[TEXT_AREA
];
10777 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
10779 /* Glyph for a line end in text. */
10780 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
10783 if (glyph
< glyph_end
)
10785 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
10786 prev_had_glyphs_p
= 1;
10789 prev_had_glyphs_p
= 0;
10791 while (glyph
< glyph_end
)
10793 if (glyph
->type
== CHAR_GLYPH
)
10796 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
10797 glyph
- row
->glyphs
[TEXT_AREA
],
10800 (BUFFERP (glyph
->object
)
10802 : (STRINGP (glyph
->object
)
10805 glyph
->pixel_width
,
10807 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
10811 glyph
->left_box_line_p
,
10812 glyph
->right_box_line_p
);
10814 else if (glyph
->type
== STRETCH_GLYPH
)
10817 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
10818 glyph
- row
->glyphs
[TEXT_AREA
],
10821 (BUFFERP (glyph
->object
)
10823 : (STRINGP (glyph
->object
)
10826 glyph
->pixel_width
,
10830 glyph
->left_box_line_p
,
10831 glyph
->right_box_line_p
);
10833 else if (glyph
->type
== IMAGE_GLYPH
)
10836 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
10837 glyph
- row
->glyphs
[TEXT_AREA
],
10840 (BUFFERP (glyph
->object
)
10842 : (STRINGP (glyph
->object
)
10845 glyph
->pixel_width
,
10849 glyph
->left_box_line_p
,
10850 glyph
->right_box_line_p
);
10858 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
10859 Sdump_glyph_matrix
, 0, 1, "p",
10860 "Dump the current matrix of the selected window to stderr.\n\
10861 Shows contents of glyph row structures. With non-nil optional\n\
10862 parameter WITH-GLYPHS-P, dump glyphs as well.")
10864 Lisp_Object with_glyphs_p
;
10866 struct window
*w
= XWINDOW (selected_window
);
10867 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10869 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
10870 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
10871 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
10872 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
10873 fprintf (stderr
, "=============================================\n");
10874 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
10879 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
10880 "Dump glyph row ROW to stderr.")
10884 CHECK_NUMBER (row
, 0);
10885 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
10890 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
,
10894 struct frame
*sf
= SELECTED_FRAME ();
10895 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)
10897 dump_glyph_row (m
, 0, 1);
10902 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
10903 Strace_redisplay_toggle
, 0, 0, "",
10904 "Toggle tracing of redisplay.")
10907 trace_redisplay_p
= !trace_redisplay_p
;
10912 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
10913 "Print STRING to stderr.")
10915 Lisp_Object string
;
10917 CHECK_STRING (string
, 0);
10918 fprintf (stderr
, "%s", XSTRING (string
)->data
);
10922 #endif /* GLYPH_DEBUG */
10926 /***********************************************************************
10927 Building Desired Matrix Rows
10928 ***********************************************************************/
10930 /* Return a temporary glyph row holding the glyphs of an overlay
10931 arrow. Only used for non-window-redisplay windows. */
10933 static struct glyph_row
*
10934 get_overlay_arrow_glyph_row (w
)
10937 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10938 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10939 struct buffer
*old
= current_buffer
;
10940 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
10941 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
10942 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
10946 int n_glyphs_before
;
10948 set_buffer_temp (buffer
);
10949 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
10950 it
.glyph_row
->used
[TEXT_AREA
] = 0;
10951 SET_TEXT_POS (it
.position
, 0, 0);
10953 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
10955 while (p
< arrow_end
)
10957 Lisp_Object face
, ilisp
;
10959 /* Get the next character. */
10961 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
10963 it
.c
= *p
, it
.len
= 1;
10966 /* Get its face. */
10967 XSETFASTINT (ilisp
, p
- arrow_string
);
10968 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
10969 it
.face_id
= compute_char_face (f
, it
.c
, face
);
10971 /* Compute its width, get its glyphs. */
10972 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
10973 SET_TEXT_POS (it
.position
, -1, -1);
10974 PRODUCE_GLYPHS (&it
);
10976 /* If this character doesn't fit any more in the line, we have
10977 to remove some glyphs. */
10978 if (it
.current_x
> it
.last_visible_x
)
10980 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
10985 set_buffer_temp (old
);
10986 return it
.glyph_row
;
10990 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
10991 glyphs are only inserted for terminal frames since we can't really
10992 win with truncation glyphs when partially visible glyphs are
10993 involved. Which glyphs to insert is determined by
10994 produce_special_glyphs. */
10997 insert_left_trunc_glyphs (it
)
11000 struct it truncate_it
;
11001 struct glyph
*from
, *end
, *to
, *toend
;
11003 xassert (!FRAME_WINDOW_P (it
->f
));
11005 /* Get the truncation glyphs. */
11007 truncate_it
.current_x
= 0;
11008 truncate_it
.face_id
= DEFAULT_FACE_ID
;
11009 truncate_it
.glyph_row
= &scratch_glyph_row
;
11010 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
11011 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
11012 truncate_it
.object
= make_number (0);
11013 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
11015 /* Overwrite glyphs from IT with truncation glyphs. */
11016 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
11017 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
11018 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
11019 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
11024 /* There may be padding glyphs left over. Remove them. */
11026 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
11028 while (from
< toend
)
11031 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
11035 /* Compute the pixel height and width of IT->glyph_row.
11037 Most of the time, ascent and height of a display line will be equal
11038 to the max_ascent and max_height values of the display iterator
11039 structure. This is not the case if
11041 1. We hit ZV without displaying anything. In this case, max_ascent
11042 and max_height will be zero.
11044 2. We have some glyphs that don't contribute to the line height.
11045 (The glyph row flag contributes_to_line_height_p is for future
11046 pixmap extensions).
11048 The first case is easily covered by using default values because in
11049 these cases, the line height does not really matter, except that it
11050 must not be zero. */
11053 compute_line_metrics (it
)
11056 struct glyph_row
*row
= it
->glyph_row
;
11059 if (FRAME_WINDOW_P (it
->f
))
11061 int i
, header_line_height
;
11063 /* The line may consist of one space only, that was added to
11064 place the cursor on it. If so, the row's height hasn't been
11066 if (row
->height
== 0)
11068 if (it
->max_ascent
+ it
->max_descent
== 0)
11069 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
11070 row
->ascent
= it
->max_ascent
;
11071 row
->height
= it
->max_ascent
+ it
->max_descent
;
11072 row
->phys_ascent
= it
->max_phys_ascent
;
11073 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11076 /* Compute the width of this line. */
11077 row
->pixel_width
= row
->x
;
11078 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
11079 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11081 xassert (row
->pixel_width
>= 0);
11082 xassert (row
->ascent
>= 0 && row
->height
> 0);
11084 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
11085 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
11087 /* If first line's physical ascent is larger than its logical
11088 ascent, use the physical ascent, and make the row taller.
11089 This makes accented characters fully visible. */
11090 if (row
== it
->w
->desired_matrix
->rows
11091 && row
->phys_ascent
> row
->ascent
)
11093 row
->height
+= row
->phys_ascent
- row
->ascent
;
11094 row
->ascent
= row
->phys_ascent
;
11097 /* Compute how much of the line is visible. */
11098 row
->visible_height
= row
->height
;
11100 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
11101 if (row
->y
< header_line_height
)
11102 row
->visible_height
-= header_line_height
- row
->y
;
11105 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
11106 if (row
->y
+ row
->height
> max_y
)
11107 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11112 row
->pixel_width
= row
->used
[TEXT_AREA
];
11113 row
->ascent
= row
->phys_ascent
= 0;
11114 row
->height
= row
->phys_height
= row
->visible_height
= 1;
11117 /* Compute a hash code for this row. */
11119 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11120 for (i
= 0; i
< row
->used
[area
]; ++i
)
11121 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
11122 + row
->glyphs
[area
][i
].u
.val
11123 + row
->glyphs
[area
][i
].face_id
11124 + row
->glyphs
[area
][i
].padding_p
11125 + (row
->glyphs
[area
][i
].type
<< 2));
11127 it
->max_ascent
= it
->max_descent
= 0;
11128 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
11132 /* Append one space to the glyph row of iterator IT if doing a
11133 window-based redisplay. DEFAULT_FACE_P non-zero means let the
11134 space have the default face, otherwise let it have the same face as
11135 IT->face_id. Value is non-zero if a space was added.
11137 This function is called to make sure that there is always one glyph
11138 at the end of a glyph row that the cursor can be set on under
11139 window-systems. (If there weren't such a glyph we would not know
11140 how wide and tall a box cursor should be displayed).
11142 At the same time this space let's a nicely handle clearing to the
11143 end of the line if the row ends in italic text. */
11146 append_space (it
, default_face_p
)
11148 int default_face_p
;
11150 if (FRAME_WINDOW_P (it
->f
))
11152 int n
= it
->glyph_row
->used
[TEXT_AREA
];
11154 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
11155 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
11157 /* Save some values that must not be changed. */
11158 int saved_x
= it
->current_x
;
11159 struct text_pos saved_pos
;
11160 int saved_what
= it
->what
;
11161 int saved_face_id
= it
->face_id
;
11162 Lisp_Object saved_object
;
11165 saved_object
= it
->object
;
11166 saved_pos
= it
->position
;
11168 it
->what
= IT_CHARACTER
;
11169 bzero (&it
->position
, sizeof it
->position
);
11170 it
->object
= make_number (0);
11174 if (default_face_p
)
11175 it
->face_id
= DEFAULT_FACE_ID
;
11176 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11177 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
11179 PRODUCE_GLYPHS (it
);
11181 it
->current_x
= saved_x
;
11182 it
->object
= saved_object
;
11183 it
->position
= saved_pos
;
11184 it
->what
= saved_what
;
11185 it
->face_id
= saved_face_id
;
11194 /* Extend the face of the last glyph in the text area of IT->glyph_row
11195 to the end of the display line. Called from display_line.
11196 If the glyph row is empty, add a space glyph to it so that we
11197 know the face to draw. Set the glyph row flag fill_line_p. */
11200 extend_face_to_end_of_line (it
)
11204 struct frame
*f
= it
->f
;
11206 /* If line is already filled, do nothing. */
11207 if (it
->current_x
>= it
->last_visible_x
)
11210 /* Face extension extends the background and box of IT->face_id
11211 to the end of the line. If the background equals the background
11212 of the frame, we haven't to do anything. */
11213 face
= FACE_FROM_ID (f
, it
->face_id
);
11214 if (FRAME_WINDOW_P (f
)
11215 && face
->box
== FACE_NO_BOX
11216 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
11220 /* Set the glyph row flag indicating that the face of the last glyph
11221 in the text area has to be drawn to the end of the text area. */
11222 it
->glyph_row
->fill_line_p
= 1;
11224 /* If current character of IT is not ASCII, make sure we have the
11225 ASCII face. This will be automatically undone the next time
11226 get_next_display_element returns a multibyte character. Note
11227 that the character will always be single byte in unibyte text. */
11228 if (!SINGLE_BYTE_CHAR_P (it
->c
))
11230 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
11233 if (FRAME_WINDOW_P (f
))
11235 /* If the row is empty, add a space with the current face of IT,
11236 so that we know which face to draw. */
11237 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
11239 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
11240 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
11241 it
->glyph_row
->used
[TEXT_AREA
] = 1;
11246 /* Save some values that must not be changed. */
11247 int saved_x
= it
->current_x
;
11248 struct text_pos saved_pos
;
11249 Lisp_Object saved_object
;
11250 int saved_what
= it
->what
;
11252 saved_object
= it
->object
;
11253 saved_pos
= it
->position
;
11255 it
->what
= IT_CHARACTER
;
11256 bzero (&it
->position
, sizeof it
->position
);
11257 it
->object
= make_number (0);
11261 PRODUCE_GLYPHS (it
);
11263 while (it
->current_x
<= it
->last_visible_x
)
11264 PRODUCE_GLYPHS (it
);
11266 /* Don't count these blanks really. It would let us insert a left
11267 truncation glyph below and make us set the cursor on them, maybe. */
11268 it
->current_x
= saved_x
;
11269 it
->object
= saved_object
;
11270 it
->position
= saved_pos
;
11271 it
->what
= saved_what
;
11276 /* Value is non-zero if text starting at CHARPOS in current_buffer is
11277 trailing whitespace. */
11280 trailing_whitespace_p (charpos
)
11283 int bytepos
= CHAR_TO_BYTE (charpos
);
11286 while (bytepos
< ZV_BYTE
11287 && (c
= FETCH_CHAR (bytepos
),
11288 c
== ' ' || c
== '\t'))
11291 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
11293 if (bytepos
!= PT_BYTE
)
11300 /* Highlight trailing whitespace, if any, in ROW. */
11303 highlight_trailing_whitespace (f
, row
)
11305 struct glyph_row
*row
;
11307 int used
= row
->used
[TEXT_AREA
];
11311 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
11312 struct glyph
*glyph
= start
+ used
- 1;
11314 /* Skip over the space glyph inserted to display the
11315 cursor at the end of a line. */
11316 if (glyph
->type
== CHAR_GLYPH
11317 && glyph
->u
.ch
== ' '
11318 && INTEGERP (glyph
->object
))
11321 /* If last glyph is a space or stretch, and it's trailing
11322 whitespace, set the face of all trailing whitespace glyphs in
11323 IT->glyph_row to `trailing-whitespace'. */
11325 && BUFFERP (glyph
->object
)
11326 && (glyph
->type
== STRETCH_GLYPH
11327 || (glyph
->type
== CHAR_GLYPH
11328 && glyph
->u
.ch
== ' '))
11329 && trailing_whitespace_p (glyph
->charpos
))
11331 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
11333 while (glyph
>= start
11334 && BUFFERP (glyph
->object
)
11335 && (glyph
->type
== STRETCH_GLYPH
11336 || (glyph
->type
== CHAR_GLYPH
11337 && glyph
->u
.ch
== ' ')))
11338 (glyph
--)->face_id
= face_id
;
11344 /* Construct the glyph row IT->glyph_row in the desired matrix of
11345 IT->w from text at the current position of IT. See dispextern.h
11346 for an overview of struct it. Value is non-zero if
11347 IT->glyph_row displays text, as opposed to a line displaying ZV
11354 struct glyph_row
*row
= it
->glyph_row
;
11356 /* We always start displaying at hpos zero even if hscrolled. */
11357 xassert (it
->hpos
== 0 && it
->current_x
== 0);
11359 /* We must not display in a row that's not a text row. */
11360 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
11361 < it
->w
->desired_matrix
->nrows
);
11363 /* Is IT->w showing the region? */
11364 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
11366 /* Clear the result glyph row and enable it. */
11367 prepare_desired_row (row
);
11369 row
->y
= it
->current_y
;
11370 row
->start
= it
->current
;
11371 row
->continuation_lines_width
= it
->continuation_lines_width
;
11372 row
->displays_text_p
= 1;
11373 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
11374 it
->starts_in_middle_of_char_p
= 0;
11376 /* Arrange the overlays nicely for our purposes. Usually, we call
11377 display_line on only one line at a time, in which case this
11378 can't really hurt too much, or we call it on lines which appear
11379 one after another in the buffer, in which case all calls to
11380 recenter_overlay_lists but the first will be pretty cheap. */
11381 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
11383 /* Move over display elements that are not visible because we are
11384 hscrolled. This may stop at an x-position < IT->first_visible_x
11385 if the first glyph is partially visible or if we hit a line end. */
11386 if (it
->current_x
< it
->first_visible_x
)
11387 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
11388 MOVE_TO_POS
| MOVE_TO_X
);
11390 /* Get the initial row height. This is either the height of the
11391 text hscrolled, if there is any, or zero. */
11392 row
->ascent
= it
->max_ascent
;
11393 row
->height
= it
->max_ascent
+ it
->max_descent
;
11394 row
->phys_ascent
= it
->max_phys_ascent
;
11395 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11397 /* Loop generating characters. The loop is left with IT on the next
11398 character to display. */
11401 int n_glyphs_before
, hpos_before
, x_before
;
11403 int ascent
, descent
, phys_ascent
, phys_descent
;
11405 /* Retrieve the next thing to display. Value is zero if end of
11407 if (!get_next_display_element (it
))
11409 /* Maybe add a space at the end of this line that is used to
11410 display the cursor there under X. Set the charpos of the
11411 first glyph of blank lines not corresponding to any text
11413 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
11414 || row
->used
[TEXT_AREA
] == 0)
11416 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
11417 row
->displays_text_p
= 0;
11419 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
11420 row
->indicate_empty_line_p
= 1;
11423 it
->continuation_lines_width
= 0;
11424 row
->ends_at_zv_p
= 1;
11428 /* Now, get the metrics of what we want to display. This also
11429 generates glyphs in `row' (which is IT->glyph_row). */
11430 n_glyphs_before
= row
->used
[TEXT_AREA
];
11433 /* Remember the line height so far in case the next element doesn't
11434 fit on the line. */
11435 if (!it
->truncate_lines_p
)
11437 ascent
= it
->max_ascent
;
11438 descent
= it
->max_descent
;
11439 phys_ascent
= it
->max_phys_ascent
;
11440 phys_descent
= it
->max_phys_descent
;
11443 PRODUCE_GLYPHS (it
);
11445 /* If this display element was in marginal areas, continue with
11447 if (it
->area
!= TEXT_AREA
)
11449 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11450 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11451 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11452 row
->phys_height
= max (row
->phys_height
,
11453 it
->max_phys_ascent
+ it
->max_phys_descent
);
11454 set_iterator_to_next (it
);
11458 /* Does the display element fit on the line? If we truncate
11459 lines, we should draw past the right edge of the window. If
11460 we don't truncate, we want to stop so that we can display the
11461 continuation glyph before the right margin. If lines are
11462 continued, there are two possible strategies for characters
11463 resulting in more than 1 glyph (e.g. tabs): Display as many
11464 glyphs as possible in this line and leave the rest for the
11465 continuation line, or display the whole element in the next
11466 line. Original redisplay did the former, so we do it also. */
11467 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11468 hpos_before
= it
->hpos
;
11472 && it
->current_x
< it
->last_visible_x
)
11475 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11476 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11477 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11478 row
->phys_height
= max (row
->phys_height
,
11479 it
->max_phys_ascent
+ it
->max_phys_descent
);
11480 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
11481 row
->x
= x
- it
->first_visible_x
;
11486 struct glyph
*glyph
;
11488 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
11490 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11491 new_x
= x
+ glyph
->pixel_width
;
11493 if (/* Lines are continued. */
11494 !it
->truncate_lines_p
11495 && (/* Glyph doesn't fit on the line. */
11496 new_x
> it
->last_visible_x
11497 /* Or it fits exactly on a window system frame. */
11498 || (new_x
== it
->last_visible_x
11499 && FRAME_WINDOW_P (it
->f
))))
11501 /* End of a continued line. */
11504 || (new_x
== it
->last_visible_x
11505 && FRAME_WINDOW_P (it
->f
)))
11507 /* Current glyph is the only one on the line or
11508 fits exactly on the line. We must continue
11509 the line because we can't draw the cursor
11510 after the glyph. */
11511 row
->continued_p
= 1;
11512 it
->current_x
= new_x
;
11513 it
->continuation_lines_width
+= new_x
;
11515 if (i
== nglyphs
- 1)
11516 set_iterator_to_next (it
);
11518 else if (CHAR_GLYPH_PADDING_P (*glyph
)
11519 && !FRAME_WINDOW_P (it
->f
))
11521 /* A padding glyph that doesn't fit on this line.
11522 This means the whole character doesn't fit
11524 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11526 /* Fill the rest of the row with continuation
11527 glyphs like in 20.x. */
11528 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
11529 < row
->glyphs
[1 + TEXT_AREA
])
11530 produce_special_glyphs (it
, IT_CONTINUATION
);
11532 row
->continued_p
= 1;
11533 it
->current_x
= x_before
;
11534 it
->continuation_lines_width
+= x_before
;
11536 /* Restore the height to what it was before the
11537 element not fitting on the line. */
11538 it
->max_ascent
= ascent
;
11539 it
->max_descent
= descent
;
11540 it
->max_phys_ascent
= phys_ascent
;
11541 it
->max_phys_descent
= phys_descent
;
11545 /* Display element draws past the right edge of
11546 the window. Restore positions to values
11547 before the element. The next line starts
11548 with current_x before the glyph that could
11549 not be displayed, so that TAB works right. */
11550 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11552 /* Display continuation glyphs. */
11553 if (!FRAME_WINDOW_P (it
->f
))
11554 produce_special_glyphs (it
, IT_CONTINUATION
);
11555 row
->continued_p
= 1;
11558 it
->continuation_lines_width
+= x
;
11559 if (nglyphs
> 1 && i
> 0)
11561 row
->ends_in_middle_of_char_p
= 1;
11562 it
->starts_in_middle_of_char_p
= 1;
11565 /* Restore the height to what it was before the
11566 element not fitting on the line. */
11567 it
->max_ascent
= ascent
;
11568 it
->max_descent
= descent
;
11569 it
->max_phys_ascent
= phys_ascent
;
11570 it
->max_phys_descent
= phys_descent
;
11575 else if (new_x
> it
->first_visible_x
)
11577 /* Increment number of glyphs actually displayed. */
11580 if (x
< it
->first_visible_x
)
11581 /* Glyph is partially visible, i.e. row starts at
11582 negative X position. */
11583 row
->x
= x
- it
->first_visible_x
;
11587 /* Glyph is completely off the left margin of the
11588 window. This should not happen because of the
11589 move_it_in_display_line at the start of
11595 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11596 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11597 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11598 row
->phys_height
= max (row
->phys_height
,
11599 it
->max_phys_ascent
+ it
->max_phys_descent
);
11601 /* End of this display line if row is continued. */
11602 if (row
->continued_p
)
11606 /* Is this a line end? If yes, we're also done, after making
11607 sure that a non-default face is extended up to the right
11608 margin of the window. */
11609 if (ITERATOR_AT_END_OF_LINE_P (it
))
11611 int used_before
= row
->used
[TEXT_AREA
];
11613 /* Add a space at the end of the line that is used to
11614 display the cursor there. */
11615 append_space (it
, 0);
11617 /* Extend the face to the end of the line. */
11618 extend_face_to_end_of_line (it
);
11620 /* Make sure we have the position. */
11621 if (used_before
== 0)
11622 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
11624 /* Consume the line end. This skips over invisible lines. */
11625 set_iterator_to_next (it
);
11626 it
->continuation_lines_width
= 0;
11630 /* Proceed with next display element. Note that this skips
11631 over lines invisible because of selective display. */
11632 set_iterator_to_next (it
);
11634 /* If we truncate lines, we are done when the last displayed
11635 glyphs reach past the right margin of the window. */
11636 if (it
->truncate_lines_p
11637 && (FRAME_WINDOW_P (it
->f
)
11638 ? (it
->current_x
>= it
->last_visible_x
)
11639 : (it
->current_x
> it
->last_visible_x
)))
11641 /* Maybe add truncation glyphs. */
11642 if (!FRAME_WINDOW_P (it
->f
))
11644 --it
->glyph_row
->used
[TEXT_AREA
];
11645 produce_special_glyphs (it
, IT_TRUNCATION
);
11648 row
->truncated_on_right_p
= 1;
11649 it
->continuation_lines_width
= 0;
11650 reseat_at_next_visible_line_start (it
, 0);
11651 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
11652 it
->hpos
= hpos_before
;
11653 it
->current_x
= x_before
;
11658 /* If line is not empty and hscrolled, maybe insert truncation glyphs
11659 at the left window margin. */
11660 if (it
->first_visible_x
11661 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
11663 if (!FRAME_WINDOW_P (it
->f
))
11664 insert_left_trunc_glyphs (it
);
11665 row
->truncated_on_left_p
= 1;
11668 /* If the start of this line is the overlay arrow-position, then
11669 mark this glyph row as the one containing the overlay arrow.
11670 This is clearly a mess with variable size fonts. It would be
11671 better to let it be displayed like cursors under X. */
11672 if (MARKERP (Voverlay_arrow_position
)
11673 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
11674 && (MATRIX_ROW_START_CHARPOS (row
)
11675 == marker_position (Voverlay_arrow_position
))
11676 && STRINGP (Voverlay_arrow_string
)
11677 && ! overlay_arrow_seen
)
11679 /* Overlay arrow in window redisplay is a bitmap. */
11680 if (!FRAME_WINDOW_P (it
->f
))
11682 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
11683 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
11684 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
11685 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
11686 struct glyph
*p2
, *end
;
11688 /* Copy the arrow glyphs. */
11689 while (glyph
< arrow_end
)
11692 /* Throw away padding glyphs. */
11694 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
11695 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
11701 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
11705 overlay_arrow_seen
= 1;
11706 row
->overlay_arrow_p
= 1;
11709 /* Compute pixel dimensions of this line. */
11710 compute_line_metrics (it
);
11712 /* Remember the position at which this line ends. */
11713 row
->end
= it
->current
;
11715 /* Maybe set the cursor. */
11716 if (it
->w
->cursor
.vpos
< 0
11717 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
11718 && PT
<= MATRIX_ROW_END_CHARPOS (row
))
11720 /* Also see redisplay_window, case cursor movement in unchanged
11722 if (MATRIX_ROW_END_CHARPOS (row
) == PT
11723 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11724 && !row
->ends_at_zv_p
)
11727 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
11730 /* Highlight trailing whitespace. */
11731 if (!NILP (Vshow_trailing_whitespace
))
11732 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
11734 /* Prepare for the next line. This line starts horizontally at (X
11735 HPOS) = (0 0). Vertical positions are incremented. As a
11736 convenience for the caller, IT->glyph_row is set to the next
11738 it
->current_x
= it
->hpos
= 0;
11739 it
->current_y
+= row
->height
;
11742 return row
->displays_text_p
;
11747 /***********************************************************************
11749 ***********************************************************************/
11751 /* Redisplay the menu bar in the frame for window W.
11753 The menu bar of X frames that don't have X toolkit support is
11754 displayed in a special window W->frame->menu_bar_window.
11756 The menu bar of terminal frames is treated specially as far as
11757 glyph matrices are concerned. Menu bar lines are not part of
11758 windows, so the update is done directly on the frame matrix rows
11759 for the menu bar. */
11762 display_menu_bar (w
)
11765 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11770 /* Don't do all this for graphical frames. */
11772 if (!NILP (Vwindow_system
))
11775 #ifdef USE_X_TOOLKIT
11780 #ifdef USE_X_TOOLKIT
11781 xassert (!FRAME_WINDOW_P (f
));
11782 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
11783 it
.first_visible_x
= 0;
11784 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11785 #else /* not USE_X_TOOLKIT */
11786 if (FRAME_WINDOW_P (f
))
11788 /* Menu bar lines are displayed in the desired matrix of the
11789 dummy window menu_bar_window. */
11790 struct window
*menu_w
;
11791 xassert (WINDOWP (f
->menu_bar_window
));
11792 menu_w
= XWINDOW (f
->menu_bar_window
);
11793 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
11795 it
.first_visible_x
= 0;
11796 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11800 /* This is a TTY frame, i.e. character hpos/vpos are used as
11802 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
11804 it
.first_visible_x
= 0;
11805 it
.last_visible_x
= FRAME_WIDTH (f
);
11807 #endif /* not USE_X_TOOLKIT */
11809 /* Clear all rows of the menu bar. */
11810 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
11812 struct glyph_row
*row
= it
.glyph_row
+ i
;
11813 clear_glyph_row (row
);
11814 row
->enabled_p
= 1;
11815 row
->full_width_p
= 1;
11818 /* Make the first line of the menu bar appear in reverse video. */
11819 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11821 /* Display all items of the menu bar. */
11822 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
11823 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
11825 Lisp_Object string
;
11827 /* Stop at nil string. */
11828 string
= XVECTOR (items
)->contents
[i
+ 1];
11832 /* Remember where item was displayed. */
11833 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
11835 /* Display the item, pad with one space. */
11836 if (it
.current_x
< it
.last_visible_x
)
11837 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
11838 XSTRING (string
)->size
+ 1, 0, 0, -1);
11841 /* Fill out the line with spaces. */
11842 if (it
.current_x
< it
.last_visible_x
)
11843 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
11845 /* Compute the total height of the lines. */
11846 compute_line_metrics (&it
);
11851 /***********************************************************************
11853 ***********************************************************************/
11855 /* Display the mode and/or top line of window W. */
11858 display_mode_lines (w
)
11861 /* These will be set while the mode line specs are processed. */
11862 line_number_displayed
= 0;
11863 w
->column_number_displayed
= Qnil
;
11865 if (WINDOW_WANTS_MODELINE_P (w
))
11866 display_mode_line (w
, MODE_LINE_FACE_ID
,
11867 current_buffer
->mode_line_format
);
11869 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11870 display_mode_line (w
, HEADER_LINE_FACE_ID
,
11871 current_buffer
->header_line_format
);
11875 /* Display mode or top line of window W. FACE_ID specifies which line
11876 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
11877 FORMAT is the mode line format to display. */
11880 display_mode_line (w
, face_id
, format
)
11882 enum face_id face_id
;
11883 Lisp_Object format
;
11888 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
11889 prepare_desired_row (it
.glyph_row
);
11891 /* Temporarily make frame's keyboard the current kboard so that
11892 kboard-local variables in the mode_line_format will get the right
11894 push_frame_kboard (it
.f
);
11895 display_mode_element (&it
, 0, 0, 0, format
);
11896 pop_frame_kboard ();
11898 /* Fill up with spaces. */
11899 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
11901 compute_line_metrics (&it
);
11902 it
.glyph_row
->full_width_p
= 1;
11903 it
.glyph_row
->mode_line_p
= 1;
11904 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11905 it
.glyph_row
->continued_p
= 0;
11906 it
.glyph_row
->truncated_on_left_p
= 0;
11907 it
.glyph_row
->truncated_on_right_p
= 0;
11909 /* Make a 3D mode-line have a shadow at its right end. */
11910 face
= FACE_FROM_ID (it
.f
, face_id
);
11911 extend_face_to_end_of_line (&it
);
11912 if (face
->box
!= FACE_NO_BOX
)
11914 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
11915 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
11916 last
->right_box_line_p
= 1;
11921 /* Contribute ELT to the mode line for window IT->w. How it
11922 translates into text depends on its data type.
11924 IT describes the display environment in which we display, as usual.
11926 DEPTH is the depth in recursion. It is used to prevent
11927 infinite recursion here.
11929 FIELD_WIDTH is the number of characters the display of ELT should
11930 occupy in the mode line, and PRECISION is the maximum number of
11931 characters to display from ELT's representation. See
11932 display_string for details. *
11934 Returns the hpos of the end of the text generated by ELT. */
11937 display_mode_element (it
, depth
, field_width
, precision
, elt
)
11940 int field_width
, precision
;
11943 int n
= 0, field
, prec
;
11951 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
11955 /* A string: output it and check for %-constructs within it. */
11957 unsigned char *this = XSTRING (elt
)->data
;
11958 unsigned char *lisp_string
= this;
11960 while ((precision
<= 0 || n
< precision
)
11962 && (frame_title_ptr
11963 || it
->current_x
< it
->last_visible_x
))
11965 unsigned char *last
= this;
11967 /* Advance to end of string or next format specifier. */
11968 while ((c
= *this++) != '\0' && c
!= '%')
11971 if (this - 1 != last
)
11973 /* Output to end of string or up to '%'. Field width
11974 is length of string. Don't output more than
11975 PRECISION allows us. */
11976 prec
= --this - last
;
11977 if (precision
> 0 && prec
> precision
- n
)
11978 prec
= precision
- n
;
11980 if (frame_title_ptr
)
11981 n
+= store_frame_title (last
, prec
, prec
);
11983 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
11984 it
, 0, prec
, 0, -1);
11986 else /* c == '%' */
11988 unsigned char *percent_position
= this;
11990 /* Get the specified minimum width. Zero means
11993 while ((c
= *this++) >= '0' && c
<= '9')
11994 field
= field
* 10 + c
- '0';
11996 /* Don't pad beyond the total padding allowed. */
11997 if (field_width
- n
> 0 && field
> field_width
- n
)
11998 field
= field_width
- n
;
12000 /* Note that either PRECISION <= 0 or N < PRECISION. */
12001 prec
= precision
- n
;
12004 n
+= display_mode_element (it
, depth
, field
, prec
,
12005 Vglobal_mode_string
);
12008 unsigned char *spec
12009 = decode_mode_spec (it
->w
, c
, field
, prec
);
12011 if (frame_title_ptr
)
12012 n
+= store_frame_title (spec
, field
, prec
);
12016 = it
->glyph_row
->used
[TEXT_AREA
];
12018 = percent_position
- XSTRING (elt
)->data
;
12020 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
12021 field
, prec
, 0, -1);
12023 /* Assign to the glyphs written above the
12024 string where the `%x' came from, position
12028 struct glyph
*glyph
12029 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
12033 for (i
= 0; i
< nwritten
; ++i
)
12035 glyph
[i
].object
= elt
;
12036 glyph
[i
].charpos
= charpos
;
12049 /* A symbol: process the value of the symbol recursively
12050 as if it appeared here directly. Avoid error if symbol void.
12051 Special case: if value of symbol is a string, output the string
12054 register Lisp_Object tem
;
12055 tem
= Fboundp (elt
);
12058 tem
= Fsymbol_value (elt
);
12059 /* If value is a string, output that string literally:
12060 don't check for % within it. */
12063 prec
= XSTRING (tem
)->size
;
12064 if (precision
> 0 && prec
> precision
- n
)
12065 prec
= precision
- n
;
12066 if (frame_title_ptr
)
12067 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
12069 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
12072 else if (!EQ (tem
, elt
))
12074 /* Give up right away for nil or t. */
12084 register Lisp_Object car
, tem
;
12086 /* A cons cell: three distinct cases.
12087 If first element is a string or a cons, process all the elements
12088 and effectively concatenate them.
12089 If first element is a negative number, truncate displaying cdr to
12090 at most that many characters. If positive, pad (with spaces)
12091 to at least that many characters.
12092 If first element is a symbol, process the cadr or caddr recursively
12093 according to whether the symbol's value is non-nil or nil. */
12095 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
12097 /* An element of the form (:eval FORM) means evaluate FORM
12098 and use the result as mode line elements. */
12099 struct gcpro gcpro1
;
12102 spec
= eval_form (XCAR (XCDR (elt
)));
12104 n
+= display_mode_element (it
, depth
, field_width
- n
,
12105 precision
- n
, spec
);
12108 else if (SYMBOLP (car
))
12110 tem
= Fboundp (car
);
12114 /* elt is now the cdr, and we know it is a cons cell.
12115 Use its car if CAR has a non-nil value. */
12118 tem
= Fsymbol_value (car
);
12125 /* Symbol's value is nil (or symbol is unbound)
12126 Get the cddr of the original list
12127 and if possible find the caddr and use that. */
12131 else if (!CONSP (elt
))
12136 else if (INTEGERP (car
))
12138 register int lim
= XINT (car
);
12142 /* Negative int means reduce maximum width. */
12143 if (precision
<= 0)
12146 precision
= min (precision
, -lim
);
12150 /* Padding specified. Don't let it be more than
12151 current maximum. */
12153 lim
= min (precision
, lim
);
12155 /* If that's more padding than already wanted, queue it.
12156 But don't reduce padding already specified even if
12157 that is beyond the current truncation point. */
12158 field_width
= max (lim
, field_width
);
12162 else if (STRINGP (car
) || CONSP (car
))
12164 register int limit
= 50;
12165 /* Limit is to protect against circular lists. */
12168 && (precision
<= 0 || n
< precision
))
12170 n
+= display_mode_element (it
, depth
, field_width
- n
,
12171 precision
- n
, XCAR (elt
));
12180 if (frame_title_ptr
)
12181 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
12183 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
12184 precision
- n
, 0, 0);
12188 /* Pad to FIELD_WIDTH. */
12189 if (field_width
> 0 && n
< field_width
)
12191 if (frame_title_ptr
)
12192 n
+= store_frame_title ("", field_width
- n
, 0);
12194 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
12202 /* Write a null-terminated, right justified decimal representation of
12203 the positive integer D to BUF using a minimal field width WIDTH. */
12206 pint2str (buf
, width
, d
)
12207 register char *buf
;
12208 register int width
;
12211 register char *p
= buf
;
12219 *p
++ = d
% 10 + '0';
12224 for (width
-= (int) (p
- buf
); width
> 0; --width
)
12235 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
12236 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
12237 type of CODING_SYSTEM. Return updated pointer into BUF. */
12239 static unsigned char invalid_eol_type
[] = "(*invalid*)";
12242 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
12243 Lisp_Object coding_system
;
12244 register char *buf
;
12248 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
12249 unsigned char *eol_str
;
12251 /* The EOL conversion we are using. */
12252 Lisp_Object eoltype
;
12254 val
= Fget (coding_system
, Qcoding_system
);
12256 if (!VECTORP (val
)) /* Not yet decided. */
12261 eoltype
= eol_mnemonic_undecided
;
12262 /* Don't mention EOL conversion if it isn't decided. */
12266 Lisp_Object eolvalue
;
12268 eolvalue
= Fget (coding_system
, Qeol_type
);
12271 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
12275 /* The EOL conversion that is normal on this system. */
12277 if (NILP (eolvalue
)) /* Not yet decided. */
12278 eoltype
= eol_mnemonic_undecided
;
12279 else if (VECTORP (eolvalue
)) /* Not yet decided. */
12280 eoltype
= eol_mnemonic_undecided
;
12281 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
12282 eoltype
= (XFASTINT (eolvalue
) == 0
12283 ? eol_mnemonic_unix
12284 : (XFASTINT (eolvalue
) == 1
12285 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
12291 /* Mention the EOL conversion if it is not the usual one. */
12292 if (STRINGP (eoltype
))
12294 eol_str
= XSTRING (eoltype
)->data
;
12295 eol_str_len
= XSTRING (eoltype
)->size
;
12297 else if (INTEGERP (eoltype
)
12298 && CHAR_VALID_P (XINT (eoltype
), 0))
12300 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
12301 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
12305 eol_str
= invalid_eol_type
;
12306 eol_str_len
= sizeof (invalid_eol_type
) - 1;
12308 bcopy (eol_str
, buf
, eol_str_len
);
12309 buf
+= eol_str_len
;
12315 /* Return a string for the output of a mode line %-spec for window W,
12316 generated by character C. PRECISION >= 0 means don't return a
12317 string longer than that value. FIELD_WIDTH > 0 means pad the
12318 string returned with spaces to that value. */
12320 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
12323 decode_mode_spec (w
, c
, field_width
, precision
)
12326 int field_width
, precision
;
12329 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12330 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
12331 struct buffer
*b
= XBUFFER (w
->buffer
);
12338 if (!NILP (b
->read_only
))
12340 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12345 /* This differs from %* only for a modified read-only buffer. */
12346 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12348 if (!NILP (b
->read_only
))
12353 /* This differs from %* in ignoring read-only-ness. */
12354 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12366 if (command_loop_level
> 5)
12368 p
= decode_mode_spec_buf
;
12369 for (i
= 0; i
< command_loop_level
; i
++)
12372 return decode_mode_spec_buf
;
12380 if (command_loop_level
> 5)
12382 p
= decode_mode_spec_buf
;
12383 for (i
= 0; i
< command_loop_level
; i
++)
12386 return decode_mode_spec_buf
;
12393 /* Let lots_of_dashes be a string of infinite length. */
12394 if (field_width
<= 0
12395 || field_width
> sizeof (lots_of_dashes
))
12397 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
12398 decode_mode_spec_buf
[i
] = '-';
12399 decode_mode_spec_buf
[i
] = '\0';
12400 return decode_mode_spec_buf
;
12403 return lots_of_dashes
;
12412 int col
= current_column ();
12413 XSETFASTINT (w
->column_number_displayed
, col
);
12414 pint2str (decode_mode_spec_buf
, field_width
, col
);
12415 return decode_mode_spec_buf
;
12419 /* %F displays the frame name. */
12420 if (!NILP (f
->title
))
12421 return (char *) XSTRING (f
->title
)->data
;
12422 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
12423 return (char *) XSTRING (f
->name
)->data
;
12432 int startpos
= XMARKER (w
->start
)->charpos
;
12433 int startpos_byte
= marker_byte_position (w
->start
);
12434 int line
, linepos
, linepos_byte
, topline
;
12436 int height
= XFASTINT (w
->height
);
12438 /* If we decided that this buffer isn't suitable for line numbers,
12439 don't forget that too fast. */
12440 if (EQ (w
->base_line_pos
, w
->buffer
))
12442 /* But do forget it, if the window shows a different buffer now. */
12443 else if (BUFFERP (w
->base_line_pos
))
12444 w
->base_line_pos
= Qnil
;
12446 /* If the buffer is very big, don't waste time. */
12447 if (INTEGERP (Vline_number_display_limit
)
12448 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
12450 w
->base_line_pos
= Qnil
;
12451 w
->base_line_number
= Qnil
;
12455 if (!NILP (w
->base_line_number
)
12456 && !NILP (w
->base_line_pos
)
12457 && XFASTINT (w
->base_line_pos
) <= startpos
)
12459 line
= XFASTINT (w
->base_line_number
);
12460 linepos
= XFASTINT (w
->base_line_pos
);
12461 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
12466 linepos
= BUF_BEGV (b
);
12467 linepos_byte
= BUF_BEGV_BYTE (b
);
12470 /* Count lines from base line to window start position. */
12471 nlines
= display_count_lines (linepos
, linepos_byte
,
12475 topline
= nlines
+ line
;
12477 /* Determine a new base line, if the old one is too close
12478 or too far away, or if we did not have one.
12479 "Too close" means it's plausible a scroll-down would
12480 go back past it. */
12481 if (startpos
== BUF_BEGV (b
))
12483 XSETFASTINT (w
->base_line_number
, topline
);
12484 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
12486 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
12487 || linepos
== BUF_BEGV (b
))
12489 int limit
= BUF_BEGV (b
);
12490 int limit_byte
= BUF_BEGV_BYTE (b
);
12492 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
12494 if (startpos
- distance
> limit
)
12496 limit
= startpos
- distance
;
12497 limit_byte
= CHAR_TO_BYTE (limit
);
12500 nlines
= display_count_lines (startpos
, startpos_byte
,
12502 - (height
* 2 + 30),
12504 /* If we couldn't find the lines we wanted within
12505 line_number_display_limit_width chars per line,
12506 give up on line numbers for this window. */
12507 if (position
== limit_byte
&& limit
== startpos
- distance
)
12509 w
->base_line_pos
= w
->buffer
;
12510 w
->base_line_number
= Qnil
;
12514 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
12515 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
12518 /* Now count lines from the start pos to point. */
12519 nlines
= display_count_lines (startpos
, startpos_byte
,
12520 PT_BYTE
, PT
, &junk
);
12522 /* Record that we did display the line number. */
12523 line_number_displayed
= 1;
12525 /* Make the string to show. */
12526 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
12527 return decode_mode_spec_buf
;
12530 char* p
= decode_mode_spec_buf
;
12531 int pad
= field_width
- 2;
12537 return decode_mode_spec_buf
;
12543 obj
= b
->mode_name
;
12547 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
12553 int pos
= marker_position (w
->start
);
12554 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12556 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
12558 if (pos
<= BUF_BEGV (b
))
12563 else if (pos
<= BUF_BEGV (b
))
12567 if (total
> 1000000)
12568 /* Do it differently for a large value, to avoid overflow. */
12569 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12571 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12572 /* We can't normally display a 3-digit number,
12573 so get us a 2-digit number that is close. */
12576 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12577 return decode_mode_spec_buf
;
12581 /* Display percentage of size above the bottom of the screen. */
12584 int toppos
= marker_position (w
->start
);
12585 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
12586 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12588 if (botpos
>= BUF_ZV (b
))
12590 if (toppos
<= BUF_BEGV (b
))
12597 if (total
> 1000000)
12598 /* Do it differently for a large value, to avoid overflow. */
12599 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12601 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12602 /* We can't normally display a 3-digit number,
12603 so get us a 2-digit number that is close. */
12606 if (toppos
<= BUF_BEGV (b
))
12607 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
12609 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12610 return decode_mode_spec_buf
;
12615 /* status of process */
12616 obj
= Fget_buffer_process (w
->buffer
);
12618 return "no process";
12619 #ifdef subprocesses
12620 obj
= Fsymbol_name (Fprocess_status (obj
));
12624 case 't': /* indicate TEXT or BINARY */
12625 #ifdef MODE_LINE_BINARY_TEXT
12626 return MODE_LINE_BINARY_TEXT (b
);
12632 /* coding-system (not including end-of-line format) */
12634 /* coding-system (including end-of-line type) */
12636 int eol_flag
= (c
== 'Z');
12637 char *p
= decode_mode_spec_buf
;
12639 if (! FRAME_WINDOW_P (f
))
12641 /* No need to mention EOL here--the terminal never needs
12642 to do EOL conversion. */
12643 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
12644 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
12646 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
12649 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
12650 #ifdef subprocesses
12651 obj
= Fget_buffer_process (Fcurrent_buffer ());
12652 if (PROCESSP (obj
))
12654 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
12656 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
12659 #endif /* subprocesses */
12662 return decode_mode_spec_buf
;
12667 return (char *) XSTRING (obj
)->data
;
12673 /* Count up to COUNT lines starting from START / START_BYTE.
12674 But don't go beyond LIMIT_BYTE.
12675 Return the number of lines thus found (always nonnegative).
12677 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
12680 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
12681 int start
, start_byte
, limit_byte
, count
;
12684 register unsigned char *cursor
;
12685 unsigned char *base
;
12687 register int ceiling
;
12688 register unsigned char *ceiling_addr
;
12689 int orig_count
= count
;
12691 /* If we are not in selective display mode,
12692 check only for newlines. */
12693 int selective_display
= (!NILP (current_buffer
->selective_display
)
12694 && !INTEGERP (current_buffer
->selective_display
));
12698 while (start_byte
< limit_byte
)
12700 ceiling
= BUFFER_CEILING_OF (start_byte
);
12701 ceiling
= min (limit_byte
- 1, ceiling
);
12702 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
12703 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
12706 if (selective_display
)
12707 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
12710 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
12713 if (cursor
!= ceiling_addr
)
12717 start_byte
+= cursor
- base
+ 1;
12718 *byte_pos_ptr
= start_byte
;
12722 if (++cursor
== ceiling_addr
)
12728 start_byte
+= cursor
- base
;
12733 while (start_byte
> limit_byte
)
12735 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
12736 ceiling
= max (limit_byte
, ceiling
);
12737 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
12738 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
12741 if (selective_display
)
12742 while (--cursor
!= ceiling_addr
12743 && *cursor
!= '\n' && *cursor
!= 015)
12746 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
12749 if (cursor
!= ceiling_addr
)
12753 start_byte
+= cursor
- base
+ 1;
12754 *byte_pos_ptr
= start_byte
;
12755 /* When scanning backwards, we should
12756 not count the newline posterior to which we stop. */
12757 return - orig_count
- 1;
12763 /* Here we add 1 to compensate for the last decrement
12764 of CURSOR, which took it past the valid range. */
12765 start_byte
+= cursor
- base
+ 1;
12769 *byte_pos_ptr
= limit_byte
;
12772 return - orig_count
+ count
;
12773 return orig_count
- count
;
12779 /***********************************************************************
12781 ***********************************************************************/
12783 /* Display a NUL-terminated string, starting with index START.
12785 If STRING is non-null, display that C string. Otherwise, the Lisp
12786 string LISP_STRING is displayed.
12788 If FACE_STRING is not nil, FACE_STRING_POS is a position in
12789 FACE_STRING. Display STRING or LISP_STRING with the face at
12790 FACE_STRING_POS in FACE_STRING:
12792 Display the string in the environment given by IT, but use the
12793 standard display table, temporarily.
12795 FIELD_WIDTH is the minimum number of output glyphs to produce.
12796 If STRING has fewer characters than FIELD_WIDTH, pad to the right
12797 with spaces. If STRING has more characters, more than FIELD_WIDTH
12798 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
12800 PRECISION is the maximum number of characters to output from
12801 STRING. PRECISION < 0 means don't truncate the string.
12803 This is roughly equivalent to printf format specifiers:
12805 FIELD_WIDTH PRECISION PRINTF
12806 ----------------------------------------
12812 MULTIBYTE zero means do not display multibyte chars, > 0 means do
12813 display them, and < 0 means obey the current buffer's value of
12814 enable_multibyte_characters.
12816 Value is the number of glyphs produced. */
12819 display_string (string
, lisp_string
, face_string
, face_string_pos
,
12820 start
, it
, field_width
, precision
, max_x
, multibyte
)
12821 unsigned char *string
;
12822 Lisp_Object lisp_string
;
12823 Lisp_Object face_string
;
12824 int face_string_pos
;
12827 int field_width
, precision
, max_x
;
12830 int hpos_at_start
= it
->hpos
;
12831 int saved_face_id
= it
->face_id
;
12832 struct glyph_row
*row
= it
->glyph_row
;
12834 /* Initialize the iterator IT for iteration over STRING beginning
12835 with index START. We assume that IT may be modified here (which
12836 means that display_line has to do something when displaying a
12837 mini-buffer prompt, which it does). */
12838 reseat_to_string (it
, string
, lisp_string
, start
,
12839 precision
, field_width
, multibyte
);
12841 /* If displaying STRING, set up the face of the iterator
12842 from LISP_STRING, if that's given. */
12843 if (STRINGP (face_string
))
12849 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
12850 0, it
->region_beg_charpos
,
12851 it
->region_end_charpos
,
12852 &endptr
, it
->base_face_id
);
12853 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12854 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
12857 /* Set max_x to the maximum allowed X position. Don't let it go
12858 beyond the right edge of the window. */
12860 max_x
= it
->last_visible_x
;
12862 max_x
= min (max_x
, it
->last_visible_x
);
12864 /* Skip over display elements that are not visible. because IT->w is
12866 if (it
->current_x
< it
->first_visible_x
)
12867 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
12868 MOVE_TO_POS
| MOVE_TO_X
);
12870 row
->ascent
= it
->max_ascent
;
12871 row
->height
= it
->max_ascent
+ it
->max_descent
;
12872 row
->phys_ascent
= it
->max_phys_ascent
;
12873 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12875 /* This condition is for the case that we are called with current_x
12876 past last_visible_x. */
12877 while (it
->current_x
< max_x
)
12879 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
12881 /* Get the next display element. */
12882 if (!get_next_display_element (it
))
12885 /* Produce glyphs. */
12886 x_before
= it
->current_x
;
12887 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
12888 PRODUCE_GLYPHS (it
);
12890 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
12893 while (i
< nglyphs
)
12895 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12897 if (!it
->truncate_lines_p
12898 && x
+ glyph
->pixel_width
> max_x
)
12900 /* End of continued line or max_x reached. */
12901 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12905 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
12907 /* Glyph is at least partially visible. */
12909 if (x
< it
->first_visible_x
)
12910 it
->glyph_row
->x
= x
- it
->first_visible_x
;
12914 /* Glyph is off the left margin of the display area.
12915 Should not happen. */
12919 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12920 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12921 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12922 row
->phys_height
= max (row
->phys_height
,
12923 it
->max_phys_ascent
+ it
->max_phys_descent
);
12924 x
+= glyph
->pixel_width
;
12928 /* Stop if max_x reached. */
12932 /* Stop at line ends. */
12933 if (ITERATOR_AT_END_OF_LINE_P (it
))
12935 it
->continuation_lines_width
= 0;
12939 set_iterator_to_next (it
);
12941 /* Stop if truncating at the right edge. */
12942 if (it
->truncate_lines_p
12943 && it
->current_x
>= it
->last_visible_x
)
12945 /* Add truncation mark, but don't do it if the line is
12946 truncated at a padding space. */
12947 if (IT_CHARPOS (*it
) < it
->string_nchars
)
12949 if (!FRAME_WINDOW_P (it
->f
))
12950 produce_special_glyphs (it
, IT_TRUNCATION
);
12951 it
->glyph_row
->truncated_on_right_p
= 1;
12957 /* Maybe insert a truncation at the left. */
12958 if (it
->first_visible_x
12959 && IT_CHARPOS (*it
) > 0)
12961 if (!FRAME_WINDOW_P (it
->f
))
12962 insert_left_trunc_glyphs (it
);
12963 it
->glyph_row
->truncated_on_left_p
= 1;
12966 it
->face_id
= saved_face_id
;
12968 /* Value is number of columns displayed. */
12969 return it
->hpos
- hpos_at_start
;
12974 /* This is like a combination of memq and assq. Return 1 if PROPVAL
12975 appears as an element of LIST or as the car of an element of LIST.
12976 If PROPVAL is a list, compare each element against LIST in that
12977 way, and return 1 if any element of PROPVAL is found in LIST.
12978 Otherwise return 0. This function cannot quit. */
12981 invisible_p (propval
, list
)
12982 register Lisp_Object propval
;
12985 register Lisp_Object tail
, proptail
;
12986 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12988 register Lisp_Object tem
;
12990 if (EQ (propval
, tem
))
12992 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
12995 if (CONSP (propval
))
12996 for (proptail
= propval
; CONSP (proptail
);
12997 proptail
= XCDR (proptail
))
12999 Lisp_Object propelt
;
13000 propelt
= XCAR (proptail
);
13001 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13003 register Lisp_Object tem
;
13005 if (EQ (propelt
, tem
))
13007 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
13015 /* Return 1 if PROPVAL appears as the car of an element of LIST and
13016 the cdr of that element is non-nil. If PROPVAL is a list, check
13017 each element of PROPVAL in that way, and the first time some
13018 element is found, return 1 if the cdr of that element is non-nil.
13019 Otherwise return 0. This function cannot quit. */
13022 invisible_ellipsis_p (propval
, list
)
13023 register Lisp_Object propval
;
13026 register Lisp_Object tail
, proptail
;
13028 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13030 register Lisp_Object tem
;
13032 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
13033 return ! NILP (XCDR (tem
));
13036 if (CONSP (propval
))
13037 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
13039 Lisp_Object propelt
;
13040 propelt
= XCAR (proptail
);
13041 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13043 register Lisp_Object tem
;
13045 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
13046 return ! NILP (XCDR (tem
));
13055 /***********************************************************************
13057 ***********************************************************************/
13062 Vwith_echo_area_save_vector
= Qnil
;
13063 staticpro (&Vwith_echo_area_save_vector
);
13065 Vmessage_stack
= Qnil
;
13066 staticpro (&Vmessage_stack
);
13068 Qinhibit_redisplay
= intern ("inhibit-redisplay");
13069 staticpro (&Qinhibit_redisplay
);
13072 defsubr (&Sdump_glyph_matrix
);
13073 defsubr (&Sdump_glyph_row
);
13074 defsubr (&Sdump_tool_bar_row
);
13075 defsubr (&Strace_redisplay_toggle
);
13076 defsubr (&Strace_to_stderr
);
13079 staticpro (&Qmenu_bar_update_hook
);
13080 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
13082 staticpro (&Qoverriding_terminal_local_map
);
13083 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
13085 staticpro (&Qoverriding_local_map
);
13086 Qoverriding_local_map
= intern ("overriding-local-map");
13088 staticpro (&Qwindow_scroll_functions
);
13089 Qwindow_scroll_functions
= intern ("window-scroll-functions");
13091 staticpro (&Qredisplay_end_trigger_functions
);
13092 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
13094 staticpro (&Qinhibit_point_motion_hooks
);
13095 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
13097 QCdata
= intern (":data");
13098 staticpro (&QCdata
);
13099 Qdisplay
= intern ("display");
13100 staticpro (&Qdisplay
);
13101 Qspace_width
= intern ("space-width");
13102 staticpro (&Qspace_width
);
13103 Qraise
= intern ("raise");
13104 staticpro (&Qraise
);
13105 Qspace
= intern ("space");
13106 staticpro (&Qspace
);
13107 Qmargin
= intern ("margin");
13108 staticpro (&Qmargin
);
13109 Qleft_margin
= intern ("left-margin");
13110 staticpro (&Qleft_margin
);
13111 Qright_margin
= intern ("right-margin");
13112 staticpro (&Qright_margin
);
13113 Qalign_to
= intern ("align-to");
13114 staticpro (&Qalign_to
);
13115 QCalign_to
= intern (":align-to");
13116 staticpro (&QCalign_to
);
13117 Qrelative_width
= intern ("relative-width");
13118 staticpro (&Qrelative_width
);
13119 QCrelative_width
= intern (":relative-width");
13120 staticpro (&QCrelative_width
);
13121 QCrelative_height
= intern (":relative-height");
13122 staticpro (&QCrelative_height
);
13123 QCeval
= intern (":eval");
13124 staticpro (&QCeval
);
13125 Qwhen
= intern ("when");
13126 staticpro (&Qwhen
);
13127 QCfile
= intern (":file");
13128 staticpro (&QCfile
);
13129 Qfontified
= intern ("fontified");
13130 staticpro (&Qfontified
);
13131 Qfontification_functions
= intern ("fontification-functions");
13132 staticpro (&Qfontification_functions
);
13133 Qtrailing_whitespace
= intern ("trailing-whitespace");
13134 staticpro (&Qtrailing_whitespace
);
13135 Qimage
= intern ("image");
13136 staticpro (&Qimage
);
13137 Qmessage_truncate_lines
= intern ("message-truncate-lines");
13138 staticpro (&Qmessage_truncate_lines
);
13140 last_arrow_position
= Qnil
;
13141 last_arrow_string
= Qnil
;
13142 staticpro (&last_arrow_position
);
13143 staticpro (&last_arrow_string
);
13145 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
13146 staticpro (&echo_buffer
[0]);
13147 staticpro (&echo_buffer
[1]);
13149 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
13150 staticpro (&echo_area_buffer
[0]);
13151 staticpro (&echo_area_buffer
[1]);
13153 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
13154 "Non-nil means highlight trailing whitespace.\n\
13155 The face used for trailing whitespace is `trailing-whitespace'.");
13156 Vshow_trailing_whitespace
= Qnil
;
13158 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
13159 "Non-nil means don't actually do any redisplay.\n\
13160 This is used for internal purposes.");
13161 Vinhibit_redisplay
= Qnil
;
13163 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
13164 "String (or mode line construct) included (normally) in `mode-line-format'.");
13165 Vglobal_mode_string
= Qnil
;
13167 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
13168 "Marker for where to display an arrow on top of the buffer text.\n\
13169 This must be the beginning of a line in order to work.\n\
13170 See also `overlay-arrow-string'.");
13171 Voverlay_arrow_position
= Qnil
;
13173 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
13174 "String to display as an arrow. See also `overlay-arrow-position'.");
13175 Voverlay_arrow_string
= Qnil
;
13177 DEFVAR_INT ("scroll-step", &scroll_step
,
13178 "*The number of lines to try scrolling a window by when point moves out.\n\
13179 If that fails to bring point back on frame, point is centered instead.\n\
13180 If this is zero, point is always centered after it moves off frame.");
13182 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
13183 "*Scroll up to this many lines, to bring point back on screen.\n\
13184 A value of zero means to scroll the text to center point vertically\n\
13186 scroll_conservatively
= 0;
13188 DEFVAR_INT ("scroll-margin", &scroll_margin
,
13189 "*Number of lines of margin at the top and bottom of a window.\n\
13190 Recenter the window whenever point gets within this many lines\n\
13191 of the top or bottom of the window.");
13195 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
13198 DEFVAR_BOOL ("truncate-partial-width-windows",
13199 &truncate_partial_width_windows
,
13200 "*Non-nil means truncate lines in all windows less than full frame wide.");
13201 truncate_partial_width_windows
= 1;
13203 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
13204 "*Non-nil means use inverse video for the mode line.");
13205 mode_line_inverse_video
= 1;
13207 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
13208 "*Maximum buffer size for which line number should be displayed.\n\
13209 If the buffer is bigger than this, the line number does not appear\n\
13210 in the mode line. A value of nil means no limit.");
13211 Vline_number_display_limit
= Qnil
;
13213 DEFVAR_INT ("line-number-display-limit-width",
13214 &line_number_display_limit_width
,
13215 "*Maximum line width (in characters) for line number display.\n\
13216 If the average length of the lines near point is bigger than this, then the\n\
13217 line number may be omitted from the mode line.");
13218 line_number_display_limit_width
= 200;
13220 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
13221 "*Non-nil means highlight region even in nonselected windows.");
13222 highlight_nonselected_windows
= 0;
13224 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
13225 "Non-nil if more than one frame is visible on this display.\n\
13226 Minibuffer-only frames don't count, but iconified frames do.\n\
13227 This variable is not guaranteed to be accurate except while processing\n\
13228 `frame-title-format' and `icon-title-format'.");
13230 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
13231 "Template for displaying the title bar of visible frames.\n\
13232 \(Assuming the window manager supports this feature.)\n\
13233 This variable has the same structure as `mode-line-format' (which see),\n\
13234 and is used only on frames for which no explicit name has been set\n\
13235 \(see `modify-frame-parameters').");
13236 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
13237 "Template for displaying the title bar of an iconified frame.\n\
13238 \(Assuming the window manager supports this feature.)\n\
13239 This variable has the same structure as `mode-line-format' (which see),\n\
13240 and is used only on frames for which no explicit name has been set\n\
13241 \(see `modify-frame-parameters').");
13243 = Vframe_title_format
13244 = Fcons (intern ("multiple-frames"),
13245 Fcons (build_string ("%b"),
13246 Fcons (Fcons (build_string (""),
13247 Fcons (intern ("invocation-name"),
13248 Fcons (build_string ("@"),
13249 Fcons (intern ("system-name"),
13253 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
13254 "Maximum number of lines to keep in the message log buffer.\n\
13255 If nil, disable message logging. If t, log messages but don't truncate\n\
13256 the buffer when it becomes large.");
13257 XSETFASTINT (Vmessage_log_max
, 50);
13259 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
13260 "Functions called before redisplay, if window sizes have changed.\n\
13261 The value should be a list of functions that take one argument.\n\
13262 Just before redisplay, for each frame, if any of its windows have changed\n\
13263 size since the last redisplay, or have been split or deleted,\n\
13264 all the functions in the list are called, with the frame as argument.");
13265 Vwindow_size_change_functions
= Qnil
;
13267 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
13268 "List of Functions to call before redisplaying a window with scrolling.\n\
13269 Each function is called with two arguments, the window\n\
13270 and its new display-start position. Note that the value of `window-end'\n\
13271 is not valid when these functions are called.");
13272 Vwindow_scroll_functions
= Qnil
;
13274 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
13275 "*Non-nil means automatically resize tool-bars.\n\
13276 This increases a tool-bar's height if not all tool-bar items are visible.\n\
13277 It decreases a tool-bar's height when it would display blank lines\n\
13279 auto_resize_tool_bars_p
= 1;
13281 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
13282 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
13283 auto_raise_tool_bar_buttons_p
= 1;
13285 DEFVAR_INT ("tool-bar-button-margin", &tool_bar_button_margin
,
13286 "*Margin around tool-bar buttons in pixels.");
13287 tool_bar_button_margin
= 1;
13289 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
13290 "Relief thickness of tool-bar buttons.");
13291 tool_bar_button_relief
= 3;
13293 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
13294 "List of functions to call to fontify regions of text.\n\
13295 Each function is called with one argument POS. Functions must\n\
13296 fontify a region starting at POS in the current buffer, and give\n\
13297 fontified regions the property `fontified'.\n\
13298 This variable automatically becomes buffer-local when set.");
13299 Vfontification_functions
= Qnil
;
13300 Fmake_local_variable (Qfontification_functions
);
13302 DEFVAR_BOOL ("unibyte-display-via-language-environment",
13303 &unibyte_display_via_language_environment
,
13304 "*Non-nil means display unibyte text according to language environment.\n\
13305 Specifically this means that unibyte non-ASCII characters\n\
13306 are displayed by converting them to the equivalent multibyte characters\n\
13307 according to the current language environment. As a result, they are\n\
13308 displayed according to the current fontset.");
13309 unibyte_display_via_language_environment
= 0;
13311 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
13312 "*Maximum height for resizing mini-windows.\n\
13313 If a float, it specifies a fraction of the mini-window frame's height.\n\
13314 If an integer, it specifies a number of lines.\n\
13315 If nil, don't resize.");
13316 Vmax_mini_window_height
= make_float (0.25);
13318 DEFVAR_BOOL ("cursor-in-non-selected-windows",
13319 &cursor_in_non_selected_windows
,
13320 "*Non-nil means display a hollow cursor in non-selected windows.\n\
13321 Nil means don't display a cursor there.");
13322 cursor_in_non_selected_windows
= 1;
13324 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
13325 "*Non-nil means scroll the display automatically to make point visible.");
13326 automatic_hscrolling_p
= 1;
13328 DEFVAR_LISP ("image-types", &Vimage_types
,
13329 "List of supported image types.\n\
13330 Each element of the list is a symbol for a supported image type.");
13331 Vimage_types
= Qnil
;
13333 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
13334 "If non-nil, messages are truncated instead of resizing the echo area.\n\
13335 Bind this around calls to `message' to let it take effect.");
13336 message_truncate_lines
= 0;
13340 /* Initialize this module when Emacs starts. */
13345 Lisp_Object root_window
;
13346 struct window
*mini_w
;
13348 CHARPOS (this_line_start_pos
) = 0;
13350 mini_w
= XWINDOW (minibuf_window
);
13351 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
13353 if (!noninteractive
)
13355 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
13358 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
13359 set_window_height (root_window
,
13360 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
13362 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
13363 set_window_height (minibuf_window
, 1, 0);
13365 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
13366 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
13368 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
13369 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
13370 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
13372 /* The default ellipsis glyphs `...'. */
13373 for (i
= 0; i
< 3; ++i
)
13374 XSETFASTINT (default_invis_vector
[i
], '.');
13377 #ifdef HAVE_WINDOW_SYSTEM
13379 /* Allocate the buffer for frame titles. */
13381 frame_title_buf
= (char *) xmalloc (size
);
13382 frame_title_buf_end
= frame_title_buf
+ size
;
13383 frame_title_ptr
= NULL
;
13385 #endif /* HAVE_WINDOW_SYSTEM */